3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
\r
4 Original author Kabak Dmitry <userdima@gmail.com>, contributed under
\r
5 the minetest contributor agreement.
\r
7 This program is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 This program is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License along
\r
18 with this program; if not, write to the Free Software Foundation, Inc.,
\r
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
23 #include "guiPauseMenu.h"
\r
25 void guiPauseMenu::scaleGui() // this function scales gui from the size stored in file to screen size
\r
27 core::dimension2du screen=dev->getVideoDriver()->getScreenSize();
\r
28 core::vector2di real=root->getAbsolutePosition().LowerRightCorner; // determine gui size stored in file (which is size of my menu root node)
\r
29 float factorX=(float)screen.Width/(float)real.X;
\r
30 float factorY=(float)screen.Height/(float)real.Y;
\r
31 scaleGui(guienv->getRootGUIElement(),factorX,factorY);
\r
33 void guiPauseMenu::scaleGui(gui::IGUIElement *node,float factorX,float factorY) // recursive set scale
\r
35 if((node->getParent() && node->getParent()->getID()==255) || node->getID()==255) // modify only menu's elements
\r
38 lx=(float)node->getRelativePosition().UpperLeftCorner.X*factorX;
\r
39 ly=(float)node->getRelativePosition().UpperLeftCorner.Y*factorY;
\r
40 rx=(float)node->getRelativePosition().LowerRightCorner.X*factorX;
\r
41 ry=(float)node->getRelativePosition().LowerRightCorner.Y*factorY;
\r
42 node->setRelativePosition(core::recti(lx,ly,rx,ry));
\r
45 core::list<gui::IGUIElement*>::ConstIterator it = node->getChildren().begin();
\r
46 for(; it != node->getChildren().end(); ++it)
\r
47 scaleGui((*it),factorX,factorY);
\r
50 bool guiPauseMenu::loadMenu()
\r
52 guienv->loadGUI("../data/pauseMenu.gui");
\r
54 root=(gui::IGUIStaticText*)guienv->getRootGUIElement()->getElementFromId(255,true);
\r
55 if(!root) // if there is no my root node then menu file not found or corrupted
\r
58 scaleGui(); // scale gui to our screen size
\r
60 root->setVisible(false); // hide our menu
\r
61 // make it transparent
\r
62 //root->setBackgroundColor(video::SColor(100,128,100,128));
\r
63 root->setBackgroundColor(video::SColor(140,0,0,0));
\r
68 guiPauseMenu::guiPauseMenu(IrrlichtDevice *device, IEventReceiver *recv) : dev(device), oldRecv(recv)
\r
72 guienv=dev->getGUIEnvironment();
\r
77 device->setEventReceiver(this); // now WE are the input receiver! ahhaha!
\r
80 bool guiPauseMenu::OnEvent(const SEvent& event)
\r
82 if(!dev->isWindowFocused())
\r
86 if(oldRecv && !isVisible()) // call master if we have it and if we are inactive
\r
87 ret=oldRecv->OnEvent(event);
\r
90 return true; // if the master receiver does the work
\r
92 if(event.EventType==EET_KEY_INPUT_EVENT)
\r
94 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
\r
96 setVisible(!isVisible());
\r
99 if(event.EventType==EET_GUI_EVENT)
\r
101 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
\r
103 switch(event.GUIEvent.Caller->getID())
\r
105 case 256: // continue
\r
109 dev->closeDevice();
\r
118 guiPauseMenu::~guiPauseMenu(void)
\r