aboutsummaryrefslogtreecommitdiff
path: root/build/android/src
Commit message (Expand)AuthorAge
* Android: build fixes & compat fixesMoNTE482019-11-09
* Fix misuse of AsyncTask (#8799)Linjie Pan2019-09-19
* Drop libgmp on Android and use mini-gmp (#8047)Loïc Blot2019-01-04
* Android: Fix start-up crashes on version 4.x (#8003)stujones112018-12-22
* Update Android java code (#7820)Maksim2018-12-02
* Android build fixes for c++11stujones112018-03-11
* Prevent Android from automatically locking display (#6876)Wayward One2018-01-04
* Tell irrlicht if we handle a key or not.est312016-05-26
* Fix locked hardware buttons on AndroidMaksim Gamarnik2016-05-14
* Upgrade Android build to Gradle build systemShadowNinja2016-04-28
* Android: shorten initial progress bar text way more simpleSapier2015-12-23
* Android: statically load iconv libraryest312015-10-24
* Fix libgmp for Androidest312015-05-15
* Android: Backport changes from stable-0.4Loic Blot2015-03-14
* Android: fix package name in JAVA sourcesLoic Blot2015-03-14
* Increase stepheight on android by 0.5 to smoothen movementsapier2015-01-11
* Fixes for androidsapier2015-01-06
* Speedup initial android startup on some devices by factor 10 or moresapier2015-01-02
* Add support for Android 2.3+sapier2014-06-29
href='#n178'>178 179 180 181 182 183
/*
Part of Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2013 Ciaran Gultnieks <ciaran@ciarang.com>
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "guiVolumeChange.h"
#include "debug.h"
#include "serialization.h"
#include <string>
#include <IGUICheckBox.h>
#include <IGUIButton.h>
#include <IGUIScrollBar.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "main.h"
#include "settings.h"

#include "gettext.h"

const int ID_soundText1 = 263;
const int ID_soundText2 = 264;
const int ID_soundExitButton = 265;
const int ID_soundSlider = 266;

GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
		gui::IGUIElement* parent, s32 id,
		IMenuManager *menumgr,
		Client* client
):
	GUIModalMenu(env, parent, id, menumgr),
	m_client(client)
{
}

GUIVolumeChange::~GUIVolumeChange()
{
	removeChildren();
}

void GUIVolumeChange::removeChildren()
{
	{
		gui::IGUIElement *e = getElementFromId(ID_soundText1);
		if(e != NULL)
			e->remove();
	}
	{
		gui::IGUIElement *e = getElementFromId(ID_soundText2);
		if(e != NULL)
			e->remove();
	}
	{
		gui::IGUIElement *e = getElementFromId(ID_soundExitButton);
		if(e != NULL)
			e->remove();
	}
	{
		gui::IGUIElement *e = getElementFromId(ID_soundSlider);
		if(e != NULL)
			e->remove();
	}
}

void GUIVolumeChange::regenerateGui(v2u32 screensize)
{
	/*
		Remove stuff
	*/
	removeChildren();
	
	/*
		Calculate new sizes and positions
	*/
	core::rect<s32> rect(
			screensize.X/2 - 380/2,
			screensize.Y/2 - 200/2,
			screensize.X/2 + 380/2,
			screensize.Y/2 + 200/2
	);
	
	DesiredRect = rect;
	recalculateAbsolutePosition(false);

	v2s32 size = rect.getSize();
	v2s32 topleft_client(40, 0);
	int volume=(int)(g_settings->getFloat("sound_volume")*100);
	/*
		Add stuff
	*/
	{
		core::rect<s32> rect(0, 0, 120, 20);
		rect = rect + v2s32(size.X/2-60, size.Y/2-35);
		wchar_t* text = wgettext("Sound Volume: ");
		Environment->addStaticText(text, rect, false,
				true, this, ID_soundText1);
		delete[] text;
	}
	{
		core::rect<s32> rect(0, 0, 30, 20);
		rect = rect + v2s32(size.X/2+40, size.Y/2-35);
		Environment->addStaticText(core::stringw(volume).c_str(), rect, false,
				true, this, ID_soundText2);
	}
	{
		core::rect<s32> rect(0, 0, 80, 30);
		rect = rect + v2s32(size.X/2-80/2, size.Y/2+55);
		wchar_t* text = wgettext("Exit");
		Environment->addButton(rect, this, ID_soundExitButton,
			text);
		delete[] text;
	}
	{
		core::rect<s32> rect(0, 0, 300, 20);
		rect = rect + v2s32(size.X/2-150, size.Y/2);
		gui::IGUIScrollBar *e = Environment->addScrollBar(true,
			rect, this, ID_soundSlider);
		e->setMax(100);
		e->setPos(volume);
	}
}

void GUIVolumeChange::drawMenu()
{
	gui::IGUISkin* skin = Environment->getSkin();
	if (!skin)
		return;
	video::IVideoDriver* driver = Environment->getVideoDriver();
	video::SColor bgcolor(140,0,0,0);
	driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
	gui::IGUIElement::draw();
}

bool GUIVolumeChange::OnEvent(const SEvent& event)
{
	if(event.EventType==EET_KEY_INPUT_EVENT)
	{
		if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
		{
			quitMenu();
			return true;
		}
		if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
		{
			quitMenu();
			return true;
		}
	}
	if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
		{
			if (event.GUIEvent.Caller->getID() == ID_soundExitButton)
				{
					quitMenu();
					return true;
				}
		}
	if(event.GUIEvent.EventType==gui::EGET_SCROLL_BAR_CHANGED)
		{
		if (event.GUIEvent.Caller->getID() == ID_soundSlider)
			{
				s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
				g_settings->setFloat("sound_volume",(float)pos/100);
				gui::IGUIElement *e = getElementFromId(ID_soundText2);
				e->setText( core::stringw(pos).c_str() );
				return true;
			}
		}
	return Parent ? Parent->OnEvent(event) : false;
}