Changeset - r22840:3800971f1447
[Not reviewed]
master
0 1 0
Niels Martin Hansen - 6 years ago 2018-03-19 20:25:08
nielsm@indvikleren.dk
Fix: Clipping issues with volume sliders in Music GUI

Tested with various languages and GUI font sizes, should look good everywhere.

Also clamps near-end values to minimum and maximum so 0 and 127 are possible to achieve even on small GUI sizes (like the default.)
1 file changed with 10 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/music_gui.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "music/music_driver.hpp"
 
#include "window_gui.h"
 
#include "strings_func.h"
 
#include "window_func.h"
 
#include "sound_func.h"
 
#include "gfx_func.h"
 
#include "zoom_func.h"
 
#include "core/random_func.hpp"
 
#include "error.h"
 
#include "core/geometry_func.hpp"
 
#include "string_func.h"
 
#include "settings_type.h"
 

	
 
@@ -615,21 +616,19 @@ struct MusicWindow : public Window {
 
				}
 
				DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_FROMSTRING, SA_HOR_CENTER);
 
				break;
 
			}
 

	
 
			case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: {
 
				DrawFrameRect(r.left, r.top + 2, r.right, r.bottom - 2, COLOUR_GREY, FR_LOWERED);
 
				int sw = ScaleGUITrad(slider_width);
 
				int hsw = sw / 2;
 
				DrawFrameRect(r.left + hsw, r.top + 2, r.right - hsw, r.bottom - 2, COLOUR_GREY, FR_LOWERED);
 
				byte volume = (widget == WID_M_MUSIC_VOL) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
 
				int x = (volume * (r.right - r.left) / 127);
 
				if (_current_text_dir == TD_RTL) {
 
					x = r.right - x;
 
				} else {
 
					x += r.left;
 
				}
 
				DrawFrameRect(x, r.top, x + slider_width, r.bottom, COLOUR_GREY, FR_NONE);
 
				if (_current_text_dir == TD_RTL) volume = 127 - volume;
 
				int x = r.left + (volume * (r.right - r.left - sw) / 127);
 
				DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
 
				break;
 
			}
 
		}
 
	}
 

	
 
	/**
 
@@ -676,12 +675,15 @@ struct MusicWindow : public Window {
 
				int x = pt.x - this->GetWidget<NWidgetBase>(widget)->pos_x;
 

	
 
				byte *vol = (widget == WID_M_MUSIC_VOL) ? &_settings_client.music.music_vol : &_settings_client.music.effect_vol;
 

	
 
				byte new_vol = x * 127 / this->GetWidget<NWidgetBase>(widget)->current_x;
 
				if (_current_text_dir == TD_RTL) new_vol = 127 - new_vol;
 
				/* Clamp to make sure min and max are properly settable */
 
				if (new_vol > 124) new_vol = 127;
 
				if (new_vol < 3) new_vol = 0;
 
				if (new_vol != *vol) {
 
					*vol = new_vol;
 
					if (widget == WID_M_MUSIC_VOL) MusicVolumeChanged(new_vol);
 
					this->SetDirty();
 
				}
 

	
0 comments (0 inline, 0 general)