Changeset 68


Ignore:
Timestamp:
Nov 28, 2020, 12:17:21 PM (4 years ago)
Author:
chronos
Message:
  • Fixed: Canvas width and height is not updated correctly on Windows. Use additional CanvasSize parameter in drawing methods.
  • Fixed: Fullscreen was not working on Windows. Form border was not hidden.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r66 r68  
    7575  if not Initialized then begin
    7676    Initialized := True;
     77    PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
     78    PersistentForm1.Load(Self, False, True);
     79    FullScreen := PersistentForm1.FormFullScreen;
     80    Randomize;
     81    Engine.InitMenus;
     82    Engine.ImagePassenger.Picture.Assign(FormImages.ImagePassenger.Picture);
     83    Engine.ImageLocomotive.Picture.Assign(FormImages.ImageLocomotive.Picture);
     84    Engine.Map.Size := Point(PaintBox1.Width, PaintBox1.Height);
     85    Engine.View.DestRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
     86    Engine.MainMenu;
    7787  end;
    7888end;
     
    111121procedure TFormMain.FormShow(Sender: TObject);
    112122begin
    113   PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
    114   PersistentForm1.Load(Self, False, True);
    115   FullScreen := PersistentForm1.FormFullScreen;
    116   Randomize;
    117   Engine.InitMenus;
    118   Engine.ImagePassenger.Picture.Assign(FormImages.ImagePassenger.Picture);
    119   Engine.ImageLocomotive.Picture.Assign(FormImages.ImageLocomotive.Picture);
    120   Engine.Map.Size := Point(PaintBox1.Width, PaintBox1.Height);
    121   Engine.View.DestRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
    122   Engine.MainMenu;
    123123end;
    124124
     
    156156begin
    157157  Engine.View.DestRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
    158   Engine.Paint(PaintBox1.Canvas);
     158  Engine.Paint(PaintBox1.Canvas, Point(PaintBox1.Width, PaintBox1.Height));
    159159end;
    160160
  • trunk/Packages/Common/UPersistentForm.pas

    r63 r68  
    317317      Form.RestoredHeight);
    318318    ShowWindow(Form.Handle, SW_SHOWFULLSCREEN);
     319    {$IFDEF WINDOWS}
     320    Form.BorderStyle := bsNone;
     321    {$ENDIF}
    319322  end else begin
    320323    FormFullScreen := False;
     
    323326      //Form.BoundsRect := FormRestoredSize;
    324327    end else if Form.WindowState = wsMaximized then ShowWindow(Form.Handle, SW_SHOWMAXIMIZED);
     328    {$IFDEF WINDOWS}
     329    Form.BorderStyle := bsSizeable;
     330    {$ENDIF}
    325331  end;
    326332end;
  • trunk/UEngine.pas

    r67 r68  
    303303    procedure DrawShape(Canvas: TCanvas; Position: TPoint; Shape: TStationShape;
    304304      Size: Integer; Angle: Double);
    305     procedure DrawClock(Canvas: TCanvas);
     305    procedure DrawClock(Canvas: TCanvas; CanvasSize: TPoint);
    306306    procedure DrawTrains(Canvas: TCanvas);
    307     procedure DrawGameOver(Canvas: TCanvas);
     307    procedure DrawGameOver(Canvas: TCanvas; CanvasSize: TPoint);
    308308    procedure DrawStationPassengerOverload(Canvas: TCanvas);
    309309    procedure DrawLines(Canvas: TCanvas);
    310310    procedure DrawStations(Canvas: TCanvas);
    311     procedure DrawGameControls(Canvas: TCanvas);
     311    procedure DrawGameControls(Canvas: TCanvas; CanvasSize: TPoint);
    312312    procedure ComputeShapeDistance;
    313313    procedure ComputeShapeDistanceStation(Station: TMapStation;
     
    361361    destructor Destroy; override;
    362362    procedure Tick;
    363     procedure Paint(Canvas: TCanvas);
     363    procedure Paint(Canvas: TCanvas; CanvasSize: TPoint);
    364364    property Time: TDateTime read FTime;
    365365    property DarkMode: Boolean read FDarkMode write SetDarkMode;
     
    20902090end;
    20912091
    2092 procedure TEngine.DrawClock(Canvas: TCanvas);
     2092procedure TEngine.DrawClock(Canvas: TCanvas; CanvasSize: TPoint);
    20932093var
    20942094  ClockCenter: TPoint;
     
    21032103  Canvas.Pen.Color := Colors.Text;
    21042104  Canvas.Pen.Width := 2;
    2105   ClockCenter := Point(Canvas.Width - 30, 40);
     2105  ClockCenter := Point(CanvasSize.X - 30, 40);
    21062106  Angle := Time / (12 * OneHour) * 2 * Pi - Pi / 2;
    21072107  Canvas.EllipseC(ClockCenter.X, ClockCenter.Y, ClockSize, ClockSize);
     
    21662166end;
    21672167
    2168 procedure TEngine.DrawGameOver(Canvas: TCanvas);
     2168procedure TEngine.DrawGameOver(Canvas: TCanvas; CanvasSize: TPoint);
    21692169var
    21702170  Y: Integer;
     
    21782178    Y := 100;
    21792179    Font.Size := 40;
    2180     TextOut((Width - TextWidth(SGameOver)) div 2, Y, SGameOver);
     2180    TextOut((CanvasSize.X - TextWidth(SGameOver)) div 2, Y, SGameOver);
    21812181    Y := Y + Round(TextHeight(SGameOver) * 1.1);
    21822182
    21832183    Font.Size := 14;
    2184     TextOut((Width - TextWidth(SGameOverReason)) div 2, Y, SGameOverReason);
     2184    TextOut((CanvasSize.X - TextWidth(SGameOverReason)) div 2, Y, SGameOverReason);
    21852185    Y := Y + Round(TextHeight(SGameOverReason) * 1.1);
    21862186
    21872187    Text := Format(SGameOverStatistic, [ServedPassengerCount, ServedDaysCount]);
    2188     TextOut((Width - TextWidth(Text)) div 2, Y, Text);
     2188    TextOut((CanvasSize.X - TextWidth(Text)) div 2, Y, Text);
    21892189    Y := Y + Round(TextHeight(SGameOverStatistic) * 1.1);
    21902190
     
    21992199    Text := Text + Format(SOldHighScore, [HighestServedPassengerCount,
    22002200      HighestServedDaysCount]);
    2201     Canvas.TextOut((Canvas.Width - Canvas.TextWidth(Text)) div 2, Y, Text);
     2201    Canvas.TextOut((CanvasSize.X - TextWidth(Text)) div 2, Y, Text);
    22022202    Y := Y + Round(TextHeight(Text) * 1.1);
    22032203    if (ServedPassengerCount > HighestServedPassengerCount) then
     
    23632363end;
    23642364
    2365 procedure TEngine.DrawGameControls(Canvas: TCanvas);
     2365procedure TEngine.DrawGameControls(Canvas: TCanvas; CanvasSize: TPoint);
    23662366var
    23672367  I: Integer;
     
    23882388    end;
    23892389
    2390     Canvas.EllipseC(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist,
    2391       Canvas.Height - LineColorsDist, Radius, Radius);
     2390    Canvas.EllipseC(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist,
     2391      CanvasSize.Y - LineColorsDist, Radius, Radius);
    23922392  end;
    23932393
    23942394  // Draw unused trains
    23952395  Text := IntToStr(Trains.GetUnusedCount);
    2396   Canvas.Draw(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 100,
    2397     Canvas.Height - LineColorsDist - ImageLocomotive.Picture.Bitmap.Height div 2, ImageLocomotive.Picture.Bitmap);
     2396  Canvas.Draw(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist - 100,
     2397    CanvasSize.Y - LineColorsDist - ImageLocomotive.Picture.Bitmap.Height div 2, ImageLocomotive.Picture.Bitmap);
    23982398  Canvas.Brush.Style := bsClear;
    23992399  Canvas.Font.Size := 14;
    24002400  Canvas.Font.Color := Colors.Text;
    2401   Canvas.TextOut(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - Canvas.TextWidth(Text),
    2402     Canvas.Height - LineColorsDist - Canvas.TextHeight(Text) div 2, Text);
     2401  Canvas.TextOut(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - Canvas.TextWidth(Text),
     2402    CanvasSize.Y - LineColorsDist - Canvas.TextHeight(Text) div 2, Text);
    24032403
    24042404  // Status interface
    24052405  Text := IntToStr(ServedPassengerCount);
    2406   Canvas.Draw(Canvas.Width - 50, Canvas.Height - 60, ImagePassenger.Picture.Bitmap);
     2406  Canvas.Draw(CanvasSize.X - 50, CanvasSize.Y - 60, ImagePassenger.Picture.Bitmap);
    24072407  Canvas.Brush.Style := bsClear;
    24082408  Canvas.Font.Size := 14;
    24092409  Canvas.Font.Color := Colors.Text;
    2410   Canvas.TextOut(Canvas.Width - 70 - Canvas.TextWidth(Text), Canvas.Height - 55, Text);
    2411 
    2412   DrawClock(Canvas);
     2410  Canvas.TextOut(CanvasSize.X - 70 - Canvas.TextWidth(Text),
     2411    CanvasSize.Y - 55, Text);
     2412
     2413  DrawClock(Canvas, CanvasSize);
    24132414
    24142415  // Back button
     
    28382839end;
    28392840
    2840 procedure TEngine.Paint(Canvas: TCanvas);
     2841procedure TEngine.Paint(Canvas: TCanvas; CanvasSize: TPoint);
    28412842begin
    28422843  MetaCanvas.Size := Point(Canvas.Width, Canvas.Height);
     
    28602861
    28612862  if State <> gsMenu then begin
    2862     DrawGameControls(Canvas);
     2863    DrawGameControls(Canvas, CanvasSize);
    28632864  end;
    28642865
     
    28662867  if State = gsGameOver then
    28672868  begin
    2868     DrawGameOver(Canvas);
     2869    DrawGameOver(Canvas, CanvasSize);
    28692870  end else
    28702871  if State = gsMenu then begin
    2871     Menu.Paint(Canvas);
     2872    Menu.Paint(Canvas, CanvasSize);
    28722873  end;
    28732874
  • trunk/UMenu.pas

    r64 r68  
    8181    procedure MouseMove(Position: TPoint);
    8282    procedure MouseUp(Button: TMouseButton; Position: TPoint);
    83     procedure Paint(Canvas: TCanvas);
     83    procedure Paint(Canvas: TCanvas; CanvasSize: TPoint);
    8484    constructor Create;
    8585    destructor Destroy; override;
     
    216216end;
    217217
    218 procedure TMenu.Paint(Canvas: TCanvas);
     218procedure TMenu.Paint(Canvas: TCanvas; CanvasSize: TPoint);
    219219var
    220220  I: Integer;
     
    240240    end;
    241241
    242     X := (Width - TotalWidth) div 2;
    243     Y := (Height - TotalHeight) div 2;
     242    X := (CanvasSize.X - TotalWidth) div 2;
     243    Y := (CanvasSize.Y - TotalHeight) div 2;
    244244
    245245    // Menu items
Note: See TracChangeset for help on using the changeset viewer.