Changeset 210 for branches/highdpi/Packages/CevoComponents/ScreenTools.pas
- Timestamp:
- May 9, 2020, 4:02:07 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/CevoComponents/ScreenTools.pas
r193 r210 4 4 5 5 uses 6 {$IFDEF WINDOWS}6 UDpiControls, {$IFDEF WINDOWS} 7 7 Windows, 8 8 {$ENDIF} 9 StringTables, LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, 10 Forms, Menus, GraphType , UDpiControls;9 StringTables, LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Math, 10 Forms, Menus, GraphType; 11 11 12 12 type … … 17 17 end; 18 18 19 TColor32 = type cardinal;20 TColor32Component = (ccBlue, ccGreen, ccRed, ccAlpha);21 TPixel32 = packed record22 case integer of23 0: (B, G, R, A: byte);24 1: (ARGB: TColor32);25 2: (Planes: array[0..3] of byte);26 3: (Components: array[TColor32Component] of byte);27 end;28 PPixel32 = ^TPixel32;29 30 { TPixelPointer }31 32 TPixelPointer = record33 Base: PPixel32;34 Pixel: PPixel32;35 Line: PPixel32;36 RelLine: PPixel32;37 BytesPerPixel: integer;38 BytesPerLine: integer;39 procedure NextLine; inline; // Move pointer to start of new base line40 procedure NextPixel; inline; // Move pointer to next pixel41 procedure SetXY(X, Y: integer); inline; // Set pixel position relative to base42 procedure SetX(X: integer); inline; // Set horizontal pixel position relative to base43 procedure Init(Bitmap: TDpiRasterImage; BaseX: integer = 0; BaseY: integer = 0); inline;44 end;45 PPixelPointer = ^TPixelPointer;46 47 19 {$IFDEF WINDOWS} 48 20 function ChangeResolution(x, y, bpp, freq: integer): boolean; 49 21 {$ENDIF} 50 22 procedure RestoreResolution; 51 function Play(Item: string; Index: integer = -1): boolean;52 procedure PreparePlay(Item: string; Index: integer = -1);53 23 procedure EmptyMenu(MenuItems: TMenuItem; Keep: Integer = 0); 54 24 function TurnToYear(Turn: integer): integer; … … 65 35 procedure Sprite(dst: TDpiBitmap; HGr, xDst, yDst, Width, Height, xGr, yGr: integer); 66 36 overload; 67 procedure MakeBlue(dst: TDpiBitmap; x, y, w, h: integer);68 procedure ImageOp_B(dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, w, h: integer);37 procedure MakeBlue(dst: TDpiBitmap; x, y, Width, Height: Integer); 38 procedure ImageOp_B(dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer); 69 39 procedure ImageOp_BCC(dst, Src: TDpiBitmap; 70 xDst, yDst, xSrc, ySrc, w, h, Color1, Color2: integer); 71 procedure ImageOp_CCC(bmp: TDpiBitmap; x, y, w, h, Color0, Color1, Color2: integer); 72 function BitBltCanvas(DestCanvas: TDpiCanvas; X, Y, Width, Height: integer; 73 SrcCanvas: TDpiCanvas; XSrc, YSrc: integer; Rop: DWORD): boolean; 40 xDst, yDst, xSrc, ySrc, Width, Height, Color1, Color2: Integer); 41 procedure ImageOp_CBC(Dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height, 42 Color0, Color2: Integer); 43 procedure ImageOp_CCC(bmp: TDpiBitmap; x, y, w, h, Color0, Color1, Color2: Integer); 44 function DpiBitCanvas(DestCanvas: TDpiCanvas; X, Y, Width, Height: Integer; 45 SrcCanvas: TDpiCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload; 46 function DpiBitCanvas(Dest: TDpiCanvas; DestRect: TRect; 47 Src: TDpiCanvas; SrcPos: TPoint; Rop: DWORD = SRCCOPY): Boolean; overload; 48 function BitBltBitmap(Dest: TDpiBitmap; X, Y, Width, Height: Integer; 49 Src: TDpiBitmap; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload; 50 function BitBltBitmap(Dest: TDpiBitmap; DestRect: TRect; 51 Src: TDpiBitmap; SrcPos: TPoint; Rop: DWORD = SRCCOPY): Boolean; overload; 74 52 procedure SLine(ca: TDpiCanvas; x0, x1, y: integer; cl: TColor); 75 53 procedure DLine(ca: TDpiCanvas; x0, x1, y: integer; cl0, cl1: TColor); … … 82 60 procedure InitOrnament; 83 61 procedure InitCityMark(const T: TTexture); 84 procedure Fill(ca: TDpiCanvas; Left, Top, Width, Height, xOffset, yOffset: integer); 62 procedure Fill(ca: TDpiCanvas; Left, Top, Width, Height, xOffset, yOffset: integer); overload; 63 procedure Fill(Canvas: TDpiCanvas; Rect: TRect; Offset: TPoint); overload; 85 64 procedure FillLarge(ca: TDpiCanvas; x0, y0, x1, y1, xm: integer); 86 65 procedure FillSeamless(ca: TDpiCanvas; Left, Top, Width, Height, xOffset, yOffset: integer; … … 88 67 procedure FillRectSeamless(ca: TDpiCanvas; x0, y0, x1, y1, xOffset, yOffset: integer; 89 68 const Texture: TDpiBitmap); 90 procedure PaintBackground(Form: TDpiForm; Left, Top, Width, Height: Integer);69 procedure PaintBackground(Form: TDpiForm; Left, Top, Width, Height: integer); 91 70 procedure Corner(ca: TDpiCanvas; x, y, Kind: integer; const T: TTexture); 92 71 procedure BiColorTextOut(ca: TDpiCanvas; clMain, clBack: TColor; x, y: integer; s: string); … … 111 90 function SetMainTextureByAge(Age: integer): boolean; 112 91 procedure LoadPhrases; 92 procedure Texturize(Dest, Texture: TDpiBitmap; TransparentColor: Integer); 93 procedure DarkenImage(Bitmap: TDpiBitmap; Change: Integer); 113 94 114 95 const … … 148 129 wOrna = 27; 149 130 hOrna = 26; // ornament 150 151 // sound modes152 smOff = 0;153 smOn = 1;154 smOnAlt = 2;155 131 156 132 // color matrix … … 188 164 TGrExtDescr = record { don't use dynamic strings here! } 189 165 Name: string[31]; 190 Data, Mask: TDpiBitmap; 191 pixUsed: array [byte] of byte; 166 Data: TDpiBitmap; 167 Mask: TDpiBitmap; 168 pixUsed: array [Byte] of Byte; 192 169 end; 193 170 … … 195 172 TGrExtDescr, but without pixUsed } 196 173 Name: string[31]; 197 Data, Mask: TBitmap; 174 Data: TDpiBitmap; 175 Mask: TDpiBitmap; 198 176 end; 199 177 … … 201 179 202 180 var 203 Phrases, Phrases2, Sounds: TStringTable; 204 nGrExt: integer; 181 Phrases: TStringTable; 182 Phrases2: TStringTable; 183 nGrExt: Integer; 205 184 GrExt: array [0 .. nGrExtmax - 1] of ^TGrExtDescr; 206 HGrSystem, HGrSystem2, ClickFrameColor, SoundMode, MainTextureAge: integer; 185 HGrSystem: Integer; 186 HGrSystem2: Integer; 187 ClickFrameColor: Integer; 188 MainTextureAge: Integer; 207 189 MainTexture: TTexture; 208 Templates, Colors, Paper, BigImp, LogoBuffer: TDpiBitmap; 209 FullScreen, GenerateNames, InitOrnamentDone, Phrases2FallenBackToEnglish: boolean; 190 Templates: TDpiBitmap; 191 Colors: TDpiBitmap; 192 Paper: TDpiBitmap; 193 BigImp: TDpiBitmap; 194 LogoBuffer: TDpiBitmap; 195 FullScreen: Boolean; 196 GenerateNames: Boolean; 197 InitOrnamentDone: Boolean; 198 Phrases2FallenBackToEnglish: Boolean; 210 199 211 200 UniFont: array [TFontType] of TDpiFont; 212 AppRegistryKey: string = '\SOFTWARE\C-evo'; 213 201 Gamma: Integer; // global gamma correction (cent) 202 203 procedure LoadAssets; 214 204 procedure UnitInit; 215 205 procedure UnitDone; 206 procedure InitGammaLookupTable; 207 216 208 217 209 implementation 218 210 219 211 uses 220 Directories, Sound, Registry;212 Directories, Sound, UPixelPointer; 221 213 222 214 var … … 226 218 {$ENDIF} 227 219 228 Gamma: Integer; // global gamma correction (cent) 229 GammaLookupTable: array [0 .. 255] of Byte; 220 GammaLookupTable: array [0..255] of Byte; 230 221 231 222 {$IFDEF WINDOWS} … … 255 246 ResolutionChanged := False; 256 247 {$ENDIF} 257 end;258 259 function Play(Item: string; Index: integer = -1): boolean;260 {$IFNDEF DEBUG}261 var262 WavFileName: string;263 {$ENDIF}264 begin265 Result := False;266 {$IFNDEF DEBUG}267 if (Sounds = nil) or (SoundMode = smOff) or (Item = '') then268 begin269 Result := True;270 Exit;271 end;272 WavFileName := Sounds.Lookup(Item, Index);273 Assert(WavFileName[1] <> '[');274 Result := (WavFileName <> '') and (WavFileName[1] <> '[') and (WavFileName <> '*');275 if Result then276 // SndPlaySound(pchar(HomeDir+'Sounds' +DirectorySeparator+WavFileName+'.wav'),SND_ASYNC)277 PlaySound(HomeDir + 'Sounds' + DirectorySeparator + WavFileName);278 {$ENDIF}279 end;280 281 procedure PreparePlay(Item: string; Index: Integer = -1);282 {$IFNDEF DEBUG}283 var284 WavFileName: string;285 {$ENDIF}286 begin287 {$IFNDEF DEBUG}288 if (Sounds = nil) or (SoundMode = smOff) or (Item = '') then289 Exit;290 WavFileName := Sounds.Lookup(Item, Index);291 Assert(WavFileName[1] <> '[');292 if (WavFileName <> '') and (WavFileName[1] <> '[') and (WavFileName <> '*') then293 PrepareSound(HomeDir + 'Sounds' + DirectorySeparator + WavFileName);294 {$ENDIF}295 248 end; 296 249 … … 409 362 begin 410 363 Bitmap.BeginUpdate; 411 PixelPtr .Init(Bitmap);364 PixelPtr := PixelPointer(Bitmap); 412 365 for Y := 0 to ScaleToVcl(Bitmap.Height) - 1 do begin 413 366 for X := 0 to ScaleToVcl(Bitmap.Width) - 1 do begin … … 420 373 end; 421 374 422 procedure CopyGray8BitTo24bitBitmap(Dst, Src: TDpi Bitmap);375 procedure CopyGray8BitTo24bitBitmap(Dst, Src: TDpiRasterImage); 423 376 var 424 377 SrcPtr, DstPtr: TPixelPointer; … … 426 379 begin 427 380 //Dst.SetSize(Src.Width, Src.Height); 428 SrcPtr .Init(Src);429 DstPtr .Init(Dst);381 SrcPtr := PixelPointer(Src); 382 DstPtr := PixelPointer(Dst); 430 383 for Y := 0 to ScaleToVcl(Src.Height) - 1 do begin 431 384 for X := 0 to ScaleToVcl(Src.Width) - 1 do begin … … 441 394 end; 442 395 443 procedure ResizeBitmap(Bitmap: TDpiBitmap; const NewWidth, NewHeight: Integer);444 var445 Buffer: TDpiBitmap;446 begin447 Buffer := TDpiBitmap.Create;448 try449 Buffer.SetSize(NewWidth, NewHeight);450 Buffer.Canvas.StretchDraw(Rect(0, 0, NewWidth, NewHeight), Bitmap);451 Bitmap.SetSize(NewWidth, NewHeight);452 Bitmap.Canvas.Draw(0, 0, Buffer);453 finally454 Buffer.Free;455 end;456 end;457 458 396 function LoadGraphicFile(bmp: TDpiBitmap; Path: string; Options: Integer): Boolean; 459 397 var … … 465 403 Path := Path + '.png'; 466 404 if ExtractFileExt(Path) = '.jpg' then begin 467 jtex := TDpiJpegImage.Create;405 jtex := tDpijpegimage.Create; 468 406 try 469 407 jtex.LoadFromFile(Path); 470 ResizeBitmap(jtex, ScaleToVcl(jtex.Width), ScaleToVcl(jtex.Height));471 408 except 472 409 Result := False; … … 487 424 try 488 425 Png.LoadFromFile(Path); 489 ResizeBitmap(Png, ScaleToVcl(Png.Width), ScaleToVcl(Png.Height));490 426 except 491 427 Result := False; … … 503 439 end 504 440 else 505 Bmp.Canvas. Draw(0, 0, Png);441 Bmp.Canvas.draw(0, 0, Png); 506 442 end; 507 443 Png.Free; … … 511 447 try 512 448 bmp.LoadFromFile(Path); 513 ResizeBitmap(bmp, ScaleToVcl(bmp.Width), ScaleToVcl(bmp.Height));514 449 except 515 450 Result := False; … … 546 481 Source := TDpiBitmap.Create; 547 482 Source.PixelFormat := pf24bit; 548 FileName := HomeDir + 'Graphics'+ DirectorySeparator + Name;483 FileName := GetGraphicsDir + DirectorySeparator + Name; 549 484 if not LoadGraphicFile(Source, FileName) then begin 550 485 Result := -1; … … 556 491 557 492 xmax := Source.Width - 1; // allows 4-byte access even for last pixel 558 if xmax > 970 then 559 xmax := 970; 493 // Why there was that limit? 494 //if xmax > 970 then 495 // xmax := 970; 560 496 561 497 GrExt[nGrExt].Data := Source; … … 567 503 GrExt[nGrExt].Data.BeginUpdate; 568 504 GrExt[nGrExt].Mask.BeginUpdate; 569 DataPixel .Init(GrExt[nGrExt].Data);570 MaskPixel .Init(GrExt[nGrExt].Mask);505 DataPixel := PixelPointer(GrExt[nGrExt].Data); 506 MaskPixel := PixelPointer(GrExt[nGrExt].Mask); 571 507 for y := 0 to ScaleToVcl(Source.Height) - 1 do begin 572 508 for x := 0 to ScaleToVcl(xmax) - 1 do begin … … 598 534 procedure Dump(dst: TDpiBitmap; HGr, xDst, yDst, Width, Height, xGr, yGr: integer); 599 535 begin 600 DpiBit Blt(dst.Canvas.Handle, xDst, yDst, Width, Height,601 GrExt[HGr].Data.Canvas .Handle, xGr, yGr, SRCCOPY);602 end; 603 604 procedure MakeBlue(dst: TDpiBitmap; x, y, w, h: integer);536 DpiBitCanvas(dst.Canvas, xDst, yDst, Width, Height, 537 GrExt[HGr].Data.Canvas, xGr, yGr); 538 end; 539 540 procedure MakeBlue(dst: TDpiBitmap; x, y, Width, Height: Integer); 605 541 var 606 542 XX, YY: integer; … … 609 545 X := ScaleToVcl(X); 610 546 Y := ScaleToVcl(Y); 611 W := ScaleToVcl(W);612 H := ScaleToVcl(H);547 Width := ScaleToVcl(Width); 548 Height := ScaleToVcl(Height); 613 549 Dst.BeginUpdate; 614 PixelPtr .Init(Dst, X, Y);615 for yy := 0 to h- 1 do begin616 for xx := 0 to w- 1 do begin550 PixelPtr := PixelPointer(Dst, X, Y); 551 for yy := 0 to Height - 1 do begin 552 for xx := 0 to Width - 1 do begin 617 553 PixelPtr.Pixel^.B := PixelPtr.Pixel^.B div 2; 618 554 PixelPtr.Pixel^.G := PixelPtr.Pixel^.G div 2; … … 625 561 end; 626 562 627 procedure ImageOp_B(dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, w, h: Integer);563 procedure ImageOp_B(dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer); 628 564 // Src is template 629 565 // X channel = background amp (old Dst content), 128=original brightness … … 638 574 xSrc := ScaleToVcl(xSrc); 639 575 ySrc := ScaleToVcl(ySrc); 640 w := ScaleToVcl(w);641 h := ScaleToVcl(h);576 Width := ScaleToVcl(Width); 577 Height := ScaleToVcl(Height); 642 578 //Assert(Src.PixelFormat = pf8bit); 643 579 Assert(dst.PixelFormat = pf24bit); 644 580 if xDst < 0 then begin 645 w := w+ xDst;581 Width := Width + xDst; 646 582 xSrc := xSrc - xDst; 647 583 xDst := 0; 648 584 end; 649 585 if yDst < 0 then begin 650 h := h+ yDst;586 Height := Height + yDst; 651 587 ySrc := ySrc - yDst; 652 588 yDst := 0; 653 589 end; 654 if xDst + w> ScaleToVcl(dst.Width) then655 w:= ScaleToVcl(dst.Width) - xDst;656 if yDst + h> ScaleToVcl(dst.Height) then657 h:= ScaleToVcl(dst.Height) - yDst;658 if ( w < 0) or (h< 0) then590 if xDst + Width > ScaleToVcl(dst.Width) then 591 Width := ScaleToVcl(dst.Width) - xDst; 592 if yDst + Height > ScaleToVcl(dst.Height) then 593 Height := ScaleToVcl(dst.Height) - yDst; 594 if (Width < 0) or (Height < 0) then 659 595 exit; 660 596 661 597 dst.BeginUpdate; 662 598 Src.BeginUpdate; 663 PixelDst .Init(Dst, xDst, yDst);664 PixelSrc .Init(Src, xSrc, ySrc);665 for Y := 0 to h- 1 do begin666 for X := 0 to w- 1 do begin599 PixelDst := PixelPointer(Dst, xDst, yDst); 600 PixelSrc := PixelPointer(Src, xSrc, ySrc); 601 for Y := 0 to Height - 1 do begin 602 for X := 0 to Width - 1 do begin 667 603 Brightness := PixelSrc.Pixel^.B; // One byte for 8-bit color 668 604 test := (PixelDst.Pixel^.R * Brightness) shr 7; … … 691 627 end; 692 628 693 procedure ImageOp_BCC(dst, Src: TDpiBitmap; 694 xDst, yDst, xSrc, ySrc, w, h, Color1, Color2: integer);629 procedure ImageOp_BCC(dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height, 630 Color1, Color2: Integer); 695 631 // Src is template 696 632 // B channel = background amp (old Dst content), 128=original brightness … … 698 634 // R channel = Color2 amp, 128=original brightness 699 635 var 700 ix, iy, amp1, amp2, trans, Value: integer; 701 SrcPixel, DstPixel: TPixelPointer; 636 ix, iy, amp1, amp2, trans, Value: Integer; 637 SrcPixel: TPixelPointer; 638 DstPixel: TPixelPointer; 702 639 begin 703 640 xDst := ScaleToVcl(xDst); … … 705 642 xSrc := ScaleToVcl(xSrc); 706 643 ySrc := ScaleToVcl(ySrc); 707 w := ScaleToVcl(w);708 h := ScaleToVcl(h);644 Width := ScaleToVcl(Width); 645 Height := ScaleToVcl(Height); 709 646 if xDst < 0 then begin 710 w := w+ xDst;647 Width := Width + xDst; 711 648 xSrc := xSrc - xDst; 712 649 xDst := 0; 713 650 end; 714 651 if yDst < 0 then begin 715 h := h+ yDst;652 Height := Height + yDst; 716 653 ySrc := ySrc - yDst; 717 654 yDst := 0; 718 655 end; 719 if xDst + w> ScaleToVcl(dst.Width) then720 w:= ScaleToVcl(dst.Width) - xDst;721 if yDst + h> ScaleToVcl(dst.Height) then722 h:= ScaleToVcl(dst.Height) - yDst;723 if ( w < 0) or (h< 0) then656 if xDst + Width > ScaleToVcl(dst.Width) then 657 Width := ScaleToVcl(dst.Width) - xDst; 658 if yDst + Height > ScaleToVcl(dst.Height) then 659 Height := ScaleToVcl(dst.Height) - yDst; 660 if (Width < 0) or (Height < 0) then 724 661 exit; 725 662 726 663 Src.BeginUpdate; 727 664 dst.BeginUpdate; 728 SrcPixel .Init(Src, xSrc, ySrc);729 DstPixel .Init(Dst, xDst, yDst);730 for iy := 0 to h- 1 do begin731 for ix := 0 to w- 1 do begin665 SrcPixel := PixelPointer(Src, xSrc, ySrc); 666 DstPixel := PixelPointer(Dst, xDst, yDst); 667 for iy := 0 to Height - 1 do begin 668 for ix := 0 to Width - 1 do begin 732 669 trans := SrcPixel.Pixel^.B * 2; // green channel = transparency 733 670 amp1 := SrcPixel.Pixel^.G * 2; … … 736 673 Value := (DstPixel.Pixel^.B * trans + ((Color2 shr 16) and $FF) * 737 674 amp2 + ((Color1 shr 16) and $FF) * amp1) div $FF; 738 if Value < 256 then 739 DstPixel.Pixel^.B := Value 740 else 741 DstPixel.Pixel^.B := 255; 675 DstPixel.Pixel^.B := Min(Value, 255); 676 742 677 Value := (DstPixel.Pixel^.G * trans + ((Color2 shr 8) and $FF) * 743 678 amp2 + ((Color1 shr 8) and $FF) * amp1) div $FF; 744 if Value < 256 then 745 DstPixel.Pixel^.G := Value 746 else 747 DstPixel.Pixel^.G := 255; 679 DstPixel.Pixel^.G := Min(Value, 255); 680 748 681 Value := (DstPixel.Pixel^.R * trans + (Color2 and $FF) * 749 682 amp2 + (Color1 and $FF) * amp1) div $FF; 750 if Value < 256 then 751 DstPixel.Pixel^.R := Value 752 else 753 DstPixel.Pixel^.R := 255; 683 DstPixel.Pixel^.R := Min(Value, 255); 684 end; 685 686 SrcPixel.NextPixel; 687 DstPixel.NextPixel; 688 end; 689 SrcPixel.NextLine; 690 DstPixel.NextLine; 691 end; 692 Src.EndUpdate; 693 dst.EndUpdate; 694 end; 695 696 procedure ImageOp_CBC(Dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height, 697 Color0, Color2: Integer); 698 // Src is template 699 // B channel = Color0 amp 700 // G channel = background amp (old Dst content), 128=original brightness 701 // R channel = Color2 amp 702 var 703 ix, iy, amp0, amp1, trans, Value: integer; 704 SrcPixel: TPixelPointer; 705 DstPixel: TPixelPointer; 706 begin 707 xDst := ScaleToVcl(xDst); 708 yDst := ScaleToVcl(yDst); 709 xSrc := ScaleToVcl(xSrc); 710 ySrc := ScaleToVcl(ySrc); 711 Width := ScaleToVcl(Width); 712 Height := ScaleToVcl(Height); 713 Src.BeginUpdate; 714 Dst.BeginUpdate; 715 SrcPixel := PixelPointer(Src, xSrc, ySrc); 716 DstPixel := PixelPointer(Dst, xDst, yDst); 717 for iy := 0 to Height - 1 do begin 718 for ix := 0 to Width - 1 do begin 719 trans := SrcPixel.Pixel^.B * 2; // green channel = transparency 720 amp0 := SrcPixel.Pixel^.G * 2; 721 amp1 := SrcPixel.Pixel^.R * 2; 722 if trans <> $FF then begin 723 Value := (DstPixel.Pixel^.B * trans + (Color2 shr 16 and $FF) * amp1 + 724 (Color0 shr 16 and $FF) * amp0) div $FF; 725 DstPixel.Pixel^.B := Min(Value, 255); 726 727 Value := (DstPixel.Pixel^.G * trans + (Color2 shr 8 and $FF) * amp1 + 728 (Color0 shr 8 and $FF) * amp0) div $FF; 729 DstPixel.Pixel^.G := Min(Value, 255); 730 731 Value := (DstPixel.Pixel^.R * trans + (Color2 and $FF) * amp1 + 732 (Color0 and $FF) * amp0) div $FF; 733 DstPixel.Pixel^.R := Min(Value, 255); 754 734 end; 755 735 SrcPixel.NextPixel; … … 760 740 end; 761 741 Src.EndUpdate; 762 dst.EndUpdate;742 Dst.EndUpdate; 763 743 end; 764 744 … … 779 759 assert(bmp.PixelFormat = pf24bit); 780 760 h := y + h; 781 PixelPtr .Init(Bmp, x, y);761 PixelPtr := PixelPointer(Bmp, x, y); 782 762 while y < h do begin 783 763 for i := 0 to w - 1 do begin … … 802 782 procedure Sprite(Canvas: TDpiCanvas; HGr, xDst, yDst, Width, Height, xGr, yGr: integer); 803 783 begin 804 DpiBit Blt(Canvas.Handle, xDst, yDst, Width, Height,805 GrExt[HGr].Mask.Canvas .Handle, xGr, yGr, SRCAND);806 DpiBit Blt(Canvas.Handle, xDst, yDst, Width, Height,807 GrExt[HGr].Data.Canvas .Handle, xGr, yGr, SRCPAINT);784 DpiBitCanvas(Canvas, xDst, yDst, Width, Height, 785 GrExt[HGr].Mask.Canvas, xGr, yGr, SRCAND); 786 DpiBitCanvas(Canvas, xDst, yDst, Width, Height, 787 GrExt[HGr].Data.Canvas, xGr, yGr, SRCPAINT); 808 788 end; 809 789 810 790 procedure Sprite(dst: TDpiBitmap; HGr, xDst, yDst, Width, Height, xGr, yGr: integer); 811 791 begin 812 DpiBitBlt(dst.Canvas.Handle, xDst, yDst, Width, Height, 813 GrExt[HGr].Mask.Canvas.Handle, xGr, yGr, SRCAND); 814 DpiBitBlt(dst.Canvas.Handle, xDst, yDst, Width, Height, 815 GrExt[HGr].Data.Canvas.Handle, xGr, yGr, SRCPAINT); 816 end; 817 818 function BitBltCanvas(DestCanvas: TDpiCanvas; X, Y, Width, Height: integer; 819 SrcCanvas: TDpiCanvas; XSrc, YSrc: integer; Rop: DWORD): boolean; 820 begin 821 Assert(Rop = SRCCOPY); 822 DestCanvas.CopyRect(Rect(X, Y, X + Width, Y + Height), SrcCanvas, 823 Rect(XSrc, YSrc, XSrc + Width, YSrc + Height)); 824 Result := True; 792 DpiBitCanvas(dst.Canvas, xDst, yDst, Width, Height, 793 GrExt[HGr].Mask.Canvas, xGr, yGr, SRCAND); 794 DpiBitCanvas(dst.Canvas, xDst, yDst, Width, Height, 795 GrExt[HGr].Data.Canvas, xGr, yGr, SRCPAINT); 796 end; 797 798 function DpiBitCanvas(DestCanvas: TDpiCanvas; X, Y, Width, Height: Integer; 799 SrcCanvas: TDpiCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; 800 begin 801 Result := DpiBitBlt(DestCanvas.Handle, X, Y, Width, Height, SrcCanvas.Handle, XSrc, YSrc, Rop); 802 end; 803 804 function DpiBitCanvas(Dest: TDpiCanvas; DestRect: TRect; Src: TDpiCanvas; 805 SrcPos: TPoint; Rop: DWORD): Boolean; 806 begin 807 Result := DpiBitCanvas(Dest, DestRect.Left, DestRect.Top, DestRect.Width, DestRect.Height, 808 Src, SrcPos.X, SrcPos.Y, Rop); 809 end; 810 811 function BitBltBitmap(Dest: TDpiBitmap; X, Y, Width, Height: Integer; 812 Src: TDpiBitmap; XSrc, YSrc: Integer; Rop: DWORD): Boolean; 813 begin 814 Result := DpiBitCanvas(Dest.Canvas, X, Y, Width, Height, Src.Canvas, XSrc, YSrc, Rop); 815 end; 816 817 function BitBltBitmap(Dest: TDpiBitmap; DestRect: TRect; Src: TDpiBitmap; 818 SrcPos: TPoint; Rop: DWORD): Boolean; 819 begin 820 Result := DpiBitCanvas(Dest.Canvas, DestRect, Src.Canvas, SrcPos, Rop); 825 821 end; 826 822 … … 904 900 end else 905 901 Frame(ca, x - 1, y - 1, x + Width, y + Height, $000000, $000000); 906 DpiBitBlt(ca.Handle, x, y, Width, Height, Src.Canvas.Handle, xSrc, ySrc, 907 SRCCOPY); 902 DpiBitCanvas(ca, x, y, Width, Height, Src.Canvas, xSrc, ySrc); 908 903 end; 909 904 … … 920 915 Height := ScaleToVcl(Height); 921 916 dst.BeginUpdate; 922 DstPtr .Init(dst, x0, y0);917 DstPtr := PixelPointer(dst, x0, y0); 923 918 for y := -DpiGlowRange + 1 to Height - 1 + DpiGlowRange - 1 do begin 924 919 for x := -DpiGlowRange + 1 to Width - 1 + DpiGlowRange - 1 do begin … … 946 941 if r = 0 then 947 942 r := 1; 948 if r < GlowRange then943 if r < DpiGlowRange then 949 944 for ch := 0 to 2 do 950 945 DstPtr.Pixel^.Planes[2 - ch] := … … 991 986 $FF * intensity div $FF shl 16; 992 987 end; 993 DpiBit Blt(GrExt[HGrSystem].Mask.Canvas.Handle, 77, 47, 10, 10,994 GrExt[HGrSystem].Mask.Canvas .Handle, 66, 47, SRCCOPY);988 DpiBitCanvas(GrExt[HGrSystem].Mask.Canvas, 77, 47, 10, 10, 989 GrExt[HGrSystem].Mask.Canvas, 66, 47); 995 990 end; 996 991 … … 999 994 Assert((Left + xOffset >= 0) and (Left + xOffset + Width <= wMainTexture) and 1000 995 (Top + yOffset >= 0) and (Top + yOffset + Height <= hMainTexture)); 1001 DpiBitBlt(ca.Handle, Left, Top, Width, Height, MainTexture.Image.Canvas.Handle, 1002 Left + xOffset, Top + yOffset, SRCCOPY); 996 DpiBitCanvas(ca, Left, Top, Width, Height, MainTexture.Image.Canvas, 997 Left + xOffset, Top + yOffset); 998 end; 999 1000 procedure Fill(Canvas: TDpiCanvas; Rect: TRect; Offset: TPoint); 1001 begin 1002 Fill(Canvas, Rect.Left, Rect.Top, Rect.Width, Rect.Height, Offset.X, Offset.Y); 1003 1003 end; 1004 1004 … … 1021 1021 begin 1022 1022 for I := 0 to (x1 - xm) div wMainTexture - 1 do 1023 DpiBit Blt(ca.Handle, xm + I * wMainTexture, y0, wMainTexture, y1 - y0,1024 MainTexture.Image.Canvas .Handle, 0, hMainTexture div 2 + Band(I) *1025 (y1 - y0) , SRCCOPY);1026 DpiBit Blt(ca.Handle, xm + ((x1 - xm) div wMainTexture) * wMainTexture, y0,1023 DpiBitCanvas(ca, xm + I * wMainTexture, y0, wMainTexture, y1 - y0, 1024 MainTexture.Image.Canvas, 0, hMainTexture div 2 + Band(I) * 1025 (y1 - y0)); 1026 DpiBitCanvas(ca, xm + ((x1 - xm) div wMainTexture) * wMainTexture, y0, 1027 1027 x1 - (xm + ((x1 - xm) div wMainTexture) * wMainTexture), y1 - y0, 1028 MainTexture.Image.Canvas .Handle, 0, hMainTexture div 2 + Band(1029 (x1 - xm) div wMainTexture) * (y1 - y0) , SRCCOPY);1028 MainTexture.Image.Canvas, 0, hMainTexture div 2 + Band( 1029 (x1 - xm) div wMainTexture) * (y1 - y0)); 1030 1030 for I := 0 to (xm - x0) div wMainTexture - 1 do 1031 DpiBit Blt(ca.Handle, xm - (I + 1) * wMainTexture, y0, wMainTexture, y1 - y0,1032 MainTexture.Image.Canvas .Handle, 0, hMainTexture div 2 +1033 Band(-I - 1) * (y1 - y0) , SRCCOPY);1034 DpiBit Blt(ca.Handle, x0, y0, xm - ((xm - x0) div wMainTexture) *1035 wMainTexture - x0, y1 - y0, MainTexture.Image.Canvas .Handle,1031 DpiBitCanvas(ca, xm - (I + 1) * wMainTexture, y0, wMainTexture, y1 - y0, 1032 MainTexture.Image.Canvas, 0, hMainTexture div 2 + 1033 Band(-I - 1) * (y1 - y0)); 1034 DpiBitCanvas(ca, x0, y0, xm - ((xm - x0) div wMainTexture) * 1035 wMainTexture - x0, y1 - y0, MainTexture.Image.Canvas, 1036 1036 ((xm - x0) div wMainTexture + 1) * wMainTexture - (xm - x0), 1037 hMainTexture div 2 + Band(-(xm - x0) div wMainTexture - 1) * (y1 - y0) , SRCCOPY);1037 hMainTexture div 2 + Band(-(xm - x0) div wMainTexture - 1) * (y1 - y0)); 1038 1038 end; 1039 1039 … … 1065 1065 if x1cut < 0 then 1066 1066 x1cut := 0; 1067 DpiBit Blt(ca.Handle, x * Texture.Width + x0cut - xOffset,1067 DpiBitCanvas(ca, x * Texture.Width + x0cut - xOffset, 1068 1068 y * Texture.Height + y0cut - yOffset, Texture.Width - x0cut - x1cut, 1069 Texture.Height - y0cut - y1cut, Texture.Canvas.Handle, x0cut, 1070 y0cut, SRCCOPY); 1069 Texture.Height - y0cut - y1cut, Texture.Canvas, x0cut, y0cut); 1071 1070 end; 1072 1071 end; … … 1087 1086 procedure Corner(ca: TDpiCanvas; x, y, Kind: Integer; const T: TTexture); 1088 1087 begin 1089 { DpiBit Blt(ca.Handle,x,y,8,8,GrExt[T.HGr].Mask.Canvas.Handle,1088 { DpiBitCanvas(ca,x,y,8,8,GrExt[T.HGr].Mask.Canvas, 1090 1089 T.xGr+29+Kind*9,T.yGr+89,SRCAND); 1091 DpiBit Blt(ca.Handle,x,y,8,8,GrExt[T.HGr].Data.Canvas.Handle,1090 DpiBitCanvas(ca,x,y,8,8,GrExt[T.HGr].Data.Canvas, 1092 1091 T.xGr+29+Kind*9,T.yGr+89,SRCPAINT); } 1093 1092 end; … … 1097 1096 procedure PaintIcon(x, y, Kind: Integer); 1098 1097 begin 1099 DpiBit Blt(ca.Handle, x, y + 6, 10, 10, GrExt[HGrSystem].Mask.Canvas.Handle,1098 DpiBitCanvas(ca, x, y + 6, 10, 10, GrExt[HGrSystem].Mask.Canvas, 1100 1099 66 + Kind mod 11 * 11, 115 + Kind div 11 * 11, SRCAND); 1101 DpiBit Blt(ca.Handle, x, y + 6, 10, 10, GrExt[HGrSystem].Data.Canvas.Handle,1100 DpiBitCanvas(ca, x, y + 6, 10, 10, GrExt[HGrSystem].Data.Canvas, 1102 1101 66 + Kind mod 11 * 11, 115 + Kind div 11 * 11, SRCPAINT); 1103 1102 end; … … 1321 1320 for i := 0 to val mod 10 - 1 do 1322 1321 begin 1323 DpiBit Blt(Handle, xIcon + 4 + i * (14 * ld div sd), yIcon + 2 + 1, 14,1324 14, GrExt[HGrSystem].Mask.Canvas .Handle, 67 + Kind mod 8 * 15,1322 DpiBitCanvas(dst.Canvas, xIcon + 4 + i * (14 * ld div sd), yIcon + 2 + 1, 14, 1323 14, GrExt[HGrSystem].Mask.Canvas, 67 + Kind mod 8 * 15, 1325 1324 70 + Kind div 8 * 15, SRCAND); 1326 1325 Sprite(dst, HGrSystem, xIcon + 3 + i * (14 * ld div sd), yIcon + 2, … … 1329 1328 for i := 0 to val div 10 - 1 do 1330 1329 begin 1331 DpiBit Blt(dst.Canvas.Handle, xIcon + 4 + (val mod 10) *1330 DpiBitCanvas(dst.Canvas, xIcon + 4 + (val mod 10) * 1332 1331 (14 * ld div sd) + i * (14 * ld div sd), yIcon + 3, 14, 14, 1333 GrExt[HGrSystem].Mask.Canvas .Handle, 67 + 7 mod 8 * 15,1332 GrExt[HGrSystem].Mask.Canvas, 67 + 7 mod 8 * 15, 1334 1333 70 + 7 div 8 * 15, SRCAND); 1335 1334 Sprite(dst, HGrSystem, xIcon + 3 + (val mod 10) * … … 1354 1353 for i := 0 to val div 10 - 1 do 1355 1354 begin 1356 DpiBit Blt(Handle, xIcon + 4 + i * (14 * ld div sd), yIcon + 3, 14, 14,1357 GrExt[HGrSystem].Mask.Canvas .Handle, 67 + Kind mod 8 * 15,1355 DpiBitCanvas(dst.Canvas, xIcon + 4 + i * (14 * ld div sd), yIcon + 3, 14, 14, 1356 GrExt[HGrSystem].Mask.Canvas, 67 + Kind mod 8 * 15, 1358 1357 70 + Kind div 8 * 15, SRCAND); 1359 1358 Sprite(dst, HGrSystem, xIcon + 3 + i * (14 * ld div sd), yIcon + 2, … … 1362 1361 for i := 0 to val mod 10 - 1 do 1363 1362 begin 1364 DpiBit Blt(dst.Canvas.Handle, xIcon + 4 + (val div 10) *1363 DpiBitCanvas(dst.Canvas, xIcon + 4 + (val div 10) * 1365 1364 (14 * ld div sd) + i * (10 * ld div sd), yIcon + 7, 10, 10, 1366 GrExt[HGrSystem].Mask.Canvas .Handle, 66 + Kind mod 11 * 11,1365 GrExt[HGrSystem].Mask.Canvas, 66 + Kind mod 11 * 11, 1367 1366 115 + Kind div 11 * 11, SRCAND); 1368 1367 Sprite(dst, HGrSystem, xIcon + 3 + (val div 10) * … … 1399 1398 begin 1400 1399 for i := 0 to pos div 8 - 1 do 1401 DpiBit Blt(Handle, x + i * 8, y, 8, 7,1402 GrExt[HGrSystem].Data.Canvas .Handle, 104, 9 + 8 * Kind, SRCCOPY);1403 DpiBit Blt(Handle, x + 8 * (pos div 8), y, pos - 8 * (pos div 8), 7,1404 GrExt[HGrSystem].Data.Canvas .Handle, 104, 9 + 8 * Kind, SRCCOPY);1400 DpiBitCanvas(ca, x + i * 8, y, 8, 7, 1401 GrExt[HGrSystem].Data.Canvas, 104, 9 + 8 * Kind); 1402 DpiBitCanvas(ca, x + 8 * (pos div 8), y, pos - 8 * (pos div 8), 7, 1403 GrExt[HGrSystem].Data.Canvas, 104, 9 + 8 * Kind); 1405 1404 if Growth > 0 then 1406 1405 begin 1407 1406 for i := 0 to Growth div 8 - 1 do 1408 DpiBit Blt(Handle, x + pos + i * 8, y, 8, 7,1409 GrExt[HGrSystem].Data.Canvas .Handle, 112, 9 + 8 * Kind, SRCCOPY);1410 DpiBit Blt(Handle, x + pos + 8 * (Growth div 8), y,1411 Growth - 8 * (Growth div 8), 7, GrExt[HGrSystem].Data.Canvas .Handle,1412 112, 9 + 8 * Kind , SRCCOPY);1407 DpiBitCanvas(ca, x + pos + i * 8, y, 8, 7, 1408 GrExt[HGrSystem].Data.Canvas, 112, 9 + 8 * Kind); 1409 DpiBitCanvas(ca, x + pos + 8 * (Growth div 8), y, 1410 Growth - 8 * (Growth div 8), 7, GrExt[HGrSystem].Data.Canvas, 1411 112, 9 + 8 * Kind); 1413 1412 end 1414 1413 else if Growth < 0 then 1415 1414 begin 1416 1415 for i := 0 to -Growth div 8 - 1 do 1417 DpiBit Blt(Handle, x + pos + i * 8, y, 8, 7,1418 GrExt[HGrSystem].Data.Canvas .Handle, 104, 1, SRCCOPY);1419 DpiBit Blt(Handle, x + pos + 8 * (-Growth div 8), y, -Growth -1416 DpiBitCanvas(ca, x + pos + i * 8, y, 8, 7, 1417 GrExt[HGrSystem].Data.Canvas, 104, 1); 1418 DpiBitCanvas(ca, x + pos + 8 * (-Growth div 8), y, -Growth - 1420 1419 8 * (-Growth div 8), 7, 1421 GrExt[HGrSystem].Data.Canvas .Handle, 104, 1, SRCCOPY);1420 GrExt[HGrSystem].Data.Canvas, 104, 1); 1422 1421 end; 1423 1422 Brush.Color := $000000; … … 1444 1443 procedure PaintLogo(ca: TDpiCanvas; x, y, clLight, clShade: Integer); 1445 1444 begin 1446 BitBltCanvas(LogoBuffer.Canvas, 0, 0, wLogo, hLogo, ca, x, 1447 y, SRCCOPY); 1445 // TODO: Explicitly clear background to black but in fact BitBlt SRCCOPY should do it 1446 LogoBuffer.Canvas.FillRect(0, 0, LogoBuffer.Width, LogoBuffer.Height); 1447 DpiBitCanvas(LogoBuffer.Canvas, 0, 0, wLogo, hLogo, ca, x, y); 1448 1448 ImageOp_BCC(LogoBuffer, Templates, 0, 0, 1, 1, wLogo, hLogo, 1449 1449 clLight, clShade); 1450 DpiBitBlt(ca.Handle, x, y, wLogo, hLogo, LogoBuffer.Canvas.Handle, 0, 1451 0, SRCCOPY); 1450 DpiBitCanvas(ca, x, y, wLogo, hLogo, LogoBuffer.Canvas, 0, 0); 1452 1451 end; 1453 1452 … … 1457 1456 with MainTexture do begin 1458 1457 MainTextureAge := Age; 1459 LoadGraphicFile(Image, HomeDir + 'Graphics'+ DirectorySeparator +1458 LoadGraphicFile(Image, GetGraphicsDir + DirectorySeparator + 1460 1459 'Texture' + IntToStr(Age + 1) + '.jpg'); 1461 1460 clBevelLight := Colors.Canvas.Pixels[clkAge0 + Age, cliBevelLight]; … … 1473 1472 end; 1474 1473 1475 { TPixelPointer }1476 1477 procedure TPixelPointer.NextLine; inline;1478 begin1479 Line := Pointer(Line) + BytesPerLine;1480 Pixel := Line;1481 end;1482 1483 procedure TPixelPointer.NextPixel; inline;1484 begin1485 Pixel := Pointer(Pixel) + BytesPerPixel;1486 end;1487 1488 procedure TPixelPointer.SetXY(X, Y: Integer); inline;1489 begin1490 Line := Pointer(Base) + Y * BytesPerLine;1491 SetX(X);1492 end;1493 1494 procedure TPixelPointer.SetX(X: Integer); inline;1495 begin1496 Pixel := Pointer(Line) + X * BytesPerPixel;1497 end;1498 1499 procedure TPixelPointer.Init(Bitmap: TDpiRasterImage; BaseX: Integer = 0;1500 BaseY: integer = 0); inline;1501 begin1502 BytesPerLine := Bitmap.RawImage.Description.BytesPerLine;1503 BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3;1504 Base := PPixel32(Bitmap.RawImage.Data + BaseX * BytesPerPixel + BaseY * BytesPerLine);1505 SetXY(0, 0);1506 end;1507 1508 1474 procedure LoadPhrases; 1509 1475 begin 1510 if Phrases = nil then 1511 Phrases := TStringTable.Create; 1512 if Phrases2 = nil then 1513 Phrases2 := TStringTable.Create; 1476 if Phrases = nil then Phrases := TStringTable.Create; 1477 if Phrases2 = nil then Phrases2 := TStringTable.Create; 1514 1478 Phrases2FallenBackToEnglish := False; 1515 1479 if FileExists(LocalizedFilePath('Language.txt')) then 1516 1480 begin 1517 Phrases. loadfromfile(LocalizedFilePath('Language.txt'));1481 Phrases.LoadFromFile(LocalizedFilePath('Language.txt')); 1518 1482 if FileExists(LocalizedFilePath('Language2.txt')) then 1519 Phrases2. loadfromfile(LocalizedFilePath('Language2.txt'))1483 Phrases2.LoadFromFile(LocalizedFilePath('Language2.txt')) 1520 1484 else 1521 1485 begin 1522 Phrases2. loadfromfile(HomeDir + 'Language2.txt');1486 Phrases2.LoadFromFile(HomeDir + 'Language2.txt'); 1523 1487 Phrases2FallenBackToEnglish := True; 1524 1488 end; … … 1526 1490 else 1527 1491 begin 1528 Phrases.loadfromfile(HomeDir + 'Language.txt'); 1529 Phrases2.loadfromfile(HomeDir + 'Language2.txt'); 1530 end; 1531 1532 if Sounds = nil then 1533 Sounds := TStringTable.Create; 1534 if not Sounds.loadfromfile(HomeDir + 'Sounds' + DirectorySeparator + 'sound.txt') then 1492 Phrases.LoadFromFile(HomeDir + 'Language.txt'); 1493 Phrases2.LoadFromFile(HomeDir + 'Language2.txt'); 1494 end; 1495 1496 if Sounds = nil then Sounds := TStringTable.Create; 1497 if not Sounds.LoadFromFile(GetSoundsDir + DirectorySeparator + 'sound.txt') then 1535 1498 begin 1536 1499 FreeAndNil(Sounds); 1537 1500 end; 1501 end; 1502 1503 procedure Texturize(Dest, Texture: TDpiBitmap; TransparentColor: Integer); 1504 var 1505 SrcPixel, DstPixel: TPixelPointer; 1506 X, Y: Integer; 1507 TexWidth, TexHeight: Integer; 1508 begin 1509 // texturize background 1510 Dest.BeginUpdate; 1511 TexWidth := ScaleToVcl(Texture.Width); 1512 TexHeight := ScaleToVcl(Texture.Height); 1513 DstPixel := PixelPointer(Dest); 1514 SrcPixel := PixelPointer(Texture); 1515 for Y := 0 to ScaleToVcl(Dest.Height) - 1 do begin 1516 for X := 0 to ScaleToVcl(Dest.Width) - 1 do begin 1517 if (DstPixel.Pixel^.ARGB and $FFFFFF) = TransparentColor then begin 1518 SrcPixel.SetXY(X mod TexWidth, Y mod TexHeight); 1519 DstPixel.Pixel^.B := SrcPixel.Pixel^.B; 1520 DstPixel.Pixel^.G := SrcPixel.Pixel^.G; 1521 DstPixel.Pixel^.R := SrcPixel.Pixel^.R; 1522 end; 1523 DstPixel.NextPixel; 1524 end; 1525 DstPixel.NextLine; 1526 end; 1527 Dest.EndUpdate; 1528 end; 1529 1530 procedure DarkenImage(Bitmap: TDpiBitmap; Change: Integer); 1531 var 1532 x, y: integer; 1533 PicturePixel: TPixelPointer; 1534 begin 1535 Bitmap.BeginUpdate; 1536 PicturePixel := PixelPointer(Bitmap); 1537 for y := 0 to ScaleToVcl(Bitmap.Height) - 1 do begin 1538 for x := 0 to ScaleToVcl(Bitmap.Width) - 1 do begin 1539 PicturePixel.Pixel^.B := Max(PicturePixel.Pixel^.B - Change, 0); 1540 PicturePixel.Pixel^.G := Max(PicturePixel.Pixel^.G - Change, 0); 1541 PicturePixel.Pixel^.R := Max(PicturePixel.Pixel^.R - Change, 0); 1542 PicturePixel.NextPixel; 1543 end; 1544 PicturePixel.NextLine; 1545 end; 1546 Bitmap.EndUpdate; 1538 1547 end; 1539 1548 … … 1547 1556 P: integer; 1548 1557 begin 1549 for Section := Low(TFontType) to High(TFontType) do1550 UniFont[Section] := TDpiFont.Create;1551 1552 1558 Section := ftNormal; 1553 1559 AssignFile(FontScript, LocalizedFilePath('Fonts.txt')); 1554 1560 try 1555 Reset( fontscript);1556 while not E OF(FontScript) do begin1561 Reset(FontScript); 1562 while not Eof(FontScript) do begin 1557 1563 ReadLn(FontScript, s); 1558 1564 if s <> '' then 1559 1565 if s[1] = '#' then begin 1560 1566 s := TrimRight(s); 1561 if s = '#SMALL' then 1562 Section := ftSmall 1563 else if s = '#TINY' then 1564 Section := ftTiny 1565 else if s = '#CAPTION' then 1566 Section := ftCaption 1567 else if s = '#BUTTON' then 1568 Section := ftButton 1569 else 1570 Section := ftNormal; 1567 if s = '#SMALL' then Section := ftSmall 1568 else if s = '#TINY' then Section := ftTiny 1569 else if s = '#CAPTION' then Section := ftCaption 1570 else if s = '#BUTTON' then Section := ftButton 1571 else Section := ftNormal; 1571 1572 end else begin 1572 1573 p := Pos(',', s); 1573 1574 if p > 0 then begin 1574 UniFont[ Section].Name := Trim(Copy(s, 1, p - 1));1575 UniFont[section].Name := Trim(Copy(s, 1, p - 1)); 1575 1576 Size := 0; 1576 1577 for i := p + 1 to Length(s) do … … 1585 1586 // 0.8 constant is compensation for Lazarus as size of fonts against Delphi differs 1586 1587 UniFont[section].Size := 1587 Round( Size * Screen.PixelsPerInch / UniFont[section].PixelsPerInch);1588 Round(size * DpiScreen.PixelsPerInch / UniFont[section].PixelsPerInch * 0.8); 1588 1589 end; 1589 1590 end; … … 1615 1616 end; 1616 1617 1618 procedure LoadAssets; 1619 begin 1620 LoadPhrases; 1621 LoadFonts; 1622 LoadGraphicFile(Templates, GetGraphicsDir + DirectorySeparator + 1623 'Templates.png', gfNoGamma); 1624 LoadGraphicFile(Colors, GetGraphicsDir + DirectorySeparator + 'Colors.png'); 1625 LoadGraphicFile(Paper, GetGraphicsDir + DirectorySeparator + 'Paper.jpg'); 1626 LoadGraphicFile(BigImp, GetGraphicsDir + DirectorySeparator + 'Icons.png'); 1627 end; 1628 1617 1629 procedure UnitInit; 1618 1630 var 1619 Reg: TRegistry; 1620 begin 1621 Reg := TRegistry.Create; 1622 with Reg do 1623 try 1624 OpenKey(AppRegistryKey, True); 1625 if ValueExists('Gamma') then 1626 Gamma := ReadInteger('Gamma') 1627 else 1628 begin 1629 Gamma := 100; 1630 WriteInteger('Gamma', Gamma); 1631 end; 1632 if ValueExists('Locale') then 1633 LocaleCode := ReadString('Locale') 1634 else 1635 LocaleCode := ''; 1636 finally 1637 Free; 1638 end; 1639 1640 if Gamma <> 100 then InitGammaLookupTable; 1631 Section: TFontType; 1632 begin 1633 Gamma := 100; 1634 InitGammaLookupTable; 1641 1635 1642 1636 {$IFDEF WINDOWS} … … 1645 1639 {$ENDIF} 1646 1640 1647 LoadPhrases;1648 1649 1641 LogoBuffer := TDpiBitmap.Create; 1650 1642 LogoBuffer.PixelFormat := pf24bit; 1651 1643 LogoBuffer.SetSize(wBBook, hBBook); 1652 1644 1653 LoadFonts; 1645 for Section := Low(TFontType) to High(TFontType) do 1646 UniFont[Section] := TDpiFont.Create; 1654 1647 1655 1648 nGrExt := 0; … … 1658 1651 Templates := TDpiBitmap.Create; 1659 1652 Templates.PixelFormat := pf24bit; 1660 LoadGraphicFile(Templates, HomeDir + 'Graphics' + DirectorySeparator +1661 'Templates.png', gfNoGamma);1662 1653 Colors := TDpiBitmap.Create; 1663 1654 Colors.PixelFormat := pf24bit; 1664 LoadGraphicFile(Colors, HomeDir + 'Graphics' + DirectorySeparator + 'Colors.png');1665 1655 Paper := TDpiBitmap.Create; 1666 1656 Paper.PixelFormat := pf24bit; 1667 LoadGraphicFile(Paper, HomeDir + 'Graphics' + DirectorySeparator + 'Paper.jpg');1668 1657 BigImp := TDpiBitmap.Create; 1669 1658 BigImp.PixelFormat := pf24bit; 1670 LoadGraphicFile(BigImp, HomeDir + 'Graphics' + DirectorySeparator + 'Icons.png');1671 1659 MainTexture.Image := TDpiBitmap.Create; 1672 1660 MainTextureAge := -2; … … 1674 1662 InitOrnamentDone := False; 1675 1663 GenerateNames := True; 1664 1665 LoadAssets; 1676 1666 end; 1677 1667 1678 1668 procedure UnitDone; 1679 1669 var 1680 Reg: TRegistry;1681 1670 I: integer; 1682 1671 begin 1683 Reg := TRegistry.Create;1684 with Reg do1685 try1686 OpenKey(AppRegistryKey, True);1687 WriteString('Locale', LocaleCode);1688 WriteInteger('Gamma', Gamma);1689 finally1690 Free;1691 end;1692 1693 1672 RestoreResolution; 1694 1673 for I := 0 to nGrExt - 1 do begin … … 1702 1681 FreeAndNil(Phrases); 1703 1682 FreeAndNil(Phrases2); 1704 if Sounds <> nil then1705 FreeAndNil(Sounds);1706 1683 FreeAndNil(LogoBuffer); 1707 1684 FreeAndNil(BigImp);
Note:
See TracChangeset
for help on using the changeset viewer.