Ignore:
Timestamp:
May 16, 2024, 12:03:29 AM (6 months ago)
Author:
chronos
Message:
  • Added: Allow to scroll tech tree form also with keyboard arrows.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/TechTree.pas

    r496 r575  
    1717    procedure FormCreate(Sender: TObject);
    1818    procedure FormDestroy(Sender: TObject);
     19    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    1920    procedure FormPaint(Sender: TObject);
    2021    procedure FormShow(Sender: TObject);
     
    2627    procedure CloseBtnClick(Sender: TObject);
    2728  private
    28     xOffset, yOffset, xDown, yDown: Integer;
     29    Offset: TPoint;
     30    Down: TPoint;
    2931    Image: TBitmap;
    3032    Dragging: Boolean;
     33    procedure Move(Diff: TPoint);
    3134  end;
    3235
     
    8083end;
    8184
     85procedure TTechTreeDlg.FormKeyUp(Sender: TObject; var Key: Word;
     86  Shift: TShiftState);
     87const
     88  Diff = 50;
     89begin
     90  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;
     96end;
     97
    8298procedure TTechTreeDlg.FormPaint(Sender: TObject);
    8399var
     
    95111    // texturize empty space
    96112    Brush.Color := $FFFFFF;
    97     if xOffset > 0 then
    98       FillRectSeamless(Canvas, BlackBorder, BlackBorder, BlackBorder + xOffset,
    99         ClientHeight - BlackBorder, -BlackBorder - xOffset,
    100         -BlackBorder - yOffset, Paper);
    101     if xOffset + Image.Width < ClientWidth - 2 * BlackBorder then
    102       FillRectSeamless(Canvas, BlackBorder + xOffset + Image.Width, BlackBorder,
     113    if Offset.X > 0 then
     114      FillRectSeamless(Canvas, BlackBorder, BlackBorder, BlackBorder + Offset.X,
     115        ClientHeight - BlackBorder, -BlackBorder - Offset.X,
     116        -BlackBorder - Offset.Y, Paper);
     117    if Offset.X + Image.Width < ClientWidth - 2 * BlackBorder then
     118      FillRectSeamless(Canvas, BlackBorder + Offset.X + Image.Width, BlackBorder,
    103119        ClientWidth - BlackBorder, ClientHeight - BlackBorder,
    104         -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
    105     X := Max(BlackBorder, BlackBorder + xOffset);
    106     W := Min(BlackBorder + xOffset + Image.Width, ClientWidth - BlackBorder);
    107     if yOffset > 0 then
    108       FillRectSeamless(Canvas, X, BlackBorder, W, BlackBorder + yOffset,
    109         -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
    110     if yOffset + Image.Height < ClientHeight - 2 * BlackBorder then
    111       FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.Height, W,
    112         ClientHeight - BlackBorder, -BlackBorder - xOffset,
    113         -BlackBorder - yOffset, Paper);
    114   end;
    115   BitBltCanvas(Canvas, Max(BlackBorder, BlackBorder + xOffset),
    116     Max(BlackBorder, BlackBorder + yOffset),
    117     Min(Image.Width, Min(Image.Width + xOffset,
    118     Min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))
    119     ), Min(Image.Height, Min(Image.Height + yOffset,
     120        -BlackBorder - Offset.X, -BlackBorder - Offset.Y, Paper);
     121    X := Max(BlackBorder, BlackBorder + Offset.X);
     122    W := Min(BlackBorder + Offset.X + Image.Width, ClientWidth - BlackBorder);
     123    if Offset.Y > 0 then
     124      FillRectSeamless(Canvas, X, BlackBorder, W, BlackBorder + Offset.Y,
     125        -BlackBorder - Offset.X, -BlackBorder - Offset.Y, Paper);
     126    if Offset.Y + Image.Height < ClientHeight - 2 * BlackBorder then
     127      FillRectSeamless(Canvas, X, BlackBorder + Offset.Y + Image.Height, W,
     128        ClientHeight - BlackBorder, -BlackBorder - Offset.X,
     129        -BlackBorder - Offset.Y, Paper);
     130  end;
     131  BitBltCanvas(Canvas, Max(BlackBorder, BlackBorder + Offset.X),
     132    Max(BlackBorder, BlackBorder + Offset.Y),
     133    Min(Image.Width, Min(Image.Width + Offset.X,
     134    Min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - Offset.X))
     135    ), Min(Image.Height, Min(Image.Height + Offset.Y,
    120136    Min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -
    121     yOffset))), Image.Canvas, Max(0, -xOffset),
    122     Max(0, -yOffset));
     137    Offset.Y))), Image.Canvas, Max(0, -Offset.X),
     138    Max(0, -Offset.Y));
    123139end;
    124140
     
    179195  CloseBtn.Left := Width - CloseBtn.Width - BlackBorder - 8;
    180196  CloseBtn.Top := BlackBorder + 8;
    181   xOffset := (ClientWidth - Image.Width + LeftBorder - RightBorder) div 2 -
     197  Offset.X := (ClientWidth - Image.Width + LeftBorder - RightBorder) div 2 -
    182198    BlackBorder;
    183   yOffset := ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder;
     199  Offset.Y := ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder;
    184200end;
    185201
     
    190206  begin
    191207    Dragging := True;
    192     xDown := X;
    193     yDown := Y;
     208    Down := Point(X, Y);
    194209  end;
    195210end;
     
    206221  if Dragging then
    207222  begin
    208     xOffset := xOffset + X - xDown;
    209     yOffset := yOffset + Y - yDown;
    210     xDown := X;
    211     yDown := Y;
    212 
    213     if xOffset > LeftBorder then
    214       xOffset := LeftBorder;
    215     if xOffset < ClientWidth - 2 * BlackBorder - Image.Width - RightBorder then
    216       xOffset := ClientWidth - 2 * BlackBorder - Image.Width - RightBorder;
    217     if yOffset > TopBorder then
    218       yOffset := TopBorder;
    219     if yOffset < ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder
    220     then
    221       yOffset := ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder;
    222 
    223     SmartInvalidate;
     223    Move(Point(X - Down.X, Y - Down.Y));
     224    Down := Point(X, Y);
    224225  end;
    225226end;
     
    230231end;
    231232
     233procedure TTechTreeDlg.Move(Diff: TPoint);
     234begin
     235  Offset := Offset + Diff;
     236
     237  if Offset.X > LeftBorder then
     238    Offset.X := LeftBorder;
     239  if Offset.X < ClientWidth - 2 * BlackBorder - Image.Width - RightBorder then
     240    Offset.X := ClientWidth - 2 * BlackBorder - Image.Width - RightBorder;
     241  if Offset.Y > TopBorder then
     242    Offset.Y := TopBorder;
     243  if Offset.Y < ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder
     244  then
     245    Offset.Y := ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder;
     246
     247  SmartInvalidate;
     248end;
     249
    232250end.
Note: See TracChangeset for help on using the changeset viewer.