source: branches/Xvcl/Drivers/Driver.VideoVCL.pas

Last change on this file was 24, checked in by chronos, 12 years ago
  • Fixed: Make only one form focused at once.
  • Modified: Enhanced TList generic class to support more methods.
File size: 2.8 KB
Line 
1unit Driver.VideoVCL;
2
3interface
4
5uses
6 Vcl.Forms, Vcl.Graphics, System.Types, UFormMain, Xvcl.Classes, Xvcl.Kernel,
7 Xvcl.Graphics, Generics.Collections;
8
9type
10 TDriverVideoVCL = class(TDriver)
11 Form: Vcl.Forms.TForm;
12 procedure Initialize; override;
13 procedure Finalize; override;
14 end;
15
16 TVideoDeviceVCL = class(TVideoDevice)
17 CanvasVCL: Vcl.Graphics.TCanvas;
18 function ColorToVCL(Color: TColor): Vcl.Graphics.TColor;
19 procedure FillRect(Rect: TRectangle; Color: TColor); override;
20 procedure Line(Pos1, Pos2: TPoint; Color: TColor); override;
21 procedure TextOut(Position: TPoint; Text: string); override;
22 function GetTextSize(Text: string): TPoint; override;
23 end;
24
25implementation
26
27{ TDriveVideoVCL }
28
29procedure TDriverVideoVCL.Finalize;
30begin
31 Form.Destroy;
32 inherited;
33end;
34
35procedure TDriverVideoVCL.Initialize;
36var
37 VideoDeviceVCL: TVideoDeviceVCL;
38begin
39 inherited;
40 Application.CreateForm(TForm1, Form1);
41 Form := Application.MainForm;
42 VideoDeviceVCL := TVideoDeviceVCL.Create;
43 VideoDeviceVCL.CanvasVCL := TForm1(Form).Image1.Canvas;
44 VideoDeviceVCL.Size := TPoint.Create(Form.Width, Form.Height);
45 Kernel.Screen.Size := TPoint.Create(Form.Width, Form.Height);
46 if Assigned(Kernel.Screen.VideoDevice) then
47 Kernel.Screen.VideoDevice.Destroy;
48 Kernel.Screen.VideoDevice := VideoDeviceVCL;
49
50 Application.MainForm.Show;
51end;
52
53{ TVideoDeviceVCL }
54
55function TVideoDeviceVCL.ColorToVCL(Color: TColor): Vcl.Graphics.TColor;
56begin
57 case Color of
58 clBlack: Result := $000000;
59 clWhite: Result := $ffffff;
60 clBlue: Result := $ff0000;
61 clGreen: Result := $00ff00;
62 clRed: Result := $0000ff;
63 clSilver: Result := $c0c0c0;
64 clGray: Result := $808080;
65 clLightBlue: Result := $ffb0b0;
66 clLightRed: Result := $b0ffb0;
67 clLightGreen: Result := $b0b0ff;
68 clBrown: Result := $a52a2a;
69 clMagenta: Result := $ff00ff;
70 clCyan: Result := $00ffff;
71 clYellow: Result := $ffff00;
72 else Result := $000000;
73 end;
74end;
75
76procedure TVideoDeviceVCL.FillRect(Rect: TRectangle; Color: TColor);
77begin
78 inherited;
79 CanvasVCL.Brush.Color := ColorToVCL(Color);
80 CanvasVCL.FillRect(System.Types.Rect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom));
81end;
82
83function TVideoDeviceVCL.GetTextSize(Text: string): TPoint;
84begin
85 Result := TPoint.Create(CanvasVCL.TextWidth(Text), CanvasVCL.TextHeight(Text));
86end;
87
88procedure TVideoDeviceVCL.Line(Pos1, Pos2: TPoint; Color: TColor);
89begin
90 CanvasVCL.Pen.Color := ColorToVCL(Color);
91 CanvasVCL.MoveTo(Pos1.X, Pos1.Y);
92 CanvasVCL.LineTo(Pos2.X, Pos2.Y);
93end;
94
95procedure TVideoDeviceVCL.TextOut(Position: TPoint; Text: string);
96begin
97 CanvasVCL.Brush.Style := bsClear;
98 CanvasVCL.TextOut(Position.X, Position.Y, Text);
99end;
100
101end.
Note: See TracBrowser for help on using the repository browser.