36void 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,
int soft_min,
int soft_max)
40 if (mark_func !=
nullptr) {
45 const int ha = r.
Height() / 5;
63 const std::array<Point, 3> wedge{
Point{wx1, r.bottom - ha},
Point{wx2, r.top + ha},
Point{wx2, r.bottom - ha} };
65 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t);
67 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow, t);
69 int range = max_value - min_value;
70 int width = r.right - r.left;
73 if (mark_func !=
nullptr) {
74 for (
int mark = 0; mark < nmarks; ++mark) {
75 int mark_value = range * mark / (nmarks - 1);
77 auto str = mark_func(nmarks, mark, mark_value + min_value);
78 if (!str.has_value())
continue;
81 x = r.left + (mark_value * width / range);
83 GfxDrawLine(x, r.bottom - ha + 1, x, r.bottom + (str->empty() ? 0 :
WidgetDimensions::scaled.hsep_normal), shadow, t);
84 if (str->empty())
continue;
90 if (soft_min > mark_value + min_value || soft_max < mark_value + min_value) {
96 if (soft_min > min_value) {
97 x = (soft_min - min_value) * width / range - t;
101 if (soft_max < max_value) {
102 x = (soft_max - min_value) * width / range + t;
109 x = r.left + (value * width / range) - sw / 2;
110 DrawFrameRect(x, r.top, x + sw - 1, r.bottom, handle_colour, {});
125 max_value -= min_value;
128 int new_value =
Clamp((pt.
x - r.left - sw / 2) * max_value / (r.right - r.left - sw), 0, max_value);
130 new_value += min_value;
133 const int step = max_value / (nmarks - 1);
134 new_value = ((new_value + step / 2) / step) * step;
137 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.
void GfxFillPolygon(std::span< const Point > shape, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Fill a polygon with colour.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Functions related to the gfx engine.
@ Small
Index of the small font in the font tables.
Colours
One of 16 base colours used for companies and windows/widgets.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ Checker
Draw only every second pixel, used for greying-out.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
Functions related to palettes.
@ Lightest
Lightest colour shade.
@ Lighter
Lighter colour shade.
@ Light
Light colour shade.
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, int soft_min, int soft_max)
Draw a slider widget with knob at given value.
static const int SLIDER_WIDTH
Width of the slider handle.
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.
Functions related to the horizontal slider widget.
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.
value_type width
The width of the rectangle.
Colour for pixel/line drawing.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int Height() const
Get height of Rect.
Rect WithX(int new_left, int new_right) const
Create a new Rect, replacing the left and right coordinates.
Functions, definitions and such used only by the GUI.
Functions related to zooming.