diff --git a/code/nel/include/nel/gui/action_handler.h b/code/nel/include/nel/gui/action_handler.h index b4234335c..d7bda1bda 100644 --- a/code/nel/include/nel/gui/action_handler.h +++ b/code/nel/include/nel/gui/action_handler.h @@ -24,113 +24,119 @@ #include "nel/misc/xml_auto_ptr.h" #include -/** - * interface for action handlers - * \author Nicolas Brigand - * \author Nevrax France - * \date 2002 - */ - -class CCtrlBase; - -class IActionHandler +namespace NLGUI { -public: - // Execute the answer to the action - // Params has the following form : paramName=theParam|paramName2=theParam2|... - virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */) { } - virtual ~IActionHandler() {} - - static std::string getParam (const std::string &Params, const std::string &ParamName); - - static void getAllParams (const std::string &Params, std::vector< std::pair > &AllParams); -}; + class CCtrlBase; -/** - interface for action handlers factory - no release in this factory : a handler must be destroyed by the control that created it - */ -class CAHManager -{ -public: - typedef std::map< std::string, IActionHandler* > TFactoryMap; - typedef std::map< IActionHandler*, std::string > TNameMap; - - static CAHManager* getInstance() - { - if (_GlobalInstance == NULL) - _GlobalInstance = new CAHManager; - return _GlobalInstance; - } - - /// return pointer to action handler or null if it doesn't exist - IActionHandler *getActionHandler(const std::string &name) const - { - TFactoryMap::const_iterator it = FactoryMap.find(name); - return it != FactoryMap.end() ? it->second : NULL; - } - - /// Return the name of the action handler given its pointer - const std::string &getActionHandlerName(IActionHandler *pAH) const - { - TNameMap::const_iterator it = NameMap.find(pAH); - return it != NameMap.end() ? it->second : EmptyName; - } - - /// map of action handler factories - TFactoryMap FactoryMap; - TNameMap NameMap; - std::string EmptyName; - - /// return the Action Handler 'name'. if name is of form 'ah:params', then params are filled (NB: else not changed) - IActionHandler *getAH(const std::string &name, std::string ¶ms); - IActionHandler *getAH(const std::string &name, class CStringShared ¶ms); - - /** common method to parse Action Handler from a xml node - * \param ahId eg: "onclick_l" - * \param paramId eg: "params_l". - * \param params returned parameters. - * NB: if paramId is NULL, empty or does not exist in the xmlNode, then the optional param in ahId (eg: "show:phrase_book") - * is taken - * NB: if none of the optional param in ahId, or the specified param are filled/found, then params is not changed + /** + * interface for action handlers + * \author Nicolas Brigand + * \author Nevrax France + * \date 2002 */ - void parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, std::string ¶ms); - void parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, class CStringShared ¶ms); - - /// Get the AH name from ptr - const std::string &getAHName(IActionHandler *pAH){ return getActionHandlerName(pAH); } + class IActionHandler + { + public: + // Execute the answer to the action + // Params has the following form : paramName=theParam|paramName2=theParam2|... + virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */) { } - void runActionHandler(const std::string &AHName, CCtrlBase *pCaller, const std::string &Params=std::string("") ); - void runActionHandler(IActionHandler *ah, CCtrlBase *pCaller, const std::string &Params=std::string("") ); + virtual ~IActionHandler() {} -private: - CAHManager(){} - static CAHManager *_GlobalInstance; + static std::string getParam (const std::string &Params, const std::string &ParamName); -}; + static void getAllParams (const std::string &Params, std::vector< std::pair > &AllParams); + }; -/// Ah name must all be lower case -#define REGISTER_ACTION_HANDLER(handler ,name) \ -class handler##Factory : public handler \ -{ \ -public: \ - handler##Factory () \ - { \ - nlassert(name!=NULL); \ - const char *c= name; \ - while(*c!='\0') \ - { \ - nlassert(islower(*c) || !isalpha(*c)); \ - c++; \ - } \ - CAHManager *pAHFM = CAHManager::getInstance(); \ - pAHFM->FactoryMap.insert(CAHManager::TFactoryMap::value_type(name,this)); \ - pAHFM->NameMap.insert(CAHManager::TNameMap::value_type(this,name)); \ - }; \ -}; \ - handler##Factory handler##FactoryInstance ; \ - \ + + /** + interface for action handlers factory + no release in this factory : a handler must be destroyed by the control that created it + */ + class CAHManager + { + public: + typedef std::map< std::string, IActionHandler* > TFactoryMap; + typedef std::map< IActionHandler*, std::string > TNameMap; + + static CAHManager* getInstance() + { + if (_GlobalInstance == NULL) + _GlobalInstance = new CAHManager; + return _GlobalInstance; + } + + /// return pointer to action handler or null if it doesn't exist + IActionHandler *getActionHandler(const std::string &name) const + { + TFactoryMap::const_iterator it = FactoryMap.find(name); + return it != FactoryMap.end() ? it->second : NULL; + } + + /// Return the name of the action handler given its pointer + const std::string &getActionHandlerName(IActionHandler *pAH) const + { + TNameMap::const_iterator it = NameMap.find(pAH); + return it != NameMap.end() ? it->second : EmptyName; + } + + /// map of action handler factories + TFactoryMap FactoryMap; + TNameMap NameMap; + std::string EmptyName; + + /// return the Action Handler 'name'. if name is of form 'ah:params', then params are filled (NB: else not changed) + IActionHandler *getAH(const std::string &name, std::string ¶ms); + IActionHandler *getAH(const std::string &name, class CStringShared ¶ms); + + /** common method to parse Action Handler from a xml node + * \param ahId eg: "onclick_l" + * \param paramId eg: "params_l". + * \param params returned parameters. + * NB: if paramId is NULL, empty or does not exist in the xmlNode, then the optional param in ahId (eg: "show:phrase_book") + * is taken + * NB: if none of the optional param in ahId, or the specified param are filled/found, then params is not changed + */ + void parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, std::string ¶ms); + void parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, class CStringShared ¶ms); + + /// Get the AH name from ptr + const std::string &getAHName(IActionHandler *pAH){ return getActionHandlerName(pAH); } + + void runActionHandler(const std::string &AHName, CCtrlBase *pCaller, const std::string &Params=std::string("") ); + void runActionHandler(IActionHandler *ah, CCtrlBase *pCaller, const std::string &Params=std::string("") ); + + private: + CAHManager(){} + static CAHManager *_GlobalInstance; + + }; + + /// Ah name must all be lower case + #define REGISTER_ACTION_HANDLER(handler ,name) \ + class handler##Factory : public handler \ + { \ + public: \ + handler##Factory () \ + { \ + nlassert(name!=NULL); \ + const char *c= name; \ + while(*c!='\0') \ + { \ + nlassert(islower(*c) || !isalpha(*c)); \ + c++; \ + } \ + CAHManager *pAHFM = CAHManager::getInstance(); \ + pAHFM->FactoryMap.insert(CAHManager::TFactoryMap::value_type(name,this)); \ + pAHFM->NameMap.insert(CAHManager::TNameMap::value_type(this,name)); \ + }; \ + }; \ + handler##Factory handler##FactoryInstance ; \ + \ + + +} #endif //NL_ACTION_HANDLER_H diff --git a/code/nel/include/nel/gui/ctrl_base.h b/code/nel/include/nel/gui/ctrl_base.h index 44ad924ec..b22148b88 100644 --- a/code/nel/include/nel/gui/ctrl_base.h +++ b/code/nel/include/nel/gui/ctrl_base.h @@ -23,141 +23,144 @@ #include "nel/gui/view_base.h" #include "nel/gui/event_descriptor.h" -class CCtrlBase : public CViewBase +namespace NLGUI { -public: - - // Tooltip mode - enum TToolTipParentType + class CCtrlBase : public CViewBase { - TTMouse= 0, // The tooltip is displayed relatively to the mouse when it appears - TTCtrl= 1, // The tooltip is displayed relatively to the ctrl it comes from when it apeears - TTWindow= 2, // The tooltip is displayed relatively to the window where the control lies. - TTSpecialWindow= 3, // The tooltip is displayed relatively to a special user window + public: - NumToolTipParentRef + // Tooltip mode + enum TToolTipParentType + { + TTMouse= 0, // The tooltip is displayed relatively to the mouse when it appears + TTCtrl= 1, // The tooltip is displayed relatively to the ctrl it comes from when it apeears + TTWindow= 2, // The tooltip is displayed relatively to the window where the control lies. + TTSpecialWindow= 3, // The tooltip is displayed relatively to a special user window + + NumToolTipParentRef + }; + + public: + + /// Constructor + CCtrlBase(const TCtorParam ¶m) : CViewBase(param) + { + _ToolTipInstant= true; + _ToolTipParent= TTCtrl; + // see interface.txt for meaning of auto + _ToolTipParentPosRef= Hotspot_TTAuto; + _ToolTipPosRef= Hotspot_TTAuto; + } + + /// Destructor + virtual ~CCtrlBase(); + + // special parse + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + + + /// Handle all events (implemented by derived classes) (return true to signal event handled) + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + + virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; } + + /// Debug + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + + + /// Get the ContextHelp for this control. Default is to return _ContextHelp + virtual void getContextHelp(ucstring &help) const {help= _ContextHelp;} + /// Get the ContextHelp for this control, with tooltip specific code. Default behaviour is identical to getContextHelp. + virtual void getContextHelpToolTip(ucstring &help) const { getContextHelp(help); } + // Get the name of the context help window. Default to "context_help" + virtual std::string getContextHelpWindowName() const; + /// Get the ContextHelp ActionHandler. If "", noop + const std::string &getContextHelpActionHandler() const {return _OnContextHelp;} + /// Get the ContextHelp ActionHandler Params + const std::string &getContextHelpAHParams() const {return _OnContextHelpParams;} + /// true if both are empty + bool emptyContextHelp() const; + // Should return true if the context help should be displayed instantly + bool wantInstantContextHelp() const { return _ToolTipInstant; } + /// Set true if ToolTip should be displayed instantly + void setInstantContextHelp(bool instant) { _ToolTipInstant = instant;} + + /** If ctrl has a non rectangle shape, perform further test to know + * if control should be taken in account for context help + */ + virtual bool preciseHitTest(sint32 /* x */, sint32 /* y */) const { return true; } + + + /// return the type of anchor for the tooltip of this control + TToolTipParentType getToolTipParent() const { return _ToolTipParent;} + const std::string &getToolTipSpecialParent() const {return _ToolTipSpecialParent.toString();} + /// Set the type of anchor for the tooltip of this control + void setToolTipParent(TToolTipParentType type) { _ToolTipParent = type; } + void setToolTipSpecialParent(const std::string &parent) { _ToolTipSpecialParent = parent; } + /// Get the ToolTip pos references (parent relevant only if getToolTipParent()!=TTMouse) + THotSpot getToolTipParentPosRef() const { return _ToolTipParentPosRef;} + THotSpot getToolTipPosRef() const { return _ToolTipPosRef;} + THotSpot getToolTipParentPosRefAlt() const { return _ToolTipParentPosRefAlt;} + THotSpot getToolTipPosRefAlt() const { return _ToolTipPosRefAlt;} + /// Set the ToolTip pos references (parent relevant only if getToolTipParent()!=TTMouse) + void setToolTipParentPosRef(THotSpot pos) { _ToolTipParentPosRef = pos;} + void setToolTipPosRef(THotSpot pos) { _ToolTipPosRef = pos;} + + /// replace the default contextHelp + ucstring getDefaultContextHelp() const {return _ContextHelp;} + void setDefaultContextHelp(const ucstring &help) {_ContextHelp= help;} + void setOnContextHelp(const std::string &help) {_OnContextHelp= help;} + void setOnContextHelpAHParams(const std::string &p) {_OnContextHelpParams= p;} + + + + // called when this element or a son has been captured + virtual void elementCaptured(CCtrlBase * /* capturedElement */) {} + + virtual bool isCtrl() const { return true; } + + // Made for CtrlResizer to take the precedence over son controls. + virtual uint getDeltaDepth() const { return 0; } + + // true if this ctrl is capturable (true by default, false for tooltip) + virtual bool isCapturable() const {return true;} + + // from CInterfaceElement + virtual void visit(CInterfaceElementVisitor *visitor); + + /** test if virtual desktop change is possible while this element is captured by the mouse + * Useful for resizers + */ + virtual bool canChangeVirtualDesktop() const { return true; } + + // called when keyboard capture has been lost + virtual void onKeyboardCaptureLost() {} + + REFLECT_EXPORT_START(CCtrlBase, CViewBase) + REFLECT_UCSTRING("tooltip", getDefaultContextHelp, setDefaultContextHelp); + REFLECT_EXPORT_END + + // special for mouse over : return true and fill the name of the cursor to display + virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; } + + virtual void serial(NLMISC::IStream &f); + protected: + // This is the ContextHelp filled by default in parse() + ucstring _ContextHelp; + CStringShared _OnContextHelp; + CStringShared _OnContextHelpParams; + CStringShared _ToolTipSpecialParent; + TToolTipParentType _ToolTipParent; + bool _ToolTipInstant : 1; + THotSpot _ToolTipParentPosRef : 6; + THotSpot _ToolTipPosRef : 6; + THotSpot _ToolTipParentPosRefAlt : 6; + THotSpot _ToolTipPosRefAlt : 6; + protected: + void convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS); }; -public: - - /// Constructor - CCtrlBase(const TCtorParam ¶m) : CViewBase(param) - { - _ToolTipInstant= true; - _ToolTipParent= TTCtrl; - // see interface.txt for meaning of auto - _ToolTipParentPosRef= Hotspot_TTAuto; - _ToolTipPosRef= Hotspot_TTAuto; - } - - /// Destructor - virtual ~CCtrlBase(); - - // special parse - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - - - /// Handle all events (implemented by derived classes) (return true to signal event handled) - virtual bool handleEvent (const NLGUI::CEventDescriptor &event); - - virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; } - - /// Debug - virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } - - - /// Get the ContextHelp for this control. Default is to return _ContextHelp - virtual void getContextHelp(ucstring &help) const {help= _ContextHelp;} - /// Get the ContextHelp for this control, with tooltip specific code. Default behaviour is identical to getContextHelp. - virtual void getContextHelpToolTip(ucstring &help) const { getContextHelp(help); } - // Get the name of the context help window. Default to "context_help" - virtual std::string getContextHelpWindowName() const; - /// Get the ContextHelp ActionHandler. If "", noop - const std::string &getContextHelpActionHandler() const {return _OnContextHelp;} - /// Get the ContextHelp ActionHandler Params - const std::string &getContextHelpAHParams() const {return _OnContextHelpParams;} - /// true if both are empty - bool emptyContextHelp() const; - // Should return true if the context help should be displayed instantly - bool wantInstantContextHelp() const { return _ToolTipInstant; } - /// Set true if ToolTip should be displayed instantly - void setInstantContextHelp(bool instant) { _ToolTipInstant = instant;} - - /** If ctrl has a non rectangle shape, perform further test to know - * if control should be taken in account for context help - */ - virtual bool preciseHitTest(sint32 /* x */, sint32 /* y */) const { return true; } - - - /// return the type of anchor for the tooltip of this control - TToolTipParentType getToolTipParent() const { return _ToolTipParent;} - const std::string &getToolTipSpecialParent() const {return _ToolTipSpecialParent.toString();} - /// Set the type of anchor for the tooltip of this control - void setToolTipParent(TToolTipParentType type) { _ToolTipParent = type; } - void setToolTipSpecialParent(const std::string &parent) { _ToolTipSpecialParent = parent; } - /// Get the ToolTip pos references (parent relevant only if getToolTipParent()!=TTMouse) - THotSpot getToolTipParentPosRef() const { return _ToolTipParentPosRef;} - THotSpot getToolTipPosRef() const { return _ToolTipPosRef;} - THotSpot getToolTipParentPosRefAlt() const { return _ToolTipParentPosRefAlt;} - THotSpot getToolTipPosRefAlt() const { return _ToolTipPosRefAlt;} - /// Set the ToolTip pos references (parent relevant only if getToolTipParent()!=TTMouse) - void setToolTipParentPosRef(THotSpot pos) { _ToolTipParentPosRef = pos;} - void setToolTipPosRef(THotSpot pos) { _ToolTipPosRef = pos;} - - /// replace the default contextHelp - ucstring getDefaultContextHelp() const {return _ContextHelp;} - void setDefaultContextHelp(const ucstring &help) {_ContextHelp= help;} - void setOnContextHelp(const std::string &help) {_OnContextHelp= help;} - void setOnContextHelpAHParams(const std::string &p) {_OnContextHelpParams= p;} - - - - // called when this element or a son has been captured - virtual void elementCaptured(CCtrlBase * /* capturedElement */) {} - - virtual bool isCtrl() const { return true; } - - // Made for CtrlResizer to take the precedence over son controls. - virtual uint getDeltaDepth() const { return 0; } - - // true if this ctrl is capturable (true by default, false for tooltip) - virtual bool isCapturable() const {return true;} - - // from CInterfaceElement - virtual void visit(CInterfaceElementVisitor *visitor); - - /** test if virtual desktop change is possible while this element is captured by the mouse - * Useful for resizers - */ - virtual bool canChangeVirtualDesktop() const { return true; } - - // called when keyboard capture has been lost - virtual void onKeyboardCaptureLost() {} - - REFLECT_EXPORT_START(CCtrlBase, CViewBase) - REFLECT_UCSTRING("tooltip", getDefaultContextHelp, setDefaultContextHelp); - REFLECT_EXPORT_END - - // special for mouse over : return true and fill the name of the cursor to display - virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; } - - virtual void serial(NLMISC::IStream &f); -protected: - // This is the ContextHelp filled by default in parse() - ucstring _ContextHelp; - CStringShared _OnContextHelp; - CStringShared _OnContextHelpParams; - CStringShared _ToolTipSpecialParent; - TToolTipParentType _ToolTipParent; - bool _ToolTipInstant : 1; - THotSpot _ToolTipParentPosRef : 6; - THotSpot _ToolTipPosRef : 6; - THotSpot _ToolTipParentPosRefAlt : 6; - THotSpot _ToolTipPosRefAlt : 6; -protected: - void convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS); -}; - +} #endif // RZ_VIEW_BASE_H diff --git a/code/nel/include/nel/gui/ctrl_draggable.h b/code/nel/include/nel/gui/ctrl_draggable.h index 256ce345b..de2432137 100644 --- a/code/nel/include/nel/gui/ctrl_draggable.h +++ b/code/nel/include/nel/gui/ctrl_draggable.h @@ -1,42 +1,64 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + #ifndef CTRL_DRAGGABLE_H #define CTRL_DRAGGABLE_H #include "nel/gui/ctrl_base.h" -class CCtrlDraggable : public CCtrlBase +namespace NLGUI { -public: - DECLARE_UI_CLASS( CCtrlDraggable ) - CCtrlDraggable( const TCtorParam ¶m ); - virtual ~CCtrlDraggable(){}; - - static CCtrlDraggable *getDraggedSheet(){ return _LastDraggedSheet; } - bool isDragged() const{ return dragged; } - void setDragged( bool dragged ){ this->dragged = dragged; } - bool isDraggable() const{ return draggable; } - void setDraggable( bool draggable ){ this->draggable = draggable; } - - void abortDragging() + class CCtrlDraggable : public CCtrlBase { - dragged = false; - _LastDraggedSheet = NULL; - } + public: + DECLARE_UI_CLASS( CCtrlDraggable ) - // Necessary because of reflection, no other purpose - void draw(){} + CCtrlDraggable( const TCtorParam ¶m ); + virtual ~CCtrlDraggable(){}; - REFLECT_EXPORT_START(CCtrlDraggable, CCtrlBase) - REFLECT_BOOL("dragable", isDraggable, setDraggable); - REFLECT_EXPORT_END + static CCtrlDraggable *getDraggedSheet(){ return _LastDraggedSheet; } + bool isDragged() const{ return dragged; } + void setDragged( bool dragged ){ this->dragged = dragged; } + bool isDraggable() const{ return draggable; } + void setDraggable( bool draggable ){ this->draggable = draggable; } + + void abortDragging() + { + dragged = false; + _LastDraggedSheet = NULL; + } -protected: - static void setDraggedSheet( CCtrlDraggable *draggable ){ _LastDraggedSheet = draggable; } + // Necessary because of reflection, no other purpose + void draw(){} -private: - static CCtrlDraggable *_LastDraggedSheet; - bool dragged; - bool draggable; -}; + REFLECT_EXPORT_START(CCtrlDraggable, CCtrlBase) + REFLECT_BOOL("dragable", isDraggable, setDraggable); + REFLECT_EXPORT_END + + protected: + static void setDraggedSheet( CCtrlDraggable *draggable ){ _LastDraggedSheet = draggable; } + + private: + static CCtrlDraggable *_LastDraggedSheet; + bool dragged; + bool draggable; + }; + +} #endif diff --git a/code/nel/include/nel/gui/ctrl_scroll_base.h b/code/nel/include/nel/gui/ctrl_scroll_base.h index 16eee9c59..8e3d6de2f 100644 --- a/code/nel/include/nel/gui/ctrl_scroll_base.h +++ b/code/nel/include/nel/gui/ctrl_scroll_base.h @@ -19,37 +19,42 @@ #include "nel/gui/ctrl_base.h" -class CInterfaceGroup; - -class CCtrlScrollBase : public CCtrlBase +namespace NLGUI { -public: - DECLARE_UI_CLASS( CCtrlScrollBase ) - CCtrlScrollBase( const TCtorParam ¶m ); - virtual ~CCtrlScrollBase(); - - virtual void setTarget( CInterfaceGroup *pIG ); - CInterfaceGroup* getTarget(){ return _Target; } - virtual sint32 moveTrackX( sint32 dx ); - virtual sint32 moveTrackY( sint32 dy ); + class CInterfaceGroup; - /** Move the Target Ofs with a Delta, and recompute TrackPos from this Ofs. - * Useful for finer controled group scrolling when the list is very big (with mouseWheel or scroll buttons) - */ - virtual void moveTargetX( sint32 dx ); - virtual void moveTargetY( sint32 dy ); + class CCtrlScrollBase : public CCtrlBase + { + public: + DECLARE_UI_CLASS( CCtrlScrollBase ) + + CCtrlScrollBase( const TCtorParam ¶m ); + virtual ~CCtrlScrollBase(); + + virtual void setTarget( CInterfaceGroup *pIG ); + CInterfaceGroup* getTarget(){ return _Target; } + virtual sint32 moveTrackX( sint32 dx ); + virtual sint32 moveTrackY( sint32 dy ); + + /** Move the Target Ofs with a Delta, and recompute TrackPos from this Ofs. + * Useful for finer controled group scrolling when the list is very big (with mouseWheel or scroll buttons) + */ + virtual void moveTargetX( sint32 dx ); + virtual void moveTargetY( sint32 dy ); - // Necessary because of reflection, no other purpose - void draw(){} + // Necessary because of reflection, no other purpose + void draw(){} -protected: - CInterfaceGroup *_Target; // If NULL the scroller is a value scroller + protected: + CInterfaceGroup *_Target; // If NULL the scroller is a value scroller -private: + private: -}; + }; + +} #endif diff --git a/code/nel/include/nel/gui/group_container_base.h b/code/nel/include/nel/gui/group_container_base.h index b3ed6e501..9122f1027 100644 --- a/code/nel/include/nel/gui/group_container_base.h +++ b/code/nel/include/nel/gui/group_container_base.h @@ -20,75 +20,82 @@ #include "nel/gui/interface_group.h" - -class CGroupContainerBase : public CInterfaceGroup +namespace NLGUI { -public: - DECLARE_UI_CLASS( CGroupContainerBase ) - CGroupContainerBase( const TCtorParam ¶m ); - virtual ~CGroupContainerBase(); + class CGroupContainerBase : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CGroupContainerBase ) - virtual void removeAllContainers(); - virtual void setLocked( bool locked ); - bool isLocked() const { return _Locked; } + CGroupContainerBase( const TCtorParam ¶m ); + virtual ~CGroupContainerBase(); - uint8 getContainerAlpha() const { return _ContainerAlpha; } - uint8 getContentAlpha() const { return _ContentAlpha; } - uint8 getRolloverAlphaContent() const { return _RolloverAlphaContent; } - uint8 getRolloverAlphaContainer() const { return _RolloverAlphaContainer; } + virtual void removeAllContainers(); + virtual void setLocked( bool locked ); + bool isLocked() const { return _Locked; } - void setContainerAlpha( uint8 alpha ); - void setContentAlpha( uint8 alpha ); - void setRolloverAlphaContent( uint8 alpha ); - void setRolloverAlphaContainer( uint8 alpha ); + uint8 getContainerAlpha() const { return _ContainerAlpha; } + uint8 getContentAlpha() const { return _ContentAlpha; } + uint8 getRolloverAlphaContent() const { return _RolloverAlphaContent; } + uint8 getRolloverAlphaContainer() const { return _RolloverAlphaContainer; } - // for export - sint32 getContainerAlphaAsSInt32() const{ return (sint32)_ContainerAlpha; } - sint32 getContentAlphaAsSInt32() const{ return (sint32)_ContentAlpha; } - sint32 getRolloverAlphaContentAsSInt32() const{ return (sint32)_RolloverAlphaContent; } - sint32 getRolloverAlphaContainerAsSInt32() const{ return (sint32)_RolloverAlphaContainer; } + void setContainerAlpha( uint8 alpha ); + void setContentAlpha( uint8 alpha ); + void setRolloverAlphaContent( uint8 alpha ); + void setRolloverAlphaContainer( uint8 alpha ); - // sin32 versions for export - void setContainerAlpha( sint32 alpha ){ setContainerAlpha((uint8) alpha); } - void setContentAlpha( sint32 alpha ){ setContentAlpha((uint8) alpha); } - void setRolloverAlphaContent( sint32 alpha ){ setRolloverAlphaContent((uint8) alpha); } - void setRolloverAlphaContainer( sint32 alpha ){ setRolloverAlphaContainer((uint8) alpha); } + // for export + sint32 getContainerAlphaAsSInt32() const{ return (sint32)_ContainerAlpha; } + sint32 getContentAlphaAsSInt32() const{ return (sint32)_ContentAlpha; } + sint32 getRolloverAlphaContentAsSInt32() const{ return (sint32)_RolloverAlphaContent; } + sint32 getRolloverAlphaContainerAsSInt32() const{ return (sint32)_RolloverAlphaContainer; } - void setUseGlobalAlpha( bool use ); - bool isUsingGlobalAlpha() const{ return _UseGlobalAlpha; } + // sin32 versions for export + void setContainerAlpha( sint32 alpha ){ setContainerAlpha((uint8) alpha); } + void setContentAlpha( sint32 alpha ){ setContentAlpha((uint8) alpha); } + void setRolloverAlphaContent( sint32 alpha ){ setRolloverAlphaContent((uint8) alpha); } + void setRolloverAlphaContainer( sint32 alpha ){ setRolloverAlphaContainer((uint8) alpha); } - std::string getAHOnAlphaSettingsChanged() const{ return CAHManager::getInstance()->getAHName( _AHOnAlphaSettingsChanged ); } - std::string getAHOnAlphaSettingsChangedParams() const{ return _AHOnAlphaSettingsChangedParams; } + void setUseGlobalAlpha( bool use ); + bool isUsingGlobalAlpha() const{ return _UseGlobalAlpha; } - void setAHOnAlphaSettingsChanged( const std::string &h ){ _AHOnAlphaSettingsChanged = CAHManager::getInstance()->getAH( h, _AHOnAlphaSettingsChangedParams ); } - void setAHOnAlphaSettingsChangedParams( const std::string &p ){ _AHOnAlphaSettingsChangedParams = p; } + std::string getAHOnAlphaSettingsChanged() const{ return CAHManager::getInstance()->getAHName( _AHOnAlphaSettingsChanged ); } + std::string getAHOnAlphaSettingsChangedParams() const{ return _AHOnAlphaSettingsChangedParams; } - REFLECT_EXPORT_START( CGroupContainerBase, CInterfaceGroup ) - REFLECT_SINT32("container_alpha", getContainerAlphaAsSInt32, setContainerAlpha); - REFLECT_SINT32("content_alpha", getContentAlphaAsSInt32, setContentAlpha); - REFLECT_SINT32("rollover_content_alpha", getRolloverAlphaContentAsSInt32, setRolloverAlphaContent); - REFLECT_SINT32("rollover_container_alpha", getRolloverAlphaContainerAsSInt32, setRolloverAlphaContainer); - REFLECT_BOOL("use_global_alpha_settings", isUsingGlobalAlpha, setUseGlobalAlpha); - REFLECT_STRING("on_alpha_settings_changed", getAHOnAlphaSettingsChanged, setAHOnAlphaSettingsChanged); - REFLECT_STRING("on_alpha_settings_changed_aparams", getAHOnAlphaSettingsChangedParams, setAHOnAlphaSettingsChangedParams); - REFLECT_EXPORT_END + void setAHOnAlphaSettingsChanged( const std::string &h ){ _AHOnAlphaSettingsChanged = CAHManager::getInstance()->getAH( h, _AHOnAlphaSettingsChangedParams ); } + void setAHOnAlphaSettingsChangedParams( const std::string &p ){ _AHOnAlphaSettingsChangedParams = p; } -protected: - void triggerAlphaSettingsChangedAH(); + REFLECT_EXPORT_START( CGroupContainerBase, CInterfaceGroup ) + REFLECT_SINT32("container_alpha", getContainerAlphaAsSInt32, setContainerAlpha); + REFLECT_SINT32("content_alpha", getContentAlphaAsSInt32, setContentAlpha); + REFLECT_SINT32("rollover_content_alpha", getRolloverAlphaContentAsSInt32, setRolloverAlphaContent); + REFLECT_SINT32("rollover_container_alpha", getRolloverAlphaContainerAsSInt32, setRolloverAlphaContainer); + REFLECT_BOOL("use_global_alpha_settings", isUsingGlobalAlpha, setUseGlobalAlpha); + REFLECT_STRING("on_alpha_settings_changed", getAHOnAlphaSettingsChanged, setAHOnAlphaSettingsChanged); + REFLECT_STRING("on_alpha_settings_changed_aparams", getAHOnAlphaSettingsChangedParams, setAHOnAlphaSettingsChangedParams); + REFLECT_EXPORT_END - uint8 _ContainerAlpha; - uint8 _ContentAlpha; - uint8 _RolloverAlphaContainer; // Alpha for the window when mouse not over it - uint8 _RolloverAlphaContent; // Alpha for the content when mouse not over it - bool _Locked : 1; // Is the container locked (ie override movable, openable ...) - bool _UseGlobalAlpha : 1; + protected: + void triggerAlphaSettingsChangedAH(); - IActionHandler *_AHOnAlphaSettingsChanged; - CStringShared _AHOnAlphaSettingsChangedParams; + uint8 _ContainerAlpha; + uint8 _ContentAlpha; + uint8 _RolloverAlphaContainer; // Alpha for the window when mouse not over it + uint8 _RolloverAlphaContent; // Alpha for the content when mouse not over it + bool _Locked : 1; // Is the container locked (ie override movable, openable ...) + bool _UseGlobalAlpha : 1; -private: + IActionHandler *_AHOnAlphaSettingsChanged; + CStringShared _AHOnAlphaSettingsChangedParams; + + private: + + }; + + + +} -}; #endif diff --git a/code/nel/include/nel/gui/group_editbox_base.h b/code/nel/include/nel/gui/group_editbox_base.h index 3f77fa8ba..fa7b6e236 100644 --- a/code/nel/include/nel/gui/group_editbox_base.h +++ b/code/nel/include/nel/gui/group_editbox_base.h @@ -20,45 +20,50 @@ #include "nel/gui/interface_group.h" -class CGroupEditBoxBase : public CInterfaceGroup +namespace NLGUI { -public: - DECLARE_UI_CLASS( CGroupEditBoxBase ) - CGroupEditBoxBase( const TCtorParam ¶m ); - ~CGroupEditBoxBase(); + class CGroupEditBoxBase : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CGroupEditBoxBase ) - // True if the editBox can recover the focus on enter. if not, it does not erase OldCapturedKeyboard when loose focus - bool getRecoverFocusOnEnter() const{ return _RecoverFocusOnEnter; } - void setRecoverFocusOnEnter( bool state ){ _RecoverFocusOnEnter = state; } + CGroupEditBoxBase( const TCtorParam ¶m ); + ~CGroupEditBoxBase(); - std::string getAHOnFocus(){ return _AHOnFocus; } - std::string getAHOnFocusParams(){ return _AHOnFocusParams; } + // True if the editBox can recover the focus on enter. if not, it does not erase OldCapturedKeyboard when loose focus + bool getRecoverFocusOnEnter() const{ return _RecoverFocusOnEnter; } + void setRecoverFocusOnEnter( bool state ){ _RecoverFocusOnEnter = state; } - // disable any current selection - static void disableSelection(){ _CurrSelection = NULL; } + std::string getAHOnFocus(){ return _AHOnFocus; } + std::string getAHOnFocusParams(){ return _AHOnFocusParams; } - // Get / set current selection - static CGroupEditBoxBase *getCurrSelection(){ return _CurrSelection; } - static void setCurrSelection( CGroupEditBoxBase *selection ){ _CurrSelection = selection; } + // disable any current selection + static void disableSelection(){ _CurrSelection = NULL; } - void draw(){} + // Get / set current selection + static CGroupEditBoxBase *getCurrSelection(){ return _CurrSelection; } + static void setCurrSelection( CGroupEditBoxBase *selection ){ _CurrSelection = selection; } - REFLECT_EXPORT_START( CGroupEditBoxBase, CInterfaceGroup ) - REFLECT_BOOL( "enter_recover_focus", getRecoverFocusOnEnter, setRecoverFocusOnEnter ); - REFLECT_EXPORT_END + void draw(){} -protected: - bool _RecoverFocusOnEnter : 1; + REFLECT_EXPORT_START( CGroupEditBoxBase, CInterfaceGroup ) + REFLECT_BOOL( "enter_recover_focus", getRecoverFocusOnEnter, setRecoverFocusOnEnter ); + REFLECT_EXPORT_END - std::string _AHOnFocus; - std::string _AHOnFocusParams; + protected: + bool _RecoverFocusOnEnter : 1; - static CGroupEditBoxBase *_CurrSelection; // the edit box for which the selection is currently active, or NULL if there's none + std::string _AHOnFocus; + std::string _AHOnFocusParams; -private: + static CGroupEditBoxBase *_CurrSelection; // the edit box for which the selection is currently active, or NULL if there's none -}; + private: + + }; + +} #endif diff --git a/code/nel/include/nel/gui/group_frame.h b/code/nel/include/nel/gui/group_frame.h index a8a1bca38..220acb5cd 100644 --- a/code/nel/include/nel/gui/group_frame.h +++ b/code/nel/include/nel/gui/group_frame.h @@ -23,83 +23,88 @@ #include "nel/gui/interface_group.h" -// *************************************************************************** -/** A Group with a background and a frame displayed - * \author Lionel Berenguier - * \author Nevrax France - * \date 2002 - */ -class CGroupFrame : public CInterfaceGroup +namespace NLGUI { -public: + - /// Constructor - CGroupFrame(const TCtorParam ¶m); - - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - virtual void draw (); - - void copyOptionFrom(const CGroupFrame &other); - - - void setColorAsString(const std::string & col); - std::string getColorAsString() const; - - REFLECT_EXPORT_START(CGroupFrame, CInterfaceGroup) - REFLECT_STRING ("color", getColorAsString, setColorAsString); - REFLECT_EXPORT_END - - - static void resetDisplayTypes() { _DispTypes.clear(); } - -// ****************** -protected: - - bool _DisplayFrame; - - NLMISC::CRGBA _Color; - - uint8 _DispType; - - // Fields Defined in the XML => must not herit them from extends="" - bool _DisplayFrameDefined : 1; - bool _ColorDefined : 1; - bool _DispTypeDefined : 1; - - // Static stuff - enum + // *************************************************************************** + /** A Group with a background and a frame displayed + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CGroupFrame : public CInterfaceGroup { - TextTL= 0, - TextTM, - TextTR, - TextML, - TextMM, - TextMR, - TextBL, - TextBM, - TextBR - }; + public: - struct SDisplayType - { - std::string Name; - sint32 BorderIds[9]; - uint8 TileBorder[9]; // Dont works for TextTL, TextTR, TextBL, TextBR - sint32 LeftBorder; // enum - sint32 RightBorder; - sint32 TopBorder; - sint32 BottomBorder; + /// Constructor + CGroupFrame(const TCtorParam ¶m); - // ----------------------- - SDisplayType() + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void draw (); + + void copyOptionFrom(const CGroupFrame &other); + + + void setColorAsString(const std::string & col); + std::string getColorAsString() const; + + REFLECT_EXPORT_START(CGroupFrame, CInterfaceGroup) + REFLECT_STRING ("color", getColorAsString, setColorAsString); + REFLECT_EXPORT_END + + + static void resetDisplayTypes() { _DispTypes.clear(); } + + // ****************** + protected: + + bool _DisplayFrame; + + NLMISC::CRGBA _Color; + + uint8 _DispType; + + // Fields Defined in the XML => must not herit them from extends="" + bool _DisplayFrameDefined : 1; + bool _ColorDefined : 1; + bool _DispTypeDefined : 1; + + // Static stuff + enum { - for (uint i = 0; i < 9; ++i) - TileBorder[i] = 0; - } - }; - static std::vector _DispTypes; -}; + TextTL= 0, + TextTM, + TextTR, + TextML, + TextMM, + TextMR, + TextBL, + TextBM, + TextBR + }; + struct SDisplayType + { + std::string Name; + sint32 BorderIds[9]; + uint8 TileBorder[9]; // Dont works for TextTL, TextTR, TextBL, TextBR + sint32 LeftBorder; // enum + sint32 RightBorder; + sint32 TopBorder; + sint32 BottomBorder; + + // ----------------------- + SDisplayType() + { + for (uint i = 0; i < 9; ++i) + TileBorder[i] = 0; + } + }; + static std::vector _DispTypes; + }; + +} #endif // NL_GROUP_FRAME_H diff --git a/code/nel/include/nel/gui/group_modal.h b/code/nel/include/nel/gui/group_modal.h index 9fab37b2a..bf8690cb9 100644 --- a/code/nel/include/nel/gui/group_modal.h +++ b/code/nel/include/nel/gui/group_modal.h @@ -22,48 +22,51 @@ #include "nel/misc/types_nl.h" #include "nel/gui/group_frame.h" - -// *************************************************************************** -/** - * A group with special modal options - * \author Lionel Berenguier - * \author Nevrax France - * \date 2002 - */ -class CGroupModal : public CGroupFrame +namespace NLGUI { -public: - bool SpawnOnMousePos : 1; - bool ExitClickOut : 1; - bool ExitClickL : 1; - bool ExitClickR : 1; - bool ForceInsideScreen : 1; - bool ExitKeyPushed : 1; - sint32 SpawnMouseX, SpawnMouseY; - std::string Category; - std::string OnClickOut; // Launched when clicking out of the window, and BEFORE a new control has been cpatured - std::string OnClickOutParams; - std::string OnPostClickOut; // Launched when clicking out of the window, and AFTER a new control has been captured - std::string OnPostClickOutParams; -public: + // *************************************************************************** + /** + * A group with special modal options + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CGroupModal : public CGroupFrame + { + public: + bool SpawnOnMousePos : 1; + bool ExitClickOut : 1; + bool ExitClickL : 1; + bool ExitClickR : 1; + bool ForceInsideScreen : 1; + bool ExitKeyPushed : 1; + sint32 SpawnMouseX, SpawnMouseY; + std::string Category; - /// Constructor - CGroupModal(const TCtorParam ¶m); + std::string OnClickOut; // Launched when clicking out of the window, and BEFORE a new control has been cpatured + std::string OnClickOutParams; + std::string OnPostClickOut; // Launched when clicking out of the window, and AFTER a new control has been captured + std::string OnPostClickOutParams; + public: - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - virtual void updateCoords (); - void setBaseX(sint32 x) { _MouseDeltaX = x;} - void setBaseY(sint32 y) { _MouseDeltaY = y;} + /// Constructor + CGroupModal(const TCtorParam ¶m); - REFLECT_EXPORT_START(CGroupModal, CGroupFrame) - REFLECT_EXPORT_END + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void updateCoords (); + void setBaseX(sint32 x) { _MouseDeltaX = x;} + void setBaseY(sint32 y) { _MouseDeltaY = y;} -// ****************** -protected: - sint32 _MouseDeltaX, _MouseDeltaY; -}; + REFLECT_EXPORT_START(CGroupModal, CGroupFrame) + REFLECT_EXPORT_END + // ****************** + protected: + sint32 _MouseDeltaX, _MouseDeltaY; + }; + +} #endif // NL_GROUP_MODAL_H diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index fc876fa61..380e81b5b 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -27,570 +27,578 @@ #include "nel/gui/reflect.h" #include "nel/gui/interface_common.h" +class CGroupList; +class CGroupParagraph; + +namespace NLGUI +{ + + class CInterfaceLink; + class CInterfaceElement; + class CInterfaceGroup; + class CViewBase; + class CCtrlBase; + class IActionHandler; + + /** + * A visitor to walk a tree of interface elements and apply a teartment on them. + * + * For each vsited element, visitElement() is called + * If the element is a control, then visitCtrl() is called, and then visitElement() + * If the element is a view, then visitView() is called, and then visitElement() + * If the element is a group, then visitGoup() is called, and then visitElement() + * + * \author Nicolas Vizerie + * \author Nevrax France + * \date 2003 + */ + class CInterfaceElementVisitor + { + public: + virtual void visit(CInterfaceElement * /* elem */) {} + virtual void visitGroup(CInterfaceGroup * /* group */) {} + virtual void visitView(CViewBase * /* view */) {} + virtual void visitCtrl(CCtrlBase * /* ctrl */) {} + }; + + + /** + * class describing a localisable interface element, i.e. : an element with coordinates + * \author Nicolas Brigand + * \author Nevrax France + * \date 2002 + */ + class CInterfaceElement : public CReflectableRefPtrTarget, public NLMISC::IStreamable + { + public: + + + enum EStrech + { + none=0, + width=1, + height=2 + }; + + /// Constructor + CInterfaceElement() + { + _Parent = NULL; + + _XReal = _YReal = _WReal = _HReal = 0; + _X = _Y = _W = _H = 0; + //_Snap = 1; + + _PosRef = Hotspot_BL; + _ParentPosRef = Hotspot_BL; + _ParentPos = NULL; + + _SizeRef = 0; + _SizeDivW = 10; + _SizeDivH = 10; + _ParentSize = NULL; + + _Links = NULL; + _Active= true; + // default to 3 pass + _InvalidCoords= 3; + + _ModulateGlobalColor= true; + _RenderLayer= 0; + + _AvoidResizeParent= false; + } + + // dtor + virtual ~CInterfaceElement(); + + /** Cloning + * Cloning is actually performed using a serial / unserial in a memory stream + * NB Nico : if too slow, should use a CFastStream version instead, that is designedto work in memory only + */ + virtual CInterfaceElement *clone(); + + // help to serialize an action handler + static void serialAH(NLMISC::IStream &f, IActionHandler *&ah); + + + /// Parse the element and initalize it + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + + /// Debug info on memory + virtual uint32 getMemory () { return (uint32)(sizeof(*this)+_Id.size()); } + + /// helper: display a parse error with the id of the lement + void parseError (CInterfaceGroup *parentGroup, const char *reason = NULL); + + /// Accessors : GET + const std::string& getId() const { return _Id; } + std::string getShortId() const; + std::string getIdByValue() const { return _Id; } + + CInterfaceGroup* getParent() const { return _Parent; } + + CInterfaceElement* getParentPos() const { return _ParentPos; } + + CInterfaceElement* getParentSize() const { return _ParentSize; } + + /// Get the master group of this element (recurs call. + CInterfaceElement* getMasterGroup() const; + + // get a possible group container + CInterfaceGroup* getParentContainer(); + + bool getActive() const { return _Active; } + + sint32 getX() const { return _X; } + + sint32 getY() const { return _Y; } + + sint32 getW() const { return (_Active?_W:0); } + sint32 getW(bool bTestActive) const { return (bTestActive?(_Active?_W:0):_W); } + + sint32 getH() const { return (_Active?_H:0); } + sint32 getH(bool bTestActive) const { return (bTestActive?(_Active?_H:0):_H); } + + /** + * Get the max width used by the window. + * + * The view must return the largest width its content can take if it will be resized at maximum. + * Typical use : for a CTextView multiline, it returns the size of the whole string. + * + * This method is used by the container CCGroupTable that need to know this information about its children in its resizing algorithm. + */ + virtual sint32 getMaxUsedW() const { return INT_MAX; }; + + /** + * Get the min width used by the window. + * + * The view must return the smallest width its content can take if it will be resized at minimum. + * Typical use : for a CTextView multiline without word clipping, it returns the size of the largest word. + * + * This method is used by the container CCGroupTable that need to know this information about its children in its resizing algorithm. + */ + virtual sint32 getMinUsedW() const { return 0; }; + + //bool isSnapped() const { return (_Snap>1); } + + //sint32 getSnapping() const { return _Snap; } + + sint32 getXReal() const { return _XReal; } + + sint32 getYReal() const { return _YReal; } + + sint32 getWReal() const { return (_Active?_WReal:0); } + + sint32 getHReal() const { return (_Active?_HReal:0); } + + THotSpot getPosRef () const { return _PosRef; } + + THotSpot getParentPosRef () const { return _ParentPosRef; } + + sint32 getSizeRef() const { return _SizeRef; } // none == 0, w == 1, h == 2, wh == 3 + + void setSizeRef(sint32 value) { _SizeRef = value; } + + /// Accessors : SET + void setId (const std::string &newID) { _Id = newID; } + + inline void setName(const std::string &name) { _Name = name; } + inline const std::string& getName() { return _Name; } + + virtual void setIdRecurse(const std::string &newID); + + void setParent (CInterfaceGroup *pIG) { _Parent = pIG; } + + void setParentPos (CInterfaceElement *pIG) { _ParentPos = pIG; } + + void setParentSize (CInterfaceElement *pIG) { _ParentSize = pIG; } + + virtual void setActive (bool state); + + void setX (sint32 x) { _X = x; } + void setXAndInvalidateCoords (sint32 x) { _X = x; invalidateCoords(); } + + void setY (sint32 y) { _Y = y; } + void setYAndInvalidateCoords (sint32 y) { _Y = y; invalidateCoords(); } + + void setW (sint32 w); + void setWAndInvalidateCoords (sint32 w) { setW(w); invalidateCoords(); } + + void setH (sint32 h); + void setHAndInvalidateCoords (sint32 h) { setH(h); invalidateCoords(); } + + void setPosRef (THotSpot hs) { _PosRef = hs; } + + void setParentPosRef (THotSpot hs) { _ParentPosRef = hs; } + + // Get the coordinate of a corner on screen + void getCorner(sint32 &px, sint32 &py, THotSpot hotSpot); + + /** Test if the given coordinates are inside this element + */ + bool isIn(sint x, sint y) const; + + /** Test if the given box intersect the element + */ + bool isIn(sint x, sint y, uint width, uint height) const; + + /** Test if another interface element intersect this one + */ + bool isIn(const CInterfaceElement &other) const; + + /** + * get the window containing the element + * \return NULL if the element is not on the window, otherwise returns a pointer to the window + */ + CInterfaceGroup* getRootWindow(); + + /** get the element Depth, ie the number of parent he has (0 if _Parent==NULL) + * \warning slow test. don't take into account CCtrlBase::getDeltaDepth() (since method not virtual) + */ + uint getParentDepth() const; + + /** + * true if the element and all its parents are active (recurs up to the root window) + */ + bool isActiveThroughParents() const; + + /** + * move the element (add dx and dy to its coords) + * \param dx : value added to _X + * \param dy : value added to _Y + */ + virtual void move (sint32 dx, sint32 dy); + + //void resizeBR (sint32 sizex, sint32 sizey); + //void stopResizeBR(); + //void startResizeBR(); + + // Some tools + + void relativeSInt64Read (CInterfaceProperty &rIP, const std::string &prop, const char *val, + const std::string &defVal); + void relativeSInt32Read (CInterfaceProperty &rIP, const std::string &prop, const char *val, + const std::string &defVal); + void relativeBoolRead (CInterfaceProperty &rIP, const std::string &prop, const char *val, + const std::string &defVal); + void relativeRGBARead (CInterfaceProperty &rIP, const std::string &prop, const char *val, + const std::string &defVal); + + // Parse tools + static THotSpot convertHotSpot (const char *ptr); // + static void convertHotSpotCouple (const char *ptr, THotSpot &parentPosRef, THotSpot &posRef); + static NLMISC::CRGBA convertColor (const char *ptr); + static bool convertBool (const char *ptr); + static NLMISC::CVector convertVector (const char *ptr); + /** Convert a value that is in the form like width="50" or width="10%" + * if the value is absolute like '50' then 'pixels' is filled, else + * the ratio is remapped to the [0, 1] range and is copied in 'ratio' + */ + static void convertPixelsOrRatio(const char *ptr, sint32 &pixels, float &ratio); + + // add an interface link to that element (kept in a smart ptr) + void addLink(CInterfaceLink *link); + + // remove a link from that element; There's one less reference on the link (which is referenced by a smart ptr) + void removeLink(CInterfaceLink *link); + + /** Update all links for this instance and its sons. + * Derivers should override this to update their sons. + */ + virtual void updateAllLinks(); + + + /** This allow to force opening an element. By default it just activate the element. + * It allow to have different behaviour on more complex containers + */ + virtual void forceOpen() { setActive(true); } + + virtual void enableBlink(uint /* numBlinks */ = 0) {} + virtual void disableBlink() {} + virtual bool getBlink() const { return false; } + + // Options for views to be modulated by interface global color or not. Parsed with "global_color". Default: true + void setModulateGlobalColor(bool state) {_ModulateGlobalColor= state;} + bool getModulateGlobalColor() const {return _ModulateGlobalColor;} + + + void dummySet(sint32 value); + void dummySet(const std::string &value); + + // lua methods + int luaUpdateCoords(CLuaState &ls); + int luaInvalidateCoords(CLuaState &ls); + int luaInvalidateContent(CLuaState &ls); + int luaCenter(CLuaState &ls); + int luaSetPosRef(CLuaState &ls); + int luaSetParentPos(CLuaState &ls); + + // set sizeref as a string, like "wh", "wh5" .... + void setSizeRef(const std::string &sizeref); + std::string getSizeRefAsString() const; + + // export some properties + REFLECT_EXPORT_START(CInterfaceElement, CReflectable) + REFLECT_BOOL ("active", getActive, setActive); + REFLECT_BOOL ("global_color", getModulateGlobalColor, setModulateGlobalColor); + REFLECT_SINT32 ("x", getX, setXAndInvalidateCoords); + REFLECT_SINT32 ("y", getY, setYAndInvalidateCoords); + REFLECT_SINT32 ("w", getW, setWAndInvalidateCoords); + REFLECT_SINT32 ("h", getH, setHAndInvalidateCoords); + REFLECT_SINT32 ("x_real", getXReal, dummySet); + REFLECT_SINT32 ("y_real", getYReal, dummySet); + REFLECT_SINT32 ("w_real", getWReal, dummySet); + REFLECT_SINT32 ("h_real", getHReal, dummySet); + REFLECT_STRING ("id", getIdByValue, dummySet); + REFLECT_STRING ("sizeref", getSizeRefAsString, setSizeRef); + REFLECT_LUA_METHOD("updateCoords", luaUpdateCoords); + REFLECT_LUA_METHOD("invalidateCoords", luaInvalidateCoords); + REFLECT_LUA_METHOD("invalidateContent", luaInvalidateContent); + REFLECT_LUA_METHOD("center", luaCenter); + REFLECT_LUA_METHOD("setPosRef", luaSetPosRef); + REFLECT_LUA_METHOD("setParentPos", luaSetParentPos); + REFLECT_EXPORT_END + + + /* invalidate coords. set numPass==1 if you are SURE that only XReal/YReal need to be updated + * Default 3 is needed for: + * 1: update _W/_H and _WReal/_HReal according to Sons + * 2: update XReal/YReal (eg: according to Scroll offset) + */ + void invalidateCoords(uint8 numPass= 2); + uint8 getInvalidCoords() const {return _InvalidCoords;} + + /* Invalidates the content of the window. This method invalidate the content of the window (for CViewText or CGroupTable). + * It invalidates the content of the parent too. + */ + void invalidateContent(); + + /* This call back is called when the content or the content of a child is been invalidated. + */ + virtual void onInvalidateContent() {} + + // called by interfaceManager for master window only + void resetInvalidCoords(); + + /// Update the elements coords convert x,y,w,h (parentpos coord) to xreal,yreal,wreal,hreal (BL coord) + virtual void updateCoords(); + /// Called each frame before draw to possibly invalidateCoords(). + virtual void checkCoords(); + + /// Test if this element is son of the given element + bool isSonOf(const CInterfaceElement *other) const; + + /// Called after first frame initialised + virtual void launch () {} + + void setRenderLayer(sint8 rl) {_RenderLayer= rl;} + sint8 getRenderLayer() const { return _RenderLayer; } + + void copyOptionFrom(const CInterfaceElement &other); + + // center the element in middle of screen + void center(); + + // for debug only: draw wired quad to see where groups and hotspots are + enum TRenderWired + { + RenderView, + RenderCtrl, + RenderGroup + }; + // if uiFilter is not empty, draw a quad only if the element id match + virtual void renderWiredQuads(TRenderWired type, const std::string &uiFilter); + + void drawHotSpot(THotSpot hs, NLMISC::CRGBA col); + + // Returns 'true' if that element can be downcasted to a view + virtual bool isView() const { return false; } + + // Returns 'true' if that element can be downcasted to a ctrl + virtual bool isCtrl() const { return false; } + + // Returns 'true' if that element can be downcasted to an interface group + virtual bool isGroup() const { return false; } + + + /** This is called before the config loading begins. This is the place to restore default state for config info. + */ + virtual void onLoadConfig() {} + /** Tells whether that element wants to save info in a config stream. If this returns true, then serialConfig + * is called. + */ + virtual bool wantSerialConfig() const { return false; } + // Serial config info about that element. This is called only if wantSerialConfig() returns true + virtual void serialConfig(NLMISC::IStream &f); + + // visit the node of the ui tree + virtual void visit(CInterfaceElementVisitor *visitor); + + /** When user is quitting the interface, this is called. Then the interface config is saved + * This is where the element get the opportunity to do some cleanup. + */ + virtual void onQuit() {} + + /// Whent an element is added to a CInterfaceGroup via addCtrl, addGroup or addView, this is called after the add. + virtual void onAddToGroup() {} + + /** typically used only in conjunction with CGroupInScene. Such groups move every Frames. so + * this function is called on each children elements to move the XReal/Yreal only (with a delta) + */ + virtual void onFrameUpdateWindowPos(sint dx, sint dy); + + /// if true, InterfaceGroup child resize won't take this element into account + bool avoidResizeParent() const {return _AvoidResizeParent;} + void setAvoidResizeParent(bool state) {_AvoidResizeParent= state;} + + virtual std::string getClassName() + { + nlassert(0); // forgot to implement serial & to register the class ? + return ""; + } + + protected: + + ///the parent + CInterfaceGroup* _Parent; + + ///the id of the element + std::string _Id; + + std::string _Name; + + ///is the element active? + bool _Active; + + // if 0, don't need updateCoords(), else tell the number of pass needed + uint8 _InvalidCoords; + + // Real display coords + sint32 _XReal, _YReal, _WReal, _HReal; + + // Relative coords + sint32 _X; + sint32 _Y; + sint32 _W; + sint32 _H; + + //sint32 _Snap; + + // position references e.g. : _PosRef=BL, _ParentPosref=MM : the bottom left corner of the element + // will be placed on the center (middle middle) of the parent window + THotSpot _PosRef; + THotSpot _ParentPosRef; + NLMISC::CRefPtr _ParentPos; // RefPtr in case of group destroyed in a parent group with posref on it + + sint32 _SizeRef; // none == 0, w == 1, h == 2, wh == 3 + sint32 _SizeDivW, _SizeDivH; + NLMISC::CRefPtr _ParentSize; // RefPtr in case of group destroyed in a parent group with posref on it + + // Friend Class + friend class ::CGroupList; + friend class ::CGroupParagraph; + + // True if must modulate the global color with the view + bool _ModulateGlobalColor; + // Index of layer to render it. + sint8 _RenderLayer; + + // Used for CInterfaceGroup ChildResize feature + bool _AvoidResizeParent; + + + virtual void serial(NLMISC::IStream &f); + + void parseSizeRef(const char *sizeRef); + void parseSizeRef(const char *sizeRefStr, sint32 &sizeref, sint32 &sizeDivW, sint32 &sizeDivH); + + private: + //void snapSize(); + + typedef NLMISC::CSmartPtr TLinkSmartPtr; + typedef std::vector TLinkVect; + TLinkVect *_Links; // links, or NULL if no link + }; + + extern NLMISC::CStringMapper *_UIStringMapper; + /** + * class to compress string usage in the interface + * \author Matthieu 'Trap' Besson + * \author Nevrax France + * \date October 2003 + */ + class CStringShared + { + + public: + CStringShared() + { + _Id = NLMISC::CStringMapper::emptyId(); + } + + const CStringShared& operator=(const std::string &str) + { + _Id = _UIStringMapper->localMap(str); + return *this; + } + + const CStringShared& operator=(const CStringShared &str) + { + _Id = str._Id; + return *this; + } + + const std::string &toString() const + { + return _UIStringMapper->localUnmap(_Id); + } + + operator const std::string &() const + { + return _UIStringMapper->localUnmap(_Id); + } + + bool empty() const + { + return _Id == NLMISC::CStringMapper::emptyId(); + } + + static CStringShared emptyString() + { + return CStringShared(); + } + + NLMISC::TStringId getStringId() const { return _Id; } + + void serial(NLMISC::IStream &f) + { + std::string str; + if (f.isReading()) + { + f.serial(str); + *this = str; + } + else + { + str = this->toString(); + f.serial(str); + } + } + + private: + + NLMISC::TStringId _Id; + }; + + inline bool operator==(const CStringShared &lhs, const CStringShared &rhs) { return lhs.getStringId() == rhs.getStringId(); } + inline bool operator!=(const CStringShared &lhs, const CStringShared &rhs) { return !(lhs == rhs); } + + +} + using namespace NLGUI; -class CInterfaceLink; -class CInterfaceElement; -class CInterfaceGroup; -class CViewBase; -class CCtrlBase; -class IActionHandler; - -/** - * A visitor to walk a tree of interface elements and apply a teartment on them. - * - * For each vsited element, visitElement() is called - * If the element is a control, then visitCtrl() is called, and then visitElement() - * If the element is a view, then visitView() is called, and then visitElement() - * If the element is a group, then visitGoup() is called, and then visitElement() - * - * \author Nicolas Vizerie - * \author Nevrax France - * \date 2003 - */ -class CInterfaceElementVisitor -{ -public: - virtual void visit(CInterfaceElement * /* elem */) {} - virtual void visitGroup(CInterfaceGroup * /* group */) {} - virtual void visitView(CViewBase * /* view */) {} - virtual void visitCtrl(CCtrlBase * /* ctrl */) {} -}; - - -/** - * class describing a localisable interface element, i.e. : an element with coordinates - * \author Nicolas Brigand - * \author Nevrax France - * \date 2002 - */ -class CInterfaceElement : public CReflectableRefPtrTarget, public NLMISC::IStreamable -{ -public: - - - enum EStrech - { - none=0, - width=1, - height=2 - }; - - /// Constructor - CInterfaceElement() - { - _Parent = NULL; - - _XReal = _YReal = _WReal = _HReal = 0; - _X = _Y = _W = _H = 0; - //_Snap = 1; - - _PosRef = Hotspot_BL; - _ParentPosRef = Hotspot_BL; - _ParentPos = NULL; - - _SizeRef = 0; - _SizeDivW = 10; - _SizeDivH = 10; - _ParentSize = NULL; - - _Links = NULL; - _Active= true; - // default to 3 pass - _InvalidCoords= 3; - - _ModulateGlobalColor= true; - _RenderLayer= 0; - - _AvoidResizeParent= false; - } - - // dtor - virtual ~CInterfaceElement(); - - /** Cloning - * Cloning is actually performed using a serial / unserial in a memory stream - * NB Nico : if too slow, should use a CFastStream version instead, that is designedto work in memory only - */ - virtual CInterfaceElement *clone(); - - // help to serialize an action handler - static void serialAH(NLMISC::IStream &f, IActionHandler *&ah); - - - /// Parse the element and initalize it - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - - /// Debug info on memory - virtual uint32 getMemory () { return (uint32)(sizeof(*this)+_Id.size()); } - - /// helper: display a parse error with the id of the lement - void parseError (CInterfaceGroup *parentGroup, const char *reason = NULL); - - /// Accessors : GET - const std::string& getId() const { return _Id; } - std::string getShortId() const; - std::string getIdByValue() const { return _Id; } - - CInterfaceGroup* getParent() const { return _Parent; } - - CInterfaceElement* getParentPos() const { return _ParentPos; } - - CInterfaceElement* getParentSize() const { return _ParentSize; } - - /// Get the master group of this element (recurs call. - CInterfaceElement* getMasterGroup() const; - - // get a possible group container - CInterfaceGroup* getParentContainer(); - - bool getActive() const { return _Active; } - - sint32 getX() const { return _X; } - - sint32 getY() const { return _Y; } - - sint32 getW() const { return (_Active?_W:0); } - sint32 getW(bool bTestActive) const { return (bTestActive?(_Active?_W:0):_W); } - - sint32 getH() const { return (_Active?_H:0); } - sint32 getH(bool bTestActive) const { return (bTestActive?(_Active?_H:0):_H); } - - /** - * Get the max width used by the window. - * - * The view must return the largest width its content can take if it will be resized at maximum. - * Typical use : for a CTextView multiline, it returns the size of the whole string. - * - * This method is used by the container CCGroupTable that need to know this information about its children in its resizing algorithm. - */ - virtual sint32 getMaxUsedW() const { return INT_MAX; }; - - /** - * Get the min width used by the window. - * - * The view must return the smallest width its content can take if it will be resized at minimum. - * Typical use : for a CTextView multiline without word clipping, it returns the size of the largest word. - * - * This method is used by the container CCGroupTable that need to know this information about its children in its resizing algorithm. - */ - virtual sint32 getMinUsedW() const { return 0; }; - - //bool isSnapped() const { return (_Snap>1); } - - //sint32 getSnapping() const { return _Snap; } - - sint32 getXReal() const { return _XReal; } - - sint32 getYReal() const { return _YReal; } - - sint32 getWReal() const { return (_Active?_WReal:0); } - - sint32 getHReal() const { return (_Active?_HReal:0); } - - THotSpot getPosRef () const { return _PosRef; } - - THotSpot getParentPosRef () const { return _ParentPosRef; } - - sint32 getSizeRef() const { return _SizeRef; } // none == 0, w == 1, h == 2, wh == 3 - - void setSizeRef(sint32 value) { _SizeRef = value; } - - /// Accessors : SET - void setId (const std::string &newID) { _Id = newID; } - - inline void setName(const std::string &name) { _Name = name; } - inline const std::string& getName() { return _Name; } - - virtual void setIdRecurse(const std::string &newID); - - void setParent (CInterfaceGroup *pIG) { _Parent = pIG; } - - void setParentPos (CInterfaceElement *pIG) { _ParentPos = pIG; } - - void setParentSize (CInterfaceElement *pIG) { _ParentSize = pIG; } - - virtual void setActive (bool state); - - void setX (sint32 x) { _X = x; } - void setXAndInvalidateCoords (sint32 x) { _X = x; invalidateCoords(); } - - void setY (sint32 y) { _Y = y; } - void setYAndInvalidateCoords (sint32 y) { _Y = y; invalidateCoords(); } - - void setW (sint32 w); - void setWAndInvalidateCoords (sint32 w) { setW(w); invalidateCoords(); } - - void setH (sint32 h); - void setHAndInvalidateCoords (sint32 h) { setH(h); invalidateCoords(); } - - void setPosRef (THotSpot hs) { _PosRef = hs; } - - void setParentPosRef (THotSpot hs) { _ParentPosRef = hs; } - - // Get the coordinate of a corner on screen - void getCorner(sint32 &px, sint32 &py, THotSpot hotSpot); - - /** Test if the given coordinates are inside this element - */ - bool isIn(sint x, sint y) const; - - /** Test if the given box intersect the element - */ - bool isIn(sint x, sint y, uint width, uint height) const; - - /** Test if another interface element intersect this one - */ - bool isIn(const CInterfaceElement &other) const; - - /** - * get the window containing the element - * \return NULL if the element is not on the window, otherwise returns a pointer to the window - */ - CInterfaceGroup* getRootWindow(); - - /** get the element Depth, ie the number of parent he has (0 if _Parent==NULL) - * \warning slow test. don't take into account CCtrlBase::getDeltaDepth() (since method not virtual) - */ - uint getParentDepth() const; - - /** - * true if the element and all its parents are active (recurs up to the root window) - */ - bool isActiveThroughParents() const; - - /** - * move the element (add dx and dy to its coords) - * \param dx : value added to _X - * \param dy : value added to _Y - */ - virtual void move (sint32 dx, sint32 dy); - - //void resizeBR (sint32 sizex, sint32 sizey); - //void stopResizeBR(); - //void startResizeBR(); - - // Some tools - - void relativeSInt64Read (CInterfaceProperty &rIP, const std::string &prop, const char *val, - const std::string &defVal); - void relativeSInt32Read (CInterfaceProperty &rIP, const std::string &prop, const char *val, - const std::string &defVal); - void relativeBoolRead (CInterfaceProperty &rIP, const std::string &prop, const char *val, - const std::string &defVal); - void relativeRGBARead (CInterfaceProperty &rIP, const std::string &prop, const char *val, - const std::string &defVal); - - // Parse tools - static THotSpot convertHotSpot (const char *ptr); // - static void convertHotSpotCouple (const char *ptr, THotSpot &parentPosRef, THotSpot &posRef); - static NLMISC::CRGBA convertColor (const char *ptr); - static bool convertBool (const char *ptr); - static NLMISC::CVector convertVector (const char *ptr); - /** Convert a value that is in the form like width="50" or width="10%" - * if the value is absolute like '50' then 'pixels' is filled, else - * the ratio is remapped to the [0, 1] range and is copied in 'ratio' - */ - static void convertPixelsOrRatio(const char *ptr, sint32 &pixels, float &ratio); - - // add an interface link to that element (kept in a smart ptr) - void addLink(CInterfaceLink *link); - - // remove a link from that element; There's one less reference on the link (which is referenced by a smart ptr) - void removeLink(CInterfaceLink *link); - - /** Update all links for this instance and its sons. - * Derivers should override this to update their sons. - */ - virtual void updateAllLinks(); - - - /** This allow to force opening an element. By default it just activate the element. - * It allow to have different behaviour on more complex containers - */ - virtual void forceOpen() { setActive(true); } - - virtual void enableBlink(uint /* numBlinks */ = 0) {} - virtual void disableBlink() {} - virtual bool getBlink() const { return false; } - - // Options for views to be modulated by interface global color or not. Parsed with "global_color". Default: true - void setModulateGlobalColor(bool state) {_ModulateGlobalColor= state;} - bool getModulateGlobalColor() const {return _ModulateGlobalColor;} - - - void dummySet(sint32 value); - void dummySet(const std::string &value); - - // lua methods - int luaUpdateCoords(CLuaState &ls); - int luaInvalidateCoords(CLuaState &ls); - int luaInvalidateContent(CLuaState &ls); - int luaCenter(CLuaState &ls); - int luaSetPosRef(CLuaState &ls); - int luaSetParentPos(CLuaState &ls); - - // set sizeref as a string, like "wh", "wh5" .... - void setSizeRef(const std::string &sizeref); - std::string getSizeRefAsString() const; - - // export some properties - REFLECT_EXPORT_START(CInterfaceElement, CReflectable) - REFLECT_BOOL ("active", getActive, setActive); - REFLECT_BOOL ("global_color", getModulateGlobalColor, setModulateGlobalColor); - REFLECT_SINT32 ("x", getX, setXAndInvalidateCoords); - REFLECT_SINT32 ("y", getY, setYAndInvalidateCoords); - REFLECT_SINT32 ("w", getW, setWAndInvalidateCoords); - REFLECT_SINT32 ("h", getH, setHAndInvalidateCoords); - REFLECT_SINT32 ("x_real", getXReal, dummySet); - REFLECT_SINT32 ("y_real", getYReal, dummySet); - REFLECT_SINT32 ("w_real", getWReal, dummySet); - REFLECT_SINT32 ("h_real", getHReal, dummySet); - REFLECT_STRING ("id", getIdByValue, dummySet); - REFLECT_STRING ("sizeref", getSizeRefAsString, setSizeRef); - REFLECT_LUA_METHOD("updateCoords", luaUpdateCoords); - REFLECT_LUA_METHOD("invalidateCoords", luaInvalidateCoords); - REFLECT_LUA_METHOD("invalidateContent", luaInvalidateContent); - REFLECT_LUA_METHOD("center", luaCenter); - REFLECT_LUA_METHOD("setPosRef", luaSetPosRef); - REFLECT_LUA_METHOD("setParentPos", luaSetParentPos); - REFLECT_EXPORT_END - - - /* invalidate coords. set numPass==1 if you are SURE that only XReal/YReal need to be updated - * Default 3 is needed for: - * 1: update _W/_H and _WReal/_HReal according to Sons - * 2: update XReal/YReal (eg: according to Scroll offset) - */ - void invalidateCoords(uint8 numPass= 2); - uint8 getInvalidCoords() const {return _InvalidCoords;} - - /* Invalidates the content of the window. This method invalidate the content of the window (for CViewText or CGroupTable). - * It invalidates the content of the parent too. - */ - void invalidateContent(); - - /* This call back is called when the content or the content of a child is been invalidated. - */ - virtual void onInvalidateContent() {} - - // called by interfaceManager for master window only - void resetInvalidCoords(); - - /// Update the elements coords convert x,y,w,h (parentpos coord) to xreal,yreal,wreal,hreal (BL coord) - virtual void updateCoords(); - /// Called each frame before draw to possibly invalidateCoords(). - virtual void checkCoords(); - - /// Test if this element is son of the given element - bool isSonOf(const CInterfaceElement *other) const; - - /// Called after first frame initialised - virtual void launch () {} - - void setRenderLayer(sint8 rl) {_RenderLayer= rl;} - sint8 getRenderLayer() const { return _RenderLayer; } - - void copyOptionFrom(const CInterfaceElement &other); - - // center the element in middle of screen - void center(); - - // for debug only: draw wired quad to see where groups and hotspots are - enum TRenderWired - { - RenderView, - RenderCtrl, - RenderGroup - }; - // if uiFilter is not empty, draw a quad only if the element id match - virtual void renderWiredQuads(TRenderWired type, const std::string &uiFilter); - - void drawHotSpot(THotSpot hs, NLMISC::CRGBA col); - - // Returns 'true' if that element can be downcasted to a view - virtual bool isView() const { return false; } - - // Returns 'true' if that element can be downcasted to a ctrl - virtual bool isCtrl() const { return false; } - - // Returns 'true' if that element can be downcasted to an interface group - virtual bool isGroup() const { return false; } - - - /** This is called before the config loading begins. This is the place to restore default state for config info. - */ - virtual void onLoadConfig() {} - /** Tells whether that element wants to save info in a config stream. If this returns true, then serialConfig - * is called. - */ - virtual bool wantSerialConfig() const { return false; } - // Serial config info about that element. This is called only if wantSerialConfig() returns true - virtual void serialConfig(NLMISC::IStream &f); - - // visit the node of the ui tree - virtual void visit(CInterfaceElementVisitor *visitor); - - /** When user is quitting the interface, this is called. Then the interface config is saved - * This is where the element get the opportunity to do some cleanup. - */ - virtual void onQuit() {} - - /// Whent an element is added to a CInterfaceGroup via addCtrl, addGroup or addView, this is called after the add. - virtual void onAddToGroup() {} - - /** typically used only in conjunction with CGroupInScene. Such groups move every Frames. so - * this function is called on each children elements to move the XReal/Yreal only (with a delta) - */ - virtual void onFrameUpdateWindowPos(sint dx, sint dy); - - /// if true, InterfaceGroup child resize won't take this element into account - bool avoidResizeParent() const {return _AvoidResizeParent;} - void setAvoidResizeParent(bool state) {_AvoidResizeParent= state;} - - virtual std::string getClassName() - { - nlassert(0); // forgot to implement serial & to register the class ? - return ""; - } - -protected: - - ///the parent - CInterfaceGroup* _Parent; - - ///the id of the element - std::string _Id; - - std::string _Name; - - ///is the element active? - bool _Active; - - // if 0, don't need updateCoords(), else tell the number of pass needed - uint8 _InvalidCoords; - - // Real display coords - sint32 _XReal, _YReal, _WReal, _HReal; - - // Relative coords - sint32 _X; - sint32 _Y; - sint32 _W; - sint32 _H; - - //sint32 _Snap; - - // position references e.g. : _PosRef=BL, _ParentPosref=MM : the bottom left corner of the element - // will be placed on the center (middle middle) of the parent window - THotSpot _PosRef; - THotSpot _ParentPosRef; - NLMISC::CRefPtr _ParentPos; // RefPtr in case of group destroyed in a parent group with posref on it - - sint32 _SizeRef; // none == 0, w == 1, h == 2, wh == 3 - sint32 _SizeDivW, _SizeDivH; - NLMISC::CRefPtr _ParentSize; // RefPtr in case of group destroyed in a parent group with posref on it - - // Friend Class - friend class CGroupList; - friend class CGroupParagraph; - - // True if must modulate the global color with the view - bool _ModulateGlobalColor; - // Index of layer to render it. - sint8 _RenderLayer; - - // Used for CInterfaceGroup ChildResize feature - bool _AvoidResizeParent; - - - virtual void serial(NLMISC::IStream &f); - - void parseSizeRef(const char *sizeRef); - void parseSizeRef(const char *sizeRefStr, sint32 &sizeref, sint32 &sizeDivW, sint32 &sizeDivH); - -private: - //void snapSize(); - - typedef NLMISC::CSmartPtr TLinkSmartPtr; - typedef std::vector TLinkVect; - TLinkVect *_Links; // links, or NULL if no link -}; - -extern NLMISC::CStringMapper *_UIStringMapper; -/** - * class to compress string usage in the interface - * \author Matthieu 'Trap' Besson - * \author Nevrax France - * \date October 2003 - */ -class CStringShared -{ - -public: - CStringShared() - { - _Id = NLMISC::CStringMapper::emptyId(); - } - - const CStringShared& operator=(const std::string &str) - { - _Id = _UIStringMapper->localMap(str); - return *this; - } - - const CStringShared& operator=(const CStringShared &str) - { - _Id = str._Id; - return *this; - } - - const std::string &toString() const - { - return _UIStringMapper->localUnmap(_Id); - } - - operator const std::string &() const - { - return _UIStringMapper->localUnmap(_Id); - } - - bool empty() const - { - return _Id == NLMISC::CStringMapper::emptyId(); - } - - static CStringShared emptyString() - { - return CStringShared(); - } - - NLMISC::TStringId getStringId() const { return _Id; } - - void serial(NLMISC::IStream &f) - { - std::string str; - if (f.isReading()) - { - f.serial(str); - *this = str; - } - else - { - str = this->toString(); - f.serial(str); - } - } - -private: - - NLMISC::TStringId _Id; -}; - -inline bool operator==(const CStringShared &lhs, const CStringShared &rhs) { return lhs.getStringId() == rhs.getStringId(); } -inline bool operator!=(const CStringShared &lhs, const CStringShared &rhs) { return !(lhs == rhs); } - - #endif // NL_INTERFACE_ELEMENT_H /* End of interface_element.h */ diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 09f248f00..451e38ff3 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -22,382 +22,386 @@ #include "nel/gui/ctrl_base.h" #include "nel/gui/action_handler.h" -// ---------------------------------------------------------------------------- -class CInterfaceGroup : public CCtrlBase +namespace NLGUI { -public: - DECLARE_UI_CLASS(CInterfaceGroup) - /// Constructor - CInterfaceGroup(const TCtorParam ¶m); + class CInterfaceGroup : public CCtrlBase + { + public: + DECLARE_UI_CLASS(CInterfaceGroup) - /// Destructor - virtual ~CInterfaceGroup(); + /// Constructor + CInterfaceGroup(const TCtorParam ¶m); - virtual void setIdRecurse(const std::string &id); + /// Destructor + virtual ~CInterfaceGroup(); - /// Coming from CInterfaceElement - virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); + virtual void setIdRecurse(const std::string &id); - virtual uint32 getMemory (); - - virtual CInterfaceElement* getElement (const std::string &id); - CInterfaceElement* findFromShortId(const std::string &id); + /// Coming from CInterfaceElement + virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); - /// Dynamic creation - virtual void addView (CViewBase *child , sint eltOrder = -1); - virtual void addCtrl (CCtrlBase *child, sint eltOrder = -1); - virtual void addGroup (CInterfaceGroup *child, sint eltOrder = -1); - - CViewBase* getView (const std::string &id); - CCtrlBase* getCtrl (const std::string &id); - CInterfaceGroup* getGroup(const std::string &id) const; - - // Delete know type by ptr (return true if found and removed) - virtual bool delView (CViewBase *child, bool dontDelete = false); - virtual bool delCtrl (CCtrlBase *child, bool dontDelete = false); - virtual bool delGroup (CInterfaceGroup * child, bool dontDelete = false); - - // Delete know type by name (return true if found and removed) - virtual bool delView (const std::string &id, bool dontDelete = false); - virtual bool delCtrl (const std::string &id, bool dontDelete = false); - virtual bool delGroup (const std::string &id, bool dontDelete = false); - - // Delete unknow type by name or ptr. NB: additionaly, if it's a group, unmakeWindow() is called as necessary - bool delElement (const std::string &id, bool noWarning=false); - bool delElement (CInterfaceElement *pIE, bool noWarning=false); + virtual uint32 getMemory (); - uint getNumGroup() const { return (uint)_ChildrenGroups.size(); } - CInterfaceGroup *getGroup(uint index) const; - - sint32 getMaxUsedW() const; - sint32 getMinUsedW() const; - - /// Coming from CCtrlBase - virtual bool handleEvent (const NLGUI::CEventDescriptor &event); - - void executeControl (const std::string &sControlName); - - const std::vector & getGroups () { return _ChildrenGroups; } - const std::vector & getControls() { return _Controls; } - const std::vector & getViews() { return _Views; } - - // test is a group is a direct child of this interface group - bool isChildGroup(const CInterfaceGroup *group) const; - - virtual bool isWindowUnder (sint32 x, sint32 y); // Virtual for menu that is not square - CInterfaceGroup *getGroupUnder (sint32 x, sint32 y); - virtual bool getViewsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vVB); // Return true if x,y under the group - virtual bool getCtrlsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vICL); - virtual bool getGroupsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vIGL); - - void absoluteToRelative (sint32 &x, sint32 &y); - - /// Coming from CViewBase - virtual void draw (); - // Draw with no clip (if clip is done by parent) - virtual void drawNoClip(); - - /// Tool function to draw a single Element that should exist in the group (clipped by the group) - void drawElement (CViewBase *el); - - - /** - * update the elements coords - */ - virtual void checkCoords(); - virtual void updateCoords(); - - /// remove all views - virtual void clearViews(); - - /// remove all controls - virtual void clearControls(); - - /// remove all groups - virtual void clearGroups(); - - void setParentSizeMax(CInterfaceElement *pIE) { _ParentSizeMax = pIE; } - void setMaxW (sint32 maxw) { _MaxW = maxw; } - void setMaxH (sint32 maxh) { _MaxH = maxh; } - void setOfsX (sint32 x) { _OffsetX = x; } - void setOfsY (sint32 y) { _OffsetY = y; } - bool moveSBTrackY (CInterfaceGroup *target, sint32 dy); - bool moveSBTargetY (CInterfaceGroup *target, sint32 dy); - void setResizeFromChildW(bool resize) { _ResizeFromChildW = resize; } - void setResizeFromChildH(bool resize) { _ResizeFromChildH = resize; } - - // Valid only for windows InterfaceGroup. - // escapable - void setEscapable(bool b) { _Escapable= b; } - bool getEscapable() const { return _Escapable; } - void setAHOnEscape(const std::string &ah) { _AHOnEscape = CAHManager::getInstance()->getAH(ah, _AHOnEscapeParams); } - const std::string &getAHOnEscape() const { return CAHManager::getInstance()->getAHName(_AHOnEscape); } - void setAHOnEscapeParams(const std::string &ah) { _AHOnEscapeParams = ah; } - const std::string &getAHOnEscapeParams() const { return _AHOnEscapeParams; } - // enterable - void setAHOnEnter(const std::string &ah) { _AHOnEnter = CAHManager::getInstance()->getAH(ah, _AHOnEnterParams); } - const std::string &getAHOnEnter() const { return CAHManager::getInstance()->getAHName(_AHOnEnter); } - void setAHOnEnterParams(const std::string &ah) { _AHOnEnterParams = ah; } - const std::string &getAHOnEnterParams() const { return _AHOnEnterParams; } - uint8 getPriority() const { return _Priority; } - void setPriority(uint8 nprio); - - - sint32 getMaxW () const { return _MaxW; } - sint32 getMaxH () const { return _MaxH; } - sint32 getMaxWReal () const { return _Active ? _MaxWReal : 0; } - sint32 getMaxHReal () const { return _Active ? _MaxHReal : 0; } - sint32 getOfsX () const { return _OffsetX; } - sint32 getOfsY () const { return _OffsetY; } - bool getResizeFromChildW() const { return _ResizeFromChildW; } - bool getResizeFromChildH() const { return _ResizeFromChildH; } - sint32 getResizeFromChildWMargin() const { return _ResizeFromChildWMargin; } - sint32 getResizeFromChildHMargin() const { return _ResizeFromChildHMargin; } - void setResizeFromChildWMargin(sint32 margin) { _ResizeFromChildWMargin = margin; } - void setResizeFromChildHMargin(sint32 margin) { _ResizeFromChildHMargin = margin; } - bool getOverlappable() const { return _Overlappable; } - - virtual void setActive (bool state); - - // eval dimension of children bbox - void evalChildrenBBox(bool resizeFromChildW, bool resizeFromChildH, sint &width, sint &height) const; - - virtual void launch (); - - - // right & left clicks handler - void setLeftClickHandler(const std::string &handler); - void setRightClickHandler(const std::string &handler); - void setLeftClickHandlerParams(const std::string ¶ms) { _AHOnLeftClickParams = params; } - void setRightClickHandlerParams(const std::string ¶ms) { _AHOnRightClickParams = params; } - void setOnActiveHandler(const std::string &h) { _AHOnActive = CAHManager::getInstance()->getAH(h,_AHOnActiveParams); } - void setOnActiveParams(const std::string &p) { _AHOnActiveParams = p; } - void setOnDeactiveHandler(const std::string &h) { _AHOnDeactive = CAHManager::getInstance()->getAH(h,_AHOnDeactiveParams); } - void setOnDeactiveParams(const std::string &p) { _AHOnDeactiveParams = p; } - - const std::string &getLeftClickHandler() const { return CAHManager::getInstance()->getAHName(_AHOnLeftClick); } - const std::string &getLeftClickHandlerParams() const { return _AHOnLeftClickParams; } - const std::string &getRightClickHandler() const { return CAHManager::getInstance()->getAHName(_AHOnRightClick); } - const std::string &getRightClickHandlerParams() const { return _AHOnRightClickParams; } - const std::string &getOnActiveHandler() const { return CAHManager::getInstance()->getAHName(_AHOnActive); } - const std::string &getOnActiveParams() const { return _AHOnActiveParams; } - const std::string &getOnDeactiveHandler() const { return CAHManager::getInstance()->getAHName(_AHOnDeactive); } - const std::string &getOnDeactiveParams() const { return _AHOnDeactiveParams; } - - // find a sub view/ctrl/group in this group from its id - int luaFind(CLuaState &ls); - int luaGetEnclosingContainer(CLuaState &ls); - int luaDeleteLUAEnvTable(CLuaState &ls); - int luaAddGroup(CLuaState &ls); - int luaDelGroup(CLuaState &ls); - int luaGetNumGroups(CLuaState &ls); - int luaGetGroup(CLuaState &ls); - - void setMaxSizeRef(const std::string &maxSizeRef); - std::string getMaxSizeRefAsString() const; - - - REFLECT_EXPORT_START(CInterfaceGroup, CCtrlBase) - REFLECT_LUA_METHOD("find", luaFind); - REFLECT_LUA_METHOD("deleteLUAEnvTable", luaDeleteLUAEnvTable); - REFLECT_LUA_METHOD("getEnclosingContainer", luaGetEnclosingContainer); - REFLECT_LUA_METHOD("addGroup", luaAddGroup); - REFLECT_LUA_METHOD("delGroup", luaDelGroup); - REFLECT_LUA_METHOD("getNumGroups", luaGetNumGroups); - REFLECT_LUA_METHOD("getGroup", luaGetGroup); - REFLECT_STRING ("left_click", getLeftClickHandler, setLeftClickHandler); - REFLECT_STRING ("right_click", getRightClickHandler, setRightClickHandler); - REFLECT_STRING ("left_click_params", getLeftClickHandlerParams, setLeftClickHandlerParams); - REFLECT_STRING ("right_click_params", getRightClickHandlerParams, setRightClickHandlerParams); - REFLECT_STRING ("on_active", getOnActiveHandler, setOnActiveHandler); - REFLECT_STRING ("on_active_params", getOnActiveParams, setOnActiveParams); - REFLECT_STRING ("on_deactive", getOnDeactiveHandler, setOnDeactiveHandler); - REFLECT_STRING ("on_deactive_params", getOnDeactiveParams, setOnDeactiveParams); - REFLECT_STRING ("on_enter", getAHOnEnter, setAHOnEnter); - REFLECT_STRING ("on_enter_params", getAHOnEnterParams, setAHOnEnterParams); - REFLECT_STRING ("on_escape", getAHOnEscape, setAHOnEscape); - REFLECT_STRING ("on_escape_params", getAHOnEscapeParams, setAHOnEscapeParams); - REFLECT_SINT32 ("ofsx", getOfsX, setOfsX); - REFLECT_SINT32 ("ofsy", getOfsY, setOfsY); - REFLECT_BOOL("child_resize_w", getResizeFromChildW, setResizeFromChildW); - REFLECT_SINT32("child_resize_wmargin", getResizeFromChildWMargin, setResizeFromChildWMargin); - REFLECT_BOOL("child_resize_h", getResizeFromChildH, setResizeFromChildH); - REFLECT_SINT32("child_resize_hmargin", getResizeFromChildHMargin, setResizeFromChildHMargin); - REFLECT_SINT32 ("ofsy", getOfsY, setOfsY); - REFLECT_STRING("max_sizeref", getMaxSizeRefAsString, setMaxSizeRef); - REFLECT_SINT32 ("max_w", getMaxW, setMaxW); - REFLECT_SINT32 ("max_h", getMaxH, setMaxH); - REFLECT_SINT32 ("max_w_real", getMaxWReal, dummySet); - REFLECT_SINT32 ("max_h_real", getMaxHReal, dummySet); - REFLECT_EXPORT_END - - - - // From CCtrlBase - virtual void updateAllLinks(); - - /// return true for some containers. false by default - virtual bool isMovable() const {return false;} - - virtual sint32 getAlpha() const; - virtual void setAlpha (sint32 a); - - /// Eval current clip coords. This is not incremental as with makeNewClip, and thus more slow. This also doesn't change the current clip window. - void getClip(sint32 &x, sint32 &y, sint32 &w, sint32 &h) const; - - // quick way to know if the group is a CGroupContainer - bool isGroupContainer() const { return _IsGroupContainer; } - bool isGroupScrollText() const{ return _IsGroupScrollText; } - bool isGroupInScene() const{ return _IsGroupInScene; } - - CInterfaceGroup* getEnclosingContainer(); - - sint getInsertionOrder(CViewBase *vb) const; - - // for debug only - void dumpGroups(); - void dumpEltsOrder(); - - virtual void renderWiredQuads(CInterfaceElement::TRenderWired type, const std::string &uiFilter); - - virtual bool isGroup() const { return true; } - - // clear all edit box in the ui - virtual void clearAllEditBox(); - // restore all backuped positions for containers - virtual void restoreAllContainersBackupPosition(); - - virtual void dumpSize(uint depth = 0) const; - - // From CInterfaceElement - virtual void visit(CInterfaceElementVisitor *visitor); - - /// Visits only this group's sub-groups and then the group itself - virtual void visitGroupAndChildren( CInterfaceElementVisitor *visitor ); - - // Check cursor - void setUseCursor(bool use); - bool getUseCursor() const { return _UseCursor; } - - - // From CInterfaceElement - virtual void onFrameUpdateWindowPos(sint dx, sint dy); - // true for CGroupInScene for instance - bool isNeedFrameUpdatePos() const {return _NeedFrameUpdatePos;} - - - /// \name LUA specific - // @{ - // Create a LUA Environement if don't exist, then push it on the LUA stack - void pushLUAEnvTable(); - // Free the LUA Env Table - void deleteLUAEnvTable(bool recurse = false); - // Set the LUA script to execute at checkCoords time (empty to reset) - void setLuaScriptOnDraw(const std::string &script); - // - void executeLuaScriptOnDraw(); - // Set the LUA script to execute when a list of DB change (of forms: "@DB1,@DB2" ....). The dbList is the key - void addLuaScriptOnDBChange(const std::string &dbList, const std::string &script); - // Remove the LUA script to execute when a list of DB change - void removeLuaScriptOnDBChange(const std::string &dbList); - // @} - - virtual CInterfaceElement *clone(); - virtual void serial(NLMISC::IStream &f); - - // Return the current Depth, with no ZBias applied. - float getDepthForZSort() const { return _DepthForZSort; } - -protected: - - void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH); - void restoreClip (sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH); - - // Compute clip contribution for current window, and a previous clipping rectangle. This doesn't change the clip window in the driver. - void computeCurrentClipContribution(sint32 prevX, sint32 prevY, sint32 prevW, sint32 prevH, - sint32 &newX, sint32 &newY, sint32 &newW, sint32 &newH) const; - - void delEltOrder (CViewBase *pElt); - - // update coords one time - void doUpdateCoords(); - - // notify children controls & groups that 'active' has been called on one of their parent - void notifyActiveCalled(const NLGUI::CEventDescriptorActiveCalledOnParent &desc); + virtual CInterfaceElement* getElement (const std::string &id); + CInterfaceElement* findFromShortId(const std::string &id); -protected: + /// Dynamic creation + virtual void addView (CViewBase *child , sint eltOrder = -1); + virtual void addCtrl (CCtrlBase *child, sint eltOrder = -1); + virtual void addGroup (CInterfaceGroup *child, sint eltOrder = -1); - /// children interface elements - std::vector _ChildrenGroups; - std::vector _Controls; - std::vector _Views; + CViewBase* getView (const std::string &id); + CCtrlBase* getCtrl (const std::string &id); + CInterfaceGroup* getGroup(const std::string &id) const; + + // Delete know type by ptr (return true if found and removed) + virtual bool delView (CViewBase *child, bool dontDelete = false); + virtual bool delCtrl (CCtrlBase *child, bool dontDelete = false); + virtual bool delGroup (CInterfaceGroup * child, bool dontDelete = false); + + // Delete know type by name (return true if found and removed) + virtual bool delView (const std::string &id, bool dontDelete = false); + virtual bool delCtrl (const std::string &id, bool dontDelete = false); + virtual bool delGroup (const std::string &id, bool dontDelete = false); + + // Delete unknow type by name or ptr. NB: additionaly, if it's a group, unmakeWindow() is called as necessary + bool delElement (const std::string &id, bool noWarning=false); + bool delElement (CInterfaceElement *pIE, bool noWarning=false); - std::vector _EltOrder; - - /// Scroll properties - NLMISC::CRefPtr _ParentSizeMax; // RefPtr in case of group destroyed in a parent group with posref on it - sint32 _MaxW, _MaxH; - sint32 _MaxWReal, _MaxHReal; - sint32 _OffsetX, _OffsetY; - - uint8 _Priority; - - // Misc prop - bool _Overlappable : 1; - bool _ResizeFromChildW : 1; - bool _ResizeFromChildH : 1; - bool _Escapable : 1; - bool _UseCursor : 1; - bool _IsGroupContainer : 1; // faster than a virual call - bool _IsGroupScrollText : 1; - bool _IsGroupInScene : 1; - bool _NeedFrameUpdatePos : 1; // typically For CGroupInScene - sint32 _ResizeFromChildWMargin; - sint32 _ResizeFromChildHMargin; - sint32 _GroupSizeRef; - - // Projected Depth with no ZBias applied - float _DepthForZSort; - - // handler for activation - IActionHandler *_AHOnActive; - CStringShared _AHOnActiveParams; - IActionHandler *_AHOnDeactive; - CStringShared _AHOnDeactiveParams; - - // right & left clicks - IActionHandler *_AHOnLeftClick; - CStringShared _AHOnLeftClickParams; - IActionHandler *_AHOnRightClick; - CStringShared _AHOnRightClickParams; - - // enter params. - IActionHandler *_AHOnEnter; - CStringShared _AHOnEnterParams; - - // escape AH - IActionHandler *_AHOnEscape; - CStringShared _AHOnEscapeParams; - -private: - - void addToEltOrder(CViewBase *view, sint order); - - /// \name LUA specific - // @{ - // Lua Env Table created. Table is in the LUA_REGISTRYINDEX, with key as this CInterfaceGroup* userdata - bool _LUAEnvTableCreated; - // The LUA script to be executed on Draw (checkCoords) - CStringShared _LUAOnDraw; - // The InterfaceLink created specialy for Lua Script to be executed at some DB change - typedef std::map > TLUAOnDbChange; - TLUAOnDbChange _LUAOnDbChange; - void removeAllLUAOnDbChange(); -protected: - void parseMaxSizeRef(const char *ptr); - // @} -}; + uint getNumGroup() const { return (uint)_ChildrenGroups.size(); } + CInterfaceGroup *getGroup(uint index) const; + + sint32 getMaxUsedW() const; + sint32 getMinUsedW() const; + + /// Coming from CCtrlBase + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + + void executeControl (const std::string &sControlName); + + const std::vector & getGroups () { return _ChildrenGroups; } + const std::vector & getControls() { return _Controls; } + const std::vector & getViews() { return _Views; } + + // test is a group is a direct child of this interface group + bool isChildGroup(const CInterfaceGroup *group) const; + + virtual bool isWindowUnder (sint32 x, sint32 y); // Virtual for menu that is not square + CInterfaceGroup *getGroupUnder (sint32 x, sint32 y); + virtual bool getViewsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vVB); // Return true if x,y under the group + virtual bool getCtrlsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vICL); + virtual bool getGroupsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vIGL); + + void absoluteToRelative (sint32 &x, sint32 &y); + + /// Coming from CViewBase + virtual void draw (); + // Draw with no clip (if clip is done by parent) + virtual void drawNoClip(); + + /// Tool function to draw a single Element that should exist in the group (clipped by the group) + void drawElement (CViewBase *el); + + + /** + * update the elements coords + */ + virtual void checkCoords(); + virtual void updateCoords(); + + /// remove all views + virtual void clearViews(); + + /// remove all controls + virtual void clearControls(); + + /// remove all groups + virtual void clearGroups(); + + void setParentSizeMax(CInterfaceElement *pIE) { _ParentSizeMax = pIE; } + void setMaxW (sint32 maxw) { _MaxW = maxw; } + void setMaxH (sint32 maxh) { _MaxH = maxh; } + void setOfsX (sint32 x) { _OffsetX = x; } + void setOfsY (sint32 y) { _OffsetY = y; } + bool moveSBTrackY (CInterfaceGroup *target, sint32 dy); + bool moveSBTargetY (CInterfaceGroup *target, sint32 dy); + void setResizeFromChildW(bool resize) { _ResizeFromChildW = resize; } + void setResizeFromChildH(bool resize) { _ResizeFromChildH = resize; } + + // Valid only for windows InterfaceGroup. + // escapable + void setEscapable(bool b) { _Escapable= b; } + bool getEscapable() const { return _Escapable; } + void setAHOnEscape(const std::string &ah) { _AHOnEscape = CAHManager::getInstance()->getAH(ah, _AHOnEscapeParams); } + const std::string &getAHOnEscape() const { return CAHManager::getInstance()->getAHName(_AHOnEscape); } + void setAHOnEscapeParams(const std::string &ah) { _AHOnEscapeParams = ah; } + const std::string &getAHOnEscapeParams() const { return _AHOnEscapeParams; } + // enterable + void setAHOnEnter(const std::string &ah) { _AHOnEnter = CAHManager::getInstance()->getAH(ah, _AHOnEnterParams); } + const std::string &getAHOnEnter() const { return CAHManager::getInstance()->getAHName(_AHOnEnter); } + void setAHOnEnterParams(const std::string &ah) { _AHOnEnterParams = ah; } + const std::string &getAHOnEnterParams() const { return _AHOnEnterParams; } + uint8 getPriority() const { return _Priority; } + void setPriority(uint8 nprio); + + + sint32 getMaxW () const { return _MaxW; } + sint32 getMaxH () const { return _MaxH; } + sint32 getMaxWReal () const { return _Active ? _MaxWReal : 0; } + sint32 getMaxHReal () const { return _Active ? _MaxHReal : 0; } + sint32 getOfsX () const { return _OffsetX; } + sint32 getOfsY () const { return _OffsetY; } + bool getResizeFromChildW() const { return _ResizeFromChildW; } + bool getResizeFromChildH() const { return _ResizeFromChildH; } + sint32 getResizeFromChildWMargin() const { return _ResizeFromChildWMargin; } + sint32 getResizeFromChildHMargin() const { return _ResizeFromChildHMargin; } + void setResizeFromChildWMargin(sint32 margin) { _ResizeFromChildWMargin = margin; } + void setResizeFromChildHMargin(sint32 margin) { _ResizeFromChildHMargin = margin; } + bool getOverlappable() const { return _Overlappable; } + + virtual void setActive (bool state); + + // eval dimension of children bbox + void evalChildrenBBox(bool resizeFromChildW, bool resizeFromChildH, sint &width, sint &height) const; + + virtual void launch (); + + + // right & left clicks handler + void setLeftClickHandler(const std::string &handler); + void setRightClickHandler(const std::string &handler); + void setLeftClickHandlerParams(const std::string ¶ms) { _AHOnLeftClickParams = params; } + void setRightClickHandlerParams(const std::string ¶ms) { _AHOnRightClickParams = params; } + void setOnActiveHandler(const std::string &h) { _AHOnActive = CAHManager::getInstance()->getAH(h,_AHOnActiveParams); } + void setOnActiveParams(const std::string &p) { _AHOnActiveParams = p; } + void setOnDeactiveHandler(const std::string &h) { _AHOnDeactive = CAHManager::getInstance()->getAH(h,_AHOnDeactiveParams); } + void setOnDeactiveParams(const std::string &p) { _AHOnDeactiveParams = p; } + + const std::string &getLeftClickHandler() const { return CAHManager::getInstance()->getAHName(_AHOnLeftClick); } + const std::string &getLeftClickHandlerParams() const { return _AHOnLeftClickParams; } + const std::string &getRightClickHandler() const { return CAHManager::getInstance()->getAHName(_AHOnRightClick); } + const std::string &getRightClickHandlerParams() const { return _AHOnRightClickParams; } + const std::string &getOnActiveHandler() const { return CAHManager::getInstance()->getAHName(_AHOnActive); } + const std::string &getOnActiveParams() const { return _AHOnActiveParams; } + const std::string &getOnDeactiveHandler() const { return CAHManager::getInstance()->getAHName(_AHOnDeactive); } + const std::string &getOnDeactiveParams() const { return _AHOnDeactiveParams; } + + // find a sub view/ctrl/group in this group from its id + int luaFind(CLuaState &ls); + int luaGetEnclosingContainer(CLuaState &ls); + int luaDeleteLUAEnvTable(CLuaState &ls); + int luaAddGroup(CLuaState &ls); + int luaDelGroup(CLuaState &ls); + int luaGetNumGroups(CLuaState &ls); + int luaGetGroup(CLuaState &ls); + + void setMaxSizeRef(const std::string &maxSizeRef); + std::string getMaxSizeRefAsString() const; + + + REFLECT_EXPORT_START(CInterfaceGroup, CCtrlBase) + REFLECT_LUA_METHOD("find", luaFind); + REFLECT_LUA_METHOD("deleteLUAEnvTable", luaDeleteLUAEnvTable); + REFLECT_LUA_METHOD("getEnclosingContainer", luaGetEnclosingContainer); + REFLECT_LUA_METHOD("addGroup", luaAddGroup); + REFLECT_LUA_METHOD("delGroup", luaDelGroup); + REFLECT_LUA_METHOD("getNumGroups", luaGetNumGroups); + REFLECT_LUA_METHOD("getGroup", luaGetGroup); + REFLECT_STRING ("left_click", getLeftClickHandler, setLeftClickHandler); + REFLECT_STRING ("right_click", getRightClickHandler, setRightClickHandler); + REFLECT_STRING ("left_click_params", getLeftClickHandlerParams, setLeftClickHandlerParams); + REFLECT_STRING ("right_click_params", getRightClickHandlerParams, setRightClickHandlerParams); + REFLECT_STRING ("on_active", getOnActiveHandler, setOnActiveHandler); + REFLECT_STRING ("on_active_params", getOnActiveParams, setOnActiveParams); + REFLECT_STRING ("on_deactive", getOnDeactiveHandler, setOnDeactiveHandler); + REFLECT_STRING ("on_deactive_params", getOnDeactiveParams, setOnDeactiveParams); + REFLECT_STRING ("on_enter", getAHOnEnter, setAHOnEnter); + REFLECT_STRING ("on_enter_params", getAHOnEnterParams, setAHOnEnterParams); + REFLECT_STRING ("on_escape", getAHOnEscape, setAHOnEscape); + REFLECT_STRING ("on_escape_params", getAHOnEscapeParams, setAHOnEscapeParams); + REFLECT_SINT32 ("ofsx", getOfsX, setOfsX); + REFLECT_SINT32 ("ofsy", getOfsY, setOfsY); + REFLECT_BOOL("child_resize_w", getResizeFromChildW, setResizeFromChildW); + REFLECT_SINT32("child_resize_wmargin", getResizeFromChildWMargin, setResizeFromChildWMargin); + REFLECT_BOOL("child_resize_h", getResizeFromChildH, setResizeFromChildH); + REFLECT_SINT32("child_resize_hmargin", getResizeFromChildHMargin, setResizeFromChildHMargin); + REFLECT_SINT32 ("ofsy", getOfsY, setOfsY); + REFLECT_STRING("max_sizeref", getMaxSizeRefAsString, setMaxSizeRef); + REFLECT_SINT32 ("max_w", getMaxW, setMaxW); + REFLECT_SINT32 ("max_h", getMaxH, setMaxH); + REFLECT_SINT32 ("max_w_real", getMaxWReal, dummySet); + REFLECT_SINT32 ("max_h_real", getMaxHReal, dummySet); + REFLECT_EXPORT_END + + + + // From CCtrlBase + virtual void updateAllLinks(); + + /// return true for some containers. false by default + virtual bool isMovable() const {return false;} + + virtual sint32 getAlpha() const; + virtual void setAlpha (sint32 a); + + /// Eval current clip coords. This is not incremental as with makeNewClip, and thus more slow. This also doesn't change the current clip window. + void getClip(sint32 &x, sint32 &y, sint32 &w, sint32 &h) const; + + // quick way to know if the group is a CGroupContainer + bool isGroupContainer() const { return _IsGroupContainer; } + bool isGroupScrollText() const{ return _IsGroupScrollText; } + bool isGroupInScene() const{ return _IsGroupInScene; } + + CInterfaceGroup* getEnclosingContainer(); + + sint getInsertionOrder(CViewBase *vb) const; + + // for debug only + void dumpGroups(); + void dumpEltsOrder(); + + virtual void renderWiredQuads(CInterfaceElement::TRenderWired type, const std::string &uiFilter); + + virtual bool isGroup() const { return true; } + + // clear all edit box in the ui + virtual void clearAllEditBox(); + // restore all backuped positions for containers + virtual void restoreAllContainersBackupPosition(); + + virtual void dumpSize(uint depth = 0) const; + + // From CInterfaceElement + virtual void visit(CInterfaceElementVisitor *visitor); + + /// Visits only this group's sub-groups and then the group itself + virtual void visitGroupAndChildren( CInterfaceElementVisitor *visitor ); + + // Check cursor + void setUseCursor(bool use); + bool getUseCursor() const { return _UseCursor; } + + + // From CInterfaceElement + virtual void onFrameUpdateWindowPos(sint dx, sint dy); + // true for CGroupInScene for instance + bool isNeedFrameUpdatePos() const {return _NeedFrameUpdatePos;} + + + /// \name LUA specific + // @{ + // Create a LUA Environement if don't exist, then push it on the LUA stack + void pushLUAEnvTable(); + // Free the LUA Env Table + void deleteLUAEnvTable(bool recurse = false); + // Set the LUA script to execute at checkCoords time (empty to reset) + void setLuaScriptOnDraw(const std::string &script); + // + void executeLuaScriptOnDraw(); + // Set the LUA script to execute when a list of DB change (of forms: "@DB1,@DB2" ....). The dbList is the key + void addLuaScriptOnDBChange(const std::string &dbList, const std::string &script); + // Remove the LUA script to execute when a list of DB change + void removeLuaScriptOnDBChange(const std::string &dbList); + // @} + + virtual CInterfaceElement *clone(); + virtual void serial(NLMISC::IStream &f); + + // Return the current Depth, with no ZBias applied. + float getDepthForZSort() const { return _DepthForZSort; } + + protected: + + void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH); + void restoreClip (sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH); + + // Compute clip contribution for current window, and a previous clipping rectangle. This doesn't change the clip window in the driver. + void computeCurrentClipContribution(sint32 prevX, sint32 prevY, sint32 prevW, sint32 prevH, + sint32 &newX, sint32 &newY, sint32 &newW, sint32 &newH) const; + + void delEltOrder (CViewBase *pElt); + + // update coords one time + void doUpdateCoords(); + + // notify children controls & groups that 'active' has been called on one of their parent + void notifyActiveCalled(const NLGUI::CEventDescriptorActiveCalledOnParent &desc); + + protected: + + /// children interface elements + std::vector _ChildrenGroups; + std::vector _Controls; + std::vector _Views; + + std::vector _EltOrder; + + /// Scroll properties + NLMISC::CRefPtr _ParentSizeMax; // RefPtr in case of group destroyed in a parent group with posref on it + sint32 _MaxW, _MaxH; + sint32 _MaxWReal, _MaxHReal; + sint32 _OffsetX, _OffsetY; + + uint8 _Priority; + + // Misc prop + bool _Overlappable : 1; + bool _ResizeFromChildW : 1; + bool _ResizeFromChildH : 1; + bool _Escapable : 1; + bool _UseCursor : 1; + bool _IsGroupContainer : 1; // faster than a virual call + bool _IsGroupScrollText : 1; + bool _IsGroupInScene : 1; + bool _NeedFrameUpdatePos : 1; // typically For CGroupInScene + sint32 _ResizeFromChildWMargin; + sint32 _ResizeFromChildHMargin; + sint32 _GroupSizeRef; + + // Projected Depth with no ZBias applied + float _DepthForZSort; + + // handler for activation + IActionHandler *_AHOnActive; + CStringShared _AHOnActiveParams; + IActionHandler *_AHOnDeactive; + CStringShared _AHOnDeactiveParams; + + // right & left clicks + IActionHandler *_AHOnLeftClick; + CStringShared _AHOnLeftClickParams; + IActionHandler *_AHOnRightClick; + CStringShared _AHOnRightClickParams; + + // enter params. + IActionHandler *_AHOnEnter; + CStringShared _AHOnEnterParams; + + // escape AH + IActionHandler *_AHOnEscape; + CStringShared _AHOnEscapeParams; + + private: + + void addToEltOrder(CViewBase *view, sint order); + + /// \name LUA specific + // @{ + // Lua Env Table created. Table is in the LUA_REGISTRYINDEX, with key as this CInterfaceGroup* userdata + bool _LUAEnvTableCreated; + // The LUA script to be executed on Draw (checkCoords) + CStringShared _LUAOnDraw; + // The InterfaceLink created specialy for Lua Script to be executed at some DB change + typedef std::map > TLUAOnDbChange; + TLUAOnDbChange _LUAOnDbChange; + void removeAllLUAOnDbChange(); + protected: + void parseMaxSizeRef(const char *ptr); + // @} + }; + +} #endif // NL_INTERFACE_GROUP_H diff --git a/code/nel/include/nel/gui/interface_link.h b/code/nel/include/nel/gui/interface_link.h index 33561ff0f..96a5558b3 100644 --- a/code/nel/include/nel/gui/interface_link.h +++ b/code/nel/include/nel/gui/interface_link.h @@ -27,165 +27,160 @@ namespace NLGUI class CReflectedProperty; class CInterfaceExprValue; class CInterfaceExprNode; -} + class CInterfaceElement; + class CInterfaceGroup; - -class CInterfaceElement; -class CInterfaceGroup; - - -using namespace NLGUI; - - -/** A link in an interface. - * A link is an object that can read one or several values from the database, that can evaluate an expression - * on these database entries (simple computation, using the CInterfaceExpr class), and that can affect the result to - * an interface property that has been exported by an interface element (the export system uses reflect.h). - * The first time it is created, it places observers on the database entries that are needed by the expression, so each - * time a database value changes, the link is marked as 'triggered' - * When updateTrigeredLinks() is called, all links are effectively updated. - * - * Example of use : connecting a change in the db tree to the 'active' state of a window - * - * NB : an additionnal action handler can be provided - * NB : The links are owned by the interface element (using a smart pointer) - * NB : Several targets may be used. - * - * \author Nicolas Vizerie - * \author Nevrax France - * \date 2002 - */ -class CInterfaceLink : public NLMISC::ICDBNode::IPropertyObserver -{ -public: - #ifdef NL_DEBUG - // for debugging purposes : if this link is 'named' e.g is owner by CInterfaceManager - // and was created by calling CInterfaceManager::addLink, contains the name of this link - std::string LinkName; - #endif -public: - struct CTargetInfo - { - CInterfaceElement *Elem; - std::string PropertyName; - /** Affect a value to this target. - * \return true if the affectation could be made - */ - bool affect(const CInterfaceExprValue &value); - }; - - - /// Updates triggered interface links when triggered by the observed branch - class CInterfaceLinkUpdater : public NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver + /** A link in an interface. + * A link is an object that can read one or several values from the database, that can evaluate an expression + * on these database entries (simple computation, using the CInterfaceExpr class), and that can affect the result to + * an interface property that has been exported by an interface element (the export system uses reflect.h). + * The first time it is created, it places observers on the database entries that are needed by the expression, so each + * time a database value changes, the link is marked as 'triggered' + * When updateTrigeredLinks() is called, all links are effectively updated. + * + * Example of use : connecting a change in the db tree to the 'active' state of a window + * + * NB : an additionnal action handler can be provided + * NB : The links are owned by the interface element (using a smart pointer) + * NB : Several targets may be used. + * + * \author Nicolas Vizerie + * \author Nevrax France + * \date 2002 + */ + class CInterfaceLink : public NLMISC::ICDBNode::IPropertyObserver { public: - CInterfaceLinkUpdater(); - ~CInterfaceLinkUpdater(); - void onObserverCallFlush(); + #ifdef NL_DEBUG + // for debugging purposes : if this link is 'named' e.g is owner by CInterfaceManager + // and was created by calling CInterfaceManager::addLink, contains the name of this link + std::string LinkName; + #endif + public: + struct CTargetInfo + { + CInterfaceElement *Elem; + std::string PropertyName; + /** Affect a value to this target. + * \return true if the affectation could be made + */ + bool affect(const CInterfaceExprValue &value); + }; + + + /// Updates triggered interface links when triggered by the observed branch + class CInterfaceLinkUpdater : public NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver + { + public: + CInterfaceLinkUpdater(); + ~CInterfaceLinkUpdater(); + void onObserverCallFlush(); + }; + + public: + CInterfaceLink(); + ~CInterfaceLink(); // this object should only be destroyed by a CInterfaceElement + /** Make a link between the given interface element properties and a value that depends on database entries. + * The link is automatically added in the link list of the targets element (it calls CInterfaceElement::addLink), so when all target elements are removed, the link is. + * If there are no target element, the link is permanent (removed at exit) + * NB : The target is not updated during this call. + */ + bool init(const std::vector &targets, const std::string &expr, const std::string &actionHandler, const std::string &ahParams, const std::string &ahCond, CInterfaceGroup *parent); + // force all the links that have been created to update their targets. This can be called when the interface has been loaded, and when the databse entries have been retrieved. + static void updateAllLinks(); + // force all trigered links to be updated + static void updateTrigeredLinks(); + // remove from the _LinksWithNoTarget list if the link has no target + void uninit(); + + // Force an update of the target of this link + void update(); + /** Remove a target element. It won't be updated anymore by that link + * NB : this don't call removeLink() on the target + */ + void removeTarget(CInterfaceElement *elem); + // Get the number of targets of this link + uint getNumTargets() const { return (uint)_Targets.size(); } + // Get the i-th target + CInterfaceElement *getTarget(uint index) const { return _Targets[index]._InterfaceElement; } + + static void removeAllLinks(); + + static void setTargetProperty (const std::string & Target, const CInterfaceExprValue &val); + + static bool isUpdatingAllLinks() { return _UpdateAllLinks; } + + /** From a target name of a link, retrieve the target element and its target target property + * \return true if the target is valid + */ + static bool splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm); + + /** From several target names of a link (seprated by ','), retrieve the target elements and their target properties + * \return true if all targets are valid + */ + static bool splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup, std::vector &targetsVect); + //////////////////////////////////////////////////////////////////////////////////////////////////////// + private: + friend struct CRemoveTargetPred; + // a target property + struct CTarget + { + CInterfaceElement *_InterfaceElement; + const CReflectedProperty *_Property; + }; + private: + typedef std::list TLinkList; + typedef NLMISC::CSmartPtr TLinkSmartPtr; + typedef std::vector TLinkVect; + typedef std::vector TNodeVect; + private: + std::vector _Targets; + TNodeVect _ObservedNodes; + std::string _Expr; + CInterfaceExprNode *_ParseTree; + std::string _ActionHandler; + std::string _AHParams; + std::string _AHCond; + CInterfaceGroup *_AHParent; + static TLinkList _LinkList; + TLinkList::iterator _ListEntry; + bool _On; + static TLinkVect _LinksWithNoTarget; // there should be an owner for links with no targets + static bool _UpdateAllLinks; + ///\ name triggered link mgt + //@{ + // next/previous link that was trigered. NULL means end or start of list + // each ptr is duplicated because with manage 2 lists : one list in which links are added, and one list in which we update links. + // This way one link can trigger another with no prb + CInterfaceLink *_PrevTriggeredLink[2]; + CInterfaceLink *_NextTriggeredLink[2]; + bool _Triggered[2]; + // global lists + static CInterfaceLink *_FirstTriggeredLink[2]; + static CInterfaceLink *_LastTriggeredLink[2]; + // iterators in current list being updated : they're global so that deleting a CInterfaceLink instance prevent them from becoming dangling pointers + static CInterfaceLink *_CurrUpdatedLink; + static CInterfaceLink *_NextUpdatedLink; + // Index of the list in which triggered link must be inserted + static uint _CurrentTriggeredLinkList; + + // + void linkInTriggerList(uint list); + void unlinkFromTriggerList(uint list); + //@} + + private: + /** Inherited from ICDBNode::IPropertyObserver + * This doesn't update the node directly, but mark it as 'triggered' + * The node is really updated during the call to 'updateTrigeredLinks()' + */ + virtual void update(NLMISC::ICDBNode *node); + void createObservers(const TNodeVect &nodes); + void removeObservers(const TNodeVect &nodes); + // debug : check that there are as many targets as reference to a link + void checkNbRefs(); }; -public: - CInterfaceLink(); - ~CInterfaceLink(); // this object should only be destroyed by a CInterfaceElement - /** Make a link between the given interface element properties and a value that depends on database entries. - * The link is automatically added in the link list of the targets element (it calls CInterfaceElement::addLink), so when all target elements are removed, the link is. - * If there are no target element, the link is permanent (removed at exit) - * NB : The target is not updated during this call. - */ - bool init(const std::vector &targets, const std::string &expr, const std::string &actionHandler, const std::string &ahParams, const std::string &ahCond, CInterfaceGroup *parent); - // force all the links that have been created to update their targets. This can be called when the interface has been loaded, and when the databse entries have been retrieved. - static void updateAllLinks(); - // force all trigered links to be updated - static void updateTrigeredLinks(); - // remove from the _LinksWithNoTarget list if the link has no target - void uninit(); - - // Force an update of the target of this link - void update(); - /** Remove a target element. It won't be updated anymore by that link - * NB : this don't call removeLink() on the target - */ - void removeTarget(CInterfaceElement *elem); - // Get the number of targets of this link - uint getNumTargets() const { return (uint)_Targets.size(); } - // Get the i-th target - CInterfaceElement *getTarget(uint index) const { return _Targets[index]._InterfaceElement; } - - static void removeAllLinks(); - - static void setTargetProperty (const std::string & Target, const CInterfaceExprValue &val); - - static bool isUpdatingAllLinks() { return _UpdateAllLinks; } - - /** From a target name of a link, retrieve the target element and its target target property - * \return true if the target is valid - */ - static bool splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm); - - /** From several target names of a link (seprated by ','), retrieve the target elements and their target properties - * \return true if all targets are valid - */ - static bool splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup, std::vector &targetsVect); -//////////////////////////////////////////////////////////////////////////////////////////////////////// -private: - friend struct CRemoveTargetPred; - // a target property - struct CTarget - { - CInterfaceElement *_InterfaceElement; - const CReflectedProperty *_Property; - }; -private: - typedef std::list TLinkList; - typedef NLMISC::CSmartPtr TLinkSmartPtr; - typedef std::vector TLinkVect; - typedef std::vector TNodeVect; -private: - std::vector _Targets; - TNodeVect _ObservedNodes; - std::string _Expr; - CInterfaceExprNode *_ParseTree; - std::string _ActionHandler; - std::string _AHParams; - std::string _AHCond; - CInterfaceGroup *_AHParent; - static TLinkList _LinkList; - TLinkList::iterator _ListEntry; - bool _On; - static TLinkVect _LinksWithNoTarget; // there should be an owner for links with no targets - static bool _UpdateAllLinks; - ///\ name triggered link mgt - //@{ - // next/previous link that was trigered. NULL means end or start of list - // each ptr is duplicated because with manage 2 lists : one list in which links are added, and one list in which we update links. - // This way one link can trigger another with no prb - CInterfaceLink *_PrevTriggeredLink[2]; - CInterfaceLink *_NextTriggeredLink[2]; - bool _Triggered[2]; - // global lists - static CInterfaceLink *_FirstTriggeredLink[2]; - static CInterfaceLink *_LastTriggeredLink[2]; - // iterators in current list being updated : they're global so that deleting a CInterfaceLink instance prevent them from becoming dangling pointers - static CInterfaceLink *_CurrUpdatedLink; - static CInterfaceLink *_NextUpdatedLink; - // Index of the list in which triggered link must be inserted - static uint _CurrentTriggeredLinkList; - - // - void linkInTriggerList(uint list); - void unlinkFromTriggerList(uint list); - //@} - -private: - /** Inherited from ICDBNode::IPropertyObserver - * This doesn't update the node directly, but mark it as 'triggered' - * The node is really updated during the call to 'updateTrigeredLinks()' - */ - virtual void update(NLMISC::ICDBNode *node); - void createObservers(const TNodeVect &nodes); - void removeObservers(const TNodeVect &nodes); - // debug : check that there are as many targets as reference to a link - void checkNbRefs(); -}; +} #endif diff --git a/code/nel/include/nel/gui/interface_options.h b/code/nel/include/nel/gui/interface_options.h index 990f1ab19..7ca938140 100644 --- a/code/nel/include/nel/gui/interface_options.h +++ b/code/nel/include/nel/gui/interface_options.h @@ -28,70 +28,73 @@ namespace NL3D class UAnimationSet; } - -// *************************************************************************** -class CInterfaceOptionValue +namespace NLGUI { -public: - CInterfaceOptionValue() + + // *************************************************************************** + class CInterfaceOptionValue { - _Color= NLMISC::CRGBA::White; - _Int= 0; - _Float= 0; - _Boolean= false; - } + public: + CInterfaceOptionValue() + { + _Color= NLMISC::CRGBA::White; + _Int= 0; + _Float= 0; + _Boolean= false; + } - const std::string &getValStr () const {return _Str;} - sint32 getValSInt32() const {return _Int;} - float getValFloat () const {return _Float;} - NLMISC::CRGBA getValColor () const {return _Color;} - bool getValBool () const {return _Boolean;} + const std::string &getValStr () const {return _Str;} + sint32 getValSInt32() const {return _Int;} + float getValFloat () const {return _Float;} + NLMISC::CRGBA getValColor () const {return _Color;} + bool getValBool () const {return _Boolean;} - void init(const std::string &str); + void init(const std::string &str); - // returned when InterfaceOptions param not found - static const CInterfaceOptionValue NullValue; + // returned when InterfaceOptions param not found + static const CInterfaceOptionValue NullValue; -private: + private: - std::string _Str; - NLMISC::CRGBA _Color; - sint32 _Int; - float _Float; - bool _Boolean; -}; + std::string _Str; + NLMISC::CRGBA _Color; + sint32 _Int; + float _Float; + bool _Boolean; + }; -// *************************************************************************** -class CInterfaceOptions : public NLMISC::CRefCount -{ + // *************************************************************************** + class CInterfaceOptions : public NLMISC::CRefCount + { -public: + public: - CInterfaceOptions(); - virtual ~CInterfaceOptions(); + CInterfaceOptions(); + virtual ~CInterfaceOptions(); - virtual bool parse (xmlNodePtr cur); + virtual bool parse (xmlNodePtr cur); - // return NullValue if param not found - const CInterfaceOptionValue &getValue(const std::string &sParamName) const; + // return NullValue if param not found + const CInterfaceOptionValue &getValue(const std::string &sParamName) const; - // shortcuts to getValue(paramName).getValXXX() - const std::string &getValStr (const std::string &sParamName) const; - sint32 getValSInt32 (const std::string &sParamName) const; - float getValFloat (const std::string &sParamName) const; - NLMISC::CRGBA getValColor (const std::string &sParamName) const; - bool getValBool (const std::string &sParamName) const; + // shortcuts to getValue(paramName).getValXXX() + const std::string &getValStr (const std::string &sParamName) const; + sint32 getValSInt32 (const std::string &sParamName) const; + float getValFloat (const std::string &sParamName) const; + NLMISC::CRGBA getValColor (const std::string &sParamName) const; + bool getValBool (const std::string &sParamName) const; - // copy basic map only from other CInterfaceOptions (non virtual method) - void copyBasicMap(const CInterfaceOptions &other); + // copy basic map only from other CInterfaceOptions (non virtual method) + void copyBasicMap(const CInterfaceOptions &other); -protected: + protected: - std::map _ParamValue; + std::map _ParamValue; -}; + }; +} #endif // NL_INTERFACE_LAYER_H diff --git a/code/nel/include/nel/gui/view_base.h b/code/nel/include/nel/gui/view_base.h index e8ab73680..db214b772 100644 --- a/code/nel/include/nel/gui/view_base.h +++ b/code/nel/include/nel/gui/view_base.h @@ -23,59 +23,63 @@ #include "nel/misc/factory.h" #include "nel/gui/interface_element.h" -class CViewBase : public CInterfaceElement +namespace NLGUI { -public: - // for factory construction - struct TCtorParam - {}; - - /// Constructor - CViewBase(const TCtorParam &/* param */) : CInterfaceElement() + class CViewBase : public CInterfaceElement { - } + public: - /// Destructor - virtual ~CViewBase(); + // for factory construction + struct TCtorParam + {}; - // Returns 'true' if that element can be downcasted to a view - virtual bool isView() const { return true; } + /// Constructor + CViewBase(const TCtorParam &/* param */) : CInterfaceElement() + { + } - /// Draw the view from XReal, YReal, WReal, HReal (implemented by derived classes) - /// this coordinates are relative to the screen bottom left and begins the bottom left of the view - virtual void draw () = 0; + /// Destructor + virtual ~CViewBase(); - virtual void updateCoords() { CInterfaceElement::updateCoords(); } + // Returns 'true' if that element can be downcasted to a view + virtual bool isView() const { return true; } - /// Debug - virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + /// Draw the view from XReal, YReal, WReal, HReal (implemented by derived classes) + /// this coordinates are relative to the screen bottom left and begins the bottom left of the view + virtual void draw () = 0; - /// Reflection - virtual sint32 getAlpha() const { return -1; } // Not obliged to implement this - virtual void setAlpha (sint32 /* a */) {} // Not obliged to implement this + virtual void updateCoords() { CInterfaceElement::updateCoords(); } + + /// Debug + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + + /// Reflection + virtual sint32 getAlpha() const { return -1; } // Not obliged to implement this + virtual void setAlpha (sint32 /* a */) {} // Not obliged to implement this - void copyOptionFrom(const CViewBase &other) - { - CInterfaceElement::copyOptionFrom(other); - } + void copyOptionFrom(const CViewBase &other) + { + CInterfaceElement::copyOptionFrom(other); + } - REFLECT_EXPORT_START(CViewBase, CInterfaceElement) - REFLECT_SINT32 ("alpha", getAlpha, setAlpha); - REFLECT_EXPORT_END + REFLECT_EXPORT_START(CViewBase, CInterfaceElement) + REFLECT_SINT32 ("alpha", getAlpha, setAlpha); + REFLECT_EXPORT_END - virtual void dumpSize(uint depth = 0) const; + virtual void dumpSize(uint depth = 0) const; - // from CInterfaceElement - virtual void visit(CInterfaceElementVisitor *visitor); + // from CInterfaceElement + virtual void visit(CInterfaceElementVisitor *visitor); - // special for mouse over : return true and fill the name of the cursor to display - virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; } + // special for mouse over : return true and fill the name of the cursor to display + virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; } -}; + }; +} #endif // RZ_VIEW_BASE_H diff --git a/code/nel/include/nel/gui/view_pointer_base.h b/code/nel/include/nel/gui/view_pointer_base.h index 341ab4259..bcc38fea4 100644 --- a/code/nel/include/nel/gui/view_pointer_base.h +++ b/code/nel/include/nel/gui/view_pointer_base.h @@ -1,55 +1,77 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + #ifndef VIEW_POINTER_BASE_H #define VIEW_POINTER_BASE_H #include "nel/gui/view_base.h" -class CViewPointerBase : public CViewBase +namespace NLGUI { -public: - DECLARE_UI_CLASS( CViewPointerBase ) - CViewPointerBase( const TCtorParam ¶m ); - virtual ~CViewPointerBase(); + class CViewPointerBase : public CViewBase + { + public: + DECLARE_UI_CLASS( CViewPointerBase ) - // Set the pointer position. - void setPointerPos (sint32 x, sint32 y); - void setPointerDispPos (sint32 x, sint32 y); + CViewPointerBase( const TCtorParam ¶m ); + virtual ~CViewPointerBase(); - void resetPointerPos (); - void setPointerDown (bool pd); - void setPointerDownString (const std::string &s); + // Set the pointer position. + void setPointerPos (sint32 x, sint32 y); + void setPointerDispPos (sint32 x, sint32 y); - void getPointerPos (sint32 &x, sint32 &y); - void getPointerDispPos (sint32 &x, sint32 &y); + void resetPointerPos (); + void setPointerDown (bool pd); + void setPointerDownString (const std::string &s); - void getPointerOldPos (sint32 &x, sint32 &y); - void getPointerDownPos (sint32 &x, sint32 &y); - bool getPointerDown (); - std::string getPointerDownString (); - bool getPointerDrag (); + void getPointerPos (sint32 &x, sint32 &y); + void getPointerDispPos (sint32 &x, sint32 &y); - /// Is the pointer visible ? - bool show() const {return _PointerVisible;} + void getPointerOldPos (sint32 &x, sint32 &y); + void getPointerDownPos (sint32 &x, sint32 &y); + bool getPointerDown (); + std::string getPointerDownString (); + bool getPointerDrag (); - void draw(){} + /// Is the pointer visible ? + bool show() const {return _PointerVisible;} -protected: - // (x,y) is from the TopLeft corner of the window - sint32 _PointerX; // Current pointer position (raw, before snapping) - sint32 _PointerY; - sint32 _PointerOldX; // Previous frame pointer position - sint32 _PointerOldY; - bool _PointerDown; // Is the pointer down ? - sint32 _PointerDownX; // Pointer down position - sint32 _PointerDownY; - std::string _PointerDownString; // What is under the pointer at the down position - bool _PointerDrag; // Is the pointer down and we have moved ? - bool _PointerVisible; // Is the pointer visible or hidden ? + void draw(){} -private: + protected: + // (x,y) is from the TopLeft corner of the window + sint32 _PointerX; // Current pointer position (raw, before snapping) + sint32 _PointerY; + sint32 _PointerOldX; // Previous frame pointer position + sint32 _PointerOldY; + bool _PointerDown; // Is the pointer down ? + sint32 _PointerDownX; // Pointer down position + sint32 _PointerDownY; + std::string _PointerDownString; // What is under the pointer at the down position + bool _PointerDrag; // Is the pointer down and we have moved ? + bool _PointerVisible; // Is the pointer visible or hidden ? + + private: -}; + }; + +} #endif diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index cf2716eed..9145f66c4 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -23,314 +23,319 @@ #include "nel/misc/types_nl.h" #include "nel/gui/interface_common.h" -class CInterfaceElement; -class CCtrlBase; -class CViewBase; -class CInterfaceGroup; -class CViewPointerBase; -class CInterfaceOptions; - namespace NLMISC { class CCDBNodeLeaf; } -class IParser +namespace NLGUI { -public: - virtual void addParentPositionAssociation( CInterfaceElement *element, const std::string &parentID ) = 0; - virtual void addParentSizeAssociation( CInterfaceElement *element, const std::string &parentID ) = 0; - virtual void addParentSizeMaxAssociation( CInterfaceElement *element, const std::string &parentID ) = 0; - virtual void addLuaClassAssociation( CInterfaceGroup *group, const std::string &luaScript ) = 0; -}; -/// Manages the GUI widgets -class CWidgetManager{ -public: + class CInterfaceElement; + class CCtrlBase; + class CViewBase; + class CInterfaceGroup; + class CViewPointerBase; + class CInterfaceOptions; - // Master groups encapsulate all windows - struct SMasterGroup + class IParser { - SMasterGroup() - { - Group = NULL; - LastTopWindowPriority = WIN_PRIORITY_NORMAL; - } - - CInterfaceGroup *Group; - std::list< CInterfaceGroup* > PrioritizedWindows[ WIN_PRIORITY_MAX ]; - - void addWindow( CInterfaceGroup *pIG, uint8 nPrio = WIN_PRIORITY_NORMAL ); - void delWindow( CInterfaceGroup *pIG ); - CInterfaceGroup *getWindowFromId( const std::string &winID ); - bool isWindowPresent( CInterfaceGroup *pIG ); - // Set a window top in its priority queue - void setTopWindow( CInterfaceGroup *pIG ); - void setBackWindow( CInterfaceGroup *pIG ); - void deactiveAllContainers(); - void centerAllContainers(); - void unlockAllContainers(); - - // Sort the world space group - void sortWorldSpaceGroup (); - - uint8 LastTopWindowPriority; + public: + virtual void addParentPositionAssociation( CInterfaceElement *element, const std::string &parentID ) = 0; + virtual void addParentSizeAssociation( CInterfaceElement *element, const std::string &parentID ) = 0; + virtual void addParentSizeMaxAssociation( CInterfaceElement *element, const std::string &parentID ) = 0; + virtual void addLuaClassAssociation( CInterfaceGroup *group, const std::string &luaScript ) = 0; }; + /// Manages the GUI widgets + class CWidgetManager{ + public: - // Infos about a modal window. - struct SModalWndInfo - { - // Yoyo: store as CRefPtr in case they are deleted (can happen for instance if menu right click on a guild memeber, and guild members are udpated after) - NLMISC::CRefPtr< CInterfaceGroup > ModalWindow; // the current modal window - NLMISC::CRefPtr< CCtrlBase > CtrlLaunchingModal; - bool ModalClip; - bool ModalExitClickOut; - bool ModalExitClickL; - bool ModalExitClickR; - bool ModalExitKeyPushed; - std::string ModalHandlerClickOut; - std::string ModalClickOutParams; - - SModalWndInfo() + // Master groups encapsulate all windows + struct SMasterGroup { - ModalWindow = NULL; - CtrlLaunchingModal = NULL; - ModalExitClickOut = false; - ModalExitClickL = false; - ModalExitClickR = false; - ModalExitKeyPushed = false; + SMasterGroup() + { + Group = NULL; + LastTopWindowPriority = WIN_PRIORITY_NORMAL; + } + + CInterfaceGroup *Group; + std::list< CInterfaceGroup* > PrioritizedWindows[ WIN_PRIORITY_MAX ]; + + void addWindow( CInterfaceGroup *pIG, uint8 nPrio = WIN_PRIORITY_NORMAL ); + void delWindow( CInterfaceGroup *pIG ); + CInterfaceGroup *getWindowFromId( const std::string &winID ); + bool isWindowPresent( CInterfaceGroup *pIG ); + // Set a window top in its priority queue + void setTopWindow( CInterfaceGroup *pIG ); + void setBackWindow( CInterfaceGroup *pIG ); + void deactiveAllContainers(); + void centerAllContainers(); + void unlockAllContainers(); + + // Sort the world space group + void sortWorldSpaceGroup (); + + uint8 LastTopWindowPriority; + }; + + + // Infos about a modal window. + struct SModalWndInfo + { + // Yoyo: store as CRefPtr in case they are deleted (can happen for instance if menu right click on a guild memeber, and guild members are udpated after) + NLMISC::CRefPtr< CInterfaceGroup > ModalWindow; // the current modal window + NLMISC::CRefPtr< CCtrlBase > CtrlLaunchingModal; + bool ModalClip; + bool ModalExitClickOut; + bool ModalExitClickL; + bool ModalExitClickR; + bool ModalExitKeyPushed; + std::string ModalHandlerClickOut; + std::string ModalClickOutParams; + + SModalWndInfo() + { + ModalWindow = NULL; + CtrlLaunchingModal = NULL; + ModalExitClickOut = false; + ModalExitClickL = false; + ModalExitClickR = false; + ModalExitKeyPushed = false; + } + }; + + + static CWidgetManager* getInstance(); + static void release(); + + CInterfaceGroup* getMasterGroupFromId( const std::string &MasterGroupName ); + std::vector< SMasterGroup > &getAllMasterGroup(){ return _MasterGroups; } + SMasterGroup& getMasterGroup( uint8 i ) { return _MasterGroups[ i ]; } + CInterfaceGroup* getWindowFromId( const std::string &groupId ); + void addWindowToMasterGroup( const std::string &sMasterGroupName, CInterfaceGroup *pIG ); + void removeWindowFromMasterGroup( const std::string &sMasterGroupName, CInterfaceGroup *pIG ); + void removeAllMasterGroups(); + + void activateMasterGroup (const std::string &sMasterGroupName, bool bActive); + + CInterfaceElement* getElementFromId( const std::string &sEltId ); + CInterfaceElement* getElementFromId( const std::string &sStart, const std::string &sEltId ); + + /// Get the window from an element (ui:interface:###) + CInterfaceGroup* getWindow(CInterfaceElement*); + + + /** + * set the top window + * \param win : pointer to the window to be set on top + */ + void setTopWindow (CInterfaceGroup *pWin); + + /** + * set the back window + * \param win : pointer to the window to be set on top + */ + void setBackWindow (CInterfaceGroup *pWin); + + /** get the top window in the first activated masterGroup + */ + CInterfaceGroup* getTopWindow (uint8 nPriority = WIN_PRIORITY_NORMAL) const; + + /** get the back window in the first activated masterGroup + */ + CInterfaceGroup* getBackWindow (uint8 nPriority = WIN_PRIORITY_NORMAL) const; + + /** get the last escapable top window in the first activated masterGroup + */ + CInterfaceGroup* getLastEscapableTopWindow() const; + + void setWindowPriority (CInterfaceGroup *pWin, uint8 nPriority); + + /** return the priority of the Last Window setTopWindow()-ed. + */ + uint8 getLastTopWindowPriority() const; + + bool hasModal() const; + + SModalWndInfo& getModal(); + + bool isPreviousModal( CInterfaceGroup *wnd ) const; + + void enableModalWindow (CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG); + void enableModalWindow (CCtrlBase *ctrlLaunchingModal, const std::string &groupName); + // Disable all modals windows + void disableModalWindow (); + + /** Push a modal window that becomes the current modal window + */ + void pushModalWindow(CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG); + void pushModalWindow (CCtrlBase *ctrlLaunchingModal, const std::string &groupName); + void popModalWindow(); + // pop all top modal windows with the given category (a string stored in the modal) + void popModalWindowCategory(const std::string &category); + + CCtrlBase *getCtrlLaunchingModal () + { + if (_ModalStack.empty()) return NULL; + return _ModalStack.back().CtrlLaunchingModal; } + /// get the currently active modal window, or NULL if none + CInterfaceGroup *getModalWindow() const + { + if (_ModalStack.empty()) return NULL; + return _ModalStack.back().ModalWindow; + } + + void setCurContextHelp( CCtrlBase *curContextHelp ){ this->curContextHelp = curContextHelp; } + CCtrlBase* getCurContextHelp(){ return curContextHelp; } + + float _DeltaTimeStopingContextHelp; + + CViewPointerBase* getPointer(){ return _Pointer; } + void setPointer( CViewPointerBase *pointer ){ _Pointer = pointer; } + + /** + * get the window under a spot + * \param : X coord of the spot + * \param : Y coord of the spot + * \return : pointer to the window + */ + CInterfaceGroup* getWindowUnder (sint32 x, sint32 y); + CInterfaceGroup* getCurrentWindowUnder() { return _WindowUnder; } + void setCurrentWindowUnder( CInterfaceGroup *group ){ _WindowUnder = group; } + CInterfaceGroup* getGroupUnder (sint32 x, sint32 y); + + void getViewsUnder( sint32 x, sint32 y, std::vector< CViewBase* > &vVB ); + void getCtrlsUnder( sint32 x, sint32 y, std::vector< CCtrlBase* > &vICL ); + void getGroupsUnder (sint32 x, sint32 y, std::vector< CInterfaceGroup* > &vIGL ); + + const std::vector< CViewBase* >& getViewsUnderPointer(){ return _ViewsUnderPointer; } + const std::vector< CInterfaceGroup* >& getGroupsUnderPointer() { return _GroupsUnderPointer; } + const std::vector< CCtrlBase* >& getCtrlsUnderPointer() { return _CtrlsUnderPointer; } + + // + void clearViewUnders(){ _ViewsUnderPointer.clear(); } + void clearGroupsUnders() { _GroupsUnderPointer.clear(); } + void clearCtrlsUnders() { _CtrlsUnderPointer.clear(); } + + // Remove all references on a view (called when the ctrl is destroyed) + void removeRefOnView( CViewBase *ctrlBase ); + + // Remove all references on a ctrl (called when the ctrl is destroyed) + void removeRefOnCtrl (CCtrlBase *ctrlBase); + + // Remove all references on a group (called when the group is destroyed) + void removeRefOnGroup (CInterfaceGroup *group); + + void reset(); + + void checkCoords(); + // Relative move of pointer + void movePointer (sint32 dx, sint32 dy); + // Set absolute coordinates of pointer + void movePointerAbs(sint32 px, sint32 py); + + /** + * Capture + */ + CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; } + CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; } + CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; } + CCtrlBase *getOldCaptureKeyboard() { return _OldCaptureKeyboard; } + CCtrlBase *getDefaultCaptureKeyboard() { return _DefaultCaptureKeyboard; } + + void setCapturePointerLeft(CCtrlBase *c); + void setCapturePointerRight(CCtrlBase *c); + void setOldCaptureKeyboard(CCtrlBase *c){ _OldCaptureKeyboard = c; } + // NB: setCaptureKeyboard(NULL) has not the same effect as resetCaptureKeyboard(). it allows the capture + // to come back to the last captured window (resetCaptureKeyboard() not) + void setCaptureKeyboard(CCtrlBase *c); + /** Set the default box to use when no keyboard has been previously captured + * The given dialog should be static + */ + void setDefaultCaptureKeyboard(CCtrlBase *c){ _DefaultCaptureKeyboard = c; } + + void resetCaptureKeyboard(); + + // True if the keyboard is captured + bool isKeyboardCaptured() const {return _CaptureKeyboard!=NULL;} + + // register a view that wants to be notified at each frame (receive the msg 'clocktick') + void registerClockMsgTarget(CCtrlBase *vb); + void unregisterClockMsgTarget(CCtrlBase *vb); + bool isClockMsgTarget(CCtrlBase *vb) const; + void sendClockTickEvent(); + + void notifyElementCaptured(CCtrlBase *c); + + // Add a group into the windows list of its master goup + void makeWindow( CInterfaceGroup *group ); + + // Remove a group from the windows list of its master group + void unMakeWindow( CInterfaceGroup *group, bool noWarning = false ); + + void setGlobalColor( NLMISC::CRGBA col ); + NLMISC::CRGBA getGlobalColor() const{ return _GlobalColor; } + + void setContentAlpha( uint8 alpha ); + uint8 getContentAlpha() const{ return _ContentAlpha; } + + NLMISC::CRGBA getGlobalColorForContent() const { return _GlobalColorForContent; } + void setGlobalColorForContent( NLMISC::CRGBA col ){ _GlobalColorForContent = col; } + void resetColorProps(); + + /// Get options by name + CInterfaceOptions* getOptions( const std::string &optName ); + void addOptions( std::string name, CInterfaceOptions *options ); + void removeOptions( std::string name ); + void removeAllOptions(); + + static IParser *parser; + + private: + CWidgetManager(); + ~CWidgetManager(); + + static CWidgetManager *instance; + std::vector< SMasterGroup > _MasterGroups; + std::vector< SModalWndInfo > _ModalStack; + static std::string _CtrlLaunchingModalId; + NLMISC::CRefPtr< CCtrlBase > curContextHelp; + CViewPointerBase *_Pointer; + + // Options description + std::map< std::string, NLMISC::CSmartPtr< CInterfaceOptions > > _OptionsMap; + + NLMISC::CRefPtr< CInterfaceGroup > _WindowUnder; + + // Capture + NLMISC::CRefPtr _CaptureKeyboard; + NLMISC::CRefPtr _OldCaptureKeyboard; + NLMISC::CRefPtr _DefaultCaptureKeyboard; + NLMISC::CRefPtr _CapturePointerLeft; + NLMISC::CRefPtr _CapturePointerRight; + + // What is under pointer + std::vector< CViewBase* > _ViewsUnderPointer; + std::vector< CCtrlBase* > _CtrlsUnderPointer; + std::vector< CInterfaceGroup* > _GroupsUnderPointer; + + // view that should be notified from clock msg + std::vector _ClockMsgTargets; + + NLMISC::CRGBA _GlobalColor; + NLMISC::CRGBA _GlobalColorForContent; + uint8 _ContentAlpha; + + NLMISC::CCDBNodeLeaf *_RProp; + NLMISC::CCDBNodeLeaf *_GProp; + NLMISC::CCDBNodeLeaf *_BProp; + NLMISC::CCDBNodeLeaf *_AProp; }; - - static CWidgetManager* getInstance(); - static void release(); - - CInterfaceGroup* getMasterGroupFromId( const std::string &MasterGroupName ); - std::vector< SMasterGroup > &getAllMasterGroup(){ return _MasterGroups; } - SMasterGroup& getMasterGroup( uint8 i ) { return _MasterGroups[ i ]; } - CInterfaceGroup* getWindowFromId( const std::string &groupId ); - void addWindowToMasterGroup( const std::string &sMasterGroupName, CInterfaceGroup *pIG ); - void removeWindowFromMasterGroup( const std::string &sMasterGroupName, CInterfaceGroup *pIG ); - void removeAllMasterGroups(); - - void activateMasterGroup (const std::string &sMasterGroupName, bool bActive); - - CInterfaceElement* getElementFromId( const std::string &sEltId ); - CInterfaceElement* getElementFromId( const std::string &sStart, const std::string &sEltId ); - - /// Get the window from an element (ui:interface:###) - CInterfaceGroup* getWindow(CInterfaceElement*); - - - /** - * set the top window - * \param win : pointer to the window to be set on top - */ - void setTopWindow (CInterfaceGroup *pWin); - - /** - * set the back window - * \param win : pointer to the window to be set on top - */ - void setBackWindow (CInterfaceGroup *pWin); - - /** get the top window in the first activated masterGroup - */ - CInterfaceGroup* getTopWindow (uint8 nPriority = WIN_PRIORITY_NORMAL) const; - - /** get the back window in the first activated masterGroup - */ - CInterfaceGroup* getBackWindow (uint8 nPriority = WIN_PRIORITY_NORMAL) const; - - /** get the last escapable top window in the first activated masterGroup - */ - CInterfaceGroup* getLastEscapableTopWindow() const; - - void setWindowPriority (CInterfaceGroup *pWin, uint8 nPriority); - - /** return the priority of the Last Window setTopWindow()-ed. - */ - uint8 getLastTopWindowPriority() const; - - bool hasModal() const; - - SModalWndInfo& getModal(); - - bool isPreviousModal( CInterfaceGroup *wnd ) const; - - void enableModalWindow (CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG); - void enableModalWindow (CCtrlBase *ctrlLaunchingModal, const std::string &groupName); - // Disable all modals windows - void disableModalWindow (); - - /** Push a modal window that becomes the current modal window - */ - void pushModalWindow(CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG); - void pushModalWindow (CCtrlBase *ctrlLaunchingModal, const std::string &groupName); - void popModalWindow(); - // pop all top modal windows with the given category (a string stored in the modal) - void popModalWindowCategory(const std::string &category); - - CCtrlBase *getCtrlLaunchingModal () - { - if (_ModalStack.empty()) return NULL; - return _ModalStack.back().CtrlLaunchingModal; - } - /// get the currently active modal window, or NULL if none - CInterfaceGroup *getModalWindow() const - { - if (_ModalStack.empty()) return NULL; - return _ModalStack.back().ModalWindow; - } - - void setCurContextHelp( CCtrlBase *curContextHelp ){ this->curContextHelp = curContextHelp; } - CCtrlBase* getCurContextHelp(){ return curContextHelp; } - - float _DeltaTimeStopingContextHelp; - - CViewPointerBase* getPointer(){ return _Pointer; } - void setPointer( CViewPointerBase *pointer ){ _Pointer = pointer; } - - /** - * get the window under a spot - * \param : X coord of the spot - * \param : Y coord of the spot - * \return : pointer to the window - */ - CInterfaceGroup* getWindowUnder (sint32 x, sint32 y); - CInterfaceGroup* getCurrentWindowUnder() { return _WindowUnder; } - void setCurrentWindowUnder( CInterfaceGroup *group ){ _WindowUnder = group; } - CInterfaceGroup* getGroupUnder (sint32 x, sint32 y); - - void getViewsUnder( sint32 x, sint32 y, std::vector< CViewBase* > &vVB ); - void getCtrlsUnder( sint32 x, sint32 y, std::vector< CCtrlBase* > &vICL ); - void getGroupsUnder (sint32 x, sint32 y, std::vector< CInterfaceGroup* > &vIGL ); - - const std::vector< CViewBase* >& getViewsUnderPointer(){ return _ViewsUnderPointer; } - const std::vector< CInterfaceGroup* >& getGroupsUnderPointer() { return _GroupsUnderPointer; } - const std::vector< CCtrlBase* >& getCtrlsUnderPointer() { return _CtrlsUnderPointer; } - - // - void clearViewUnders(){ _ViewsUnderPointer.clear(); } - void clearGroupsUnders() { _GroupsUnderPointer.clear(); } - void clearCtrlsUnders() { _CtrlsUnderPointer.clear(); } - - // Remove all references on a view (called when the ctrl is destroyed) - void removeRefOnView( CViewBase *ctrlBase ); - - // Remove all references on a ctrl (called when the ctrl is destroyed) - void removeRefOnCtrl (CCtrlBase *ctrlBase); - - // Remove all references on a group (called when the group is destroyed) - void removeRefOnGroup (CInterfaceGroup *group); - - void reset(); - - void checkCoords(); - // Relative move of pointer - void movePointer (sint32 dx, sint32 dy); - // Set absolute coordinates of pointer - void movePointerAbs(sint32 px, sint32 py); - - /** - * Capture - */ - CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; } - CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; } - CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; } - CCtrlBase *getOldCaptureKeyboard() { return _OldCaptureKeyboard; } - CCtrlBase *getDefaultCaptureKeyboard() { return _DefaultCaptureKeyboard; } - - void setCapturePointerLeft(CCtrlBase *c); - void setCapturePointerRight(CCtrlBase *c); - void setOldCaptureKeyboard(CCtrlBase *c){ _OldCaptureKeyboard = c; } - // NB: setCaptureKeyboard(NULL) has not the same effect as resetCaptureKeyboard(). it allows the capture - // to come back to the last captured window (resetCaptureKeyboard() not) - void setCaptureKeyboard(CCtrlBase *c); - /** Set the default box to use when no keyboard has been previously captured - * The given dialog should be static - */ - void setDefaultCaptureKeyboard(CCtrlBase *c){ _DefaultCaptureKeyboard = c; } - - void resetCaptureKeyboard(); - - // True if the keyboard is captured - bool isKeyboardCaptured() const {return _CaptureKeyboard!=NULL;} - - // register a view that wants to be notified at each frame (receive the msg 'clocktick') - void registerClockMsgTarget(CCtrlBase *vb); - void unregisterClockMsgTarget(CCtrlBase *vb); - bool isClockMsgTarget(CCtrlBase *vb) const; - void sendClockTickEvent(); - - void notifyElementCaptured(CCtrlBase *c); - - // Add a group into the windows list of its master goup - void makeWindow( CInterfaceGroup *group ); - - // Remove a group from the windows list of its master group - void unMakeWindow( CInterfaceGroup *group, bool noWarning = false ); - - void setGlobalColor( NLMISC::CRGBA col ); - NLMISC::CRGBA getGlobalColor() const{ return _GlobalColor; } - - void setContentAlpha( uint8 alpha ); - uint8 getContentAlpha() const{ return _ContentAlpha; } - - NLMISC::CRGBA getGlobalColorForContent() const { return _GlobalColorForContent; } - void setGlobalColorForContent( NLMISC::CRGBA col ){ _GlobalColorForContent = col; } - void resetColorProps(); - - /// Get options by name - CInterfaceOptions* getOptions( const std::string &optName ); - void addOptions( std::string name, CInterfaceOptions *options ); - void removeOptions( std::string name ); - void removeAllOptions(); - - static IParser *parser; - -private: - CWidgetManager(); - ~CWidgetManager(); - - static CWidgetManager *instance; - std::vector< SMasterGroup > _MasterGroups; - std::vector< SModalWndInfo > _ModalStack; - static std::string _CtrlLaunchingModalId; - NLMISC::CRefPtr< CCtrlBase > curContextHelp; - CViewPointerBase *_Pointer; - - // Options description - std::map< std::string, NLMISC::CSmartPtr< CInterfaceOptions > > _OptionsMap; - - NLMISC::CRefPtr< CInterfaceGroup > _WindowUnder; - - // Capture - NLMISC::CRefPtr _CaptureKeyboard; - NLMISC::CRefPtr _OldCaptureKeyboard; - NLMISC::CRefPtr _DefaultCaptureKeyboard; - NLMISC::CRefPtr _CapturePointerLeft; - NLMISC::CRefPtr _CapturePointerRight; - - // What is under pointer - std::vector< CViewBase* > _ViewsUnderPointer; - std::vector< CCtrlBase* > _CtrlsUnderPointer; - std::vector< CInterfaceGroup* > _GroupsUnderPointer; - - // view that should be notified from clock msg - std::vector _ClockMsgTargets; - - NLMISC::CRGBA _GlobalColor; - NLMISC::CRGBA _GlobalColorForContent; - uint8 _ContentAlpha; - - NLMISC::CCDBNodeLeaf *_RProp; - NLMISC::CCDBNodeLeaf *_GProp; - NLMISC::CCDBNodeLeaf *_BProp; - NLMISC::CCDBNodeLeaf *_AProp; -}; +} #endif diff --git a/code/nel/src/gui/action_handler.cpp b/code/nel/src/gui/action_handler.cpp index 110fbb37c..be14aa5c5 100644 --- a/code/nel/src/gui/action_handler.cpp +++ b/code/nel/src/gui/action_handler.cpp @@ -25,684 +25,689 @@ using namespace std; using namespace NLMISC; -// ------------------------------------------------------------------------------------------------ -CAHManager *CAHManager::_GlobalInstance = NULL; -// ------------------------------------------------------------------------------------------------ - -// ------------------------------------------------------------------------------------------------ -static void skipBlankAtStart (string &start) +namespace NLGUI { - while (!start.empty()) - { - if ((start[0] == ' ' || start[0] == '\t' || start[0] == '\r' || start[0] == '\n')) - start = start.substr(1,start.size()); - else - break; - } -} -// ------------------------------------------------------------------------------------------------ -static void skipBlankAtEnd (string &end) -{ - while (!end.empty()) - { - if ((end[end.size()-1] == ' ' || end[end.size()-1] == '\t' || end[end.size()-1] == '\r' || end[end.size()-1] == '\n')) - end = end.substr(0,end.size()-1); - else - break; - } -} + // ------------------------------------------------------------------------------------------------ + CAHManager *CAHManager::_GlobalInstance = NULL; + // ------------------------------------------------------------------------------------------------ -// ------------------------------------------------------------------------------------------------ -std::string IActionHandler::getParam (const string &Params, const string &ParamName) -{ - string allparam = Params; - skipBlankAtStart (allparam); - string param = toLower (ParamName); - while (allparam.size() > 0) + // ------------------------------------------------------------------------------------------------ + static void skipBlankAtStart (string &start) { - std::string::size_type e = allparam.find('='); - if (e == std::string::npos || e == 0) break; - std::string::size_type p = allparam.find('|'); - string tmp = NLMISC::toLower(allparam.substr(0,e)); - skipBlankAtEnd(tmp); - if (tmp == param) + while (!start.empty()) { + if ((start[0] == ' ' || start[0] == '\t' || start[0] == '\r' || start[0] == '\n')) + start = start.substr(1,start.size()); + else + break; + } + } + + // ------------------------------------------------------------------------------------------------ + static void skipBlankAtEnd (string &end) + { + while (!end.empty()) + { + if ((end[end.size()-1] == ' ' || end[end.size()-1] == '\t' || end[end.size()-1] == '\r' || end[end.size()-1] == '\n')) + end = end.substr(0,end.size()-1); + else + break; + } + } + + // ------------------------------------------------------------------------------------------------ + std::string IActionHandler::getParam (const string &Params, const string &ParamName) + { + string allparam = Params; + skipBlankAtStart (allparam); + string param = toLower (ParamName); + while (allparam.size() > 0) + { + std::string::size_type e = allparam.find('='); + if (e == std::string::npos || e == 0) break; + std::string::size_type p = allparam.find('|'); + string tmp = NLMISC::toLower(allparam.substr(0,e)); + skipBlankAtEnd(tmp); + if (tmp == param) + { + string tmp2 = allparam.substr(e+1,p-e-1); + skipBlankAtStart(tmp2); + skipBlankAtEnd(tmp2); + return tmp2; + } + if (p == std::string::npos || p == 0) break; + allparam = allparam.substr(p+1,allparam.size()); + skipBlankAtStart (allparam); + } + return ""; + } + + // ------------------------------------------------------------------------------------------------ + void IActionHandler::getAllParams (const string &Params, vector< pair > &vAllParams) + { + string allparam = Params; + skipBlankAtStart (allparam); + while (allparam.size() > 0) + { + std::string::size_type e = allparam.find('='); + if (e == std::string::npos || e == 0) break; + std::string::size_type p = allparam.find('|'); + string tmp = NLMISC::toLower(allparam.substr(0,e)); + skipBlankAtEnd(tmp); + string tmp2 = allparam.substr(e+1,p-e-1); skipBlankAtStart(tmp2); skipBlankAtEnd(tmp2); - return tmp2; - } - if (p == std::string::npos || p == 0) break; - allparam = allparam.substr(p+1,allparam.size()); - skipBlankAtStart (allparam); - } - return ""; -} -// ------------------------------------------------------------------------------------------------ -void IActionHandler::getAllParams (const string &Params, vector< pair > &vAllParams) -{ - string allparam = Params; - skipBlankAtStart (allparam); - while (allparam.size() > 0) - { - std::string::size_type e = allparam.find('='); - if (e == std::string::npos || e == 0) break; - std::string::size_type p = allparam.find('|'); - string tmp = NLMISC::toLower(allparam.substr(0,e)); - skipBlankAtEnd(tmp); + vAllParams.push_back(pair(tmp,tmp2)); - string tmp2 = allparam.substr(e+1,p-e-1); - skipBlankAtStart(tmp2); - skipBlankAtEnd(tmp2); - - vAllParams.push_back(pair(tmp,tmp2)); - - if (p == std::string::npos || p == 0) break; - allparam = allparam.substr(p+1,allparam.size()); - skipBlankAtStart (allparam); - } -} - -// ------------------------------------------------------------------------------------------------ -IActionHandler* CAHManager::getAH(const std::string &name, std::string ¶ms) -{ - // Special AH form? - string::size_type i= name.find(':'); - if(i!=string::npos) - { - string ahName= name.substr(0, i); - params= name.substr(i+1); - return getActionHandler(ahName); - } - // standalone form - else - return getActionHandler(name); -} - -// ------------------------------------------------------------------------------------------------ -IActionHandler* CAHManager::getAH(const std::string &name, CStringShared ¶ms) -{ - // Special AH form? - string::size_type i= name.find(':'); - if(i!=string::npos) - { - string ahName= name.substr(0, i); - params= name.substr(i+1); - return getActionHandler(ahName); - } - // standalone form - else - return getActionHandler(name); -} - -// ------------------------------------------------------------------------------------------------ -void CAHManager::parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, std::string ¶mRet) -{ - CXMLAutoPtr prop; - - // Read the action handler and any param he defines - bool paramSpecifiedInAH= false; - if(ahId) - { - prop = (char*) xmlGetProp( cur, (xmlChar*)ahId ); - if (prop) - { - string ahVal= (const char*)prop; - if(ahVal.find(':')!= string::npos) - paramSpecifiedInAH= true; - ahRet = getAH(ahVal, paramRet); + if (p == std::string::npos || p == 0) break; + allparam = allparam.substr(p+1,allparam.size()); + skipBlankAtStart (allparam); } } - // Read parameter (if specified) - if(paramId) + // ------------------------------------------------------------------------------------------------ + IActionHandler* CAHManager::getAH(const std::string &name, std::string ¶ms) { - prop = (char*) xmlGetProp( cur, (xmlChar*)paramId ); - /* Precise stuff here (for legacy rules): - If the param is not specified in the ahId, then replace params. - But if it is specified, don't replace it if the prop is empty!! - Because this cause problems with template and parameter replacement. - */ - if ((const char *)prop && (!paramSpecifiedInAH || strlen((const char*)prop)>0) ) - paramRet = string((const char*)prop); - } -} - -void CAHManager::parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, CStringShared ¶mRet) -{ - CXMLAutoPtr prop; - - // Read the action handler and any param he defines - bool paramSpecifiedInAH= false; - if(ahId) - { - prop = (char*) xmlGetProp( cur, (xmlChar*)ahId ); - if (prop) + // Special AH form? + string::size_type i= name.find(':'); + if(i!=string::npos) { - string ahVal= (const char*)prop; - if(ahVal.find(':')!= string::npos) - paramSpecifiedInAH= true; - ahRet = getAH(ahVal, paramRet); + string ahName= name.substr(0, i); + params= name.substr(i+1); + return getActionHandler(ahName); + } + // standalone form + else + return getActionHandler(name); + } + + // ------------------------------------------------------------------------------------------------ + IActionHandler* CAHManager::getAH(const std::string &name, CStringShared ¶ms) + { + // Special AH form? + string::size_type i= name.find(':'); + if(i!=string::npos) + { + string ahName= name.substr(0, i); + params= name.substr(i+1); + return getActionHandler(ahName); + } + // standalone form + else + return getActionHandler(name); + } + + // ------------------------------------------------------------------------------------------------ + void CAHManager::parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, std::string ¶mRet) + { + CXMLAutoPtr prop; + + // Read the action handler and any param he defines + bool paramSpecifiedInAH= false; + if(ahId) + { + prop = (char*) xmlGetProp( cur, (xmlChar*)ahId ); + if (prop) + { + string ahVal= (const char*)prop; + if(ahVal.find(':')!= string::npos) + paramSpecifiedInAH= true; + ahRet = getAH(ahVal, paramRet); + } + } + + // Read parameter (if specified) + if(paramId) + { + prop = (char*) xmlGetProp( cur, (xmlChar*)paramId ); + /* Precise stuff here (for legacy rules): + If the param is not specified in the ahId, then replace params. + But if it is specified, don't replace it if the prop is empty!! + Because this cause problems with template and parameter replacement. + */ + if ((const char *)prop && (!paramSpecifiedInAH || strlen((const char*)prop)>0) ) + paramRet = string((const char*)prop); } } - // Read parameter (if specified) - if(paramId) + void CAHManager::parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, CStringShared ¶mRet) { - prop = (char*) xmlGetProp( cur, (xmlChar*)paramId ); - /* Precise stuff here (for legacy rules): - If the param is not specified in the ahId, then replace params. - But if it is specified, don't replace it if the prop is empty!! - Because this cause problems with template and parameter replacement. - */ - if ((const char *)prop && (!paramSpecifiedInAH || strlen((const char*)prop)>0) ) - paramRet = string((const char*)prop); - } -} + CXMLAutoPtr prop; -// ------------------------------------------------------------------------------------------------ -void CAHManager::runActionHandler (const string &ahCmdLine, CCtrlBase *pCaller, const string &ahUserParams) -{ - if (ahCmdLine.empty()) return; - - // Special AH form ("ah:params") ? - string::size_type i = ahCmdLine.find(':'); - string ahName; - string ahParams; - if(i!=string::npos) - { - ahName= ahCmdLine.substr(0, i); - ahParams= ahCmdLine.substr(i+1); - } - else - { - ahName= ahCmdLine; - } - - // Replace params if defined - if(!ahUserParams.empty()) - ahParams= ahUserParams; - - // Execute the action handler - map::iterator it = FactoryMap.find (ahName); - if (it == FactoryMap.end()) - { - nlwarning ("not found action handler : %s",ahName.c_str()); - return; - } - IActionHandler *pAH = it->second; - pAH->execute (pCaller, ahParams); - - // Quick Help - const string submitQuickHelp = "submit_quick_help"; - it = FactoryMap.find(submitQuickHelp); - if(it == FactoryMap.end()) - { - nlwarning ("not found action handler : %s", submitQuickHelp.c_str()); - return; - } - pAH = it->second; - const std::string event = ahName + ":" + ahParams; - pAH->execute(NULL, event); -} - -// ------------------------------------------------------------------------------------------------ -void CAHManager::runActionHandler (IActionHandler *pAH, CCtrlBase *pCaller, const std::string &Params) -{ - if (pAH == NULL) - { - nlwarning ("no action handler"); - return; - } - pAH->execute (pCaller, Params); - string AHName = CAHManager::getInstance()->getAHName(pAH); - - // Quick Help - const string submitQuickHelp = "submit_quick_help"; - map::iterator it = FactoryMap.find (AHName); - it = FactoryMap.find(submitQuickHelp); - if(it == FactoryMap.end()) - { - nlwarning ("not found action handler : %s", submitQuickHelp.c_str()); - return; - } - pAH = it->second; - const std::string event = AHName + ":" + Params; - pAH->execute(NULL, event); -} - - -// ------------------------------------------------------------------------------------------------ -class CAHSet : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - string dblink = getParam (Params, "dblink"); - string property = getParam (Params, "target_property"); - string propertyToEval = getParam (Params, "target"); - string expr = getParam (Params, "value"); - //nlinfo("set %s %s %s %s", dblink.c_str(), property.c_str(), propertyToEval.c_str(), expr.c_str()); - CInterfaceExprValue value; - if (CInterfaceExpr::eval(expr, value, NULL)) + // Read the action handler and any param he defines + bool paramSpecifiedInAH= false; + if(ahId) { - if (!dblink.empty()) + prop = (char*) xmlGetProp( cur, (xmlChar*)ahId ); + if (prop) { - // Do not allow Write on SERVER: or LOCAL: - static const std::string dbServer= "SERVER:"; - static const std::string dbLocal= "LOCAL:"; - static const std::string dbLocalR2= "LOCAL:R2"; - if( (0==dblink.compare(0, dbServer.size(), dbServer)) || - (0==dblink.compare(0, dbLocal.size(), dbLocal)) - ) - { - if (0!=dblink.compare(0, dbLocalR2.size(), dbLocalR2)) - { - //nlwarning("You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database"); - nlstop; - return; - } - } - - string dblinkeval; - CInterfaceExpr::unpackDBentry(dblink.c_str(), NULL, dblinkeval); - if (!value.toInteger()) - { - nlwarning(" expression doesn't evaluate to a numerical value"); - } - CInterfaceProperty ip; - - if (!value.toInteger()) - { - nlwarning(" expression doesn't evaluate to a numerical value"); - } - if (ip.link (dblinkeval.c_str())) - { - ip.setSInt64(value.getInteger()); - } + string ahVal= (const char*)prop; + if(ahVal.find(':')!= string::npos) + paramSpecifiedInAH= true; + ahRet = getAH(ahVal, paramRet); } + } - if (!propertyToEval.empty()) - { - CInterfaceExprValue res; - if (!CInterfaceExpr::eval(propertyToEval, res, NULL)) return; - res.toString(); - property = res.getString(); - } + // Read parameter (if specified) + if(paramId) + { + prop = (char*) xmlGetProp( cur, (xmlChar*)paramId ); + /* Precise stuff here (for legacy rules): + If the param is not specified in the ahId, then replace params. + But if it is specified, don't replace it if the prop is empty!! + Because this cause problems with template and parameter replacement. + */ + if ((const char *)prop && (!paramSpecifiedInAH || strlen((const char*)prop)>0) ) + paramRet = string((const char*)prop); + } + } + // ------------------------------------------------------------------------------------------------ + void CAHManager::runActionHandler (const string &ahCmdLine, CCtrlBase *pCaller, const string &ahUserParams) + { + if (ahCmdLine.empty()) return; - if (!property.empty()) - { - std::vector targets; - // find first enclosing group - CCtrlBase *currCtrl = pCaller; - CInterfaceGroup *ig = NULL; - while (currCtrl) - { - ig = dynamic_cast(currCtrl); - if (ig != NULL) break; - currCtrl = currCtrl->getParent(); - } - if (ig == NULL) - { - string elt = property.substr(0,property.rfind(':')); - CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(elt); - ig = dynamic_cast(pIE); - if (ig == NULL && pIE != NULL) - ig = pIE->getParent(); - } - - if (ig != NULL) - { - CInterfaceLink::splitLinkTargets(property, ig, targets); - for(uint k = 0; k < targets.size(); ++k) - { - if (targets[k].Elem) targets[k].affect(value); - } - } - } + // Special AH form ("ah:params") ? + string::size_type i = ahCmdLine.find(':'); + string ahName; + string ahParams; + if(i!=string::npos) + { + ahName= ahCmdLine.substr(0, i); + ahParams= ahCmdLine.substr(i+1); } else { - nlwarning(" Couldn't evaluate expression to affect, expr = %s", expr.c_str()); + ahName= ahCmdLine; } - } -}; -REGISTER_ACTION_HANDLER (CAHSet, "set"); + // Replace params if defined + if(!ahUserParams.empty()) + ahParams= ahUserParams; -// ------------------------------------------------------------------------------------------------ -class CAHCopy : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - string dbdst = getParam (Params, "dbdst"); - string dbsrc = getParam (Params, "dbsrc"); - CCDBNodeBranch *pNBdst = NLGUI::CDBManager::getInstance()->getDbBranch(dbdst); - CCDBNodeBranch *pNBsrc = NLGUI::CDBManager::getInstance()->getDbBranch(dbsrc); - - // Branch copy - - if ((pNBdst != NULL) && (pNBsrc != NULL)) + // Execute the action handler + map::iterator it = FactoryMap.find (ahName); + if (it == FactoryMap.end()) { - //nlinfo("copying from %s to %s",pNBsrc->getName()->c_str(), pNBdst->getName()->c_str()); + nlwarning ("not found action handler : %s",ahName.c_str()); + return; + } + IActionHandler *pAH = it->second; + pAH->execute (pCaller, ahParams); - // Parse all children of the src branch - uint nbLeaves = pNBsrc->countLeaves(); - for (uint i = 0; i < nbLeaves; ++i) + // Quick Help + const string submitQuickHelp = "submit_quick_help"; + it = FactoryMap.find(submitQuickHelp); + if(it == FactoryMap.end()) + { + nlwarning ("not found action handler : %s", submitQuickHelp.c_str()); + return; + } + pAH = it->second; + const std::string event = ahName + ":" + ahParams; + pAH->execute(NULL, event); + } + + // ------------------------------------------------------------------------------------------------ + void CAHManager::runActionHandler (IActionHandler *pAH, CCtrlBase *pCaller, const std::string &Params) + { + if (pAH == NULL) + { + nlwarning ("no action handler"); + return; + } + pAH->execute (pCaller, Params); + string AHName = CAHManager::getInstance()->getAHName(pAH); + + // Quick Help + const string submitQuickHelp = "submit_quick_help"; + map::iterator it = FactoryMap.find (AHName); + it = FactoryMap.find(submitQuickHelp); + if(it == FactoryMap.end()) + { + nlwarning ("not found action handler : %s", submitQuickHelp.c_str()); + return; + } + pAH = it->second; + const std::string event = AHName + ":" + Params; + pAH->execute(NULL, event); + } + + + // ------------------------------------------------------------------------------------------------ + class CAHSet : public IActionHandler + { + public: + virtual void execute (CCtrlBase *pCaller, const string &Params) + { + string dblink = getParam (Params, "dblink"); + string property = getParam (Params, "target_property"); + string propertyToEval = getParam (Params, "target"); + string expr = getParam (Params, "value"); + //nlinfo("set %s %s %s %s", dblink.c_str(), property.c_str(), propertyToEval.c_str(), expr.c_str()); + CInterfaceExprValue value; + if (CInterfaceExpr::eval(expr, value, NULL)) { - uint count = i; - CCDBNodeLeaf *pNLsrc = pNBsrc->findLeafAtCount(count); - // Find its access name - string sTmp = *pNLsrc->getName(); - CCDBNodeBranch *pParent = pNLsrc->getParent(); - while (pParent != pNBsrc) + if (!dblink.empty()) { - sTmp = *pParent->getName() + ":" + sTmp; - pParent = pParent->getParent(); - } - // Find the correspondant node in the dst branch - CCDBNodeLeaf *pNLdst = dynamic_cast(pNBdst->getNode(ICDBNode::CTextId(sTmp))); - if (pNLdst == NULL) - { - nlwarning ("cannot find destination leaf %s",sTmp.c_str()); - } - else - { - pNLdst->setValue64(pNLsrc->getValue64()); + // Do not allow Write on SERVER: or LOCAL: + static const std::string dbServer= "SERVER:"; + static const std::string dbLocal= "LOCAL:"; + static const std::string dbLocalR2= "LOCAL:R2"; + if( (0==dblink.compare(0, dbServer.size(), dbServer)) || + (0==dblink.compare(0, dbLocal.size(), dbLocal)) + ) + { + if (0!=dblink.compare(0, dbLocalR2.size(), dbLocalR2)) + { + //nlwarning("You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database"); + nlstop; + return; + } + } - //sint32 nVal = pNLsrc->getValue64(); - //nlinfo("set value %d for node %s", nVal, sTmp.c_str()); + string dblinkeval; + CInterfaceExpr::unpackDBentry(dblink.c_str(), NULL, dblinkeval); + if (!value.toInteger()) + { + nlwarning(" expression doesn't evaluate to a numerical value"); + } + CInterfaceProperty ip; + + if (!value.toInteger()) + { + nlwarning(" expression doesn't evaluate to a numerical value"); + } + if (ip.link (dblinkeval.c_str())) + { + ip.setSInt64(value.getInteger()); + } + } + + if (!propertyToEval.empty()) + { + CInterfaceExprValue res; + if (!CInterfaceExpr::eval(propertyToEval, res, NULL)) return; + res.toString(); + property = res.getString(); + } + + + if (!property.empty()) + { + std::vector targets; + // find first enclosing group + CCtrlBase *currCtrl = pCaller; + CInterfaceGroup *ig = NULL; + while (currCtrl) + { + ig = dynamic_cast(currCtrl); + if (ig != NULL) break; + currCtrl = currCtrl->getParent(); + } + if (ig == NULL) + { + string elt = property.substr(0,property.rfind(':')); + CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(elt); + ig = dynamic_cast(pIE); + if (ig == NULL && pIE != NULL) + ig = pIE->getParent(); + } + + if (ig != NULL) + { + CInterfaceLink::splitLinkTargets(property, ig, targets); + for(uint k = 0; k < targets.size(); ++k) + { + if (targets[k].Elem) targets[k].affect(value); + } + } } } - return; + else + { + nlwarning(" Couldn't evaluate expression to affect, expr = %s", expr.c_str()); + } } - - // Not branch copy so leaf copy - - CInterfaceProperty ipsrc; - CInterfaceProperty ipdst; - if (!ipsrc.link (dbsrc.c_str())) - { - nlwarning("cannot find leaf %s",dbsrc.c_str()); - return; - } - if (!ipdst.link (dbdst.c_str())) - { - nlwarning("cannot find leaf %s",dbdst.c_str()); - return; - } - // copy - ipdst.setSInt64 (ipsrc.getSInt64()); - } -}; -REGISTER_ACTION_HANDLER (CAHCopy, "copy"); + }; + REGISTER_ACTION_HANDLER (CAHSet, "set"); -// ------------------------------------------------------------------------------------------------ -class CAHResizeW : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &Params) + // ------------------------------------------------------------------------------------------------ + class CAHCopy : public IActionHandler { - string elt = getParam (Params, "elt"); - - sint32 value; - fromString(getParam(Params, "value"), value); - - sint32 limit; - fromString(getParam(Params, "limit"), limit); - - CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId (pCaller->getId(), elt); - if (pIE == NULL) return; - - sint32 newW = pIE->getW(); - newW += value; - if (value < 0) + public: + virtual void execute (CCtrlBase * /* pCaller */, const string &Params) { - if (newW < limit) - newW = limit; + string dbdst = getParam (Params, "dbdst"); + string dbsrc = getParam (Params, "dbsrc"); + CCDBNodeBranch *pNBdst = NLGUI::CDBManager::getInstance()->getDbBranch(dbdst); + CCDBNodeBranch *pNBsrc = NLGUI::CDBManager::getInstance()->getDbBranch(dbsrc); + + // Branch copy + + if ((pNBdst != NULL) && (pNBsrc != NULL)) + { + //nlinfo("copying from %s to %s",pNBsrc->getName()->c_str(), pNBdst->getName()->c_str()); + + // Parse all children of the src branch + uint nbLeaves = pNBsrc->countLeaves(); + for (uint i = 0; i < nbLeaves; ++i) + { + uint count = i; + CCDBNodeLeaf *pNLsrc = pNBsrc->findLeafAtCount(count); + // Find its access name + string sTmp = *pNLsrc->getName(); + CCDBNodeBranch *pParent = pNLsrc->getParent(); + while (pParent != pNBsrc) + { + sTmp = *pParent->getName() + ":" + sTmp; + pParent = pParent->getParent(); + } + // Find the correspondant node in the dst branch + CCDBNodeLeaf *pNLdst = dynamic_cast(pNBdst->getNode(ICDBNode::CTextId(sTmp))); + if (pNLdst == NULL) + { + nlwarning ("cannot find destination leaf %s",sTmp.c_str()); + } + else + { + pNLdst->setValue64(pNLsrc->getValue64()); + + //sint32 nVal = pNLsrc->getValue64(); + //nlinfo("set value %d for node %s", nVal, sTmp.c_str()); + } + } + return; + } + + // Not branch copy so leaf copy + + CInterfaceProperty ipsrc; + CInterfaceProperty ipdst; + if (!ipsrc.link (dbsrc.c_str())) + { + nlwarning("cannot find leaf %s",dbsrc.c_str()); + return; + } + if (!ipdst.link (dbdst.c_str())) + { + nlwarning("cannot find leaf %s",dbdst.c_str()); + return; + } + // copy + ipdst.setSInt64 (ipsrc.getSInt64()); } - else - { - if (newW > limit) - newW = limit; - } - pIE->setW (newW); - pIE->invalidateCoords(); - } -}; -REGISTER_ACTION_HANDLER (CAHResizeW, "resize_w"); + }; + REGISTER_ACTION_HANDLER (CAHCopy, "copy"); -//////////////////////////////// -// EDITION OF CONTAINER ALPHA // -//////////////////////////////// -// the container whose alpha is being edited -static CGroupContainerBase *AlphaChooserTarget = NULL; -static bool OldUseGlobalAlpha; -static uint8 OldContentAlpha; -static uint8 OldBgAlpha; -static uint8 OldRolloverAlphaBG; -static uint8 OldRolloverAlphaContent; - -// observer to change the container alpha -class CContainerAlphaObserver : public ICDBNode::IPropertyObserver -{ -public: - bool On; - enum TTargetAlpha { ContentAlpha = 0, BgAlpha, RolloverAlphaContent, RolloverAlphaBG }; - TTargetAlpha Target; - virtual void update(ICDBNode *node) + // ------------------------------------------------------------------------------------------------ + class CAHResizeW : public IActionHandler { - if (!On) return; - if (!AlphaChooserTarget) return; - CCDBNodeLeaf *leaf = safe_cast(node); - switch(Target) + public: + virtual void execute (CCtrlBase *pCaller, const string &Params) { - case ContentAlpha: AlphaChooserTarget->setContentAlpha((uint8) leaf->getValue32()); break; - case BgAlpha: AlphaChooserTarget->setContainerAlpha((uint8) leaf->getValue32()); break; - case RolloverAlphaContent: AlphaChooserTarget->setRolloverAlphaContent((uint8) (255 - (uint8) leaf->getValue32())); break; - case RolloverAlphaBG: AlphaChooserTarget->setRolloverAlphaContainer((uint8) (255 - (uint8) leaf->getValue32())); break; + string elt = getParam (Params, "elt"); + + sint32 value; + fromString(getParam(Params, "value"), value); + + sint32 limit; + fromString(getParam(Params, "limit"), limit); + + CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId (pCaller->getId(), elt); + if (pIE == NULL) return; + + sint32 newW = pIE->getW(); + newW += value; + if (value < 0) + { + if (newW < limit) + newW = limit; + } + else + { + if (newW > limit) + newW = limit; + } + pIE->setW (newW); + pIE->invalidateCoords(); } - } -}; + }; + REGISTER_ACTION_HANDLER (CAHResizeW, "resize_w"); + //////////////////////////////// + // EDITION OF CONTAINER ALPHA // + //////////////////////////////// + // the container whose alpha is being edited + static CGroupContainerBase *AlphaChooserTarget = NULL; + static bool OldUseGlobalAlpha; + static uint8 OldContentAlpha; + static uint8 OldBgAlpha; + static uint8 OldRolloverAlphaBG; + static uint8 OldRolloverAlphaContent; -// ------------------------------------------------------------------------------------------------ -class CAHChooseUIAlpha : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) + // observer to change the container alpha + class CContainerAlphaObserver : public ICDBNode::IPropertyObserver { - CGroupContainerBase *gc = NULL; - CCtrlBase *cb = pCaller; - while (cb) + public: + bool On; + enum TTargetAlpha { ContentAlpha = 0, BgAlpha, RolloverAlphaContent, RolloverAlphaBG }; + TTargetAlpha Target; + virtual void update(ICDBNode *node) { - gc = dynamic_cast(cb); - if (gc) break; - cb = cb->getParent(); + if (!On) return; + if (!AlphaChooserTarget) return; + CCDBNodeLeaf *leaf = safe_cast(node); + switch(Target) + { + case ContentAlpha: AlphaChooserTarget->setContentAlpha((uint8) leaf->getValue32()); break; + case BgAlpha: AlphaChooserTarget->setContainerAlpha((uint8) leaf->getValue32()); break; + case RolloverAlphaContent: AlphaChooserTarget->setRolloverAlphaContent((uint8) (255 - (uint8) leaf->getValue32())); break; + case RolloverAlphaBG: AlphaChooserTarget->setRolloverAlphaContainer((uint8) (255 - (uint8) leaf->getValue32())); break; + } } - if (!gc) return; - AlphaChooserTarget = gc; - if (!_AlphaObserversAdded) - { - _UiVariableBGAlpha = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_BG"); - _UiVariableContentAlpha = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_CONTENT"); - _UiVariableRolloverAlphaBG = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_ROLLOVER_BG"); - _UiVariableRolloverAlphaContent = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_ROLLOVER_CONTENT"); - ICDBNode::CTextId textIdBGAlpha, textIdContentAlpha, textIdRolloverAlphaBG, textIdRolloverAlphaContent; - _UiVariableBGAlpha->addObserver(&_BgAlphaObs, textIdBGAlpha); - _UiVariableContentAlpha->addObserver(&_ContentAlphaObs, textIdContentAlpha); - _UiVariableRolloverAlphaBG->addObserver(&_RolloverAlphaBGObs, textIdRolloverAlphaBG); - _UiVariableRolloverAlphaContent->addObserver(&_RolloverAlphaContentObs, textIdRolloverAlphaContent); - _AlphaObserversAdded = true; - } - // disable observers - _ContentAlphaObs.On = false; - _BgAlphaObs.On = false; - _RolloverAlphaBGObs.On = false; - _RolloverAlphaContentObs.On = false; - // set alpha of current chosen container - _UiVariableBGAlpha->setValue32(gc->getContainerAlpha()); - _UiVariableContentAlpha->setValue32(gc->getContentAlpha()); - _UiVariableRolloverAlphaBG->setValue32(255 - gc->getRolloverAlphaContainer()); - _UiVariableRolloverAlphaContent->setValue32(255 - gc->getRolloverAlphaContent()); - // enable observers - _ContentAlphaObs.On = true; - _BgAlphaObs.On = true; - _RolloverAlphaBGObs.On = true; - _RolloverAlphaContentObs.On = true; - // backup current alpha (if the user cancel) - OldContentAlpha = gc->getContentAlpha(); - OldBgAlpha = gc->getContainerAlpha(); - OldRolloverAlphaBG = gc->getRolloverAlphaContainer(); - OldRolloverAlphaContent = gc->getRolloverAlphaContent(); - OldUseGlobalAlpha = gc->isUsingGlobalAlpha(); - // Enable 'use global alpha' button - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER_ALPHA")->setValue64(gc->isUsingGlobalAlpha() ? 0 : 1); - // show the modal box - CWidgetManager::getInstance()->enableModalWindow(gc, "ui:interface:define_ui_transparency"); - - } + }; - CAHChooseUIAlpha() + + // ------------------------------------------------------------------------------------------------ + class CAHChooseUIAlpha : public IActionHandler { - _UiVariableContentAlpha = NULL; - _UiVariableBGAlpha = NULL; - _UiVariableRolloverAlphaBG = NULL; - _UiVariableRolloverAlphaContent = NULL; - _AlphaObserversAdded = false; - _BgAlphaObs.Target = CContainerAlphaObserver::BgAlpha; - _ContentAlphaObs.Target = CContainerAlphaObserver::ContentAlpha; - _RolloverAlphaBGObs.Target = CContainerAlphaObserver::RolloverAlphaBG; - _RolloverAlphaContentObs.Target = CContainerAlphaObserver::RolloverAlphaContent; - } -private: - // instance of observer to copy alpha from db to a container - CContainerAlphaObserver _ContentAlphaObs; - CContainerAlphaObserver _BgAlphaObs; - CContainerAlphaObserver _RolloverAlphaContentObs; - CContainerAlphaObserver _RolloverAlphaBGObs; - // flag to know if observer have been added - bool _AlphaObserversAdded; - // db leaf that contains alpha for the current container - CCDBNodeLeaf *_UiVariableContentAlpha; - CCDBNodeLeaf *_UiVariableBGAlpha; - CCDBNodeLeaf *_UiVariableRolloverAlphaContent; - CCDBNodeLeaf *_UiVariableRolloverAlphaBG; -}; -REGISTER_ACTION_HANDLER (CAHChooseUIAlpha, "choose_ui_alpha"); - -// ------------------------------------------------------------------------------------------------ -class CAHCancelChooseUIAlpha : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* Params */) - { - if (AlphaChooserTarget) + public: + virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) { - AlphaChooserTarget->setUseGlobalAlpha(OldUseGlobalAlpha); - AlphaChooserTarget->setContainerAlpha(OldBgAlpha); - AlphaChooserTarget->setContentAlpha(OldContentAlpha); - AlphaChooserTarget->setRolloverAlphaContainer(OldRolloverAlphaBG); - AlphaChooserTarget->setRolloverAlphaContent(OldRolloverAlphaContent); - } - } -}; -REGISTER_ACTION_HANDLER (CAHCancelChooseUIAlpha, "cancel_choose_ui_alpha"); + CGroupContainerBase *gc = NULL; + CCtrlBase *cb = pCaller; + while (cb) + { + gc = dynamic_cast(cb); + if (gc) break; + cb = cb->getParent(); + } + if (!gc) return; + AlphaChooserTarget = gc; + if (!_AlphaObserversAdded) + { + _UiVariableBGAlpha = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_BG"); + _UiVariableContentAlpha = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_CONTENT"); + _UiVariableRolloverAlphaBG = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_ROLLOVER_BG"); + _UiVariableRolloverAlphaContent = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:ALPHA_ROLLOVER_CONTENT"); + ICDBNode::CTextId textIdBGAlpha, textIdContentAlpha, textIdRolloverAlphaBG, textIdRolloverAlphaContent; + _UiVariableBGAlpha->addObserver(&_BgAlphaObs, textIdBGAlpha); + _UiVariableContentAlpha->addObserver(&_ContentAlphaObs, textIdContentAlpha); + _UiVariableRolloverAlphaBG->addObserver(&_RolloverAlphaBGObs, textIdRolloverAlphaBG); + _UiVariableRolloverAlphaContent->addObserver(&_RolloverAlphaContentObs, textIdRolloverAlphaContent); + _AlphaObserversAdded = true; + } + // disable observers + _ContentAlphaObs.On = false; + _BgAlphaObs.On = false; + _RolloverAlphaBGObs.On = false; + _RolloverAlphaContentObs.On = false; + // set alpha of current chosen container + _UiVariableBGAlpha->setValue32(gc->getContainerAlpha()); + _UiVariableContentAlpha->setValue32(gc->getContentAlpha()); + _UiVariableRolloverAlphaBG->setValue32(255 - gc->getRolloverAlphaContainer()); + _UiVariableRolloverAlphaContent->setValue32(255 - gc->getRolloverAlphaContent()); + // enable observers + _ContentAlphaObs.On = true; + _BgAlphaObs.On = true; + _RolloverAlphaBGObs.On = true; + _RolloverAlphaContentObs.On = true; + // backup current alpha (if the user cancel) + OldContentAlpha = gc->getContentAlpha(); + OldBgAlpha = gc->getContainerAlpha(); + OldRolloverAlphaBG = gc->getRolloverAlphaContainer(); + OldRolloverAlphaContent = gc->getRolloverAlphaContent(); + OldUseGlobalAlpha = gc->isUsingGlobalAlpha(); + // Enable 'use global alpha' button + NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER_ALPHA")->setValue64(gc->isUsingGlobalAlpha() ? 0 : 1); + // show the modal box + CWidgetManager::getInstance()->enableModalWindow(gc, "ui:interface:define_ui_transparency"); -// ------------------------------------------------------------------------------------------------ -class CAHUseGlobalAlphaSettings : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* Params */) - { - if (AlphaChooserTarget) + } + + + CAHChooseUIAlpha() { - AlphaChooserTarget->setUseGlobalAlpha(!AlphaChooserTarget->isUsingGlobalAlpha()); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER_ALPHA")->setValue64(AlphaChooserTarget->isUsingGlobalAlpha() ? 0 : 1); + _UiVariableContentAlpha = NULL; + _UiVariableBGAlpha = NULL; + _UiVariableRolloverAlphaBG = NULL; + _UiVariableRolloverAlphaContent = NULL; + _AlphaObserversAdded = false; + _BgAlphaObs.Target = CContainerAlphaObserver::BgAlpha; + _ContentAlphaObs.Target = CContainerAlphaObserver::ContentAlpha; + _RolloverAlphaBGObs.Target = CContainerAlphaObserver::RolloverAlphaBG; + _RolloverAlphaContentObs.Target = CContainerAlphaObserver::RolloverAlphaContent; } - } -}; -REGISTER_ACTION_HANDLER (CAHUseGlobalAlphaSettings, "use_global_alpha_settings"); + private: + // instance of observer to copy alpha from db to a container + CContainerAlphaObserver _ContentAlphaObs; + CContainerAlphaObserver _BgAlphaObs; + CContainerAlphaObserver _RolloverAlphaContentObs; + CContainerAlphaObserver _RolloverAlphaBGObs; + // flag to know if observer have been added + bool _AlphaObserversAdded; + // db leaf that contains alpha for the current container + CCDBNodeLeaf *_UiVariableContentAlpha; + CCDBNodeLeaf *_UiVariableBGAlpha; + CCDBNodeLeaf *_UiVariableRolloverAlphaContent; + CCDBNodeLeaf *_UiVariableRolloverAlphaBG; + }; + REGISTER_ACTION_HANDLER (CAHChooseUIAlpha, "choose_ui_alpha"); - -// ------------------------------------------------------------------------------------------------ -class CAHLockUnlock : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) + // ------------------------------------------------------------------------------------------------ + class CAHCancelChooseUIAlpha : public IActionHandler { - CGroupContainerBase *gc = NULL; - CCtrlBase *cb = pCaller; - while (cb) + virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* Params */) { - gc = dynamic_cast< CGroupContainerBase* >(cb); - if (gc) break; - cb = cb->getParent(); + if (AlphaChooserTarget) + { + AlphaChooserTarget->setUseGlobalAlpha(OldUseGlobalAlpha); + AlphaChooserTarget->setContainerAlpha(OldBgAlpha); + AlphaChooserTarget->setContentAlpha(OldContentAlpha); + AlphaChooserTarget->setRolloverAlphaContainer(OldRolloverAlphaBG); + AlphaChooserTarget->setRolloverAlphaContent(OldRolloverAlphaContent); + } } - if (!gc) return; - //gc->setMovable(!gc->isMovable()); - gc->setLocked(!gc->isLocked()); - } -}; -REGISTER_ACTION_HANDLER (CAHLockUnlock, "lock_unlock"); + }; + REGISTER_ACTION_HANDLER (CAHCancelChooseUIAlpha, "cancel_choose_ui_alpha"); -// ------------------------------------------------------------------------------------------------ -class CAHSetTransparent : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) + // ------------------------------------------------------------------------------------------------ + class CAHUseGlobalAlphaSettings : public IActionHandler { - CGroupContainerBase *pGC = dynamic_cast< CGroupContainerBase* >(CWidgetManager::getInstance()->getElementFromId(Params)); - if (pGC != NULL) + virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* Params */) { - pGC->setUseGlobalAlpha(false); - pGC->setContainerAlpha((uint8) 0); - pGC->setContentAlpha((uint8) 255); - pGC->setRolloverAlphaContainer((uint8) 255); - pGC->setRolloverAlphaContent((uint8) 0); + if (AlphaChooserTarget) + { + AlphaChooserTarget->setUseGlobalAlpha(!AlphaChooserTarget->isUsingGlobalAlpha()); + NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER_ALPHA")->setValue64(AlphaChooserTarget->isUsingGlobalAlpha() ? 0 : 1); + } } - } -}; -REGISTER_ACTION_HANDLER (CAHSetTransparent, "set_transparent"); + }; + REGISTER_ACTION_HANDLER (CAHUseGlobalAlphaSettings, "use_global_alpha_settings"); -// ------------------------------------------------------------------------------------------------ -class CAHSetAlpha : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) + + // ------------------------------------------------------------------------------------------------ + class CAHLockUnlock : public IActionHandler { - string ui = getParam (Params, "target"); - - uint8 alpha; - fromString(getParam (Params, "alpha"), alpha); - - CGroupContainerBase *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(ui)); - if (pGC != NULL) + virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) { - pGC->setUseGlobalAlpha(false); - pGC->setContainerAlpha((uint8) alpha); - pGC->setContentAlpha((uint8) 255); - pGC->setRolloverAlphaContainer((uint8) 0); - pGC->setRolloverAlphaContent((uint8) 0); + CGroupContainerBase *gc = NULL; + CCtrlBase *cb = pCaller; + while (cb) + { + gc = dynamic_cast< CGroupContainerBase* >(cb); + if (gc) break; + cb = cb->getParent(); + } + if (!gc) return; + //gc->setMovable(!gc->isMovable()); + gc->setLocked(!gc->isLocked()); } - } -}; -REGISTER_ACTION_HANDLER (CAHSetAlpha, "set_alpha"); + }; + REGISTER_ACTION_HANDLER (CAHLockUnlock, "lock_unlock"); -// ------------------------------------------------------------------------------------------------ -class CAHUnlockAllContainer : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) + // ------------------------------------------------------------------------------------------------ + class CAHSetTransparent : public IActionHandler { - const vector &rVMG = CWidgetManager::getInstance()->getAllMasterGroup(); - for (uint32 nMasterGroup = 0; nMasterGroup < rVMG.size(); nMasterGroup++) + virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) { -// const CInterfaceManager::SMasterGroup &rMG = rVMG[nMasterGroup]; - CWidgetManager::getInstance()->getMasterGroup((uint8)nMasterGroup).unlockAllContainers(); + CGroupContainerBase *pGC = dynamic_cast< CGroupContainerBase* >(CWidgetManager::getInstance()->getElementFromId(Params)); + if (pGC != NULL) + { + pGC->setUseGlobalAlpha(false); + pGC->setContainerAlpha((uint8) 0); + pGC->setContentAlpha((uint8) 255); + pGC->setRolloverAlphaContainer((uint8) 255); + pGC->setRolloverAlphaContent((uint8) 0); + } } - } -}; -REGISTER_ACTION_HANDLER (CAHUnlockAllContainer, "unlock_all_container"); + }; + REGISTER_ACTION_HANDLER (CAHSetTransparent, "set_transparent"); + + // ------------------------------------------------------------------------------------------------ + class CAHSetAlpha : public IActionHandler + { + virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) + { + string ui = getParam (Params, "target"); + + uint8 alpha; + fromString(getParam (Params, "alpha"), alpha); + + CGroupContainerBase *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(ui)); + if (pGC != NULL) + { + pGC->setUseGlobalAlpha(false); + pGC->setContainerAlpha((uint8) alpha); + pGC->setContentAlpha((uint8) 255); + pGC->setRolloverAlphaContainer((uint8) 0); + pGC->setRolloverAlphaContent((uint8) 0); + } + } + }; + REGISTER_ACTION_HANDLER (CAHSetAlpha, "set_alpha"); + + // ------------------------------------------------------------------------------------------------ + class CAHUnlockAllContainer : public IActionHandler + { + virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) + { + const vector &rVMG = CWidgetManager::getInstance()->getAllMasterGroup(); + for (uint32 nMasterGroup = 0; nMasterGroup < rVMG.size(); nMasterGroup++) + { + // const CInterfaceManager::SMasterGroup &rMG = rVMG[nMasterGroup]; + CWidgetManager::getInstance()->getMasterGroup((uint8)nMasterGroup).unlockAllContainers(); + } + } + }; + REGISTER_ACTION_HANDLER (CAHUnlockAllContainer, "unlock_all_container"); + +} \ No newline at end of file diff --git a/code/nel/src/gui/ctrl_base.cpp b/code/nel/src/gui/ctrl_base.cpp index 2577fba21..38871b286 100644 --- a/code/nel/src/gui/ctrl_base.cpp +++ b/code/nel/src/gui/ctrl_base.cpp @@ -24,200 +24,204 @@ using namespace NLMISC; -// *************************************************************************** -CCtrlBase::~CCtrlBase() +namespace NLGUI { - CWidgetManager::getInstance()->removeRefOnCtrl (this); -} -// *************************************************************************** -bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event) -{ - if (event.getType() == NLGUI::CEventDescriptor::system) + // *************************************************************************** + CCtrlBase::~CCtrlBase() { - NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; - if (eds.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::activecalledonparent) + CWidgetManager::getInstance()->removeRefOnCtrl (this); + } + + // *************************************************************************** + bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event) + { + if (event.getType() == NLGUI::CEventDescriptor::system) { - if (!((NLGUI::CEventDescriptorActiveCalledOnParent &) eds).getActive()) + NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; + if (eds.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::activecalledonparent) { - // the mouse capture should be lost when the ctrl is hidden - if (CWidgetManager::getInstance()->getCapturePointerLeft() == this) + if (!((NLGUI::CEventDescriptorActiveCalledOnParent &) eds).getActive()) { - CWidgetManager::getInstance()->setCapturePointerLeft(NULL); + // the mouse capture should be lost when the ctrl is hidden + if (CWidgetManager::getInstance()->getCapturePointerLeft() == this) + { + CWidgetManager::getInstance()->setCapturePointerLeft(NULL); + } + if (CWidgetManager::getInstance()->getCapturePointerRight() == this) + { + CWidgetManager::getInstance()->setCapturePointerRight(NULL); + } + // NB : don't call return here because derived class may be interested + // in handling event more speciffically } - if (CWidgetManager::getInstance()->getCapturePointerRight() == this) - { - CWidgetManager::getInstance()->setCapturePointerRight(NULL); - } - // NB : don't call return here because derived class may be interested - // in handling event more speciffically + } + } + return false; + } + + // *************************************************************************** + bool CCtrlBase::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) + { + if(!CViewBase::parse(cur, parentGroup)) + return false; + + CXMLAutoPtr prop; + + // get static toolTip + prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip" ); + if (prop) + { + const char *propPtr = prop; + + _ContextHelp = ucstring(propPtr); + + if (strlen(propPtr) > 2) + { + if ((propPtr[0] == 'u') && (propPtr[1] == 'i')) + _ContextHelp = CI18N::get ((const char *) prop); + } + } + // Force I18N tooltip + prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_i18n" ); + if ((bool)prop && strlen((const char*)prop)>0) + { + _ContextHelp = CI18N::get ((const char *) prop); + } + + // get dynamic toolTip ActionHandler + prop = (char*) xmlGetProp( cur, (xmlChar*)"on_tooltip" ); + if (prop) + { + _OnContextHelp= (const char*)prop; + } + prop = (char*) xmlGetProp( cur, (xmlChar*)"on_tooltip_params" ); + if (prop) + { + _OnContextHelpParams= (const char*)prop; + } + + // Tooltip parent + prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_parent" ); + _ToolTipParent= TTCtrl; + if(prop) + { + if(stricmp((const char*)prop, "win")==0) + _ToolTipParent= TTWindow; + else if(stricmp((const char*)prop, "mouse")==0) + _ToolTipParent= TTMouse; + else if(stricmp((const char*)prop, "special")==0) + _ToolTipParent= TTSpecialWindow; + else + _ToolTipParent= TTCtrl; + } + + // Tooltip special parent + prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_special_parent" ); + _ToolTipSpecialParent= CStringShared(); + if(prop) + { + _ToolTipSpecialParent= std::string((const char*)prop); + } + + // Tooltip posref + THotSpot tmpParentHS, tmpChildHS; + prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_posref" ); + convertTooltipHotSpot(prop, tmpParentHS, tmpChildHS); + _ToolTipParentPosRef= tmpParentHS; + _ToolTipPosRef= tmpChildHS; + + // Alternative tooltip posref : this one will be chosen + prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_posref_alt" ); + convertTooltipHotSpot(prop, tmpParentHS, tmpChildHS); + _ToolTipParentPosRefAlt = tmpParentHS; + _ToolTipPosRefAlt = tmpChildHS; + + // ToolTip instant + prop = (char*) xmlGetProp( cur, (xmlChar*)"instant_help"); + _ToolTipInstant= true; + if (prop) _ToolTipInstant = convertBool(prop); + + return true; + } + + // *************************************************************************** + void CCtrlBase::convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS) + { + parentHS = Hotspot_TTAuto; + childHS = Hotspot_TTAuto; + if(prop) + { + const char *ptr= (const char*)prop; + if(stricmp(ptr, "auto")==0) + { + parentHS = Hotspot_TTAuto; + childHS = Hotspot_TTAuto; + } + // valid ref? + else if(strlen(ptr)>=5) + { + THotSpot parentPosRef; + THotSpot posRef; + CInterfaceElement::convertHotSpotCouple(ptr, parentPosRef, posRef); + parentHS = parentPosRef; + childHS = posRef; } } } - return false; -} -// *************************************************************************** -bool CCtrlBase::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CViewBase::parse(cur, parentGroup)) - return false; - CXMLAutoPtr prop; - - // get static toolTip - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip" ); - if (prop) + // *************************************************************************** + bool CCtrlBase::emptyContextHelp() const { - const char *propPtr = prop; - - _ContextHelp = ucstring(propPtr); - - if (strlen(propPtr) > 2) - { - if ((propPtr[0] == 'u') && (propPtr[1] == 'i')) - _ContextHelp = CI18N::get ((const char *) prop); - } - } - // Force I18N tooltip - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_i18n" ); - if ((bool)prop && strlen((const char*)prop)>0) - { - _ContextHelp = CI18N::get ((const char *) prop); + ucstring help; + getContextHelp(help); + std::string sTmp = _OnContextHelp; + return help.empty() && sTmp.empty(); } - // get dynamic toolTip ActionHandler - prop = (char*) xmlGetProp( cur, (xmlChar*)"on_tooltip" ); - if (prop) + // *************************************************************************** + void CCtrlBase::visit(CInterfaceElementVisitor *visitor) { - _OnContextHelp= (const char*)prop; - } - prop = (char*) xmlGetProp( cur, (xmlChar*)"on_tooltip_params" ); - if (prop) - { - _OnContextHelpParams= (const char*)prop; + nlassert(visitor); + visitor->visitCtrl(this); + CInterfaceElement::visit(visitor); } - // Tooltip parent - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_parent" ); - _ToolTipParent= TTCtrl; - if(prop) + // *************************************************************************** + void CCtrlBase::serial(NLMISC::IStream &f) { - if(stricmp((const char*)prop, "win")==0) - _ToolTipParent= TTWindow; - else if(stricmp((const char*)prop, "mouse")==0) - _ToolTipParent= TTMouse; - else if(stricmp((const char*)prop, "special")==0) - _ToolTipParent= TTSpecialWindow; - else - _ToolTipParent= TTCtrl; + CViewBase::serial(f); + f.serial(_ContextHelp); + f.serial(_OnContextHelp); + f.serial(_OnContextHelpParams); + f.serial(_ToolTipSpecialParent); + f.serialEnum(_ToolTipParent); + // + + THotSpot tmpToolTipParentPosRef = _ToolTipParentPosRef; + THotSpot tmpToolTipPosRef = _ToolTipPosRef; + THotSpot tmpToolTipParentPosRefAlt = _ToolTipParentPosRefAlt; + THotSpot tmpToolTipPosRefAlt = _ToolTipPosRefAlt; + + f.serialEnum(tmpToolTipParentPosRef); + f.serialEnum(tmpToolTipPosRef); + f.serialEnum(tmpToolTipParentPosRefAlt); + f.serialEnum(tmpToolTipPosRefAlt); + + _ToolTipParentPosRef = tmpToolTipParentPosRef; + _ToolTipPosRef = tmpToolTipPosRef; + _ToolTipParentPosRefAlt = tmpToolTipParentPosRefAlt; + _ToolTipPosRefAlt = tmpToolTipPosRefAlt; + // + nlSerialBitBool(f, _ToolTipInstant); } - // Tooltip special parent - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_special_parent" ); - _ToolTipSpecialParent= CStringShared(); - if(prop) + // *************************************************************************** + std::string CCtrlBase::getContextHelpWindowName() const { - _ToolTipSpecialParent= std::string((const char*)prop); + return "context_help"; } - // Tooltip posref - THotSpot tmpParentHS, tmpChildHS; - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_posref" ); - convertTooltipHotSpot(prop, tmpParentHS, tmpChildHS); - _ToolTipParentPosRef= tmpParentHS; - _ToolTipPosRef= tmpChildHS; - - // Alternative tooltip posref : this one will be chosen - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_posref_alt" ); - convertTooltipHotSpot(prop, tmpParentHS, tmpChildHS); - _ToolTipParentPosRefAlt = tmpParentHS; - _ToolTipPosRefAlt = tmpChildHS; - - // ToolTip instant - prop = (char*) xmlGetProp( cur, (xmlChar*)"instant_help"); - _ToolTipInstant= true; - if (prop) _ToolTipInstant = convertBool(prop); - - return true; } -// *************************************************************************** -void CCtrlBase::convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS) -{ - parentHS = Hotspot_TTAuto; - childHS = Hotspot_TTAuto; - if(prop) - { - const char *ptr= (const char*)prop; - if(stricmp(ptr, "auto")==0) - { - parentHS = Hotspot_TTAuto; - childHS = Hotspot_TTAuto; - } - // valid ref? - else if(strlen(ptr)>=5) - { - THotSpot parentPosRef; - THotSpot posRef; - CInterfaceElement::convertHotSpotCouple(ptr, parentPosRef, posRef); - parentHS = parentPosRef; - childHS = posRef; - } - } -} - - -// *************************************************************************** -bool CCtrlBase::emptyContextHelp() const -{ - ucstring help; - getContextHelp(help); - std::string sTmp = _OnContextHelp; - return help.empty() && sTmp.empty(); -} - -// *************************************************************************** -void CCtrlBase::visit(CInterfaceElementVisitor *visitor) -{ - nlassert(visitor); - visitor->visitCtrl(this); - CInterfaceElement::visit(visitor); -} - -// *************************************************************************** -void CCtrlBase::serial(NLMISC::IStream &f) -{ - CViewBase::serial(f); - f.serial(_ContextHelp); - f.serial(_OnContextHelp); - f.serial(_OnContextHelpParams); - f.serial(_ToolTipSpecialParent); - f.serialEnum(_ToolTipParent); - // - - THotSpot tmpToolTipParentPosRef = _ToolTipParentPosRef; - THotSpot tmpToolTipPosRef = _ToolTipPosRef; - THotSpot tmpToolTipParentPosRefAlt = _ToolTipParentPosRefAlt; - THotSpot tmpToolTipPosRefAlt = _ToolTipPosRefAlt; - - f.serialEnum(tmpToolTipParentPosRef); - f.serialEnum(tmpToolTipPosRef); - f.serialEnum(tmpToolTipParentPosRefAlt); - f.serialEnum(tmpToolTipPosRefAlt); - - _ToolTipParentPosRef = tmpToolTipParentPosRef; - _ToolTipPosRef = tmpToolTipPosRef; - _ToolTipParentPosRefAlt = tmpToolTipParentPosRefAlt; - _ToolTipPosRefAlt = tmpToolTipPosRefAlt; - // - nlSerialBitBool(f, _ToolTipInstant); -} - -// *************************************************************************** -std::string CCtrlBase::getContextHelpWindowName() const -{ - return "context_help"; -} - - diff --git a/code/nel/src/gui/ctrl_draggable.cpp b/code/nel/src/gui/ctrl_draggable.cpp index 0e38d5c8f..b833fa547 100644 --- a/code/nel/src/gui/ctrl_draggable.cpp +++ b/code/nel/src/gui/ctrl_draggable.cpp @@ -1,11 +1,32 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + #include "nel/gui/ctrl_draggable.h" -CCtrlDraggable* CCtrlDraggable::_LastDraggedSheet = NULL; - -CCtrlDraggable::CCtrlDraggable(const TCtorParam ¶m) : -CCtrlBase( param ) +namespace NLGUI { - dragged = false; - draggable = false; -} + CCtrlDraggable* CCtrlDraggable::_LastDraggedSheet = NULL; + + CCtrlDraggable::CCtrlDraggable(const TCtorParam ¶m) : + CCtrlBase( param ) + { + dragged = false; + draggable = false; + } + +} \ No newline at end of file diff --git a/code/nel/src/gui/ctrl_scroll_base.cpp b/code/nel/src/gui/ctrl_scroll_base.cpp index a3ed058ac..57932af6b 100644 --- a/code/nel/src/gui/ctrl_scroll_base.cpp +++ b/code/nel/src/gui/ctrl_scroll_base.cpp @@ -16,51 +16,57 @@ #include "nel/gui/ctrl_scroll_base.h" -CCtrlScrollBase::CCtrlScrollBase( const TCtorParam ¶m ) : -CCtrlBase( param ) +namespace NLGUI { - _Target = NULL; + + CCtrlScrollBase::CCtrlScrollBase( const TCtorParam ¶m ) : + CCtrlBase( param ) + { + _Target = NULL; + } + + CCtrlScrollBase::~CCtrlScrollBase() + { + } + + void CCtrlScrollBase::setTarget( CInterfaceGroup *pIG ) + { + // Necessary because it's supposed to be an abstract class, + // however reflection requires the class to be instantiated. + nlassert( false ); + } + + sint32 CCtrlScrollBase::moveTrackX( sint32 dx ) + { + // Necessary because it's supposed to be an abstract class, + // however reflection requires the class to be instantiated. + nlassert( false ); + + return 0; + } + + sint32 CCtrlScrollBase::moveTrackY( sint32 dy ) + { + // Necessary because it's supposed to be an abstract class, + // however reflection requires the class to be instantiated. + nlassert( false ); + + return 0; + } + + void CCtrlScrollBase::moveTargetX( sint32 dx ) + { + // Necessary because it's supposed to be an abstract class, + // however reflection requires the class to be instantiated. + nlassert( false ); + } + + void CCtrlScrollBase::moveTargetY( sint32 dy ) + { + // Necessary because it's supposed to be an abstract class, + // however reflection requires the class to be instantiated. + nlassert( false ); + } + } -CCtrlScrollBase::~CCtrlScrollBase() -{ -} - -void CCtrlScrollBase::setTarget( CInterfaceGroup *pIG ) -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); -} - -sint32 CCtrlScrollBase::moveTrackX( sint32 dx ) -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); - - return 0; -} - -sint32 CCtrlScrollBase::moveTrackY( sint32 dy ) -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); - - return 0; -} - -void CCtrlScrollBase::moveTargetX( sint32 dx ) -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); -} - -void CCtrlScrollBase::moveTargetY( sint32 dy ) -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); -} \ No newline at end of file diff --git a/code/nel/src/gui/group_container_base.cpp b/code/nel/src/gui/group_container_base.cpp index 9946f5e0c..7ef134c8a 100644 --- a/code/nel/src/gui/group_container_base.cpp +++ b/code/nel/src/gui/group_container_base.cpp @@ -17,76 +17,81 @@ #include "nel/gui/group_container_base.h" -CGroupContainerBase::CGroupContainerBase( const CViewBase::TCtorParam ¶m ) : -CInterfaceGroup( param ) +namespace NLGUI { - _ContentAlpha = 255; - _ContainerAlpha = 255; - _RolloverAlphaContainer = 0; - _RolloverAlphaContent = 0; - _Locked = false; - _UseGlobalAlpha = true; -} - -CGroupContainerBase::~CGroupContainerBase() -{ -} - -void CGroupContainerBase::removeAllContainers() -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); -} - -void CGroupContainerBase::setLocked( bool locked ) -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); -} - - -// *************************************************************************** -void CGroupContainerBase::triggerAlphaSettingsChangedAH() -{ - if (_AHOnAlphaSettingsChanged != NULL) - CAHManager::getInstance()->runActionHandler(_AHOnAlphaSettingsChanged, this, _AHOnAlphaSettingsChangedParams); -} - - -// *************************************************************************** -void CGroupContainerBase::setUseGlobalAlpha(bool use) -{ - _UseGlobalAlpha = use; - triggerAlphaSettingsChangedAH(); -} - -// *************************************************************************** -void CGroupContainerBase::setContainerAlpha(uint8 alpha) -{ - _ContainerAlpha = alpha; - triggerAlphaSettingsChangedAH(); -} - -// *************************************************************************** -void CGroupContainerBase::setContentAlpha(uint8 alpha) -{ - _ContentAlpha = alpha; - triggerAlphaSettingsChangedAH(); -} - -// *************************************************************************** -void CGroupContainerBase::setRolloverAlphaContent(uint8 alpha) -{ - _RolloverAlphaContent = alpha; - triggerAlphaSettingsChangedAH(); -} - -// *************************************************************************** -void CGroupContainerBase::setRolloverAlphaContainer(uint8 alpha) -{ - _RolloverAlphaContainer = alpha; - triggerAlphaSettingsChangedAH(); + + CGroupContainerBase::CGroupContainerBase( const CViewBase::TCtorParam ¶m ) : + CInterfaceGroup( param ) + { + _ContentAlpha = 255; + _ContainerAlpha = 255; + _RolloverAlphaContainer = 0; + _RolloverAlphaContent = 0; + _Locked = false; + _UseGlobalAlpha = true; + } + + CGroupContainerBase::~CGroupContainerBase() + { + } + + void CGroupContainerBase::removeAllContainers() + { + // Necessary because it's supposed to be an abstract class, + // however reflection requires the class to be instantiated. + nlassert( false ); + } + + void CGroupContainerBase::setLocked( bool locked ) + { + // Necessary because it's supposed to be an abstract class, + // however reflection requires the class to be instantiated. + nlassert( false ); + } + + + // *************************************************************************** + void CGroupContainerBase::triggerAlphaSettingsChangedAH() + { + if (_AHOnAlphaSettingsChanged != NULL) + CAHManager::getInstance()->runActionHandler(_AHOnAlphaSettingsChanged, this, _AHOnAlphaSettingsChangedParams); + } + + + // *************************************************************************** + void CGroupContainerBase::setUseGlobalAlpha(bool use) + { + _UseGlobalAlpha = use; + triggerAlphaSettingsChangedAH(); + } + + // *************************************************************************** + void CGroupContainerBase::setContainerAlpha(uint8 alpha) + { + _ContainerAlpha = alpha; + triggerAlphaSettingsChangedAH(); + } + + // *************************************************************************** + void CGroupContainerBase::setContentAlpha(uint8 alpha) + { + _ContentAlpha = alpha; + triggerAlphaSettingsChangedAH(); + } + + // *************************************************************************** + void CGroupContainerBase::setRolloverAlphaContent(uint8 alpha) + { + _RolloverAlphaContent = alpha; + triggerAlphaSettingsChangedAH(); + } + + // *************************************************************************** + void CGroupContainerBase::setRolloverAlphaContainer(uint8 alpha) + { + _RolloverAlphaContainer = alpha; + triggerAlphaSettingsChangedAH(); + } + } diff --git a/code/nel/src/gui/group_editbox_base.cpp b/code/nel/src/gui/group_editbox_base.cpp index 3c67d7d2f..7eafd22aa 100644 --- a/code/nel/src/gui/group_editbox_base.cpp +++ b/code/nel/src/gui/group_editbox_base.cpp @@ -1,14 +1,36 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + #include "nel/gui/group_editbox_base.h" -CGroupEditBoxBase *CGroupEditBoxBase::_CurrSelection = NULL; - -CGroupEditBoxBase::CGroupEditBoxBase( const TCtorParam ¶m ) : -CInterfaceGroup( param ) -{ - _RecoverFocusOnEnter = true; -} - -CGroupEditBoxBase::~CGroupEditBoxBase() +namespace NLGUI { + + CGroupEditBoxBase *CGroupEditBoxBase::_CurrSelection = NULL; + + CGroupEditBoxBase::CGroupEditBoxBase( const TCtorParam ¶m ) : + CInterfaceGroup( param ) + { + _RecoverFocusOnEnter = true; + } + + CGroupEditBoxBase::~CGroupEditBoxBase() + { + } + } diff --git a/code/nel/src/gui/group_frame.cpp b/code/nel/src/gui/group_frame.cpp index e8fbfa228..9f8e7ab1d 100644 --- a/code/nel/src/gui/group_frame.cpp +++ b/code/nel/src/gui/group_frame.cpp @@ -24,226 +24,232 @@ using namespace std; using namespace NLMISC; -NLMISC_REGISTER_OBJECT(CViewBase, CGroupFrame, std::string, "frame"); - -// *************************************************************************** -vector CGroupFrame::_DispTypes; - -// *************************************************************************** -CGroupFrame::CGroupFrame(const TCtorParam ¶m) -: CInterfaceGroup(param) +namespace NLGUI { - _DisplayFrame = true; - _Color = CRGBA(255,255,255,255); - _DispType = 0; - _DisplayFrameDefined= false; - _ColorDefined= false; - _DispTypeDefined= false; -} -// *************************************************************************** -bool CGroupFrame::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CInterfaceGroup::parse(cur, parentGroup)) - return false; + NLMISC_REGISTER_OBJECT(CViewBase, CGroupFrame, std::string, "frame"); - // display - CXMLAutoPtr ptr((const char*) xmlGetProp (cur, (xmlChar*)"display")); - _DisplayFrame = true; - _DisplayFrameDefined= false; - if (ptr) + // *************************************************************************** + vector CGroupFrame::_DispTypes; + + // *************************************************************************** + CGroupFrame::CGroupFrame(const TCtorParam ¶m) + : CInterfaceGroup(param) { - _DisplayFrame = convertBool (ptr); - _DisplayFrameDefined= true; + _DisplayFrame = true; + _Color = CRGBA(255,255,255,255); + _DispType = 0; + _DisplayFrameDefined= false; + _ColorDefined= false; + _DispTypeDefined= false; } - // color - ptr = (char*) xmlGetProp( cur, (xmlChar*)"color" ); - _Color = CRGBA(255,255,255,255); - _ColorDefined= false; - if (ptr) + // *************************************************************************** + bool CGroupFrame::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) { - _Color = convertColor (ptr); - _ColorDefined= true; - } + if(!CInterfaceGroup::parse(cur, parentGroup)) + return false; - // Get the borders texture - _DispTypeDefined= false; - CViewRenderer &rVR = *CViewRenderer::getInstance(); + // display + CXMLAutoPtr ptr((const char*) xmlGetProp (cur, (xmlChar*)"display")); + _DisplayFrame = true; + _DisplayFrameDefined= false; + if (ptr) + { + _DisplayFrame = convertBool (ptr); + _DisplayFrameDefined= true; + } - ptr = (char*) xmlGetProp( cur, (xmlChar*)"options" ); - CInterfaceOptions *pIO = NULL; + // color + ptr = (char*) xmlGetProp( cur, (xmlChar*)"color" ); + _Color = CRGBA(255,255,255,255); + _ColorDefined= false; + if (ptr) + { + _Color = convertColor (ptr); + _ColorDefined= true; + } - if (ptr) - pIO = CWidgetManager::getInstance()->getOptions(ptr); + // Get the borders texture + _DispTypeDefined= false; + CViewRenderer &rVR = *CViewRenderer::getInstance(); - // The first type in display type struct is the default display type - if (_DispTypes.size() == 0) - { - SDisplayType dt; - dt.Name = "default"; - // get texture ids. - dt.BorderIds[TextTL]= rVR.getTextureIdFromName ("w_modal_tl.tga"); - dt.BorderIds[TextTM]= rVR.getTextureIdFromName ("w_modal_t.tga"); - dt.BorderIds[TextTR]= rVR.getTextureIdFromName ("w_modal_tr.tga"); - // middle - dt.BorderIds[TextML]= rVR.getTextureIdFromName ("w_modal_l.tga"); - dt.BorderIds[TextMM]= rVR.getTextureIdFromName ("w_modal_blank.tga"); - dt.BorderIds[TextMR]= rVR.getTextureIdFromName ("w_modal_r.tga"); - // bottom - dt.BorderIds[TextBL]= rVR.getTextureIdFromName ("w_modal_bl.tga"); - dt.BorderIds[TextBM]= rVR.getTextureIdFromName ("w_modal_b.tga"); - dt.BorderIds[TextBR]= rVR.getTextureIdFromName ("w_modal_br.tga"); - // get size - rVR.getTextureSizeFromId (dt.BorderIds[TextTL], dt.LeftBorder, dt.TopBorder); - rVR.getTextureSizeFromId (dt.BorderIds[TextBR], dt.RightBorder, dt.BottomBorder); - _DispTypes.push_back(dt); - } + ptr = (char*) xmlGetProp( cur, (xmlChar*)"options" ); + CInterfaceOptions *pIO = NULL; - if (pIO != NULL) - { - _DispTypeDefined= true; + if (ptr) + pIO = CWidgetManager::getInstance()->getOptions(ptr); - // Look if we find the type... - uint32 i; - for (i = 0; i < _DispTypes.size(); ++i) - if (_DispTypes[i].Name == string((const char*)ptr)) - break; - - if (i == _DispTypes.size()) + // The first type in display type struct is the default display type + if (_DispTypes.size() == 0) { SDisplayType dt; - dt.Name = string((const char*)ptr); + dt.Name = "default"; // get texture ids. - dt.BorderIds[TextTL]= rVR.getTextureIdFromName (pIO->getValStr("tx_tl")); - dt.BorderIds[TextTM]= rVR.getTextureIdFromName (pIO->getValStr("tx_t")); - dt.BorderIds[TextTR]= rVR.getTextureIdFromName (pIO->getValStr("tx_tr")); + dt.BorderIds[TextTL]= rVR.getTextureIdFromName ("w_modal_tl.tga"); + dt.BorderIds[TextTM]= rVR.getTextureIdFromName ("w_modal_t.tga"); + dt.BorderIds[TextTR]= rVR.getTextureIdFromName ("w_modal_tr.tga"); // middle - dt.BorderIds[TextML]= rVR.getTextureIdFromName (pIO->getValStr("tx_l")); - dt.BorderIds[TextMM]= rVR.getTextureIdFromName (pIO->getValStr("tx_blank")); - dt.BorderIds[TextMR]= rVR.getTextureIdFromName (pIO->getValStr("tx_r")); + dt.BorderIds[TextML]= rVR.getTextureIdFromName ("w_modal_l.tga"); + dt.BorderIds[TextMM]= rVR.getTextureIdFromName ("w_modal_blank.tga"); + dt.BorderIds[TextMR]= rVR.getTextureIdFromName ("w_modal_r.tga"); // bottom - dt.BorderIds[TextBL]= rVR.getTextureIdFromName (pIO->getValStr("tx_bl")); - dt.BorderIds[TextBM]= rVR.getTextureIdFromName (pIO->getValStr("tx_b")); - dt.BorderIds[TextBR]= rVR.getTextureIdFromName (pIO->getValStr("tx_br")); - - // Tile - dt.TileBorder[TextTM] = (uint8)pIO->getValSInt32("tile_t"); - dt.TileBorder[TextML] = (uint8)pIO->getValSInt32("tile_l"); - dt.TileBorder[TextMM] = (uint8)pIO->getValSInt32("tile_blank"); - dt.TileBorder[TextMR] = (uint8)pIO->getValSInt32("tile_r"); - dt.TileBorder[TextBM] = (uint8)pIO->getValSInt32("tile_b"); - + dt.BorderIds[TextBL]= rVR.getTextureIdFromName ("w_modal_bl.tga"); + dt.BorderIds[TextBM]= rVR.getTextureIdFromName ("w_modal_b.tga"); + dt.BorderIds[TextBR]= rVR.getTextureIdFromName ("w_modal_br.tga"); // get size rVR.getTextureSizeFromId (dt.BorderIds[TextTL], dt.LeftBorder, dt.TopBorder); rVR.getTextureSizeFromId (dt.BorderIds[TextBR], dt.RightBorder, dt.BottomBorder); _DispTypes.push_back(dt); } - _DispType = (uint8)i; - } - else - { - _DispType = 0; - } - - return true; -} - - -// *************************************************************************** -void CGroupFrame::draw () -{ - if (_DisplayFrame) - { - CViewRenderer &rVR = *CViewRenderer::getInstance(); - - // get global color - CRGBA col; - if(getModulateGlobalColor()) - col.modulateFromColor( _Color, CWidgetManager::getInstance()->getGlobalColor() ); - else - col= _Color; - - // draw the background - sint xId = 0, yId = 0; - for (yId = 0; yId < 3; yId++) + if (pIO != NULL) { - for (xId = 0; xId < 3; xId++) + _DispTypeDefined= true; + + // Look if we find the type... + uint32 i; + for (i = 0; i < _DispTypes.size(); ++i) + if (_DispTypes[i].Name == string((const char*)ptr)) + break; + + if (i == _DispTypes.size()) { - sint32 x = _XReal; - sint32 y = _YReal; - sint32 w, h; - // top - if (yId == 0) - { - y += _HReal-_DispTypes[_DispType].TopBorder; - h = _DispTypes[_DispType].TopBorder; - } - // Middle - else if (yId == 1) - { - y += _DispTypes[_DispType].BottomBorder; - h = _HReal-_DispTypes[_DispType].TopBorder-_DispTypes[_DispType].BottomBorder; - } - // Bottom - else - { - h = _DispTypes[_DispType].BottomBorder; - } + SDisplayType dt; + dt.Name = string((const char*)ptr); + // get texture ids. + dt.BorderIds[TextTL]= rVR.getTextureIdFromName (pIO->getValStr("tx_tl")); + dt.BorderIds[TextTM]= rVR.getTextureIdFromName (pIO->getValStr("tx_t")); + dt.BorderIds[TextTR]= rVR.getTextureIdFromName (pIO->getValStr("tx_tr")); + // middle + dt.BorderIds[TextML]= rVR.getTextureIdFromName (pIO->getValStr("tx_l")); + dt.BorderIds[TextMM]= rVR.getTextureIdFromName (pIO->getValStr("tx_blank")); + dt.BorderIds[TextMR]= rVR.getTextureIdFromName (pIO->getValStr("tx_r")); + // bottom + dt.BorderIds[TextBL]= rVR.getTextureIdFromName (pIO->getValStr("tx_bl")); + dt.BorderIds[TextBM]= rVR.getTextureIdFromName (pIO->getValStr("tx_b")); + dt.BorderIds[TextBR]= rVR.getTextureIdFromName (pIO->getValStr("tx_br")); - // Left - if (xId == 0) - { - w = _DispTypes[_DispType].LeftBorder; - } - else if (xId == 1) - { - x += _DispTypes[_DispType].LeftBorder; - w = _WReal-_DispTypes[_DispType].LeftBorder-_DispTypes[_DispType].RightBorder; - } - else - { - x += _WReal-_DispTypes[_DispType].RightBorder; - w = _DispTypes[_DispType].RightBorder; - } + // Tile + dt.TileBorder[TextTM] = (uint8)pIO->getValSInt32("tile_t"); + dt.TileBorder[TextML] = (uint8)pIO->getValSInt32("tile_l"); + dt.TileBorder[TextMM] = (uint8)pIO->getValSInt32("tile_blank"); + dt.TileBorder[TextMR] = (uint8)pIO->getValSInt32("tile_r"); + dt.TileBorder[TextBM] = (uint8)pIO->getValSInt32("tile_b"); - // render - uint8 tile = _DispTypes[_DispType].TileBorder[yId*3+xId]; - if (tile == 0) - rVR.drawRotFlipBitmap (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], col); - else - rVR.drawRotFlipBitmapTiled (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], tile-1, col); + // get size + rVR.getTextureSizeFromId (dt.BorderIds[TextTL], dt.LeftBorder, dt.TopBorder); + rVR.getTextureSizeFromId (dt.BorderIds[TextBR], dt.RightBorder, dt.BottomBorder); + _DispTypes.push_back(dt); + } + _DispType = (uint8)i; + } + else + { + _DispType = 0; + } + + return true; + } + + + // *************************************************************************** + void CGroupFrame::draw () + { + if (_DisplayFrame) + { + CViewRenderer &rVR = *CViewRenderer::getInstance(); + + // get global color + CRGBA col; + if(getModulateGlobalColor()) + col.modulateFromColor( _Color, CWidgetManager::getInstance()->getGlobalColor() ); + else + col= _Color; + + // draw the background + sint xId = 0, yId = 0; + for (yId = 0; yId < 3; yId++) + { + for (xId = 0; xId < 3; xId++) + { + sint32 x = _XReal; + sint32 y = _YReal; + sint32 w, h; + // top + if (yId == 0) + { + y += _HReal-_DispTypes[_DispType].TopBorder; + h = _DispTypes[_DispType].TopBorder; + } + // Middle + else if (yId == 1) + { + y += _DispTypes[_DispType].BottomBorder; + h = _HReal-_DispTypes[_DispType].TopBorder-_DispTypes[_DispType].BottomBorder; + } + // Bottom + else + { + h = _DispTypes[_DispType].BottomBorder; + } + + // Left + if (xId == 0) + { + w = _DispTypes[_DispType].LeftBorder; + } + else if (xId == 1) + { + x += _DispTypes[_DispType].LeftBorder; + w = _WReal-_DispTypes[_DispType].LeftBorder-_DispTypes[_DispType].RightBorder; + } + else + { + x += _WReal-_DispTypes[_DispType].RightBorder; + w = _DispTypes[_DispType].RightBorder; + } + + // render + uint8 tile = _DispTypes[_DispType].TileBorder[yId*3+xId]; + if (tile == 0) + rVR.drawRotFlipBitmap (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], col); + else + rVR.drawRotFlipBitmapTiled (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], tile-1, col); + + } } } + // draw the components + CInterfaceGroup::draw(); } - // draw the components - CInterfaceGroup::draw(); + + // *************************************************************************** + void CGroupFrame::copyOptionFrom(const CGroupFrame &other) + { + CInterfaceGroup::copyOptionFrom(other); + + // Copy option only if they were not explicitly defined in xml + if(!_DisplayFrameDefined) + _DisplayFrame = other._DisplayFrame; + if(!_ColorDefined) + _Color = other._Color; + if(!_DispTypeDefined) + _DispType = other._DispType; + } + + // *************************************************************************** + void CGroupFrame::setColorAsString(const string & col) + { + _Color = convertColor (col.c_str()); + } + + // *************************************************************************** + string CGroupFrame::getColorAsString() const + { + return NLMISC::toString(_Color.R) + " " + NLMISC::toString(_Color.G) + " " + NLMISC::toString(_Color.B) + " " + NLMISC::toString(_Color.A); + } + } -// *************************************************************************** -void CGroupFrame::copyOptionFrom(const CGroupFrame &other) -{ - CInterfaceGroup::copyOptionFrom(other); - - // Copy option only if they were not explicitly defined in xml - if(!_DisplayFrameDefined) - _DisplayFrame = other._DisplayFrame; - if(!_ColorDefined) - _Color = other._Color; - if(!_DispTypeDefined) - _DispType = other._DispType; -} - -// *************************************************************************** -void CGroupFrame::setColorAsString(const string & col) -{ - _Color = convertColor (col.c_str()); -} - -// *************************************************************************** -string CGroupFrame::getColorAsString() const -{ - return NLMISC::toString(_Color.R) + " " + NLMISC::toString(_Color.G) + " " + NLMISC::toString(_Color.B) + " " + NLMISC::toString(_Color.A); -} diff --git a/code/nel/src/gui/group_modal.cpp b/code/nel/src/gui/group_modal.cpp index 1b763fad5..22a9956f5 100644 --- a/code/nel/src/gui/group_modal.cpp +++ b/code/nel/src/gui/group_modal.cpp @@ -20,156 +20,159 @@ #include "nel/gui/interface_element.h" #include "nel/misc/xml_auto_ptr.h" #include "nel/gui/view_renderer.h" +#include "nel/misc/i_xml.h" using namespace std; -#include "nel/misc/i_xml.h" - -NLMISC_REGISTER_OBJECT(CViewBase, CGroupModal, std::string, "modal"); - -// *************************************************************************** -CGroupModal::CGroupModal(const TCtorParam ¶m) -: CGroupFrame(param) +namespace NLGUI { - SpawnOnMousePos= true; - ExitClickOut= true; - ExitClickL= false; - ExitClickR= false; - ExitKeyPushed = false; - ForceInsideScreen= false; - SpawnMouseX= SpawnMouseY= 0; - _MouseDeltaX= _MouseDeltaY= 0; - //By default, modal are escapable - _Escapable= true; -} + NLMISC_REGISTER_OBJECT(CViewBase, CGroupModal, std::string, "modal"); -// *************************************************************************** -bool CGroupModal::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CGroupFrame::parse(cur, parentGroup)) - return false; - - // read modal option - CXMLAutoPtr prop; - prop = xmlGetProp (cur, (xmlChar*)"mouse_pos"); - if ( prop ) SpawnOnMousePos= convertBool(prop); - prop = xmlGetProp (cur, (xmlChar*)"exit_click_out"); - if ( prop ) ExitClickOut= convertBool(prop); - prop = xmlGetProp (cur, (xmlChar*)"exit_click_l"); - if ( prop ) ExitClickL= convertBool(prop); - prop = xmlGetProp (cur, (xmlChar*)"exit_click_r"); - if ( prop ) ExitClickR= convertBool(prop); - prop = xmlGetProp (cur, (xmlChar*)"exit_click_b"); - if ( prop ) ExitClickR= ExitClickL= convertBool(prop); - prop = xmlGetProp (cur, (xmlChar*)"force_inside_screen"); - if ( prop ) ForceInsideScreen= convertBool(prop); - prop = xmlGetProp (cur, (xmlChar*)"category"); - if ( prop ) Category= (const char *) prop; - prop = xmlGetProp (cur, (xmlChar*)"onclick_out"); - if ( prop ) OnClickOut = (const char *) prop; - prop = xmlGetProp (cur, (xmlChar*)"onclick_out_params"); - if ( prop ) OnClickOutParams = (const char *) prop; - prop = xmlGetProp (cur, (xmlChar*)"onpostclick_out"); - if ( prop ) OnPostClickOut = (const char *) prop; - prop = xmlGetProp (cur, (xmlChar*)"onpostclick_out_params"); - if ( prop ) OnPostClickOutParams = (const char *) prop; - prop = xmlGetProp (cur, (xmlChar*)"exit_key_pushed"); - if ( prop ) ExitKeyPushed= convertBool(prop); - - // Force parent hotspot for spawn on mouse - if(SpawnOnMousePos) - setParentPosRef(Hotspot_BL); - - // bkup x/y as the deltas. - _MouseDeltaX= getX(); - _MouseDeltaY= getY(); - - // Modals are disabled by default - _Active = false; - - return true; -} - -// *************************************************************************** -void CGroupModal::updateCoords () -{ - // if snap to mouse pos. - if(SpawnOnMousePos) + // *************************************************************************** + CGroupModal::CGroupModal(const TCtorParam ¶m) + : CGroupFrame(param) { - // Special for menu for instance: If the size is bigger or equal to the screen, keep 0, because will be clipped just after - CViewRenderer &rVR = *CViewRenderer::getInstance(); - uint32 w,h; - rVR.getScreenSize(w,h); - if(_W>=(sint32)w && _H>=(sint32)h) + SpawnOnMousePos= true; + ExitClickOut= true; + ExitClickL= false; + ExitClickR= false; + ExitKeyPushed = false; + ForceInsideScreen= false; + SpawnMouseX= SpawnMouseY= 0; + _MouseDeltaX= _MouseDeltaY= 0; + //By default, modal are escapable + _Escapable= true; + } + + + // *************************************************************************** + bool CGroupModal::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) + { + if(!CGroupFrame::parse(cur, parentGroup)) + return false; + + // read modal option + CXMLAutoPtr prop; + prop = xmlGetProp (cur, (xmlChar*)"mouse_pos"); + if ( prop ) SpawnOnMousePos= convertBool(prop); + prop = xmlGetProp (cur, (xmlChar*)"exit_click_out"); + if ( prop ) ExitClickOut= convertBool(prop); + prop = xmlGetProp (cur, (xmlChar*)"exit_click_l"); + if ( prop ) ExitClickL= convertBool(prop); + prop = xmlGetProp (cur, (xmlChar*)"exit_click_r"); + if ( prop ) ExitClickR= convertBool(prop); + prop = xmlGetProp (cur, (xmlChar*)"exit_click_b"); + if ( prop ) ExitClickR= ExitClickL= convertBool(prop); + prop = xmlGetProp (cur, (xmlChar*)"force_inside_screen"); + if ( prop ) ForceInsideScreen= convertBool(prop); + prop = xmlGetProp (cur, (xmlChar*)"category"); + if ( prop ) Category= (const char *) prop; + prop = xmlGetProp (cur, (xmlChar*)"onclick_out"); + if ( prop ) OnClickOut = (const char *) prop; + prop = xmlGetProp (cur, (xmlChar*)"onclick_out_params"); + if ( prop ) OnClickOutParams = (const char *) prop; + prop = xmlGetProp (cur, (xmlChar*)"onpostclick_out"); + if ( prop ) OnPostClickOut = (const char *) prop; + prop = xmlGetProp (cur, (xmlChar*)"onpostclick_out_params"); + if ( prop ) OnPostClickOutParams = (const char *) prop; + prop = xmlGetProp (cur, (xmlChar*)"exit_key_pushed"); + if ( prop ) ExitKeyPushed= convertBool(prop); + + // Force parent hotspot for spawn on mouse + if(SpawnOnMousePos) + setParentPosRef(Hotspot_BL); + + // bkup x/y as the deltas. + _MouseDeltaX= getX(); + _MouseDeltaY= getY(); + + // Modals are disabled by default + _Active = false; + + return true; + } + + // *************************************************************************** + void CGroupModal::updateCoords () + { + // if snap to mouse pos. + if(SpawnOnMousePos) { - _X= _Y= 0; + // Special for menu for instance: If the size is bigger or equal to the screen, keep 0, because will be clipped just after + CViewRenderer &rVR = *CViewRenderer::getInstance(); + uint32 w,h; + rVR.getScreenSize(w,h); + if(_W>=(sint32)w && _H>=(sint32)h) + { + _X= _Y= 0; + } + else + { + // change coords + _X= SpawnMouseX+_MouseDeltaX; + _Y= SpawnMouseY+_MouseDeltaY; + } } - else + + // update group + CGroupFrame::updateCoords(); + + // if snap to mouse pos or ForceInsideScreen + if(SpawnOnMousePos || ForceInsideScreen) { - // change coords - _X= SpawnMouseX+_MouseDeltaX; - _Y= SpawnMouseY+_MouseDeltaY; + bool clipped = false; + // repos the group according to real size. clip against screen + if(_XReal<0) + { + _X+= -_XReal; + clipped = true; + } + else + { + if (!SpawnOnMousePos) + _X = _MouseDeltaX; + } + + if(_XReal+_WReal>_Parent->getW()) + { + _X-= _XReal+_WReal-_Parent->getW(); + clipped =true; + } + else + { + if ((!SpawnOnMousePos) && (_XReal>=0)) + _X = _MouseDeltaX; + } + + if(_YReal<0) + { + _Y+= -_YReal; + clipped =true; + } + else + { + if (!SpawnOnMousePos) + _Y = _MouseDeltaY; + } + + if(_YReal+_HReal>_Parent->getH()) + { + _Y-= _YReal+_HReal-_Parent->getH(); + clipped =true; + } + else + { + if ((!SpawnOnMousePos) && (_YReal>=0)) + _Y = _MouseDeltaY; + } + + if (clipped) + { + CGroupFrame::updateCoords(); + } } } - // update group - CGroupFrame::updateCoords(); - - // if snap to mouse pos or ForceInsideScreen - if(SpawnOnMousePos || ForceInsideScreen) - { - bool clipped = false; - // repos the group according to real size. clip against screen - if(_XReal<0) - { - _X+= -_XReal; - clipped = true; - } - else - { - if (!SpawnOnMousePos) - _X = _MouseDeltaX; - } - - if(_XReal+_WReal>_Parent->getW()) - { - _X-= _XReal+_WReal-_Parent->getW(); - clipped =true; - } - else - { - if ((!SpawnOnMousePos) && (_XReal>=0)) - _X = _MouseDeltaX; - } - - if(_YReal<0) - { - _Y+= -_YReal; - clipped =true; - } - else - { - if (!SpawnOnMousePos) - _Y = _MouseDeltaY; - } - - if(_YReal+_HReal>_Parent->getH()) - { - _Y-= _YReal+_HReal-_Parent->getH(); - clipped =true; - } - else - { - if ((!SpawnOnMousePos) && (_YReal>=0)) - _Y = _MouseDeltaY; - } - - if (clipped) - { - CGroupFrame::updateCoords(); - } - } } - diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index a90e2639a..4d969b187 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -29,174 +29,253 @@ using namespace std; using namespace NLMISC; -CStringMapper *_UIStringMapper = NULL; - -// ------------------------------------------------------------------------------------------------ -CInterfaceElement::~CInterfaceElement() +namespace NLGUI { - if (_Links) // remove any link that point to that element + + CStringMapper *_UIStringMapper = NULL; + + // ------------------------------------------------------------------------------------------------ + CInterfaceElement::~CInterfaceElement() { - for(TLinkVect::iterator it = _Links->begin(); it != _Links->end(); ++it) + if (_Links) // remove any link that point to that element { - (*it)->removeTarget(this); + for(TLinkVect::iterator it = _Links->begin(); it != _Links->end(); ++it) + { + (*it)->removeTarget(this); + } + delete _Links; } - delete _Links; } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::parseError(CInterfaceGroup * parentGroup, const char *reason) -{ - string tmp = string("cannot parse view:")+getId()+", parent:"+parentGroup->getId(); - nlinfo(tmp.c_str()); - if (reason) - nlinfo("reason : %s", reason); -} - - -void CInterfaceElement::setIdRecurse(const std::string &newID) -{ - std::string baseId = _Parent ? _Parent->getId() : "ui"; - setId(baseId + ":" + newID); -} - -// ------------------------------------------------------------------------------------------------ -std::string CInterfaceElement::getShortId() const -{ - std::string::size_type last = _Id.find_last_of(':'); - if (last != std::string::npos) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::parseError(CInterfaceGroup * parentGroup, const char *reason) { - return _Id.substr(last + 1); + string tmp = string("cannot parse view:")+getId()+", parent:"+parentGroup->getId(); + nlinfo(tmp.c_str()); + if (reason) + nlinfo("reason : %s", reason); } - return _Id; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - // parse the basic properties - CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"id" )); - if (ptr) + + void CInterfaceElement::setIdRecurse(const std::string &newID) { - if (parentGroup) + std::string baseId = _Parent ? _Parent->getId() : "ui"; + setId(baseId + ":" + newID); + } + + // ------------------------------------------------------------------------------------------------ + std::string CInterfaceElement::getShortId() const + { + std::string::size_type last = _Id.find_last_of(':'); + if (last != std::string::npos) { - _Id = ( (CInterfaceElement*)parentGroup )->_Id; + return _Id.substr(last + 1); + } + return _Id; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) + { + // parse the basic properties + CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"id" )); + if (ptr) + { + if (parentGroup) + { + _Id = ( (CInterfaceElement*)parentGroup )->_Id; + } + else + { + _Id ="ui"; + } + _Id += ":"+ string((const char*)ptr); } else { - _Id ="ui"; + nlinfo(" error no id in an element"); + return false; } - _Id += ":"+ string((const char*)ptr); - } - else - { - nlinfo(" error no id in an element"); - return false; - } - ptr = (char*) xmlGetProp( cur, (xmlChar*)"active" ); - _Active = true; - if (ptr) - { - _Active = convertBool(ptr); - } - - _Parent = parentGroup; - - // parse location. If these properties are not specified, set them to 0 - ptr = (char*) xmlGetProp( cur, (xmlChar*)"x" ); - _X = 0; - if (ptr) fromString((const char*)ptr, _X); - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"y" ); - _Y = 0; - if (ptr) fromString((const char*)ptr, _Y); - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"w" ); - _W = 0; - if (parentGroup != NULL) - _W = parentGroup->getW(); - if (ptr) fromString((const char*)ptr, _W); - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"h" ); - _H = 0; - if (parentGroup != NULL) - _H = parentGroup->getH(); - if (ptr) fromString((const char*)ptr, _H); - - // snapping -// ptr = (char*) xmlGetProp( cur, (xmlChar*)"snap" ); -// _Snap = 1; -// if (ptr) -// fromString((const char*)ptr, _Snap); -// if (_Snap <= 0) -// { -// parseError(parentGroup, "snap must be > 0" ); -// return false; -// } - - ptr = (char*) xmlGetProp( cur, (xmlChar*) "posref" ); - _ParentPosRef = Hotspot_BL; - _PosRef = Hotspot_BL; - if (ptr) - { - convertHotSpotCouple(ptr.getDatas(), _ParentPosRef, _PosRef); - } - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"posparent" ); - if (ptr) - { - if (strcmp(ptr,"parent")) // is ptr != "parent" + ptr = (char*) xmlGetProp( cur, (xmlChar*)"active" ); + _Active = true; + if (ptr) { - string idparent; - if (parentGroup) - idparent = parentGroup->getId() +":"; + _Active = convertBool(ptr); + } + + _Parent = parentGroup; + + // parse location. If these properties are not specified, set them to 0 + ptr = (char*) xmlGetProp( cur, (xmlChar*)"x" ); + _X = 0; + if (ptr) fromString((const char*)ptr, _X); + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"y" ); + _Y = 0; + if (ptr) fromString((const char*)ptr, _Y); + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"w" ); + _W = 0; + if (parentGroup != NULL) + _W = parentGroup->getW(); + if (ptr) fromString((const char*)ptr, _W); + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"h" ); + _H = 0; + if (parentGroup != NULL) + _H = parentGroup->getH(); + if (ptr) fromString((const char*)ptr, _H); + + // snapping + // ptr = (char*) xmlGetProp( cur, (xmlChar*)"snap" ); + // _Snap = 1; + // if (ptr) + // fromString((const char*)ptr, _Snap); + // if (_Snap <= 0) + // { + // parseError(parentGroup, "snap must be > 0" ); + // return false; + // } + + ptr = (char*) xmlGetProp( cur, (xmlChar*) "posref" ); + _ParentPosRef = Hotspot_BL; + _PosRef = Hotspot_BL; + if (ptr) + { + convertHotSpotCouple(ptr.getDatas(), _ParentPosRef, _PosRef); + } + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"posparent" ); + if (ptr) + { + if (strcmp(ptr,"parent")) // is ptr != "parent" + { + string idparent; + if (parentGroup) + idparent = parentGroup->getId() +":"; + else + idparent = "ui:"; + CWidgetManager::parser->addParentPositionAssociation(this, idparent + string((const char*)ptr)); + } + } + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"sizeparent" ); + if (ptr) + { + string idparent = ptr; + idparent = NLMISC::strlwr(idparent); + if (idparent != "parent") + { + if (parentGroup) + idparent = parentGroup->getId() +":" + string((const char*)ptr); + else + idparent = "ui:" + string((const char*)ptr); + } else - idparent = "ui:"; - CWidgetManager::parser->addParentPositionAssociation(this, idparent + string((const char*)ptr)); + { + if (parentGroup) + idparent = parentGroup->getId(); + } + CWidgetManager::parser->addParentSizeAssociation( this, idparent ); } + + ptr = (char*) xmlGetProp (cur, (xmlChar*)"sizeref"); + _SizeRef = 0; + _SizeDivW = 10; + _SizeDivH = 10; + if (ptr) + { + parseSizeRef(ptr.getDatas()); + sint32 nWhat = 0; + const char *seekPtr = ptr.getDatas(); + while (*seekPtr != 0) + { + if ((*seekPtr=='w')||(*seekPtr=='W')) + { + _SizeRef |= 1; + nWhat = 1; + } + + if ((*seekPtr=='h')||(*seekPtr=='H')) + { + _SizeRef |= 2; + nWhat = 2; + } + + if ((*seekPtr>='1')&&(*seekPtr<='9')) + { + if (nWhat != 0) + { + if (nWhat == 1) + _SizeDivW = *seekPtr-'0'; + if (nWhat == 2) + _SizeDivH = *seekPtr-'0'; + } + } + + ++seekPtr; + } + } + + // snapSize(); + + ptr= (char*) xmlGetProp (cur, (xmlChar*)"global_color"); + if(ptr) + { + _ModulateGlobalColor= convertBool(ptr); + } + + ptr= (char*) xmlGetProp (cur, (xmlChar*)"render_layer"); + if(ptr) fromString((const char*)ptr, _RenderLayer); + + ptr= (char*) xmlGetProp (cur, (xmlChar*)"avoid_resize_parent"); + if(ptr) _AvoidResizeParent= convertBool(ptr); + + return true; } - ptr = (char*) xmlGetProp( cur, (xmlChar*)"sizeparent" ); - if (ptr) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::setSizeRef(const std::string &sizeref) { - string idparent = ptr; - idparent = NLMISC::strlwr(idparent); - if (idparent != "parent") - { - if (parentGroup) - idparent = parentGroup->getId() +":" + string((const char*)ptr); - else - idparent = "ui:" + string((const char*)ptr); - } - else - { - if (parentGroup) - idparent = parentGroup->getId(); - } - CWidgetManager::parser->addParentSizeAssociation( this, idparent ); + parseSizeRef(sizeref.c_str()); } - ptr = (char*) xmlGetProp (cur, (xmlChar*)"sizeref"); - _SizeRef = 0; - _SizeDivW = 10; - _SizeDivH = 10; - if (ptr) + // ------------------------------------------------------------------------------------------------ + std::string CInterfaceElement::getSizeRefAsString() const { - parseSizeRef(ptr.getDatas()); + return "IMPLEMENT ME!"; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::parseSizeRef(const char *sizeRefStr) + { + parseSizeRef(sizeRefStr, _SizeRef, _SizeDivW, _SizeDivH); + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::parseSizeRef(const char *sizeRefStr, sint32 &sizeRef, sint32 &sizeDivW, sint32 &sizeDivH) + { + nlassert(sizeRefStr); + + sizeRef = 0; + sizeDivW = 10; + sizeDivH = 10; sint32 nWhat = 0; - const char *seekPtr = ptr.getDatas(); + const char *seekPtr = sizeRefStr; while (*seekPtr != 0) { if ((*seekPtr=='w')||(*seekPtr=='W')) { - _SizeRef |= 1; + sizeRef |= 1; nWhat = 1; } if ((*seekPtr=='h')||(*seekPtr=='H')) { - _SizeRef |= 2; + sizeRef |= 2; nWhat = 2; } @@ -205,9 +284,9 @@ bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) if (nWhat != 0) { if (nWhat == 1) - _SizeDivW = *seekPtr-'0'; + sizeDivW = *seekPtr-'0'; if (nWhat == 2) - _SizeDivH = *seekPtr-'0'; + sizeDivH = *seekPtr-'0'; } } @@ -215,1046 +294,971 @@ bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) } } -// snapSize(); - - ptr= (char*) xmlGetProp (cur, (xmlChar*)"global_color"); - if(ptr) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::updateCoords() { - _ModulateGlobalColor= convertBool(ptr); - } + _XReal = _X; + _YReal = _Y; + _WReal = getW(); + _HReal = getH(); - ptr= (char*) xmlGetProp (cur, (xmlChar*)"render_layer"); - if(ptr) fromString((const char*)ptr, _RenderLayer); + CInterfaceElement *el = NULL; - ptr= (char*) xmlGetProp (cur, (xmlChar*)"avoid_resize_parent"); - if(ptr) _AvoidResizeParent= convertBool(ptr); + // Modif Pos - return true; -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::setSizeRef(const std::string &sizeref) -{ - parseSizeRef(sizeref.c_str()); -} - -// ------------------------------------------------------------------------------------------------ -std::string CInterfaceElement::getSizeRefAsString() const -{ - return "IMPLEMENT ME!"; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::parseSizeRef(const char *sizeRefStr) -{ - parseSizeRef(sizeRefStr, _SizeRef, _SizeDivW, _SizeDivH); -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::parseSizeRef(const char *sizeRefStr, sint32 &sizeRef, sint32 &sizeDivW, sint32 &sizeDivH) -{ - nlassert(sizeRefStr); - - sizeRef = 0; - sizeDivW = 10; - sizeDivH = 10; - sint32 nWhat = 0; - const char *seekPtr = sizeRefStr; - while (*seekPtr != 0) - { - if ((*seekPtr=='w')||(*seekPtr=='W')) - { - sizeRef |= 1; - nWhat = 1; - } - - if ((*seekPtr=='h')||(*seekPtr=='H')) - { - sizeRef |= 2; - nWhat = 2; - } - - if ((*seekPtr>='1')&&(*seekPtr<='9')) - { - if (nWhat != 0) - { - if (nWhat == 1) - sizeDivW = *seekPtr-'0'; - if (nWhat == 2) - sizeDivH = *seekPtr-'0'; - } - } - - ++seekPtr; - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::updateCoords() -{ - _XReal = _X; - _YReal = _Y; - _WReal = getW(); - _HReal = getH(); - - CInterfaceElement *el = NULL; - - // Modif Pos - - if (_ParentPos != NULL) - el = _ParentPos; - else - el = _Parent; - - if (el == NULL) - return; - - _XReal += el->_XReal; - _YReal += el->_YReal; - - THotSpot hsParent = _ParentPosRef; - if (hsParent & Hotspot_Mx) - _YReal += el->_HReal/2; - if (hsParent & Hotspot_Tx) - _YReal += el->_HReal; - if (hsParent & Hotspot_xM) - _XReal += el->_WReal/2; - if (hsParent & Hotspot_xR) - _XReal += el->_WReal; - - // Modif Size - - if (_ParentSize != NULL) - { - el = _ParentSize; - } - else - { if (_ParentPos != NULL) el = _ParentPos; else el = _Parent; - } - if (el == NULL) - return; - - if (_SizeRef&1) - _WReal += _SizeDivW * el->_WReal / 10; - - if (_SizeRef&2) - _HReal += _SizeDivH * el->_HReal / 10; - - THotSpot hs = _PosRef; - if (hs & Hotspot_Mx) - _YReal -= _HReal/2; - if (hs & Hotspot_Tx) - _YReal -= _HReal; - if (hs & Hotspot_xM) - _XReal -= _WReal/2; - if (hs & Hotspot_xR) - _XReal -= _WReal; -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::getCorner(sint32 &px, sint32 &py, THotSpot hs) -{ - px = _XReal; - py = _YReal; - if (hs & 1) px += _WReal; - if (hs & 2) px += _WReal >> 1; - if (hs & 8) py += _HReal; - if (hs & 16) py += _HReal >> 1; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::move (sint32 dx, sint32 dy) -{ - _X += dx; - _Y += dy; - invalidateCoords(); -} - - - -// ------------------------------------------------------------------------------------------------ -/*void CInterfaceElement::resizeBR (sint32 sizeW, sint32 sizeH) -{ - uint32 i = i / 0; - THotSpot hs = _PosRef; - - sint32 dw = sizeW - _W; - sint32 dh = sizeH - _H; - - sint32 snap = _Snap; - nlassert(snap > 0); - - if (hs&8) // is top ? - { - sint32 newH = dh + _H; - if (snap > 1) - newH -= newH % snap; - _H = newH; - } - if (hs&32) // is bottom ? - { - sint32 newH = dh + _H; - if (snap > 1) - newH -= newH % snap; - _Y = _H - newH + _Y; - _H = newH; - } - - if (hs&1) // is right ? - { - sint32 newW = dw + _W; - if (snap > 1) - newW -= newW % snap; - _X = newW - _W + _X; - _W = newW; - } - if (hs&4) // is left ? - { - sint32 newW = dw + _W; - if (snap > 1) - newW -= newW % snap; - _W = newW; - } - - // DO NOT TREAT THE MIDDLE HOTSPOT CASE - - invalidateCoords(); -}*/ - - -// ------------------------------------------------------------------------------------------------ -/*void CInterfaceElement::snapSize() -{ - sint32 snap = _Snap; - nlassert(snap > 0); - if (snap > 1) - { - _W = _W - (_W % snap); - _H = _H - (_H % snap); - } -}*/ - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::setW (sint32 w) -{ - _W = w; -// sint32 snap = _Snap; -// nlassert(snap > 0); -// if (snap > 1) -// { -// _W = _W - (_W % snap); -// } -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::setH (sint32 h) -{ - _H = h; -// sint32 snap = _Snap; -// nlassert(snap > 0); -// if (snap > 1) -// { -// _H = _H - (_H % snap); -// } -} - - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CInterfaceElement::getRootWindow () -{ - if (_Parent == NULL) - return NULL; - if (_Parent->getParent() == NULL) - return dynamic_cast(this); - return _Parent->getRootWindow(); -} - -// ------------------------------------------------------------------------------------------------ -uint CInterfaceElement::getParentDepth() const -{ - uint depth= 0; - CInterfaceGroup *parent= _Parent; - while(parent!=NULL) - { - parent= parent->getParent(); - depth++; - } - return depth; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceElement::isActiveThroughParents() const -{ - if(!getActive()) - return false; - if(_Parent == NULL) - return false; - // is it the root window? - if (_Parent->getParent() == NULL) - // yes and getActive() is true => the element is visible! - return true; - else - return _Parent->isActiveThroughParents(); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::relativeSInt64Read (CInterfaceProperty &rIP, const string &prop, const char *val, - const string &defVal) -{ - if (val == NULL) - { - rIP.readSInt64 (defVal.c_str(), _Id+":"+prop); - } - else - { - if ( isdigit(*val) || *val=='-') - { - rIP.readSInt64 (val, _Id+":"+prop); + if (el == NULL) return; - } - sint32 decal = 0; - if (val[0] == ':') - decal = 1; - if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) + _XReal += el->_XReal; + _YReal += el->_YReal; + + THotSpot hsParent = _ParentPosRef; + if (hsParent & Hotspot_Mx) + _YReal += el->_HReal/2; + if (hsParent & Hotspot_Tx) + _YReal += el->_HReal; + if (hsParent & Hotspot_xM) + _XReal += el->_WReal/2; + if (hsParent & Hotspot_xR) + _XReal += el->_WReal; + + // Modif Size + + if (_ParentSize != NULL) { - rIP.readSInt64 (val+decal, _Id+":"+prop); - return; + el = _ParentSize; } else { - string sTmp; - CInterfaceElement *pIEL = this; - - while (pIEL != NULL) - { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) - { - rIP.readSInt64 (sTmp.c_str(), _Id+":"+prop); - return; - } - pIEL = pIEL->getParent(); - } - - rIP.readSInt64 (val+decal, _Id+":"+prop); + if (_ParentPos != NULL) + el = _ParentPos; + else + el = _Parent; } - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::relativeSInt32Read (CInterfaceProperty &rIP, const string &prop, const char *val, - const string &defVal) -{ - if (val == NULL) - { - rIP.readSInt32 (defVal.c_str(), _Id+":"+prop); - } - else - { - if ( isdigit(*val) || *val=='-') - { - rIP.readSInt32 (val, _Id+":"+prop); + if (el == NULL) return; - } - sint32 decal = 0; - if (val[0] == ':') - decal = 1; - if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) - { - rIP.readSInt32 (val+decal, _Id+":"+prop); - return; - } - else - { - string sTmp; - CInterfaceElement *pIEL = this; + if (_SizeRef&1) + _WReal += _SizeDivW * el->_WReal / 10; - while (pIEL != NULL) - { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) - { - rIP.readSInt32 (sTmp.c_str(), _Id+":"+prop); - return; - } - pIEL = pIEL->getParent(); - } + if (_SizeRef&2) + _HReal += _SizeDivH * el->_HReal / 10; - rIP.readSInt32 (val+decal, _Id+":"+prop); - } + THotSpot hs = _PosRef; + if (hs & Hotspot_Mx) + _YReal -= _HReal/2; + if (hs & Hotspot_Tx) + _YReal -= _HReal; + if (hs & Hotspot_xM) + _XReal -= _WReal/2; + if (hs & Hotspot_xR) + _XReal -= _WReal; } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::relativeBoolRead (CInterfaceProperty &rIP, const string &prop, const char *val, - const string &defVal) -{ - if (val == NULL) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::getCorner(sint32 &px, sint32 &py, THotSpot hs) { - rIP.readBool (defVal.c_str(), _Id+":"+prop); + px = _XReal; + py = _YReal; + if (hs & 1) px += _WReal; + if (hs & 2) px += _WReal >> 1; + if (hs & 8) py += _HReal; + if (hs & 16) py += _HReal >> 1; } - else + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::move (sint32 dx, sint32 dy) { - sint32 decal = 0; - if (val[0] == ':') - decal = 1; - if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) - { - rIP.readBool (val+decal, _Id+":"+prop); - return; - } - else - { - string sTmp; - CInterfaceElement *pIEL = this; - - while (pIEL != NULL) - { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) - { - rIP.readBool (sTmp.c_str(), _Id+":"+prop); - return; - } - pIEL = pIEL->getParent(); - } - - rIP.readBool (val+decal, _Id+":"+prop); - } - } -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::relativeRGBARead(CInterfaceProperty &rIP,const std::string &prop,const char *val,const std::string &defVal) -{ - if (val == NULL) - { - rIP.readRGBA (defVal.c_str(), _Id+":"+prop); - } - else - { - if ( isdigit(*val) || *val=='-') - { - rIP.readRGBA (val, _Id+":"+prop); - return; - } - - sint32 decal = 0; - if (val[0] == ':') - decal = 1; - if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) - { - rIP.readRGBA (val+decal, _Id+":"+prop); - return; - } - else - { - string sTmp; - CInterfaceElement *pIEL = this; - - while (pIEL != NULL) - { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) - { - rIP.readRGBA (sTmp.c_str(), _Id+":"+prop); - return; - } - pIEL = pIEL->getParent(); - } - - rIP.readRGBA (val+decal, _Id+":"+prop); - } - } -} - - -// ------------------------------------------------------------------------------------------------ -THotSpot CInterfaceElement::convertHotSpot (const char *ptr) -{ - if ( !strnicmp(ptr,"TL",2) ) - { - return Hotspot_TL; - } - else if ( !strnicmp(ptr,"TM",2) ) - { - return Hotspot_TM; - } - else if ( !strnicmp(ptr,"TR",2) ) - { - return Hotspot_TR; - } - else if ( !strnicmp(ptr,"ML",2) ) - { - return Hotspot_ML; - } - else if ( !strnicmp(ptr,"MM",2) ) - { - return Hotspot_MM; - } - else if ( !strnicmp(ptr,"MR",2) ) - { - return Hotspot_MR; - } - else if ( !strnicmp(ptr,"BL",2) ) - { - return Hotspot_BL; - } - else if ( !strnicmp(ptr,"BM",2) ) - { - return Hotspot_BM; - } - else if ( !strnicmp(ptr,"BR",2) ) - { - return Hotspot_BR; - } - else - return Hotspot_BL; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::convertHotSpotCouple (const char *ptr, THotSpot &parentPosRef, THotSpot &posRef) -{ - nlassert(ptr); - - // *** first hotspot - // skip any space or tab - while(*ptr=='\t' || *ptr==' ') - ptr++; - // convert first - parentPosRef = convertHotSpot (ptr); - - // *** second hotspot - // must be at least 2 letter and a space - nlassert(strlen(ptr)>=3); - ptr+=3; - // skip any space or tab - while(*ptr=='\t' || *ptr==' ') - ptr++; - // convert second - posRef = convertHotSpot (ptr); -} - -// ------------------------------------------------------------------------------------------------ -NLMISC::CRGBA CInterfaceElement::convertColor (const char *ptr) -{ - return NLMISC::CRGBA::stringToRGBA(ptr); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceElement::convertBool (const char *ptr) -{ - string str= ptr; - NLMISC::strlwr(str); - return str=="true"?true:false; -} - -// ------------------------------------------------------------------------------------------------ -NLMISC::CVector CInterfaceElement::convertVector (const char *ptr) -{ - float x = 0.0f, y = 0.0f, z = 0.0f; - - sscanf (ptr, "%f %f %f", &x, &y, &z); - - return CVector(x,y,z); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::convertPixelsOrRatio(const char *ptr, sint32 &pixels, float &ratio) -{ - std::string value = ptr; - if (!value.empty()) - { - if (value[value.size() - 1] == '%') - { - value.resize(value.size() - 1); - fromString(value, ratio); - ratio /= 100.f; - clamp(ratio, 0.f, 1.f); - } - else - { - fromString(value, pixels); - } - } -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::addLink(CInterfaceLink *link) -{ - nlassert(link != NULL); - if (!_Links) - { - _Links = new TLinkVect; - } - TLinkSmartPtr linkPtr(link); - TLinkVect::const_iterator it = std::find(_Links->begin(), _Links->end(), linkPtr); - if (it != _Links->end()) - { - // Link already appened : this can be the case when a link has several targets property that belong to the same element, in this case, one single ptr in the vector is enough. - // nlwarning("Link added twice"); - } - else - { - _Links->push_back(linkPtr); - } -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::removeLink(CInterfaceLink *link) -{ - nlassert(link != NULL); - if (!_Links) - { - nlwarning("No link added"); - return; - } - TLinkVect::iterator it = std::find(_Links->begin(), _Links->end(), TLinkSmartPtr(link)); - if (it == _Links->end()) - { - nlwarning("Unknown link"); - return; - } - _Links->erase(it); // kill the smart ptr, maybe deleting the link. - if (_Links->empty()) - { - delete _Links; - _Links = NULL; - } -} - - -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CInterfaceElement::getMasterGroup() const -{ - if(getParent()==NULL) - return const_cast(this); - else - return getParent()->getMasterGroup(); -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CInterfaceElement::getParentContainer() -{ - CInterfaceElement *parent = this; - while (parent) - { - CInterfaceGroup *gc = dynamic_cast< CInterfaceGroup* >( parent ); - if( ( gc != NULL ) && gc->isGroupContainer() ) - return gc; - - parent = parent->getParent(); - } - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceElement::isIn(sint x, sint y) const -{ - return (x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal+ _HReal)); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceElement::isIn(sint x, sint y, uint width, uint height) const -{ - return (x + (sint) width) >= _XReal && - (y + (sint) height) > _YReal && - x < (_XReal + _WReal) && - y <= (_YReal + _HReal); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceElement::isIn(const CInterfaceElement &other) const -{ - return isIn(other._XReal, other._YReal, other._WReal, other._HReal); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::setActive (bool state) -{ - if (_Active != state) - { - _Active = state; + _X += dx; + _Y += dy; invalidateCoords(); } -} -// *************************************************************************** -void CInterfaceElement::invalidateCoords(uint8 numPass) -{ - // Get the "Root Group" ie the 1st son of the master group of us (eg "ui:interface:rootgroup" ) - CInterfaceGroup *parent= getParent(); - // if our parent is NULL, then we are the master group (error!) - if(parent==NULL) - return; - // if our grandfather is NULL, then our father is the Master Group => we are the "Root group" - if(parent->getParent()==NULL) + + // ------------------------------------------------------------------------------------------------ + /*void CInterfaceElement::resizeBR (sint32 sizeW, sint32 sizeH) { - parent= dynamic_cast(this); + uint32 i = i / 0; + THotSpot hs = _PosRef; + + sint32 dw = sizeW - _W; + sint32 dh = sizeH - _H; + + sint32 snap = _Snap; + nlassert(snap > 0); + + if (hs&8) // is top ? + { + sint32 newH = dh + _H; + if (snap > 1) + newH -= newH % snap; + _H = newH; + } + if (hs&32) // is bottom ? + { + sint32 newH = dh + _H; + if (snap > 1) + newH -= newH % snap; + _Y = _H - newH + _Y; + _H = newH; + } + + if (hs&1) // is right ? + { + sint32 newW = dw + _W; + if (snap > 1) + newW -= newW % snap; + _X = newW - _W + _X; + _W = newW; + } + if (hs&4) // is left ? + { + sint32 newW = dw + _W; + if (snap > 1) + newW -= newW % snap; + _W = newW; + } + + // DO NOT TREAT THE MIDDLE HOTSPOT CASE + + invalidateCoords(); + }*/ + + + // ------------------------------------------------------------------------------------------------ + /*void CInterfaceElement::snapSize() + { + sint32 snap = _Snap; + nlassert(snap > 0); + if (snap > 1) + { + _W = _W - (_W % snap); + _H = _H - (_H % snap); + } + }*/ + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::setW (sint32 w) + { + _W = w; + // sint32 snap = _Snap; + // nlassert(snap > 0); + // if (snap > 1) + // { + // _W = _W - (_W % snap); + // } } - else + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::setH (sint32 h) { - // parent is the root group when is grandFather is NULL - while( parent->getParent()->getParent()!=NULL ) + _H = h; + // sint32 snap = _Snap; + // nlassert(snap > 0); + // if (snap > 1) + // { + // _H = _H - (_H % snap); + // } + } + + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CInterfaceElement::getRootWindow () + { + if (_Parent == NULL) + return NULL; + if (_Parent->getParent() == NULL) + return dynamic_cast(this); + return _Parent->getRootWindow(); + } + + // ------------------------------------------------------------------------------------------------ + uint CInterfaceElement::getParentDepth() const + { + uint depth= 0; + CInterfaceGroup *parent= _Parent; + while(parent!=NULL) { parent= parent->getParent(); + depth++; } + return depth; } - // invalidate the "root group" - if(parent) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::isActiveThroughParents() const { - uint8 &val= static_cast(parent)->_InvalidCoords; - val= max(val, numPass); + if(!getActive()) + return false; + if(_Parent == NULL) + return false; + // is it the root window? + if (_Parent->getParent() == NULL) + // yes and getActive() is true => the element is visible! + return true; + else + return _Parent->isActiveThroughParents(); } -} - -// *************************************************************************** -void CInterfaceElement::checkCoords() -{ -} - -// *************************************************************************** -bool CInterfaceElement::isSonOf(const CInterfaceElement *other) const -{ - const CInterfaceElement *currElem = this; - do + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::relativeSInt64Read (CInterfaceProperty &rIP, const string &prop, const char *val, + const string &defVal) { - if (currElem == other) return true; - currElem = currElem->_Parent; - } - while (currElem); - return false; -} - -// *************************************************************************** -void CInterfaceElement::resetInvalidCoords() -{ - _InvalidCoords= 0; -} - -// *************************************************************************** -void CInterfaceElement::updateAllLinks() -{ - if (_Links) - { - for(TLinkVect::iterator it = _Links->begin(); it != _Links->end(); ++it) + if (val == NULL) { - (*it)->update(); + rIP.readSInt64 (defVal.c_str(), _Id+":"+prop); + } + else + { + if ( isdigit(*val) || *val=='-') + { + rIP.readSInt64 (val, _Id+":"+prop); + return; + } + + sint32 decal = 0; + if (val[0] == ':') + decal = 1; + if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) + { + rIP.readSInt64 (val+decal, _Id+":"+prop); + return; + } + else + { + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) + { + sTmp = pIEL->getId()+":"+string(val+decal); + if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + { + rIP.readSInt64 (sTmp.c_str(), _Id+":"+prop); + return; + } + pIEL = pIEL->getParent(); + } + + rIP.readSInt64 (val+decal, _Id+":"+prop); + } } } -} -// *************************************************************************** -void CInterfaceElement::copyOptionFrom(const CInterfaceElement &other) -{ - _Active = other._Active; - _InvalidCoords = other._InvalidCoords; - _XReal = other._XReal; - _YReal = other._YReal; - _WReal = other._WReal; - _HReal = other._HReal; - _X = other._X; - _Y = other._Y; - _XReal = other._XReal; - _YReal = other._YReal; - _PosRef = other._PosRef; - _ParentPosRef = other._ParentPosRef; - _SizeRef = other._SizeRef; - _SizeDivW = other._SizeDivW; - _SizeDivH = other._SizeDivH; - _ModulateGlobalColor = other._ModulateGlobalColor; - _RenderLayer = other._RenderLayer; -} - -// *************************************************************************** -void CInterfaceElement::center() -{ - // center the pc - CViewRenderer &vr = *CViewRenderer::getInstance(); - uint32 sw, sh; - vr.getScreenSize(sw, sh); - setX(sw / 2 - getWReal() / 2); - setY(sh / 2 + getHReal() / 2); -} - -// *************************************************************************** -void CInterfaceElement::renderWiredQuads(TRenderWired type, const std::string &uiFilter) -{ - CCtrlBase *ctrlBase = dynamic_cast(this); - CInterfaceGroup *groupBase = dynamic_cast(this); - if ( - ((type == RenderView) && (ctrlBase==NULL) && (groupBase==NULL)) || - ((type == RenderCtrl) && (ctrlBase!=NULL) && (groupBase==NULL)) || - ((type == RenderGroup) && (ctrlBase!=NULL) && (groupBase!=NULL))) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::relativeSInt32Read (CInterfaceProperty &rIP, const string &prop, const char *val, + const string &defVal) { - if (!_Active) return; - // if there is an uiFilter, the end of _Id must match it - if (!uiFilter.empty() && (uiFilter.size()>_Id.size() || - _Id.compare(_Id.size()-uiFilter.size(),string::npos,uiFilter)!=0) - ) + if (val == NULL) + { + rIP.readSInt32 (defVal.c_str(), _Id+":"+prop); + } + else + { + if ( isdigit(*val) || *val=='-') + { + rIP.readSInt32 (val, _Id+":"+prop); + return; + } + + sint32 decal = 0; + if (val[0] == ':') + decal = 1; + if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) + { + rIP.readSInt32 (val+decal, _Id+":"+prop); + return; + } + else + { + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) + { + sTmp = pIEL->getId()+":"+string(val+decal); + if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + { + rIP.readSInt32 (sTmp.c_str(), _Id+":"+prop); + return; + } + pIEL = pIEL->getParent(); + } + + rIP.readSInt32 (val+decal, _Id+":"+prop); + } + } + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::relativeBoolRead (CInterfaceProperty &rIP, const string &prop, const char *val, + const string &defVal) + { + if (val == NULL) + { + rIP.readBool (defVal.c_str(), _Id+":"+prop); + } + else + { + sint32 decal = 0; + if (val[0] == ':') + decal = 1; + if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) + { + rIP.readBool (val+decal, _Id+":"+prop); + return; + } + else + { + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) + { + sTmp = pIEL->getId()+":"+string(val+decal); + if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + { + rIP.readBool (sTmp.c_str(), _Id+":"+prop); + return; + } + pIEL = pIEL->getParent(); + } + + rIP.readBool (val+decal, _Id+":"+prop); + } + } + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::relativeRGBARead(CInterfaceProperty &rIP,const std::string &prop,const char *val,const std::string &defVal) + { + if (val == NULL) + { + rIP.readRGBA (defVal.c_str(), _Id+":"+prop); + } + else + { + if ( isdigit(*val) || *val=='-') + { + rIP.readRGBA (val, _Id+":"+prop); + return; + } + + sint32 decal = 0; + if (val[0] == ':') + decal = 1; + if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) + { + rIP.readRGBA (val+decal, _Id+":"+prop); + return; + } + else + { + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) + { + sTmp = pIEL->getId()+":"+string(val+decal); + if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + { + rIP.readRGBA (sTmp.c_str(), _Id+":"+prop); + return; + } + pIEL = pIEL->getParent(); + } + + rIP.readRGBA (val+decal, _Id+":"+prop); + } + } + } + + + // ------------------------------------------------------------------------------------------------ + THotSpot CInterfaceElement::convertHotSpot (const char *ptr) + { + if ( !strnicmp(ptr,"TL",2) ) + { + return Hotspot_TL; + } + else if ( !strnicmp(ptr,"TM",2) ) + { + return Hotspot_TM; + } + else if ( !strnicmp(ptr,"TR",2) ) + { + return Hotspot_TR; + } + else if ( !strnicmp(ptr,"ML",2) ) + { + return Hotspot_ML; + } + else if ( !strnicmp(ptr,"MM",2) ) + { + return Hotspot_MM; + } + else if ( !strnicmp(ptr,"MR",2) ) + { + return Hotspot_MR; + } + else if ( !strnicmp(ptr,"BL",2) ) + { + return Hotspot_BL; + } + else if ( !strnicmp(ptr,"BM",2) ) + { + return Hotspot_BM; + } + else if ( !strnicmp(ptr,"BR",2) ) + { + return Hotspot_BR; + } + else + return Hotspot_BL; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::convertHotSpotCouple (const char *ptr, THotSpot &parentPosRef, THotSpot &posRef) + { + nlassert(ptr); + + // *** first hotspot + // skip any space or tab + while(*ptr=='\t' || *ptr==' ') + ptr++; + // convert first + parentPosRef = convertHotSpot (ptr); + + // *** second hotspot + // must be at least 2 letter and a space + nlassert(strlen(ptr)>=3); + ptr+=3; + // skip any space or tab + while(*ptr=='\t' || *ptr==' ') + ptr++; + // convert second + posRef = convertHotSpot (ptr); + } + + // ------------------------------------------------------------------------------------------------ + NLMISC::CRGBA CInterfaceElement::convertColor (const char *ptr) + { + return NLMISC::CRGBA::stringToRGBA(ptr); + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::convertBool (const char *ptr) + { + string str= ptr; + NLMISC::strlwr(str); + return str=="true"?true:false; + } + + // ------------------------------------------------------------------------------------------------ + NLMISC::CVector CInterfaceElement::convertVector (const char *ptr) + { + float x = 0.0f, y = 0.0f, z = 0.0f; + + sscanf (ptr, "%f %f %f", &x, &y, &z); + + return CVector(x,y,z); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::convertPixelsOrRatio(const char *ptr, sint32 &pixels, float &ratio) + { + std::string value = ptr; + if (!value.empty()) + { + if (value[value.size() - 1] == '%') + { + value.resize(value.size() - 1); + fromString(value, ratio); + ratio /= 100.f; + clamp(ratio, 0.f, 1.f); + } + else + { + fromString(value, pixels); + } + } + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::addLink(CInterfaceLink *link) + { + nlassert(link != NULL); + if (!_Links) + { + _Links = new TLinkVect; + } + TLinkSmartPtr linkPtr(link); + TLinkVect::const_iterator it = std::find(_Links->begin(), _Links->end(), linkPtr); + if (it != _Links->end()) + { + // Link already appened : this can be the case when a link has several targets property that belong to the same element, in this case, one single ptr in the vector is enough. + // nlwarning("Link added twice"); + } + else + { + _Links->push_back(linkPtr); + } + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::removeLink(CInterfaceLink *link) + { + nlassert(link != NULL); + if (!_Links) + { + nlwarning("No link added"); return; - CViewRenderer &vr = *CViewRenderer::getInstance(); - vr.drawWiredQuad(_XReal, _YReal, _WReal, _HReal); - drawHotSpot(_PosRef, CRGBA::Red); - if (_Parent) _Parent->drawHotSpot(_ParentPosRef, CRGBA::Blue); - } -} - -// *************************************************************************** -void CInterfaceElement::drawHotSpot(THotSpot hs, CRGBA col) -{ - const sint32 radius = 2; - sint32 px, py; - // - if (hs & Hotspot_Bx) - { - py = _YReal + radius; - } - else if (hs & Hotspot_Mx) - { - py = _YReal + _HReal / 2; - } - else - { - py = _YReal + _HReal - radius; - } - // - if (hs & Hotspot_xL) - { - px = _XReal + radius; - } - else if (hs & Hotspot_xM) - { - px = _XReal + _WReal / 2; - } - else - { - px = _XReal + _WReal - radius; - } - CViewRenderer &vr = *CViewRenderer::getInstance(); - vr.drawFilledQuad(px - radius, py - radius, radius * 2, radius * 2, col); - -} - -// *************************************************************************** -void CInterfaceElement::invalidateContent() -{ - CInterfaceElement *elm = this; - while (elm) - { - // Call back - elm->onInvalidateContent(); - - // Get the parent - elm = elm->getParent(); - } -} - -// *************************************************************************** -void CInterfaceElement::visit(CInterfaceElementVisitor *visitor) -{ - nlassert(visitor); - visitor->visit(this); -} - -// *************************************************************************** -void CInterfaceElement::serialConfig(NLMISC::IStream &f) -{ - if (f.isReading()) - { - throw NLMISC::ENewerStream(f); - nlassert(0); - } -} - -// *************************************************************************** -void CInterfaceElement::onFrameUpdateWindowPos(sint dx, sint dy) -{ - _XReal+= dx; - _YReal+= dy; -} - -// *************************************************************************** -void CInterfaceElement::dummySet(sint32 /* value */) -{ - nlwarning("Element can't be written."); -} - -// *************************************************************************** -void CInterfaceElement::dummySet(const std::string &/* value */) -{ - nlwarning("Element can't be written."); -} - -// *************************************************************************** -int CInterfaceElement::luaUpdateCoords(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "updateCoords", 0); - updateCoords(); - return 0; -} - -// *************************************************************************** -int CInterfaceElement::luaInvalidateCoords(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "updateCoords", 0); - invalidateCoords(); - return 0; -} - -// *************************************************************************** -int CInterfaceElement::luaInvalidateContent(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "invalidateContent", 0); - invalidateContent(); - return 0; -} - -// *************************************************************************** -int CInterfaceElement::luaCenter(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "center", 0); - center(); - return 0; -} - -// *************************************************************************** -int CInterfaceElement::luaSetPosRef(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "setPosRef", 1); - CLuaIHM::check(ls, ls.isString(1), "setPosRef() requires a string in param 1"); - - // get hotspot - THotSpot newParentPosRef, newPosRef; - convertHotSpotCouple(ls.toString(1), newParentPosRef, newPosRef); - - // if different from current, set,a nd invalidate coords - if(newParentPosRef!=getParentPosRef() || newPosRef!=getPosRef()) - { - setParentPosRef(newParentPosRef); - setPosRef(newPosRef); - invalidateCoords(); - } - - return 0; -} - -// *************************************************************************** -int CInterfaceElement::luaSetParentPos(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "setParentPos", 1); - CInterfaceElement *ie = CLuaIHM::getUIOnStack(ls, 1); - if(ie) - { - setParentPos(ie); - } - return 0; -} - - - -// *************************************************************************** -CInterfaceElement *CInterfaceElement::clone() -{ - NLMISC::CMemStream dupStream; - nlassert(!dupStream.isReading()); - CInterfaceGroup *oldParent = _Parent; - _Parent = NULL; - CInterfaceElement *oldParentPos = _ParentPos; - CInterfaceElement *oldParentSize = _ParentSize; - if (_ParentPos == oldParent) _ParentPos = NULL; - if (_ParentSize == oldParent) _ParentSize = NULL; - CInterfaceElement *begunThisCloneWarHas = NULL; - try - { - if (dupStream.isReading()) - { - dupStream.invert(); } - CInterfaceElement *self = this; - dupStream.serialPolyPtr(self); - std::vector datas(dupStream.length()); - std::copy(dupStream.buffer(), dupStream.buffer() + dupStream.length(), datas.begin()); - dupStream.resetPtrTable(); - dupStream.invert(); - dupStream.fill(&datas[0], (uint32)datas.size()); - dupStream.serialPolyPtr(begunThisCloneWarHas); + TLinkVect::iterator it = std::find(_Links->begin(), _Links->end(), TLinkSmartPtr(link)); + if (it == _Links->end()) + { + nlwarning("Unknown link"); + return; + } + _Links->erase(it); // kill the smart ptr, maybe deleting the link. + if (_Links->empty()) + { + delete _Links; + _Links = NULL; + } } - catch(const NLMISC::EStream &) - { - // no-op -> caller has to handle the failure because NULL will be returned - } - // - _Parent = oldParent; - _ParentPos = oldParentPos; - _ParentSize = oldParentSize; - // - return begunThisCloneWarHas; -} - -// *************************************************************************** -void CInterfaceElement::serial(NLMISC::IStream &f) -{ - f.serialPolyPtr(_Parent); - f.serial(_Id); - f.serial(_Active); - f.serial(_InvalidCoords); - f.serial(_XReal, _YReal, _WReal, _HReal); - f.serial(_X, _Y, _W, _H); - f.serialEnum(_PosRef); - f.serialEnum(_ParentPosRef); - _ParentPos.serialPolyPtr(f); - f.serial(_SizeRef); - f.serial(_SizeDivW, _SizeDivH); - _ParentSize.serialPolyPtr(f); - f.serial(_ModulateGlobalColor); - f.serial(_RenderLayer); - f.serial(_AvoidResizeParent); - nlassert(_Links == NULL); // not supported -} -// *************************************************************************** -void CInterfaceElement::serialAH(NLMISC::IStream &f, IActionHandler *&ah) -{ - std::string ahName; - if (f.isReading()) + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CInterfaceElement::getMasterGroup() const { - f.serial(ahName); - ah = CAHManager::getInstance()->getActionHandler(ahName); + if(getParent()==NULL) + return const_cast(this); + else + return getParent()->getMasterGroup(); } - else + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CInterfaceElement::getParentContainer() { - ahName = CAHManager::getInstance()->getActionHandlerName(ah); - f.serial(ahName); + CInterfaceElement *parent = this; + while (parent) + { + CInterfaceGroup *gc = dynamic_cast< CInterfaceGroup* >( parent ); + if( ( gc != NULL ) && gc->isGroupContainer() ) + return gc; + + parent = parent->getParent(); + } + return NULL; } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::isIn(sint x, sint y) const + { + return (x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal+ _HReal)); + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::isIn(sint x, sint y, uint width, uint height) const + { + return (x + (sint) width) >= _XReal && + (y + (sint) height) > _YReal && + x < (_XReal + _WReal) && + y <= (_YReal + _HReal); + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::isIn(const CInterfaceElement &other) const + { + return isIn(other._XReal, other._YReal, other._WReal, other._HReal); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::setActive (bool state) + { + if (_Active != state) + { + _Active = state; + invalidateCoords(); + } + } + + + // *************************************************************************** + void CInterfaceElement::invalidateCoords(uint8 numPass) + { + // Get the "Root Group" ie the 1st son of the master group of us (eg "ui:interface:rootgroup" ) + CInterfaceGroup *parent= getParent(); + // if our parent is NULL, then we are the master group (error!) + if(parent==NULL) + return; + // if our grandfather is NULL, then our father is the Master Group => we are the "Root group" + if(parent->getParent()==NULL) + { + parent= dynamic_cast(this); + } + else + { + // parent is the root group when is grandFather is NULL + while( parent->getParent()->getParent()!=NULL ) + { + parent= parent->getParent(); + } + } + + // invalidate the "root group" + if(parent) + { + uint8 &val= static_cast(parent)->_InvalidCoords; + val= max(val, numPass); + } + } + + + // *************************************************************************** + void CInterfaceElement::checkCoords() + { + } + + // *************************************************************************** + bool CInterfaceElement::isSonOf(const CInterfaceElement *other) const + { + const CInterfaceElement *currElem = this; + do + { + if (currElem == other) return true; + currElem = currElem->_Parent; + } + while (currElem); + return false; + } + + // *************************************************************************** + void CInterfaceElement::resetInvalidCoords() + { + _InvalidCoords= 0; + } + + // *************************************************************************** + void CInterfaceElement::updateAllLinks() + { + if (_Links) + { + for(TLinkVect::iterator it = _Links->begin(); it != _Links->end(); ++it) + { + (*it)->update(); + } + } + } + + // *************************************************************************** + void CInterfaceElement::copyOptionFrom(const CInterfaceElement &other) + { + _Active = other._Active; + _InvalidCoords = other._InvalidCoords; + _XReal = other._XReal; + _YReal = other._YReal; + _WReal = other._WReal; + _HReal = other._HReal; + _X = other._X; + _Y = other._Y; + _XReal = other._XReal; + _YReal = other._YReal; + _PosRef = other._PosRef; + _ParentPosRef = other._ParentPosRef; + _SizeRef = other._SizeRef; + _SizeDivW = other._SizeDivW; + _SizeDivH = other._SizeDivH; + _ModulateGlobalColor = other._ModulateGlobalColor; + _RenderLayer = other._RenderLayer; + + } + + // *************************************************************************** + void CInterfaceElement::center() + { + // center the pc + CViewRenderer &vr = *CViewRenderer::getInstance(); + uint32 sw, sh; + vr.getScreenSize(sw, sh); + setX(sw / 2 - getWReal() / 2); + setY(sh / 2 + getHReal() / 2); + } + + // *************************************************************************** + void CInterfaceElement::renderWiredQuads(TRenderWired type, const std::string &uiFilter) + { + CCtrlBase *ctrlBase = dynamic_cast(this); + CInterfaceGroup *groupBase = dynamic_cast(this); + if ( + ((type == RenderView) && (ctrlBase==NULL) && (groupBase==NULL)) || + ((type == RenderCtrl) && (ctrlBase!=NULL) && (groupBase==NULL)) || + ((type == RenderGroup) && (ctrlBase!=NULL) && (groupBase!=NULL))) + { + if (!_Active) return; + // if there is an uiFilter, the end of _Id must match it + if (!uiFilter.empty() && (uiFilter.size()>_Id.size() || + _Id.compare(_Id.size()-uiFilter.size(),string::npos,uiFilter)!=0) + ) + return; + CViewRenderer &vr = *CViewRenderer::getInstance(); + vr.drawWiredQuad(_XReal, _YReal, _WReal, _HReal); + drawHotSpot(_PosRef, CRGBA::Red); + if (_Parent) _Parent->drawHotSpot(_ParentPosRef, CRGBA::Blue); + } + } + + // *************************************************************************** + void CInterfaceElement::drawHotSpot(THotSpot hs, CRGBA col) + { + const sint32 radius = 2; + sint32 px, py; + // + if (hs & Hotspot_Bx) + { + py = _YReal + radius; + } + else if (hs & Hotspot_Mx) + { + py = _YReal + _HReal / 2; + } + else + { + py = _YReal + _HReal - radius; + } + // + if (hs & Hotspot_xL) + { + px = _XReal + radius; + } + else if (hs & Hotspot_xM) + { + px = _XReal + _WReal / 2; + } + else + { + px = _XReal + _WReal - radius; + } + CViewRenderer &vr = *CViewRenderer::getInstance(); + vr.drawFilledQuad(px - radius, py - radius, radius * 2, radius * 2, col); + + } + + // *************************************************************************** + void CInterfaceElement::invalidateContent() + { + CInterfaceElement *elm = this; + while (elm) + { + // Call back + elm->onInvalidateContent(); + + // Get the parent + elm = elm->getParent(); + } + } + + // *************************************************************************** + void CInterfaceElement::visit(CInterfaceElementVisitor *visitor) + { + nlassert(visitor); + visitor->visit(this); + } + + // *************************************************************************** + void CInterfaceElement::serialConfig(NLMISC::IStream &f) + { + if (f.isReading()) + { + throw NLMISC::ENewerStream(f); + nlassert(0); + } + } + + // *************************************************************************** + void CInterfaceElement::onFrameUpdateWindowPos(sint dx, sint dy) + { + _XReal+= dx; + _YReal+= dy; + } + + // *************************************************************************** + void CInterfaceElement::dummySet(sint32 /* value */) + { + nlwarning("Element can't be written."); + } + + // *************************************************************************** + void CInterfaceElement::dummySet(const std::string &/* value */) + { + nlwarning("Element can't be written."); + } + + // *************************************************************************** + int CInterfaceElement::luaUpdateCoords(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "updateCoords", 0); + updateCoords(); + return 0; + } + + // *************************************************************************** + int CInterfaceElement::luaInvalidateCoords(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "updateCoords", 0); + invalidateCoords(); + return 0; + } + + // *************************************************************************** + int CInterfaceElement::luaInvalidateContent(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "invalidateContent", 0); + invalidateContent(); + return 0; + } + + // *************************************************************************** + int CInterfaceElement::luaCenter(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "center", 0); + center(); + return 0; + } + + // *************************************************************************** + int CInterfaceElement::luaSetPosRef(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "setPosRef", 1); + CLuaIHM::check(ls, ls.isString(1), "setPosRef() requires a string in param 1"); + + // get hotspot + THotSpot newParentPosRef, newPosRef; + convertHotSpotCouple(ls.toString(1), newParentPosRef, newPosRef); + + // if different from current, set,a nd invalidate coords + if(newParentPosRef!=getParentPosRef() || newPosRef!=getPosRef()) + { + setParentPosRef(newParentPosRef); + setPosRef(newPosRef); + invalidateCoords(); + } + + return 0; + } + + // *************************************************************************** + int CInterfaceElement::luaSetParentPos(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "setParentPos", 1); + CInterfaceElement *ie = CLuaIHM::getUIOnStack(ls, 1); + if(ie) + { + setParentPos(ie); + } + return 0; + } + + + + // *************************************************************************** + CInterfaceElement *CInterfaceElement::clone() + { + NLMISC::CMemStream dupStream; + nlassert(!dupStream.isReading()); + CInterfaceGroup *oldParent = _Parent; + _Parent = NULL; + CInterfaceElement *oldParentPos = _ParentPos; + CInterfaceElement *oldParentSize = _ParentSize; + if (_ParentPos == oldParent) _ParentPos = NULL; + if (_ParentSize == oldParent) _ParentSize = NULL; + CInterfaceElement *begunThisCloneWarHas = NULL; + try + { + if (dupStream.isReading()) + { + dupStream.invert(); + } + CInterfaceElement *self = this; + dupStream.serialPolyPtr(self); + std::vector datas(dupStream.length()); + std::copy(dupStream.buffer(), dupStream.buffer() + dupStream.length(), datas.begin()); + dupStream.resetPtrTable(); + dupStream.invert(); + dupStream.fill(&datas[0], (uint32)datas.size()); + dupStream.serialPolyPtr(begunThisCloneWarHas); + } + catch(const NLMISC::EStream &) + { + // no-op -> caller has to handle the failure because NULL will be returned + } + // + _Parent = oldParent; + _ParentPos = oldParentPos; + _ParentSize = oldParentSize; + // + return begunThisCloneWarHas; + } + + // *************************************************************************** + void CInterfaceElement::serial(NLMISC::IStream &f) + { + f.serialPolyPtr(_Parent); + f.serial(_Id); + f.serial(_Active); + f.serial(_InvalidCoords); + f.serial(_XReal, _YReal, _WReal, _HReal); + f.serial(_X, _Y, _W, _H); + f.serialEnum(_PosRef); + f.serialEnum(_ParentPosRef); + _ParentPos.serialPolyPtr(f); + f.serial(_SizeRef); + f.serial(_SizeDivW, _SizeDivH); + _ParentSize.serialPolyPtr(f); + f.serial(_ModulateGlobalColor); + f.serial(_RenderLayer); + f.serial(_AvoidResizeParent); + nlassert(_Links == NULL); // not supported + } + + + // *************************************************************************** + void CInterfaceElement::serialAH(NLMISC::IStream &f, IActionHandler *&ah) + { + std::string ahName; + if (f.isReading()) + { + f.serial(ahName); + ah = CAHManager::getInstance()->getActionHandler(ahName); + } + else + { + ahName = CAHManager::getInstance()->getActionHandlerName(ah); + f.serial(ahName); + } + } + + } - - diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index 9b1ae75fb..bfa58b535 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -34,1923 +34,1928 @@ using namespace NL3D; // the first), instead of using 'this'. 'this' is already used by // CLuaIHM::pushReflectableOnStack as unique id to CInterfaceElement's ref pointers -REGISTER_UI_CLASS(CInterfaceGroup) - -// ------------------------------------------------------------------------------------------------ -NLMISC_REGISTER_OBJECT(CViewBase, CInterfaceGroup, std::string, "interface_group"); - -CInterfaceGroup::CInterfaceGroup(const TCtorParam ¶m) : CCtrlBase(param) +namespace NLGUI { - _ParentSizeMax = NULL; - _MaxW = _MaxH = 16384; - _OffsetX = _OffsetY = 0; - _Overlappable= true; - _ResizeFromChildW= false; - _ResizeFromChildH= false; - _ResizeFromChildWMargin= 0; - _ResizeFromChildHMargin= 0; - _MaxWReal = _MaxHReal = 16384; - _GroupSizeRef = 0; - _Escapable= false; - _Priority= WIN_PRIORITY_NORMAL; - _UseCursor = true; - _IsGroupContainer = false; - _IsGroupScrollText = false; - _IsGroupInScene = false; - _AHOnActive = NULL; - _AHOnDeactive = NULL; - _AHOnLeftClick = NULL; - _AHOnRightClick = NULL; - _AHOnEnter = NULL; - _AHOnEscape = NULL; - _NeedFrameUpdatePos= false; - _LUAEnvTableCreated= false; - _DepthForZSort= 0.f; -#ifdef AJM_DEBUG_TRACK_INTERFACE_GROUPS - CInterfaceManager::getInstance()->DebugTrackGroupsCreated( this ); -#endif -} + REGISTER_UI_CLASS(CInterfaceGroup) + // ------------------------------------------------------------------------------------------------ + NLMISC_REGISTER_OBJECT(CViewBase, CInterfaceGroup, std::string, "interface_group"); -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setIdRecurse(const std::string &id) -{ - CCtrlBase::setIdRecurse(id); - for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) + CInterfaceGroup::CInterfaceGroup(const TCtorParam ¶m) : CCtrlBase(param) { - (*it)->setIdRecurse((*it)->getShortId()); + _ParentSizeMax = NULL; + _MaxW = _MaxH = 16384; + _OffsetX = _OffsetY = 0; + _Overlappable= true; + _ResizeFromChildW= false; + _ResizeFromChildH= false; + _ResizeFromChildWMargin= 0; + _ResizeFromChildHMargin= 0; + _MaxWReal = _MaxHReal = 16384; + _GroupSizeRef = 0; + _Escapable= false; + _Priority= WIN_PRIORITY_NORMAL; + _UseCursor = true; + _IsGroupContainer = false; + _IsGroupScrollText = false; + _IsGroupInScene = false; + _AHOnActive = NULL; + _AHOnDeactive = NULL; + _AHOnLeftClick = NULL; + _AHOnRightClick = NULL; + _AHOnEnter = NULL; + _AHOnEscape = NULL; + _NeedFrameUpdatePos= false; + _LUAEnvTableCreated= false; + _DepthForZSort= 0.f; + + #ifdef AJM_DEBUG_TRACK_INTERFACE_GROUPS + CInterfaceManager::getInstance()->DebugTrackGroupsCreated( this ); + #endif } - for(std::vector::iterator it = _Controls.begin(); it != _Controls.end(); ++it) - { - (*it)->setIdRecurse((*it)->getShortId()); - } - for(std::vector::iterator it = _Views.begin(); it != _Views.end(); ++it) - { - (*it)->setIdRecurse((*it)->getShortId()); - } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::notifyActiveCalled(const NLGUI::CEventDescriptorActiveCalledOnParent &desc) -{ - // notify children that the 'active' state of this group has changed - for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setIdRecurse(const std::string &id) { - (*it)->handleEvent(desc); - } - for(std::vector::iterator ctrlIt = _Controls.begin(); ctrlIt != _Controls.end(); ++ctrlIt) - { - (*ctrlIt)->handleEvent(desc); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setActive(bool state) -{ - if(state != getActive()) - { - CCtrlBase::setActive(state); - if (_AHOnActive != NULL && state) + CCtrlBase::setIdRecurse(id); + for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) { - CAHManager::getInstance()->runActionHandler (_AHOnActive, this, _AHOnActiveParams); + (*it)->setIdRecurse((*it)->getShortId()); } - if (_AHOnDeactive != NULL && !state) + for(std::vector::iterator it = _Controls.begin(); it != _Controls.end(); ++it) { - CAHManager::getInstance()->runActionHandler (_AHOnDeactive, this, _AHOnDeactiveParams); + (*it)->setIdRecurse((*it)->getShortId()); } - - notifyActiveCalled(NLGUI::CEventDescriptorActiveCalledOnParent(state)); - } -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup::~CInterfaceGroup() -{ - // delete any LUA group environnement - deleteLUAEnvTable(); - // delete any LUA interface link "ondbchange" - removeAllLUAOnDbChange(); - -// NLMISC::TTime initStart; -// initStart = ryzomGetLocalTime (); - clearGroups(); -// nlinfo ("%d seconds for clearGroups '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); -// initStart = ryzomGetLocalTime (); - clearViews(); -// nlinfo ("%d seconds for clearViews '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); -// initStart = ryzomGetLocalTime (); - clearControls(); -// nlinfo ("%d seconds for clearControls '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); - CWidgetManager::getInstance()->removeRefOnGroup (this); - -#ifdef AJM_DEBUG_TRACK_INTERFACE_GROUPS - // AJM DEBUG - CInterfaceManager::getInstance()->DebugTrackGroupsDestroyed( this ); -#endif -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::clearViews() -{ - // Yoyo: important to not Leave NULL in the array, because of ~CGroupHTML and LibWWW callback - // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) - while(!_Views.empty()) - { - CViewBase *pVB = _Views.back(); - delEltOrder (pVB); - delete pVB; - // slower than a _Views.clear() out of loop, but we have to keep a clean array. - _Views.pop_back(); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::clearControls() -{ - // Yoyo: important to not Leave NULL in the array, because of ~CGroupHTML() and LibWWW callback - // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) - while(!_Controls.empty()) - { - CCtrlBase *pCB = _Controls.back(); - delEltOrder (pCB); - delete pCB; - // slower than a _Controls.clear() out of loop, but we have to keep a clean array. - _Controls.pop_back(); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::clearGroups() -{ - // Yoyo: important to not Leave NULL in the array, because of ~CGroupHTML() and LibWWW callback - // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) - while(!_ChildrenGroups.empty()) - { - CInterfaceGroup *pIG = _ChildrenGroups.back(); - delEltOrder (pIG); - delete pIG; - // slower than a _ChildrenGroups.clear() out of loop, but we have to keep a clean array. - _ChildrenGroups.pop_back(); - } -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::moveSBTrackY (CInterfaceGroup *target, sint32 dy) -{ - // Look if there is a vertical scrollbar with this target attached ... - vector::iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) - { - CCtrlBase *pCB = *itc; - CCtrlScrollBase *pSB = dynamic_cast(pCB); - if (pSB != NULL) + for(std::vector::iterator it = _Views.begin(); it != _Views.end(); ++it) { - if (pSB->getTarget() == target) + (*it)->setIdRecurse((*it)->getShortId()); + } + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::notifyActiveCalled(const NLGUI::CEventDescriptorActiveCalledOnParent &desc) + { + // notify children that the 'active' state of this group has changed + for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) + { + (*it)->handleEvent(desc); + } + for(std::vector::iterator ctrlIt = _Controls.begin(); ctrlIt != _Controls.end(); ++ctrlIt) + { + (*ctrlIt)->handleEvent(desc); + } + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setActive(bool state) + { + if(state != getActive()) + { + CCtrlBase::setActive(state); + if (_AHOnActive != NULL && state) { - pSB->moveTrackY(dy); - return true; + CAHManager::getInstance()->runActionHandler (_AHOnActive, this, _AHOnActiveParams); + } + if (_AHOnDeactive != NULL && !state) + { + CAHManager::getInstance()->runActionHandler (_AHOnDeactive, this, _AHOnDeactiveParams); + } + + notifyActiveCalled(NLGUI::CEventDescriptorActiveCalledOnParent(state)); + } + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup::~CInterfaceGroup() + { + // delete any LUA group environnement + deleteLUAEnvTable(); + // delete any LUA interface link "ondbchange" + removeAllLUAOnDbChange(); + + // NLMISC::TTime initStart; + // initStart = ryzomGetLocalTime (); + clearGroups(); + // nlinfo ("%d seconds for clearGroups '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); + // initStart = ryzomGetLocalTime (); + clearViews(); + // nlinfo ("%d seconds for clearViews '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); + // initStart = ryzomGetLocalTime (); + clearControls(); + // nlinfo ("%d seconds for clearControls '%s'", (uint32)(ryzomGetLocalTime ()-initStart)/1000, _Id.c_str()); + CWidgetManager::getInstance()->removeRefOnGroup (this); + + #ifdef AJM_DEBUG_TRACK_INTERFACE_GROUPS + // AJM DEBUG + CInterfaceManager::getInstance()->DebugTrackGroupsDestroyed( this ); + #endif + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearViews() + { + // Yoyo: important to not Leave NULL in the array, because of ~CGroupHTML and LibWWW callback + // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) + while(!_Views.empty()) + { + CViewBase *pVB = _Views.back(); + delEltOrder (pVB); + delete pVB; + // slower than a _Views.clear() out of loop, but we have to keep a clean array. + _Views.pop_back(); + } + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearControls() + { + // Yoyo: important to not Leave NULL in the array, because of ~CGroupHTML() and LibWWW callback + // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) + while(!_Controls.empty()) + { + CCtrlBase *pCB = _Controls.back(); + delEltOrder (pCB); + delete pCB; + // slower than a _Controls.clear() out of loop, but we have to keep a clean array. + _Controls.pop_back(); + } + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearGroups() + { + // Yoyo: important to not Leave NULL in the array, because of ~CGroupHTML() and LibWWW callback + // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) + while(!_ChildrenGroups.empty()) + { + CInterfaceGroup *pIG = _ChildrenGroups.back(); + delEltOrder (pIG); + delete pIG; + // slower than a _ChildrenGroups.clear() out of loop, but we have to keep a clean array. + _ChildrenGroups.pop_back(); + } + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::moveSBTrackY (CInterfaceGroup *target, sint32 dy) + { + // Look if there is a vertical scrollbar with this target attached ... + vector::iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) + { + CCtrlBase *pCB = *itc; + CCtrlScrollBase *pSB = dynamic_cast(pCB); + if (pSB != NULL) + { + if (pSB->getTarget() == target) + { + pSB->moveTrackY(dy); + return true; + } } } - } - return false; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::moveSBTargetY(CInterfaceGroup *target,sint32 dy) -{ - // Look if there is a vertical scrollbar with this target attached ... - vector::iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) - { - CCtrlBase *pCB = *itc; - CCtrlScrollBase *pSB = dynamic_cast(pCB); - if (pSB != NULL) - { - if (pSB->getTarget() == target) - { - pSB->moveTargetY(dy); - return true; - } - } - } - return false; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setPriority(uint8 nprio) -{ - if (nprio != _Priority) - { - CWidgetManager::getInstance()->setWindowPriority(this, nprio); - } -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - if ( !CCtrlBase::parse(cur,parentGroup) ) - { - nlinfo ("cannot parse InterfaceElementLocalisable part"); return false; } - //determine if the group is a window. If the property is not specified, set it to false. - CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"win" )); - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"overlappable" ); - if(ptr) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::moveSBTargetY(CInterfaceGroup *target,sint32 dy) { - _Overlappable= convertBool(ptr); - } - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"escapable" ); - if(ptr) _Escapable= convertBool(ptr); - - // determine if the group must be sized according to his sons. - ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_w" ); - if(ptr) - { - _ResizeFromChildW= convertBool(ptr); - } - ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_h" ); - if(ptr) - { - _ResizeFromChildH= convertBool(ptr); - } - ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_wmargin" ); - if(ptr) - { - NLMISC::fromString((const char*)ptr, _ResizeFromChildWMargin); - } - ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_hmargin" ); - if(ptr) - { - NLMISC::fromString((const char*)ptr, _ResizeFromChildHMargin); - } - CAHManager::getInstance()->parseAH(cur, "on_active", "on_active_params", _AHOnActive, _AHOnActiveParams); - CAHManager::getInstance()->parseAH(cur, "on_deactive", "on_deactive_params", _AHOnDeactive, _AHOnDeactiveParams); - - // Read user max size - ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_w" ); - if (ptr) NLMISC::fromString((const char*)ptr, _MaxW); - ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_h" ); - if (ptr) NLMISC::fromString((const char*)ptr, _MaxH); - ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_sizeref" ); - if (ptr) - { - parseMaxSizeRef(ptr); - } - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_sizeparent" ); - if (ptr) - { - string idparent = ptr; - idparent = NLMISC::strlwr(idparent); - if (idparent != "parent") + // Look if there is a vertical scrollbar with this target attached ... + vector::iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) { - if (parentGroup) - idparent = parentGroup->getId() +":" + string((const char*)ptr); - else - idparent = "ui:" + string((const char*)ptr); + CCtrlBase *pCB = *itc; + CCtrlScrollBase *pSB = dynamic_cast(pCB); + if (pSB != NULL) + { + if (pSB->getTarget() == target) + { + pSB->moveTargetY(dy); + return true; + } + } } - else + return false; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setPriority(uint8 nprio) + { + if (nprio != _Priority) { - if (parentGroup) - idparent = parentGroup->getId(); + CWidgetManager::getInstance()->setWindowPriority(this, nprio); } - CWidgetManager::parser->addParentSizeMaxAssociation (this, idparent); } - // left & right clicks - CAHManager::getInstance()->parseAH(cur, "group_onclick_r", "group_params_r", _AHOnRightClick, _AHOnRightClickParams); - CAHManager::getInstance()->parseAH(cur, "group_onclick_l", "group_params_l", _AHOnLeftClick, _AHOnLeftClickParams); - - // Each window (modal and groupContainer) can be validated by Enter. if "" => no op. - CAHManager::getInstance()->parseAH(cur, "on_enter", "on_enter_params", _AHOnEnter, _AHOnEnterParams); - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"win_priority" ); - if(ptr) NLMISC::fromString((const char*)ptr, _Priority); - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"use_cursor" ); - if(ptr) _UseCursor= convertBool(ptr); - - // Each window (modal and groupContainer) can be escaped if "escapable" set - // they can add an action handler before the hide - CAHManager::getInstance()->parseAH(cur, "on_escape", "on_escape_params", _AHOnEscape, _AHOnEscapeParams); - - - // LuaClass script - ptr = xmlGetProp (cur, (xmlChar*)"lua_class"); - if( ptr ) - CWidgetManager::parser->addLuaClassAssociation( this, (const char*)ptr ); - - return true; -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::parseMaxSizeRef(const char *ptr) -{ - parseSizeRef(ptr, _GroupSizeRef, _SizeDivW, _SizeDivH); -} - -// ------------------------------------------------------------------------------------------------ -uint32 CInterfaceGroup::getMemory () -{ - uint32 Mem = sizeof(*this); - /*vector::const_iterator itg; - for (itg = _ChildrenGroups.begin() ; itg != _ChildrenGroups.end(); itg++) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup) { - CInterfaceGroup *pIG = *itg; - Mem += pIG->getMemory(); - }*/ - - for (vector::const_iterator itv = _Views.begin() ; itv != _Views.end(); itv++) - { - CViewBase *pVB = *itv; - Mem += pVB->getMemory(); - } - - for (vector::const_iterator itc = _Controls.begin() ; itc != _Controls.end(); itc++) - { - CCtrlBase* ctrl = *itc; - Mem += ctrl->getMemory(); - } - return Mem; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addToEltOrder(CViewBase *view, sint order) -{ - if (!view) return; - if (order == -1) - { - _EltOrder.push_back(view); - } - else - { - if (order > (sint) _EltOrder.size()) return; - _EltOrder.insert(_EltOrder.begin() + order, view); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addView (CViewBase *child, sint eltOrder /*= -1*/) -{ - if (!child) - { - nlwarning(" : tried to add a NULL view"); - return; - } - _Views.push_back(child); - addToEltOrder(child, eltOrder); - - // elt callBack. - child->onAddToGroup(); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addCtrl (CCtrlBase *child, sint eltOrder /*= -1*/) -{ - if (!child) - { - nlwarning(" : tried to add a NULL ctrl"); - return; - } - _Controls.push_back(child); - addToEltOrder(child, eltOrder); - - // elt callBack. - child->onAddToGroup(); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addGroup (CInterfaceGroup *child, sint eltOrder /*= -1*/) -{ - if (!child) - { - nlwarning(" : tried to add a NULL group"); - return; - } - _ChildrenGroups.push_back(child); - addToEltOrder(child, eltOrder); - - // elt callBack. - child->onAddToGroup(); -} - -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaAddGroup (CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::addTab", 1); - CInterfaceGroup * group = dynamic_cast(CLuaIHM::getUIOnStack(ls, 1)); - if(group) - { - group->setParent(this); - group->setParentPos(this); - addGroup(group); - } - return 0; -} -// ------------------------------------------------------------------------------------------------ -// id = incomplete path (text:list:a) lid complete one (ui:interface:content:text:list:a) -static bool reverseCheckPath(const string &id, const string &lid) -{ - string idTmp = id, lidTmp = lid; -// bool isFound = true; - while (idTmp.size() > 0) - { - string tokid, toklid; - - string::size_type posid = idTmp.rfind (":"); - if (posid == string::npos) + if ( !CCtrlBase::parse(cur,parentGroup) ) { - posid = 0; - tokid = idTmp; - } - else - { - tokid = idTmp.substr (posid+1); - } - - string::size_type poslid = lidTmp.rfind (":"); - if (poslid == string::npos) - { - poslid = 0; - toklid = lidTmp; - } - else - { - toklid = lidTmp.substr (poslid+1); - } - - if (tokid != toklid) + nlinfo ("cannot parse InterfaceElementLocalisable part"); return false; + } - if (posid > 0) - idTmp = idTmp.substr (0, posid); + //determine if the group is a window. If the property is not specified, set it to false. + CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"win" )); + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"overlappable" ); + if(ptr) + { + _Overlappable= convertBool(ptr); + } + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"escapable" ); + if(ptr) _Escapable= convertBool(ptr); + + // determine if the group must be sized according to his sons. + ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_w" ); + if(ptr) + { + _ResizeFromChildW= convertBool(ptr); + } + ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_h" ); + if(ptr) + { + _ResizeFromChildH= convertBool(ptr); + } + ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_wmargin" ); + if(ptr) + { + NLMISC::fromString((const char*)ptr, _ResizeFromChildWMargin); + } + ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_hmargin" ); + if(ptr) + { + NLMISC::fromString((const char*)ptr, _ResizeFromChildHMargin); + } + CAHManager::getInstance()->parseAH(cur, "on_active", "on_active_params", _AHOnActive, _AHOnActiveParams); + CAHManager::getInstance()->parseAH(cur, "on_deactive", "on_deactive_params", _AHOnDeactive, _AHOnDeactiveParams); + + // Read user max size + ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_w" ); + if (ptr) NLMISC::fromString((const char*)ptr, _MaxW); + ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_h" ); + if (ptr) NLMISC::fromString((const char*)ptr, _MaxH); + ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_sizeref" ); + if (ptr) + { + parseMaxSizeRef(ptr); + } + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_sizeparent" ); + if (ptr) + { + string idparent = ptr; + idparent = NLMISC::strlwr(idparent); + if (idparent != "parent") + { + if (parentGroup) + idparent = parentGroup->getId() +":" + string((const char*)ptr); + else + idparent = "ui:" + string((const char*)ptr); + } + else + { + if (parentGroup) + idparent = parentGroup->getId(); + } + CWidgetManager::parser->addParentSizeMaxAssociation (this, idparent); + } + + // left & right clicks + CAHManager::getInstance()->parseAH(cur, "group_onclick_r", "group_params_r", _AHOnRightClick, _AHOnRightClickParams); + CAHManager::getInstance()->parseAH(cur, "group_onclick_l", "group_params_l", _AHOnLeftClick, _AHOnLeftClickParams); + + // Each window (modal and groupContainer) can be validated by Enter. if "" => no op. + CAHManager::getInstance()->parseAH(cur, "on_enter", "on_enter_params", _AHOnEnter, _AHOnEnterParams); + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"win_priority" ); + if(ptr) NLMISC::fromString((const char*)ptr, _Priority); + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"use_cursor" ); + if(ptr) _UseCursor= convertBool(ptr); + + // Each window (modal and groupContainer) can be escaped if "escapable" set + // they can add an action handler before the hide + CAHManager::getInstance()->parseAH(cur, "on_escape", "on_escape_params", _AHOnEscape, _AHOnEscapeParams); + + + // LuaClass script + ptr = xmlGetProp (cur, (xmlChar*)"lua_class"); + if( ptr ) + CWidgetManager::parser->addLuaClassAssociation( this, (const char*)ptr ); + + return true; + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::parseMaxSizeRef(const char *ptr) + { + parseSizeRef(ptr, _GroupSizeRef, _SizeDivW, _SizeDivH); + } + + // ------------------------------------------------------------------------------------------------ + uint32 CInterfaceGroup::getMemory () + { + uint32 Mem = sizeof(*this); + /*vector::const_iterator itg; + for (itg = _ChildrenGroups.begin() ; itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pIG = *itg; + Mem += pIG->getMemory(); + }*/ + + for (vector::const_iterator itv = _Views.begin() ; itv != _Views.end(); itv++) + { + CViewBase *pVB = *itv; + Mem += pVB->getMemory(); + } + + for (vector::const_iterator itc = _Controls.begin() ; itc != _Controls.end(); itc++) + { + CCtrlBase* ctrl = *itc; + Mem += ctrl->getMemory(); + } + return Mem; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addToEltOrder(CViewBase *view, sint order) + { + if (!view) return; + if (order == -1) + { + _EltOrder.push_back(view); + } else - idTmp = ""; - - if (poslid > 0) - lidTmp = lidTmp.substr (0, poslid); - else - lidTmp = ""; - } - return true; -} - -// ------------------------------------------------------------------------------------------------ -CViewBase* CInterfaceGroup::getView (const std::string &id) -{ - vector::const_iterator itv; - for (itv = _Views.begin(); itv != _Views.end(); ++itv) - { - CViewBase *pVB = (*itv); - if (reverseCheckPath(id, pVB->getId())) - return *itv; - } - // search in sons - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) - { - CViewBase* view = (*itg)->getView(id); - if (view) - return view; - } - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -CCtrlBase* CInterfaceGroup::getCtrl (const std::string &id) -{ - vector::const_iterator itv; - for (itv = _Controls.begin(); itv != _Controls.end(); ++itv) - { - CCtrlBase *pCB = (*itv); - if (reverseCheckPath(id, pCB->getId())) - return *itv; - } - // search in sons - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) - { - CCtrlBase*pCtrl = (*itg)->getCtrl (id); - if (pCtrl) - return pCtrl; - } - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup*CInterfaceGroup::getGroup (const std::string &id) const -{ - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end();itg++) - { - CInterfaceGroup *pIG = (*itg); - if (reverseCheckPath(id, pIG->getId())) - return *itg; - } - // search in sons - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) - { - CInterfaceGroup *pCtrl = (*itg)->getGroup (id); - if (pCtrl) - return pCtrl; - } - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delView (CViewBase *child, bool dontDelete /* = false*/) -{ - for (sint32 i = 0; i < (sint32)_Views.size(); ++i) - { - if (_Views[i] == child) { - if (!dontDelete) delete _Views[i]; - _Views.erase(_Views.begin()+i); - delEltOrder (child); - return true; + if (order > (sint) _EltOrder.size()) return; + _EltOrder.insert(_EltOrder.begin() + order, view); } } - return false; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delCtrl (CCtrlBase *child, bool dontDelete /* = false*/) -{ - for (sint32 i = 0; i < (sint32)_Controls.size(); ++i) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addView (CViewBase *child, sint eltOrder /*= -1*/) { - if (_Controls[i] == child) + if (!child) { - if (!dontDelete) delete _Controls[i]; - _Controls.erase(_Controls.begin()+i); - delEltOrder (child); - return true; - } - } - return false; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delGroup (CInterfaceGroup *child, bool dontDelete /* = false*/) -{ - for (sint32 i = 0; i < (sint32)_ChildrenGroups.size(); ++i) - { - if (_ChildrenGroups[i] == child) - { - if (!dontDelete) delete _ChildrenGroups[i]; - _ChildrenGroups.erase(_ChildrenGroups.begin()+i); - delEltOrder (child); - return true; - } - } - return false; -} - -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaDelGroup (CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::delTab", 1); - CInterfaceGroup * group = dynamic_cast(CLuaIHM::getUIOnStack(ls, 1)); - if(group) - { - delGroup(group); - } - return 0; -} - -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaGetNumGroups(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getNumGroups", 0); - ls.push((double) _ChildrenGroups.size()); - return 1; -} - -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaGetGroup(CLuaState &ls) -{ - const char *funcName = "CInterfaceGroup::getGroup"; - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getGroup", 1); - CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); - uint index = (uint) ls.toNumber(1); - if (index >= _ChildrenGroups.size()) - { - CLuaIHM::fails(ls, "getGroup : try to index group %s, but there are only %d son groups", ls.toString(1), (int) _ChildrenGroups.size()); - } - CLuaIHM::pushUIOnStack(ls, _ChildrenGroups[index]); - return 1; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::delEltOrder (CViewBase *pElt) -{ - for (sint32 i = 0; i < (sint32)_EltOrder.size(); ++i) - { - if (_EltOrder[i] == pElt) - { - _EltOrder.erase (_EltOrder.begin()+i); + nlwarning(" : tried to add a NULL view"); return; } + _Views.push_back(child); + addToEltOrder(child, eltOrder); + + // elt callBack. + child->onAddToGroup(); } -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delView (const std::string &id, bool dontDelete /* = false*/) -{ - return delView(getView(id), dontDelete); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delCtrl (const std::string &id, bool dontDelete /* = false*/) -{ - return delCtrl(getCtrl(id), dontDelete); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delGroup (const std::string &id, bool dontDelete /* = false*/) -{ - return delGroup(getGroup(id), dontDelete); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::isChildGroup(const CInterfaceGroup *group) const -{ - return std::find(_ChildrenGroups.begin(), _ChildrenGroups.end(), group) != _ChildrenGroups.end(); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::handleEvent (const NLGUI::CEventDescriptor &event) -{ - if (CCtrlBase::handleEvent(event)) return true; - if (!_Active) - return false; - - if (event.getType() == NLGUI::CEventDescriptor::system) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addCtrl (CCtrlBase *child, sint eltOrder /*= -1*/) { - NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; - if (eds.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::activecalledonparent) + if (!child) { - // notify all childrens - notifyActiveCalled((NLGUI::CEventDescriptorActiveCalledOnParent &) eds); + nlwarning(" : tried to add a NULL ctrl"); + return; + } + _Controls.push_back(child); + addToEltOrder(child, eltOrder); + + // elt callBack. + child->onAddToGroup(); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addGroup (CInterfaceGroup *child, sint eltOrder /*= -1*/) + { + if (!child) + { + nlwarning(" : tried to add a NULL group"); + return; + } + _ChildrenGroups.push_back(child); + addToEltOrder(child, eltOrder); + + // elt callBack. + child->onAddToGroup(); + } + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaAddGroup (CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::addTab", 1); + CInterfaceGroup * group = dynamic_cast(CLuaIHM::getUIOnStack(ls, 1)); + if(group) + { + group->setParent(this); + group->setParentPos(this); + addGroup(group); + } + return 0; + } + // ------------------------------------------------------------------------------------------------ + // id = incomplete path (text:list:a) lid complete one (ui:interface:content:text:list:a) + static bool reverseCheckPath(const string &id, const string &lid) + { + string idTmp = id, lidTmp = lid; + // bool isFound = true; + while (idTmp.size() > 0) + { + string tokid, toklid; + + string::size_type posid = idTmp.rfind (":"); + if (posid == string::npos) + { + posid = 0; + tokid = idTmp; + } + else + { + tokid = idTmp.substr (posid+1); + } + + string::size_type poslid = lidTmp.rfind (":"); + if (poslid == string::npos) + { + poslid = 0; + toklid = lidTmp; + } + else + { + toklid = lidTmp.substr (poslid+1); + } + + if (tokid != toklid) + return false; + + if (posid > 0) + idTmp = idTmp.substr (0, posid); + else + idTmp = ""; + + if (poslid > 0) + lidTmp = lidTmp.substr (0, poslid); + else + lidTmp = ""; + } + return true; + } + + // ------------------------------------------------------------------------------------------------ + CViewBase* CInterfaceGroup::getView (const std::string &id) + { + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); ++itv) + { + CViewBase *pVB = (*itv); + if (reverseCheckPath(id, pVB->getId())) + return *itv; + } + // search in sons + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) + { + CViewBase* view = (*itg)->getView(id); + if (view) + return view; + } + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + CCtrlBase* CInterfaceGroup::getCtrl (const std::string &id) + { + vector::const_iterator itv; + for (itv = _Controls.begin(); itv != _Controls.end(); ++itv) + { + CCtrlBase *pCB = (*itv); + if (reverseCheckPath(id, pCB->getId())) + return *itv; + } + // search in sons + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) + { + CCtrlBase*pCtrl = (*itg)->getCtrl (id); + if (pCtrl) + return pCtrl; + } + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup*CInterfaceGroup::getGroup (const std::string &id) const + { + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end();itg++) + { + CInterfaceGroup *pIG = (*itg); + if (reverseCheckPath(id, pIG->getId())) + return *itg; + } + // search in sons + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) + { + CInterfaceGroup *pCtrl = (*itg)->getGroup (id); + if (pCtrl) + return pCtrl; + } + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delView (CViewBase *child, bool dontDelete /* = false*/) + { + for (sint32 i = 0; i < (sint32)_Views.size(); ++i) + { + if (_Views[i] == child) + { + if (!dontDelete) delete _Views[i]; + _Views.erase(_Views.begin()+i); + delEltOrder (child); + return true; + } + } + return false; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delCtrl (CCtrlBase *child, bool dontDelete /* = false*/) + { + for (sint32 i = 0; i < (sint32)_Controls.size(); ++i) + { + if (_Controls[i] == child) + { + if (!dontDelete) delete _Controls[i]; + _Controls.erase(_Controls.begin()+i); + delEltOrder (child); + return true; + } + } + return false; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delGroup (CInterfaceGroup *child, bool dontDelete /* = false*/) + { + for (sint32 i = 0; i < (sint32)_ChildrenGroups.size(); ++i) + { + if (_ChildrenGroups[i] == child) + { + if (!dontDelete) delete _ChildrenGroups[i]; + _ChildrenGroups.erase(_ChildrenGroups.begin()+i); + delEltOrder (child); + return true; + } + } + return false; + } + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaDelGroup (CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::delTab", 1); + CInterfaceGroup * group = dynamic_cast(CLuaIHM::getUIOnStack(ls, 1)); + if(group) + { + delGroup(group); + } + return 0; + } + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaGetNumGroups(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getNumGroups", 0); + ls.push((double) _ChildrenGroups.size()); + return 1; + } + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaGetGroup(CLuaState &ls) + { + const char *funcName = "CInterfaceGroup::getGroup"; + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getGroup", 1); + CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); + uint index = (uint) ls.toNumber(1); + if (index >= _ChildrenGroups.size()) + { + CLuaIHM::fails(ls, "getGroup : try to index group %s, but there are only %d son groups", ls.toString(1), (int) _ChildrenGroups.size()); + } + CLuaIHM::pushUIOnStack(ls, _ChildrenGroups[index]); + return 1; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::delEltOrder (CViewBase *pElt) + { + for (sint32 i = 0; i < (sint32)_EltOrder.size(); ++i) + { + if (_EltOrder[i] == pElt) + { + _EltOrder.erase (_EltOrder.begin()+i); + return; + } } } - if (event.getType() == NLGUI::CEventDescriptor::mouse) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delView (const std::string &id, bool dontDelete /* = false*/) { - const NLGUI::CEventDescriptorMouse &eventDesc = (const NLGUI::CEventDescriptorMouse &)event; + return delView(getView(id), dontDelete); + } - if (!isIn(eventDesc.getX(), eventDesc.getY())) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delCtrl (const std::string &id, bool dontDelete /* = false*/) + { + return delCtrl(getCtrl(id), dontDelete); + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delGroup (const std::string &id, bool dontDelete /* = false*/) + { + return delGroup(getGroup(id), dontDelete); + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::isChildGroup(const CInterfaceGroup *group) const + { + return std::find(_ChildrenGroups.begin(), _ChildrenGroups.end(), group) != _ChildrenGroups.end(); + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::handleEvent (const NLGUI::CEventDescriptor &event) + { + if (CCtrlBase::handleEvent(event)) return true; + if (!_Active) return false; - bool taken = false; + if (event.getType() == NLGUI::CEventDescriptor::system) + { + NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; + if (eds.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::activecalledonparent) + { + // notify all childrens + notifyActiveCalled((NLGUI::CEventDescriptorActiveCalledOnParent &) eds); + } + } + + if (event.getType() == NLGUI::CEventDescriptor::mouse) + { + const NLGUI::CEventDescriptorMouse &eventDesc = (const NLGUI::CEventDescriptorMouse &)event; + + if (!isIn(eventDesc.getX(), eventDesc.getY())) + return false; + + bool taken = false; + + // For each control in the group... + vector::const_iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) + { + CCtrlBase *pCB = *itc; + if (pCB->getActive()) + taken = taken || pCB->handleEvent(eventDesc); + } + if (taken) + return true; + + // For each child group + for (sint i = (sint)_ChildrenGroups.size()-1; i >= 0; --i) + { + CInterfaceGroup *pIG = _ChildrenGroups[i]; + if (pIG->getActive()) + if (pIG->handleEvent(eventDesc)) + return true; + } + + + if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown) + { + if (_AHOnLeftClick != NULL) + { + CAHManager::getInstance()->runActionHandler(_AHOnLeftClick, this, _AHOnLeftClickParams); + return true; + } + } + + if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouserightup) + { + if (_AHOnRightClick != NULL) + { + CAHManager::getInstance()->runActionHandler(_AHOnRightClick, this, _AHOnRightClickParams); + return true; + } + } + if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousewheel) + { + // handle the Mouse Wheel only if interesting + if (_H>_MaxH) + { + CInterfaceGroup *currParent = _Parent; + while (currParent) + { + if (currParent->moveSBTrackY (this, eventDesc.getWheel()*12)) + return true; + currParent = currParent->getParent(); + } + } + } + } + return false; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::executeControl (const std::string &/* sControlName */) + { + // bool taken = false; + // CCtrlBase *pIC = getCtrl (sControlName); + // if (pIC != NULL) + // pIC->callback(taken); + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::draw () + { + sint32 oldSciX, oldSciY, oldSciW, oldSciH; + makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); + + // Display sons only if not total clipped + CViewRenderer &rVR = *CViewRenderer::getInstance(); + if( !rVR.isClipWindowEmpty() ) + { + // Draw all decorative elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pVB = *ite; + if (pVB->getActive()) + pVB->draw(); + } + } + + restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::drawNoClip() + { + // Display sons only if not total clipped + CViewRenderer &rVR = *CViewRenderer::getInstance(); + if( !rVR.isClipWindowEmpty() ) + { + // Draw all decorative elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pVB = *ite; + if (pVB->getActive()) + pVB->draw(); + } + } + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::renderWiredQuads(CInterfaceElement::TRenderWired type, const std::string &uiFilter) + { + if (!_Active) return; + CInterfaceElement::renderWiredQuads(type, uiFilter); + sint32 oldSciX, oldSciY, oldSciW, oldSciH; + makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); + for(std::vector::iterator it = _EltOrder.begin(); it != _EltOrder.end(); ++it) + { + if (*it) (*it)->renderWiredQuads(type, uiFilter); + } + restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::drawElement (CViewBase *el) + { + sint32 oldSciX, oldSciY, oldSciW, oldSciH; + makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); + + if(el) + el->draw(); + + restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::checkCoords() + { + //update all children elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pIE = *ite; + if(pIE->getActive()) + pIE->checkCoords(); + } + executeLuaScriptOnDraw(); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::executeLuaScriptOnDraw() + { + // If some LUA script attached to me, execute it + if(!_LUAOnDraw.empty()) + CAHManager::getInstance()->runActionHandler("lua", this, _LUAOnDraw); + + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::doUpdateCoords() + { + _MaxWReal = _MaxW; + _MaxHReal = _MaxH; + + CInterfaceElement *el = NULL; + + if (_ParentSizeMax != NULL) + { + el = _ParentSizeMax; + } + else + { + if (_ParentSize != NULL) + { + el = _ParentSize; + } + else + { + if (_ParentPos != NULL) + el = _ParentPos; + else + el = _Parent; + } + } + + if (el != NULL) + { + if (_GroupSizeRef&1) + _MaxWReal += _SizeDivW * el->getWReal() / 10; + + if (_GroupSizeRef&2) + _MaxHReal += _SizeDivH * el->getHReal() / 10; + } + + CViewBase::updateCoords(); + _XReal += _OffsetX; + _YReal += _OffsetY; + + //update all children elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pIE = *ite; + pIE->updateCoords(); + } + + _XReal -= _OffsetX; + _YReal -= _OffsetY; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::updateCoords() + { + // update basis and sons one time. + doUpdateCoords(); + + // if the group must resize from children + if(_ResizeFromChildH || _ResizeFromChildW) + { + // compute BBox of all childrens + sint width, height; + evalChildrenBBox(_ResizeFromChildW, _ResizeFromChildH, width, height); + // set forced size. + if(_ResizeFromChildW) + { + _W= _ResizeFromChildWMargin + width; + } + if(_ResizeFromChildH) + { + _H= _ResizeFromChildHMargin + height; + } + } + + CInterfaceElement::updateCoords(); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::evalChildrenBBox(bool resizeFromChildW, bool resizeFromChildH, sint &width, sint &height) const + { + sint yMin=INT_MAX, yMax=INT_MIN; + sint xMin=INT_MAX, xMax=INT_MIN; + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pIE = *ite; + if (pIE->getActive()) + { + const CInterfaceElement *el = pIE->getParentPos() ? pIE->getParentPos() : pIE->getParent(); + if (el == this) + { + // to compute the bbox, don't use direct sons that have a sizeref on the resizing coordinate + if ((resizeFromChildW && (pIE->getSizeRef() & 1)) + || (resizeFromChildH && (pIE->getSizeRef() & 2)) + ) + { + continue; + } + } + // avoid also some interface elements + if(pIE->avoidResizeParent()) + continue; + // get the real coords bounds. + sint32 x0,y0,x1,y1; + // If it is a group, minimize with MaxHReal / MaxWReal + const CInterfaceGroup *sonGroup= dynamic_cast(pIE); + // \todo yoyo: do not know why but don't work if this==scroll_text + if(sonGroup && !isGroupScrollText()) + { + sint32 oldSciX= -16384; + sint32 oldSciY= -16384; + sint32 oldSciW= 32768; + sint32 oldSciH= 32768; + sint32 w, h; + sonGroup->computeCurrentClipContribution(oldSciX, oldSciY, oldSciW, oldSciH, x0, y0, w, h); + x1= x0 + w; + y1= y0 + h; + } + else + { + x0= pIE->getXReal(); + y0= pIE->getYReal(); + x1= x0 + pIE->getWReal(); + y1= y0 + pIE->getHReal(); + } + // enlarge + if(x0xMax) + xMax= x1; + if(y1>yMax) + yMax= y1; + } + } + width = xMax - xMin; + height = yMax - yMin; + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CInterfaceGroup::getElement (const std::string &id) + { + if (_Id == id) + return this; + + if (id.compare(0, _Id.size(), _Id) != 0) + return NULL; + + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) + { + CViewBase *pVB = *itv; + #if !FINAL_VERSION // For SpeedUp in final version + nlassert(pVB); // The element must not be NULL + #endif + if (pVB->getId() == id) + return pVB; + } + + vector::const_iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) + { + CCtrlBase* ctrl = *itc; + #if !FINAL_VERSION // For SpeedUp in final version + nlassert(ctrl); // The element must not be NULL + #endif + if (ctrl->getId() == id) + return ctrl; + } + + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pIG = *itg; + #if !FINAL_VERSION // For SpeedUp in final version + nlassert(pIG); // The element must not be NULL + #endif + CInterfaceElement *pIEL = pIG->getElement(id); + if (pIEL != NULL) + return pIEL; + } + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delElement (const std::string &id, bool noWarning) + { + if (id.substr(0, _Id.size()) != _Id) + return false; + + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) + { + CViewBase *pVB = *itv; + if (pVB->getId() == id) + { + delView (pVB, false); + return true; + } + } + + vector::const_iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) + { + CCtrlBase* ctrl = *itc; + if (ctrl->getId() == id) + { + delCtrl (ctrl, false); + return true; + } + } + + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pIG = *itg; + if (pIG->getId() == id) + { + // If this is a root window + if (pIG->getRootWindow () == pIG) + CWidgetManager::getInstance()->unMakeWindow(pIG, noWarning); + delGroup (pIG, false); + return true; + } + } + return false; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delElement (CInterfaceElement *pIE, bool noWarning) + { + // delete correct type of element + if(pIE->isGroup()) + { + CInterfaceGroup *pIG= static_cast(pIE); + // unmake window if it is + if (pIG->getRootWindow () == pIG) + CWidgetManager::getInstance()->unMakeWindow(pIG, noWarning); + return delGroup(pIG); + } + else if(pIE->isCtrl()) + { + return delCtrl(static_cast(pIE)); + } + + nlassert(pIE->isView()); + return delView(static_cast(pIE)); + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::isWindowUnder (sint32 x, sint32 y) + { + return ((x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal + _HReal))); + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CInterfaceGroup::getGroupUnder (sint32 x, sint32 y) + { + // Begins by the children + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pChild = *itg; + CInterfaceGroup *pChildUnder = pChild->getGroupUnder (x-_XReal, y-_YReal); + if (pChildUnder != NULL) + { + if ( (x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal+ _HReal))) + return pChildUnder; + } + } + + // If not found in childs then try in the parent one + if ( (x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal+ _HReal))) + return this; + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::getViewsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vVB) + { + if (!((x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal+ _HReal)))) + return false; + // test against current clip + computeCurrentClipContribution(clipX, clipY, clipW, clipH, + clipX, clipY, clipW, clipH); + + if (!((x > clipX) && + (x < (clipX + clipW))&& + (y > clipY) && + (y < (clipY + clipH)))) + return false; + + + + // same as draw order: start with parent + std::vector::const_iterator itc; + for (itc = _EltOrder.begin(); itc != _EltOrder.end(); itc++) + { + if (!(*itc)->isCtrl() && !(*itc)->isGroup()) // must be a view + { + CViewBase *pVB = *itc; + if (pVB != NULL) + if (pVB->getActive()) + if ( ((x) > pVB->getXReal()) && + ((x) < (pVB->getXReal() + pVB->getWReal()))&& + ((y) > pVB->getYReal()) && + ((y) < (pVB->getYReal() + pVB->getHReal()))) + { + vVB.push_back (pVB); + } + } + } + + // same as draw order: continue with children + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pChild = *itg; + if (pChild->getActive()) + { + // bool bUnder = + pChild->getViewsUnder (x, y, clipX, clipY, clipW, clipH, vVB); + // if (bUnder && (vICL.size() > 0)) + // return true; + } + } + return true; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::getCtrlsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vICL) + { + if (!((x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal+ _HReal)))) + return false; + // test against current clip + computeCurrentClipContribution(clipX, clipY, clipW, clipH, + clipX, clipY, clipW, clipH); + + if (!((x >= clipX) && + (x < (clipX + clipW))&& + (y > clipY) && + (y <= (clipY + clipH)))) + return false; + + + + // same as draw order: start with parent + std::vector::const_iterator itc; + for (itc = _EltOrder.begin(); itc != _EltOrder.end(); itc++) + { + if ((*itc)->isCtrl() && !(*itc)->isGroup()) // must be a ctrl but not a group (parsed later) + { + CCtrlBase *pICL = (CCtrlBase *) *itc; + if (pICL != NULL) + if (pICL->getActive()) + if ( ((x) >= pICL->getXReal()) && + ((x) < (pICL->getXReal() + pICL->getWReal()))&& + ((y) > pICL->getYReal()) && + ((y) <= (pICL->getYReal() + pICL->getHReal()))) + { + vICL.push_back (pICL->getSubCtrl(x,y)); + } + } + } + + // same as draw order: continue with children + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pChild = *itg; + if (pChild->getActive()) + { + // bool bUnder = + pChild->getCtrlsUnder (x, y, clipX, clipY, clipW, clipH, vICL); + // if (bUnder && (vICL.size() > 0)) + // return true; + } + } + return true; + } + + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::getGroupsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vIGL) + { + if (!((x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal+ _HReal)))) + return false; + // test against current clip + computeCurrentClipContribution(clipX, clipY, clipW, clipH, + clipX, clipY, clipW, clipH); + + if (!((x >= clipX) && + (x < (clipX + clipW))&& + (y > clipY) && + (y <= (clipY + clipH)))) + return false; + + + + // same as draw order: start with parent + std::vector::const_iterator itc; + for (itc = _EltOrder.begin(); itc != _EltOrder.end(); itc++) + { + if ((*itc)->isGroup()) // must be a group + { + CInterfaceGroup *pIGL = (CInterfaceGroup *) *itc; + if (pIGL != NULL) + if (pIGL->getActive()) + if ( ((x) >= pIGL->getXReal()) && + ((x) < (pIGL->getXReal() + pIGL->getWReal()))&& + ((y) > pIGL->getYReal()) && + ((y) <= (pIGL->getYReal() + pIGL->getHReal()))) + { + vIGL.push_back (pIGL); + } + } + } + + // same as draw order: continue with children + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pChild = *itg; + if (pChild->getActive()) + { + // bool bUnder = + pChild->getGroupsUnder (x, y, clipX, clipY, clipW, clipH, vIGL); + // if (bUnder && (vICL.size() > 0)) + // return true; + } + } + return true; + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::absoluteToRelative (sint32 &x, sint32 &y) + { + CInterfaceGroup *curGrp = _Parent; + while (curGrp != NULL) + { + x = x - curGrp->_XReal; + y = y - curGrp->_YReal; + curGrp = curGrp->_Parent; + } + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::computeCurrentClipContribution(sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH, + sint32 &newSciXDest, sint32 &newSciYDest, sint32 &newSciWDest, sint32 &newSciHDest) const + { + sint32 newSciX = _XReal; + sint32 newSciY = _YReal; + sint32 newSciW = _WReal; + sint32 newSciH = _HReal; + // If there is width size limiter + if (_MaxWReal < _WReal) + { + if ((_PosRef == Hotspot_TR) || (_PosRef == Hotspot_MR) || (_PosRef == Hotspot_BR)) + newSciX = _XReal + _WReal - _MaxWReal; + newSciW = _MaxWReal; + } + // If there is height size limiter + if (_MaxHReal < _HReal) + { + if ((_PosRef == Hotspot_TL) || (_PosRef == Hotspot_TM) || (_PosRef == Hotspot_TR)) + newSciY = _YReal + _HReal - _MaxHReal; + newSciH = _MaxHReal; + } + // Clip Left + if (newSciX < oldSciX) + { + newSciW = newSciW - (oldSciX - newSciX); + newSciX = oldSciX; + } + // Clip Right + if ((newSciX+newSciW) > (oldSciX+oldSciW)) + { + newSciW = newSciW - ((newSciX+newSciW)-(oldSciX+oldSciW)); + } + // Clip Bottom + if (newSciY < oldSciY) + { + newSciH = newSciH - (oldSciY - newSciY); + newSciY = oldSciY; + } + // Clip Top + if ((newSciY+newSciH) > (oldSciY+oldSciH)) + { + newSciH = newSciH - ((newSciY+newSciH)-(oldSciY+oldSciH)); + } + + newSciXDest = newSciX; + newSciYDest = newSciY; + newSciWDest = newSciW; + newSciHDest = newSciH; + + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::makeNewClip (sint32 &oldSciX, sint32 &oldSciY, sint32 &oldSciW, sint32 &oldSciH) + { + CViewRenderer &rVR = *CViewRenderer::getInstance(); + rVR.getClipWindow (oldSciX, oldSciY, oldSciW, oldSciH); + + sint32 newSciX, newSciY, newSciW, newSciH; + computeCurrentClipContribution(oldSciX, oldSciY, oldSciW, oldSciH, newSciX, newSciY, newSciW, newSciH); + rVR.setClipWindow (newSciX, newSciY, newSciW, newSciH); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::getClip(sint32 &x, sint32 &y, sint32 &w, sint32 &h) const + { + CViewRenderer &rVR = *CViewRenderer::getInstance(); + uint32 sw, sh; + rVR.getScreenSize(sw, sh); + sint32 sciX = 0, sciY = 0, sciW = sw, sciH =sh; + const CInterfaceGroup *currGroup = this; + do + { + currGroup->computeCurrentClipContribution(sciX, sciY, sciW, sciH, sciX, sciY, sciW, sciH); + currGroup = currGroup->_Parent; + } while(currGroup); + x = sciX; + y = sciY; + w = sciW; + h = sciH; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::restoreClip (sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH) + { + CViewRenderer &rVR = *CViewRenderer::getInstance(); + rVR.setClipWindow (oldSciX, oldSciY, oldSciW, oldSciH); + } + + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::launch () + { + // launch all elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pIE = *ite; + pIE->launch(); + } + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup *CInterfaceGroup::getGroup(uint index) const + { + if (index > _ChildrenGroups.size()) + { + nlwarning(" bad index;"); + return NULL; + } + return _ChildrenGroups[index]; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::updateAllLinks() + { + CCtrlBase::updateAllLinks(); + { + for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) + { + (*it)->updateAllLinks(); + } + } + { + for(std::vector::iterator it = _Controls.begin(); it != _Controls.end(); ++it) + { + (*it)->updateAllLinks(); + } + } + { + for(std::vector::iterator it = _Views.begin(); it != _Views.end(); ++it) + { + (*it)->updateAllLinks(); + } + } + } + + // ------------------------------------------------------------------------------------------------ + sint32 CInterfaceGroup::getAlpha() const + { + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) + { + CViewBase *pVB = *itv; + sint32 a = pVB->getAlpha(); + if (a != -1) + return a; + } - // For each control in the group... vector::const_iterator itc; for (itc = _Controls.begin(); itc != _Controls.end(); itc++) { CCtrlBase *pCB = *itc; - if (pCB->getActive()) - taken = taken || pCB->handleEvent(eventDesc); - } - if (taken) - return true; - - // For each child group - for (sint i = (sint)_ChildrenGroups.size()-1; i >= 0; --i) - { - CInterfaceGroup *pIG = _ChildrenGroups[i]; - if (pIG->getActive()) - if (pIG->handleEvent(eventDesc)) - return true; + sint32 a = pCB->getAlpha(); + if (a != -1) + return a; } - - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown) + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) { - if (_AHOnLeftClick != NULL) + CInterfaceGroup *pIG = *itg; + sint32 a = pIG->getAlpha(); + if (a != -1) + return a; + } + return -1; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setAlpha (sint32 a) + { + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) + { + CViewBase *pVB = *itv; + pVB->setAlpha(a); + } + + vector::const_iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) + { + CCtrlBase *pCB = *itc; + pCB->setAlpha(a); + } + + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pIG = *itg; + pIG->setAlpha(a); + } + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setLeftClickHandler(const std::string &handler) + { + _AHOnLeftClick = CAHManager::getInstance()->getAH(handler, _AHOnLeftClickParams); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setRightClickHandler(const std::string &handler) + { + _AHOnRightClick = CAHManager::getInstance()->getAH(handler, _AHOnRightClickParams); + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CInterfaceGroup::getEnclosingContainer() + { + CInterfaceGroup *ig = this; + do + { + if( ig->isGroupContainer() ) + return ig; + ig = ig->getParent(); + } + while( ig != NULL ); + + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::dumpGroups() + { + nlinfo("Num groups = %d", (int) _ChildrenGroups.size()); + for(uint k = 0; k < _ChildrenGroups.size(); ++k) + { + std::string typeName = "???"; + if (_ChildrenGroups[k]) { - CAHManager::getInstance()->runActionHandler(_AHOnLeftClick, this, _AHOnLeftClickParams); - return true; + const type_info &ti = typeid(*_ChildrenGroups[k]); + typeName = ti.name(); } + nlinfo("Group %d, name = %s, type=%s", k, _ChildrenGroups[k] ? _ChildrenGroups[k]->getId().c_str() : "???", typeName.c_str()); } + } - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouserightup) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::dumpEltsOrder() + { + nlinfo("Num elements = %d", (int) _EltOrder.size()); + for(uint k = 0; k < _EltOrder.size(); ++k) { - if (_AHOnRightClick != NULL) + std::string typeName = "???"; + if (_ChildrenGroups[k]) { - CAHManager::getInstance()->runActionHandler(_AHOnRightClick, this, _AHOnRightClickParams); - return true; + const type_info &ti = typeid(*_EltOrder[k]); + typeName = ti.name(); } - } - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousewheel) - { - // handle the Mouse Wheel only if interesting - if (_H>_MaxH) + CInterfaceElement *el = _EltOrder[k]; + if (el) { - CInterfaceGroup *currParent = _Parent; - while (currParent) - { - if (currParent->moveSBTrackY (this, eventDesc.getWheel()*12)) - return true; - currParent = currParent->getParent(); - } - } - } - } - return false; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::executeControl (const std::string &/* sControlName */) -{ -// bool taken = false; -// CCtrlBase *pIC = getCtrl (sControlName); -// if (pIC != NULL) -// pIC->callback(taken); -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::draw () -{ - sint32 oldSciX, oldSciY, oldSciW, oldSciH; - makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); - - // Display sons only if not total clipped - CViewRenderer &rVR = *CViewRenderer::getInstance(); - if( !rVR.isClipWindowEmpty() ) - { - // Draw all decorative elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pVB = *ite; - if (pVB->getActive()) - pVB->draw(); - } - } - - restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::drawNoClip() -{ - // Display sons only if not total clipped - CViewRenderer &rVR = *CViewRenderer::getInstance(); - if( !rVR.isClipWindowEmpty() ) - { - // Draw all decorative elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pVB = *ite; - if (pVB->getActive()) - pVB->draw(); - } - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::renderWiredQuads(CInterfaceElement::TRenderWired type, const std::string &uiFilter) -{ - if (!_Active) return; - CInterfaceElement::renderWiredQuads(type, uiFilter); - sint32 oldSciX, oldSciY, oldSciW, oldSciH; - makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); - for(std::vector::iterator it = _EltOrder.begin(); it != _EltOrder.end(); ++it) - { - if (*it) (*it)->renderWiredQuads(type, uiFilter); - } - restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::drawElement (CViewBase *el) -{ - sint32 oldSciX, oldSciY, oldSciW, oldSciH; - makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); - - if(el) - el->draw(); - - restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::checkCoords() -{ - //update all children elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pIE = *ite; - if(pIE->getActive()) - pIE->checkCoords(); - } - executeLuaScriptOnDraw(); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::executeLuaScriptOnDraw() -{ - // If some LUA script attached to me, execute it - if(!_LUAOnDraw.empty()) - CAHManager::getInstance()->runActionHandler("lua", this, _LUAOnDraw); - -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::doUpdateCoords() -{ - _MaxWReal = _MaxW; - _MaxHReal = _MaxH; - - CInterfaceElement *el = NULL; - - if (_ParentSizeMax != NULL) - { - el = _ParentSizeMax; - } - else - { - if (_ParentSize != NULL) - { - el = _ParentSize; - } - else - { - if (_ParentPos != NULL) - el = _ParentPos; - else - el = _Parent; - } - } - - if (el != NULL) - { - if (_GroupSizeRef&1) - _MaxWReal += _SizeDivW * el->getWReal() / 10; - - if (_GroupSizeRef&2) - _MaxHReal += _SizeDivH * el->getHReal() / 10; - } - - CViewBase::updateCoords(); - _XReal += _OffsetX; - _YReal += _OffsetY; - - //update all children elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pIE = *ite; - pIE->updateCoords(); - } - - _XReal -= _OffsetX; - _YReal -= _OffsetY; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::updateCoords() -{ - // update basis and sons one time. - doUpdateCoords(); - - // if the group must resize from children - if(_ResizeFromChildH || _ResizeFromChildW) - { - // compute BBox of all childrens - sint width, height; - evalChildrenBBox(_ResizeFromChildW, _ResizeFromChildH, width, height); - // set forced size. - if(_ResizeFromChildW) - { - _W= _ResizeFromChildWMargin + width; - } - if(_ResizeFromChildH) - { - _H= _ResizeFromChildHMargin + height; - } - } - - CInterfaceElement::updateCoords(); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::evalChildrenBBox(bool resizeFromChildW, bool resizeFromChildH, sint &width, sint &height) const -{ - sint yMin=INT_MAX, yMax=INT_MIN; - sint xMin=INT_MAX, xMax=INT_MIN; - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pIE = *ite; - if (pIE->getActive()) - { - const CInterfaceElement *el = pIE->getParentPos() ? pIE->getParentPos() : pIE->getParent(); - if (el == this) - { - // to compute the bbox, don't use direct sons that have a sizeref on the resizing coordinate - if ((resizeFromChildW && (pIE->getSizeRef() & 1)) - || (resizeFromChildH && (pIE->getSizeRef() & 2)) - ) - { - continue; - } - } - // avoid also some interface elements - if(pIE->avoidResizeParent()) - continue; - // get the real coords bounds. - sint32 x0,y0,x1,y1; - // If it is a group, minimize with MaxHReal / MaxWReal - const CInterfaceGroup *sonGroup= dynamic_cast(pIE); - // \todo yoyo: do not know why but don't work if this==scroll_text - if(sonGroup && !isGroupScrollText()) - { - sint32 oldSciX= -16384; - sint32 oldSciY= -16384; - sint32 oldSciW= 32768; - sint32 oldSciH= 32768; - sint32 w, h; - sonGroup->computeCurrentClipContribution(oldSciX, oldSciY, oldSciW, oldSciH, x0, y0, w, h); - x1= x0 + w; - y1= y0 + h; + nlinfo("Element %d, name = %s, type=%s, x=%d, y=%d, parent_name=%s parentposname=%s xreal=%d, yreal=%d, wreal=%d, hreal=%d", + k, el->getId().c_str(), typeName.c_str(), el->getX(), el->getY(), el->getParent() ? el->getParent()->getId().c_str() : "no parent", + el->getParentPos() ? el->getParentPos()->getId().c_str() : "parent", + (int) el->getXReal(), + (int) el->getYReal(), + (int) el->getWReal(), + (int) el->getHReal() + ); } else { - x0= pIE->getXReal(); - y0= pIE->getYReal(); - x1= x0 + pIE->getWReal(); - y1= y0 + pIE->getHReal(); - } - // enlarge - if(x0xMax) - xMax= x1; - if(y1>yMax) - yMax= y1; - } - } - width = xMax - xMin; - height = yMax - yMin; -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CInterfaceGroup::getElement (const std::string &id) -{ - if (_Id == id) - return this; - - if (id.compare(0, _Id.size(), _Id) != 0) - return NULL; - - vector::const_iterator itv; - for (itv = _Views.begin(); itv != _Views.end(); itv++) - { - CViewBase *pVB = *itv; -#if !FINAL_VERSION // For SpeedUp in final version - nlassert(pVB); // The element must not be NULL -#endif - if (pVB->getId() == id) - return pVB; - } - - vector::const_iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) - { - CCtrlBase* ctrl = *itc; -#if !FINAL_VERSION // For SpeedUp in final version - nlassert(ctrl); // The element must not be NULL -#endif - if (ctrl->getId() == id) - return ctrl; - } - - vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) - { - CInterfaceGroup *pIG = *itg; -#if !FINAL_VERSION // For SpeedUp in final version - nlassert(pIG); // The element must not be NULL -#endif - CInterfaceElement *pIEL = pIG->getElement(id); - if (pIEL != NULL) - return pIEL; - } - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delElement (const std::string &id, bool noWarning) -{ - if (id.substr(0, _Id.size()) != _Id) - return false; - - vector::const_iterator itv; - for (itv = _Views.begin(); itv != _Views.end(); itv++) - { - CViewBase *pVB = *itv; - if (pVB->getId() == id) - { - delView (pVB, false); - return true; - } - } - - vector::const_iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) - { - CCtrlBase* ctrl = *itc; - if (ctrl->getId() == id) - { - delCtrl (ctrl, false); - return true; - } - } - - vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) - { - CInterfaceGroup *pIG = *itg; - if (pIG->getId() == id) - { - // If this is a root window - if (pIG->getRootWindow () == pIG) - CWidgetManager::getInstance()->unMakeWindow(pIG, noWarning); - delGroup (pIG, false); - return true; - } - } - return false; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delElement (CInterfaceElement *pIE, bool noWarning) -{ - // delete correct type of element - if(pIE->isGroup()) - { - CInterfaceGroup *pIG= static_cast(pIE); - // unmake window if it is - if (pIG->getRootWindow () == pIG) - CWidgetManager::getInstance()->unMakeWindow(pIG, noWarning); - return delGroup(pIG); - } - else if(pIE->isCtrl()) - { - return delCtrl(static_cast(pIE)); - } - - nlassert(pIE->isView()); - return delView(static_cast(pIE)); -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::isWindowUnder (sint32 x, sint32 y) -{ - return ((x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal + _HReal))); -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CInterfaceGroup::getGroupUnder (sint32 x, sint32 y) -{ - // Begins by the children - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) - { - CInterfaceGroup *pChild = *itg; - CInterfaceGroup *pChildUnder = pChild->getGroupUnder (x-_XReal, y-_YReal); - if (pChildUnder != NULL) - { - if ( (x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal+ _HReal))) - return pChildUnder; - } - } - - // If not found in childs then try in the parent one - if ( (x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal+ _HReal))) - return this; - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::getViewsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vVB) -{ - if (!((x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal+ _HReal)))) - return false; - // test against current clip - computeCurrentClipContribution(clipX, clipY, clipW, clipH, - clipX, clipY, clipW, clipH); - - if (!((x > clipX) && - (x < (clipX + clipW))&& - (y > clipY) && - (y < (clipY + clipH)))) - return false; - - - - // same as draw order: start with parent - std::vector::const_iterator itc; - for (itc = _EltOrder.begin(); itc != _EltOrder.end(); itc++) - { - if (!(*itc)->isCtrl() && !(*itc)->isGroup()) // must be a view - { - CViewBase *pVB = *itc; - if (pVB != NULL) - if (pVB->getActive()) - if ( ((x) > pVB->getXReal()) && - ((x) < (pVB->getXReal() + pVB->getWReal()))&& - ((y) > pVB->getYReal()) && - ((y) < (pVB->getYReal() + pVB->getHReal()))) - { - vVB.push_back (pVB); + nlinfo("Element %d = NULL", (int) k); } } } - // same as draw order: continue with children - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + // ------------------------------------------------------------------------------------------------ + sint CInterfaceGroup::getInsertionOrder(CViewBase *vb) const { - CInterfaceGroup *pChild = *itg; - if (pChild->getActive()) + for(uint k = 0; k < _EltOrder.size(); ++k) { -// bool bUnder = - pChild->getViewsUnder (x, y, clipX, clipY, clipW, clipH, vVB); -// if (bUnder && (vICL.size() > 0)) -// return true; + if (_EltOrder[k] == vb) return (sint) k; } + return -1; } - return true; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::getCtrlsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vICL) -{ - if (!((x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal+ _HReal)))) - return false; - // test against current clip - computeCurrentClipContribution(clipX, clipY, clipW, clipH, - clipX, clipY, clipW, clipH); - - if (!((x >= clipX) && - (x < (clipX + clipW))&& - (y > clipY) && - (y <= (clipY + clipH)))) - return false; - - - - // same as draw order: start with parent - std::vector::const_iterator itc; - for (itc = _EltOrder.begin(); itc != _EltOrder.end(); itc++) + // ------------------------------------------------------------------------------------------------ + sint32 CInterfaceGroup::getMaxUsedW() const { - if ((*itc)->isCtrl() && !(*itc)->isGroup()) // must be a ctrl but not a group (parsed later) + sint maxWidth = 0; + for (uint k = 0; k < _EltOrder.size(); ++k) { - CCtrlBase *pICL = (CCtrlBase *) *itc; - if (pICL != NULL) - if (pICL->getActive()) - if ( ((x) >= pICL->getXReal()) && - ((x) < (pICL->getXReal() + pICL->getWReal()))&& - ((y) > pICL->getYReal()) && - ((y) <= (pICL->getYReal() + pICL->getHReal()))) - { - vICL.push_back (pICL->getSubCtrl(x,y)); - } + // Get the child width + sint32 width = _EltOrder[k]->getMaxUsedW()+_EltOrder[k]->getXReal() - getXReal(); + if (width > maxWidth) + maxWidth = width; + } + return maxWidth; + } + + // ------------------------------------------------------------------------------------------------ + sint32 CInterfaceGroup::getMinUsedW() const + { + sint32 minWidth = 0; + for (uint k = 0; k < _EltOrder.size(); ++k) + { + // Get the child width + sint32 width = _EltOrder[k]->getMinUsedW()+_EltOrder[k]->getXReal() - getXReal(); + if (width > minWidth) + minWidth = width; + } + return minWidth; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearAllEditBox() + { + for(uint k = 0; k < _ChildrenGroups.size(); ++k) + { + if (_ChildrenGroups[k]) _ChildrenGroups[k]->clearAllEditBox(); } } - // same as draw order: continue with children - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::restoreAllContainersBackupPosition() { - CInterfaceGroup *pChild = *itg; - if (pChild->getActive()) + for(uint k = 0; k < _ChildrenGroups.size(); ++k) { -// bool bUnder = - pChild->getCtrlsUnder (x, y, clipX, clipY, clipW, clipH, vICL); -// if (bUnder && (vICL.size() > 0)) -// return true; - } - } - return true; -} - - -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::getGroupsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vIGL) -{ - if (!((x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal+ _HReal)))) - return false; - // test against current clip - computeCurrentClipContribution(clipX, clipY, clipW, clipH, - clipX, clipY, clipW, clipH); - - if (!((x >= clipX) && - (x < (clipX + clipW))&& - (y > clipY) && - (y <= (clipY + clipH)))) - return false; - - - - // same as draw order: start with parent - std::vector::const_iterator itc; - for (itc = _EltOrder.begin(); itc != _EltOrder.end(); itc++) - { - if ((*itc)->isGroup()) // must be a group - { - CInterfaceGroup *pIGL = (CInterfaceGroup *) *itc; - if (pIGL != NULL) - if (pIGL->getActive()) - if ( ((x) >= pIGL->getXReal()) && - ((x) < (pIGL->getXReal() + pIGL->getWReal()))&& - ((y) > pIGL->getYReal()) && - ((y) <= (pIGL->getYReal() + pIGL->getHReal()))) - { - vIGL.push_back (pIGL); - } + if (_ChildrenGroups[k]) _ChildrenGroups[k]->restoreAllContainersBackupPosition(); } } - // same as draw order: continue with children - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::dumpSize(uint depth /*=0*/) const { - CInterfaceGroup *pChild = *itg; - if (pChild->getActive()) + CViewBase::dumpSize(depth); + for(uint k = 0; k < _ChildrenGroups.size(); ++k) { -// bool bUnder = - pChild->getGroupsUnder (x, y, clipX, clipY, clipW, clipH, vIGL); -// if (bUnder && (vICL.size() > 0)) -// return true; + _ChildrenGroups[k]->dumpSize(depth + 1); + } + for(uint k = 0; k < _Controls.size(); ++k) + { + _Controls[k]->dumpSize(depth + 1); + } + for(uint k = 0; k < _Views.size(); ++k) + { + _Views[k]->dumpSize(depth + 1); } } - return true; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::absoluteToRelative (sint32 &x, sint32 &y) -{ - CInterfaceGroup *curGrp = _Parent; - while (curGrp != NULL) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::visit(CInterfaceElementVisitor *visitor) { - x = x - curGrp->_XReal; - y = y - curGrp->_YReal; - curGrp = curGrp->_Parent; - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::computeCurrentClipContribution(sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH, - sint32 &newSciXDest, sint32 &newSciYDest, sint32 &newSciWDest, sint32 &newSciHDest) const -{ - sint32 newSciX = _XReal; - sint32 newSciY = _YReal; - sint32 newSciW = _WReal; - sint32 newSciH = _HReal; - // If there is width size limiter - if (_MaxWReal < _WReal) - { - if ((_PosRef == Hotspot_TR) || (_PosRef == Hotspot_MR) || (_PosRef == Hotspot_BR)) - newSciX = _XReal + _WReal - _MaxWReal; - newSciW = _MaxWReal; - } - // If there is height size limiter - if (_MaxHReal < _HReal) - { - if ((_PosRef == Hotspot_TL) || (_PosRef == Hotspot_TM) || (_PosRef == Hotspot_TR)) - newSciY = _YReal + _HReal - _MaxHReal; - newSciH = _MaxHReal; - } - // Clip Left - if (newSciX < oldSciX) - { - newSciW = newSciW - (oldSciX - newSciX); - newSciX = oldSciX; - } - // Clip Right - if ((newSciX+newSciW) > (oldSciX+oldSciW)) - { - newSciW = newSciW - ((newSciX+newSciW)-(oldSciX+oldSciW)); - } - // Clip Bottom - if (newSciY < oldSciY) - { - newSciH = newSciH - (oldSciY - newSciY); - newSciY = oldSciY; - } - // Clip Top - if ((newSciY+newSciH) > (oldSciY+oldSciH)) - { - newSciH = newSciH - ((newSciY+newSciH)-(oldSciY+oldSciH)); - } - - newSciXDest = newSciX; - newSciYDest = newSciY; - newSciWDest = newSciW; - newSciHDest = newSciH; - -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::makeNewClip (sint32 &oldSciX, sint32 &oldSciY, sint32 &oldSciW, sint32 &oldSciH) -{ - CViewRenderer &rVR = *CViewRenderer::getInstance(); - rVR.getClipWindow (oldSciX, oldSciY, oldSciW, oldSciH); - - sint32 newSciX, newSciY, newSciW, newSciH; - computeCurrentClipContribution(oldSciX, oldSciY, oldSciW, oldSciH, newSciX, newSciY, newSciW, newSciH); - rVR.setClipWindow (newSciX, newSciY, newSciW, newSciH); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::getClip(sint32 &x, sint32 &y, sint32 &w, sint32 &h) const -{ - CViewRenderer &rVR = *CViewRenderer::getInstance(); - uint32 sw, sh; - rVR.getScreenSize(sw, sh); - sint32 sciX = 0, sciY = 0, sciW = sw, sciH =sh; - const CInterfaceGroup *currGroup = this; - do - { - currGroup->computeCurrentClipContribution(sciX, sciY, sciW, sciH, sciX, sciY, sciW, sciH); - currGroup = currGroup->_Parent; - } while(currGroup); - x = sciX; - y = sciY; - w = sciW; - h = sciH; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::restoreClip (sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH) -{ - CViewRenderer &rVR = *CViewRenderer::getInstance(); - rVR.setClipWindow (oldSciX, oldSciY, oldSciW, oldSciH); -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::launch () -{ - // launch all elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pIE = *ite; - pIE->launch(); - } -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup *CInterfaceGroup::getGroup(uint index) const -{ - if (index > _ChildrenGroups.size()) - { - nlwarning(" bad index;"); - return NULL; - } - return _ChildrenGroups[index]; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::updateAllLinks() -{ - CCtrlBase::updateAllLinks(); - { - for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) + nlassert(visitor); + for(uint k = 0; k < _ChildrenGroups.size(); ++k) { - (*it)->updateAllLinks(); + _ChildrenGroups[k]->visit(visitor); + } + for(uint k = 0; k < _Controls.size(); ++k) + { + _Controls[k]->visit(visitor); + } + for(uint k = 0; k < _Views.size(); ++k) + { + _Views[k]->visit(visitor); + } + visitor->visitGroup(this); + CInterfaceElement::visit(visitor); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::visitGroupAndChildren( CInterfaceElementVisitor *visitor ) + { + nlassert( visitor != 0 ); + for( uint i = 0; i < _ChildrenGroups.size(); i++ ) + { + _ChildrenGroups[ i ]->visitGroupAndChildren( visitor ); + } + + visitor->visitGroup( this ); + } + + + // ------------------------------------------------------------------------------------------------ + + void CInterfaceGroup::setUseCursor(bool use) + { + _UseCursor=use; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::onFrameUpdateWindowPos(sint dx, sint dy) + { + // Move me. + _XReal+= dx; + _YReal+= dy; + + // Move all my sons. + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pIE = *ite; + pIE->onFrameUpdateWindowPos(dx, dy); } } - { - for(std::vector::iterator it = _Controls.begin(); it != _Controls.end(); ++it) - { - (*it)->updateAllLinks(); - } - } - { - for(std::vector::iterator it = _Views.begin(); it != _Views.end(); ++it) - { - (*it)->updateAllLinks(); - } - } -} -// ------------------------------------------------------------------------------------------------ -sint32 CInterfaceGroup::getAlpha() const -{ - vector::const_iterator itv; - for (itv = _Views.begin(); itv != _Views.end(); itv++) - { - CViewBase *pVB = *itv; - sint32 a = pVB->getAlpha(); - if (a != -1) - return a; - } - - vector::const_iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) - { - CCtrlBase *pCB = *itc; - sint32 a = pCB->getAlpha(); - if (a != -1) - return a; - } - - vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) - { - CInterfaceGroup *pIG = *itg; - sint32 a = pIG->getAlpha(); - if (a != -1) - return a; - } - return -1; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setAlpha (sint32 a) -{ - vector::const_iterator itv; - for (itv = _Views.begin(); itv != _Views.end(); itv++) - { - CViewBase *pVB = *itv; - pVB->setAlpha(a); - } - - vector::const_iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) - { - CCtrlBase *pCB = *itc; - pCB->setAlpha(a); - } - - vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) - { - CInterfaceGroup *pIG = *itg; - pIG->setAlpha(a); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setLeftClickHandler(const std::string &handler) -{ - _AHOnLeftClick = CAHManager::getInstance()->getAH(handler, _AHOnLeftClickParams); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setRightClickHandler(const std::string &handler) -{ - _AHOnRightClick = CAHManager::getInstance()->getAH(handler, _AHOnRightClickParams); -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CInterfaceGroup::getEnclosingContainer() -{ - CInterfaceGroup *ig = this; - do - { - if( ig->isGroupContainer() ) - return ig; - ig = ig->getParent(); - } - while( ig != NULL ); - - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::dumpGroups() -{ - nlinfo("Num groups = %d", (int) _ChildrenGroups.size()); - for(uint k = 0; k < _ChildrenGroups.size(); ++k) - { - std::string typeName = "???"; - if (_ChildrenGroups[k]) - { - const type_info &ti = typeid(*_ChildrenGroups[k]); - typeName = ti.name(); - } - nlinfo("Group %d, name = %s, type=%s", k, _ChildrenGroups[k] ? _ChildrenGroups[k]->getId().c_str() : "???", typeName.c_str()); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::dumpEltsOrder() -{ - nlinfo("Num elements = %d", (int) _EltOrder.size()); - for(uint k = 0; k < _EltOrder.size(); ++k) - { - std::string typeName = "???"; - if (_ChildrenGroups[k]) - { - const type_info &ti = typeid(*_EltOrder[k]); - typeName = ti.name(); - } - CInterfaceElement *el = _EltOrder[k]; - if (el) - { - nlinfo("Element %d, name = %s, type=%s, x=%d, y=%d, parent_name=%s parentposname=%s xreal=%d, yreal=%d, wreal=%d, hreal=%d", - k, el->getId().c_str(), typeName.c_str(), el->getX(), el->getY(), el->getParent() ? el->getParent()->getId().c_str() : "no parent", - el->getParentPos() ? el->getParentPos()->getId().c_str() : "parent", - (int) el->getXReal(), - (int) el->getYReal(), - (int) el->getWReal(), - (int) el->getHReal() - ); - } - else - { - nlinfo("Element %d = NULL", (int) k); - } - } -} - -// ------------------------------------------------------------------------------------------------ -sint CInterfaceGroup::getInsertionOrder(CViewBase *vb) const -{ - for(uint k = 0; k < _EltOrder.size(); ++k) - { - if (_EltOrder[k] == vb) return (sint) k; - } - return -1; -} - -// ------------------------------------------------------------------------------------------------ -sint32 CInterfaceGroup::getMaxUsedW() const -{ - sint maxWidth = 0; - for (uint k = 0; k < _EltOrder.size(); ++k) - { - // Get the child width - sint32 width = _EltOrder[k]->getMaxUsedW()+_EltOrder[k]->getXReal() - getXReal(); - if (width > maxWidth) - maxWidth = width; - } - return maxWidth; -} - -// ------------------------------------------------------------------------------------------------ -sint32 CInterfaceGroup::getMinUsedW() const -{ - sint32 minWidth = 0; - for (uint k = 0; k < _EltOrder.size(); ++k) - { - // Get the child width - sint32 width = _EltOrder[k]->getMinUsedW()+_EltOrder[k]->getXReal() - getXReal(); - if (width > minWidth) - minWidth = width; - } - return minWidth; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::clearAllEditBox() -{ - for(uint k = 0; k < _ChildrenGroups.size(); ++k) - { - if (_ChildrenGroups[k]) _ChildrenGroups[k]->clearAllEditBox(); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::restoreAllContainersBackupPosition() -{ - for(uint k = 0; k < _ChildrenGroups.size(); ++k) - { - if (_ChildrenGroups[k]) _ChildrenGroups[k]->restoreAllContainersBackupPosition(); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::dumpSize(uint depth /*=0*/) const -{ - CViewBase::dumpSize(depth); - for(uint k = 0; k < _ChildrenGroups.size(); ++k) - { - _ChildrenGroups[k]->dumpSize(depth + 1); - } - for(uint k = 0; k < _Controls.size(); ++k) - { - _Controls[k]->dumpSize(depth + 1); - } - for(uint k = 0; k < _Views.size(); ++k) - { - _Views[k]->dumpSize(depth + 1); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::visit(CInterfaceElementVisitor *visitor) -{ - nlassert(visitor); - for(uint k = 0; k < _ChildrenGroups.size(); ++k) - { - _ChildrenGroups[k]->visit(visitor); - } - for(uint k = 0; k < _Controls.size(); ++k) - { - _Controls[k]->visit(visitor); - } - for(uint k = 0; k < _Views.size(); ++k) - { - _Views[k]->visit(visitor); - } - visitor->visitGroup(this); - CInterfaceElement::visit(visitor); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::visitGroupAndChildren( CInterfaceElementVisitor *visitor ) -{ - nlassert( visitor != 0 ); - for( uint i = 0; i < _ChildrenGroups.size(); i++ ) - { - _ChildrenGroups[ i ]->visitGroupAndChildren( visitor ); - } - - visitor->visitGroup( this ); -} - - -// ------------------------------------------------------------------------------------------------ - -void CInterfaceGroup::setUseCursor(bool use) -{ - _UseCursor=use; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::onFrameUpdateWindowPos(sint dx, sint dy) -{ - // Move me. - _XReal+= dx; - _YReal+= dy; - - // Move all my sons. - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pIE = *ite; - pIE->onFrameUpdateWindowPos(dx, dy); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::pushLUAEnvTable() -{ - CLuaState *lua= CLuaManager::getInstance().getLuaState(); - nlassert(lua); - - if(!_LUAEnvTableCreated) - { - CLuaStackChecker lsc(lua); - - // Create a table and assign it in the REGISTRY."__ui_envtable" table, with a userdata ptr - lua->push(IHM_LUA_ENVTABLE); - lua->getTable(LUA_REGISTRYINDEX); // Stack: __ui_envtable - lua->pushLightUserData(IG_UNIQUE_ID(this)); - lua->newTable(); - lua->setTable(-3); // Stack: __ui_envtable (with .this={}) - lua->pop(); - - // Created! - _LUAEnvTableCreated= true; - } - - // Get the table from registry, and push it on stack - CLuaStackChecker lsc(lua, 1); - lua->push(IHM_LUA_ENVTABLE); - lua->getTable(LUA_REGISTRYINDEX); // __ui_envtable - lua->pushLightUserData(IG_UNIQUE_ID(this)); - lua->getTable(-2); // __ui_envtable envtable - lua->remove(-2); // envtable - nlassert(lua->isTable()); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::deleteLUAEnvTable(bool recurse) -{ - if(_LUAEnvTableCreated) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::pushLUAEnvTable() { CLuaState *lua= CLuaManager::getInstance().getLuaState(); nlassert(lua); - // replace simply the table with Nil, letting LUA Garbage collector do the realease stuff - CLuaStackChecker lsc(lua); + if(!_LUAEnvTableCreated) + { + CLuaStackChecker lsc(lua); + + // Create a table and assign it in the REGISTRY."__ui_envtable" table, with a userdata ptr + lua->push(IHM_LUA_ENVTABLE); + lua->getTable(LUA_REGISTRYINDEX); // Stack: __ui_envtable + lua->pushLightUserData(IG_UNIQUE_ID(this)); + lua->newTable(); + lua->setTable(-3); // Stack: __ui_envtable (with .this={}) + lua->pop(); + + // Created! + _LUAEnvTableCreated= true; + } + + // Get the table from registry, and push it on stack + CLuaStackChecker lsc(lua, 1); lua->push(IHM_LUA_ENVTABLE); lua->getTable(LUA_REGISTRYINDEX); // __ui_envtable - lua->pushLightUserData(IG_UNIQUE_ID(this)); // NB nico : use some pointer *inside* that object as a unique id (any field but - // the first), instead of using 'this'. 'this' is already used by - // CLuaIHM::pushReflectableOnStack - lua->pushNil(); - lua->setTable(-3); // __ui_envtable - lua->pop(); - - _LUAEnvTableCreated= false; + lua->pushLightUserData(IG_UNIQUE_ID(this)); + lua->getTable(-2); // __ui_envtable envtable + lua->remove(-2); // envtable + nlassert(lua->isTable()); } - if (recurse) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::deleteLUAEnvTable(bool recurse) { - for(uint k = 0; k < _ChildrenGroups.size(); ++k) + if(_LUAEnvTableCreated) { - _ChildrenGroups[k]->deleteLUAEnvTable(true); + CLuaState *lua= CLuaManager::getInstance().getLuaState(); + nlassert(lua); + + // replace simply the table with Nil, letting LUA Garbage collector do the realease stuff + CLuaStackChecker lsc(lua); + lua->push(IHM_LUA_ENVTABLE); + lua->getTable(LUA_REGISTRYINDEX); // __ui_envtable + lua->pushLightUserData(IG_UNIQUE_ID(this)); // NB nico : use some pointer *inside* that object as a unique id (any field but + // the first), instead of using 'this'. 'this' is already used by + // CLuaIHM::pushReflectableOnStack + lua->pushNil(); + lua->setTable(-3); // __ui_envtable + lua->pop(); + + _LUAEnvTableCreated= false; + } + if (recurse) + { + for(uint k = 0; k < _ChildrenGroups.size(); ++k) + { + _ChildrenGroups[k]->deleteLUAEnvTable(true); + } } } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setLuaScriptOnDraw(const std::string &script) -{ - _LUAOnDraw= script; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addLuaScriptOnDBChange(const std::string &dbList, const std::string &script) -{ - // remove any existing - removeLuaScriptOnDBChange(dbList); - - // create and attach the link - NLMISC::CSmartPtr newLink= new CInterfaceLink; - _LUAOnDbChange[dbList]= newLink; - // Init and attach to list of untargeted links - std::vector noTargets; - newLink->init(noTargets, NLMISC::toString("depends(%s)", dbList.c_str()), "lua", script, "", this); -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::removeLuaScriptOnDBChange(const std::string &dbList) -{ - TLUAOnDbChange::iterator it= _LUAOnDbChange.find(dbList); - if(it!=_LUAOnDbChange.end()) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setLuaScriptOnDraw(const std::string &script) { - nlassert(it->second!=NULL); - // Remove from link of untargeted Links - it->second->uninit(); - // erase from map (thus the ptr should be deleted) - _LUAOnDbChange.erase(it); + _LUAOnDraw= script; } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::removeAllLUAOnDbChange() -{ - TLUAOnDbChange::iterator it= _LUAOnDbChange.begin(); - for(;it!=_LUAOnDbChange.end();) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addLuaScriptOnDBChange(const std::string &dbList, const std::string &script) { - // since deleted, must not do it++, but it= begin() - removeLuaScriptOnDBChange(it->first); - it= _LUAOnDbChange.begin(); - } -} + // remove any existing + removeLuaScriptOnDBChange(dbList); -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaFind(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::find", 1); - CLuaIHM::checkArgType(ls, "CInterfaceGroup::find", 1, LUA_TSTRING); - std::string id = ls.toString(1); - CInterfaceElement* element = findFromShortId(id); - if (!element) + // create and attach the link + NLMISC::CSmartPtr newLink= new CInterfaceLink; + _LUAOnDbChange[dbList]= newLink; + // Init and attach to list of untargeted links + std::vector noTargets; + newLink->init(noTargets, NLMISC::toString("depends(%s)", dbList.c_str()), "lua", script, "", this); + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::removeLuaScriptOnDBChange(const std::string &dbList) { - ls.pushNil(); + TLUAOnDbChange::iterator it= _LUAOnDbChange.find(dbList); + if(it!=_LUAOnDbChange.end()) + { + nlassert(it->second!=NULL); + // Remove from link of untargeted Links + it->second->uninit(); + // erase from map (thus the ptr should be deleted) + _LUAOnDbChange.erase(it); + } } - else + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::removeAllLUAOnDbChange() { - CLuaIHM::pushUIOnStack(ls, element); + TLUAOnDbChange::iterator it= _LUAOnDbChange.begin(); + for(;it!=_LUAOnDbChange.end();) + { + // since deleted, must not do it++, but it= begin() + removeLuaScriptOnDBChange(it->first); + it= _LUAOnDbChange.begin(); + } } - return 1; -} -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CInterfaceGroup::findFromShortId(const std::string &id) -{ - CInterfaceElement* element = NULL; - element = getView(id); - if (!element) element = getCtrl(id); - if (!element) element = getGroup(id); - return element; -} - -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaGetEnclosingContainer(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getEnclosingContainer", 0); - CLuaIHM::pushUIOnStack(ls, getEnclosingContainer()); - return 1; -} - -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaDeleteLUAEnvTable(CLuaState &ls) -{ - const char *funcName = "deleteLUAenvTable"; - CLuaIHM::checkArgCount(ls, funcName, 1); - CLuaIHM::checkArgType(ls, funcName, 1, LUA_TBOOLEAN); // is delete recursive - deleteLUAEnvTable(ls.toBoolean(1)); - return 0; -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::serial(NLMISC::IStream &f) -{ - CCtrlBase::serial(f); - f.serialContPolyPtr(_ChildrenGroups); - f.serialContPolyPtr(_Controls); - f.serialContPolyPtr(_Views); - f.serialContPolyPtr(_EltOrder); - f.serial(_MaxW, _MaxH); - f.serial(_MaxWReal, _MaxHReal); - f.serial(_OffsetX, _OffsetY); - f.serial(_Priority); - - nlSerialBitBool(f, _Overlappable); - nlSerialBitBool(f, _ResizeFromChildW); - nlSerialBitBool(f, _ResizeFromChildH); - nlSerialBitBool(f, _Escapable); - nlSerialBitBool(f, _UseCursor); - nlSerialBitBool(f, _IsGroupContainer); - nlSerialBitBool(f, _NeedFrameUpdatePos); - - f.serial(_ResizeFromChildWMargin); - f.serial(_ResizeFromChildHMargin); - f.serial(_GroupSizeRef); - - serialAH(f, _AHOnActive); - f.serial(_AHOnActiveParams); - serialAH(f, _AHOnDeactive); - f.serial(_AHOnDeactiveParams); - - // right & left clicks - serialAH(f, _AHOnLeftClick); - f.serial(_AHOnLeftClickParams); - serialAH(f, _AHOnRightClick); - f.serial(_AHOnRightClickParams); - - // enter params. - serialAH(f, _AHOnEnter); - f.serial(_AHOnEnterParams); - - // escape AH - serialAH(f, _AHOnEscape); - f.serial(_AHOnEscapeParams); -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceElement *CInterfaceGroup::clone() -{ - CInterfaceElement *oldParentSizeMax = _ParentSizeMax; - if (_ParentSizeMax == _Parent) + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaFind(CLuaState &ls) { - _ParentSizeMax = NULL; + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::find", 1); + CLuaIHM::checkArgType(ls, "CInterfaceGroup::find", 1, LUA_TSTRING); + std::string id = ls.toString(1); + CInterfaceElement* element = findFromShortId(id); + if (!element) + { + ls.pushNil(); + } + else + { + CLuaIHM::pushUIOnStack(ls, element); + } + return 1; } - CInterfaceElement *ret = CCtrlBase::clone(); - _ParentSizeMax = oldParentSizeMax; - return ret; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setMaxSizeRef(const std::string &maxSizeRef) -{ - parseMaxSizeRef(maxSizeRef.c_str()); -} + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CInterfaceGroup::findFromShortId(const std::string &id) + { + CInterfaceElement* element = NULL; + element = getView(id); + if (!element) element = getCtrl(id); + if (!element) element = getGroup(id); + return element; + } -// ------------------------------------------------------------------------------------------------ -std::string CInterfaceGroup::getMaxSizeRefAsString() const -{ - return "IMPLEMENT ME!"; -} + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaGetEnclosingContainer(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getEnclosingContainer", 0); + CLuaIHM::pushUIOnStack(ls, getEnclosingContainer()); + return 1; + } + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaDeleteLUAEnvTable(CLuaState &ls) + { + const char *funcName = "deleteLUAenvTable"; + CLuaIHM::checkArgCount(ls, funcName, 1); + CLuaIHM::checkArgType(ls, funcName, 1, LUA_TBOOLEAN); // is delete recursive + deleteLUAEnvTable(ls.toBoolean(1)); + return 0; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::serial(NLMISC::IStream &f) + { + CCtrlBase::serial(f); + f.serialContPolyPtr(_ChildrenGroups); + f.serialContPolyPtr(_Controls); + f.serialContPolyPtr(_Views); + f.serialContPolyPtr(_EltOrder); + f.serial(_MaxW, _MaxH); + f.serial(_MaxWReal, _MaxHReal); + f.serial(_OffsetX, _OffsetY); + f.serial(_Priority); + + nlSerialBitBool(f, _Overlappable); + nlSerialBitBool(f, _ResizeFromChildW); + nlSerialBitBool(f, _ResizeFromChildH); + nlSerialBitBool(f, _Escapable); + nlSerialBitBool(f, _UseCursor); + nlSerialBitBool(f, _IsGroupContainer); + nlSerialBitBool(f, _NeedFrameUpdatePos); + + f.serial(_ResizeFromChildWMargin); + f.serial(_ResizeFromChildHMargin); + f.serial(_GroupSizeRef); + + serialAH(f, _AHOnActive); + f.serial(_AHOnActiveParams); + serialAH(f, _AHOnDeactive); + f.serial(_AHOnDeactiveParams); + + // right & left clicks + serialAH(f, _AHOnLeftClick); + f.serial(_AHOnLeftClickParams); + serialAH(f, _AHOnRightClick); + f.serial(_AHOnRightClickParams); + + // enter params. + serialAH(f, _AHOnEnter); + f.serial(_AHOnEnterParams); + + // escape AH + serialAH(f, _AHOnEscape); + f.serial(_AHOnEscapeParams); + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceElement *CInterfaceGroup::clone() + { + CInterfaceElement *oldParentSizeMax = _ParentSizeMax; + if (_ParentSizeMax == _Parent) + { + _ParentSizeMax = NULL; + } + CInterfaceElement *ret = CCtrlBase::clone(); + _ParentSizeMax = oldParentSizeMax; + return ret; + } + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setMaxSizeRef(const std::string &maxSizeRef) + { + parseMaxSizeRef(maxSizeRef.c_str()); + } + + // ------------------------------------------------------------------------------------------------ + std::string CInterfaceGroup::getMaxSizeRefAsString() const + { + return "IMPLEMENT ME!"; + } + +} \ No newline at end of file diff --git a/code/nel/src/gui/interface_link.cpp b/code/nel/src/gui/interface_link.cpp index 68e9a194c..0dffc3d4d 100644 --- a/code/nel/src/gui/interface_link.cpp +++ b/code/nel/src/gui/interface_link.cpp @@ -29,619 +29,626 @@ using namespace std; using namespace NLMISC; -///////////// -// GLOBALS // -///////////// - -CInterfaceLink::TLinkList CInterfaceLink::_LinkList; -CInterfaceLink::TLinkVect CInterfaceLink::_LinksWithNoTarget; -// -CInterfaceLink *CInterfaceLink::_FirstTriggeredLink[2] = { NULL, NULL }; -CInterfaceLink *CInterfaceLink::_LastTriggeredLink[2] = { NULL, NULL }; -CInterfaceLink *CInterfaceLink::_CurrUpdatedLink = NULL; -CInterfaceLink *CInterfaceLink::_NextUpdatedLink = NULL; -uint CInterfaceLink::_CurrentTriggeredLinkList = 0; - -bool CInterfaceLink::_UpdateAllLinks = false; - - -/////////////// -// FUNCTIONS // -/////////////// - -/** Tool fct : affect a value to a reflected property of an interface element. - */ -static bool affect(const CInterfaceExprValue &value, CInterfaceElement &destElem, const CReflectedProperty &property) +namespace NLGUI { - CInterfaceExprValue valueToAffect = value; - switch(property.Type) + ///////////// + // GLOBALS // + ///////////// + + CInterfaceLink::TLinkList CInterfaceLink::_LinkList; + CInterfaceLink::TLinkVect CInterfaceLink::_LinksWithNoTarget; + // + CInterfaceLink *CInterfaceLink::_FirstTriggeredLink[2] = { NULL, NULL }; + CInterfaceLink *CInterfaceLink::_LastTriggeredLink[2] = { NULL, NULL }; + CInterfaceLink *CInterfaceLink::_CurrUpdatedLink = NULL; + CInterfaceLink *CInterfaceLink::_NextUpdatedLink = NULL; + uint CInterfaceLink::_CurrentTriggeredLinkList = 0; + + bool CInterfaceLink::_UpdateAllLinks = false; + + + /////////////// + // FUNCTIONS // + /////////////// + + /** Tool fct : affect a value to a reflected property of an interface element. + */ + static bool affect(const CInterfaceExprValue &value, CInterfaceElement &destElem, const CReflectedProperty &property) { - case CReflectedProperty::Boolean: - if (valueToAffect.toBool()) - { - (destElem.*(property.SetMethod.SetBool))(valueToAffect.getBool()); - } - else - { - return false; - } - break; - case CReflectedProperty::SInt32: - if (valueToAffect.toInteger()) - { - (destElem.*(property.SetMethod.SetSInt32))((sint32) valueToAffect.getInteger()); - } - else - { - - return false; - } - break; - case CReflectedProperty::Float: - if (valueToAffect.toDouble()) - { - (destElem.*(property.SetMethod.SetFloat))((float) valueToAffect.getDouble()); - } - else - { - - return false; - } - break; - case CReflectedProperty::String: - if (valueToAffect.toString()) - { - (destElem.*(property.SetMethod.SetString))(valueToAffect.getString()); - } - else - { - - return false; - } - break; - case CReflectedProperty::UCString: - if (valueToAffect.toString()) - { - (destElem.*(property.SetMethod.SetUCString))(valueToAffect.getUCString()); - } - else - { - - return false; - } - break; - case CReflectedProperty::RGBA: - if (valueToAffect.toRGBA()) - { - (destElem.*(property.SetMethod.SetRGBA))(valueToAffect.getRGBA()); - } - else - { - - return false; - } - break; - default: - break; - } - - return true; -} - -CInterfaceLink::CInterfaceLinkUpdater::CInterfaceLinkUpdater() -{ - NLGUI::CDBManager::getInstance()->addFlushObserver( this ); -} - -CInterfaceLink::CInterfaceLinkUpdater::~CInterfaceLinkUpdater() -{ -} - -void CInterfaceLink::CInterfaceLinkUpdater::onObserverCallFlush() -{ - CInterfaceLink::updateTrigeredLinks(); -} - -///////////// -// MEMBERS // -///////////// - -//=========================================================== -CInterfaceLink::CInterfaceLink() : _On(true) -{ - // add an entry in the links list - _LinkList.push_front(this); - _ListEntry = _LinkList.begin(); - _PrevTriggeredLink[0] = _PrevTriggeredLink[1] = NULL; - _NextTriggeredLink[0] = _NextTriggeredLink[1] = NULL; - _Triggered[0] = _Triggered[1] = false; - _ParseTree = NULL; -} - -//=========================================================== -CInterfaceLink::~CInterfaceLink() -{ - if (this == _CurrUpdatedLink) - { - _CurrUpdatedLink = NULL; - } - if (this == _NextUpdatedLink) - { - _NextUpdatedLink = _NextUpdatedLink->_NextTriggeredLink[1 - _CurrentTriggeredLinkList]; - } - // unlink observer from both update lists - unlinkFromTriggerList(0); - unlinkFromTriggerList(1); - - removeObservers(_ObservedNodes); - // removes from the link list - _LinkList.erase(_ListEntry); - - delete _ParseTree; -} - -//=========================================================== -bool CInterfaceLink::init(const std::vector &targets, const std::string &expr, const std::string &actionHandler, const std::string &ahParams, const std::string &ahCond, CInterfaceGroup *parentGroup) -{ - CInterfaceExprValue result; - // Build the parse tree - nlassert(!_ParseTree); - _ParseTree = CInterfaceExpr::buildExprTree(expr); - if (!_ParseTree) - { - // wrong expression : release the link - nlwarning("CInterfaceLink::init : can't parse expression %s", expr.c_str()); - _LinksWithNoTarget.push_back(TLinkSmartPtr(this)); - return false; - } - // Examine the expression, to see which database nodes it depends on - _ParseTree->getDepends(_ObservedNodes); - // must keep observerd node sorted (for std::set_xx ops) - std::sort(_ObservedNodes.begin(), _ObservedNodes.end()); - if (!targets.empty()) - { - // retrieve properties from the element - _Targets.resize(targets.size()); - for (uint k = 0; k < targets.size(); ++k) + CInterfaceExprValue valueToAffect = value; + switch(property.Type) { - CInterfaceElement *elem = targets[k].Elem; - if (!elem) + case CReflectedProperty::Boolean: + if (valueToAffect.toBool()) + { + (destElem.*(property.SetMethod.SetBool))(valueToAffect.getBool()); + } + else + { + + return false; + } + break; + case CReflectedProperty::SInt32: + if (valueToAffect.toInteger()) + { + (destElem.*(property.SetMethod.SetSInt32))((sint32) valueToAffect.getInteger()); + } + else + { + + return false; + } + break; + case CReflectedProperty::Float: + if (valueToAffect.toDouble()) + { + (destElem.*(property.SetMethod.SetFloat))((float) valueToAffect.getDouble()); + } + else + { + + return false; + } + break; + case CReflectedProperty::String: + if (valueToAffect.toString()) + { + (destElem.*(property.SetMethod.SetString))(valueToAffect.getString()); + } + else + { + + return false; + } + break; + case CReflectedProperty::UCString: + if (valueToAffect.toString()) + { + (destElem.*(property.SetMethod.SetUCString))(valueToAffect.getUCString()); + } + else + { + + return false; + } + break; + case CReflectedProperty::RGBA: + if (valueToAffect.toRGBA()) + { + (destElem.*(property.SetMethod.SetRGBA))(valueToAffect.getRGBA()); + } + else + { + + return false; + } + break; + default: + break; + } + + return true; + } + + CInterfaceLink::CInterfaceLinkUpdater::CInterfaceLinkUpdater() + { + NLGUI::CDBManager::getInstance()->addFlushObserver( this ); + } + + CInterfaceLink::CInterfaceLinkUpdater::~CInterfaceLinkUpdater() + { + } + + void CInterfaceLink::CInterfaceLinkUpdater::onObserverCallFlush() + { + CInterfaceLink::updateTrigeredLinks(); + } + + ///////////// + // MEMBERS // + ///////////// + + //=========================================================== + CInterfaceLink::CInterfaceLink() : _On(true) + { + // add an entry in the links list + _LinkList.push_front(this); + _ListEntry = _LinkList.begin(); + _PrevTriggeredLink[0] = _PrevTriggeredLink[1] = NULL; + _NextTriggeredLink[0] = _NextTriggeredLink[1] = NULL; + _Triggered[0] = _Triggered[1] = false; + _ParseTree = NULL; + } + + //=========================================================== + CInterfaceLink::~CInterfaceLink() + { + if (this == _CurrUpdatedLink) + { + _CurrUpdatedLink = NULL; + } + if (this == _NextUpdatedLink) + { + _NextUpdatedLink = _NextUpdatedLink->_NextTriggeredLink[1 - _CurrentTriggeredLinkList]; + } + // unlink observer from both update lists + unlinkFromTriggerList(0); + unlinkFromTriggerList(1); + + removeObservers(_ObservedNodes); + // removes from the link list + _LinkList.erase(_ListEntry); + + delete _ParseTree; + } + + //=========================================================== + bool CInterfaceLink::init(const std::vector &targets, const std::string &expr, const std::string &actionHandler, const std::string &ahParams, const std::string &ahCond, CInterfaceGroup *parentGroup) + { + CInterfaceExprValue result; + // Build the parse tree + nlassert(!_ParseTree); + _ParseTree = CInterfaceExpr::buildExprTree(expr); + if (!_ParseTree) + { + // wrong expression : release the link + nlwarning("CInterfaceLink::init : can't parse expression %s", expr.c_str()); + _LinksWithNoTarget.push_back(TLinkSmartPtr(this)); + return false; + } + // Examine the expression, to see which database nodes it depends on + _ParseTree->getDepends(_ObservedNodes); + // must keep observerd node sorted (for std::set_xx ops) + std::sort(_ObservedNodes.begin(), _ObservedNodes.end()); + if (!targets.empty()) + { + // retrieve properties from the element + _Targets.resize(targets.size()); + for (uint k = 0; k < targets.size(); ++k) { - nlwarning(" : Element %d is NULL", k); - _Targets[k]._InterfaceElement = NULL; - continue; + CInterfaceElement *elem = targets[k].Elem; + if (!elem) + { + nlwarning(" : Element %d is NULL", k); + _Targets[k]._InterfaceElement = NULL; + continue; + } + _Targets[k]._Property = elem->getReflectedProperty(targets[k].PropertyName); + if (!_Targets[k]._Property) + { + nlwarning(" : Can't retrieve property %s for element %d.", targets[k].PropertyName.c_str(), k); + _Targets[k]._InterfaceElement = NULL; + continue; + } + _Targets[k]._InterfaceElement = elem; + elem->addLink(this); } - _Targets[k]._Property = elem->getReflectedProperty(targets[k].PropertyName); - if (!_Targets[k]._Property) + } + else + { + // There are no target for this link, so, put in a dedicated list to ensure that the link will be destroyed at exit + _LinksWithNoTarget.push_back(TLinkSmartPtr(this)); + } + + // create observers + createObservers(_ObservedNodes); + _Expr = expr; + // + _ActionHandler = actionHandler; + _AHParams = ahParams; + _AHCond = ahCond; + _AHParent = parentGroup; + return true; + } + + //=========================================================== + void CInterfaceLink::uninit() + { + for (uint32 i = 0; i < _LinksWithNoTarget.size(); i++) + { + CInterfaceLink *pLink = _LinksWithNoTarget[i]; + if (pLink == this) { - nlwarning(" : Can't retrieve property %s for element %d.", targets[k].PropertyName.c_str(), k); - _Targets[k]._InterfaceElement = NULL; - continue; + _LinksWithNoTarget.erase(_LinksWithNoTarget.begin()+i); + return; } - _Targets[k]._InterfaceElement = elem; - elem->addLink(this); } } - else + + //=========================================================== + void CInterfaceLink::update(ICDBNode * /* node */) { - // There are no target for this link, so, put in a dedicated list to ensure that the link will be destroyed at exit - _LinksWithNoTarget.push_back(TLinkSmartPtr(this)); + // mark link as triggered + linkInTriggerList(_CurrentTriggeredLinkList); } - // create observers - createObservers(_ObservedNodes); - _Expr = expr; - // - _ActionHandler = actionHandler; - _AHParams = ahParams; - _AHCond = ahCond; - _AHParent = parentGroup; - return true; -} - -//=========================================================== -void CInterfaceLink::uninit() -{ - for (uint32 i = 0; i < _LinksWithNoTarget.size(); i++) + //=========================================================== + void CInterfaceLink::createObservers(const TNodeVect &nodes) { - CInterfaceLink *pLink = _LinksWithNoTarget[i]; - if (pLink == this) + for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { - _LinksWithNoTarget.erase(_LinksWithNoTarget.begin()+i); + if ((*it)->isLeaf()) + { + ICDBNode::CTextId textId; + (*it)->addObserver(this, textId); + } + else + { + CCDBNodeBranch *br = static_cast(*it); + NLGUI::CDBManager::getInstance()->addBranchObserver( br, this ); + } + } + } + + //=========================================================== + void CInterfaceLink::removeObservers(const TNodeVect &nodes) + { + for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) + { + if ((*it)->isLeaf()) + { + ICDBNode::CTextId textId; + (*it)->removeObserver(this, textId); + } + else + { + CCDBNodeBranch *br = static_cast(*it); + NLGUI::CDBManager::getInstance()->removeBranchObserver( br, this ); + } + } + } + + //=========================================================== + void CInterfaceLink::updateAllLinks() + { + nlassert(!_UpdateAllLinks); + _UpdateAllLinks = true; + for(TLinkList::iterator it = _LinkList.begin(); it != _LinkList.end(); ++it) + { + CInterfaceLink *pLink = *it; + pLink->update(); + } + _UpdateAllLinks = false; + } + + //=========================================================== + void CInterfaceLink::update() + { + //_On = false; // prvent recursive calls + if (!_ParseTree) return; + static TNodeVect observedNodes; // should not be too big, so ok to keep it static. + static TNodeVect tmpNodes; + observedNodes.clear(); + CInterfaceExprValue result; + _ParseTree->evalWithDepends(result, observedNodes); + // std::set_xxx require ordered container + std::sort(observedNodes.begin(), observedNodes.end()); + // we assume that _ObservedNode are also sorted + // compute new observers + tmpNodes.clear(); + std::set_difference(observedNodes.begin(), observedNodes.end(), _ObservedNodes.begin(), _ObservedNodes.end(), std::back_inserter(tmpNodes)); + // add these observers + createObservers(tmpNodes); + // compute lost observers + tmpNodes.clear(); + std::set_difference(_ObservedNodes.begin(), _ObservedNodes.end(), observedNodes.begin(), observedNodes.end(), std::back_inserter(tmpNodes)); + // remove these observers + removeObservers(tmpNodes); + // subsitute new (sorted) list to current + _ObservedNodes.swap(observedNodes); + // + for (uint k = 0; k < _Targets.size(); ++k) + { + CInterfaceElement *elem = _Targets[k]._InterfaceElement; + const CReflectedProperty *prop = _Targets[k]._Property; + if (elem && prop) + { + if (!affect(result, *elem, *prop)) + { + nlwarning("CInterfaceLink::update: Result conversion failed"); + } + } + } + // if there's an action handler, execute it + if (!_ActionHandler.empty()) + { + // If there is a condition, test it. + bool launch= true; + if(!_AHCond.empty()) + { + launch= false; + CInterfaceExprValue result; + if(CInterfaceExpr::eval(_AHCond, result)) + launch= result.getBool(); + } + if(launch) + { + CAHManager::getInstance()->runActionHandler(_ActionHandler, _AHParent, _AHParams); + // do not add any code after this line because this can be deleted !!!! + } + } + + //_On = true; // prevent recursive calls + } + + // predicate to remove an element from a list + struct CRemoveTargetPred + { + CInterfaceElement *Target; + bool operator()(const CInterfaceLink::CTarget &target) const { return target._InterfaceElement == Target; } + }; + + //=========================================================== + void CInterfaceLink::removeTarget(CInterfaceElement *elem) + { + CRemoveTargetPred pred; + pred.Target = elem; + _Targets.erase(std::remove_if(_Targets.begin(), _Targets.end(), pred), _Targets.end()); + } + + //=========================================================== + bool CInterfaceLink::CTargetInfo::affect(const CInterfaceExprValue &value) + { + + if (!Elem) + { + nlwarning(" : Target element is NULL"); + + return false; + } + const CReflectedProperty *property = Elem->getReflectedProperty(PropertyName); + if (!property) + { + nlwarning(" : Can't retrieve property %s for element %s.", PropertyName.c_str(), Elem->getId().c_str()); + + return false; + } + // try to affect the property + if (!NLGUI::affect(value, *Elem, *property)) + { + nlwarning(" Couldn't convert the value to affect to %s", Elem->getId().c_str()); + + return false; + } + + return true; + } + + //=========================================================== + void CInterfaceLink::removeAllLinks() + { + _LinksWithNoTarget.clear(); + TLinkList::iterator curr = _LinkList.begin(); + TLinkList::iterator nextIt; + uint k; + while(curr != _LinkList.end()) + { + nextIt = curr; + ++ nextIt; + CInterfaceLink &link = **curr; + link.checkNbRefs(); + NLMISC::CSmartPtr linkPtr = *curr; // must keep a smart ptr because of the test in the loop + for (k = 0; k < link._Targets.size(); ++k) + { + if (link._Targets[k]._InterfaceElement) + { + nlinfo("InterfaceElement %s was not remove.", link._Targets[k]._InterfaceElement->getId().c_str()); + link._Targets[k]._InterfaceElement->removeLink(&link); + } + } + linkPtr = NULL; // effectively destroy link + curr = nextIt; + } + nlassert(_LinkList.empty()); + } + + // *************************************************************************** + bool CInterfaceLink::splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm) + { + // the last token of the target gives the name of the property + std::string::size_type lastPos = target.find_last_of(':'); + if (lastPos == (target.length() - 1)) + { + // todo hulud interface syntax error + nlwarning("The target should at least contains a path and a property as follow 'path:property'"); + return false; + } + std::string elmPath; + std::string elmProp; + CInterfaceElement *elm = NULL; + if (parentGroup) + { + if (lastPos == std::string::npos) + { + elmProp = target; + elm = parentGroup; + elmPath = "current"; + } + else + { + elmProp = target.substr(lastPos + 1); + elmPath = parentGroup->getId() + ":" + target.substr(0, lastPos); + elm = parentGroup->getElement(elmPath); + } + } + if (!elm) + { + // try the absolute adress of the element + elmPath = target.substr(0, lastPos); + elm = CWidgetManager::getInstance()->getElementFromId(elmPath); + elmProp = target.substr(lastPos + 1); + } + + if (!elm) + { + // todo hulud interface syntax error + nlwarning(" can't find target link %s", elmPath.c_str()); + return false; + } + targetElm = elm; + propertyName = elmProp; + return true; + } + + + // *************************************************************************** + bool CInterfaceLink::splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup,std::vector &targetsVect) + { + std::vector targetNames; + NLMISC::splitString(targets, ",", targetNames); + targetsVect.clear(); + targetsVect.reserve(targetNames.size()); + bool everythingOk = true; + for (uint k = 0; k < targetNames.size(); ++k) + { + CInterfaceLink::CTargetInfo ti; + std::string::size_type startPos = targetNames[k].find_first_not_of(" "); + if(startPos == std::string::npos) + { + // todo hulud interface syntax error + nlwarning(" empty target encountered"); + continue; + } + std::string::size_type lastPos = targetNames[k].find_last_not_of(" "); + + if (!splitLinkTarget(targetNames[k].substr(startPos, lastPos - startPos+1), parentGroup, ti.PropertyName, ti.Elem)) + { + // todo hulud interface syntax error + nlwarning(" Can't get link target"); + everythingOk = false; + continue; + } + targetsVect.push_back(ti); + } + return everythingOk; + } + + + //=========================================================== + void CInterfaceLink::checkNbRefs() + { + uint numValidPtr = 0; + for(uint k = 0; k < _Targets.size(); ++k) + { + if (_Targets[k]._InterfaceElement != NULL) ++numValidPtr; + } + nlassert(numValidPtr == (uint) crefs); + } + + + //=========================================================== + void CInterfaceLink::setTargetProperty (const std::string &Target, const CInterfaceExprValue &val) + { + // Eval target ! + string elt = Target.substr(0,Target.rfind(':')); + CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(elt); + CInterfaceGroup *pIG = dynamic_cast(pIE); + if (pIG == NULL) + pIG = pIE->getParent(); + + if (pIG != NULL) + { + std::vector vTargets; + splitLinkTargets(Target, pIG, vTargets); + if ((vTargets.size() > 0) && (vTargets[0].Elem)) + { + vTargets[0].affect(val); + } + } + } + + //----------------------------------------------- + void CInterfaceLink::linkInTriggerList(uint list) + { + nlassert(list < 2); + if (_Triggered[list]) return; // already inserted in list + _Triggered[list] = true; + nlassert(!_PrevTriggeredLink[list]); + nlassert(!_NextTriggeredLink[list]); + if (!_FirstTriggeredLink[list]) + { + _FirstTriggeredLink[list] = _LastTriggeredLink[list] = this; + } + else + { + nlassert(!_LastTriggeredLink[list]->_NextTriggeredLink[list]); + _LastTriggeredLink[list]->_NextTriggeredLink[list] = this; + _PrevTriggeredLink[list] = _LastTriggeredLink[list]; + _LastTriggeredLink[list] = this; + } + } + + //----------------------------------------------- + void CInterfaceLink::unlinkFromTriggerList(uint list) + { + nlassert(list < 2); + if (!_Triggered[list]) + { + // not linked in this list + nlassert(_PrevTriggeredLink[list] == NULL); + nlassert(_NextTriggeredLink[list] == NULL); return; } - } -} - -//=========================================================== -void CInterfaceLink::update(ICDBNode * /* node */) -{ - // mark link as triggered - linkInTriggerList(_CurrentTriggeredLinkList); -} - -//=========================================================== -void CInterfaceLink::createObservers(const TNodeVect &nodes) -{ - for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) - { - if ((*it)->isLeaf()) + if (_PrevTriggeredLink[list]) { - ICDBNode::CTextId textId; - (*it)->addObserver(this, textId); + _PrevTriggeredLink[list]->_NextTriggeredLink[list] = _NextTriggeredLink[list]; } else { - CCDBNodeBranch *br = static_cast(*it); - NLGUI::CDBManager::getInstance()->addBranchObserver( br, this ); + // this was the first node + _FirstTriggeredLink[list] = _NextTriggeredLink[list]; } - } -} - -//=========================================================== -void CInterfaceLink::removeObservers(const TNodeVect &nodes) -{ - for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) - { - if ((*it)->isLeaf()) + if (_NextTriggeredLink[list]) { - ICDBNode::CTextId textId; - (*it)->removeObserver(this, textId); + _NextTriggeredLink[list]->_PrevTriggeredLink[list] = _PrevTriggeredLink[list]; } else { - CCDBNodeBranch *br = static_cast(*it); - NLGUI::CDBManager::getInstance()->removeBranchObserver( br, this ); - } - } -} - -//=========================================================== -void CInterfaceLink::updateAllLinks() -{ - nlassert(!_UpdateAllLinks); - _UpdateAllLinks = true; - for(TLinkList::iterator it = _LinkList.begin(); it != _LinkList.end(); ++it) - { - CInterfaceLink *pLink = *it; - pLink->update(); - } - _UpdateAllLinks = false; -} - -//=========================================================== -void CInterfaceLink::update() -{ - //_On = false; // prvent recursive calls - if (!_ParseTree) return; - static TNodeVect observedNodes; // should not be too big, so ok to keep it static. - static TNodeVect tmpNodes; - observedNodes.clear(); - CInterfaceExprValue result; - _ParseTree->evalWithDepends(result, observedNodes); - // std::set_xxx require ordered container - std::sort(observedNodes.begin(), observedNodes.end()); - // we assume that _ObservedNode are also sorted - // compute new observers - tmpNodes.clear(); - std::set_difference(observedNodes.begin(), observedNodes.end(), _ObservedNodes.begin(), _ObservedNodes.end(), std::back_inserter(tmpNodes)); - // add these observers - createObservers(tmpNodes); - // compute lost observers - tmpNodes.clear(); - std::set_difference(_ObservedNodes.begin(), _ObservedNodes.end(), observedNodes.begin(), observedNodes.end(), std::back_inserter(tmpNodes)); - // remove these observers - removeObservers(tmpNodes); - // subsitute new (sorted) list to current - _ObservedNodes.swap(observedNodes); - // - for (uint k = 0; k < _Targets.size(); ++k) - { - CInterfaceElement *elem = _Targets[k]._InterfaceElement; - const CReflectedProperty *prop = _Targets[k]._Property; - if (elem && prop) - { - if (!affect(result, *elem, *prop)) - { - nlwarning("CInterfaceLink::update: Result conversion failed"); - } - } - } - // if there's an action handler, execute it - if (!_ActionHandler.empty()) - { - // If there is a condition, test it. - bool launch= true; - if(!_AHCond.empty()) - { - launch= false; - CInterfaceExprValue result; - if(CInterfaceExpr::eval(_AHCond, result)) - launch= result.getBool(); - } - if(launch) - { - CAHManager::getInstance()->runActionHandler(_ActionHandler, _AHParent, _AHParams); - // do not add any code after this line because this can be deleted !!!! + // this was the last node + _LastTriggeredLink[list] = _PrevTriggeredLink[list]; } + _PrevTriggeredLink[list] = NULL; + _NextTriggeredLink[list] = NULL; + _Triggered[list] = false; } - //_On = true; // prevent recursive calls -} -// predicate to remove an element from a list -struct CRemoveTargetPred -{ - CInterfaceElement *Target; - bool operator()(const CInterfaceLink::CTarget &target) const { return target._InterfaceElement == Target; } -}; -//=========================================================== -void CInterfaceLink::removeTarget(CInterfaceElement *elem) -{ - CRemoveTargetPred pred; - pred.Target = elem; - _Targets.erase(std::remove_if(_Targets.begin(), _Targets.end(), pred), _Targets.end()); -} -//=========================================================== -bool CInterfaceLink::CTargetInfo::affect(const CInterfaceExprValue &value) -{ - if (!Elem) + //----------------------------------------------- + void CInterfaceLink::updateTrigeredLinks() { - nlwarning(" : Target element is NULL"); - - return false; - } - const CReflectedProperty *property = Elem->getReflectedProperty(PropertyName); - if (!property) - { - nlwarning(" : Can't retrieve property %s for element %s.", PropertyName.c_str(), Elem->getId().c_str()); - - return false; - } - // try to affect the property - if (!::affect(value, *Elem, *property)) - { - nlwarning(" Couldn't convert the value to affect to %s", Elem->getId().c_str()); - - return false; - } - - return true; -} - -//=========================================================== -void CInterfaceLink::removeAllLinks() -{ - _LinksWithNoTarget.clear(); - TLinkList::iterator curr = _LinkList.begin(); - TLinkList::iterator nextIt; - uint k; - while(curr != _LinkList.end()) - { - nextIt = curr; - ++ nextIt; - CInterfaceLink &link = **curr; - link.checkNbRefs(); - NLMISC::CSmartPtr linkPtr = *curr; // must keep a smart ptr because of the test in the loop - for (k = 0; k < link._Targets.size(); ++k) - { - if (link._Targets[k]._InterfaceElement) - { - nlinfo("InterfaceElement %s was not remove.", link._Targets[k]._InterfaceElement->getId().c_str()); - link._Targets[k]._InterfaceElement->removeLink(&link); - } - } - linkPtr = NULL; // effectively destroy link - curr = nextIt; - } - nlassert(_LinkList.empty()); -} - -// *************************************************************************** -bool CInterfaceLink::splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm) -{ - // the last token of the target gives the name of the property - std::string::size_type lastPos = target.find_last_of(':'); - if (lastPos == (target.length() - 1)) - { - // todo hulud interface syntax error - nlwarning("The target should at least contains a path and a property as follow 'path:property'"); - return false; - } - std::string elmPath; - std::string elmProp; - CInterfaceElement *elm = NULL; - if (parentGroup) - { - if (lastPos == std::string::npos) - { - elmProp = target; - elm = parentGroup; - elmPath = "current"; - } - else - { - elmProp = target.substr(lastPos + 1); - elmPath = parentGroup->getId() + ":" + target.substr(0, lastPos); - elm = parentGroup->getElement(elmPath); - } - } - if (!elm) - { - // try the absolute adress of the element - elmPath = target.substr(0, lastPos); - elm = CWidgetManager::getInstance()->getElementFromId(elmPath); - elmProp = target.substr(lastPos + 1); - } - - if (!elm) - { - // todo hulud interface syntax error - nlwarning(" can't find target link %s", elmPath.c_str()); - return false; - } - targetElm = elm; - propertyName = elmProp; - return true; -} - - -// *************************************************************************** -bool CInterfaceLink::splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup,std::vector &targetsVect) -{ - std::vector targetNames; - NLMISC::splitString(targets, ",", targetNames); - targetsVect.clear(); - targetsVect.reserve(targetNames.size()); - bool everythingOk = true; - for (uint k = 0; k < targetNames.size(); ++k) - { - CInterfaceLink::CTargetInfo ti; - std::string::size_type startPos = targetNames[k].find_first_not_of(" "); - if(startPos == std::string::npos) - { - // todo hulud interface syntax error - nlwarning(" empty target encountered"); - continue; - } - std::string::size_type lastPos = targetNames[k].find_last_not_of(" "); - - if (!splitLinkTarget(targetNames[k].substr(startPos, lastPos - startPos+1), parentGroup, ti.PropertyName, ti.Elem)) - { - // todo hulud interface syntax error - nlwarning(" Can't get link target"); - everythingOk = false; - continue; - } - targetsVect.push_back(ti); - } - return everythingOk; -} - - -//=========================================================== -void CInterfaceLink::checkNbRefs() -{ - uint numValidPtr = 0; - for(uint k = 0; k < _Targets.size(); ++k) - { - if (_Targets[k]._InterfaceElement != NULL) ++numValidPtr; - } - nlassert(numValidPtr == (uint) crefs); -} - - -//=========================================================== -void CInterfaceLink::setTargetProperty (const std::string &Target, const CInterfaceExprValue &val) -{ - // Eval target ! - string elt = Target.substr(0,Target.rfind(':')); - CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(elt); - CInterfaceGroup *pIG = dynamic_cast(pIE); - if (pIG == NULL) - pIG = pIE->getParent(); - - if (pIG != NULL) - { - std::vector vTargets; - splitLinkTargets(Target, pIG, vTargets); - if ((vTargets.size() > 0) && (vTargets[0].Elem)) - { - vTargets[0].affect(val); - } - } -} - -//----------------------------------------------- -void CInterfaceLink::linkInTriggerList(uint list) -{ - nlassert(list < 2); - if (_Triggered[list]) return; // already inserted in list - _Triggered[list] = true; - nlassert(!_PrevTriggeredLink[list]); - nlassert(!_NextTriggeredLink[list]); - if (!_FirstTriggeredLink[list]) - { - _FirstTriggeredLink[list] = _LastTriggeredLink[list] = this; - } - else - { - nlassert(!_LastTriggeredLink[list]->_NextTriggeredLink[list]); - _LastTriggeredLink[list]->_NextTriggeredLink[list] = this; - _PrevTriggeredLink[list] = _LastTriggeredLink[list]; - _LastTriggeredLink[list] = this; - } -} - -//----------------------------------------------- -void CInterfaceLink::unlinkFromTriggerList(uint list) -{ - nlassert(list < 2); - if (!_Triggered[list]) - { - // not linked in this list - nlassert(_PrevTriggeredLink[list] == NULL); - nlassert(_NextTriggeredLink[list] == NULL); - return; - } - if (_PrevTriggeredLink[list]) - { - _PrevTriggeredLink[list]->_NextTriggeredLink[list] = _NextTriggeredLink[list]; - } - else - { - // this was the first node - _FirstTriggeredLink[list] = _NextTriggeredLink[list]; - } - if (_NextTriggeredLink[list]) - { - _NextTriggeredLink[list]->_PrevTriggeredLink[list] = _PrevTriggeredLink[list]; - } - else - { - // this was the last node - _LastTriggeredLink[list] = _PrevTriggeredLink[list]; - } - _PrevTriggeredLink[list] = NULL; - _NextTriggeredLink[list] = NULL; - _Triggered[list] = false; -} - - - - - -//----------------------------------------------- -void CInterfaceLink::updateTrigeredLinks() -{ - static bool called = false; - nlassert(!called); - called = true; - _CurrUpdatedLink = _FirstTriggeredLink[_CurrentTriggeredLinkList]; - while (_CurrUpdatedLink) - { - // modified node should now store them in other list when they're modified - _CurrentTriggeredLinkList = 1 - _CurrentTriggeredLinkList; - // switch list so that modified node are stored in the other list + static bool called = false; + nlassert(!called); + called = true; + _CurrUpdatedLink = _FirstTriggeredLink[_CurrentTriggeredLinkList]; while (_CurrUpdatedLink) { - _NextUpdatedLink = _CurrUpdatedLink->_NextTriggeredLink[1 - _CurrentTriggeredLinkList]; - _CurrUpdatedLink->update(); - if (_CurrUpdatedLink) // this may be modified by the call (if current observer is removed) + // modified node should now store them in other list when they're modified + _CurrentTriggeredLinkList = 1 - _CurrentTriggeredLinkList; + // switch list so that modified node are stored in the other list + while (_CurrUpdatedLink) { - _CurrUpdatedLink->unlinkFromTriggerList(1 - _CurrentTriggeredLinkList); + _NextUpdatedLink = _CurrUpdatedLink->_NextTriggeredLink[1 - _CurrentTriggeredLinkList]; + _CurrUpdatedLink->update(); + if (_CurrUpdatedLink) // this may be modified by the call (if current observer is removed) + { + _CurrUpdatedLink->unlinkFromTriggerList(1 - _CurrentTriggeredLinkList); + } + _CurrUpdatedLink = _NextUpdatedLink; } - _CurrUpdatedLink = _NextUpdatedLink; + nlassert(_FirstTriggeredLink[1 - _CurrentTriggeredLinkList] == NULL); + nlassert(_LastTriggeredLink[1 - _CurrentTriggeredLinkList] == NULL); + // examine other list to see if nodes have been registered + _CurrUpdatedLink = _FirstTriggeredLink[_CurrentTriggeredLinkList]; } - nlassert(_FirstTriggeredLink[1 - _CurrentTriggeredLinkList] == NULL); - nlassert(_LastTriggeredLink[1 - _CurrentTriggeredLinkList] == NULL); - // examine other list to see if nodes have been registered - _CurrUpdatedLink = _FirstTriggeredLink[_CurrentTriggeredLinkList]; + called = false; } - called = false; + + } + diff --git a/code/nel/src/gui/interface_options.cpp b/code/nel/src/gui/interface_options.cpp index 2c9bd97d8..1a01bce6e 100644 --- a/code/nel/src/gui/interface_options.cpp +++ b/code/nel/src/gui/interface_options.cpp @@ -23,103 +23,106 @@ using namespace std; using namespace NLMISC; -// *************************************************************************** -const CInterfaceOptionValue CInterfaceOptionValue::NullValue; - -// *************************************************************************** -void CInterfaceOptionValue::init(const std::string &str) +namespace NLGUI { - _Str= str; - fromString(str, _Int); - fromString(str, _Float); - _Color= CInterfaceElement::convertColor (str.c_str()); - _Boolean= CInterfaceElement::convertBool(str.c_str()); -} + const CInterfaceOptionValue CInterfaceOptionValue::NullValue; -// ---------------------------------------------------------------------------- -// CInterfaceOptions -// ---------------------------------------------------------------------------- - -// ---------------------------------------------------------------------------- -CInterfaceOptions::CInterfaceOptions() -{ -} - -// ---------------------------------------------------------------------------- -CInterfaceOptions::~CInterfaceOptions() -{ -} - -// ---------------------------------------------------------------------------- -bool CInterfaceOptions::parse (xmlNodePtr cur) -{ - cur = cur->children; - bool ok = true; - while (cur) + // *************************************************************************** + void CInterfaceOptionValue::init(const std::string &str) { - if ( !stricmp((char*)cur->name,"param") ) - { - CXMLAutoPtr ptr, val; - ptr = xmlGetProp (cur, (xmlChar*)"name"); - val = xmlGetProp (cur, (xmlChar*)"value"); - if (!ptr || !val) - { - nlinfo("param with no name or no value"); - ok = false; - } - else - { - string name = NLMISC::toLower(string((const char*)ptr)); - string value = (string((const char*)val)); - _ParamValue[name].init(value); - } - } - cur = cur->next; + _Str= str; + fromString(str, _Int); + fromString(str, _Float); + _Color= CInterfaceElement::convertColor (str.c_str()); + _Boolean= CInterfaceElement::convertBool(str.c_str()); } - return ok; -} -// *************************************************************************** -void CInterfaceOptions::copyBasicMap(const CInterfaceOptions &other) -{ - _ParamValue= other._ParamValue; -} -// *************************************************************************** -const CInterfaceOptionValue &CInterfaceOptions::getValue(const string &sParamName) const -{ - string sLwrParamName = strlwr (sParamName); - std::map::const_iterator it = _ParamValue.find (sLwrParamName); - if (it != _ParamValue.end()) - return it->second; - else - return CInterfaceOptionValue::NullValue; -} + // ---------------------------------------------------------------------------- + // CInterfaceOptions + // ---------------------------------------------------------------------------- -// *************************************************************************** -const std::string &CInterfaceOptions::getValStr(const std::string &sParamName) const -{ - return getValue(sParamName).getValStr(); -} -// *************************************************************************** -sint32 CInterfaceOptions::getValSInt32(const std::string &sParamName) const -{ - return getValue(sParamName).getValSInt32(); -} -// *************************************************************************** -float CInterfaceOptions::getValFloat(const std::string &sParamName) const -{ - return getValue(sParamName).getValFloat(); -} -// *************************************************************************** -NLMISC::CRGBA CInterfaceOptions::getValColor(const std::string &sParamName) const -{ - return getValue(sParamName).getValColor(); -} -// *************************************************************************** -bool CInterfaceOptions::getValBool(const std::string &sParamName) const -{ - return getValue(sParamName).getValBool(); -} + // ---------------------------------------------------------------------------- + CInterfaceOptions::CInterfaceOptions() + { + } + // ---------------------------------------------------------------------------- + CInterfaceOptions::~CInterfaceOptions() + { + } + + // ---------------------------------------------------------------------------- + bool CInterfaceOptions::parse (xmlNodePtr cur) + { + cur = cur->children; + bool ok = true; + while (cur) + { + if ( !stricmp((char*)cur->name,"param") ) + { + CXMLAutoPtr ptr, val; + ptr = xmlGetProp (cur, (xmlChar*)"name"); + val = xmlGetProp (cur, (xmlChar*)"value"); + if (!ptr || !val) + { + nlinfo("param with no name or no value"); + ok = false; + } + else + { + string name = NLMISC::toLower(string((const char*)ptr)); + string value = (string((const char*)val)); + _ParamValue[name].init(value); + } + } + cur = cur->next; + } + return ok; + } + + // *************************************************************************** + void CInterfaceOptions::copyBasicMap(const CInterfaceOptions &other) + { + _ParamValue= other._ParamValue; + } + + // *************************************************************************** + const CInterfaceOptionValue &CInterfaceOptions::getValue(const string &sParamName) const + { + string sLwrParamName = strlwr (sParamName); + std::map::const_iterator it = _ParamValue.find (sLwrParamName); + if (it != _ParamValue.end()) + return it->second; + else + return CInterfaceOptionValue::NullValue; + } + + // *************************************************************************** + const std::string &CInterfaceOptions::getValStr(const std::string &sParamName) const + { + return getValue(sParamName).getValStr(); + } + // *************************************************************************** + sint32 CInterfaceOptions::getValSInt32(const std::string &sParamName) const + { + return getValue(sParamName).getValSInt32(); + } + // *************************************************************************** + float CInterfaceOptions::getValFloat(const std::string &sParamName) const + { + return getValue(sParamName).getValFloat(); + } + // *************************************************************************** + NLMISC::CRGBA CInterfaceOptions::getValColor(const std::string &sParamName) const + { + return getValue(sParamName).getValColor(); + } + // *************************************************************************** + bool CInterfaceOptions::getValBool(const std::string &sParamName) const + { + return getValue(sParamName).getValBool(); + } + +} diff --git a/code/nel/src/gui/view_base.cpp b/code/nel/src/gui/view_base.cpp index 56761c571..9636ed9c1 100644 --- a/code/nel/src/gui/view_base.cpp +++ b/code/nel/src/gui/view_base.cpp @@ -18,27 +18,32 @@ #include "nel/gui/interface_group.h" #include "nel/gui/widget_manager.h" -CViewBase::~CViewBase() +namespace NLGUI { - CWidgetManager::getInstance()->removeRefOnView (this); -} - -// *************************************************************************** -void CViewBase::dumpSize(uint depth /*=0*/) const -{ - std::string result; - result.resize(depth * 4, ' '); - std::string::size_type pos = _Id.find_last_of(':'); - std::string shortID = pos == std::string::npos ? _Id : _Id.substr(pos); - result += NLMISC::toString("id=%s, w=%d, h=%d, x=%d, y=%d, wreal=%d, hreal=%d, xreal=%d, yreal=%d", shortID.c_str(), (int) _W, (int) _H, (int) _X, (int) _Y, (int) _WReal, (int) _HReal, (int) _XReal, (int) _YReal); - nlinfo(result.c_str()); -} - -// *************************************************************************** -void CViewBase::visit(CInterfaceElementVisitor *visitor) -{ - nlassert(visitor); - visitor->visitView(this); - CInterfaceElement::visit(visitor); + + CViewBase::~CViewBase() + { + CWidgetManager::getInstance()->removeRefOnView (this); + } + + // *************************************************************************** + void CViewBase::dumpSize(uint depth /*=0*/) const + { + std::string result; + result.resize(depth * 4, ' '); + std::string::size_type pos = _Id.find_last_of(':'); + std::string shortID = pos == std::string::npos ? _Id : _Id.substr(pos); + result += NLMISC::toString("id=%s, w=%d, h=%d, x=%d, y=%d, wreal=%d, hreal=%d, xreal=%d, yreal=%d", shortID.c_str(), (int) _W, (int) _H, (int) _X, (int) _Y, (int) _WReal, (int) _HReal, (int) _XReal, (int) _YReal); + nlinfo(result.c_str()); + } + + // *************************************************************************** + void CViewBase::visit(CInterfaceElementVisitor *visitor) + { + nlassert(visitor); + visitor->visitView(this); + CInterfaceElement::visit(visitor); + } + } diff --git a/code/nel/src/gui/view_pointer_base.cpp b/code/nel/src/gui/view_pointer_base.cpp index b89febad9..976263eb1 100644 --- a/code/nel/src/gui/view_pointer_base.cpp +++ b/code/nel/src/gui/view_pointer_base.cpp @@ -1,122 +1,142 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + #include "nel/gui/view_pointer_base.h" -CViewPointerBase::CViewPointerBase( const CViewBase::TCtorParam ¶m ) : -CViewBase( param ) +namespace NLGUI { - _PointerX = _PointerY = _PointerOldX = _PointerOldY = _PointerDownX = _PointerDownY = 0; - _PointerDown = false; - _PointerVisible = true; -} -CViewPointerBase::~CViewPointerBase() -{ -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerPos (sint32 x, sint32 y) -{ - if (_PointerDown) + CViewPointerBase::CViewPointerBase( const CViewBase::TCtorParam ¶m ) : + CViewBase( param ) { - if (!_PointerDrag) + _PointerX = _PointerY = _PointerOldX = _PointerOldY = _PointerDownX = _PointerDownY = 0; + _PointerDown = false; + _PointerVisible = true; + } + + CViewPointerBase::~CViewPointerBase() + { + } + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::setPointerPos (sint32 x, sint32 y) + { + if (_PointerDown) { - if (((_PointerX - _PointerDownX) != 0) || - ((_PointerY - _PointerDownY) != 0)) + if (!_PointerDrag) { - _PointerDrag = true; + if (((_PointerX - _PointerDownX) != 0) || + ((_PointerY - _PointerDownY) != 0)) + { + _PointerDrag = true; + } } } + + _PointerOldX = getX(); + _PointerOldY = getY(); + + _PointerX = x; + _PointerY = y; } - _PointerOldX = getX(); - _PointerOldY = getY(); - - _PointerX = x; - _PointerY = y; -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerDispPos (sint32 x, sint32 y) -{ - setX (x); - setY (y); - updateCoords (); -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::resetPointerPos () -{ - _PointerOldX = _PointerX; - _PointerOldY = _PointerY; -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerDown (bool pd) -{ - _PointerDown = pd; - - if (_PointerDown == true) + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::setPointerDispPos (sint32 x, sint32 y) { - _PointerDownX = _PointerX; - _PointerDownY = _PointerY; + setX (x); + setY (y); + updateCoords (); + } + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::resetPointerPos () + { + _PointerOldX = _PointerX; + _PointerOldY = _PointerY; + } + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::setPointerDown (bool pd) + { + _PointerDown = pd; + + if (_PointerDown == true) + { + _PointerDownX = _PointerX; + _PointerDownY = _PointerY; + } + + if (_PointerDown == false) + _PointerDrag = false; + } + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::setPointerDownString (const std::string &s) + { + _PointerDownString = s; + } + + // +++ GET +++ + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerPos (sint32 &x, sint32 &y) + { + x = _PointerX; + y = _PointerY; + } + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerDispPos (sint32 &x, sint32 &y) + { + x = getX(); + y = getY(); + } + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerOldPos (sint32 &x, sint32 &y) + { + x = _PointerOldX; + y = _PointerOldY; + } + + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerDownPos (sint32 &x, sint32 &y) + { + x = _PointerDownX; + y = _PointerDownY; + } + + // -------------------------------------------------------------------------------------------------------------------- + bool CViewPointerBase::getPointerDown () + { + return _PointerDown; + } + + // -------------------------------------------------------------------------------------------------------------------- + bool CViewPointerBase::getPointerDrag () + { + return _PointerDrag; + } + + // -------------------------------------------------------------------------------------------------------------------- + std::string CViewPointerBase::getPointerDownString () + { + return _PointerDownString; } - if (_PointerDown == false) - _PointerDrag = false; } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerDownString (const std::string &s) -{ - _PointerDownString = s; -} - -// +++ GET +++ - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerPos (sint32 &x, sint32 &y) -{ - x = _PointerX; - y = _PointerY; -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerDispPos (sint32 &x, sint32 &y) -{ - x = getX(); - y = getY(); -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerOldPos (sint32 &x, sint32 &y) -{ - x = _PointerOldX; - y = _PointerOldY; -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerDownPos (sint32 &x, sint32 &y) -{ - x = _PointerDownX; - y = _PointerDownY; -} - -// -------------------------------------------------------------------------------------------------------------------- -bool CViewPointerBase::getPointerDown () -{ - return _PointerDown; -} - -// -------------------------------------------------------------------------------------------------------------------- -bool CViewPointerBase::getPointerDrag () -{ - return _PointerDrag; -} - -// -------------------------------------------------------------------------------------------------------------------- -std::string CViewPointerBase::getPointerDownString () -{ - return _PointerDownString; -} - - - diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index aaf0813ef..14064ec40 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -25,1377 +25,1382 @@ #include "nel/gui/group_editbox_base.h" #include "nel/gui/interface_options.h" - -CWidgetManager* CWidgetManager::instance = NULL; -std::string CWidgetManager::_CtrlLaunchingModalId= "ctrl_launch_modal"; -IParser* CWidgetManager::parser = NULL; - -// ---------------------------------------------------------------------------- -// SMasterGroup -// ---------------------------------------------------------------------------- - -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::addWindow(CInterfaceGroup *pIG, uint8 nPrio) +namespace NLGUI { - nlassert(nPrioisGroupInScene() ); + CWidgetManager* CWidgetManager::instance = NULL; + std::string CWidgetManager::_CtrlLaunchingModalId= "ctrl_launch_modal"; + IParser* CWidgetManager::parser = NULL; - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + // ---------------------------------------------------------------------------- + // SMasterGroup + // ---------------------------------------------------------------------------- + + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::addWindow(CInterfaceGroup *pIG, uint8 nPrio) { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) - { - // If the element already exists in the list return ! - if (*it == pIG) - return; - it++; - } - } - PrioritizedWindows[nPrio].push_back(pIG); -} + nlassert(nPrio::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) + // Priority WIN_PRIORITY_WORLD_SPACE is only for CGroupInScene ! + // Add this group in another priority list + nlassert ((nPrio!=WIN_PRIORITY_MAX) || pIG->isGroupInScene() ); + + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) { - if ((*it) == pIG) + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) { - PrioritizedWindows[i].erase(it); - return; + // If the element already exists in the list return ! + if (*it == pIG) + return; + it++; } - it++; } + PrioritizedWindows[nPrio].push_back(pIG); } -} -// ---------------------------------------------------------------------------- -CInterfaceGroup* CWidgetManager::SMasterGroup::getWindowFromId(const std::string &winID) -{ - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::delWindow(CInterfaceGroup *pIG) { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) { - if ((*it)->getId() == winID) - return *it; - it++; - } - } - return NULL; -} - -// ---------------------------------------------------------------------------- -bool CWidgetManager::SMasterGroup::isWindowPresent(CInterfaceGroup *pIG) -{ - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) - { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) - { - if ((*it) == pIG) - return true; - it++; - } - } - return false; -} - -// Set a window top in its priority queue -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::setTopWindow(CInterfaceGroup *pIG) -{ - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) - { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) - { - if (*it == pIG) + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) { - PrioritizedWindows[i].erase(it); - PrioritizedWindows[i].push_back(pIG); - LastTopWindowPriority= i; - return; + if ((*it) == pIG) + { + PrioritizedWindows[i].erase(it); + return; + } + it++; } - it++; } } - // todo hulud interface syntax error - nlwarning("window %s do not exist in a priority list", pIG->getId().c_str()); -} -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::setBackWindow(CInterfaceGroup *pIG) -{ - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + // ---------------------------------------------------------------------------- + CInterfaceGroup* CWidgetManager::SMasterGroup::getWindowFromId(const std::string &winID) { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) { - if (*it == pIG) + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) { - PrioritizedWindows[i].erase(it); - PrioritizedWindows[i].push_front(pIG); - return; + if ((*it)->getId() == winID) + return *it; + it++; } - it++; } + return NULL; } - // todo hulud interface syntax error - nlwarning("window %s do not exist in a priority list", pIG->getId().c_str()); -} -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::deactiveAllContainers() -{ - std::vector gcs; - - // Make first a list of all window (Warning: all group container are not window!) - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + // ---------------------------------------------------------------------------- + bool CWidgetManager::SMasterGroup::isWindowPresent(CInterfaceGroup *pIG) { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) { - CGroupContainerBase *pGC = dynamic_cast(*it); - if (pGC != NULL) - gcs.push_back(pGC); - it++; - } - } - - // Then hide them. Must do this in 2 times, because setActive(false) change PrioritizedWindows, - // and hence invalidate its. - for (uint32 i = 0; i < gcs.size(); ++i) - { - gcs[i]->setActive(false); - } -} - -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::centerAllContainers() -{ - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) - { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) - { - CGroupContainerBase *pGC = dynamic_cast(*it); - if ((pGC != NULL) && (pGC->getParent() != NULL)) + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) { - sint32 wParent = pGC->getParent()->getW(false); - sint32 w = pGC->getW(false); - pGC->setXAndInvalidateCoords((wParent - w) / 2); - sint32 hParent = pGC->getParent()->getH(false); - sint32 h = pGC->getH(false); - pGC->setYAndInvalidateCoords(h+(hParent - h) / 2); + if ((*it) == pIG) + return true; + it++; } - - it++; } + return false; } -} -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::unlockAllContainers() -{ - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + // Set a window top in its priority queue + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::setTopWindow(CInterfaceGroup *pIG) { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) { - CGroupContainerBase *pGC = dynamic_cast(*it); - if (pGC != NULL) - pGC->setLocked(false); + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) + { + if (*it == pIG) + { + PrioritizedWindows[i].erase(it); + PrioritizedWindows[i].push_back(pIG); + LastTopWindowPriority= i; + return; + } + it++; + } + } + // todo hulud interface syntax error + nlwarning("window %s do not exist in a priority list", pIG->getId().c_str()); + } + + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::setBackWindow(CInterfaceGroup *pIG) + { + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + { + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) + { + if (*it == pIG) + { + PrioritizedWindows[i].erase(it); + PrioritizedWindows[i].push_front(pIG); + return; + } + it++; + } + } + // todo hulud interface syntax error + nlwarning("window %s do not exist in a priority list", pIG->getId().c_str()); + } + + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::deactiveAllContainers() + { + std::vector gcs; + + // Make first a list of all window (Warning: all group container are not window!) + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + { + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) + { + CGroupContainerBase *pGC = dynamic_cast(*it); + if (pGC != NULL) + gcs.push_back(pGC); + it++; + } + } + + // Then hide them. Must do this in 2 times, because setActive(false) change PrioritizedWindows, + // and hence invalidate its. + for (uint32 i = 0; i < gcs.size(); ++i) + { + gcs[i]->setActive(false); + } + } + + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::centerAllContainers() + { + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + { + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) + { + CGroupContainerBase *pGC = dynamic_cast(*it); + if ((pGC != NULL) && (pGC->getParent() != NULL)) + { + sint32 wParent = pGC->getParent()->getW(false); + sint32 w = pGC->getW(false); + pGC->setXAndInvalidateCoords((wParent - w) / 2); + sint32 hParent = pGC->getParent()->getH(false); + sint32 h = pGC->getH(false); + pGC->setYAndInvalidateCoords(h+(hParent - h) / 2); + } + + it++; + } + } + } + + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::unlockAllContainers() + { + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + { + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) + { + CGroupContainerBase *pGC = dynamic_cast(*it); + if (pGC != NULL) + pGC->setLocked(false); + + it++; + } + } + } + + class CElementToSort + { + public: + CInterfaceGroup *pIG; + float Distance; + bool operator< (const CElementToSort& other) const + { + // We want first farest views + return Distance > other.Distance; + } + }; + + void CWidgetManager::SMasterGroup::sortWorldSpaceGroup () + { + static std::vector sortTable; + sortTable.clear (); + + // Fill the sort table + std::list::iterator it = PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].begin(); + while (it != PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].end()) + { + sortTable.push_back (CElementToSort ()); + CElementToSort &elm = sortTable.back(); + elm.pIG = *it; + elm.Distance = (*it)->getDepthForZSort(); it++; } - } -} -class CElementToSort -{ -public: - CInterfaceGroup *pIG; - float Distance; - bool operator< (const CElementToSort& other) const - { - // We want first farest views - return Distance > other.Distance; - } -}; + // Sort the table + std::sort (sortTable.begin(), sortTable.end()); -void CWidgetManager::SMasterGroup::sortWorldSpaceGroup () -{ - static std::vector sortTable; - sortTable.clear (); + // Fill the final table + uint i = 0; + it = PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].begin(); + while (it != PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].end()) + { + *it = sortTable[i].pIG; - // Fill the sort table - std::list::iterator it = PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].begin(); - while (it != PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].end()) - { - sortTable.push_back (CElementToSort ()); - CElementToSort &elm = sortTable.back(); - elm.pIG = *it; - elm.Distance = (*it)->getDepthForZSort(); - - it++; + it++; + i++; + } } - // Sort the table - std::sort (sortTable.begin(), sortTable.end()); - // Fill the final table - uint i = 0; - it = PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].begin(); - while (it != PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].end()) + CWidgetManager* CWidgetManager::getInstance() { - *it = sortTable[i].pIG; + if( instance == NULL ) + instance = new CWidgetManager; - it++; - i++; + return instance; } -} - -CWidgetManager* CWidgetManager::getInstance() -{ - if( instance == NULL ) - instance = new CWidgetManager; - - return instance; -} - -void CWidgetManager::release() -{ - delete instance; - instance = NULL; -} - -// ---------------------------------------------------------------------------- -CInterfaceGroup* CWidgetManager::getMasterGroupFromId (const std::string &MasterGroupName) -{ - for (uint32 i = 0; i < _MasterGroups.size(); ++i) + void CWidgetManager::release() { - if (_MasterGroups[i].Group->getId() == MasterGroupName) - return _MasterGroups[i].Group; + delete instance; + instance = NULL; } - return NULL; -} -// ---------------------------------------------------------------------------- -CInterfaceGroup* CWidgetManager::getWindowFromId (const std::string & groupId) -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ---------------------------------------------------------------------------- + CInterfaceGroup* CWidgetManager::getMasterGroupFromId (const std::string &MasterGroupName) { - SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - CInterfaceGroup *pIG = rMG.getWindowFromId(groupId); + for (uint32 i = 0; i < _MasterGroups.size(); ++i) + { + if (_MasterGroups[i].Group->getId() == MasterGroupName) + return _MasterGroups[i].Group; + } + return NULL; + } + + // ---------------------------------------------------------------------------- + CInterfaceGroup* CWidgetManager::getWindowFromId (const std::string & groupId) + { + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + CInterfaceGroup *pIG = rMG.getWindowFromId(groupId); + if (pIG != NULL) + return pIG; + } + return NULL; + } + + // ---------------------------------------------------------------------------- + void CWidgetManager::addWindowToMasterGroup (const std::string &sMasterGroupName, CInterfaceGroup *pIG) + { + // Warning this function is not smart : its a o(n) ! + if (pIG == NULL) return; + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); ++nMasterGroup) + { + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getId() == sMasterGroupName) + { + rMG.addWindow(pIG, pIG->getPriority()); + } + } + } + + // ---------------------------------------------------------------------------- + void CWidgetManager::removeWindowFromMasterGroup(const std::string &sMasterGroupName,CInterfaceGroup *pIG) + { + // Warning this function is not smart : its a o(n) ! + if (pIG == NULL) return; + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); ++nMasterGroup) + { + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getId() == sMasterGroupName) + { + rMG.delWindow(pIG); + } + } + } + + void unlinkAllContainers (CInterfaceGroup *pIG) + { + const std::vector &rG = pIG->getGroups(); + for(uint i = 0; i < rG.size(); ++i) + unlinkAllContainers (rG[i]); + + CGroupContainerBase *pGC = dynamic_cast(pIG); + if (pGC != NULL) + pGC->removeAllContainers(); + } + + // *************************************************************************** + void CWidgetManager::removeAllMasterGroups() + { + uint i; + + for (i = 0; i < _MasterGroups.size(); ++i) + unlinkAllContainers (_MasterGroups[i].Group); + + // Yoyo: important to not Leave NULL in the array, because of CGroupHTML and LibWWW callback + // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) + while(!_MasterGroups.empty()) + { + delete _MasterGroups.back().Group; + _MasterGroups.pop_back(); + } + + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::activateMasterGroup (const std::string &sMasterGroupName, bool bActive) + { + CInterfaceGroup *pIG = CWidgetManager::getInstance()->getMasterGroupFromId (sMasterGroupName); if (pIG != NULL) - return pIG; - } - return NULL; -} - -// ---------------------------------------------------------------------------- -void CWidgetManager::addWindowToMasterGroup (const std::string &sMasterGroupName, CInterfaceGroup *pIG) -{ - // Warning this function is not smart : its a o(n) ! - if (pIG == NULL) return; - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); ++nMasterGroup) - { - SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getId() == sMasterGroupName) { - rMG.addWindow(pIG, pIG->getPriority()); + pIG->setActive(bActive); + pIG->invalidateCoords(); } } -} -// ---------------------------------------------------------------------------- -void CWidgetManager::removeWindowFromMasterGroup(const std::string &sMasterGroupName,CInterfaceGroup *pIG) -{ - // Warning this function is not smart : its a o(n) ! - if (pIG == NULL) return; - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); ++nMasterGroup) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getWindow(CInterfaceElement *pIE) { - SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getId() == sMasterGroupName) + CInterfaceGroup *pIG = pIE->getParent(); + if (pIG == NULL) return NULL; + if (pIG->getParent() == NULL) return NULL; + while (pIG->getParent()->getParent() != NULL) { - rMG.delWindow(pIG); + pIG = pIG->getParent(); } - } -} - -void unlinkAllContainers (CInterfaceGroup *pIG) -{ - const std::vector &rG = pIG->getGroups(); - for(uint i = 0; i < rG.size(); ++i) - unlinkAllContainers (rG[i]); - - CGroupContainerBase *pGC = dynamic_cast(pIG); - if (pGC != NULL) - pGC->removeAllContainers(); -} - -// *************************************************************************** -void CWidgetManager::removeAllMasterGroups() -{ - uint i; - - for (i = 0; i < _MasterGroups.size(); ++i) - unlinkAllContainers (_MasterGroups[i].Group); - - // Yoyo: important to not Leave NULL in the array, because of CGroupHTML and LibWWW callback - // that may call CInterfaceManager::getElementFromId() (and this method hates having NULL in the arrays ^^) - while(!_MasterGroups.empty()) - { - delete _MasterGroups.back().Group; - _MasterGroups.pop_back(); + return pIG; } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::activateMasterGroup (const std::string &sMasterGroupName, bool bActive) -{ - CInterfaceGroup *pIG = CWidgetManager::getInstance()->getMasterGroupFromId (sMasterGroupName); - if (pIG != NULL) + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CWidgetManager::getElementFromId (const std::string &sEltId) { - pIG->setActive(bActive); - pIG->invalidateCoords(); - } -} + // System special + if(sEltId == _CtrlLaunchingModalId) + return getCtrlLaunchingModal(); -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CWidgetManager::getWindow(CInterfaceElement *pIE) -{ - CInterfaceGroup *pIG = pIE->getParent(); - if (pIG == NULL) return NULL; - if (pIG->getParent() == NULL) return NULL; - while (pIG->getParent()->getParent() != NULL) - { - pIG = pIG->getParent(); - } - return pIG; -} - - -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CWidgetManager::getElementFromId (const std::string &sEltId) -{ - // System special - if(sEltId == _CtrlLaunchingModalId) - return getCtrlLaunchingModal(); - - // Search for all elements - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - CInterfaceElement *pIEL = rMG.Group->getElement (sEltId); - if (pIEL != NULL) - return pIEL; - } - return NULL; -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CWidgetManager::getElementFromId (const std::string &sStart, const std::string &sEltId) -{ - CInterfaceElement *pIEL = getElementFromId (sEltId); - if (pIEL == NULL) - { - std::string sZeStart = sStart, sTmp; - if (sZeStart[sZeStart.size()-1] == ':') - sZeStart = sZeStart.substr(0, sZeStart.size()-1); - - while (sZeStart != "") + // Search for all elements + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - if (sEltId[0] == ':') - sTmp = sZeStart + sEltId; - else - sTmp = sZeStart + ":" + sEltId; - pIEL = getElementFromId (sTmp); + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + CInterfaceElement *pIEL = rMG.Group->getElement (sEltId); if (pIEL != NULL) return pIEL; - std::string::size_type nextPos = sZeStart.rfind(':'); - if (nextPos == std::string::npos) break; - sZeStart = sZeStart.substr(0, nextPos); } + return NULL; } - return pIEL; -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::setTopWindow (CInterfaceGroup* win) -{ - //find the window in the window list - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CWidgetManager::getElementFromId (const std::string &sStart, const std::string &sEltId) { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - rMG.setTopWindow(win); - } -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::setBackWindow(CInterfaceGroup* win) -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - rMG.setBackWindow(win); - } -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CWidgetManager::getTopWindow (uint8 nPriority) const -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + CInterfaceElement *pIEL = getElementFromId (sEltId); + if (pIEL == NULL) { - // return the first. - if(rMG.PrioritizedWindows[nPriority].empty()) - return NULL; - else - return rMG.PrioritizedWindows[nPriority].back(); - } - } - return NULL; -} + std::string sZeStart = sStart, sTmp; + if (sZeStart[sZeStart.size()-1] == ':') + sZeStart = sZeStart.substr(0, sZeStart.size()-1); - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CWidgetManager::getBackWindow (uint8 nPriority) const -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - // return the first. - if(rMG.PrioritizedWindows[nPriority].empty()) - return NULL; - else - return rMG.PrioritizedWindows[nPriority].front(); - } - } - return NULL; -} - -// *************************************************************************** -CInterfaceGroup* CWidgetManager::getLastEscapableTopWindow() const -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + while (sZeStart != "") { - const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; - std::list::const_reverse_iterator it; - it= rList.rbegin(); - for(;it!=rList.rend();it++) + if (sEltId[0] == ':') + sTmp = sZeStart + sEltId; + else + sTmp = sZeStart + ":" + sEltId; + pIEL = getElementFromId (sTmp); + if (pIEL != NULL) + return pIEL; + std::string::size_type nextPos = sZeStart.rfind(':'); + if (nextPos == std::string::npos) break; + sZeStart = sZeStart.substr(0, nextPos); + } + } + return pIEL; + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setTopWindow (CInterfaceGroup* win) + { + //find the window in the window list + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + rMG.setTopWindow(win); + } + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setBackWindow(CInterfaceGroup* win) + { + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + rMG.setBackWindow(win); + } + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getTopWindow (uint8 nPriority) const + { + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + // return the first. + if(rMG.PrioritizedWindows[nPriority].empty()) + return NULL; + else + return rMG.PrioritizedWindows[nPriority].back(); + } + } + return NULL; + } + + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getBackWindow (uint8 nPriority) const + { + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + // return the first. + if(rMG.PrioritizedWindows[nPriority].empty()) + return NULL; + else + return rMG.PrioritizedWindows[nPriority].front(); + } + } + return NULL; + } + + // *************************************************************************** + CInterfaceGroup* CWidgetManager::getLastEscapableTopWindow() const + { + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) { - if((*it)->getActive() && (*it)->getEscapable()) - return *it; + const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; + std::list::const_reverse_iterator it; + it= rList.rbegin(); + for(;it!=rList.rend();it++) + { + if((*it)->getActive() && (*it)->getEscapable()) + return *it; + } + } + } + } + return NULL; + } + + // *************************************************************************** + void CWidgetManager::setWindowPriority (CInterfaceGroup *pWin, uint8 nNewPriority) + { + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + if (rMG.isWindowPresent(pWin)) + { + rMG.delWindow(pWin); + rMG.addWindow(pWin, nNewPriority); } } } } - return NULL; -} -// *************************************************************************** -void CWidgetManager::setWindowPriority (CInterfaceGroup *pWin, uint8 nNewPriority) -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // *************************************************************************** + uint8 CWidgetManager::getLastTopWindowPriority() const { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - if (rMG.isWindowPresent(pWin)) + const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) { - rMG.delWindow(pWin); - rMG.addWindow(pWin, nNewPriority); + return rMG.LastTopWindowPriority; } } + return 0; } -} -// *************************************************************************** -uint8 CWidgetManager::getLastTopWindowPriority() const -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + bool CWidgetManager::hasModal() const { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - return rMG.LastTopWindowPriority; - } - } - return 0; -} - -bool CWidgetManager::hasModal() const -{ - if( !_ModalStack.empty() ) - return true; - else - return false; -} - -CWidgetManager::SModalWndInfo& CWidgetManager::getModal() -{ - return _ModalStack.back(); -} - -bool CWidgetManager::isPreviousModal( CInterfaceGroup *wnd ) const -{ - std::vector< SModalWndInfo >::size_type s = _ModalStack.size(); - for( std::vector< SModalWndInfo >::size_type i = 0; i < s; i++ ) - if( _ModalStack[ i ].ModalWindow == wnd ) + if( !_ModalStack.empty() ) return true; - - return false; -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::enableModalWindow (CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG) -{ - // disable any modal before. release keyboard - disableModalWindow(); - pushModalWindow(ctrlLaunchingModal, pIG); -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::enableModalWindow (CCtrlBase *CtrlLaunchingModal, const std::string &groupName) -{ - CInterfaceGroup *group= dynamic_cast( getElementFromId(groupName) ); - if(group) - { - // enable the modal - enableModalWindow(CtrlLaunchingModal, group); + else + return false; } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::disableModalWindow () -{ - while (!_ModalStack.empty()) + CWidgetManager::SModalWndInfo& CWidgetManager::getModal() { - SModalWndInfo winInfo = _ModalStack.back(); - _ModalStack.pop_back(); // must pop back as early as possible because 'setActive' may trigger another 'popModalWindow', leading to a crash - // disable old modal window - if(winInfo.ModalWindow) + return _ModalStack.back(); + } + + bool CWidgetManager::isPreviousModal( CInterfaceGroup *wnd ) const + { + std::vector< SModalWndInfo >::size_type s = _ModalStack.size(); + for( std::vector< SModalWndInfo >::size_type i = 0; i < s; i++ ) + if( _ModalStack[ i ].ModalWindow == wnd ) + return true; + + return false; + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::enableModalWindow (CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG) + { + // disable any modal before. release keyboard + disableModalWindow(); + pushModalWindow(ctrlLaunchingModal, pIG); + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::enableModalWindow (CCtrlBase *CtrlLaunchingModal, const std::string &groupName) + { + CInterfaceGroup *group= dynamic_cast( getElementFromId(groupName) ); + if(group) { - setBackWindow(winInfo.ModalWindow); - winInfo.ModalWindow->setActive(false); + // enable the modal + enableModalWindow(CtrlLaunchingModal, group); } } - // disable any context help - setCurContextHelp( NULL ); - CWidgetManager::getInstance()->_DeltaTimeStopingContextHelp = 0; -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::pushModalWindow(CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG) -{ - // enable the wanted modal - if(pIG) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::disableModalWindow () { - SModalWndInfo mwi; - mwi.ModalWindow = pIG; - mwi.CtrlLaunchingModal = ctrlLaunchingModal; - // setup special group - CGroupModal *groupModal= dynamic_cast(pIG); - if(groupModal) + while (!_ModalStack.empty()) { - mwi.ModalExitClickOut = groupModal->ExitClickOut; - mwi.ModalExitClickL = groupModal->ExitClickL; - mwi.ModalExitClickR = groupModal->ExitClickR; - mwi.ModalHandlerClickOut = groupModal->OnClickOut; - mwi.ModalClickOutParams = groupModal->OnClickOutParams; - mwi.ModalExitKeyPushed = groupModal->ExitKeyPushed; - // update coords of the modal - if(groupModal->SpawnOnMousePos) + SModalWndInfo winInfo = _ModalStack.back(); + _ModalStack.pop_back(); // must pop back as early as possible because 'setActive' may trigger another 'popModalWindow', leading to a crash + // disable old modal window + if(winInfo.ModalWindow) { - groupModal->SpawnMouseX = _Pointer->getX(); - groupModal->SpawnMouseY = _Pointer->getY(); + setBackWindow(winInfo.ModalWindow); + winInfo.ModalWindow->setActive(false); } } - else - { - // default for group not modal. Backward compatibility - mwi.ModalExitClickOut = false; - mwi.ModalExitClickL = false; - mwi.ModalExitClickR = false; - mwi.ModalExitKeyPushed = false; - } - _ModalStack.push_back(mwi); - - // update coords and activate the modal - mwi.ModalWindow->invalidateCoords(); - mwi.ModalWindow->setActive(true); - setTopWindow(mwi.ModalWindow); + // disable any context help + setCurContextHelp( NULL ); + CWidgetManager::getInstance()->_DeltaTimeStopingContextHelp = 0; } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::pushModalWindow(CCtrlBase *ctrlLaunchingModal, const std::string &groupName) -{ - CInterfaceGroup *group= dynamic_cast( getElementFromId(groupName) ); - if(group) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::pushModalWindow(CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG) { - // enable the modal - enableModalWindow(ctrlLaunchingModal, group); - } -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::popModalWindow() -{ - if (!_ModalStack.empty()) - { - SModalWndInfo winInfo = _ModalStack.back(); - _ModalStack.pop_back(); // must pop back as early as possible because 'setActive' may trigger another 'popModalWindow', leading to a crash - if(winInfo.ModalWindow) + // enable the wanted modal + if(pIG) { - setBackWindow(winInfo.ModalWindow); - winInfo.ModalWindow->setActive(false); + SModalWndInfo mwi; + mwi.ModalWindow = pIG; + mwi.CtrlLaunchingModal = ctrlLaunchingModal; + // setup special group + CGroupModal *groupModal= dynamic_cast(pIG); + if(groupModal) + { + mwi.ModalExitClickOut = groupModal->ExitClickOut; + mwi.ModalExitClickL = groupModal->ExitClickL; + mwi.ModalExitClickR = groupModal->ExitClickR; + mwi.ModalHandlerClickOut = groupModal->OnClickOut; + mwi.ModalClickOutParams = groupModal->OnClickOutParams; + mwi.ModalExitKeyPushed = groupModal->ExitKeyPushed; + // update coords of the modal + if(groupModal->SpawnOnMousePos) + { + groupModal->SpawnMouseX = _Pointer->getX(); + groupModal->SpawnMouseY = _Pointer->getY(); + } + } + else + { + // default for group not modal. Backward compatibility + mwi.ModalExitClickOut = false; + mwi.ModalExitClickL = false; + mwi.ModalExitClickR = false; + mwi.ModalExitKeyPushed = false; + } + + _ModalStack.push_back(mwi); + + // update coords and activate the modal + mwi.ModalWindow->invalidateCoords(); + mwi.ModalWindow->setActive(true); + setTopWindow(mwi.ModalWindow); } + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::pushModalWindow(CCtrlBase *ctrlLaunchingModal, const std::string &groupName) + { + CInterfaceGroup *group= dynamic_cast( getElementFromId(groupName) ); + if(group) + { + // enable the modal + enableModalWindow(ctrlLaunchingModal, group); + } + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::popModalWindow() + { if (!_ModalStack.empty()) { - if(_ModalStack.back().ModalWindow) + SModalWndInfo winInfo = _ModalStack.back(); + _ModalStack.pop_back(); // must pop back as early as possible because 'setActive' may trigger another 'popModalWindow', leading to a crash + if(winInfo.ModalWindow) { - _ModalStack.back().ModalWindow->setActive(true); - setTopWindow(_ModalStack.back().ModalWindow); + setBackWindow(winInfo.ModalWindow); + winInfo.ModalWindow->setActive(false); } - } - } -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::popModalWindowCategory(const std::string &category) -{ - for(;;) - { - if (_ModalStack.empty()) break; - if (!_ModalStack.back().ModalWindow) break; - CGroupModal *gm = dynamic_cast((CInterfaceGroup*)(_ModalStack.back().ModalWindow)); - if (gm && gm->Category == category) - { - _ModalStack.back().ModalWindow->setActive(false); - _ModalStack.pop_back(); - } - else - { - break; - } - } -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CWidgetManager::getWindowUnder (sint32 x, sint32 y) -{ - H_AUTO (RZ_Interface_Window_Under ) - - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + if (!_ModalStack.empty()) { - const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; - std::list::const_reverse_iterator itw; - for (itw = rList.rbegin(); itw != rList.rend(); itw++) + if(_ModalStack.back().ModalWindow) { - CInterfaceGroup *pIG = *itw; - if (pIG->getActive() && pIG->getUseCursor()) - { - if (pIG->isWindowUnder (x, y)) - return pIG; - } + _ModalStack.back().ModalWindow->setActive(true); + setTopWindow(_ModalStack.back().ModalWindow); } } } } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CWidgetManager::getGroupUnder (sint32 x, sint32 y) -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::popModalWindowCategory(const std::string &category) { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + for(;;) { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + if (_ModalStack.empty()) break; + if (!_ModalStack.back().ModalWindow) break; + CGroupModal *gm = dynamic_cast((CInterfaceGroup*)(_ModalStack.back().ModalWindow)); + if (gm && gm->Category == category) { - const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; - std::list::const_reverse_iterator itw; - for (itw = rList.rbegin(); itw != rList.rend(); itw++) - { - CInterfaceGroup *pIG = *itw; - if (pIG->getActive() && pIG->getUseCursor()) - { - CInterfaceGroup *pIGunder = pIG->getGroupUnder (x ,y); - if (pIGunder != NULL) - return pIGunder; - } - } + _ModalStack.back().ModalWindow->setActive(false); + _ModalStack.pop_back(); + } + else + { + break; } } } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::getViewsUnder (sint32 x, sint32 y, std::vector &vVB) -{ - vVB.clear (); - - // No Op if screen minimized - if(CViewRenderer::getInstance()->isMinimized()) - return; - - uint32 sw, sh; - CViewRenderer::getInstance()->getScreenSize(sw, sh); - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getWindowUnder (sint32 x, sint32 y) { - SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + H_AUTO (RZ_Interface_Window_Under ) + + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) { - const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; - std::list::const_reverse_iterator itw; - for (itw = rList.rbegin(); itw != rList.rend(); itw++) + for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) { - CInterfaceGroup *pIG = *itw; - - // Accecpt if not modal clip - if (pIG->getActive() && pIG->getUseCursor()) + const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; + std::list::const_reverse_iterator itw; + for (itw = rList.rbegin(); itw != rList.rend(); itw++) { - if (pIG->getViewsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vVB)) - return ; - } - } - } - } - } -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::getCtrlsUnder (sint32 x, sint32 y, std::vector &vICL) -{ - vICL.clear (); - - // No Op if screen minimized - if(CViewRenderer::getInstance()->isMinimized()) - return; - - uint32 sw, sh; - CViewRenderer::getInstance()->getScreenSize(sw, sh); - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0 ; nPriority--) - { - const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; - std::list::const_reverse_iterator itw; - for (itw = rList.rbegin(); itw != rList.rend(); itw++) - { - CInterfaceGroup *pIG = *itw; - - // Accecpt if not modal clip - if (!CWidgetManager::getInstance()->hasModal() || CWidgetManager::getInstance()->getModal().ModalWindow == pIG || CWidgetManager::getInstance()->getModal().ModalExitClickOut) - if (pIG->getActive() && pIG->getUseCursor()) - { - if (pIG->getCtrlsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vICL)) - return; - } - } - } - } - } -} - - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::getGroupsUnder (sint32 x, sint32 y, std::vector &vIGL) -{ - vIGL.clear (); - - // No Op if screen minimized - if(CViewRenderer::getInstance()->isMinimized()) - return; - - uint32 sw, sh; - CViewRenderer::getInstance()->getScreenSize(sw, sh); - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) - { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0 ; nPriority--) - { - const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; - std::list::const_reverse_iterator itw; - for (itw = rList.rbegin(); itw != rList.rend(); itw++) - { - CInterfaceGroup *pIG = *itw; - - // Accecpt if not modal clip - if (!CWidgetManager::getInstance()->hasModal() || CWidgetManager::getInstance()->getModal().ModalWindow == pIG || - CWidgetManager::getInstance()->getModal().ModalExitClickOut) - if (pIG->getActive() && pIG->getUseCursor()) - { - if (pIG->isIn(x, y)) + CInterfaceGroup *pIG = *itw; + if (pIG->getActive() && pIG->getUseCursor()) { - vIGL.push_back(pIG); - pIG->getGroupsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vIGL); - return; + if (pIG->isWindowUnder (x, y)) + return pIG; + } + } + } + } + } + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getGroupUnder (sint32 x, sint32 y) + { + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + { + const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; + std::list::const_reverse_iterator itw; + for (itw = rList.rbegin(); itw != rList.rend(); itw++) + { + CInterfaceGroup *pIG = *itw; + if (pIG->getActive() && pIG->getUseCursor()) + { + CInterfaceGroup *pIGunder = pIG->getGroupUnder (x ,y); + if (pIGunder != NULL) + return pIGunder; + } + } + } + } + } + return NULL; + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::getViewsUnder (sint32 x, sint32 y, std::vector &vVB) + { + vVB.clear (); + + // No Op if screen minimized + if(CViewRenderer::getInstance()->isMinimized()) + return; + + uint32 sw, sh; + CViewRenderer::getInstance()->getScreenSize(sw, sh); + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + { + const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; + std::list::const_reverse_iterator itw; + for (itw = rList.rbegin(); itw != rList.rend(); itw++) + { + CInterfaceGroup *pIG = *itw; + + // Accecpt if not modal clip + if (pIG->getActive() && pIG->getUseCursor()) + { + if (pIG->getViewsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vVB)) + return ; } } } } } } -} - -// *************************************************************************** -void CWidgetManager::removeRefOnView( CViewBase *viewBase ) -{ - uint i; - for (i=0; i<_ViewsUnderPointer.size(); i++) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::getCtrlsUnder (sint32 x, sint32 y, std::vector &vICL) { - if (_ViewsUnderPointer[i] == viewBase) - { - _ViewsUnderPointer.erase (_ViewsUnderPointer.begin()+i); - i--; - } - } -} + vICL.clear (); -// *************************************************************************** -void CWidgetManager::removeRefOnCtrl(CCtrlBase *ctrlBase) -{ - if ( getCurContextHelp() == ctrlBase) - setCurContextHelp( NULL ); - if (getCapturePointerLeft() == ctrlBase) - setCapturePointerLeft(NULL); - if (getCapturePointerRight() == ctrlBase) - setCapturePointerRight (NULL); - if (getCaptureKeyboard() == ctrlBase) - setCaptureKeyboard(NULL); - if (getOldCaptureKeyboard() == ctrlBase) - setOldCaptureKeyboard(NULL); - if (getDefaultCaptureKeyboard() == ctrlBase) - setDefaultCaptureKeyboard(NULL); - uint i; - for (i=0; i<_CtrlsUnderPointer.size(); i++) - { - if (_CtrlsUnderPointer[i] == ctrlBase) - { - _CtrlsUnderPointer.erase (_CtrlsUnderPointer.begin()+i); - i--; - } - } + // No Op if screen minimized + if(CViewRenderer::getInstance()->isMinimized()) + return; - // Unregister from ClockMsgTargets - unregisterClockMsgTarget(ctrlBase); -} - - -// *************************************************************************** -void CWidgetManager::removeRefOnGroup (CInterfaceGroup *group) -{ - uint i; - for (i=0; i<_GroupsUnderPointer.size(); i++) - { - if (_GroupsUnderPointer[i] == group) - { - _GroupsUnderPointer.erase (_GroupsUnderPointer.begin()+i); - i--; - } - } -} - - -void CWidgetManager::reset() -{ - setCurContextHelp( NULL ); - - _ViewsUnderPointer.clear(); - _CtrlsUnderPointer.clear(); - _GroupsUnderPointer.clear(); - - _CaptureKeyboard = NULL; - _OldCaptureKeyboard = NULL; - setCapturePointerLeft(NULL); - setCapturePointerRight(NULL); - - resetColorProps(); -} - - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::checkCoords() -{ - H_AUTO ( RZ_Interface_validateCoords ) - - uint32 nMasterGroup; - - { - H_AUTO ( RZ_Interface_checkCoords ) - - // checkCoords all the windows - for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + uint32 sw, sh; + CViewRenderer::getInstance()->getScreenSize(sw, sh); + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; if (rMG.Group->getActive()) { - for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0 ; nPriority--) { - std::list &rList = rMG.PrioritizedWindows[nPriority]; - std::list::const_iterator itw; - for (itw = rList.begin(); itw!= rList.end();) + const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; + std::list::const_reverse_iterator itw; + for (itw = rList.rbegin(); itw != rList.rend(); itw++) { CInterfaceGroup *pIG = *itw; - itw++; // since checkCoords invalidate the iterator, be sure we move to the next one before - if (pIG->getActive()) - pIG->checkCoords (); + + // Accecpt if not modal clip + if (!CWidgetManager::getInstance()->hasModal() || CWidgetManager::getInstance()->getModal().ModalWindow == pIG || CWidgetManager::getInstance()->getModal().ModalExitClickOut) + if (pIG->getActive() && pIG->getUseCursor()) + { + if (pIG->getCtrlsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vICL)) + return; + } } } } } } - bool bRecomputeCtrlUnderPtr = false; - { - H_AUTO ( RZ_Interface_updateCoords ) - // updateCoords all the needed windows - for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::getGroupsUnder (sint32 x, sint32 y, std::vector &vIGL) + { + vIGL.clear (); + + // No Op if screen minimized + if(CViewRenderer::getInstance()->isMinimized()) + return; + + uint32 sw, sh; + CViewRenderer::getInstance()->getScreenSize(sw, sh); + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; if (rMG.Group->getActive()) { - for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0 ; nPriority--) { - std::list &rList = rMG.PrioritizedWindows[nPriority]; - std::list::const_iterator itw; - for (itw = rList.begin(); itw!= rList.end(); itw++) + const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; + std::list::const_reverse_iterator itw; + for (itw = rList.rbegin(); itw != rList.rend(); itw++) { CInterfaceGroup *pIG = *itw; - bool updateCoordCalled= false; - // updateCoords the window only if the master group is his parent and if need it - // do it until updateCoords() no more invalidate coordinates!! - while (pIG->getParent()==rMG.Group && (pIG->getInvalidCoords()>0)) + + // Accecpt if not modal clip + if (!CWidgetManager::getInstance()->hasModal() || CWidgetManager::getInstance()->getModal().ModalWindow == pIG || + CWidgetManager::getInstance()->getModal().ModalExitClickOut) + if (pIG->getActive() && pIG->getUseCursor()) { - bRecomputeCtrlUnderPtr = true; - // Update as many pass wanted (3 time for complex resizing, 1 for scroll for example) - uint numPass= pIG->getInvalidCoords(); - // reset before updateCoords - pIG->resetInvalidCoords(); - for(uint i=0;iisIn(x, y)) { - pIG->updateCoords (); + vIGL.push_back(pIG); + pIG->getGroupsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vIGL); + return; } - updateCoordCalled= true; } - // If the group need to update pos each frame (eg: CGroupInScene), - // and updateCoords not called - if(pIG->getParent()==rMG.Group && !updateCoordCalled && pIG->isNeedFrameUpdatePos()) + } + } + } + } + } + + + // *************************************************************************** + void CWidgetManager::removeRefOnView( CViewBase *viewBase ) + { + uint i; + for (i=0; i<_ViewsUnderPointer.size(); i++) + { + if (_ViewsUnderPointer[i] == viewBase) + { + _ViewsUnderPointer.erase (_ViewsUnderPointer.begin()+i); + i--; + } + } + } + + // *************************************************************************** + void CWidgetManager::removeRefOnCtrl(CCtrlBase *ctrlBase) + { + if ( getCurContextHelp() == ctrlBase) + setCurContextHelp( NULL ); + if (getCapturePointerLeft() == ctrlBase) + setCapturePointerLeft(NULL); + if (getCapturePointerRight() == ctrlBase) + setCapturePointerRight (NULL); + if (getCaptureKeyboard() == ctrlBase) + setCaptureKeyboard(NULL); + if (getOldCaptureKeyboard() == ctrlBase) + setOldCaptureKeyboard(NULL); + if (getDefaultCaptureKeyboard() == ctrlBase) + setDefaultCaptureKeyboard(NULL); + uint i; + for (i=0; i<_CtrlsUnderPointer.size(); i++) + { + if (_CtrlsUnderPointer[i] == ctrlBase) + { + _CtrlsUnderPointer.erase (_CtrlsUnderPointer.begin()+i); + i--; + } + } + + // Unregister from ClockMsgTargets + unregisterClockMsgTarget(ctrlBase); + } + + + // *************************************************************************** + void CWidgetManager::removeRefOnGroup (CInterfaceGroup *group) + { + uint i; + for (i=0; i<_GroupsUnderPointer.size(); i++) + { + if (_GroupsUnderPointer[i] == group) + { + _GroupsUnderPointer.erase (_GroupsUnderPointer.begin()+i); + i--; + } + } + } + + + void CWidgetManager::reset() + { + setCurContextHelp( NULL ); + + _ViewsUnderPointer.clear(); + _CtrlsUnderPointer.clear(); + _GroupsUnderPointer.clear(); + + _CaptureKeyboard = NULL; + _OldCaptureKeyboard = NULL; + setCapturePointerLeft(NULL); + setCapturePointerRight(NULL); + + resetColorProps(); + } + + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::checkCoords() + { + H_AUTO ( RZ_Interface_validateCoords ) + + uint32 nMasterGroup; + + { + H_AUTO ( RZ_Interface_checkCoords ) + + // checkCoords all the windows + for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + { + std::list &rList = rMG.PrioritizedWindows[nPriority]; + std::list::const_iterator itw; + for (itw = rList.begin(); itw!= rList.end();) { - // This Group will compute the delta to apply. - pIG->onFrameUpdateWindowPos(0,0); + CInterfaceGroup *pIG = *itw; + itw++; // since checkCoords invalidate the iterator, be sure we move to the next one before + if (pIG->getActive()) + pIG->checkCoords (); } } } } } - if ( CWidgetManager::getInstance()->getPointer() != NULL) - CWidgetManager::getInstance()->getPointer()->updateCoords(); - } - - - - if (bRecomputeCtrlUnderPtr) - { - H_AUTO ( RZ_Interface_RecomputeCtrlUnderPtr ) - if ( CWidgetManager::getInstance()->getPointer() != NULL ) + bool bRecomputeCtrlUnderPtr = false; { - sint32 mx = _Pointer->getX(); - sint32 my = _Pointer->getY(); - getViewsUnder (mx, my, _ViewsUnderPointer); - getCtrlsUnder (mx, my, _CtrlsUnderPointer); - getGroupsUnder (mx, my, _GroupsUnderPointer); - CInterfaceGroup *ptr = getWindowUnder (mx, my); - _WindowUnder = ptr; - } - } -} + H_AUTO ( RZ_Interface_updateCoords ) -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::movePointer (sint32 dx, sint32 dy) -{ - if (!_Pointer) - return; + // updateCoords all the needed windows + for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + { + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + { + std::list &rList = rMG.PrioritizedWindows[nPriority]; + std::list::const_iterator itw; + for (itw = rList.begin(); itw!= rList.end(); itw++) + { + CInterfaceGroup *pIG = *itw; + bool updateCoordCalled= false; + // updateCoords the window only if the master group is his parent and if need it + // do it until updateCoords() no more invalidate coordinates!! + while (pIG->getParent()==rMG.Group && (pIG->getInvalidCoords()>0)) + { + bRecomputeCtrlUnderPtr = true; + // Update as many pass wanted (3 time for complex resizing, 1 for scroll for example) + uint numPass= pIG->getInvalidCoords(); + // reset before updateCoords + pIG->resetInvalidCoords(); + for(uint i=0;iupdateCoords (); + } + updateCoordCalled= true; + } + // If the group need to update pos each frame (eg: CGroupInScene), + // and updateCoords not called + if(pIG->getParent()==rMG.Group && !updateCoordCalled && pIG->isNeedFrameUpdatePos()) + { + // This Group will compute the delta to apply. + pIG->onFrameUpdateWindowPos(0,0); + } + } + } + } + } - uint32 nScrW, nScrH; - sint32 oldpx, oldpy, newpx, newpy, disppx, disppy, olddisppx, olddisppy; - - CViewRenderer::getInstance()->getScreenSize (nScrW, nScrH); - _Pointer->getPointerPos (oldpx, oldpy); - - olddisppx = oldpx; - olddisppy = oldpy; - - newpx = oldpx + dx; - newpy = oldpy + dy; - - if (newpx < 0) newpx = 0; - if (newpy < 0) newpy = 0; - if (newpx > (sint32)nScrW) newpx = nScrW; - if (newpy > (sint32)nScrH) newpy = nScrH; - dx = newpx - oldpx; - dy = newpy - oldpy; - - disppx = newpx; - disppy = newpy; - - _Pointer->setPointerPos (newpx, newpy); - _Pointer->setPointerDispPos (disppx, disppy); - - // must get back coordinates because of snapping - sint32 mx = _Pointer->getX(); - sint32 my = _Pointer->getY(); - getViewsUnder (mx, my, _ViewsUnderPointer); - getCtrlsUnder (mx, my, _CtrlsUnderPointer); - getGroupsUnder (mx, my, _GroupsUnderPointer); -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::movePointerAbs(sint32 px, sint32 py) -{ - if(!CWidgetManager::getInstance()->getPointer()) - return; - - uint32 nScrW, nScrH; - CViewRenderer::getInstance()->getScreenSize (nScrW, nScrH); - NLMISC::clamp(px, 0, (sint32) nScrW); - NLMISC::clamp(py, 0, (sint32) nScrH); - // - _Pointer->setPointerPos (px, py); - _Pointer->setPointerDispPos (px, py); - // - getViewsUnder (px, py, _ViewsUnderPointer); - getCtrlsUnder (px, py, _CtrlsUnderPointer); - getGroupsUnder (px, py, _GroupsUnderPointer); -} - -// *************************************************************************** -void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) -{ - // additionally, abort any dragging - if( CCtrlDraggable::getDraggedSheet() != NULL ) - CCtrlDraggable::getDraggedSheet()->abortDragging(); - - _CapturePointerLeft = c; - notifyElementCaptured(c); -} - -// *************************************************************************** -void CWidgetManager::setCapturePointerRight(CCtrlBase *c) -{ - _CapturePointerRight = c; - notifyElementCaptured(c); -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::setCaptureKeyboard(CCtrlBase *c) -{ - CGroupEditBoxBase *oldEb= dynamic_cast((CCtrlBase*)_CaptureKeyboard); - CGroupEditBoxBase *newEb= dynamic_cast(c); - - if (_CaptureKeyboard && _CaptureKeyboard != c) - { - _CaptureKeyboard->onKeyboardCaptureLost(); - } - // If the old capturedKeyboard is an editBox and allow recoverFocusOnEnter - if ( oldEb && oldEb->getRecoverFocusOnEnter() ) - { - _OldCaptureKeyboard = _CaptureKeyboard; - } - if ( newEb ) - { - CGroupEditBoxBase::disableSelection(); - - if (!newEb->getAHOnFocus().empty()) - { - CAHManager::getInstance()->runActionHandler(newEb->getAHOnFocus(), newEb, newEb->getAHOnFocusParams()); + if ( CWidgetManager::getInstance()->getPointer() != NULL) + CWidgetManager::getInstance()->getPointer()->updateCoords(); } - } - _CaptureKeyboard = c; - notifyElementCaptured(c); -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::resetCaptureKeyboard() -{ - CCtrlBase *captureKeyboard = _CaptureKeyboard; - _OldCaptureKeyboard = NULL; - _CaptureKeyboard = NULL; - if (captureKeyboard) - { - captureKeyboard->onKeyboardCaptureLost(); - } -} -// *************************************************************************** -void CWidgetManager::registerClockMsgTarget(CCtrlBase *vb) -{ - if (!vb) return; - if (isClockMsgTarget(vb)) - { - nlwarning(" Element %s is already registered", vb->getId().c_str()); - return; - } - _ClockMsgTargets.push_back(vb); -} - -// *************************************************************************** -void CWidgetManager::unregisterClockMsgTarget(CCtrlBase *vb) -{ - if (!vb) return; - std::vector::iterator it = std::find(_ClockMsgTargets.begin(), _ClockMsgTargets.end(), vb); - if (it != _ClockMsgTargets.end()) - { - _ClockMsgTargets.erase(it); - } -} - -// *************************************************************************** -bool CWidgetManager::isClockMsgTarget(CCtrlBase *vb) const -{ - std::vector::const_iterator it = std::find(_ClockMsgTargets.begin(), _ClockMsgTargets.end(), vb); - return it != _ClockMsgTargets.end(); -} - -void CWidgetManager::sendClockTickEvent() -{ - NLGUI::CEventDescriptorSystem clockTick; - clockTick.setEventTypeExtended(NLGUI::CEventDescriptorSystem::clocktick); - - if (_CapturePointerLeft) - { - _CapturePointerLeft->handleEvent(clockTick); - } - if (_CapturePointerRight) - { - _CapturePointerRight->handleEvent(clockTick); - } - - // and send clock tick msg to ctrl that are registered - std::vector clockMsgTarget = _ClockMsgTargets; - for(std::vector::iterator it = clockMsgTarget.begin(); it != clockMsgTarget.end(); ++it) - { - (*it)->handleEvent(clockTick); - } -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::notifyElementCaptured(CCtrlBase *c) -{ - std::set seen; - CCtrlBase *curr = c; - while (curr) - { - seen.insert(curr); - curr->elementCaptured(c); - curr = curr->getParent(); - } - // also warn the ctrl under the pointer - for (uint i = 0; i < (uint) _CtrlsUnderPointer.size(); ++i) - { - if (!seen.count(_CtrlsUnderPointer[i])) + if (bRecomputeCtrlUnderPtr) { - _CtrlsUnderPointer[i]->elementCaptured(c); + H_AUTO ( RZ_Interface_RecomputeCtrlUnderPtr ) + if ( CWidgetManager::getInstance()->getPointer() != NULL ) + { + sint32 mx = _Pointer->getX(); + sint32 my = _Pointer->getY(); + getViewsUnder (mx, my, _ViewsUnderPointer); + getCtrlsUnder (mx, my, _CtrlsUnderPointer); + getGroupsUnder (mx, my, _GroupsUnderPointer); + CInterfaceGroup *ptr = getWindowUnder (mx, my); + _WindowUnder = ptr; + } } } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::makeWindow(CInterfaceGroup *group) -{ - if(!group) - return; - - uint32 i = 0; - for (i = 0; i < _MasterGroups.size(); ++i) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::movePointer (sint32 dx, sint32 dy) { - if (_MasterGroups[i].Group == group->getParent()) - break; + if (!_Pointer) + return; + + uint32 nScrW, nScrH; + sint32 oldpx, oldpy, newpx, newpy, disppx, disppy, olddisppx, olddisppy; + + CViewRenderer::getInstance()->getScreenSize (nScrW, nScrH); + _Pointer->getPointerPos (oldpx, oldpy); + + olddisppx = oldpx; + olddisppy = oldpy; + + newpx = oldpx + dx; + newpy = oldpy + dy; + + if (newpx < 0) newpx = 0; + if (newpy < 0) newpy = 0; + if (newpx > (sint32)nScrW) newpx = nScrW; + if (newpy > (sint32)nScrH) newpy = nScrH; + dx = newpx - oldpx; + dy = newpy - oldpy; + + disppx = newpx; + disppy = newpy; + + _Pointer->setPointerPos (newpx, newpy); + _Pointer->setPointerDispPos (disppx, disppy); + + // must get back coordinates because of snapping + sint32 mx = _Pointer->getX(); + sint32 my = _Pointer->getY(); + getViewsUnder (mx, my, _ViewsUnderPointer); + getCtrlsUnder (mx, my, _CtrlsUnderPointer); + getGroupsUnder (mx, my, _GroupsUnderPointer); } - if (i == _MasterGroups.size()) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::movePointerAbs(sint32 px, sint32 py) { - std::string stmp = std::string("not found master group for window: ")+group->getId(); - nlwarning (stmp.c_str()); - return; + if(!CWidgetManager::getInstance()->getPointer()) + return; + + uint32 nScrW, nScrH; + CViewRenderer::getInstance()->getScreenSize (nScrW, nScrH); + NLMISC::clamp(px, 0, (sint32) nScrW); + NLMISC::clamp(py, 0, (sint32) nScrH); + // + _Pointer->setPointerPos (px, py); + _Pointer->setPointerDispPos (px, py); + // + getViewsUnder (px, py, _ViewsUnderPointer); + getCtrlsUnder (px, py, _CtrlsUnderPointer); + getGroupsUnder (px, py, _GroupsUnderPointer); } - else + + // *************************************************************************** + void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) { - // check if group hasn't been inserted twice. - if (_MasterGroups[i].isWindowPresent(group)) + // additionally, abort any dragging + if( CCtrlDraggable::getDraggedSheet() != NULL ) + CCtrlDraggable::getDraggedSheet()->abortDragging(); + + _CapturePointerLeft = c; + notifyElementCaptured(c); + } + + // *************************************************************************** + void CWidgetManager::setCapturePointerRight(CCtrlBase *c) + { + _CapturePointerRight = c; + notifyElementCaptured(c); + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setCaptureKeyboard(CCtrlBase *c) + { + CGroupEditBoxBase *oldEb= dynamic_cast((CCtrlBase*)_CaptureKeyboard); + CGroupEditBoxBase *newEb= dynamic_cast(c); + + if (_CaptureKeyboard && _CaptureKeyboard != c) { - nlwarning("Window inserted twice"); + _CaptureKeyboard->onKeyboardCaptureLost(); } - else + // If the old capturedKeyboard is an editBox and allow recoverFocusOnEnter + if ( oldEb && oldEb->getRecoverFocusOnEnter() ) { - _MasterGroups[i].addWindow(group,group->getPriority()); + _OldCaptureKeyboard = _CaptureKeyboard; + } + if ( newEb ) + { + CGroupEditBoxBase::disableSelection(); + + if (!newEb->getAHOnFocus().empty()) + { + CAHManager::getInstance()->runActionHandler(newEb->getAHOnFocus(), newEb, newEb->getAHOnFocusParams()); + } + + } + _CaptureKeyboard = c; + notifyElementCaptured(c); + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::resetCaptureKeyboard() + { + CCtrlBase *captureKeyboard = _CaptureKeyboard; + _OldCaptureKeyboard = NULL; + _CaptureKeyboard = NULL; + if (captureKeyboard) + { + captureKeyboard->onKeyboardCaptureLost(); } } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::unMakeWindow(CInterfaceGroup *group, bool noWarning) -{ - if (!group) - return; - - uint32 i = 0; - for (i = 0; i < _MasterGroups.size(); ++i) + // *************************************************************************** + void CWidgetManager::registerClockMsgTarget(CCtrlBase *vb) { - if (_MasterGroups[i].Group == group->getParent()) - break; + if (!vb) return; + if (isClockMsgTarget(vb)) + { + nlwarning(" Element %s is already registered", vb->getId().c_str()); + return; + } + _ClockMsgTargets.push_back(vb); } - if (i == _MasterGroups.size()) + // *************************************************************************** + void CWidgetManager::unregisterClockMsgTarget(CCtrlBase *vb) { - if (!noWarning) + if (!vb) return; + std::vector::iterator it = std::find(_ClockMsgTargets.begin(), _ClockMsgTargets.end(), vb); + if (it != _ClockMsgTargets.end()) + { + _ClockMsgTargets.erase(it); + } + } + + // *************************************************************************** + bool CWidgetManager::isClockMsgTarget(CCtrlBase *vb) const + { + std::vector::const_iterator it = std::find(_ClockMsgTargets.begin(), _ClockMsgTargets.end(), vb); + return it != _ClockMsgTargets.end(); + } + + void CWidgetManager::sendClockTickEvent() + { + NLGUI::CEventDescriptorSystem clockTick; + clockTick.setEventTypeExtended(NLGUI::CEventDescriptorSystem::clocktick); + + if (_CapturePointerLeft) + { + _CapturePointerLeft->handleEvent(clockTick); + } + if (_CapturePointerRight) + { + _CapturePointerRight->handleEvent(clockTick); + } + + // and send clock tick msg to ctrl that are registered + std::vector clockMsgTarget = _ClockMsgTargets; + for(std::vector::iterator it = clockMsgTarget.begin(); it != clockMsgTarget.end(); ++it) + { + (*it)->handleEvent(clockTick); + } + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::notifyElementCaptured(CCtrlBase *c) + { + std::set seen; + CCtrlBase *curr = c; + while (curr) + { + seen.insert(curr); + curr->elementCaptured(c); + curr = curr->getParent(); + } + // also warn the ctrl under the pointer + for (uint i = 0; i < (uint) _CtrlsUnderPointer.size(); ++i) + { + if (!seen.count(_CtrlsUnderPointer[i])) + { + _CtrlsUnderPointer[i]->elementCaptured(c); + } + } + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::makeWindow(CInterfaceGroup *group) + { + if(!group) + return; + + uint32 i = 0; + for (i = 0; i < _MasterGroups.size(); ++i) + { + if (_MasterGroups[i].Group == group->getParent()) + break; + } + + if (i == _MasterGroups.size()) { std::string stmp = std::string("not found master group for window: ")+group->getId(); nlwarning (stmp.c_str()); - } - return; - } - else - { - // check if group hasn't been inserted twice. - if (!_MasterGroups[i].isWindowPresent(group)) - { - if (!noWarning) - nlwarning("Window not inserted in master group"); + return; } else { - _MasterGroups[i].delWindow(group); + // check if group hasn't been inserted twice. + if (_MasterGroups[i].isWindowPresent(group)) + { + nlwarning("Window inserted twice"); + } + else + { + _MasterGroups[i].addWindow(group,group->getPriority()); + } } } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::setGlobalColor (NLMISC::CRGBA col) -{ - if (!_RProp) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::unMakeWindow(CInterfaceGroup *group, bool noWarning) { - _RProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:R"); - _GProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:G"); - _BProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:B"); - _AProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:A"); - } - _RProp ->setValue32 (col.R); - _GProp ->setValue32 (col.G); - _BProp ->setValue32 (col.B); - _AProp ->setValue32 (col.A); + if (!group) + return; - _GlobalColor = col; + uint32 i = 0; + for (i = 0; i < _MasterGroups.size(); ++i) + { + if (_MasterGroups[i].Group == group->getParent()) + break; + } - // set the global color for content (the same with modulated alpha) - _GlobalColorForContent = _GlobalColor; - _GlobalColorForContent.A = (uint8) (( (uint16) _GlobalColorForContent.A * (uint16) _ContentAlpha) >> 8); -} - -// *************************************************************************** -void CWidgetManager::setContentAlpha(uint8 alpha) -{ - _ContentAlpha = alpha; - // update alpha of global color - _GlobalColorForContent.A = alpha;/*(uint8) (( (uint16) _GlobalColor.A * (uint16) _ContentAlpha) >> 8);*/ -} - -void CWidgetManager::resetColorProps() -{ - _RProp = NULL; - _GProp = NULL; - _BProp = NULL; - _AProp = NULL; -} - -// ------------------------------------------------------------------------------------------------ -CInterfaceOptions* CWidgetManager::getOptions( const std::string &name ) -{ - std::map< std::string, NLMISC::CSmartPtr< CInterfaceOptions > >::iterator it = _OptionsMap.find( name ); - if( it == _OptionsMap.end() ) - return NULL; - else - return it->second; -} - -void CWidgetManager::addOptions( std::string name, CInterfaceOptions *options ) -{ - _OptionsMap.insert( std::map< std::string, CInterfaceOptions* >::value_type( name, options ) ); -} - -void CWidgetManager::removeOptions( std::string name ) -{ - _OptionsMap.erase( name ); -} - -void CWidgetManager::removeAllOptions() -{ - _OptionsMap.clear(); -} - -CWidgetManager::CWidgetManager() -{ - _Pointer = NULL; - curContextHelp = NULL; - - resetColorProps(); - - _GlobalColor = NLMISC::CRGBA(255,255,255,255); - _GlobalColorForContent = _GlobalColor; - _ContentAlpha = 255; -} - -CWidgetManager::~CWidgetManager() -{ - for (uint32 i = 0; i < _MasterGroups.size(); ++i) - { - delete _MasterGroups[i].Group; + if (i == _MasterGroups.size()) + { + if (!noWarning) + { + std::string stmp = std::string("not found master group for window: ")+group->getId(); + nlwarning (stmp.c_str()); + } + return; + } + else + { + // check if group hasn't been inserted twice. + if (!_MasterGroups[i].isWindowPresent(group)) + { + if (!noWarning) + nlwarning("Window not inserted in master group"); + } + else + { + _MasterGroups[i].delWindow(group); + } + } } - _Pointer = NULL; - curContextHelp = NULL; -} \ No newline at end of file + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setGlobalColor (NLMISC::CRGBA col) + { + if (!_RProp) + { + _RProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:R"); + _GProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:G"); + _BProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:B"); + _AProp = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:COLOR:A"); + } + _RProp ->setValue32 (col.R); + _GProp ->setValue32 (col.G); + _BProp ->setValue32 (col.B); + _AProp ->setValue32 (col.A); + + _GlobalColor = col; + + // set the global color for content (the same with modulated alpha) + _GlobalColorForContent = _GlobalColor; + _GlobalColorForContent.A = (uint8) (( (uint16) _GlobalColorForContent.A * (uint16) _ContentAlpha) >> 8); + } + + // *************************************************************************** + void CWidgetManager::setContentAlpha(uint8 alpha) + { + _ContentAlpha = alpha; + // update alpha of global color + _GlobalColorForContent.A = alpha;/*(uint8) (( (uint16) _GlobalColor.A * (uint16) _ContentAlpha) >> 8);*/ + } + + void CWidgetManager::resetColorProps() + { + _RProp = NULL; + _GProp = NULL; + _BProp = NULL; + _AProp = NULL; + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceOptions* CWidgetManager::getOptions( const std::string &name ) + { + std::map< std::string, NLMISC::CSmartPtr< CInterfaceOptions > >::iterator it = _OptionsMap.find( name ); + if( it == _OptionsMap.end() ) + return NULL; + else + return it->second; + } + + void CWidgetManager::addOptions( std::string name, CInterfaceOptions *options ) + { + _OptionsMap.insert( std::map< std::string, CInterfaceOptions* >::value_type( name, options ) ); + } + + void CWidgetManager::removeOptions( std::string name ) + { + _OptionsMap.erase( name ); + } + + void CWidgetManager::removeAllOptions() + { + _OptionsMap.clear(); + } + + CWidgetManager::CWidgetManager() + { + _Pointer = NULL; + curContextHelp = NULL; + + resetColorProps(); + + _GlobalColor = NLMISC::CRGBA(255,255,255,255); + _GlobalColorForContent = _GlobalColor; + _ContentAlpha = 255; + } + + CWidgetManager::~CWidgetManager() + { + for (uint32 i = 0; i < _MasterGroups.size(); ++i) + { + delete _MasterGroups[i].Group; + } + + _Pointer = NULL; + curContextHelp = NULL; + } + +} + diff --git a/code/ryzom/client/src/camera_recorder.cpp b/code/ryzom/client/src/camera_recorder.cpp index 68c0ddf4e..174fe84ed 100644 --- a/code/ryzom/client/src/camera_recorder.cpp +++ b/code/ryzom/client/src/camera_recorder.cpp @@ -29,6 +29,7 @@ using namespace NLMISC; using namespace NL3D; +using namespace NLGUI; // TODO nico : that stuff was coded in a hurry, but could be good to add it to NL3D with a better packaging later... diff --git a/code/ryzom/client/src/interface_v3/action_handler_debug.cpp b/code/ryzom/client/src/interface_v3/action_handler_debug.cpp index 8f74e3076..95f63af0c 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_debug.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_debug.cpp @@ -33,6 +33,8 @@ using namespace NL3D; #include "../user_entity.h" #include "../connection.h" +using namespace NLGUI; + //////////// // GLOBAL // //////////// diff --git a/code/ryzom/client/src/interface_v3/action_handler_misc.h b/code/ryzom/client/src/interface_v3/action_handler_misc.h index d0fabdcfc..5d6ff7910 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_misc.h +++ b/code/ryzom/client/src/interface_v3/action_handler_misc.h @@ -23,7 +23,10 @@ #include "nel/gui/action_handler.h" #include "interface_manager.h" -class CInterfaceGroup; +namespace NLGUI +{ + class CInterfaceGroup; +} // *************************************************************************** diff --git a/code/ryzom/client/src/interface_v3/bot_chat_manager.h b/code/ryzom/client/src/interface_v3/bot_chat_manager.h index e3dd73d79..3ecadca8c 100644 --- a/code/ryzom/client/src/interface_v3/bot_chat_manager.h +++ b/code/ryzom/client/src/interface_v3/bot_chat_manager.h @@ -22,7 +22,11 @@ class CBotChatPage; class CPrerequisitInfos; -class CInterfaceGroup; + +namespace NLGUI +{ + class CInterfaceGroup; +} class IMissionPrereqInfosWaiter { diff --git a/code/ryzom/client/src/interface_v3/chat_text_manager.h b/code/ryzom/client/src/interface_v3/chat_text_manager.h index 1c9d6d0cf..1e6f2ad0e 100644 --- a/code/ryzom/client/src/interface_v3/chat_text_manager.h +++ b/code/ryzom/client/src/interface_v3/chat_text_manager.h @@ -21,7 +21,11 @@ #include "nel/misc/rgba.h" -class CViewBase; +namespace NLGUI +{ + class CViewBase; +} + class ucstring; namespace NLMISC{ class CCDBNodeLeaf; @@ -46,7 +50,7 @@ public: * \param col the color of the text * \param justified Should be true for justified text (stretch spaces of line to fill the full width) */ - CViewBase *createMsgText(const ucstring &msg, NLMISC::CRGBA col, bool justified = false); + NLGUI::CViewBase *createMsgText(const ucstring &msg, NLMISC::CRGBA col, bool justified = false); // Singleton access static CChatTextManager &getInstance(); diff --git a/code/ryzom/client/src/interface_v3/chat_window.h b/code/ryzom/client/src/interface_v3/chat_window.h index 5daf24c36..8e5da91c2 100644 --- a/code/ryzom/client/src/interface_v3/chat_window.h +++ b/code/ryzom/client/src/interface_v3/chat_window.h @@ -24,10 +24,15 @@ #include "game_share/chat_group.h" + +namespace NLGUI +{ + class CCtrlBase; +} + class CChatWindow; class CGroupContainer; class CGroupEditBox; -class CCtrlBase; class CViewText; /** Interface to react to a chat box entry @@ -240,7 +245,7 @@ public: // Remove a chat window by its pointer void removeChatWindow(CChatWindow *cw); /// from a ctrl of a chat box that triggered a menu, or an event, retrieve the associated chat box - CChatWindow *getChatWindowFromCaller(CCtrlBase *caller); + CChatWindow *getChatWindowFromCaller(NLGUI::CCtrlBase *caller); // Singleton pattern applied to the chat window manager static CChatWindowManager &getInstance(); // try to rename a window diff --git a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h b/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h index deb96a691..3d1ea5ca7 100644 --- a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h +++ b/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h @@ -22,7 +22,11 @@ class CDBCtrlSheet; -class IActionHandler; + +namespace NLGUI +{ + class IActionHandler; +} /** Infos about a selection group */ diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index 7feafadbe..b473c29e3 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -107,10 +107,6 @@ #include "../npc_icon.h" #include "nel/gui/lua_helper.h" -namespace NLGUI -{ - extern void luaDebuggerMainLoop(); -} using namespace NLGUI; #include "nel/gui/lua_ihm.h" #include "lua_ihm_ryzom.h" @@ -128,9 +124,14 @@ using namespace NLGUI; using namespace NLMISC; +namespace NLGUI +{ + extern void luaDebuggerMainLoop(); + extern NLMISC::CStringMapper *_UIStringMapper; +} + extern CClientChatManager ChatMngr; extern CContinentManager ContinentMngr; -extern CStringMapper *_UIStringMapper; extern bool IsInRingSession; extern CEventsListener EventsListener; diff --git a/code/ryzom/client/src/interface_v3/interface_manager.h b/code/ryzom/client/src/interface_v3/interface_manager.h index 93b72c97e..4413c5bec 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.h +++ b/code/ryzom/client/src/interface_v3/interface_manager.h @@ -69,8 +69,12 @@ extern bool g_hidden; // #define AJM_DEBUG_TRACK_INTERFACE_GROUPS +namespace NLGUI +{ + class CInterfaceOptions; +} + class CGroupContainer; -class CInterfaceOptions; class CInterfaceAnim; class CGroupMenu; diff --git a/code/ryzom/client/src/interface_v3/interface_options_ryzom.h b/code/ryzom/client/src/interface_v3/interface_options_ryzom.h index 2d830c1fb..14a623e28 100644 --- a/code/ryzom/client/src/interface_v3/interface_options_ryzom.h +++ b/code/ryzom/client/src/interface_v3/interface_options_ryzom.h @@ -20,6 +20,8 @@ #include "nel/gui/interface_options.h" +using namespace NLGUI; + // *************************************************************************** class COptionsLayer : public CInterfaceOptions { diff --git a/code/ryzom/client/src/interface_v3/interface_parser.h b/code/ryzom/client/src/interface_v3/interface_parser.h index b94ffaa70..0e74c503b 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.h +++ b/code/ryzom/client/src/interface_v3/interface_parser.h @@ -29,17 +29,20 @@ #include "nel/gui/widget_manager.h" using namespace NLGUI; -// *************************************************************************** -class CInterfaceElement; -class CInterfaceGroup; +namespace NLGUI +{ + class CInterfaceElement; + class CInterfaceGroup; + class CInterfaceOptions; + class CInterfaceLink; + class CCtrlBase; +} + class CGroupContainer; class CGroupList; -class CInterfaceOptions; class CInterfaceAnim; class CViewPointer; -class CInterfaceLink; class CBrickJob; -class CCtrlBase; // *************************************************************************** /** diff --git a/code/ryzom/client/src/interface_v3/interface_pointer.h b/code/ryzom/client/src/interface_v3/interface_pointer.h index 8b0e42771..817c927ae 100644 --- a/code/ryzom/client/src/interface_v3/interface_pointer.h +++ b/code/ryzom/client/src/interface_v3/interface_pointer.h @@ -21,7 +21,16 @@ #include "nel/misc/resource_ptr.h" -class CInterfaceElement *getInterfaceResource(const std::string &key); +namespace NLGUI +{ + class CInterfaceElement; + class CCtrlBase; + class CInterfaceGroup; +} + +using namespace NLGUI; + +CInterfaceElement *getInterfaceResource(const std::string &key); /** Interface element ptr * This pointer uses the NLMISC::CResourcePtr @@ -47,13 +56,12 @@ public: }; // Some pointers -typedef CInterfacePtr::TInterfacePtr CInterfaceElementPtr; -typedef CInterfacePtr::TInterfacePtr CInterfaceGroupPtr; +typedef CInterfacePtr::TInterfacePtr CInterfaceElementPtr; +typedef CInterfacePtr::TInterfacePtr CInterfaceGroupPtr; typedef CInterfacePtr::TInterfacePtr CCtrlTextButtonPtr; typedef CInterfacePtr::TInterfacePtr CViewTextPtr; typedef CInterfacePtr::TInterfacePtr CViewTextMenuPtr; -typedef CInterfacePtr::TInterfacePtr CViewTextMenuPtr; -typedef CInterfacePtr::TInterfacePtr CCtrlBasePtr; +typedef CInterfacePtr::TInterfacePtr CCtrlBasePtr; typedef CInterfacePtr::TInterfacePtr CCtrlBaseButtonPtr; typedef CInterfacePtr::TInterfacePtr CGroupContainerPtr; diff --git a/code/ryzom/client/src/interface_v3/view_pointer.h b/code/ryzom/client/src/interface_v3/view_pointer.h index ebaa84225..274d07a56 100644 --- a/code/ryzom/client/src/interface_v3/view_pointer.h +++ b/code/ryzom/client/src/interface_v3/view_pointer.h @@ -24,7 +24,11 @@ #include "nel/gui/view_pointer_base.h" class CGroupContainer; -class CCtrlBase; + +namespace NLGUI +{ + class CCtrlBase; +} /** * class describing the pointer diff --git a/code/ryzom/client/src/r2/displayer_base.h b/code/ryzom/client/src/r2/displayer_base.h index 4d60a9f59..20ebdf87a 100644 --- a/code/ryzom/client/src/r2/displayer_base.h +++ b/code/ryzom/client/src/r2/displayer_base.h @@ -38,7 +38,7 @@ class CObjectTable; * - one for the ui (displaying instance in the object tree for example) * - one for the property sheet of the instance */ -class CDisplayerBase : public NLMISC::IClassable, public CReflectableRefPtrTarget +class CDisplayerBase : public NLMISC::IClassable, public NLGUI::CReflectableRefPtrTarget { public: typedef NLMISC::CSmartPtr TSmartPtr;