1
0
mirror of synced 2024-11-22 01:53:50 +00:00

Export/Import GraphicList

This commit is contained in:
Mark van Renswoude 2013-12-08 09:27:27 +00:00
parent 9ffd13c06e
commit d3ca72b5ff
4 changed files with 255 additions and 231 deletions

View File

@ -1,10 +1,10 @@
object GraphicsEditorForm: TGraphicsEditorForm object GraphicsEditorForm: TGraphicsEditorForm
Left = 325 Left = 325
Top = 363 Top = 363
Width = 534
Height = 451
BorderIcons = [biSystemMenu] BorderIcons = [biSystemMenu]
Caption = '<runtime>' Caption = '<runtime>'
ClientHeight = 413
ClientWidth = 518
Color = clBtnFace Color = clBtnFace
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText Font.Color = clWindowText
@ -12,7 +12,6 @@ object GraphicsEditorForm: TGraphicsEditorForm
Font.Name = 'MS Sans Serif' Font.Name = 'MS Sans Serif'
Font.Style = [] Font.Style = []
OldCreateOrder = False OldCreateOrder = False
Position = poDefaultPosOnly
OnClose = FormClose OnClose = FormClose
PixelsPerInch = 96 PixelsPerInch = 96
TextHeight = 13 TextHeight = 13
@ -20,24 +19,25 @@ object GraphicsEditorForm: TGraphicsEditorForm
Left = 189 Left = 189
Top = 0 Top = 0
Width = 4 Width = 4
Height = 424 Height = 413
ExplicitHeight = 424
end end
object pnlImage: TPanel object pnlImage: TPanel
Left = 193 Left = 193
Top = 0 Top = 0
Width = 333 Width = 325
Height = 424 Height = 413
Align = alClient Align = alClient
BevelOuter = bvNone BevelOuter = bvNone
TabOrder = 1 TabOrder = 1
object tbImage: TToolBar object tbImage: TToolBar
Left = 0 Left = 0
Top = 0 Top = 0
Width = 333 Width = 325
Height = 26 Height = 26
AutoSize = True AutoSize = True
DrawingStyle = dsGradient
EdgeBorders = [ebTop, ebBottom] EdgeBorders = [ebTop, ebBottom]
Flat = True
Images = ilsIcons Images = ilsIcons
TabOrder = 0 TabOrder = 0
object tbOpen: TToolButton object tbOpen: TToolButton
@ -59,8 +59,8 @@ object GraphicsEditorForm: TGraphicsEditorForm
object sbImage: TScrollBox object sbImage: TScrollBox
Left = 0 Left = 0
Top = 26 Top = 26
Width = 333 Width = 325
Height = 370 Height = 334
Align = alClient Align = alClient
BevelInner = bvNone BevelInner = bvNone
BevelKind = bkTile BevelKind = bkTile
@ -78,27 +78,40 @@ object GraphicsEditorForm: TGraphicsEditorForm
end end
object pnlProperties: TPanel object pnlProperties: TPanel
Left = 0 Left = 0
Top = 396 Top = 360
Width = 333 Width = 325
Height = 28 Height = 53
Align = alBottom Align = alBottom
BevelOuter = bvNone BevelOuter = bvNone
Caption = 'pnlProperties'
TabOrder = 2 TabOrder = 2
DesignSize = ( DesignSize = (
333 325
28) 53)
object lblName: TLabel object lblName: TLabel
Left = 8 Left = 8
Top = 8 Top = 32
Width = 31 Width = 31
Height = 13 Height = 13
Caption = 'Name:' Caption = 'Name:'
end end
object lblClassType: TLabel
Left = 8
Top = 6
Width = 309
Height = 13
Anchors = [akLeft, akTop, akRight]
AutoSize = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clGrayText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object txtName: TEdit object txtName: TEdit
Left = 52 Left = 52
Top = 4 Top = 28
Width = 277 Width = 269
Height = 21 Height = 21
Anchors = [akLeft, akTop, akRight] Anchors = [akLeft, akTop, akRight]
TabOrder = 0 TabOrder = 0
@ -110,7 +123,7 @@ object GraphicsEditorForm: TGraphicsEditorForm
Left = 0 Left = 0
Top = 0 Top = 0
Width = 189 Width = 189
Height = 424 Height = 413
Align = alLeft Align = alLeft
BevelOuter = bvNone BevelOuter = bvNone
TabOrder = 0 TabOrder = 0
@ -118,7 +131,7 @@ object GraphicsEditorForm: TGraphicsEditorForm
Left = 0 Left = 0
Top = 26 Top = 26
Width = 189 Width = 189
Height = 398 Height = 387
Style = lbVirtual Style = lbVirtual
Align = alClient Align = alClient
ItemHeight = 13 ItemHeight = 13
@ -134,8 +147,8 @@ object GraphicsEditorForm: TGraphicsEditorForm
Width = 189 Width = 189
Height = 26 Height = 26
AutoSize = True AutoSize = True
DrawingStyle = dsGradient
EdgeBorders = [ebTop, ebBottom] EdgeBorders = [ebTop, ebBottom]
Flat = True
Images = ilsIcons Images = ilsIcons
TabOrder = 0 TabOrder = 0
object tbNew: TToolButton object tbNew: TToolButton
@ -165,6 +178,23 @@ object GraphicsEditorForm: TGraphicsEditorForm
Top = 0 Top = 0
Action = actDown Action = actDown
end end
object tbSep2: TToolButton
Left = 100
Top = 0
Width = 8
ImageIndex = 9
Style = tbsSeparator
end
object tbExport: TToolButton
Left = 108
Top = 0
Action = actExport
end
object tbImport: TToolButton
Left = 131
Top = 0
Action = actImport
end
end end
end end
object ilsIcons: TImageList object ilsIcons: TImageList
@ -172,135 +202,7 @@ object GraphicsEditorForm: TGraphicsEditorForm
Top = 360 Top = 360
Bitmap = { Bitmap = {
494C010107000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 494C010107000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000003000000001002000000000000030 0000000000003600000028000000400000002000000001002000000000000020
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
@ -558,12 +460,8 @@ object GraphicsEditorForm: TGraphicsEditorForm
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000424D3E000000000000003E000000 000000000000000000000000000000000000424D3E000000000000003E000000
2800000040000000300000000100010000000000800100000000000000000000 2800000040000000200000000100010000000000000100000000000000000000
000000000000000000000000FFFFFF0000000000000000000000000000000000 000000000000000000000000FFFFFF00FFFFFFFFFFFF0000EFFDFFFFFFFF0000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000FFFFFFFFFFFF0000EFFDFFFFFFFF0000
C7FFFFFFFFFF0000C3FBF83FFEFF0000E3F7F83FFC7F0000F1E7F83FF83F0000 C7FFFFFFFFFF0000C3FBF83FFEFF0000E3F7F83FFC7F0000F1E7F83FF83F0000
F8CFF83FF01F0000FC1FC007E00F0000FE3FE00FC0070000FC1FF01FF83F0000 F8CFF83FF01F0000FC1FC007E00F0000FE3FE00FC0070000FC1FF01FF83F0000
F8CFF83FF83F0000E1E7FC7FF83F0000C3F3FEFFF83F0000C7FDFFFFFFFF0000 F8CFF83FF83F0000E1E7FC7FF83F0000C3F3FEFFF83F0000C7FDFFFFFFFF0000
@ -627,6 +525,18 @@ object GraphicsEditorForm: TGraphicsEditorForm
ShortCut = 16424 ShortCut = 16424
OnExecute = actDownExecute OnExecute = actDownExecute
end end
object actExport: TAction
Caption = '&Export'
Hint = 'Export all graphics'
ImageIndex = 3
OnExecute = actExportExecute
end
object actImport: TAction
Caption = '&Import'
Hint = 'Import all graphics'
ImageIndex = 2
OnExecute = actImportExecute
end
end end
object dlgOpen: TOpenPictureDialog object dlgOpen: TOpenPictureDialog
Left = 20 Left = 20
@ -636,4 +546,14 @@ object GraphicsEditorForm: TGraphicsEditorForm
Left = 104 Left = 104
Top = 304 Top = 304
end end
object dlgExport: TSaveDialog
Filter = 'GraphicList Export (*.gle)|*.gle'
Left = 104
Top = 256
end
object dlgImport: TOpenDialog
Filter = 'GraphicList Export (*.gle)|*.gle'
Left = 24
Top = 256
end
end end

View File

@ -26,64 +26,72 @@ uses
type type
TGraphicsEditorForm = class(TForm) TGraphicsEditorForm = class(TForm)
actAdd: TAction; actAdd: TAction;
actClear: TAction; actClear: TAction;
actDelete: TAction; actDelete: TAction;
actDown: TAction; actDown: TAction;
actOpen: TAction; actOpen: TAction;
actSave: TAction; actSave: TAction;
actUp: TAction; actUp: TAction;
alGraphics: TActionList; alGraphics: TActionList;
dlgOpen: TOpenPictureDialog; dlgOpen: TOpenPictureDialog;
dlgSave: TSavePictureDialog; dlgSave: TSavePictureDialog;
ilsIcons: TImageList; ilsIcons: TImageList;
imgPreview: TImage; imgPreview: TImage;
lblName: TLabel; lblName: TLabel;
lstGraphics: TListBox; lstGraphics: TListBox;
pnlGraphics: TPanel; pnlGraphics: TPanel;
pnlImage: TPanel; pnlImage: TPanel;
pnlProperties: TPanel; pnlProperties: TPanel;
sbImage: TScrollBox; sbImage: TScrollBox;
spltGraphics: TSplitter; spltGraphics: TSplitter;
tbClear: TToolButton; tbClear: TToolButton;
tbDelete: TToolButton; tbDelete: TToolButton;
tbDown: TToolButton; tbDown: TToolButton;
tbGraphics: TToolBar; tbGraphics: TToolBar;
tbImage: TToolBar; tbImage: TToolBar;
tbNew: TToolButton; tbNew: TToolButton;
tbOpen: TToolButton; tbOpen: TToolButton;
tbSave: TToolButton; tbSave: TToolButton;
tbSep1: TToolButton; tbSep1: TToolButton;
tbUp: TToolButton; tbUp: TToolButton;
txtName: TEdit; txtName: TEdit;
lblClassType: TLabel;
tbExport: TToolButton;
tbImport: TToolButton;
actExport: TAction;
actImport: TAction;
tbSep2: TToolButton;
dlgExport: TSaveDialog;
dlgImport: TOpenDialog;
procedure FormClose(Sender: TObject; var Action: TCloseAction); function lstGraphicsDataFind(Control: TWinControl; FindString: String): Integer;
procedure lstGraphicsClick(Sender: TObject);
procedure txtNameChange(Sender: TObject);
procedure actAddExecute(Sender: TObject); procedure actAddExecute(Sender: TObject);
procedure actClearExecute(Sender: TObject);
procedure actDeleteExecute(Sender: TObject); procedure actDeleteExecute(Sender: TObject);
procedure actUpExecute(Sender: TObject);
procedure actDownExecute(Sender: TObject); procedure actDownExecute(Sender: TObject);
procedure actExportExecute(Sender: TObject);
procedure actImportExecute(Sender: TObject);
procedure actOpenExecute(Sender: TObject); procedure actOpenExecute(Sender: TObject);
procedure actSaveExecute(Sender: TObject); procedure actSaveExecute(Sender: TObject);
procedure actClearExecute(Sender: TObject); procedure actUpExecute(Sender: TObject);
procedure lstGraphicsData(Control: TWinControl; Index: Integer; procedure FormClose(Sender: TObject; var Action: TCloseAction);
var Data: String); procedure lstGraphicsClick(Sender: TObject);
function lstGraphicsDataFind(Control: TWinControl; procedure lstGraphicsData(Control: TWinControl; Index: Integer; var Data: String);
FindString: String): Integer;
procedure lstGraphicsKeyPress(Sender: TObject; var Key: Char); procedure lstGraphicsKeyPress(Sender: TObject; var Key: Char);
procedure txtNameChange(Sender: TObject);
private private
FComponent: TX2GraphicContainer; FComponent: TX2GraphicContainer;
FComponentDesigner: IDesigner; FComponentDesigner: IDesigner;
FUpdating: Boolean; FUpdating: Boolean;
procedure InternalExecute(const AComponent: TComponent; const ADesigner: IDesigner); procedure InternalExecute(const AComponent: TComponent; const ADesigner: IDesigner);
procedure LoadGraphic(AGraphic: TX2GraphicContainerItem; const AFileName: string); procedure LoadGraphic(AGraphic: TX2GraphicContainerItem; const AFileName: string);
procedure ItemChanged(AUpdatePreview: Boolean = True); procedure ItemChanged(AUpdatePreview: Boolean = True);
procedure UpdateUI(); procedure UpdateUI;
procedure UpdatePreview(); procedure UpdatePreview;
function Active(out AIndex: Integer; out AGraphic: TX2GraphicContainerItem): Boolean; function Active(out AIndex: Integer; out AGraphic: TX2GraphicContainerItem): Boolean;
protected protected
@ -95,12 +103,13 @@ type
implementation implementation
uses uses
Graphics, Graphics,
IniFiles,
SysUtils, SysUtils,
Windows; Windows;
var var
EditorInstance: TGraphicsEditorForm; EditorInstance: TGraphicsEditorForm;
{$R *.dfm} {$R *.dfm}
@ -115,6 +124,7 @@ begin
EditorInstance.InternalExecute(AComponent, ADesigner); EditorInstance.InternalExecute(AComponent, ADesigner);
end; end;
procedure TGraphicsEditorForm.InternalExecute(const AComponent: TComponent; const ADesigner: IDesigner); procedure TGraphicsEditorForm.InternalExecute(const AComponent: TComponent; const ADesigner: IDesigner);
begin begin
FComponent := TX2GraphicContainer(AComponent); FComponent := TX2GraphicContainer(AComponent);
@ -126,9 +136,9 @@ begin
lstGraphics.Count := FComponent.GraphicCount; lstGraphics.Count := FComponent.GraphicCount;
lstGraphics.ItemIndex := 0; lstGraphics.ItemIndex := 0;
UpdateUI(); UpdateUI;
UpdatePreview(); UpdatePreview;
Show(); Show;
end; end;
@ -147,6 +157,7 @@ end;
procedure TGraphicsEditorForm.LoadGraphic(AGraphic: TX2GraphicContainerItem; const AFileName: string); procedure TGraphicsEditorForm.LoadGraphic(AGraphic: TX2GraphicContainerItem; const AFileName: string);
begin begin
AGraphic.Picture.LoadFromFile(AFileName); AGraphic.Picture.LoadFromFile(AFileName);
if Length(AGraphic.PictureName) = 0 then if Length(AGraphic.PictureName) = 0 then
begin begin
AGraphic.PictureName := ChangeFileExt(ExtractFileName(AFileName), ''); AGraphic.PictureName := ChangeFileExt(ExtractFileName(AFileName), '');
@ -160,14 +171,14 @@ begin
if Assigned(FComponentDesigner) then if Assigned(FComponentDesigner) then
FComponentDesigner.Modified; FComponentDesigner.Modified;
UpdateUI(); UpdateUI;
if AUpdatePreview then if AUpdatePreview then
UpdatePreview; UpdatePreview;
end; end;
procedure TGraphicsEditorForm.UpdateUI(); procedure TGraphicsEditorForm.UpdateUI;
var var
enabled: Boolean; enabled: Boolean;
index: Integer; index: Integer;
@ -185,13 +196,14 @@ begin
actSave.Enabled := enabled; actSave.Enabled := enabled;
actClear.Enabled := enabled; actClear.Enabled := enabled;
actExport.Enabled := (FComponent.GraphicCount > 0);
actUp.Enabled := enabled and (index > 0); actUp.Enabled := enabled and (index > 0);
actDown.Enabled := enabled and (index < Pred(FComponent.GraphicCount)); actDown.Enabled := enabled and (index < Pred(FComponent.GraphicCount));
end; end;
procedure TGraphicsEditorForm.UpdatePreview(); procedure TGraphicsEditorForm.UpdatePreview;
var var
index: Integer; index: Integer;
graphic: TX2GraphicContainerItem; graphic: TX2GraphicContainerItem;
@ -202,11 +214,18 @@ begin
if Active(index, graphic) then if Active(index, graphic) then
begin begin
imgPreview.Picture.Assign(graphic.Picture); imgPreview.Picture.Assign(graphic.Picture);
txtName.Text := graphic.PictureName;
if Assigned(graphic.Picture.Graphic) then
lblClassType.Caption := graphic.Picture.Graphic.ClassName
else
lblClassType.Caption := '';
txtName.Text := graphic.PictureName;
lstGraphics.Invalidate; lstGraphics.Invalidate;
end else end else
begin begin
imgPreview.Picture.Assign(nil); imgPreview.Picture.Assign(nil);
lblClassType.Caption := '';
txtName.Text := ''; txtName.Text := '';
end; end;
finally finally
@ -230,8 +249,8 @@ end;
procedure TGraphicsEditorForm.lstGraphicsClick(Sender: TObject); procedure TGraphicsEditorForm.lstGraphicsClick(Sender: TObject);
begin begin
UpdateUI(); UpdateUI;
UpdatePreview(); UpdatePreview;
end; end;
@ -265,7 +284,7 @@ begin
dlgOpen.Filter := GraphicFilter(TGraphic); dlgOpen.Filter := GraphicFilter(TGraphic);
dlgOpen.Options := dlgOpen.Options + [ofAllowMultiSelect]; dlgOpen.Options := dlgOpen.Options + [ofAllowMultiSelect];
if dlgOpen.Execute() then if dlgOpen.Execute then
begin begin
for fileIndex := 0 to Pred(dlgOpen.Files.Count) do for fileIndex := 0 to Pred(dlgOpen.Files.Count) do
begin begin
@ -275,13 +294,13 @@ begin
begin begin
graphic.Container := FComponent; graphic.Container := FComponent;
lstGraphics.Count := FComponent.GraphicCount; lstGraphics.Count := FComponent.GraphicCount;
LoadGraphic(graphic, dlgOpen.Files[fileIndex]); LoadGraphic(graphic, dlgOpen.Files[fileIndex]);
end else end else
raise Exception.Create('Failed to create TX2GraphicContainerItem!'); raise Exception.Create('Failed to create TX2GraphicContainerItem!');
end; end;
ItemChanged(); ItemChanged;
end; end;
end else end else
raise Exception.Create('Designer not found!'); raise Exception.Create('Designer not found!');
@ -299,7 +318,7 @@ begin
{ First attempt to remove the component; this will raise an exception { First attempt to remove the component; this will raise an exception
if it's not allowed, for example due to it being introduced in if it's not allowed, for example due to it being introduced in
an ancestor. } an ancestor. }
graphic.Free(); graphic.Free;
lstGraphics.Count := FComponent.GraphicCount; lstGraphics.Count := FComponent.GraphicCount;
if index > Pred(FComponent.GraphicCount) then if index > Pred(FComponent.GraphicCount) then
@ -307,7 +326,7 @@ begin
lstGraphics.ItemIndex := index; lstGraphics.ItemIndex := index;
ItemChanged(); ItemChanged;
end; end;
end; end;
@ -359,14 +378,15 @@ begin
dlgOpen.Filter := GraphicFilter(TGraphic); dlgOpen.Filter := GraphicFilter(TGraphic);
dlgOpen.Options := dlgOpen.Options - [ofAllowMultiSelect]; dlgOpen.Options := dlgOpen.Options - [ofAllowMultiSelect];
if dlgOpen.Execute() then if dlgOpen.Execute then
begin begin
LoadGraphic(graphic, dlgOpen.FileName); LoadGraphic(graphic, dlgOpen.FileName);
ItemChanged(); ItemChanged;
end; end;
end; end;
end; end;
procedure TGraphicsEditorForm.actSaveExecute(Sender: TObject); procedure TGraphicsEditorForm.actSaveExecute(Sender: TObject);
var var
index: Integer; index: Integer;
@ -380,11 +400,12 @@ begin
dlgSave.Filter := GraphicFilter(graphicClass); dlgSave.Filter := GraphicFilter(graphicClass);
dlgSave.FileName := ChangeFileExt(graphic.PictureName, '.' + GraphicExtension(graphicClass)); dlgSave.FileName := ChangeFileExt(graphic.PictureName, '.' + GraphicExtension(graphicClass));
if dlgSave.Execute() then if dlgSave.Execute then
graphic.Picture.SaveToFile(dlgSave.FileName); graphic.Picture.SaveToFile(dlgSave.FileName);
end; end;
end; end;
procedure TGraphicsEditorForm.actClearExecute(Sender: TObject); procedure TGraphicsEditorForm.actClearExecute(Sender: TObject);
var var
index: Integer; index: Integer;
@ -394,7 +415,97 @@ begin
if Active(index, graphic) then if Active(index, graphic) then
begin begin
graphic.Picture.Assign(nil); graphic.Picture.Assign(nil);
ItemChanged(); ItemChanged;
end;
end;
procedure TGraphicsEditorForm.actExportExecute(Sender: TObject);
var
exportFile: TIniFile;
exportBaseFileName: string;
exportPath: string;
index: Integer;
graphic: TX2GraphicContainerItem;
fileName: string;
begin
if dlgExport.Execute then
begin
exportPath := ExtractFilePath(dlgExport.FileName);
exportBaseFileName := ChangeFileExt(ExtractFileName(dlgExport.FileName), '');
exportFile := TIniFile.Create(dlgExport.FileName);
try
for index := 0 to Pred(FComponent.GraphicCount) do
begin
graphic := FComponent.Graphics[index];
exportFile.WriteString('PictureName', IntToStr(index), graphic.PictureName);
if Assigned(graphic.Picture.Graphic) then
begin
fileName := exportBaseFileName + '.' + IntToStr(index) + '.' + GraphicExtension(TGraphicClass(graphic.Picture.Graphic.ClassType));
graphic.Picture.Graphic.SaveToFile(exportPath + fileName);
exportFile.WriteString('FileName', IntToStr(index), fileName);
end;
end;
ShowMessage('Graphics have been exported');
finally
FreeAndNil(exportFile);
end;
end;
end;
procedure TGraphicsEditorForm.actImportExecute(Sender: TObject);
var
importFile: TIniFile;
importPath: string;
index: Integer;
graphic: TX2GraphicContainerItem;
fileName: string;
begin
if dlgImport.Execute then
begin
if FComponent.GraphicCount > 0 then
begin
if MessageBox(Self.Handle, 'All graphics will be replaced. Do you want to continue?', 'Import', MB_YESNO or MB_ICONQUESTION) <> ID_YES then
exit;
end;
lstGraphics.Clear;
FComponent.Clear;
importPath := ExtractFilePath(dlgImport.FileName);
importFile := TIniFile.Create(dlgImport.FileName);
try
index := 0;
while importFile.ValueExists('PictureName', IntToStr(index)) do
begin
graphic := TX2GraphicContainerItem(FComponentDesigner.CreateComponent(TX2GraphicContainerItem, nil, 0, 0, 0, 0));
if Assigned(graphic) then
begin
graphic.Container := FComponent;
graphic.PictureName := importFile.ReadString('PictureName', IntToStr(index), IntToStr(index));
fileName := importFile.ReadString('FileName', IntToStr(index), '');
if (Length(fileName) > 0) and FileExists(importPath + fileName) then
graphic.Picture.LoadFromFile(importPath + fileName);
end;
Inc(index);
end;
finally
FreeAndNil(importFile);
lstGraphics.Count := FComponent.GraphicCount;
ItemChanged(True);
end;
end; end;
end; end;
@ -406,7 +517,7 @@ begin
if (Operation = opRemove) and (AComponent = FComponent) then if (Operation = opRemove) and (AComponent = FComponent) then
begin begin
FComponent := nil; FComponent := nil;
Close(); Close;
end; end;
end; end;

View File

@ -22,18 +22,11 @@ uses
Controls, Controls,
Graphics; Graphics;
{$IFDEF VER150} {$IF CompilerVersion >= 15}
{$WARN UNSAFE_CODE OFF} {$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF} {$WARN UNSAFE_CAST OFF}
{$WARN UNSAFE_TYPE OFF} {$WARN UNSAFE_TYPE OFF}
{$ENDIF} {$IFEND}
{$IFDEF VER180}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF}
{$WARN UNSAFE_TYPE OFF}
{$ENDIF}
type type
// Forward declarations // Forward declarations

View File

@ -13,7 +13,7 @@
<Borland.Personality>Default.Personality</Borland.Personality> <Borland.Personality>Default.Personality</Borland.Personality>
<Borland.ProjectType /> <Borland.ProjectType />
<BorlandProject> <BorlandProject>
<BorlandProject xmlns=""> <Default.Personality> </Default.Personality> </BorlandProject></BorlandProject> <BorlandProject xmlns=""><Default.Personality></Default.Personality></BorlandProject></BorlandProject>
</ProjectExtensions> </ProjectExtensions>
<Target Name="X2CLGL"> <Target Name="X2CLGL">
<MSBuild Projects="Packages\D7\X2CLGL.dproj" Targets="" /> <MSBuild Projects="Packages\D7\X2CLGL.dproj" Targets="" />