From bfe1805927c82c77d8eb80c0bc337f530733ab13 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 16 Jun 2014 16:22:52 +0200 Subject: [PATCH] Object Viewer plugin will now use the Nel3DWidget in the Core plugin. --- .../plugins/core/Nel3DWidget/nel3d_widget.cpp | 13 ++- .../plugins/core/Nel3DWidget/nel3d_widget.h | 6 +- .../object_viewer/graphics_viewport.cpp | 100 ++++-------------- .../plugins/object_viewer/graphics_viewport.h | 40 ++----- .../src/plugins/object_viewer/main_window.cpp | 2 +- .../plugins/object_viewer/object_viewer.cpp | 17 +-- .../src/plugins/object_viewer/object_viewer.h | 2 +- 7 files changed, 52 insertions(+), 128 deletions(-) diff --git a/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.cpp b/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.cpp index 8ebc393ba..dc0bb858b 100644 --- a/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.cpp +++ b/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.cpp @@ -1,4 +1,4 @@ -// Object Viewer Qt GUI Editor plugin +// Ryzom Core MMORPG framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify @@ -21,12 +21,13 @@ #include "nel/3d/driver_user.h" #include "nel/misc/rgba.h" #include "nel/misc/path.h" -//#include "nel/misc/event_listener.h" #ifdef NL_OS_WINDOWS #include #endif +#include + Nel3DWidget::Nel3DWidget( QWidget *parent ) : QWidget( parent ) { @@ -62,7 +63,6 @@ void Nel3DWidget::init() nlassert( driver == NULL ); driver = NL3D::UDriver::createDriver( 0, false, 0 ); - driver->setMatrixMode2D11(); driver->setDisplay( winId(), NL3D::UDriver::CMode( width(), height(), 32, true ) ); } @@ -108,6 +108,13 @@ void Nel3DWidget::showEvent( QShowEvent *evnt ) driver->activate(); } +void Nel3DWidget::resizeEvent( QResizeEvent *evnt ) +{ + QWidget::resizeEvent( evnt ); + + Q_EMIT( evnt->size().width(), evnt->size().height() ); +} + #if defined ( NL_OS_WINDOWS ) typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); diff --git a/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.h b/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.h index 9cbf474bc..059e1b738 100644 --- a/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.h +++ b/code/studio/src/plugins/core/Nel3DWidget/nel3d_widget.h @@ -1,4 +1,4 @@ -// Object Viewer Qt GUI Editor plugin +// Ryzom Core MMORPG framework // Copyright (C) 2010 Winch Gate Property Limited // // 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 QPaintEngine* paintEngine() const{ return NULL; } +Q_SIGNALS: + void resize( int width, int height ); + public Q_SLOTS: void clear(); protected: void showEvent( QShowEvent *evnt ); + void resizeEvent( QResizeEvent *evnt ); #if defined(NL_OS_WINDOWS) bool winEvent( MSG *message, long *result ); diff --git a/code/studio/src/plugins/object_viewer/graphics_viewport.cpp b/code/studio/src/plugins/object_viewer/graphics_viewport.cpp index d8e36e785..8cf6f3f60 100644 --- a/code/studio/src/plugins/object_viewer/graphics_viewport.cpp +++ b/code/studio/src/plugins/object_viewer/graphics_viewport.cpp @@ -19,6 +19,7 @@ #include "stdpch.h" #include "graphics_viewport.h" +#include "../core/Nel3DWidget/nel3d_widget.h" // STL includes @@ -46,17 +47,18 @@ using namespace NL3D; namespace NLQT { -CGraphicsViewport::CGraphicsViewport(QWidget *parent) - : QNLWidget(parent) +CGraphicsViewport::CGraphicsViewport(QObject *parent) + : QObject(parent) { - setAttribute(Qt::WA_OpaquePaintEvent); - setAttribute(Qt::WA_NoSystemBackground); - setAttribute(Qt::WA_PaintOnScreen); + w = new Nel3DWidget(); + connect( w, SIGNAL( resize( int, int ) ), this, SLOT( onResize( int, int ) ) ); } CGraphicsViewport::~CGraphicsViewport() { - + disconnect( w, SIGNAL( resize( int, int ) ), this, SLOT( onResize( int, int ) ) ); + delete w; + w = NULL; } void CGraphicsViewport::init() @@ -68,12 +70,13 @@ void CGraphicsViewport::init() makeCurrent(); #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::veget().init(); - setMouseTracking(true); - setFocusPolicy(Qt::StrongFocus); + w->setMouseTracking(true); + w->setFocusPolicy(Qt::StrongFocus); } void CGraphicsViewport::release() @@ -101,6 +104,11 @@ QAction *CGraphicsViewport::createSetBackgroundColor(QObject *parent) return action; } +QWidget* CGraphicsViewport::widget() +{ + return w; +} + void CGraphicsViewport::saveScreenshot() { 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())); } -void CGraphicsViewport::resizeEvent(QResizeEvent *resizeEvent) +void CGraphicsViewport::onResize( int width, int height ) { - QWidget::resizeEvent(resizeEvent); 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(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(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(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 */ diff --git a/code/studio/src/plugins/object_viewer/graphics_viewport.h b/code/studio/src/plugins/object_viewer/graphics_viewport.h index 0c01fa1ad..9bbad9806 100644 --- a/code/studio/src/plugins/object_viewer/graphics_viewport.h +++ b/code/studio/src/plugins/object_viewer/graphics_viewport.h @@ -26,23 +26,14 @@ // STL includes // Qt includes -#include -#include +#include // NeL includes // Project includes - -/* 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 QWidget; class QAction; +class Nel3DWidget; namespace NLQT { @@ -51,25 +42,22 @@ namespace NLQT @class CGraphicsViewport @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 public: - CGraphicsViewport(QWidget *parent); + CGraphicsViewport(QObject *parent); virtual ~CGraphicsViewport(); - virtual QPaintEngine *paintEngine() const - { - return NULL; - } - void init(); void release(); QAction *createSaveScreenshotAction(QObject *parent); QAction *createSetBackgroundColor(QObject *parent); + QWidget* widget(); + private Q_SLOTS: void saveScreenshot(); void setBackgroundColor(); @@ -77,21 +65,15 @@ private Q_SLOTS: void submitEvents(NLMISC::CEventServer &server, bool allWindows) { } void emulateMouseRawMode(bool) { } -protected: - 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 + void onResize( int width, int height ); private: CGraphicsViewport(const CGraphicsViewport &); CGraphicsViewport &operator=(const CGraphicsViewport &); + + Nel3DWidget *w; + }; /* class CGraphicsViewport */ } /* namespace NLQT */ diff --git a/code/studio/src/plugins/object_viewer/main_window.cpp b/code/studio/src/plugins/object_viewer/main_window.cpp index 864896ca1..10da56ffa 100644 --- a/code/studio/src/plugins/object_viewer/main_window.cpp +++ b/code/studio/src/plugins/object_viewer/main_window.cpp @@ -77,7 +77,7 @@ CMainWindow::CMainWindow(QWidget *parent) // create NeL viewport _GraphicsViewport = new CGraphicsViewport(this); - setCentralWidget(_GraphicsViewport); + setCentralWidget(_GraphicsViewport->widget()); setDockNestingEnabled(true); diff --git a/code/studio/src/plugins/object_viewer/object_viewer.cpp b/code/studio/src/plugins/object_viewer/object_viewer.cpp index 48c679455..2cf803d3d 100644 --- a/code/studio/src/plugins/object_viewer/object_viewer.cpp +++ b/code/studio/src/plugins/object_viewer/object_viewer.cpp @@ -70,20 +70,16 @@ CObjectViewer::~CObjectViewer() saveConfig(); } -void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h) +void CObjectViewer::init( NL3D::UDriver *driver ) { //H_AUTO2 nldebug("CObjectViewert::init"); // create the driver nlassert(!_Driver); - - _Driver = NL3D::UDriver::createDriver(0, _Direct3D, 0); + _Driver = driver; nlassert(_Driver); - // initialize the window with config file values - _Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32)); - // Create a scene _Scene = _Driver->createScene(false); _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().setSquareBloom(_BloomSquare); - NL3D::CDriverUser *driver = dynamic_cast(Modules::objView().getDriver()); - _IDriver = driver->getDriver(); + NL3D::CDriverUser *udriver = dynamic_cast(Modules::objView().getDriver()); + _IDriver = udriver->getDriver(); NL3D::CSceneUser *scene = dynamic_cast(Modules::objView().getScene()); _CScene = &scene->getScene(); @@ -158,11 +154,8 @@ void CObjectViewer::release() // delete the light delete _Light; - // release driver - nlassert(_Driver); - _Driver->release(); - delete _Driver; _Driver = 0; + _IDriver = NULL; } void CObjectViewer::updateInput() diff --git a/code/studio/src/plugins/object_viewer/object_viewer.h b/code/studio/src/plugins/object_viewer/object_viewer.h index 5e978d7e0..e8cc7304e 100644 --- a/code/studio/src/plugins/object_viewer/object_viewer.h +++ b/code/studio/src/plugins/object_viewer/object_viewer.h @@ -78,7 +78,7 @@ public: /// @param wnd - handle window. /// @param w - width window. /// @param h - height window. - void init(nlWindow wnd, uint16 w, uint16 h); + void init( NL3D::UDriver *driver ); /// Release class. void release();