Changeset 31


Ignore:
Timestamp:
Jan 4, 2017, 11:49:56 PM (8 years ago)
Author:
chronos
Message:
  • Added: Pen tool to draw pixels by mouse with selected color.
  • Added: Mirror and Flip image operation.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r30 r31  
    55  Width = 920
    66  Caption = 'LibrePaint'
    7   ClientHeight = 615
     7  ClientHeight = 608
    88  ClientWidth = 920
    99  Menu = MainMenu1
     
    1313  OnDestroy = FormDestroy
    1414  OnShow = FormShow
    15   LCLVersion = '1.6.2.0'
     15  LCLVersion = '1.6.0.4'
    1616  object PaintBox1: TPaintBox
    1717    Left = 0
    18     Height = 561
     18    Height = 554
    1919    Top = 26
    2020    Width = 920
     
    3232    Left = 0
    3333    Height = 28
    34     Top = 587
     34    Top = 580
    3535    Width = 920
    3636    Panels = <   
     
    5151      Top = 2
    5252      Action = Core.AFileNew
     53    end
     54    object ColorButton1: TColorButton
     55      Left = 24
     56      Height = 22
     57      Top = 2
     58      Width = 43
     59      BorderWidth = 2
     60      ButtonColorSize = 16
     61      ButtonColor = clMaroon
     62    end
     63    object ToolButton2: TToolButton
     64      Left = 67
     65      Top = 2
     66      Action = Core.AToolMove
     67    end
     68    object ToolButton3: TToolButton
     69      Left = 90
     70      Top = 2
     71      Action = Core.AToolPen
    5372    end
    5473  end
     
    82101      object MenuItem2: TMenuItem
    83102        Action = Core.AExit
     103      end
     104    end
     105    object MenuItem21: TMenuItem
     106      Caption = 'Tool'
     107      object MenuItem23: TMenuItem
     108        Action = Core.AToolMove
     109      end
     110      object MenuItem22: TMenuItem
     111        Action = Core.AToolPen
    84112      end
    85113    end
  • trunk/Forms/UFormMain.pas

    r30 r31  
    1111type
    1212
     13  TImageTool = (itMoveView, itPen);
     14
    1315  { TFormMain }
    1416
    1517  TFormMain = class(TForm)
     18    ColorButton1: TColorButton;
    1619    LastOpenedList1: TLastOpenedList;
    1720    MainMenu1: TMainMenu;
     
    2629    MenuItem19: TMenuItem;
    2730    MenuItem20: TMenuItem;
     31    MenuItem21: TMenuItem;
     32    MenuItem22: TMenuItem;
     33    MenuItem23: TMenuItem;
    2834    MenuItemRecentFiles: TMenuItem;
    2935    MenuItem15: TMenuItem;
     
    4248    ToolBar1: TToolBar;
    4349    ToolButton1: TToolButton;
     50    ToolButton2: TToolButton;
     51    ToolButton3: TToolButton;
    4452    procedure FormActivate(Sender: TObject);
    4553    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     
    6674    StartMousePoint: TPoint;
    6775    StartViewPoint: TPoint;
    68     MoveActive: Boolean;
     76    MouseButtonDown: Boolean;
    6977    MousePos: TPoint;
    7078    Activated: Boolean;
    7179    procedure OpenRecentClick(Sender: TObject);
    7280  public
     81    ImageTool: TImageTool;
    7382    procedure EraseBackground(DC: HDC); override;
    7483    procedure UpdateStatusBar;
     
    8291
    8392uses
    84   UCore;
     93  UCore, UFGraphics;
    8594
    8695{$R *.lfm}
     
    184193procedure TFormMain.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    185194  Shift: TShiftState; X, Y: Integer);
     195var
     196  P: TPoint;
    186197begin
    187198  if Button = mbLeft then begin
    188     StartMousePoint := Point(X, Y);
    189     StartViewPoint := Core.Project.View.SrcRect.TopLeft;
    190     MoveActive := True;
     199    if ImageTool = itMoveView then begin
     200      StartMousePoint := Point(X, Y);
     201      StartViewPoint := Core.Project.View.SrcRect.TopLeft;
     202    end else
     203    if ImageTool = itPen then begin
     204      P := Core.Project.View.DestToSrcPos(Point(X, Y));
     205      if (P.X >= 0) and (P.X < Core.Project.Bitmap.Size.X) and (P.Y >= 0) and (P.Y < Core.Project.Bitmap.Size.Y) then
     206        Core.Project.Bitmap.Pixels[P.X, P.Y] := TFColor.Create(Core.Project.Bitmap.ColorFormat, ColorButton1.ButtonColor);
     207      Redraw;
     208    end;
     209    MouseButtonDown := True;
    191210  end;
    192211end;
     
    194213procedure TFormMain.PaintBox1MouseLeave(Sender: TObject);
    195214begin
    196   MoveActive := False;
     215  MouseButtonDown := False;
    197216end;
    198217
    199218procedure TFormMain.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
    200219  Y: Integer);
     220var
     221  P: TPoint;
    201222begin
    202223  MousePos := Point(X, Y);
    203   if Assigned(Core.Project) then begin
    204     if MoveActive then
    205     with Core.Project do begin
     224  if MouseButtonDown then
     225  if Assigned(Core.Project) then
     226  with Core.Project do begin
     227    if Imagetool = itMoveView then begin
    206228      View.SrcRect := Bounds(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom),
    207229        Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / View.Zoom),
     
    209231        View.SrcRect.Bottom - View.SrcRect.Top);
    210232      Redraw;
     233    end else
     234    if ImageTool = itPen then begin
     235      P := Core.Project.View.DestToSrcPos(Point(X, Y));
     236      if (P.X >= 0) and (P.X < Core.Project.Bitmap.Size.X) and (P.Y >= 0) and (P.Y < Core.Project.Bitmap.Size.Y) then
     237        Core.Project.Bitmap.Pixels[P.X, P.Y] := TFColor.Create(Core.Project.Bitmap.ColorFormat, ColorButton1.ButtonColor);
     238      Redraw;
    211239    end;
    212240  end;
     
    217245  Shift: TShiftState; X, Y: Integer);
    218246begin
    219   MoveActive := False;
     247  MouseButtonDown := False;
    220248end;
    221249
  • trunk/Packages/FastGraphics/ColorFormats/UColorRGB8.pas

    r29 r31  
    3737    constructor Create(Color: TColorRGB8);
    3838    procedure SetColorName(ColorName: TColorName); override;
     39    procedure SetColor(Color: TColor); override;
    3940    procedure SetRandom; override;
    4041  end;
     
    4748    function FillGetColor(Position: TPoint): TColorRGB8;
    4849  protected
     50    function GetPixel(X, Y: Integer): IBColor;  override;
     51    procedure SetPixel(X, Y: Integer; AValue: IBColor); override;
    4952    procedure SetSize(AValue: TPoint); override;
    5053  public
    5154    Pixmap: TPixmapRGB8;
     55    procedure Mirror; override;
     56    procedure Flip; override;
    5257    procedure Fill(Color: IBColor); override;
    5358    procedure Fill(Func: TGetColorPos); override;
     
    121126end;
    122127
     128procedure TBColorRGB8.SetColor(Color: TColor);
     129begin
     130  Value := TColorRGB8.Create((Color shr 0) and $ff, (Color shr 8) and $ff, (Color shr 16) and $ff);
     131end;
     132
    123133procedure TBColorRGB8.SetRandom;
    124134begin
     
    131141begin
    132142  Result := (FillCallBack(Position) as TBColorRGB8).Value;
     143end;
     144
     145function TBPixmapRGB8.GetPixel(X, Y: Integer): IBColor;
     146begin
     147  Result := TBColorRGB8.Create(Pixmap.Pixels[X, Y]);
     148end;
     149
     150procedure TBPixmapRGB8.SetPixel(X, Y: Integer; AValue: IBColor);
     151begin
     152  Pixmap.Pixels[X, Y] := (AValue as TBColorRGB8).Value;
    133153end;
    134154
     
    139159end;
    140160
     161procedure TBPixmapRGB8.Mirror;
     162begin
     163  Pixmap.Mirror;
     164end;
     165
     166procedure TBPixmapRGB8.Flip;
     167begin
     168  Pixmap.Flip;
     169end;
     170
    141171procedure TBPixmapRGB8.Fill(Color: IBColor);
    142172begin
  • trunk/Packages/FastGraphics/UFGraphics.pas

    r29 r31  
    1313  IBColor = interface
    1414    procedure SetColorName(ColorName: TColorName);
     15    procedure SetColor(Color: TColor);
    1516    procedure SetRandom;
    1617  end;
     
    2021  TBColor = class(TInterfacedObject, IBColor)
    2122    procedure SetColorName(ColorName: TColorName); virtual;
     23    procedure SetColor(Color: TColor); virtual;
    2224    procedure SetRandom; virtual;
    2325  end;
     
    3840    procedure SetSize(AValue: TPoint); virtual;
    3941  public
     42    procedure Mirror; virtual;
     43    procedure Flip; virtual;
    4044    procedure Fill(Color: IBColor); virtual; overload;
    4145    procedure Fill(Func: TGetColorPos); virtual; overload;
     
    110114    constructor Create; overload;
    111115    constructor Create(ColorFormat: TColorFormat; ColorName: TColorName); overload;
     116    constructor Create(ColorFormat: TColorFormat; Color: TColor); overload;
    112117    destructor Destroy; override;
    113118  end;
     
    239244end;
    240245
     246procedure TBColor.SetColor(Color: TColor);
     247begin
     248end;
     249
    241250procedure TBColor.SetRandom;
    242251begin
     
    334343end;
    335344
     345constructor TFColor.Create(ColorFormat: TColorFormat; Color: TColor);
     346begin
     347  Self.ColorFormat := ColorFormat;
     348  Backend.SetColor(Color);
     349end;
     350
    336351destructor TFColor.Destroy;
    337352begin
     
    355370  if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit;
    356371  FSize := AValue;
     372end;
     373
     374procedure TBImage.Mirror;
     375begin
     376
     377end;
     378
     379procedure TBImage.Flip;
     380begin
    357381end;
    358382
     
    449473procedure TFPixmap.Flip;
    450474begin
    451 
     475  FBackend.Flip;
    452476end;
    453477
    454478procedure TFPixmap.Mirror;
    455479begin
    456 
     480  FBackend.Mirror;
    457481end;
    458482
  • trunk/Packages/FastGraphics/UGGraphics.pas

    r30 r31  
    7171    procedure Fill(Color: TGColor); overload;
    7272    procedure Fill(Func: TGGetColor); overload;
     73    procedure Mirror;
     74    procedure Flip;
    7375    function GetDataSize: Int64; virtual;
    7476    property Canvas: TGCanvas<TGColor> read FCanvas;
     
    278280end;
    279281
     282procedure TGPixmap<TGColor>.Mirror;
     283var
     284  X, Y: Integer;
     285  Color: TGColor;
     286begin
     287  for Y := 0 to FSize.Y - 1 do
     288    for X := 0 to FSize.X div 2 - 1 do begin
     289      Color := Pixels[X, Y];
     290      Pixels[X, Y] := Pixels[Size.X - 1 - X, Y];
     291      Pixels[Size.X - 1 - X, Y] := Color;
     292    end;
     293end;
     294
     295procedure TGPixmap<TGColor>.Flip;
     296var
     297  X, Y: Integer;
     298  Color: TGColor;
     299begin
     300  for Y := 0 to FSize.Y div 2 - 1 do
     301    for X := 0 to FSize.X - 1 do begin
     302      Color := Pixels[X, Y];
     303      Pixels[X, Y] := Pixels[X, Size.Y - 1 - Y];
     304      Pixels[X, Size.Y - 1 - Y] := Color;
     305    end;
     306end;
     307
    280308{ TGPen }
    281309
  • trunk/UCore.lfm

    r30 r31  
    9595      OnExecute = AImageNegativeExecute
    9696    end
     97    object AToolPen: TAction
     98      Category = 'Tool'
     99      Caption = 'Pen'
     100      OnExecute = AToolPenExecute
     101    end
     102    object AToolMove: TAction
     103      Category = 'Tool'
     104      Caption = 'Move'
     105      OnExecute = AToolMoveExecute
     106    end
    97107  end
    98108  object ImageList1: TImageList
  • trunk/UCore.pas

    r30 r31  
    2020
    2121  TCore = class(TDataModule)
     22    AToolMove: TAction;
     23    AToolPen: TAction;
    2224    AImageNegative: TAction;
    2325    AImageGradient: TAction;
     
    5456    procedure AImageNegativeExecute(Sender: TObject);
    5557    procedure AImageRandomExecute(Sender: TObject);
     58    procedure AToolMoveExecute(Sender: TObject);
     59    procedure AToolPenExecute(Sender: TObject);
    5660    procedure AZoomAllExecute(Sender: TObject);
    5761    procedure AZoomInExecute(Sender: TObject);
     
    291295end;
    292296
     297procedure TCore.AToolMoveExecute(Sender: TObject);
     298begin
     299  FormMain.ImageTool := itMoveView;
     300end;
     301
     302procedure TCore.AToolPenExecute(Sender: TObject);
     303begin
     304  FormMain.ImageTool := itPen;
     305end;
     306
    293307end.
    294308
Note: See TracChangeset for help on using the changeset viewer.