Changeset 3
- Timestamp:
- Sep 15, 2014, 11:13:21 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r2 r3 23 23 object MenuItem1: TMenuItem 24 24 Caption = 'Soubor' 25 object MenuItem3: TMenuItem 26 Action = Core.AProjectNew 27 end 25 28 object MenuItem2: TMenuItem 26 Action = Core.AProjectNew 29 Action = Core.AExit 30 end 31 end 32 object MenuItem4: TMenuItem 33 Caption = 'Image' 34 object MenuItem5: TMenuItem 35 Action = Core.AImageClear 27 36 end 28 37 end 29 38 end 39 object Timer1: TTimer 40 Enabled = False 41 Interval = 50 42 OnTimer = Timer1Timer 43 left = 195 44 top = 206 45 end 30 46 end -
trunk/Forms/UFormMain.pas
r2 r3 17 17 MenuItem1: TMenuItem; 18 18 MenuItem2: TMenuItem; 19 MenuItem3: TMenuItem; 20 MenuItem4: TMenuItem; 21 MenuItem5: TMenuItem; 19 22 PaintBox1: TPaintBox; 23 Timer1: TTimer; 20 24 procedure PaintBox1Paint(Sender: TObject); 21 25 procedure PaintBox1Resize(Sender: TObject); 26 procedure Timer1Timer(Sender: TObject); 22 27 private 23 28 { private declarations } 24 29 public 25 { public declarations }30 procedure Redraw; 26 31 end; 27 32 … … 43 48 end; 44 49 50 procedure TFormMain.Timer1Timer(Sender: TObject); 51 var 52 Bitmap: TBitmap; 53 begin 54 Timer1.Enabled := False; 55 try 56 Bitmap := TBitmap.Create; 57 Bitmap.SetSize(Core.Project.Bitmap.Size.X, Core.Project.Bitmap.Size.Y); 58 Bitmap.BeginUpdate(True); 59 Core.Project.Bitmap.PaintToCanvas(Bitmap.Canvas); 60 Bitmap.EndUpdate(False); 61 PaintBox1.Canvas.Draw(0, 0, Bitmap); 62 finally 63 Bitmap.Free; 64 end; 65 end; 66 67 procedure TFormMain.Redraw; 68 begin 69 Timer1.Enabled := True; 70 end; 71 45 72 procedure TFormMain.PaintBox1Paint(Sender: TObject); 46 73 begin 47 Core.Project.Bitmap.PaintToCanvas(PaintBox1.Canvas);74 Redraw; 48 75 end; 49 76 -
trunk/LibrePaint.lpi
r2 r3 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 6">35 <Units Count="7"> 36 36 <Unit0> 37 37 <Filename Value="LibrePaint.lpr"/> 38 38 <IsPartOfProject Value="True"/> 39 <UnitName Value="LibrePaint"/>40 39 </Unit0> 41 40 <Unit1> 42 <Filename Value="UFormMain.pas"/>43 <IsPartOfProject Value="True"/>44 <ComponentName Value="FormMain"/>45 <ResourceBaseClass Value="Form"/>46 <UnitName Value="UFormMain"/>47 </Unit1>48 <Unit2>49 41 <Filename Value="UCore.pas"/> 50 42 <IsPartOfProject Value="True"/> 51 43 <ComponentName Value="Core"/> 44 <HasResources Value="True"/> 52 45 <ResourceBaseClass Value="DataModule"/> 53 46 <UnitName Value="UCore"/> 54 </Unit 2>55 <Unit 3>47 </Unit1> 48 <Unit2> 56 49 <Filename Value="UGraphic.pas"/> 57 50 <IsPartOfProject Value="True"/> 58 51 <UnitName Value="UGraphic"/> 59 </Unit 3>60 <Unit 4>52 </Unit2> 53 <Unit3> 61 54 <Filename Value="UProject.pas"/> 62 55 <IsPartOfProject Value="True"/> 63 56 <UnitName Value="UProject"/> 64 </Unit 4>65 <Unit 5>57 </Unit3> 58 <Unit4> 66 59 <Filename Value="Forms/UFormNew.pas"/> 67 60 <IsPartOfProject Value="True"/> 68 61 <ComponentName Value="FormNew"/> 62 <HasResources Value="True"/> 69 63 <ResourceBaseClass Value="Form"/> 70 64 <UnitName Value="UFormNew"/> 65 </Unit4> 66 <Unit5> 67 <Filename Value="ColorFormats/UColorRGBA8.pas"/> 68 <IsPartOfProject Value="True"/> 69 <UnitName Value="UColorRGBA8"/> 71 70 </Unit5> 71 <Unit6> 72 <Filename Value="Forms/UFormMain.pas"/> 73 <IsPartOfProject Value="True"/> 74 <ComponentName Value="FormMain"/> 75 <HasResources Value="True"/> 76 <ResourceBaseClass Value="Form"/> 77 <UnitName Value="UFormMain"/> 78 </Unit6> 72 79 </Units> 73 80 </ProjectOptions> … … 79 86 <SearchPaths> 80 87 <IncludeFiles Value="$(ProjOutDir)"/> 81 <OtherUnitFiles Value="Forms "/>88 <OtherUnitFiles Value="Forms;ColorFormats"/> 82 89 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> 83 90 </SearchPaths> -
trunk/LibrePaint.lpr
r2 r3 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, U FormMain, UCore, UGraphic, UProject, UFormNew10 Forms, UCore, UGraphic, UProject, UFormNew, UFormMain, UColorRGBA8 11 11 { you can add units after this }; 12 12 -
trunk/UCore.lfm
r2 r3 13 13 OnExecute = AProjectNewExecute 14 14 end 15 object AExit: TAction 16 Caption = 'Exit' 17 OnExecute = AExitExecute 18 end 19 object AImageClear: TAction 20 Caption = 'Clear' 21 OnExecute = AImageClearExecute 22 end 15 23 end 16 24 end -
trunk/UCore.pas
r2 r3 13 13 14 14 TCore = class(TDataModule) 15 AImageClear: TAction; 16 AExit: TAction; 15 17 AProjectNew: TAction; 16 18 ActionList1: TActionList; 19 procedure AExitExecute(Sender: TObject); 20 procedure AImageClearExecute(Sender: TObject); 17 21 procedure AProjectNewExecute(Sender: TObject); 18 22 procedure DataModuleCreate(Sender: TObject); … … 31 35 32 36 uses 33 UFormNew, UFormMain ;37 UFormNew, UFormMain, UColorRGBA8, Forms; 34 38 35 39 { TCore } … … 56 60 Project.Bitmap.ColorFormat := ColorManager.Formats[FormNew.ComboBoxColorFormat.ItemIndex]; 57 61 Project.Bitmap.DPI := FormNew.SpinEditDPI.Value; 58 Project.Bitmap.PaintToCanvas(FormMain.PaintBox1.Canvas);62 FormMain.Redraw; 59 63 end; 64 end; 65 66 procedure TCore.AExitExecute(Sender: TObject); 67 begin 68 Application.Terminate; 69 end; 70 71 procedure TCore.AImageClearExecute(Sender: TObject); 72 begin 73 Project.Bitmap.Clear; 74 FormMain.Redraw; 60 75 end; 61 76 -
trunk/UGraphic.pas
r2 r3 30 30 TGColorFormatClass = class of TGColorFormat; 31 31 32 { TGColorFormatRGBA8 }33 34 TGColorFormatRGBA8 = class(TGColorFormat)35 function GetPixelSize: Integer; override;36 function GetBitDepth: Integer; override;37 function GetName: string; override;38 function GetChannelBytePos(Channel: TGColorChannel): Integer; override;39 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override;40 function ColorToTColor(Color: TGColor): TColor; override;41 function GetColorClass: TGColorClass; override;42 end;43 44 32 { TGColor } 45 33 46 34 TGColor = class 47 35 private 36 FColorFormat: TGColorFormatClass; 48 37 FData: PByte; 49 FColorFormat: TGColorFormatClass;50 38 function GetChannel(Channel: TGColorChannel): TGColor; 51 39 procedure SetColorFormat(AValue: TGColorFormatClass); … … 56 44 procedure Assign(Source: TGColor); virtual; 57 45 property Channels[Channel: TGColorChannel]: TGColor read GetChannel; 46 property Data: PByte read FData; 58 47 published 59 48 property Format: TGColorFormatClass read FColorFormat write SetColorFormat; … … 64 53 TGBitmap = class 65 54 private 55 FBackgroundColor: TGColor; 66 56 FColorFormat: TGColorFormatClass; 67 57 FDPI: Integer; … … 70 60 function GetPixel(X, Y: Integer): TGColor; 71 61 function GetSize: TPoint; 62 procedure SetBackgroundColor(AValue: TGColor); 72 63 procedure SetColorFormat(AValue: TGColorFormatClass); 73 64 procedure SetPixel(X, Y: Integer; AValue: TGColor); … … 77 68 function GetDataSize: Integer; 78 69 procedure PaintToCanvas(Canvas: TCanvas); 70 procedure Clear; 79 71 constructor Create; virtual; 80 72 destructor Destroy; override; 73 property BackgroundColor: TGColor read FBackgroundColor write SetBackgroundColor; 81 74 property DPI: Integer read FDPI write FDPI; 82 75 property ColorFormat: TGColorFormatClass read FColorFormat write SetColorFormat; … … 134 127 end; 135 128 136 { TGColorFormatRGBA8 }137 138 function TGColorFormatRGBA8.GetPixelSize: Integer;139 begin140 Result := 4;141 end;142 143 function TGColorFormatRGBA8.GetBitDepth: Integer;144 begin145 Result := 32;146 end;147 148 function TGColorFormatRGBA8.GetName: string;149 begin150 Result := 'RGBA8';151 end;152 153 function TGColorFormatRGBA8.GetChannelBytePos(Channel: TGColorChannel): Integer;154 begin155 case Channel of156 ccRed: Result := 0;157 ccGreen: Result := 1;158 ccBlue: Result := 2;159 ccOpacity: Result := 3;160 else raise Exception.Create('Unsupported color channel');161 end;162 end;163 164 function TGColorFormatRGBA8.GetChannelBitWidth(Channel: TGColorChannel165 ): Integer;166 begin167 if (Channel = ccBlue) or (Channel = ccRed) or (Channel = ccGreen) then168 Result := 8 else Result := 0;169 end;170 171 function TGColorFormatRGBA8.ColorToTColor(Color: TGColor): TColor;172 begin173 Result := PByte(Color.FData + GetChannelBytePos(ccRed))^ or174 (PByte(Color.FData + GetChannelBytePos(ccGreen))^ shl 8) or175 (PByte(Color.FData + GetChannelBytePos(ccBlue))^ shl 16);176 end;177 178 function TGColorFormatRGBA8.GetColorClass: TGColorClass;179 begin180 Result := TGColor;181 end;182 183 129 { TGColorFormat } 184 130 … … 286 232 end; 287 233 234 procedure TGBitmap.SetBackgroundColor(AValue: TGColor); 235 begin 236 if FBackgroundColor = AValue then Exit; 237 FBackgroundColor := AValue; 238 end; 239 288 240 procedure TGBitmap.SetColorFormat(AValue: TGColorFormatClass); 289 241 begin … … 291 243 FColorFormat := AValue; 292 244 ReAllocMem(FData, GetDataSize); 245 FBackgroundColor.Format := ColorFormat; 293 246 end; 294 247 … … 328 281 Pixel: TGColor; 329 282 begin 283 try 284 Canvas.Lock; 330 285 for Y := 0 to Size.Y - 1 do 331 286 for X := 0 to Size.X - 1 do begin … … 334 289 Pixel.Free; 335 290 end; 291 292 finally 293 Canvas.Unlock; 294 end; 295 end; 296 297 procedure TGBitmap.Clear; 298 var 299 X, Y: Integer; 300 begin 301 for Y := 0 to Size.Y - 1 do 302 for X := 0 to Size.X - 1 do begin 303 Pixels[X, Y] := BackgroundColor; 304 end; 336 305 end; 337 306 … … 339 308 begin 340 309 FData := GetMem(0); 341 ColorFormat := TGColorFormatRGBA8; 310 FBackgroundColor := TGColor.Create; 311 ColorFormat := TGColorFormat; 312 FBackgroundColor.Format := ColorFormat; 342 313 end; 343 314
Note:
See TracChangeset
for help on using the changeset viewer.