13 #include "slider_func.h"
20 static const int SLIDER_WIDTH = 3;
31 void DrawSliderWidget(
Rect r,
int min_value,
int max_value,
int nmarks,
int value, SliderMarkFunc *mark_func)
36 max_value -= min_value;
39 const int ha = (r.bottom - r.top) / 5;
42 int wx1 = r.left + sw / 2;
43 int wx2 = r.right - sw / 2;
48 const std::vector<Point> wedge{
Point{wx1, r.bottom - ha},
Point{wx2, r.top + ha},
Point{wx2, r.bottom - ha} };
50 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t);
52 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow, t);
55 if (mark_func !=
nullptr) {
56 for (
int mark = 0; mark < nmarks; ++mark) {
57 const int mark_value = (max_value * mark) / (nmarks - 1);
59 const StringID str = mark_func(nmarks, mark, mark_value + min_value);
64 x = r.left + (x * (r.right - r.left - sw) / max_value) + sw / 2;
66 if (str == STR_NULL)
continue;
69 x =
Clamp(x - d.width / 2, r.left, r.right - d.width);
77 x = r.left + (value * (r.right - r.left - sw) / max_value);
78 DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
93 max_value -= min_value;
96 int new_value =
Clamp((pt.x - r.left - sw / 2) * max_value / (r.right - r.left - sw), 0, max_value);
98 new_value += min_value;
101 const int step = max_value / (nmarks - 1);
102 new_value = ((new_value + step / 2) / step) * step;
105 if (new_value != value) {
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
void GfxFillPolygon(const std::vector< Point > &shape, int colour, FillRectMode mode)
Fill a polygon with colour.
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.
Functions related to the gfx engine.
@ SA_CENTER
Center both horizontally and vertically.
@ FS_SMALL
Index of the small font in the font tables.
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, 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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
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.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.