From d6f7029221ee70be7f4e388a503f094f8aa27b8e Mon Sep 17 00:00:00 2001 From: cutealien Date: Mon, 17 Feb 2014 12:01:07 +0000 Subject: [PATCH] Add IrrlichtDevice::setWindowSize (implemented only on X11, will try Windows next). A few minor changes to the GUIEditor: - Displays the window-size - Update (rarely) when Window now active - Sleep after drawing to prevent update-delays on resizing - Driver choice now only for available drivers - Kick out the "Tools" tab as it's unused so far and just irritating users. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4692 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IrrlichtDevice.h | 6 ++++++ source/Irrlicht/CIrrDeviceLinux.cpp | 14 ++++++++++++++ source/Irrlicht/CIrrDeviceLinux.h | 3 +++ source/Irrlicht/CIrrDeviceStub.h | 2 ++ tools/GUIEditor/CGUIEditWindow.cpp | 14 ++++++++------ tools/GUIEditor/main.cpp | 22 +++++++++++++++------- 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index 10dd6ffa..7bd96028 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -227,6 +227,12 @@ namespace irr \param resize Flag whether the window should be resizable. */ virtual void setResizable(bool resize=false) = 0; + //! Resize the render window. + /** This will only work in windowed mode and is not yet supported on all systems. + It does set the drawing/clientDC size of the window, the window decorations are added to that. + */ + virtual void setWindowSize(const irr::core::dimension2d& size) = 0; + //! Minimizes the window if possible. virtual void minimizeWindow() =0; diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index f1e14512..8db460ae 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -1341,6 +1341,20 @@ void CIrrDeviceLinux::setResizable(bool resize) #endif // #ifdef _IRR_COMPILE_WITH_X11_ } +//! Resize the render window. +void CIrrDeviceLinux::setWindowSize(const irr::core::dimension2d& size) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType == video::EDT_NULL || CreationParams.Fullscreen ) + return; + + XWindowChanges values; + values.width = size.Width; + values.height = size.Height; + XConfigureWindow(display, window, CWWidth | CWHeight, &values); + XFlush(display); +#endif // #ifdef _IRR_COMPILE_WITH_X11_ +} //! Return pointer to a list with all video modes supported by the gfx adapter. video::IVideoModeList* CIrrDeviceLinux::getVideoModeList() diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index 3c2b4838..c1373592 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -92,6 +92,9 @@ namespace irr //! Sets if the window should be resizable in windowed mode. virtual void setResizable(bool resize=false) _IRR_OVERRIDE_; + //! Resize the render window. + virtual void setWindowSize(const irr::core::dimension2d& size) _IRR_OVERRIDE_; + //! Minimizes the window. virtual void minimizeWindow() _IRR_OVERRIDE_; diff --git a/source/Irrlicht/CIrrDeviceStub.h b/source/Irrlicht/CIrrDeviceStub.h index 907a4f54..2e3b81a5 100644 --- a/source/Irrlicht/CIrrDeviceStub.h +++ b/source/Irrlicht/CIrrDeviceStub.h @@ -135,6 +135,8 @@ namespace irr //! Remove all messages pending in the system message loop virtual void clearSystemMessages() _IRR_OVERRIDE_; + //! Resize the render window. + virtual void setWindowSize(const irr::core::dimension2d& size) _IRR_OVERRIDE_ {} protected: diff --git a/tools/GUIEditor/CGUIEditWindow.cpp b/tools/GUIEditor/CGUIEditWindow.cpp index 2ff96aeb..ae9d2443 100644 --- a/tools/GUIEditor/CGUIEditWindow.cpp +++ b/tools/GUIEditor/CGUIEditWindow.cpp @@ -37,16 +37,16 @@ CGUIEditWindow::CGUIEditWindow(IGUIEnvironment* environment, core::rect rec if (!skin) return; - s32 th = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH); - - setRelativePosition(core::rect(50,50,250,500)); + core::rect dlgRect(50,50,250,500); + setRelativePosition(dlgRect); setMinSize(core::dimension2du(200,200)); - IGUITabControl *TabControl = environment->addTabControl(core::rect(1,th+5,199,449), this, false, true); + s32 th = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH); + IGUITabControl *TabControl = environment->addTabControl(core::rect(1,th+5,dlgRect.getWidth()-1,dlgRect.getHeight()-1), this, false, true); TabControl->setSubElement(true); TabControl->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); - TabControl->addTab(L"Tools"); + //TabControl->addTab(L"Tools"); //L"Texture Cache Browser" //L"Font Browser" //L"Font Generator" @@ -83,7 +83,8 @@ CGUIEditWindow::CGUIEditWindow(IGUIEnvironment* environment, core::rect rec TreeView->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); IGUITreeViewNode* treenode = TreeView->getRoot(); //treenode->addChildFront(L"Elements"); - ResizeButton = environment->addButton(core::rect(199-th,449-th,199,449), this); + + ResizeButton = environment->addButton(core::rect(dlgRect.getWidth()-(th+1),dlgRect.getHeight()-(th+1),dlgRect.getWidth()-1,dlgRect.getHeight()-1), this); ResizeButton->setDrawBorder(false); ResizeButton->setEnabled(false); ResizeButton->setSpriteBank(skin->getSpriteBank()); @@ -92,6 +93,7 @@ CGUIEditWindow::CGUIEditWindow(IGUIEnvironment* environment, core::rect rec ResizeButton->grab(); ResizeButton->setSubElement(true); ResizeButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT); + updateTree(); } diff --git a/tools/GUIEditor/main.cpp b/tools/GUIEditor/main.cpp index e8434b20..7df42523 100644 --- a/tools/GUIEditor/main.cpp +++ b/tools/GUIEditor/main.cpp @@ -14,7 +14,7 @@ using namespace gui; int main() { // ask user for driver - video::E_DRIVER_TYPE driverType=driverChoiceConsole(); + video::E_DRIVER_TYPE driverType=driverChoiceConsole(false); if (driverType==video::EDT_COUNT) return 1; @@ -56,21 +56,29 @@ int main() */ env->addGUIElement("GUIEditor"); - - while(device->run()) - { - device->sleep(10); - if (device->isWindowActive()) + while(device->run()) + { + if (!device->isWindowMinimized()) { + const core::dimension2d& screenSize = driver->getScreenSize(); + wchar_t caption[512]; + swprintf(caption, 512, L"screen (%4u/%4u)", screenSize.Width, screenSize.Height); + device->setWindowCaption(caption); driver->beginScene(true, true, video::SColor(0,200,200,200)); smgr->drawAll(); env->drawAll(); driver->endScene(); } + + // be nice to CPU + device->sleep(10); + if (!device->isWindowActive()) + device->sleep(90); } + device->closeDevice(); device->drop(); - + return 0; }