diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-02-13 19:15:25 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-02-13 19:15:25 +0000 |
commit | 6dccfb0375b69e2661174d0728165980b71706c2 (patch) | |
tree | 94a92daeff3843d9cc2f39af9f92613d73f3ff3b | |
parent | 7f2beb3c8d52fc037460b597c76dfdcc5556ae6d (diff) | |
download | fpGUI-6dccfb0375b69e2661174d0728165980b71706c2.tar.xz |
* Created a new ImageList unit and class.
-rw-r--r-- | src/corelib/gdi/fpgfx_package.lpk | 6 | ||||
-rw-r--r-- | src/corelib/gdi/fpgfx_package.pas | 5 | ||||
-rw-r--r-- | src/corelib/gfx_imagelist.pas | 273 | ||||
-rw-r--r-- | src/corelib/gfx_wuline.pas | 2 | ||||
-rw-r--r-- | src/corelib/x11/fpgfx_package.lpk | 8 | ||||
-rw-r--r-- | src/corelib/x11/fpgfx_package.pas | 2 |
6 files changed, 289 insertions, 7 deletions
diff --git a/src/corelib/gdi/fpgfx_package.lpk b/src/corelib/gdi/fpgfx_package.lpk index a020eae0..b9f53dff 100644 --- a/src/corelib/gdi/fpgfx_package.lpk +++ b/src/corelib/gdi/fpgfx_package.lpk @@ -26,7 +26,7 @@ <License Value="Modified LGPL "/> <Version Minor="5" Release="1"/> - <Files Count="15"> + <Files Count="16"> <Item1> <Filename Value="..\gfxbase.pas"/> <UnitName Value="gfxbase"/> @@ -87,6 +87,10 @@ <Filename Value="..\gfx_wuline.pas"/> <UnitName Value="gfx_wuline"/> </Item15> + <Item16> + <Filename Value="..\gfx_imagelist.pas"/> + <UnitName Value="gfx_imagelist"/> + </Item16> </Files> <RequiredPkgs Count="1"> <Item1> diff --git a/src/corelib/gdi/fpgfx_package.pas b/src/corelib/gdi/fpgfx_package.pas index 620e4890..8f347baa 100644 --- a/src/corelib/gdi/fpgfx_package.pas +++ b/src/corelib/gdi/fpgfx_package.pas @@ -8,8 +8,9 @@ interface uses gfxbase, fpgfx, gfx_gdi, gfx_stdimages, gfx_imgfmt_bmp, gfx_widget, - gfx_UTF8utils, gfx_extinterpolation, gfx_cmdlineparams, gfx_clipboard, - gfx_utils, gfx_popupwindow, gfx_impl, gfx_command_intf, gfx_wuline; + gfx_UTF8utils, gfx_extinterpolation, gfx_cmdlineparams, gfx_clipboard, + gfx_utils, gfx_popupwindow, gfx_impl, gfx_command_intf, gfx_wuline, + gfx_imagelist; implementation diff --git a/src/corelib/gfx_imagelist.pas b/src/corelib/gfx_imagelist.pas new file mode 100644 index 00000000..97282b62 --- /dev/null +++ b/src/corelib/gfx_imagelist.pas @@ -0,0 +1,273 @@ +{ + fpGUI - Free Pascal GUI Library + + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this + distribution, for details of the copyright. + + See the file COPYING.modifiedLGPL, included in this distribution, + for details about redistributing fpGUI. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + Description: + + A basic image list component for use by the GUI components like the + treeview etc. +} + +unit gfx_imagelist; + +{$mode objfpc}{$H+} + +{.$define DEBUG} + +interface + +uses + Classes, + SysUtils, + fpgfx; + +type + + EItemExists = class(Exception); + + TfpgImageList = class; // forward declaration + + + TfpgImageItem = class(TObject) + private + FImage: TfpgImage; + FIndex: word; + FImageList: TfpgImageList; + procedure SetImageList(AImageList: TfpgImageList); + procedure SetIndex(AIndex: word); + procedure SetImage(AImage: TfpgImage); + public + constructor Create; overload; + constructor Create(AImageList: TfpgImageList; AIndex: word; AImage: TfpgImage); overload; + constructor Create(AFileName: string; AIndex: word); overload; + destructor Destroy; override; + property Index: word read FIndex write SetIndex; + property Image: TfpgImage read FImage write SetImage; + property ImageList: TfpgImageList read FImageList write SetImageList; + procedure LoadFromFile(AFileName: String); + end; + + + TfpgImageList = class(TObject) + private + FList: TList; + function GetFListIndex(AIndex: Integer): Integer; + function GetItem(AIndex: integer): TfpgImageItem; + procedure SetItem(AIndex: integer; AItem: TfpgImageItem); + public + constructor Create; + destructor Destroy; override; + procedure AddItemFromFile(AFileName: String; AIndex: word); + procedure AddImage(AImage: TfpgImage; AIndex: word); + procedure RemoveIndex(AIndex: integer); + function GetMaxItem: word; + property Item[AIndex: integer]: TfpgImageItem read GetItem write SetItem; + end; + + + +implementation + +uses + gfx_imgfmt_bmp; + +{ TfpgImageList } + +function TfpgImageList.GetFListIndex(AIndex: Integer): Integer; +var + ACounter: integer; +begin + {$IFDEF DEBUG} + writeln('TfpgImageList.GetFListIndex'); + {$ENDIF} + result := -1; + for ACounter := 0 to FList.Count - 1 do + if TfpgImageItem(FList[ACounter]).Index = AIndex then + begin + result := ACounter; + Break; //==> + end; +end; + +function TfpgImageList.GetItem(AIndex: integer): TfpgImageItem; +var + AFindIndex: integer; +begin + {$IFDEF DEBUG} + writeln('TfpgImageList.GetItem'); + {$ENDIF} + result := nil; + AFindIndex := GetFListIndex(AIndex); + if AFindIndex > -1 then + result := TfpgImageItem(FList[AFindIndex]); +end; + +procedure TfpgImageList.SetItem(AIndex: integer; AItem: TfpgImageItem); +begin + if AItem = nil then + Exit; //==> + + if GetItem(AIndex) = AItem then + Exit; //==> + + RemoveIndex(AIndex); // delete existing Item + AItem.Index := AIndex; + FList.Add(AItem); +end; + +constructor TfpgImageList.Create; +begin + FList := TList.Create; +end; + +destructor TfpgImageList.Destroy; +var + ACounter: integer; +begin + for ACounter := 0 to FList.Count - 1 do + TfpgImageItem(FList[ACounter]).Destroy; // frees images + FList.Destroy; + inherited Destroy +end; + +procedure TfpgImageList.AddItemFromFile(AFileName: String; AIndex: word); +var + AImageItem: TfpgImageItem; +begin + {$IFDEF DEBUG} + writeln('TfpgImageList.AddItemFromFile'); + {$ENDIF} + AImageItem := TfpgImageItem.Create; + AImageItem.LoadFromFile(AFileName); + Item[AIndex] := AImageItem; +end; + +procedure TfpgImageList.AddImage(AImage: TfpgImage; AIndex: word); +var + AImageItem: TfpgImageItem; +begin + AImageItem := TfpgImageItem.Create; + AImageItem.Image := AImage; + Item[AIndex] := AImageItem; +end; + +procedure TfpgImageList.RemoveIndex(AIndex: integer); +begin + {$IFDEF DEBUG} + writeln('TfpgImageList.RemoveIndex'); + {$ENDIF} + AIndex := GetFListIndex(AIndex); + if AIndex <> -1 then + begin + TfpgImageItem(FList[AIndex]).Destroy; + FList.Delete(AIndex); + end; +end; + +function TfpgImageList.GetMaxItem: word; +var + ACounter: integer; +begin + result := 0; + for ACounter := 0 to FList.Count - 1 do + if TfpgImageItem(FList[ACounter]).Index > result then + result := TfpgImageItem(FList[ACounter]).Index; +end; + +{ TfpgImageItem } + +procedure TfpgImageItem.SetImageList(AImageList: TfpgImageList); +begin + if AImageList = nil then + begin + FImageList := nil; + end + else + begin + if FImageList <> nil then + FImageList.RemoveIndex(Index); + FImageList := AImageList; + FImageList.Item[Index] := self; + end; +end; + +procedure TfpgImageItem.SetIndex(AIndex: word); +begin + {$IFDEF DEBUG} + writeln('TfpgImageItem.SetIndex'); + {$ENDIF} + if AIndex <> FIndex then + begin + if ImageList <> nil then + ImageList.RemoveIndex(AIndex); + FIndex := AIndex; + end; +end; + +procedure TfpgImageItem.SetImage(AImage: TfpgImage); +begin + {$IFDEF DEBUG} + writeln('TfpgImageItem.SetImage'); + {$ENDIF} + if AImage <> FImage then + begin + FImage := AImage; + FImage.CreateMaskFromSample(0,0); + end; +end; + +constructor TfpgImageItem.Create; +begin + ImageList := nil; + FIndex := 0; + FImage := nil; +end; + +constructor TfpgImageItem.Create(AImageList: TfpgImageList; AIndex: word; + AImage: TfpgImage); +begin + if AImageList = nil then + Exit; //==> + FImage := AImage; + FIndex := AIndex; + FImageList := nil; + ImageList := AImageList; +end; + +constructor TfpgImageItem.Create(AFileName: string; AIndex: word); +begin + {$IFDEF DEBUG} + writeln('TfpgImageItem.Create(', AFileName, ',', AIndex, ')'); + {$ENDIF} + Index := AIndex; + LoadFromFile(AFileName); +end; + +destructor TfpgImageItem.Destroy; +begin + if FImage <> nil then + FImage.Destroy; + inherited Destroy; +end; + +procedure TfpgImageItem.LoadFromFile(AFileName: String); +begin + {$IFDEF DEBUG} + writeln('TfpgImageItem.LoadFromFile'); + {$ENDIF} + if FImage <> nil then + FImage.Destroy; + FImage := LoadImage_BMP(AFileName); +end; + +end. + diff --git a/src/corelib/gfx_wuline.pas b/src/corelib/gfx_wuline.pas index ce5c403b..e2472a2e 100644 --- a/src/corelib/gfx_wuline.pas +++ b/src/corelib/gfx_wuline.pas @@ -1,7 +1,7 @@ { fpGUI - Free Pascal GUI Library - Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, diff --git a/src/corelib/x11/fpgfx_package.lpk b/src/corelib/x11/fpgfx_package.lpk index 814f5a15..e6790455 100644 --- a/src/corelib/x11/fpgfx_package.lpk +++ b/src/corelib/x11/fpgfx_package.lpk @@ -24,7 +24,7 @@ <License Value="Modified LGPL "/> <Version Minor="5" Release="1"/> - <Files Count="17"> + <Files Count="18"> <Item1> <Filename Value="x11_xft.pas"/> <UnitName Value="x11_xft"/> @@ -93,6 +93,10 @@ <Filename Value="../gfx_wuline.pas"/> <UnitName Value="gfx_wuline"/> </Item17> + <Item18> + <Filename Value="../gfx_imagelist.pas"/> + <UnitName Value="gfx_imagelist"/> + </Item18> </Files> <LazDoc Paths="../../../docs/xml/corelib/;../../../docs/xml/corelib/x11/;../../../docs/xml/corelib/gdi/"/> <RequiredPkgs Count="1"> @@ -109,4 +113,4 @@ <IgnoreBinaries Value="False"/> </PublishOptions> </Package> -</CONFIG>
\ No newline at end of file +</CONFIG> diff --git a/src/corelib/x11/fpgfx_package.pas b/src/corelib/x11/fpgfx_package.pas index aa0d1848..b1b3678a 100644 --- a/src/corelib/x11/fpgfx_package.pas +++ b/src/corelib/x11/fpgfx_package.pas @@ -10,7 +10,7 @@ uses x11_xft, x11_keyconv, gfxbase, gfx_x11, fpgfx, gfx_stdimages, gfx_imgfmt_bmp, gfx_widget, gfx_UTF8utils, gfx_extinterpolation, gfx_cmdlineparams, gfx_clipboard, gfx_utils, gfx_popupwindow, gfx_impl, gfx_command_intf, - gfx_wuline; + gfx_wuline, gfx_imagelist; implementation |