Merge branch 'master' into jgrpp

# Conflicts:
#	src/cheat_gui.cpp
#	src/main_gui.cpp
#	src/network/network_gui.cpp
#	src/saveload/saveload.h
#	src/smallmap_gui.cpp
#	src/station_cmd.cpp
#	src/timetable_cmd.cpp
#	src/toolbar_gui.cpp
#	src/widget.cpp
#	src/widget_type.h
#	src/widgets/dropdown_type.h
This commit is contained in:
Jonathan G Rennison
2023-11-25 14:02:04 +00:00
100 changed files with 450 additions and 655 deletions

View File

@@ -915,6 +915,18 @@ int Window::SortButtonWidth()
return NWidgetScrollbar::GetVerticalDimension().width + 1;
}
bool _draw_widget_outlines;
void DrawOutline(const Window *, const NWidgetBase *wid)
{
if (!_draw_widget_outlines || wid->current_x == 0 || wid->current_y == 0) return;
Rect r = wid->GetCurrentRect();
GfxDrawLine(r.left, r.top, r.right, r.top, PC_WHITE, 1, 4);
GfxDrawLine(r.left, r.top, r.left, r.bottom, PC_WHITE, 1, 4);
GfxDrawLine(r.right, r.top, r.right, r.bottom, PC_WHITE, 1, 4);
GfxDrawLine(r.left, r.bottom, r.right, r.bottom, PC_WHITE, 1, 4);
}
/**
* @defgroup NestedWidgets Hierarchical widgets
@@ -1307,6 +1319,37 @@ void NWidgetContainer::FillNestedArray(NWidgetBase **array, uint length)
}
}
void NWidgetContainer::Draw(const Window *w)
{
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->Draw(w);
}
DrawOutline(w, this);
}
NWidgetCore *NWidgetContainer::GetWidgetFromPos(int x, int y)
{
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
if (nwid != nullptr) return nwid;
}
return nullptr;
}
void NWidgetContainer::FillDirtyWidgets(std::vector<NWidgetBase *> &dirty_widgets)
{
if (this->base_flags & WBF_DIRTY) {
dirty_widgets.push_back(this);
} else {
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->FillDirtyWidgets(dirty_widgets);
}
}
}
/**
* Widgets stacked on top of each other.
*/
@@ -1414,6 +1457,7 @@ void NWidgetStacked::Draw(const Window *w)
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
if (plane == this->shown_plane) {
child_wid->Draw(w);
DrawOutline(w, this);
return;
}
}
@@ -1492,37 +1536,6 @@ void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
this->pip_post = ScaleGUITrad(this->uz_pip_post);
}
void NWidgetPIPContainer::Draw(const Window *w)
{
if (this->IsOutsideDrawArea()) return;
this->base_flags &= ~WBF_DIRTY;
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->Draw(w);
}
}
NWidgetCore *NWidgetPIPContainer::GetWidgetFromPos(int x, int y)
{
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
if (nwid != nullptr) return nwid;
}
return nullptr;
}
void NWidgetPIPContainer::FillDirtyWidgets(std::vector<NWidgetBase *> &dirty_widgets)
{
if (this->base_flags & WBF_DIRTY) {
dirty_widgets.push_back(this);
} else {
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->FillDirtyWidgets(dirty_widgets);
}
}
}
/** Horizontal container widget. */
NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
{
@@ -1889,9 +1902,16 @@ void NWidgetSpacer::FillNestedArray(NWidgetBase **, uint)
{
}
void NWidgetSpacer::Draw(const Window *)
void NWidgetSpacer::Draw(const Window *w)
{
/* Spacer widget is never visible. */
/* Spacer widget is never normally visible. */
if (_draw_widget_outlines && this->current_x != 0 && this->current_y != 0) {
/* Spacers indicate a potential design issue, so get extra highlighting. */
GfxFillRect(this->GetCurrentRect(), PC_WHITE, FILLRECT_CHECKER);
DrawOutline(w, this);
}
}
void NWidgetSpacer::SetDirty(Window *w)
@@ -2085,39 +2105,44 @@ void NWidgetMatrix::FillDirtyWidgets(std::vector<NWidgetBase *> &dirty_widgets)
bool rtl = _current_text_dir == TD_RTL;
DrawPixelInfo tmp_dpi;
if (!FillDrawPixelInfo(&tmp_dpi, this->pos_x + (rtl ? this->pip_post : this->pip_pre), this->pos_y + this->pip_pre, this->current_x - this->pip_pre - this->pip_post, this->current_y - this->pip_pre - this->pip_post)) return;
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
/* Get the appropriate offsets so we can draw the right widgets. */
NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
assert(child != nullptr);
int start_x, start_y, base_offs_x, base_offs_y;
this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
{
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
int offs_y = base_offs_y;
for (int y = start_y; y < start_y + this->widgets_y + 1; y++, offs_y += this->widget_h) {
/* Are we within bounds? */
if (offs_y + child->smallest_y <= 0) continue;
if (offs_y >= (int)this->current_y) break;
/* Get the appropriate offsets so we can draw the right widgets. */
NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
assert(child != nullptr);
int start_x, start_y, base_offs_x, base_offs_y;
this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
/* We've passed our amount of widgets. */
if (y * this->widgets_x >= this->count) break;
int offs_x = base_offs_x;
for (int x = start_x; x < start_x + this->widgets_x + 1; x++, offs_x += rtl ? -this->widget_w : this->widget_w) {
int offs_y = base_offs_y;
for (int y = start_y; y < start_y + this->widgets_y + 1; y++, offs_y += this->widget_h) {
/* Are we within bounds? */
if (offs_x + child->smallest_x <= 0) continue;
if (offs_x >= (int)this->current_x) continue;
if (offs_y + child->smallest_y <= 0) continue;
if (offs_y >= (int)this->current_y) break;
/* Do we have this many widgets? */
int sub_wid = y * this->widgets_x + x;
if (sub_wid >= this->count) break;
/* We've passed our amount of widgets. */
if (y * this->widgets_x >= this->count) break;
child->AssignSizePosition(ST_RESIZE, offs_x, offs_y, child->smallest_x, child->smallest_y, rtl);
child->SetLowered(this->clicked == sub_wid);
SB(child->index, 16, 16, sub_wid);
child->Draw(w);
int offs_x = base_offs_x;
for (int x = start_x; x < start_x + this->widgets_x + 1; x++, offs_x += rtl ? -this->widget_w : this->widget_w) {
/* Are we within bounds? */
if (offs_x + child->smallest_x <= 0) continue;
if (offs_x >= (int)this->current_x) continue;
/* Do we have this many widgets? */
int sub_wid = y * this->widgets_x + x;
if (sub_wid >= this->count) break;
child->AssignSizePosition(ST_RESIZE, offs_x, offs_y, child->smallest_x, child->smallest_y, rtl);
child->SetLowered(this->clicked == sub_wid);
SB(child->index, 16, 16, sub_wid);
child->Draw(w);
}
}
}
DrawOutline(w, this);
}
/**
@@ -2333,6 +2358,8 @@ void NWidgetBackground::Draw(const Window *w)
if (this->IsDisabled()) {
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
}
DrawOutline(w, this);
}
NWidgetCore *NWidgetBackground::GetWidgetFromPos(int x, int y)
@@ -2390,6 +2417,8 @@ void NWidgetViewport::Draw(const Window *w)
} else {
w->DrawViewport(this->disp_flags);
}
DrawOutline(w, this);
}
/**
@@ -2594,6 +2623,8 @@ void NWidgetScrollbar::Draw(const Window *w)
if (this->IsDisabled()) {
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
}
DrawOutline(w, this);
}
/* static */ void NWidgetScrollbar::InvalidateDimensionCache()
@@ -2949,6 +2980,10 @@ void NWidgetLeaf::Draw(const Window *w)
bool clicked = this->IsLowered();
switch (this->type) {
case WWT_EMPTY:
/* WWT_EMPTY used as a spacer indicates a potential design issue. */
if (this->index == -1 && _draw_widget_outlines) {
GfxFillRect(r, PC_BLACK, FILLRECT_CHECKER);
}
break;
case WWT_PUSHBTN:
@@ -3056,6 +3091,8 @@ void NWidgetLeaf::Draw(const Window *w)
if (this->IsDisabled()) {
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
}
DrawOutline(w, this);
}
/**