Change the core internal event dispatch to use a BWinEvent structure
authorDaniel Dunbar <daniel@zuster.org>
Sun, 23 Mar 2003 22:52:11 +0000 (22:52 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 23 Mar 2003 22:52:11 +0000 (22:52 +0000)
instead of passing seperate arguments. For when we want to pass 'richer'
events around.

source/blender/include/BIF_mywindow.h
source/blender/include/BIF_space.h
source/blender/src/editscreen.c
source/blender/src/mywindow.c
source/blender/src/spacetypes.c

index 1e581b3dc4b09cf5a24c09b91b9ab52bf2f61eb4..c16098f1f1780903dea18da6f253e4a04bedcd74 100644 (file)
@@ -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);
 
 /*---*/
 
index 7d3deec1be94b30b60516ff55a674850da226fdd..6f102e11deb1739a315a620d31c65ba856dab48b 100644 (file)
@@ -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);
 
index 4f4cd263c15e291119e844fc78d8ff395d82bd1c..0672a3f7977ab796d7126c13214640029a20b382 100644 (file)
@@ -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;
index de91299a50db209779ba105da2dfd90e1c121a1d..fd09a4623f431cbf18f6a7a82551268043179890 100644 (file)
 
 #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);
index 9a9fa755ae2be944628370d3fc29f64ca80b6510..2eb923896d2319f37bb20122d08bd960097f169d 100644 (file)
@@ -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);
        }
 }