| 1 | unit Xvcl.Graphics;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Xvcl.Classes;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 |
|
|---|
| 10 | TColor = (clNone, clBlack, clWhite, clGray, clSilver, clBlue, clGreen, clRed,
|
|---|
| 11 | clLightBlue, clLightRed, clLightGreen, clBrown, clYellow, clMagenta, clCyan);
|
|---|
| 12 |
|
|---|
| 13 | TPen = class
|
|---|
| 14 | Position: TPoint;
|
|---|
| 15 | Color: TColor;
|
|---|
| 16 | end;
|
|---|
| 17 |
|
|---|
| 18 | TBrush = class
|
|---|
| 19 | Color: TColor;
|
|---|
| 20 | end;
|
|---|
| 21 |
|
|---|
| 22 | TFont = class
|
|---|
| 23 |
|
|---|
| 24 | end;
|
|---|
| 25 |
|
|---|
| 26 | TVideoDevice = class
|
|---|
| 27 | Size: TPoint;
|
|---|
| 28 | procedure FillRect(Rect: TRectangle; Color: TColor); virtual;
|
|---|
| 29 | procedure Line(Pos1, Pos2: TPoint; Color: TColor); virtual;
|
|---|
| 30 | procedure SetPixel(Position: TPoint; Color: TColor); virtual;
|
|---|
| 31 | function GetPixel(Position: TPoint): TColor; virtual;
|
|---|
| 32 | procedure TextOut(Position: TPoint; Text: string); virtual;
|
|---|
| 33 | function GetTextSize(Text: string): TPoint; virtual;
|
|---|
| 34 | end;
|
|---|
| 35 |
|
|---|
| 36 | TCanvas = class
|
|---|
| 37 | private
|
|---|
| 38 | FPen: TPen;
|
|---|
| 39 | FBrush: TBrush;
|
|---|
| 40 | FFont: TFont;
|
|---|
| 41 | protected
|
|---|
| 42 | function GetVideoDevice: TVideoDevice; virtual;
|
|---|
| 43 | public
|
|---|
| 44 | Parent: TCanvas;
|
|---|
| 45 | function AdjustPos(Position: TPoint): TPoint; virtual;
|
|---|
| 46 | procedure TextOut(Position: TPoint; Text: string);
|
|---|
| 47 | function GetTextSize(Text: string): TPoint;
|
|---|
| 48 | procedure MoveTo(Position: TPoint);
|
|---|
| 49 | procedure LineTo(Position: TPoint);
|
|---|
| 50 | procedure Line(StartPos, EndPos: TPoint; Color: TColor);
|
|---|
| 51 | procedure SetPixel(Position: TPoint; Color: TColor);
|
|---|
| 52 | function GetPixel(Position: TPoint): TColor;
|
|---|
| 53 | procedure FillRect(Rect: TRectangle);
|
|---|
| 54 | constructor Create;
|
|---|
| 55 | destructor Destroy; override;
|
|---|
| 56 | property Pen: TPen read FPen;
|
|---|
| 57 | property Brush: TBrush read FBrush;
|
|---|
| 58 | property Font: TFont read FFont;
|
|---|
| 59 | property VideoDevice: TVideoDevice read GetVideoDevice;
|
|---|
| 60 | end;
|
|---|
| 61 |
|
|---|
| 62 | TBitmap = class
|
|---|
| 63 | private
|
|---|
| 64 | function GetPixel(X, Y: Integer): TColor;
|
|---|
| 65 | procedure SetPixel(X, Y: Integer; const Value: TColor);
|
|---|
| 66 | public
|
|---|
| 67 | property Pixels[X, Y: Integer]: TColor read GetPixel write SetPixel;
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | implementation
|
|---|
| 72 |
|
|---|
| 73 | { TPen }
|
|---|
| 74 |
|
|---|
| 75 | { TCanvas }
|
|---|
| 76 |
|
|---|
| 77 | function TCanvas.AdjustPos(Position: TPoint): TPoint;
|
|---|
| 78 | begin
|
|---|
| 79 | Result := Position;
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | constructor TCanvas.Create;
|
|---|
| 83 | begin
|
|---|
| 84 | FPen := TPen.Create;
|
|---|
| 85 | FBrush := TBrush.Create;
|
|---|
| 86 | FFont := TFont.Create;
|
|---|
| 87 | end;
|
|---|
| 88 |
|
|---|
| 89 | destructor TCanvas.Destroy;
|
|---|
| 90 | begin
|
|---|
| 91 | FFont.Destroy;
|
|---|
| 92 | FBrush.Destroy;
|
|---|
| 93 | FPen.Destroy;
|
|---|
| 94 | inherited;
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TCanvas.FillRect(Rect: TRectangle);
|
|---|
| 98 | begin
|
|---|
| 99 | Rect.TopLeft := AdjustPos(Rect.TopLeft);
|
|---|
| 100 | if Assigned(VideoDevice) then VideoDevice.FillRect(Rect, Brush.Color);
|
|---|
| 101 | end;
|
|---|
| 102 |
|
|---|
| 103 | function TCanvas.GetPixel(Position: TPoint): TColor;
|
|---|
| 104 | begin
|
|---|
| 105 | if Assigned(VideoDevice) then Result := VideoDevice.GetPixel(Position)
|
|---|
| 106 | else Result := clNone;
|
|---|
| 107 | end;
|
|---|
| 108 |
|
|---|
| 109 | function TCanvas.GetTextSize(Text: string): TPoint;
|
|---|
| 110 | begin
|
|---|
| 111 | if Assigned(VideoDevice) then
|
|---|
| 112 | Result := VideoDevice.GetTextSize(Text)
|
|---|
| 113 | else Result := TPoint.Create(0, 0);
|
|---|
| 114 | end;
|
|---|
| 115 |
|
|---|
| 116 | function TCanvas.GetVideoDevice: TVideoDevice;
|
|---|
| 117 | begin
|
|---|
| 118 | Result := nil;
|
|---|
| 119 | end;
|
|---|
| 120 |
|
|---|
| 121 | procedure TCanvas.Line(StartPos, EndPos: TPoint; Color: TColor);
|
|---|
| 122 | begin
|
|---|
| 123 | if Assigned(Parent) then Parent.Line(StartPos, EndPos, Color);
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | procedure TCanvas.LineTo(Position: TPoint);
|
|---|
| 127 | begin
|
|---|
| 128 | if Assigned(VideoDevice) then
|
|---|
| 129 | VideoDevice.Line(AdjustPos(Pen.Position), AdjustPos(Position), Pen.Color);
|
|---|
| 130 | MoveTo(Position);
|
|---|
| 131 | end;
|
|---|
| 132 |
|
|---|
| 133 | procedure TCanvas.MoveTo(Position: TPoint);
|
|---|
| 134 | begin
|
|---|
| 135 | Pen.Position := Position;
|
|---|
| 136 | end;
|
|---|
| 137 |
|
|---|
| 138 | procedure TCanvas.SetPixel(Position: TPoint; Color: TColor);
|
|---|
| 139 | begin
|
|---|
| 140 | if Assigned(VideoDevice) then VideoDevice.SetPixel(Position, Color);
|
|---|
| 141 | end;
|
|---|
| 142 |
|
|---|
| 143 | procedure TCanvas.TextOut(Position: TPoint; Text: string);
|
|---|
| 144 | begin
|
|---|
| 145 | if Assigned(VideoDevice) then VideoDevice.TextOut(AdjustPos(Position), Text);
|
|---|
| 146 | end;
|
|---|
| 147 |
|
|---|
| 148 | { TBitmap }
|
|---|
| 149 |
|
|---|
| 150 | function TBitmap.GetPixel(X, Y: Integer): TColor;
|
|---|
| 151 | begin
|
|---|
| 152 |
|
|---|
| 153 | end;
|
|---|
| 154 |
|
|---|
| 155 | procedure TBitmap.SetPixel(X, Y: Integer; const Value: TColor);
|
|---|
| 156 | begin
|
|---|
| 157 |
|
|---|
| 158 | end;
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | { TVideoDevice }
|
|---|
| 162 |
|
|---|
| 163 | procedure TVideoDevice.FillRect(Rect: TRectangle; Color: TColor);
|
|---|
| 164 | begin
|
|---|
| 165 |
|
|---|
| 166 | end;
|
|---|
| 167 |
|
|---|
| 168 | function TVideoDevice.GetPixel(Position: TPoint): TColor;
|
|---|
| 169 | begin
|
|---|
| 170 | Result := clNone;
|
|---|
| 171 | end;
|
|---|
| 172 |
|
|---|
| 173 | function TVideoDevice.GetTextSize(Text: string): TPoint;
|
|---|
| 174 | begin
|
|---|
| 175 | Result := TPoint.Create(0, 0);
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | procedure TVideoDevice.Line(Pos1, Pos2: TPoint; Color: TColor);
|
|---|
| 179 | begin
|
|---|
| 180 |
|
|---|
| 181 | end;
|
|---|
| 182 |
|
|---|
| 183 | procedure TVideoDevice.SetPixel(Position: TPoint; Color: TColor);
|
|---|
| 184 | begin
|
|---|
| 185 |
|
|---|
| 186 | end;
|
|---|
| 187 |
|
|---|
| 188 | procedure TVideoDevice.TextOut(Position: TPoint; Text: string);
|
|---|
| 189 | begin
|
|---|
| 190 | end;
|
|---|
| 191 |
|
|---|
| 192 | end.
|
|---|