From f9bcc43d8ced5f1e86c63b11b6636db34a7615e5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 19 Jul 2012 04:39:30 +0200 Subject: [PATCH] ADDED: #1471 Nel3D widget ( based on Dnk's similar widget ), NelGUI widget skeletons. NelGUI widget will be the widget which renders the GUI library's output and forward the input for it. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/view_renderer.h | 3 + code/nel/src/gui/view_renderer.cpp | 12 +++ .../src/plugins/gui_editor/CMakeLists.txt | 2 + .../plugins/gui_editor/gui_editor_window.cpp | 15 ++- .../plugins/gui_editor/gui_editor_window.h | 2 + .../src/plugins/gui_editor/nel3d_widget.cpp | 94 +++++++++++++++++++ .../src/plugins/gui_editor/nel3d_widget.h | 56 +++++++++++ .../src/plugins/gui_editor/nelgui_widget.cpp | 52 ++++++++++ .../src/plugins/gui_editor/nelgui_widget.h | 37 ++++++++ 9 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h diff --git a/code/nel/include/nel/gui/view_renderer.h b/code/nel/include/nel/gui/view_renderer.h index effe4fd70..d716997ce 100644 --- a/code/nel/include/nel/gui/view_renderer.h +++ b/code/nel/include/nel/gui/view_renderer.h @@ -126,6 +126,9 @@ namespace NLGUI /// Delete all textures and the like and reset the view renderer void reset(); + /// Release the resources of CViewRenderer, and delete the Singleton + static void release(); + /// Retrieves the 3d driver we are using static NL3D::UDriver* getDriver(); diff --git a/code/nel/src/gui/view_renderer.cpp b/code/nel/src/gui/view_renderer.cpp index 6e66c3edf..c8ddae40b 100644 --- a/code/nel/src/gui/view_renderer.cpp +++ b/code/nel/src/gui/view_renderer.cpp @@ -184,6 +184,18 @@ namespace NLGUI _Material.setTexture(3, NULL); _Material.setZBias(0); } + + void CViewRenderer::release() + { + if( instance != NULL ) + { + instance->reset(); + delete instance; + instance = NULL; + } + } + + /* * reset: reset the whole view renderer */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt index f355524a3..2810931d5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt @@ -20,6 +20,8 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR proc_editor.h property_browser_ctrl.h project_window.h + nel3d_widget.h + nelgui_widget.h ) SET(OVQT_PLUGIN_GUI_EDITOR_UIS diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index 7b4bdab6b..734a7fcd9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -37,6 +37,7 @@ #include "proc_editor.h" #include "project_file_parser.h" #include "project_window.h" +#include "nelgui_widget.h" namespace GUIEditor { @@ -51,7 +52,10 @@ namespace GUIEditor widgetProps = new CWidgetProperties; linkEditor = new LinkEditor; procEditor = new ProcEditor; - projectWindow = new ProjectWindow(); + projectWindow = new ProjectWindow; + viewPort = new NelGUIWidget; + setCentralWidget( viewPort ); + createMenus(); readSettings(); @@ -74,6 +78,8 @@ namespace GUIEditor browserCtrl.setup(); dock->setWidget( tb ); addDockWidget( Qt::RightDockWidgetArea, dock ); + + viewPort->init(); } GUIEditorWindow::~GUIEditorWindow() @@ -91,6 +97,9 @@ namespace GUIEditor delete projectWindow; projectWindow = NULL; + + delete viewPort; + viewPort = NULL; } QUndoStack *GUIEditorWindow::undoStack() const @@ -163,6 +172,10 @@ namespace GUIEditor a = new QAction( "Project Window", this ); connect( a, SIGNAL( triggered( bool ) ), projectWindow, SLOT( show() ) ); m->addAction( a ); + + a = new QAction( "Clear Viewport", this ); + connect( a, SIGNAL( triggered( bool ) ), viewPort, SLOT( clear() ) ); + m->addAction( a ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h index f3acdbfa7..8dcbee745 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h @@ -31,6 +31,7 @@ namespace GUIEditor class LinkEditor; class ProcEditor; class ProjectWindow; + class NelGUIWidget; class GUIEditorWindow: public QMainWindow { @@ -63,6 +64,7 @@ private: LinkEditor *linkEditor; ProcEditor *procEditor; ProjectWindow *projectWindow; + NelGUIWidget *viewPort; CPropBrowserCtrl browserCtrl; QString currentProject; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.cpp new file mode 100644 index 000000000..8f211057f --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.cpp @@ -0,0 +1,94 @@ +// Object Viewer Qt GUI Editor plugin +// 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 . + + +#include "nel3d_widget.h" +#include "nel/3d/u_driver.h" +#include "nel/3d/text_context.h" +#include "nel/misc/rgba.h" +#include "nel/misc/path.h" + + +namespace GUIEditor +{ + Nel3DWidget::Nel3DWidget( QWidget *parent ) : + QWidget( parent ) + { + driver = NULL; + textContext = NULL; + } + + Nel3DWidget::~Nel3DWidget() + { + if( driver != NULL ) + { + if( textContext != NULL ) + { + driver->deleteTextContext( textContext ); + textContext = NULL; + } + + driver->release(); + delete driver; + driver = NULL; + } + } + + 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 ) ); + } + + void Nel3DWidget::createTextContext( std::string fontFile ) + { + if( driver == NULL ) + return; + + std::string font; + + try + { + font = NLMISC::CPath::lookup( fontFile ); + } + catch( ... ) + { + nlinfo( "Font %s cannot be found, cannot create textcontext!", fontFile.c_str() ); + exit( EXIT_FAILURE ); + } + + if( textContext != NULL ) + { + driver->deleteTextContext( textContext ); + textContext = NULL; + } + + textContext = driver->createTextContext( font ); + } + + void Nel3DWidget::clear() + { + if( driver == NULL ) + return; + driver->clearBuffers( NLMISC::CRGBA::Black ); + driver->swapBuffers(); + } +} + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.h new file mode 100644 index 000000000..cfb634916 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nel3d_widget.h @@ -0,0 +1,56 @@ +// Object Viewer Qt GUI Editor plugin +// 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 . + + +#ifndef NEL3D_WIDGET_H +#define NEL3D_WIDGET_H + +#include +#include + +namespace NL3D +{ + class UDriver; + class UTextContext; +} + +namespace GUIEditor +{ + /// Nel 3D interface to Qt + class Nel3DWidget : public QWidget + { + Q_OBJECT + public: + Nel3DWidget( QWidget *parent = NULL ); + virtual ~Nel3DWidget(); + + virtual void init(); + void createTextContext( std::string fontFile ); + + NL3D::UDriver* getDriver() const{ return driver; } + NL3D::UTextContext* getTextContext() const{ return textContext; } + + public Q_SLOTS: + void clear(); + + private: + NL3D::UDriver *driver; + NL3D::UTextContext *textContext; + }; +} + +#endif + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp new file mode 100644 index 000000000..d8bae62c5 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp @@ -0,0 +1,52 @@ +// Object Viewer Qt GUI Editor plugin +// 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 . + + +#include "nelgui_widget.h" +#include "nel/misc/path.h" +#include "nel/gui/view_renderer.h" +#include +#include + +namespace GUIEditor +{ + std::set< std::string > hwCursors; + + NelGUIWidget::NelGUIWidget( QWidget *parent ) : + Nel3DWidget( parent ) + { + } + + NelGUIWidget::~NelGUIWidget() + { + NLGUI::CViewRenderer::release(); + + } + + void NelGUIWidget::init() + { + NLMISC::CPath::addSearchPath( "fonts" ); + + Nel3DWidget::init(); + createTextContext( "Ryzom.ttf" ); + + NLGUI::CViewRenderer::setDriver( getDriver() ); + NLGUI::CViewRenderer::setTextContext( getTextContext() ); + NLGUI::CViewRenderer::hwCursors = &hwCursors; + NLGUI::CViewRenderer::getInstance()->init(); + } +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h new file mode 100644 index 000000000..334c15f4e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h @@ -0,0 +1,37 @@ +// Object Viewer Qt GUI Editor plugin +// 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 . + + +#ifndef NELGUI_WIDGET_H +#define NELGUI_WIDGET_H + +#include "nel3d_widget.h" + +namespace GUIEditor +{ + /// Qt viewport for the Nel GUI library + class NelGUIWidget : public Nel3DWidget + { + Q_OBJECT + public: + NelGUIWidget( QWidget *parent = NULL ); + ~NelGUIWidget(); + + void init(); + }; +} + +#endif