Changeset 102
- Timestamp:
- Dec 9, 2024, 11:55:53 AM (12 days ago)
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/FormMain.pas
r101 r102 137 137 D: Real; 138 138 Angle: Real; 139 const 140 SwipeMinDistance = 50; 139 141 begin 140 142 if MouseDown then begin; 141 143 D := MouseStart.Distance(Point(X, Y)); 142 if D > ScaleX( 100, 96) then begin144 if D > ScaleX(SwipeMinDistance, 96) then begin 143 145 MouseDown := False; 144 146 Angle := AngleOfLine(MouseStart, Point(X, Y)); -
trunk/Game.pas
r100 r102 119 119 procedure DoPaint; 120 120 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; 121 123 procedure GameOver; 122 124 procedure SetColorPalette(AValue: TColorPalette); … … 185 187 resourcestring 186 188 SScore = 'Score'; 187 STopScore = ' Top score';189 STopScore = 'Best'; 188 190 SSkinLinear = 'Linear'; 189 191 SSkinPowerOfTwo = 'Power of two'; … … 643 645 X, Y: Integer; 644 646 TileSize: TPoint; 645 ValueStr: string;646 647 Frame: TRect; 647 648 TileRect: TRect; 648 649 TopBarHeight: Integer; 650 LeftBarWidth: Integer; 649 651 TileMargin: Integer; 650 652 TileCenter: TPoint; … … 652 654 MetaCanvas: TMetaCanvas; 653 655 BorderSize: Integer; 654 begin 656 ControlsRect: TRect; 657 BoardRect: TRect; 658 Horizontal: Boolean; 659 begin 660 // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows. 661 // So dimensions are provided by CanvasSize parameter. 662 655 663 MetaCanvas := TMetaCanvas.Create; 656 664 MetaCanvas.Size := Point(Canvas.Width, Canvas.Height); 657 665 658 TopBarHeight := ScaleY(24, 96);666 // Clear background 659 667 MetaCanvas.Brush.Style := bsSolid; 660 668 MetaCanvas.Brush.Color := Core.Core.ThemeManager1.Theme.ColorControl; 661 669 MetaCanvas.FillRect(0, 0, MetaCanvas.Width, MetaCanvas.Height); 662 670 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 676 685 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 678 689 TileSize := Point(Frame.Width div Board.Size.X, Frame.Height div Board.Size.Y); 679 690 if TileSize.X < TileSize.Y then TileSize.Y := TileSize.X; … … 849 860 end; 850 861 862 procedure TGame.RenderControls(Canvas: TCanvas; Rect: TRect; Horizontal: Boolean); 863 var 864 Pos: TPoint; 865 Size: TSize; 866 begin 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)); 876 end; 877 878 function TGame.RenderTextBox(Canvas: TCanvas; Pos: TPoint; Title, Value: string 879 ): TSize; 880 var 881 BoxSize: TSize; 882 begin 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; 906 end; 907 851 908 function TGame.CanUndo: Boolean; 852 909 begin -
trunk/Languages/Game2048.cs.po
r101 r102 129 129 #: game.stopscore 130 130 msgctxt "game.stopscore" 131 msgid " Top score"132 msgstr "Nej vyšší skóre"131 msgid "Best" 132 msgstr "Nejlepší" 133 133 134 134 #: tcore.aabout.caption -
trunk/Packages/Common/Common.lpk
r85 r102 43 43 <License Value="Copy left."/> 44 44 <Version Minor="12"/> 45 <Files Count="3 6">45 <Files Count="37"> 46 46 <Item1> 47 47 <Filename Value="StopWatch.pas"/> … … 201 201 <UnitName Value="FormAbout"/> 202 202 </Item36> 203 <Item37> 204 <Filename Value="Forms\FormKeyShortcuts.pas"/> 205 <UnitName Value="FormKeyShortcuts"/> 206 </Item37> 203 207 </Files> 204 208 <CompatibilityMode Value="True"/> -
trunk/Packages/Common/Common.pas
r99 r102 55 55 function EndsWith(Text, What: string): Boolean; 56 56 function Explode(Separator: Char; Data: string): TStringArray; 57 procedure ExecuteProgram(Executable: string; Parameters: array of string); 57 procedure ExecuteProgram(Executable: string; Parameters: array of string; 58 Environment: array of string; CurrentDirectory: string = ''); 59 procedure ExecuteProgramOutput(Executable: string; Parameters: array of string; 60 Environment: array of string; out Output, Error: string; 61 out ExitCode: Integer; CurrentDirectory: string = ''); 58 62 procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog); 59 63 procedure FreeThenNil(var Obj); … … 63 67 function GetBit(Variable: QWord; Index: Byte): Boolean; 64 68 function GetStringPart(var Text: string; Separator: string): string; 69 function GetEnvironmentVariables: TStringArray; 65 70 function GenerateNewName(OldName: string): string; 66 71 function GetFileFilterItemExt(Filter: string; Index: Integer): string; 67 72 function 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; 73 function Implode(Separator: string; List: TList<string>): string; overload; 74 function Implode(Separator: string; List: array of string): string; overload; 75 function Implode(Separator: string; List: TStringList; Around: string = ''): string; overload; 70 76 function LastPos(const SubStr: String; const S: String): Integer; 71 77 function LoadFileToStr(const FileName: TFileName): AnsiString; … … 98 104 implementation 99 105 106 resourcestring 107 SExecutionError = 'Excution error: %s (exit code: %d)'; 108 100 109 function StartsWith(Text, What: string): Boolean; 101 110 begin … … 108 117 end; 109 118 110 function BinToInt(BinStr : string): Int64;111 var 112 i : byte;113 RetVar 119 function BinToInt(BinStr: string): Int64; 120 var 121 I: Byte; 122 RetVar: Int64; 114 123 begin 115 124 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); 117 126 RetVar := 0; 118 for i := 1 to length(BinStr) do begin119 if not (BinStr[ i] in ['0','1']) then begin127 for I := 1 to Length(BinStr) do begin 128 if not (BinStr[I] in ['0','1']) then begin 120 129 RetVar := 0; 121 130 Break; 122 131 end; 123 RetVar := (RetVar shl 1) + ( byte(BinStr[i]) and 1);132 RetVar := (RetVar shl 1) + (Byte(BinStr[I]) and 1); 124 133 end; 125 134 … … 136 145 end; 137 146 end; 138 139 147 140 148 procedure DeleteFiles(APath, AFileSpec: string); … … 154 162 FindClose(SearchRec); 155 163 end; 156 157 164 158 165 function GetFileFilterItemExt(Filter: string; Index: Integer): string; … … 177 184 if FileExt <> '.*' then 178 185 FileDialog.FileName := ChangeFileExt(FileDialog.FileName, FileExt) 186 end; 187 188 function GetEnvironmentVariables: TStringArray; 189 var 190 I: Integer; 191 begin 192 SetLength(Result, GetEnvironmentVariableCount); 193 for I := 0 to GetEnvironmentVariableCount - 1 do 194 Result[I] := GetEnvironmentString(I); 179 195 end; 180 196 … … 219 235 end;*) 220 236 237 function Implode(Separator: string; List: array of string): string; 238 var 239 I: Integer; 240 begin 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; 246 end; 247 221 248 function Implode(Separator: string; List: TStringList; Around: string = ''): string; 222 249 var … … 494 521 end; 495 522 496 procedure ExecuteProgram(Executable: string; Parameters: array of string); 523 procedure ExecuteProgram(Executable: string; Parameters: array of string; 524 Environment: array of string; CurrentDirectory: string = ''); 497 525 var 498 526 Process: TProcess; 499 527 I: Integer; 500 528 begin 529 Process := TProcess.Create(nil); 501 530 try 502 Process := TProcess.Create(nil);503 531 Process.Executable := Executable; 504 532 for I := 0 to Length(Parameters) - 1 do 505 533 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; 506 538 Process.Options := [poNoConsole]; 507 539 Process.Execute; … … 511 543 end; 512 544 545 procedure ExecuteProgramOutput(Executable: string; Parameters: array of string; 546 Environment: array of string; out Output, Error: string; out ExitCode: Integer; 547 CurrentDirectory: string); 548 var 549 Process: TProcess; 550 I: Integer; 551 ReadCount: Integer; 552 Buffer: string; 553 const 554 BufferSize = 1000; 555 begin 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; 603 end; 604 513 605 procedure FreeThenNil(var Obj); 514 606 begin … … 529 621 procedure OpenFileInShell(FileName: string); 530 622 begin 531 ExecuteProgram('cmd.exe', ['/c', 'start', FileName] );623 ExecuteProgram('cmd.exe', ['/c', 'start', FileName], []); 532 624 end; 533 625 -
trunk/Packages/Common/CommonPackage.pas
r85 r102 14 14 ScaleDPI, Theme, StringTable, MetaCanvas, Geometric, Translator, Languages, 15 15 PixelPointer, DataFile, TestCase, Generics, Table, FormEx, FormTests, 16 FormTest, FormAbout, LazarusPackageIntf;16 FormTest, FormAbout, FormKeyShortcuts, LazarusPackageIntf; 17 17 18 18 implementation -
trunk/Packages/Common/FormEx.pas
r99 r102 82 82 procedure TFormEx.DoClose(var CloseAction: TCloseAction); 83 83 begin 84 if 84 if (not (csDesigning in ComponentState)) then begin 85 85 PersistentForm.FormFullScreen := FullScreen; 86 86 PersistentForm.Save(Self); -
trunk/Packages/Common/Forms/FormAbout.lfm
r90 r102 1 1 object FormAbout: TFormAbout 2 Left = 9292 Left = 624 3 3 Height = 402 4 Top = 5194 Top = 622 5 5 Width = 702 6 6 Caption = 'About' … … 10 10 OnShow = FormShow 11 11 Position = poScreenCenter 12 LCLVersion = ' 3.4.0.0'12 LCLVersion = '2.2.6.0' 13 13 object LabelDescription: TLabel 14 14 Left = 30 … … 88 88 Anchors = [akLeft, akBottom] 89 89 Caption = 'Home page' 90 OnClick = ButtonHomePageClick 90 91 ParentFont = False 91 92 TabOrder = 0 92 OnClick = ButtonHomePageClick93 93 end 94 94 object ButtonClose: TButton -
trunk/Packages/Common/ListViewSort.pas
r89 r102 358 358 List.Clear; 359 359 List.AddRange(Source); 360 end else List.Clear;360 end; 361 361 if ListView.Items.Count <> List.Count then 362 362 ListView.Items.Count := List.Count; -
trunk/Packages/Common/PersistentForm.pas
r99 r102 336 336 end; 337 337 Form.OnWindowStateChange := OldHandler; 338 FormFullScreen := True; 338 339 {$ENDIF} 339 340 end else begin -
trunk/Packages/Common/Table.pas
r85 r102 4 4 5 5 uses 6 Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, XMLWrite,DOM;6 Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, DOM; 7 7 8 8 type
Note:
See TracChangeset
for help on using the changeset viewer.