1 | unit ScreenTools;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | {$IFDEF WINDOWS}
|
---|
7 | Windows,
|
---|
8 | {$ENDIF}
|
---|
9 | StringTables, LCLIntf, LCLType, SysUtils, Classes, Math,
|
---|
10 | GraphType, GraphicSet, LazFileUtils, Texture,
|
---|
11 | {$IFDEF DPI}Dpi.Forms, Dpi.Menus, Dpi.Graphics, Dpi.Controls, Dpi.Common{$ELSE}
|
---|
12 | Forms, Menus, Graphics, Controls{$ENDIF};
|
---|
13 |
|
---|
14 | type
|
---|
15 | TLoadGraphicFileOption = (gfNoError, gfNoGamma);
|
---|
16 | TLoadGraphicFileOptions = set of TLoadGraphicFileOption;
|
---|
17 |
|
---|
18 | TFontType = (ftNormal, ftSmall, ftTiny, ftCaption, ftButton);
|
---|
19 |
|
---|
20 | {$IFDEF WINDOWS}
|
---|
21 | function ChangeResolution(X, Y, bpp, freq: Integer): Boolean;
|
---|
22 | {$ENDIF}
|
---|
23 | procedure RestoreResolution;
|
---|
24 | procedure EmptyMenu(MenuItems: TMenuItem; Keep: Integer = 0);
|
---|
25 | function TurnToYear(Turn: Integer): Integer;
|
---|
26 | function TurnToString(Turn: Integer): string;
|
---|
27 | function MovementToString(Movement: Integer): string;
|
---|
28 | procedure BtnFrame(Canvas: TCanvas; P: TRect; T: TTexture);
|
---|
29 | procedure EditFrame(Canvas: TCanvas; P: TRect; T: TTexture);
|
---|
30 | function HexStringToColor(S: string): Integer;
|
---|
31 | function ExtractFileNameWithoutExt(const Filename: string): string;
|
---|
32 | function LoadGraphicFile(Bmp: TBitmap; FileName: string; Options: TLoadGraphicFileOptions = []): Boolean;
|
---|
33 | function LoadGraphicSet(const Name: string; Transparency: Boolean = True): TGraphicSet;
|
---|
34 | procedure Dump(Dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
|
---|
35 | procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor);
|
---|
36 | procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
|
---|
37 | overload;
|
---|
38 | procedure Sprite(Canvas: TCanvas; xDst, yDst: Integer; GraphicSetItem: TGraphicSetItem);
|
---|
39 | overload;
|
---|
40 | procedure Sprite(Dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
|
---|
41 | overload;
|
---|
42 | procedure MakeBlue(Dst: TBitmap; X, Y, Width, Height: Integer);
|
---|
43 | procedure MakeRed(Dst: TBitmap; X, Y, Width, Height: Integer);
|
---|
44 | procedure ImageOp_B(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer);
|
---|
45 | procedure ImageOp_BCC(Dst, Src: TBitmap;
|
---|
46 | xDst, yDst, xSrc, ySrc, Width, Height, Color1, Color2: Integer); overload;
|
---|
47 | procedure ImageOp_BCC(Dst, Src: TBitmap;
|
---|
48 | DstPos: TPoint; SrcRect: TRect; Color1, Color2: Integer); overload;
|
---|
49 | procedure ImageOp_CBC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
|
---|
50 | Color0, Color2: Integer);
|
---|
51 | procedure ImageOp_CCC(Bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
|
---|
52 | function BitBltCanvas(DestCanvas: TCanvas; X, Y, Width, Height: Integer;
|
---|
53 | SrcCanvas: TCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload;
|
---|
54 | function BitBltCanvas(Dest: TCanvas; DestRect: TRect;
|
---|
55 | Src: TCanvas; SrcPos: TPoint; Rop: DWORD = SRCCOPY): Boolean; overload;
|
---|
56 | function BitBltBitmap(Dest: TBitmap; X, Y, Width, Height: Integer;
|
---|
57 | Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload;
|
---|
58 | function BitBltBitmap(Dest: TBitmap; DestRect: TRect;
|
---|
59 | Src: TBitmap; SrcPos: TPoint; Rop: DWORD = SRCCOPY): Boolean; overload;
|
---|
60 | procedure SLine(Canvas: TCanvas; x0, x1, Y: Integer; cl: TColor);
|
---|
61 | procedure DLine(Canvas: TCanvas; x0, x1, Y: Integer; cl0, cl1: TColor);
|
---|
62 | procedure Frame(Canvas: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
|
---|
63 | procedure RFrame(Canvas: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
|
---|
64 | procedure CFrame(Canvas: TCanvas; x0, y0, x1, y1, Corner: Integer; cl: TColor);
|
---|
65 | procedure FrameImage(Canvas: TCanvas; Src: TBitmap;
|
---|
66 | X, Y, Width, Height, xSrc, ySrc: Integer; IsControl: Boolean = False);
|
---|
67 | procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: Integer; cl: TColor);
|
---|
68 | procedure InitOrnament;
|
---|
69 | procedure InitCityMark(Texture: TTexture);
|
---|
70 | procedure Fill(Canvas: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer); overload;
|
---|
71 | procedure Fill(Canvas: TCanvas; Rect: TRect; Offset: TPoint); overload;
|
---|
72 | procedure FillLarge(Canvas: TCanvas; x0, y0, x1, y1, xm: Integer);
|
---|
73 | procedure FillSeamless(Canvas: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer;
|
---|
74 | const Texture: TBitmap);
|
---|
75 | procedure FillRectSeamless(Canvas: TCanvas; x0, y0, x1, y1, xOffset, yOffset: Integer;
|
---|
76 | const Texture: TBitmap);
|
---|
77 | procedure PaintBackground(Canvas: TCanvas; Left, Top, Width, Height, FormWidth,
|
---|
78 | FormHeight: Integer);
|
---|
79 | procedure Corner(Canvas: TCanvas; X, Y, Kind: Integer; T: TTexture);
|
---|
80 | procedure BiColorTextOut(Canvas: TCanvas; clMain, clBack: TColor; X, Y: Integer; S: string);
|
---|
81 | procedure LoweredTextOut(Canvas: TCanvas; cl: TColor; T: TTexture;
|
---|
82 | X, Y: Integer; S: string);
|
---|
83 | function BiColorTextWidth(Canvas: TCanvas; S: string): Integer;
|
---|
84 | procedure RisedTextOut(Canvas: TCanvas; X, Y: Integer; S: string);
|
---|
85 | procedure LightGradient(Canvas: TCanvas; X, Y, Width, Color: Integer);
|
---|
86 | procedure DarkGradient(Canvas: TCanvas; X, Y, Width, Kind: Integer);
|
---|
87 | procedure VLightGradient(Canvas: TCanvas; X, Y, Height, Color: Integer);
|
---|
88 | procedure VDarkGradient(Canvas: TCanvas; X, Y, Height, Kind: Integer);
|
---|
89 | procedure UnderlinedTitleValue(Canvas: TCanvas; Title, Value: string; X, Y, Width: Integer);
|
---|
90 | procedure NumberBar(Dst: TBitmap; X, Y: Integer; Cap: string; Val: Integer;
|
---|
91 | T: TTexture);
|
---|
92 | procedure CountBar(Dst: TBitmap; X, Y, W: Integer; Kind: Integer;
|
---|
93 | Cap: string; Val: Integer; T: TTexture);
|
---|
94 | procedure PaintProgressBar(Canvas: TCanvas; Kind, X, Y, Pos, Growth, Max: Integer;
|
---|
95 | T: TTexture);
|
---|
96 | procedure PaintRelativeProgressBar(Canvas: TCanvas;
|
---|
97 | Kind, X, Y, Size, Pos, Growth, Max: Integer; IndicateComplete: Boolean;
|
---|
98 | T: TTexture);
|
---|
99 | procedure PaintLogo(Canvas: TCanvas; X, Y, LightColor, ShadeColor: Integer);
|
---|
100 | procedure DrawBufferEnsureSize(Width, Height: Integer);
|
---|
101 | procedure LoadPhrases;
|
---|
102 | procedure Texturize(Dest, Texture: TBitmap; TransparentColor: Cardinal);
|
---|
103 | procedure DarkenImage(Bitmap: TBitmap; Change: Integer);
|
---|
104 | {$IFNDEF DPI}
|
---|
105 | function ScaleToNative(Value: Integer): Integer;
|
---|
106 | function ScaleToNativeDist(Base, Value: Integer): Integer;
|
---|
107 | function ScaleFromNative(Value: Integer): Integer;
|
---|
108 | {$ENDIF}
|
---|
109 | procedure UnshareBitmap(Bitmap: TBitmap);
|
---|
110 | procedure Gtk2Fix;
|
---|
111 | procedure Gtk2DisableControlStyling(WinControl: TWinControl);
|
---|
112 | procedure LoadConfig(Key: string);
|
---|
113 | procedure SaveConfig(Key: string);
|
---|
114 |
|
---|
115 | const
|
---|
116 | TransparentColor1 = $FF00FF;
|
---|
117 | TransparentColor2 = $7F007F;
|
---|
118 |
|
---|
119 | // template positions in Templates.png
|
---|
120 | xNation = 1;
|
---|
121 | yNation = 25;
|
---|
122 | xCoal = 1;
|
---|
123 | yCoal = 148;
|
---|
124 |
|
---|
125 | // Icons.bmp structure
|
---|
126 | xSizeBig = 56;
|
---|
127 | ySizeBig = 40;
|
---|
128 |
|
---|
129 | GlowRange = 8;
|
---|
130 |
|
---|
131 | EmptySpaceColor = $101010;
|
---|
132 |
|
---|
133 | // color matrix
|
---|
134 | clkAge0 = 1;
|
---|
135 | cliTexture = 0;
|
---|
136 | cliBevelLight = cliTexture + 1;
|
---|
137 | cliBevelShade = cliTexture + 2;
|
---|
138 | cliTextLight = cliTexture + 3;
|
---|
139 | cliTextShade = cliTexture + 4;
|
---|
140 | cliLitText = cliTexture + 5;
|
---|
141 | cliMark = cliTexture + 6;
|
---|
142 | cliDimmedText = cliTexture + 7;
|
---|
143 | cliRoad = 8;
|
---|
144 | cliHouse = cliRoad + 1;
|
---|
145 | cliImp = cliRoad + 2;
|
---|
146 | cliImpProject = cliRoad + 3;
|
---|
147 | cliPage = 13;
|
---|
148 | cliCover = cliPage + 1;
|
---|
149 | clkMisc = 5;
|
---|
150 | cliPaper = 0;
|
---|
151 | cliPaperText = 1;
|
---|
152 | cliPaperCaption = 2;
|
---|
153 | clkCity = 6;
|
---|
154 | cliPlains = 0;
|
---|
155 | cliPrairie = 1;
|
---|
156 | cliHills = 2;
|
---|
157 | cliTundra = 3;
|
---|
158 | cliWater = 4;
|
---|
159 |
|
---|
160 | var
|
---|
161 | Phrases: TStringTable;
|
---|
162 | Phrases2: TStringTable;
|
---|
163 | GrExt: TGraphicSets;
|
---|
164 |
|
---|
165 | HGrSystem: TGraphicSet;
|
---|
166 | CityMark1: TGraphicSetItem;
|
---|
167 | CityMark2: TGraphicSetItem;
|
---|
168 |
|
---|
169 | HGrSystem2: TGraphicSet;
|
---|
170 | Ornament: TGraphicSetItem;
|
---|
171 | GBrainNoTerm: TGraphicSetItem;
|
---|
172 | GBrainSuperVirtual: TGraphicSetItem;
|
---|
173 | GBrainTerm: TGraphicSetItem;
|
---|
174 | GBrainRandom: TGraphicSetItem;
|
---|
175 |
|
---|
176 | Templates: TGraphicSet;
|
---|
177 | Logo: TGraphicSetItem;
|
---|
178 | BigBook: TGraphicSetItem;
|
---|
179 | SmallBook: TGraphicSetItem;
|
---|
180 | MenuLogo: TGraphicSetItem;
|
---|
181 | LinkArrows: TGraphicSetItem;
|
---|
182 | ScienceNationDot: TGraphicSetItem;
|
---|
183 | ResearchIcon: TGraphicSetItem;
|
---|
184 | ChangeIcon: TGraphicSetItem;
|
---|
185 | TreasuryIcon: TGraphicSetItem;
|
---|
186 | StarshipDeparted: TGraphicSetItem;
|
---|
187 | WeightOn: TGraphicSetItem;
|
---|
188 | WeightOff: TGraphicSetItem;
|
---|
189 |
|
---|
190 | ClickFrameColor: Integer;
|
---|
191 | MainTexture: TTexture;
|
---|
192 | Colors: TBitmap;
|
---|
193 | Paper: TBitmap;
|
---|
194 | BigImp: TBitmap;
|
---|
195 | DrawBuffer: TBitmap;
|
---|
196 | FullScreen: Boolean;
|
---|
197 | TermBounds: TRect;
|
---|
198 | GenerateNames: Boolean;
|
---|
199 | InitOrnamentDone: Boolean;
|
---|
200 | Phrases2FallenBackToEnglish: Boolean;
|
---|
201 |
|
---|
202 | UniFont: array [TFontType] of TFont;
|
---|
203 | Gamma: Integer; // global gamma correction (cent)
|
---|
204 | CustomDpiEnabled: Boolean;
|
---|
205 | CustomDpi: Integer;
|
---|
206 |
|
---|
207 | procedure LoadAssets;
|
---|
208 | procedure UnitInit;
|
---|
209 | procedure UnitDone;
|
---|
210 | procedure InitGammaLookupTable;
|
---|
211 |
|
---|
212 |
|
---|
213 | implementation
|
---|
214 |
|
---|
215 | uses
|
---|
216 | {$IFDEF DPI}Dpi.PixelPointer,{$ELSE}PixelPointer,{$ENDIF}
|
---|
217 | Directories, Sound, Registry
|
---|
218 | {$IFDEF LCLGTK2}, gtk2, WSProc{$ENDIF};
|
---|
219 |
|
---|
220 | var
|
---|
221 | {$IFDEF WINDOWS}
|
---|
222 | StartResolution: TDeviceMode;
|
---|
223 | ResolutionChanged: Boolean;
|
---|
224 | {$ENDIF}
|
---|
225 |
|
---|
226 | GammaLookupTable: array [0..255] of Byte;
|
---|
227 |
|
---|
228 | {$IFDEF WINDOWS}
|
---|
229 | function ChangeResolution(X, Y, bpp, freq: Integer): Boolean;
|
---|
230 | var
|
---|
231 | DevMode: TDeviceMode;
|
---|
232 | begin
|
---|
233 | EnumDisplaySettings(nil, 0, DevMode);
|
---|
234 | DevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or DM_BITSPERPEL or
|
---|
235 | DM_DISPLAYFREQUENCY;
|
---|
236 | DevMode.dmPelsWidth := X;
|
---|
237 | DevMode.dmPelsHeight := Y;
|
---|
238 | DevMode.dmBitsPerPel := bpp;
|
---|
239 | DevMode.dmDisplayFrequency := freq;
|
---|
240 | Result := ChangeDisplaySettings(DevMode, 0) = DISP_CHANGE_SUCCESSFUL;
|
---|
241 | if Result then
|
---|
242 | ResolutionChanged := True;
|
---|
243 | end;
|
---|
244 |
|
---|
245 | {$ENDIF}
|
---|
246 |
|
---|
247 | procedure RestoreResolution;
|
---|
248 | begin
|
---|
249 | {$IFDEF WINDOWS}
|
---|
250 | if ResolutionChanged then
|
---|
251 | ChangeDisplaySettings(StartResolution, 0);
|
---|
252 | ResolutionChanged := False;
|
---|
253 | {$ENDIF}
|
---|
254 | end;
|
---|
255 |
|
---|
256 | procedure EmptyMenu(MenuItems: TMenuItem; Keep: Integer = 0);
|
---|
257 | var
|
---|
258 | MenuItem: TMenuItem;
|
---|
259 | begin
|
---|
260 | if Keep = 0 then MenuItems.Clear
|
---|
261 | else
|
---|
262 | while MenuItems.Count > Keep do begin
|
---|
263 | MenuItem := MenuItems[MenuItems.Count - 1];
|
---|
264 | MenuItems.Delete(MenuItems.Count - 1);
|
---|
265 | FreeAndNil(MenuItem);
|
---|
266 | end;
|
---|
267 | end;
|
---|
268 |
|
---|
269 | function TurnToYear(Turn: Integer): Integer;
|
---|
270 | begin
|
---|
271 | Result := -4000;
|
---|
272 | if Turn <= 0 then Exit;
|
---|
273 |
|
---|
274 | // Year -4000..-1000, Turn 0..60
|
---|
275 | Inc(Result, Min(60, Turn) * 50);
|
---|
276 | Dec(Turn, Min(60, Turn));
|
---|
277 | if Turn = 0 then Exit;
|
---|
278 |
|
---|
279 | // Year -1000..0, Turn 60..100
|
---|
280 | Inc(Result, Min(40, Turn) * 25);
|
---|
281 | Dec(Turn, Min(40, Turn));
|
---|
282 | if Turn = 0 then Exit;
|
---|
283 |
|
---|
284 | // Year 0..1500, Turn 100..175
|
---|
285 | Inc(Result, Min(75, Turn) * 20);
|
---|
286 | Dec(Turn, Min(75, Turn));
|
---|
287 | if Turn = 0 then Exit;
|
---|
288 |
|
---|
289 | // Year 1500..1750, Turn 175..200
|
---|
290 | Inc(Result, Min(25, Turn) * 10);
|
---|
291 | Dec(Turn, Min(25, Turn));
|
---|
292 | if Turn = 0 then Exit;
|
---|
293 |
|
---|
294 | // Year 1750..1850, Turn 200..250
|
---|
295 | Inc(Result, Min(50, Turn) * 2);
|
---|
296 | Dec(Turn, Min(50, Turn));
|
---|
297 | if Turn = 0 then Exit;
|
---|
298 |
|
---|
299 | // Year 1850.., Turn 250..
|
---|
300 | Inc(Result, Turn);
|
---|
301 | end;
|
---|
302 |
|
---|
303 | function TurnToString(Turn: Integer): string;
|
---|
304 | var
|
---|
305 | Year: Integer;
|
---|
306 | begin
|
---|
307 | if GenerateNames then
|
---|
308 | begin
|
---|
309 | Year := TurnToYear(Turn);
|
---|
310 | if Year < 0 then
|
---|
311 | Result := Format(Phrases.Lookup('BC'), [-Year])
|
---|
312 | else
|
---|
313 | Result := Format(Phrases.Lookup('AD'), [Year]);
|
---|
314 | end
|
---|
315 | else
|
---|
316 | Result := IntToStr(Turn);
|
---|
317 | end;
|
---|
318 |
|
---|
319 | function MovementToString(Movement: Integer): string;
|
---|
320 | begin
|
---|
321 | if Movement >= 1000 then
|
---|
322 | begin
|
---|
323 | Result := Char(48 + Movement div 1000);
|
---|
324 | Movement := Movement mod 1000;
|
---|
325 | end
|
---|
326 | else
|
---|
327 | Result := '';
|
---|
328 | Result := Result + Char(48 + Movement div 100);
|
---|
329 | Movement := Movement mod 100;
|
---|
330 | if Movement > 0 then
|
---|
331 | begin
|
---|
332 | Result := Result + '.' + Char(48 + Movement div 10);
|
---|
333 | Movement := Movement mod 10;
|
---|
334 | if Movement > 0 then
|
---|
335 | Result := Result + Char(48 + Movement);
|
---|
336 | end;
|
---|
337 | end;
|
---|
338 |
|
---|
339 | procedure BtnFrame(Canvas: TCanvas; P: TRect; T: TTexture);
|
---|
340 | begin
|
---|
341 | RFrame(Canvas, P.Left - 1, P.Top - 1, P.Right, P.Bottom, T.ColorBevelShade,
|
---|
342 | T.ColorBevelLight);
|
---|
343 | end;
|
---|
344 |
|
---|
345 | procedure EditFrame(Canvas: TCanvas; P: TRect; T: TTexture);
|
---|
346 | begin
|
---|
347 | Frame(Canvas, P.Left - 1, P.Top - 1, P.Right, P.Bottom, $000000, $000000);
|
---|
348 | Frame(Canvas, P.Left - 2, P.Top - 2, P.Right + 1, P.Bottom + 1, $000000, $000000);
|
---|
349 | Frame(Canvas, P.Left - 3, P.Top - 3, P.Right + 2, P.Bottom + 1, $000000, $000000);
|
---|
350 | RFrame(Canvas, P.Left - 4, P.Top - 4, P.Right + 3, P.Bottom + 2, T.ColorBevelShade,
|
---|
351 | T.ColorBevelLight);
|
---|
352 | end;
|
---|
353 |
|
---|
354 | function HexCharToInt(X: Char): Integer;
|
---|
355 | begin
|
---|
356 | case X of
|
---|
357 | '0' .. '9': Result := Ord(X) - Ord('0');
|
---|
358 | 'A' .. 'F': Result := Ord(X) - Ord('A') + 10;
|
---|
359 | 'a' .. 'f': Result := Ord(X) - Ord('a') + 10;
|
---|
360 | else Result := 0
|
---|
361 | end;
|
---|
362 | end;
|
---|
363 |
|
---|
364 | function HexStringToColor(S: string): Integer;
|
---|
365 | begin
|
---|
366 | while (Length(S) > 0) and (S[1] = ' ') do
|
---|
367 | Delete(S, 1, 1);
|
---|
368 | S := S + '000000';
|
---|
369 | if Gamma = 100 then
|
---|
370 | Result := $10 * HexCharToInt(S[1]) + $1 * HexCharToInt(S[2]) +
|
---|
371 | $1000 * HexCharToInt(S[3]) + $100 * HexCharToInt(S[4]) +
|
---|
372 | $100000 * HexCharToInt(S[5]) + $10000 * HexCharToInt(S[6])
|
---|
373 | else
|
---|
374 | Result := GammaLookupTable[$10 * HexCharToInt(S[1]) + HexCharToInt(S[2])] +
|
---|
375 | $100 * GammaLookupTable[$10 * HexCharToInt(S[3]) + HexCharToInt(S[4])] +
|
---|
376 | $10000 * GammaLookupTable[$10 * HexCharToInt(S[5]) + HexCharToInt(S[6])];
|
---|
377 | end;
|
---|
378 |
|
---|
379 | function ApplyGammaToPixel(Pixel: TPixel32): TPixel32;
|
---|
380 | begin
|
---|
381 | Result.R := GammaLookupTable[Pixel.R];
|
---|
382 | Result.G := GammaLookupTable[Pixel.G];
|
---|
383 | Result.B := GammaLookupTable[Pixel.B];
|
---|
384 | end;
|
---|
385 |
|
---|
386 | procedure ApplyGammaToBitmap(Bitmap: TBitmap);
|
---|
387 | var
|
---|
388 | PixelPtr: TPixelPointer;
|
---|
389 | X, Y: Integer;
|
---|
390 | begin
|
---|
391 | Bitmap.BeginUpdate;
|
---|
392 | PixelPtr := TPixelPointer.Create(Bitmap);
|
---|
393 | for Y := 0 to ScaleToNative(Bitmap.Height) - 1 do begin
|
---|
394 | for X := 0 to ScaleToNative(Bitmap.Width) - 1 do begin
|
---|
395 | PixelPtr.Pixel^ := ApplyGammaToPixel(PixelPtr.Pixel^);
|
---|
396 | PixelPtr.NextPixel;
|
---|
397 | end;
|
---|
398 | PixelPtr.NextLine;
|
---|
399 | end;
|
---|
400 | Bitmap.EndUpdate;
|
---|
401 | end;
|
---|
402 |
|
---|
403 | procedure CopyGray8BitTo24bitBitmap(Dst, Src: TRasterImage);
|
---|
404 | var
|
---|
405 | SrcPtr, DstPtr: TPixelPointer;
|
---|
406 | X, Y: Integer;
|
---|
407 | begin
|
---|
408 | //Dst.SetSize(Src.Width, Src.Height);
|
---|
409 | SrcPtr := TPixelPointer.Create(Src);
|
---|
410 | DstPtr := TPixelPointer.Create(Dst);
|
---|
411 | for Y := 0 to ScaleToNative(Src.Height - 1) do begin
|
---|
412 | for X := 0 to ScaleToNative(Src.Width - 1) do begin
|
---|
413 | DstPtr.PixelB := SrcPtr.PixelB;
|
---|
414 | DstPtr.PixelG := SrcPtr.PixelB;
|
---|
415 | DstPtr.PixelR := SrcPtr.PixelB;
|
---|
416 | SrcPtr.NextPixel;
|
---|
417 | DstPtr.NextPixel;
|
---|
418 | end;
|
---|
419 | SrcPtr.NextLine;
|
---|
420 | DstPtr.NextLine;
|
---|
421 | end;
|
---|
422 | end;
|
---|
423 |
|
---|
424 | function LoadGraphicFile(Bmp: TBitmap; FileName: string; Options:
|
---|
425 | TLoadGraphicFileOptions = []): Boolean;
|
---|
426 | var
|
---|
427 | Jpeg: TJpegImage;
|
---|
428 | Png: TPortableNetworkGraphic;
|
---|
429 | begin
|
---|
430 | Result := False;
|
---|
431 | if ExtractFileExt(FileName) = '' then
|
---|
432 | FileName := FileName + '.png';
|
---|
433 |
|
---|
434 | if FileExists(FileName) then begin
|
---|
435 | if ExtractFileExt(FileName) = '.jpg' then begin
|
---|
436 | Jpeg := TJpegImage.Create;
|
---|
437 | try
|
---|
438 | Jpeg.LoadFromFile(FileName);
|
---|
439 | if not (gfNoGamma in Options) then
|
---|
440 | Bmp.PixelFormat := TPixelFormat.pf24bit;
|
---|
441 | Bmp.SetSize(Jpeg.Width, Jpeg.Height);
|
---|
442 | Bmp.Canvas.Draw(0, 0, Jpeg);
|
---|
443 | Result := True;
|
---|
444 | except
|
---|
445 | Result := False;
|
---|
446 | end;
|
---|
447 | FreeAndNil(Jpeg);
|
---|
448 | end else
|
---|
449 | if ExtractFileExt(FileName) = '.png' then begin
|
---|
450 | Png := TPortableNetworkGraphic.Create;
|
---|
451 | try
|
---|
452 | Png.PixelFormat := Bmp.PixelFormat;
|
---|
453 | Png.LoadFromFile(FileName);
|
---|
454 | if not (gfNoGamma in Options) then
|
---|
455 | Bmp.PixelFormat := TPixelFormat.pf24bit;
|
---|
456 | Bmp.SetSize(Png.Width, Png.Height);
|
---|
457 | if (Png.RawImage.Description.Format = ricfGray) then
|
---|
458 | begin
|
---|
459 | // LCL doesn't support 8-bit colors properly. Use 24-bit instead.
|
---|
460 | Bmp.PixelFormat := TPixelFormat.pf24bit;
|
---|
461 | CopyGray8BitTo24bitBitmap(Bmp, Png);
|
---|
462 | end
|
---|
463 | else
|
---|
464 | Bmp.Canvas.Draw(0, 0, Png);
|
---|
465 | Result := True;
|
---|
466 | except
|
---|
467 | Result := False;
|
---|
468 | end;
|
---|
469 | FreeAndNil(Png);
|
---|
470 | end else
|
---|
471 | if ExtractFileExt(FileName) = '.bmp' then begin
|
---|
472 | try
|
---|
473 | Bmp.LoadFromFile(FileName);
|
---|
474 | if not (gfNoGamma in Options) then
|
---|
475 | Bmp.PixelFormat := TPixelFormat.pf24bit;
|
---|
476 | Result := True;
|
---|
477 | except
|
---|
478 | Result := False;
|
---|
479 | end;
|
---|
480 | end else
|
---|
481 | raise Exception.Create('Unsupported image file type ' + ExtractFileExt(FileName));
|
---|
482 | end;
|
---|
483 |
|
---|
484 | if not Result then begin
|
---|
485 | if not (gfNoError in Options) then
|
---|
486 | raise Exception.Create(Format(Phrases.Lookup('FILENOTFOUND'), [FileName]));
|
---|
487 | end;
|
---|
488 |
|
---|
489 | if (not (gfNoGamma in Options)) and (Gamma <> 100) then
|
---|
490 | ApplyGammaToBitmap(Bmp);
|
---|
491 | end;
|
---|
492 |
|
---|
493 | function ExtractFileNameWithoutExt(const Filename: string): string;
|
---|
494 | var
|
---|
495 | P: Integer;
|
---|
496 | begin
|
---|
497 | Result := Filename;
|
---|
498 | P := Length(Result);
|
---|
499 | while P > 0 do begin
|
---|
500 | case Result[P] of
|
---|
501 | PathDelim: Exit;
|
---|
502 | {$ifdef windows}
|
---|
503 | '/': if ('/' in AllowDirectorySeparators) then Exit;
|
---|
504 | {$endif}
|
---|
505 | '.': Exit(Copy(Result, 1, P - 1));
|
---|
506 | end;
|
---|
507 | Dec(P);
|
---|
508 | end;
|
---|
509 | end;
|
---|
510 |
|
---|
511 | function LoadGraphicSet(const Name: string; Transparency: Boolean = True): TGraphicSet;
|
---|
512 | var
|
---|
513 | X: Integer;
|
---|
514 | Y: Integer;
|
---|
515 | OriginalColor: Integer;
|
---|
516 | FileName: string;
|
---|
517 | DataPixel: TPixelPointer;
|
---|
518 | MaskPixel: TPixelPointer;
|
---|
519 | begin
|
---|
520 | Result := GrExt.SearchByName(Name);
|
---|
521 | if not Assigned(Result) then begin
|
---|
522 | Result := GrExt.AddNew(Name);
|
---|
523 | FileName := GetGraphicsDir + DirectorySeparator + Name;
|
---|
524 | // Do not apply gamma during file load as it would affect also transparency colors
|
---|
525 | if not LoadGraphicFile(Result.Data, FileName, [gfNoGamma]) then begin
|
---|
526 | Result := nil;
|
---|
527 | Exit;
|
---|
528 | end;
|
---|
529 |
|
---|
530 | FileName := ExtractFileNameWithoutExt(FileName) + GraphicSetFileExt;
|
---|
531 | if FileExists(FileName) then
|
---|
532 | Result.LoadFromFile(FileName);
|
---|
533 |
|
---|
534 | Result.ResetPixUsed;
|
---|
535 |
|
---|
536 | if Transparency then begin
|
---|
537 | Result.Mask.SetSize(Result.Data.Width, Result.Data.Height);
|
---|
538 |
|
---|
539 | Result.Data.BeginUpdate;
|
---|
540 | Result.Mask.BeginUpdate;
|
---|
541 | DataPixel := TPixelPointer.Create(Result.Data);
|
---|
542 | MaskPixel := TPixelPointer.Create(Result.Mask);
|
---|
543 | for Y := 0 to ScaleToNative(Result.Data.Height) - 1 do begin
|
---|
544 | for X := 0 to ScaleToNative(Result.Data.Width) - 1 do begin
|
---|
545 | OriginalColor := DataPixel.PixelARGB and $FFFFFF;
|
---|
546 | if (OriginalColor = TransparentColor1) or (OriginalColor = TransparentColor2) then begin
|
---|
547 | MaskPixel.PixelRGB := $ffffff;
|
---|
548 | DataPixel.PixelRGB := 0;
|
---|
549 | end else begin
|
---|
550 | MaskPixel.PixelRGB := 0;
|
---|
551 | end;
|
---|
552 | DataPixel.NextPixel;
|
---|
553 | MaskPixel.NextPixel;
|
---|
554 | end;
|
---|
555 | DataPixel.NextLine;
|
---|
556 | MaskPixel.NextLine;
|
---|
557 | end;
|
---|
558 | Result.Data.EndUpdate;
|
---|
559 | Result.Mask.EndUpdate;
|
---|
560 |
|
---|
561 | if Gamma <> 100 then
|
---|
562 | ApplyGammaToBitmap(Result.Data);
|
---|
563 | end;
|
---|
564 | end;
|
---|
565 | end;
|
---|
566 |
|
---|
567 | procedure Dump(Dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
|
---|
568 | begin
|
---|
569 | BitBltBitmap(Dst, xDst, yDst, Width, Height, HGr.Data, xGr, yGr);
|
---|
570 | end;
|
---|
571 |
|
---|
572 | procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor);
|
---|
573 | var
|
---|
574 | XX, YY: Integer;
|
---|
575 | PixelPtr: TPixelPointer;
|
---|
576 | begin
|
---|
577 | Dst.BeginUpdate;
|
---|
578 | PixelPtr := TPixelPointer.Create(Dst, ScaleToNative(X), ScaleToNative(Y));
|
---|
579 | for YY := 0 to ScaleToNative(Height) - 1 do begin
|
---|
580 | for XX := 0 to ScaleToNative(Width) - 1 do begin
|
---|
581 | if PixelPtr.PixelRGB = SwapRedBlue(OldColor) then begin
|
---|
582 | PixelPtr.PixelRGB := SwapRedBlue(NewColor);
|
---|
583 | end;
|
---|
584 | PixelPtr.NextPixel;
|
---|
585 | end;
|
---|
586 | PixelPtr.NextLine;
|
---|
587 | end;
|
---|
588 | Dst.EndUpdate;
|
---|
589 | end;
|
---|
590 |
|
---|
591 | procedure MakeBlue(Dst: TBitmap; X, Y, Width, Height: Integer);
|
---|
592 | var
|
---|
593 | XX, YY: Integer;
|
---|
594 | PixelPtr: TPixelPointer;
|
---|
595 | begin
|
---|
596 | Dst.BeginUpdate;
|
---|
597 | PixelPtr := TPixelPointer.Create(Dst, ScaleToNative(X), ScaleToNative(Y));
|
---|
598 | for yy := 0 to ScaleToNative(Height) - 1 do begin
|
---|
599 | for xx := 0 to ScaleToNative(Width) - 1 do begin
|
---|
600 | PixelPtr.PixelB := PixelPtr.PixelB div 2;
|
---|
601 | PixelPtr.PixelG := PixelPtr.PixelG div 2;
|
---|
602 | PixelPtr.PixelR := PixelPtr.PixelR div 2;
|
---|
603 | PixelPtr.NextPixel;
|
---|
604 | end;
|
---|
605 | PixelPtr.NextLine;
|
---|
606 | end;
|
---|
607 | Dst.EndUpdate;
|
---|
608 | end;
|
---|
609 |
|
---|
610 | procedure MakeRed(Dst: TBitmap; X, Y, Width, Height: Integer);
|
---|
611 | var
|
---|
612 | XX, YY: Integer;
|
---|
613 | Gray: Integer;
|
---|
614 | PixelPtr: TPixelPointer;
|
---|
615 | begin
|
---|
616 | Dst.BeginUpdate;
|
---|
617 | PixelPtr := TPixelPointer.Create(Dst, ScaleToNative(X), ScaleToNative(Y));
|
---|
618 | for YY := 0 to ScaleToNative(Height) - 1 do begin
|
---|
619 | for XX := 0 to ScaleToNative(Width) - 1 do begin
|
---|
620 | Gray := (Integer(PixelPtr.PixelB) + Integer(PixelPtr.PixelG) +
|
---|
621 | Integer(PixelPtr.PixelR)) * 85 shr 8;
|
---|
622 | PixelPtr.PixelB := 0;
|
---|
623 | PixelPtr.PixelG := 0;
|
---|
624 | PixelPtr.PixelR := Gray; // 255-(255-gray) div 2;
|
---|
625 | PixelPtr.NextPixel;
|
---|
626 | end;
|
---|
627 | PixelPtr.NextLine;
|
---|
628 | end;
|
---|
629 | Dst.EndUpdate;
|
---|
630 | end;
|
---|
631 |
|
---|
632 | procedure ImageOp_B(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer);
|
---|
633 | // Src is template
|
---|
634 | // X channel = background amp (old Dst content), 128=original brightness
|
---|
635 | var
|
---|
636 | X, Y: Integer;
|
---|
637 | Brightness, Test: Integer;
|
---|
638 | PixelSrc: TPixelPointer;
|
---|
639 | PixelDst: TPixelPointer;
|
---|
640 | begin
|
---|
641 | xDst := ScaleToNative(xDst);
|
---|
642 | yDst := ScaleToNative(yDst);
|
---|
643 | xSrc := ScaleToNative(xSrc);
|
---|
644 | ySrc := ScaleToNative(ySrc);
|
---|
645 | Width := ScaleToNative(Width);
|
---|
646 | Height := ScaleToNative(Height);
|
---|
647 | //Assert(Src.PixelFormat = pf8bit);
|
---|
648 | Assert(Dst.PixelFormat = TPixelFormat.pf24bit);
|
---|
649 | if xDst < 0 then begin
|
---|
650 | Width := Width + xDst;
|
---|
651 | xSrc := xSrc - xDst;
|
---|
652 | xDst := 0;
|
---|
653 | end;
|
---|
654 | if yDst < 0 then begin
|
---|
655 | Height := Height + yDst;
|
---|
656 | ySrc := ySrc - yDst;
|
---|
657 | yDst := 0;
|
---|
658 | end;
|
---|
659 | if xDst + Width > ScaleToNative(Dst.Width) then
|
---|
660 | Width := ScaleToNative(Dst.Width) - xDst;
|
---|
661 | if yDst + Height > ScaleToNative(Dst.Height) then
|
---|
662 | Height := ScaleToNative(Dst.Height) - yDst;
|
---|
663 | if (Width < 0) or (Height < 0) then
|
---|
664 | Exit;
|
---|
665 |
|
---|
666 | Dst.BeginUpdate;
|
---|
667 | Src.BeginUpdate;
|
---|
668 | PixelDst := TPixelPointer.Create(Dst, xDst, yDst);
|
---|
669 | PixelSrc := TPixelPointer.Create(Src, xSrc, ySrc);
|
---|
670 | for Y := 0 to Height - 1 do begin
|
---|
671 | for X := 0 to Width - 1 do begin
|
---|
672 | Brightness := PixelSrc.PixelB; // One byte for 8-bit color
|
---|
673 | Test := (PixelDst.PixelR * Brightness) shr 7;
|
---|
674 | if Test >= 256 then
|
---|
675 | PixelDst.PixelR := 255
|
---|
676 | else
|
---|
677 | PixelDst.PixelR := Test; // Red
|
---|
678 | Test := (PixelDst.PixelG * Brightness) shr 7;
|
---|
679 | if Test >= 256 then
|
---|
680 | PixelDst.PixelG := 255
|
---|
681 | else
|
---|
682 | PixelDst.PixelG := Test; // Green
|
---|
683 | Test := (PixelDst.PixelB * Brightness) shr 7;
|
---|
684 | if Test >= 256 then
|
---|
685 | PixelDst.PixelR := 255
|
---|
686 | else
|
---|
687 | PixelDst.PixelB := Test; // Blue
|
---|
688 | PixelDst.NextPixel;
|
---|
689 | PixelSrc.NextPixel;
|
---|
690 | end;
|
---|
691 | PixelDst.NextLine;
|
---|
692 | PixelSrc.NextLine;
|
---|
693 | end;
|
---|
694 | Src.EndUpdate;
|
---|
695 | Dst.EndUpdate;
|
---|
696 | end;
|
---|
697 |
|
---|
698 | procedure ImageOp_BCC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
|
---|
699 | Color1, Color2: Integer);
|
---|
700 | // Src is template
|
---|
701 | // B channel = background amp (old Dst content), 128=original brightness
|
---|
702 | // G channel = Color1 amp, 128=original brightness
|
---|
703 | // R channel = Color2 amp, 128=original brightness
|
---|
704 | var
|
---|
705 | ix, iy, amp1, amp2, trans, Value: Integer;
|
---|
706 | SrcPixel: TPixelPointer;
|
---|
707 | DstPixel: TPixelPointer;
|
---|
708 | DstWidth, DstHeight: Integer;
|
---|
709 | SrcWidth, SrcHeight: Integer;
|
---|
710 | begin
|
---|
711 | if xDst < 0 then begin
|
---|
712 | Width := Width + xDst;
|
---|
713 | xSrc := xSrc - xDst;
|
---|
714 | xDst := 0;
|
---|
715 | end;
|
---|
716 | if yDst < 0 then begin
|
---|
717 | Height := Height + yDst;
|
---|
718 | ySrc := ySrc - yDst;
|
---|
719 | yDst := 0;
|
---|
720 | end;
|
---|
721 | if xDst + Width > Dst.Width then
|
---|
722 | Width := Dst.Width - xDst;
|
---|
723 | if yDst + Height > Dst.Height then
|
---|
724 | Height := Dst.Height - yDst;
|
---|
725 | if (Width < 0) or (Height < 0) then
|
---|
726 | Exit;
|
---|
727 | DstWidth := ScaleToNativeDist(xDst, Width);
|
---|
728 | DstHeight := ScaleToNativeDist(yDst, Height);
|
---|
729 | SrcWidth := ScaleToNativeDist(xSrc, Width);
|
---|
730 | SrcHeight := ScaleToNativeDist(ySrc, Height);
|
---|
731 | xDst := ScaleToNative(xDst);
|
---|
732 | yDst := ScaleToNative(yDst);
|
---|
733 | xSrc := ScaleToNative(xSrc);
|
---|
734 | ySrc := ScaleToNative(ySrc);
|
---|
735 |
|
---|
736 | Src.BeginUpdate;
|
---|
737 | Dst.BeginUpdate;
|
---|
738 | SrcPixel := TPixelPointer.Create(Src, xSrc, ySrc);
|
---|
739 | DstPixel := TPixelPointer.Create(Dst, xDst, yDst);
|
---|
740 | for iy := 0 to DstHeight - 1 do begin
|
---|
741 | for ix := 0 to DstWidth - 1 do begin
|
---|
742 | trans := SrcPixel.PixelB * 2; // green channel = transparency
|
---|
743 | amp1 := SrcPixel.PixelG * 2;
|
---|
744 | amp2 := SrcPixel.PixelR * 2;
|
---|
745 | if trans <> $FF then begin
|
---|
746 | Value := (DstPixel.PixelB * trans + ((Color2 shr 16) and $FF) *
|
---|
747 | amp2 + ((Color1 shr 16) and $FF) * amp1) div $FF;
|
---|
748 | DstPixel.PixelB := Min(Value, 255);
|
---|
749 |
|
---|
750 | Value := (DstPixel.PixelG * trans + ((Color2 shr 8) and $FF) *
|
---|
751 | amp2 + ((Color1 shr 8) and $FF) * amp1) div $FF;
|
---|
752 | DstPixel.PixelG := Min(Value, 255);
|
---|
753 |
|
---|
754 | Value := (DstPixel.PixelR * trans + (Color2 and $FF) *
|
---|
755 | amp2 + (Color1 and $FF) * amp1) div $FF;
|
---|
756 | DstPixel.PixelR := Min(Value, 255);
|
---|
757 | end;
|
---|
758 |
|
---|
759 | if ix < SrcWidth - 1 then SrcPixel.NextPixel;
|
---|
760 | DstPixel.NextPixel;
|
---|
761 | end;
|
---|
762 | if iy < SrcHeight - 1 then SrcPixel.NextLine
|
---|
763 | else SrcPixel.SetX(0);
|
---|
764 | DstPixel.NextLine;
|
---|
765 | end;
|
---|
766 | Src.EndUpdate;
|
---|
767 | Dst.EndUpdate;
|
---|
768 | end;
|
---|
769 |
|
---|
770 | procedure ImageOp_BCC(Dst, Src: TBitmap; DstPos: TPoint; SrcRect: TRect;
|
---|
771 | Color1, Color2: Integer);
|
---|
772 | begin
|
---|
773 | ImageOp_BCC(Dst, Src, DstPos.X, DstPos.Y, SrcRect.Left, SrcRect.Top,
|
---|
774 | SrcRect.Width, SrcRect.Height, Color1, Color2);
|
---|
775 | end;
|
---|
776 |
|
---|
777 | procedure ImageOp_CBC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
|
---|
778 | Color0, Color2: Integer);
|
---|
779 | // Src is template
|
---|
780 | // B channel = Color0 amp
|
---|
781 | // G channel = background amp (old Dst content), 128=original brightness
|
---|
782 | // R channel = Color2 amp
|
---|
783 | var
|
---|
784 | ix, iy, amp0, amp1, trans, Value: Integer;
|
---|
785 | SrcPixel: TPixelPointer;
|
---|
786 | DstPixel: TPixelPointer;
|
---|
787 | begin
|
---|
788 | xDst := ScaleToNative(xDst);
|
---|
789 | yDst := ScaleToNative(yDst);
|
---|
790 | xSrc := ScaleToNative(xSrc);
|
---|
791 | ySrc := ScaleToNative(ySrc);
|
---|
792 | Width := ScaleToNative(Width);
|
---|
793 | Height := ScaleToNative(Height);
|
---|
794 | Src.BeginUpdate;
|
---|
795 | Dst.BeginUpdate;
|
---|
796 | SrcPixel := TPixelPointer.Create(Src, xSrc, ySrc);
|
---|
797 | DstPixel := TPixelPointer.Create(Dst, xDst, yDst);
|
---|
798 | for iy := 0 to Height - 1 do begin
|
---|
799 | for ix := 0 to Width - 1 do begin
|
---|
800 | trans := SrcPixel.PixelB * 2; // green channel = transparency
|
---|
801 | amp0 := SrcPixel.PixelG * 2;
|
---|
802 | amp1 := SrcPixel.PixelR * 2;
|
---|
803 | if trans <> $FF then begin
|
---|
804 | Value := (DstPixel.PixelB * trans + (Color2 shr 16 and $FF) * amp1 +
|
---|
805 | (Color0 shr 16 and $FF) * amp0) div $FF;
|
---|
806 | DstPixel.PixelB := Min(Value, 255);
|
---|
807 |
|
---|
808 | Value := (DstPixel.PixelG * trans + (Color2 shr 8 and $FF) * amp1 +
|
---|
809 | (Color0 shr 8 and $FF) * amp0) div $FF;
|
---|
810 | DstPixel.PixelG := Min(Value, 255);
|
---|
811 |
|
---|
812 | Value := (DstPixel.PixelR * trans + (Color2 and $FF) * amp1 +
|
---|
813 | (Color0 and $FF) * amp0) div $FF;
|
---|
814 | DstPixel.PixelR := Min(Value, 255);
|
---|
815 | end;
|
---|
816 | SrcPixel.NextPixel;
|
---|
817 | DstPixel.NextPixel;
|
---|
818 | end;
|
---|
819 | SrcPixel.NextLine;
|
---|
820 | DstPixel.NextLine;
|
---|
821 | end;
|
---|
822 | Src.EndUpdate;
|
---|
823 | Dst.EndUpdate;
|
---|
824 | end;
|
---|
825 |
|
---|
826 | procedure ImageOp_CCC(Bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
|
---|
827 | // Bmp is template
|
---|
828 | // B channel = Color0 amp, 128=original brightness
|
---|
829 | // G channel = Color1 amp, 128=original brightness
|
---|
830 | // R channel = Color2 amp, 128=original brightness
|
---|
831 | var
|
---|
832 | XX, YY: Integer;
|
---|
833 | Red, Green: Integer;
|
---|
834 | PixelPtr: TPixelPointer;
|
---|
835 | begin
|
---|
836 | X := ScaleToNative(X);
|
---|
837 | Y := ScaleToNative(Y);
|
---|
838 | Width := ScaleToNativeDist(X, Width);
|
---|
839 | Height := ScaleToNativeDist(Y, Height);
|
---|
840 |
|
---|
841 | if X + Width > ScaleToNative(Bmp.Width) then
|
---|
842 | Width := ScaleToNative(Bmp.Width) - X;
|
---|
843 | if Y + Height > ScaleToNative(Bmp.Height) then
|
---|
844 | Height := ScaleToNative(Bmp.Height) - Y;
|
---|
845 | if (Width < 0) or (Height < 0) then
|
---|
846 | Exit;
|
---|
847 |
|
---|
848 | Bmp.BeginUpdate;
|
---|
849 | Assert(Bmp.PixelFormat = TPixelFormat.pf24bit);
|
---|
850 | PixelPtr := TPixelPointer.Create(Bmp, X, Y);
|
---|
851 | for YY := 0 to Height - 1 do begin
|
---|
852 | for XX := 0 to Width - 1 do begin
|
---|
853 | Red := ((PixelPtr.PixelB * (Color0 and $0000FF) + PixelPtr.PixelG *
|
---|
854 | (Color1 and $0000FF) + PixelPtr.PixelR * (Color2 and $0000FF)) shr 8) and $ff;
|
---|
855 | Green := ((PixelPtr.PixelB * ((Color0 shr 8) and $0000FF) +
|
---|
856 | PixelPtr.PixelG * ((Color1 shr 8) and $0000FF) + PixelPtr.PixelR *
|
---|
857 | ((Color2 shr 8) and $0000FF)) shr 8) and $ff;
|
---|
858 | PixelPtr.PixelB := ((PixelPtr.PixelB * ((Color0 shr 16) and $0000FF) +
|
---|
859 | PixelPtr.PixelG * ((Color1 shr 16) and $0000FF) + PixelPtr.PixelR *
|
---|
860 | ((Color2 shr 16) and $0000FF)) shr 8) and $ff; // Blue
|
---|
861 | PixelPtr.PixelG := Green;
|
---|
862 | PixelPtr.PixelR := Red;
|
---|
863 | PixelPtr.NextPixel;
|
---|
864 | end;
|
---|
865 | PixelPtr.NextLine;
|
---|
866 | end;
|
---|
867 | Bmp.EndUpdate;
|
---|
868 | end;
|
---|
869 |
|
---|
870 | procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
|
---|
871 | begin
|
---|
872 | BitBltCanvas(Canvas, xDst, yDst, Width, Height, HGr.Mask.Canvas, xGr, yGr, SRCAND);
|
---|
873 | BitBltCanvas(Canvas, xDst, yDst, Width, Height, HGr.Data.Canvas, xGr, yGr, SRCPAINT);
|
---|
874 | end;
|
---|
875 |
|
---|
876 | procedure Sprite(Canvas: TCanvas; xDst, yDst: Integer; GraphicSetItem: TGraphicSetItem);
|
---|
877 | begin
|
---|
878 | Sprite(Canvas, GraphicSetItem.GraphicSet, xDst, yDst, GraphicSetItem.Width,
|
---|
879 | GraphicSetItem.Height, GraphicSetItem.Left, GraphicSetItem.Top);
|
---|
880 | end;
|
---|
881 |
|
---|
882 | procedure Sprite(Dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
|
---|
883 | begin
|
---|
884 | Sprite(Dst.Canvas, HGr, xDst, yDst, Width, Height, xGr, yGr);
|
---|
885 | end;
|
---|
886 |
|
---|
887 | function BitBltCanvas(DestCanvas: TCanvas; X, Y, Width, Height: Integer;
|
---|
888 | SrcCanvas: TCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean;
|
---|
889 | begin
|
---|
890 | {$IFDEF WINDOWS}
|
---|
891 | {$IFDEF DPI}
|
---|
892 | Result := BitBlt(DestCanvas.Handle, X, Y, Width, Height, SrcCanvas.Handle, XSrc, YSrc, Rop);
|
---|
893 | {$ELSE}
|
---|
894 | // LCLIntf.BitBlt is slower than direct Windows BitBlt
|
---|
895 | Result := Windows.BitBlt(DestCanvas.Handle, ScaleToNative(X), ScaleToNative(Y),
|
---|
896 | ScaleToNative(Width), ScaleToNative(Height), SrcCanvas.Handle,
|
---|
897 | ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
|
---|
898 | {$ENDIF}
|
---|
899 | {$ELSE}
|
---|
900 | Result := BitBlt(DestCanvas.Handle, X, Y, Width, Height, SrcCanvas.Handle, XSrc, YSrc, Rop);
|
---|
901 | {$ENDIF}
|
---|
902 | end;
|
---|
903 |
|
---|
904 | function BitBltCanvas(Dest: TCanvas; DestRect: TRect; Src: TCanvas;
|
---|
905 | SrcPos: TPoint; Rop: DWORD): Boolean;
|
---|
906 | begin
|
---|
907 | Result := BitBltCanvas(Dest, DestRect.Left, DestRect.Top, DestRect.Width, DestRect.Height,
|
---|
908 | Src, SrcPos.X, SrcPos.Y, Rop);
|
---|
909 | end;
|
---|
910 |
|
---|
911 | function BitBltBitmap(Dest: TBitmap; X, Y, Width, Height: Integer;
|
---|
912 | Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD): Boolean;
|
---|
913 | begin
|
---|
914 | Result := BitBltCanvas(Dest.Canvas, X, Y, Width, Height, Src.Canvas, XSrc, YSrc, Rop);
|
---|
915 | end;
|
---|
916 |
|
---|
917 | function BitBltBitmap(Dest: TBitmap; DestRect: TRect; Src: TBitmap;
|
---|
918 | SrcPos: TPoint; Rop: DWORD): Boolean;
|
---|
919 | begin
|
---|
920 | Result := BitBltCanvas(Dest.Canvas, DestRect, Src.Canvas, SrcPos, Rop);
|
---|
921 | end;
|
---|
922 |
|
---|
923 | procedure SLine(Canvas: TCanvas; x0, x1, Y: Integer; cl: TColor);
|
---|
924 | begin
|
---|
925 | with Canvas do begin
|
---|
926 | Pen.Color := cl;
|
---|
927 | MoveTo(x0, Y);
|
---|
928 | LineTo(x1 + 1, Y);
|
---|
929 | end;
|
---|
930 | end;
|
---|
931 |
|
---|
932 | procedure DLine(Canvas: TCanvas; x0, x1, Y: Integer; cl0, cl1: TColor);
|
---|
933 | begin
|
---|
934 | with Canvas do begin
|
---|
935 | Pen.Color := cl0;
|
---|
936 | MoveTo(x0, Y);
|
---|
937 | LineTo(x1, Y);
|
---|
938 | Pen.Color := cl1;
|
---|
939 | MoveTo(x0 + 1, Y + 1);
|
---|
940 | LineTo(x1 + 1, Y + 1);
|
---|
941 | Pixels[x0, Y + 1] := cl0;
|
---|
942 | Pixels[x1, Y] := cl1;
|
---|
943 | end;
|
---|
944 | end;
|
---|
945 |
|
---|
946 | procedure Frame(Canvas: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
|
---|
947 | begin
|
---|
948 | with Canvas do begin
|
---|
949 | MoveTo(x0, y1);
|
---|
950 | Pen.Color := cl0;
|
---|
951 | LineTo(x0, y0);
|
---|
952 | LineTo(x1, y0);
|
---|
953 | Pen.Color := cl1;
|
---|
954 | LineTo(x1, y1);
|
---|
955 | LineTo(x0, y1);
|
---|
956 | end;
|
---|
957 | end;
|
---|
958 |
|
---|
959 | procedure RFrame(Canvas: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
|
---|
960 | begin
|
---|
961 | with Canvas do begin
|
---|
962 | Pen.Color := cl0;
|
---|
963 | MoveTo(x0, y0 + 1);
|
---|
964 | LineTo(x0, y1);
|
---|
965 | MoveTo(x0 + 1, y0);
|
---|
966 | LineTo(x1, y0);
|
---|
967 | Pen.Color := cl1;
|
---|
968 | MoveTo(x1, y0 + 1);
|
---|
969 | LineTo(x1, y1);
|
---|
970 | MoveTo(x0 + 1, y1);
|
---|
971 | LineTo(x1, y1);
|
---|
972 | end;
|
---|
973 | end;
|
---|
974 |
|
---|
975 | procedure CFrame(Canvas: TCanvas; x0, y0, x1, y1, Corner: Integer; cl: TColor);
|
---|
976 | begin
|
---|
977 | with Canvas do begin
|
---|
978 | Pen.Color := cl;
|
---|
979 | MoveTo(x0, y0 + Corner - 1);
|
---|
980 | LineTo(x0, y0);
|
---|
981 | LineTo(x0 + Corner, y0);
|
---|
982 | MoveTo(x1, y0 + Corner - 1);
|
---|
983 | LineTo(x1, y0);
|
---|
984 | LineTo(x1 - Corner, y0);
|
---|
985 | MoveTo(x1, y1 - Corner + 1);
|
---|
986 | LineTo(x1, y1);
|
---|
987 | LineTo(x1 - Corner, y1);
|
---|
988 | MoveTo(x0, y1 - Corner + 1);
|
---|
989 | LineTo(x0, y1);
|
---|
990 | LineTo(x0 + Corner, y1);
|
---|
991 | end;
|
---|
992 | end;
|
---|
993 |
|
---|
994 | procedure FrameImage(Canvas: TCanvas; Src: TBitmap;
|
---|
995 | X, Y, Width, Height, xSrc, ySrc: Integer; IsControl: Boolean = False);
|
---|
996 | begin
|
---|
997 | if IsControl then begin
|
---|
998 | Frame(Canvas, X - 1, Y - 1, X + Width, Y + Height, $B0B0B0, $FFFFFF);
|
---|
999 | RFrame(Canvas, X - 2, Y - 2, X + Width + 1, Y + Height + 1, $FFFFFF, $B0B0B0);
|
---|
1000 | end else
|
---|
1001 | Frame(Canvas, X - 1, Y - 1, X + Width, Y + Height, $000000, $000000);
|
---|
1002 | BitBltCanvas(Canvas, X, Y, Width, Height, Src.Canvas, xSrc, ySrc);
|
---|
1003 | end;
|
---|
1004 |
|
---|
1005 | procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: Integer; cl: TColor);
|
---|
1006 | var
|
---|
1007 | X, Y, ch, R: Integer;
|
---|
1008 | DstPtr: TPixelPointer;
|
---|
1009 | DpiGlowRange: Integer;
|
---|
1010 | begin
|
---|
1011 | DpiGlowRange := ScaleToNative(GlowRange);
|
---|
1012 | X0 := ScaleToNative(X0);
|
---|
1013 | Y0 := ScaleToNative(Y0);
|
---|
1014 | Width := ScaleToNative(Width);
|
---|
1015 | Height := ScaleToNative(Height);
|
---|
1016 | Dst.BeginUpdate;
|
---|
1017 | DstPtr := TPixelPointer.Create(Dst, x0 - DpiGlowRange + 1, y0 - DpiGlowRange + 1);
|
---|
1018 | for Y := -DpiGlowRange + 1 to Height - 1 + DpiGlowRange - 1 do begin
|
---|
1019 | for X := -DpiGlowRange + 1 to Width - 1 + DpiGlowRange - 1 do begin
|
---|
1020 | if X < 0 then
|
---|
1021 | if Y < 0 then
|
---|
1022 | R := Round(Sqrt(Sqr(X) + Sqr(Y)))
|
---|
1023 | else if Y >= Height then
|
---|
1024 | R := Round(Sqrt(Sqr(X) + Sqr(Y - (Height - 1))))
|
---|
1025 | else
|
---|
1026 | R := -X
|
---|
1027 | else if X >= Width then
|
---|
1028 | if Y < 0 then
|
---|
1029 | R := Round(sqrt(Sqr(X - (Width - 1)) + Sqr(Y)))
|
---|
1030 | else if Y >= Height then
|
---|
1031 | R := Round(Sqrt(Sqr(X - (Width - 1)) + Sqr(Y - (Height - 1))))
|
---|
1032 | else
|
---|
1033 | R := X - (Width - 1)
|
---|
1034 | else if Y < 0 then
|
---|
1035 | R := -Y
|
---|
1036 | else if Y >= Height then
|
---|
1037 | R := Y - (Height - 1)
|
---|
1038 | else begin
|
---|
1039 | DstPtr.NextPixel;
|
---|
1040 | Continue;
|
---|
1041 | end;
|
---|
1042 | if R = 0 then
|
---|
1043 | R := 1;
|
---|
1044 | if R < DpiGlowRange then
|
---|
1045 | for ch := 0 to 2 do
|
---|
1046 | DstPtr.PixelPlane[2 - ch] :=
|
---|
1047 | (DstPtr.PixelPlane[2 - ch] * (R - 1) + (cl shr (8 * ch) and $FF) *
|
---|
1048 | (DpiGlowRange - R)) div (DpiGlowRange - 1);
|
---|
1049 | DstPtr.NextPixel;
|
---|
1050 | end;
|
---|
1051 | DstPtr.NextLine;
|
---|
1052 | end;
|
---|
1053 | Dst.EndUpdate;
|
---|
1054 | end;
|
---|
1055 |
|
---|
1056 | procedure InitOrnament;
|
---|
1057 | var
|
---|
1058 | P: TColor;
|
---|
1059 | X, Y: Integer;
|
---|
1060 | Light, Shade: TColor32;
|
---|
1061 | PixelPtr: TPixelPointer;
|
---|
1062 | begin
|
---|
1063 | if InitOrnamentDone then Exit;
|
---|
1064 | Light := ColorToColor32(MainTexture.ColorBevelLight);
|
---|
1065 | // and $FCFCFC shr 2*3+MainTexture.ColorBevelShade and $FCFCFC shr 2;
|
---|
1066 | Shade := ColorToColor32(MainTexture.ColorBevelShade and $FCFCFC shr 2 * 3 +
|
---|
1067 | MainTexture.ColorBevelLight and $FCFCFC shr 2);
|
---|
1068 | HGrSystem2.Data.BeginUpdate;
|
---|
1069 | PixelPtr := TPixelPointer.Create(HGrSystem2.Data, ScaleToNative(Ornament.Left),
|
---|
1070 | ScaleToNative(Ornament.Top));
|
---|
1071 | if PixelPtr.BytesPerPixel = 3 then begin
|
---|
1072 | for Y := 0 to ScaleToNative(Ornament.Height) - 1 do begin
|
---|
1073 | for X := 0 to ScaleToNative(Ornament.Width) - 1 do begin
|
---|
1074 | P := Color32ToColor(PixelPtr.PixelRGB);
|
---|
1075 | if P = $0000FF then PixelPtr.PixelRGB := Light
|
---|
1076 | else if P = $FF0000 then PixelPtr.PixelRGB := Shade;
|
---|
1077 | PixelPtr.NextPixel;
|
---|
1078 | end;
|
---|
1079 | PixelPtr.NextLine;
|
---|
1080 | end;
|
---|
1081 | end else begin
|
---|
1082 | for Y := 0 to ScaleToNative(Ornament.Height) - 1 do begin
|
---|
1083 | for X := 0 to ScaleToNative(Ornament.Width) - 1 do begin
|
---|
1084 | P := Color32ToColor(PixelPtr.PixelARGB);
|
---|
1085 | if P = $0000FF then PixelPtr.PixelARGB := Light
|
---|
1086 | else if P = $FF0000 then PixelPtr.PixelARGB := Shade;
|
---|
1087 | PixelPtr.NextPixel;
|
---|
1088 | end;
|
---|
1089 | PixelPtr.NextLine;
|
---|
1090 | end;
|
---|
1091 | end;
|
---|
1092 | InitOrnamentDone := True;
|
---|
1093 | HGrSystem2.Data.EndUpdate;
|
---|
1094 | end;
|
---|
1095 |
|
---|
1096 | procedure InitCityMark(Texture: TTexture);
|
---|
1097 | var
|
---|
1098 | X: Integer;
|
---|
1099 | Y: Integer;
|
---|
1100 | Intensity: Integer;
|
---|
1101 | begin
|
---|
1102 | for X := 0 to CityMark1.Width - 1 do begin
|
---|
1103 | for Y := 0 to CityMark1.Height - 1 do begin
|
---|
1104 | if HGrSystem.Mask.Canvas.Pixels[CityMark1.Left + X, CityMark1.Top + Y] = 0 then
|
---|
1105 | begin
|
---|
1106 | Intensity := HGrSystem.Data.Canvas.Pixels[CityMark1.Left +
|
---|
1107 | X, CityMark1.Top + Y] and $FF;
|
---|
1108 | HGrSystem.Data.Canvas.Pixels[CityMark2.Left + X, CityMark2.Top + Y] :=
|
---|
1109 | Texture.ColorMark and $FF * Intensity div $FF + Texture.ColorMark shr 8 and
|
---|
1110 | $FF * Intensity div $FF shl 8 + Texture.ColorMark shr 16 and
|
---|
1111 | $FF * Intensity div $FF shl 16;
|
---|
1112 | end;
|
---|
1113 | end;
|
---|
1114 | end;
|
---|
1115 | BitBltBitmap(HGrSystem.Mask, CityMark2.Left, CityMark2.Top, CityMark1.Width,
|
---|
1116 | CityMark1.Width, HGrSystem.Mask, CityMark1.Left, CityMark1.Top);
|
---|
1117 | end;
|
---|
1118 |
|
---|
1119 | procedure Fill(Canvas: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer);
|
---|
1120 | begin
|
---|
1121 | //Assert((Left + xOffset >= 0) and (Left + xOffset + Width <= MainTexture.Width) and
|
---|
1122 | // (Top + yOffset >= 0) and (Top + yOffset + Height <= MainTexture.Height));
|
---|
1123 | BitBltCanvas(Canvas, Left, Top, Width, Height, MainTexture.Image.Canvas,
|
---|
1124 | Left + xOffset, Top + yOffset);
|
---|
1125 | end;
|
---|
1126 |
|
---|
1127 | procedure Fill(Canvas: TCanvas; Rect: TRect; Offset: TPoint);
|
---|
1128 | begin
|
---|
1129 | Fill(Canvas, Rect.Left, Rect.Top, Rect.Width, Rect.Height, Offset.X, Offset.Y);
|
---|
1130 | end;
|
---|
1131 |
|
---|
1132 | procedure FillLarge(Canvas: TCanvas; x0, y0, x1, y1, xm: Integer);
|
---|
1133 |
|
---|
1134 | function Band(I: Integer): Integer;
|
---|
1135 | var
|
---|
1136 | N: Integer;
|
---|
1137 | begin
|
---|
1138 | N := ((MainTexture.Height div 2) div (y1 - y0)) * 2;
|
---|
1139 | while MainTexture.Height div 2 + (I + 1) * (y1 - y0) > MainTexture.Height do
|
---|
1140 | Dec(I, N);
|
---|
1141 | while MainTexture.Height div 2 + I * (y1 - y0) < 0 do
|
---|
1142 | Inc(I, N);
|
---|
1143 | Result := I;
|
---|
1144 | end;
|
---|
1145 |
|
---|
1146 | var
|
---|
1147 | I: Integer;
|
---|
1148 | begin
|
---|
1149 | for I := 0 to (x1 - xm) div MainTexture.Width - 1 do
|
---|
1150 | BitBltCanvas(Canvas, xm + I * MainTexture.Width, y0, MainTexture.Width, y1 - y0,
|
---|
1151 | MainTexture.Image.Canvas, 0, MainTexture.Height div 2 + Band(I) *
|
---|
1152 | (y1 - y0));
|
---|
1153 | BitBltCanvas(Canvas, xm + ((x1 - xm) div MainTexture.Width) * MainTexture.Width, y0,
|
---|
1154 | x1 - (xm + ((x1 - xm) div MainTexture.Width) * MainTexture.Width), y1 - y0,
|
---|
1155 | MainTexture.Image.Canvas, 0, MainTexture.Height div 2 + Band(
|
---|
1156 | (x1 - xm) div MainTexture.Width) * (y1 - y0));
|
---|
1157 | for I := 0 to (xm - x0) div MainTexture.Width - 1 do
|
---|
1158 | BitBltCanvas(Canvas, xm - (I + 1) * MainTexture.Width, y0, MainTexture.Width, y1 - y0,
|
---|
1159 | MainTexture.Image.Canvas, 0, MainTexture.Height div 2 +
|
---|
1160 | Band(-I - 1) * (y1 - y0));
|
---|
1161 | BitBltCanvas(Canvas, x0, y0, xm - ((xm - x0) div MainTexture.Width) *
|
---|
1162 | MainTexture.Width - x0, y1 - y0, MainTexture.Image.Canvas,
|
---|
1163 | ((xm - x0) div MainTexture.Width + 1) * MainTexture.Width - (xm - x0),
|
---|
1164 | MainTexture.Height div 2 + Band(-(xm - x0) div MainTexture.Width - 1) * (y1 - y0));
|
---|
1165 | end;
|
---|
1166 |
|
---|
1167 | procedure FillSeamless(Canvas: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer;
|
---|
1168 | const Texture: TBitmap);
|
---|
1169 | var
|
---|
1170 | X, Y, x0cut, y0cut, x1cut, y1cut: Integer;
|
---|
1171 | begin
|
---|
1172 | while xOffset < 0 do
|
---|
1173 | Inc(xOffset, Texture.Width);
|
---|
1174 | while yOffset < 0 do
|
---|
1175 | Inc(yOffset, Texture.Height);
|
---|
1176 | for Y := (Top + yOffset) div Texture.Height to (Top + yOffset + Height - 1) div
|
---|
1177 | Texture.Height do
|
---|
1178 | begin
|
---|
1179 | y0cut := Top + yOffset - Y * Texture.Height;
|
---|
1180 | if y0cut < 0 then
|
---|
1181 | y0cut := 0;
|
---|
1182 | y1cut := (Y + 1) * Texture.Height - (Top + yOffset + Height);
|
---|
1183 | if y1cut < 0 then
|
---|
1184 | y1cut := 0;
|
---|
1185 | for X := (Left + xOffset) div Texture.Width to (Left + xOffset + Width - 1) div
|
---|
1186 | Texture.Width do
|
---|
1187 | begin
|
---|
1188 | x0cut := Left + xOffset - X * Texture.Width;
|
---|
1189 | if x0cut < 0 then
|
---|
1190 | x0cut := 0;
|
---|
1191 | x1cut := (X + 1) * Texture.Width - (Left + xOffset + Width);
|
---|
1192 | if x1cut < 0 then
|
---|
1193 | x1cut := 0;
|
---|
1194 | BitBltCanvas(Canvas, X * Texture.Width + x0cut - xOffset,
|
---|
1195 | Y * Texture.Height + y0cut - yOffset, Texture.Width - x0cut - x1cut,
|
---|
1196 | Texture.Height - y0cut - y1cut, Texture.Canvas, x0cut, y0cut);
|
---|
1197 | end;
|
---|
1198 | end;
|
---|
1199 | end;
|
---|
1200 |
|
---|
1201 | procedure FillRectSeamless(Canvas: TCanvas; x0, y0, x1, y1, xOffset, yOffset: Integer;
|
---|
1202 | const Texture: TBitmap);
|
---|
1203 | begin
|
---|
1204 | FillSeamless(Canvas, x0, y0, x1 - x0, y1 - y0, xOffset, yOffset, Texture);
|
---|
1205 | end;
|
---|
1206 |
|
---|
1207 | procedure PaintBackground(Canvas: TCanvas; Left, Top, Width, Height, FormWidth,
|
---|
1208 | FormHeight: Integer);
|
---|
1209 | begin
|
---|
1210 | Fill(Canvas, Left, Top, Width, Height, (MainTexture.Width - FormWidth) div
|
---|
1211 | 2, (MainTexture.Height - FormHeight) div 2);
|
---|
1212 | end;
|
---|
1213 |
|
---|
1214 | procedure Corner(Canvas: TCanvas; X, Y, Kind: Integer; T: TTexture);
|
---|
1215 | begin
|
---|
1216 | { BitBltCanvas(Canvas, x, y, 8, 8, T.HGr.Mask.Canvas,
|
---|
1217 | T.xGr + 29 + Kind * 9, T.yGr + 89, SRCAND);
|
---|
1218 | BitBltCanvas(Canvas, X, Y, 8, 8, T.HGr.Data.Canvas,
|
---|
1219 | T.xGr + 29 + Kind * 9, T.yGr + 89, SRCPAINT); }
|
---|
1220 | end;
|
---|
1221 |
|
---|
1222 | procedure BiColorTextOut(Canvas: TCanvas; clMain, clBack: TColor; X, Y: Integer; S: string);
|
---|
1223 |
|
---|
1224 | procedure PaintIcon(X, Y, Kind: Integer);
|
---|
1225 | begin
|
---|
1226 | Sprite(Canvas, HGrSystem, X, Y + 6, 10, 10,
|
---|
1227 | 66 + Kind mod 11 * 11, 115 + Kind div 11 * 11);
|
---|
1228 | end;
|
---|
1229 |
|
---|
1230 | var
|
---|
1231 | P, xp: Integer;
|
---|
1232 | sp: string;
|
---|
1233 | Shadow: Boolean;
|
---|
1234 | Text: string;
|
---|
1235 | begin
|
---|
1236 | Inc(X);
|
---|
1237 | Inc(Y);
|
---|
1238 | for Shadow := True downto False do
|
---|
1239 | with Canvas do
|
---|
1240 | if not Shadow or (clBack <> $7F007F) then
|
---|
1241 | begin
|
---|
1242 | if Shadow then
|
---|
1243 | Font.Color := clBack
|
---|
1244 | else
|
---|
1245 | Font.Color := clMain;
|
---|
1246 | sp := S;
|
---|
1247 | xp := X;
|
---|
1248 | repeat
|
---|
1249 | P := Pos('%', sp);
|
---|
1250 | if (P = 0) or (P + 1 > Length(sp)) or not
|
---|
1251 | (sp[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w']) then
|
---|
1252 | begin
|
---|
1253 | Canvas.TextOut(xp, Y, sp);
|
---|
1254 | Break;
|
---|
1255 | end
|
---|
1256 | else
|
---|
1257 | begin
|
---|
1258 | Text := Copy(sp, 1, P - 1);
|
---|
1259 | TextOut(xp, Y, Text);
|
---|
1260 | Inc(xp, Canvas.TextWidth(Text));
|
---|
1261 | if not Shadow then
|
---|
1262 | case sp[P + 1] of
|
---|
1263 | 'c': PaintIcon(xp + 1, Y, 6);
|
---|
1264 | 'f': PaintIcon(xp + 1, Y, 0);
|
---|
1265 | 'l': PaintIcon(xp + 1, Y, 8);
|
---|
1266 | 'm': PaintIcon(xp + 1, Y, 17);
|
---|
1267 | 'n': PaintIcon(xp + 1, Y, 7);
|
---|
1268 | 'o': PaintIcon(xp + 1, Y, 16);
|
---|
1269 | 'p': PaintIcon(xp + 1, Y, 2);
|
---|
1270 | 'r': PaintIcon(xp + 1, Y, 12);
|
---|
1271 | 't': PaintIcon(xp + 1, Y, 4);
|
---|
1272 | 'w': PaintIcon(xp + 1, Y, 13);
|
---|
1273 | end;
|
---|
1274 | Inc(xp, 10);
|
---|
1275 | Delete(sp, 1, P + 1);
|
---|
1276 | end;
|
---|
1277 | until False;
|
---|
1278 | Dec(X);
|
---|
1279 | Dec(Y);
|
---|
1280 | end;
|
---|
1281 | end;
|
---|
1282 |
|
---|
1283 | function BiColorTextWidth(Canvas: TCanvas; S: string): Integer;
|
---|
1284 | var
|
---|
1285 | P: Integer;
|
---|
1286 | begin
|
---|
1287 | Result := 1;
|
---|
1288 | repeat
|
---|
1289 | P := Pos('%', S);
|
---|
1290 | if (P = 0) or (P = Length(S)) then
|
---|
1291 | begin
|
---|
1292 | Inc(Result, Canvas.TextWidth(S));
|
---|
1293 | Break;
|
---|
1294 | end
|
---|
1295 | else
|
---|
1296 | begin
|
---|
1297 | if not (S[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w'])
|
---|
1298 | then
|
---|
1299 | Inc(Result, Canvas.TextWidth(Copy(S, 1, P + 1)))
|
---|
1300 | else
|
---|
1301 | Inc(Result, Canvas.TextWidth(Copy(S, 1, P - 1)) + 10);
|
---|
1302 | Delete(S, 1, P + 1);
|
---|
1303 | end;
|
---|
1304 | until False;
|
---|
1305 | end;
|
---|
1306 |
|
---|
1307 | procedure LoweredTextOut(Canvas: TCanvas; cl: TColor; T: TTexture;
|
---|
1308 | X, Y: Integer; S: string);
|
---|
1309 | begin
|
---|
1310 | if cl = -2 then
|
---|
1311 | BiColorTextOut(Canvas, (T.ColorBevelShade and $FEFEFE) shr 1,
|
---|
1312 | T.ColorBevelLight, X, Y, S)
|
---|
1313 | else if cl < 0 then
|
---|
1314 | BiColorTextOut(Canvas, T.ColorTextShade, T.ColorTextLight, X, Y, S)
|
---|
1315 | else
|
---|
1316 | BiColorTextOut(Canvas, cl, T.ColorTextLight, X, Y, S);
|
---|
1317 | end;
|
---|
1318 |
|
---|
1319 | procedure RisedTextOut(Canvas: TCanvas; X, Y: Integer; S: string);
|
---|
1320 | begin
|
---|
1321 | BiColorTextOut(Canvas, $FFFFFF, $000000, X, Y, S);
|
---|
1322 | end;
|
---|
1323 |
|
---|
1324 | procedure Gradient(Canvas: TCanvas; X, Y, dx, dy, Width, Height, Color: Integer;
|
---|
1325 | Brightness: array of Integer);
|
---|
1326 | var
|
---|
1327 | I, R, G, B: Integer;
|
---|
1328 | begin
|
---|
1329 | for I := 0 to Length(Brightness) - 1 do begin // gradient
|
---|
1330 | R := Color and $FF + Brightness[I];
|
---|
1331 | if R < 0 then
|
---|
1332 | R := 0
|
---|
1333 | else if R >= 256 then
|
---|
1334 | R := 255;
|
---|
1335 | G := Color shr 8 and $FF + Brightness[I];
|
---|
1336 | if G < 0 then
|
---|
1337 | G := 0
|
---|
1338 | else if G >= 256 then
|
---|
1339 | G := 255;
|
---|
1340 | B := Color shr 16 and $FF + Brightness[I];
|
---|
1341 | if B < 0 then
|
---|
1342 | B := 0
|
---|
1343 | else if B >= 256 then
|
---|
1344 | B := 255;
|
---|
1345 | Canvas.Pen.Color := R + G shl 8 + B shl 16;
|
---|
1346 | Canvas.MoveTo(X + dx * I, Y + dy * I);
|
---|
1347 | Canvas.LineTo(X + dx * I + Width, Y + dy * I + Height);
|
---|
1348 | end;
|
---|
1349 | Canvas.Pen.Color := $000000;
|
---|
1350 | Canvas.MoveTo(X + 1, Y + 16 * dy + Height);
|
---|
1351 | Canvas.LineTo(X + 16 * dx + Width, Y + 16 * dy + Height);
|
---|
1352 | Canvas.LineTo(X + 16 * dx + Width, Y);
|
---|
1353 | end;
|
---|
1354 |
|
---|
1355 | procedure LightGradient(Canvas: TCanvas; X, Y, Width, Color: Integer);
|
---|
1356 | const
|
---|
1357 | Brightness: array [0 .. 15] of Integer =
|
---|
1358 | (16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -44);
|
---|
1359 | begin
|
---|
1360 | Gradient(Canvas, X, Y, 0, 1, Width, 0, Color, Brightness);
|
---|
1361 | end;
|
---|
1362 |
|
---|
1363 | procedure DarkGradient(Canvas: TCanvas; X, Y, Width, Kind: Integer);
|
---|
1364 | const
|
---|
1365 | Brightness: array [0 .. 15] of Integer =
|
---|
1366 | (16, 12, 8, 4, 0, -4, -8, -12 - 24, -16 + 16, -20, -24, -28, -32, -36, -40, -44);
|
---|
1367 | begin
|
---|
1368 | Gradient(Canvas, X, Y, 0, 1, Width, 0, HGrSystem.Data.Canvas.Pixels
|
---|
1369 | [187, 137 + Kind], Brightness);
|
---|
1370 | end;
|
---|
1371 |
|
---|
1372 | procedure VLightGradient(Canvas: TCanvas; X, Y, Height, Color: Integer);
|
---|
1373 | const
|
---|
1374 | Brightness: array [0 .. 15] of Integer =
|
---|
1375 | (16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -44);
|
---|
1376 | begin
|
---|
1377 | Gradient(Canvas, X, Y, 1, 0, 0, Height, Color, Brightness);
|
---|
1378 | end;
|
---|
1379 |
|
---|
1380 | procedure VDarkGradient(Canvas: TCanvas; X, Y, Height, Kind: Integer);
|
---|
1381 | const
|
---|
1382 | Brightness: array [0 .. 15] of Integer =
|
---|
1383 | (16, 12, 8, 4, 0, -4, -8, -12 - 24, -16 + 16, -20, -24, -28, -32, -36, -40, -44);
|
---|
1384 | begin
|
---|
1385 | Gradient(Canvas, X, Y, 1, 0, 0, Height,
|
---|
1386 | HGrSystem.Data.Canvas.Pixels[187, 137 + Kind], Brightness);
|
---|
1387 | end;
|
---|
1388 |
|
---|
1389 | procedure UnderlinedTitleValue(Canvas: TCanvas; Title, Value: string; X, Y, Width: Integer);
|
---|
1390 | begin
|
---|
1391 | DLine(Canvas, X, X + Width, Y + 19, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
|
---|
1392 | RisedTextOut(Canvas, X, Y, Title);
|
---|
1393 | RisedTextOut(Canvas, X + Width - BiColorTextWidth(Canvas, Value), Y, Value);
|
---|
1394 | end;
|
---|
1395 |
|
---|
1396 | procedure NumberBar(Dst: TBitmap; X, Y: Integer; Cap: string;
|
---|
1397 | Val: Integer; T: TTexture);
|
---|
1398 | var
|
---|
1399 | S: string;
|
---|
1400 | begin
|
---|
1401 | if Val > 0 then
|
---|
1402 | begin
|
---|
1403 | DLine(Dst.Canvas, X - 2, X + 170, Y + 16, T.ColorBevelShade,
|
---|
1404 | T.ColorBevelLight);
|
---|
1405 | LoweredTextOut(Dst.Canvas, -1, T, X - 2, Y, Cap);
|
---|
1406 | S := IntToStr(Val);
|
---|
1407 | RisedTextOut(Dst.Canvas, X + 170 - BiColorTextWidth(Dst.Canvas,
|
---|
1408 | S), Y, S);
|
---|
1409 | end;
|
---|
1410 | end;
|
---|
1411 |
|
---|
1412 | procedure CountBar(Dst: TBitmap; X, Y, W: Integer; Kind: Integer;
|
---|
1413 | Cap: string; Val: Integer; T: TTexture);
|
---|
1414 | var
|
---|
1415 | I, sd, ld, cl, xIcon, yIcon: Integer;
|
---|
1416 | S: string;
|
---|
1417 | begin
|
---|
1418 | // Val := Random(40); //!!!
|
---|
1419 | if Val = 0 then
|
---|
1420 | Exit;
|
---|
1421 | Assert(Kind >= 0);
|
---|
1422 | with Dst.Canvas do
|
---|
1423 | begin
|
---|
1424 | // xIcon:=x+100;
|
---|
1425 | // yIcon:=y;
|
---|
1426 | // DLine(Dst.Canvas,x-2,x+170+32,y+16,T.ColorBevelShade,T.ColorBevelLight);
|
---|
1427 |
|
---|
1428 | xIcon := X - 5;
|
---|
1429 | yIcon := Y + 15;
|
---|
1430 | DLine(Dst.Canvas, X - 2, xIcon + W + 2, yIcon + 16, T.ColorBevelShade,
|
---|
1431 | T.ColorBevelLight);
|
---|
1432 |
|
---|
1433 | S := IntToStr(Val);
|
---|
1434 | if Val < 0 then
|
---|
1435 | cl := $0000FF
|
---|
1436 | else
|
---|
1437 | cl := -1;
|
---|
1438 | LoweredTextOut(Dst.Canvas, cl, T, X - 2, Y, Cap);
|
---|
1439 | LoweredTextOut(Dst.Canvas, cl, T,
|
---|
1440 | xIcon + W + 2 - BiColorTextWidth(Dst.Canvas, S), yIcon, S);
|
---|
1441 |
|
---|
1442 | if (Kind = 12) and (Val >= 100) then
|
---|
1443 | begin // science with symbol for 100
|
---|
1444 | Val := Val div 10;
|
---|
1445 | sd := 14 * (Val div 10 + Val mod 10 - 1);
|
---|
1446 | if sd = 0 then
|
---|
1447 | sd := 1;
|
---|
1448 | if sd < W - 44 then
|
---|
1449 | ld := sd
|
---|
1450 | else
|
---|
1451 | ld := W - 44;
|
---|
1452 | for I := 0 to Val mod 10 - 1 do
|
---|
1453 | begin
|
---|
1454 | BitBltBitmap(Dst, xIcon + 4 + I * (14 * ld div sd), yIcon + 2 + 1, 14,
|
---|
1455 | 14, HGrSystem.Mask, 67 + Kind mod 8 * 15,
|
---|
1456 | 70 + Kind div 8 * 15, SRCAND);
|
---|
1457 | Sprite(Dst, HGrSystem, xIcon + 3 + I * (14 * ld div sd), yIcon + 2,
|
---|
1458 | 14, 14, 67 + Kind mod 8 * 15, 70 + Kind div 8 * 15);
|
---|
1459 | end;
|
---|
1460 | for I := 0 to Val div 10 - 1 do
|
---|
1461 | begin
|
---|
1462 | BitBltBitmap(Dst, xIcon + 4 + (Val mod 10) *
|
---|
1463 | (14 * ld div sd) + I * (14 * ld div sd), yIcon + 3, 14, 14,
|
---|
1464 | HGrSystem.Mask, 67 + 7 mod 8 * 15,
|
---|
1465 | 70 + 7 div 8 * 15, SRCAND);
|
---|
1466 | Sprite(Dst, HGrSystem, xIcon + 3 + (Val mod 10) *
|
---|
1467 | (14 * ld div sd) + I * (14 * ld div sd), yIcon + 2, 14,
|
---|
1468 | 14, 67 + 7 mod 8 * 15,
|
---|
1469 | 70 + 7 div 8 * 15);
|
---|
1470 | end;
|
---|
1471 | end
|
---|
1472 | else
|
---|
1473 | begin
|
---|
1474 | Val := Abs(Val);
|
---|
1475 | if Val mod 10 = 0 then
|
---|
1476 | sd := 14 * (Val div 10 - 1)
|
---|
1477 | else
|
---|
1478 | sd := 10 * (Val mod 10 - 1) + 14 * (Val div 10);
|
---|
1479 | if sd = 0 then
|
---|
1480 | sd := 1;
|
---|
1481 | if sd < W - 44 then
|
---|
1482 | ld := sd
|
---|
1483 | else
|
---|
1484 | ld := W - 44;
|
---|
1485 | for I := 0 to Val div 10 - 1 do
|
---|
1486 | begin
|
---|
1487 | BitBltBitmap(Dst, xIcon + 4 + I * (14 * ld div sd), yIcon + 3, 14, 14,
|
---|
1488 | HGrSystem.Mask, 67 + Kind mod 8 * 15,
|
---|
1489 | 70 + Kind div 8 * 15, SRCAND);
|
---|
1490 | Sprite(Dst, HGrSystem, xIcon + 3 + I * (14 * ld div sd), yIcon + 2,
|
---|
1491 | 14, 14, 67 + Kind mod 8 * 15, 70 + Kind div 8 * 15);
|
---|
1492 | end;
|
---|
1493 | for I := 0 to Val mod 10 - 1 do
|
---|
1494 | begin
|
---|
1495 | BitBltBitmap(Dst, xIcon + 4 + (Val div 10) *
|
---|
1496 | (14 * ld div sd) + I * (10 * ld div sd), yIcon + 7, 10, 10,
|
---|
1497 | HGrSystem.Mask, 66 + Kind mod 11 * 11,
|
---|
1498 | 115 + Kind div 11 * 11, SRCAND);
|
---|
1499 | Sprite(Dst, HGrSystem, xIcon + 3 + (Val div 10) *
|
---|
1500 | (14 * ld div sd) + I * (10 * ld div sd), yIcon + 6, 10,
|
---|
1501 | 10, 66 + Kind mod 11 * 11,
|
---|
1502 | 115 + Kind div 11 * 11);
|
---|
1503 | end;
|
---|
1504 | end;
|
---|
1505 | end;
|
---|
1506 | end;
|
---|
1507 |
|
---|
1508 | procedure PaintProgressBar(Canvas: TCanvas; Kind, X, Y, Pos, Growth, Max: Integer;
|
---|
1509 | T: TTexture);
|
---|
1510 | var
|
---|
1511 | I: Integer;
|
---|
1512 | begin
|
---|
1513 | if Pos > Max then
|
---|
1514 | Pos := Max;
|
---|
1515 | if Growth < 0 then
|
---|
1516 | begin
|
---|
1517 | Pos := Pos + Growth;
|
---|
1518 | if Pos < 0 then
|
---|
1519 | begin
|
---|
1520 | Growth := Growth - Pos;
|
---|
1521 | Pos := 0;
|
---|
1522 | end;
|
---|
1523 | end
|
---|
1524 | else if Pos + Growth > Max then
|
---|
1525 | Growth := Max - Pos;
|
---|
1526 | Frame(Canvas, X - 1, Y - 1, X + Max, Y + 7, $000000, $000000);
|
---|
1527 | RFrame(Canvas, X - 2, Y - 2, X + Max + 1, Y + 8, T.ColorBevelShade,
|
---|
1528 | T.ColorBevelLight);
|
---|
1529 | with Canvas do
|
---|
1530 | begin
|
---|
1531 | for I := 0 to Pos div 8 - 1 do
|
---|
1532 | BitBltCanvas(Canvas, X + I * 8, Y, 8, 7,
|
---|
1533 | HGrSystem.Data.Canvas, 104, 9 + 8 * Kind);
|
---|
1534 | BitBltCanvas(Canvas, X + 8 * (Pos div 8), Y, Pos - 8 * (Pos div 8), 7,
|
---|
1535 | HGrSystem.Data.Canvas, 104, 9 + 8 * Kind);
|
---|
1536 | if Growth > 0 then
|
---|
1537 | begin
|
---|
1538 | for I := 0 to Growth div 8 - 1 do
|
---|
1539 | BitBltCanvas(Canvas, X + Pos + I * 8, Y, 8, 7,
|
---|
1540 | HGrSystem.Data.Canvas, 112, 9 + 8 * Kind);
|
---|
1541 | BitBltCanvas(Canvas, X + Pos + 8 * (Growth div 8), Y,
|
---|
1542 | Growth - 8 * (Growth div 8), 7, HGrSystem.Data.Canvas,
|
---|
1543 | 112, 9 + 8 * Kind);
|
---|
1544 | end
|
---|
1545 | else if Growth < 0 then
|
---|
1546 | begin
|
---|
1547 | for I := 0 to -Growth div 8 - 1 do
|
---|
1548 | BitBltCanvas(Canvas, X + Pos + I * 8, Y, 8, 7,
|
---|
1549 | HGrSystem.Data.Canvas, 104, 1);
|
---|
1550 | BitBltCanvas(Canvas, X + Pos + 8 * (-Growth div 8), Y, -Growth -
|
---|
1551 | 8 * (-Growth div 8), 7,
|
---|
1552 | HGrSystem.Data.Canvas, 104, 1);
|
---|
1553 | end;
|
---|
1554 | Brush.Color := $000000;
|
---|
1555 | FillRect(Rect(X + Pos + Abs(Growth), Y, X + Max, Y + 7));
|
---|
1556 | Brush.Style := TBrushStyle.bsClear;
|
---|
1557 | end;
|
---|
1558 | end;
|
---|
1559 |
|
---|
1560 | // pos and growth are relative to max, set size independent
|
---|
1561 | procedure PaintRelativeProgressBar(Canvas: TCanvas;
|
---|
1562 | Kind, X, Y, Size, Pos, Growth, Max: Integer; IndicateComplete: Boolean;
|
---|
1563 | T: TTexture);
|
---|
1564 | begin
|
---|
1565 | if Growth > 0 then
|
---|
1566 | PaintProgressBar(Canvas, Kind, X, Y, Pos * Size div Max,
|
---|
1567 | (Growth * Size + Max div 2) div Max, Size, T)
|
---|
1568 | else
|
---|
1569 | PaintProgressBar(Canvas, Kind, X, Y, Pos * Size div Max,
|
---|
1570 | (Growth * Size - Max div 2) div Max, Size, T);
|
---|
1571 | if IndicateComplete and (Pos + Growth >= Max) then
|
---|
1572 | Sprite(Canvas, HGrSystem, X + Size - 10, Y - 7, 23, 16, 1, 129);
|
---|
1573 | end;
|
---|
1574 |
|
---|
1575 | procedure PaintLogo(Canvas: TCanvas; X, Y, LightColor, ShadeColor: Integer);
|
---|
1576 | begin
|
---|
1577 | if not Assigned(DrawBuffer) then Exit;
|
---|
1578 | DrawBufferEnsureSize(Logo.Width, Logo.Height);
|
---|
1579 | UnshareBitmap(DrawBuffer);
|
---|
1580 | BitBltCanvas(DrawBuffer.Canvas, 0, 0, Logo.Width, Logo.Height, Canvas, X, Y);
|
---|
1581 | ImageOp_BCC(DrawBuffer, Templates.Data, Point(0, 0), Logo.BoundsRect,
|
---|
1582 | LightColor, ShadeColor);
|
---|
1583 | BitBltCanvas(Canvas, X, Y, Logo.Width, Logo.Height, DrawBuffer.Canvas, 0, 0);
|
---|
1584 | end;
|
---|
1585 |
|
---|
1586 | procedure DrawBufferEnsureSize(Width, Height: Integer);
|
---|
1587 | begin
|
---|
1588 | if (DrawBuffer.Width >= Width) and (DrawBuffer.Height >= Height) then Exit;
|
---|
1589 | if (DrawBuffer.Width < Width) and (DrawBuffer.Height < Height) then
|
---|
1590 | DrawBuffer.SetSize(Width, Height)
|
---|
1591 | else if DrawBuffer.Width < Width then DrawBuffer.Width := Width
|
---|
1592 | else if DrawBuffer.Height < Height then DrawBuffer.Height := Height;
|
---|
1593 | DrawBuffer.Canvas.FillRect(0, 0, DrawBuffer.Width, DrawBuffer.Height);
|
---|
1594 | end;
|
---|
1595 |
|
---|
1596 | procedure LoadPhrases;
|
---|
1597 | begin
|
---|
1598 | if Phrases = nil then Phrases := TStringTable.Create;
|
---|
1599 | if Phrases2 = nil then Phrases2 := TStringTable.Create;
|
---|
1600 | Phrases2FallenBackToEnglish := False;
|
---|
1601 | if FileExists(LocalizedFilePath('Language.txt')) then
|
---|
1602 | begin
|
---|
1603 | Phrases.LoadFromFile(LocalizedFilePath('Language.txt'));
|
---|
1604 | if FileExists(LocalizedFilePath('Language2.txt')) then
|
---|
1605 | Phrases2.LoadFromFile(LocalizedFilePath('Language2.txt'))
|
---|
1606 | else
|
---|
1607 | begin
|
---|
1608 | Phrases2.LoadFromFile(HomeDir + 'Language2.txt');
|
---|
1609 | Phrases2FallenBackToEnglish := True;
|
---|
1610 | end;
|
---|
1611 | end
|
---|
1612 | else
|
---|
1613 | begin
|
---|
1614 | Phrases.LoadFromFile(HomeDir + 'Language.txt');
|
---|
1615 | Phrases2.LoadFromFile(HomeDir + 'Language2.txt');
|
---|
1616 | end;
|
---|
1617 |
|
---|
1618 | if Sounds = nil then Sounds := TStringTable.Create;
|
---|
1619 | if not Sounds.LoadFromFile(GetSoundsDir + DirectorySeparator + 'sound.txt') then
|
---|
1620 | begin
|
---|
1621 | FreeAndNil(Sounds);
|
---|
1622 | end;
|
---|
1623 | end;
|
---|
1624 |
|
---|
1625 | procedure Texturize(Dest, Texture: TBitmap; TransparentColor: Cardinal);
|
---|
1626 | var
|
---|
1627 | SrcPixel, DstPixel: TPixelPointer;
|
---|
1628 | X, Y: Integer;
|
---|
1629 | TexWidth, TexHeight: Integer;
|
---|
1630 | begin
|
---|
1631 | // Texturize background
|
---|
1632 | Dest.BeginUpdate;
|
---|
1633 | TexWidth := Texture.Width;
|
---|
1634 | TexHeight := Texture.Height;
|
---|
1635 | DstPixel := TPixelPointer.Create(Dest);
|
---|
1636 | SrcPixel := TPixelPointer.Create(Texture);
|
---|
1637 | for Y := 0 to ScaleToNative(Dest.Height) - 1 do begin
|
---|
1638 | for X := 0 to ScaleToNative(Dest.Width) - 1 do begin
|
---|
1639 | if DstPixel.PixelRGB = TransparentColor then begin
|
---|
1640 | SrcPixel.SetXY(X mod TexWidth, Y mod TexHeight);
|
---|
1641 | DstPixel.PixelRGB := SrcPixel.PixelRGB;
|
---|
1642 | end;
|
---|
1643 | DstPixel.NextPixel;
|
---|
1644 | end;
|
---|
1645 | DstPixel.NextLine;
|
---|
1646 | end;
|
---|
1647 | Dest.EndUpdate;
|
---|
1648 | end;
|
---|
1649 |
|
---|
1650 | procedure DarkenImage(Bitmap: TBitmap; Change: Integer);
|
---|
1651 | var
|
---|
1652 | X, Y: Integer;
|
---|
1653 | PicturePixel: TPixelPointer;
|
---|
1654 | begin
|
---|
1655 | Bitmap.BeginUpdate;
|
---|
1656 | PicturePixel := TPixelPointer.Create(Bitmap);
|
---|
1657 | for Y := 0 to ScaleToNative(Bitmap.Height) - 1 do begin
|
---|
1658 | for X := 0 to ScaleToNative(Bitmap.Width) - 1 do begin
|
---|
1659 | PicturePixel.PixelB := Max(PicturePixel.PixelB - Change, 0);
|
---|
1660 | PicturePixel.PixelG := Max(PicturePixel.PixelG - Change, 0);
|
---|
1661 | PicturePixel.PixelR := Max(PicturePixel.PixelR - Change, 0);
|
---|
1662 | PicturePixel.NextPixel;
|
---|
1663 | end;
|
---|
1664 | PicturePixel.NextLine;
|
---|
1665 | end;
|
---|
1666 | Bitmap.EndUpdate;
|
---|
1667 | end;
|
---|
1668 |
|
---|
1669 | {$IFNDEF DPI}
|
---|
1670 | function ScaleToNative(Value: Integer): Integer;
|
---|
1671 | begin
|
---|
1672 | Result := Value;
|
---|
1673 | end;
|
---|
1674 |
|
---|
1675 | function ScaleToNativeDist(Base, Value: Integer): Integer;
|
---|
1676 | begin
|
---|
1677 | Result := Value;
|
---|
1678 | end;
|
---|
1679 |
|
---|
1680 | function ScaleFromNative(Value: Integer): Integer;
|
---|
1681 | begin
|
---|
1682 | Result := Value;
|
---|
1683 | end;
|
---|
1684 | {$ENDIF}
|
---|
1685 |
|
---|
1686 | procedure UnshareBitmap(Bitmap: TBitmap);
|
---|
1687 | begin
|
---|
1688 | // FillRect cause image data to be freed so subsequent BitBlt can access valid image data
|
---|
1689 | Bitmap.Canvas.FillRect(0, 0, 0, 0);
|
---|
1690 | end;
|
---|
1691 |
|
---|
1692 | procedure Gtk2Fix;
|
---|
1693 | {$IFDEF UNIX}
|
---|
1694 | var
|
---|
1695 | I: Integer;
|
---|
1696 | {$ENDIF}
|
---|
1697 | begin
|
---|
1698 | {$IFDEF UNIX}
|
---|
1699 | // Wait and process messages little bit to avoid crash or force repaint under Gtk2
|
---|
1700 | for I := 0 to 10 do begin
|
---|
1701 | Sleep(1);
|
---|
1702 | Application.ProcessMessages;
|
---|
1703 | end;
|
---|
1704 | {$ENDIF}
|
---|
1705 | end;
|
---|
1706 |
|
---|
1707 | procedure LoadFonts;
|
---|
1708 | var
|
---|
1709 | Section: TFontType;
|
---|
1710 | FontScript: TextFile;
|
---|
1711 | Size: Integer;
|
---|
1712 | S: string;
|
---|
1713 | I: Integer;
|
---|
1714 | P: Integer;
|
---|
1715 | begin
|
---|
1716 | Section := ftNormal;
|
---|
1717 | AssignFile(FontScript, LocalizedFilePath('Fonts.txt'));
|
---|
1718 | try
|
---|
1719 | Reset(FontScript);
|
---|
1720 | while not Eof(FontScript) do begin
|
---|
1721 | ReadLn(FontScript, S);
|
---|
1722 | if S <> '' then
|
---|
1723 | if S[1] = '#' then begin
|
---|
1724 | S := TrimRight(S);
|
---|
1725 | if S = '#SMALL' then Section := ftSmall
|
---|
1726 | else if S = '#TINY' then Section := ftTiny
|
---|
1727 | else if S = '#CAPTION' then Section := ftCaption
|
---|
1728 | else if S = '#BUTTON' then Section := ftButton
|
---|
1729 | else Section := ftNormal;
|
---|
1730 | end else begin
|
---|
1731 | P := Pos(',', S);
|
---|
1732 | if P > 0 then begin
|
---|
1733 | UniFont[section].Name := Trim(Copy(S, 1, P - 1));
|
---|
1734 | Size := 0;
|
---|
1735 | for I := P + 1 to Length(S) do
|
---|
1736 | case S[I] of
|
---|
1737 | '0' .. '9':
|
---|
1738 | Size := Size * 10 + Byte(S[I]) - 48;
|
---|
1739 | 'B', 'b':
|
---|
1740 | UniFont[section].Style := UniFont[section].Style + [TFontStyle.fsBold];
|
---|
1741 | 'I', 'i':
|
---|
1742 | UniFont[section].Style := UniFont[section].Style + [TFontStyle.fsItalic];
|
---|
1743 | end;
|
---|
1744 | UniFont[section].Size := Round(Size * ScaleToNative(72) / UniFont[section].PixelsPerInch);
|
---|
1745 | end;
|
---|
1746 | end;
|
---|
1747 | end;
|
---|
1748 | CloseFile(FontScript);
|
---|
1749 | except
|
---|
1750 | end;
|
---|
1751 | end;
|
---|
1752 |
|
---|
1753 | procedure ReleaseFonts;
|
---|
1754 | var
|
---|
1755 | Section: TFontType;
|
---|
1756 | begin
|
---|
1757 | for Section := Low(TFontType) to High(TFontType) do
|
---|
1758 | FreeAndNil(UniFont[section]);
|
---|
1759 | end;
|
---|
1760 |
|
---|
1761 | procedure InitGammaLookupTable;
|
---|
1762 | var
|
---|
1763 | I: Integer;
|
---|
1764 | P: Integer;
|
---|
1765 | begin
|
---|
1766 | GammaLookupTable[0] := 0;
|
---|
1767 | for I := 1 to 255 do begin
|
---|
1768 | P := Round(255.0 * Exp(Ln(I / 255.0) * 100.0 / Gamma));
|
---|
1769 | Assert((P >= 0) and (P < 256));
|
---|
1770 | GammaLookupTable[I] := P;
|
---|
1771 | end;
|
---|
1772 | end;
|
---|
1773 |
|
---|
1774 | procedure Gtk2DisableControlStyling(WinControl: TWinControl);
|
---|
1775 | begin
|
---|
1776 | // https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/38516
|
---|
1777 | {$IFDEF LCLGTK2}
|
---|
1778 | // parse gtkrc from string
|
---|
1779 | gtk_rc_parse_string(PChar('style "noengine" {' + LineEnding +
|
---|
1780 | 'engine "" {}' + LineEnding +
|
---|
1781 | '}' + LineEnding +
|
---|
1782 | 'widget "*.your-edit" style "noengine"'));
|
---|
1783 |
|
---|
1784 | if WinControl.HandleAllocated then begin
|
---|
1785 | // set gtk name to our component
|
---|
1786 | gtk_widget_set_name({%H-}PGtkWidget(WinControl.Handle), 'your-edit');
|
---|
1787 | end;
|
---|
1788 | {$ENDIF}
|
---|
1789 | end;
|
---|
1790 |
|
---|
1791 | procedure LoadConfig(Key: string);
|
---|
1792 | var
|
---|
1793 | Reg: TRegistry;
|
---|
1794 | begin
|
---|
1795 | Reg := TRegistry.Create;
|
---|
1796 | with Reg do try
|
---|
1797 | OpenKey(Key, True);
|
---|
1798 | if ValueExists('Gamma') then Gamma := ReadInteger('Gamma')
|
---|
1799 | else Gamma := 100;
|
---|
1800 | if Gamma <> 100 then InitGammaLookupTable;
|
---|
1801 | if ValueExists('CustomDpiEnabled') then CustomDpiEnabled := Reg.ReadBool('CustomDpiEnabled')
|
---|
1802 | else CustomDpiEnabled := False;
|
---|
1803 | if ValueExists('CustomDpi') then CustomDpi := Reg.ReadInteger('CustomDpi')
|
---|
1804 | else CustomDpi := 96;
|
---|
1805 | {$IFDEF DPI}
|
---|
1806 | if CustomDpiEnabled then Screen.Dpi := CustomDpi
|
---|
1807 | else Screen.Dpi := Screen.GetSystemDpi;
|
---|
1808 | {$ENDIF}
|
---|
1809 | finally
|
---|
1810 | Reg.Free;
|
---|
1811 | end;
|
---|
1812 | end;
|
---|
1813 |
|
---|
1814 | procedure SaveConfig(Key: string);
|
---|
1815 | var
|
---|
1816 | Reg: TRegistry;
|
---|
1817 | begin
|
---|
1818 | Reg := TRegistry.Create;
|
---|
1819 | with Reg do try
|
---|
1820 | OpenKey(Key, True);
|
---|
1821 | WriteInteger('Gamma', Gamma);
|
---|
1822 | WriteBool('CustomDpiEnabled', CustomDpiEnabled);
|
---|
1823 | WriteInteger('CustomDpi', CustomDpi);
|
---|
1824 | finally
|
---|
1825 | Free;
|
---|
1826 | end;
|
---|
1827 | end;
|
---|
1828 |
|
---|
1829 | procedure LoadAssets;
|
---|
1830 | begin
|
---|
1831 | LoadPhrases;
|
---|
1832 | LoadFonts;
|
---|
1833 | Templates := LoadGraphicSet('Templates.png', False);
|
---|
1834 | with Templates do begin
|
---|
1835 | Logo := GetItem('Logo');
|
---|
1836 | BigBook := GetItem('BigBook');
|
---|
1837 | SmallBook := GetItem('SmallBook');
|
---|
1838 | MenuLogo := GetItem('MenuLogo');
|
---|
1839 | LinkArrows := GetItem('LinkArrows');
|
---|
1840 | ScienceNationDot := GetItem('ScienceNationDot');
|
---|
1841 | ResearchIcon := GetItem('Research');
|
---|
1842 | ChangeIcon := GetItem('Change');
|
---|
1843 | TreasuryIcon := GetItem('Treasury');
|
---|
1844 | StarshipDeparted := GetItem('StarshipDeparted');
|
---|
1845 | WeightOn := GetItem('WeightOn');
|
---|
1846 | WeightOff := GetItem('WeightOff');
|
---|
1847 | end;
|
---|
1848 |
|
---|
1849 | LoadGraphicFile(Colors, GetGraphicsDir + DirectorySeparator + 'Colors.png');
|
---|
1850 | LoadGraphicFile(Paper, GetGraphicsDir + DirectorySeparator + 'Paper.jpg');
|
---|
1851 | LoadGraphicFile(BigImp, GetGraphicsDir + DirectorySeparator + 'Icons.png');
|
---|
1852 | end;
|
---|
1853 |
|
---|
1854 | procedure UnitInit;
|
---|
1855 | var
|
---|
1856 | Section: TFontType;
|
---|
1857 | begin
|
---|
1858 | Gamma := 100;
|
---|
1859 | InitGammaLookupTable;
|
---|
1860 |
|
---|
1861 | {$IFDEF WINDOWS}
|
---|
1862 | EnumDisplaySettings(nil, $FFFFFFFF, StartResolution);
|
---|
1863 | ResolutionChanged := False;
|
---|
1864 | {$ENDIF}
|
---|
1865 |
|
---|
1866 | for Section := Low(TFontType) to High(TFontType) do
|
---|
1867 | UniFont[Section] := TFont.Create;
|
---|
1868 |
|
---|
1869 | DrawBuffer := TBitmap.Create;
|
---|
1870 | DrawBuffer.PixelFormat := TPixelFormat.pf24bit;
|
---|
1871 |
|
---|
1872 | GrExt := TGraphicSets.Create;
|
---|
1873 |
|
---|
1874 | HGrSystem := LoadGraphicSet('System.png');
|
---|
1875 | with HGrSystem do begin
|
---|
1876 | CityMark1 := GetItem('CityMark1');
|
---|
1877 | CityMark2 := GetItem('CityMark2');
|
---|
1878 | end;
|
---|
1879 |
|
---|
1880 | HGrSystem2 := LoadGraphicSet('System2.png');
|
---|
1881 | with HGrSystem2 do begin
|
---|
1882 | Ornament := GetItem('Ornament');
|
---|
1883 | GBrainNoTerm := GetItem('BrainNoTerm');
|
---|
1884 | GBrainSuperVirtual := GetItem('BrainSuperVirtual');
|
---|
1885 | GBrainTerm := GetItem('BrainTerm');
|
---|
1886 | GBrainRandom := GetItem('BrainRandom');
|
---|
1887 | end;
|
---|
1888 |
|
---|
1889 | Colors := TBitmap.Create;
|
---|
1890 | Colors.PixelFormat := TPixelFormat.pf24bit;
|
---|
1891 | Paper := TBitmap.Create;
|
---|
1892 | Paper.PixelFormat := TPixelFormat.pf24bit;
|
---|
1893 | BigImp := TBitmap.Create;
|
---|
1894 | BigImp.PixelFormat := TPixelFormat.pf24bit;
|
---|
1895 | MainTexture := TTexture.Create;
|
---|
1896 | ClickFrameColor := HGrSystem.Data.Canvas.Pixels[187, 175];
|
---|
1897 | InitOrnamentDone := False;
|
---|
1898 | GenerateNames := True;
|
---|
1899 |
|
---|
1900 | LoadAssets;
|
---|
1901 | end;
|
---|
1902 |
|
---|
1903 | procedure UnitDone;
|
---|
1904 | begin
|
---|
1905 | RestoreResolution;
|
---|
1906 | FreeAndNil(GrExt);
|
---|
1907 | ReleaseFonts;
|
---|
1908 | FreeAndNil(Phrases);
|
---|
1909 | FreeAndNil(Phrases2);
|
---|
1910 | FreeAndNil(DrawBuffer);
|
---|
1911 | FreeAndNil(BigImp);
|
---|
1912 | FreeAndNil(Paper);
|
---|
1913 | FreeAndNil(Colors);
|
---|
1914 | FreeAndNil(MainTexture);
|
---|
1915 | end;
|
---|
1916 |
|
---|
1917 | end.
|
---|