From c792abe091d3e4407fe4dcafa36e2652ce2e41e5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 9 Jun 2012 03:57:40 +0200 Subject: [PATCH] CHANGED: #1471 The classes moved in the previous commit are now under the NLGUI namespace. --HG-- branch : gui-refactoring --- code/nel/include/nel/gui/action_handler.h | 202 +- code/nel/include/nel/gui/ctrl_base.h | 265 +- code/nel/include/nel/gui/ctrl_draggable.h | 80 +- code/nel/include/nel/gui/ctrl_scroll_base.h | 51 +- .../include/nel/gui/group_container_base.h | 145 +- code/nel/include/nel/gui/group_editbox_base.h | 57 +- code/nel/include/nel/gui/group_frame.h | 123 +- code/nel/include/nel/gui/group_modal.h | 73 +- code/nel/include/nel/gui/interface_element.h | 896 ++--- code/nel/include/nel/gui/interface_group.h | 734 ++-- code/nel/include/nel/gui/interface_link.h | 297 +- code/nel/include/nel/gui/interface_options.h | 107 +- code/nel/include/nel/gui/view_base.h | 74 +- code/nel/include/nel/gui/view_pointer_base.h | 92 +- code/nel/include/nel/gui/widget_manager.h | 591 ++-- code/nel/src/gui/action_handler.cpp | 1119 +++--- code/nel/src/gui/ctrl_base.cpp | 328 +- code/nel/src/gui/ctrl_draggable.cpp | 35 +- code/nel/src/gui/ctrl_scroll_base.cpp | 82 +- code/nel/src/gui/group_container_base.cpp | 123 +- code/nel/src/gui/group_editbox_base.cpp | 38 +- code/nel/src/gui/group_frame.cpp | 372 +- code/nel/src/gui/group_modal.cpp | 267 +- code/nel/src/gui/interface_element.cpp | 1910 +++++----- code/nel/src/gui/interface_group.cpp | 3077 +++++++++-------- code/nel/src/gui/interface_link.cpp | 1005 +++--- code/nel/src/gui/interface_options.cpp | 171 +- code/nel/src/gui/view_base.cpp | 43 +- code/nel/src/gui/view_pointer_base.cpp | 204 +- code/nel/src/gui/widget_manager.cpp | 2005 +++++------ code/ryzom/client/src/camera_recorder.cpp | 1 + .../src/interface_v3/action_handler_debug.cpp | 2 + .../src/interface_v3/action_handler_misc.h | 5 +- .../src/interface_v3/bot_chat_manager.h | 6 +- .../src/interface_v3/chat_text_manager.h | 8 +- .../client/src/interface_v3/chat_window.h | 9 +- .../src/interface_v3/ctrl_sheet_selection.h | 6 +- .../src/interface_v3/interface_manager.cpp | 11 +- .../src/interface_v3/interface_manager.h | 6 +- .../interface_v3/interface_options_ryzom.h | 2 + .../src/interface_v3/interface_parser.h | 15 +- .../src/interface_v3/interface_pointer.h | 18 +- .../client/src/interface_v3/view_pointer.h | 6 +- code/ryzom/client/src/r2/displayer_base.h | 2 +- 44 files changed, 7463 insertions(+), 7200 deletions(-) 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() {} + class CCtrlBase; - static std::string getParam (const std::string &Params, const std::string &ParamName); - static void getAllParams (const std::string &Params, std::vector< std::pair > &AllParams); -}; + /** + * interface for action handlers + * \author Nicolas Brigand + * \author Nevrax France + * \date 2002 + */ + 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 */) { } + virtual ~IActionHandler() {} -/** - 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 std::string getParam (const std::string &Params, const std::string &ParamName); - static CAHManager* getInstance() - { - if (_GlobalInstance == NULL) - _GlobalInstance = new CAHManager; - return _GlobalInstance; - } + static void getAllParams (const std::string &Params, std::vector< std::pair > &AllParams); + }; - /// 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 factory + no release in this factory : a handler must be destroyed by the control that created it */ - 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 ; \ - \ + 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 - - NumToolTipParentRef + public: + + // 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 ) + + 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() + { + dragged = false; + _LastDraggedSheet = NULL; + } + + // Necessary because of reflection, no other purpose + void draw(){} - // Necessary because of reflection, no other purpose - void draw(){} + REFLECT_EXPORT_START(CCtrlDraggable, CCtrlBase) + REFLECT_BOOL("dragable", isDraggable, setDraggable); + REFLECT_EXPORT_END - REFLECT_EXPORT_START(CCtrlDraggable, CCtrlBase) - REFLECT_BOOL("dragable", isDraggable, setDraggable); - REFLECT_EXPORT_END + protected: + static void setDraggedSheet( CCtrlDraggable *draggable ){ _LastDraggedSheet = draggable; } -protected: - static void setDraggedSheet( CCtrlDraggable *draggable ){ _LastDraggedSheet = draggable; } + private: + static CCtrlDraggable *_LastDraggedSheet; + bool dragged; + bool 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; + + 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 ); - /** 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(); - - virtual void removeAllContainers(); - virtual void setLocked( bool locked ); - bool isLocked() const { return _Locked; } - - uint8 getContainerAlpha() const { return _ContainerAlpha; } - uint8 getContentAlpha() const { return _ContentAlpha; } - uint8 getRolloverAlphaContent() const { return _RolloverAlphaContent; } - uint8 getRolloverAlphaContainer() const { return _RolloverAlphaContainer; } - - void setContainerAlpha( uint8 alpha ); - void setContentAlpha( uint8 alpha ); - void setRolloverAlphaContent( uint8 alpha ); - void 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; } - - // 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); } - - void setUseGlobalAlpha( bool use ); - bool isUsingGlobalAlpha() const{ return _UseGlobalAlpha; } - - std::string getAHOnAlphaSettingsChanged() const{ return CAHManager::getInstance()->getAHName( _AHOnAlphaSettingsChanged ); } - std::string getAHOnAlphaSettingsChangedParams() const{ return _AHOnAlphaSettingsChangedParams; } - - void setAHOnAlphaSettingsChanged( const std::string &h ){ _AHOnAlphaSettingsChanged = CAHManager::getInstance()->getAH( h, _AHOnAlphaSettingsChangedParams ); } - void setAHOnAlphaSettingsChangedParams( const std::string &p ){ _AHOnAlphaSettingsChangedParams = p; } - - 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 - -protected: - void triggerAlphaSettingsChangedAH(); - - 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; - - IActionHandler *_AHOnAlphaSettingsChanged; - CStringShared _AHOnAlphaSettingsChangedParams; - -private: - -}; + + class CGroupContainerBase : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CGroupContainerBase ) + + CGroupContainerBase( const TCtorParam ¶m ); + virtual ~CGroupContainerBase(); + + virtual void removeAllContainers(); + virtual void setLocked( bool locked ); + bool isLocked() const { return _Locked; } + + uint8 getContainerAlpha() const { return _ContainerAlpha; } + uint8 getContentAlpha() const { return _ContentAlpha; } + uint8 getRolloverAlphaContent() const { return _RolloverAlphaContent; } + uint8 getRolloverAlphaContainer() const { return _RolloverAlphaContainer; } + + void setContainerAlpha( uint8 alpha ); + void setContentAlpha( uint8 alpha ); + void setRolloverAlphaContent( uint8 alpha ); + void 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; } + + // 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); } + + void setUseGlobalAlpha( bool use ); + bool isUsingGlobalAlpha() const{ return _UseGlobalAlpha; } + + std::string getAHOnAlphaSettingsChanged() const{ return CAHManager::getInstance()->getAHName( _AHOnAlphaSettingsChanged ); } + std::string getAHOnAlphaSettingsChangedParams() const{ return _AHOnAlphaSettingsChangedParams; } + + void setAHOnAlphaSettingsChanged( const std::string &h ){ _AHOnAlphaSettingsChanged = CAHManager::getInstance()->getAH( h, _AHOnAlphaSettingsChangedParams ); } + void setAHOnAlphaSettingsChangedParams( const std::string &p ){ _AHOnAlphaSettingsChangedParams = p; } + + 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 + + protected: + void triggerAlphaSettingsChangedAH(); + + 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; + + 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); + + + // *************************************************************************** + /** A Group with a background and a frame displayed + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CGroupFrame : public CInterfaceGroup + { + public: - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - virtual void draw (); + /// Constructor + CGroupFrame(const TCtorParam ¶m); - void copyOptionFrom(const CGroupFrame &other); + 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 + 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: + static void resetDisplayTypes() { _DispTypes.clear(); } - bool _DisplayFrame; + // ****************** + protected: - NLMISC::CRGBA _Color; + bool _DisplayFrame; - uint8 _DispType; + NLMISC::CRGBA _Color; - // Fields Defined in the XML => must not herit them from extends="" - bool _DisplayFrameDefined : 1; - bool _ColorDefined : 1; - bool _DispTypeDefined : 1; + uint8 _DispType; - // Static stuff - enum - { - TextTL= 0, - TextTM, - TextTR, - TextML, - TextMM, - TextMR, - TextBL, - TextBM, - TextBR - }; + // Fields Defined in the XML => must not herit them from extends="" + bool _DisplayFrameDefined : 1; + bool _ColorDefined : 1; + bool _DispTypeDefined : 1; - 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() + // Static stuff + enum + { + TextTL= 0, + TextTM, + TextTR, + TextML, + TextMM, + TextMR, + TextBL, + TextBM, + TextBR + }; + + struct SDisplayType { - for (uint i = 0; i < 9; ++i) - TileBorder[i] = 0; - } + 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; }; - 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; + + 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: - /// Constructor - CGroupModal(const TCtorParam ¶m); + /// Constructor + CGroupModal(const TCtorParam ¶m); - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - virtual void updateCoords (); - void setBaseX(sint32 x) { _MouseDeltaX = x;} - void setBaseY(sint32 y) { _MouseDeltaY = y;} + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void updateCoords (); + void setBaseX(sint32 x) { _MouseDeltaX = x;} + void setBaseY(sint32 y) { _MouseDeltaY = y;} - REFLECT_EXPORT_START(CGroupModal, CGroupFrame) - REFLECT_EXPORT_END + REFLECT_EXPORT_START(CGroupModal, CGroupFrame) + REFLECT_EXPORT_END -// ****************** -protected: - sint32 _MouseDeltaX, _MouseDeltaY; -}; + // ****************** + 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,569 +27,577 @@ #include "nel/gui/reflect.h" #include "nel/gui/interface_common.h" -using namespace NLGUI; +class CGroupList; +class CGroupParagraph; -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 +namespace NLGUI { -public: + class CInterfaceLink; + class CInterfaceElement; + class CInterfaceGroup; + class CViewBase; + class CCtrlBase; + class IActionHandler; - enum EStrech + /** + * 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 { - none=0, - width=1, - height=2 + public: + virtual void visit(CInterfaceElement * /* elem */) {} + virtual void visitGroup(CInterfaceGroup * /* group */) {} + virtual void visitView(CViewBase * /* view */) {} + virtual void visitCtrl(CCtrlBase * /* ctrl */) {} }; - /// 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; - } + /** + * 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: - // 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(); + enum EStrech + { + none=0, + width=1, + height=2 + }; - // help to serialize an action handler - static void serialAH(NLMISC::IStream &f, IActionHandler *&ah); + /// Constructor + CInterfaceElement() + { + _Parent = NULL; + _XReal = _YReal = _WReal = _HReal = 0; + _X = _Y = _W = _H = 0; + //_Snap = 1; - /// Parse the element and initalize it - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + _PosRef = Hotspot_BL; + _ParentPosRef = Hotspot_BL; + _ParentPos = NULL; - /// Debug info on memory - virtual uint32 getMemory () { return (uint32)(sizeof(*this)+_Id.size()); } + _SizeRef = 0; + _SizeDivW = 10; + _SizeDivH = 10; + _ParentSize = NULL; - /// helper: display a parse error with the id of the lement - void parseError (CInterfaceGroup *parentGroup, const char *reason = NULL); + _Links = NULL; + _Active= true; + // default to 3 pass + _InvalidCoords= 3; - /// Accessors : GET - const std::string& getId() const { return _Id; } - std::string getShortId() const; - std::string getIdByValue() const { return _Id; } + _ModulateGlobalColor= true; + _RenderLayer= 0; - CInterfaceGroup* getParent() const { return _Parent; } + _AvoidResizeParent= false; + } - CInterfaceElement* getParentPos() const { return _ParentPos; } + // dtor + virtual ~CInterfaceElement(); - CInterfaceElement* getParentSize() const { return _ParentSize; } + /** 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(); - /// Get the master group of this element (recurs call. - CInterfaceElement* getMasterGroup() const; + // help to serialize an action handler + static void serialAH(NLMISC::IStream &f, IActionHandler *&ah); - // get a possible group container - CInterfaceGroup* getParentContainer(); - bool getActive() const { return _Active; } + /// Parse the element and initalize it + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - sint32 getX() const { return _X; } + /// Debug info on memory + virtual uint32 getMemory () { return (uint32)(sizeof(*this)+_Id.size()); } - sint32 getY() const { return _Y; } + /// helper: display a parse error with the id of the lement + void parseError (CInterfaceGroup *parentGroup, const char *reason = NULL); - sint32 getW() const { return (_Active?_W:0); } - sint32 getW(bool bTestActive) const { return (bTestActive?(_Active?_W:0):_W); } + /// Accessors : GET + const std::string& getId() const { return _Id; } + std::string getShortId() const; + std::string getIdByValue() const { return _Id; } - sint32 getH() const { return (_Active?_H:0); } - sint32 getH(bool bTestActive) const { return (bTestActive?(_Active?_H:0):_H); } + CInterfaceGroup* getParent() const { return _Parent; } - /** - * 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; }; + CInterfaceElement* getParentPos() const { return _ParentPos; } - /** - * 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; }; + CInterfaceElement* getParentSize() const { return _ParentSize; } - //bool isSnapped() const { return (_Snap>1); } + /// Get the master group of this element (recurs call. + CInterfaceElement* getMasterGroup() const; - //sint32 getSnapping() const { return _Snap; } + // get a possible group container + CInterfaceGroup* getParentContainer(); - sint32 getXReal() const { return _XReal; } + bool getActive() const { return _Active; } - sint32 getYReal() const { return _YReal; } + sint32 getX() const { return _X; } - sint32 getWReal() const { return (_Active?_WReal:0); } + sint32 getY() const { return _Y; } - sint32 getHReal() const { return (_Active?_HReal:0); } + sint32 getW() const { return (_Active?_W:0); } + sint32 getW(bool bTestActive) const { return (bTestActive?(_Active?_W:0):_W); } - THotSpot getPosRef () const { return _PosRef; } + sint32 getH() const { return (_Active?_H:0); } + sint32 getH(bool bTestActive) const { return (bTestActive?(_Active?_H:0):_H); } - THotSpot getParentPosRef () const { return _ParentPosRef; } + /** + * 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; }; - sint32 getSizeRef() const { return _SizeRef; } // none == 0, w == 1, h == 2, wh == 3 + /** + * 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; }; - void setSizeRef(sint32 value) { _SizeRef = value; } + //bool isSnapped() const { return (_Snap>1); } - /// Accessors : SET - void setId (const std::string &newID) { _Id = newID; } + //sint32 getSnapping() const { return _Snap; } - inline void setName(const std::string &name) { _Name = name; } - inline const std::string& getName() { return _Name; } + sint32 getXReal() const { return _XReal; } - virtual void setIdRecurse(const std::string &newID); + sint32 getYReal() const { return _YReal; } - void setParent (CInterfaceGroup *pIG) { _Parent = pIG; } + sint32 getWReal() const { return (_Active?_WReal:0); } - void setParentPos (CInterfaceElement *pIG) { _ParentPos = pIG; } + sint32 getHReal() const { return (_Active?_HReal:0); } - void setParentSize (CInterfaceElement *pIG) { _ParentSize = pIG; } + THotSpot getPosRef () const { return _PosRef; } - virtual void setActive (bool state); + THotSpot getParentPosRef () const { return _ParentPosRef; } - void setX (sint32 x) { _X = x; } - void setXAndInvalidateCoords (sint32 x) { _X = x; invalidateCoords(); } + sint32 getSizeRef() const { return _SizeRef; } // none == 0, w == 1, h == 2, wh == 3 - void setY (sint32 y) { _Y = y; } - void setYAndInvalidateCoords (sint32 y) { _Y = y; invalidateCoords(); } + void setSizeRef(sint32 value) { _SizeRef = value; } - void setW (sint32 w); - void setWAndInvalidateCoords (sint32 w) { setW(w); invalidateCoords(); } + /// Accessors : SET + void setId (const std::string &newID) { _Id = newID; } - void setH (sint32 h); - void setHAndInvalidateCoords (sint32 h) { setH(h); invalidateCoords(); } + inline void setName(const std::string &name) { _Name = name; } + inline const std::string& getName() { return _Name; } - void setPosRef (THotSpot hs) { _PosRef = hs; } + virtual void setIdRecurse(const std::string &newID); - void setParentPosRef (THotSpot hs) { _ParentPosRef = hs; } + void setParent (CInterfaceGroup *pIG) { _Parent = pIG; } - // Get the coordinate of a corner on screen - void getCorner(sint32 &px, sint32 &py, THotSpot hotSpot); + void setParentPos (CInterfaceElement *pIG) { _ParentPos = pIG; } - /** Test if the given coordinates are inside this element - */ - bool isIn(sint x, sint y) const; + void setParentSize (CInterfaceElement *pIG) { _ParentSize = pIG; } - /** Test if the given box intersect the element - */ - bool isIn(sint x, sint y, uint width, uint height) const; + virtual void setActive (bool state); - /** Test if another interface element intersect this one - */ - bool isIn(const CInterfaceElement &other) const; + void setX (sint32 x) { _X = x; } + void setXAndInvalidateCoords (sint32 x) { _X = x; invalidateCoords(); } - /** - * 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(); + void setY (sint32 y) { _Y = y; } + void setYAndInvalidateCoords (sint32 y) { _Y = y; invalidateCoords(); } - /** 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; + void setW (sint32 w); + void setWAndInvalidateCoords (sint32 w) { setW(w); invalidateCoords(); } - /** - * true if the element and all its parents are active (recurs up to the root window) - */ - bool isActiveThroughParents() const; + void setH (sint32 h); + void setHAndInvalidateCoords (sint32 h) { setH(h); invalidateCoords(); } - /** - * 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;} + void setPosRef (THotSpot hs) { _PosRef = hs; } - /* 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(); + void setParentPosRef (THotSpot hs) { _ParentPosRef = hs; } - /* This call back is called when the content or the content of a child is been invalidated. - */ - virtual void onInvalidateContent() {} + // Get the coordinate of a corner on screen + void getCorner(sint32 &px, sint32 &py, THotSpot hotSpot); - // called by interfaceManager for master window only - void resetInvalidCoords(); + /** Test if the given coordinates are inside this element + */ + bool isIn(sint x, sint y) const; - /// 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 the given box intersect the element + */ + bool isIn(sint x, sint y, uint width, uint height) const; - /// Test if this element is son of the given element - bool isSonOf(const CInterfaceElement *other) const; + /** Test if another interface element intersect this one + */ + bool isIn(const CInterfaceElement &other) const; - /// Called after first frame initialised - virtual void launch () {} + /** + * 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(); - void setRenderLayer(sint8 rl) {_RenderLayer= rl;} - sint8 getRenderLayer() const { return _RenderLayer; } + /** 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; - void copyOptionFrom(const CInterfaceElement &other); + /** + * 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); - // center the element in middle of screen - void center(); + //void resizeBR (sint32 sizex, sint32 sizey); + //void stopResizeBR(); + //void startResizeBR(); - // 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); + // Some tools - void drawHotSpot(THotSpot hs, NLMISC::CRGBA col); + 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); - // Returns 'true' if that element can be downcasted to a view - virtual bool isView() const { return false; } + // 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); - // Returns 'true' if that element can be downcasted to a ctrl - virtual bool isCtrl() const { return false; } + void drawHotSpot(THotSpot hs, NLMISC::CRGBA col); - // Returns 'true' if that element can be downcasted to an interface group - virtual bool isGroup() const { return false; } + // 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; } - /** 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); + // Returns 'true' if that element can be downcasted to an interface group + virtual bool isGroup() const { return false; } - // 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() {} + /** 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); - /// Whent an element is added to a CInterfaceGroup via addCtrl, addGroup or addView, this is called after the add. - virtual void onAddToGroup() {} + // visit the node of the ui tree + virtual void visit(CInterfaceElementVisitor *visitor); - /** 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); + /** 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() {} - /// if true, InterfaceGroup child resize won't take this element into account - bool avoidResizeParent() const {return _AvoidResizeParent;} - void setAvoidResizeParent(bool state) {_AvoidResizeParent= state;} + /// Whent an element is added to a CInterfaceGroup via addCtrl, addGroup or addView, this is called after the add. + virtual void onAddToGroup() {} - virtual std::string getClassName() - { - nlassert(0); // forgot to implement serial & to register the class ? - return ""; - } + /** 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); -protected: + /// if true, InterfaceGroup child resize won't take this element into account + bool avoidResizeParent() const {return _AvoidResizeParent;} + void setAvoidResizeParent(bool state) {_AvoidResizeParent= state;} - ///the parent - CInterfaceGroup* _Parent; + virtual std::string getClassName() + { + nlassert(0); // forgot to implement serial & to register the class ? + return ""; + } - ///the id of the element - std::string _Id; + protected: - std::string _Name; + ///the parent + CInterfaceGroup* _Parent; - ///is the element active? - bool _Active; + ///the id of the element + std::string _Id; - // if 0, don't need updateCoords(), else tell the number of pass needed - uint8 _InvalidCoords; + std::string _Name; - // Real display coords - sint32 _XReal, _YReal, _WReal, _HReal; + ///is the element active? + bool _Active; - // Relative coords - sint32 _X; - sint32 _Y; - sint32 _W; - sint32 _H; + // if 0, don't need updateCoords(), else tell the number of pass needed + uint8 _InvalidCoords; - //sint32 _Snap; + // Real display coords + sint32 _XReal, _YReal, _WReal, _HReal; - // 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 + // Relative coords + sint32 _X; + sint32 _Y; + sint32 _W; + sint32 _H; - 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 + //sint32 _Snap; - // Friend Class - friend class CGroupList; - friend class CGroupParagraph; + // 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 - // True if must modulate the global color with the view - bool _ModulateGlobalColor; - // Index of layer to render it. - sint8 _RenderLayer; + 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 - // Used for CInterfaceGroup ChildResize feature - bool _AvoidResizeParent; + // 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; - virtual void serial(NLMISC::IStream &f); + // Used for CInterfaceGroup ChildResize feature + bool _AvoidResizeParent; - void parseSizeRef(const char *sizeRef); - void parseSizeRef(const char *sizeRefStr, sint32 &sizeref, sint32 &sizeDivW, sint32 &sizeDivH); -private: - //void snapSize(); + virtual void serial(NLMISC::IStream &f); - typedef NLMISC::CSmartPtr TLinkSmartPtr; - typedef std::vector TLinkVect; - TLinkVect *_Links; // links, or NULL if no link -}; + void parseSizeRef(const char *sizeRef); + void parseSizeRef(const char *sizeRefStr, sint32 &sizeref, sint32 &sizeDivW, sint32 &sizeDivH); -extern NLMISC::CStringMapper *_UIStringMapper; -/** - * class to compress string usage in the interface - * \author Matthieu 'Trap' Besson - * \author Nevrax France - * \date October 2003 - */ -class CStringShared -{ + private: + //void snapSize(); -public: - CStringShared() - { - _Id = NLMISC::CStringMapper::emptyId(); - } + typedef NLMISC::CSmartPtr TLinkSmartPtr; + typedef std::vector TLinkVect; + TLinkVect *_Links; // links, or NULL if no link + }; - const CStringShared& operator=(const std::string &str) + extern NLMISC::CStringMapper *_UIStringMapper; + /** + * class to compress string usage in the interface + * \author Matthieu 'Trap' Besson + * \author Nevrax France + * \date October 2003 + */ + class CStringShared { - _Id = _UIStringMapper->localMap(str); - return *this; - } - const CStringShared& operator=(const CStringShared &str) - { - _Id = str._Id; - return *this; - } + public: + CStringShared() + { + _Id = NLMISC::CStringMapper::emptyId(); + } - const std::string &toString() const - { - return _UIStringMapper->localUnmap(_Id); - } + const CStringShared& operator=(const std::string &str) + { + _Id = _UIStringMapper->localMap(str); + return *this; + } - operator const std::string &() const - { - return _UIStringMapper->localUnmap(_Id); - } + const CStringShared& operator=(const CStringShared &str) + { + _Id = str._Id; + return *this; + } - bool empty() const - { - return _Id == NLMISC::CStringMapper::emptyId(); - } + const std::string &toString() const + { + return _UIStringMapper->localUnmap(_Id); + } - static CStringShared emptyString() - { - return CStringShared(); - } + operator const std::string &() const + { + return _UIStringMapper->localUnmap(_Id); + } - NLMISC::TStringId getStringId() const { return _Id; } + bool empty() const + { + return _Id == NLMISC::CStringMapper::emptyId(); + } - void serial(NLMISC::IStream &f) - { - std::string str; - if (f.isReading()) + static CStringShared emptyString() { - f.serial(str); - *this = str; + return CStringShared(); } - else + + NLMISC::TStringId getStringId() const { return _Id; } + + void serial(NLMISC::IStream &f) { - str = this->toString(); - f.serial(str); + std::string str; + if (f.isReading()) + { + f.serial(str); + *this = str; + } + else + { + str = this->toString(); + f.serial(str); + } } - } -private: + private: - NLMISC::TStringId _Id; -}; + 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); } -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; #endif // NL_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; - - -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 + class CInterfaceElement; + class CInterfaceGroup; + + /** 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; } + 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 removeAllLinks(); - static void setTargetProperty (const std::string & Target, const CInterfaceExprValue &val); + static void setTargetProperty (const std::string & Target, const CInterfaceExprValue &val); - static bool isUpdatingAllLinks() { return _UpdateAllLinks; } + 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 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; + /** 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(); }; -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() - { - _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;} - - void init(const std::string &str); - - // returned when InterfaceOptions param not found - static const CInterfaceOptionValue NullValue; - -private: - std::string _Str; - NLMISC::CRGBA _Color; - sint32 _Int; - float _Float; - bool _Boolean; -}; - - -// *************************************************************************** -class CInterfaceOptions : public NLMISC::CRefCount -{ + // *************************************************************************** + class CInterfaceOptionValue + { + 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;} + + void init(const std::string &str); + + // returned when InterfaceOptions param not found + static const CInterfaceOptionValue NullValue; + + private: + + std::string _Str; + NLMISC::CRGBA _Color; + sint32 _Int; + float _Float; + bool _Boolean; + }; + + + // *************************************************************************** + 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()); } - void copyOptionFrom(const CViewBase &other) - { - CInterfaceElement::copyOptionFrom(other); - } + /// 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); + } - 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 ) + + CViewPointerBase( const TCtorParam ¶m ); + virtual ~CViewPointerBase(); + + // Set the pointer position. + void setPointerPos (sint32 x, sint32 y); + void setPointerDispPos (sint32 x, sint32 y); - // Set the pointer position. - void setPointerPos (sint32 x, sint32 y); - void setPointerDispPos (sint32 x, sint32 y); + void resetPointerPos (); + void setPointerDown (bool pd); + void setPointerDownString (const std::string &s); - void resetPointerPos (); - void setPointerDown (bool pd); - void setPointerDownString (const std::string &s); + void getPointerPos (sint32 &x, sint32 &y); + void getPointerDispPos (sint32 &x, sint32 &y); - void getPointerPos (sint32 &x, sint32 &y); - void getPointerDispPos (sint32 &x, sint32 &y); + void getPointerOldPos (sint32 &x, sint32 &y); + void getPointerDownPos (sint32 &x, sint32 &y); + bool getPointerDown (); + std::string getPointerDownString (); + bool getPointerDrag (); - void getPointerOldPos (sint32 &x, sint32 &y); - void getPointerDownPos (sint32 &x, sint32 &y); - bool getPointerDown (); - std::string getPointerDownString (); - bool getPointerDrag (); + /// Is the pointer visible ? + bool show() const {return _PointerVisible;} - /// Is the pointer visible ? - bool show() const {return _PointerVisible;} + void draw(){} - void draw(){} + 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 ? -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: -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: - - // Master groups encapsulate all windows - struct SMasterGroup - { - 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(); + class CInterfaceElement; + class CCtrlBase; + class CViewBase; + class CInterfaceGroup; + class CViewPointerBase; + class CInterfaceOptions; - // Sort the world space group - void sortWorldSpaceGroup (); - - uint8 LastTopWindowPriority; + class IParser + { + 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 + { + 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 { - ModalWindow = NULL; - CtrlLaunchingModal = NULL; - ModalExitClickOut = false; - ModalExitClickL = false; - ModalExitClickR = false; - ModalExitKeyPushed = false; + // 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; } - }; - - - 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); + 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; + }; - 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()) + + // ------------------------------------------------------------------------------------------------ + CAHManager *CAHManager::_GlobalInstance = NULL; + // ------------------------------------------------------------------------------------------------ + + // ------------------------------------------------------------------------------------------------ + static void skipBlankAtStart (string &start) { - if ((start[0] == ' ' || start[0] == '\t' || start[0] == '\r' || start[0] == '\n')) - start = start.substr(1,start.size()); - else - break; + 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()) + // ------------------------------------------------------------------------------------------------ + static void skipBlankAtEnd (string &end) { - 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; + 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 IActionHandler::getParam (const string &Params, const string &ParamName) { - 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 allparam = Params; + skipBlankAtStart (allparam); + string param = toLower (ParamName); + while (allparam.size() > 0) { - string tmp2 = allparam.substr(e+1,p-e-1); - skipBlankAtStart(tmp2); - skipBlankAtEnd(tmp2); - return tmp2; + 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); } - if (p == std::string::npos || p == 0) break; - allparam = allparam.substr(p+1,allparam.size()); - skipBlankAtStart (allparam); + return ""; } - return ""; -} -// ------------------------------------------------------------------------------------------------ -void IActionHandler::getAllParams (const string &Params, vector< pair > &vAllParams) -{ - string allparam = Params; - skipBlankAtStart (allparam); - while (allparam.size() > 0) + // ------------------------------------------------------------------------------------------------ + void IActionHandler::getAllParams (const string &Params, vector< pair > &vAllParams) { - 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 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); + string tmp2 = allparam.substr(e+1,p-e-1); + skipBlankAtStart(tmp2); + skipBlankAtEnd(tmp2); - vAllParams.push_back(pair(tmp,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); + if (p == std::string::npos || p == 0) break; + allparam = allparam.substr(p+1,allparam.size()); + skipBlankAtStart (allparam); + } } - // 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) + // ------------------------------------------------------------------------------------------------ + IActionHandler* CAHManager::getAH(const std::string &name, std::string ¶ms) { - string ahName= name.substr(0, i); - params= name.substr(i+1); - return getActionHandler(ahName); + // 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); } - // 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) + // ------------------------------------------------------------------------------------------------ + IActionHandler* CAHManager::getAH(const std::string &name, CStringShared ¶ms) { - 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); } - // Read parameter (if specified) - if(paramId) + // ------------------------------------------------------------------------------------------------ + void CAHManager::parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, std::string ¶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::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) + { + string ahVal= (const char*)prop; + if(ahVal.find(':')!= string::npos) + paramSpecifiedInAH= true; + ahRet = getAH(ahVal, paramRet); + } + } - // Read the action handler and any param he defines - bool paramSpecifiedInAH= false; - if(ahId) - { - prop = (char*) xmlGetProp( cur, (xmlChar*)ahId ); - if (prop) + // Read parameter (if specified) + if(paramId) { - string ahVal= (const char*)prop; - if(ahVal.find(':')!= string::npos) - paramSpecifiedInAH= true; - ahRet = getAH(ahVal, paramRet); + 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; + // 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); + } + } - // 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); + // 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); + } } - else + + // ------------------------------------------------------------------------------------------------ + void CAHManager::runActionHandler (const string &ahCmdLine, CCtrlBase *pCaller, const string &ahUserParams) { - ahName= ahCmdLine; - } + if (ahCmdLine.empty()) return; - // Replace params if defined - if(!ahUserParams.empty()) - ahParams= ahUserParams; + // 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; + } - // 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); + // Replace params if defined + if(!ahUserParams.empty()) + ahParams= ahUserParams; - // 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); -} + // 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); -// ------------------------------------------------------------------------------------------------ -void CAHManager::runActionHandler (IActionHandler *pAH, CCtrlBase *pCaller, const std::string &Params) -{ - if (pAH == NULL) - { - nlwarning ("no action handler"); - return; + // 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); } - 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()) + + // ------------------------------------------------------------------------------------------------ + void CAHManager::runActionHandler (IActionHandler *pAH, CCtrlBase *pCaller, const std::string &Params) { - nlwarning ("not found action handler : %s", submitQuickHelp.c_str()); - return; + 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); } - 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) + // ------------------------------------------------------------------------------------------------ + class CAHSet : public IActionHandler { - 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)) + public: + virtual void execute (CCtrlBase *pCaller, const string &Params) { - if (!dblink.empty()) + 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)) { - // 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 (!dblink.empty()) { - if (0!=dblink.compare(0, dbLocalR2.size(), dbLocalR2)) + // 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)) + ) { - //nlwarning("You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database"); - nlstop; - return; + 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; + 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 (!value.toInteger()) + { + nlwarning(" expression doesn't evaluate to a numerical value"); + } + if (ip.link (dblinkeval.c_str())) + { + ip.setSInt64(value.getInteger()); + } } - if (ip.link (dblinkeval.c_str())) + + if (!propertyToEval.empty()) { - ip.setSInt64(value.getInteger()); + CInterfaceExprValue res; + if (!CInterfaceExpr::eval(propertyToEval, res, NULL)) return; + res.toString(); + property = res.getString(); } - } - - 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) + if (!property.empty()) { - 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(); - } + 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 (ig != NULL) { - if (targets[k].Elem) targets[k].affect(value); + CInterfaceLink::splitLinkTargets(property, ig, targets); + for(uint k = 0; k < targets.size(); ++k) + { + if (targets[k].Elem) targets[k].affect(value); + } } } } + else + { + nlwarning(" Couldn't evaluate expression to affect, expr = %s", expr.c_str()); + } } - else - { - nlwarning(" Couldn't evaluate expression to affect, expr = %s", expr.c_str()); - } - } -}; -REGISTER_ACTION_HANDLER (CAHSet, "set"); + }; + REGISTER_ACTION_HANDLER (CAHSet, "set"); -// ------------------------------------------------------------------------------------------------ -class CAHCopy : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) + // ------------------------------------------------------------------------------------------------ + class CAHCopy : public IActionHandler { - 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)) + public: + virtual void execute (CCtrlBase * /* pCaller */, const string &Params) { - //nlinfo("copying from %s to %s",pNBsrc->getName()->c_str(), pNBdst->getName()->c_str()); + 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 - // Parse all children of the src branch - uint nbLeaves = pNBsrc->countLeaves(); - for (uint i = 0; i < nbLeaves; ++i) + if ((pNBdst != NULL) && (pNBsrc != NULL)) { - 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 + //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) { - pNLdst->setValue64(pNLsrc->getValue64()); + 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()); + //sint32 nVal = pNLsrc->getValue64(); + //nlinfo("set value %d for node %s", nVal, sTmp.c_str()); + } } + return; } - return; - } - // Not branch copy so leaf copy + // 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; + 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()); } - // copy - ipdst.setSInt64 (ipsrc.getSInt64()); - } -}; -REGISTER_ACTION_HANDLER (CAHCopy, "copy"); + }; + REGISTER_ACTION_HANDLER (CAHCopy, "copy"); -// ------------------------------------------------------------------------------------------------ -class CAHResizeW : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &Params) + // ------------------------------------------------------------------------------------------------ + class CAHResizeW : public IActionHandler { - string elt = getParam (Params, "elt"); + public: + virtual void execute (CCtrlBase *pCaller, const string &Params) + { + string elt = getParam (Params, "elt"); - sint32 value; - fromString(getParam(Params, "value"), value); + sint32 value; + fromString(getParam(Params, "value"), value); - sint32 limit; - fromString(getParam(Params, "limit"), limit); + sint32 limit; + fromString(getParam(Params, "limit"), limit); - CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId (pCaller->getId(), elt); - if (pIE == NULL) return; + 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; + 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(); } - 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; - -// 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) + }; + 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; + + // observer to change the container alpha + class CContainerAlphaObserver : public ICDBNode::IPropertyObserver { - if (!On) return; - if (!AlphaChooserTarget) return; - CCDBNodeLeaf *leaf = safe_cast(node); - switch(Target) + public: + bool On; + enum TTargetAlpha { ContentAlpha = 0, BgAlpha, RolloverAlphaContent, RolloverAlphaBG }; + TTargetAlpha Target; + virtual void update(ICDBNode *node) { - 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 (!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; + } } - } -}; + }; -// ------------------------------------------------------------------------------------------------ -class CAHChooseUIAlpha : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) + // ------------------------------------------------------------------------------------------------ + class CAHChooseUIAlpha : public IActionHandler { - 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) + public: + virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) { - _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"); + 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"); - } + } - CAHChooseUIAlpha() - { - _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 */) + CAHChooseUIAlpha() + { + _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 { - if (AlphaChooserTarget) + virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* Params */) { - AlphaChooserTarget->setUseGlobalAlpha(OldUseGlobalAlpha); - AlphaChooserTarget->setContainerAlpha(OldBgAlpha); - AlphaChooserTarget->setContentAlpha(OldContentAlpha); - AlphaChooserTarget->setRolloverAlphaContainer(OldRolloverAlphaBG); - AlphaChooserTarget->setRolloverAlphaContent(OldRolloverAlphaContent); + if (AlphaChooserTarget) + { + AlphaChooserTarget->setUseGlobalAlpha(OldUseGlobalAlpha); + AlphaChooserTarget->setContainerAlpha(OldBgAlpha); + AlphaChooserTarget->setContentAlpha(OldContentAlpha); + AlphaChooserTarget->setRolloverAlphaContainer(OldRolloverAlphaBG); + AlphaChooserTarget->setRolloverAlphaContent(OldRolloverAlphaContent); + } } - } -}; -REGISTER_ACTION_HANDLER (CAHCancelChooseUIAlpha, "cancel_choose_ui_alpha"); + }; + REGISTER_ACTION_HANDLER (CAHCancelChooseUIAlpha, "cancel_choose_ui_alpha"); -// ------------------------------------------------------------------------------------------------ -class CAHUseGlobalAlphaSettings : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* Params */) + // ------------------------------------------------------------------------------------------------ + class CAHUseGlobalAlphaSettings : public IActionHandler { - if (AlphaChooserTarget) + virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* Params */) { - AlphaChooserTarget->setUseGlobalAlpha(!AlphaChooserTarget->isUsingGlobalAlpha()); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER_ALPHA")->setValue64(AlphaChooserTarget->isUsingGlobalAlpha() ? 0 : 1); + if (AlphaChooserTarget) + { + AlphaChooserTarget->setUseGlobalAlpha(!AlphaChooserTarget->isUsingGlobalAlpha()); + NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER_ALPHA")->setValue64(AlphaChooserTarget->isUsingGlobalAlpha() ? 0 : 1); + } } - } -}; -REGISTER_ACTION_HANDLER (CAHUseGlobalAlphaSettings, "use_global_alpha_settings"); + }; + REGISTER_ACTION_HANDLER (CAHUseGlobalAlphaSettings, "use_global_alpha_settings"); -// ------------------------------------------------------------------------------------------------ -class CAHLockUnlock : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) + // ------------------------------------------------------------------------------------------------ + class CAHLockUnlock : 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(); + 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()); } - if (!gc) return; - //gc->setMovable(!gc->isMovable()); - gc->setLocked(!gc->isLocked()); - } -}; -REGISTER_ACTION_HANDLER (CAHLockUnlock, "lock_unlock"); + }; + REGISTER_ACTION_HANDLER (CAHLockUnlock, "lock_unlock"); -// ------------------------------------------------------------------------------------------------ -class CAHSetTransparent : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) + // ------------------------------------------------------------------------------------------------ + class CAHSetTransparent : 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); + 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 (CAHSetTransparent, "set_transparent"); + }; + REGISTER_ACTION_HANDLER (CAHSetTransparent, "set_transparent"); -// ------------------------------------------------------------------------------------------------ -class CAHSetAlpha : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) + // ------------------------------------------------------------------------------------------------ + class CAHSetAlpha : public IActionHandler { - string ui = getParam (Params, "target"); + virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) + { + string ui = getParam (Params, "target"); - uint8 alpha; - fromString(getParam (Params, "alpha"), alpha); + 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); + 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"); + }; + REGISTER_ACTION_HANDLER (CAHSetAlpha, "set_alpha"); -// ------------------------------------------------------------------------------------------------ -class CAHUnlockAllContainer : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) + // ------------------------------------------------------------------------------------------------ + class CAHUnlockAllContainer : public IActionHandler { - const vector &rVMG = CWidgetManager::getInstance()->getAllMasterGroup(); - for (uint32 nMasterGroup = 0; nMasterGroup < rVMG.size(); nMasterGroup++) + virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) { -// const CInterfaceManager::SMasterGroup &rMG = rVMG[nMasterGroup]; - CWidgetManager::getInstance()->getMasterGroup((uint8)nMasterGroup).unlockAllContainers(); + 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"); + }; + 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() + { + CWidgetManager::getInstance()->removeRefOnCtrl (this); + } + + // *************************************************************************** + bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event) { - NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; - if (eds.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::activecalledonparent) + 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) - { - CWidgetManager::getInstance()->setCapturePointerLeft(NULL); - } - if (CWidgetManager::getInstance()->getCapturePointerRight() == this) + if (!((NLGUI::CEventDescriptorActiveCalledOnParent &) eds).getActive()) { - CWidgetManager::getInstance()->setCapturePointerRight(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 } - // NB : don't call return here because derived class may be interested - // in handling event more speciffically } } + return false; } - return false; -} -// *************************************************************************** -bool CCtrlBase::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CViewBase::parse(cur, parentGroup)) - return false; + // *************************************************************************** + bool CCtrlBase::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) + { + if(!CViewBase::parse(cur, parentGroup)) + return false; - CXMLAutoPtr prop; + CXMLAutoPtr prop; - // get static toolTip - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip" ); - if (prop) - { - const char *propPtr = prop; + // get static toolTip + prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip" ); + if (prop) + { + const char *propPtr = prop; + + _ContextHelp = ucstring(propPtr); - _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); + } - if (strlen(propPtr) > 2) + // get dynamic toolTip ActionHandler + prop = (char*) xmlGetProp( cur, (xmlChar*)"on_tooltip" ); + if (prop) { - if ((propPtr[0] == 'u') && (propPtr[1] == 'i')) - _ContextHelp = CI18N::get ((const char *) prop); + _OnContextHelp= (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); + 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; } - // get dynamic toolTip ActionHandler - prop = (char*) xmlGetProp( cur, (xmlChar*)"on_tooltip" ); - if (prop) + // *************************************************************************** + void CCtrlBase::convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS) { - _OnContextHelp= (const char*)prop; + 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; + } + } } - prop = (char*) xmlGetProp( cur, (xmlChar*)"on_tooltip_params" ); - if (prop) + + + // *************************************************************************** + bool CCtrlBase::emptyContextHelp() const { - _OnContextHelpParams= (const char*)prop; + ucstring help; + getContextHelp(help); + std::string sTmp = _OnContextHelp; + return help.empty() && sTmp.empty(); } - // Tooltip parent - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_parent" ); - _ToolTipParent= TTCtrl; - if(prop) + // *************************************************************************** + void CCtrlBase::visit(CInterfaceElementVisitor *visitor) { - 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; + nlassert(visitor); + visitor->visitCtrl(this); + CInterfaceElement::visit(visitor); } - // Tooltip special parent - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_special_parent" ); - _ToolTipSpecialParent= CStringShared(); - if(prop) + // *************************************************************************** + void CCtrlBase::serial(NLMISC::IStream &f) { - _ToolTipSpecialParent= std::string((const char*)prop); + 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 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) + // *************************************************************************** + std::string CCtrlBase::getContextHelpWindowName() const { - 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 "context_help"; } -} - - -// *************************************************************************** -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 @@ -#include "nel/gui/ctrl_draggable.h" +// 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 . + -CCtrlDraggable* CCtrlDraggable::_LastDraggedSheet = NULL; +#include "nel/gui/ctrl_draggable.h" -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() -{ -} + CCtrlScrollBase::CCtrlScrollBase( const TCtorParam ¶m ) : + CCtrlBase( param ) + { + _Target = NULL; + } -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 ); -} + CCtrlScrollBase::~CCtrlScrollBase() + { + } -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 ); + 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 ); + } - return 0; -} + 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 ); -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; + } - 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 ); + } -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() -{ -} + CGroupContainerBase::CGroupContainerBase( const CViewBase::TCtorParam ¶m ) : + CInterfaceGroup( param ) + { + _ContentAlpha = 255; + _ContainerAlpha = 255; + _RolloverAlphaContainer = 0; + _RolloverAlphaContent = 0; + _Locked = false; + _UseGlobalAlpha = true; + } -void CGroupContainerBase::removeAllContainers() -{ - // Necessary because it's supposed to be an abstract class, - // however reflection requires the class to be instantiated. - nlassert( false ); -} + CGroupContainerBase::~CGroupContainerBase() + { + } -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::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::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::setUseGlobalAlpha(bool use) + { + _UseGlobalAlpha = use; + triggerAlphaSettingsChangedAH(); + } -// *************************************************************************** -void CGroupContainerBase::setContentAlpha(uint8 alpha) -{ - _ContentAlpha = alpha; - triggerAlphaSettingsChangedAH(); -} + // *************************************************************************** + void CGroupContainerBase::setContainerAlpha(uint8 alpha) + { + _ContainerAlpha = alpha; + triggerAlphaSettingsChangedAH(); + } -// *************************************************************************** -void CGroupContainerBase::setRolloverAlphaContent(uint8 alpha) -{ - _RolloverAlphaContent = 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(); + } -// *************************************************************************** -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 @@ -#include "nel/gui/group_editbox_base.h" +// 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 . -CGroupEditBoxBase *CGroupEditBoxBase::_CurrSelection = NULL; -CGroupEditBoxBase::CGroupEditBoxBase( const TCtorParam ¶m ) : -CInterfaceGroup( param ) -{ - _RecoverFocusOnEnter = true; -} +#include "nel/gui/group_editbox_base.h" -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"); +namespace NLGUI +{ -// *************************************************************************** -vector CGroupFrame::_DispTypes; + NLMISC_REGISTER_OBJECT(CViewBase, CGroupFrame, std::string, "frame"); -// *************************************************************************** -CGroupFrame::CGroupFrame(const TCtorParam ¶m) -: CInterfaceGroup(param) -{ - _DisplayFrame = true; - _Color = CRGBA(255,255,255,255); - _DispType = 0; - _DisplayFrameDefined= false; - _ColorDefined= false; - _DispTypeDefined= false; -} + // *************************************************************************** + vector CGroupFrame::_DispTypes; -// *************************************************************************** -bool CGroupFrame::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CInterfaceGroup::parse(cur, parentGroup)) - return false; - - // display - CXMLAutoPtr ptr((const char*) xmlGetProp (cur, (xmlChar*)"display")); - _DisplayFrame = true; - _DisplayFrameDefined= false; - if (ptr) + // *************************************************************************** + 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; - } - - // Get the borders texture - _DispTypeDefined= false; - CViewRenderer &rVR = *CViewRenderer::getInstance(); - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"options" ); - CInterfaceOptions *pIO = NULL; + if(!CInterfaceGroup::parse(cur, parentGroup)) + return false; + + // display + CXMLAutoPtr ptr((const char*) xmlGetProp (cur, (xmlChar*)"display")); + _DisplayFrame = true; + _DisplayFrameDefined= false; + if (ptr) + { + _DisplayFrame = convertBool (ptr); + _DisplayFrameDefined= true; + } - if (ptr) - pIO = CWidgetManager::getInstance()->getOptions(ptr); + // color + ptr = (char*) xmlGetProp( cur, (xmlChar*)"color" ); + _Color = CRGBA(255,255,255,255); + _ColorDefined= false; + if (ptr) + { + _Color = convertColor (ptr); + _ColorDefined= true; + } - // 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); - } + // Get the borders texture + _DispTypeDefined= false; + CViewRenderer &rVR = *CViewRenderer::getInstance(); - if (pIO != NULL) - { - _DispTypeDefined= true; + ptr = (char*) xmlGetProp( cur, (xmlChar*)"options" ); + CInterfaceOptions *pIO = NULL; - // 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 (ptr) + pIO = CWidgetManager::getInstance()->getOptions(ptr); - 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; - } + if (pIO != NULL) + { + _DispTypeDefined= true; - return 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()) + { + 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")); + + // 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"); + + // 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; + } -// *************************************************************************** -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; + return true; + } + - // draw the background - sint xId = 0, yId = 0; - for (yId = 0; yId < 3; yId++) + // *************************************************************************** + void CGroupFrame::draw () + { + if (_DisplayFrame) { - for (xId = 0; xId < 3; xId++) + 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++) { - 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 + for (xId = 0; xId < 3; xId++) { - h = _DispTypes[_DispType].BottomBorder; - } + 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); - // 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::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()); -} + // *************************************************************************** + 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); + } -// *************************************************************************** -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" - -using namespace std; - #include "nel/misc/i_xml.h" -NLMISC_REGISTER_OBJECT(CViewBase, CGroupModal, std::string, "modal"); +using namespace std; -// *************************************************************************** -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; -} - -// *************************************************************************** -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; -} + NLMISC_REGISTER_OBJECT(CViewBase, CGroupModal, std::string, "modal"); -// *************************************************************************** -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) - { - _X= _Y= 0; - } - else - { - // change coords - _X= SpawnMouseX+_MouseDeltaX; - _Y= SpawnMouseY+_MouseDeltaY; - } + 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; } - // update group - CGroupFrame::updateCoords(); - // if snap to mouse pos or ForceInsideScreen - if(SpawnOnMousePos || ForceInsideScreen) + // *************************************************************************** + bool CGroupModal::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) { - 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(!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; + } - if(_YReal<0) - { - _Y+= -_YReal; - clipped =true; - } - else + // *************************************************************************** + void CGroupModal::updateCoords () + { + // if snap to mouse pos. + if(SpawnOnMousePos) { - if (!SpawnOnMousePos) - _Y = _MouseDeltaY; + // 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; + } } - if(_YReal+_HReal>_Parent->getH()) - { - _Y-= _YReal+_HReal-_Parent->getH(); - clipped =true; - } - else - { - if ((!SpawnOnMousePos) && (_YReal>=0)) - _Y = _MouseDeltaY; - } + // update group + CGroupFrame::updateCoords(); - if (clipped) + // if snap to mouse pos or ForceInsideScreen + if(SpawnOnMousePos || ForceInsideScreen) { - CGroupFrame::updateCoords(); + 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::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); -} + 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) + // ------------------------------------------------------------------------------------------------ + std::string CInterfaceElement::getShortId() const { - return _Id.substr(last + 1); + std::string::size_type last = _Id.find_last_of(':'); + if (last != std::string::npos) + { + return _Id.substr(last + 1); + } + return _Id; } - return _Id; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - // parse the basic properties - CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"id" )); - if (ptr) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) { - if (parentGroup) + // parse the basic properties + CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"id" )); + if (ptr) { - _Id = ( (CInterfaceElement*)parentGroup )->_Id; + 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); - } + 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); - } + _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*)"posparent" ); + if (ptr) { - string idparent; - if (parentGroup) - idparent = parentGroup->getId() +":"; - else - idparent = "ui:"; - CWidgetManager::parser->addParentPositionAssociation(this, idparent + string((const char*)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") + ptr = (char*) xmlGetProp( cur, (xmlChar*)"sizeparent" ); + if (ptr) { - if (parentGroup) - idparent = parentGroup->getId() +":" + string((const char*)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:" + string((const char*)ptr); + { + if (parentGroup) + idparent = parentGroup->getId(); + } + CWidgetManager::parser->addParentSizeAssociation( this, idparent ); } - else + + ptr = (char*) xmlGetProp (cur, (xmlChar*)"sizeref"); + _SizeRef = 0; + _SizeDivW = 10; + _SizeDivH = 10; + if (ptr) { - if (parentGroup) - idparent = parentGroup->getId(); + 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); } - CWidgetManager::parser->addParentSizeAssociation( this, idparent ); + + 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; + } + + + // ------------------------------------------------------------------------------------------------ + 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); } - ptr = (char*) xmlGetProp (cur, (xmlChar*)"sizeref"); - _SizeRef = 0; - _SizeDivW = 10; - _SizeDivH = 10; - if (ptr) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::parseSizeRef(const char *sizeRefStr, sint32 &sizeRef, sint32 &sizeDivW, sint32 &sizeDivH) { - parseSizeRef(ptr.getDatas()); + 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); - } - - ptr= (char*) xmlGetProp (cur, (xmlChar*)"render_layer"); - if(ptr) fromString((const char*)ptr, _RenderLayer); + _XReal = _X; + _YReal = _Y; + _WReal = getW(); + _HReal = getH(); - ptr= (char*) xmlGetProp (cur, (xmlChar*)"avoid_resize_parent"); - if(ptr) _AvoidResizeParent= convertBool(ptr); - - return true; -} + CInterfaceElement *el = NULL; + // Modif Pos -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::setSizeRef(const std::string &sizeref) -{ - parseSizeRef(sizeref.c_str()); -} + if (_ParentPos != NULL) + el = _ParentPos; + else + el = _Parent; -// ------------------------------------------------------------------------------------------------ -std::string CInterfaceElement::getSizeRefAsString() const -{ - return "IMPLEMENT ME!"; -} + if (el == NULL) + return; -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::parseSizeRef(const char *sizeRefStr) -{ - parseSizeRef(sizeRefStr, _SizeRef, _SizeDivW, _SizeDivH); -} + _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; -// ------------------------------------------------------------------------------------------------ -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; - } + // Modif Size - if ((*seekPtr=='h')||(*seekPtr=='H')) + if (_ParentSize != NULL) { - sizeRef |= 2; - nWhat = 2; + el = _ParentSize; } - - if ((*seekPtr>='1')&&(*seekPtr<='9')) + else { - if (nWhat != 0) - { - if (nWhat == 1) - sizeDivW = *seekPtr-'0'; - if (nWhat == 2) - sizeDivH = *seekPtr-'0'; - } + if (_ParentPos != NULL) + el = _ParentPos; + else + el = _Parent; } - ++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; - if (el == NULL) - return; + if (_SizeRef&1) + _WReal += _SizeDivW * el->_WReal / 10; - _XReal += el->_XReal; - _YReal += el->_YReal; + if (_SizeRef&2) + _HReal += _SizeDivH * el->_HReal / 10; - 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; + 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; + } - // Modif Size - if (_ParentSize != NULL) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::getCorner(sint32 &px, sint32 &py, THotSpot hs) { - el = _ParentSize; + 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) { - if (_ParentPos != NULL) - el = _ParentPos; - else - el = _Parent; + _X += dx; + _Y += dy; + invalidateCoords(); } - 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::resizeBR (sint32 sizeW, sint32 sizeH) + { + uint32 i = i / 0; + THotSpot hs = _PosRef; -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::move (sint32 dx, sint32 dy) -{ - _X += dx; - _Y += dy; - invalidateCoords(); -} + 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; + } -// ------------------------------------------------------------------------------------------------ -/*void CInterfaceElement::resizeBR (sint32 sizeW, sint32 sizeH) -{ - uint32 i = i / 0; - THotSpot hs = _PosRef; + 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; + } - sint32 dw = sizeW - _W; - sint32 dh = sizeH - _H; + // DO NOT TREAT THE MIDDLE HOTSPOT CASE - sint32 snap = _Snap; - nlassert(snap > 0); + invalidateCoords(); + }*/ - 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 ? + // ------------------------------------------------------------------------------------------------ + /*void CInterfaceElement::snapSize() { - sint32 newW = dw + _W; + sint32 snap = _Snap; + nlassert(snap > 0); if (snap > 1) - newW -= newW % snap; - _W = newW; - } - - // DO NOT TREAT THE MIDDLE HOTSPOT CASE - - invalidateCoords(); -}*/ + { + _W = _W - (_W % snap); + _H = _H - (_H % snap); + } + }*/ -// ------------------------------------------------------------------------------------------------ -/*void CInterfaceElement::snapSize() -{ - sint32 snap = _Snap; - nlassert(snap > 0); - if (snap > 1) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::setW (sint32 w) { - _W = _W - (_W % snap); - _H = _H - (_H % snap); + _W = w; + // sint32 snap = _Snap; + // nlassert(snap > 0); + // if (snap > 1) + // { + // _W = _W - (_W % 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) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::setH (sint32 h) { - parent= parent->getParent(); - depth++; + _H = h; + // sint32 snap = _Snap; + // nlassert(snap > 0); + // if (snap > 1) + // { + // _H = _H - (_H % snap); + // } } - 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) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CInterfaceElement::getRootWindow () { - rIP.readSInt64 (defVal.c_str(), _Id+":"+prop); + if (_Parent == NULL) + return NULL; + if (_Parent->getParent() == NULL) + return dynamic_cast(this); + return _Parent->getRootWindow(); } - else + + // ------------------------------------------------------------------------------------------------ + uint CInterfaceElement::getParentDepth() const { - if ( isdigit(*val) || *val=='-') + uint depth= 0; + CInterfaceGroup *parent= _Parent; + while(parent!=NULL) { - rIP.readSInt64 (val, _Id+":"+prop); - return; + parent= parent->getParent(); + depth++; } + return depth; + } - sint32 decal = 0; - if (val[0] == ':') - decal = 1; - if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) + // ------------------------------------------------------------------------------------------------ + 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 (val+decal, _Id+":"+prop); - return; + rIP.readSInt64 (defVal.c_str(), _Id+":"+prop); } else { - string sTmp; - CInterfaceElement *pIEL = this; + if ( isdigit(*val) || *val=='-') + { + rIP.readSInt64 (val, _Id+":"+prop); + return; + } - while (pIEL != NULL) + sint32 decal = 0; + if (val[0] == ':') + decal = 1; + if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + rIP.readSInt64 (val+decal, _Id+":"+prop); + return; + } + else + { + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) { - rIP.readSInt64 (sTmp.c_str(), _Id+":"+prop); - return; + 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(); } - pIEL = pIEL->getParent(); - } - rIP.readSInt64 (val+decal, _Id+":"+prop); + rIP.readSInt64 (val+decal, _Id+":"+prop); + } } } -} -// ------------------------------------------------------------------------------------------------ -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 + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::relativeSInt32Read (CInterfaceProperty &rIP, const string &prop, const char *val, + const string &defVal) { - 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) + if (val == NULL) { - rIP.readSInt32 (val+decal, _Id+":"+prop); - return; + rIP.readSInt32 (defVal.c_str(), _Id+":"+prop); } else { - string sTmp; - CInterfaceElement *pIEL = this; + if ( isdigit(*val) || *val=='-') + { + rIP.readSInt32 (val, _Id+":"+prop); + return; + } - while (pIEL != NULL) + sint32 decal = 0; + if (val[0] == ':') + decal = 1; + if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + rIP.readSInt32 (val+decal, _Id+":"+prop); + return; + } + else + { + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) { - rIP.readSInt32 (sTmp.c_str(), _Id+":"+prop); - return; + 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(); } - pIEL = pIEL->getParent(); - } - rIP.readSInt32 (val+decal, _Id+":"+prop); + 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 + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::relativeBoolRead (CInterfaceProperty &rIP, const string &prop, const char *val, + const string &defVal) { - sint32 decal = 0; - if (val[0] == ':') - decal = 1; - if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) + if (val == NULL) { - rIP.readBool (val+decal, _Id+":"+prop); - return; + rIP.readBool (defVal.c_str(), _Id+":"+prop); } else { - string sTmp; - CInterfaceElement *pIEL = this; - - while (pIEL != NULL) + sint32 decal = 0; + if (val[0] == ':') + decal = 1; + if (NLGUI::CDBManager::getInstance()->getDbProp(val+decal, false) != NULL) { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + rIP.readBool (val+decal, _Id+":"+prop); + return; + } + else + { + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) { - rIP.readBool (sTmp.c_str(), _Id+":"+prop); - return; + 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(); } - pIEL = pIEL->getParent(); - } - rIP.readBool (val+decal, _Id+":"+prop); + 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) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::relativeRGBARead(CInterfaceProperty &rIP,const std::string &prop,const char *val,const std::string &defVal) { - 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) + if (val == NULL) { - rIP.readRGBA (val+decal, _Id+":"+prop); - return; + rIP.readRGBA (defVal.c_str(), _Id+":"+prop); } else { - string sTmp; - CInterfaceElement *pIEL = this; + if ( isdigit(*val) || *val=='-') + { + rIP.readRGBA (val, _Id+":"+prop); + return; + } - while (pIEL != NULL) + 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 { - sTmp = pIEL->getId()+":"+string(val+decal); - if (NLGUI::CDBManager::getInstance()->getDbProp(sTmp, false) != NULL) + string sTmp; + CInterfaceElement *pIEL = this; + + while (pIEL != NULL) { - rIP.readRGBA (sTmp.c_str(), _Id+":"+prop); - return; + 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(); } - pIEL = pIEL->getParent(); - } - rIP.readRGBA (val+decal, _Id+":"+prop); + 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) ) + // ------------------------------------------------------------------------------------------------ + THotSpot CInterfaceElement::convertHotSpot (const char *ptr) { - return Hotspot_ML; - } - else if ( !strnicmp(ptr,"MM",2) ) - { - return Hotspot_MM; - } - else if ( !strnicmp(ptr,"MR",2) ) - { - return Hotspot_MR; + 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; } - else if ( !strnicmp(ptr,"BL",2) ) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::convertHotSpotCouple (const char *ptr, THotSpot &parentPosRef, THotSpot &posRef) { - return Hotspot_BL; + 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); } - else if ( !strnicmp(ptr,"BM",2) ) + + // ------------------------------------------------------------------------------------------------ + NLMISC::CRGBA CInterfaceElement::convertColor (const char *ptr) { - return Hotspot_BM; + return NLMISC::CRGBA::stringToRGBA(ptr); } - else if ( !strnicmp(ptr,"BR",2) ) + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::convertBool (const char *ptr) { - return Hotspot_BR; + string str= ptr; + NLMISC::strlwr(str); + return str=="true"?true:false; } - 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::CVector CInterfaceElement::convertVector (const char *ptr) + { + float x = 0.0f, y = 0.0f, z = 0.0f; -// ------------------------------------------------------------------------------------------------ -NLMISC::CRGBA CInterfaceElement::convertColor (const char *ptr) -{ - return NLMISC::CRGBA::stringToRGBA(ptr); -} + sscanf (ptr, "%f %f %f", &x, &y, &z); -// ------------------------------------------------------------------------------------------------ -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; + return CVector(x,y,z); + } - sscanf (ptr, "%f %f %f", &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); + } + } + } - return CVector(x,y,z); -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::convertPixelsOrRatio(const char *ptr, sint32 &pixels, float &ratio) -{ - std::string value = ptr; - if (!value.empty()) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::addLink(CInterfaceLink *link) { - if (value[value.size() - 1] == '%') + nlassert(link != NULL); + if (!_Links) { - value.resize(value.size() - 1); - fromString(value, ratio); - ratio /= 100.f; - clamp(ratio, 0.f, 1.f); + _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 { - fromString(value, pixels); + _Links->push_back(linkPtr); } } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::addLink(CInterfaceLink *link) -{ - nlassert(link != NULL); - if (!_Links) + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::removeLink(CInterfaceLink *link) { - _Links = new TLinkVect; + 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; + } } - TLinkSmartPtr linkPtr(link); - TLinkVect::const_iterator it = std::find(_Links->begin(), _Links->end(), linkPtr); - if (it != _Links->end()) + + + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CInterfaceElement::getMasterGroup() const { - // 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"); + if(getParent()==NULL) + return const_cast(this); + else + return getParent()->getMasterGroup(); } - else + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CInterfaceElement::getParentContainer() { - _Links->push_back(linkPtr); - } -} + CInterfaceElement *parent = this; + while (parent) + { + CInterfaceGroup *gc = dynamic_cast< CInterfaceGroup* >( parent ); + if( ( gc != NULL ) && gc->isGroupContainer() ) + return gc; + parent = parent->getParent(); + } + return NULL; + } -// ------------------------------------------------------------------------------------------------ -void CInterfaceElement::removeLink(CInterfaceLink *link) -{ - nlassert(link != NULL); - if (!_Links) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::isIn(sint x, sint y) const { - nlwarning("No link added"); - return; + return (x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal+ _HReal)); } - TLinkVect::iterator it = std::find(_Links->begin(), _Links->end(), TLinkSmartPtr(link)); - if (it == _Links->end()) + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::isIn(sint x, sint y, uint width, uint height) const { - nlwarning("Unknown link"); - return; + return (x + (sint) width) >= _XReal && + (y + (sint) height) > _YReal && + x < (_XReal + _WReal) && + y <= (_YReal + _HReal); } - _Links->erase(it); // kill the smart ptr, maybe deleting the link. - if (_Links->empty()) + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceElement::isIn(const CInterfaceElement &other) const { - delete _Links; - _Links = NULL; + return isIn(other._XReal, other._YReal, other._WReal, other._HReal); } -} + // ------------------------------------------------------------------------------------------------ + void CInterfaceElement::setActive (bool state) + { + if (_Active != state) + { + _Active = state; + invalidateCoords(); + } + } -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CInterfaceElement::getMasterGroup() const -{ - if(getParent()==NULL) - return const_cast(this); - else - return getParent()->getMasterGroup(); -} -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CInterfaceElement::getParentContainer() -{ - CInterfaceElement *parent = this; - while (parent) + // *************************************************************************** + void CInterfaceElement::invalidateCoords(uint8 numPass) { - CInterfaceGroup *gc = dynamic_cast< CInterfaceGroup* >( parent ); - if( ( gc != NULL ) && gc->isGroupContainer() ) - return gc; + // 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(); + } + } - parent = parent->getParent(); + // invalidate the "root group" + if(parent) + { + uint8 &val= static_cast(parent)->_InvalidCoords; + val= max(val, numPass); + } } - 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) + // *************************************************************************** + void CInterfaceElement::checkCoords() { - _Active = state; - invalidateCoords(); } -} + // *************************************************************************** + 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::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::resetInvalidCoords() { - parent= dynamic_cast(this); + _InvalidCoords= 0; } - else + + // *************************************************************************** + void CInterfaceElement::updateAllLinks() { - // parent is the root group when is grandFather is NULL - while( parent->getParent()->getParent()!=NULL ) + if (_Links) { - parent= parent->getParent(); + for(TLinkVect::iterator it = _Links->begin(); it != _Links->end(); ++it) + { + (*it)->update(); + } } } - // invalidate the "root group" - if(parent) + // *************************************************************************** + void CInterfaceElement::copyOptionFrom(const CInterfaceElement &other) { - uint8 &val= static_cast(parent)->_InvalidCoords; - val= max(val, numPass); - } -} + _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::checkCoords() -{ -} - -// *************************************************************************** -bool CInterfaceElement::isSonOf(const CInterfaceElement *other) const -{ - const CInterfaceElement *currElem = this; - do + // *************************************************************************** + void CInterfaceElement::center() { - if (currElem == other) return true; - currElem = currElem->_Parent; + // center the pc + CViewRenderer &vr = *CViewRenderer::getInstance(); + uint32 sw, sh; + vr.getScreenSize(sw, sh); + setX(sw / 2 - getWReal() / 2); + setY(sh / 2 + getHReal() / 2); } - while (currElem); - return false; -} -// *************************************************************************** -void CInterfaceElement::resetInvalidCoords() -{ - _InvalidCoords= 0; -} - -// *************************************************************************** -void CInterfaceElement::updateAllLinks() -{ - if (_Links) + // *************************************************************************** + void CInterfaceElement::renderWiredQuads(TRenderWired type, const std::string &uiFilter) { - for(TLinkVect::iterator it = _Links->begin(); it != _Links->end(); ++it) + 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))) { - (*it)->update(); + 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::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::drawHotSpot(THotSpot hs, CRGBA col) { - 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; + 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.drawWiredQuad(_XReal, _YReal, _WReal, _HReal); - drawHotSpot(_PosRef, CRGBA::Red); - if (_Parent) _Parent->drawHotSpot(_ParentPosRef, CRGBA::Blue); - } -} + vr.drawFilledQuad(px - radius, py - radius, radius * 2, radius * 2, col); -// *************************************************************************** -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) + + // *************************************************************************** + void CInterfaceElement::invalidateContent() { - py = _YReal + _HReal / 2; + CInterfaceElement *elm = this; + while (elm) + { + // Call back + elm->onInvalidateContent(); + + // Get the parent + elm = elm->getParent(); + } } - else + + // *************************************************************************** + void CInterfaceElement::visit(CInterfaceElementVisitor *visitor) { - py = _YReal + _HReal - radius; + nlassert(visitor); + visitor->visit(this); } - // - if (hs & Hotspot_xL) + + // *************************************************************************** + void CInterfaceElement::serialConfig(NLMISC::IStream &f) { - px = _XReal + radius; + if (f.isReading()) + { + throw NLMISC::ENewerStream(f); + nlassert(0); + } } - else if (hs & Hotspot_xM) + + // *************************************************************************** + void CInterfaceElement::onFrameUpdateWindowPos(sint dx, sint dy) { - px = _XReal + _WReal / 2; + _XReal+= dx; + _YReal+= dy; } - else + + // *************************************************************************** + void CInterfaceElement::dummySet(sint32 /* value */) { - px = _XReal + _WReal - radius; + nlwarning("Element can't be written."); } - CViewRenderer &vr = *CViewRenderer::getInstance(); - vr.drawFilledQuad(px - radius, py - radius, radius * 2, radius * 2, col); -} - -// *************************************************************************** -void CInterfaceElement::invalidateContent() -{ - CInterfaceElement *elm = this; - while (elm) + // *************************************************************************** + void CInterfaceElement::dummySet(const std::string &/* value */) { - // Call back - elm->onInvalidateContent(); - - // Get the parent - elm = elm->getParent(); + nlwarning("Element can't be written."); } -} - -// *************************************************************************** -void CInterfaceElement::visit(CInterfaceElementVisitor *visitor) -{ - nlassert(visitor); - visitor->visit(this); -} -// *************************************************************************** -void CInterfaceElement::serialConfig(NLMISC::IStream &f) -{ - if (f.isReading()) + // *************************************************************************** + int CInterfaceElement::luaUpdateCoords(CLuaState &ls) { - throw NLMISC::ENewerStream(f); - nlassert(0); + CLuaIHM::checkArgCount(ls, "updateCoords", 0); + updateCoords(); + return 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()) + // *************************************************************************** + int CInterfaceElement::luaInvalidateCoords(CLuaState &ls) { - setParentPosRef(newParentPosRef); - setPosRef(newPosRef); + CLuaIHM::checkArgCount(ls, "updateCoords", 0); invalidateCoords(); + return 0; } - return 0; -} + // *************************************************************************** + int CInterfaceElement::luaInvalidateContent(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "invalidateContent", 0); + invalidateContent(); + return 0; + } -// *************************************************************************** -int CInterfaceElement::luaSetParentPos(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "setParentPos", 1); - CInterfaceElement *ie = CLuaIHM::getUIOnStack(ls, 1); - if(ie) + // *************************************************************************** + int CInterfaceElement::luaCenter(CLuaState &ls) { - setParentPos(ie); + CLuaIHM::checkArgCount(ls, "center", 0); + center(); + return 0; } - 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); -// *************************************************************************** -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()) + // if different from current, set,a nd invalidate coords + if(newParentPosRef!=getParentPosRef() || newPosRef!=getPosRef()) { - dupStream.invert(); + setParentPosRef(newParentPosRef); + setPosRef(newPosRef); + invalidateCoords(); } - 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); + + return 0; } - catch(const NLMISC::EStream &) + + // *************************************************************************** + int CInterfaceElement::luaSetParentPos(CLuaState &ls) { - // no-op -> caller has to handle the failure because NULL will be returned + CLuaIHM::checkArgCount(ls, "setParentPos", 1); + CInterfaceElement *ie = CLuaIHM::getUIOnStack(ls, 1); + if(ie) + { + setParentPos(ie); + } + return 0; } - // - _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 + // *************************************************************************** + CInterfaceElement *CInterfaceElement::clone() { - ahName = CAHManager::getInstance()->getActionHandlerName(ah); - f.serial(ahName); + 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) +namespace NLGUI +{ -// ------------------------------------------------------------------------------------------------ -NLMISC_REGISTER_OBJECT(CViewBase, CInterfaceGroup, std::string, "interface_group"); + REGISTER_UI_CLASS(CInterfaceGroup) -CInterfaceGroup::CInterfaceGroup(const TCtorParam ¶m) : CCtrlBase(param) -{ - _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 -} - - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setIdRecurse(const std::string &id) -{ - CCtrlBase::setIdRecurse(id); - for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) - { - (*it)->setIdRecurse((*it)->getShortId()); - } - 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) + // ------------------------------------------------------------------------------------------------ + NLMISC_REGISTER_OBJECT(CViewBase, CInterfaceGroup, std::string, "interface_group"); + + 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 } -} -// ------------------------------------------------------------------------------------------------ -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) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setIdRecurse(const std::string &id) { - (*ctrlIt)->handleEvent(desc); + CCtrlBase::setIdRecurse(id); + for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) + { + (*it)->setIdRecurse((*it)->getShortId()); + } + 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::setActive(bool state) -{ - if(state != getActive()) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::notifyActiveCalled(const NLGUI::CEventDescriptorActiveCalledOnParent &desc) { - CCtrlBase::setActive(state); - if (_AHOnActive != NULL && state) + // notify children that the 'active' state of this group has changed + for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) { - CAHManager::getInstance()->runActionHandler (_AHOnActive, this, _AHOnActiveParams); + (*it)->handleEvent(desc); } - if (_AHOnDeactive != NULL && !state) + for(std::vector::iterator ctrlIt = _Controls.begin(); ctrlIt != _Controls.end(); ++ctrlIt) { - CAHManager::getInstance()->runActionHandler (_AHOnDeactive, this, _AHOnDeactiveParams); + (*ctrlIt)->handleEvent(desc); } + } - notifyActiveCalled(NLGUI::CEventDescriptorActiveCalledOnParent(state)); + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setActive(bool state) + { + if(state != getActive()) + { + CCtrlBase::setActive(state); + if (_AHOnActive != NULL && state) + { + 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()) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup::~CInterfaceGroup() { - 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(); + // 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::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()) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearViews() { - 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(); + // 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::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()) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearControls() { - 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(); + // 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(); + } } -} -// ------------------------------------------------------------------------------------------------ -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++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearGroups() { - CCtrlBase *pCB = *itc; - CCtrlScrollBase *pSB = dynamic_cast(pCB); - if (pSB != NULL) + // 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()) { - if (pSB->getTarget() == target) - { - pSB->moveTrackY(dy); - return true; - } + 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(); } } - 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++) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::moveSBTrackY (CInterfaceGroup *target, sint32 dy) { - CCtrlBase *pCB = *itc; - CCtrlScrollBase *pSB = dynamic_cast(pCB); - if (pSB != NULL) + // Look if there is a vertical scrollbar with this target attached ... + vector::iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) { - if (pSB->getTarget() == target) + CCtrlBase *pCB = *itc; + CCtrlScrollBase *pSB = dynamic_cast(pCB); + if (pSB != NULL) { - pSB->moveTargetY(dy); - return true; + if (pSB->getTarget() == target) + { + pSB->moveTrackY(dy); + return true; + } } } + return false; } - return false; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::setPriority(uint8 nprio) -{ - if (nprio != _Priority) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::moveSBTargetY(CInterfaceGroup *target,sint32 dy) { - CWidgetManager::getInstance()->setWindowPriority(this, nprio); + // 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; } -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - if ( !CCtrlBase::parse(cur,parentGroup) ) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setPriority(uint8 nprio) { - nlinfo ("cannot parse InterfaceElementLocalisable part"); - return false; + if (nprio != _Priority) + { + CWidgetManager::getInstance()->setWindowPriority(this, nprio); + } } - //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::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup) { - _Overlappable= convertBool(ptr); - } + if ( !CCtrlBase::parse(cur,parentGroup) ) + { + nlinfo ("cannot parse InterfaceElementLocalisable part"); + return false; + } - ptr = (char*) xmlGetProp( cur, (xmlChar*)"escapable" ); - if(ptr) _Escapable= convertBool(ptr); + //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" )); - // 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); + ptr = (char*) xmlGetProp( cur, (xmlChar*)"overlappable" ); + if(ptr) + { + _Overlappable= convertBool(ptr); + } - // 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*)"escapable" ); + if(ptr) _Escapable= convertBool(ptr); - ptr = (char*) xmlGetProp( cur, (xmlChar*)"max_sizeparent" ); - if (ptr) - { - string idparent = ptr; - idparent = NLMISC::strlwr(idparent); - if (idparent != "parent") + // determine if the group must be sized according to his sons. + ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_w" ); + if(ptr) { - if (parentGroup) - idparent = parentGroup->getId() +":" + string((const char*)ptr); - else - idparent = "ui:" + string((const char*)ptr); + _ResizeFromChildW= convertBool(ptr); } - else + ptr = (char*) xmlGetProp( cur, (xmlChar*)"child_resize_h" ); + if(ptr) { - if (parentGroup) - idparent = parentGroup->getId(); + _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); } - 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); + 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); + } - // Each window (modal and groupContainer) can be validated by Enter. if "" => no op. - CAHManager::getInstance()->parseAH(cur, "on_enter", "on_enter_params", _AHOnEnter, _AHOnEnterParams); + // 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); - ptr = (char*) xmlGetProp( cur, (xmlChar*)"win_priority" ); - if(ptr) NLMISC::fromString((const char*)ptr, _Priority); + // 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*)"use_cursor" ); - if(ptr) _UseCursor= convertBool(ptr); + ptr = (char*) xmlGetProp( cur, (xmlChar*)"win_priority" ); + if(ptr) NLMISC::fromString((const char*)ptr, _Priority); - // 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); + 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; -} + // 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++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::parseMaxSizeRef(const char *ptr) { - CInterfaceGroup *pIG = *itg; - Mem += pIG->getMemory(); - }*/ + parseSizeRef(ptr, _GroupSizeRef, _SizeDivW, _SizeDivH); + } - for (vector::const_iterator itv = _Views.begin() ; itv != _Views.end(); itv++) + // ------------------------------------------------------------------------------------------------ + uint32 CInterfaceGroup::getMemory () { - CViewBase *pVB = *itv; - Mem += pVB->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; } - for (vector::const_iterator itc = _Controls.begin() ; itc != _Controls.end(); itc++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addToEltOrder(CViewBase *view, sint order) { - CCtrlBase* ctrl = *itc; - Mem += ctrl->getMemory(); + if (!view) return; + if (order == -1) + { + _EltOrder.push_back(view); + } + else + { + if (order > (sint) _EltOrder.size()) return; + _EltOrder.insert(_EltOrder.begin() + order, view); + } } - return Mem; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addToEltOrder(CViewBase *view, sint order) -{ - if (!view) return; - if (order == -1) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addView (CViewBase *child, sint eltOrder /*= -1*/) { - _EltOrder.push_back(view); + if (!child) + { + nlwarning(" : tried to add a NULL view"); + return; + } + _Views.push_back(child); + addToEltOrder(child, eltOrder); + + // elt callBack. + child->onAddToGroup(); } - else + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addCtrl (CCtrlBase *child, sint eltOrder /*= -1*/) { - if (order > (sint) _EltOrder.size()) return; - _EltOrder.insert(_EltOrder.begin() + order, view); + if (!child) + { + nlwarning(" : tried to add a NULL ctrl"); + return; + } + _Controls.push_back(child); + addToEltOrder(child, eltOrder); + + // elt callBack. + child->onAddToGroup(); } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addView (CViewBase *child, sint eltOrder /*= -1*/) -{ - if (!child) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addGroup (CInterfaceGroup *child, sint eltOrder /*= -1*/) { - nlwarning(" : tried to add a NULL view"); - return; - } - _Views.push_back(child); - addToEltOrder(child, eltOrder); + if (!child) + { + nlwarning(" : tried to add a NULL group"); + return; + } + _ChildrenGroups.push_back(child); + addToEltOrder(child, eltOrder); - // elt callBack. - child->onAddToGroup(); -} + // elt callBack. + child->onAddToGroup(); + } -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addCtrl (CCtrlBase *child, sint eltOrder /*= -1*/) -{ - if (!child) + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaAddGroup (CLuaState &ls) { - nlwarning(" : tried to add a NULL ctrl"); - return; + 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; } - _Controls.push_back(child); - addToEltOrder(child, eltOrder); + // ------------------------------------------------------------------------------------------------ + // 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; - // elt callBack. - child->onAddToGroup(); -} + string::size_type posid = idTmp.rfind (":"); + if (posid == string::npos) + { + posid = 0; + tokid = idTmp; + } + else + { + tokid = idTmp.substr (posid+1); + } -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::addGroup (CInterfaceGroup *child, sint eltOrder /*= -1*/) -{ - if (!child) + 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) { - nlwarning(" : tried to add a NULL group"); - return; + 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; } - _ChildrenGroups.push_back(child); - addToEltOrder(child, eltOrder); - // elt callBack. - child->onAddToGroup(); -} + // ------------------------------------------------------------------------------------------------ + 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; + } -// ------------------------------------------------------------------------------------------------ -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) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup*CInterfaceGroup::getGroup (const std::string &id) const { - string tokid, toklid; + 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; + } - string::size_type posid = idTmp.rfind (":"); - if (posid == string::npos) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delView (CViewBase *child, bool dontDelete /* = false*/) + { + for (sint32 i = 0; i < (sint32)_Views.size(); ++i) { - posid = 0; - tokid = idTmp; + if (_Views[i] == child) + { + if (!dontDelete) delete _Views[i]; + _Views.erase(_Views.begin()+i); + delEltOrder (child); + return true; + } } - else + return false; + } + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delCtrl (CCtrlBase *child, bool dontDelete /* = false*/) + { + for (sint32 i = 0; i < (sint32)_Controls.size(); ++i) { - tokid = idTmp.substr (posid+1); + if (_Controls[i] == child) + { + if (!dontDelete) delete _Controls[i]; + _Controls.erase(_Controls.begin()+i); + delEltOrder (child); + return true; + } } + return false; + } - string::size_type poslid = lidTmp.rfind (":"); - if (poslid == string::npos) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delGroup (CInterfaceGroup *child, bool dontDelete /* = false*/) + { + for (sint32 i = 0; i < (sint32)_ChildrenGroups.size(); ++i) { - poslid = 0; - toklid = lidTmp; + if (_ChildrenGroups[i] == child) + { + if (!dontDelete) delete _ChildrenGroups[i]; + _ChildrenGroups.erase(_ChildrenGroups.begin()+i); + delEltOrder (child); + return true; + } } - else + return false; + } + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaDelGroup (CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::delTab", 1); + CInterfaceGroup * group = dynamic_cast(CLuaIHM::getUIOnStack(ls, 1)); + if(group) { - toklid = lidTmp.substr (poslid+1); + delGroup(group); } + return 0; + } - if (tokid != toklid) - return false; + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaGetNumGroups(CLuaState &ls) + { + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getNumGroups", 0); + ls.push((double) _ChildrenGroups.size()); + return 1; + } - if (posid > 0) - idTmp = idTmp.substr (0, posid); - else - idTmp = ""; + // ------------------------------------------------------------------------------------------------ + 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; + } - if (poslid > 0) - lidTmp = lidTmp.substr (0, poslid); - else - lidTmp = ""; + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::delEltOrder (CViewBase *pElt) + { + for (sint32 i = 0; i < (sint32)_EltOrder.size(); ++i) + { + if (_EltOrder[i] == pElt) + { + _EltOrder.erase (_EltOrder.begin()+i); + return; + } + } } - return true; -} -// ------------------------------------------------------------------------------------------------ -CViewBase* CInterfaceGroup::getView (const std::string &id) -{ - vector::const_iterator itv; - for (itv = _Views.begin(); itv != _Views.end(); ++itv) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delView (const std::string &id, bool dontDelete /* = false*/) { - CViewBase *pVB = (*itv); - if (reverseCheckPath(id, pVB->getId())) - return *itv; + return delView(getView(id), dontDelete); } - // search in sons - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delCtrl (const std::string &id, bool dontDelete /* = false*/) { - CViewBase* view = (*itg)->getView(id); - if (view) - return view; + return delCtrl(getCtrl(id), dontDelete); } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -CCtrlBase* CInterfaceGroup::getCtrl (const std::string &id) -{ - vector::const_iterator itv; - for (itv = _Controls.begin(); itv != _Controls.end(); ++itv) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::delGroup (const std::string &id, bool dontDelete /* = false*/) { - CCtrlBase *pCB = (*itv); - if (reverseCheckPath(id, pCB->getId())) - return *itv; + return delGroup(getGroup(id), dontDelete); } - // search in sons - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) + + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::isChildGroup(const CInterfaceGroup *group) const { - CCtrlBase*pCtrl = (*itg)->getCtrl (id); - if (pCtrl) - return pCtrl; + return std::find(_ChildrenGroups.begin(), _ChildrenGroups.end(), group) != _ChildrenGroups.end(); } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup*CInterfaceGroup::getGroup (const std::string &id) const -{ - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end();itg++) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::handleEvent (const NLGUI::CEventDescriptor &event) { - CInterfaceGroup *pIG = (*itg); - if (reverseCheckPath(id, pIG->getId())) - return *itg; + if (CCtrlBase::handleEvent(event)) return true; + if (!_Active) + return 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; } - // search in sons - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); ++itg) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::executeControl (const std::string &/* sControlName */) { - CInterfaceGroup *pCtrl = (*itg)->getGroup (id); - if (pCtrl) - return pCtrl; + // bool taken = false; + // CCtrlBase *pIC = getCtrl (sControlName); + // if (pIC != NULL) + // pIC->callback(taken); } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delView (CViewBase *child, bool dontDelete /* = false*/) -{ - for (sint32 i = 0; i < (sint32)_Views.size(); ++i) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::draw () { - if (_Views[i] == child) + sint32 oldSciX, oldSciY, oldSciW, oldSciH; + makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); + + // Display sons only if not total clipped + CViewRenderer &rVR = *CViewRenderer::getInstance(); + if( !rVR.isClipWindowEmpty() ) { - if (!dontDelete) delete _Views[i]; - _Views.erase(_Views.begin()+i); - delEltOrder (child); - return true; + // 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); } - return false; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delCtrl (CCtrlBase *child, bool dontDelete /* = false*/) -{ - for (sint32 i = 0; i < (sint32)_Controls.size(); ++i) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::drawNoClip() { - if (_Controls[i] == child) + // Display sons only if not total clipped + CViewRenderer &rVR = *CViewRenderer::getInstance(); + if( !rVR.isClipWindowEmpty() ) { - if (!dontDelete) delete _Controls[i]; - _Controls.erase(_Controls.begin()+i); - delEltOrder (child); - return true; + // Draw all decorative elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pVB = *ite; + if (pVB->getActive()) + pVB->draw(); + } } } - return false; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delGroup (CInterfaceGroup *child, bool dontDelete /* = false*/) -{ - for (sint32 i = 0; i < (sint32)_ChildrenGroups.size(); ++i) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::renderWiredQuads(CInterfaceElement::TRenderWired type, const std::string &uiFilter) { - if (_ChildrenGroups[i] == child) + 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 (!dontDelete) delete _ChildrenGroups[i]; - _ChildrenGroups.erase(_ChildrenGroups.begin()+i); - delEltOrder (child); - return true; + if (*it) (*it)->renderWiredQuads(type, uiFilter); } + restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); } - return false; -} -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaDelGroup (CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::delTab", 1); - CInterfaceGroup * group = dynamic_cast(CLuaIHM::getUIOnStack(ls, 1)); - if(group) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::drawElement (CViewBase *el) { - delGroup(group); + sint32 oldSciX, oldSciY, oldSciW, oldSciH; + makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); + + if(el) + el->draw(); + + restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); } - return 0; -} -// ------------------------------------------------------------------------------------------------ -int CInterfaceGroup::luaGetNumGroups(CLuaState &ls) -{ - CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getNumGroups", 0); - ls.push((double) _ChildrenGroups.size()); - return 1; -} + // ------------------------------------------------------------------------------------------------ + 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(); + } -// ------------------------------------------------------------------------------------------------ -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()) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::executeLuaScriptOnDraw() { - CLuaIHM::fails(ls, "getGroup : try to index group %s, but there are only %d son groups", ls.toString(1), (int) _ChildrenGroups.size()); + // If some LUA script attached to me, execute it + if(!_LUAOnDraw.empty()) + CAHManager::getInstance()->runActionHandler("lua", this, _LUAOnDraw); + } - CLuaIHM::pushUIOnStack(ls, _ChildrenGroups[index]); - return 1; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::delEltOrder (CViewBase *pElt) -{ - for (sint32 i = 0; i < (sint32)_EltOrder.size(); ++i) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::doUpdateCoords() { - if (_EltOrder[i] == pElt) + _MaxWReal = _MaxW; + _MaxHReal = _MaxH; + + CInterfaceElement *el = NULL; + + if (_ParentSizeMax != NULL) { - _EltOrder.erase (_EltOrder.begin()+i); - return; + el = _ParentSizeMax; + } + else + { + if (_ParentSize != NULL) + { + el = _ParentSize; + } + else + { + if (_ParentPos != NULL) + el = _ParentPos; + else + el = _Parent; + } } - } -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delView (const std::string &id, bool dontDelete /* = false*/) -{ - return delView(getView(id), dontDelete); -} + if (el != NULL) + { + if (_GroupSizeRef&1) + _MaxWReal += _SizeDivW * el->getWReal() / 10; -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delCtrl (const std::string &id, bool dontDelete /* = false*/) -{ - return delCtrl(getCtrl(id), dontDelete); -} + if (_GroupSizeRef&2) + _MaxHReal += _SizeDivH * el->getHReal() / 10; + } -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delGroup (const std::string &id, bool dontDelete /* = false*/) -{ - return delGroup(getGroup(id), dontDelete); -} + CViewBase::updateCoords(); + _XReal += _OffsetX; + _YReal += _OffsetY; -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::isChildGroup(const CInterfaceGroup *group) const -{ - return std::find(_ChildrenGroups.begin(), _ChildrenGroups.end(), group) != _ChildrenGroups.end(); -} + //update all children elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pIE = *ite; + pIE->updateCoords(); + } -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::handleEvent (const NLGUI::CEventDescriptor &event) -{ - if (CCtrlBase::handleEvent(event)) return true; - if (!_Active) - return false; + _XReal -= _OffsetX; + _YReal -= _OffsetY; + } - if (event.getType() == NLGUI::CEventDescriptor::system) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::updateCoords() { - NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; - if (eds.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::activecalledonparent) + // update basis and sons one time. + doUpdateCoords(); + + // if the group must resize from children + if(_ResizeFromChildH || _ResizeFromChildW) { - // notify all childrens - notifyActiveCalled((NLGUI::CEventDescriptorActiveCalledOnParent &) eds); + // 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(); } - if (event.getType() == NLGUI::CEventDescriptor::mouse) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::evalChildrenBBox(bool resizeFromChildW, bool resizeFromChildH, sint &width, sint &height) const { - const NLGUI::CEventDescriptorMouse &eventDesc = (const NLGUI::CEventDescriptorMouse &)event; + 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; + } - if (!isIn(eventDesc.getX(), eventDesc.getY())) - return false; + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CInterfaceGroup::getElement (const std::string &id) + { + if (_Id == id) + return this; - bool taken = false; + 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; + } - // 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); + 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; } - if (taken) - return true; - // For each child group - for (sint i = (sint)_ChildrenGroups.size()-1; i >= 0; --i) + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) { - CInterfaceGroup *pIG = _ChildrenGroups[i]; - if (pIG->getActive()) - if (pIG->handleEvent(eventDesc)) - return true; + 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; - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown) + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) { - if (_AHOnLeftClick != NULL) + CViewBase *pVB = *itv; + if (pVB->getId() == id) { - CAHManager::getInstance()->runActionHandler(_AHOnLeftClick, this, _AHOnLeftClickParams); + delView (pVB, false); return true; } } - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouserightup) + vector::const_iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) { - if (_AHOnRightClick != NULL) + CCtrlBase* ctrl = *itc; + if (ctrl->getId() == id) { - CAHManager::getInstance()->runActionHandler(_AHOnRightClick, this, _AHOnRightClickParams); + delCtrl (ctrl, false); return true; } } - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousewheel) + + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) { - // handle the Mouse Wheel only if interesting - if (_H>_MaxH) + CInterfaceGroup *pIG = *itg; + if (pIG->getId() == id) { - CInterfaceGroup *currParent = _Parent; - while (currParent) - { - if (currParent->moveSBTrackY (this, eventDesc.getWheel()*12)) - return true; - currParent = currParent->getParent(); - } + // If this is a root window + if (pIG->getRootWindow () == pIG) + CWidgetManager::getInstance()->unMakeWindow(pIG, noWarning); + delGroup (pIG, false); + return true; } } + return false; } - return false; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::executeControl (const std::string &/* sControlName */) -{ -// bool taken = false; -// CCtrlBase *pIC = getCtrl (sControlName); -// if (pIC != NULL) -// pIC->callback(taken); -} + // ------------------------------------------------------------------------------------------------ + 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)); + } -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::draw () -{ - sint32 oldSciX, oldSciY, oldSciW, oldSciH; - makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::isWindowUnder (sint32 x, sint32 y) + { + return ((x >= _XReal) && + (x < (_XReal + _WReal))&& + (y > _YReal) && + (y <= (_YReal + _HReal))); + } - // Display sons only if not total clipped - CViewRenderer &rVR = *CViewRenderer::getInstance(); - if( !rVR.isClipWindowEmpty() ) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CInterfaceGroup::getGroupUnder (sint32 x, sint32 y) { - // Draw all decorative elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + // Begins by the children + std::vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) { - CViewBase *pVB = *ite; - if (pVB->getActive()) - pVB->draw(); + 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; + } } - } - restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); -} + // 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; + } -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::drawNoClip() -{ - // Display sons only if not total clipped - CViewRenderer &rVR = *CViewRenderer::getInstance(); - if( !rVR.isClipWindowEmpty() ) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::getViewsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vVB) { - // Draw all decorative elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + 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++) { - CViewBase *pVB = *ite; - if (pVB->getActive()) - pVB->draw(); + 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; } -} -// ------------------------------------------------------------------------------------------------ -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) + // ------------------------------------------------------------------------------------------------ + bool CInterfaceGroup::getCtrlsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vICL) { - if (*it) (*it)->renderWiredQuads(type, uiFilter); - } - restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); -} + 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; -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::drawElement (CViewBase *el) -{ - sint32 oldSciX, oldSciY, oldSciW, oldSciH; - makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH); - if(el) - el->draw(); - restoreClip (oldSciX, oldSciY, oldSciW, oldSciH); -} + // 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)); + } + } + } -// ------------------------------------------------------------------------------------------------ -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(); + // 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; } - executeLuaScriptOnDraw(); -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::executeLuaScriptOnDraw() -{ - // If some LUA script attached to me, execute it - if(!_LUAOnDraw.empty()) - CAHManager::getInstance()->runActionHandler("lua", this, _LUAOnDraw); -} + // ------------------------------------------------------------------------------------------------ + 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; + -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::doUpdateCoords() -{ - _MaxWReal = _MaxW; - _MaxHReal = _MaxH; - CInterfaceElement *el = NULL; + // 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 (_ParentSizeMax != NULL) + // 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) { - el = _ParentSizeMax; + CInterfaceGroup *curGrp = _Parent; + while (curGrp != NULL) + { + x = x - curGrp->_XReal; + y = y - curGrp->_YReal; + curGrp = curGrp->_Parent; + } } - else + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::computeCurrentClipContribution(sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH, + sint32 &newSciXDest, sint32 &newSciYDest, sint32 &newSciWDest, sint32 &newSciHDest) const { - if (_ParentSize != NULL) + 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) { - el = _ParentSize; + newSciH = newSciH - (oldSciY - newSciY); + newSciY = oldSciY; } - else + // Clip Top + if ((newSciY+newSciH) > (oldSciY+oldSciH)) { - if (_ParentPos != NULL) - el = _ParentPos; - else - el = _Parent; + newSciH = newSciH - ((newSciY+newSciH)-(oldSciY+oldSciH)); } + + newSciXDest = newSciX; + newSciYDest = newSciY; + newSciWDest = newSciW; + newSciHDest = newSciH; + } - if (el != NULL) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::makeNewClip (sint32 &oldSciX, sint32 &oldSciY, sint32 &oldSciW, sint32 &oldSciH) { - if (_GroupSizeRef&1) - _MaxWReal += _SizeDivW * el->getWReal() / 10; + CViewRenderer &rVR = *CViewRenderer::getInstance(); + rVR.getClipWindow (oldSciX, oldSciY, oldSciW, oldSciH); - if (_GroupSizeRef&2) - _MaxHReal += _SizeDivH * el->getHReal() / 10; + sint32 newSciX, newSciY, newSciW, newSciH; + computeCurrentClipContribution(oldSciX, oldSciY, oldSciW, oldSciH, newSciX, newSciY, newSciW, newSciH); + rVR.setClipWindow (newSciX, newSciY, newSciW, newSciH); } - CViewBase::updateCoords(); - _XReal += _OffsetX; - _YReal += _OffsetY; - - //update all children elements - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::getClip(sint32 &x, sint32 &y, sint32 &w, sint32 &h) const { - CViewBase *pIE = *ite; - pIE->updateCoords(); + 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; } - _XReal -= _OffsetX; - _YReal -= _OffsetY; -} + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::restoreClip (sint32 oldSciX, sint32 oldSciY, sint32 oldSciW, sint32 oldSciH) + { + CViewRenderer &rVR = *CViewRenderer::getInstance(); + rVR.setClipWindow (oldSciX, oldSciY, oldSciW, oldSciH); + } -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::updateCoords() -{ - // update basis and sons one time. - doUpdateCoords(); - // if the group must resize from children - if(_ResizeFromChildH || _ResizeFromChildW) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::launch () { - // compute BBox of all childrens - sint width, height; - evalChildrenBBox(_ResizeFromChildW, _ResizeFromChildH, width, height); - // set forced size. - if(_ResizeFromChildW) + // launch all elements + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) { - _W= _ResizeFromChildWMargin + width; + CViewBase *pIE = *ite; + pIE->launch(); } - if(_ResizeFromChildH) + } + + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup *CInterfaceGroup::getGroup(uint index) const + { + if (index > _ChildrenGroups.size()) { - _H= _ResizeFromChildHMargin + height; + nlwarning(" bad index;"); + return NULL; } + return _ChildrenGroups[index]; } - 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++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::updateAllLinks() { - CViewBase *pIE = *ite; - if (pIE->getActive()) + CCtrlBase::updateAllLinks(); { - const CInterfaceElement *el = pIE->getParentPos() ? pIE->getParentPos() : pIE->getParent(); - if (el == this) + for(std::vector::iterator it = _ChildrenGroups.begin(); it != _ChildrenGroups.end(); ++it) { - // 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; - } + (*it)->updateAllLinks(); } - // 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()) + } + { + for(std::vector::iterator it = _Controls.begin(); it != _Controls.end(); ++it) { - 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; + (*it)->updateAllLinks(); } - else + } + { + for(std::vector::iterator it = _Views.begin(); it != _Views.end(); ++it) { - x0= pIE->getXReal(); - y0= pIE->getYReal(); - x1= x0 + pIE->getWReal(); - y1= y0 + pIE->getHReal(); + (*it)->updateAllLinks(); } - // 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++) + // ------------------------------------------------------------------------------------------------ + sint32 CInterfaceGroup::getAlpha() const { - 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; -} + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) + { + CViewBase *pVB = *itv; + sint32 a = pVB->getAlpha(); + if (a != -1) + return a; + } -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delElement (const std::string &id, bool noWarning) -{ - if (id.substr(0, _Id.size()) != _Id) - return false; + 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 itv; - for (itv = _Views.begin(); itv != _Views.end(); itv++) - { - CViewBase *pVB = *itv; - if (pVB->getId() == id) + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) { - delView (pVB, false); - return true; + CInterfaceGroup *pIG = *itg; + sint32 a = pIG->getAlpha(); + if (a != -1) + return a; } + return -1; } - vector::const_iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setAlpha (sint32 a) { - CCtrlBase* ctrl = *itc; - if (ctrl->getId() == id) + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) { - delCtrl (ctrl, false); - return true; + CViewBase *pVB = *itv; + pVB->setAlpha(a); } - } - vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) - { - CInterfaceGroup *pIG = *itg; - if (pIG->getId() == id) + vector::const_iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) { - // If this is a root window - if (pIG->getRootWindow () == pIG) - CWidgetManager::getInstance()->unMakeWindow(pIG, noWarning); - delGroup (pIG, false); - return true; + CCtrlBase *pCB = *itc; + pCB->setAlpha(a); + } + + vector::const_iterator itg; + for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + { + CInterfaceGroup *pIG = *itg; + pIG->setAlpha(a); } } - return false; -} -// ------------------------------------------------------------------------------------------------ -bool CInterfaceGroup::delElement (CInterfaceElement *pIE, bool noWarning) -{ - // delete correct type of element - if(pIE->isGroup()) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setLeftClickHandler(const std::string &handler) { - CInterfaceGroup *pIG= static_cast(pIE); - // unmake window if it is - if (pIG->getRootWindow () == pIG) - CWidgetManager::getInstance()->unMakeWindow(pIG, noWarning); - return delGroup(pIG); + _AHOnLeftClick = CAHManager::getInstance()->getAH(handler, _AHOnLeftClickParams); } - else if(pIE->isCtrl()) + + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setRightClickHandler(const std::string &handler) { - return delCtrl(static_cast(pIE)); + _AHOnRightClick = CAHManager::getInstance()->getAH(handler, _AHOnRightClickParams); } - 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* CInterfaceGroup::getEnclosingContainer() { - CInterfaceGroup *pChild = *itg; - CInterfaceGroup *pChildUnder = pChild->getGroupUnder (x-_XReal, y-_YReal); - if (pChildUnder != NULL) + CInterfaceGroup *ig = this; + do { - if ( (x >= _XReal) && - (x < (_XReal + _WReal))&& - (y > _YReal) && - (y <= (_YReal+ _HReal))) - return pChildUnder; + if( ig->isGroupContainer() ) + return ig; + ig = ig->getParent(); } - } - - // 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; - + while( ig != NULL ); + return NULL; + } - // same as draw order: start with parent - std::vector::const_iterator itc; - for (itc = _EltOrder.begin(); itc != _EltOrder.end(); itc++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::dumpGroups() { - if (!(*itc)->isCtrl() && !(*itc)->isGroup()) // must be a view + nlinfo("Num groups = %d", (int) _ChildrenGroups.size()); + for(uint k = 0; k < _ChildrenGroups.size(); ++k) { - 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()))) + std::string typeName = "???"; + if (_ChildrenGroups[k]) { - vVB.push_back (pVB); + 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()); } } - // 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++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::dumpEltsOrder() { - if ((*itc)->isCtrl() && !(*itc)->isGroup()) // must be a ctrl but not a group (parsed later) + nlinfo("Num elements = %d", (int) _EltOrder.size()); + 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()))) + std::string typeName = "???"; + if (_ChildrenGroups[k]) + { + const type_info &ti = typeid(*_EltOrder[k]); + typeName = ti.name(); + } + CInterfaceElement *el = _EltOrder[k]; + if (el) { - vICL.push_back (pICL->getSubCtrl(x,y)); + 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); } } } - // 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->getCtrlsUnder (x, y, clipX, clipY, clipW, clipH, vICL); -// if (bUnder && (vICL.size() > 0)) -// return true; + if (_EltOrder[k] == vb) return (sint) k; } + return -1; } - 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++) + // ------------------------------------------------------------------------------------------------ + sint32 CInterfaceGroup::getMaxUsedW() const { - if ((*itc)->isGroup()) // must be a group + sint maxWidth = 0; + for (uint k = 0; k < _EltOrder.size(); ++k) { - 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); - } + // Get the child width + sint32 width = _EltOrder[k]->getMaxUsedW()+_EltOrder[k]->getXReal() - getXReal(); + if (width > maxWidth) + maxWidth = width; } + return maxWidth; } - // same as draw order: continue with children - std::vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + // ------------------------------------------------------------------------------------------------ + sint32 CInterfaceGroup::getMinUsedW() const { - CInterfaceGroup *pChild = *itg; - if (pChild->getActive()) + sint32 minWidth = 0; + for (uint k = 0; k < _EltOrder.size(); ++k) { -// bool bUnder = - pChild->getGroupsUnder (x, y, clipX, clipY, clipW, clipH, vIGL); -// if (bUnder && (vICL.size() > 0)) -// return true; + // Get the child width + sint32 width = _EltOrder[k]->getMinUsedW()+_EltOrder[k]->getXReal() - getXReal(); + if (width > minWidth) + minWidth = width; } + return minWidth; } - 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)) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::clearAllEditBox() { - 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)); + for(uint k = 0; k < _ChildrenGroups.size(); ++k) + { + if (_ChildrenGroups[k]) _ChildrenGroups[k]->clearAllEditBox(); + } } - 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++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::restoreAllContainersBackupPosition() { - CViewBase *pIE = *ite; - pIE->launch(); + for(uint k = 0; k < _ChildrenGroups.size(); ++k) + { + if (_ChildrenGroups[k]) _ChildrenGroups[k]->restoreAllContainersBackupPosition(); + } } -} -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup *CInterfaceGroup::getGroup(uint index) const -{ - if (index > _ChildrenGroups.size()) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::dumpSize(uint depth /*=0*/) const { - nlwarning(" bad index;"); - return NULL; + 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); + } } - return _ChildrenGroups[index]; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::updateAllLinks() -{ - CCtrlBase::updateAllLinks(); + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::visit(CInterfaceElementVisitor *visitor) { - 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(std::vector::iterator it = _Controls.begin(); it != _Controls.end(); ++it) + for(uint k = 0; k < _Controls.size(); ++k) { - (*it)->updateAllLinks(); + _Controls[k]->visit(visitor); } - } - { - for(std::vector::iterator it = _Views.begin(); it != _Views.end(); ++it) + for(uint k = 0; k < _Views.size(); ++k) { - (*it)->updateAllLinks(); + _Views[k]->visit(visitor); } + visitor->visitGroup(this); + CInterfaceElement::visit(visitor); } -} -// ------------------------------------------------------------------------------------------------ -sint32 CInterfaceGroup::getAlpha() const -{ - vector::const_iterator itv; - for (itv = _Views.begin(); itv != _Views.end(); itv++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::visitGroupAndChildren( CInterfaceElementVisitor *visitor ) { - CViewBase *pVB = *itv; - sint32 a = pVB->getAlpha(); - if (a != -1) - return a; - } + nlassert( visitor != 0 ); + for( uint i = 0; i < _ChildrenGroups.size(); i++ ) + { + _ChildrenGroups[ i ]->visitGroupAndChildren( visitor ); + } - vector::const_iterator itc; - for (itc = _Controls.begin(); itc != _Controls.end(); itc++) - { - CCtrlBase *pCB = *itc; - sint32 a = pCB->getAlpha(); - if (a != -1) - return a; + visitor->visitGroup( this ); } - 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++) + void CInterfaceGroup::setUseCursor(bool use) { - CCtrlBase *pCB = *itc; - pCB->setAlpha(a); + _UseCursor=use; } - vector::const_iterator itg; - for (itg = _ChildrenGroups.begin(); itg != _ChildrenGroups.end(); itg++) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::onFrameUpdateWindowPos(sint dx, sint dy) { - 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); -} + // Move me. + _XReal+= dx; + _YReal+= dy; -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CInterfaceGroup::getEnclosingContainer() -{ - CInterfaceGroup *ig = this; - do - { - if( ig->isGroupContainer() ) - return ig; - ig = ig->getParent(); + // Move all my sons. + vector::const_iterator ite; + for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) + { + CViewBase *pIE = *ite; + pIE->onFrameUpdateWindowPos(dx, dy); + } } - while( ig != NULL ); - - return NULL; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::dumpGroups() -{ - nlinfo("Num groups = %d", (int) _ChildrenGroups.size()); - for(uint k = 0; k < _ChildrenGroups.size(); ++k) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::pushLUAEnvTable() { - std::string typeName = "???"; - if (_ChildrenGroups[k]) + CLuaState *lua= CLuaManager::getInstance().getLuaState(); + nlassert(lua); + + if(!_LUAEnvTableCreated) { - const type_info &ti = typeid(*_ChildrenGroups[k]); - typeName = ti.name(); + 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; } - nlinfo("Group %d, name = %s, type=%s", k, _ChildrenGroups[k] ? _ChildrenGroups[k]->getId().c_str() : "???", typeName.c_str()); + + // 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::dumpEltsOrder() -{ - nlinfo("Num elements = %d", (int) _EltOrder.size()); - for(uint k = 0; k < _EltOrder.size(); ++k) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::deleteLUAEnvTable(bool recurse) { - std::string typeName = "???"; - if (_ChildrenGroups[k]) - { - const type_info &ti = typeid(*_EltOrder[k]); - typeName = ti.name(); - } - CInterfaceElement *el = _EltOrder[k]; - if (el) + if(_LUAEnvTableCreated) { - 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() - ); + 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; } - else + if (recurse) { - nlinfo("Element %d = NULL", (int) k); + for(uint k = 0; k < _ChildrenGroups.size(); ++k) + { + _ChildrenGroups[k]->deleteLUAEnvTable(true); + } } } -} -// ------------------------------------------------------------------------------------------------ -sint CInterfaceGroup::getInsertionOrder(CViewBase *vb) const -{ - for(uint k = 0; k < _EltOrder.size(); ++k) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setLuaScriptOnDraw(const std::string &script) { - if (_EltOrder[k] == vb) return (sint) k; + _LUAOnDraw= script; } - return -1; -} -// ------------------------------------------------------------------------------------------------ -sint32 CInterfaceGroup::getMaxUsedW() const -{ - sint maxWidth = 0; - for (uint k = 0; k < _EltOrder.size(); ++k) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::addLuaScriptOnDBChange(const std::string &dbList, const std::string &script) { - // Get the child width - sint32 width = _EltOrder[k]->getMaxUsedW()+_EltOrder[k]->getXReal() - getXReal(); - if (width > maxWidth) - maxWidth = width; - } - return maxWidth; -} + // remove any existing + removeLuaScriptOnDBChange(dbList); -// ------------------------------------------------------------------------------------------------ -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; + // 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); } - return minWidth; -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::clearAllEditBox() -{ - for(uint k = 0; k < _ChildrenGroups.size(); ++k) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::removeLuaScriptOnDBChange(const std::string &dbList) { - if (_ChildrenGroups[k]) _ChildrenGroups[k]->clearAllEditBox(); + 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); + } } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::restoreAllContainersBackupPosition() -{ - for(uint k = 0; k < _ChildrenGroups.size(); ++k) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::removeAllLUAOnDbChange() { - if (_ChildrenGroups[k]) _ChildrenGroups[k]->restoreAllContainersBackupPosition(); + TLUAOnDbChange::iterator it= _LUAOnDbChange.begin(); + for(;it!=_LUAOnDbChange.end();) + { + // since deleted, must not do it++, but it= begin() + removeLuaScriptOnDBChange(it->first); + it= _LUAOnDbChange.begin(); + } } -} -// ------------------------------------------------------------------------------------------------ -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) + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaFind(CLuaState &ls) { - _Controls[k]->dumpSize(depth + 1); - } - for(uint k = 0; k < _Views.size(); ++k) - { - _Views[k]->dumpSize(depth + 1); + 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; } -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::visit(CInterfaceElementVisitor *visitor) -{ - nlassert(visitor); - for(uint k = 0; k < _ChildrenGroups.size(); ++k) + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CInterfaceGroup::findFromShortId(const std::string &id) { - _ChildrenGroups[k]->visit(visitor); + CInterfaceElement* element = NULL; + element = getView(id); + if (!element) element = getCtrl(id); + if (!element) element = getGroup(id); + return element; } - for(uint k = 0; k < _Controls.size(); ++k) + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaGetEnclosingContainer(CLuaState &ls) { - _Controls[k]->visit(visitor); + CLuaIHM::checkArgCount(ls, "CInterfaceGroup::getEnclosingContainer", 0); + CLuaIHM::pushUIOnStack(ls, getEnclosingContainer()); + return 1; } - for(uint k = 0; k < _Views.size(); ++k) + + // ------------------------------------------------------------------------------------------------ + int CInterfaceGroup::luaDeleteLUAEnvTable(CLuaState &ls) { - _Views[k]->visit(visitor); + 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; } - visitor->visitGroup(this); - CInterfaceElement::visit(visitor); -} -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::visitGroupAndChildren( CInterfaceElementVisitor *visitor ) -{ - nlassert( visitor != 0 ); - for( uint i = 0; i < _ChildrenGroups.size(); i++ ) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::serial(NLMISC::IStream &f) { - _ChildrenGroups[ i ]->visitGroupAndChildren( visitor ); - } + 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); - visitor->visitGroup( this ); -} + 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); -void CInterfaceGroup::setUseCursor(bool use) -{ - _UseCursor=use; -} + // right & left clicks + serialAH(f, _AHOnLeftClick); + f.serial(_AHOnLeftClickParams); + serialAH(f, _AHOnRightClick); + f.serial(_AHOnRightClickParams); -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::onFrameUpdateWindowPos(sint dx, sint dy) -{ - // Move me. - _XReal+= dx; - _YReal+= dy; + // enter params. + serialAH(f, _AHOnEnter); + f.serial(_AHOnEnterParams); - // Move all my sons. - vector::const_iterator ite; - for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++) - { - CViewBase *pIE = *ite; - pIE->onFrameUpdateWindowPos(dx, dy); + // escape AH + serialAH(f, _AHOnEscape); + f.serial(_AHOnEscapeParams); } -} - -// ------------------------------------------------------------------------------------------------ -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) - { - 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) + // ------------------------------------------------------------------------------------------------ + CInterfaceElement *CInterfaceGroup::clone() { - for(uint k = 0; k < _ChildrenGroups.size(); ++k) + CInterfaceElement *oldParentSizeMax = _ParentSizeMax; + if (_ParentSizeMax == _Parent) { - _ChildrenGroups[k]->deleteLUAEnvTable(true); + _ParentSizeMax = NULL; } + CInterfaceElement *ret = CCtrlBase::clone(); + _ParentSizeMax = oldParentSizeMax; + return ret; } -} - -// ------------------------------------------------------------------------------------------------ -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()) - { - 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); - } -} - -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::removeAllLUAOnDbChange() -{ - TLUAOnDbChange::iterator it= _LUAOnDbChange.begin(); - for(;it!=_LUAOnDbChange.end();) - { - // since deleted, must not do it++, but it= begin() - removeLuaScriptOnDBChange(it->first); - it= _LUAOnDbChange.begin(); - } -} -// ------------------------------------------------------------------------------------------------ -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) + // ------------------------------------------------------------------------------------------------ + void CInterfaceGroup::setMaxSizeRef(const std::string &maxSizeRef) { - ls.pushNil(); + parseMaxSizeRef(maxSizeRef.c_str()); } - else - { - CLuaIHM::pushUIOnStack(ls, element); - } - 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) + // ------------------------------------------------------------------------------------------------ + std::string CInterfaceGroup::getMaxSizeRefAsString() const { - _ParentSizeMax = NULL; + return "IMPLEMENT ME!"; } - 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 // -///////////// +namespace NLGUI +{ -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; + ///////////// + // GLOBALS // + ///////////// -bool CInterfaceLink::_UpdateAllLinks = false; + 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) -{ + /////////////// + // FUNCTIONS // + /////////////// - CInterfaceExprValue valueToAffect = value; - switch(property.Type) + /** 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 - { + CInterfaceExprValue valueToAffect = value; + switch(property.Type) + { + 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 false; - } - break; - default: - break; + return true; } - 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) + CInterfaceLink::CInterfaceLinkUpdater::CInterfaceLinkUpdater() { - _CurrUpdatedLink = NULL; + NLGUI::CDBManager::getInstance()->addFlushObserver( this ); } - if (this == _NextUpdatedLink) + + CInterfaceLink::CInterfaceLinkUpdater::~CInterfaceLinkUpdater() { - _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); + void CInterfaceLink::CInterfaceLinkUpdater::onObserverCallFlush() + { + CInterfaceLink::updateTrigeredLinks(); + } - delete _ParseTree; -} + ///////////// + // MEMBERS // + ///////////// -//=========================================================== -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) + //=========================================================== + CInterfaceLink::CInterfaceLink() : _On(true) { - // wrong expression : release the link - nlwarning("CInterfaceLink::init : can't parse expression %s", expr.c_str()); - _LinksWithNoTarget.push_back(TLinkSmartPtr(this)); - return false; + // 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; } - // 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()) + + //=========================================================== + CInterfaceLink::~CInterfaceLink() { - // retrieve properties from the element - _Targets.resize(targets.size()); - for (uint k = 0; k < targets.size(); ++k) + if (this == _CurrUpdatedLink) { - 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); + _CurrUpdatedLink = NULL; } - } - 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) + if (this == _NextUpdatedLink) { - _LinksWithNoTarget.erase(_LinksWithNoTarget.begin()+i); - return; + _NextUpdatedLink = _NextUpdatedLink->_NextTriggeredLink[1 - _CurrentTriggeredLinkList]; } - } -} + // unlink observer from both update lists + unlinkFromTriggerList(0); + unlinkFromTriggerList(1); -//=========================================================== -void CInterfaceLink::update(ICDBNode * /* node */) -{ - // mark link as triggered - linkInTriggerList(_CurrentTriggeredLinkList); -} + removeObservers(_ObservedNodes); + // removes from the link list + _LinkList.erase(_ListEntry); -//=========================================================== -void CInterfaceLink::createObservers(const TNodeVect &nodes) -{ - for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) + 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) { - if ((*it)->isLeaf()) + CInterfaceExprValue result; + // Build the parse tree + nlassert(!_ParseTree); + _ParseTree = CInterfaceExpr::buildExprTree(expr); + if (!_ParseTree) { - ICDBNode::CTextId textId; - (*it)->addObserver(this, textId); + // 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) + { + 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); + } } else { - CCDBNodeBranch *br = static_cast(*it); - NLGUI::CDBManager::getInstance()->addBranchObserver( br, this ); + // 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::removeObservers(const TNodeVect &nodes) -{ - for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) + //=========================================================== + void CInterfaceLink::uninit() { - if ((*it)->isLeaf()) - { - ICDBNode::CTextId textId; - (*it)->removeObserver(this, textId); - } - else + for (uint32 i = 0; i < _LinksWithNoTarget.size(); i++) { - CCDBNodeBranch *br = static_cast(*it); - NLGUI::CDBManager::getInstance()->removeBranchObserver( br, this ); + CInterfaceLink *pLink = _LinksWithNoTarget[i]; + if (pLink == this) + { + _LinksWithNoTarget.erase(_LinksWithNoTarget.begin()+i); + return; + } } } -} -//=========================================================== -void CInterfaceLink::updateAllLinks() -{ - nlassert(!_UpdateAllLinks); - _UpdateAllLinks = true; - for(TLinkList::iterator it = _LinkList.begin(); it != _LinkList.end(); ++it) + //=========================================================== + void CInterfaceLink::update(ICDBNode * /* node */) { - CInterfaceLink *pLink = *it; - pLink->update(); + // mark link as triggered + linkInTriggerList(_CurrentTriggeredLinkList); } - _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) + //=========================================================== + void CInterfaceLink::createObservers(const TNodeVect &nodes) { - CInterfaceElement *elem = _Targets[k]._InterfaceElement; - const CReflectedProperty *prop = _Targets[k]._Property; - if (elem && prop) + for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { - if (!affect(result, *elem, *prop)) + if ((*it)->isLeaf()) { - nlwarning("CInterfaceLink::update: Result conversion failed"); + ICDBNode::CTextId textId; + (*it)->addObserver(this, textId); + } + else + { + CCDBNodeBranch *br = static_cast(*it); + NLGUI::CDBManager::getInstance()->addBranchObserver( br, this ); } } } - // if there's an action handler, execute it - if (!_ActionHandler.empty()) + + //=========================================================== + void CInterfaceLink::removeObservers(const TNodeVect &nodes) { - // If there is a condition, test it. - bool launch= true; - if(!_AHCond.empty()) + for(std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { - launch= false; - CInterfaceExprValue result; - if(CInterfaceExpr::eval(_AHCond, result)) - launch= result.getBool(); + if ((*it)->isLeaf()) + { + ICDBNode::CTextId textId; + (*it)->removeObserver(this, textId); + } + else + { + CCDBNodeBranch *br = static_cast(*it); + NLGUI::CDBManager::getInstance()->removeBranchObserver( br, this ); + } } - if(launch) + } + + //=========================================================== + void CInterfaceLink::updateAllLinks() + { + nlassert(!_UpdateAllLinks); + _UpdateAllLinks = true; + for(TLinkList::iterator it = _LinkList.begin(); it != _LinkList.end(); ++it) { - CAHManager::getInstance()->runActionHandler(_ActionHandler, _AHParent, _AHParams); - // do not add any code after this line because this can be deleted !!!! + CInterfaceLink *pLink = *it; + pLink->update(); } + _UpdateAllLinks = 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::update() { - nlwarning(" : Target element is NULL"); + //_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 !!!! + } + } - return false; + //_On = true; // prevent recursive calls } - const CReflectedProperty *property = Elem->getReflectedProperty(PropertyName); - if (!property) + + // predicate to remove an element from a list + struct CRemoveTargetPred { - nlwarning(" : Can't retrieve property %s for element %s.", PropertyName.c_str(), Elem->getId().c_str()); + CInterfaceElement *Target; + bool operator()(const CInterfaceLink::CTarget &target) const { return target._InterfaceElement == Target; } + }; - return false; + //=========================================================== + void CInterfaceLink::removeTarget(CInterfaceElement *elem) + { + CRemoveTargetPred pred; + pred.Target = elem; + _Targets.erase(std::remove_if(_Targets.begin(), _Targets.end(), pred), _Targets.end()); } - // try to affect the property - if (!::affect(value, *Elem, *property)) + + //=========================================================== + bool CInterfaceLink::CTargetInfo::affect(const CInterfaceExprValue &value) { - nlwarning(" Couldn't convert the value to affect to %s", Elem->getId().c_str()); - return false; - } + if (!Elem) + { + nlwarning(" : Target element is NULL"); - return true; -} + 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()); -//=========================================================== -void CInterfaceLink::removeAllLinks() -{ - _LinksWithNoTarget.clear(); - TLinkList::iterator curr = _LinkList.begin(); - TLinkList::iterator nextIt; - uint k; - while(curr != _LinkList.end()) + 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() { - 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) + _LinksWithNoTarget.clear(); + TLinkList::iterator curr = _LinkList.begin(); + TLinkList::iterator nextIt; + uint k; + while(curr != _LinkList.end()) { - if (link._Targets[k]._InterfaceElement) + 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) { - nlinfo("InterfaceElement %s was not remove.", link._Targets[k]._InterfaceElement->getId().c_str()); - link._Targets[k]._InterfaceElement->removeLink(&link); + 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; } - linkPtr = NULL; // effectively destroy link - curr = nextIt; + nlassert(_LinkList.empty()); } - 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) + // *************************************************************************** + bool CInterfaceLink::splitLinkTarget(const std::string &target, CInterfaceGroup *parentGroup, std::string &propertyName, CInterfaceElement *&targetElm) { - if (lastPos == std::string::npos) + // 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)) { - elmProp = target; - elm = parentGroup; - elmPath = "current"; + // todo hulud interface syntax error + nlwarning("The target should at least contains a path and a property as follow 'path:property'"); + return false; } - else + 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); - 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; + 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; } - 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) + // *************************************************************************** + bool CInterfaceLink::splitLinkTargets(const std::string &targets, CInterfaceGroup *parentGroup,std::vector &targetsVect) { - CInterfaceLink::CTargetInfo ti; - std::string::size_type startPos = targetNames[k].find_first_not_of(" "); - if(startPos == std::string::npos) + std::vector targetNames; + NLMISC::splitString(targets, ",", targetNames); + targetsVect.clear(); + targetsVect.reserve(targetNames.size()); + bool everythingOk = true; + for (uint k = 0; k < targetNames.size(); ++k) { - // todo hulud interface syntax error - nlwarning(" empty target encountered"); - continue; - } - std::string::size_type lastPos = targetNames[k].find_last_not_of(" "); + 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; + 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); } - targetsVect.push_back(ti); + return everythingOk; } - return everythingOk; -} -//=========================================================== -void CInterfaceLink::checkNbRefs() -{ - uint numValidPtr = 0; - for(uint k = 0; k < _Targets.size(); ++k) + //=========================================================== + void CInterfaceLink::checkNbRefs() { - if (_Targets[k]._InterfaceElement != NULL) ++numValidPtr; + uint numValidPtr = 0; + for(uint k = 0; k < _Targets.size(); ++k) + { + if (_Targets[k]._InterfaceElement != NULL) ++numValidPtr; + } + nlassert(numValidPtr == (uint) crefs); } - 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) + //=========================================================== + void CInterfaceLink::setTargetProperty (const std::string &Target, const CInterfaceExprValue &val) { - std::vector vTargets; - splitLinkTargets(Target, pIG, vTargets); - if ((vTargets.size() > 0) && (vTargets[0].Elem)) + // 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) { - vTargets[0].affect(val); + 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 + //----------------------------------------------- + void CInterfaceLink::linkInTriggerList(uint list) { - nlassert(!_LastTriggeredLink[list]->_NextTriggeredLink[list]); - _LastTriggeredLink[list]->_NextTriggeredLink[list] = this; - _PrevTriggeredLink[list] = _LastTriggeredLink[list]; - _LastTriggeredLink[list] = this; + 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]) + //----------------------------------------------- + void CInterfaceLink::unlinkFromTriggerList(uint 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]; + 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; } - _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) + //----------------------------------------------- + void CInterfaceLink::updateTrigeredLinks() { - // 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 -// ---------------------------------------------------------------------------- + // *************************************************************************** + void CInterfaceOptionValue::init(const std::string &str) + { + _Str= str; + fromString(str, _Int); + fromString(str, _Float); + _Color= CInterfaceElement::convertColor (str.c_str()); + _Boolean= CInterfaceElement::convertBool(str.c_str()); + } -// ---------------------------------------------------------------------------- -CInterfaceOptions::CInterfaceOptions() -{ -} -// ---------------------------------------------------------------------------- -CInterfaceOptions::~CInterfaceOptions() -{ -} + // ---------------------------------------------------------------------------- + // CInterfaceOptions + // ---------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -bool CInterfaceOptions::parse (xmlNodePtr cur) -{ - cur = cur->children; - bool ok = true; - while (cur) + // ---------------------------------------------------------------------------- + CInterfaceOptions::CInterfaceOptions() + { + } + + // ---------------------------------------------------------------------------- + CInterfaceOptions::~CInterfaceOptions() { - if ( !stricmp((char*)cur->name,"param") ) + } + + // ---------------------------------------------------------------------------- + bool CInterfaceOptions::parse (xmlNodePtr cur) + { + cur = cur->children; + bool ok = true; + while (cur) { - CXMLAutoPtr ptr, val; - ptr = xmlGetProp (cur, (xmlChar*)"name"); - val = xmlGetProp (cur, (xmlChar*)"value"); - if (!ptr || !val) + if ( !stricmp((char*)cur->name,"param") ) { - 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); + 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; } - cur = cur->next; + return ok; } - return ok; -} -// *************************************************************************** -void CInterfaceOptions::copyBasicMap(const CInterfaceOptions &other) -{ - _ParamValue= other._ParamValue; -} + // *************************************************************************** + 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 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(); -} + // *************************************************************************** + 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()); -} + 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); + } -// *************************************************************************** -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() -{ -} + CViewPointerBase::CViewPointerBase( const CViewBase::TCtorParam ¶m ) : + CViewBase( param ) + { + _PointerX = _PointerY = _PointerOldX = _PointerOldY = _PointerDownX = _PointerDownY = 0; + _PointerDown = false; + _PointerVisible = true; + } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerPos (sint32 x, sint32 y) -{ - if (_PointerDown) + CViewPointerBase::~CViewPointerBase() { - if (!_PointerDrag) + } + + // -------------------------------------------------------------------------------------------------------------------- + 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(); + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::setPointerDispPos (sint32 x, sint32 y) + { + setX (x); + setY (y); + updateCoords (); + } - _PointerX = x; - _PointerY = y; -} + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::resetPointerPos () + { + _PointerOldX = _PointerX; + _PointerOldY = _PointerY; + } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerDispPos (sint32 x, sint32 y) -{ - setX (x); - setY (y); - updateCoords (); -} + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::setPointerDown (bool pd) + { + _PointerDown = pd; -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::resetPointerPos () -{ - _PointerOldX = _PointerX; - _PointerOldY = _PointerY; -} + if (_PointerDown == true) + { + _PointerDownX = _PointerX; + _PointerDownY = _PointerY; + } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerDown (bool pd) -{ - _PointerDown = pd; + if (_PointerDown == false) + _PointerDrag = false; + } - if (_PointerDown == true) + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::setPointerDownString (const std::string &s) { - _PointerDownX = _PointerX; - _PointerDownY = _PointerY; + _PointerDownString = s; } - if (_PointerDown == false) - _PointerDrag = false; -} - -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::setPointerDownString (const std::string &s) -{ - _PointerDownString = s; -} + // +++ GET +++ -// +++ GET +++ + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerPos (sint32 &x, sint32 &y) + { + x = _PointerX; + y = _PointerY; + } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerPos (sint32 &x, sint32 &y) -{ - x = _PointerX; - y = _PointerY; -} + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerDispPos (sint32 &x, sint32 &y) + { + x = getX(); + y = getY(); + } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerDispPos (sint32 &x, sint32 &y) -{ - x = getX(); - y = getY(); -} + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerOldPos (sint32 &x, sint32 &y) + { + x = _PointerOldX; + y = _PointerOldY; + } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerOldPos (sint32 &x, sint32 &y) -{ - x = _PointerOldX; - y = _PointerOldY; -} + // -------------------------------------------------------------------------------------------------------------------- + void CViewPointerBase::getPointerDownPos (sint32 &x, sint32 &y) + { + x = _PointerDownX; + y = _PointerDownY; + } -// -------------------------------------------------------------------------------------------------------------------- -void CViewPointerBase::getPointerDownPos (sint32 &x, sint32 &y) -{ - x = _PointerDownX; - y = _PointerDownY; -} + // -------------------------------------------------------------------------------------------------------------------- + bool CViewPointerBase::getPointerDown () + { + return _PointerDown; + } -// -------------------------------------------------------------------------------------------------------------------- -bool CViewPointerBase::getPointerDown () -{ - return _PointerDown; -} + // -------------------------------------------------------------------------------------------------------------------- + bool CViewPointerBase::getPointerDrag () + { + return _PointerDrag; + } -// -------------------------------------------------------------------------------------------------------------------- -bool CViewPointerBase::getPointerDrag () -{ - return _PointerDrag; -} + // -------------------------------------------------------------------------------------------------------------------- + std::string CViewPointerBase::getPointerDownString () + { + return _PointerDownString; + } -// -------------------------------------------------------------------------------------------------------------------- -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" +namespace NLGUI +{ -CWidgetManager* CWidgetManager::instance = NULL; -std::string CWidgetManager::_CtrlLaunchingModalId= "ctrl_launch_modal"; -IParser* CWidgetManager::parser = NULL; + CWidgetManager* CWidgetManager::instance = NULL; + std::string CWidgetManager::_CtrlLaunchingModalId= "ctrl_launch_modal"; + IParser* CWidgetManager::parser = NULL; -// ---------------------------------------------------------------------------- -// SMasterGroup -// ---------------------------------------------------------------------------- + // ---------------------------------------------------------------------------- + // SMasterGroup + // ---------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::addWindow(CInterfaceGroup *pIG, uint8 nPrio) -{ - nlassert(nPrioisGroupInScene() ); + // 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) - { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) + for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) { - // If the element already exists in the list return ! - if (*it == pIG) - return; - it++; + 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); } - PrioritizedWindows[nPrio].push_back(pIG); -} -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::delWindow(CInterfaceGroup *pIG) -{ - 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) == pIG) + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) { - PrioritizedWindows[i].erase(it); - return; + if ((*it) == pIG) + { + PrioritizedWindows[i].erase(it); + return; + } + it++; } - it++; } } -} -// ---------------------------------------------------------------------------- -CInterfaceGroup* CWidgetManager::SMasterGroup::getWindowFromId(const std::string &winID) -{ - 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)->getId() == winID) - return *it; - it++; + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) + { + if ((*it)->getId() == winID) + return *it; + it++; + } } + return NULL; } - return NULL; -} -// ---------------------------------------------------------------------------- -bool CWidgetManager::SMasterGroup::isWindowPresent(CInterfaceGroup *pIG) -{ - 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) { - if ((*it) == pIG) - return true; - it++; + std::list::iterator it = PrioritizedWindows[i].begin(); + while (it != PrioritizedWindows[i].end()) + { + if ((*it) == pIG) + return true; + it++; + } } + return false; } - 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) + // 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) { - 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); + PrioritizedWindows[i].push_back(pIG); + LastTopWindowPriority= i; + return; + } + it++; } - it++; } + // todo hulud interface syntax error + nlwarning("window %s do not exist in a priority list", pIG->getId().c_str()); } - // 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) + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::setBackWindow(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 == 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 == pIG) + { + PrioritizedWindows[i].erase(it); + PrioritizedWindows[i].push_front(pIG); + return; + } + it++; } - it++; } + // todo hulud interface syntax error + nlwarning("window %s do not exist in a priority list", pIG->getId().c_str()); } - // 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) + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::deactiveAllContainers() { - std::list::iterator it = PrioritizedWindows[i].begin(); - while (it != PrioritizedWindows[i].end()) + 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) { - CGroupContainerBase *pGC = dynamic_cast(*it); - if (pGC != NULL) - gcs.push_back(pGC); - it++; + 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); + // 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) + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::centerAllContainers() { - 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->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); - } + 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++; + it++; + } } } -} -// ---------------------------------------------------------------------------- -void CWidgetManager::SMasterGroup::unlockAllContainers() -{ - for (uint8 i = 0; i < WIN_PRIORITY_MAX; ++i) + // ---------------------------------------------------------------------------- + void CWidgetManager::SMasterGroup::unlockAllContainers() { - 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()) + { + CGroupContainerBase *pGC = dynamic_cast(*it); + if (pGC != NULL) + pGC->setLocked(false); - it++; + it++; + } } } -} -class CElementToSort -{ -public: - CInterfaceGroup *pIG; - float Distance; - bool operator< (const CElementToSort& other) const + class CElementToSort { - // We want first farest views - return Distance > other.Distance; - } -}; - -void CWidgetManager::SMasterGroup::sortWorldSpaceGroup () -{ - static std::vector sortTable; - sortTable.clear (); + public: + CInterfaceGroup *pIG; + float Distance; + bool operator< (const CElementToSort& other) const + { + // We want first farest views + return Distance > other.Distance; + } + }; - // Fill the sort table - std::list::iterator it = PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].begin(); - while (it != PrioritizedWindows[WIN_PRIORITY_WORLD_SPACE].end()) + void CWidgetManager::SMasterGroup::sortWorldSpaceGroup () { - sortTable.push_back (CElementToSort ()); - CElementToSort &elm = sortTable.back(); - elm.pIG = *it; - elm.Distance = (*it)->getDepthForZSort(); + static std::vector sortTable; + sortTable.clear (); - it++; - } + // 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(); - // Sort the table - std::sort (sortTable.begin(), sortTable.end()); + it++; + } - // 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; + // Sort the table + std::sort (sortTable.begin(), sortTable.end()); - it++; - i++; - } -} + // 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; + it++; + i++; + } + } -CWidgetManager* CWidgetManager::getInstance() -{ - if( instance == NULL ) - instance = new CWidgetManager; - return instance; -} + CWidgetManager* CWidgetManager::getInstance() + { + if( instance == NULL ) + instance = new CWidgetManager; -void CWidgetManager::release() -{ - delete instance; - instance = NULL; -} + return instance; + } -// ---------------------------------------------------------------------------- -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); - if (pIG != NULL) - return pIG; + for (uint32 i = 0; i < _MasterGroups.size(); ++i) + { + if (_MasterGroups[i].Group->getId() == MasterGroupName) + return _MasterGroups[i].Group; + } + return NULL; } - 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) + // ---------------------------------------------------------------------------- + CInterfaceGroup* CWidgetManager::getWindowFromId (const std::string & groupId) { - SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getId() == sMasterGroupName) + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - rMG.addWindow(pIG, pIG->getPriority()); + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + CInterfaceGroup *pIG = rMG.getWindowFromId(groupId); + if (pIG != NULL) + return pIG; } + return NULL; } -} -// ---------------------------------------------------------------------------- -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) + // ---------------------------------------------------------------------------- + void CWidgetManager::addWindowToMasterGroup (const std::string &sMasterGroupName, CInterfaceGroup *pIG) { - SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getId() == sMasterGroupName) + // Warning this function is not smart : its a o(n) ! + if (pIG == NULL) return; + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); ++nMasterGroup) { - rMG.delWindow(pIG); + SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getId() == sMasterGroupName) + { + rMG.addWindow(pIG, pIG->getPriority()); + } } } -} -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::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 CWidgetManager::removeAllMasterGroups() -{ - uint i; + void unlinkAllContainers (CInterfaceGroup *pIG) + { + const std::vector &rG = pIG->getGroups(); + for(uint i = 0; i < rG.size(); ++i) + unlinkAllContainers (rG[i]); - for (i = 0; i < _MasterGroups.size(); ++i) - unlinkAllContainers (_MasterGroups[i].Group); + CGroupContainerBase *pGC = dynamic_cast(pIG); + if (pGC != NULL) + pGC->removeAllContainers(); + } - // 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()) + // *************************************************************************** + void CWidgetManager::removeAllMasterGroups() { - delete _MasterGroups.back().Group; - _MasterGroups.pop_back(); - } + 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) - { - pIG->setActive(bActive); - pIG->invalidateCoords(); } -} -// ------------------------------------------------------------------------------------------------ -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) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::activateMasterGroup (const std::string &sMasterGroupName, bool bActive) { - pIG = pIG->getParent(); + CInterfaceGroup *pIG = CWidgetManager::getInstance()->getMasterGroupFromId (sMasterGroupName); + if (pIG != NULL) + { + pIG->setActive(bActive); + pIG->invalidateCoords(); + } } - 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++) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getWindow(CInterfaceElement *pIE) { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - CInterfaceElement *pIEL = rMG.Group->getElement (sEltId); - if (pIEL != NULL) - return pIEL; + 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; } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -CInterfaceElement* CWidgetManager::getElementFromId (const std::string &sStart, const std::string &sEltId) -{ - CInterfaceElement *pIEL = getElementFromId (sEltId); - if (pIEL == NULL) + + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CWidgetManager::getElementFromId (const std::string &sEltId) { - std::string sZeStart = sStart, sTmp; - if (sZeStart[sZeStart.size()-1] == ':') - sZeStart = sZeStart.substr(0, sZeStart.size()-1); + // System special + if(sEltId == _CtrlLaunchingModalId) + return getCtrlLaunchingModal(); - 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); + 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 != "") + { + 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::setBackWindow(CInterfaceGroup* win) -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setTopWindow (CInterfaceGroup* win) { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) - rMG.setBackWindow(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); + } } -} -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CWidgetManager::getTopWindow (uint8 nPriority) const -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setBackWindow(CInterfaceGroup* win) { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - // return the first. - if(rMG.PrioritizedWindows[nPriority].empty()) - return NULL; - else - return rMG.PrioritizedWindows[nPriority].back(); + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + rMG.setBackWindow(win); } } - return NULL; -} + + // ------------------------------------------------------------------------------------------------ + 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++) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getBackWindow (uint8 nPriority) const { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - // return the first. - if(rMG.PrioritizedWindows[nPriority].empty()) - return NULL; - else - return rMG.PrioritizedWindows[nPriority].front(); + 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; } - return NULL; -} -// *************************************************************************** -CInterfaceGroup* CWidgetManager::getLastEscapableTopWindow() const -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // *************************************************************************** + CInterfaceGroup* CWidgetManager::getLastEscapableTopWindow() const { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) { - const std::list &rList = rMG.PrioritizedWindows[nPriority-1]; - std::list::const_reverse_iterator it; - it= rList.rbegin(); - for(;it!=rList.rend();it++) + 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; } - return NULL; -} -// *************************************************************************** -void CWidgetManager::setWindowPriority (CInterfaceGroup *pWin, uint8 nNewPriority) -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // *************************************************************************** + void CWidgetManager::setWindowPriority (CInterfaceGroup *pWin, uint8 nNewPriority) { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - if (rMG.isWindowPresent(pWin)) + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) { - rMG.delWindow(pWin); - rMG.addWindow(pWin, nNewPriority); + if (rMG.isWindowPresent(pWin)) + { + rMG.delWindow(pWin); + rMG.addWindow(pWin, nNewPriority); + } } } } -} -// *************************************************************************** -uint8 CWidgetManager::getLastTopWindowPriority() const -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // *************************************************************************** + uint8 CWidgetManager::getLastTopWindowPriority() const { - const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - return rMG.LastTopWindowPriority; + const CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) + { + return rMG.LastTopWindowPriority; + } } + return 0; } - 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 ) + bool CWidgetManager::hasModal() const + { + if( !_ModalStack.empty() ) return true; + else + return false; + } - return false; -} + CWidgetManager::SModalWndInfo& CWidgetManager::getModal() + { + return _ModalStack.back(); + } -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::enableModalWindow (CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG) -{ - // disable any modal before. release keyboard - disableModalWindow(); - pushModalWindow(ctrlLaunchingModal, pIG); -} + 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; -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::enableModalWindow (CCtrlBase *CtrlLaunchingModal, const std::string &groupName) -{ - CInterfaceGroup *group= dynamic_cast( getElementFromId(groupName) ); - if(group) + return false; + } + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::enableModalWindow (CCtrlBase *ctrlLaunchingModal, CInterfaceGroup *pIG) { - // enable the modal - enableModalWindow(CtrlLaunchingModal, group); + // disable any modal before. release keyboard + disableModalWindow(); + pushModalWindow(ctrlLaunchingModal, pIG); } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::disableModalWindow () -{ - while (!_ModalStack.empty()) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::enableModalWindow (CCtrlBase *CtrlLaunchingModal, const std::string &groupName) { - 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) + 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) - { - 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) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::disableModalWindow () + { + while (!_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 + // 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); + // enable the wanted modal + if(pIG) + { + 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::popModalWindow() -{ - if (!_ModalStack.empty()) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::pushModalWindow(CCtrlBase *ctrlLaunchingModal, const std::string &groupName) { - 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) + CInterfaceGroup *group= dynamic_cast( getElementFromId(groupName) ); + if(group) { - setBackWindow(winInfo.ModalWindow); - winInfo.ModalWindow->setActive(false); + // 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); + } + if (!_ModalStack.empty()) + { + if(_ModalStack.back().ModalWindow) + { + _ModalStack.back().ModalWindow->setActive(true); + setTopWindow(_ModalStack.back().ModalWindow); + } } } } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::popModalWindowCategory(const std::string &category) -{ - for(;;) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::popModalWindowCategory(const std::string &category) { - 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 + for(;;) { - break; + 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++) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getWindowUnder (sint32 x, sint32 y) { - CWidgetManager::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; - 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->isWindowUnder (x, y)) - return pIG; + CInterfaceGroup *pIG = *itw; + if (pIG->getActive() && pIG->getUseCursor()) + { + if (pIG->isWindowUnder (x, y)) + return pIG; + } } } } } + return NULL; } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -CInterfaceGroup* CWidgetManager::getGroupUnder (sint32 x, sint32 y) -{ - for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + // ------------------------------------------------------------------------------------------------ + CInterfaceGroup* CWidgetManager::getGroupUnder (sint32 x, sint32 y) { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + 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; - 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++) { - CInterfaceGroup *pIGunder = pIG->getGroupUnder (x ,y); - if (pIGunder != NULL) - return pIGunder; + CInterfaceGroup *pIG = *itw; + if (pIG->getActive() && pIG->getUseCursor()) + { + CInterfaceGroup *pIGunder = pIG->getGroupUnder (x ,y); + if (pIGunder != NULL) + return pIGunder; + } } } } } + return NULL; } - return NULL; -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::getViewsUnder (sint32 x, sint32 y, std::vector &vVB) -{ - vVB.clear (); + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::getViewsUnder (sint32 x, sint32 y, std::vector &vVB) + { + vVB.clear (); - // No Op if screen minimized - if(CViewRenderer::getInstance()->isMinimized()) - return; + // 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()) + uint32 sw, sh; + CViewRenderer::getInstance()->getScreenSize(sw, sh); + for (uint32 nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - for (uint8 nPriority = WIN_PRIORITY_MAX; nPriority > 0; nPriority--) + 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 ; + 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::getCtrlsUnder (sint32 x, sint32 y, std::vector &vICL) -{ - vICL.clear (); + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::getCtrlsUnder (sint32 x, sint32 y, std::vector &vICL) + { + vICL.clear (); - // No Op if screen minimized - if(CViewRenderer::getInstance()->isMinimized()) - return; + // 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()) + uint32 sw, sh; + CViewRenderer::getInstance()->getScreenSize(sw, sh); + 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 (!CWidgetManager::getInstance()->hasModal() || CWidgetManager::getInstance()->getModal().ModalWindow == pIG || CWidgetManager::getInstance()->getModal().ModalExitClickOut) - 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->getCtrlsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vICL)) - return; + 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 (); + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::getGroupsUnder (sint32 x, sint32 y, std::vector &vIGL) + { + vIGL.clear (); - // No Op if screen minimized - if(CViewRenderer::getInstance()->isMinimized()) - return; + // 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()) + uint32 sw, sh; + CViewRenderer::getInstance()->getScreenSize(sw, sh); + 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 (!CWidgetManager::getInstance()->hasModal() || CWidgetManager::getInstance()->getModal().ModalWindow == pIG || - CWidgetManager::getInstance()->getModal().ModalExitClickOut) - 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->isIn(x, y)) + 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()) { - vIGL.push_back(pIG); - pIG->getGroupsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vIGL); - return; + if (pIG->isIn(x, y)) + { + vIGL.push_back(pIG); + pIG->getGroupsUnder (x, y, 0, 0, (sint32) sw, (sint32) sh, vIGL); + return; + } } } } } } } -} -// *************************************************************************** -void CWidgetManager::removeRefOnView( CViewBase *viewBase ) -{ - uint i; - for (i=0; i<_ViewsUnderPointer.size(); i++) + // *************************************************************************** + void CWidgetManager::removeRefOnView( CViewBase *viewBase ) { - if (_ViewsUnderPointer[i] == viewBase) + uint i; + for (i=0; i<_ViewsUnderPointer.size(); i++) { - _ViewsUnderPointer.erase (_ViewsUnderPointer.begin()+i); - 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) + // *************************************************************************** + 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++) { - _CtrlsUnderPointer.erase (_CtrlsUnderPointer.begin()+i); - i--; + if (_CtrlsUnderPointer[i] == ctrlBase) + { + _CtrlsUnderPointer.erase (_CtrlsUnderPointer.begin()+i); + i--; + } } - } - // Unregister from ClockMsgTargets - unregisterClockMsgTarget(ctrlBase); -} + // Unregister from ClockMsgTargets + unregisterClockMsgTarget(ctrlBase); + } -// *************************************************************************** -void CWidgetManager::removeRefOnGroup (CInterfaceGroup *group) -{ - uint i; - for (i=0; i<_GroupsUnderPointer.size(); i++) + // *************************************************************************** + void CWidgetManager::removeRefOnGroup (CInterfaceGroup *group) { - if (_GroupsUnderPointer[i] == group) + uint i; + for (i=0; i<_GroupsUnderPointer.size(); i++) { - _GroupsUnderPointer.erase (_GroupsUnderPointer.begin()+i); - 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::reset() + { + setCurContextHelp( NULL ); + + _ViewsUnderPointer.clear(); + _CtrlsUnderPointer.clear(); + _GroupsUnderPointer.clear(); -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::checkCoords() -{ - H_AUTO ( RZ_Interface_validateCoords ) + _CaptureKeyboard = NULL; + _OldCaptureKeyboard = NULL; + setCapturePointerLeft(NULL); + setCapturePointerRight(NULL); + + resetColorProps(); + } - uint32 nMasterGroup; + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::checkCoords() { - H_AUTO ( RZ_Interface_checkCoords ) + H_AUTO ( RZ_Interface_validateCoords ) + + uint32 nMasterGroup; - // checkCoords all the windows - for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + H_AUTO ( RZ_Interface_checkCoords ) + + // checkCoords all the windows + for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) { - std::list &rList = rMG.PrioritizedWindows[nPriority]; - std::list::const_iterator itw; - for (itw = rList.begin(); itw!= rList.end();) + for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) { - CInterfaceGroup *pIG = *itw; - itw++; // since checkCoords invalidate the iterator, be sure we move to the next one before - if (pIG->getActive()) - pIG->checkCoords (); + std::list &rList = rMG.PrioritizedWindows[nPriority]; + std::list::const_iterator itw; + for (itw = rList.begin(); itw!= rList.end();) + { + CInterfaceGroup *pIG = *itw; + itw++; // since checkCoords invalidate the iterator, be sure we move to the next one before + if (pIG->getActive()) + pIG->checkCoords (); + } } } } } - } - bool bRecomputeCtrlUnderPtr = false; - { - H_AUTO ( RZ_Interface_updateCoords ) - - // updateCoords all the needed windows - for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) + bool bRecomputeCtrlUnderPtr = false; { - CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - if (rMG.Group->getActive()) + H_AUTO ( RZ_Interface_updateCoords ) + + // updateCoords all the needed windows + for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++) { - for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) + CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; + if (rMG.Group->getActive()) { - std::list &rList = rMG.PrioritizedWindows[nPriority]; - std::list::const_iterator itw; - for (itw = rList.begin(); itw!= rList.end(); itw++) + for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) { - 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)) + std::list &rList = rMG.PrioritizedWindows[nPriority]; + std::list::const_iterator itw; + for (itw = rList.begin(); itw!= rList.end(); itw++) { - 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;igetParent()==rMG.Group && (pIG->getInvalidCoords()>0)) { - pIG->updateCoords (); + 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); } - 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); } } } } - } - if ( CWidgetManager::getInstance()->getPointer() != NULL) - CWidgetManager::getInstance()->getPointer()->updateCoords(); - } + if ( CWidgetManager::getInstance()->getPointer() != NULL) + CWidgetManager::getInstance()->getPointer()->updateCoords(); + } - if (bRecomputeCtrlUnderPtr) - { - H_AUTO ( RZ_Interface_RecomputeCtrlUnderPtr ) - if ( CWidgetManager::getInstance()->getPointer() != NULL ) + if (bRecomputeCtrlUnderPtr) { - 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_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::movePointer (sint32 dx, sint32 dy) -{ - 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; + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::movePointer (sint32 dx, sint32 dy) + { + if (!_Pointer) + return; - newpx = oldpx + dx; - newpy = oldpy + dy; + uint32 nScrW, nScrH; + sint32 oldpx, oldpy, newpx, newpy, disppx, disppy, olddisppx, olddisppy; - 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; + CViewRenderer::getInstance()->getScreenSize (nScrW, nScrH); + _Pointer->getPointerPos (oldpx, oldpy); - disppx = newpx; - disppy = newpy; + olddisppx = oldpx; + olddisppy = oldpy; - _Pointer->setPointerPos (newpx, newpy); - _Pointer->setPointerDispPos (disppx, disppy); + newpx = oldpx + dx; + newpy = oldpy + dy; - // 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 (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; -// ------------------------------------------------------------------------------------------------ -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); -} + disppx = newpx; + disppy = newpy; -// *************************************************************************** -void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) -{ - // additionally, abort any dragging - if( CCtrlDraggable::getDraggedSheet() != NULL ) - CCtrlDraggable::getDraggedSheet()->abortDragging(); + _Pointer->setPointerPos (newpx, newpy); + _Pointer->setPointerDispPos (disppx, disppy); - _CapturePointerLeft = c; - notifyElementCaptured(c); -} + // 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::setCapturePointerRight(CCtrlBase *c) -{ - _CapturePointerRight = c; - notifyElementCaptured(c); -} + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::movePointerAbs(sint32 px, sint32 py) + { + if(!CWidgetManager::getInstance()->getPointer()) + return; -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::setCaptureKeyboard(CCtrlBase *c) -{ - CGroupEditBoxBase *oldEb= dynamic_cast((CCtrlBase*)_CaptureKeyboard); - CGroupEditBoxBase *newEb= dynamic_cast(c); + 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); + } - if (_CaptureKeyboard && _CaptureKeyboard != c) + // *************************************************************************** + void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) { - _CaptureKeyboard->onKeyboardCaptureLost(); + // additionally, abort any dragging + if( CCtrlDraggable::getDraggedSheet() != NULL ) + CCtrlDraggable::getDraggedSheet()->abortDragging(); + + _CapturePointerLeft = c; + notifyElementCaptured(c); } - // If the old capturedKeyboard is an editBox and allow recoverFocusOnEnter - if ( oldEb && oldEb->getRecoverFocusOnEnter() ) + + // *************************************************************************** + void CWidgetManager::setCapturePointerRight(CCtrlBase *c) { - _OldCaptureKeyboard = _CaptureKeyboard; + _CapturePointerRight = c; + notifyElementCaptured(c); } - if ( newEb ) + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setCaptureKeyboard(CCtrlBase *c) { - CGroupEditBoxBase::disableSelection(); + CGroupEditBoxBase *oldEb= dynamic_cast((CCtrlBase*)_CaptureKeyboard); + CGroupEditBoxBase *newEb= dynamic_cast(c); - if (!newEb->getAHOnFocus().empty()) + if (_CaptureKeyboard && _CaptureKeyboard != c) + { + _CaptureKeyboard->onKeyboardCaptureLost(); + } + // If the old capturedKeyboard is an editBox and allow recoverFocusOnEnter + if ( oldEb && oldEb->getRecoverFocusOnEnter() ) { - CAHManager::getInstance()->runActionHandler(newEb->getAHOnFocus(), newEb, newEb->getAHOnFocusParams()); + _OldCaptureKeyboard = _CaptureKeyboard; } + if ( newEb ) + { + CGroupEditBoxBase::disableSelection(); - } - _CaptureKeyboard = c; - notifyElementCaptured(c); -} + if (!newEb->getAHOnFocus().empty()) + { + CAHManager::getInstance()->runActionHandler(newEb->getAHOnFocus(), newEb, newEb->getAHOnFocusParams()); + } -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::resetCaptureKeyboard() -{ - CCtrlBase *captureKeyboard = _CaptureKeyboard; - _OldCaptureKeyboard = NULL; - _CaptureKeyboard = NULL; - if (captureKeyboard) - { - captureKeyboard->onKeyboardCaptureLost(); + } + _CaptureKeyboard = c; + notifyElementCaptured(c); } -} -// *************************************************************************** -void CWidgetManager::registerClockMsgTarget(CCtrlBase *vb) -{ - if (!vb) return; - if (isClockMsgTarget(vb)) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::resetCaptureKeyboard() { - nlwarning(" Element %s is already registered", vb->getId().c_str()); - return; + CCtrlBase *captureKeyboard = _CaptureKeyboard; + _OldCaptureKeyboard = NULL; + _CaptureKeyboard = NULL; + if (captureKeyboard) + { + captureKeyboard->onKeyboardCaptureLost(); + } } - _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()) + // *************************************************************************** + void CWidgetManager::registerClockMsgTarget(CCtrlBase *vb) { - _ClockMsgTargets.erase(it); + if (!vb) return; + if (isClockMsgTarget(vb)) + { + nlwarning(" Element %s is already registered", vb->getId().c_str()); + return; + } + _ClockMsgTargets.push_back(vb); } -} -// *************************************************************************** -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) + // *************************************************************************** + void CWidgetManager::unregisterClockMsgTarget(CCtrlBase *vb) { - _CapturePointerLeft->handleEvent(clockTick); - } - if (_CapturePointerRight) - { - _CapturePointerRight->handleEvent(clockTick); + if (!vb) return; + std::vector::iterator it = std::find(_ClockMsgTargets.begin(), _ClockMsgTargets.end(), vb); + if (it != _ClockMsgTargets.end()) + { + _ClockMsgTargets.erase(it); + } } - // 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) + // *************************************************************************** + bool CWidgetManager::isClockMsgTarget(CCtrlBase *vb) const { - (*it)->handleEvent(clockTick); + std::vector::const_iterator it = std::find(_ClockMsgTargets.begin(), _ClockMsgTargets.end(), vb); + return it != _ClockMsgTargets.end(); } -} -// ------------------------------------------------------------------------------------------------ -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) + void CWidgetManager::sendClockTickEvent() { - if (!seen.count(_CtrlsUnderPointer[i])) + NLGUI::CEventDescriptorSystem clockTick; + clockTick.setEventTypeExtended(NLGUI::CEventDescriptorSystem::clocktick); + + if (_CapturePointerLeft) { - _CtrlsUnderPointer[i]->elementCaptured(c); + _CapturePointerLeft->handleEvent(clockTick); + } + if (_CapturePointerRight) + { + _CapturePointerRight->handleEvent(clockTick); } - } -} - -// ------------------------------------------------------------------------------------------------ -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; + // 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); + } } - if (i == _MasterGroups.size()) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::notifyElementCaptured(CCtrlBase *c) { - 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)) + std::set seen; + CCtrlBase *curr = c; + while (curr) { - nlwarning("Window inserted twice"); + seen.insert(curr); + curr->elementCaptured(c); + curr = curr->getParent(); } - else + // also warn the ctrl under the pointer + for (uint i = 0; i < (uint) _CtrlsUnderPointer.size(); ++i) { - _MasterGroups[i].addWindow(group,group->getPriority()); + if (!seen.count(_CtrlsUnderPointer[i])) + { + _CtrlsUnderPointer[i]->elementCaptured(c); + } } } -} - -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::unMakeWindow(CInterfaceGroup *group, bool noWarning) -{ - if (!group) - return; - uint32 i = 0; - for (i = 0; i < _MasterGroups.size(); ++i) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::makeWindow(CInterfaceGroup *group) { - if (_MasterGroups[i].Group == group->getParent()) - break; - } + if(!group) + return; - if (i == _MasterGroups.size()) - { - if (!noWarning) + 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)) + { + nlwarning("Window inserted twice"); + } + else + { + _MasterGroups[i].addWindow(group,group->getPriority()); + } } - return; } - else + + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::unMakeWindow(CInterfaceGroup *group, bool noWarning) { - // check if group hasn't been inserted twice. - if (!_MasterGroups[i].isWindowPresent(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()) { if (!noWarning) - nlwarning("Window not inserted in master group"); + { + std::string stmp = std::string("not found master group for window: ")+group->getId(); + nlwarning (stmp.c_str()); + } + return; } else { - _MasterGroups[i].delWindow(group); + // 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); + } } } -} -// ------------------------------------------------------------------------------------------------ -void CWidgetManager::setGlobalColor (NLMISC::CRGBA col) -{ - if (!_RProp) + // ------------------------------------------------------------------------------------------------ + void CWidgetManager::setGlobalColor (NLMISC::CRGBA col) { - _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 (!_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; + _GlobalColor = col; - // set the global color for content (the same with modulated alpha) - _GlobalColorForContent = _GlobalColor; - _GlobalColorForContent.A = (uint8) (( (uint16) _GlobalColorForContent.A * (uint16) _ContentAlpha) >> 8); -} + // 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::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; -} + 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; -} + // ------------------------------------------------------------------------------------------------ + 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::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::removeOptions( std::string name ) + { + _OptionsMap.erase( name ); + } -void CWidgetManager::removeAllOptions() -{ - _OptionsMap.clear(); -} + void CWidgetManager::removeAllOptions() + { + _OptionsMap.clear(); + } -CWidgetManager::CWidgetManager() -{ - _Pointer = NULL; - curContextHelp = NULL; + CWidgetManager::CWidgetManager() + { + _Pointer = NULL; + curContextHelp = NULL; - resetColorProps(); + resetColorProps(); - _GlobalColor = NLMISC::CRGBA(255,255,255,255); - _GlobalColorForContent = _GlobalColor; - _ContentAlpha = 255; -} + _GlobalColor = NLMISC::CRGBA(255,255,255,255); + _GlobalColorForContent = _GlobalColor; + _ContentAlpha = 255; + } -CWidgetManager::~CWidgetManager() -{ - for (uint32 i = 0; i < _MasterGroups.size(); ++i) + CWidgetManager::~CWidgetManager() { - delete _MasterGroups[i].Group; + for (uint32 i = 0; i < _MasterGroups.size(); ++i) + { + delete _MasterGroups[i].Group; + } + + _Pointer = NULL; + curContextHelp = NULL; } - _Pointer = NULL; - curContextHelp = NULL; -} \ No newline at end of file +} + 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;