Changeset 622 for trunk


Ignore:
Timestamp:
Sep 15, 2024, 10:04:45 PM (2 months ago)
Author:
chronos
Message:
  • Modified: Show windows by default on primary screen if multiple monitors present.
Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Back.lfm

    r426 r622  
    1212  Font.Height = -30
    1313  Font.Name = 'MS Sans Serif'
    14   OnClose = FormClose
    1514  OnCreate = FormCreate
    1615  OnDestroy = FormDestroy
  • trunk/Back.pas

    r468 r622  
    1818    procedure FormShow(Sender: TObject);
    1919    procedure FormCreate(Sender: TObject);
    20     procedure FormClose(Sender: TObject; var Action: TCloseAction);
    2120  private
    2221    Img: TBitmap;
     
    5453begin
    5554  if Assigned(Img) then
    56     BitBltCanvas(Canvas, Screen.Width - Img.Width - (Screen.Width - 800) *
    57       3 div 8, (Screen.Height - 600) div 3, Img.Width, Img.Height,
     55    BitBltCanvas(Canvas, Screen.PrimaryMonitor.Width - Img.Width - (Screen.PrimaryMonitor.Width - 800) *
     56      3 div 8, (Screen.PrimaryMonitor.Height - 600) div 3, Img.Width, Img.Height,
    5857      Img.Canvas, 0, 0);
    59 end;
    60 
    61 procedure TBackground.FormClose(Sender: TObject; var Action: TCloseAction);
    62 begin
    6358end;
    6459
     
    6863begin
    6964  if FullScreen then begin
     65    BoundsRect := Screen.PrimaryMonitor.BoundsRect;
    7066    WindowState := TWindowState.wsFullScreen;
    7167    if not Assigned(Img) then begin
  • trunk/Inp.pas

    r570 r622  
    8989  EditInput.SelLength := Length(EditInput.Text);
    9090  if Center then
    91     CenterToRect(Rect(0, 0, Screen.Width, Screen.Height));
     91    CenterToRect(Screen.PrimaryMonitor.BoundsRect);
    9292  Gtk2DisableControlStyling(EditInput);
    9393end;
  • trunk/LocalPlayer/Battle.pas

    r565 r622  
    207207    OKBtn.Visible := True;
    208208    CancelBtn.Visible := True;
    209     Left := (Screen.Width - ClientWidth) div 2; // center on screen
    210     Top := (Screen.Height - ClientHeight) div 2;
     209    CenterToScreen;
    211210  end
    212211  else
  • trunk/LocalPlayer/CityScreen.pas

    r617 r622  
    11001100      end;
    11011101
    1102   if WindowMode = wmModal then
    1103   begin { center on screen }
    1104     Left := (Screen.Width - Width) div 2;
    1105     Top := (Screen.Height - Height) div 2;
    1106   end;
     1102  if WindowMode = wmModal then CenterToScreen;
    11071103
    11081104  Caption := CityName(C.ID);
  • trunk/LocalPlayer/Diagram.pas

    r550 r622  
    291291procedure TDiaDlg.FormShow(Sender: TObject);
    292292begin
    293   if WindowMode = wmModal then
    294   begin { center on screen }
    295     Left := (Screen.Width - Width) div 2;
    296     Top := (Screen.Height - Height) div 2;
    297   end;
     293  if WindowMode = wmModal then CenterToScreen;
    298294  OffscreenPaint;
    299295end;
  • trunk/LocalPlayer/Draft.pas

    r558 r622  
    485485  yView := yView0 - Cut;
    486486
    487   if WindowMode = wmModal then
    488   begin { center on screen }
    489     Left := (Screen.Width - Template.Width) div 2;
    490     Top := (Screen.Height - (Template.Height - Cut)) div 2;
    491   end;
     487  if WindowMode = wmModal then CenterToScreen(Template.Width, Template.Height - Cut);
    492488
    493489  SetDomain(Domain);
  • trunk/LocalPlayer/Enhance.pas

    r558 r622  
    131131  TypeChanged: Boolean;
    132132begin
    133   OffscreenUser := Self;
     133  inherited;
    134134  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    135135  FillOffscreen(0, 0, InnerWidth, InnerHeight);
  • trunk/LocalPlayer/MessgEx.pas

    r570 r622  
    169169    0:
    170170      begin
    171         Left := (Screen.Width - Width) div 2;
    172         Top := (Screen.Height - Height) div 2 - MapCenterUp;
     171        Left := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2;
     172        Top := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 2 - MapCenterUp;
    173173      end;
    174174    1:
    175175      begin
    176         Left := (Screen.Width - Width) div 4;
    177         Top := (Screen.Height - Height) * 2 div 3 - MapCenterUp;
     176        Left := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 4;
     177        Top := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) * 2 div 3 - MapCenterUp;
    178178      end;
    179179    -1:
    180180      begin
    181         Left := (Screen.Width - Width) div 4;
    182         Top := (Screen.Height - Height) div 3 - MapCenterUp;
     181        Left := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 4;
     182        Top := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 3 - MapCenterUp;
    183183      end;
    184184  end;
  • trunk/LocalPlayer/Nego.pas

    r592 r622  
    485485  OkEnabled: Boolean;
    486486begin
    487   if (OffscreenUser <> nil) and (OffscreenUser <> Self) then
    488     OffscreenUser.Update;
    489   // complete working with old owner to prevent rebound
    490   OffscreenUser := Self;
     487  inherited;
    491488
    492489  if (DipCommand >= 0) and (Page = History[Me].N) then
     
    917914      { opLowTreaty:
    918915        begin
    919         if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire
    920         else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
     916        if MyRO.Treaty[DipMem[Me].pContact] = trNone then Price := opTreaty + trCeaseFire
     917        else Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact]-  1;
    921918        end }
    922919    end;
  • trunk/LocalPlayer/Rates.pas

    r565 r622  
    4040procedure TRatesDlg.FormCreate(Sender: TObject);
    4141begin
    42   TitleHeight := Screen.Height;
     42  TitleHeight := Screen.PrimaryMonitor.Height;
    4343  InitButtons;
    4444end;
  • trunk/LocalPlayer/Select.pas

    r613 r622  
    15451545var
    15461546  I: Integer;
     1547  NewTop, NewLeft: Integer;
    15471548begin
    15481549  Result := -1;
     
    16431644  begin { center on screen }
    16441645    if Kind = kTribe then
    1645       Left := (Screen.Width - 800) * 3 div 8 + 130
     1646      NewLeft := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - 800) * 3 div 8 + 130
    16461647    else
    1647       Left := (Screen.Width - Width) div 2;
    1648     Top := (Screen.Height - Height) div 2;
     1648      NewLeft := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2;
     1649    NewTop := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 2;
    16491650    if Kind = kProject then
    1650       Top := Top + 48;
     1651      NewTop := NewTop + 48;
     1652    BoundsRect := Bounds(NewLeft, NewTop, Width, Height);
    16511653  end;
    16521654
  • trunk/LocalPlayer/TechTree.pas

    r577 r622  
    214214
    215215  // Fit window to image, center image in window, center window to screen
    216   NewWidth := Min(Screen.Width - 40, Image.Width + LeftBorder + RightBorder +
     216  NewWidth := Min(Screen.PrimaryMonitor.Width - 40, Image.Width + LeftBorder + RightBorder +
    217217    2 * BlackBorder);
    218   NewHeight := Min(Screen.Height - 40, Image.Height + TopBorder + BottomBorder +
     218  NewHeight := Min(Screen.PrimaryMonitor.Height - 40, Image.Height + TopBorder + BottomBorder +
    219219    2 * BlackBorder);
    220   BoundsRect := Bounds((Screen.Width - NewWidth) div 2,
    221     (Screen.Height - NewHeight) div 2, NewWidth, NewHeight);
     220  BoundsRect := Bounds(Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - NewWidth) div 2,
     221    Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - NewHeight) div 2, NewWidth, NewHeight);
    222222  CloseBtn.Left := Width - CloseBtn.Width - BlackBorder - 8;
    223223  CloseBtn.Top := BlackBorder + 8;
  • trunk/LocalPlayer/Term.pas

    r621 r622  
    1212{$ENDIF}
    1313  Protocol, Tribes, PVSB, ClientTools, ScreenTools, BaseWin, Messg, ButtonBase,
    14   LCLIntf, LCLType, Menus, SysUtils, Classes, DrawDlg, Types, Math,
     14  LCLIntf, LCLType, SysUtils, Classes, DrawDlg, Types, Math,
    1515  DateUtils, Platform, ButtonB, ButtonC, EOTButton, Area, Help,
    1616  GraphicSet, MiniMap, IsoEngine, Wonders, TechTree, Enhance, Nego, CityType,
     
    26432643          MainTexture.Age := -1;
    26442644        Tribes.Init;
    2645         HelpDlg.UserLeft := (Screen.Width - HelpDlg.Width) div 2;
    2646         HelpDlg.UserTop := (Screen.Height - HelpDlg.Height) div 2;
     2645        HelpDlg.UserLeft := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - HelpDlg.Width) div 2;
     2646        HelpDlg.UserTop := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - HelpDlg.Height) div 2;
    26472647        HelpDlg.Difficulty := 0;
    26482648        if Command = cStartCredits then
     
    59635963      if BattleDlg.Left < 0 then
    59645964        BattleDlg.Left := 0
    5965       else if BattleDlg.Left + BattleDlg.Width > Screen.Width then
    5966         BattleDlg.Left := Screen.Width - BattleDlg.Width;
     5965      else if BattleDlg.Left + BattleDlg.Width > Screen.DesktopWidth then
     5966        BattleDlg.Left := Screen.DesktopWidth - BattleDlg.Width;
    59675967      BattleDlg.Top := Y - BattleDlg.Height div 2;
    59685968      if BattleDlg.Top < 0 then
    59695969        BattleDlg.Top := 0
    5970       else if BattleDlg.Top + BattleDlg.Height > Screen.Height then
    5971         BattleDlg.Top := Screen.Height - BattleDlg.Height;
     5970      else if BattleDlg.Top + BattleDlg.Height > Screen.DesktopHeight then
     5971        BattleDlg.Top := Screen.DesktopHeight - BattleDlg.Height;
    59725972      BattleDlg.IsSuicideQuery := False;
    59735973      BattleDlg.Show;
     
    80658065procedure TMainScreen.FormShow(Sender: TObject);
    80668066begin
    8067   if FullScreen then BoundsRect := Bounds(0, 0, Screen.Width, Screen.Height)
     8067  if FullScreen then BoundsRect := Screen.PrimaryMonitor.BoundsRect
    80688068    else BoundsRect := TermBounds;
    80698069  FormRestoredSize := TermBounds;
     
    83878387
    83888388  if Form is TListDlg then begin;
    8389     ListDlg.UserLeft := 8;
    8390     ListDlg.UserTop := TopBarHeight + 8;
     8389    ListDlg.UserLeft := Screen.PrimaryMonitor.Left + 8;
     8390    ListDlg.UserTop := Screen.PrimaryMonitor.Top + TopBarHeight + 8;
    83918391  end;
    83928392  if Form is THelpDlg then begin
    8393    HelpDlg.UserLeft := Screen.Width - HelpDlg.Width - 8;
    8394     HelpDlg.UserTop := TopBarHeight + 8;
     8393    HelpDlg.UserLeft := Screen.PrimaryMonitor.Left + Screen.PrimaryMonitor.Width - HelpDlg.Width - 8;
     8394    HelpDlg.UserTop := Screen.PrimaryMonitor.Top + TopBarHeight + 8;
    83958395  end;
    83968396  if Form is TUnitStatDlg then begin
    8397     UnitStatDlg.UserLeft := 397;
    8398     UnitStatDlg.UserTop := TopBarHeight + 64;
     8397    UnitStatDlg.UserLeft := Screen.PrimaryMonitor.Left + 397;
     8398    UnitStatDlg.UserTop := Screen.PrimaryMonitor.Top + TopBarHeight + 64;
    83998399  end;
    84008400  if Form is TDiaDlg then begin
    8401     DiaDlg.UserLeft := (Screen.Width - DiaDlg.Width) div 2;
    8402     DiaDlg.UserTop := (Screen.Height - DiaDlg.Height) div 2;
     8401    DiaDlg.UserLeft := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - DiaDlg.Width) div 2;
     8402    DiaDlg.UserTop := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - DiaDlg.Height) div 2;
    84038403  end;
    84048404  if Form is TNatStatDlg then begin
    8405     NatStatDlg.UserLeft := Screen.Width - NatStatDlg.Width - 8;
    8406     NatStatDlg.UserTop := Screen.Height - PanelHeight - NatStatDlg.Height - 8;
     8405    NatStatDlg.UserLeft := Screen.PrimaryMonitor.Left + Screen.PrimaryMonitor.Width - NatStatDlg.Width - 8;
     8406    NatStatDlg.UserTop := Screen.PrimaryMonitor.Top + Screen.PrimaryMonitor.Height - PanelHeight - NatStatDlg.Height - 8;
    84078407    if NatStatDlg.UserTop < 8 then
    84088408      NatStatDlg.UserTop := 8;
  • trunk/LocalPlayer/UnitStat.pas

    r536 r622  
    7777  NoMap := TIsoMap.Create;
    7878  AgePrepared := -2;
    79   TitleHeight := Screen.Height;
     79  TitleHeight := Screen.PrimaryMonitor.Height;
    8080  InitButtons;
    8181
     
    164164  if Kind in [dkOwnModel, dkEnemyModel] then
    165165  begin
    166     Left := UserLeft;
    167     Top := UserTop;
     166    BoundsRect := Bounds(UserLeft, UserTop, Width, Height);
    168167  end else begin
    169     Left := (Screen.Width - Width) div 2;
    170     Top := (Screen.Height - Height) div 2;
     168    BoundsRect := Bounds(Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2,
     169      Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 2,
     170      Width, Height);
    171171  end;
    172172
  • trunk/NoTerm.pas

    r549 r622  
    8787procedure TNoTermDlg.FormCreate(Sender: TObject);
    8888begin
    89   Left := Screen.Width - Width - 8;
    90   Top := 8;
     89  BoundsRect := Bounds(Screen.PrimaryMonitor.Left + Screen.PrimaryMonitor.Width - Width - 8,
     90    8, Width, Height);
    9191  Caption := Phrases.Lookup('AIT');
    9292  Canvas.Brush.Style := TBrushStyle.bsClear;
  • trunk/Packages/CevoComponents/BaseWin.pas

    r620 r622  
    103103  TitleHeight := WideFrame;
    104104  ModalFrameIndent := 45;
    105   UserLeft := (Screen.Width - Width) div 2;
    106   UserTop := (Screen.Height - Height) div 2;
     105  UserLeft := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2;
     106  UserTop := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 2;
    107107end;
    108108
  • trunk/Packages/CevoComponents/DrawDlg.pas

    r617 r622  
    3535    destructor Destroy; override;
    3636    procedure SmartInvalidate; virtual;
     37    procedure CenterToScreen; overload;
     38    procedure CenterToScreen(AWidth, AHeight: Integer); overload;
    3739  end;
    3840
     
    210212end;
    211213
     214procedure TDrawDlg.CenterToScreen;
     215begin
     216  BoundsRect := Bounds(
     217    Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2,
     218    Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 2,
     219    Width, Height);
     220end;
     221
     222procedure TDrawDlg.CenterToScreen(AWidth, AHeight: Integer);
     223begin
     224  BoundsRect := Bounds(
     225    Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - AWidth) div 2,
     226    Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - AHeight) div 2,
     227    Width, Height);
     228end;
     229
    212230{ TBaseMessgDlg }
    213231
    214232procedure TBaseMessgDlg.FormCreate(Sender: TObject);
    215233begin
    216   Left := (Screen.Width - Width) div 2;
     234  Left := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2;
    217235  Canvas.Font.Assign(UniFont[ftNormal]);
    218236  Canvas.Brush.Style := TBrushStyle.bsClear;
    219237  MessgText := '';
    220238  TopSpace := 0;
    221   TitleHeight := Screen.Height;
     239  TitleHeight := Screen.PrimaryMonitor.Height;
    222240  if csDesigning in ComponentState then Exit;
    223241  InitButtons;
     
    287305var
    288306  I: Integer;
    289 begin
    290   Height := 72 + Border + TopSpace + Lines * MessageLineSpacing;
    291   Top := (Screen.Height - Height) div 2;
    292   for i := 0 to ControlCount - 1 do
    293     Controls[i].Top := Height - (34 + Border);
     307  NewHeight: Integer;
     308  NewTop: Integer;
     309begin
     310  NewHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;
     311  NewTop := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - NewHeight) div 2;
     312  BoundsRect := Bounds(Left, NewTop, Width, NewHeight);
     313  for I := 0 to ControlCount - 1 do
     314    Controls[I].Top := NewHeight - (34 + Border);
    294315end;
    295316
  • trunk/Packages/DpiControls/Dpi.Forms.pas

    r500 r622  
    202202  end;
    203203
     204  { TMonitor }
     205
     206  TMonitor = class
     207  private
     208    function GetLeft: Integer;
     209    function GetHeight: Integer;
     210    function GetTop: Integer;
     211    function GetWidth: Integer;
     212    function GetBoundsRect: TRect;
     213  public
     214    NativeMonitor: Forms.TMonitor;
     215    property Left: Integer read GetLeft;
     216    property Height: Integer read GetHeight;
     217    property Top: Integer read GetTop;
     218    property Width: Integer read GetWidth;
     219    property BoundsRect: TRect read GetBoundsRect;
     220  end;
     221
    204222  { TScreen }
    205223
     
    209227    FActiveForm: TForm;
    210228    FPrevActiveForms: TForms;
     229    FPrimaryMonitor: TMonitor;
    211230    FForms: TForms;
    212231    procedure AddForm(AForm: TForm);
     
    215234    function GetDesktopTop: Integer;
    216235    function GetDesktopWidth: Integer;
     236    function GetPrimaryMonitor: TMonitor;
    217237    procedure RemoveForm(AForm: TForm);
    218238    function GetActiveForm: TForm;
     
    248268    property DesktopWidth: Integer read GetDesktopWidth;
    249269    property DesktopHeight: Integer read GetDesktopHeight;
     270    property PrimaryMonitor: TMonitor read GetPrimaryMonitor;
    250271  end;
    251272
     
    477498begin
    478499  Result := Application.MessageBox(Text, Caption, Flags);
     500end;
     501
     502{ TMonitor }
     503
     504function TMonitor.GetLeft: Integer;
     505begin
     506  Result := ScaleFromNative(NativeMonitor.Left);
     507end;
     508
     509function TMonitor.GetHeight: Integer;
     510begin
     511  Result := ScaleFromNative(NativeMonitor.Height);
     512end;
     513
     514function TMonitor.GetTop: Integer;
     515begin
     516  Result := ScaleFromNative(NativeMonitor.Top);
     517end;
     518
     519function TMonitor.GetWidth: Integer;
     520begin
     521  Result := ScaleFromNative(NativeMonitor.Width);
     522end;
     523
     524function TMonitor.GetBoundsRect: TRect;
     525begin
     526  Result := ScaleRectFromNative(NativeMonitor.BoundsRect);
    479527end;
    480528
     
    944992end;
    945993
     994function TScreen.GetPrimaryMonitor: TMonitor;
     995begin
     996  if not Assigned(FPrimaryMonitor) then begin
     997    FPrimaryMonitor := TMonitor.Create;
     998    FPrimaryMonitor.NativeMonitor := LCLScreen.PrimaryMonitor;
     999  end;
     1000  Result := FPrimaryMonitor;
     1001end;
     1002
    9461003procedure TScreen.RemoveForm(AForm: TForm);
    9471004begin
     
    10061063  FreeAndNil(FForms);
    10071064  FreeAndNil(FPrevActiveForms);
     1065  if Assigned(FPrimaryMonitor) then
     1066    FreeAndNil(FPrimaryMonitor);
    10081067  inherited;
    10091068end;
  • trunk/Start.pas

    r597 r622  
    252252    end; // default AI not found, use any
    253253
    254   DirectDlg.Left := (Screen.Width - DirectDlg.Width) div 2;
    255   DirectDlg.Top := (Screen.Height - DirectDlg.Height) div 2;
     254  DirectDlg.CenterToScreen;
    256255
    257256  UpdateInterface;
     
    509508begin
    510509  if FullScreen then begin
    511     Location := Point((Screen.Width - 800) * 3 div 8,
    512       Screen.Height - Height - (Screen.Height - 600) div 3);
     510    Location := Point(Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - 800) * 3 div 8,
     511      Screen.PrimaryMonitor.Top + Screen.PrimaryMonitor.Height - Height - (Screen.PrimaryMonitor.Height - 600) div 3);
    513512    BoundsRect := Bounds(Location.X, Location.Y, Width, Height);
    514513
     
    524523    DeleteObject(r0); // causes crash with Windows 95
    525524  end else begin
    526     BoundsRect := Bounds((Screen.Width - Width) div 2,
    527       (Screen.Height - Height) div 2, Width, Height);
     525    CenterToScreen;
    528526  end;
    529527end;
Note: See TracChangeset for help on using the changeset viewer.