mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-25 10:20:54 +00:00
Object Viewer plugin will now use the Nel3DWidget in the Core plugin.
This commit is contained in:
parent
3c9dad8ba5
commit
676e4893a0
7 changed files with 52 additions and 128 deletions
|
@ -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
|
||||
//
|
||||
// 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 <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <QResizeEvent>
|
||||
|
||||
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 );
|
||||
|
|
|
@ -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
|
||||
//
|
||||
// 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 );
|
||||
|
|
|
@ -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<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 */
|
||||
|
||||
|
|
|
@ -26,23 +26,14 @@
|
|||
// STL includes
|
||||
|
||||
// Qt includes
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QObject>
|
||||
|
||||
// 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 */
|
||||
|
|
|
@ -77,7 +77,7 @@ CMainWindow::CMainWindow(QWidget *parent)
|
|||
|
||||
// create NeL viewport
|
||||
_GraphicsViewport = new CGraphicsViewport(this);
|
||||
setCentralWidget(_GraphicsViewport);
|
||||
setCentralWidget(_GraphicsViewport->widget());
|
||||
|
||||
setDockNestingEnabled(true);
|
||||
|
||||
|
|
|
@ -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<NL3D::CDriverUser *>(Modules::objView().getDriver());
|
||||
_IDriver = driver->getDriver();
|
||||
NL3D::CDriverUser *udriver = dynamic_cast<NL3D::CDriverUser *>(Modules::objView().getDriver());
|
||||
_IDriver = udriver->getDriver();
|
||||
|
||||
NL3D::CSceneUser *scene = dynamic_cast<NL3D::CSceneUser *>(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()
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue