Changeset 576 for trunk


Ignore:
Timestamp:
May 17, 2024, 9:21:22 AM (6 months ago)
Author:
chronos
Message:
  • Added: Move tech tree form with pressed arrow keys for longer time.
Location:
trunk/LocalPlayer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/TechTree.lfm

    r575 r576  
    11object TechTreeDlg: TTechTreeDlg
     2  Cursor = 3
    23  Left = 1162
     4  Height = 482
     5  Top = 481
    36  Width = 611
    4   Top = 481
    5   Height = 482
    6   Cursor = 3
    77  BorderIcons = []
    88  BorderStyle = bsNone
     
    1919  Position = poDefault
    2020  Scaled = False
     21  OnClose = FormClose
    2122  OnCreate = FormCreate
    2223  OnDestroy = FormDestroy
     24  OnKeyDown = FormKeyDown
    2325  OnKeyUp = FormKeyUp
    2426  OnMouseDown = FormMouseDown
     
    3032  TextHeight = 16
    3133  object CloseBtn: TButtonB
     34    Cursor = crArrow
    3235    Left = 568
     36    Height = 25
    3337    Top = 16
    3438    Width = 25
    35     Height = 25
    36     Cursor = crArrow
    3739    Down = False
    3840    Permanent = False
     
    4042    ButtonIndex = 0
    4143  end
     44  object TimerKeyPressed: TTimer
     45    Enabled = False
     46    Interval = 250
     47    OnTimer = TimerKeyPressedTimer
     48    Left = 177
     49    Top = 180
     50  end
    4251end
  • trunk/LocalPlayer/TechTree.pas

    r575 r576  
    77  ScreenTools, LCLIntf, LCLType, SysUtils, Classes, ButtonB, DrawDlg,
    88  {$IFDEF DPI}Dpi.Graphics, Dpi.Controls, Dpi.Forms{$ELSE}
    9   Graphics, Controls, Forms{$ENDIF};
     9  Graphics, Controls, Forms{$ENDIF}, Controls, ExtCtrls, Forms;
    1010
    1111type
     
    1515  TTechTreeDlg = class(TDrawDlg)
    1616    CloseBtn: TButtonB;
     17    TimerKeyPressed: TTimer;
     18    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    1719    procedure FormCreate(Sender: TObject);
    1820    procedure FormDestroy(Sender: TObject);
     21    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    1922    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    2023    procedure FormPaint(Sender: TObject);
     
    2629    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    2730    procedure CloseBtnClick(Sender: TObject);
     31    procedure TimerKeyPressedTimer(Sender: TObject);
    2832  private
    2933    Offset: TPoint;
     
    3135    Image: TBitmap;
    3236    Dragging: Boolean;
     37    LeftPressed: Boolean;
     38    RightPressed: Boolean;
     39    UpPressed: Boolean;
     40    DownPressed: Boolean;
    3341    procedure Move(Diff: TPoint);
    3442  end;
     
    5866function Min(A, B: Integer): Integer;
    5967begin
    60   if A < B then
    61     Result := A
    62   else
    63     Result := B;
     68  if A < B then Result := A
     69    else Result := B;
    6470end;
    6571
    6672function Max(A, B: Integer): Integer;
    6773begin
    68   if A > B then
    69     Result := A
    70   else
    71     Result := B;
     74  if A > B then Result := A
     75    else Result := B;
    7276end;
    7377
     
    7882end;
    7983
     84procedure TTechTreeDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction
     85  );
     86begin
     87  TimerKeyPressed.Enabled := False;
     88  RightPressed := False;
     89  DownPressed := False;
     90  LeftPressed := False;
     91  UpPressed := False;
     92end;
     93
    8094procedure TTechTreeDlg.FormDestroy(Sender: TObject);
    8195begin
    8296  FreeAndNil(Image);
     97end;
     98
     99procedure TTechTreeDlg.FormKeyDown(Sender: TObject; var Key: Word;
     100  Shift: TShiftState);
     101begin
     102  case Key of
     103    37: RightPressed := True;
     104    38: DownPressed := True;
     105    39: LeftPressed := True;
     106    40: UpPressed := True;
     107  end;
     108  TimerKeyPressedTimer(nil);
     109  TimerKeyPressed.Enabled := RightPressed or DownPressed or LeftPressed or UpPressed;
    83110end;
    84111
    85112procedure TTechTreeDlg.FormKeyUp(Sender: TObject; var Key: Word;
    86113  Shift: TShiftState);
    87 const
    88   Diff = 50;
    89114begin
    90115  case Key of
    91     37: Move(Point(Diff, 0));
    92     38: Move(Point(0, Diff));
    93     39: Move(Point(-Diff, 0));
    94     40: Move(Point(0, -Diff));
    95   end;
     116    37: RightPressed := False;
     117    38: DownPressed := False;
     118    39: LeftPressed := False;
     119    40: UpPressed := False;
     120  end;
     121  TimerKeyPressed.Enabled := RightPressed or DownPressed or LeftPressed or UpPressed;
    96122end;
    97123
     
    188214
    189215  // Fit window to image, center image in window, center window to screen
    190   NewWidth := Min(Screen.Width - 40, Image.Width + LeftBorder + RightBorder + 2 * BlackBorder);
    191   NewHeight := Min(Screen.Height - 40, Image.Height + TopBorder + BottomBorder + 2 * BlackBorder);
     216  NewWidth := Min(Screen.Width - 40, Image.Width + LeftBorder + RightBorder +
     217    2 * BlackBorder);
     218  NewHeight := Min(Screen.Height - 40, Image.Height + TopBorder + BottomBorder +
     219    2 * BlackBorder);
    192220  BoundsRect := Bounds((Screen.Width - NewWidth) div 2,
    193     (Screen.Height - NewHeight) div 2,
    194     NewWidth, NewHeight);
     221    (Screen.Height - NewHeight) div 2, NewWidth, NewHeight);
    195222  CloseBtn.Left := Width - CloseBtn.Width - BlackBorder - 8;
    196223  CloseBtn.Top := BlackBorder + 8;
     
    229256begin
    230257  Close;
     258end;
     259
     260procedure TTechTreeDlg.TimerKeyPressedTimer(Sender: TObject);
     261const
     262  Diff = 50;
     263var
     264  Change: TPoint;
     265begin
     266  Change := Point(0, 0);
     267  if RightPressed then Change.X := Change.X + Diff;
     268  if LeftPressed then Change.X := Change.X - Diff;
     269  if DownPressed then Change.Y := Change.Y + Diff;
     270  if UpPressed then Change.Y := Change.Y - Diff;
     271
     272  if (Change.X <> 0) or (Change.Y <> 0) then Move(Change);
    231273end;
    232274
     
    241283  if Offset.Y > TopBorder then
    242284    Offset.Y := TopBorder;
    243   if Offset.Y < ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder
    244   then
     285  if Offset.Y < ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder then
    245286    Offset.Y := ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder;
    246287
Note: See TracChangeset for help on using the changeset viewer.