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