Changeset 33 for trunk/UCore.pas


Ignore:
Timestamp:
Jan 5, 2017, 11:48:36 PM (8 years ago)
Author:
chronos
Message:
  • Added: Remember last used image size and color format.
  • Added: Automatically create blank image.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r31 r33  
    1313
    1414type
    15   TFloatPoint = record
    16     X, Y: Double;
    17   end;
    18 
    1915  { TCore }
    2016
     
    6763  public
    6864    LastColorFormat: string;
     65    LastImageSize: TPoint;
    6966    Project: TProject;
    7067    RegistryContext: TRegistryContext;
    7168    procedure ProjectOpen(FileName: string);
     69    procedure ProjectNew;
    7270    procedure Init;
    7371    procedure LoadConfig;
     
    8583  UFormNew, UFormMain, Forms, UColorRGBA8, UColorGray8, UColorGray1, UColorGray4,
    8684  UColorRGB565;
    87 
    88 function FloatPoint(AX, AY: Double): TFloatPoint;
    89 begin
    90   Result.X := AX;
    91   Result.Y := AY;
    92 end;
    9385
    9486{ TCore }
     
    120112  //Image.Picture.Bitmap.EndUpdate;
    121113  Image.Free;
    122   AZoomAll.Execute;
     114  Project.View.ZoomAll(Project.Bitmap.Size);
    123115  FormMain.Redraw;
    124116  Project.FileName := FileName;
     117end;
     118
     119procedure TCore.ProjectNew;
     120var
     121  ColorFormatIndex: Integer;
     122begin
     123  // Set default
     124  ColorFormatIndex := ColorFormatManager.FindByName(LastColorFormat);
     125  if ColorFormatIndex < ColorFormatManager.Formats.Count then
     126    Project.Bitmap.ColorFormat := ColorFormatManager.Formats[ColorFormatIndex]
     127    else Project.Bitmap.ColorFormat := ColorFormatManager.Formats[0];
     128  Project.Bitmap.Size := LastImageSize;
     129
     130  Project.View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
     131  Project.View.ZoomAll(Project.Bitmap.Size);
    125132end;
    126133
     
    130137  LoadConfig;
    131138
    132   // Set default
    133   Project.Bitmap.ColorFormat := ColorFormatManager.Formats[0];
    134   Project.Bitmap.Size := Point(200, 100);
    135   Project.View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
    136   Core.AZoomAll.Execute;
     139  ProjectNew;
     140  FormMain.Redraw;
    137141end;
    138142
     
    145149
    146150    LastColorFormat := ReadStringWithDefault('LastColorFormat', '');
     151    LastImageSize.X := ReadIntegerWithDefault('LastImageSizeX', 600);
     152    LastImageSize.Y := ReadIntegerWithDefault('LastImageSizeY', 400);
    147153  finally
    148154    Free;
     
    158164
    159165    WriteString('LastColorFormat', LastColorFormat);
     166    WriteInteger('LastImageSizeX', LastImageSize.X);
     167    WriteInteger('LastImageSizeY', LastImageSize.Y);
    160168  finally
    161169    Free;
     
    165173procedure TCore.AFileNewExecute(Sender: TObject);
    166174begin
     175  FormNew.DefaultSize := LastImageSize;
    167176  if FormNew.ShowModal = mrOk then begin
    168177    Project.Bitmap.ColorFormat := TColorFormat.Create;
     
    173182//    Project.Bitmap.BackgroundColor.FromTColor(clBlack);
    174183//    Project.Bitmap.DPI := FormNew.SpinEditDPI.Value;
    175     AZoomAll.Execute;
     184    Project.View.ZoomAll(Project.Bitmap.Size);
     185    FormMain.Redraw;
     186    LastImageSize := Project.Bitmap.Size;
    176187  end;
    177188end;
    178189
    179190procedure TCore.AZoomAllExecute(Sender: TObject);
    180 var
    181   Factor: TFloatPoint;
    182 begin
    183   with Core.Project, View do begin
    184     Factor := FloatPoint((DestRect.Right - DestRect.Left) / Bitmap.Size.X,
    185       (DestRect.Bottom - DestRect.Top) / Bitmap.Size.Y);
    186     if Factor.X < Factor.Y then Zoom := Factor.X
    187       else Zoom := Factor.Y;
    188     Center(Rect(0, 0, Bitmap.Size.X, Bitmap.Size.Y));
    189   end;
     191begin
     192  with Core.Project do
     193    View.ZoomAll(Bitmap.Size);
    190194  FormMain.Redraw;
    191195end;
Note: See TracChangeset for help on using the changeset viewer.