Skip to content

Commit ef15242

Browse files
authoredMay 28, 2017
guiVolumeChange: prevent wrong value position by using 1 label instead of 2 (#5839)
* Use only one label instead of two for the soundText, this permit to ensure both label & values are aligned * Add '%' character too, to reflect it's a percentage volume * Remove rect on regenerateGui (upper part) which shadows outer part and which is not needed outside of the DesiredRect affectation Fix issue #5837
1 parent c09e16f commit ef15242

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed
 

‎src/guiVolumeChange.cpp

+29-31
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3030

3131
#include "gettext.h"
3232

33-
const int ID_soundText1 = 263;
34-
const int ID_soundText2 = 264;
35-
const int ID_soundExitButton = 265;
36-
const int ID_soundSlider = 266;
33+
const int ID_soundText = 263;
34+
const int ID_soundExitButton = 264;
35+
const int ID_soundSlider = 265;
3736

3837
GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
3938
gui::IGUIElement* parent, s32 id,
@@ -50,10 +49,7 @@ GUIVolumeChange::~GUIVolumeChange()
5049

5150
void GUIVolumeChange::removeChildren()
5251
{
53-
if (gui::IGUIElement *e = getElementFromId(ID_soundText1))
54-
e->remove();
55-
56-
if (gui::IGUIElement *e = getElementFromId(ID_soundText2))
52+
if (gui::IGUIElement *e = getElementFromId(ID_soundText))
5753
e->remove();
5854

5955
if (gui::IGUIElement *e = getElementFromId(ID_soundExitButton))
@@ -73,34 +69,31 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
7369
/*
7470
Calculate new sizes and positions
7571
*/
76-
core::rect<s32> rect(
77-
screensize.X/2 - 380/2,
78-
screensize.Y/2 - 200/2,
79-
screensize.X/2 + 380/2,
80-
screensize.Y/2 + 200/2
72+
DesiredRect = core::rect<s32>(
73+
screensize.X/2 - 380/2,
74+
screensize.Y/2 - 200/2,
75+
screensize.X/2 + 380/2,
76+
screensize.Y/2 + 200/2
8177
);
82-
83-
DesiredRect = rect;
8478
recalculateAbsolutePosition(false);
8579

86-
v2s32 size = rect.getSize();
87-
int volume = (int)(g_settings->getFloat("sound_volume")*100);
80+
v2s32 size = DesiredRect.getSize();
81+
int volume = (int)(g_settings->getFloat("sound_volume") * 100);
82+
8883
/*
8984
Add stuff
9085
*/
9186
{
92-
core::rect<s32> rect(0, 0, 120, 20);
93-
rect = rect + v2s32(size.X/2-60, size.Y/2-35);
87+
core::rect<s32> rect(0, 0, 160, 20);
88+
rect = rect + v2s32(size.X / 2 - 80, size.Y / 2 - 35);
89+
9490
const wchar_t *text = wgettext("Sound Volume: ");
95-
Environment->addStaticText(text, rect, false,
96-
true, this, ID_soundText1);
97-
delete[] text;
98-
}
99-
{
100-
core::rect<s32> rect(0, 0, 30, 20);
101-
rect = rect + v2s32(size.X/2+40, size.Y/2-35);
102-
Environment->addStaticText(core::stringw(volume).c_str(), rect, false,
103-
true, this, ID_soundText2);
91+
core::stringw volume_text = text;
92+
delete [] text;
93+
94+
volume_text += core::stringw(volume) + core::stringw("%");
95+
Environment->addStaticText(volume_text.c_str(), rect, false,
96+
true, this, ID_soundText);
10497
}
10598
{
10699
core::rect<s32> rect(0, 0, 80, 30);
@@ -155,10 +148,15 @@ bool GUIVolumeChange::OnEvent(const SEvent& event)
155148
if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) {
156149
if (event.GUIEvent.Caller->getID() == ID_soundSlider) {
157150
s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
158-
g_settings->setFloat("sound_volume", (float)pos/100);
151+
g_settings->setFloat("sound_volume", (float) pos / 100);
152+
153+
gui::IGUIElement *e = getElementFromId(ID_soundText);
154+
const wchar_t *text = wgettext("Sound Volume: ");
155+
core::stringw volume_text = text;
156+
delete [] text;
159157

160-
gui::IGUIElement *e = getElementFromId(ID_soundText2);
161-
e->setText(core::stringw(pos).c_str());
158+
volume_text += core::stringw(pos) + core::stringw("%");
159+
e->setText(volume_text.c_str());
162160
return true;
163161
}
164162
}

0 commit comments

Comments
 (0)
Please sign in to comment.