Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #ifndef __SP_GUI_LISTGADGET_H__
00009 #define __SP_GUI_LISTGADGET_H__
00010 
00011 
00012 #include "Base/spStandard.hpp"
00013 
00014 #ifdef SP_COMPILE_WITH_GUI
00015 
00016 
00017 #include "GUI/spGUIGadget.hpp"
00018 #include "GUI/spGUIScrollViewBased.hpp"
00019 
00020 
00021 namespace sp
00022 {
00023 namespace gui
00024 {
00025 
00026 
00027 static const s32 DEF_GUILIST_COLUMNSIZE = -1;
00028 
00029 enum EListFlags
00030 {
00031     GUIFLAG_NOCOLUMNSCROLL = 0x00000001,
00032 };
00033 
00034 
00035 
00036 
00037 
00038 
00039 class SP_EXPORT GUIListRootEntry
00040 {
00041     
00042     public:
00043         
00044         virtual ~GUIListRootEntry();
00045         
00046         virtual void setText(const io::stringc &Text);
00047         
00048         
00049         
00050         inline io::stringc getText() const
00051         {
00052             return Text_;
00053         }
00054         
00055         inline void setVisible(bool isVisible)
00056         {
00057             isVisible_ = isVisible;
00058         }
00059         inline bool getVisible() const
00060         {
00061             return isVisible_;
00062         }
00063         
00064         inline void setIcon(video::Texture* Icon)
00065         {
00066             Icon_ = Icon;
00067         }
00068         inline video::Texture* getIcon() const
00069         {
00070             return Icon_;
00071         }
00072         
00073         inline void setColor(const video::color &Color)
00074         {
00075             Color_ = Color;
00076         }
00077         inline video::color getColor() const
00078         {
00079             return Color_;
00080         }
00081         
00082     protected:
00083         
00084         friend class GUIListGadget;
00085         
00086         
00087         
00088         GUIListRootEntry();
00089         
00090         
00091         
00092         io::stringc Text_;
00093         video::Texture* Icon_;
00094         video::color Color_;
00095         
00096         bool isVisible_;
00097         bool isPicked_;
00098         
00099 };
00100 
00101 
00102 
00103 
00104 
00105 
00106 class SP_EXPORT GUIListColumn : public GUIListRootEntry
00107 {
00108     
00109     public:
00110         
00111         GUIListColumn();
00112         ~GUIListColumn();
00113         
00114         
00115         
00116         inline void setColumnSize(s32 Size)
00117         {
00118             ColumnSize_ = math::Max(0, Size);
00119         }
00120         inline s32 getColumnSize() const
00121         {
00122             return ColumnSize_;
00123         }
00124         
00125     private:
00126         
00127         
00128         
00129         s32 ColumnSize_;
00130         
00131 };
00132 
00133 
00134 
00135 
00136 
00137 
00138 class SP_EXPORT GUIListItem : public GUIListRootEntry
00139 {
00140     
00141     public:
00142         
00143         GUIListItem();
00144         ~GUIListItem();
00145         
00146         void setText(const io::stringc &Text);
00147         
00148         
00149         
00150         inline void setGroup(bool isGroup)
00151         {
00152             isGroup_ = isGroup;
00153         }
00154         inline bool getGroup() const
00155         {
00156             return isGroup_;
00157         }
00158         
00159         inline void setGroupParent(GUIListItem* Parent)
00160         {
00161             GroupParent_ = Parent;
00162         }
00163         inline GUIListItem* getGroupParent() const
00164         {
00165             return GroupParent_;
00166         }
00167         
00168         inline void setItemSize(s32 Size)
00169         {
00170             ItemSize_ = math::Max(0, Size);
00171         }
00172         inline s32 getItemSize() const
00173         {
00174             return ItemSize_;
00175         }
00176         
00177     private:
00178         
00179         
00180         
00181         std::vector<io::stringc> SubTextList_;
00182         
00183         bool isGroup_;
00184         GUIListItem* GroupParent_;
00185         s32 ItemSize_;
00186         
00187         GUIGadget* StateGadget_;
00188         u32 StateGadgetSub_;
00189         
00190 };
00191 
00192 
00193 
00194 
00195 
00196 
00201 class SP_EXPORT GUIListGadget : public GUIGadget, public GUIScrollViewBased
00202 {
00203     
00204     public:
00205         
00206         GUIListGadget();
00207         ~GUIListGadget();
00208         
00209         
00210         
00211         bool update();
00212         void draw();
00213         
00214         dim::rect2di getLocalViewArea(const GUIController* Obj = 0) const;
00215         
00216         GUIListColumn* addColumn(
00217             const io::stringc &Text, s32 ColumnSize = DEF_GUILIST_COLUMNSIZE, video::Texture* Icon = 0
00218         );
00219         void removeColumn(GUIListColumn* Column);
00220         
00222         void clearColumns();
00223         
00224         GUIListItem* addItem(
00225             const io::stringc &Text, GUIListItem* GroupParent = 0, bool isGroup = false, video::Texture* Icon = 0
00226         );
00227         void removeItem(GUIListItem* Item);
00228         
00230         void clearItems();
00231         
00236         void addDirectoryItems(io::stringc DirPath);
00237         
00238         
00239         
00240         inline GUIListItem* getSelectedItem() const
00241         {
00242             return SelectedItem_;
00243         }
00244         
00245     private:
00246         
00247         
00248         
00249         static const s32 COLUMN_HEIGHT      = 25;
00250         
00251         static const video::color ITEMPICK_COLOR_A;
00252         static const video::color ITEMPICK_COLOR_B;
00253         
00254         
00255         
00256         enum EFocusUsages
00257         {
00258             USAGE_RESIZE_COLUMN,
00259         };
00260         
00261         
00262         
00263         void drawColumn(GUIListColumn* Column, s32 EntryPos);
00264         void drawItem(GUIListItem* Item, s32 EntryPos);
00265         
00266         bool pickColumn(GUIListColumn* &Column, bool &isEdgePick);
00267         void updateItem(GUIListItem* Item, dim::point2di &Pos);
00268         
00269         dim::point2di getItemsStartPos() const;
00270         
00271         
00272         
00273         template <class T> bool deleteListObject(T* Object, std::list<T*> &List)
00274         {
00275             if (Object)
00276             {
00277                 for (typename std::list< T*, std::allocator<T*> >::iterator it = List.begin(); it != List.end(); ++it)
00278                 {
00279                     if (*it == Object)
00280                     {
00281                         MemoryManager::deleteMemory(*it);
00282                         List.erase(it);
00283                         return true;
00284                     }
00285                 }
00286             }
00287             return false;
00288         }
00289         
00290         
00291         
00292         std::list<GUIListColumn*> ColumnList_;
00293         std::list<GUIListItem*> ItemList_;
00294         
00295         GUIListColumn* FocusedColumn_;
00296         s32 FocusedColumnPosHorz_;
00297         
00298         GUIListItem* SelectedItem_;
00299         
00300 };
00301 
00302 
00303 } 
00304 
00305 } 
00306 
00307 
00308 #endif
00309 
00310 #endif
00311 
00312 
00313 
00314