Changeset 10 for trunk/UCore.pas


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r9 r10  
    88  Classes, SysUtils, FileUtil, ActnList, UProject, UGraphic, Controls, Graphics;
    99
     10const
     11  ZoomFactor = 1.5;
     12
    1013type
     14  TFloatPoint = record
     15    X, Y: Double;
     16  end;
    1117
    1218  { TCore }
    1319
    1420  TCore = class(TDataModule)
     21    AImageGradient: TAction;
    1522    AImageMirror: TAction;
    1623    AImageFlip: TAction;
     
    3239    procedure AImageClearExecute(Sender: TObject);
    3340    procedure AImageFlipExecute(Sender: TObject);
     41    procedure AImageGradientExecute(Sender: TObject);
    3442    procedure AImageMirrorExecute(Sender: TObject);
    3543    procedure AImageRandomExecute(Sender: TObject);
    3644    procedure AFileNewExecute(Sender: TObject);
     45    procedure AZoomAllExecute(Sender: TObject);
    3746    procedure AZoomInExecute(Sender: TObject);
    3847    procedure AZoomNormalExecute(Sender: TObject);
     
    4352  public
    4453    Project: TProject;
     54    procedure Init;
    4555  end;
    4656
     
    5363
    5464uses
    55   UFormNew, UFormMain, Forms, UColorRGBA8, UColorGray8, UColorGray1;
     65  UFormNew, UFormMain, Forms, UColorRGBA8, UColorGray8, UColorGray1, UColorGray4;
     66
     67function FloatPoint(AX, AY: Double): TFloatPoint;
     68begin
     69  Result.X := AX;
     70  Result.Y := AY;
     71end;
    5672
    5773{ TCore }
     
    6379  ColorManager.RegisterFormat(TGColorFormatRGBA8);
    6480  ColorManager.RegisterFormat(TGColorFormatGray8);
     81  ColorManager.RegisterFormat(TGColorFormatGray4);
    6582  ColorManager.RegisterFormat(TGColorFormatGray1);
     83end;
    6684
     85procedure TCore.Init;
     86begin
    6787  // Set default
    6888  Project.Bitmap.Size := Point(200, 100);
    6989  if ColorManager.FormatCount > 0 then
    7090    Project.Bitmap.ColorFormat := ColorManager.Formats[0];
     91  Project.View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
     92  Core.AZoomAll.Execute;
    7193end;
    7294
     
    81103    Project.Bitmap.BackgroundColor.FromTColor(clBlack);
    82104    Project.Bitmap.DPI := FormNew.SpinEditDPI.Value;
    83     FormMain.Redraw;
     105    AZoomAll.Execute;;
    84106  end;
     107end;
     108
     109procedure TCore.AZoomAllExecute(Sender: TObject);
     110var
     111  Factor: TFloatPoint;
     112begin
     113  with Core.Project, View do begin
     114    Factor := FloatPoint((DestRect.Right - DestRect.Left) / Bitmap.Size.X,
     115      (DestRect.Bottom - DestRect.Top) / Bitmap.Size.Y);
     116    if Factor.X < Factor.Y then Zoom := Factor.X
     117      else Zoom := Factor.Y;
     118    Center(Rect(0, 0, Bitmap.Size.X, Bitmap.Size.Y));
     119  end;
     120  FormMain.Redraw;
    85121end;
    86122
    87123procedure TCore.AZoomInExecute(Sender: TObject);
    88124begin
    89   Project.ViewPort.Zoom := Project.ViewPort.Zoom * 1.3;
     125  Project.View.Zoom := Project.View.Zoom * ZoomFactor;
    90126  FormMain.Redraw;
    91127end;
     
    93129procedure TCore.AZoomNormalExecute(Sender: TObject);
    94130begin
    95   Project.ViewPort.Zoom := 1;
     131  Project.View.Zoom := 1;
    96132  FormMain.Redraw;
    97133end;
     
    99135procedure TCore.AZoomOutExecute(Sender: TObject);
    100136begin
    101   Project.ViewPort.Zoom := Project.ViewPort.Zoom / 1.3;
     137  Project.View.Zoom := Project.View.Zoom / ZoomFactor;
    102138  FormMain.Redraw;
    103139end;
     
    124160end;
    125161
     162procedure TCore.AImageGradientExecute(Sender: TObject);
     163begin
     164  Core.Project.Bitmap.Gradient;
     165  FormMain.Redraw;
     166end;
     167
    126168procedure TCore.AImageMirrorExecute(Sender: TObject);
    127169begin
Note: See TracChangeset for help on using the changeset viewer.