Skip to content

Commit

Permalink
Cleanup: Remove unnecessary parameter of GetScrolledRowFromWidget()
Browse files Browse the repository at this point in the history
Line height defaults to the resize height of the relevant widget, which is
set in all cases. Therefore it is not necessary to specify this value every time.

Additionally fixes scrolled padding for the framerate window.
  • Loading branch information
PeterN authored and michicc committed Apr 21, 2021
1 parent 96b78bc commit 2a0365b
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/ai/ai_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ struct AIListWindow : public Window {
{
switch (widget) {
case WID_AIL_LIST: { // Select one of the AIs
int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_AIL_LIST, 0, this->line_height) - 1;
int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_AIL_LIST) - 1;
if (sel < (int)this->info_list->size()) {
this->selected = sel;
this->SetDirty();
Expand Down Expand Up @@ -784,6 +784,7 @@ struct AIConfigWindow : public Window {

case WID_AIC_LIST:
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
resize->height = this->line_height;
size->height = 8 * this->line_height;
break;

Expand Down Expand Up @@ -895,7 +896,7 @@ struct AIConfigWindow : public Window {
}

case WID_AIC_LIST: { // Select a slot
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
this->InvalidateData();
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/company_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ struct SelectCompanyLiveryWindow : public Window {
break;

case WID_SCL_MATRIX: {
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCL_MATRIX, 0, this->line_height);
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCL_MATRIX);
if (row >= this->rows) return;

if (this->livery_class < LC_GROUP_RAIL) {
Expand Down
2 changes: 1 addition & 1 deletion src/framerate_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ struct FramerateWindow : Window {
case WID_FRW_TIMES_AVERAGE: {
/* Open time graph windows when clicking detail measurement lines */
const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
int line = sb->GetScrolledRowFromWidget(pt.y - FONT_HEIGHT_NORMAL - VSPACING, this, widget, VSPACING, FONT_HEIGHT_NORMAL);
int line = sb->GetScrolledRowFromWidget(pt.y, this, widget, VSPACING + FONT_HEIGHT_NORMAL);
if (line != INT_MAX) {
line++;
/* Find the visible line that was clicked */
Expand Down
2 changes: 1 addition & 1 deletion src/graph_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
}

case WID_CPR_MATRIX: {
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX, 0, this->line_height);
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX);
if (row >= this->vscroll->GetCount()) return;

const CargoSpec *cs;
Expand Down
8 changes: 4 additions & 4 deletions src/group_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
break;

case WID_GL_LIST_GROUP: { // Matrix Group
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP);
if (id_g >= this->groups.size()) return;

if (groups[id_g]->folded || (id_g + 1 < this->groups.size() && this->indents[id_g + 1] > this->indents[id_g])) {
Expand Down Expand Up @@ -822,7 +822,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
break;

case WID_GL_LIST_GROUP: { // Matrix group
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP);
GroupID new_g = id_g >= this->groups.size() ? INVALID_GROUP : this->groups[id_g]->index;

if (this->group_sel != new_g && g->parent != new_g) {
Expand Down Expand Up @@ -855,7 +855,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
this->group_over = INVALID_GROUP;
this->SetDirty();

uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP);
GroupID new_g = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;

DoCommandP(0, new_g, vindex | (_ctrl_pressed || this->grouping == GB_SHARED_ORDERS ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE), new_g == NEW_GROUP ? CcAddVehicleNewGroup : nullptr);
Expand Down Expand Up @@ -996,7 +996,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
break;

case WID_GL_LIST_GROUP: { // ... the list of custom groups.
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP);
new_group_over = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/news_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ struct MessageHistoryWindow : Window {
NewsItem *ni = _latest_news;
if (ni == nullptr) return;

for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_MH_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_MH_BACKGROUND, WD_FRAMERECT_TOP); n > 0; n--) {
ni = ni->prev;
if (ni == nullptr) return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rail_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ struct BuildRailStationWindow : public PickerWindowBase {
break;

case WID_BRAS_NEWST_LIST: {
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BRAS_NEWST_LIST, 0, this->line_height);
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BRAS_NEWST_LIST);
if (y >= (int)this->station_classes.size()) return;
StationClassID station_class_id = this->station_classes[y];
if (_railstation.station_class != station_class_id) {
Expand Down
4 changes: 2 additions & 2 deletions src/station_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class CompanyStationsWindow : public Window
{
switch (widget) {
case WID_STL_LIST: {
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_STL_LIST, 0, FONT_HEIGHT_NORMAL);
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_STL_LIST);
if (id_v >= this->stations.size()) return; // click out of list bound

const Station *st = this->stations[id_v];
Expand Down Expand Up @@ -1906,7 +1906,7 @@ struct StationViewWindow : public Window {
{
switch (widget) {
case WID_SV_WAITING:
this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL) - this->vscroll->GetPosition());
this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WD_FRAMERECT_TOP) - this->vscroll->GetPosition());
break;

case WID_SV_CATCHMENT:
Expand Down
5 changes: 2 additions & 3 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1964,12 +1964,11 @@ void NWidgetViewport::UpdateViewportCoordinates(Window *w)
* @param w The window the click was in.
* @param widget Widget number of the widget clicked in.
* @param padding Amount of empty space between the widget edge and the top of the first row. Default value is \c 0.
* @param line_height Height of a single row. A negative value means using the vertical resize step of the widget.
* @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.
*/
int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding, int line_height) const
int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding) const
{
uint pos = w->GetRowFromWidget(clickpos, widget, padding, line_height);
uint pos = w->GetRowFromWidget(clickpos, widget, padding, -1);
if (pos != INT_MAX) pos += this->GetPosition();
return (pos >= this->GetCount()) ? INT_MAX : pos;
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ class Scrollbar {
}
}

int GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding = 0, int line_height = -1) const;
int GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding = 0) const;
EventState UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const;
};

Expand Down

0 comments on commit 2a0365b

Please sign in to comment.