Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../window_gui.h"
12 #include "../window_func.h"
13 #include "../strings_func.h"
14 #include "../zoom_func.h"
15 #include "slider_func.h"
17 #include "../safeguards.h"
19 static const int SLIDER_WIDTH = 3;
29 void DrawSliderWidget(
Rect r,
int min_value,
int max_value,
int value,
const std::map<int, StringID> &labels)
34 max_value -= min_value;
37 const int ha = (r.bottom - r.top) / 5;
40 int wx1 = r.left + sw / 2;
41 int wx2 = r.right - sw / 2;
46 const std::vector<Point> wedge{
Point{wx1, r.bottom - ha},
Point{wx2, r.top + ha},
Point{wx2, r.bottom - ha} };
48 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t);
50 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow, t);
53 for (
auto label : labels) {
54 x = label.first - min_value;
56 x = r.left + (x * (r.right - r.left - sw) / max_value) + sw / 2;
58 if (label.second != STR_NULL) {
60 x =
Clamp(x - d.width / 2, r.left, r.right - d.width);
68 x = r.left + (value * (r.right - r.left - sw) / max_value);
69 DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
81 max_value -= min_value;
84 int new_value =
Clamp((pt.x - r.left - sw / 2) * max_value / (r.right - r.left - sw), 0, max_value);
86 new_value += min_value;
88 if (new_value != value) {
Dimensions (a width and height) of a rectangle in 2D.
void GfxFillPolygon(const std::vector< Point > &shape, int colour, FillRectMode mode)
Fill a polygon with colour.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
@ FS_SMALL
Index of the small font in the font tables.
void DrawSliderWidget(Rect r, int min_value, int max_value, int value, const std::map< int, StringID > &labels)
Draw a slider widget with knob at given value.
Coordinates of a point in 2D.
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int &value)
Handle click on a slider widget to change the value.
@ SA_CENTER
Center both horizontally and vertically.
Specification of a rectangle with absolute coordinates of all edges.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.