| 1 | unit Driver.VideoVCL;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Vcl.Forms, Vcl.Graphics, System.Types, UFormMain, Xvcl.Classes, Xvcl.Kernel,
|
|---|
| 7 | Xvcl.Graphics, Generics.Collections;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 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 |
|
|---|
| 25 | implementation
|
|---|
| 26 |
|
|---|
| 27 | { TDriveVideoVCL }
|
|---|
| 28 |
|
|---|
| 29 | procedure TDriverVideoVCL.Finalize;
|
|---|
| 30 | begin
|
|---|
| 31 | Form.Destroy;
|
|---|
| 32 | inherited;
|
|---|
| 33 | end;
|
|---|
| 34 |
|
|---|
| 35 | procedure TDriverVideoVCL.Initialize;
|
|---|
| 36 | var
|
|---|
| 37 | VideoDeviceVCL: TVideoDeviceVCL;
|
|---|
| 38 | begin
|
|---|
| 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;
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | { TVideoDeviceVCL }
|
|---|
| 54 |
|
|---|
| 55 | function TVideoDeviceVCL.ColorToVCL(Color: TColor): Vcl.Graphics.TColor;
|
|---|
| 56 | begin
|
|---|
| 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;
|
|---|
| 74 | end;
|
|---|
| 75 |
|
|---|
| 76 | procedure TVideoDeviceVCL.FillRect(Rect: TRectangle; Color: TColor);
|
|---|
| 77 | begin
|
|---|
| 78 | inherited;
|
|---|
| 79 | CanvasVCL.Brush.Color := ColorToVCL(Color);
|
|---|
| 80 | CanvasVCL.FillRect(System.Types.Rect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom));
|
|---|
| 81 | end;
|
|---|
| 82 |
|
|---|
| 83 | function TVideoDeviceVCL.GetTextSize(Text: string): TPoint;
|
|---|
| 84 | begin
|
|---|
| 85 | Result := TPoint.Create(CanvasVCL.TextWidth(Text), CanvasVCL.TextHeight(Text));
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | procedure TVideoDeviceVCL.Line(Pos1, Pos2: TPoint; Color: TColor);
|
|---|
| 89 | begin
|
|---|
| 90 | CanvasVCL.Pen.Color := ColorToVCL(Color);
|
|---|
| 91 | CanvasVCL.MoveTo(Pos1.X, Pos1.Y);
|
|---|
| 92 | CanvasVCL.LineTo(Pos2.X, Pos2.Y);
|
|---|
| 93 | end;
|
|---|
| 94 |
|
|---|
| 95 | procedure TVideoDeviceVCL.TextOut(Position: TPoint; Text: string);
|
|---|
| 96 | begin
|
|---|
| 97 | CanvasVCL.Brush.Style := bsClear;
|
|---|
| 98 | CanvasVCL.TextOut(Position.X, Position.Y, Text);
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 | end.
|
|---|