--- /dev/null
+/*\r
+Minetest-c55\r
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>\r
+Original author Kabak Dmitry <userdima@gmail.com>, contributed under\r
+the minetest contributor agreement.\r
+\r
+This program is free software; you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation; either version 2 of the License, or\r
+(at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License along\r
+with this program; if not, write to the Free Software Foundation, Inc.,\r
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
+*/\r
+\r
+\r
+#include "guiPauseMenu.h"\r
+\r
+void guiPauseMenu::scaleGui() // this function scales gui from the size stored in file to screen size\r
+{\r
+ core::dimension2du screen=dev->getVideoDriver()->getScreenSize();\r
+ core::vector2di real=root->getAbsolutePosition().LowerRightCorner; // determine gui size stored in file (which is size of my menu root node)\r
+ float factorX=(float)screen.Width/(float)real.X;\r
+ float factorY=(float)screen.Height/(float)real.Y;\r
+ scaleGui(guienv->getRootGUIElement(),factorX,factorY);\r
+}\r
+void guiPauseMenu::scaleGui(gui::IGUIElement *node,float factorX,float factorY) // recursive set scale\r
+{\r
+ if((node->getParent() && node->getParent()->getID()==255) || node->getID()==255) // modify only menu's elements\r
+ {\r
+ int lx,rx,ly,ry;\r
+ lx=(float)node->getRelativePosition().UpperLeftCorner.X*factorX;\r
+ ly=(float)node->getRelativePosition().UpperLeftCorner.Y*factorY;\r
+ rx=(float)node->getRelativePosition().LowerRightCorner.X*factorX;\r
+ ry=(float)node->getRelativePosition().LowerRightCorner.Y*factorY;\r
+ node->setRelativePosition(core::recti(lx,ly,rx,ry));\r
+ }\r
+\r
+ core::list<gui::IGUIElement*>::ConstIterator it = node->getChildren().begin();\r
+ for(; it != node->getChildren().end(); ++it)\r
+ scaleGui((*it),factorX,factorY);\r
+}\r
+\r
+bool guiPauseMenu::loadMenu()\r
+{\r
+ guienv->loadGUI("../data/pauseMenu.gui");\r
+\r
+ root=(gui::IGUIStaticText*)guienv->getRootGUIElement()->getElementFromId(255,true);\r
+ if(!root) // if there is no my root node then menu file not found or corrupted\r
+ return false;\r
+\r
+ scaleGui(); // scale gui to our screen size\r
+\r
+ root->setVisible(false); // hide our menu\r
+ // make it transparent\r
+ //root->setBackgroundColor(video::SColor(100,128,100,128));\r
+ root->setBackgroundColor(video::SColor(140,0,0,0));\r
+\r
+ return true;\r
+}\r
+\r
+guiPauseMenu::guiPauseMenu(IrrlichtDevice *device, IEventReceiver *recv) : dev(device), oldRecv(recv)\r
+{\r
+ if(!dev)\r
+ return;\r
+ guienv=dev->getGUIEnvironment();\r
+\r
+ if (!loadMenu())\r
+ return;\r
+\r
+ device->setEventReceiver(this); // now WE are the input receiver! ahhaha! \r
+}\r
+\r
+bool guiPauseMenu::OnEvent(const SEvent& event)\r
+{\r
+ if(!dev->isWindowFocused())\r
+ setVisible(true);\r
+\r
+ bool ret=false;\r
+ if(oldRecv && !isVisible()) // call master if we have it and if we are inactive\r
+ ret=oldRecv->OnEvent(event);\r
+\r
+ if(ret==true)\r
+ return true; // if the master receiver does the work\r
+\r
+ if(event.EventType==EET_KEY_INPUT_EVENT)\r
+ {\r
+ if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)\r
+ {\r
+ setVisible(!isVisible());\r
+ }\r
+ }\r
+ if(event.EventType==EET_GUI_EVENT)\r
+ {\r
+ if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)\r
+ {\r
+ switch(event.GUIEvent.Caller->getID())\r
+ {\r
+ case 256: // continue\r
+ setVisible(false);\r
+ break;\r
+ case 257: // exit\r
+ dev->closeDevice();\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+guiPauseMenu::~guiPauseMenu(void)\r
+{\r
+}\r
--- /dev/null
+/*\r
+Minetest-c55\r
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>\r
+Original author Kabak Dmitry <userdima@gmail.com>, contributed under\r
+the minetest contributor agreement.\r
+\r
+This program is free software; you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation; either version 2 of the License, or\r
+(at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License along\r
+with this program; if not, write to the Free Software Foundation, Inc.,\r
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
+*/\r
+\r
+\r
+#ifndef GUIPAUSEMENU_HEADER\r
+#define GUIPAUSEMENU_HEADER\r
+\r
+#include <irrlicht.h>\r
+using namespace irr;\r
+\r
+class guiPauseMenu : public IEventReceiver\r
+{\r
+private:\r
+ IrrlichtDevice *dev;\r
+ gui::IGUIEnvironment *guienv;\r
+ IEventReceiver *oldRecv;\r
+\r
+ gui::IGUIStaticText *root;\r
+\r
+ bool loadMenu();\r
+ void scaleGui();\r
+ void scaleGui(gui::IGUIElement *node,float factorX,float factorY);\r
+public:\r
+ guiPauseMenu(IrrlichtDevice *device,IEventReceiver *recv);\r
+\r
+ void setVisible(bool visible){root->setVisible(visible);};\r
+ bool isVisible(){return root->isVisible();};\r
+\r
+ bool OnEvent(const SEvent& event);\r
+\r
+ ~guiPauseMenu(void);\r
+};\r
+\r
+#endif\r
+\r