mirror of https://github.com/OpenTTD/OpenTTD.git
Cleanup: Remove unnecessary parameter of GetScrolledRowFromWidget()
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.
This commit is contained in:
parent
96b78bc2cd
commit
2a0365b3d9
|
@ -190,7 +190,7 @@ struct AIListWindow : public Window {
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_AIL_LIST: { // Select one of the AIs
|
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()) {
|
if (sel < (int)this->info_list->size()) {
|
||||||
this->selected = sel;
|
this->selected = sel;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
@ -784,6 +784,7 @@ struct AIConfigWindow : public Window {
|
||||||
|
|
||||||
case WID_AIC_LIST:
|
case WID_AIC_LIST:
|
||||||
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
||||||
|
resize->height = this->line_height;
|
||||||
size->height = 8 * this->line_height;
|
size->height = 8 * this->line_height;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -895,7 +896,7 @@ struct AIConfigWindow : public Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_AIC_LIST: { // Select a slot
|
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();
|
this->InvalidateData();
|
||||||
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
|
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -956,7 +956,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_SCL_MATRIX: {
|
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 (row >= this->rows) return;
|
||||||
|
|
||||||
if (this->livery_class < LC_GROUP_RAIL) {
|
if (this->livery_class < LC_GROUP_RAIL) {
|
||||||
|
|
|
@ -683,7 +683,7 @@ struct FramerateWindow : Window {
|
||||||
case WID_FRW_TIMES_AVERAGE: {
|
case WID_FRW_TIMES_AVERAGE: {
|
||||||
/* Open time graph windows when clicking detail measurement lines */
|
/* Open time graph windows when clicking detail measurement lines */
|
||||||
const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
|
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) {
|
if (line != INT_MAX) {
|
||||||
line++;
|
line++;
|
||||||
/* Find the visible line that was clicked */
|
/* Find the visible line that was clicked */
|
||||||
|
|
|
@ -992,7 +992,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_CPR_MATRIX: {
|
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;
|
if (row >= this->vscroll->GetCount()) return;
|
||||||
|
|
||||||
const CargoSpec *cs;
|
const CargoSpec *cs;
|
||||||
|
|
|
@ -676,7 +676,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GL_LIST_GROUP: { // Matrix Group
|
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 (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])) {
|
if (groups[id_g]->folded || (id_g + 1 < this->groups.size() && this->indents[id_g + 1] > this->indents[id_g])) {
|
||||||
|
@ -822,7 +822,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GL_LIST_GROUP: { // Matrix group
|
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;
|
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) {
|
if (this->group_sel != new_g && g->parent != new_g) {
|
||||||
|
@ -855,7 +855,7 @@ public:
|
||||||
this->group_over = INVALID_GROUP;
|
this->group_over = INVALID_GROUP;
|
||||||
this->SetDirty();
|
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;
|
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);
|
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);
|
||||||
|
@ -996,7 +996,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GL_LIST_GROUP: { // ... the list of custom groups.
|
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;
|
new_group_over = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1205,7 +1205,7 @@ struct MessageHistoryWindow : Window {
|
||||||
NewsItem *ni = _latest_news;
|
NewsItem *ni = _latest_news;
|
||||||
if (ni == nullptr) return;
|
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;
|
ni = ni->prev;
|
||||||
if (ni == nullptr) return;
|
if (ni == nullptr) return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1464,7 +1464,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_BRAS_NEWST_LIST: {
|
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;
|
if (y >= (int)this->station_classes.size()) return;
|
||||||
StationClassID station_class_id = this->station_classes[y];
|
StationClassID station_class_id = this->station_classes[y];
|
||||||
if (_railstation.station_class != station_class_id) {
|
if (_railstation.station_class != station_class_id) {
|
||||||
|
|
|
@ -529,7 +529,7 @@ public:
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_STL_LIST: {
|
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
|
if (id_v >= this->stations.size()) return; // click out of list bound
|
||||||
|
|
||||||
const Station *st = this->stations[id_v];
|
const Station *st = this->stations[id_v];
|
||||||
|
@ -1906,7 +1906,7 @@ struct StationViewWindow : public Window {
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_SV_WAITING:
|
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;
|
break;
|
||||||
|
|
||||||
case WID_SV_CATCHMENT:
|
case WID_SV_CATCHMENT:
|
||||||
|
|
|
@ -1964,12 +1964,11 @@ void NWidgetViewport::UpdateViewportCoordinates(Window *w)
|
||||||
* @param w The window the click was in.
|
* @param w The window the click was in.
|
||||||
* @param widget Widget number of the widget clicked 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 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.
|
* @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();
|
if (pos != INT_MAX) pos += this->GetPosition();
|
||||||
return (pos >= this->GetCount()) ? INT_MAX : pos;
|
return (pos >= this->GetCount()) ? INT_MAX : pos;
|
||||||
}
|
}
|
||||||
|
|
|
@ -748,7 +748,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
EventState UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue