Pass grs_canvas &to window_create

This commit is contained in:
Kp 2016-10-15 00:53:20 +00:00
parent d903a5db3b
commit 01f2932824
19 changed files with 28 additions and 40 deletions

View file

@ -25,16 +25,15 @@ namespace dcx {
static window *FrontWindow = nullptr;
static window *FirstWindow = nullptr;
window::window(grs_canvas *src, int x, int y, int w, int h, window_subfunction<void> event_callback, void *data, const void *createdata) :
window::window(grs_canvas &src, int x, int y, int w, int h, window_subfunction<void> event_callback, void *data, const void *createdata) :
// Default to visible and modal
w_callback(event_callback), w_visible(1), w_modal(1), w_data(data), prev(FrontWindow), next(nullptr)
{
window *prev_front = window_get_front();
d_create_event event;
window *wind = this;
Assert(src != nullptr);
Assert(event_callback != nullptr);
gr_init_sub_canvas(wind->w_canv, *src, x, y, w, h);
gr_init_sub_canvas(wind->w_canv, src, x, y, w, h);
if (FirstWindow == nullptr)
FirstWindow = wind;

View file

@ -65,17 +65,17 @@ class window
public:
// For creating the window, there are two ways - using the (older) window_create function
// or using the constructor, passing an event handler that takes a subclass of window.
explicit window(grs_canvas *src, int x, int y, int w, int h, window_subfunction<void> event_callback, void *data, const void *createdata);
explicit window(grs_canvas &src, int x, int y, int w, int h, window_subfunction<void> event_callback, void *data, const void *createdata);
template <typename T>
window(grs_canvas *src, int x, int y, int w, int h, window_subclass_subfunction<T> event_callback) :
window(grs_canvas &src, const int x, const int y, const int w, const int h, const window_subclass_subfunction<T> event_callback) :
window(src, x, y, w, h, reinterpret_cast<window_subclass_subfunction<window>>(event_callback), nullptr, nullptr) {}
~window();
// Declaring as friends to keep function syntax, for historical reasons (for now at least)
// Intended to transition to the class method form
friend window *window_create(grs_canvas *src, int x, int y, int w, int h, window_subfunction<void> event_callback, void *userdata, const void *createdata);
friend window *window_create(grs_canvas &src, int x, int y, int w, int h, window_subfunction<void> event_callback, void *userdata, const void *createdata);
friend int window_close(window *wind);
friend int window_exists(window *wind);
@ -143,7 +143,7 @@ public:
};
template <typename T1, typename T2 = const void>
static inline window *window_create(grs_canvas *src, int x, int y, int w, int h, window_subfunction<T1> event_callback, T1 *data, T2 *createdata = nullptr)
static inline window *window_create(grs_canvas &src, int x, int y, int w, int h, window_subfunction<T1> event_callback, T1 *data, T2 *createdata = nullptr)
{
auto win = new window(src, x, y, w, h, reinterpret_cast<window_subfunction<void>>(event_callback), static_cast<void *>(data), static_cast<const void *>(createdata));
set_embedded_window_pointer(data, win);
@ -151,7 +151,7 @@ static inline window *window_create(grs_canvas *src, int x, int y, int w, int h,
}
template <typename T1, typename T2 = const void>
static inline window *window_create(grs_canvas *src, int x, int y, int w, int h, window_subfunction<const T1> event_callback, const T1 *userdata, T2 *createdata = nullptr)
static inline window *window_create(grs_canvas &src, int x, int y, int w, int h, window_subfunction<const T1> event_callback, const T1 *userdata, T2 *createdata = nullptr)
{
return new window(src, x, y, w, h, reinterpret_cast<window_subfunction<void>>(event_callback), static_cast<void *>(const_cast<T1 *>(userdata)), static_cast<const void *>(createdata));
}

View file

@ -173,7 +173,7 @@ d_callback(callback), gadget(nullptr), keyboard_focus_gadget(nullptr), d_userdat
D_HEIGHT = h;
selected_gadget = NULL;
dlg->wind = window_create(&grd_curscreen->sc_canvas,
dlg->wind = window_create(grd_curscreen->sc_canvas,
x + ((flags & DF_BORDER) ? BORDER_WIDTH : 0),
y + ((flags & DF_BORDER) ? BORDER_WIDTH : 0),
req_w, req_h, ui_dialog_handler, dlg, createdata);

View file

@ -146,7 +146,7 @@ static void menu_show( MENU * menu )
{
if (!menu->wind)
{
menu->wind = window_create(&grd_curscreen->sc_canvas, menu->x, menu->y, menu->w, menu->h,
menu->wind = window_create(grd_curscreen->sc_canvas, menu->x, menu->y, menu->w, menu->h,
((menu == &Menu[0]) ? menubar_handler : menu_handler), menu);
if (!menu->wind)
return;

View file

@ -1710,7 +1710,6 @@ void do_escort_menu(void)
const char *goal_txt;
const char *tstr;
escort_menu *menu;
window *wind;
if (Game_mode & GM_MULTI) {
HUD_init_message_literal(HM_DEFAULT, "No Guide-Bot in Multiplayer!");
@ -1735,7 +1734,7 @@ void do_escort_menu(void)
return;
// Just make it the full screen size and let show_escort_menu figure it out
wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, escort_menu_handler, menu);
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, escort_menu_handler, menu);
if (!wind)
{
d_free(menu);

View file

@ -342,7 +342,7 @@ static window_event_result MovieHandler(window *, const d_event &event, movie *m
// If PAUSE pressed, then pause movie
if ((key == KEY_PAUSE) || (key == KEY_COMMAND + KEY_P))
{
if (window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, show_pause_message, unused_window_userdata))
if (window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, show_pause_message, unused_window_userdata))
MVE_rmHoldMovie();
return window_event_result::handled;
}
@ -402,7 +402,7 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy)
return MOVIE_NOT_PLAYED;
}
const auto reshow = hide_menus();
const auto wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, MovieHandler, &m);
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, MovieHandler, &m);
if (!wind)
{
if (reshow)

View file

@ -345,9 +345,7 @@ static window_event_result info_display_all(window *wind,const d_event &event, c
// ------------------------------------------------------------------------------------
window *info_window_create(void)
{
window *wind;
wind = window_create(Canv_editor, PAD_X + 250, PAD_Y + 8, 180, 160, info_display_all, unused_window_userdata);
const auto wind = window_create(*Canv_editor, PAD_X + 250, PAD_Y + 8, 180, 160, info_display_all, unused_window_userdata);
if (wind)
window_set_modal(wind, 0);

View file

@ -985,7 +985,7 @@ void do_automap()
int pcx_error;
palette_array_t pal;
automap *am = new automap{};
window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, automap_handler, am);
window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, automap_handler, am);
am->leave_mode = 0;
am->pause_game = 1; // Set to 1 if everything is paused during automap...No pause during net.
am->max_segments_away = 0;

View file

@ -297,11 +297,9 @@ static window_event_result con_handler(window *wind,const d_event &event, const
void con_showup(void)
{
window *wind;
game_flush_inputs();
con_state = CON_STATE_OPENING;
wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, con_handler, unused_window_userdata);
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, con_handler, unused_window_userdata);
if (!wind)
{

View file

@ -257,7 +257,7 @@ static void credits_show_common(RAIIPHYSFS_File file, const int have_bin_file)
key_flush();
credits *pcr = cr.get();
const auto wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, credits_handler, cr.release());
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, credits_handler, cr.release());
if (!wind)
{
d_event event = { EVENT_WINDOW_CLOSE };

View file

@ -1166,13 +1166,12 @@ namespace dsx {
window *game_setup(void)
{
window *game_wind;
PlayerCfg.CockpitMode[1] = PlayerCfg.CockpitMode[0];
last_drawn_cockpit = -1; // Force cockpit to redraw next time a frame renders.
Endlevel_sequence = 0;
game_wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, game_handler, unused_window_userdata);
const auto game_wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, game_handler, unused_window_userdata);
if (!game_wind)
return NULL;

View file

@ -409,7 +409,7 @@ static int do_game_pause()
snprintf(&p->msg[0], p->msg.size(), "PAUSE\n\nSkill level: %s\nHostages on board: %d\n", MENU_DIFFICULTY_TEXT(Difficulty_level), player_info.mission.hostages_on_board);
set_screen_mode(SCREEN_MENU);
if (!window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, pause_handler, p))
if (!window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, pause_handler, p))
delete p;
return 0 /*key*/; // Keycode returning ripped out (kreatordxx)

View file

@ -536,7 +536,7 @@ void editor_reset_stuff_on_level()
compute_slide_segs();
#endif
if (!Game_wind)
Game_wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, game_handler, unused_window_userdata);
Game_wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, game_handler, unused_window_userdata);
}
#endif

View file

@ -1330,7 +1330,7 @@ static void kconfig_sub(const char *litems, const kc_item * items,kc_mitem *mite
const auto &&fspacx = FSPACX();
const auto &&fspacy = FSPACY();
if (!(menu->wind = window_create(&grd_curscreen->sc_canvas, (SWIDTH - fspacx(320)) / 2, (SHEIGHT - fspacy(200)) / 2, fspacx(320), fspacy(200),
if (!(menu->wind = window_create(grd_curscreen->sc_canvas, (SWIDTH - fspacx(320)) / 2, (SHEIGHT - fspacy(200)) / 2, fspacx(320), fspacy(200),
kconfig_handler, menu)))
delete menu;
}

View file

@ -387,7 +387,6 @@ static window_event_result kmatrix_handler(window *, const d_event &event, kmatr
kmatrix_result kmatrix_view(int network)
{
window *wind;
kmatrix_screen km;
gr_init_bitmap_data(km.background);
if (pcx_read_bitmap(STARS_BACKGROUND, km.background, gr_palette) != PCX_ERROR_NONE)
@ -408,7 +407,7 @@ kmatrix_result kmatrix_view(int network)
if (i.objnum != object_none)
digi_kill_sound_linked_to_object(vcobjptridx(i.objnum));
wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, kmatrix_handler, &km);
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, kmatrix_handler, &km);
if (!wind)
{
return kmatrix_result::abort;

View file

@ -2366,7 +2366,7 @@ static window_event_result polygon_models_viewer_handler(window *, const d_event
static void polygon_models_viewer()
{
window *wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, polygon_models_viewer_handler, unused_window_userdata);
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, polygon_models_viewer_handler, unused_window_userdata);
if (!wind)
{
d_event event = { EVENT_WINDOW_CLOSE };
@ -2445,7 +2445,7 @@ static window_event_result gamebitmaps_viewer_handler(window *, const d_event &e
static void gamebitmaps_viewer()
{
window *wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, gamebitmaps_viewer_handler, unused_window_userdata);
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, gamebitmaps_viewer_handler, unused_window_userdata);
if (!wind)
{
d_event event = { EVENT_WINDOW_CLOSE };

View file

@ -1574,7 +1574,6 @@ static window_event_result newmenu_handler(window *wind,const d_event &event, ne
newmenu *newmenu_do4( const char * title, const char * subtitle, uint_fast32_t nitems, newmenu_item * item, newmenu_subfunction subfunction, void *userdata, int citem, const char * filename, int TinyMode, int TabsFlag )
{
window *wind = NULL;
newmenu *menu = new newmenu{};
menu->citem = citem;
menu->scroll_offset = 0;
@ -1608,7 +1607,7 @@ newmenu *newmenu_do4( const char * title, const char * subtitle, uint_fast32_t n
newmenu_create_structure(menu);
// Create the basic window
wind = window_create(&grd_curscreen->sc_canvas, menu->x, menu->y, menu->w, menu->h, newmenu_handler, menu);
const auto wind = window_create(grd_curscreen->sc_canvas, menu->x, menu->y, menu->w, menu->h, newmenu_handler, menu);
if (!wind)
{
@ -2094,7 +2093,7 @@ listbox *newmenu_listbox1(const char *const title, const uint_fast32_t nitems, c
listbox_create_structure(lb.get());
wind = window_create(&grd_curscreen->sc_canvas, lb->box_x-BORDERX, lb->box_y-lb->title_height-BORDERY, lb->box_w+2*BORDERX, lb->height+2*BORDERY, listbox_handler, lb.get());
wind = window_create(grd_curscreen->sc_canvas, lb->box_x-BORDERX, lb->box_y-lb->title_height-BORDERY, lb->box_w+2*BORDERX, lb->height+2*BORDERY, listbox_handler, lb.get());
if (!wind)
{
lb.reset();

View file

@ -482,6 +482,6 @@ void scores_view(stats_info *last_game, int citem)
const auto &&fspacx320 = FSPACX(320);
const auto &&fspacy200 = FSPACY(200);
window_create(&grd_curscreen->sc_canvas, (SWIDTH - fspacx320) / 2, (SHEIGHT - fspacy200) / 2, fspacx320, fspacy200,
window_create(grd_curscreen->sc_canvas, (SWIDTH - fspacx320) / 2, (SHEIGHT - fspacy200) / 2, fspacx320, fspacy200,
scores_handler, menu);
}

View file

@ -156,7 +156,6 @@ static window_event_result title_handler(window *, const d_event &event, title_s
static void show_title_screen(const char * filename, int allow_keys, int from_hog_only )
{
window *wind;
int pcx_error;
char new_filename[PATH_MAX] = "";
@ -181,7 +180,7 @@ static void show_title_screen(const char * filename, int allow_keys, int from_ho
gr_palette_load( gr_palette );
wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, title_handler, ts.get());
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, title_handler, ts.get());
if (!wind)
{
gr_free_bitmap_data(ts->title_bm);
@ -1566,8 +1565,6 @@ namespace dsx {
void do_briefing_screens(const d_fname &filename, int level_num)
{
window *wind;
if (!*static_cast<const char *>(filename))
return;
@ -1579,7 +1576,7 @@ void do_briefing_screens(const d_fname &filename, int level_num)
return;
}
wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, briefing_handler, br.get());
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, briefing_handler, br.get());
if (!wind)
{
return;