Skip to content

Commit

Permalink
Codechange: Replace mishmash of types with WidgetIndex.
Browse files Browse the repository at this point in the history
Indices were stored as int, but often passed around with int/uint/uint8 and casts.
  • Loading branch information
PeterN committed Mar 28, 2023
1 parent 60f043b commit 1cd9ddf
Show file tree
Hide file tree
Showing 75 changed files with 695 additions and 691 deletions.
8 changes: 4 additions & 4 deletions src/ai/ai_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct AIConfigWindow : public Window {
this->Window::Close();
}

void SetStringParameters(int widget) const override
void SetStringParameters(WidgetIndex widget) const override
{
switch (widget) {
case WID_AIC_NUMBER:
Expand All @@ -109,7 +109,7 @@ struct AIConfigWindow : public Window {
}
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_AIC_DECREASE:
Expand Down Expand Up @@ -144,7 +144,7 @@ struct AIConfigWindow : public Window {
return slot < max_slot;
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
switch (widget) {
case WID_AIC_LIST: {
Expand All @@ -169,7 +169,7 @@ struct AIConfigWindow : public Window {
}
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
if (this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot) == nullptr) return;
Expand Down
12 changes: 6 additions & 6 deletions src/airport_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct BuildAirToolbarWindow : Window {
}
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
switch (widget) {
case WID_AT_AIRPORT:
Expand Down Expand Up @@ -295,7 +295,7 @@ class BuildAirportWindow : public PickerWindowBase {
this->PickerWindowBase::Close();
}

void SetStringParameters(int widget) const override
void SetStringParameters(WidgetIndex widget) const override
{
switch (widget) {
case WID_AP_CLASS_DROPDOWN:
Expand All @@ -320,7 +320,7 @@ class BuildAirportWindow : public PickerWindowBase {
}
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_AP_CLASS_DROPDOWN: {
Expand Down Expand Up @@ -384,7 +384,7 @@ class BuildAirportWindow : public PickerWindowBase {
}
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
switch (widget) {
case WID_AP_AIRPORT_LIST: {
Expand Down Expand Up @@ -495,7 +495,7 @@ class BuildAirportWindow : public PickerWindowBase {
}
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
switch (widget) {
case WID_AP_CLASS_DROPDOWN:
Expand Down Expand Up @@ -569,7 +569,7 @@ class BuildAirportWindow : public PickerWindowBase {
this->SelectOtherAirport(-1);
}

void OnDropdownSelect(int widget, int index) override
void OnDropdownSelect(WidgetIndex widget, int index) override
{
assert(widget == WID_AP_CLASS_DROPDOWN);
_selected_airport_class = (AirportClassID)index;
Expand Down
12 changes: 6 additions & 6 deletions src/autoreplace_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class ReplaceVehicleWindow : public Window {
this->sel_group = id_g;
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING: {
Expand Down Expand Up @@ -394,7 +394,7 @@ class ReplaceVehicleWindow : public Window {
}
}

void SetStringParameters(int widget) const override
void SetStringParameters(WidgetIndex widget) const override
{
switch (widget) {
case WID_RV_CAPTION:
Expand Down Expand Up @@ -441,7 +441,7 @@ class ReplaceVehicleWindow : public Window {
}
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING:
Expand Down Expand Up @@ -539,7 +539,7 @@ class ReplaceVehicleWindow : public Window {
}
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING:
Expand Down Expand Up @@ -658,7 +658,7 @@ class ReplaceVehicleWindow : public Window {
}
}

void OnDropdownSelect(int widget, int index) override
void OnDropdownSelect(WidgetIndex widget, int index) override
{
switch (widget) {
case WID_RV_SORT_DROPDOWN:
Expand Down Expand Up @@ -713,7 +713,7 @@ class ReplaceVehicleWindow : public Window {
}
}

bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
bool OnTooltip(Point pt, WidgetIndex widget, TooltipCloseCondition close_cond) override
{
if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false;

Expand Down
14 changes: 7 additions & 7 deletions src/bootstrap_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BootstrapBackground : public Window {
ResizeWindow(this, _screen.width, _screen.height);
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
GfxFillRect(r.left, r.top, r.right, r.bottom, 4, FILLRECT_OPAQUE);
GfxFillRect(r.left, r.top, r.right, r.bottom, 0, FILLRECT_CHECKER);
Expand Down Expand Up @@ -97,22 +97,22 @@ class BootstrapErrorWindow : public Window {
this->Window::Close();
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget == WID_BEM_MESSAGE) {
*size = GetStringBoundingBox(STR_MISSING_GRAPHICS_ERROR);
size->height = GetStringHeight(STR_MISSING_GRAPHICS_ERROR, size->width - WidgetDimensions::scaled.frametext.Horizontal()) + WidgetDimensions::scaled.frametext.Vertical();
}
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
if (widget == WID_BEM_MESSAGE) {
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_ERROR, TC_FROMSTRING, SA_CENTER);
}
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
if (widget == WID_BEM_QUIT) {
_exit_game = true;
Expand Down Expand Up @@ -212,7 +212,7 @@ class BootstrapAskForDownloadWindow : public Window, ContentCallback {
this->Window::Close();
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
/* We cache the button size. This is safe as no reinit can happen here. */
if (this->button_size.width == 0) {
Expand All @@ -235,14 +235,14 @@ class BootstrapAskForDownloadWindow : public Window, ContentCallback {
}
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
if (widget != 0) return;

DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_SET_MESSAGE, TC_FROMSTRING, SA_CENTER);
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
switch (widget) {
case WID_BAFD_YES:
Expand Down
8 changes: 4 additions & 4 deletions src/bridge_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class BuildBridgeWindow : public Window {
delete bridges;
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BBS_DROPDOWN_ORDER: {
Expand Down Expand Up @@ -226,7 +226,7 @@ class BuildBridgeWindow : public Window {
return corner;
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
switch (widget) {
case WID_BBS_DROPDOWN_ORDER:
Expand Down Expand Up @@ -259,7 +259,7 @@ class BuildBridgeWindow : public Window {
return ES_NOT_HANDLED;
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
switch (widget) {
default: break;
Expand All @@ -283,7 +283,7 @@ class BuildBridgeWindow : public Window {
}
}

void OnDropdownSelect(int widget, int index) override
void OnDropdownSelect(WidgetIndex widget, int index) override
{
if (widget == WID_BBS_DROPDOWN_CRITERIA && this->bridges->SortType() != index) {
this->bridges->SetSortType(index);
Expand Down
10 changes: 5 additions & 5 deletions src/build_vehicle_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ struct BuildVehicleWindow : Window {
this->eng_list.RebuildDone();
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
switch (widget) {
case WID_BV_SORT_ASCENDING_DESCENDING:
Expand Down Expand Up @@ -1626,7 +1626,7 @@ struct BuildVehicleWindow : Window {
this->eng_list.ForceRebuild();
}

void SetStringParameters(int widget) const override
void SetStringParameters(WidgetIndex widget) const override
{
switch (widget) {
case WID_BV_CAPTION:
Expand Down Expand Up @@ -1661,7 +1661,7 @@ struct BuildVehicleWindow : Window {
}
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BV_LIST:
Expand Down Expand Up @@ -1698,7 +1698,7 @@ struct BuildVehicleWindow : Window {
}
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
switch (widget) {
case WID_BV_LIST:
Expand Down Expand Up @@ -1756,7 +1756,7 @@ struct BuildVehicleWindow : Window {
Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, str);
}

void OnDropdownSelect(int widget, int index) override
void OnDropdownSelect(WidgetIndex widget, int index) override
{
switch (widget) {
case WID_BV_SORT_DROPDOWN:
Expand Down
6 changes: 3 additions & 3 deletions src/cheat_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct CheatWindow : Window {
this->icon = GetSpriteSize(SPR_COMPANY_ICON);
}

void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetIndex widget) const override
{
if (widget != WID_C_PANEL) return;

Expand Down Expand Up @@ -297,7 +297,7 @@ struct CheatWindow : Window {
}
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
void UpdateWidgetSize(WidgetIndex widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_C_PANEL) return;

Expand Down Expand Up @@ -343,7 +343,7 @@ struct CheatWindow : Window {
size->height = WidgetDimensions::scaled.framerect.Vertical() + this->line_height * lengthof(_cheats_ui);
}

void OnClick(Point pt, int widget, int click_count) override
void OnClick(Point pt, WidgetIndex widget, int click_count) override
{
Rect r = this->GetWidget<NWidgetBase>(WID_C_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
uint btn = (pt.y - r.top) / this->line_height;
Expand Down

0 comments on commit 1cd9ddf

Please sign in to comment.