Changeset 10 for trunk/Forms


Ignore:
Timestamp:
Sep 22, 2014, 3:07:02 AM (10 years ago)
Author:
chronos
Message:
  • Added: Zooming and moving image.
  • Added: Color format 4-bit gray.
  • Added: Image operation for generating test gradient image.
Location:
trunk/Forms
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r7 r10  
    22  Left = 664
    33  Height = 640
    4   Top = 443
     4  Top = 382
    55  Width = 920
    66  Caption = 'LibrePaint'
     
    88  ClientWidth = 920
    99  Menu = MainMenu1
     10  OnActivate = FormActivate
     11  OnCreate = FormCreate
     12  OnDestroy = FormDestroy
     13  OnShow = FormShow
    1014  LCLVersion = '1.3'
    1115  object PaintBox1: TPaintBox
     
    1519    Width = 920
    1620    Align = alClient
     21    OnMouseDown = PaintBox1MouseDown
     22    OnMouseMove = PaintBox1MouseMove
     23    OnMouseUp = PaintBox1MouseUp
     24    OnMouseLeave = PaintBox1MouseLeave
     25    OnMouseWheelDown = PaintBox1MouseWheelDown
     26    OnMouseWheelUp = PaintBox1MouseWheelUp
    1727    OnPaint = PaintBox1Paint
    1828    OnResize = PaintBox1Resize
     
    2333    Top = 588
    2434    Width = 920
    25     Panels = <>
     35    Panels = <   
     36      item
     37        Width = 50
     38      end>
     39    SimplePanel = False
    2640  end
    2741  object MainMenu1: TMainMenu
     
    8599        Action = Core.AImageFlip
    86100      end
     101      object MenuItem19: TMenuItem
     102        Action = Core.AImageGradient
     103      end
    87104    end
    88105  end
  • trunk/Forms/UFormMain.pas

    r7 r10  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
    9   ExtCtrls, ComCtrls;
     9  ExtCtrls, ComCtrls, types;
    1010
    1111type
     
    2323    MenuItem17: TMenuItem;
    2424    MenuItem18: TMenuItem;
     25    MenuItem19: TMenuItem;
    2526    MenuItemRecentFiles: TMenuItem;
    2627    MenuItem15: TMenuItem;
     
    3738    StatusBar1: TStatusBar;
    3839    Timer1: TTimer;
     40    procedure FormActivate(Sender: TObject);
     41    procedure FormCreate(Sender: TObject);
     42    procedure FormDestroy(Sender: TObject);
     43    procedure FormShow(Sender: TObject);
     44    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
     45      Shift: TShiftState; X, Y: Integer);
     46    procedure PaintBox1MouseLeave(Sender: TObject);
     47    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
     48      Y: Integer);
     49    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
     50      Shift: TShiftState; X, Y: Integer);
     51    procedure PaintBox1MouseWheelDown(Sender: TObject; Shift: TShiftState;
     52      MousePos: TPoint; var Handled: Boolean);
     53    procedure PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;
     54      MousePos: TPoint; var Handled: Boolean);
    3955    procedure PaintBox1Paint(Sender: TObject);
    4056    procedure PaintBox1Resize(Sender: TObject);
    4157    procedure Timer1Timer(Sender: TObject);
    4258  private
    43     { private declarations }
     59    TempBitmap: TBitmap;
     60    StartMousePoint: TPoint;
     61    StartViewPoint: TPoint;
     62    MoveActive: Boolean;
     63    MousePos: TPoint;
     64    Activated: Boolean;
    4465  public
     66    procedure UpdateStatusBar;
    4567    procedure Redraw;
    4668  end;
     
    6082procedure TFormMain.PaintBox1Resize(Sender: TObject);
    6183begin
    62 
     84  Redraw;
    6385end;
    6486
    6587procedure TFormMain.Timer1Timer(Sender: TObject);
    66 var
    67   Bitmap: TBitmap;
    6888begin
    6989  Timer1.Enabled := False;
    70   try
    71     Bitmap := TBitmap.Create;
    72     Bitmap.SetSize(Core.Project.Bitmap.Size.X, Core.Project.Bitmap.Size.Y);
    73     Bitmap.BeginUpdate(True);
    74     Core.Project.Bitmap.PaintToCanvas(Bitmap.Canvas);
    75     Bitmap.EndUpdate(False);
    76     PaintBox1.Canvas.Draw(0, 0, Bitmap);
    77   finally
    78     Bitmap.Free;
     90  PaintBox1.Repaint;
     91  UpdateStatusBar;
     92end;
     93
     94procedure TFormMain.UpdateStatusBar;
     95var
     96  Pos: TPoint;
     97begin
     98  with Core.Project do begin
     99    Pos := View.DestToSrcPos(MousePos);
     100    StatusBar1.Panels[0].Text := '[' + IntToStr(Pos.X) + ', ' + IntToStr(Pos.Y) + '] Zoom:' +
     101      FloatToStr(Core.Project.View.Zoom);
    79102  end;
    80103end;
     
    87110procedure TFormMain.PaintBox1Paint(Sender: TObject);
    88111begin
    89   Redraw;
     112  with Core.Project do begin
     113    TempBitmap.SetSize(View.SrcRect.Right - View.SrcRect.Left,
     114      View.SrcRect.Bottom - View.SrcRect.Top);
     115    TempBitmap.BeginUpdate(True);
     116    TempBitmap.Canvas.Brush.Color := clBlack;
     117    TempBitmap.Canvas.FillRect(0, 0, TempBitmap.Width, TempBitmap.Height);
     118    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
     119    Bitmap.PaintToCanvas(TempBitmap.Canvas, View.SrcRect);
     120    TempBitmap.EndUpdate(False);
     121    PaintBox1.Canvas.StretchDraw(View.DestRect, TempBitmap);
     122    //PaintBox1.Canvas.Draw(0, 0, TempBitmap);
     123  end;
     124end;
     125
     126procedure TFormMain.FormCreate(Sender: TObject);
     127begin
     128  TempBitmap := TBitmap.Create;
     129end;
     130
     131procedure TFormMain.FormActivate(Sender: TObject);
     132begin
     133  if not Activated then begin
     134    Activated := True;
     135    Core.Init;
     136  end;
     137end;
     138
     139procedure TFormMain.FormDestroy(Sender: TObject);
     140begin
     141  TempBitmap.Free;
     142end;
     143
     144procedure TFormMain.FormShow(Sender: TObject);
     145begin
     146end;
     147
     148procedure TFormMain.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
     149  Shift: TShiftState; X, Y: Integer);
     150begin
     151  if Button = mbLeft then begin
     152    StartMousePoint := Point(X, Y);
     153    StartViewPoint := Core.Project.View.SrcRect.TopLeft;
     154    MoveActive := True;
     155  end;
     156end;
     157
     158procedure TFormMain.PaintBox1MouseLeave(Sender: TObject);
     159begin
     160  MoveActive := False;
     161end;
     162
     163procedure TFormMain.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
     164  Y: Integer);
     165begin
     166  MousePos := Point(X, Y);
     167  if Assigned(Core.Project) then begin
     168    if MoveActive then
     169    with Core.Project do begin
     170      View.SrcRect := Bounds(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom),
     171        Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / View.Zoom),
     172        View.SrcRect.Right - View.SrcRect.Left,
     173        View.SrcRect.Bottom - View.SrcRect.Top);
     174      Redraw;
     175    end;
     176  end;
     177  UpdateStatusBar;
     178end;
     179
     180procedure TFormMain.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
     181  Shift: TShiftState; X, Y: Integer);
     182begin
     183  MoveActive := False;
     184end;
     185
     186procedure TFormMain.PaintBox1MouseWheelDown(Sender: TObject;
     187  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
     188begin
     189  Core.AZoomOut.Execute;
     190end;
     191
     192procedure TFormMain.PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;
     193  MousePos: TPoint; var Handled: Boolean);
     194begin
     195  Core.AZoomIn.Execute;
    90196end;
    91197
  • trunk/Forms/UFormNew.pas

    r8 r10  
    6666
    6767  // Default
    68   SpinEditWidth.Value := 800;
    69   SpinEditHeight.Value := 600;
     68  SpinEditWidth.Value := 200;
     69  SpinEditHeight.Value := 100;
    7070  SpinEditDPI.Value := 72;
    7171end;
Note: See TracChangeset for help on using the changeset viewer.