Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIMenubar.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIMenubar.cpp
00003         created:        31/3/2005
00004         author:         Tomas Lindquist Olsen (based on code by Paul D Turner)
00005         
00006         purpose:        Implementation of Menubar widget base class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "elements/CEGUIMenubar.h"
00027 #include "elements/CEGUIPopupMenu.h"
00028 #include "elements/CEGUIMenuItem.h"
00029 
00030 // Start of CEGUI namespace section
00031 namespace CEGUI
00032 {
00033 
00034 /*************************************************************************
00035         Constants
00036 *************************************************************************/
00037 const String Menubar::EventNamespace("Menubar");
00038 
00039 /*************************************************************************
00040         Constructor for Menubar base class.
00041 *************************************************************************/
00042 Menubar::Menubar(const String& type, const String& name)
00043         : MenuBase(type, name)
00044 {
00045         d_itemSpacing = 10;
00046         d_horzPadding = d_vertPadding = 3;
00047         d_borderWidth = 5;
00048 }
00049 
00050 
00051 /*************************************************************************
00052         Destructor for Menubar base class.
00053 *************************************************************************/
00054 Menubar::~Menubar(void)
00055 {
00056 }
00057 
00058 
00059 /*************************************************************************
00060         Sets up sizes and positions for attached ItemEntry children.
00061 *************************************************************************/
00062 void Menubar::layoutItemWidgets()
00063 {
00064         Rect render_rect = getItemRenderArea();
00065         float x0 = PixelAligned(render_rect.d_left+d_borderWidth);
00066         
00067         Rect rect;
00068 
00069         ItemEntryList::iterator item = d_listItems.begin();
00070         while ( item != d_listItems.end() )
00071         {
00072                 Size optimal = (*item)->getItemPixelSize();
00073                 optimal.d_width += 2*d_horzPadding;
00074                 optimal.d_height += 2*d_vertPadding;
00075 
00076                 (*item)->setVerticalAlignment(VA_CENTRE);
00077                 rect.setPosition( Point(x0,0) );
00078                 rect.setSize( Size( PixelAligned(optimal.d_width), PixelAligned(optimal.d_height) ) );
00079 
00080                 (*item)->setRect(Absolute,rect);
00081                 
00082                 x0 += optimal.d_width + d_itemSpacing;
00083 
00084                 item++;
00085         }
00086 
00087 }
00088 
00089 
00090 /*************************************************************************
00091         Returns the "optimal" size for the content in unclipped pixels
00092 *************************************************************************/
00093 Size Menubar::getContentSize()
00094 {
00095         // find the content sizes
00096         float tallest = 0;
00097         float total_width = 0;
00098         
00099         size_t count = 0;
00100         size_t max = d_listItems.size();
00101         while (count < max)
00102         {
00103                 const Size sz = d_listItems[count]->getItemPixelSize();
00104                 if (sz.d_height > tallest)
00105                         tallest = sz.d_height;
00106                 total_width += sz.d_width;
00107 
00108                 count++;
00109         }
00110         
00111         const float dbl_border = d_borderWidth+d_borderWidth;
00112 
00113         // add horz padding
00114         total_width += 2.0f*count*d_horzPadding;
00115         // spacing
00116         total_width += (count-1)*d_itemSpacing;
00117         // border
00118         total_width += dbl_border;
00119 
00120         // add vert padding
00121         tallest += d_vertPadding+d_vertPadding;
00122         // border
00123         tallest += dbl_border;
00124 
00125         // return the content size
00126         return Size( total_width, tallest);
00127 }
00128 
00129 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:32 2005 for Crazy Eddies GUI System by  doxygen 1.4.3