From 008cfe954673a6632376e1a65e2dbc6ceda03a99 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 27 Sep 2006 19:30:22 +0000 Subject: [PATCH] IDEIntf: image list editor: implemented auto splitting added image from etrusco git-svn-id: trunk@9997 - --- ide/idetranslations.pas | 2 +- ideintf/imagelisteditor.pp | 64 ++++++++++++++++++++++++++++-------- ideintf/objinspstrconsts.pas | 6 ++++ 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/ide/idetranslations.pas b/ide/idetranslations.pas index 62f3dbf061..c27c97af6e 100644 --- a/ide/idetranslations.pas +++ b/ide/idetranslations.pas @@ -117,7 +117,7 @@ begin Result:=rsLanguageDutch else if CompareText(ID,'ja')=0 then Result:=rsLanguageJapanese - else if CompareText(ID,'zh-cn')=0 then + else if CompareText(ID,'zh_CN')=0 then Result:=rsLanguageChinese else if CompareText(ID,'id')=0 then Result:=rsLanguageIndonesian diff --git a/ideintf/imagelisteditor.pp b/ideintf/imagelisteditor.pp index b943398bfe..541e0687e5 100644 --- a/ideintf/imagelisteditor.pp +++ b/ideintf/imagelisteditor.pp @@ -34,8 +34,8 @@ interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, LResources, ComCtrls, - StdCtrls, Buttons, ExtCtrls, Menus, PropEdits, ComponentEditors, LCLProc, - ColorBox, ExtDlgs, ObjInspStrConsts; + StdCtrls, Buttons, ExtCtrls, Menus, LCLProc, ColorBox, ExtDlgs, + IDEDialogs, PropEdits, ComponentEditors, ObjInspStrConsts; type TGlyphAdjustment = (gaNone, gaStretch, gaCrop, gaCenter); @@ -110,8 +110,10 @@ type function GetVerbCount: Integer; override; end; + implementation + function EditImageList(AImageList: TImageList): Boolean; var ImageListEditorDlg: TImageListEditorDlg; @@ -156,6 +158,15 @@ begin end; end; +function CreateGlyphSplit(Src: TBitmap; Width, Height: Integer; SrcSplitIndex: Integer): TBitmap; +begin + Result := TBitmap.Create; + Result.Width := Width; + Result.Height := Height; + Result.Canvas.CopyRect( Rect(0, 0, Width, Height), + Src.Canvas, Bounds(SrcSplitIndex * Width, 0, Width, Height) ); +end; + { TImageListEditorDlg } procedure TImageListEditorDlg.FormCreate(Sender: TObject); @@ -469,6 +480,9 @@ var Picture: TPicture; P: PGlyphInfo; Node: TTreeNode; + v_PartCount: Integer; + c_Part: Integer; + v_CompositeBmp: TBitmap; begin SaveDialog.InitialDir := ExtractFileDir(FileName); Bmp := nil; @@ -487,18 +501,40 @@ begin begin if not Bmp.Empty then begin - Glyph := CreateGlyph(Bmp, ImageList.Width, ImageList.Height, gaNone); - I := ImageList.AddDirect(Glyph, nil); - - New(P); - P^.Bitmap := Bmp; - P^.Adjustment := gaNone; - P^.TransparentColor := clFuchsia; - - Node := TreeView.Items.AddObject(nil, IntToStr(I), P); - Node.ImageIndex := I; - Node.SelectedIndex := I; - TreeView.Selected := Node; + if (Bmp.Height = ImageList.Height) + and (Bmp.Width mod ImageList.Width = 0) + and (IDEQuestionDialog(Caption +' - '+ btnAdd.Caption, + s_SuggestSplitImage, mtConfirmation, + [s_AddAsSingle, mrNo, s_SplitImage, mrYes]) = mrYes) + then begin + v_PartCount := Bmp.Width div ImageList.Width; + v_CompositeBmp := Bmp; + Bmp := nil; + end + else begin + v_PartCount := 1; + v_CompositeBmp := nil; + end; + + for c_Part := 0 to v_PartCount -1 do + begin + if Assigned(v_CompositeBmp) then + Bmp := CreateGlyphSplit(v_CompositeBmp, ImageList.Width, ImageList.Height, c_Part); + + Glyph := CreateGlyph(Bmp, ImageList.Width, ImageList.Height, gaNone); + I := ImageList.AddDirect(Glyph, nil); + + New(P); + P^.Bitmap := Bmp; + P^.Adjustment := gaNone; + P^.TransparentColor := clFuchsia; + + Node := TreeView.Items.AddObject(nil, IntToStr(I), P); + Node.ImageIndex := I; + Node.SelectedIndex := I; + TreeView.Selected := Node; + end; + v_CompositeBmp.Free; end else Bmp.Free; end; diff --git a/ideintf/objinspstrconsts.pas b/ideintf/objinspstrconsts.pas index 5553deb8af..b90840ac01 100644 --- a/ideintf/objinspstrconsts.pas +++ b/ideintf/objinspstrconsts.pas @@ -309,6 +309,12 @@ resourcestring rscdAlignment = 'Alignment'; rscdLeft = 'Left'; + // image list editor + s_SuggestSplitImage = 'Do you want to split the image?'; + s_AddAsSingle = 'Add as single'; + s_SplitImage = 'Split image'; + + implementation end.