OpenTTD Source 20260206-master-g4d4e37dbf1
slider.cpp File Reference

Implementation of the horizontal slider widget. More...

#include "stdafx.h"
#include "gfx_func.h"
#include "palette_func.h"
#include "slider_func.h"
#include "strings_func.h"
#include "window_gui.h"
#include "zoom_func.h"
#include "safeguards.h"

Go to the source code of this file.

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.

Variables

static const int SLIDER_WIDTH = 3

Detailed Description

Implementation of the horizontal slider widget.

Definition in file slider.cpp.

Function Documentation

◆ ClickSliderWidget()

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.
[in,out]valueValue to modify
Returns
True if the value setting was modified

Definition at line 94 of file slider.cpp.

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

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

◆ 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, Clamp(), DrawFrameRect(), DrawString(), FS_SMALL, GetCharacterHeight(), GetColourGradient(), GetStringBoundingBox(), GfxFillPolygon(), Point, Rect, SA_CENTER, WidgetDimensions::scaled, ScaleGUITrad(), and TD_RTL.

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

Variable Documentation

◆ SLIDER_WIDTH

const int SLIDER_WIDTH = 3
static

Definition at line 20 of file slider.cpp.