Changeset 180 for trunk/Forms/UFormMain.pas
- Timestamp:
- Feb 8, 2018, 5:32:31 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r171 r180 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, 9 UGame, LCLType, Menus, ActnList, ComCtrls, dateutils, XMLConf, DOM, 10 UGeometry; 9 UGame, LCLType, Menus, ActnList, ComCtrls, dateutils, XMLConf, DOM; 11 10 12 11 const … … 19 18 20 19 TFormMain = class(TForm) 21 AStatusBarVisible: TAction;22 20 AToolBarVisible: TAction; 23 21 AToolBarBigIcons: TAction; 24 AZoomIn: TAction;25 AZoomAll: TAction;26 AZoomOut: TAction;27 22 ActionList1: TActionList; 28 23 MainMenu1: TMainMenu; … … 45 40 MenuItem24: TMenuItem; 46 41 MenuItem25: TMenuItem; 42 MenuItem26: TMenuItem; 43 MenuItem27: TMenuItem; 47 44 MenuItemLoadRecent: TMenuItem; 48 45 MenuItem3: TMenuItem; … … 53 50 MenuItem8: TMenuItem; 54 51 MenuItem9: TMenuItem; 55 Pa intBox1: TPaintBox;52 PanelMain: TPanel; 56 53 PopupMenuToolbar: TPopupMenu; 57 StatusBar1: TStatusBar;58 54 Timer1: TTimer; 59 55 ToolBar1: TToolBar; 60 56 ToolButton1: TToolButton; 61 ToolButton10: TToolButton;62 57 ToolButton11: TToolButton; 63 58 ToolButton12: TToolButton; … … 67 62 ToolButton4: TToolButton; 68 63 ToolButton5: TToolButton; 69 ToolButton6: TToolButton;70 ToolButton7: TToolButton;71 ToolButton8: TToolButton;72 64 ToolButton9: TToolButton; 73 procedure AStatusBarVisibleExecute(Sender: TObject);74 65 procedure AToolBarBigIconsExecute(Sender: TObject); 75 66 procedure AToolBarVisibleExecute(Sender: TObject); 76 procedure AZoomAllExecute(Sender: TObject);77 procedure AZoomInExecute(Sender: TObject);78 procedure AZoomOutExecute(Sender: TObject);79 67 procedure FormShow(Sender: TObject); 80 68 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 81 69 procedure FormCreate(Sender: TObject); 82 70 procedure FormDestroy(Sender: TObject); 83 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);84 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;85 Shift: TShiftState; X, Y: Integer);86 procedure PaintBox1MouseLeave(Sender: TObject);87 procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,88 Y: Integer);89 procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;90 Shift: TShiftState; X, Y: Integer);91 procedure PaintBox1MouseWheelDown(Sender: TObject; Shift: TShiftState;92 MousePos: TPoint; var Handled: Boolean);93 procedure PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;94 MousePos: TPoint; var Handled: Boolean);95 procedure PaintBox1Paint(Sender: TObject);96 71 procedure EraseBackground(DC: HDC); override; 97 procedure PaintBox1Resize(Sender: TObject);98 72 procedure Timer1Timer(Sender: TObject); 99 73 private 100 TempBitmap: TBitmap;101 StartMousePoint: TPoint;102 StartViewPoint: TPoint;103 MoveActive: Boolean;104 RedrawPending: Boolean;105 Drawing: Boolean;106 DrawDuration: TDateTime;107 LastTimerTime: TDateTime;108 TimerPeriod: TDateTime;109 74 public 110 75 procedure LoadConfig(Config: TXmlConfig; Path: string); 111 76 procedure SaveConfig(Config: TXmlConfig; Path: string); 112 77 procedure ReloadView; 113 procedure Redraw;114 78 end; 115 79 … … 120 84 121 85 uses 122 UCore ;86 UCore, UFormClient; 123 87 124 88 resourcestring … … 129 93 { TFormMain } 130 94 131 procedure TFormMain.PaintBox1Paint(Sender: TObject);132 var133 DrawStart: TDateTime;134 const135 BackgroundColor = $404040;136 begin137 DrawStart := Now;138 if Assigned(Core.CurrentClient) then139 with Core.CurrentClient do begin140 View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0), TPoint.Create(PaintBox1.Width, PaintBox1.Height));141 if csOpaque in PaintBox1.ControlStyle then begin142 TempBitmap.SetSize(PaintBox1.Width, PaintBox1.Height);143 TempBitmap.Canvas.Brush.Color := BackGroundColor; //clBackground; //PaintBox1.GetColorResolvingParent;144 TempBitmap.Canvas.FillRect(0, 0, PaintBox1.Width, PaintBox1.Height);145 if Assigned(ControlPlayer) then ControlPlayer.Paint(TempBitmap.Canvas, View)146 else Core.Game.Map.Paint(TempBitmap.Canvas, View);147 PaintBox1.Canvas.Draw(0, 0, TempBitmap);148 end else begin149 {$ifdef WINDOWS}150 PaintBox1.Canvas.Brush.Color := BackgroundColor; //clBackground; //PaintBox1.GetColorResolvingParent;151 PaintBox1.Canvas.FillRect(0, 0, PaintBox1.Width, PaintBox1.Height);152 {$endif}153 if Assigned(ControlPlayer) then ControlPlayer.Paint(PaintBox1.Canvas, View)154 else Core.Game.Map.Paint(PaintBox1.Canvas, View);155 end;156 end;157 DrawDuration := (9 * DrawDuration + (Now - DrawStart)) / 10;158 end;159 160 95 procedure TFormMain.EraseBackground(DC: HDC); 161 96 begin 162 97 // Do nothing, all background space covered by controls 163 end;164 165 procedure TFormMain.PaintBox1Resize(Sender: TObject);166 begin167 if Assigned(Core.CurrentClient) then168 with Core.CurrentClient do169 View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0), TPoint.Create(PaintBox1.Width, PaintBox1.Height));170 Redraw;171 98 end; 172 99 … … 175 102 NewCaption: string; 176 103 begin 177 if RedrawPending and not Drawing then begin 178 Drawing := True; 179 if not Core.DevelMode then RedrawPending := False; 180 TimerPeriod := (9 * TimerPeriod + (Now - LastTimerTime)) / 10; 181 LastTimerTime := Now; 182 PaintBox1.Repaint; 183 StatusBar1.Panels[1].Text := IntToStr(Trunc(DrawDuration / OneMillisecond)) + ' / ' + 184 IntToStr(Trunc(TimerPeriod / OneMillisecond)) + ' ms' + 185 ' ' + IntToStr(Core.Game.Map.CellLinks.Count); 186 NewCaption := 'xTactics'; 187 if Assigned(Core.Game.CurrentPlayer) then 188 NewCaption := Core.Game.CurrentPlayer.Name + ' - ' + STurn + ' ' + IntToStr(Core.Game.TurnCounter) + ' - ' + NewCaption; 189 Caption := NewCaption; 190 Drawing := False; 191 end; 104 NewCaption := 'xTactics'; 105 if Assigned(Core.Game.CurrentPlayer) then 106 NewCaption := Core.Game.CurrentPlayer.Name + ' - ' + STurn + ' ' + IntToStr(Core.Game.TurnCounter) + ' - ' + NewCaption; 107 Caption := NewCaption; 192 108 end; 193 109 … … 197 113 AToolBarBigIcons.Checked := GetValue(DOMString(Path + '/LargeIcons'), False); 198 114 AToolBarVisible.Checked := GetValue(DOMString(Path + '/ToolBarVisible'), True); 199 AStatusBarVisible.Checked := GetValue(DOMString(Path + '/StatusBarVisible'), False);200 115 end; 201 116 end; … … 206 121 SetValue(DOMString(Path + '/LargeIcons'), AToolBarBigIcons.Checked); 207 122 SetValue(DOMString(Path + '/ToolBarVisible'), AToolBarVisible.Checked); 208 SetValue(DOMString(Path + '/StatusBarVisible'), AStatusBarVisible.Checked);209 123 end; 210 124 end; … … 226 140 end; 227 141 ToolBar1.Visible := AToolBarVisible.Checked; 228 StatusBar1.Visible := AStatusBarVisible.Checked;229 end;230 231 procedure TFormMain.Redraw;232 begin233 RedrawPending := True;234 142 end; 235 143 236 144 procedure TFormMain.FormCreate(Sender: TObject); 237 145 begin 238 {$IFDEF Linux} 239 //PaintBox1.ControlStyle := PaintBox1.ControlStyle + [csOpaque]; 240 {$ENDIF} 241 //DoubleBuffered := True; 242 TempBitmap := TBitmap.Create; 243 TimerPeriod := 0; 244 LastTimerTime := Now; 245 end; 246 247 procedure TFormMain.AZoomAllExecute(Sender: TObject); 248 var 249 Factor: TPointF; 250 MapRect: TRect; 251 NewZoom: Single; 252 begin 253 with Core, Game, CurrentClient, View do begin 254 MapRect := Map.CalculatePixelRect; 255 Factor := TPointF.Create(DestRect.Size.X / MapRect.Size.X, 256 DestRect.Size.Y / MapRect.Size.Y); 257 if Factor.X < Factor.Y then NewZoom := Factor.X 258 else NewZoom := Factor.Y; 259 if NewZoom = 0 then NewZoom := 1; 260 Zoom := NewZoom; 261 CenterMap; 262 end; 263 Redraw; 146 FormClient := TFormClient.Create(nil); 147 FormClient.ManualDock(PanelMain, nil, alClient); 148 FormClient.Align := alClient; 149 FormClient.Show; 264 150 end; 265 151 … … 270 156 end; 271 157 272 procedure TFormMain.AStatusBarVisibleExecute(Sender: TObject);273 begin274 AStatusBarVisible.Checked := not AStatusBarVisible.Checked;275 ReloadView;276 end;277 278 158 procedure TFormMain.AToolBarVisibleExecute(Sender: TObject); 279 159 begin 280 160 AToolBarVisible.Checked := not AToolBarVisible.Checked; 281 161 ReloadView; 282 end;283 284 procedure TFormMain.AZoomInExecute(Sender: TObject);285 begin286 with Core.CurrentClient do begin287 View.Zoom := View.Zoom * ZoomFactor;288 end;289 Redraw;290 end;291 292 procedure TFormMain.AZoomOutExecute(Sender: TObject);293 //var294 // D: TPoint;295 begin296 with Core.CurrentClient do begin297 //D := Point(Trunc(MousePos.X - View.Left / ViewZoom),298 // Trunc(MousePos.Y - View.Top / ViewZoom));299 View.Zoom := View.Zoom / ZoomFactor;300 //View := Bounds(Trunc((D.X - MousePos.X) * ViewZoom),301 // Trunc((D.Y - MousePos.Y) * ViewZoom),302 // View.Right - View.Left,303 // View.Bottom - View.Top);304 end;305 Redraw;306 162 end; 307 163 … … 316 172 procedure TFormMain.FormDestroy(Sender: TObject); 317 173 begin 318 TempBitmap.Free; 319 end; 320 321 procedure TFormMain.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState 322 ); 323 begin 324 if (Key = 27) or (Key = 17) then 325 if Assigned(Core.Game.CurrentPlayer) then begin 326 Core.CurrentClient.View.SelectedCell := nil; 327 Redraw; 328 end; 174 FormClient.Free; 329 175 end; 330 176 … … 335 181 Core.PersistentForm.Load(Self, wsMaximized); 336 182 ReloadView; 337 Redraw;338 end;339 340 procedure TFormMain.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;341 Shift: TShiftState; X, Y: Integer);342 begin343 if Button = mbLeft then begin344 if Assigned(Core.CurrentClient) then begin345 StartMousePoint := TPoint.Create(X, Y);346 StartViewPoint := Core.CurrentClient.View.SourceRect.P1;347 MoveActive := True;348 end;349 end;350 end;351 352 procedure TFormMain.PaintBox1MouseLeave(Sender: TObject);353 begin354 MoveActive := False;355 end;356 357 procedure TFormMain.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,358 Y: Integer);359 var360 Cell: TCell;361 OldCell: TCell;362 CellPos: TPoint;363 begin364 if Assigned(Core.CurrentClient) then begin365 if MoveActive then366 if (Abs(StartMousePoint.X - X) > Trunc(Screen.PixelsPerInch * MouseMinDiff)) or367 (Abs(StartMousePoint.Y - Y) > Trunc(Screen.PixelsPerInch * MouseMinDiff)) then368 with Core.Game.CurrentPlayer, Core.CurrentClient do begin369 View.SourceRect := TRect.CreateBounds(TPoint.Create(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom),370 Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / View.Zoom)),371 View.SourceRect.Size);372 Redraw;373 end;374 Cell := nil;375 OldCell := Core.CurrentClient.View.FocusedCell;376 with Core.Game do377 Cell := Map.PosToCell(Core.CurrentClient.View.CanvasToCellPos(TPoint.Create(X, Y)), Core.CurrentClient.View );378 if Assigned(Cell) then begin379 Core.CurrentClient.View.FocusedCell := Cell;380 StatusBar1.Panels[0].Text := '[' + IntToStr(Cell.PosPx.X) + ', ' + IntToStr(Cell.PosPx.Y) +381 '] (' + IntToStr(Cell.MovesFrom.Count) + ', ' + IntToStr(Cell.MovesTo.Count) + ')';382 end else begin383 Core.CurrentClient.View.FocusedCell := nil;384 StatusBar1.Panels[0].Text := '';385 end;386 CellPos := Core.CurrentClient.View.CanvasToCellPos(TPoint.Create(X, Y));387 StatusBar1.Panels[2].Text := 'CellPos: ' + IntToStr(CellPos.X) + ', ' + IntToStr(CellPos.Y);388 if Cell <> OldCell then Redraw;389 end else StatusBar1.Panels[0].Text := '';390 end;391 392 procedure TFormMain.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;393 Shift: TShiftState; X, Y: Integer);394 begin395 if (Abs(StartMousePoint.X - X) < Trunc(Screen.PixelsPerInch * MouseMinDiff)) and396 (Abs(StartMousePoint.Y - Y) < Trunc(Screen.PixelsPerInch * MouseMinDiff)) then begin397 if Core.Game.Running and (Core.Game.CurrentPlayer.Mode = pmHuman) then begin398 Core.CurrentClient.View.SelectCell(TPoint.Create(X, Y), Core.Game.CurrentPlayer, Shift);399 Redraw;400 end;401 end;402 MoveActive := False;403 end;404 405 procedure TFormMain.PaintBox1MouseWheelDown(Sender: TObject;406 Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);407 begin408 AZoomOut.Execute;409 end;410 411 procedure TFormMain.PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;412 MousePos: TPoint; var Handled: Boolean);413 begin414 AZoomIn.Execute;415 183 end; 416 184
Note:
See TracChangeset
for help on using the changeset viewer.