Merge branch 'master' into jgrpp

# Conflicts:
#	src/build_vehicle_gui.cpp
#	src/cheat_gui.cpp
#	src/company_gui.cpp
#	src/error_gui.cpp
#	src/fios_gui.cpp
#	src/gfx_func.h
#	src/graph_gui.cpp
#	src/group_gui.cpp
#	src/misc_gui.cpp
#	src/newgrf_debug_gui.cpp
#	src/order_gui.cpp
#	src/road_gui.cpp
#	src/roadveh_gui.cpp
#	src/settings_gui.cpp
#	src/ship_gui.cpp
#	src/station_gui.cpp
#	src/statusbar_gui.cpp
#	src/subsidy_gui.cpp
#	src/timetable_gui.cpp
#	src/town_gui.cpp
#	src/train_gui.cpp
#	src/tree_gui.cpp
#	src/vehicle_gui.cpp
#	src/widget.cpp
#	src/widgets/dropdown.cpp
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2022-12-04 13:53:36 +00:00
53 changed files with 1478 additions and 1416 deletions

View File

@@ -88,8 +88,10 @@ uint DropDownListIconItem::Width() const
void DropDownListIconItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
bool rtl = _current_text_dir == TD_RTL;
DrawSprite(this->sprite, this->pal, rtl ? r.right - this->dim.width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT, CenterBounds(r.top, r.bottom, this->sprite_y));
DrawString(r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), r.right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
Rect ir = r.Shrink(WD_DROPDOWNTEXT_LEFT, WD_DROPDOWNTEXT_TOP, WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_LEFT);
Rect tr = ir.Indent(this->dim.width + WD_FRAMERECT_LEFT, rtl);
DrawSprite(this->sprite, this->pal, ir.WithWidth(this->dim.width, rtl).left, CenterBounds(r.top, r.bottom, this->sprite_y));
DrawString(tr.left, tr.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
}
void DropDownListIconItem::SetDimension(Dimension d)

View File

@@ -19,47 +19,73 @@
static const int SLIDER_WIDTH = 3;
/**
* Draw a volume slider widget with know at given value
* @param r Rectangle to draw the widget in
* Draw a slider widget with knob at given value
* @param r Rectangle to draw the widget in
* @param min_value Minimum value of slider
* @param max_value Maximum value of slider
* @param value Value to put the slider at
* @param labels List of positions and labels to draw along the slider.
*/
void DrawVolumeSliderWidget(Rect r, byte value)
void DrawSliderWidget(Rect r, int min_value, int max_value, int value, const std::map<int, StringID> &labels)
{
/* Draw a wedge indicating low to high volume level. */
/* Allow space for labels. We assume they are in the small font. */
if (labels.size() > 0) r.bottom -= FONT_HEIGHT_SMALL + WidgetDimensions::scaled.hsep_normal;
max_value -= min_value;
/* Draw a wedge indicating low to high value. */
const int ha = (r.bottom - r.top) / 5;
int wx1 = r.left, wx2 = r.right;
const int sw = ScaleGUITrad(SLIDER_WIDTH);
const int t = WidgetDimensions::scaled.bevel.top; /* Thickness of lines */
int wx1 = r.left + sw / 2;
int wx2 = r.right - sw / 2;
if (_current_text_dir == TD_RTL) std::swap(wx1, wx2);
const uint shadow = _colour_gradient[COLOUR_GREY][3];
const uint fill = _colour_gradient[COLOUR_GREY][6];
const uint light = _colour_gradient[COLOUR_GREY][7];
const std::vector<Point> wedge{ Point{wx1, r.bottom - ha}, Point{wx2, r.top + ha}, Point{wx2, r.bottom - ha} };
GfxFillPolygon(wedge, fill);
GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light);
GfxDrawLine(wedge[1].x, wedge[1].y, wedge[2].x, wedge[2].y, _current_text_dir == TD_RTL ? shadow : light);
GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow);
GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t);
GfxDrawLine(wedge[1].x, wedge[1].y, wedge[2].x, wedge[2].y, _current_text_dir == TD_RTL ? shadow : light, t);
GfxDrawLine(wedge[0].x, wedge[0].y, wedge[1].x, wedge[1].y, shadow, t);
/* Draw a slider handle indicating current volume level. */
const int sw = ScaleGUITrad(SLIDER_WIDTH);
if (_current_text_dir == TD_RTL) value = 127 - value;
const int x = r.left + (value * (r.right - r.left - sw) / 127);
int x;
for (auto label : labels) {
x = label.first - min_value;
if (_current_text_dir == TD_RTL) x = max_value - x;
x = r.left + (x * (r.right - r.left - sw) / max_value) + sw / 2;
GfxDrawLine(x, r.bottom - ha + 1, x, r.bottom + (label.second == STR_NULL ? 0 : WidgetDimensions::scaled.hsep_normal), shadow, t);
if (label.second != STR_NULL) {
Dimension d = GetStringBoundingBox(label.second, FS_SMALL);
x = Clamp(x - d.width / 2, r.left, r.right - d.width);
DrawString(x, x + d.width, r.bottom + 1 + WidgetDimensions::scaled.hsep_normal, label.second, TC_BLACK, SA_CENTER, false, FS_SMALL);
}
}
/* Draw a slider handle indicating current value. */
if (_current_text_dir == TD_RTL) value = max_value - value;
x = r.left + ((value - min_value) * (r.right - r.left - sw) / max_value);
DrawFrameRect(x, r.top, x + sw, r.bottom, COLOUR_GREY, FR_NONE);
}
/**
* Handle click on a volume slider widget to change the value
* Handle click on a slider widget to change the value
* @param r Rectangle of the widget
* @param pt Clicked point
* @param value[in,out] Volume value to modify
* @return True if the volume setting was modified
* @param value[in,out] Value to modify
* @return True if the value setting was modified
*/
bool ClickVolumeSliderWidget(Rect r, Point pt, byte &value)
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int &value)
{
const int sw = ScaleGUITrad(SLIDER_WIDTH);
byte new_vol = Clamp((pt.x - r.left - sw / 2) * 127 / (r.right - r.left - sw), 0, 127);
if (_current_text_dir == TD_RTL) new_vol = 127 - new_vol;
max_value -= min_value;
if (new_vol != value) {
value = new_vol;
const int sw = ScaleGUITrad(SLIDER_WIDTH);
int new_value = Clamp((pt.x - r.left - sw / 2) * max_value / (r.right - r.left - sw), 0, max_value);
if (_current_text_dir == TD_RTL) new_value = max_value - new_value;
new_value += min_value;
if (new_value != value) {
value = new_value;
return true;
}

View File

@@ -13,9 +13,17 @@
#include "../window_type.h"
#include "../gfx_func.h"
#include <map>
void DrawVolumeSliderWidget(Rect r, byte value);
bool ClickVolumeSliderWidget(Rect r, Point pt, byte &value);
void DrawSliderWidget(Rect r, int min_value, int max_value, int value, const std::map<int, StringID> &labels);
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int &value);
inline bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, byte &value)
{
int tmp_value = value;
if (!ClickSliderWidget(r, pt, min_value, max_value, tmp_value)) return false;
value = tmp_value;
return true;
}
#endif /* WIDGETS_SLIDER_TYPE_H */