Changeset 331 for trunk


Ignore:
Timestamp:
Mar 26, 2021, 3:24:15 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Player border tile preparation code for bitmap color replacement moved to ScreenTools.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Help.pas

    r330 r331  
    771771                  xxt * 2 - 8, yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
    772772                  3 + yyt + 2 * (yyt * 3 + 1));
    773                 srcno := 45
     773                srcno := 45;
    774774              end
    775775              else
  • trunk/LocalPlayer/IsoEngine.pas

    r330 r331  
    10931093  var
    10941094    dx, dy: integer;
    1095     PixelPtr: TPixelPointer;
    10961095  begin
    10971096    if ShowBorder and (Loc >= 0) and (Loc < G.lx * G.ly) and
     
    11041103            yyt * 2, HGrTerrain.Data.Canvas,
    11051104            1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1));
    1106           Borders.BeginUpdate;
    1107           PixelPtr := PixelPointer(Borders, ScaleToNative(0), ScaleToNative(p1 * (yyt * 2)));
    1108           for dy := 0 to ScaleToNative(yyt * 2) - 1 do begin
    1109             for dx := 0 to ScaleToNative(xxt * 2) - 1 do begin
    1110               if PixelPtr.Pixel^.B = 99 then begin
    1111                 PixelPtr.Pixel^.B := Tribe[p1].Color shr 16 and $FF;
    1112                 PixelPtr.Pixel^.G := Tribe[p1].Color shr 8 and $FF;
    1113                 PixelPtr.Pixel^.R := Tribe[p1].Color and $FF;
    1114               end;
    1115               PixelPtr.NextPixel;
    1116             end;
    1117             PixelPtr.NextLine;
    1118           end;
    1119           Borders.EndUpdate;
     1105          BitmapReplaceColor(Borders, 0, p1 * (yyt * 2), xxt * 2, yyt * 2, $636363, Tribe[p1].Color);
    11201106          BordersOK^ := BordersOK^ or 1 shl p1;
    11211107        end;
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r323 r331  
    4242function LoadGraphicSet2(const Name: string): TGraphicSet;
    4343procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     44procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor);
    4445procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
    4546  overload;
     
    567568end;
    568569
     570procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor);
     571var
     572  XX, YY: Integer;
     573  PixelPtr: TPixelPointer;
     574begin
     575  Dst.BeginUpdate;
     576  PixelPtr := PixelPointer(Dst, ScaleToNative(X), ScaleToNative(Y));
     577  for YY := 0 to ScaleToNative(Height) - 1 do begin
     578    for XX := 0 to ScaleToNative(Width) - 1 do begin
     579      if PixelPtr.Pixel^.RGB = SwapRedBlue(OldColor) then begin
     580        PixelPtr.Pixel^.RGB := SwapRedBlue(NewColor);
     581      end;
     582      PixelPtr.NextPixel;
     583    end;
     584    PixelPtr.NextLine;
     585  end;
     586  Dst.EndUpdate;
     587end;
     588
    569589procedure MakeBlue(Dst: TBitmap; X, Y, Width, Height: Integer);
    570590var
  • trunk/Packages/CevoComponents/UPixelPointer.pas

    r230 r331  
    99  TColor32 = type Cardinal;
    1010  TColor32Component = (ccBlue, ccGreen, ccRed, ccAlpha);
     11
     12  { TPixel32 }
     13
    1114  TPixel32 = packed record
     15  private
     16    function GetRGB: Cardinal;
     17    procedure SetRGB(AValue: Cardinal);
     18  public
     19    property RGB: Cardinal read GetRGB write SetRGB;
    1220    case Integer of
    1321      0: (B, G, R, A: Byte);
     
    3745
    3846  function PixelPointer(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; inline;
    39 
     47  function SwapRedBlue(Color: TColor32): TColor32;
    4048
    4149implementation
     50
     51{ TPixel32 }
     52
     53function TPixel32.GetRGB: Cardinal;
     54begin
     55  Result := ARGB and $ffffff;
     56end;
     57
     58procedure TPixel32.SetRGB(AValue: Cardinal);
     59begin
     60  R := (AValue shr 16) and $ff;
     61  G := (AValue shr 8) and $ff;
     62  B := (AValue shr 0) and $ff;
     63end;
    4264
    4365{ TPixelPointer }
     
    86108end;
    87109
     110function SwapRedBlue(Color: TColor32): TColor32;
     111begin
     112  Result := (Color and $ff00ff00) or ((Color and $ff) shl 16) or ((Color shr 16) and $ff);
     113end;
     114
    88115
    89116end.
Note: See TracChangeset for help on using the changeset viewer.