diff --git a/code/ryzom/client/src/interface_v3/action_handler_item.cpp b/code/ryzom/client/src/interface_v3/action_handler_item.cpp index 5c64d2219..e86c0691e 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_item.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_item.cpp @@ -909,7 +909,7 @@ class CIsPlayerItem : public IActionHandler public: virtual void execute (CCtrlBase *pCaller, const string &/* Params */) { - CDBCtrlSheet *cs = CDBCtrlSheet::getDraggedSheet(); + CDBCtrlSheet *cs = dynamic_cast< CDBCtrlSheet* >( CCtrlDraggable::getDraggedSheet() ); if (cs) { CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); diff --git a/code/ryzom/client/src/interface_v3/ctrl_draggable.cpp b/code/ryzom/client/src/interface_v3/ctrl_draggable.cpp new file mode 100644 index 000000000..7d98e7794 --- /dev/null +++ b/code/ryzom/client/src/interface_v3/ctrl_draggable.cpp @@ -0,0 +1,11 @@ +#include "ctrl_draggable.h" + +CCtrlDraggable* CCtrlDraggable::_LastDraggedSheet = NULL; + +CCtrlDraggable::CCtrlDraggable(const TCtorParam ¶m) : +CCtrlBase( param ) +{ + dragged = false; + draggable = false; +} + diff --git a/code/ryzom/client/src/interface_v3/ctrl_draggable.h b/code/ryzom/client/src/interface_v3/ctrl_draggable.h new file mode 100644 index 000000000..6b59af553 --- /dev/null +++ b/code/ryzom/client/src/interface_v3/ctrl_draggable.h @@ -0,0 +1,38 @@ +#ifndef CTRL_DRAGGABLE_H +#define CTRL_DRAGGABLE_H + +#include "ctrl_base.h" + +class CCtrlDraggable : public CCtrlBase +{ +public: + 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; + } + + + REFLECT_EXPORT_START(CCtrlDraggable, CCtrlBase) + REFLECT_BOOL("dragable", isDraggable, setDraggable); + REFLECT_EXPORT_END + +protected: + static void setDraggedSheet( CCtrlDraggable *draggable ){ _LastDraggedSheet = draggable; } + +private: + static CCtrlDraggable *_LastDraggedSheet; + bool dragged; + bool draggable; +}; + +#endif diff --git a/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp b/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp index c30fcf776..74a5bb132 100644 --- a/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp +++ b/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp @@ -62,7 +62,6 @@ using namespace STRING_MANAGER; NLMISC::CSmartPtr CDBCtrlSheet::_PhraseAdapter; CDBCtrlSheet *CDBCtrlSheet::_CurrSelection = NULL; -CDBCtrlSheet *CDBCtrlSheet::_LastDraggedSheet = NULL; CDBCtrlSheet *CDBCtrlSheet::_CurrMenuSheet = NULL; UMaterial CDBCtrlSheet::_GuildMat; @@ -131,7 +130,7 @@ ucstring CControlSheetTooltipInfoWaiter::infoValidated(CDBCtrlSheet* ctrlSheet, // *************************************************************************** int CDBCtrlSheet::luaGetDraggedSheet(CLuaState &ls) { - CLuaIHMRyzom::pushUIOnStack(ls, dynamic_cast(_LastDraggedSheet)); + CLuaIHMRyzom::pushUIOnStack(ls, dynamic_cast( dynamic_cast< CDBCtrlSheet* >( CCtrlDraggable::getDraggedSheet() ) )); return 1; } @@ -293,7 +292,6 @@ CCtrlSheetInfo::CCtrlSheetInfo() { _Type = CCtrlSheetInfo::SheetType_Item; _DispNoSheetBmpId = -1; - _Dragable = false; _InterfaceColor= true; _SheetSelectionGroup = -1; _UseQuality = true; @@ -379,9 +377,6 @@ bool CCtrlSheetInfo::parseCtrlInfo(xmlNodePtr cur, CInterfaceGroup * /* parentGr if (prop) _HasTradeSlotType= CInterfaceElement::convertBool(prop); - prop = (char*) xmlGetProp( cur, (xmlChar*)"dragable" ); - if (prop) _Dragable = CInterfaceElement::convertBool(prop); - // Read Action handlers CAHManager::getInstance()->parseAH(cur, "onclick_l", "params_l", _AHOnLeftClick, _AHLeftClickParams); CAHManager::getInstance()->parseAH(cur, "onclick_r", "params_r", _AHOnRightClick, _AHRightClickParams); @@ -502,8 +497,8 @@ bool CCtrlSheetInfo::parseCtrlInfo(xmlNodePtr cur, CInterfaceGroup * /* parentGr NLMISC_REGISTER_OBJECT(CViewBase, CDBCtrlSheet, std::string, "sheet"); // ---------------------------------------------------------------------------- -CDBCtrlSheet::CDBCtrlSheet(const TCtorParam ¶m) -: CCtrlBase(param) +CDBCtrlSheet::CDBCtrlSheet(const TCtorParam ¶m) : +CCtrlDraggable(param) { _LastSheetId = 0; _DispSlotBmpId= -1; @@ -511,7 +506,6 @@ CDBCtrlSheet::CDBCtrlSheet(const TCtorParam ¶m) _DispSheetBmpId = -1; _DispOverBmpId = -1; _DispOver2BmpId= -1; - _Draging = false; _CanDrop = false; _Stackable= 1; _DispQuality= -1; @@ -575,7 +569,8 @@ CDBCtrlSheet::~CDBCtrlSheet() // ensure erase static if(this==_CurrMenuSheet) _CurrMenuSheet = NULL; - if(this==_LastDraggedSheet) _LastDraggedSheet = NULL; + if(this == dynamic_cast< CDBCtrlSheet* >( CCtrlDraggable::getDraggedSheet() ) ) + setDraggedSheet( NULL ); if(this==_CurrSelection) _CurrSelection = NULL; } @@ -595,6 +590,12 @@ bool CDBCtrlSheet::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) if(!parseCtrlInfo(cur, parentGroup)) return false; + prop = (char*) xmlGetProp( cur, (xmlChar*)"dragable" ); + if( prop != NULL ) + setDraggable( CInterfaceElement::convertBool(prop) ); + else + setDraggable( false ); + if (_Type != SheetType_Macro) { prop = (char*) xmlGetProp( cur, (xmlChar*)"value" ); @@ -1865,7 +1866,7 @@ void CDBCtrlSheet::draw() if (CWidgetManager::getInstance()->getCurrentWindowUnder() == CWidgetManager::getInstance()->getWindow(this)) { CDBCtrlSheet *pCSSrc = dynamic_cast(CWidgetManager::getInstance()->getCapturePointerLeft()); - if ((pCSSrc != NULL) && pCSSrc->isDraging()) + if ((pCSSrc != NULL) && pCSSrc->isDragged()) { string params = string("src=") + pCSSrc->getId(); if (!_AHCanDropParams.empty()) @@ -1886,7 +1887,7 @@ void CDBCtrlSheet::draw() } } - drawSheet (_XReal+1, _YReal+1, _Draging); + drawSheet (_XReal+1, _YReal+1, isDragged() ); // Draw the selection after the sheet. Important for spells because selection border is same size as spell square if (_CanDrop) @@ -2512,7 +2513,7 @@ void CDBCtrlSheet::drawSheet (sint32 x, sint32 y, bool draging, bool showSelecti if (showSelectionBorder) { - if (!_Draging || (_Draging && _DuplicateOnDrag)) + if (!isDragged() || (isDragged() && _DuplicateOnDrag)) { // draw selection border if this sheet is selected if (_SheetSelectionGroup != -1) // is this sheet selectable ? @@ -2604,7 +2605,7 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) // Handle drag'n'drop if (CWidgetManager::getInstance()->getCapturePointerLeft() == this) { - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown && !_Draging) + if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown && !isDragged()) { _DragX = eventDesc.getX(); _DragY = eventDesc.getY(); @@ -2616,17 +2617,17 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) // Cannot drag if grayed (LOCKED or LATENT)!. Still can drag a shortcut if (asItemSheet() && asItemSheet()->Stackable > 1 && _UseQuantity) { - validClic = _Dragable && !_Draging && (getQuantity() > 0); + validClic = isDraggable() && !isDragged() && (getQuantity() > 0); validClic = validClic && (!getItemWeared()); } else { - validClic = _Dragable && !_Draging && ((!getItemWeared()&&!getGrayed()) || isShortCut()); + validClic = isDraggable() && !isDragged() && ((!getItemWeared()&&!getGrayed()) || isShortCut()); } } if (_Type == SheetType_Macro) { - validClic = _Dragable; + validClic = isDraggable(); } // posssibly check AH to see if really can draging @@ -2645,8 +2646,8 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) _DeltaDragY= _DragY-(_YReal+1); if (_DeltaDragX > _WReal) _DeltaDragX = _WReal; if (_DeltaDragY > _HReal) _DeltaDragY = _HReal; - _Draging = true; - _LastDraggedSheet = this; + setDragged( true ); + setDraggedSheet( this ); if (_AHOnDrag != NULL) { @@ -2655,7 +2656,7 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) } } - if (_Draging) + if (isDragged()) { // If mouse left up, must end the Drag if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftup) @@ -2827,8 +2828,8 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) } // In all case, quit - _Draging = false; - _LastDraggedSheet = NULL; + setDragged( false ); + setDraggedSheet( NULL ); // In call case, end of drag => consider handled to not call another action return true; } @@ -2836,7 +2837,7 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) } // If we are dragging, no more event on us - if(_Draging) + if(isDragged()) return false; // true; // Mouse events that must be done over the control @@ -2856,7 +2857,7 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) if(_AHOnLeftClick != NULL) CAHManager::getInstance()->runActionHandler (_AHOnLeftClick, this, _AHLeftClickParams); // Run Menu (if item is not being dragged) - if (!_ListMenuLeft.empty() && _LastDraggedSheet == NULL) + if (!_ListMenuLeft.empty() && dynamic_cast< CDBCtrlSheet* >( CCtrlDraggable::getDraggedSheet() ) == NULL) { if (getSheetId() != 0) { @@ -2891,7 +2892,7 @@ bool CDBCtrlSheet::handleEvent (const NLGUI::CEventDescriptor &event) { handled= true; // There must be no dragged sheet - if(_LastDraggedSheet == NULL) + if( dynamic_cast< CDBCtrlSheet* >( CCtrlDraggable::getDraggedSheet() ) == NULL) { // if a macro, don't test if Sheet==0 if ( isMacro() || getSheetId() != 0) @@ -2973,7 +2974,6 @@ void CDBCtrlSheet::swapSheet(CDBCtrlSheet *other) void CDBCtrlSheet::setCurrSelection(CDBCtrlSheet *selected) { _CurrSelection = selected; - CInterfaceManager *im = CInterfaceManager::getInstance(); NLGUI::CDBManager::getInstance()->getDbProp("UI:SELECTED_ITEM_SHEET_ID:SHEET")->setValue64(selected ? selected->getSheetId() : 0); NLGUI::CDBManager::getInstance()->getDbProp("UI:SELECTED_ITEM_SHEET_ID:QUALITY")->setValue64(selected ? selected->getQuality() : 0); NLGUI::CDBManager::getInstance()->getDbProp("UI:SELECTED_ITEM_SHEET_ID:SLOT_TYPE")->setValue64(selected ? selected->getBehaviour() : 0); @@ -4246,13 +4246,6 @@ ucstring CDBCtrlSheet::getItemActualName() const } } -// *************************************************************************** -void CDBCtrlSheet::abortDraging() -{ - _Draging = false; - _LastDraggedSheet = NULL; -} - // *************************************************************************** void CDBCtrlSheet::updateArmourColor(sint8 col) { diff --git a/code/ryzom/client/src/interface_v3/dbctrl_sheet.h b/code/ryzom/client/src/interface_v3/dbctrl_sheet.h index b683ea597..3071d78df 100644 --- a/code/ryzom/client/src/interface_v3/dbctrl_sheet.h +++ b/code/ryzom/client/src/interface_v3/dbctrl_sheet.h @@ -24,7 +24,7 @@ #include "nel/misc/smart_ptr.h" // client #include "nel/gui/reflect.h" -#include "ctrl_base.h" +#include "ctrl_draggable.h" #include "nel/gui/interface_expr.h" #include "action_handler.h" #include "sphrase_manager.h" @@ -135,7 +135,6 @@ public: // bool _InterfaceColor : 1; // Color given by the interface ? - bool _Dragable : 1; bool _UseQuantity : 1; // is the quantity read and displayed ? bool _ReadQuantityFromSheet : 1; // Read quantity from sheet rather than from database bool _UseQuality : 1; // is the quality read and displayed ? @@ -174,7 +173,7 @@ public: * \author Nevrax France * \date 2002 */ -class CDBCtrlSheet : public CCtrlBase, protected CCtrlSheetInfo +class CDBCtrlSheet : public CCtrlDraggable, protected CCtrlSheetInfo { public: DECLARE_UI_CLASS(CDBCtrlSheet) @@ -223,15 +222,11 @@ public: void setCanDrop (bool cd) { _CanDrop = cd; } bool getCanDrop () const { return _CanDrop; } - bool isDragable() { return _Dragable; } - void setDragable(bool dragable) { _Dragable = dragable; } - bool isDraging() { return _Draging; } sint32 getDeltaDragX() {return _DeltaDragX;} sint32 getDeltaDragY() {return _DeltaDragY;} // For "oncandrag" action handlers only, which would want to avoid the drag void setTempCanDrag(bool cd) {_TempCanDrag= cd;} // called when a setCapturePointerLeft(NULL) is made for instance - void abortDraging(); CCtrlSheetInfo::TSheetType getType () const; void setType (CCtrlSheetInfo::TSheetType type); @@ -267,7 +262,7 @@ public: void setSheet (const std::string &dbBranchId); void setSheetFast( const std::string &dbParentBranchId, int sheetNum, int slotNum ); - REFLECT_EXPORT_START(CDBCtrlSheet, CCtrlBase) + REFLECT_EXPORT_START(CDBCtrlSheet, CCtrlDraggable) REFLECT_STRING("sheet", getSheet, setSheet); REFLECT_RGBA("color", getSheetColor, setSheetColor); REFLECT_RGBA("color1", getGuildColor1, setGuildColor1); @@ -275,7 +270,6 @@ public: REFLECT_SINT32("back", getGuildBack, setGuildBack); REFLECT_SINT32("symbol", getGuildSymbol, setGuildSymbol); REFLECT_BOOL("invert_symbol", getInvertGuildSymbol, setInvertGuildSymbol); - REFLECT_BOOL("dragable", isDragable, setDragable); REFLECT_BOOL("can_drop", getCanDrop, setCanDrop); REFLECT_STRING ("left_click", getActionOnLeftClick, setActionOnLeftClick); REFLECT_STRING ("right_click", getActionOnRightClick, setActionOnRightClick); @@ -341,7 +335,7 @@ public: static uint getInventorySlot( const std::string &dbBranchId ); // Get the last dropped sheet. The pointer is only valid during the call of the event handler - static CDBCtrlSheet *getDraggedSheet() { return _LastDraggedSheet; } + //static CDBCtrlSheet *getDraggedSheet() { return _LastDraggedSheet; } /* Get the last selected sheet that have been draged or right clicked (should be use by menu to get their caller) * It is used by the item actions like destroy, move etc.. @@ -649,7 +643,6 @@ protected: /// Events - bool _Draging : 1; bool _CanDrop : 1; bool _Over : 1; @@ -753,7 +746,6 @@ private: mutable TSheetType _ActualType; static CDBCtrlSheet *_CurrSelection; - static CDBCtrlSheet *_LastDraggedSheet; static CDBCtrlSheet *_CurrMenuSheet; private: void updateActualType() const; diff --git a/code/ryzom/client/src/interface_v3/dbgroup_list_sheet.cpp b/code/ryzom/client/src/interface_v3/dbgroup_list_sheet.cpp index b9ca8c283..83d29b76f 100644 --- a/code/ryzom/client/src/interface_v3/dbgroup_list_sheet.cpp +++ b/code/ryzom/client/src/interface_v3/dbgroup_list_sheet.cpp @@ -722,7 +722,7 @@ void CDBGroupListSheet::draw () (CWidgetManager::getInstance()->getPointer()->getY() <= (_YReal+ _HReal))) { CDBCtrlSheet *pCSSrc = dynamic_cast(CWidgetManager::getInstance()->getCapturePointerLeft()); - if ((pCSSrc != NULL) && pCSSrc->isDraging()) + if ((pCSSrc != NULL) && pCSSrc->isDragged()) { string params = string("src=") + pCSSrc->getId(); if (!_CtrlInfo._AHCanDropParams.empty()) diff --git a/code/ryzom/client/src/interface_v3/dbgroup_list_sheet_text.cpp b/code/ryzom/client/src/interface_v3/dbgroup_list_sheet_text.cpp index 250f7adcc..02ee3fa14 100644 --- a/code/ryzom/client/src/interface_v3/dbgroup_list_sheet_text.cpp +++ b/code/ryzom/client/src/interface_v3/dbgroup_list_sheet_text.cpp @@ -632,7 +632,7 @@ void CDBGroupListSheetText::draw () (CWidgetManager::getInstance()->getPointer()->getY() <= (_YReal+ _HReal))) { CDBCtrlSheet *pCSSrc = dynamic_cast(CWidgetManager::getInstance()->getCapturePointerLeft()); - if ((pCSSrc != NULL) && pCSSrc->isDraging()) + if ((pCSSrc != NULL) && pCSSrc->isDragged()) { string params = string("src=") + pCSSrc->getId(); if (!_CtrlInfo._AHCanDropParams.empty()) @@ -683,7 +683,7 @@ bool CDBGroupListSheetText::handleEvent (const NLGUI::CEventDescriptor &event) // A button has been captured -> Transform the capture to the corresponding ctrlsheet sint pos = getIndexOf(pCB); if ((pos >= 0) && - _SheetChildren[pos]->Ctrl->isDragable() && (!_SheetChildren[pos]->Ctrl->getGrayed())) + _SheetChildren[pos]->Ctrl->isDraggable() && (!_SheetChildren[pos]->Ctrl->getGrayed())) { pDraggedSheet = _SheetChildren[pos]->Ctrl; CWidgetManager::getInstance()->setCapturePointerLeft(pDraggedSheet); diff --git a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp index 356ca8c38..23807a361 100644 --- a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp +++ b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp @@ -134,7 +134,7 @@ REGISTER_INTERFACE_USER_FCT("getSelectedItemPrice", getSelectedItemPrice) ///////////////////////////////////////////////// static DECLARE_INTERFACE_USER_FCT(getDraggedSheet) { - result.setUserType(new CDBCtrlSheetPtrUserType(CDBCtrlSheet::getDraggedSheet())); + result.setUserType(new CDBCtrlSheetPtrUserType( dynamic_cast< CDBCtrlSheet* >( CDBCtrlSheet::getDraggedSheet() ) )); return true; } REGISTER_INTERFACE_USER_FCT("getDraggedSheet", getDraggedSheet) diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index 3a16927ea..63406bcb3 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -1941,7 +1941,7 @@ void CInterfaceManager::drawViews(NL3D::UCamera camera) if ( CWidgetManager::getInstance()->getPointer()->show()) { CDBCtrlSheet *pCS = dynamic_cast( CWidgetManager::getInstance()->getCapturePointerLeft() ); - if ((pCS != NULL) && (pCS->isDraging())) + if ((pCS != NULL) && (pCS->isDragged())) { sint x= CWidgetManager::getInstance()->getPointer()->getX() - pCS->getDeltaDragX(); sint y= CWidgetManager::getInstance()->getPointer()->getY() - pCS->getDeltaDragY(); diff --git a/code/ryzom/client/src/interface_v3/widget_manager.cpp b/code/ryzom/client/src/interface_v3/widget_manager.cpp index a27d674fd..740218e8b 100644 --- a/code/ryzom/client/src/interface_v3/widget_manager.cpp +++ b/code/ryzom/client/src/interface_v3/widget_manager.cpp @@ -20,7 +20,7 @@ #include "group_in_scene.h" #include "view_pointer.h" #include "group_editbox.h" -#include "dbctrl_sheet.h" +#include "ctrl_draggable.h" CWidgetManager* CWidgetManager::instance = NULL; std::string CWidgetManager::_CtrlLaunchingModalId= "ctrl_launch_modal"; @@ -1110,10 +1110,9 @@ void CWidgetManager::movePointerAbs(sint32 px, sint32 py) void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) { // additionally, abort any dragging - if(CDBCtrlSheet::getDraggedSheet()) - { - CDBCtrlSheet::getDraggedSheet()->abortDraging(); - } + if( CCtrlDraggable::getDraggedSheet() != NULL ) + CCtrlDraggable::getDraggedSheet()->abortDragging(); + _CapturePointerLeft = c; notifyElementCaptured(c); }