summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-07-22 16:13:42 +0000
committerpeter1138 <peter1138@openttd.org>2008-07-22 16:13:42 +0000
commit49769dffba7f54dcc392550f78650fb6eb016ba7 (patch)
treeac53d29fff555f0d12825f3db5bf9c97ea31c9f4
parent1f0939f4e2cd44a7321c1dcc61b93e14ff1d5d71 (diff)
downloadopenttd-49769dffba7f54dcc392550f78650fb6eb016ba7.tar.xz
(svn r13784) -Codechange: Truncate vehicle names in purchase list to width of window.
-rw-r--r--src/autoreplace_gui.cpp4
-rw-r--r--src/build_vehicle_gui.cpp8
2 files changed, 7 insertions, 5 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index 7dd69d3cc..964ded850 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -27,7 +27,7 @@
#include "table/sprites.h"
#include "table/strings.h"
-void DrawEngineList(VehicleType type, int x, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group);
+void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group);
static const StringID _rail_types_list[] = {
STR_RAIL_VEHICLES,
@@ -384,7 +384,7 @@ public:
EngineID end = min((i == 0 ? this->vscroll.cap : this->vscroll2.cap) + start, list->Length());
/* Do the actual drawing */
- DrawEngineList((VehicleType)this->window_number, this->widget[widget].left + 2, this->widget[widget].top + 1, list, start, end, this->sel_engine[i], i == 0 ? this->widget[RVW_WIDGET_LEFT_MATRIX].right - 2 : 0, selected_group);
+ DrawEngineList((VehicleType)this->window_number, this->widget[widget].left + 2, this->widget[widget].right, this->widget[widget].top + 1, list, start, end, this->sel_engine[i], i == 0 ? this->widget[RVW_WIDGET_LEFT_MATRIX].right - 2 : 0, selected_group);
/* Also draw the details if an engine is selected */
if (this->sel_engine[i] != INVALID_ENGINE) {
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index cfc67df61..39c58d415 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -736,7 +736,7 @@ static void DrawVehicleEngine(VehicleType type, int x, int y, EngineID engine, S
* @param selected_id what engine to highlight as selected, if any
* @param count_location Offset to print the engine count (used by autoreplace). 0 means it's off
*/
-void DrawEngineList(VehicleType type, int x, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
+void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
{
byte step_size = GetVehicleListHeight(type);
byte x_offset = 0;
@@ -769,13 +769,15 @@ void DrawEngineList(VehicleType type, int x, int y, const GUIEngineList *eng_lis
default: NOT_REACHED();
}
+ uint maxw = r - x - x_offset;
+
for (; min < max; min++, y += step_size) {
const EngineID engine = (*eng_list)[min];
/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */
const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine);
SetDParam(0, engine);
- DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
+ DrawStringTruncated(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK, maxw);
DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
if (count_location != 0) {
SetDParam(0, num_engines);
@@ -1118,7 +1120,7 @@ struct BuildVehicleWindow : Window {
this->DrawWidgets();
- DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, &this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP);
+ DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].right, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, &this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP);
if (this->sel_engine != INVALID_ENGINE) {
const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL];