![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cGuiElement.hGo to the documentation of this file.00001 /************************************************************************ 00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library 00003 Copyright (C) 2002 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 #ifndef _n2l4_cGuiElement_H 00026 #define _n2l4_cGuiElement_H 00027 00028 #include "n2l/n2l.h" 00029 #include "n2l/timing.h" 00030 #include "n2l/geometry.h" 00031 00032 #include "gui/types.h" 00033 00034 #include <list> 00035 #include <map> 00036 00037 00038 /******************************************************************************/ 00039 namespace n2l 00040 { 00041 class cGuiCanvas; 00042 class cVfsNodeInterface; 00043 class cDynVar; 00044 00045 class cGuiFill; 00046 class cGuiTextStyle; 00047 00048 class cEventInterface; 00049 00050 class cGuiSEInt; 00051 class cGuiACInt; 00052 00055 class cGuiElement 00056 { 00057 public: 00058 typedef std::list<cAutoPtr<cGuiElement> > tOElementList; 00059 00060 cGuiElement(); 00061 cGuiElement( const tGuiPos &iPos, const tGuiPos &iSize, 00062 const tString &iName = "" ); 00063 virtual ~cGuiElement(); 00064 00065 //-------------------------------------------------------- 00066 // Basic Properties 00067 00068 virtual const tGuiPos &pos() const; 00069 virtual void pos( const tGuiPos &iPos ); 00070 00071 virtual const tGuiPos &size() const; 00072 virtual void size( const tGuiPos &iSize ); 00073 00074 virtual const tGuiPos &bottomRightPadding() const; 00075 00076 virtual void padding( const tGuiPos &iTopLeft, 00077 const tGuiPos &iBottomRight ); 00078 00079 virtual const tGuiPos &topLeftPadding() const; 00080 00081 virtual const tString &name() const; 00082 virtual void name( const tString &iName ); 00083 00084 virtual void renderOrder( const tSint iOrder ); 00085 virtual const tSint &renderOrder() const; 00086 00094 virtual void prop( const tString &iName, const cDynVar &iVal, 00095 const tString &iInnerKey = "" ); 00096 00097 virtual const cDynVar prop( const tString &iName, 00098 const tString &iInnerKey = "" ) const; 00099 00100 //-------------------------------------------------------- 00101 // Element Action Methods 00102 00105 virtual const tActionBindingID bindUserAction( 00106 const tGuiActionType iType, 00107 const cAutoPtr<cGuiACInt> &i_ioAction ); 00108 00111 virtual void unbindUserAction( const tActionBindingID iID ); 00112 00115 virtual void clearUserActions(); 00116 00117 00118 00119 //-------------------------------------------------------- 00120 // System Event handling 00121 00124 virtual void systemEvent( 00125 const cAutoPtr<const cEventInterface> &i_iEvent ); 00126 00127 00133 virtual void systemEventOutside( 00134 const cAutoPtr<const cEventInterface> &i_iEvent ); 00135 00136 00137 //-------------------------------------------------------- 00138 // Focus handling 00139 00142 virtual const tBool focus() const; 00143 00144 00147 virtual void focus( const tBool iFocus ); 00148 00149 00155 virtual const tBool wantsFocus() const; 00156 00157 00158 //-------------------------------------------------------- 00159 // General 00163 virtual void update( const tUint iTimePassed ); 00164 00165 00169 virtual void draw() const; 00170 00171 00175 virtual tOElementList getByType( const type_info &iType ); 00176 00177 00180 virtual tOElementList &getByType( tOElementList &oList, 00181 const type_info &iType ); 00182 00186 virtual const cAutoPtr<cGuiElement> get( const tGuiName &iName ); 00187 00188 00192 virtual const cAutoPtr<cGuiElement> mustGet( const tGuiName &iName ); 00193 00194 00198 virtual const tBool hasChildren() const; 00199 00200 //-------------------------------------------------------- 00201 // Resource Management support 00202 00205 virtual void load( const cVfsNodeInterface &iNode ); 00206 00209 virtual void load( const cDynVar &iDefinition ); 00210 00216 virtual const cAutoPtr<cGuiElement> clone() const = 0; 00217 00218 template <class TSEClass> 00219 static const cAutoPtr<cGuiElement> loadNew( 00220 const cDynVar &iDef ) 00221 { 00222 return new TSEClass( iDef ); 00223 } 00224 00225 //---------------------------------------------------------------- 00226 // Special Effect code below 00227 00230 virtual void addEffect( 00231 const cAutoPtr<cGuiSEInt> &i_ioEffect ); 00232 00235 virtual void clearEffects(); 00236 00239 virtual const tUint numEffects() const; 00240 00241 virtual cGuiCanvas *const canvas(); 00242 00243 virtual void commitSuicide() { mSuicide = true; } 00244 virtual const tBool &suicidal() const { return mSuicide; } 00245 00246 inline const tGuiPos &outerPos() const { return mPos; } 00247 inline const tGuiPos &outerSize() const { return mSize; } 00248 00249 inline const tGuiPos &innerPos() const { return mInnerPos; } 00250 inline const tGuiPos &innerSize() const { return mInnerSize; } 00251 00252 protected: 00253 typedef std::list<cAutoPtr<cGuiSEInt> > 00254 tSpecialEffectContainer; 00255 00256 tGuiPos mPos; 00257 tGuiPos mSize; 00258 tGuiPos mTopLeftPadding; 00259 tGuiPos mBottomRightPadding; 00260 tBool mHasFocus; 00261 tString mName; 00262 tSint mRenderOrder; 00263 00264 cGuiCanvas *mMyCanvas; 00265 00266 tSpecialEffectContainer mEffects; 00267 00268 const tUint nextElementNumber(); 00269 00270 friend class cGuiCanvas; 00271 virtual void canvas( cGuiCanvas *const iCanvas ); 00272 00273 // This method is called when size or position are changed 00274 // or when the parent canvas's resolution mapping changes. 00275 // It is specifically provided for children classes to redefine 00276 // with whatever cache changes need to be made if these values 00277 // change. 00278 // It is good behaviour to call the parent's version of the 00279 // method before any child work is done. 00280 virtual void dimensionChanged(); 00281 00282 // This method is called when focus or name are changed 00283 // Hotspot also calls this method if the over/out/down state 00284 // changes for an item. 00285 // This method is designed specifically for children classes to 00286 // redefine to catch changes in their parent class. 00287 // It is good behaviour to call the parent's version of the 00288 // method before any child work is done. 00289 virtual void stateChanged(); 00290 00291 // This method should be called when an externally selectable 00292 // property changes. It is never called by this class, and 00293 // is provided only as an interface. 00294 virtual void propertyChanged(); 00295 00299 virtual void cloneInto( 00300 const cAutoPtr<cGuiElement> &i_ioElement ) const; 00301 00302 00303 friend class cGuiFill; 00304 friend class cGuiTextStyle; 00309 static void validateAndDecode( cDynVar &oDefinition, 00310 const cVfsNodeInterface &iNode, 00311 const tString &iRequiredHeader ); 00312 00313 00314 //--------------------------------------------------------------- 00315 // Internal Element Action Methods 00318 virtual const tActionBindingID bindAction( 00319 const tGuiActionType iType, 00320 const cAutoPtr<cGuiACInt> &i_ioAction, 00321 const tBool iUser ); 00322 00323 00324 virtual void unbindAction( const tActionBindingID iID, 00325 const tBool iUser ); 00326 00329 virtual void broadcastAction( const tGuiActionType iType, 00330 const tActionData &iData ); 00331 00332 00333 private: 00334 typedef std::map<tActionBindingID, cAutoPtr<cGuiACInt> > 00335 tActionList; 00336 00337 tActionList mActions[ GuiActionType_NumActionTypes ]; 00338 00339 static const tActionBindingID FirstUserActionID; 00340 static const tActionBindingID FirstSystemActionID; 00341 00342 static tUint smNextElementNumber; 00343 00344 tGuiPos mInnerPos; 00345 tGuiPos mInnerSize; 00346 00347 tActionBindingID mNextSystemActionID; 00348 tActionBindingID mNextUserActionID; 00349 00352 tBool mFirstUpdateDone; 00353 tBool mSuicide; 00354 00355 00356 void boundCheckActionType( const tUint &iType ) const; 00357 }; 00358 00359 } // namespace n2l 00360 00361 #endif |