Changeset 102


Ignore:
Timestamp:
Dec 9, 2024, 11:55:53 AM (12 days ago)
Author:
chronos
Message:
  • Modified: Lowered minimal swipe distance.
  • Modified: Show score and best score as boxes. Place them according window size.
  • Modified: Updated Common package.
Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormMain.pas

    r101 r102  
    137137  D: Real;
    138138  Angle: Real;
     139const
     140  SwipeMinDistance = 50;
    139141begin
    140142  if MouseDown then begin;
    141143    D := MouseStart.Distance(Point(X, Y));
    142     if D > ScaleX(100, 96) then begin
     144    if D > ScaleX(SwipeMinDistance, 96) then begin
    143145      MouseDown := False;
    144146      Angle := AngleOfLine(MouseStart, Point(X, Y));
  • trunk/Game.pas

    r100 r102  
    119119    procedure DoPaint;
    120120    procedure RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect; WithText: Boolean);
     121    procedure RenderControls(Canvas: TCanvas; Rect: TRect; Horizontal: Boolean);
     122    function RenderTextBox(Canvas: TCanvas; Pos: TPoint; Title, Value: string): TSize;
    121123    procedure GameOver;
    122124    procedure SetColorPalette(AValue: TColorPalette);
     
    185187resourcestring
    186188  SScore = 'Score';
    187   STopScore = 'Top score';
     189  STopScore = 'Best';
    188190  SSkinLinear = 'Linear';
    189191  SSkinPowerOfTwo = 'Power of two';
     
    643645  X, Y: Integer;
    644646  TileSize: TPoint;
    645   ValueStr: string;
    646647  Frame: TRect;
    647648  TileRect: TRect;
    648649  TopBarHeight: Integer;
     650  LeftBarWidth: Integer;
    649651  TileMargin: Integer;
    650652  TileCenter: TPoint;
     
    652654  MetaCanvas: TMetaCanvas;
    653655  BorderSize: Integer;
    654 begin
     656  ControlsRect: TRect;
     657  BoardRect: TRect;
     658  Horizontal: Boolean;
     659begin
     660  // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows.
     661  // So dimensions are provided by CanvasSize parameter.
     662
    655663  MetaCanvas := TMetaCanvas.Create;
    656664  MetaCanvas.Size := Point(Canvas.Width, Canvas.Height);
    657665
    658   TopBarHeight := ScaleY(24, 96);
     666  // Clear background
    659667  MetaCanvas.Brush.Style := bsSolid;
    660668  MetaCanvas.Brush.Color := Core.Core.ThemeManager1.Theme.ColorControl;
    661669  MetaCanvas.FillRect(0, 0, MetaCanvas.Width, MetaCanvas.Height);
    662670
    663   ValueStr := SScore + ': ' + IntToStr(Score);
    664   MetaCanvas.Brush.Style := bsClear;
    665   MetaCanvas.Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText;
    666   MetaCanvas.Font.Height := Trunc(TopBarHeight * 0.7);
    667   MetaCanvas.TextOut(ScaleY(16, 96), (TopBarHeight - MetaCanvas.TextHeight(ValueStr)) div 2, ValueStr);
    668 
    669   ValueStr := STopScore + ': ' + IntToStr(TopScore);
    670   MetaCanvas.Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText;
    671   MetaCanvas.Font.Height := Trunc(TopBarHeight * 0.7);
    672   MetaCanvas.TextOut(ScaleY(136, 96), (TopBarHeight - MetaCanvas.TextHeight(ValueStr)) div 2, ValueStr);
    673 
    674   // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows.
    675   // So dimensions are provided by CanvasSize parameter.
     671  TopBarHeight := ScaleY(55, 96);
     672  LeftBarWidth := ScaleY(90, 96);
     673  if CanvasSize.X - LeftBarWidth < Canvas.Height then begin
     674    ControlsRect := Rect(0, 0, CanvasSize.X, TopBarHeight);
     675    BoardRect := Rect(0, TopBarHeight, CanvasSize.X, CanvasSize.Y);
     676    Horizontal := True;
     677  end else begin
     678    ControlsRect := Rect(0, 0, LeftBarWidth, CanvasSize.Y);
     679    BoardRect := Rect(LeftBarWidth, 0, CanvasSize.X, CanvasSize.Y);
     680    Horizontal := False;
     681  end;
     682
     683  RenderControls(MetaCanvas, ControlsRect, Horizontal);
     684
    676685  BorderSize := ScaleY(2, 96);
    677   Frame := Rect(BorderSize, BorderSize + TopBarHeight, CanvasSize.X - BorderSize, CanvasSize.Y - BorderSize);
     686  Frame := Rect(BoardRect.Left + BorderSize, BoardRect.Top + BorderSize,
     687    BoardRect.Right - BorderSize, BoardRect.Bottom - BorderSize);
     688
    678689  TileSize := Point(Frame.Width div Board.Size.X, Frame.Height div Board.Size.Y);
    679690  if TileSize.X < TileSize.Y then TileSize.Y := TileSize.X;
     
    849860end;
    850861
     862procedure TGame.RenderControls(Canvas: TCanvas; Rect: TRect; Horizontal: Boolean);
     863var
     864  Pos: TPoint;
     865  Size: TSize;
     866begin
     867  if Horizontal then Pos := Point(ScaleY(16, 96), ScaleY(4, 96))
     868    else Pos := Point(ScaleY(4, 96), ScaleY(16, 96));
     869
     870  Size := RenderTextBox(Canvas, Pos, SScore, IntToStr(Score));
     871
     872  if Horizontal then Pos := Point(ScaleY(16 + 16, 96) + Size.Width, ScaleY(4, 96))
     873    else Pos := Point(ScaleY(4, 96), ScaleY(16 + 16, 96) + Size.Height);
     874
     875  Size := RenderTextBox(Canvas, Pos, STopScore, IntToStr(TopScore));
     876end;
     877
     878function TGame.RenderTextBox(Canvas: TCanvas; Pos: TPoint; Title, Value: string
     879  ): TSize;
     880var
     881  BoxSize: TSize;
     882begin
     883  with Canvas do begin
     884    Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText;
     885    Font.Height := Trunc(24);
     886
     887    BoxSize := Size(TextWidth(Title), TextHeight(Title) + TextHeight(Value));
     888    if BoxSize.Width < TextWidth(Value) then BoxSize.Width := TextWidth(Value);
     889    BoxSize := Size(Round(BoxSize.Width * 1.2), Round(BoxSize.Height * 1));
     890
     891    Brush.Style := bsSolid;
     892    Brush.Color := Core.Core.ThemeManager1.Theme.ColorWindow;
     893    FillRect(Pos.X, Pos.Y, Pos.X + BoxSize.Width, Pos.Y + BoxSize.Height);
     894
     895    Brush.Style := bsClear;
     896    TextOut(Pos.X + (BoxSize.Width - TextWidth(Title)) div 2, Pos.Y, Title);
     897
     898    Brush.Style := bsClear;
     899    Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText;
     900    Font.Height := Trunc(24);
     901    TextOut(Pos.X + (BoxSize.Width - TextWidth(Value)) div 2,
     902      Pos.Y + TextHeight(Title), Value);
     903  end;
     904
     905  Result := BoxSize;
     906end;
     907
    851908function TGame.CanUndo: Boolean;
    852909begin
  • trunk/Languages/Game2048.cs.po

    r101 r102  
    129129#: game.stopscore
    130130msgctxt "game.stopscore"
    131 msgid "Top score"
    132 msgstr "Nejvyšší skóre"
     131msgid "Best"
     132msgstr "Nejlepší"
    133133
    134134#: tcore.aabout.caption
  • trunk/Packages/Common/Common.lpk

    r85 r102  
    4343    <License Value="Copy left."/>
    4444    <Version Minor="12"/>
    45     <Files Count="36">
     45    <Files Count="37">
    4646      <Item1>
    4747        <Filename Value="StopWatch.pas"/>
     
    201201        <UnitName Value="FormAbout"/>
    202202      </Item36>
     203      <Item37>
     204        <Filename Value="Forms\FormKeyShortcuts.pas"/>
     205        <UnitName Value="FormKeyShortcuts"/>
     206      </Item37>
    203207    </Files>
    204208    <CompatibilityMode Value="True"/>
  • trunk/Packages/Common/Common.pas

    r99 r102  
    5555function EndsWith(Text, What: string): Boolean;
    5656function Explode(Separator: Char; Data: string): TStringArray;
    57 procedure ExecuteProgram(Executable: string; Parameters: array of string);
     57procedure ExecuteProgram(Executable: string; Parameters: array of string;
     58  Environment: array of string; CurrentDirectory: string = '');
     59procedure ExecuteProgramOutput(Executable: string; Parameters: array of string;
     60  Environment: array of string; out Output, Error: string;
     61  out ExitCode: Integer; CurrentDirectory: string = '');
    5862procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog);
    5963procedure FreeThenNil(var Obj);
     
    6367function GetBit(Variable: QWord; Index: Byte): Boolean;
    6468function GetStringPart(var Text: string; Separator: string): string;
     69function GetEnvironmentVariables: TStringArray;
    6570function GenerateNewName(OldName: string): string;
    6671function GetFileFilterItemExt(Filter: string; Index: Integer): string;
    6772function IntToBin(Data: Int64; Count: Byte): string;
    68 function Implode(Separator: string; List: TList<string>): string;
    69 function Implode(Separator: string; List: TStringList; Around: string = ''): string;
     73function Implode(Separator: string; List: TList<string>): string; overload;
     74function Implode(Separator: string; List: array of string): string; overload;
     75function Implode(Separator: string; List: TStringList; Around: string = ''): string; overload;
    7076function LastPos(const SubStr: String; const S: String): Integer;
    7177function LoadFileToStr(const FileName: TFileName): AnsiString;
     
    98104implementation
    99105
     106resourcestring
     107  SExecutionError = 'Excution error: %s (exit code: %d)';
     108
    100109function StartsWith(Text, What: string): Boolean;
    101110begin
     
    108117end;
    109118
    110 function BinToInt(BinStr : string) : Int64;
    111 var
    112   i : byte;
    113   RetVar : Int64;
     119function BinToInt(BinStr: string): Int64;
     120var
     121  I: Byte;
     122  RetVar: Int64;
    114123begin
    115124  BinStr := UpperCase(BinStr);
    116   if BinStr[length(BinStr)] = 'B' then Delete(BinStr,length(BinStr),1);
     125  if BinStr[length(BinStr)] = 'B' then Delete(BinStr, Length(BinStr), 1);
    117126  RetVar := 0;
    118   for i := 1 to length(BinStr) do begin
    119     if not (BinStr[i] in ['0','1']) then begin
     127  for I := 1 to Length(BinStr) do begin
     128    if not (BinStr[I] in ['0','1']) then begin
    120129      RetVar := 0;
    121130      Break;
    122131    end;
    123     RetVar := (RetVar shl 1) + (byte(BinStr[i]) and 1) ;
     132    RetVar := (RetVar shl 1) + (Byte(BinStr[I]) and 1);
    124133  end;
    125134
     
    136145  end;
    137146end;
    138 
    139147
    140148procedure DeleteFiles(APath, AFileSpec: string);
     
    154162  FindClose(SearchRec);
    155163end;
    156 
    157164
    158165function GetFileFilterItemExt(Filter: string; Index: Integer): string;
     
    177184  if FileExt <> '.*' then
    178185    FileDialog.FileName := ChangeFileExt(FileDialog.FileName, FileExt)
     186end;
     187
     188function GetEnvironmentVariables: TStringArray;
     189var
     190  I: Integer;
     191begin
     192  SetLength(Result, GetEnvironmentVariableCount);
     193  for I := 0 to GetEnvironmentVariableCount - 1 do
     194    Result[I] := GetEnvironmentString(I);
    179195end;
    180196
     
    219235end;*)
    220236
     237function Implode(Separator: string; List: array of string): string;
     238var
     239  I: Integer;
     240begin
     241  Result := '';
     242  for I := 0 to Length(List) - 1 do begin
     243    Result := Result + List[I];
     244    if I < Length(List) - 1 then Result := Result + Separator;
     245  end;
     246end;
     247
    221248function Implode(Separator: string; List: TStringList; Around: string = ''): string;
    222249var
     
    494521end;
    495522
    496 procedure ExecuteProgram(Executable: string; Parameters: array of string);
     523procedure ExecuteProgram(Executable: string; Parameters: array of string;
     524  Environment: array of string; CurrentDirectory: string = '');
    497525var
    498526  Process: TProcess;
    499527  I: Integer;
    500528begin
     529  Process := TProcess.Create(nil);
    501530  try
    502     Process := TProcess.Create(nil);
    503531    Process.Executable := Executable;
    504532    for I := 0 to Length(Parameters) - 1 do
    505533      Process.Parameters.Add(Parameters[I]);
     534    for I := 0 to Length(Environment) - 1 do
     535      Process.Environment.Add(Environment[I]);
     536    Process.CurrentDirectory := CurrentDirectory;
     537    Process.ShowWindow := swoHIDE;
    506538    Process.Options := [poNoConsole];
    507539    Process.Execute;
     
    511543end;
    512544
     545procedure ExecuteProgramOutput(Executable: string; Parameters: array of string;
     546  Environment: array of string; out Output, Error: string; out ExitCode: Integer;
     547  CurrentDirectory: string);
     548var
     549  Process: TProcess;
     550  I: Integer;
     551  ReadCount: Integer;
     552  Buffer: string;
     553const
     554  BufferSize = 1000;
     555begin
     556  Process := TProcess.Create(nil);
     557  try
     558    Process.Executable := Executable;
     559    for I := 0 to Length(Parameters) - 1 do
     560      Process.Parameters.Add(Parameters[I]);
     561    for I := 0 to Length(Environment) - 1 do
     562      Process.Environment.Add(Environment[I]);
     563    Process.CurrentDirectory := CurrentDirectory;
     564    Process.ShowWindow := swoHIDE;
     565    Process.Options := [poNoConsole, poUsePipes];
     566    Process.Execute;
     567
     568    Output := '';
     569    Error := '';
     570    Buffer := '';
     571    SetLength(Buffer, BufferSize);
     572    while Process.Running do begin
     573      if Process.Output.NumBytesAvailable > 0 then begin
     574        ReadCount := Process.Output.Read(Buffer[1], Length(Buffer));
     575        Output := Output + Copy(Buffer, 1, ReadCount);
     576      end;
     577
     578      if Process.Stderr.NumBytesAvailable > 0 then begin
     579        ReadCount := Process.Stderr.Read(Buffer[1], Length(Buffer));
     580        Error := Error + Copy(Buffer, 1, ReadCount)
     581      end;
     582
     583      Sleep(10);
     584    end;
     585
     586    if Process.Output.NumBytesAvailable > 0 then begin
     587      ReadCount := Process.Output.Read(Buffer[1], Length(Buffer));
     588      Output := Output + Copy(Buffer, 1, ReadCount);
     589    end;
     590
     591    if Process.Stderr.NumBytesAvailable > 0 then begin
     592      ReadCount := Process.Stderr.Read(Buffer[1], Length(Buffer));
     593      Error := Error + Copy(Buffer, 1, ReadCount);
     594    end;
     595
     596    ExitCode := Process.ExitCode;
     597
     598    if (ExitCode <> 0) or (Error <> '') then
     599      raise Exception.Create(Format(SExecutionError, [Output + Error, ExitCode]));
     600  finally
     601    Process.Free;
     602  end;
     603end;
     604
    513605procedure FreeThenNil(var Obj);
    514606begin
     
    529621procedure OpenFileInShell(FileName: string);
    530622begin
    531   ExecuteProgram('cmd.exe', ['/c', 'start', FileName]);
     623  ExecuteProgram('cmd.exe', ['/c', 'start', FileName], []);
    532624end;
    533625
  • trunk/Packages/Common/CommonPackage.pas

    r85 r102  
    1414  ScaleDPI, Theme, StringTable, MetaCanvas, Geometric, Translator, Languages,
    1515  PixelPointer, DataFile, TestCase, Generics, Table, FormEx, FormTests,
    16   FormTest, FormAbout, LazarusPackageIntf;
     16  FormTest, FormAbout, FormKeyShortcuts, LazarusPackageIntf;
    1717
    1818implementation
  • trunk/Packages/Common/FormEx.pas

    r99 r102  
    8282procedure TFormEx.DoClose(var CloseAction: TCloseAction);
    8383begin
    84   if  (not (csDesigning in ComponentState)) then begin
     84  if (not (csDesigning in ComponentState)) then begin
    8585    PersistentForm.FormFullScreen := FullScreen;
    8686    PersistentForm.Save(Self);
  • trunk/Packages/Common/Forms/FormAbout.lfm

    r90 r102  
    11object FormAbout: TFormAbout
    2   Left = 929
     2  Left = 624
    33  Height = 402
    4   Top = 519
     4  Top = 622
    55  Width = 702
    66  Caption = 'About'
     
    1010  OnShow = FormShow
    1111  Position = poScreenCenter
    12   LCLVersion = '3.4.0.0'
     12  LCLVersion = '2.2.6.0'
    1313  object LabelDescription: TLabel
    1414    Left = 30
     
    8888      Anchors = [akLeft, akBottom]
    8989      Caption = 'Home page'
     90      OnClick = ButtonHomePageClick
    9091      ParentFont = False
    9192      TabOrder = 0
    92       OnClick = ButtonHomePageClick
    9393    end
    9494    object ButtonClose: TButton
  • trunk/Packages/Common/ListViewSort.pas

    r89 r102  
    358358    List.Clear;
    359359    List.AddRange(Source);
    360   end else List.Clear;
     360  end;
    361361  if ListView.Items.Count <> List.Count then
    362362    ListView.Items.Count := List.Count;
  • trunk/Packages/Common/PersistentForm.pas

    r99 r102  
    336336    end;
    337337    Form.OnWindowStateChange := OldHandler;
     338    FormFullScreen := True;
    338339    {$ENDIF}
    339340  end else begin
  • trunk/Packages/Common/Table.pas

    r85 r102  
    44
    55uses
    6   Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, XMLWrite, DOM;
     6  Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, DOM;
    77
    88type
Note: See TracChangeset for help on using the changeset viewer.