From 510e2d584062e43aab22a16aade93ce332ce003c Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 23 Mar 2003 22:52:11 +0000 Subject: [PATCH] Change the core internal event dispatch to use a BWinEvent structure instead of passing seperate arguments. For when we want to pass 'richer' events around. --- source/blender/include/BIF_mywindow.h | 30 +++++++++++++++++-- source/blender/include/BIF_space.h | 3 +- source/blender/src/editscreen.c | 43 +++++++++++++++------------ source/blender/src/mywindow.c | 29 +++++------------- source/blender/src/spacetypes.c | 4 +-- 5 files changed, 64 insertions(+), 45 deletions(-) diff --git a/source/blender/include/BIF_mywindow.h b/source/blender/include/BIF_mywindow.h index 1e581b3dc4b..c16098f1f17 100644 --- a/source/blender/include/BIF_mywindow.h +++ b/source/blender/include/BIF_mywindow.h @@ -40,6 +40,14 @@ struct rcti; /*---*/ +typedef struct BWinEvent { + unsigned short event; + short val; + char ascii; +} BWinEvent; + +/*---*/ + int mywinget(void); void mywinclose(int winid); void mywinposition(int winid, @@ -47,9 +55,27 @@ void mywinposition(int winid, int ymin, int ymax); /*---*/ + /** Test if there are events available on a BWin queue. + * + * @param winid The ID of the window to query. + * @return True if there is an event available for _qread'ing. + */ int bwin_qtest(int winid); -unsigned short bwin_qread(int winid, short *val_r, char *ascii_r); -void bwin_qadd(int winid, unsigned short event, short val, char ascii); + + /** Read an event off of the BWin queue (if available). + * + * @param winid The ID of the window to read from. + * @param event_r A pointer to return the event in. + * @return True if an event was read and @a event_r filled. + */ +int bwin_qread(int winid, BWinEvent *event_r); + + /** Add an event to the BWin queue. + * + * @param winid The ID of the window to add to. + * @param event A pointer to copy the event from. + */ +void bwin_qadd(int winid, BWinEvent *event); /*---*/ diff --git a/source/blender/include/BIF_space.h b/source/blender/include/BIF_space.h index 7d3deec1be9..6f102e11deb 100644 --- a/source/blender/include/BIF_space.h +++ b/source/blender/include/BIF_space.h @@ -37,6 +37,7 @@ struct ListBase; struct ScrArea; struct SpaceButs; struct View2D; +struct BWinEvent; #define REMAKEIPO 1 #define OOPS_TEST 2 @@ -44,7 +45,7 @@ struct View2D; void scrarea_do_windraw (struct ScrArea *sa); void scrarea_do_winchange (struct ScrArea *sa); -void scrarea_do_winhandle (struct ScrArea *sa, unsigned short event, short val, char ascii); +void scrarea_do_winhandle (struct ScrArea *sa, struct BWinEvent *evt); void scrarea_do_headdraw (struct ScrArea *sa); void scrarea_do_headchange (struct ScrArea *sa); diff --git a/source/blender/src/editscreen.c b/source/blender/src/editscreen.c index 4f4cd263c15..0672a3f7977 100644 --- a/source/blender/src/editscreen.c +++ b/source/blender/src/editscreen.c @@ -392,7 +392,11 @@ static void addqueue_ext(short win, unsigned short event, short val, char ascii) if (win<4 || !areawinar[win]) { printf("bad call to addqueue: %d (%d, %d)\n", win, event, val); } else { - bwin_qadd(win, event, val, ascii); + BWinEvent evt; + evt.event= event; + evt.val= val; + evt.ascii= ascii; + bwin_qadd(win, &evt); } } @@ -419,21 +423,18 @@ static void scrollheader(ScrArea *area); static void scrarea_dispatch_header_events(ScrArea *sa) { ScrArea *tempsa; + BWinEvent evt; short do_redraw=0, do_change=0; areawinset(sa->headwin); - while(bwin_qtest(sa->headwin)) { - char ascii; - short val; - unsigned short event= bwin_qread(sa->headwin, &val, &ascii); + while(bwin_qread(sa->headwin, &evt)) { + if(evt.val) { + if( uiDoBlocks(&curarea->uiblocks, evt.event)!=UI_NOTHING ) evt.event= 0; - if(val) { - if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0; - - switch(event) { + switch(evt.event) { case UI_BUT_EVENT: - do_headerbuttons(val); + do_headerbuttons(evt.val); break; case LEFTMOUSE: @@ -460,7 +461,7 @@ static void scrarea_dispatch_header_events(ScrArea *sa) break; default: if (winqueue_break == 0) { - scrarea_do_winhandle(sa, event, val, ascii); + scrarea_do_winhandle(sa, &evt); if (winqueue_break == 0) areawinset(sa->headwin); } } @@ -481,25 +482,22 @@ static void scrarea_dispatch_header_events(ScrArea *sa) static void scrarea_dispatch_events(ScrArea *sa) { ScrArea *tempsa; + BWinEvent evt; short do_redraw=0, do_change=0; if(sa!=curarea || sa->win!=mywinget()) areawinset(sa->win); - while(bwin_qtest(sa->win)) { - char ascii; - short val; - unsigned short event= bwin_qread(sa->win, &val, &ascii); - - if(event==REDRAW) { + while(bwin_qread(sa->win, &evt)) { + if(evt.event==REDRAW) { do_redraw= 1; } - else if(event==CHANGED) { + else if(evt.event==CHANGED) { sa->win_swap= 0; do_change= 1; do_redraw= 1; } else { - scrarea_do_winhandle(sa, event, val, ascii); + scrarea_do_winhandle(sa, &evt); } if(winqueue_break) return; @@ -900,6 +898,13 @@ void screenmain(void) has_input= val; } + /* If the main window is active, find the current active ScrArea + * underneath the mouse cursor, updating the headers & cursor for + * the appropriate internal window if things have changed. + * + * If the main window is not active, deactivate the internal + * window. + */ if (has_input) { ScrArea *newactarea; int newactwin; diff --git a/source/blender/src/mywindow.c b/source/blender/src/mywindow.c index de91299a50d..fd09a4623f4 100644 --- a/source/blender/src/mywindow.c +++ b/source/blender/src/mywindow.c @@ -63,13 +63,6 @@ #include "winlay.h" - -typedef struct { - unsigned short event; - short val; - char ascii; -} QEvent; - typedef struct { struct bWindow *next, *prev; int id, pad; @@ -117,6 +110,8 @@ void mywindow_init_mainwin(Window *win, int orx, int ory, int sizex, int sizey) /* XXXXXXXXXXXXXXXX very hacky, not allowed to release * again after 2.24 + * + * Nah ha! And you thought you'd be in business that long! */ void mywindow_build_and_set_renderwin(void) { @@ -145,26 +140,18 @@ int bwin_qtest(int winid) { return !BLI_gsqueue_is_empty(bwin_from_winid(winid)->qevents); } -unsigned short bwin_qread(int winid, short *val_r, char *ascii_r) +int bwin_qread(int winid, BWinEvent *evt_r) { if (bwin_qtest(winid)) { - QEvent evt; - BLI_gsqueue_pop(bwin_from_winid(winid)->qevents, &evt); - *val_r= evt.val; - *ascii_r= evt.ascii; - return evt.event; + BLI_gsqueue_pop(bwin_from_winid(winid)->qevents, evt_r); + return 1; } else { - *val_r= 0; return 0; } } -void bwin_qadd(int winid, unsigned short event, short val, char ascii) +void bwin_qadd(int winid, BWinEvent *evt) { - QEvent evt; - evt.event= event; - evt.val= val; - evt.ascii= ascii; - BLI_gsqueue_push(bwin_from_winid(winid)->qevents, &evt); + BLI_gsqueue_push(bwin_from_winid(winid)->qevents, evt); } /* ------------------------------------------------------------------------- */ @@ -383,7 +370,7 @@ int myswinopen(int parentid, int xmin, int xmax, int ymin, int ymax) win->xmax= xmax; win->ymax= ymax; - win->qevents= BLI_gsqueue_new(sizeof(QEvent)); + win->qevents= BLI_gsqueue_new(sizeof(BWinEvent)); Mat4One(win->viewmat); Mat4One(win->winmat); diff --git a/source/blender/src/spacetypes.c b/source/blender/src/spacetypes.c index 9a9fa755ae2..2eb923896d2 100644 --- a/source/blender/src/spacetypes.c +++ b/source/blender/src/spacetypes.c @@ -129,13 +129,13 @@ void scrarea_do_winchange(ScrArea *area) } } } -void scrarea_do_winhandle(ScrArea *area, unsigned short event, short val, char ascii) +void scrarea_do_winhandle(ScrArea *area, BWinEvent *evt) { SpaceType *st= spacetype_from_code(area->spacetype); areawinset(area->win); if (st->winhandle) { - st->winhandle(event, val, ascii); + st->winhandle(evt->event, evt->val, evt->ascii); } }