summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-05-28 17:29:27 +0000
committerpeter1138 <peter1138@openttd.org>2008-05-28 17:29:27 +0000
commitf954a93ee00ec9f7c69afc306e8346d80ccbb432 (patch)
tree08d42b0dc303e2f3691a402d44db0a3dcdb9d86a
parentf44a2c38f8887a2f9d6d3e6111d7d00537033274 (diff)
downloadopenttd-f954a93ee00ec9f7c69afc306e8346d80ccbb432.tar.xz
(svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
-rw-r--r--src/autoreplace_gui.cpp26
-rw-r--r--src/build_vehicle_gui.cpp31
-rw-r--r--src/engine_gui.cpp14
-rw-r--r--src/engine_gui.h8
4 files changed, 40 insertions, 39 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index 101f61427..c2c98ebd7 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 EngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group);
+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);
static const StringID _rail_types_list[] = {
STR_RAIL_VEHICLES,
@@ -143,7 +143,7 @@ class ReplaceVehicleWindow : public Window {
EngineID sel_engine[2];
uint16 count[2];
bool wagon_btnstate; ///< true means engine is selected
- EngineList list[2];
+ GUIEngineList list[2];
bool update_left;
bool update_right;
bool init_lists;
@@ -185,8 +185,8 @@ class ReplaceVehicleWindow : public Window {
VehicleType type = (VehicleType)this->window_number;
byte i = draw_left ? 0 : 1;
- EngineList *list = &this->list[i];
- list->clear();
+ GUIEngineList *list = &this->list[i];
+ list->Clear();
const Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, type) {
@@ -209,7 +209,7 @@ class ReplaceVehicleWindow : public Window {
if (eid == this->sel_engine[0]) continue; // we can't replace an engine into itself (that would be autorenew)
}
- list->push_back(eid);
+ *list->Append() = eid;
if (eid == this->sel_engine[i]) selected_engine = eid; // The selected engine is still in the list
}
this->sel_engine[i] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
@@ -224,8 +224,8 @@ class ReplaceVehicleWindow : public Window {
if (this->update_left == true) {
/* We need to rebuild the left list */
GenerateReplaceVehList(this, true);
- SetVScrollCount(this, this->list[0].size());
- if (this->init_lists && this->sel_engine[0] == INVALID_ENGINE && this->list[0].size() != 0) {
+ SetVScrollCount(this, this->list[0].Length());
+ if (this->init_lists && this->sel_engine[0] == INVALID_ENGINE && this->list[0].Length() != 0) {
this->sel_engine[0] = this->list[0][0];
}
}
@@ -234,12 +234,12 @@ class ReplaceVehicleWindow : public Window {
/* Either we got a request to rebuild the right list or the left list selected a different engine */
if (this->sel_engine[0] == INVALID_ENGINE) {
/* Always empty the right list when nothing is selected in the left list */
- this->list[1].clear();
+ this->list[1].Clear();
this->sel_engine[1] = INVALID_ENGINE;
} else {
GenerateReplaceVehList(this, false);
- SetVScroll2Count(this, this->list[1].size());
- if (this->init_lists && this->sel_engine[1] == INVALID_ENGINE && this->list[1].size() != 0) {
+ SetVScroll2Count(this, this->list[1].Length());
+ if (this->init_lists && this->sel_engine[1] == INVALID_ENGINE && this->list[1].Length() != 0) {
this->sel_engine[1] = this->list[1][0];
}
}
@@ -379,9 +379,9 @@ public:
/* Draw the lists */
for (byte i = 0; i < 2; i++) {
uint widget = (i == 0) ? RVW_WIDGET_LEFT_MATRIX : RVW_WIDGET_RIGHT_MATRIX;
- EngineList *list = &this->list[i]; // which list to draw
+ GUIEngineList *list = &this->list[i]; // which list to draw
EngineID start = i == 0 ? this->vscroll.pos : this->vscroll2.pos; // what is the offset for the start (scrolling)
- EngineID end = min((i == 0 ? this->vscroll.cap : this->vscroll2.cap) + start, list->size());
+ 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);
@@ -435,7 +435,7 @@ public:
uint16 click_scroll_pos = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.pos : this->vscroll2.pos;
uint16 click_scroll_cap = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.cap : this->vscroll2.cap;
byte click_side = widget == RVW_WIDGET_LEFT_MATRIX ? 0 : 1;
- size_t engine_count = this->list[click_side].size();
+ size_t engine_count = this->list[click_side].Length();
if (i < click_scroll_cap) {
i += click_scroll_pos;
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 8f453170f..6fd3f76f1 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -745,13 +745,13 @@ 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 EngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
+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)
{
byte step_size = GetVehicleListHeight(type);
byte x_offset = 0;
byte y_offset = 0;
- assert(max <= eng_list->size());
+ assert(max <= eng_list->Length());
switch (type) {
case VEH_TRAIN:
@@ -806,7 +806,7 @@ struct BuildVehicleWindow : Window {
bool regenerate_list;
EngineID sel_engine;
EngineID rename_engine;
- EngineList eng_list;
+ GUIEngineList eng_list;
BuildVehicleWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc, tile == 0 ? (int)type : tile)
{
@@ -848,7 +848,7 @@ struct BuildVehicleWindow : Window {
this->GenerateBuildList(); // generate the list, since we need it in the next line
/* Select the first engine in the list as default when opening the window */
- if (this->eng_list.size() > 0) this->sel_engine = this->eng_list[0];
+ if (this->eng_list.Length() > 0) this->sel_engine = this->eng_list[0];
this->FindWindowPlacementAndResize(desc);
}
@@ -906,7 +906,7 @@ struct BuildVehicleWindow : Window {
this->filter.railtype = (this->window_number <= VEH_END) ? RAILTYPE_END : GetRailType(this->window_number);
- this->eng_list.clear();
+ this->eng_list.Clear();
/* Make list of all available train engines and wagons.
* Also check to see if the previously selected engine is still available,
@@ -920,7 +920,8 @@ struct BuildVehicleWindow : Window {
if (this->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, this->filter.railtype)) continue;
if (!IsEngineBuildable(eid, VEH_TRAIN, _local_player)) continue;
- this->eng_list.push_back(eid);
+ *this->eng_list.Append() = eid;
+
if (rvi->railveh_type != RAILVEH_WAGON) {
num_engines++;
} else {
@@ -949,14 +950,14 @@ struct BuildVehicleWindow : Window {
{
EngineID sel_id = INVALID_ENGINE;
- this->eng_list.clear();
+ this->eng_list.Clear();
const Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
if (!HasBit(this->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
- this->eng_list.push_back(eid);
+ *this->eng_list.Append() = eid;
if (eid == this->sel_engine) sel_id = eid;
}
@@ -967,13 +968,13 @@ struct BuildVehicleWindow : Window {
void GenerateBuildShipList()
{
EngineID sel_id = INVALID_ENGINE;
- this->eng_list.clear();
+ this->eng_list.Clear();
const Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) {
EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_SHIP, _local_player)) continue;
- this->eng_list.push_back(eid);
+ *this->eng_list.Append() = eid;
if (eid == this->sel_engine) sel_id = eid;
}
@@ -985,7 +986,7 @@ struct BuildVehicleWindow : Window {
{
EngineID sel_id = INVALID_ENGINE;
- this->eng_list.clear();
+ this->eng_list.Clear();
/* Make list of all available planes.
* Also check to see if the previously selected plane is still available,
@@ -998,7 +999,7 @@ struct BuildVehicleWindow : Window {
/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
if (this->window_number > VEH_END && !CanAircraftUseStation(eid, this->window_number)) continue;
- this->eng_list.push_back(eid);
+ *this->eng_list.Append() = eid;
if (eid == this->sel_engine) sel_id = eid;
}
@@ -1039,7 +1040,7 @@ struct BuildVehicleWindow : Window {
case BUILD_VEHICLE_WIDGET_LIST: {
uint i = (pt.y - this->widget[BUILD_VEHICLE_WIDGET_LIST].top) / GetVehicleListHeight(this->vehicle_type) + this->vscroll.pos;
- size_t num_items = this->eng_list.size();
+ size_t num_items = this->eng_list.Length();
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
this->SetDirty();
break;
@@ -1105,11 +1106,11 @@ struct BuildVehicleWindow : Window {
this->GenerateBuildList();
}
- uint max = min(this->vscroll.pos + this->vscroll.cap, this->eng_list.size());
+ uint max = min(this->vscroll.pos + this->vscroll.cap, this->eng_list.Length());
this->SetWidgetDisabledState(BUILD_VEHICLE_WIDGET_BUILD, this->window_number <= VEH_END);
- SetVScrollCount(this, this->eng_list.size());
+ SetVScrollCount(this, this->eng_list.Length());
SetDParam(0, this->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
/* Set text of sort by dropdown */
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index bd48d778a..c9bd05650 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -197,13 +197,13 @@ void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
* @param el list to be sorted
* @param compare function for evaluation of the quicksort
*/
-void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare)
+void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
{
- size_t size = el->size();
+ uint size = el->Length();
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
* generally, do not sort if there are less than 2 items */
if (size < 2) return;
- qsort(&((*el)[0]), size, sizeof(EngineID), compare); // MorphOS doesn't know vector::at(int) ...
+ qsort(el->Begin(), size, sizeof(*el->Begin()), compare); // MorphOS doesn't know vector::at(int) ...
}
/** Sort selected range of items (on indices @ <begin, begin+num_items-1>)
@@ -212,11 +212,11 @@ void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare)
* @param begin start of sorting
* @param num_items count of items to be sorted
*/
-void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
+void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
{
- assert(begin <= (uint)el->size());
- assert(begin + num_items <= (uint)el->size());
+ assert(begin < el->Length());
+ assert(begin + num_items <= el->Length());
if (num_items < 2) return;
- qsort(&((*el)[begin]), num_items, sizeof(EngineID), compare);
+ qsort(el->Get(begin), num_items, sizeof(*el->Begin()), compare);
}
diff --git a/src/engine_gui.h b/src/engine_gui.h
index 12957da92..6f002600b 100644
--- a/src/engine_gui.h
+++ b/src/engine_gui.h
@@ -5,12 +5,12 @@
#ifndef ENGINE_GUI_H
#define ENGINE_GUI_H
-#include <vector>
+#include "sortlist_type.h"
-typedef std::vector<EngineID> EngineList;
+typedef GUIList<EngineID> GUIEngineList;
typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argument type for EngList_Sort()
-void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list
-void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list
+void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list
+void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list
#endif /* ENGINE_GUI_H */