X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fgui%2FguiVolumeChange.cpp;h=61ab758a11425c5d0e35b6afcf0bc87e7056d32b;hb=b7b5aad02758ae897fc0239f50f93e04d085ceed;hp=8c462312bcc4c85bcaea1e99f9b3c84fadae6673;hpb=20a85d76d94c9c5c7fbe198c3d0e1fbee97a485f;p=dragonfireclient.git diff --git a/src/gui/guiVolumeChange.cpp b/src/gui/guiVolumeChange.cpp index 8c462312b..61ab758a1 100644 --- a/src/gui/guiVolumeChange.cpp +++ b/src/gui/guiVolumeChange.cpp @@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "guiVolumeChange.h" #include "debug.h" +#include "guiButton.h" #include "serialization.h" #include #include @@ -37,9 +38,10 @@ const int ID_soundMuteButton = 266; GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr + IMenuManager *menumgr, ISimpleTextureSource *tsrc ): - GUIModalMenu(env, parent, id, menumgr) + GUIModalMenu(env, parent, id, menumgr), + m_tsrc(tsrc) { } @@ -58,6 +60,9 @@ void GUIVolumeChange::removeChildren() if (gui::IGUIElement *e = getElementFromId(ID_soundSlider)) e->remove(); + + if (gui::IGUIElement *e = getElementFromId(ID_soundMuteButton)) + e->remove(); } void GUIVolumeChange::regenerateGui(v2u32 screensize) @@ -66,15 +71,15 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) Remove stuff */ removeChildren(); - /* Calculate new sizes and positions */ + const float s = m_gui_scale; DesiredRect = core::rect( - screensize.X/2 - 380/2, - screensize.Y/2 - 200/2, - screensize.X/2 + 380/2, - screensize.Y/2 + 200/2 + screensize.X / 2 - 380 * s / 2, + screensize.Y / 2 - 200 * s / 2, + screensize.X / 2 + 380 * s / 2, + screensize.Y / 2 + 200 * s / 2 ); recalculateAbsolutePosition(false); @@ -85,36 +90,36 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) Add stuff */ { - core::rect rect(0, 0, 160, 20); - rect = rect + v2s32(size.X / 2 - 80, size.Y / 2 - 70); + core::rect rect(0, 0, 160 * s, 20 * s); + rect = rect + v2s32(size.X / 2 - 80 * s, size.Y / 2 - 70 * s); - const wchar_t *text = wgettext("Sound Volume: "); + wchar_t text[100]; + const wchar_t *str = wgettext("Sound Volume: %d%%"); + swprintf(text, sizeof(text) / sizeof(wchar_t), str, volume); + delete[] str; core::stringw volume_text = text; - delete [] text; - volume_text += core::stringw(volume) + core::stringw("%"); Environment->addStaticText(volume_text.c_str(), rect, false, true, this, ID_soundText); } { - core::rect rect(0, 0, 80, 30); - rect = rect + v2s32(size.X/2-80/2, size.Y/2+55); + core::rect rect(0, 0, 80 * s, 30 * s); + rect = rect + v2s32(size.X / 2 - 80 * s / 2, size.Y / 2 + 55 * s); const wchar_t *text = wgettext("Exit"); - Environment->addButton(rect, this, ID_soundExitButton, - text); + GUIButton::addButton(Environment, rect, m_tsrc, this, ID_soundExitButton, text); delete[] text; } { - core::rect rect(0, 0, 300, 20); - rect = rect + v2s32(size.X / 2 - 150, size.Y / 2); + core::rect rect(0, 0, 300 * s, 20 * s); + rect = rect + v2s32(size.X / 2 - 150 * s, size.Y / 2); gui::IGUIScrollBar *e = Environment->addScrollBar(true, rect, this, ID_soundSlider); e->setMax(100); e->setPos(volume); } { - core::rect rect(0, 0, 160, 20); - rect = rect + v2s32(size.X / 2 - 80, size.Y / 2 - 35); + core::rect rect(0, 0, 160 * s, 20 * s); + rect = rect + v2s32(size.X / 2 - 80 * s, size.Y / 2 - 35 * s); const wchar_t *text = wgettext("Muted"); Environment->addCheckBox(g_settings->getBool("mute_sound"), rect, this, ID_soundMuteButton, text); @@ -167,7 +172,7 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if (!canTakeFocus(event.GUIEvent.Element)) { - dstream << "GUIMainMenu: Not allowing focus change." + infostream << "GUIVolumeChange: Not allowing focus change." << std::endl; // Returning true disables focus change return true; @@ -179,11 +184,13 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) g_settings->setFloat("sound_volume", (float) pos / 100); gui::IGUIElement *e = getElementFromId(ID_soundText); - const wchar_t *text = wgettext("Sound Volume: "); + wchar_t text[100]; + const wchar_t *str = wgettext("Sound Volume: %d%%"); + swprintf(text, sizeof(text) / sizeof(wchar_t), str, pos); + delete[] str; + core::stringw volume_text = text; - delete [] text; - volume_text += core::stringw(pos) + core::stringw("%"); e->setText(volume_text.c_str()); return true; } @@ -193,4 +200,3 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) return Parent ? Parent->OnEvent(event) : false; } -