summaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2021-05-07 22:33:48 +0100
committerPeterN <peter@fuzzle.org>2021-05-08 09:54:14 +0100
commitdd41de89315156cf7c5e43872de0863d4c539a95 (patch)
tree1f989df48343ee109beefb37f2bd8230f22afe51 /src/widgets
parentd8e06e590aff56c837b29ddbba3764292ea08d85 (diff)
downloadopenttd-dd41de89315156cf7c5e43872de0863d4c539a95.tar.xz
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.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/slider.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp
index 6d6d73288..67c4c372d 100644
--- a/src/widgets/slider.cpp
+++ b/src/widgets/slider.cpp
@@ -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 value)
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 value)
*/
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;