mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Pass rect to DrawStationCoverageAreaText. (#13442)
This moves the overflow behaviour to the callers, making it clearer why that is desired.pull/13448/head
parent
5ffaf6cdb9
commit
fb55ab0742
|
@ -422,7 +422,8 @@ public:
|
|||
this->DrawWidgets();
|
||||
|
||||
Rect r = this->GetWidget<NWidgetBase>(WID_AP_ACCEPTANCE)->GetCurrentRect();
|
||||
int top = r.top;
|
||||
const int bottom = r.bottom;
|
||||
r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
|
||||
|
||||
if (_selected_airport_index != -1) {
|
||||
const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
|
||||
|
@ -432,27 +433,27 @@ public:
|
|||
if (_settings_game.economy.station_noise_level) {
|
||||
/* show the noise of the selected airport */
|
||||
SetDParam(0, as->noise_level);
|
||||
DrawString(r.left, r.right, top, STR_STATION_BUILD_NOISE);
|
||||
top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
|
||||
DrawString(r, STR_STATION_BUILD_NOISE);
|
||||
r.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
|
||||
}
|
||||
|
||||
if (_settings_game.economy.infrastructure_maintenance) {
|
||||
Money monthly = _price[PR_INFRASTRUCTURE_AIRPORT] * as->maintenance_cost >> 3;
|
||||
SetDParam(0, monthly * 12);
|
||||
DrawString(r.left, r.right, top, TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_BUILD_INFRASTRUCTURE_COST_PERIOD : STR_STATION_BUILD_INFRASTRUCTURE_COST_YEAR);
|
||||
top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
|
||||
DrawString(r, TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_BUILD_INFRASTRUCTURE_COST_PERIOD : STR_STATION_BUILD_INFRASTRUCTURE_COST_YEAR);
|
||||
r.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
|
||||
}
|
||||
|
||||
/* strings such as 'Size' and 'Coverage Area' */
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, true);
|
||||
r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
|
||||
}
|
||||
|
||||
/* Resize background if the window is too small.
|
||||
* Never make the window smaller to avoid oscillating if the size change affects the acceptance.
|
||||
* (This is the case, if making the window bigger moves the mouse into the window.) */
|
||||
if (top > r.bottom) {
|
||||
ResizeWindow(this, 0, top - r.bottom, false);
|
||||
if (r.top > bottom) {
|
||||
ResizeWindow(this, 0, r.top - bottom, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -442,14 +442,15 @@ public:
|
|||
|
||||
/* strings such as 'Size' and 'Coverage Area' */
|
||||
Rect r = this->GetWidget<NWidgetBase>(BDSW_ACCEPTANCE)->GetCurrentRect();
|
||||
int top = r.top;
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, true);
|
||||
const int bottom = r.bottom;
|
||||
r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
|
||||
r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
|
||||
/* Resize background if the window is too small.
|
||||
* Never make the window smaller to avoid oscillating if the size change affects the acceptance.
|
||||
* (This is the case, if making the window bigger moves the mouse into the window.) */
|
||||
if (top > r.bottom) {
|
||||
ResizeWindow(this, 0, top - r.bottom, false);
|
||||
if (r.top > bottom) {
|
||||
ResizeWindow(this, 0, r.top - bottom, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1150,14 +1150,15 @@ public:
|
|||
if (this->IsShaded()) return;
|
||||
/* 'Accepts' and 'Supplies' texts. */
|
||||
Rect r = this->GetWidget<NWidgetBase>(WID_BRAS_COVERAGE_TEXTS)->GetCurrentRect();
|
||||
int top = r.top;
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, true);
|
||||
const int bottom = r.bottom;
|
||||
r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
|
||||
r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
|
||||
/* Resize background if the window is too small.
|
||||
* Never make the window smaller to avoid oscillating if the size change affects the acceptance.
|
||||
* (This is the case, if making the window bigger moves the mouse into the window.) */
|
||||
if (top > r.bottom) {
|
||||
this->coverage_height += top - r.bottom;
|
||||
if (r.top > bottom) {
|
||||
this->coverage_height += r.top - bottom;
|
||||
this->ReInit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1361,14 +1361,15 @@ public:
|
|||
/* 'Accepts' and 'Supplies' texts. */
|
||||
StationCoverageType sct = (this->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY;
|
||||
Rect r = this->GetWidget<NWidgetBase>(WID_BROS_ACCEPTANCE)->GetCurrentRect();
|
||||
int top = r.top;
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, sct, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
top = DrawStationCoverageAreaText(r.left, r.right, top, sct, rad, true);
|
||||
const int bottom = r.bottom;
|
||||
r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
|
||||
r.top = DrawStationCoverageAreaText(r, sct, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
||||
r.top = DrawStationCoverageAreaText(r, sct, rad, true);
|
||||
/* Resize background if the window is too small.
|
||||
* Never make the window smaller to avoid oscillating if the size change affects the acceptance.
|
||||
* (This is the case, if making the window bigger moves the mouse into the window.) */
|
||||
if (top > r.bottom) {
|
||||
this->coverage_height += top - r.bottom;
|
||||
if (r.top > bottom) {
|
||||
this->coverage_height += r.top - bottom;
|
||||
this->ReInit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,15 +66,13 @@ using RoadWaypointTypeFilter = GenericWaypointTypeFilter<true, MP_ROAD>;
|
|||
|
||||
/**
|
||||
* Calculates and draws the accepted or supplied cargo around the selected tile(s)
|
||||
* @param left x position where the string is to be drawn
|
||||
* @param right the right most position to draw on
|
||||
* @param top y position where the string is to be drawn
|
||||
* @param r Rect where the string is to be drawn.
|
||||
* @param sct which type of cargo is to be displayed (passengers/non-passengers)
|
||||
* @param rad radius around selected tile(s) to be searched
|
||||
* @param supplies if supplied cargoes should be drawn, else accepted cargoes
|
||||
* @return Returns the y value below the string that was drawn
|
||||
*/
|
||||
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
|
||||
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
|
||||
{
|
||||
TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
|
||||
CargoTypes cargo_mask = 0;
|
||||
|
@ -98,7 +96,7 @@ int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageTyp
|
|||
}
|
||||
}
|
||||
SetDParam(0, cargo_mask);
|
||||
return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
|
||||
return DrawStringMultiLine(r, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef STATION_GUI_H
|
||||
#define STATION_GUI_H
|
||||
|
||||
#include "core/geometry_type.hpp"
|
||||
#include "command_type.h"
|
||||
#include "tilearea_type.h"
|
||||
#include "window_type.h"
|
||||
|
@ -23,7 +24,7 @@ enum StationCoverageType : uint8_t {
|
|||
SCT_ALL, ///< Draw all cargoes.
|
||||
};
|
||||
|
||||
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies);
|
||||
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies);
|
||||
void CheckRedrawStationCoverage(const Window *w);
|
||||
void CheckRedrawRailWaypointCoverage(const Window *w);
|
||||
void CheckRedrawRoadWaypointCoverage(const Window *w);
|
||||
|
|
Loading…
Reference in New Issue