13#include "slider_func.h"
20static const int SLIDER_WIDTH = 3;
34void 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)
39 max_value -= min_value;
42 const int ha = (r.bottom - r.top) / 5;
45 int wx1 = r.left + sw / 2;
46 int wx2 = r.right - sw / 2;
51 const std::array<Point, 3> wedge{
Point{wx1, r.bottom - ha},
Point{wx2, r.top + ha},
Point{wx2, r.bottom - ha} };
53 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t);
55 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow, t);
58 if (mark_func !=
nullptr) {
59 for (
int mark = 0; mark < nmarks; ++mark) {
60 const int mark_value = (max_value * mark) / (nmarks - 1);
62 auto str = mark_func(nmarks, mark, mark_value + min_value);
63 if (!str.has_value())
continue;
67 x = r.left + (x * (r.right - r.left - sw) / max_value) + sw / 2;
69 if (str->empty())
continue;
72 x =
Clamp(x - d.width / 2, r.left, r.right - d.width);
80 x = r.left + (value * (r.right - r.left - sw) / max_value);
34void 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) {
…}
96 max_value -= min_value;
99 int new_value =
Clamp((pt.x - r.left - sw / 2) * max_value / (r.right - r.left - sw), 0, max_value);
101 new_value += min_value;
104 const int step = max_value / (nmarks - 1);
105 new_value = ((new_value + step / 2) / step) * step;
108 if (new_value != value) {
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void GfxFillPolygon(std::span< const Point > shape, int colour, FillRectMode mode)
Fill a polygon with colour.
Functions related to the gfx engine.
@ FS_SMALL
Index of the small font in the font tables.
@ SA_CENTER
Center both horizontally and vertically.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Functions related to palettes.
A number of safeguards to prevent using unsafe methods.
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.
Definition of base types and functions in a cross-platform compatible way.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
Dimensions (a width and height) of a rectangle in 2D.
Coordinates of a point in 2D.
Specification of a rectangle with absolute coordinates of all edges.
Functions, definitions and such used only by the GUI.
Functions related to zooming.