From d35f1d3d06f270d607aafa39b0f25232b0964936 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 11 Sep 2022 21:21:59 +0100 Subject: [PATCH] Codechange: Rename slider widget functions to be less specific. --- src/music_gui.cpp | 6 +++--- src/settings_gui.cpp | 6 +++--- src/widgets/slider.cpp | 24 ++++++++++++------------ src/widgets/slider_func.h | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/music_gui.cpp b/src/music_gui.cpp index edfccf5766..72fec6f9c6 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -741,11 +741,11 @@ struct MusicWindow : public Window { } case WID_M_MUSIC_VOL: - DrawVolumeSliderWidget(r, _settings_client.music.music_vol); + DrawSliderWidget(r, _settings_client.music.music_vol); break; case WID_M_EFFECT_VOL: - DrawVolumeSliderWidget(r, _settings_client.music.effect_vol); + DrawSliderWidget(r, _settings_client.music.effect_vol); break; } } @@ -788,7 +788,7 @@ struct MusicWindow : public Window { case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: { // volume sliders byte &vol = (widget == WID_M_MUSIC_VOL) ? _settings_client.music.music_vol : _settings_client.music.effect_vol; - if (ClickVolumeSliderWidget(this->GetWidget(widget)->GetCurrentRect(), pt, vol)) { + if (ClickSliderWidget(this->GetWidget(widget)->GetCurrentRect(), pt, vol)) { if (widget == WID_M_MUSIC_VOL) { MusicDriver::GetInstance()->SetVolume(vol); } else { diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 035999e580..dc1f78e50f 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -347,11 +347,11 @@ struct GameOptionsWindow : Window { break; case WID_GO_BASE_SFX_VOLUME: - DrawVolumeSliderWidget(r, _settings_client.music.effect_vol); + DrawSliderWidget(r, _settings_client.music.effect_vol); break; case WID_GO_BASE_MUSIC_VOLUME: - DrawVolumeSliderWidget(r, _settings_client.music.music_vol); + DrawSliderWidget(r, _settings_client.music.music_vol); break; } } @@ -478,7 +478,7 @@ struct GameOptionsWindow : Window { case WID_GO_BASE_SFX_VOLUME: case WID_GO_BASE_MUSIC_VOLUME: { byte &vol = (widget == WID_GO_BASE_MUSIC_VOLUME) ? _settings_client.music.music_vol : _settings_client.music.effect_vol; - if (ClickVolumeSliderWidget(this->GetWidget(widget)->GetCurrentRect(), pt, vol)) { + if (ClickSliderWidget(this->GetWidget(widget)->GetCurrentRect(), pt, vol)) { if (widget == WID_GO_BASE_MUSIC_VOLUME) MusicDriver::GetInstance()->SetVolume(vol); this->SetWidgetDirty(widget); SetWindowClassesDirty(WC_MUSIC_WINDOW); diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp index 67c4c372d2..253cd34c52 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -19,13 +19,13 @@ static const int SLIDER_WIDTH = 3; /** - * Draw a volume slider widget with know at given value + * Draw a slider widget with knob at given value * @param r Rectangle to draw the widget in * @param value Value to put the slider at */ -void DrawVolumeSliderWidget(Rect r, byte value) +void DrawSliderWidget(Rect r, byte value) { - /* Draw a wedge indicating low to high volume level. */ + /* Draw a wedge indicating low to high value. */ const int ha = (r.bottom - r.top) / 5; int wx1 = r.left, wx2 = r.right; if (_current_text_dir == TD_RTL) std::swap(wx1, wx2); @@ -38,7 +38,7 @@ void DrawVolumeSliderWidget(Rect r, byte value) GfxDrawLine(wedge[1].x, wedge[1].y, wedge[2].x, wedge[2].y, _current_text_dir == TD_RTL ? shadow : light); GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow); - /* Draw a slider handle indicating current volume level. */ + /* Draw a slider handle indicating current value. */ 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); @@ -46,20 +46,20 @@ void DrawVolumeSliderWidget(Rect r, byte value) } /** - * Handle click on a volume slider widget to change the value + * Handle click on a slider widget to change the value * @param r Rectangle of the widget * @param pt Clicked point - * @param value[in,out] Volume value to modify - * @return True if the volume setting was modified + * @param value[in,out] Value to modify + * @return True if the value setting was modified */ -bool ClickVolumeSliderWidget(Rect r, Point pt, byte &value) +bool ClickSliderWidget(Rect r, Point pt, byte &value) { 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; + byte new_value = Clamp((pt.x - r.left - sw / 2) * 127 / (r.right - r.left - sw), 0, 127); + if (_current_text_dir == TD_RTL) new_value = 127 - new_value; - if (new_vol != value) { - value = new_vol; + if (new_value != value) { + value = new_value; return true; } diff --git a/src/widgets/slider_func.h b/src/widgets/slider_func.h index 1aa1fa10c6..64f445da64 100644 --- a/src/widgets/slider_func.h +++ b/src/widgets/slider_func.h @@ -14,8 +14,8 @@ #include "../gfx_func.h" -void DrawVolumeSliderWidget(Rect r, byte value); -bool ClickVolumeSliderWidget(Rect r, Point pt, byte &value); +void DrawSliderWidget(Rect r, byte value); +bool ClickSliderWidget(Rect r, Point pt, byte &value); #endif /* WIDGETS_SLIDER_TYPE_H */