Changeset 97 for trunk/UEngine.pas


Ignore:
Timestamp:
Sep 28, 2022, 1:18:41 PM (20 months ago)
Author:
chronos
Message:
  • Fixed: Normalized images quality and on screen placement.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r96 r97  
    178178    LastState: TGameState;
    179179    TimePerSecond: TDateTime;
     180    ImprovementImageSize: Integer;
     181    IconSize: Integer;
    180182    function GetServedDaysCount: Integer;
    181183    procedure ResizeView;
     
    301303  LineColorsDist = 50;
    302304  TrainSpeed = 2000;
    303   ImagePassengerName = 'Images/Passenger.png';
    304   ImageLocomotiveName = 'Images/Locomotive.png';
    305   ImageLeftArrowName = 'Images/Left arrow.png';
    306   ImagePlayName = 'Images/Play.png';
    307   ImagePauseName = 'Images/Pause.png';
    308   ImageFastForwardName = 'Images/Fast forward.png';
    309305  TrainPassengerCount = 6;
    310306  StationMinDistance = 100;
     
    21732169
    21742170    ImageNewTrain.Canvas := Canvas;
    2175     ImageNewTrain.Bounds := Bounds((CanvasSize.X - ImageLocomotive.Bitmap.Width * ImageZoom) div 2,
    2176       (CanvasSize.Y - ImageLocomotive.Bitmap.Height * ImageZoom) div 2,
    2177       ImageLocomotive.Bitmap.Width * ImageZoom,
    2178       ImageLocomotive.Bitmap.Height * ImageZoom);
     2171    ImageNewTrain.Bounds := Bounds(CanvasSize.X div 2 - ImprovementImageSize div 2,
     2172      CanvasSize.Y div 2 - ImprovementImageSize div 2,
     2173      ImprovementImageSize, ImprovementImageSize);
    21792174    ImageNewTrain.Paint;
    21802175
    2181     Y := (CanvasSize.Y - ImageLocomotive.Bitmap.Height * ImageZoom) div 2 +
    2182       Round(ImageLocomotive.Bitmap.Height * ImageZoom * 1.1);
     2176    Y := (CanvasSize.Y - ImprovementImageSize) div 2 +
     2177      Round(ImprovementImageSize * 1.1);
    21832178
    21842179    Text := STrain;
     
    21962191  Y: Integer;
    21972192  X: Integer;
    2198 const
    2199   ImageZoom = 4;
     2193  Center: TPoint;
    22002194begin
    22012195  with Canvas do begin
     2196    Center := Point(CanvasSize.X div 2, CanvasSize.Y div 2);
     2197
    22022198    Pen.Color := Self.Colors.Text;
    22032199    Pen.Style := psSolid;
     
    22262222    if Improvement1 <> miNone then begin
    22272223      ImageNewImprovement1.Canvas := Canvas;
    2228       ImageNewImprovement1.Bounds := Bounds(CanvasSize.X div 2 - CanvasSize.X div 8 -
    2229         ImageNewImprovement1.Bitmap.Width * ImageZoom div 2,
    2230         (CanvasSize.Y - ImageNewImprovement1.Bitmap.Height * ImageZoom) div 2,
    2231         ImageNewImprovement1.Bitmap.Width * ImageZoom,
    2232         ImageNewImprovement1.Bitmap.Height * ImageZoom);
     2224      ImageNewImprovement1.Bounds := Bounds(Center.X - CanvasSize.X div 8 -
     2225        ImprovementImageSize div 2, Center.Y - ImprovementImageSize div 2,
     2226        ImprovementImageSize, ImprovementImageSize);
    22332227      ImageNewImprovement1.Paint;
    22342228    end;
     
    22362230    if Improvement2 <> miNone then begin
    22372231      ImageNewImprovement2.Canvas := Canvas;
    2238       ImageNewImprovement2.Bounds := Bounds(CanvasSize.X div 2 + CanvasSize.X div 8 -
    2239         ImageNewImprovement2.Bitmap.Width * ImageZoom div 2,
    2240         (CanvasSize.Y - ImageNewImprovement2.Bitmap.Height * ImageZoom) div 2,
    2241         ImageNewImprovement2.Bitmap.Width * ImageZoom,
    2242         ImageNewImprovement2.Bitmap.Height * ImageZoom);
     2232      ImageNewImprovement2.Bounds := Bounds(Center.X + CanvasSize.X div 8 -
     2233        ImprovementImageSize div 2, Center.Y - ImprovementImageSize div 2,
     2234        ImprovementImageSize, ImprovementImageSize);
    22432235     ImageNewImprovement2.Paint;
    22442236    end;
    22452237
    2246     Y := (CanvasSize.Y - ImageLocomotive.Bitmap.Height * ImageZoom) div 2 +
    2247       Round(ImageLocomotive.Bitmap.Height * ImageZoom * 1.1);
     2238    Y := Center.Y - ImprovementImageSize div 2 +
     2239      Round(ImprovementImageSize * 1.1);
    22482240
    22492241    if Improvement1 <> miNone then begin
     
    22522244      Font.Color := Self.Colors.Text;
    22532245      TextSize := TextExtent(Text);
    2254       TextOut(CanvasSize.X div 2 - CanvasSize.X div 8 - TextSize.Width div 2, Y, Text);
     2246      TextOut(Center.X - CanvasSize.X div 8 - TextSize.Width div 2, Y, Text);
    22552247    end;
    22562248
     
    22602252      Font.Color := Self.Colors.Text;
    22612253      TextSize := TextExtent(Text);
    2262       TextOut(CanvasSize.X div 2 + CanvasSize.X div 8 - TextSize.Width div 2, Y, Text);
     2254      TextOut(Center.X + CanvasSize.X div 8 - TextSize.Width div 2, Y, Text);
    22632255    end;
    22642256  end;
     
    24272419  Angle: Real;
    24282420  Pos: TPoint;
    2429 begin
     2421  X: Integer;
     2422  Y: Integer;
     2423  SeparatorSize: Integer;
     2424begin
     2425  SeparatorSize := ScaleX(20, 96);
     2426  X := CanvasSize.X div 2;
     2427  Y := CanvasSize.Y - LineColorsDist;
     2428
    24302429  // Line selection
    24312430  Canvas.Pen.Width := 4;
     
    24452444    end;
    24462445
    2447     Canvas.EllipseC(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist,
    2448       CanvasSize.Y - LineColorsDist, Radius, Radius);
    2449   end;
     2446    Canvas.EllipseC(X - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist,
     2447      Y, Radius, Radius);
     2448  end;
     2449  X := X - Length(LineColors) div 2 * LineColorsDist - 2 * SeparatorSize;
    24502450
    24512451  // Draw unused trains
     2452  ImageLocomotive.Bounds := Bounds(X - IconSize, Y - IconSize div 2,
     2453    IconSize, IconSize);
     2454  ImageLocomotive.Canvas := Canvas;
     2455  ImageLocomotive.Paint;
     2456  X := X - IconSize - SeparatorSize div 3;
     2457
    24522458  Text := IntToStr(Trains.GetUnusedCount);
    2453   Canvas.Draw(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist - 100,
    2454     CanvasSize.Y - LineColorsDist - ImageLocomotive.Bitmap.Height div 2, ImageLocomotive.Bitmap);
    24552459  Canvas.Brush.Style := bsClear;
    24562460  Canvas.Font.Size := 14;
    24572461  Canvas.Font.Color := Colors.Text;
    2458   Canvas.TextOut(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - Canvas.TextWidth(Text),
    2459     CanvasSize.Y - LineColorsDist - Canvas.TextHeight(Text) div 2, Text);
     2462  Canvas.TextOut(X - Canvas.TextWidth(Text),
     2463    Y - Canvas.TextHeight(Text) div 2, Text);
     2464  X := X - Canvas.TextWidth(Text) - SeparatorSize;
    24602465
    24612466  // Draw unused carriages
    24622467  Text := IntToStr(Carriages.GetUnusedCount);
    2463   Canvas.Draw(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist - 200,
    2464     CanvasSize.Y - LineColorsDist - ImageCarriage.Bitmap.Height div 2, ImageCarriage.Bitmap);
     2468  ImageCarriage.Bounds := Bounds(X - IconSize, Y - IconSize div 2,
     2469    IconSize, IconSize);
     2470  ImageCarriage.Canvas := Canvas;
     2471  ImageCarriage.Paint;
     2472  X := X - IconSize - SeparatorSize div 3;
     2473
    24652474  Canvas.Brush.Style := bsClear;
    24662475  Canvas.Font.Size := 14;
    24672476  Canvas.Font.Color := Colors.Text;
    2468   Canvas.TextOut(CanvasSize.X div 2 - Length(LineColors) div 2 * LineColorsDist - 150 - Canvas.TextWidth(Text),
    2469     CanvasSize.Y - LineColorsDist - Canvas.TextHeight(Text) div 2, Text);
    2470 
    2471   // Status interface
     2477  Canvas.TextOut(X - Canvas.TextWidth(Text),
     2478    Y - Canvas.TextHeight(Text) div 2, Text);
     2479
     2480  // Passenger count
     2481  X := CanvasSize.X - ScaleX(30, 96);
    24722482  Text := IntToStr(ServedPassengerCount);
    2473   Canvas.Draw(CanvasSize.X - 50, CanvasSize.Y - 60, ImagePassenger.Bitmap);
     2483  ImagePassenger.Bounds := Bounds(X - Canvas.TextWidth(Text), Y - IconSize div 2,
     2484    IconSize, IconSize);
     2485  ImagePassenger.Canvas := Canvas;
     2486  ImagePassenger.Paint;
     2487  X := X - Canvas.TextWidth(Text) - SeparatorSize div 3;
     2488
    24742489  Canvas.Brush.Style := bsClear;
    24752490  Canvas.Font.Size := 14;
    24762491  Canvas.Font.Color := Colors.Text;
    2477   Canvas.TextOut(CanvasSize.X - 70 - Canvas.TextWidth(Text),
    2478     CanvasSize.Y - 55, Text);
     2492  Canvas.TextOut(X - Canvas.TextWidth(Text),
     2493    Y - Canvas.TextHeight(Text) div 2, Text);
    24792494
    24802495  DrawClock(Canvas, CanvasSize);
     
    27832798
    27842799    // Select unused train
    2785     if (Distance(Position, Point(View.DestRect.Right div 2 - Length(LineColors) div 2 * LineColorsDist - 100,
    2786       View.DestRect.Bottom - LineColorsDist)) < 30) and
     2800    if (Distance(Position, ImageLocomotive.Bounds.CenterPoint) < 30) and
    27872801    (Trains.GetUnusedCount > 0) then begin
    27882802      SelectedTrain := Trains.GetUnused;
     
    27912805
    27922806    // Select unused carriage
    2793     if (Distance(Position, Point(View.DestRect.Right div 2 - Length(LineColors) div 2 * LineColorsDist - 200,
    2794       View.DestRect.Bottom - LineColorsDist)) < 30) and
     2807    if (Distance(Position, ImageCarriage.Bounds.CenterPoint) < 30) and
    27952808    (Carriages.GetUnusedCount > 0) then begin
    27962809      SelectedCarriage := Carriages.GetUnused;
     
    29742987constructor TEngine.Create;
    29752988begin
     2989  ImprovementImageSize := ScaleX(64, 96);
     2990  IconSize := ScaleX(32, 96);
    29762991  TimePerSecond := TimePerSecondNormal;
    29772992  ButtonBack := TImage.Create;
     
    30103025  ImageNewImprovement2 := TImage.Create;
    30113026  ImageNewImprovement2.OnClick := ButtonNewImprovement2;
    3012   //if FileExists(ImagePassengerName) then
    3013   //  ImagePassenger.Picture.LoadFromFile(ImagePassengerName);
    3014   //if FileExists(ImageLocomotiveName) then
    3015   //  ImageLocomotive.Picture.LoadFromFile(ImageLocomotiveName);
    30163027  MetaCanvas := TMetaCanvas.Create;
    30173028  Cities := TCities.Create;
Note: See TracChangeset for help on using the changeset viewer.