Inline window_get_canvas

The helper returns a reference to a mutable canvas, so there is no
isolation provided by using the helper.
This commit is contained in:
Kp 2020-08-28 00:18:45 +00:00
parent 0f89331924
commit 1d3e546848
9 changed files with 12 additions and 17 deletions

View file

@ -183,7 +183,7 @@ void mouse_get_pos( int *x, int *y, int *z )
window_event_result mouse_in_window(window *wind)
{
auto &canv = window_get_canvas(*wind);
auto &canv = wind->w_canv;
return (static_cast<unsigned>(Mouse.x) - canv.cv_bitmap.bm_x <= canv.cv_bitmap.bm_w) &&
(static_cast<unsigned>(Mouse.y) - canv.cv_bitmap.bm_y <= canv.cv_bitmap.bm_h) ? window_event_result::handled : window_event_result::ignored;
}

View file

@ -45,7 +45,6 @@ window *window_get_next(window &wind);
window *window_get_prev(window &wind);
void window_select(window &wind);
window *window_set_visible(window &wind, int visible);
grs_canvas &window_get_canvas(window &wind);
#if !DXX_USE_OGL
void window_update_canvases();
#endif

View file

@ -46,7 +46,9 @@ static inline void set_embedded_window_pointer(ignore_window_pointer_t *, window
class window
{
public:
grs_canvas w_canv; // the window's canvas to draw to
private:
int w_visible; // whether it's visible
int w_modal; // modal = accept all user input exclusively
class window *prev; // the previous window in the doubly linked list
@ -75,12 +77,6 @@ public:
#if !DXX_USE_OGL
friend void window_update_canvases();
#endif
friend grs_canvas &window_get_canvas(window &wind)
{
return wind.w_canv;
}
friend window *window_set_visible(window *wind, int visible)
{
return window_set_visible(*wind, visible);
@ -161,7 +157,7 @@ static inline callback_window *window_create(grs_canvas &src, int x, int y, int
static inline window_event_result (WINDOW_SEND_EVENT)(window &w, const d_event &event, const char *const file, const unsigned line)
{
auto &c = window_get_canvas(w);
auto &c = w.w_canv;
con_printf(CON_DEBUG, "%s:%u: sending event %i to window of dimensions %dx%d", file, line, event.type, c.cv_bitmap.bm_w, c.cv_bitmap.bm_h);
return window_send_event(w, event);
}

View file

@ -181,7 +181,7 @@ window *ui_dialog_get_window(UI_DIALOG *dlg)
void ui_dialog_set_current_canvas(UI_DIALOG *dlg)
{
gr_set_current_canvas(window_get_canvas(*dlg->wind));
gr_set_current_canvas(dlg->wind->w_canv);
}
UI_DIALOG::~UI_DIALOG()

View file

@ -84,7 +84,7 @@ void ui_gadget_add(UI_DIALOG * dlg, short x1, short y1, short x2, short y2, UI_G
if ( x1==0 && x2==0 && y1==0 && y2== 0 )
gadget->canvas.reset();
else
gadget->canvas = gr_create_sub_canvas(window_get_canvas(*ui_dialog_get_window(dlg)), x1, y1, x2-x1+1, y2-y1+1);
gadget->canvas = gr_create_sub_canvas(ui_dialog_get_window(dlg)->w_canv, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
gadget->x1 = gadget->canvas->cv_bitmap.bm_x;
gadget->y1 = gadget->canvas->cv_bitmap.bm_y;
gadget->x2 = gadget->canvas->cv_bitmap.bm_x+x2-x1+1;

View file

@ -322,7 +322,7 @@ static window_event_result info_display_all(window *wind,const d_event &event, c
{
case EVENT_WINDOW_DRAW:
{
gr_set_current_canvas(window_get_canvas(*wind));
gr_set_current_canvas(wind->w_canv);
auto &canvas = *grd_curcanv;
padnum = ui_pad_get_current();

View file

@ -349,7 +349,7 @@ static void kconfig_draw(kc_menu *menu)
gr_set_default_canvas();
nm_draw_background(*grd_curcanv, ((SWIDTH - w) / 2) - BORDERX, ((SHEIGHT - h) / 2) - BORDERY, ((SWIDTH - w) / 2) + w + BORDERX, ((SHEIGHT - h) / 2) + h + BORDERY);
gr_set_current_canvas(window_get_canvas(*menu->wind));
gr_set_current_canvas(menu->wind->w_canv);
auto &canvas = *grd_curcanv;
const grs_font *save_font = canvas.cv_font;
@ -527,7 +527,7 @@ static window_event_result kconfig_mouse(window *wind,const d_event &event, kc_m
int mx, my, mz, x1, y1;
window_event_result rval = window_event_result::ignored;
gr_set_current_canvas(window_get_canvas(*wind));
gr_set_current_canvas(wind->w_canv);
auto &canvas = *grd_curcanv;
if (menu->mouse_state)

View file

@ -715,7 +715,7 @@ static int nm_trigger_radio_button(newmenu &menu, newmenu_item &citem)
static window_event_result newmenu_mouse(window *wind,const d_event &event, newmenu *menu, int button)
{
int old_choice, mx=0, my=0, mz=0, x1 = 0, x2, y1, y2, changed = 0;
grs_canvas &menu_canvas = window_get_canvas(*wind);
grs_canvas &menu_canvas = wind->w_canv;
grs_canvas &save_canvas = *grd_curcanv;
switch (button)
@ -1412,7 +1412,7 @@ static void newmenu_create_structure( newmenu *menu )
static window_event_result newmenu_draw(window *wind, newmenu *menu)
{
grs_canvas &menu_canvas = window_get_canvas(*wind);
grs_canvas &menu_canvas = wind->w_canv;
grs_canvas &save_canvas = *grd_curcanv;
int th = 0, ty, sx, sy;
int i;

View file

@ -420,7 +420,7 @@ static window_event_result scores_handler(window *wind,const d_event &event, sco
nm_draw_background(*grd_curcanv, ((SWIDTH - w) / 2) - BORDERX, ((SHEIGHT - h) / 2) - BORDERY, ((SWIDTH - w) / 2) + w + BORDERX, ((SHEIGHT - h) / 2) + h + BORDERY);
{
auto &canvas = window_get_canvas(*wind);
auto &canvas = wind->w_canv;
auto &medium3_font = *MEDIUM3_FONT;
gr_string(canvas, medium3_font, 0x8000, fspacy(15), TXT_HIGH_SCORES);
gr_set_fontcolor(canvas, BM_XRGB(31, 26, 5), -1);