mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use unified NWidgetContainer methods instead of duplicating.
Most NWidgetContainer derivatives implemented Draw() and GetWidgetFromPos() the same way. Move this these to NWidgetContainer itself to avoid repeating.pull/11387/head
parent
af41c5cb4e
commit
59a2abd298
|
@ -161,24 +161,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw(const Window *w) override
|
|
||||||
{
|
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
|
||||||
child_wid->Draw(w);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NWidgetCore *GetWidgetFromPos(int x, int y) override
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class NetworkGameWindow : public Window {
|
class NetworkGameWindow : public Window {
|
||||||
|
|
|
@ -1763,21 +1763,6 @@ public:
|
||||||
display->AssignSizePosition(ST_RESIZE, x, y, given_width, display_height, rtl);
|
display->AssignSizePosition(ST_RESIZE, x, y, given_width, display_height, rtl);
|
||||||
bar->AssignSizePosition(ST_RESIZE, x, y + display_height, given_width, bar_height, rtl);
|
bar->AssignSizePosition(ST_RESIZE, x, y + display_height, given_width, bar_height, rtl);
|
||||||
}
|
}
|
||||||
|
|
||||||
NWidgetCore *GetWidgetFromPos(int x, int y) override
|
|
||||||
{
|
|
||||||
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 *widget = child_wid->GetWidgetFromPos(x, y);
|
|
||||||
if (widget != nullptr) return widget;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Draw(const Window *w) override
|
|
||||||
{
|
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) child_wid->Draw(w);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Widget parts of the smallmap display. */
|
/** Widget parts of the smallmap display. */
|
||||||
|
|
|
@ -1477,21 +1477,7 @@ public:
|
||||||
GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_VERY_DARK_RED);
|
GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_VERY_DARK_RED);
|
||||||
GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_DARK_RED, FILLRECT_CHECKER);
|
GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_DARK_RED, FILLRECT_CHECKER);
|
||||||
|
|
||||||
bool rtl = _current_text_dir == TD_RTL;
|
this->NWidgetContainer::Draw(w);
|
||||||
for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
|
|
||||||
child_wid->Draw(w);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NWidgetCore *GetWidgetFromPos(int x, int y) override
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1303,6 +1303,24 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Widgets stacked on top of each other.
|
* Widgets stacked on top of each other.
|
||||||
*/
|
*/
|
||||||
|
@ -1465,24 +1483,6 @@ void NWidgetPIPContainer::SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip
|
||||||
this->pip_post = ScaleGUITrad(this->uz_pip_post);
|
this->pip_post = ScaleGUITrad(this->uz_pip_post);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NWidgetPIPContainer::Draw(const Window *w)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Horizontal container widget. */
|
/** Horizontal container widget. */
|
||||||
NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
|
NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
|
||||||
{
|
{
|
||||||
|
|
|
@ -412,6 +412,9 @@ public:
|
||||||
void Add(NWidgetBase *wid);
|
void Add(NWidgetBase *wid);
|
||||||
void FillNestedArray(NWidgetBase **array, uint length) override;
|
void FillNestedArray(NWidgetBase **array, uint length) override;
|
||||||
|
|
||||||
|
void Draw(const Window *w) override;
|
||||||
|
NWidgetCore *GetWidgetFromPos(int x, int y) override;
|
||||||
|
|
||||||
/** Return whether the container is empty. */
|
/** Return whether the container is empty. */
|
||||||
inline bool IsEmpty() { return head == nullptr; }
|
inline bool IsEmpty() { return head == nullptr; }
|
||||||
|
|
||||||
|
@ -480,9 +483,6 @@ public:
|
||||||
void AdjustPaddingForZoom() override;
|
void AdjustPaddingForZoom() override;
|
||||||
void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
|
void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
|
||||||
|
|
||||||
void Draw(const Window *w) override;
|
|
||||||
NWidgetCore *GetWidgetFromPos(int x, int y) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NWidContainerFlags flags; ///< Flags of the container.
|
NWidContainerFlags flags; ///< Flags of the container.
|
||||||
uint8_t pip_pre; ///< Amount of space before first widget.
|
uint8_t pip_pre; ///< Amount of space before first widget.
|
||||||
|
|
Loading…
Reference in New Issue