Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

DynamicList.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // DynamicList.h
00003 // A list that adjusts its size based on the components added to it.
00004 //
00005 // Author: Richard van Balen
00006 
00007 #ifndef OglGui_DynamicList_h
00008 #define OglGui_DynamicList_h
00009 
00010 #ifndef OglGui_StaticText_h
00011 #include "OglGui/StaticText.h"
00012 #endif
00013 
00014 namespace OglGui {
00015 
00016 class DynamicList : public Window
00017 {
00018 public:
00019     DynamicList(Window* parent, int minW, int minH) :
00020         Window(parent, minW, minH)
00021     {
00022         Init(minW, minH);
00023     }
00024 
00025     DynamicList(Window* parent, int x, int y, int minW, int minH) :
00026         Window(parent, x, y, minW, minH)
00027     {
00028         Init(minW, minH);
00029     }
00030 
00031     void    Spacing(int nPix)           { mSpacing = nPix; }
00032     int     Spacing()                   { return mSpacing; }
00033  
00034     void HandleLayout()
00035     {
00036         int     curY = H();
00037         int     nY = curY;
00038         int     nW = 0, nH = 0;
00039 
00040         for (int i=0 ; i < mChildWindows.size() ; i++)
00041         {
00042             Window* child = mChildWindows[i];
00043             if (!HasTags((TAGABLE*)child->GetOGLWND(), visibleTag))
00044                 continue;
00045 
00046             int cX, cY, cW, cH;
00047             child->GetDimensions(cX,cY,cW,cH);
00048             nH   += cH + mSpacing;
00049             curY -= cH + mSpacing;
00050             child->SetDimensions(RETAIN, curY, RETAIN, RETAIN);
00051             if (nW < cX+cW)
00052                 nW = cX+cW;
00053         }
00054 
00055         if (nH < mMinH)
00056             nH = mMinH;
00057         if (nW < mMinW)
00058             nW = mMinW;
00059         nY = Y() + H() - nH;
00060         SetDimensions(RETAIN, nY, nW, nH);
00061     }
00062 
00063 
00064     // Must be called when a child window has been deleted
00065     // from the DynamicList.
00066     virtual void RemoveWindow(Window* child, bool destroy=false)
00067     {
00068         for (int i=0; i<mChildWindows.size(); i++)
00069             if (child == mChildWindows[i])
00070             {
00071                 mChildWindows.erase(mChildWindows.begin() + i);
00072                 if (destroy)
00073                     delete child;
00074                 HandleLayout();
00075                 return;
00076             }
00077     }
00078 
00079     virtual void AddWindow(Window* child, int insertAt=-1)
00080     {
00081         if (insertAt==-1 || insertAt>mChildWindows.size()-1)
00082             insertAt = mChildWindows.size();
00083 
00084         mChildWindows.insert(mChildWindows.begin()+insertAt,child);
00085         child->SetAllowReposition(false);
00086         HandleLayout();
00087     }
00088 
00089     virtual void DisplayFunc()
00090     {
00091         HandleLayout();
00092         Window::DisplayFunc();
00093     }
00094 
00095 
00096 protected :
00097     std::vector<Window*>  mChildWindows;
00098     int                   mMinW;
00099     int                   mMinH;
00100     int                   mSpacing;
00101 
00102 private :
00103     void Init(int minW, int minH)
00104     {
00105         mMinW = minW;
00106         mMinH = minH;
00107 
00108         mSpacing = 2;
00109     }
00110 };
00111 
00112 } // namespace OglGui
00113 
00114 #endif // DynamicList_h

Generated on Fri Mar 19 09:31:35 2010 for ImpalaSrc by  doxygen 1.5.1