diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 725ccd1ef..e46025cb7 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D2X-Rebirth Changelog +20111218 +-------- +include/ui.h, ui/dialog.c, ui/gadget.c, ui/keypad.c: Remove redundant canvas, next and prev members in the UI_DIALOG struct + 20111127 -------- arch/sdl/event.c: break out of loop in event_send() in case window_send_event() closed the window to prevent invalid read on memory diff --git a/include/ui.h b/include/ui.h index 3b0475a86..860f44835 100644 --- a/include/ui.h +++ b/include/ui.h @@ -198,13 +198,10 @@ enum dialog_flags typedef struct _ui_window { struct window *wind; int (*callback)(struct _ui_window *, struct d_event *, void *); - grs_canvas * canvas; grs_canvas * oldcanvas; grs_bitmap * background; UI_GADGET * gadget; UI_GADGET * keyboard_focus_gadget; - struct _ui_window * next; - struct _ui_window * prev; void *userdata; short x, y; short width, height; @@ -281,6 +278,8 @@ extern void ui_mouse_hide(); extern void ui_mouse_show(); extern UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, int (*callback)(UI_DIALOG *, struct d_event *, void *), void *userdata ); +extern struct window *ui_dialog_get_window(UI_DIALOG *dlg); +extern void ui_dialog_set_current_canvas(UI_DIALOG *dlg); extern void ui_close_dialog( UI_DIALOG * dlg ); extern UI_GADGET * ui_gadget_add( UI_DIALOG * dlg, short kind, short x1, short y1, short x2, short y2 ); diff --git a/ui/dialog.c b/ui/dialog.c index 08b87717c..e9a893c2b 100644 --- a/ui/dialog.c +++ b/ui/dialog.c @@ -38,12 +38,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define D_WIDTH (dlg->width) #define D_HEIGHT (dlg->height) #define D_OLDCANVAS (dlg->oldcanvas) -#define D_CANVAS (dlg->canvas) #define D_GADGET (dlg->gadget) #define D_TEXT_X (dlg->text_x) #define D_TEXT_Y (dlg->text_y) -#define D_NEXT (dlg->next) -#define D_PREV (dlg->prev) #ifndef __MSDOS__ #define _disable() @@ -139,65 +136,6 @@ int ui_recorder_status() return Record; } -void add_window_to_end( UI_DIALOG * dlg ) -{ - if (LastWindow) { - D_PREV = LastWindow; - LastWindow->next = dlg; - } - LastWindow = dlg; - if (!FirstWindow) - FirstWindow = dlg; -} - -void add_window_to_beg( UI_DIALOG * dlg ) -{ - if (FirstWindow) { - D_NEXT = FirstWindow; - FirstWindow->prev = dlg; - } - FirstWindow = dlg; - if (!LastWindow) - LastWindow = dlg; -} - -// Add w1 after w2 -void add_window_after( UI_DIALOG * w1, UI_DIALOG * w2 ) -{ - w1->prev = w2; - w1->next = w2->next; - w2->next = w1; - if (w1->next == NULL ) - LastWindow = w1; - else - w1->next->prev = w1; -} - -void close_all() -{ - UI_DIALOG *sav, *dlg = LastWindow; - - while(dlg) - { - sav = D_PREV; - ui_close_dialog(dlg); - dlg = sav; - } -} - -void remove_window( UI_DIALOG * dlg ) -{ - if (D_NEXT) - D_NEXT->prev = D_PREV; - if (D_PREV) - D_PREV->next = D_NEXT; - if (FirstWindow == dlg ) - FirstWindow = D_NEXT; - if (LastWindow == dlg ) - LastWindow = D_PREV; - D_NEXT = D_PREV = NULL; -} - int ui_dialog_draw(UI_DIALOG *dlg) { return 0; @@ -266,11 +204,6 @@ UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_fl dlg = (UI_DIALOG *) d_malloc(sizeof(UI_DIALOG)); if (dlg==NULL) Error("Could not create dialog: Out of memory"); - D_NEXT = NULL; - D_PREV = NULL; - - add_window_to_end( dlg ); - sw = grd_curscreen->sc_w; sh = grd_curscreen->sc_h; @@ -314,21 +247,18 @@ UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_fl if (flags & DF_BORDER) { - D_CANVAS = gr_create_sub_canvas( &(grd_curscreen->sc_canvas), x+BORDER_WIDTH, y+BORDER_WIDTH, req_w, req_h ); gr_set_current_canvas( NULL ); ui_draw_frame( x, y, x+w-1, y+h-1 ); } - else - D_CANVAS = gr_create_sub_canvas( &(grd_curscreen->sc_canvas), x, y, req_w, req_h ); - gr_set_current_canvas( D_CANVAS ); - dlg->callback = callback; dlg->userdata = userdata; 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, (int (*)(window *, d_event *, void *)) ui_dialog_handler, dlg); + ui_dialog_set_current_canvas(dlg); + if (!dlg->wind) { ui_close_dialog(dlg); @@ -352,6 +282,16 @@ UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_fl } +window *ui_dialog_get_window(UI_DIALOG *dlg) +{ + return dlg->wind; +} + +void ui_dialog_set_current_canvas(UI_DIALOG *dlg) +{ + gr_set_current_canvas(window_get_canvas(dlg->wind)); +} + void ui_close_dialog( UI_DIALOG * dlg ) { @@ -370,14 +310,10 @@ void ui_close_dialog( UI_DIALOG * dlg ) gr_rect( D_X, D_Y, D_X+D_WIDTH-1, D_Y+D_HEIGHT-1 ); } - gr_free_sub_canvas( D_CANVAS ); - gr_set_current_canvas( D_OLDCANVAS ); selected_gadget = NULL; - remove_window( dlg ); - if (CurWindow==dlg) CurWindow = NULL; @@ -714,7 +650,7 @@ void ui_dprintf( UI_DIALOG * dlg, char * format, ... ) va_start(args, format ); vsprintf(buffer,format,args); - gr_set_current_canvas( D_CANVAS ); + ui_dialog_set_current_canvas( dlg ); ui_mouse_hide(); D_TEXT_X = gr_string( D_TEXT_X, D_TEXT_Y, buffer ); @@ -729,7 +665,7 @@ void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, char * format, ... ) va_start(args, format ); vsprintf(buffer,format,args); - gr_set_current_canvas( D_CANVAS ); + ui_dialog_set_current_canvas( dlg ); ui_mouse_hide(); gr_string( x, y, buffer ); diff --git a/ui/gadget.c b/ui/gadget.c index 1ce026e26..20d83fbb4 100644 --- a/ui/gadget.c +++ b/ui/gadget.c @@ -26,6 +26,7 @@ static char rcsid[] = "$Id: gadget.c,v 1.1.1.1 2006/03/17 19:52:21 zicodxx Exp $ #include "ui.h" #include "event.h" #include "mouse.h" +#include "window.h" #include "error.h" #include "key.h" @@ -63,7 +64,7 @@ UI_GADGET * ui_gadget_add( UI_DIALOG * dlg, short kind, short x1, short y1, shor if ( x1==0 && x2==0 && y1==0 && y2== 0 ) gadget->canvas = NULL; else - gadget->canvas = gr_create_sub_canvas( dlg->canvas, x1, y1, x2-x1+1, y2-y1+1 ); + gadget->canvas = gr_create_sub_canvas( window_get_canvas(ui_dialog_get_window( dlg )), 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; @@ -126,7 +127,7 @@ void ui_gadget_delete_all( UI_DIALOG * dlg ) } -#if 1 +#if 0 int is_under_another_window( UI_DIALOG * dlg, UI_GADGET * gadget ) { UI_DIALOG * temp; @@ -170,7 +171,7 @@ int ui_mouse_on_gadget( UI_GADGET * gadget ) mouse_get_pos(&x, &y, &z); if ((x >= gadget->x1) && (x <= gadget->x2-1) && (y >= gadget->y1) && (y <= gadget->y2-1) ) { -#if 1 +#if 0 // check is no longer required - if it is under another window, that dialog's handler would have returned 1 if (is_under_another_window(CurWindow, gadget)) return 0; #endif @@ -271,7 +272,9 @@ int ui_dialog_do_gadgets(UI_DIALOG * dlg, d_event *event) tmp = dlg->gadget; do { - if (!is_under_another_window( CurWindow, tmp )) // won't be a necessary check when the rval is set properly + // If it is under another dialog, that dialog's handler would have returned 1 for mouse events. + // Key events are handled in a priority depending on the window ordering. + //if (!is_under_another_window( CurWindow, tmp )) { UI_DIALOG *curwindow_save=CurWindow; diff --git a/ui/keypad.c b/ui/keypad.c index 22435ec90..2f70905ac 100644 --- a/ui/keypad.c +++ b/ui/keypad.c @@ -95,7 +95,7 @@ void ui_pad_activate( UI_DIALOG * dlg, int x, int y ) bw = 56; bh = 30; - gr_set_current_canvas( dlg->canvas ); + ui_dialog_set_current_canvas( dlg ); ui_draw_box_in( x, y, x+(bw*4)+10 + 200, y+(bh*5)+45 ); x += 5;