We can now drag elements, they will disappear and whatnot, but at least they can be dragged!

This commit is contained in:
dfighter1985 2014-04-21 19:30:33 +02:00
parent 83e0c1ceda
commit 916c9bf919
5 changed files with 96 additions and 4 deletions

View file

@ -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(); }

View file

@ -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;

View file

@ -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;

View file

@ -1638,6 +1638,32 @@ namespace NLGUI
return delView(static_cast<CViewBase*>(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)
{

View file

@ -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,10 +2443,10 @@ 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 = getCapturePointerLeft();
// handle the capture
_CapturedView->handleEvent( evnt );
}
}
@ -2534,6 +2540,11 @@ namespace NLGUI
setCapturePointerLeft(NULL);
handled = true;
}
_CapturedView = NULL;
if( CInterfaceElement::getEditorMode() )
stopDragging();
}
@ -2602,9 +2613,53 @@ 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)
{