Object Viewer plugin will now use the Nel3DWidget in the Core plugin.

This commit is contained in:
dfighter1985 2014-06-16 16:22:52 +02:00
parent 320a9dd33a
commit bfe1805927
7 changed files with 52 additions and 128 deletions

View file

@ -1,4 +1,4 @@
// Object Viewer Qt GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/> // Ryzom Core MMORPG framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2010 Winch Gate Property Limited
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
@ -21,12 +21,13 @@
#include "nel/3d/driver_user.h" #include "nel/3d/driver_user.h"
#include "nel/misc/rgba.h" #include "nel/misc/rgba.h"
#include "nel/misc/path.h" #include "nel/misc/path.h"
//#include "nel/misc/event_listener.h"
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
#include <Windows.h> #include <Windows.h>
#endif #endif
#include <QResizeEvent>
Nel3DWidget::Nel3DWidget( QWidget *parent ) : Nel3DWidget::Nel3DWidget( QWidget *parent ) :
QWidget( parent ) QWidget( parent )
{ {
@ -62,7 +63,6 @@ void Nel3DWidget::init()
nlassert( driver == NULL ); nlassert( driver == NULL );
driver = NL3D::UDriver::createDriver( 0, false, 0 ); driver = NL3D::UDriver::createDriver( 0, false, 0 );
driver->setMatrixMode2D11();
driver->setDisplay( winId(), NL3D::UDriver::CMode( width(), height(), 32, true ) ); driver->setDisplay( winId(), NL3D::UDriver::CMode( width(), height(), 32, true ) );
} }
@ -108,6 +108,13 @@ void Nel3DWidget::showEvent( QShowEvent *evnt )
driver->activate(); driver->activate();
} }
void Nel3DWidget::resizeEvent( QResizeEvent *evnt )
{
QWidget::resizeEvent( evnt );
Q_EMIT( evnt->size().width(), evnt->size().height() );
}
#if defined ( NL_OS_WINDOWS ) #if defined ( NL_OS_WINDOWS )
typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );

View file

@ -1,4 +1,4 @@
// Object Viewer Qt GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/> // Ryzom Core MMORPG framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2010 Winch Gate Property Limited
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
@ -50,12 +50,16 @@ public:
// disappearing when a widget is resized or shown on top of us // disappearing when a widget is resized or shown on top of us
QPaintEngine* paintEngine() const{ return NULL; } QPaintEngine* paintEngine() const{ return NULL; }
Q_SIGNALS:
void resize( int width, int height );
public Q_SLOTS: public Q_SLOTS:
void clear(); void clear();
protected: protected:
void showEvent( QShowEvent *evnt ); void showEvent( QShowEvent *evnt );
void resizeEvent( QResizeEvent *evnt );
#if defined(NL_OS_WINDOWS) #if defined(NL_OS_WINDOWS)
bool winEvent( MSG *message, long *result ); bool winEvent( MSG *message, long *result );

View file

@ -19,6 +19,7 @@
#include "stdpch.h" #include "stdpch.h"
#include "graphics_viewport.h" #include "graphics_viewport.h"
#include "../core/Nel3DWidget/nel3d_widget.h"
// STL includes // STL includes
@ -46,17 +47,18 @@ using namespace NL3D;
namespace NLQT namespace NLQT
{ {
CGraphicsViewport::CGraphicsViewport(QWidget *parent) CGraphicsViewport::CGraphicsViewport(QObject *parent)
: QNLWidget(parent) : QObject(parent)
{ {
setAttribute(Qt::WA_OpaquePaintEvent); w = new Nel3DWidget();
setAttribute(Qt::WA_NoSystemBackground); connect( w, SIGNAL( resize( int, int ) ), this, SLOT( onResize( int, int ) ) );
setAttribute(Qt::WA_PaintOnScreen);
} }
CGraphicsViewport::~CGraphicsViewport() CGraphicsViewport::~CGraphicsViewport()
{ {
disconnect( w, SIGNAL( resize( int, int ) ), this, SLOT( onResize( int, int ) ) );
delete w;
w = NULL;
} }
void CGraphicsViewport::init() void CGraphicsViewport::init()
@ -68,12 +70,13 @@ void CGraphicsViewport::init()
makeCurrent(); makeCurrent();
#endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC) #endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
Modules::objView().init((nlWindow)winId(), width(), height()); w->init();
Modules::objView().init( w->getDriver() );
Modules::psEdit().init(); Modules::psEdit().init();
Modules::veget().init(); Modules::veget().init();
setMouseTracking(true); w->setMouseTracking(true);
setFocusPolicy(Qt::StrongFocus); w->setFocusPolicy(Qt::StrongFocus);
} }
void CGraphicsViewport::release() void CGraphicsViewport::release()
@ -101,6 +104,11 @@ QAction *CGraphicsViewport::createSetBackgroundColor(QObject *parent)
return action; return action;
} }
QWidget* CGraphicsViewport::widget()
{
return w;
}
void CGraphicsViewport::saveScreenshot() void CGraphicsViewport::saveScreenshot()
{ {
Modules::objView().saveScreenshot("screenshot", false, true, false); Modules::objView().saveScreenshot("screenshot", false, true, false);
@ -115,81 +123,11 @@ void CGraphicsViewport::setBackgroundColor()
Modules::objView().setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue())); Modules::objView().setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue()));
} }
void CGraphicsViewport::resizeEvent(QResizeEvent *resizeEvent) void CGraphicsViewport::onResize( int width, int height )
{ {
QWidget::resizeEvent(resizeEvent);
if (Modules::objView().getDriver()) if (Modules::objView().getDriver())
Modules::objView().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height()); Modules::objView().setSizeViewport( width, height );
} }
#if defined(NL_OS_WINDOWS)
typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
bool CGraphicsViewport::winEvent(MSG *message, long *result)
{
if (Modules::objView().getDriver() && Modules::objView().getDriver()->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(Modules::objView().getDriver())->getDriver();
if (driver)
{
winProc proc = (winProc)driver->getWindowProc();
// TODO: shouldn't it return false like the others?
// see macEvent() and x11Event() below
return proc(driver, message->hwnd, message->message, message->wParam, message->lParam);
}
}
return false;
}
#elif defined(NL_OS_MAC)
typedef bool (*cocoaProc)(NL3D::IDriver *, const void *e);
bool CGraphicsViewport::macEvent(EventHandlerCallRef caller, EventRef event)
{
if(caller)
nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt");
if (Modules::objView().getDriver() && Modules::objView().getDriver()->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(Modules::objView().getDriver())->getDriver();
if (driver)
{
cocoaProc proc = (cocoaProc)driver->getWindowProc();
proc(driver, event);
}
}
// return false to let Qt handle the event as well,
// else the widget would never get focus
return false;
}
#elif defined(NL_OS_UNIX)
typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e);
bool CGraphicsViewport::x11Event(XEvent *event)
{
if (Modules::objView().getDriver() && Modules::objView().getDriver()->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(Modules::objView().getDriver())->getDriver();
if (driver)
{
x11Proc proc = (x11Proc)driver->getWindowProc();
proc(driver, event);
}
}
// return false to let Qt handle the event as well,
// else the widget would never get focus
// TODO: test me please, i have no linux at hand (rti)
return false;
}
#endif
} /* namespace NLQT */ } /* namespace NLQT */

View file

@ -26,23 +26,14 @@
// STL includes // STL includes
// Qt includes // Qt includes
#include <QtOpenGL/QGLWidget> #include <QObject>
#include <QtGui/QWidget>
// NeL includes // NeL includes
// Project includes // Project includes
class QWidget;
/* TODO every platform should use QWidget */
#if defined(NL_OS_WINDOWS)
typedef QWidget QNLWidget;
#elif defined(NL_OS_MAC)
typedef QWidget QNLWidget;
#elif defined(NL_OS_UNIX)
typedef QGLWidget QNLWidget;
#endif // NL_OS_UNIX
class QAction; class QAction;
class Nel3DWidget;
namespace NLQT namespace NLQT
{ {
@ -51,25 +42,22 @@ namespace NLQT
@class CGraphicsViewport @class CGraphicsViewport
@brief Responsible for interaction between Qt and NeL. Initializes CObjectViewer, CParticleEditor and CVegetableEditor subsystem. @brief Responsible for interaction between Qt and NeL. Initializes CObjectViewer, CParticleEditor and CVegetableEditor subsystem.
*/ */
class CGraphicsViewport : public QNLWidget, public NLMISC::IEventEmitter class CGraphicsViewport : public QObject, public NLMISC::IEventEmitter
{ {
Q_OBJECT Q_OBJECT
public: public:
CGraphicsViewport(QWidget *parent); CGraphicsViewport(QObject *parent);
virtual ~CGraphicsViewport(); virtual ~CGraphicsViewport();
virtual QPaintEngine *paintEngine() const
{
return NULL;
}
void init(); void init();
void release(); void release();
QAction *createSaveScreenshotAction(QObject *parent); QAction *createSaveScreenshotAction(QObject *parent);
QAction *createSetBackgroundColor(QObject *parent); QAction *createSetBackgroundColor(QObject *parent);
QWidget* widget();
private Q_SLOTS: private Q_SLOTS:
void saveScreenshot(); void saveScreenshot();
void setBackgroundColor(); void setBackgroundColor();
@ -77,21 +65,15 @@ private Q_SLOTS:
void submitEvents(NLMISC::CEventServer &server, bool allWindows) { } void submitEvents(NLMISC::CEventServer &server, bool allWindows) { }
void emulateMouseRawMode(bool) { } void emulateMouseRawMode(bool) { }
protected: void onResize( int width, int height );
virtual void resizeEvent(QResizeEvent *resizeEvent);
#if defined(NL_OS_WINDOWS)
virtual bool winEvent(MSG *message, long *result);
#elif defined(NL_OS_MAC)
virtual bool macEvent(EventHandlerCallRef caller, EventRef event);
#elif defined(NL_OS_UNIX)
virtual bool x11Event(XEvent *event);
#endif
private: private:
CGraphicsViewport(const CGraphicsViewport &); CGraphicsViewport(const CGraphicsViewport &);
CGraphicsViewport &operator=(const CGraphicsViewport &); CGraphicsViewport &operator=(const CGraphicsViewport &);
Nel3DWidget *w;
}; /* class CGraphicsViewport */ }; /* class CGraphicsViewport */
} /* namespace NLQT */ } /* namespace NLQT */

View file

@ -77,7 +77,7 @@ CMainWindow::CMainWindow(QWidget *parent)
// create NeL viewport // create NeL viewport
_GraphicsViewport = new CGraphicsViewport(this); _GraphicsViewport = new CGraphicsViewport(this);
setCentralWidget(_GraphicsViewport); setCentralWidget(_GraphicsViewport->widget());
setDockNestingEnabled(true); setDockNestingEnabled(true);

View file

@ -70,20 +70,16 @@ CObjectViewer::~CObjectViewer()
saveConfig(); saveConfig();
} }
void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h) void CObjectViewer::init( NL3D::UDriver *driver )
{ {
//H_AUTO2 //H_AUTO2
nldebug("CObjectViewert::init"); nldebug("CObjectViewert::init");
// create the driver // create the driver
nlassert(!_Driver); nlassert(!_Driver);
_Driver = driver;
_Driver = NL3D::UDriver::createDriver(0, _Direct3D, 0);
nlassert(_Driver); nlassert(_Driver);
// initialize the window with config file values
_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));
// Create a scene // Create a scene
_Scene = _Driver->createScene(false); _Scene = _Driver->createScene(false);
_Scene->setPolygonBalancingMode(NL3D::UScene::PolygonBalancingClamp); _Scene->setPolygonBalancingMode(NL3D::UScene::PolygonBalancingClamp);
@ -128,8 +124,8 @@ void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h)
NL3D::CBloomEffect::instance().setDensityBloom(uint8(_BloomDensity)); NL3D::CBloomEffect::instance().setDensityBloom(uint8(_BloomDensity));
NL3D::CBloomEffect::instance().setSquareBloom(_BloomSquare); NL3D::CBloomEffect::instance().setSquareBloom(_BloomSquare);
NL3D::CDriverUser *driver = dynamic_cast<NL3D::CDriverUser *>(Modules::objView().getDriver()); NL3D::CDriverUser *udriver = dynamic_cast<NL3D::CDriverUser *>(Modules::objView().getDriver());
_IDriver = driver->getDriver(); _IDriver = udriver->getDriver();
NL3D::CSceneUser *scene = dynamic_cast<NL3D::CSceneUser *>(Modules::objView().getScene()); NL3D::CSceneUser *scene = dynamic_cast<NL3D::CSceneUser *>(Modules::objView().getScene());
_CScene = &scene->getScene(); _CScene = &scene->getScene();
@ -158,11 +154,8 @@ void CObjectViewer::release()
// delete the light // delete the light
delete _Light; delete _Light;
// release driver
nlassert(_Driver);
_Driver->release();
delete _Driver;
_Driver = 0; _Driver = 0;
_IDriver = NULL;
} }
void CObjectViewer::updateInput() void CObjectViewer::updateInput()

View file

@ -78,7 +78,7 @@ public:
/// @param wnd - handle window. /// @param wnd - handle window.
/// @param w - width window. /// @param w - width window.
/// @param h - height window. /// @param h - height window.
void init(nlWindow wnd, uint16 w, uint16 h); void init( NL3D::UDriver *driver );
/// Release class. /// Release class.
void release(); void release();