Merged the gui-editor branch.

This commit is contained in:
dfighter1985 2014-09-17 21:12:14 +02:00
commit e40ecbda00
5 changed files with 554 additions and 434 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

@ -333,6 +333,12 @@ namespace NLGUI
bool handleEvent( const CEventDescriptor &evnt );
bool handleSystemEvent( const CEventDescriptor &evnt );
bool handleKeyboardEvent( const CEventDescriptor &evnt );
bool handleMouseEvent( const CEventDescriptor &evnt );
bool handleMouseMoveEvent( const CEventDescriptor &eventDesc );
// Relative move of pointer
@ -526,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();
@ -2096,7 +2102,30 @@ namespace NLGUI
if( activeAnims[i]->isDisableButtons() )
return false;
bool handled = false;
CViewPointer *_Pointer = static_cast< CViewPointer* >( getPointer() );
if( evnt.getType() == CEventDescriptor::system )
{
handleSystemEvent( evnt );
}
else
if (evnt.getType() == CEventDescriptor::key)
{
handled = handleKeyboardEvent( evnt );
}
else if (evnt.getType() == CEventDescriptor::mouse )
{
handled = handleMouseEvent( evnt );
}
CDBManager::getInstance()->flushObserverCalls();
return handled;
}
bool CWidgetManager::handleSystemEvent( const CEventDescriptor &evnt )
{
const CEventDescriptorSystem &systemEvent = reinterpret_cast< const CEventDescriptorSystem& >( evnt );
if( systemEvent.getEventTypeExtended() == CEventDescriptorSystem::setfocus )
@ -2119,15 +2148,16 @@ namespace NLGUI
_CapturedView = NULL;
}
}
return true;
}
bool CWidgetManager::handleKeyboardEvent( const CEventDescriptor &evnt )
{
bool handled = false;
CViewPointer *_Pointer = static_cast< CViewPointer* >( getPointer() );
if (evnt.getType() == CEventDescriptor::key)
{
CEventDescriptorKey &eventDesc = (CEventDescriptorKey&)evnt;
//_LastEventKeyDesc = eventDesc;
// Any Key event disable the ContextHelp
@ -2246,12 +2276,14 @@ namespace NLGUI
}
lastKeyEvent = eventDesc;
return handled;
}
//////////////////////////////////////////////// Keyboard handling ends here ////////////////////////////////////
else if (evnt.getType() == CEventDescriptor::mouse )
bool CWidgetManager::handleMouseEvent( const CEventDescriptor &evnt )
{
bool handled = false;
CEventDescriptorMouse &eventDesc = (CEventDescriptorMouse&)evnt;
if( eventDesc.getEventTypeExtended() == CEventDescriptorMouse::mouseleftdown )
@ -2411,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 );
}
}
@ -2508,6 +2540,11 @@ namespace NLGUI
setCapturePointerLeft(NULL);
handled = true;
}
_CapturedView = NULL;
if( CInterfaceElement::getEditorMode() )
stopDragging();
}
@ -2538,14 +2575,10 @@ namespace NLGUI
// If the mouse is over a window, always consider the event is taken (avoid click behind)
handled|= isMouseOverWindow();
}
}
CDBManager::getInstance()->flushObserverCalls();
return handled;
}
bool CWidgetManager::handleMouseMoveEvent( const CEventDescriptor &eventDesc )
{
if( getPointer() == NULL )
@ -2580,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)
{