Merge branch 'master' into jgrpp

# Conflicts:
#	src/core/geometry_type.hpp
#	src/error_gui.cpp
#	src/rail_gui.cpp
#	src/tree_gui.cpp
#	src/vehicle_gui.cpp
#	src/widgets/dropdown.cpp
This commit is contained in:
Jonathan G Rennison
2022-12-03 23:40:22 +00:00
33 changed files with 174 additions and 147 deletions

View File

@@ -20,14 +20,14 @@
#include "../safeguards.h"
void DropDownListItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
void DropDownListItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
int c1 = _colour_gradient[bg_colour][3];
int c2 = _colour_gradient[bg_colour][7];
int mid = top + this->Height(0) / 2;
GfxFillRect(left + 1, mid - 2, right - 1, mid - 2, c1);
GfxFillRect(left + 1, mid - 1, right - 1, mid - 1, c2);
int mid = (r.top + r.bottom) / 2;
GfxFillRect(r.left + 1, mid - 2, r.right - 1, mid - 2, c1);
GfxFillRect(r.left + 1, mid - 1, r.right - 1, mid - 1, c2);
}
uint DropDownListStringItem::Width() const
@@ -37,9 +37,9 @@ uint DropDownListStringItem::Width() const
return GetStringBoundingBox(buffer).width;
}
void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
void DropDownListStringItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top, this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
}
/**
@@ -85,11 +85,11 @@ uint DropDownListIconItem::Width() const
return DropDownListStringItem::Width() + this->dim.width + WD_FRAMERECT_LEFT;
}
void DropDownListIconItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) 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 ? right - this->dim.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, CenterBounds(top, bottom, this->sprite_y));
DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), CenterBounds(top, bottom, FONT_HEIGHT_NORMAL), this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
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);
}
void DropDownListIconItem::SetDimension(Dimension d)
@@ -219,9 +219,9 @@ struct DropdownWindow : Window {
{
if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_DM_ITEMS);
int y = _cursor.pos.y - this->top - nwi->pos_y - 2;
int width = nwi->current_x - 4;
const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect();
int y = _cursor.pos.y - this->top - r.top - 2;
int width = r.Width();
int pos = this->vscroll->GetPosition();
for (const auto &item : this->list) {
@@ -251,7 +251,7 @@ struct DropdownWindow : Window {
int y = r.top + 2;
int pos = this->vscroll->GetPosition();
for (const auto &item : this->list) {
int item_height = item->Height(r.right - r.left + 1);
int item_height = item->Height(r.Width());
/* Skip items that are scrolled up */
if (--pos >= 0) continue;
@@ -260,7 +260,7 @@ struct DropdownWindow : Window {
bool selected = (this->selected_index == item->result);
if (selected) GfxFillRect(r.left + 2, y, r.right - 1, y + item_height - 1, PC_BLACK);
item->Draw(r.left, r.right, y, y + item_height, selected, colour);
item->Draw({r.left, y, r.right, y + item_height - 1}, selected, colour);
if (item->masked) {
GfxFillRect(r.left + 1, y, r.right - 1, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
@@ -386,7 +386,7 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
int top = w->top + wi_rect.bottom + 1;
/* The preferred width equals the calling widget */
uint width = wi_rect.right - wi_rect.left + 1;
uint width = wi_rect.Width();
/* Longest item in the list, if auto_width is enabled */
uint max_item_width = 0;