Changeset - r25404:47718855e263
[Not reviewed]
master
0 1 0
Peter Nelson - 3 years ago 2021-05-07 21:33:48
peter1138@openttd.org
Codechange: Slider widget used different range for drawing vs setting.

Using the same range for setting means that no workaround for setting the extremes is necessary.
1 file changed with 4 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/widgets/slider.cpp
Show inline comments
 
@@ -16,6 +16,7 @@
 

	
 
#include "../safeguards.h"
 

	
 
static const int SLIDER_WIDTH = 3;
 

	
 
/**
 
 * Draw a volume slider widget with know at given value
 
@@ -24,8 +25,6 @@
 
 */
 
void DrawVolumeSliderWidget(Rect r, byte value)
 
{
 
	static const int slider_width = 3;
 

	
 
	/* Draw a wedge indicating low to high volume level. */
 
	const int ha = (r.bottom - r.top) / 5;
 
	int wx1 = r.left, wx2 = r.right;
 
@@ -40,7 +39,7 @@ void DrawVolumeSliderWidget(Rect r, byte
 
	GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow);
 

	
 
	/* Draw a slider handle indicating current volume level. */
 
	const int sw = ScaleGUITrad(slider_width);
 
	const int sw = ScaleGUITrad(SLIDER_WIDTH);
 
	if (_current_text_dir == TD_RTL) value = 127 - value;
 
	const int x = r.left + (value * (r.right - r.left - sw) / 127);
 
	DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
 
@@ -55,12 +54,10 @@ void DrawVolumeSliderWidget(Rect r, byte
 
 */
 
bool ClickVolumeSliderWidget(Rect r, Point pt, byte &value)
 
{
 
	byte new_vol = Clamp((pt.x - r.left) * 127 / (r.right - r.left), 0, 127);
 
	const int sw = ScaleGUITrad(SLIDER_WIDTH);
 
	byte new_vol = Clamp((pt.x - r.left - sw / 2) * 127 / (r.right - r.left - sw), 0, 127);
 
	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 != value) {
 
		value = new_vol;
 
		return true;
0 comments (0 inline, 0 general)