LCOV - code coverage report
Current view: top level - src - guiVolumeChange.cpp (source / functions) Hit Total Coverage
Test: report Lines: 1 84 1.2 %
Date: 2015-07-11 18:23:49 Functions: 2 11 18.2 %

          Line data    Source code
       1             : /*
       2             : Part of Minetest
       3             : Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
       4             : Copyright (C) 2013 Ciaran Gultnieks <ciaran@ciarang.com>
       5             : Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
       6             : 
       7             : Permission to use, copy, modify, and distribute this software for any
       8             : purpose with or without fee is hereby granted, provided that the above
       9             : copyright notice and this permission notice appear in all copies.
      10             : 
      11             : THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      12             : WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      13             : MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
      14             : ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
      15             : WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
      16             : ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      17             : OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      18             : */
      19             : 
      20             : #include "guiVolumeChange.h"
      21             : #include "debug.h"
      22             : #include "serialization.h"
      23             : #include <string>
      24             : #include <IGUICheckBox.h>
      25             : #include <IGUIButton.h>
      26             : #include <IGUIScrollBar.h>
      27             : #include <IGUIStaticText.h>
      28             : #include <IGUIFont.h>
      29             : #include "settings.h"
      30             : 
      31             : #include "gettext.h"
      32             : 
      33             : const int ID_soundText1 = 263;
      34             : const int ID_soundText2 = 264;
      35             : const int ID_soundExitButton = 265;
      36             : const int ID_soundSlider = 266;
      37             : 
      38           0 : GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
      39             :                 gui::IGUIElement* parent, s32 id,
      40             :                 IMenuManager *menumgr,
      41             :                 Client* client
      42             : ):
      43           0 :         GUIModalMenu(env, parent, id, menumgr)
      44             : {
      45           0 : }
      46             : 
      47           0 : GUIVolumeChange::~GUIVolumeChange()
      48             : {
      49           0 :         removeChildren();
      50           0 : }
      51             : 
      52           0 : void GUIVolumeChange::removeChildren()
      53             : {
      54             :         {
      55           0 :                 gui::IGUIElement *e = getElementFromId(ID_soundText1);
      56           0 :                 if(e != NULL)
      57           0 :                         e->remove();
      58             :         }
      59             :         {
      60           0 :                 gui::IGUIElement *e = getElementFromId(ID_soundText2);
      61           0 :                 if(e != NULL)
      62           0 :                         e->remove();
      63             :         }
      64             :         {
      65           0 :                 gui::IGUIElement *e = getElementFromId(ID_soundExitButton);
      66           0 :                 if(e != NULL)
      67           0 :                         e->remove();
      68             :         }
      69             :         {
      70           0 :                 gui::IGUIElement *e = getElementFromId(ID_soundSlider);
      71           0 :                 if(e != NULL)
      72           0 :                         e->remove();
      73             :         }
      74           0 : }
      75             : 
      76           0 : void GUIVolumeChange::regenerateGui(v2u32 screensize)
      77             : {
      78             :         /*
      79             :                 Remove stuff
      80             :         */
      81           0 :         removeChildren();
      82             :         
      83             :         /*
      84             :                 Calculate new sizes and positions
      85             :         */
      86             :         core::rect<s32> rect(
      87           0 :                         screensize.X/2 - 380/2,
      88           0 :                         screensize.Y/2 - 200/2,
      89           0 :                         screensize.X/2 + 380/2,
      90           0 :                         screensize.Y/2 + 200/2
      91           0 :         );
      92             :         
      93           0 :         DesiredRect = rect;
      94           0 :         recalculateAbsolutePosition(false);
      95             : 
      96           0 :         v2s32 size = rect.getSize();
      97           0 :         v2s32 topleft_client(40, 0);
      98           0 :         int volume=(int)(g_settings->getFloat("sound_volume")*100);
      99             :         /*
     100             :                 Add stuff
     101             :         */
     102             :         {
     103           0 :                 core::rect<s32> rect(0, 0, 120, 20);
     104           0 :                 rect = rect + v2s32(size.X/2-60, size.Y/2-35);
     105           0 :                 const wchar_t *text = wgettext("Sound Volume: ");
     106           0 :                 Environment->addStaticText(text, rect, false,
     107           0 :                                 true, this, ID_soundText1);
     108           0 :                 delete[] text;
     109             :         }
     110             :         {
     111           0 :                 core::rect<s32> rect(0, 0, 30, 20);
     112           0 :                 rect = rect + v2s32(size.X/2+40, size.Y/2-35);
     113           0 :                 Environment->addStaticText(core::stringw(volume).c_str(), rect, false,
     114           0 :                                 true, this, ID_soundText2);
     115             :         }
     116             :         {
     117           0 :                 core::rect<s32> rect(0, 0, 80, 30);
     118           0 :                 rect = rect + v2s32(size.X/2-80/2, size.Y/2+55);
     119           0 :                 const wchar_t *text = wgettext("Exit");
     120           0 :                 Environment->addButton(rect, this, ID_soundExitButton,
     121           0 :                         text);
     122           0 :                 delete[] text;
     123             :         }
     124             :         {
     125           0 :                 core::rect<s32> rect(0, 0, 300, 20);
     126           0 :                 rect = rect + v2s32(size.X/2-150, size.Y/2);
     127           0 :                 gui::IGUIScrollBar *e = Environment->addScrollBar(true,
     128           0 :                         rect, this, ID_soundSlider);
     129           0 :                 e->setMax(100);
     130           0 :                 e->setPos(volume);
     131             :         }
     132           0 : }
     133             : 
     134           0 : void GUIVolumeChange::drawMenu()
     135             : {
     136           0 :         gui::IGUISkin* skin = Environment->getSkin();
     137           0 :         if (!skin)
     138           0 :                 return;
     139           0 :         video::IVideoDriver* driver = Environment->getVideoDriver();
     140           0 :         video::SColor bgcolor(140,0,0,0);
     141           0 :         driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
     142           0 :         gui::IGUIElement::draw();
     143             : }
     144             : 
     145           0 : bool GUIVolumeChange::OnEvent(const SEvent& event)
     146             : {
     147           0 :         if(event.EventType==EET_KEY_INPUT_EVENT)
     148             :         {
     149           0 :                 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
     150             :                 {
     151           0 :                         quitMenu();
     152           0 :                         return true;
     153             :                 }
     154           0 :                 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
     155             :                 {
     156           0 :                         quitMenu();
     157           0 :                         return true;
     158             :                 }
     159             :         }
     160           0 :         if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
     161             :                 {
     162           0 :                         if (event.GUIEvent.Caller->getID() == ID_soundExitButton)
     163             :                                 {
     164           0 :                                         quitMenu();
     165           0 :                                         return true;
     166             :                                 }
     167             :                 }
     168           0 :         if(event.GUIEvent.EventType==gui::EGET_SCROLL_BAR_CHANGED)
     169             :                 {
     170           0 :                 if (event.GUIEvent.Caller->getID() == ID_soundSlider)
     171             :                         {
     172           0 :                                 s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
     173           0 :                                 g_settings->setFloat("sound_volume",(float)pos/100);
     174           0 :                                 gui::IGUIElement *e = getElementFromId(ID_soundText2);
     175           0 :                                 e->setText( core::stringw(pos).c_str() );
     176           0 :                                 return true;
     177             :                         }
     178             :                 }
     179           0 :         return Parent ? Parent->OnEvent(event) : false;
     180           3 : }
     181             : 

Generated by: LCOV version 1.11