Changeset 5 for trunk


Ignore:
Timestamp:
Sep 16, 2014, 1:21:18 PM (10 years ago)
Author:
chronos
Message:
  • Added: 8-bit grayscale color format for testing.
  • Added: Canvas, Pen, Brush, line draw test code.
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r4 r5  
    11object FormMain: TFormMain
    2   Left = 594
     2  Left = 514
    33  Height = 640
    4   Top = 327
     4  Top = 299
    55  Width = 920
    66  Caption = 'LibrePaint'
  • trunk/LibrePaint.lpi

    r4 r5  
    3333      </Item1>
    3434    </RequiredPackages>
    35     <Units Count="7">
     35    <Units Count="8">
    3636      <Unit0>
    3737        <Filename Value="LibrePaint.lpr"/>
     
    7575        <UnitName Value="UFormMain"/>
    7676      </Unit6>
     77      <Unit7>
     78        <Filename Value="ColorFormats/UColorGray8.pas"/>
     79        <IsPartOfProject Value="True"/>
     80        <UnitName Value="UColorGray8"/>
     81      </Unit7>
    7782    </Units>
    7883  </ProjectOptions>
  • trunk/LibrePaint.lpr

    r3 r5  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UCore, UGraphic, UProject, UFormNew, UFormMain, UColorRGBA8
     10  Forms, UCore, UGraphic, UProject, UFormNew, UFormMain, UColorRGBA8,
     11UColorGray8
    1112  { you can add units after this };
    1213
  • trunk/UCore.pas

    r4 r5  
    3737
    3838uses
    39   UFormNew, UFormMain, UColorRGBA8, Forms;
     39  UFormNew, UFormMain, Forms, UColorRGBA8, UColorGray8;
    4040
    4141{ TCore }
     
    4646
    4747  ColorManager.RegisterFormat(TGColorFormatRGBA8);
     48  ColorManager.RegisterFormat(TGColorFormatGray8);
    4849
    4950  // Set default
     
    7475begin
    7576  Project.Bitmap.Clear;
     77  Project.Bitmap.Canvas.Pen.Color.Format := Project.Bitmap.ColorFormat;
     78  Project.Bitmap.Canvas.Pen.Color.FromTColor(clWhite);
     79  Project.Bitmap.Canvas.Pen.MoveTo(Point(100, 100));
     80  Project.Bitmap.Canvas.Pen.LineTo(Point(700, 500));
    7681  FormMain.Redraw;
    7782end;
  • trunk/UGraphic.pas

    r4 r5  
    1212
    1313  TGColor = class;
     14  TGCanvas = class;
    1415
    1516  TGColorClass = class of TGColor;
     
    4546    procedure FromTColor(Color: TColor);
    4647    procedure Assign(Source: TGColor); virtual;
     48    constructor Create;
    4749    property Channels[Channel: TGColorChannel]: TGColor read GetChannel;
    4850    property Data: PByte read FData;
     
    5658  private
    5759    FBackgroundColor: TGColor;
     60    FCanvas: TGCanvas;
    5861    FColorFormat: TGColorFormatClass;
    5962    FDPI: Integer;
     
    7982    property Size: TPoint read FSize write SetSize;
    8083    property Pixels[X, Y: Integer]: TGColor read GetPixel write SetPixel;
     84    property Canvas: TGCanvas read FCanvas write FCanvas;
    8185  published
    8286  end;
     
    96100  end;
    97101
     102  { TGPen }
     103
     104  TGPen = class
     105    Canvas: TGCanvas;
     106    Color: TGColor;
     107    Position: TPoint;
     108    procedure MoveTo(Pos: TPoint);
     109    procedure LineTo(Pos: TPoint);
     110    constructor Create; virtual;
     111    destructor Destroy; override;
     112  end;
     113
     114  { TGBrush }
     115
     116  TGBrush = class
     117    Canvas: TGCanvas;
     118    Color: TGColor;
     119    constructor Create; virtual;
     120    destructor Destroy; override;
     121  end;
     122
     123  { TGCanvas }
     124
     125  TGCanvas = class
     126    Brush: TGBrush;
     127    Pen: TGPen;
     128    Bitmap: TGBitmap;
     129    constructor Create; virtual;
     130    destructor Destroy; override;
     131  end;
     132
     133
    98134var
    99135  ColorManager: TGColorManager;
    100136
    101137implementation
     138
     139{ TGBrush }
     140
     141constructor TGBrush.Create;
     142begin
     143  Color := TGColor.Create;
     144end;
     145
     146destructor TGBrush.Destroy;
     147begin
     148  Color.Free;
     149  inherited Destroy;
     150end;
     151
     152{ TGPen }
     153
     154procedure TGPen.MoveTo(Pos: TPoint);
     155begin
     156  Position := Pos;
     157end;
     158
     159procedure TGPen.LineTo(Pos: TPoint);
     160var
     161  I: Integer;
     162  Len: Integer;
     163begin
     164  Len := Trunc(Sqrt(Sqr(Position.X - Pos.X) + Sqr(Position.Y - Pos.Y)));
     165  for I := 0 to Len - 1 do
     166    Canvas.Bitmap.Pixels[Trunc(Position.X + I * (Pos.X - Position.X) / Len),
     167      Trunc(Position.Y + I * (Pos.Y - Position.Y) / Len)] := Color;
     168end;
     169
     170constructor TGPen.Create;
     171begin
     172  Color := TGColor.Create;
     173end;
     174
     175destructor TGPen.Destroy;
     176begin
     177  Color.Free;
     178  inherited Destroy;
     179end;
     180
     181{ TGCanvas }
     182
     183constructor TGCanvas.Create;
     184begin
     185  Pen := TGPen.Create;
     186  Pen.Canvas := Self;
     187  Brush := TGBrush.Create;
     188  Brush.Canvas := Self;
     189end;
     190
     191destructor TGCanvas.Destroy;
     192begin
     193  Pen.Free;
     194  Brush.Free;
     195  inherited Destroy;
     196end;
    102197
    103198{ TGColorManager }
     
    233328procedure TGColor.Assign(Source: TGColor);
    234329begin
     330end;
     331
     332constructor TGColor.Create;
     333begin
     334  Format := TGColorFormat;
    235335end;
    236336
     
    343443  ColorFormat := TGColorFormat;
    344444  FBackgroundColor.Format := ColorFormat;
     445  FBackgroundColor.FromTColor(clBlack);
     446  Canvas := TGCanvas.Create;
     447  Canvas.Bitmap := Self;
    345448end;
    346449
Note: See TracChangeset for help on using the changeset viewer.