From 4abf74d6e9738efee8830dcde5029f1c71484062 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 21 Apr 2014 19:30:33 +0200 Subject: [PATCH] We can now drag elements, they will disappear and whatnot, but at least they can be dragged! --HG-- branch : gui-editor --- code/nel/include/nel/gui/interface_element.h | 3 + code/nel/include/nel/gui/interface_group.h | 3 + code/nel/include/nel/gui/widget_manager.h | 5 ++ code/nel/src/gui/interface_group.cpp | 26 ++++++++ code/nel/src/gui/widget_manager.cpp | 63 ++++++++++++++++++-- 5 files changed, 96 insertions(+), 4 deletions(-) diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 764d165ef..db7a499c8 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -233,6 +233,9 @@ namespace NLGUI virtual void setActive (bool state); + void setXReal( sint32 x ){ _XReal = x; } + void setYReal( sint32 y ){ _YReal = y; } + void setX (sint32 x) { _X = x; } void setXAndInvalidateCoords (sint32 x) { _X = x; invalidateCoords(); } diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index f72bc6f1f..ff0efac3b 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -79,6 +79,9 @@ namespace NLGUI bool delElement (const std::string &id, bool noWarning=false); bool delElement (CInterfaceElement *pIE, bool noWarning=false); + // Take the element from the group, but don't delete it! + CInterfaceElement* takeElement( CInterfaceElement *e ); + uint getNumGroup() const { return (uint)_ChildrenGroups.size(); } CInterfaceGroup *getGroup(uint index) const; diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 6d4f47164..5d2468e7a 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -532,6 +532,11 @@ namespace NLGUI NLMISC::CRefPtr< CViewBase > _CapturedView; + NLMISC::CRefPtr< CInterfaceElement > draggedElement; + + bool startDragging(); + void stopDragging(); + // What is under pointer std::vector< CViewBase* > _ViewsUnderPointer; std::vector< CCtrlBase* > _CtrlsUnderPointer; diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index 5fa83e1c5..4d37eda1c 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -1638,6 +1638,32 @@ namespace NLGUI return delView(static_cast(pIE)); } + // ------------------------------------------------------------------------------------------------ + CInterfaceElement* CInterfaceGroup::takeElement( CInterfaceElement *e ) + { + bool ok = false; + + if( e->isGroup() ) + { + ok = delGroup( static_cast< CInterfaceGroup* >( e ), true ); + } + else + if( e->isCtrl() ) + { + ok = delCtrl( static_cast< CCtrlBase* >( e ), true ); + } + else + if( e->isView() ) + { + ok = delView( static_cast< CViewBase* >( e ), true ); + } + + if( ok ) + return e; + else + return NULL; + } + // ------------------------------------------------------------------------------------------------ bool CInterfaceGroup::isWindowUnder (sint32 x, sint32 y) { diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index 2c3f1159e..e3f1064fa 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -2039,6 +2039,12 @@ namespace NLGUI } } + if( draggedElement != NULL ) + { + CInterfaceElement *e = draggedElement; + static_cast< CViewBase* >( e )->draw(); + } + if ( (nPriority == WIN_PRIORITY_WORLD_SPACE) && !camera.empty()) { driver->setMatrixMode2D11(); @@ -2437,11 +2443,11 @@ namespace NLGUI // consider clicking on a control implies handling of the event. handled= true; - // handle the capture if( getCapturePointerLeft() != NULL ) - getCapturePointerLeft()->handleEvent(evnt); - else - _CapturedView->handleEvent( evnt ); + _CapturedView = getCapturePointerLeft(); + + // handle the capture + _CapturedView->handleEvent( evnt ); } } @@ -2534,6 +2540,11 @@ namespace NLGUI setCapturePointerLeft(NULL); handled = true; } + + _CapturedView = NULL; + + if( CInterfaceElement::getEditorMode() ) + stopDragging(); } @@ -2602,8 +2613,52 @@ namespace NLGUI ve.setY( getPointer()->getY() ); } + if( CInterfaceElement::getEditorMode() ) + { + if( ( _CapturedView != NULL ) && ( draggedElement == NULL ) ) + { + startDragging(); + } + else + if( draggedElement != NULL ) + { + draggedElement->setXReal( newX ); + draggedElement->setYReal( newY ); + draggedElement->invalidateCoords(); + } + } + return true; } + + // ------------------------------------------------------------------------------------------------ + bool CWidgetManager::startDragging() + { + CInterfaceElement *e = NULL; + + CInterfaceGroup *g = _CapturedView->getParent(); + if( g != NULL ) + { + e = g->takeElement( _CapturedView ); + if( e == NULL ) + { + nlinfo( "Something went horribly wrong :(" ); + return false; + } + } + else + e = _CapturedView; + + e->setParent( NULL ); + draggedElement = e; + + return true; + } + + void CWidgetManager::stopDragging() + { + draggedElement = NULL; + } // ------------------------------------------------------------------------------------------------ void CWidgetManager::movePointer (sint32 dx, sint32 dy)