AaronCameron.net
Because you all make me very, very tired.
Not a Member? - Login or Create an Account
Wednesday the 23rd of May 2012 @ 09:43am
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cGuiLabel.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2003  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "gui/cGuiLabel.h"
00026 
00027 #include "n2l/dynVars.h"
00028 #include "n2l/resourceManagement.h"
00029 
00030 #include "gui/cGuiFactory.h"
00031 
00032 namespace n2l
00033 {
00034 
00035 #   ifdef N2L_PASSIVE_GUI_REG
00036         tBool cGuiLabel::smRegistered = cGuiFactory::current().registerLoader(
00037             "n2l::cGuiLabel", cGuiElement::loadNew<cGuiLabel> );
00038 #   endif
00039     /**************************************************************************/
00040     cGuiLabel::cGuiLabel() :
00041         cGuiElement( tGuiPos(0,0), tGuiPos(1,1) )
00042     {
00043     }
00044 
00045 
00046     /**************************************************************************/
00047     cGuiLabel::~cGuiLabel()
00048     {
00049     }
00050 
00051 
00052     /**************************************************************************/
00053     cGuiLabel::cGuiLabel( const cVfsNodeInterface & iNode ) :
00054         cGuiElement( tGuiPos(0,0), tGuiPos(1,1) )
00055     {
00056         load( iNode );
00057     }
00058 
00059 
00060     /**************************************************************************/
00061     cGuiLabel::cGuiLabel( const cDynVar & iDefinition ) :
00062         cGuiElement( tGuiPos(0,0), tGuiPos(1,1) )
00063     {
00064         load( iDefinition );
00065     }
00066 
00067 
00068     /**************************************************************************/
00069     void cGuiLabel::load( const cVfsNodeInterface & iNode )
00070     {
00071         cDynVar def;
00072         validateAndDecode( def, iNode, "n2l::cGuiLabel" );
00073         load( def );
00074     }
00075 
00076 
00077     /**************************************************************************/
00078     void cGuiLabel::load( const cDynVar & iDefinition )
00079     {
00080         // Load parent properties
00081         cGuiElement::load( iDefinition );
00082 
00083         // Now my properties
00084         if (iDefinition["textStyle"]) {
00085             if (iDefinition["textStyle"].isArray())
00086                 textStyle( cGuiTextStyle( iDefinition["textStyle"] ) );
00087             else textStyle( *cResourceManager::get<cGuiTextStyle>(
00088                 iDefinition["textStyle"]) );
00089         }
00090 
00091         if (iDefinition.keyExists("label"))
00092             label( iDefinition["label"] );
00093     }
00094 
00095 
00096     /**************************************************************************/
00097     void cGuiLabel::draw() const
00098     {
00099         mTextStyle.draw( innerPos(), innerSize(), mLabel );
00100     }
00101 
00102 
00103     /**************************************************************************/
00104     void cGuiLabel::textStyle( const cGuiTextStyle & iStyle )
00105     {
00106         mTextStyle = iStyle;
00107     }
00108 
00109 
00110     /**************************************************************************/
00111     void cGuiLabel::label( const tString & iLabel )
00112     {
00113         mLabel = iLabel;
00114     }
00115 
00116 
00117     /**************************************************************************/
00118     const tString & cGuiLabel::label() const
00119     {
00120         return mLabel;
00121     }
00122 
00123 
00124     /**************************************************************************/
00125     const cAutoPtr<cGuiElement> cGuiLabel::clone() const
00126     {
00127         cAutoPtr<cGuiElement> newElement( new cGuiLabel );
00128         cloneInto( newElement );
00129         return newElement;
00130     }
00131 
00132     /**************************************************************************/
00133     void cGuiLabel::prop( const tString &iName, const cDynVar &iVal,
00134         const tString &iInnerKey )
00135     {
00136         if (iName == "textStyle") {
00137             if (iInnerKey.empty()) {
00138                 if (iVal.isArray())
00139                     textStyle( iVal );
00140                 else
00141                     textStyle( *cResourceManager::get<cGuiTextStyle>(iVal) );
00142             } else
00143                 mTextStyle.prop( iInnerKey, iVal );
00144 
00145         } else
00146             cGuiElement::prop( iName, iVal );
00147     }
00148 
00149     /**************************************************************************/
00150     const cDynVar cGuiLabel::prop( const tString &iName,
00151         const tString &iInnerKey ) const
00152     {
00153         if (iName == "textStyle")
00154             return mTextStyle.prop( iInnerKey );
00155 
00156         return cGuiElement::prop( iName );
00157     }
00158 
00159     /**************************************************************************/
00160     void cGuiLabel::cloneInto( const cAutoPtr<cGuiLabel> & i_ioElement ) const
00161     {
00162         // Parent Properties first
00163         cGuiElement::cloneInto( i_ioElement );
00164         
00165         //  Now our properties.
00166         i_ioElement->textStyle(mTextStyle);
00167         i_ioElement->label(mLabel);
00168     }
00169 
00170 } // namespace n2l
©2012 Aaron Cameron