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

CEGUIFalWidgetComponent.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002     filename:   CEGUIFalWidgetComponent.cpp
00003     created:    Mon Jun 13 2005
00004     author:     Paul D Turner <paul@cegui.org.uk>
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009  
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014  
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019  
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 *************************************************************************/
00024 #include "falagard/CEGUIFalWidgetComponent.h"
00025 #include "falagard/CEGUIFalXMLEnumHelper.h"
00026 #include "CEGUIWindowManager.h"
00027 #include "CEGUIExceptions.h"
00028 #include <iostream>
00029 
00030 // Start of CEGUI namespace section
00031 namespace CEGUI
00032 {
00033     WidgetComponent::WidgetComponent(const String& type, const String& look, const String& suffix) :
00034         d_baseType(type),
00035         d_imageryName(look),
00036         d_nameSuffix(suffix),
00037         d_vertAlign(VA_TOP),
00038         d_horzAlign(HA_LEFT)
00039     {}
00040 
00041     void WidgetComponent::create(Window& parent) const
00042     {
00043         // build final name and create widget.
00044         String widgetName = parent.getName() + d_nameSuffix;
00045         Window* widget = WindowManager::getSingleton().createWindow(d_baseType, widgetName);
00046 
00047         // set the widget look
00048         if (!d_imageryName.empty())
00049             widget->setLookNFeel("", d_imageryName);
00050 
00051         // add the new widget to its parent
00052         parent.addChildWindow(widget);
00053 
00054         // set alignment options
00055         widget->setVerticalAlignment(d_vertAlign);
00056         widget->setHorizontalAlignment(d_horzAlign);
00057 
00058         // TODO: We still need code to specify position and size.  Due to the advanced
00059         // TODO: possibilities, this is better handled via a 'layout' method instead of
00060         // TODO: setting this once and forgetting about it.
00061 
00062         // initialise properties.  This is done last so that these properties can
00063         // override properties specified in the look assigned to the created widget.
00064         for(PropertiesList::const_iterator curr = d_properties.begin(); curr != d_properties.end(); ++curr)
00065         {
00066             (*curr).apply(*widget);
00067         }
00068     }
00069 
00070     const ComponentArea& WidgetComponent::getComponentArea() const
00071     {
00072         return d_area;
00073     }
00074 
00075     void WidgetComponent::setComponentArea(const ComponentArea& area)
00076     {
00077         d_area = area;
00078     }
00079 
00080     const String& WidgetComponent::getBaseWidgetType() const
00081     {
00082         return d_baseType;
00083     }
00084 
00085     void WidgetComponent::setBaseWidgetType(const String& type)
00086     {
00087         d_baseType = type;
00088     }
00089 
00090     const String& WidgetComponent::getWidgetLookName() const
00091     {
00092         return d_imageryName;
00093     }
00094 
00095     void WidgetComponent::setWidgetLookName(const String& look)
00096     {
00097         d_imageryName = look;
00098     }
00099 
00100     const String& WidgetComponent::getWidgetNameSuffix() const
00101     {
00102         return d_nameSuffix;
00103     }
00104 
00105     void WidgetComponent::setWidgetNameSuffix(const String& suffix)
00106     {
00107         d_nameSuffix = suffix;
00108     }
00109 
00110     VerticalAlignment WidgetComponent::getVerticalWidgetAlignemnt() const
00111     {
00112         return d_vertAlign;
00113     }
00114 
00115     void WidgetComponent::setVerticalWidgetAlignment(VerticalAlignment alignment)
00116     {
00117         d_vertAlign = alignment;
00118     }
00119 
00120     HorizontalAlignment WidgetComponent::getHorizontalWidgetAlignemnt() const
00121     {
00122         return d_horzAlign;
00123     }
00124 
00125     void WidgetComponent::setHorizontalWidgetAlignemnt(HorizontalAlignment alignment)
00126     {
00127         d_horzAlign = alignment;
00128     }
00129 
00130     void WidgetComponent::addPropertyInitialiser(const PropertyInitialiser& initialiser)
00131     {
00132         d_properties.push_back(initialiser);
00133     }
00134 
00135     void WidgetComponent::clearPropertyInitialisers()
00136     {
00137         d_properties.clear();
00138     }
00139 
00140     void WidgetComponent::layout(const Window& owner) const
00141     {
00142         try
00143         {
00144             WindowManager::getSingleton().getWindow(owner.getName() + d_nameSuffix)->setRect(Absolute, d_area.getPixelRect(owner));
00145         }
00146         catch (UnknownObjectException)
00147         {}
00148     }
00149 
00150     void WidgetComponent::writeXMLToStream(OutStream& out_stream) const
00151     {
00152         // output opening tag
00153         out_stream << "<Child type=\"" << d_baseType << "\" nameSuffix=\"" << d_nameSuffix << "\"";
00154 
00155         if (!d_imageryName.empty())
00156             out_stream << " look=\"" << d_imageryName << "\"";
00157 
00158         out_stream << ">" << std::endl;
00159 
00160         // output target area
00161         d_area.writeXMLToStream(out_stream);
00162 
00163         // output vertical alignment
00164         out_stream << "<VertAlignment type=\"" << FalagardXMLHelper::vertAlignmentToString(d_vertAlign) << "\" />" << std::endl;
00165 
00166         // output horizontal alignment
00167         out_stream << "<HorzAlignment type=\"" << FalagardXMLHelper::horzAlignmentToString(d_horzAlign) << "\" />" << std::endl;
00168 
00169         //output property initialisers
00170         for (PropertiesList::const_iterator prop = d_properties.begin(); prop != d_properties.end(); ++prop)
00171         {
00172             (*prop).writeXMLToStream(out_stream);
00173         }
00174 
00175         // output closing tag
00176         out_stream << "</Child>" << std::endl;
00177     }
00178 
00179 } // End of  CEGUI namespace section

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