MODIFIED: Views can now be selected too from the central widget.

This commit is contained in:
dfighter1985 2013-02-23 00:13:44 +01:00
parent 93de10c56d
commit dcad62844b
10 changed files with 72 additions and 11 deletions

View file

@ -68,9 +68,7 @@ namespace NLGUI
// special parse // special parse
virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup); virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup);
bool handleEvent (const NLGUI::CEventDescriptor &event);
/// 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; } virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; }

View file

@ -473,6 +473,7 @@ namespace NLGUI
bool isInGroup( CInterfaceGroup *group ); bool isInGroup( CInterfaceGroup *group );
static void setEditorMode( bool b ){ editorMode = b; } static void setEditorMode( bool b ){ editorMode = b; }
static bool getEditorMode(){ return editorMode; }
void setEditorSelected( bool b ){ editorSelected = b; } void setEditorSelected( bool b ){ editorSelected = b; }
bool isEditorSelected() const{ return editorSelected; } bool isEditorSelected() const{ return editorSelected; }

View file

@ -25,6 +25,7 @@
namespace NLGUI namespace NLGUI
{ {
class CEventDescriptor;
class CViewBase : public CInterfaceElement class CViewBase : public CInterfaceElement
{ {
@ -76,6 +77,9 @@ namespace NLGUI
// special for mouse over : return true and fill the name of the cursor to display // 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 bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; }
/// Handle all events (implemented by derived classes) (return true to signal event handled)
virtual bool handleEvent (const NLGUI::CEventDescriptor &evnt);
}; };

View file

@ -188,6 +188,8 @@ namespace NLGUI
int luaSetLineMaxW(CLuaState &ls); int luaSetLineMaxW(CLuaState &ls);
bool handleEvent( const NLGUI::CEventDescriptor &evnt );
REFLECT_EXPORT_START(CViewText, CViewBase) REFLECT_EXPORT_START(CViewText, CViewBase)
REFLECT_STRING("hardtext", getHardText, setHardText); REFLECT_STRING("hardtext", getHardText, setHardText);
REFLECT_UCSTRING("uc_hardtext", getText, setText); REFLECT_UCSTRING("uc_hardtext", getText, setText);

View file

@ -341,6 +341,7 @@ namespace NLGUI
/** /**
* Capture * Capture
*/ */
CViewBase *getCapturedView(){ return _CapturedView; }
CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; } CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; }
CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; } CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; }
CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; } CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; }
@ -510,6 +511,8 @@ namespace NLGUI
NLMISC::CRefPtr<CCtrlBase> _CapturePointerLeft; NLMISC::CRefPtr<CCtrlBase> _CapturePointerLeft;
NLMISC::CRefPtr<CCtrlBase> _CapturePointerRight; NLMISC::CRefPtr<CCtrlBase> _CapturePointerRight;
NLMISC::CRefPtr< CViewBase > _CapturedView;
// What is under pointer // What is under pointer
std::vector< CViewBase* > _ViewsUnderPointer; std::vector< CViewBase* > _ViewsUnderPointer;
std::vector< CCtrlBase* > _CtrlsUnderPointer; std::vector< CCtrlBase* > _CtrlsUnderPointer;

View file

@ -37,6 +37,9 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event) bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event)
{ {
if( CViewBase::handleEvent( event ) )
return true;
if (event.getType() == NLGUI::CEventDescriptor::system) if (event.getType() == NLGUI::CEventDescriptor::system)
{ {
NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event;

View file

@ -668,12 +668,6 @@ namespace NLGUI
if (CWidgetManager::getInstance()->getCapturePointerLeft() != this) if (CWidgetManager::getInstance()->getCapturePointerLeft() != this)
return false; return false;
if( editorMode )
{
CWidgetManager::getInstance()->setCurrentEditorSelection( getId() );
return true;
}
if (_LeftDblClickHandled) // no effect on mouse up after double click has been handled if (_LeftDblClickHandled) // no effect on mouse up after double click has been handled
{ {
_LeftDblClickHandled = false; _LeftDblClickHandled = false;

View file

@ -45,5 +45,23 @@ namespace NLGUI
CInterfaceElement::visit(visitor); CInterfaceElement::visit(visitor);
} }
bool CViewBase::handleEvent( const NLGUI::CEventDescriptor &evnt )
{
if( evnt.getType() == NLGUI::CEventDescriptor::mouse )
{
const NLGUI::CEventDescriptorMouse &eventDesc = ( const NLGUI::CEventDescriptorMouse& )evnt;
if( eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown )
{
if( editorMode )
{
CWidgetManager::getInstance()->setCurrentEditorSelection( getId() );
return true;
}
}
}
return false;
}
} }

View file

@ -2945,6 +2945,11 @@ namespace NLGUI
} }
} }
bool CViewText::handleEvent( const NLGUI::CEventDescriptor &evnt )
{
return false;
}
// *************************************************************************** // ***************************************************************************
void CViewText::serial(NLMISC::IStream &f) void CViewText::serial(NLMISC::IStream &f)
{ {

View file

@ -1031,6 +1031,7 @@ namespace NLGUI
_OldCaptureKeyboard = NULL; _OldCaptureKeyboard = NULL;
setCapturePointerLeft(NULL); setCapturePointerLeft(NULL);
setCapturePointerRight(NULL); setCapturePointerRight(NULL);
_CapturedView = NULL;
resetColorProps(); resetColorProps();
@ -2086,6 +2087,12 @@ namespace NLGUI
getCapturePointerRight()->handleEvent( evnt ); getCapturePointerRight()->handleEvent( evnt );
setCapturePointerRight( NULL ); setCapturePointerRight( NULL );
} }
if( _CapturedView != NULL )
{
_CapturedView->handleEvent( evnt );
_CapturedView = NULL;
}
} }
} }
@ -2249,6 +2256,9 @@ namespace NLGUI
getCapturePointerLeft() != getCapturePointerRight() ) getCapturePointerLeft() != getCapturePointerRight() )
handled|= getCapturePointerRight()->handleEvent(evnt); handled|= getCapturePointerRight()->handleEvent(evnt);
if( _CapturedView != NULL )
_CapturedView->handleEvent( evnt );
CInterfaceGroup *ptr = getWindowUnder (eventDesc.getX(), eventDesc.getY()); CInterfaceGroup *ptr = getWindowUnder (eventDesc.getX(), eventDesc.getY());
setCurrentWindowUnder( ptr ); setCurrentWindowUnder( ptr );
@ -2326,6 +2336,8 @@ namespace NLGUI
} }
} }
bool captured = false;
// must not capture a new element if a sheet is currentlty being dragged. // must not capture a new element if a sheet is currentlty being dragged.
// This may happen when alt-tab has been used => the sheet is dragged but the left button is up // This may happen when alt-tab has been used => the sheet is dragged but the left button is up
if (!CCtrlDraggable::getDraggedSheet()) if (!CCtrlDraggable::getDraggedSheet())
@ -2343,9 +2355,25 @@ namespace NLGUI
{ {
nMaxDepth = d; nMaxDepth = d;
setCapturePointerLeft( ctrl ); setCapturePointerLeft( ctrl );
captured = true;
} }
} }
} }
if( CInterfaceElement::getEditorMode() && !captured )
{
for( sint32 i = _ViewsUnderPointer.size()-1; i >= 0; i-- )
{
CViewBase *v = _ViewsUnderPointer[i];
if( ( v != NULL ) && v->isInGroup( pNewCurrentWnd ) )
{
_CapturedView = v;
captured = true;
break;
}
}
}
notifyElementCaptured( getCapturePointerLeft() ); notifyElementCaptured( getCapturePointerLeft() );
if (clickedOutModalWindow && !clickedOutModalWindow->OnPostClickOut.empty()) if (clickedOutModalWindow && !clickedOutModalWindow->OnPostClickOut.empty())
{ {
@ -2353,13 +2381,16 @@ namespace NLGUI
} }
} }
//if found //if found
if ( getCapturePointerLeft() != NULL) if ( captured )
{ {
// consider clicking on a control implies handling of the event. // consider clicking on a control implies handling of the event.
handled= true; handled= true;
// handle the capture // handle the capture
getCapturePointerLeft()->handleEvent(evnt); if( getCapturePointerLeft() != NULL )
getCapturePointerLeft()->handleEvent(evnt);
else
_CapturedView->handleEvent( evnt );
} }
} }
@ -2588,6 +2619,8 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) void CWidgetManager::setCapturePointerLeft(CCtrlBase *c)
{ {
_CapturedView = NULL;
// additionally, abort any dragging // additionally, abort any dragging
if( CCtrlDraggable::getDraggedSheet() != NULL ) if( CCtrlDraggable::getDraggedSheet() != NULL )
CCtrlDraggable::getDraggedSheet()->abortDragging(); CCtrlDraggable::getDraggedSheet()->abortDragging();