summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/airport_gui.cpp2
-rw-r--r--src/bridge_gui.cpp2
-rw-r--r--src/cheat_gui.cpp2
-rw-r--r--src/console.cpp2
-rw-r--r--src/dock_gui.cpp4
-rw-r--r--src/intro_gui.cpp2
-rw-r--r--src/main_gui.cpp2
-rw-r--r--src/misc_gui.cpp16
-rw-r--r--src/network/network_gui.cpp14
-rw-r--r--src/newgrf_gui.cpp4
-rw-r--r--src/news_gui.cpp10
-rw-r--r--src/osk_gui.cpp2
-rw-r--r--src/player_gui.cpp4
-rw-r--r--src/rail_gui.cpp10
-rw-r--r--src/road_gui.cpp4
-rw-r--r--src/settings_gui.cpp8
-rw-r--r--src/signs_gui.cpp2
-rw-r--r--src/statusbar_gui.cpp2
-rw-r--r--src/toolbar_gui.cpp6
-rw-r--r--src/widgets/dropdown.cpp2
-rw-r--r--src/window.cpp156
-rw-r--r--src/window_gui.h12
22 files changed, 124 insertions, 144 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index fb6b39df2..c504a2458 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -282,7 +282,7 @@ static const WindowDesc _build_airport_desc = {
static void ShowBuildAirportPicker()
{
- AllocateWindowDesc(&_build_airport_desc);
+ new Window(&_build_airport_desc);
}
void InitializeAirportGui()
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index f3d48b367..a5eb1efbc 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -184,7 +184,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
}
if (j != 0) {
- Window *w = AllocateWindowDesc(&_build_bridge_desc);
+ Window *w = new Window(&_build_bridge_desc);
/* Change the data, or the caption of the gui. Set it to road or rail, accordingly */
w->widget[BBSW_CAPTION].data = (transport_type == TRANSPORT_ROAD) ? STR_1803_SELECT_ROAD_BRIDGE : STR_100D_SELECT_RAIL_BRIDGE;
} else {
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index 65fdb889d..198d6ecc3 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -229,5 +229,5 @@ static const WindowDesc _cheats_desc = {
void ShowCheatWindow()
{
DeleteWindowById(WC_CHEATS, 0);
- AllocateWindowDesc(&_cheats_desc);
+ new Window(&_cheats_desc);
}
diff --git a/src/console.cpp b/src/console.cpp
index db2902690..5e80134a4 100644
--- a/src/console.cpp
+++ b/src/console.cpp
@@ -318,7 +318,7 @@ void IConsoleSwitch()
{
switch (_iconsole_mode) {
case ICONSOLE_CLOSED: {
- Window *w = AllocateWindowDesc(&_iconsole_window_desc);
+ Window *w = new Window(&_iconsole_window_desc);
w->height = _screen.height / 3;
w->width = _screen.width;
_iconsole_mode = ICONSOLE_OPENED;
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index 70530dcb5..b5fa85d5d 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -309,7 +309,7 @@ static const WindowDesc _build_dock_station_desc = {
static void ShowBuildDockStationPicker()
{
- AllocateWindowDesc(&_build_dock_station_desc);
+ new Window(&_build_dock_station_desc);
}
static void UpdateDocksDirection()
@@ -379,7 +379,7 @@ static const WindowDesc _build_docks_depot_desc = {
static void ShowBuildDocksDepotPicker()
{
- AllocateWindowDesc(&_build_docks_depot_desc);
+ new Window(&_build_docks_depot_desc);
UpdateDocksDirection();
}
diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp
index 4e702f937..da3887325 100644
--- a/src/intro_gui.cpp
+++ b/src/intro_gui.cpp
@@ -133,7 +133,7 @@ static const WindowDesc _select_game_desc = {
void ShowSelectGameWindow()
{
- AllocateWindowDesc(&_select_game_desc);
+ new Window(&_select_game_desc);
}
static void AskExitGameCallback(Window *w, bool confirmed)
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index c9927d8ff..ab81405ff 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -412,7 +412,7 @@ void SetupColorsAndInitialWindow()
int width = _screen.width;
int height = _screen.height;
- Window *w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
+ Window *w = new Window(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
InitializeWindowViewport(w, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
/* XXX: these are not done */
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 296c3ab6e..59dea3bd3 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -98,7 +98,7 @@ static void Place_LandInfo(TileIndex tile)
{
DeleteWindowById(WC_LAND_INFO, 0);
- Window *w = AllocateWindowDesc(&_land_info_desc);
+ Window *w = new Window(&_land_info_desc);
WP(w, void_d).data = &_landinfo_data;
Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
@@ -318,7 +318,7 @@ static const WindowDesc _about_desc = {
void ShowAboutWindow()
{
DeleteWindowById(WC_GAME_OPTIONS, 0);
- AllocateWindowDesc(&_about_desc);
+ new Window(&_about_desc);
}
static int _tree_to_plant;
@@ -615,7 +615,7 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
pt.x = (_screen.width - 240) >> 1;
pt.y = (_screen.height - 46) >> 1;
}
- w = AllocateWindow(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets);
+ w = new Window(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets);
} else {
if ((x | y) != 0) {
pt = RemapCoords2(x, y);
@@ -626,7 +626,7 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
pt.x = (_screen.width - 334) >> 1;
pt.y = (_screen.height - 137) >> 1;
}
- w = AllocateWindow(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets);
+ w = new Window(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets);
}
w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET;
@@ -753,7 +753,7 @@ void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[
if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
int x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
- Window *w = AllocateWindow(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets);
+ Window *w = new Window(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets);
WP(w, tooltips_d).string_id = str;
assert(sizeof(WP(w, tooltips_d).params[0]) == sizeof(params[0]));
@@ -1241,7 +1241,7 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth,
DeleteWindowById(WC_QUERY_STRING, 0);
DeleteWindowById(WC_SAVELOAD, 0);
- Window *w = AllocateWindowDesc(&_query_string_desc);
+ Window *w = new Window(&_query_string_desc);
w->parent = parent;
GetString(_edit_str_buf, str, lastof(_edit_str_buf));
@@ -1353,7 +1353,7 @@ static const WindowDesc _query_desc = {
* @param callback callback function pointer to set in the window descriptor*/
void ShowQuery(StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool))
{
- Window *w = AllocateWindowDesc(&_query_desc);
+ Window *w = new Window(&_query_desc);
if (w == NULL) return;
if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
@@ -1741,7 +1741,7 @@ void ShowSaveLoadDialog(SaveLoadDialogMode mode)
assert((uint)mode < lengthof(saveload_captions));
- Window *w = AllocateWindowDesc(sld);
+ Window *w = new Window(sld);
w->widget[1].data = saveload_captions[mode];
w->LowerWidget(7);
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 0629b5ede..670eff31b 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -675,7 +675,7 @@ void ShowNetworkGameWindow()
_ng_sorting.order = 0; // sort ascending by default
}
- Window *w = AllocateWindowDesc(&_network_game_window_desc);
+ Window *w = new Window(&_network_game_window_desc);
if (w != NULL) {
querystr_d *querystr = &WP(w, network_ql_d).q;
@@ -992,7 +992,7 @@ static void ShowNetworkStartServerWindow()
{
DeleteWindowById(WC_NETWORK_WINDOW, 0);
- Window *w = AllocateWindowDesc(&_network_start_server_window_desc);
+ Window *w = new Window(&_network_start_server_window_desc);
ttd_strlcpy(_edit_str_net_buf, _network_server_name, lengthof(_edit_str_net_buf));
_saveload_mode = SLD_NEW_GAME;
@@ -1228,7 +1228,7 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
- Window *w = AllocateWindowDesc(&_network_lobby_window_desc);
+ Window *w = new Window(&_network_lobby_window_desc);
if (w != NULL) {
WP(w, network_ql_d).n.server = ngl;
strcpy(_edit_str_net_buf, "");
@@ -1471,7 +1471,7 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
int h = ClientListPopupHeight();
/* Allocate the popup */
- w = AllocateWindow(x, y, 150, h + 1, ClientListPopupWndProc, WC_TOOLBAR_MENU, _client_list_popup_widgets);
+ w = new Window(x, y, 150, h + 1, ClientListPopupWndProc, WC_TOOLBAR_MENU, _client_list_popup_widgets);
w->widget[0].bottom = w->widget[0].top + h;
w->widget[0].right = w->widget[0].left + 150;
@@ -1708,7 +1708,7 @@ static const WindowDesc _network_join_status_window_desc = {
void ShowJoinStatusWindow()
{
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
- Window *w = AllocateWindowDesc(&_network_join_status_window_desc);
+ Window *w = new Window(&_network_join_status_window_desc);
/* Parent the status window to the lobby */
if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
}
@@ -1943,7 +1943,7 @@ void ShowNetworkChatQueryWindow(DestType type, int dest)
_edit_str_net_buf[0] = '\0';
_chat_tab_completion_active = false;
- Window *w = AllocateWindowDesc(&_chat_window_desc);
+ Window *w = new Window(&_chat_window_desc);
w->LowerWidget(2);
WP(w, chatquerystr_d).dtype = type;
@@ -2045,7 +2045,7 @@ void ShowNetworkCompanyPasswordWindow()
DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
_edit_str_net_buf[0] = '\0';
- Window *w = AllocateWindowDesc(&_ncp_window_desc);
+ Window *w = new Window(&_ncp_window_desc);
WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL;
InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_net_buf, min(lengthof(_network_default_company_pass), lengthof(_edit_str_net_buf)), 0);
}
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 2d7926cbd..dca4db5f1 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -408,7 +408,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
Window *w;
DeleteWindowByClass(WC_SAVELOAD);
- w = AllocateWindowDesc(&_newgrf_add_dlg_desc);
+ w = new Window(&_newgrf_add_dlg_desc);
w->resize.step_height = 10;
WP(w, newgrf_add_d).list = list;
@@ -582,7 +582,7 @@ void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFC
Window *w;
DeleteWindowByClass(WC_GAME_OPTIONS);
- w = AllocateWindowDesc(&_newgrf_desc);
+ w = new Window(&_newgrf_desc);
if (w == NULL) return;
w->resize.step_height = 14;
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index f67e8667f..2b1bacb6a 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -432,7 +432,7 @@ static void ShowNewspaper(NewsItem *ni)
case NM_NORMAL:
case NM_CALLBACK:
_news_type13_desc.top = top;
- w = AllocateWindowDesc(&_news_type13_desc);
+ w = new Window(&_news_type13_desc);
if (ni->flags & NF_VIEWPORT) {
InitializeWindowViewport(w, 2, 58, 426, 110,
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
@@ -441,7 +441,7 @@ static void ShowNewspaper(NewsItem *ni)
case NM_THIN:
_news_type2_desc.top = top;
- w = AllocateWindowDesc(&_news_type2_desc);
+ w = new Window(&_news_type2_desc);
if (ni->flags & NF_VIEWPORT) {
InitializeWindowViewport(w, 2, 58, 426, 70,
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
@@ -450,7 +450,7 @@ static void ShowNewspaper(NewsItem *ni)
default:
_news_type0_desc.top = top;
- w = AllocateWindowDesc(&_news_type0_desc);
+ w = new Window(&_news_type0_desc);
if (ni->flags & NF_VIEWPORT) {
InitializeWindowViewport(w, 3, 17, 274, 47,
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
@@ -711,7 +711,7 @@ static const WindowDesc _message_history_desc = {
void ShowMessageHistory()
{
DeleteWindowById(WC_MESSAGE_HISTORY, 0);
- Window *w = AllocateWindowDesc(&_message_history_desc);
+ Window *w = new Window(&_message_history_desc);
if (w == NULL) return;
@@ -933,7 +933,7 @@ static const WindowDesc _message_options_desc = {
void ShowMessageOptions()
{
DeleteWindowById(WC_GAME_OPTIONS, 0);
- AllocateWindowDesc(&_message_options_desc);
+ new Window(&_message_options_desc);
}
diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp
index 1bc3a2738..681762e08 100644
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -349,7 +349,7 @@ void ShowOnScreenKeyboard(Window *parent, querystr_d *q, int button, int cancel,
{
DeleteWindowById(WC_OSK, 0);
- Window *w = AllocateWindowDesc(&_osk_desc);
+ Window *w = new Window(&_osk_desc);
w->parent = parent;
assert(parent != NULL);
diff --git a/src/player_gui.cpp b/src/player_gui.cpp
index a8f05d593..fb8a8b11d 100644
--- a/src/player_gui.cpp
+++ b/src/player_gui.cpp
@@ -1552,7 +1552,7 @@ void ShowHighscoreTable(int difficulty, int8 ranking)
if (_game_mode != GM_MENU) HideVitalWindows();
DeleteWindowByClass(WC_HIGHSCORE);
- w = AllocateWindowDesc(&_highscore_desc);
+ w = new Window(&_highscore_desc);
if (w != NULL) {
MarkWholeScreenDirty();
@@ -1575,7 +1575,7 @@ void ShowEndGameChart()
HideVitalWindows();
DeleteWindowByClass(WC_ENDSCREEN);
- w = AllocateWindowDesc(&_endgame_desc);
+ w = new Window(&_endgame_desc);
if (w != NULL) {
MarkWholeScreenDirty();
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 5c6f9fe76..2fcbc489c 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -1226,10 +1226,10 @@ static void ShowStationBuilder()
{
Window *w;
if (GetNumStationClasses() <= 2 && GetNumCustomStations(STAT_CLASS_DFLT) == 1) {
- w = AllocateWindowDesc(&_station_builder_desc);
+ w = new Window(&_station_builder_desc);
_railstation.newstations = false;
} else {
- w = AllocateWindowDesc(&_newstation_builder_desc);
+ w = new Window(&_newstation_builder_desc);
_railstation.newstations = true;
_railstation.station_count = GetNumCustomStations(_railstation.station_class);
@@ -1397,7 +1397,7 @@ static const WindowDesc _signal_builder_desc = {
*/
static void ShowSignalBuilder()
{
- AllocateWindowDesc(&_signal_builder_desc);
+ new Window(&_signal_builder_desc);
}
/** Enum referring to the widgets of the build rail depot window */
@@ -1473,7 +1473,7 @@ static const WindowDesc _build_depot_desc = {
static void ShowBuildTrainDepotPicker()
{
- AllocateWindowDesc(&_build_depot_desc);
+ new Window(&_build_depot_desc);
}
/** Enum referring to the widgets of the build NewGRF rail waypoint window */
@@ -1576,7 +1576,7 @@ static const WindowDesc _build_waypoint_desc = {
static void ShowBuildWaypointPicker()
{
- Window *w = AllocateWindowDesc(&_build_waypoint_desc);
+ Window *w = new Window(&_build_waypoint_desc);
w->hscroll.cap = 5;
w->hscroll.count = _waypoint_count;
}
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index c20a6e03e..adad95164 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -817,7 +817,7 @@ static const WindowDesc _build_tram_depot_desc = {
static void ShowRoadDepotPicker()
{
- AllocateWindowDesc(_cur_roadtype == ROADTYPE_ROAD ? &_build_road_depot_desc : &_build_tram_depot_desc);
+ new Window(_cur_roadtype == ROADTYPE_ROAD ? &_build_road_depot_desc : &_build_tram_depot_desc);
}
/** Enum referring to the widgets of the build road station window */
@@ -966,7 +966,7 @@ static const WindowDesc _rv_station_picker_desc = {
static void ShowRVStationPicker(RoadStopType rs)
{
- Window *w = AllocateWindowDesc(&_rv_station_picker_desc);
+ Window *w = new Window(&_rv_station_picker_desc);
if (w == NULL) return;
w->window_class = (rs == ROADSTOP_BUS) ? WC_BUS_STATION : WC_TRUCK_STATION;
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index a857a0461..3ce65d5ab 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -389,7 +389,7 @@ static const WindowDesc _game_options_desc = {
void ShowGameOptions()
{
DeleteWindowById(WC_GAME_OPTIONS, 0);
- AllocateWindowDesc(&_game_options_desc);
+ new Window(&_game_options_desc);
}
struct GameSettingData {
@@ -698,7 +698,7 @@ void ShowGameDifficulty()
/* Copy current settings (ingame or in intro) to temporary holding place
* change that when setting stuff, copy back on clicking 'OK' */
_opt_mod_temp = *_opt_ptr;
- AllocateWindowDesc(&_game_difficulty_desc);
+ new Window(&_game_difficulty_desc);
}
static const char *_patches_ui[] = {
@@ -1104,7 +1104,7 @@ static const WindowDesc _patches_selection_desc = {
void ShowPatchesSelection()
{
DeleteWindowById(WC_GAME_OPTIONS, 0);
- AllocateWindowDesc(&_patches_selection_desc);
+ new Window(&_patches_selection_desc);
}
@@ -1334,5 +1334,5 @@ static void ShowCustCurrency()
_str_separator[1] = '\0';
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
- AllocateWindowDesc(&_cust_currency_desc);
+ new Window(&_cust_currency_desc);
}
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 2f1da2419..328f02ad2 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -301,7 +301,7 @@ void ShowRenameSignWindow(const Sign *si)
DeleteWindowById(WC_QUERY_STRING, 0);
DeleteWindowById(WC_SAVELOAD, 0);
- Window *w = AllocateWindowDesc(&_query_sign_edit_desc);
+ Window *w = new Window(&_query_sign_edit_desc);
WP(w, editsign_d).caption = STR_280B_EDIT_SIGN_TEXT;
WP(w, editsign_d).afilter = CS_ALPHANUMERAL;
diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp
index 0b145c8a2..730114321 100644
--- a/src/statusbar_gui.cpp
+++ b/src/statusbar_gui.cpp
@@ -163,7 +163,7 @@ static WindowDesc _main_status_desc = {
void ShowStatusBar()
{
_main_status_desc.top = _screen.height - 12;
- Window *w = AllocateWindowDesc(&_main_status_desc);
+ Window *w = new Window(&_main_status_desc);
if (w != NULL) {
CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
WP(w, def_d).data_1 = -1280;
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index f848d3345..f0ac39dd8 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -1230,7 +1230,7 @@ static Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base
Point pos = GetToolbarDropdownPos(parent_button, width, height);
- w = AllocateWindow(pos.x, pos.y, width, height, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets);
+ w = new Window(pos.x, pos.y, width, height, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets);
w->widget[0].bottom = item_count * 10 + 1;
w->flags4 &= ~WF_WHITE_BORDER_MASK;
@@ -1390,7 +1390,7 @@ static Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray)
DeleteWindowById(WC_TOOLBAR_MENU, 0);
Point pos = GetToolbarDropdownPos(main_button, 241, 82);
- w = AllocateWindow(pos.x, pos.y, 241, 82, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets);
+ w = new Window(pos.x, pos.y, 241, 82, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets);
w->flags4 &= ~WF_WHITE_BORDER_MASK;
WP(w, menu_d).item_count = 0;
WP(w, menu_d).sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0);
@@ -1418,7 +1418,7 @@ Window *AllocateToolbar()
/* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
_last_built_roadtype = ROADTYPE_ROAD;
- Window *w = AllocateWindowDesc((_game_mode != GM_EDITOR) ? &_toolb_normal_desc : &_toolb_scen_desc);
+ Window *w = new Window((_game_mode != GM_EDITOR) ? &_toolb_normal_desc : &_toolb_scen_desc);
if (w == NULL) return NULL;
CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index 5eb79e9f7..37f0ccdf7 100644
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -282,7 +282,7 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u
if (width == 0) width = wi->right - wi->left + 1;
- Window *dw = AllocateWindow(
+ Window *dw = new Window(
w->left + wi->left,
top,
width,
diff --git a/src/window.cpp b/src/window.cpp
index e214d94e1..a220a9369 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -677,10 +677,10 @@ void AssignWidgetToWindow(Window *w, const Widget *widget)
}
}
-/** Open a new window.
- * This function is called from AllocateWindow() or AllocateWindowDesc()
+/**
+ * Initializes a new Window.
+ * This function is called the constructors.
* See descriptions for those functions for usage
- * See AllocateWindow() for description of arguments.
* Only addition here is window_number, which is the window_number being assigned to the new window
* @param x offset in pixels from the left of the screen
* @param y offset in pixels from the top of the screen
@@ -694,71 +694,65 @@ void AssignWidgetToWindow(Window *w, const Widget *widget)
* @param window_number number being assigned to the new window
* @param data the data to be given during the WE_CREATE message
* @return Window pointer of the newly created window */
-static Window *LocalAllocateWindow(int x, int y, int min_width, int min_height, int def_width, int def_height,
+void Window::Initialize(int x, int y, int min_width, int min_height, int def_width, int def_height,
WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data)
{
- Window *w;
-
/* We have run out of windows, close one and use that as the place for our new one */
if (_last_z_window == endof(_z_windows)) {
- w = FindDeletableWindow();
+ Window *w = FindDeletableWindow();
if (w == NULL) w = ForceFindDeletableWindow();
delete w;
}
- w = new Window(proc);
-
/* Set up window properties */
- w->window_class = cls;
- w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
- w->caption_color = 0xFF;
- w->left = x;
- w->top = y;
- w->width = min_width;
- w->height = min_height;
- AssignWidgetToWindow(w, widget);
- w->resize.width = min_width;
- w->resize.height = min_height;
- w->resize.step_width = 1;
- w->resize.step_height = 1;
- w->window_number = window_number;
-
- {
- Window **wz = _last_z_window;
-
- /* Hacky way of specifying always-on-top windows. These windows are
- * always above other windows because they are moved below them.
- * status-bar is above news-window because it has been created earlier.
- * Also, as the chat-window is excluded from this, it will always be
- * the last window, thus always on top.
- * XXX - Yes, ugly, probably needs something like w->always_on_top flag
- * to implement correctly, but even then you need some kind of distinction
- * between on-top of chat/news and status windows, because these conflict */
- if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG && w->window_class != WC_HIGHSCORE && w->window_class != WC_ENDSCREEN) {
- if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) wz--;
- if (FindWindowById(WC_STATUS_BAR, 0) != NULL) wz--;
- if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) wz--;
- if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
-
- assert(wz >= _z_windows);
- if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
- }
-
- *wz = w;
- _last_z_window++;
- }
+ this->window_class = cls;
+ this->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
+ this->caption_color = 0xFF;
+ this->left = x;
+ this->top = y;
+ this->width = min_width;
+ this->height = min_height;
+ this->wndproc = proc;
+ AssignWidgetToWindow(this, widget);
+ this->resize.width = min_width;
+ this->resize.height = min_height;
+ this->resize.step_width = 1;
+ this->resize.step_height = 1;
+ this->window_number = window_number;
+
+ /* Hacky way of specifying always-on-top windows. These windows are
+ * always above other windows because they are moved below them.
+ * status-bar is above news-window because it has been created earlier.
+ * Also, as the chat-window is excluded from this, it will always be
+ * the last window, thus always on top.
+ * XXX - Yes, ugly, probably needs something like w->always_on_top flag
+ * to implement correctly, but even then you need some kind of distinction
+ * between on-top of chat/news and status windows, because these conflict */
+ Window **wz = _last_z_window;
+ if (wz != _z_windows && this->window_class != WC_SEND_NETWORK_MSG && this->window_class != WC_HIGHSCORE && this->window_class != WC_ENDSCREEN) {
+ if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) wz--;
+ if (FindWindowById(WC_STATUS_BAR, 0) != NULL) wz--;
+ if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) wz--;
+ if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
+
+ assert(wz >= _z_windows);
+ if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
+ }
+
+ *wz = this;
+ _last_z_window++;
WindowEvent e;
e.event = WE_CREATE;
e.we.create.data = data;
- w->HandleWindowEvent(&e);
+ this->HandleWindowEvent(&e);
/* Try to make windows smaller when our window is too small.
* w->(width|height) is normally the same as min_(width|height),
* but this way the GUIs can be made a little more dynamic;
* one can use the same spec for multiple windows and those
* can then determine the real minimum size of the window. */
- if (w->width != def_width || w->height != def_height) {
+ if (this->width != def_width || this->height != def_height) {
/* Think about the overlapping toolbars when determining the minimum window size */
int free_height = _screen.height;
const Window *wt = FindWindowById(WC_STATUS_BAR, 0);
@@ -766,45 +760,43 @@ static Window *LocalAllocateWindow(int x, int y, int min_width, int min_height,
wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
if (wt != NULL) free_height -= wt->height;
- int enlarge_x = max(min(def_width - w->width, _screen.width - w->width), 0);
- int enlarge_y = max(min(def_height - w->height, free_height - w->height), 0);
+ int enlarge_x = max(min(def_width - this->width, _screen.width - this->width), 0);
+ int enlarge_y = max(min(def_height - this->height, free_height - this->height), 0);
/* X and Y has to go by step.. calculate it.
* The cast to int is necessary else x/y are implicitly casted to
* unsigned int, which won't work. */
- if (w->resize.step_width > 1) enlarge_x -= enlarge_x % (int)w->resize.step_width;
- if (w->resize.step_height > 1) enlarge_y -= enlarge_y % (int)w->resize.step_height;
+ if (this->resize.step_width > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width;
+ if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
- ResizeWindow(w, enlarge_x, enlarge_y);
+ ResizeWindow(this, enlarge_x, enlarge_y);
WindowEvent e;
e.event = WE_RESIZE;
- e.we.sizing.size.x = w->width;
- e.we.sizing.size.y = w->height;
+ e.we.sizing.size.x = this->width;
+ e.we.sizing.size.y = this->height;
e.we.sizing.diff.x = enlarge_x;
e.we.sizing.diff.y = enlarge_y;
- w->HandleWindowEvent(&e);
+ this->HandleWindowEvent(&e);
}
- int nx = w->left;
- int ny = w->top;
+ int nx = this->left;
+ int ny = this->top;
- if (nx + w->width > _screen.width) nx -= (nx + w->width - _screen.width);
+ if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
- ny = max(ny, (wt == NULL || w == wt || y == 0) ? 0 : wt->height);
+ ny = max(ny, (wt == NULL || this == wt || y == 0) ? 0 : wt->height);
nx = max(nx, 0);
- if (w->viewport != NULL) {
- w->viewport->left += nx - w->left;
- w->viewport->top += ny - w->top;
+ if (this->viewport != NULL) {
+ this->viewport->left += nx - this->left;
+ this->viewport->top += ny - this->top;
}
- w->left = nx;
- w->top = ny;
-
- w->SetDirty();
+ this->left = nx;
+ this->top = ny;
- return w;
+ this->SetDirty();
}
/**
@@ -821,10 +813,9 @@ static Window *LocalAllocateWindow(int x, int y, int min_width, int min_height,
* @param *widget see Widget pointer to the window layout and various elements
* @return Window pointer of the newly created window
*/
-Window *AllocateWindow(int x, int y, int width, int height,
- WindowProc *proc, WindowClass cls, const Widget *widget, void *data)
+Window::Window(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const Widget *widget, void *data)
{
- return LocalAllocateWindow(x, y, width, height, width, height, proc, cls, widget, 0, data);
+ this->Initialize(x, y, width, height, width, height, proc, cls, widget, 0, data);
}
@@ -1014,24 +1005,11 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int window_number)
*
* @return Window pointer of the newly created window
*/
-static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number, void *data)
+Window::Window(const WindowDesc *desc, void *data, WindowNumber window_number)
{
Point pt = LocalGetWindowPlacement(desc, window_number);
- Window *w = LocalAllocateWindow(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data);
- w->desc_flags = desc->flags;
-
- return w;
-}
-
-/**
- * Open a new window.
- * @param *desc The pointer to the WindowDesc to be created
- * @param data arbitrary data that is send with the WE_CREATE message
- * @return Window pointer of the newly created window
- */
-Window *AllocateWindowDesc(const WindowDesc *desc, void *data)
-{
- return LocalAllocateWindowDesc(desc, 0, data);
+ this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data);
+ this->desc_flags = desc->flags;
}
/**
@@ -1044,7 +1022,7 @@ Window *AllocateWindowDesc(const WindowDesc *desc, void *data)
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data)
{
if (BringWindowToFrontById(desc->cls, window_number)) return NULL;
- return LocalAllocateWindowDesc(desc, window_number, data);
+ return new Window(desc, data, window_number);
}
/** Do a search for a window at specific coordinates. For this we start
diff --git a/src/window_gui.h b/src/window_gui.h
index 081ec736b..32352d3ea 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -297,8 +297,14 @@ struct Window : ZeroedMemoryAllocator {
private:
WindowProc *wndproc; ///< Event handler function for the window. Do not use directly, call HandleWindowEvent() instead.
+protected:
+ void Initialize(int x, int y, int min_width, int min_height, int def_width, int def_height,
+ WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data);
+
public:
- Window(WindowProc *proc) : wndproc(proc) {}
+ Window(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const Widget *widget, void *data = NULL);
+ Window(const WindowDesc *desc, void *data = NULL, WindowNumber number = 0);
+
virtual ~Window();
uint16 flags4; ///< Window flags, @see WindowFlags
@@ -554,11 +560,7 @@ Window *FindWindowFromPt(int x, int y);
bool IsWindowOfPrototype(const Window *w, const Widget *widget);
void AssignWidgetToWindow(Window *w, const Widget *widget);
-Window *AllocateWindow(int x, int y, int width, int height,
- WindowProc *proc, WindowClass cls, const Widget *widget,
- void *data = NULL);
-Window *AllocateWindowDesc(const WindowDesc *desc, void *data = NULL);
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data = NULL);
void DrawWindowViewport(const Window *w);