Ignore:
Timestamp:
Dec 22, 2016, 2:34:33 PM (7 years ago)
Author:
chronos
Message:
  • Fixed: Memory leaks introduced by TFColor. TFColor now use reference counting as descendant of IFColor.
  • Added: Line drawing for TFPixmap class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gbitmap/Packages/FastGraphics/UFGraphics.pas

    r24 r25  
    4040    procedure Fill(Color: IBColor); virtual; overload;
    4141    procedure Fill(Func: TGetColorPos); virtual; overload;
     42    procedure Line(P1, P2: TPoint; Color: IBColor); virtual;
    4243    procedure PaintToCanvas(Canvas: TCanvas); virtual;
    4344    function GetDataSize: Integer; virtual;
     
    8889  end;
    8990
     91  IFColor = interface
     92  end;
     93
    9094  { TFColor }
    9195
    92   TFColor = class
     96  TFColor = class(TInterfacedObject, IFColor)
    9397  private
    9498    FBackend: IBColor;
     
    105109  end;
    106110
     111  TFCanvas = class;
     112  TFPixmap = class;
     113
     114  { TFBrush }
     115
     116  TFBrush = class
     117    Color: IFColor;
     118    Canvas: TFCanvas;
     119  end;
     120
     121  { TFPen }
     122
     123  TFPen = class
     124    Position: TPoint;
     125    Color: IFColor;
     126    Canvas: TFCanvas;
     127    procedure MoveTo(Pos: TPoint);
     128    procedure LineTo(Pos: TPoint);
     129  end;
     130
     131  { TFCanvas }
     132
     133  TFCanvas = class
     134    Pixmap: TFPixmap;
     135    Pen: TFPen;
     136    Brush: TFBrush;
     137    constructor Create;
     138    destructor Destroy; override;
     139  end;
     140
     141
    107142  { TFPixmap }
    108143
     
    110145  public
    111146    type
    112       TGetColorPos = function (Position: TPoint; ColorFormat: TColorFormat): TFColor of object;
     147      TGetColorPos = function (Position: TPoint; ColorFormat: TColorFormat): IFColor of object;
    113148  private
    114149    FBackend: TBImage;
     150    FCanvas: TFCanvas;
    115151    FColorFormat: TColorFormat;
    116152    FSize: TPoint;
    117153    FillCallBack: TGetColorPos;
    118154    function FillGetColor(Position: TPoint): IBColor;
    119     function GetPixel(X, Y: Integer): TFColor;
     155    function GetPixel(X, Y: Integer): IFColor;
    120156    procedure SetColorFormat(AValue: TColorFormat);
    121     procedure SetPixel(X, Y: Integer; AValue: TFColor);
     157    procedure SetPixel(X, Y: Integer; AValue: IFColor);
    122158    procedure SetSize(AValue: TPoint);
    123159  public
    124     procedure Fill(Color: TFColor); overload;
     160    procedure Fill(Color: IFColor); overload;
    125161    procedure Fill(Func: TGetColorPos); overload;
    126162    procedure PaintToCanvas(Canvas: TCanvas);
     
    128164    constructor Create(AOwner: TComponent); override;
    129165    destructor Destroy; override;
     166    property Canvas: TFCanvas read FCanvas;
    130167    property Backend: TBImage read FBackend;
    131168    property ColorFormat: TColorFormat read FColorFormat write SetColorFormat;
    132169    property Size: TPoint read FSize write SetSize;
    133     property Pixels[X, Y: Integer]: TFColor read GetPixel write SetPixel;
     170    property Pixels[X, Y: Integer]: IFColor read GetPixel write SetPixel;
    134171  end;
    135172
     
    149186begin
    150187  RegisterComponents('FastGraphics', [TFPixmap]);
     188end;
     189
     190{ TFPen }
     191
     192procedure TFPen.MoveTo(Pos: TPoint);
     193begin
     194  Position := Pos;
     195end;
     196
     197procedure TFPen.LineTo(Pos: TPoint);
     198begin
     199  Canvas.Pixmap.Backend.Line(Position, Pos, (Color as TFColor).Backend);
     200  Position := Pos;
     201end;
     202
     203{ TFCanvas }
     204
     205constructor TFCanvas.Create;
     206begin
     207  Pen := TFPen.Create;
     208  Pen.Canvas := Self;
     209  Brush := TFBrush.Create;
     210  Brush.Canvas := Self;
     211end;
     212
     213destructor TFCanvas.Destroy;
     214begin
     215  FreeAndNil(Pen);
     216  FreeAndNil(Brush);
     217  inherited Destroy;
    151218end;
    152219
     
    254321destructor TFColor.Destroy;
    255322begin
     323  FColorFormat := nil;
    256324  inherited Destroy;
    257325end;
     
    279347
    280348procedure TBImage.Fill(Func: TGetColorPos);
     349begin
     350end;
     351
     352procedure TBImage.Line(P1, P2: TPoint; Color: IBColor);
    281353begin
    282354end;
     
    309381function TFPixmap.FillGetColor(Position: TPoint): IBColor;
    310382begin
    311   Result := FillCallBack(Position, ColorFormat).Backend;
    312 end;
    313 
    314 function TFPixmap.GetPixel(X, Y: Integer): TFColor;
     383  Result := (FillCallBack(Position, ColorFormat) as TFColor).Backend;
     384end;
     385
     386function TFPixmap.GetPixel(X, Y: Integer): IFColor;
    315387begin
    316388  Result := TFColor.Create;
    317   Result.ColorFormat := ColorFormat;
    318   Result.FBackend := FBackend.Pixels[X, Y];
    319 end;
    320 
    321 procedure TFPixmap.SetPixel(X, Y: Integer; AValue: TFColor);
    322 begin
    323   FBackend.Pixels[X, Y] := AValue.FBackend;
     389  (Result as TFColor).ColorFormat := ColorFormat;
     390  (Result as TFColor).FBackend := FBackend.Pixels[X, Y];
     391end;
     392
     393procedure TFPixmap.SetPixel(X, Y: Integer; AValue: IFColor);
     394begin
     395  FBackend.Pixels[X, Y] := (AValue as TFColor).FBackend;
    324396end;
    325397
     
    331403end;
    332404
    333 procedure TFPixmap.Fill(Color: TFColor);
    334 begin
    335   FBackend.Fill(Color.Backend);
     405procedure TFPixmap.Fill(Color: IFColor);
     406begin
     407  FBackend.Fill((Color as TFColor).Backend);
    336408end;
    337409
     
    349421function TFPixmap.GetDataSize: Integer;
    350422begin
    351   FBackend.GetDataSize;
    352 end;
    353 
    354 constructor TFPixmap.Create;
     423  Result := FBackend.GetDataSize;
     424end;
     425
     426constructor TFPixmap.Create(AOwner: TComponent);
    355427begin
    356428  inherited;
     429  FBackend := TBImage.Create;
     430  FCanvas := TFCanvas.Create;
     431  FCanvas.Pixmap := Self;
    357432  ColorFormat := ColorFormatManager.GetFormat(0);
    358   FBackend := TBImage.Create;
    359433end;
    360434
    361435destructor TFPixmap.Destroy;
    362436begin
     437  FreeAndNil(FCanvas);
    363438  FreeAndNil(FBackend);
    364439  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.