Changeset 126 for trunk/UEngine.pas
- Timestamp:
- Apr 23, 2023, 10:35:50 PM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r125 r126 173 173 TMetroImprovementSet = set of TMetroImprovement; 174 174 TFullScrenChangeEvent = procedure (Sender: TObject; Active: Boolean) of object; 175 176 { TClock } 177 178 TClock = class(TControl) 179 Time: TDateTime; 180 TextColor: TColor; 181 BackgroundColor: TColor; 182 procedure Paint; override; 183 end; 175 184 176 185 { TEngine } … … 306 315 ImageNewImprovement1: TImage; 307 316 ImageNewImprovement2: TImage; 317 Clock: TClock; 308 318 AvailableImprovements: TMetroImprovementSet; 309 319 Improvement1: TMetroImprovement; … … 425 435 SSeoul = 'Seoul'; 426 436 SBeijing = 'Beijing'; 437 438 { TClock } 439 440 procedure TClock.Paint; 441 var 442 ClockCenter: TPoint; 443 Angle: Double; 444 I: Integer; 445 IsDay: Boolean; 446 begin 447 IsDay := (((Time / OneHour) mod 24) > 6) and (((Time / OneHour) mod 24) < 18); 448 if IsDay then begin 449 Canvas.Brush.Style := bsSolid; 450 Canvas.Brush.Color := BackgroundColor; 451 end else begin 452 Canvas.Brush.Style := bsSolid; 453 Canvas.Brush.Color := TextColor; 454 end; 455 Canvas.Pen.Style := psSolid; 456 Canvas.Pen.Color := TextColor; 457 Canvas.Pen.Width := 2; 458 ClockCenter := Point(Bounds.Left + Bounds.Width div 2, 459 Bounds.Top + Bounds.Height div 2); 460 Angle := Time / (12 * OneHour) * 2 * Pi - Pi / 2; 461 Canvas.EllipseC(ClockCenter.X, ClockCenter.Y, Bounds.Width div 2, Bounds.Height div 2); 462 Canvas.Brush.Style := bsClear; 463 464 if IsDay then begin 465 Canvas.Pen.Color := TextColor; 466 end else begin 467 Canvas.Pen.Color := BackgroundColor; 468 end; 469 Canvas.Line(ClockCenter, Point(ClockCenter.X + Round(Cos(Angle) * (Bounds.Width / 2) * 0.8), 470 ClockCenter.Y + Round(Sin(Angle) * (Bounds.Height / 2) * 0.8))); 471 for I := 0 to 12 do begin 472 Angle := I / 12 * 2 * Pi; 473 Canvas.Line(ClockCenter.X + Round(Cos(Angle) * (Bounds.Width / 2) * 0.7), 474 ClockCenter.Y + Round(Sin(Angle) * (Bounds.Height / 2) * 0.7), 475 ClockCenter.X + Round(Cos(Angle) * (Bounds.Width / 2) * 0.9), 476 ClockCenter.Y + Round(Sin(Angle) * (Bounds.Height / 2) * 0.9)); 477 end; 478 end; 427 479 428 480 { TMetroCarriage } … … 2240 2292 procedure TEngine.DrawClock(Canvas: TCanvas; CanvasSize: TPoint); 2241 2293 var 2242 ClockCenter: TPoint;2243 Angle: Double;2294 X: Integer; 2295 Y: Integer; 2244 2296 Text: string; 2245 I: Integer; 2246 Y: Integer; 2247 IsDay: Boolean; 2248 const 2249 ClockSize = 20; 2250 begin 2251 IsDay := (((Time / OneHour) mod 24) > 6) and (((Time / OneHour) mod 24) < 18); 2252 if IsDay then begin 2253 Canvas.Brush.Style := bsSolid; 2254 Canvas.Brush.Color := Colors.Background; 2255 end else begin 2256 Canvas.Brush.Style := bsSolid; 2257 Canvas.Brush.Color := Colors.Text; 2258 end; 2259 Canvas.Pen.Style := psSolid; 2260 Canvas.Pen.Color := Colors.Text; 2261 Canvas.Pen.Width := 2; 2262 ClockCenter := Point(CanvasSize.X - 30, 40); 2263 Angle := Time / (12 * OneHour) * 2 * Pi - Pi / 2; 2264 Canvas.EllipseC(ClockCenter.X, ClockCenter.Y, ClockSize, ClockSize); 2265 Canvas.Brush.Style := bsClear; 2266 2267 if IsDay then begin 2268 Canvas.Pen.Color := Colors.Text; 2269 end else begin 2270 Canvas.Pen.Color := Colors.Background; 2271 end; 2272 Canvas.Line(ClockCenter, Point(ClockCenter.X + Round(Cos(Angle) * ClockSize * 0.8), 2273 ClockCenter.Y + Round(Sin(Angle) * ClockSize * 0.8))); 2274 for I := 0 to 12 do begin 2275 Angle := I / 12 * 2 * Pi; 2276 Canvas.Line(ClockCenter.X + Round(Cos(Angle) * ClockSize * 0.7), 2277 ClockCenter.Y + Round(Sin(Angle) * ClockSize * 0.7), 2278 ClockCenter.X + Round(Cos(Angle) * ClockSize * 0.9), 2279 ClockCenter.Y + Round(Sin(Angle) * ClockSize * 0.9)); 2280 end; 2281 Y := ClockCenter.Y; 2297 begin 2298 Clock.Time := Time; 2299 Clock.Canvas := Canvas; 2300 Clock.TextColor := Colors.Text; 2301 Clock.BackgroundColor := Colors.Background; 2302 Clock.Bounds := Bounds(ScaleX(15, 96), ScaleY(15, 96), 2303 ScaleX(40, 96), ScaleY(40, 96)); 2304 Clock.Paint; 2305 2306 X := Clock.Bounds.Left + Clock.Bounds.Width + ScaleY(10, 96); 2307 Y := Clock.Bounds.Top; 2282 2308 2283 2309 Canvas.Pen.Color := Colors.Text; 2284 2310 Canvas.Font.Color := Colors.Text; 2311 Canvas.Brush.Style := bsClear; 2285 2312 Text := FormatDateTime('ddd', Time + 2); 2286 Canvas.TextOut(ClockCenter.X - ClockSize - Canvas.TextWidth(Text) - ScaleX(10, 96), 2287 Y - Canvas.TextHeight(Text) div 2, Text); 2313 Canvas.TextOut(X, Y + (Clock.Bounds.Height - Canvas.TextHeight(Text)) div 2, Text); 2314 X := X + ScaleX(40, 96) + ScaleY(5, 96); 2315 Y := Clock.Bounds.Top + (Clock.Bounds.Height - ImagePause.Bounds.Height) div 2; 2316 2317 ImagePause.Canvas := Canvas; 2318 ImagePause.Bounds := Bounds(X, Y, ScaleX(20, 96), ScaleY(20, 96)); 2319 ImagePause.Paint; 2320 X := X + ImagePause.Bounds.Width + ScaleX(5, 96); 2321 2322 ImagePlay.Canvas := Canvas; 2323 ImagePlay.Bounds := Bounds(X, Y, ScaleX(20, 96), ScaleY(20, 96)); 2324 ImagePlay.Paint; 2325 X := X + ImagePlay.Bounds.Width + ScaleX(5, 96); 2326 2327 ImageFastForward.Canvas := Canvas; 2328 ImageFastForward.Bounds := Bounds(X, Y, ScaleX(20, 96), ScaleY(20, 96)); 2329 ImageFastForward.Paint; 2330 2331 X := Clock.Bounds.Left; 2332 Y := Clock.Bounds.Top + Clock.Bounds.Height + ScaleY(5, 96); 2333 2334 Canvas.Pen.Color := Colors.Text; 2335 Canvas.Font.Color := Colors.Text; 2336 Canvas.Brush.Style := bsClear; 2337 Text := SDay + ' ' + IntToStr(Trunc(Time)); 2338 Canvas.TextOut(X, Y, Text); 2288 2339 Y := Y + Canvas.TextHeight(Text) + ScaleY(5, 96); 2289 2290 Text := SDay + ' ' + IntToStr(Trunc(Time));2291 Canvas.TextOut(ClockCenter.X - ClockSize - Canvas.TextWidth(Text) - ScaleX(10, 96),2292 Y - Canvas.TextHeight(Text) div 2, Text);2293 Y := Y + Canvas.TextHeight(Text) + ScaleY(5, 96);2294 2295 ImagePause.Canvas := Canvas;2296 ImagePause.Bounds := Bounds(CanvasSize.X - ScaleX(20 + 10, 96), Y,2297 ScaleX(20, 96), ScaleY(20, 96));2298 ImagePause.Paint;2299 Y := Y + ImagePause.Bounds.Height + ScaleY(5, 96);2300 2301 ImagePlay.Canvas := Canvas;2302 ImagePlay.Bounds := Bounds(CanvasSize.X - ScaleX(20 + 10, 96) , Y,2303 ScaleX(20, 96), ScaleY(20, 96));2304 ImagePlay.Paint;2305 Y := Y + ImagePlay.Bounds.Height + ScaleY(5, 96);2306 2307 ImageFastForward.Canvas := Canvas;2308 ImageFastForward.Bounds := Bounds(CanvasSize.X - ScaleX(20 + 10, 96) , Y,2309 ScaleX(20, 96), ScaleY(20, 96));2310 ImageFastForward.Paint;2311 Y := Y + ImageFastForward.Bounds.Height + ScaleY(5, 96);2312 2340 end; 2313 2341 … … 2778 2806 Text: string; 2779 2807 Radius: Integer; 2780 Angle: Real;2781 Pos: TPoint;2782 2808 X: Integer; 2783 2809 Y: Integer; … … 2881 2907 Canvas.Font.Color := Colors.Text; 2882 2908 ButtonBack.Canvas := Canvas; 2883 ButtonBack.Bounds .Left := 10;2884 ButtonBack.Bounds.Top := 10;2909 ButtonBack.Bounds := Bounds(CanvasSize.X - ButtonBack.Bounds.Width - 10, 10, 2910 ButtonBack.Bounds.Width, ButtonBack.Bounds.Height); 2885 2911 ButtonBack.Paint; 2886 2912 … … 3599 3625 begin 3600 3626 inherited; 3627 Colors := TColors.Create; 3628 Colors.Init(FDarkMode); 3601 3629 ImprovementImageSize := ScaleX(64, 96); 3602 3630 IconSize := ScaleX(32, 96); … … 3604 3632 ButtonBack := TImage.Create; 3605 3633 ButtonBack.OnClick := ButtonBackClick; 3606 ButtonBack.Bounds := Bounds(0, 0, ScaleX( 80, 96), ScaleY(80, 96));3634 ButtonBack.Bounds := Bounds(0, 0, ScaleX(50, 96), ScaleY(50, 96)); 3607 3635 Cities := TCities.Create; 3608 3636 InitCities; … … 3641 3669 ImageNewImprovement2 := TImage.Create; 3642 3670 ImageNewImprovement2.OnClick := ButtonNewImprovement2; 3671 Clock := TClock.Create; 3643 3672 MetaCanvas := TMetaCanvas.Create; 3644 Colors.Init(FDarkMode);3645 3673 end; 3646 3674 … … 3650 3678 FreeAndNil(Trains); 3651 3679 FreeAndNil(Carriages); 3680 FreeAndNil(Clock); 3652 3681 FreeAndNil(ImageTunnel); 3653 3682 FreeAndNil(ImageTerminal);
Note:
See TracChangeset
for help on using the changeset viewer.