ADDED: #1471 new class CEventListener that can register with the NEl event server and then send the pumped events to a CInputHandler instance which ofc translates them to Nel GUI events and sends them to whoever listens. Also added a timer to NelGUIWidget which periodically pumps events and redraws the viewport.

--HG--
branch : gsoc2012-gui-editor
This commit is contained in:
dfighter1985 2012-07-21 21:12:43 +02:00
parent 165762c94c
commit 0d21b4fd29
13 changed files with 199 additions and 2 deletions

View file

@ -0,0 +1,44 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef EVENT_LISTENER
#define EVENT_LISTENER
#include "nel/misc/event_listener.h"
#include "nel/gui/input_handler.h"
namespace NLGUI
{
class CEventListener : public NLMISC::IEventListener
{
public:
CEventListener();
~CEventListener();
void addToServer( NLMISC::CEventServer *server );
void removeFromServer();
void operator()( const NLMISC::CEvent &evnt );
private:
NLGUI::CInputHandler inputHandler;
NLMISC::CEventServer *eventServer;
};
}
#endif

View file

@ -66,6 +66,7 @@ namespace NLGUI
void show(bool s) {_PointerVisible = s;}
static void setHWMouse( bool hw ){ hwMouse = hw; }
static void forceLink();
private:

View file

@ -29,6 +29,7 @@
#include "nel/gui/event_descriptor.h"
#include "nel/3d/u_camera.h"
#include "nel/gui/parser.h"
#include "nel/gui/input_event_listener.h"
namespace NLMISC
{
@ -52,7 +53,7 @@ namespace NLGUI
Manages the GUI widgets, asks them to draw themselves, etc.
*/
class CWidgetManager{
class CWidgetManager : public IInputEventListener{
public:

View file

@ -1,3 +1,20 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "nel/gui/db_manager.h"
namespace NLGUI

View file

@ -0,0 +1,61 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "nel/misc/event_server.h"
#include "nel/gui/event_listener.h"
#include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h"
namespace NLGUI
{
CEventListener::CEventListener()
{
inputHandler.setListener( CWidgetManager::getInstance() );
}
CEventListener::~CEventListener()
{
}
void CEventListener::addToServer( NLMISC::CEventServer *server )
{
server->addListener( NLMISC::EventMouseMoveId, this );
server->addListener( NLMISC::EventMouseDownId, this );
server->addListener( NLMISC::EventMouseUpId, this );
server->addListener( NLMISC::EventMouseWheelId, this );
server->addListener( NLMISC::EventMouseDblClkId, this );
eventServer = server;
}
void CEventListener::removeFromServer()
{
eventServer->removeListener( NLMISC::EventMouseMoveId, this );
eventServer->removeListener( NLMISC::EventMouseDownId, this );
eventServer->removeListener( NLMISC::EventMouseUpId, this );
eventServer->removeListener( NLMISC::EventMouseWheelId, this );
eventServer->removeListener( NLMISC::EventMouseDblClkId, this );
eventServer = NULL;
}
void CEventListener::operator ()(const NLMISC::CEvent &evnt)
{
inputHandler.handleEvent( evnt );
}
}

View file

@ -437,6 +437,15 @@ namespace NLGUI
NLMISC::CHTimer::display(&log, CHTimer::TotalTime);
*/
if( ok )
{
if( CWidgetManager::getInstance()->getPointer() == NULL )
{
CViewPointer *pointer = dynamic_cast< CViewPointer* >( NLMISC_GET_FACTORY(CViewBase, std::string).createObject( "generic_pointer", CViewBase::TCtorParam() ) );
CWidgetManager::getInstance()->setPointer( pointer );
}
}
return ok;
}

View file

@ -1,6 +1,7 @@
#include "nel/gui/dbview_bar3.h"
#include "nel/gui/dbview_number.h"
#include "nel/gui/dbview_quantity.h"
#include "nel/gui/view_pointer.h"
namespace NLGUI
{
@ -12,6 +13,7 @@ namespace NLGUI
CDBViewBar3::forceLink();
CDBViewNumber::forceLink();
CDBViewQuantity::forceLink();
CViewPointer::forceLink();
ifexprufct_forcelink();
}
}

View file

@ -60,6 +60,10 @@ namespace NLGUI
_StringCursor = NULL;
}
void CViewPointer::forceLink()
{
}
// +++ VIEW SPECIFIC +++

View file

@ -2492,6 +2492,9 @@ namespace NLGUI
bool CWidgetManager::handleMouseMoveEvent( const CEventDescriptor &eventDesc )
{
if( getPointer() == NULL )
return false;
if( eventDesc.getType() != CEventDescriptor::mouse )
return false;

View file

@ -21,12 +21,15 @@
#include "nel/3d/driver_user.h"
#include "nel/misc/rgba.h"
#include "nel/misc/path.h"
#include "nel/misc/event_listener.h"
#include "nel/gui/event_listener.h"
#ifdef NL_OS_WINDOWS
#include <Windows.h>
#endif
namespace GUIEditor
{
Nel3DWidget::Nel3DWidget( QWidget *parent ) :
@ -39,6 +42,7 @@ namespace GUIEditor
// so that we can render the widget normally ourselves, without the image
// disappearing when a widget is resized or shown on top of us
setAttribute( Qt::WA_PaintOnScreen, true );
eventListener = NULL;
}
Nel3DWidget::~Nel3DWidget()
@ -55,6 +59,7 @@ namespace GUIEditor
delete driver;
driver = NULL;
}
delete eventListener;
}
void Nel3DWidget::init()
@ -64,6 +69,8 @@ namespace GUIEditor
driver = NL3D::UDriver::createDriver( 0, false, 0 );
driver->setMatrixMode2D11();
driver->setDisplay( winId(), NL3D::UDriver::CMode( width(), height(), 32, true ) );
eventListener = new NLGUI::CEventListener();
eventListener->addToServer( &driver->EventServer );
}
void Nel3DWidget::createTextContext( std::string fontFile )

View file

@ -22,6 +22,11 @@
#include "nel/misc/types_nl.h"
#include <string>
namespace NLGUI
{
class CEventListener;
}
namespace NL3D
{
class UDriver;
@ -66,6 +71,7 @@ namespace GUIEditor
private:
NL3D::UDriver *driver;
NL3D::UTextContext *textContext;
NLGUI::CEventListener *eventListener;
};
}

View file

@ -24,6 +24,7 @@
#include "nel/misc/i18n.h"
#include <set>
#include <string>
#include <QTimerEvent>
namespace GUIEditor
{
@ -32,10 +33,16 @@ namespace GUIEditor
NelGUIWidget::NelGUIWidget( QWidget *parent ) :
Nel3DWidget( parent )
{
timerID = 0;
guiLoaded = false;
}
NelGUIWidget::~NelGUIWidget()
{
guiLoaded = false;
if( timerID != 0 )
killTimer( timerID );
NLGUI::CViewRenderer::release();
NLMISC::CI18N::setNoResolution( false );
@ -59,6 +66,7 @@ namespace GUIEditor
bool NelGUIWidget::parse( SProjectFiles &files )
{
guiLoaded = false;
CWidgetManager::getInstance()->reset();
IParser *parser = CWidgetManager::getInstance()->getParser();
parser->removeAll();
@ -89,6 +97,9 @@ namespace GUIEditor
if( e != NULL )
e->setActive( true );
timerID = startTimer( 200 );
guiLoaded = true;
return true;
}
@ -102,7 +113,31 @@ namespace GUIEditor
void NelGUIWidget::paintEvent( QPaintEvent *evnt )
{
//draw();
}
void NelGUIWidget::timerEvent( QTimerEvent *evnt )
{
if( evnt->timerId() == timerID )
{
if( guiLoaded )
{
getDriver()->EventServer.pump();
draw();
}
}
}
void NelGUIWidget::showEvent( QShowEvent *evnt )
{
if( timerID == 0 )
timerID = startTimer( 200 );
}
void NelGUIWidget::hideEvent( QHideEvent *evnt )
{
if( timerID != 0 )
killTimer( timerID );
}
}

View file

@ -37,7 +37,14 @@ namespace GUIEditor
protected:
void paintEvent( QPaintEvent *evnt );
void timerEvent( QTimerEvent *evnt );
void showEvent( QShowEvent *evnt );
void hideEvent( QHideEvent *evnt );
private:
int timerID;
bool guiLoaded;
};
}