|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../palette_func.h"
12 #include "../window_gui.h"
13 #include "../window_func.h"
14 #include "../strings_func.h"
15 #include "../zoom_func.h"
16 #include "slider_func.h"
18 #include "../safeguards.h"
20 static const int SLIDER_WIDTH = 3;
30 void DrawSliderWidget(
Rect r,
int min_value,
int max_value,
int value,
const std::map<int, StringID> &labels)
35 max_value -= min_value;
38 const int ha = (r.bottom - r.top) / 5;
41 int wx1 = r.left + sw / 2;
42 int wx2 = r.right - sw / 2;
47 const std::vector<Point> wedge{
Point{wx1, r.bottom - ha},
Point{wx2, r.top + ha},
Point{wx2, r.bottom - ha} };
49 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t);
51 GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow, t);
54 for (
auto label : labels) {
55 x = label.first - min_value;
57 x = r.left + (x * (r.right - r.left - sw) / max_value) + sw / 2;
59 if (label.second != STR_NULL) {
61 x =
Clamp(x - d.width / 2, r.left, r.right - d.width);
69 x = r.left + (value * (r.right - r.left - sw) / max_value);
70 DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
82 max_value -= min_value;
85 int new_value =
Clamp((pt.x - r.left - sw / 2) * max_value / (r.right - r.left - sw), 0, max_value);
87 new_value += min_value;
89 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.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
@ 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.
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.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
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.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
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.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.