Changeset 69


Ignore:
Timestamp:
Feb 3, 2020, 12:24:17 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Draw to Canvas through TMetaCanvas class.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Common.lpk

    r8 r69  
    4040    <License Value="GNU/GPL"/>
    4141    <Version Minor="7"/>
    42     <Files Count="24">
     42    <Files Count="26">
    4343      <Item1>
    4444        <Filename Value="StopWatch.pas"/>
     
    140140      </Item22>
    141141      <Item23>
    142         <Filename Value="ULanguages.pas"/>
    143         <UnitName Value="ULanguages"/>
     142        <Filename Value="UMetaCanvas.pas"/>
     143        <UnitName Value="UMetaCanvas"/>
    144144      </Item23>
    145145      <Item24>
     146        <Filename Value="UGeometric.pas"/>
     147        <UnitName Value="UGeometric"/>
     148      </Item24>
     149      <Item25>
    146150        <Filename Value="UTranslator.pas"/>
    147151        <HasRegisterProc Value="True"/>
    148152        <UnitName Value="UTranslator"/>
    149       </Item24>
     153      </Item25>
     154      <Item26>
     155        <Filename Value="ULanguages.pas"/>
     156        <UnitName Value="ULanguages"/>
     157      </Item26>
    150158    </Files>
    151159    <i18n>
  • trunk/Packages/Common/Common.pas

    r8 r69  
    1212  UMemory, UResetableThread, UPool, ULastOpenedList, URegistry,
    1313  UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort,
    14   UPersistentForm, UFindFile, UScaleDPI, UTheme, UStringTable, ULanguages,
    15   UTranslator, LazarusPackageIntf;
     14  UPersistentForm, UFindFile, UScaleDPI, UTheme, UStringTable, UMetaCanvas,
     15  UGeometric, UTranslator, ULanguages, LazarusPackageIntf;
    1616
    1717implementation
  • trunk/UGame.pas

    r68 r69  
    195195
    196196uses
    197   UCore;
     197  UCore, UMetaCanvas;
    198198
    199199procedure Translate;
     
    618618  TileCenter: TPoint;
    619619  S: TPoint;
    620 begin
     620  MetaCanvas: TMetaCanvas;
     621begin
     622  MetaCanvas := TMetaCanvas.Create;
     623
    621624  TopBarHeight := ScaleY(24, 96);
    622   Canvas.Brush.Style := bsSolid;
    623   Canvas.Brush.Color := Core.ThemeManager1.Theme.ColorControl;
    624   Canvas.FillRect(0, 0, Canvas.Width, Canvas.Height);
     625  MetaCanvas.Brush.Style := bsSolid;
     626  MetaCanvas.Brush.Color := Core.ThemeManager1.Theme.ColorControl;
     627  MetaCanvas.FillRect(0, 0, MetaCanvas.Width, MetaCanvas.Height);
    625628
    626629  ValueStr := SScore + ': ' + IntToStr(Score);
    627   Canvas.Font.Color := Core.ThemeManager1.Theme.ColorControlText;
    628   Canvas.Font.Height := Trunc(TopBarHeight * 0.7);
    629   Canvas.TextOut(ScaleY(16, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr);
     630  MetaCanvas.Font.Color := Core.ThemeManager1.Theme.ColorControlText;
     631  MetaCanvas.Font.Height := Trunc(TopBarHeight * 0.7);
     632  MetaCanvas.TextOut(ScaleY(16, 96), (TopBarHeight - MetaCanvas.TextHeight(ValueStr)) div 2, ValueStr);
    630633
    631634  ValueStr := STopScore + ': ' + IntToStr(TopScore);
    632   Canvas.Font.Color := Core.ThemeManager1.Theme.ColorControlText;
    633   Canvas.Font.Height := Trunc(TopBarHeight * 0.7);
    634   Canvas.TextOut(ScaleY(136, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr);
     635  MetaCanvas.Font.Color := Core.ThemeManager1.Theme.ColorControlText;
     636  MetaCanvas.Font.Height := Trunc(TopBarHeight * 0.7);
     637  MetaCanvas.TextOut(ScaleY(136, 96), (TopBarHeight - MetaCanvas.TextHeight(ValueStr)) div 2, ValueStr);
    635638
    636639  // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows.
     
    647650  TileMargin := Round(Frame.Width / Board.Size.X * 0.03);
    648651
    649   Canvas.Brush.Style := bsSolid;
    650   Canvas.Brush.Color := clGray;
    651   Canvas.Pen.Style := psClear;
    652   Canvas.RoundRect(Frame, ScaleX(Frame.Width div (20 * Board.Size.X), 96),
     652  MetaCanvas.Brush.Style := bsSolid;
     653  MetaCanvas.Brush.Color := clGray;
     654  MetaCanvas.Pen.Style := psClear;
     655  MetaCanvas.RoundRect(Frame, ScaleX(Frame.Width div (20 * Board.Size.X), 96),
    653656    ScaleY(Frame.Height div (20 * Board.Size.Y), 96));
    654657
     
    657660  TileSize := Point(Frame.Width div Board.Size.X, Frame.Height div Board.Size.Y);
    658661
    659   Canvas.Font.Color := clBlack;
     662  MetaCanvas.Font.Color := clBlack;
    660663
    661664  // Draw static tiles
    662665  for Y := 0 to Board.Size.Y - 1 do
    663666    for X := 0 to Board.Size.X - 1 do begin
    664       if (Board.Tiles[Y, X].Action <> taNone) then Canvas.Brush.Color := GetTileColor(0)
    665         else Canvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
    666       Canvas.Brush.Style := bsSolid;
     667      if (Board.Tiles[Y, X].Action <> taNone) then MetaCanvas.Brush.Color := GetTileColor(0)
     668        else MetaCanvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
     669      MetaCanvas.Brush.Style := bsSolid;
    667670      TileRect := Bounds(
    668671        Frame.Left + X * TileSize.X + TileMargin,
    669672        Frame.Top + Y * TileSize.Y + TileMargin,
    670673        TileSize.X - 2 * TileMargin, TileSize.Y - 2 * TileMargin);
    671       RenderTile(Canvas, Board.Tiles[Y, X], TileRect, Board.Tiles[Y, X].Action = taNone);
     674      RenderTile(MetaCanvas, Board.Tiles[Y, X], TileRect, Board.Tiles[Y, X].Action = taNone);
    672675    end;
    673676
     
    676679    for X := 0 to Board.Size.X - 1 do
    677680    if Board.Tiles[Y, X].Action = taMove then begin
    678       Canvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
    679       Canvas.Brush.Style := bsSolid;
     681      MetaCanvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
     682      MetaCanvas.Brush.Style := bsSolid;
    680683      TileRect := Bounds(
    681684        Frame.Left + X * TileSize.X + Trunc(Board.Tiles[Y, X].Shift.X / 100 * TileSize.X + TileMargin),
    682685        Frame.Top + Y * TileSize.Y + Trunc(Board.Tiles[Y, X].Shift.Y / 100 * TileSize.Y + TileMargin),
    683686        TileSize.X - 2 * TileMargin, TileSize.Y - 2 * TileMargin);
    684       RenderTile(Canvas, Board.Tiles[Y, X], TileRect, True);
     687      RenderTile(MetaCanvas, Board.Tiles[Y, X], TileRect, True);
    685688    end;
    686689
     
    689692    for X := 0 to Board.Size.X - 1 do
    690693    if Board.Tiles[Y, X].Action = taAppear then begin
    691       Canvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
    692       Canvas.Brush.Style := bsSolid;
     694      MetaCanvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
     695      MetaCanvas.Brush.Style := bsSolid;
    693696      TileRect := Bounds(
    694697        Frame.Left + X * TileSize.X + TileMargin,
     
    703706      TileRect := Rect(TileCenter.X - S.X div 2, TileCenter.Y - S.Y div 2,
    704707        TileCenter.X + S.X div 2, TileCenter.Y + S.Y div 2);
    705       RenderTile(Canvas, Board.Tiles[Y, X], TileRect, True);
     708      RenderTile(MetaCanvas, Board.Tiles[Y, X], TileRect, True);
    706709    end;
    707710
     
    710713    for X := 0 to Board.Size.X - 1 do
    711714    if Board.Tiles[Y, X].Action = taMerge then begin
    712       Canvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
    713       Canvas.Brush.Style := bsSolid;
     715      MetaCanvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
     716      MetaCanvas.Brush.Style := bsSolid;
    714717      TileRect := Bounds(
    715718        Frame.Left + X * TileSize.X + TileMargin,
     
    723726      TileRect := Rect(TileRect.Left - S.X, TileRect.Top - S.Y,
    724727        TileRect.Right + S.X, TileRect.Bottom + S.Y);
    725       RenderTile(Canvas, Board.Tiles[Y, X], TileRect, True);
    726     end;
     728      RenderTile(MetaCanvas, Board.Tiles[Y, X], TileRect, True);
     729    end;
     730
     731  MetaCanvas.DrawTo(Canvas);
     732  MetaCanvas.Free;
    727733end;
    728734
Note: See TracChangeset for help on using the changeset viewer.