mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Rename slider widget functions to be less specific.
parent
23a8222200
commit
d35f1d3d06
|
@ -741,11 +741,11 @@ struct MusicWindow : public Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_M_MUSIC_VOL:
|
case WID_M_MUSIC_VOL:
|
||||||
DrawVolumeSliderWidget(r, _settings_client.music.music_vol);
|
DrawSliderWidget(r, _settings_client.music.music_vol);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_M_EFFECT_VOL:
|
case WID_M_EFFECT_VOL:
|
||||||
DrawVolumeSliderWidget(r, _settings_client.music.effect_vol);
|
DrawSliderWidget(r, _settings_client.music.effect_vol);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -788,7 +788,7 @@ struct MusicWindow : public Window {
|
||||||
|
|
||||||
case WID_M_MUSIC_VOL: case WID_M_EFFECT_VOL: { // volume sliders
|
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;
|
byte &vol = (widget == WID_M_MUSIC_VOL) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
|
||||||
if (ClickVolumeSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, vol)) {
|
if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, vol)) {
|
||||||
if (widget == WID_M_MUSIC_VOL) {
|
if (widget == WID_M_MUSIC_VOL) {
|
||||||
MusicDriver::GetInstance()->SetVolume(vol);
|
MusicDriver::GetInstance()->SetVolume(vol);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -347,11 +347,11 @@ struct GameOptionsWindow : Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GO_BASE_SFX_VOLUME:
|
case WID_GO_BASE_SFX_VOLUME:
|
||||||
DrawVolumeSliderWidget(r, _settings_client.music.effect_vol);
|
DrawSliderWidget(r, _settings_client.music.effect_vol);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GO_BASE_MUSIC_VOLUME:
|
case WID_GO_BASE_MUSIC_VOLUME:
|
||||||
DrawVolumeSliderWidget(r, _settings_client.music.music_vol);
|
DrawSliderWidget(r, _settings_client.music.music_vol);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,7 +478,7 @@ struct GameOptionsWindow : Window {
|
||||||
case WID_GO_BASE_SFX_VOLUME:
|
case WID_GO_BASE_SFX_VOLUME:
|
||||||
case WID_GO_BASE_MUSIC_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;
|
byte &vol = (widget == WID_GO_BASE_MUSIC_VOLUME) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
|
||||||
if (ClickVolumeSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, vol)) {
|
if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, vol)) {
|
||||||
if (widget == WID_GO_BASE_MUSIC_VOLUME) MusicDriver::GetInstance()->SetVolume(vol);
|
if (widget == WID_GO_BASE_MUSIC_VOLUME) MusicDriver::GetInstance()->SetVolume(vol);
|
||||||
this->SetWidgetDirty(widget);
|
this->SetWidgetDirty(widget);
|
||||||
SetWindowClassesDirty(WC_MUSIC_WINDOW);
|
SetWindowClassesDirty(WC_MUSIC_WINDOW);
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
static const int SLIDER_WIDTH = 3;
|
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 r Rectangle to draw the widget in
|
||||||
* @param value Value to put the slider at
|
* @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;
|
const int ha = (r.bottom - r.top) / 5;
|
||||||
int wx1 = r.left, wx2 = r.right;
|
int wx1 = r.left, wx2 = r.right;
|
||||||
if (_current_text_dir == TD_RTL) std::swap(wx1, wx2);
|
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[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);
|
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);
|
const int sw = ScaleGUITrad(SLIDER_WIDTH);
|
||||||
if (_current_text_dir == TD_RTL) value = 127 - value;
|
if (_current_text_dir == TD_RTL) value = 127 - value;
|
||||||
const int x = r.left + (value * (r.right - r.left - sw) / 127);
|
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 r Rectangle of the widget
|
||||||
* @param pt Clicked point
|
* @param pt Clicked point
|
||||||
* @param value[in,out] Volume value to modify
|
* @param value[in,out] Value to modify
|
||||||
* @return True if the volume setting was modified
|
* @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);
|
const int sw = ScaleGUITrad(SLIDER_WIDTH);
|
||||||
byte new_vol = Clamp((pt.x - r.left - sw / 2) * 127 / (r.right - r.left - sw), 0, 127);
|
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_vol = 127 - new_vol;
|
if (_current_text_dir == TD_RTL) new_value = 127 - new_value;
|
||||||
|
|
||||||
if (new_vol != value) {
|
if (new_value != value) {
|
||||||
value = new_vol;
|
value = new_value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
#include "../gfx_func.h"
|
#include "../gfx_func.h"
|
||||||
|
|
||||||
|
|
||||||
void DrawVolumeSliderWidget(Rect r, byte value);
|
void DrawSliderWidget(Rect r, byte value);
|
||||||
bool ClickVolumeSliderWidget(Rect r, Point pt, byte &value);
|
bool ClickSliderWidget(Rect r, Point pt, byte &value);
|
||||||
|
|
||||||
|
|
||||||
#endif /* WIDGETS_SLIDER_TYPE_H */
|
#endif /* WIDGETS_SLIDER_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue