Changeset 212


Ignore:
Timestamp:
May 9, 2020, 9:35:25 PM (5 years ago)
Author:
chronos
Message:
  • Fixed: Better High DPI scaling on highdpi branch.
Location:
branches/highdpi
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/LocalPlayer/Help.pas

    r210 r212  
    445445  x, y, dx, dy, xSrc, ySrc, sum, xx: integer;
    446446  Heaven: array [0..nHeaven] of integer;
    447   PaintPtr, CoalPtr: TPixelPointer;
     447  PaintPtr: TPixelPointer;
     448  CoalPtr: TPixelPointer;
    448449  ImpPtr: array [-1..1] of TPixelPointer;
    449450begin
  • branches/highdpi/LocalPlayer/IsoEngine.pas

    r210 r212  
    3434    function IsShoreTile(Loc: integer): boolean;
    3535    procedure MakeDark(Line: PPixelPointer; Length: Integer);
    36     procedure ShadeOutside(x0, y0, x1, y1, xm, ym: integer);
     36    procedure ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
    3737  protected
    3838    FOutput: TDpiBitmap;
     
    10151015            1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1));
    10161016          Borders.BeginUpdate;
    1017           for dy := 0 to yyt * 2 - 1 do
    1018           begin
    1019             PixelPtr := PixelPointer(Borders, 0, p1 * (yyt * 2) + dy);
    1020             for dx := 0 to xxt * 2 - 1 do begin
     1017          PixelPtr := PixelPointer(Borders, ScaleToVcl(0), ScaleToVcl(p1 * (yyt * 2)));
     1018          for dy := 0 to ScaleToVcl(yyt * 2) - 1 do begin
     1019            for dx := 0 to ScaleToVcl(xxt * 2) - 1 do begin
    10211020              if PixelPtr.Pixel^.B = 99 then begin
    10221021                PixelPtr.Pixel^.B := Tribe[p1].Color shr 16 and $FF;
     
    10261025              PixelPtr.NextPixel;
    10271026            end;
     1027            PixelPtr.NextLine;
    10281028          end;
    10291029          Borders.EndUpdate;
     
    13301330end;
    13311331
    1332 procedure TIsoMap.ShadeOutside(x0, y0, x1, y1, xm, ym: integer);
     1332procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
    13331333const
    13341334  rShade = 3.75;
     
    13391339begin
    13401340  FOutput.BeginUpdate;
    1341   for y := y0 to y1 - 1 do begin
    1342     Line := PixelPointer(FOutput, 0, y);
    1343     y_n := (y - ym) / yyt;
    1344     if abs(y_n) < rShade then begin
     1341  Line := PixelPointer(FOutput, ScaleToVcl(x0), ScaleToVcl(y0));
     1342  for y := 0 to ScaleToVcl(Height) - 1 do begin
     1343    y_n := (ScaleFromVcl(y) + y0 - ym) / yyt;
     1344    if Abs(y_n) < rShade then begin
    13451345      // Darken left and right parts of elipsis
    1346       w_n := sqrt(sqr(rShade) - sqr(y_n));
    1347       wBright := trunc(w_n * xxt + 0.5);
    1348       Line.SetX(x0);
    1349       MakeDark(@Line, xm - x0 - wBright);
    1350       Line.SetX(xm + wBright);
    1351       MakeDark(@Line, x1 - xm - wBright);
     1346      w_n := Sqrt(Sqr(rShade) - Sqr(y_n));
     1347      wBright := Trunc(w_n * xxt + 0.5);
     1348      Line.SetX(0);
     1349      MakeDark(@Line, ScaleToVcl(xm - wBright));
     1350      Line.SetX(ScaleToVcl(xm + wBright));
     1351      MakeDark(@Line, ScaleToVcl(Width - xm - wBright));
    13521352    end else begin
    13531353      // Darken entire line
    1354       Line.SetX(x0);
    1355       MakeDark(@Line, x1 - x0);
     1354      Line.SetX(0);
     1355      MakeDark(@Line, ScaleToVcl(Width));
    13561356    end;
     1357    Line.NextLine;
    13571358  end;
    13581359  FOutput.EndUpdate;
     
    15761577    xm := x + (dx + 1) * xxt;
    15771578    ym := y + (dy + 1) * yyt + yyt;
    1578     ShadeOutside(FLeft, FTop, FRight, FBottom, xm, ym);
     1579    ShadeOutside(FLeft, FTop, FRight - FLeft, FBottom - FTop, xm, ym);
    15791580    CityGrid(xm, ym, CityAllowClick);
    15801581    for dy := -2 to ny + 1 do
  • branches/highdpi/LocalPlayer/Term.pas

    r210 r212  
    532532  SmallScreen, GameOK, MapValid, skipped, idle: boolean;
    533533
    534   SaveOption: array [0 .. nSaveOption - 1] of integer;
    535   MiniColors: array [0 .. 11, 0 .. 1] of TColor;
     534  SaveOption: array [0..nSaveOption - 1] of integer;
     535  MiniColors: array [0..fTerrain, 0..1] of TColor;
    536536  MainMap: TIsoMap;
    537537  CurrentMoveInfo: record AfterMovePaintRadius, AfterAttackExpeller: integer;
     
    40774077  MiniPixel := PixelPointer(Mini);
    40784078  PrevMiniPixel := PixelPointer(Mini);
    4079   for y := 0 to G.ly - 1 do
    4080   begin
    4081     for x := 0 to G.lx - 1 do
    4082       if MyMap[x + G.lx * y] and fTerrain <> fUNKNOWN then
    4083       begin
    4084         Loc := x + G.lx * y;
     4079  for y := 0 to ScaleToVcl(G.ly) - 1 do
     4080  begin
     4081    for x := 0 to ScaleToVcl(G.lx) - 1 do
     4082      if MyMap[ScaleFromVcl(x) + G.lx * ScaleFromVcl(y)] and fTerrain <> fUNKNOWN then
     4083      begin
     4084        Loc := ScaleFromVcl(x) + G.lx * ScaleFromVcl(y);
    40854085        for i := 0 to 1 do
    40864086        begin
    4087           xm := ((x - xwMini) * 2 + i + y and 1 - hw + G.lx * 5) mod (G.lx * 2);
     4087          xm := ((x - ScaleToVcl(xwMini)) * 2 + i + y and 1 - ScaleToVcl(hw) +
     4088            ScaleToVcl(G.lx) * 5) mod (ScaleToVcl(G.lx) * 2);
    40884089          MiniPixel.SetXY(xm, y);
    40894090          cm := MiniColors[MyMap[Loc] and fTerrain, i];
     
    50795080        dx := 0;
    50805081        dy := 0;
    5081         if Mouse.CursorPos.y < DpiScreen.height - PanelHeight then
    5082           if Mouse.CursorPos.x = 0 then
     5082        if DpiMouse.CursorPos.y < DpiScreen.height - PanelHeight then
     5083          if DpiMouse.CursorPos.x = 0 then
    50835084            dx := -speed // scroll left
    5084           else if Mouse.CursorPos.x = DpiScreen.width - 1 then
     5085          else if DpiMouse.CursorPos.x = DpiScreen.width - 1 then
    50855086            dx := speed; // scroll right
    5086         if Mouse.CursorPos.y = 0 then
     5087        if DpiMouse.CursorPos.y = 0 then
    50875088          dy := -speed // scroll up
    5088         else if (Mouse.CursorPos.y = DpiScreen.height - 1) and
    5089           (Mouse.CursorPos.x >= TerrainBtn.Left + TerrainBtn.width) and
    5090           (Mouse.CursorPos.x < xRightPanel + 10 - 8) then
     5089        else if (DpiMouse.CursorPos.y = DpiScreen.height - 1) and
     5090          (DpiMouse.CursorPos.x >= TerrainBtn.Left + TerrainBtn.width) and
     5091          (DpiMouse.CursorPos.x < xRightPanel + 10 - 8) then
    50915092          dy := speed; // scroll down
    50925093        if (dx <> 0) or (dy <> 0) then
  • branches/highdpi/Packages/CevoComponents/DrawDlg.pas

    r210 r212  
    128128  {$IFDEF LINUX}
    129129  // HitTest is not supported under Linux GTK2 so use form inside move mechanizm
    130   NewFormPos := ScreenToClient(Mouse.CursorPos);
     130  NewFormPos := ScreenToClient(DpiMouse.CursorPos);
    131131  if (NewFormPos.X >= 0) and (NewFormPos.X < Width) and
    132132    (NewFormPos.Y >= 0) and (NewFormPos.Y < Height) then begin
    133133    MoveMousePos := ClientToScreen(Point(X, Y));
    134134    MoveFormPos := Point(Left, Top);
    135     MousePosNew := Mouse.CursorPos;
     135    MousePosNew := DpiMouse.CursorPos;
    136136    // Activate move only if mouse position was not changed during inherited call
    137137    if (MousePosNew.X = MoveMousePos.X) and (MousePosNew.Y = MoveMousePos.Y) then begin
  • branches/highdpi/Packages/DpiControls/UDpiControls.pas

    r210 r212  
    3838    property OnMouseUp;
    3939    property OnMouseMove;
     40    property OnMouseWheel;
     41    property OnMouseLeave;
     42    property OnMouseEnter;
    4043  end;
    4144
     
    122125    FLeft: Integer;
    123126    FOnChangeBounds: TNotifyEvent;
     127    FOnMouseUp: TMouseEvent;
    124128    FOnMouseDown: TMouseEvent;
    125129    FOnMouseMove: TMouseMoveEvent;
    126     FOnMouseUp: TMouseEvent;
     130    FOnMouseEnter: TNotifyEvent;
     131    FOnMouseLeave: TNotifyEvent;
    127132    FOnMouseWheel: TMouseWheelEvent;
    128133    FOnResize: TNotifyEvent;
     
    161166    procedure DoFormResize;
    162167    procedure DoChangeBounds;
     168    procedure MouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
     169      X, Y: Integer); virtual;
     170    procedure MouseUpHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
     171      X, Y: Integer); virtual;
     172    procedure MouseMoveHandler(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual;
     173    procedure MouseWheelHandler(Sender: TObject; Shift: TShiftState;
     174         WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual;
     175    procedure MouseLeaveHandler(Sender: TObject); virtual;
     176    procedure MouseEnterHandler(Sender: TObject); virtual;
    163177  protected
    164178    procedure UpdateBounds; virtual;
     
    174188    function GetVclControl: TControl; virtual;
    175189    procedure UpdateVclControl; virtual;
    176     procedure MouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
    177       X, Y: Integer); virtual;
    178     procedure MouseUpHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
    179       X, Y: Integer); virtual;
    180     procedure MouseMoveHandler(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual;
    181     procedure MouseWheelHandler(Sender: TObject; Shift: TShiftState;
    182          WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual;
    183190    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
    184191      X, Y: Integer); virtual;
     
    187194    procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual;
    188195    procedure MouseLeave; virtual;
     196    procedure MouseEnter; virtual;
    189197  public
    190198    function ScreenToClient(const APoint: TPoint): TPoint; virtual;
     
    333341    function GetVclGraphicControl: TGraphicControl; virtual;
    334342    procedure UpdateVclControl; override;
    335     procedure UpdateVclControlPrivate; virtual;
    336343    property OnPaint: TNotifyEvent read GetOnPaint write SetOnPaint;
    337344  public
     
    668675
    669676  TDpiPaintBox = class(TDpiGraphicControl)
    670   private
    671     procedure UpdateVclControlPrivate; override;
    672677  public
    673678    VclPaintBox: TPaintBox;
     
    689694    FForms: TDpiForms;
    690695    procedure AddForm(AForm: TDpiForm);
     696    procedure RemoveForm(AForm: TDpiForm);
    691697    function GetActiveForm: TDpiForm;
    692698    function GetCursor: TCursor;
     
    767773  end;
    768774
     775  { TDpiMouse }
     776
     777  // TMouse
     778  TDpiMouse = class
     779  private
     780    function GetCursorPos: TPoint;
     781    procedure SetCursorPos(AValue: TPoint);
     782  public
     783    property CursorPos: TPoint read GetCursorPos write SetCursorPos;
     784  end;
     785
    769786var
    770787  DpiFormFileDesc: TDpiFormFileDesc;
    771788  DpiScreen: TDpiScreen;
    772789  DpiApplication: TDpiApplication;
     790  DpiMouse: TDpiMouse;
    773791
    774792procedure Register;
     
    869887end;
    870888
     889{ TDpiMouse }
     890
     891function TDpiMouse.GetCursorPos: TPoint;
     892begin
     893  Result := ScalePointFromVcl(Mouse.CursorPos);
     894end;
     895
     896procedure TDpiMouse.SetCursorPos(AValue: TPoint);
     897begin
     898  Mouse.CursorPos := ScalePointToVcl(AValue);
     899end;
     900
    871901{ TDpiSizeConstraints }
    872902
     
    15491579{ TDpiPaintBox }
    15501580
    1551 procedure TDpiPaintBox.UpdateVclControlPrivate;
    1552 begin
    1553   VclPaintBox.OnPaint := @PaintHandler;
    1554   VclPaintBox.OnMouseDown := @MouseDownHandler;
    1555   VclPaintBox.OnMouseUp := @MouseUpHandler;
    1556   VclPaintBox.OnMouseMove := @MouseMoveHandler;
    1557 end;
    1558 
    15591581function TDpiPaintBox.GetVclGraphicControl: TGraphicControl;
    15601582begin
     
    17961818begin
    17971819  inherited;
    1798   UpdateVclControlPrivate;
    1799 end;
    1800 
    1801 procedure TDpiGraphicControl.UpdateVclControlPrivate;
    1802 begin
    18031820  TGraphicControlEx(GetVclGraphicControl).OnPaint := @PaintHandler;
    1804   TControlEx(GetVclControl).OnMouseDown := @MouseDownHandler;
    1805   TControlEx(GetVclControl).OnMouseUp := @MouseUpHandler;
    1806   TControlEx(GetVclControl).OnMouseMove := @MouseMoveHandler;
    1807   // Some VCL component event are not accessible on TGraphicControl level.
    1808   // Delegate this responsibility up
    1809   {
    1810   GetVclGraphicControl.OnPaint := @PaintHandler;
    1811   GetVclControl.OnMouseDown := @MouseDownHandler;
    1812   GetVclControl.OnMouseUp := @MouseUpHandler;
    1813   GetVclControl.OnMouseMove := @MouseMoveHandler;
    1814   }
    1815 //  raise Exception.Create('Missing inicialization of private fields for ' + ClassName);
    18161821end;
    18171822
     
    21342139end;
    21352140
     2141procedure TDpiScreen.RemoveForm(AForm: TDpiForm);
     2142begin
     2143  FForms.Remove(AForm);
     2144  if AForm = FActiveForm then FActiveForm := nil;
     2145end;
     2146
    21362147function TDpiScreen.GetActiveForm: TDpiForm;
    21372148begin
     
    21612172  FForms := TDpiForms.Create;
    21622173  FForms.FreeObjects := False;
    2163   Dpi := 150;
     2174  Dpi := Round(96 * 2); //Screen.PixelsPerInch;
    21642175end;
    21652176
     
    22142225  GetVclControl.OnResize := @VclFormResize;
    22152226  GetVclControl.OnChangeBounds := @VclChangeBounds;
     2227  TControlEx(GetVclControl).OnMouseDown := @MouseDownHandler;
     2228  TControlEx(GetVclControl).OnMouseUp := @MouseUpHandler;
     2229  TControlEx(GetVclControl).OnMouseMove := @MouseMoveHandler;
     2230  TControlEx(GetVclControl).OnMouseEnter := @MouseEnterHandler;
     2231  TControlEx(GetVclControl).OnMouseLeave := @MouseLeaveHandler;
     2232  TControlEx(GetVclControl).OnMouseWheel := @MouseWheelHandler;
    22162233end;
    22172234
     
    22442261end;
    22452262
     2263procedure TDpiControl.MouseLeaveHandler(Sender: TObject);
     2264begin
     2265  MouseLeave;
     2266  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
     2267end;
     2268
     2269procedure TDpiControl.MouseEnterHandler(Sender: TObject);
     2270begin
     2271  MouseEnter;
     2272  if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
     2273end;
     2274
    22462275procedure TDpiControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
    22472276  Y: Integer);
     
    22602289procedure TDpiControl.MouseLeave;
    22612290begin
    2262 
     2291end;
     2292
     2293procedure TDpiControl.MouseEnter;
     2294begin
    22632295end;
    22642296
     
    28172849begin
    28182850  inherited;
    2819   GetVclForm.OnMouseDown := @MouseDownHandler;
    2820   GetVclForm.OnMouseUp := @MouseUpHandler;
    2821   GetVclForm.OnMouseMove := @MouseMoveHandler;
    28222851  GetVclForm.OnActivate := @ActivateHandler;
    28232852  GetVclForm.OnDeactivate := @DeactivateHandler;
     
    28472876// Init the component with an IDE resource
    28482877constructor TDpiForm.Create(TheOwner: TComponent);
    2849 var
    2850   C: TComponent;
    28512878begin
    28522879  //inherited;
     
    28552882  try
    28562883    CreateNew(TheOwner, 1); // this calls BeginFormUpdate, which is ended in AfterConstruction
    2857     // Self
    2858     C := FindGlobalComponent('TListDlg');
    28592884    if (ClassType <> TDpiForm) and not (csDesigning in ComponentState) then begin
    28602885      if not InitResourceComponent(Self, TDataModule) then begin
     
    28782903begin
    28792904  FreeAndNil(VclForm);
     2905  DpiScreen.RemoveForm(Self);
    28802906end;
    28812907
  • branches/highdpi/Start.pas

    r210 r212  
    4848    Bitmap: TDpiBitmap; { game world sample preview }
    4949    Size: TPoint;
    50     Colors: array [0 .. 11, 0 .. 1] of TColor;
     50    Colors: array [0..fTerrain, 0..1] of TColor;
    5151    Mode: TMiniMode;
    5252    procedure LoadFromLogFile(FileName: string; var LastTurn: Integer);
Note: See TracChangeset for help on using the changeset viewer.