OpenTTD Source 20260109-master-g241b5fcdfe
slider_func.h File Reference

Functions related to the horizontal slider widget. More...

#include "core/geometry_type.hpp"
#include "gfx_type.h"

Go to the source code of this file.

Typedefs

using SliderMarkFunc = std::optional< std::string >(int nmarks, int mark, int value)
 

Functions

void DrawSliderWidget (Rect r, Colours wedge_colour, Colours handle_colour, TextColour text_colour, int min_value, int max_value, int nmarks, int value, SliderMarkFunc *mark_func)
 Draw a slider widget with knob at given value.
 
bool ClickSliderWidget (Rect r, Point pt, int min_value, int max_value, int nmarks, int &value)
 Handle click on a slider widget to change the value.
 
bool ClickSliderWidget (Rect r, Point pt, int min_value, int max_value, int nmarks, uint8_t &value)
 

Detailed Description

Functions related to the horizontal slider widget.

Definition in file slider_func.h.

Typedef Documentation

◆ SliderMarkFunc

using SliderMarkFunc = std::optional<std::string>(int nmarks, int mark, int value)

Definition at line 16 of file slider_func.h.

Function Documentation

◆ ClickSliderWidget() [1/2]

bool ClickSliderWidget ( Rect  r,
Point  pt,
int  min_value,
int  max_value,
int  nmarks,
int &  value 
)

Handle click on a slider widget to change the value.

Parameters
rRectangle of the widget
ptClicked point
min_valueMinimum value of slider
max_valueMaximum value of slider
nmarksNumber of marks displayed. Value will be rounded to nearest mark.
value[in,out]Value to modify
Returns
True if the value setting was modified

Definition at line 94 of file slider.cpp.

References _current_text_dir, Clamp(), ScaleGUITrad(), TD_RTL, and Coord2D< T >::x.

Referenced by MusicWindow::OnClick(), and GameOptionsWindow::OnClick().

◆ ClickSliderWidget() [2/2]

bool ClickSliderWidget ( Rect  r,
Point  pt,
int  min_value,
int  max_value,
int  nmarks,
uint8_t &  value 
)
inline

Definition at line 20 of file slider_func.h.

◆ DrawSliderWidget()

void DrawSliderWidget ( Rect  r,
Colours  wedge_colour,
Colours  handle_colour,
TextColour  text_colour,
int  min_value,
int  max_value,
int  nmarks,
int  value,
SliderMarkFunc *  mark_func 
)

Draw a slider widget with knob at given value.

Parameters
rRectangle to draw the widget in
wedge_colourColour to draw wedge.
handle_colourColour to draw handle.
text_colourColour of text.
min_valueMinimum value of slider
max_valueMaximum value of slider
nmarksNumber of marks to display (when mark_func is provided.)
valueValue to put the slider at
mark_funcCallback function to get the StringID to draw on a mark.

Definition at line 34 of file slider.cpp.

References _current_text_dir, WidgetDimensions::bevel, Clamp(), DrawFrameRect(), DrawString(), FS_SMALL, GetCharacterHeight(), GetColourGradient(), GetStringBoundingBox(), GfxFillPolygon(), WidgetDimensions::hsep_normal, SA_CENTER, WidgetDimensions::scaled, ScaleGUITrad(), and TD_RTL.

Referenced by MusicWindow::DrawWidget(), and GameOptionsWindow::DrawWidget().