-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathBattery.Splash.pas
More file actions
223 lines (194 loc) · 6.69 KB
/
Battery.Splash.pas
File metadata and controls
223 lines (194 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
unit Battery.Splash;
interface
uses
Winapi.Windows, Winapi.ActiveX,
System.SysUtils, System.Classes,
Battery.Mode,
Power,
Power.WinApi.PowrProf,
Helpers.Images.Generator,
GdiPlus, SplashUnit, ScreenLiteUnit;
type
/// <summary>
/// sdtNone - Никогда не отображать Splash
/// sdtSelf - Только при изменении схемы питания из приложения
/// sdtAlways - Всегда отображать
/// </summary>
TSplashDisplayType = (sdtNone, sdtSelf, sdtAlways);
TBatterySplash = class(TSplash)
private
class var FSplashDisplayType: TSplashDisplayType;
class var FBatteryState: TBatteryState;
class var FInvertColor: Boolean;
class var ImageList: IGPImage;
class function PercentageToIndex(Percentage: DWORD): Integer;
class procedure SetSplashDisplayType(const Value: TSplashDisplayType); static;
class constructor Create;
protected
class procedure Enabling;
class procedure Disabling;
class function GetRealImageSize: TSize;
class function GeneratePicture(Width, Height: Integer; Monitor: TMonitorLite): IGPBitmap;
public
class procedure ShowSplash(DisplayType: TSplashDisplayType; const State: TBatteryState; InvertColor: Boolean); overload;
class property SplashDisplayType: TSplashDisplayType read FSplashDisplayType write SetSplashDisplayType;
class property MonitorConfig;
class property Interval;
class property Transparency;
class property Showing;
class property ScaleByScreen;
end;
implementation
class procedure TBatterySplash.SetSplashDisplayType(
const Value: TSplashDisplayType);
begin
if FSplashDisplayType = Value then Exit;
FSplashDisplayType := Value;
Enable := Value <> sdtNone;
end;
class procedure TBatterySplash.Enabling;
var
ResStream: TResourceStream;
Stream: IStream;
begin
ResStream := TResourceStream.Create(HInstance, 'BatterySplash', RT_RCDATA);
try
Stream := TStreamAdapter.Create(ResStream);
ImageList := TGPImage.Create(Stream);
finally
ResStream.Free;
end;
end;
class procedure TBatterySplash.Disabling;
begin
//
end;
class procedure TBatterySplash.ShowSplash(DisplayType: TSplashDisplayType;
const State: TBatteryState; InvertColor: Boolean);
begin
if (DisplayType <> FSplashDisplayType) or (FSplashDisplayType = sdtNone) then Exit;
FBatteryState := State;
FInvertColor := InvertColor;
inherited ShowSplash;
end;
class function TBatterySplash.GetRealImageSize: TSize;
begin
Result.Create(ImageList.Height, ImageList.Height);
end;
class function TBatterySplash.GeneratePicture(Width, Height: Integer; Monitor: TMonitorLite): IGPBitmap;
const
CircleGreen = 0;
CircleYellow = 1;
CircleRed = 2;
CirclePurple = 3;
CircleBlue = 4;
RingGreen = 5;
RingYellow = 6;
RingRed = 7;
RingPurple = 8;
RingBlue = 9;
BatteryBody = 10;
PercentageOffset = 11;
Charge = 20;
var
Graphics: IGPGraphics;
Indexes: array of Integer;
IsOverlayAsScheme: Boolean;
begin
Indexes := [];
IsOverlayAsScheme := not (psfMissingScheme in TBatteryMode.PowerSchemes.SchemeFeatures);
if FInvertColor then
begin
case FBatteryState.PowerScheme.PowerSchemeType of
pstMaxPowerSavings : Indexes := Indexes + [CircleRed];
pstTypicalPowerSavings:
begin
if IsOverlayAsScheme then
begin
case FBatteryState.PowerScheme.OverlaySchemeType of
ostOverlayMin : Indexes := Indexes + [CircleRed];
ostOverlayHigh : Indexes := Indexes + [CircleBlue];
ostOverlayMax : Indexes := Indexes + [CircleGreen];
else Indexes := Indexes + [CircleYellow];
end;
end
else
begin
Indexes := Indexes + [CircleYellow];
end;
end;
pstMinPowerSavings : Indexes := Indexes + [CircleGreen];
pstUltimatePowerSavings: Indexes := Indexes + [CirclePurple];
else Indexes := Indexes + [CircleBlue];
end;
case FBatteryState.PowerScheme.OverlaySchemeType of
ostOverlayMin : Indexes := Indexes + [RingRed];
ostOverlayHigh: Indexes := Indexes + [RingBlue];
ostOverlayMax : Indexes := Indexes + [RingGreen];
else Indexes := Indexes + [Indexes[0] + RingGreen];
end;
end
else
begin
case FBatteryState.PowerScheme.PowerSchemeType of
pstMaxPowerSavings : Indexes := Indexes + [CircleGreen];
pstTypicalPowerSavings:
begin
if IsOverlayAsScheme then
begin
case FBatteryState.PowerScheme.OverlaySchemeType of
ostOverlayMin : Indexes := Indexes + [CircleGreen];
ostOverlayHigh : Indexes := Indexes + [CircleBlue];
ostOverlayMax : Indexes := Indexes + [CircleRed];
else Indexes := Indexes + [CircleYellow];
end;
end
else
begin
Indexes := Indexes + [CircleYellow];
end;
end;
pstMinPowerSavings : Indexes := Indexes + [CircleRed];
pstUltimatePowerSavings: Indexes := Indexes + [CirclePurple];
else Indexes := Indexes + [CircleBlue];
end;
case FBatteryState.PowerScheme.OverlaySchemeType of
ostOverlayMin : Indexes := Indexes + [RingGreen];
ostOverlayHigh: Indexes := Indexes + [RingBlue];
ostOverlayMax : Indexes := Indexes + [RingRed];
else Indexes := Indexes + [Indexes[0] + RingGreen];
end;
end;
Indexes := Indexes + [BatteryBody];
if FBatteryState.PowerCondition = PoDc then
Indexes := Indexes + [PercentageOffset + PercentageToIndex(FBatteryState.Percentage)]
else
Indexes := Indexes + [Charge];
Result := TGPBitmap.Create(Width, Height);
Graphics := TGPGraphics.Create(Result);
Graphics.DrawImage(GenerateGPBitmapFromBitmap(ImageList, Indexes, 1, 0, Monitor.Dpi), 0, 0, Width, Height);
end;
class function TBatterySplash.PercentageToIndex(Percentage: DWORD): Integer;
begin
case Percentage of
0 .. 4: Result := 0; // _
5 .. 14: Result := 1; // \
15 .. 25: Result := 2; // |
26 .. 37: Result := 3; // |\
38 .. 49: Result := 4; // ||
50 .. 63: Result := 5; // ||\
64 .. 78: Result := 6; // |||
79 .. 94: Result := 7; // |||\
95 .. 100: Result := 8; // ||||
else Result := 0;
end;
end;
class constructor TBatterySplash.Create;
begin
FSplashDisplayType := sdtNone;
EnablingFunc := Enabling;
DisablingFunc := Disabling;
GetRealImageSizeFunc := GetRealImageSize;
GeneratePictureFunc := GeneratePicture;
end;
end.