2.5
authorTon Roosendaal <ton@blender.org>
Wed, 10 Dec 2008 13:56:54 +0000 (13:56 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 10 Dec 2008 13:56:54 +0000 (13:56 +0000)
Cleanup in area/region management

- more intelligence in area management for adding handlers and setting
  data correct. Space/Region type callbacks only have to do own things.

- added option for adding default handlers to areas/regions. (flag in
  type definition)

- ensured that region-types store the minsizes for regions.

- added boundbox check for handlers; note that it accepts pointer to
  boundbox, because handlers don't get reset on area-resizing or
  view changes. Example: view2d handlers use mask rect.

- handlers get now added on correct context levels (example frame change
  also worked in header)

- removed ->refresh() callback. Context refreshing is Listener.

- the ->init() is being called on all WM level actions, also after a
  file read, moving areas, re-opening areas etc.

- fixed bug: crash on exit was caused by cleaning up Screen too late.

- UI_view2d_size_update() removed from draw callback, is init()

- regions now store (winx, winy) subwindow size.

16 files changed:
source/blender/blenkernel/BKE_screen.h
source/blender/blenloader/intern/readfile.c
source/blender/editors/include/ED_screen.h
source/blender/editors/interface/interface_regions.c
source/blender/editors/screen/area.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/spacetypes.c
source/blender/editors/space_outliner/space_outliner.c
source/blender/editors/space_time/space_time.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesdna/DNA_screen_types.h
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_window.c
source/blender/windowmanager/wm_event_system.h

index 49e6b20725da5b44973a741ee6e558d933b9f213..77179122b6e4ecc78b618d4a99c939e439f5ca9a 100644 (file)
@@ -52,16 +52,15 @@ typedef struct SpaceType {
        int                             spaceid;                                        /* unique space identifier */
        int                             iconid;                                         /* icon lookup for menus */
        
-       /* calls init too */
+       /* initial allocation, after this WM will call init() too */
        struct SpaceLink        *(*new)(void);
        /* not free spacelink itself */
        void            (*free)(struct SpaceLink *);
        
-       /* init is to cope with internal contextual changes, adds handlers,
-        * creates/sets screarea regions */
+       /* init is to cope with file load, screen (size) changes, check handlers */
        void            (*init)(struct wmWindowManager *, struct ScrArea *);
-       /* refresh is for external bContext changes */
-       void            (*refresh)(struct bContext *, struct ScrArea *);
+       /* Listeners can react to bContext changes */
+       void            (*listener)(struct ARegion *, struct wmNotifier *);
        
        /* after a spacedata copy, an init should result in exact same situation */
        struct SpaceLink        *(*duplicate)(struct SpaceLink *);
@@ -76,6 +75,9 @@ typedef struct SpaceType {
        
        /* read and write... */
        
+       /* default keymaps to add */
+       int                     keymapflag;
+       
 } SpaceType;
 
 /* region types are also defined using spacetypes_init, via a callback */
@@ -85,18 +87,24 @@ typedef struct ARegionType {
        
        int                     regionid;       /* unique identifier within this space */
        
-       void            (*init)(const struct bContext *, struct ARegion *);             /* add handlers, stuff you only do once or on area/region changes */
-       void            (*refresh)(const struct bContext *, struct ARegion *);  /* refresh to match contextual changes */
-       void            (*draw)(const struct bContext *, struct ARegion *);             /* draw entirely, windowsize changes should be handled here */
-       
+       /* add handlers, stuff you only do once or on area/region type/size changes */
+       void            (*init)(struct wmWindowManager *, struct ARegion *);
+       /* draw entirely, view changes should be handled here */
+       void            (*draw)(const struct bContext *, struct ARegion *);     
+       /* contextual changes should be handled here */
        void            (*listener)(struct ARegion *, struct wmNotifier *);
+       
        void            (*free)(struct ARegion *);
 
        /* register operator types on startup */
        void            (*operatortypes)(void);
-       /* add default items to keymap */
+       /* add own items to keymap */
        void            (*keymap)(struct wmWindowManager *);
        
+       /* hardcoded constraints, smaller than these values region is not visible */
+       int                     minsizex, minsizey;
+       /* default keymaps to add */
+       int                     keymapflag;
 } ARegionType;
 
 
index 71ef913e488e57f75e847836722577a1d6da8687..fd56709c822889dec2e78673620cc3f742420819 100644 (file)
@@ -5050,7 +5050,6 @@ static void do_versions_windowmanager_2_50(bScreen *screen)
                        ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                        BLI_addtail(&sa->regionbase, ar);
                        ar->regiontype= RGN_TYPE_HEADER;
-                       ar->minsize= HEADERY;   // DNA_screen_types.h
                        if(sa->headertype==1)
                                ar->alignment= RGN_ALIGN_BOTTOM;
                        else
index fe832baf7c90a5827e49fa0dc8ac7266369e28e5..4161da135e43a5b1eebcac1890a98c779f0b53b1 100644 (file)
@@ -40,12 +40,11 @@ struct SpaceType;
 struct AreagionType;
 
 /* regions */
-void   ED_region_initialize(struct wmWindowManager *wm, struct wmWindow *win, struct ARegion *ar);
 void   ED_region_do_listen(ARegion *ar, struct wmNotifier *note);
 void   ED_region_do_draw(struct bContext *C, ARegion *ar);
-void   ED_region_do_refresh(struct bContext *C, ARegion *ar);
 void   ED_region_exit(struct bContext *C, ARegion *ar);
 void   ED_region_pixelspace(const struct bContext *C, ARegion *ar);
+void   ED_region_init(struct bContext *C, ARegion *ar);
 ARegion *ED_region_copy(ARegion *ar);
 
 /* spaces */
@@ -75,6 +74,10 @@ int          ED_operator_screenactive(struct bContext *C);
 int            ED_operator_screen_mainwinactive(struct bContext *C);
 int            ED_operator_areaactive(struct bContext *C);
 
+/* default keymaps, bitflags */
+#define ED_KEYMAP_UI           1
+#define ED_KEYMAP_VIEW2D       2
+#define ED_KEYMAP_MARKERS      4
 
 #endif /* ED_SCREEN_H */
 
index 2154236cc59ccbd2ef560a0ac62cf65090e9c3b1..251db907bf4217cc6600e0f599232b8887871610 100644 (file)
@@ -350,6 +350,9 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
        ar->winrct.xmax= x2;
        ar->winrct.ymax= y2;
 
+       /* adds subwindow */
+       ED_region_init(C, ar);
+       
        /* notify change and redraw */
        WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
@@ -663,6 +666,9 @@ uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *
 
        block->flag |= UI_BLOCK_LOOP|UI_BLOCK_MOVEMOUSE_QUIT;
 
+       /* adds subwindow */
+       ED_region_init(C, ar);
+       
        /* notify change and redraw */
        WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
index c959e1da17dd0174add62c8f197dbff7aa4eeaa9..7b85a7c655631b7a10c9ba6360ef815e94e012d2 100644 (file)
@@ -50,7 +50,9 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "UI_interface.h"
 #include "UI_resources.h"
+#include "UI_view2d.h"
 
 #ifndef DISABLE_PYTHON
 #include "BPY_extern.h"
@@ -108,13 +110,9 @@ void ED_region_do_listen(ARegion *ar, wmNotifier *note)
                case WM_NOTE_WINDOW_REDRAW:
                case WM_NOTE_AREA_REDRAW:
                case WM_NOTE_REGION_REDRAW:
-                       ar->do_draw= 1;
-                       break;
                case WM_NOTE_GESTURE_REDRAW:
-                       ar->do_draw= 1;
-                       break;
                case WM_NOTE_SCREEN_CHANGED:
-                       ar->do_draw= ar->do_refresh= 1;
+                       ar->do_draw= 1;
                        break;
                default:
                        if(ar->type->listener)
@@ -177,21 +175,6 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
        ar->do_draw= 0;
 }
 
-void ED_region_do_refresh(bContext *C, ARegion *ar)
-{
-       ARegionType *at= ar->type;
-
-       /* refresh can be called before window opened */
-       if(ar->swinid)
-               wm_subwindow_set(C->window, ar->swinid);
-       
-       if (at->refresh) {
-               at->refresh(C, ar);
-       }
-       
-       ar->do_refresh= 0;
-}
-
 /* *************************************************************** */
 
 /* dir is direction to check, not the splitting edge direction! */
@@ -207,6 +190,8 @@ static int rct_fits(rcti *rect, char dir, int size)
 
 static void region_rect_recursive(ARegion *ar, rcti *remainder)
 {
+       int prefsizex, prefsizey;
+       
        if(ar==NULL)
                return;
        
@@ -215,8 +200,8 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
        if(ar->next==NULL)
                ar->alignment= RGN_ALIGN_NONE;
        
-       if(ar->size<ar->minsize)
-               ar->size= ar->minsize;
+       prefsizex= ar->type->minsizex;
+       prefsizey= ar->type->minsizey;
        
        /* hidden is user flag */
        if(ar->flag & RGN_FLAG_HIDDEN);
@@ -233,46 +218,46 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
        }
        else if(ar->alignment==RGN_ALIGN_TOP || ar->alignment==RGN_ALIGN_BOTTOM) {
                
-               if( rct_fits(remainder, 'v', ar->minsize) < 0 ) {
+               if( rct_fits(remainder, 'v', prefsizey) < 0 ) {
                        ar->flag |= RGN_FLAG_TOO_SMALL;
                }
                else {
-                       int fac= rct_fits(remainder, 'v', ar->size);
+                       int fac= rct_fits(remainder, 'v', prefsizey);
 
                        if(fac < 0 )
-                               ar->size += fac;
+                               prefsizey += fac;
                        
                        ar->winrct= *remainder;
                        
                        if(ar->alignment==RGN_ALIGN_TOP) {
-                               ar->winrct.ymin= ar->winrct.ymax - ar->size;
+                               ar->winrct.ymin= ar->winrct.ymax - prefsizey;
                                remainder->ymax= ar->winrct.ymin-1;
                        }
                        else {
-                               ar->winrct.ymax= ar->winrct.ymin + ar->size;
+                               ar->winrct.ymax= ar->winrct.ymin + prefsizey;
                                remainder->ymin= ar->winrct.ymax+1;
                        }
                }
        }
        else if(ar->alignment==RGN_ALIGN_LEFT || ar->alignment==RGN_ALIGN_RIGHT) {
                
-               if( rct_fits(remainder, 'h', ar->minsize) < 0 ) {
+               if( rct_fits(remainder, 'h', prefsizex) < 0 ) {
                        ar->flag |= RGN_FLAG_TOO_SMALL;
                }
                else {
-                       int fac= rct_fits(remainder, 'h', ar->size);
+                       int fac= rct_fits(remainder, 'h', prefsizex);
                        
                        if(fac < 0 )
-                               ar->size += fac;
+                               prefsizex += fac;
                        
                        ar->winrct= *remainder;
                        
                        if(ar->alignment==RGN_ALIGN_RIGHT) {
-                               ar->winrct.xmin= ar->winrct.xmax - ar->size;
+                               ar->winrct.xmin= ar->winrct.xmax - prefsizex;
                                remainder->xmax= ar->winrct.xmin-1;
                        }
                        else {
-                               ar->winrct.xmax= ar->winrct.xmin + ar->size;
+                               ar->winrct.xmax= ar->winrct.xmin + prefsizex;
                                remainder->xmin= ar->winrct.xmax+1;
                        }
                }
@@ -282,7 +267,7 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
                ar->winrct= *remainder;
                
                if(ar->alignment==RGN_ALIGN_HSPLIT) {
-                       if( rct_fits(remainder, 'h', ar->size) > 4) {
+                       if( rct_fits(remainder, 'h', prefsizex) > 4) {
                                ar->winrct.xmax= (remainder->xmin+remainder->xmax)/2;
                                remainder->xmin= ar->winrct.xmax+1;
                        }
@@ -291,7 +276,7 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
                        }
                }
                else {
-                       if( rct_fits(remainder, 'v', ar->size) > 4) {
+                       if( rct_fits(remainder, 'v', prefsizey) > 4) {
                                ar->winrct.ymax= (remainder->ymin+remainder->ymax)/2;
                                remainder->ymin= ar->winrct.ymax+1;
                        }
@@ -300,6 +285,9 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
                        }
                }
        }
+       /* for speedup */
+       ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
+       ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
        
        region_rect_recursive(ar->next, remainder);
 }
@@ -356,8 +344,8 @@ void area_azone_initialize(ScrArea *sa)
        }
 }
 
-/* used for area and screen regions */
-void ED_region_initialize(wmWindowManager *wm, wmWindow *win, ARegion *ar)
+/* used for area initialize below */
+static void region_subwindow(wmWindowManager *wm, wmWindow *win, ARegion *ar)
 {
        if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
                if(ar->swinid)
@@ -370,7 +358,25 @@ void ED_region_initialize(wmWindowManager *wm, wmWindow *win, ARegion *ar)
                wm_subwindow_position(win, ar->swinid, &ar->winrct);
 }
 
-/* called in screen_refresh, or screens_init */
+static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int flag)
+{
+       /* note, add-handler checks if it already exists */
+       
+       if(flag & ED_KEYMAP_UI) {
+               UI_add_region_handlers(handlers);
+       }
+       if(flag & ED_KEYMAP_VIEW2D) {
+               ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
+               WM_event_add_keymap_handler(handlers, keymap);
+       }
+       if(flag & ED_KEYMAP_MARKERS) {
+               ListBase *keymap= WM_keymap_listbase(wm, "Markers", 0, 0);
+               WM_event_add_keymap_handler(handlers, keymap);
+       }
+}
+
+
+/* called in screen_refresh, or screens_init, also area size changes */
 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
 {
        ARegion *ar;
@@ -378,28 +384,52 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
        
        /* set typedefinitions */
        sa->type= BKE_spacetype_from_id(sa->spacetype);
+       
        if(sa->type==NULL) {
                sa->spacetype= SPACE_VIEW3D;
                sa->type= BKE_spacetype_from_id(sa->spacetype);
        }
        
-       area_calc_totrct(sa, win->sizex, win->sizey);
+       for(ar= sa->regionbase.first; ar; ar= ar->next)
+               ar->type= ED_regiontype_from_id(sa->type, ar->regiontype);
        
-       /* regiontype callback, it should create/verify the amount of subregions with minsizes etc */
-       if(sa->type->init)
-               sa->type->init(wm, sa);
+       /* area sizes */
+       area_calc_totrct(sa, win->sizex, win->sizey);
        
        /* region rect sizes */
        rect= sa->totrct;
        region_rect_recursive(sa->regionbase.first, &rect);
        
-       /* region windows */
-       for(ar= sa->regionbase.first; ar; ar= ar->next)
-               ED_region_initialize(wm, win, ar);
+       /* default area handlers */
+       ed_default_handlers(wm, &sa->handlers, sa->type->keymapflag);
+       /* checks spacedata, adds own handlers */
+       if(sa->type->init)
+               sa->type->init(wm, sa);
        
+       /* region windows, default and own handlers */
+       for(ar= sa->regionbase.first; ar; ar= ar->next) {
+               region_subwindow(wm, win, ar);
+               
+               /* default region handlers */
+               ed_default_handlers(wm, &ar->handlers, ar->type->keymapflag);
+
+               if(ar->type->init)
+                       ar->type->init(wm, ar);
+               
+       }
        area_azone_initialize(sa);
 }
 
+/* externally called for floating regions like menus */
+void ED_region_init(bContext *C, ARegion *ar)
+{
+//     ARegionType *at= ar->type;
+       
+       /* refresh can be called before window opened */
+       region_subwindow(C->wm, C->window, ar);
+       
+}
+
 
 ARegion *ED_region_copy(ARegion *ar)
 {
index e2ac4d9064579944986b1874fb0a89f0e6ecfada..94f907ee06b6a737834636a61271819627d7bf15 100644 (file)
@@ -878,7 +878,6 @@ void ED_screen_draw(wmWindow *win)
 void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
 {
        ScrArea *sa;
-       ARegion *ar;
        rcti winrct= {0, win->sizex-1, 0, win->sizey-1};
        
        screen_test_scale(win->screen, win->sizex, win->sizey);
@@ -889,16 +888,11 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
                wm_subwindow_position(win, win->screen->mainwin, &winrct);
        
        for(sa= win->screen->areabase.first; sa; sa= sa->next) {
-               /* set spacetype and region callbacks */
-               /* sets subwindow */
+               /* set spacetype and region callbacks, calls init() */
+               /* sets subwindows for regions, adds handlers */
                ED_area_initialize(wm, win, sa);
        }
 
-       for(ar= win->screen->regionbase.first; ar; ar= ar->next) {
-               /* set subwindow */
-               ED_region_initialize(wm, win, ar);
-       }
-       
        if(G.f & G_DEBUG) printf("set screen\n");
        win->screen->do_refresh= 0;
 
@@ -942,7 +936,7 @@ void ED_area_exit(bContext *C, ScrArea *sa)
 
 void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
 {
-       wmWindow *prevwin= C->window;
+       wmWindow *prevwin= C?C->window:NULL;
        ScrArea *sa;
        ARegion *ar;
 
index 514a459df4fe2e60525e5bd2b6090ede6d4bcdc9..d3d0bfe38d8542268dff966525c674642d4a3193 100644 (file)
@@ -84,14 +84,21 @@ void ED_spacetypes_init(void)
 void ED_spacetypes_keymap(wmWindowManager *wm)
 {
        const ListBase *spacetypes;
-       SpaceType *type;
+       SpaceType *stype;
+       ARegionType *atype;
 
        ED_keymap_screen(wm);
        UI_view2d_keymap(wm);
 
        spacetypes = BKE_spacetypes_list();
-       for(type=spacetypes->first; type; type=type->next)
-               type->keymap(wm);
+       for(stype=spacetypes->first; stype; stype=stype->next) {
+               if(stype->keymap)
+                       stype->keymap(wm);
+               for(atype=stype->regiontypes.first; atype; atype=atype->next) {
+                       if(atype->keymap)
+                               atype->keymap(wm);
+               }
+       }
 }
 
 /* ****************************** space template *********************** */
@@ -119,12 +126,6 @@ static void xxx_init(wmWindowManager *wm, ScrArea *sa)
        /* add types to regions */
 }
 
-/* spacetype; external context changed */
-static void xxx_refresh(bContext *C, ScrArea *sa)
-{
-       
-}
-
 static SpaceLink *xxx_duplicate(SpaceLink *sl)
 {
        
@@ -151,7 +152,6 @@ void ED_spacetype_xxx(void)
        st.new= xxx_new;
        st.free= xxx_free;
        st.init= xxx_init;
-       st.refresh= xxx_refresh;
        st.duplicate= xxx_duplicate;
        st.operatortypes= xxx_operatortypes;
        st.keymap= xxx_keymap;
index 558767ce97eab9f6300753b1edf5f94448cba3c3..29a849541b21991ddc3bcbd60136ce4bda5ee6b9 100644 (file)
@@ -331,6 +331,12 @@ static void rna_table_cell_func(void *userdata, int row, int col, rcti *rct, uiB
                rna_but(cell, rct, block);
 }
 
+static void outliner_main_area_init(wmWindowManager *wm, ARegion *ar)
+{
+       UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
+
+}
+
 static void outliner_main_area_draw(const bContext *C, ARegion *ar)
 {
        uiTable *table;
@@ -349,10 +355,8 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
        glClearColor(col[0], col[1], col[2], 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        
-       awidth= width= ar->winrct.xmax - ar->winrct.xmin + 1;
-       aheight= height= ar->winrct.ymax - ar->winrct.ymin + 1;
-       
-       UI_view2d_size_update(v2d, awidth, aheight);
+       awidth= width= ar->winx;
+       aheight= height= ar->winy;
        
        /* create table */
        cell.space= soutliner;
@@ -437,6 +441,7 @@ static void outliner_main_area_free(ARegion *ar)
 
 /* ************************ header outliner area region *********************** */
 
+
 static void outliner_header_area_draw(const bContext *C, ARegion *ar)
 {
        SpaceOops *soutliner= C->area->spacedata.first;
@@ -492,30 +497,6 @@ static void outliner_free(SpaceLink *sl)
 
 /* spacetype; init callback */
 static void outliner_init(wmWindowManager *wm, ScrArea *sa)
-{
-       ARegion *ar;
-       
-       /* add types to regions, check handlers */
-       for(ar= sa->regionbase.first; ar; ar= ar->next) {
-               
-               ar->type= ED_regiontype_from_id(sa->type, ar->regiontype); 
-
-               if(ar->handlers.first==NULL) {
-                       ListBase *keymap;
-                       
-                       /* XXX fixme, should be smarter */
-                       
-                       UI_add_region_handlers(&ar->handlers);
-                       
-                       keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
-                       WM_event_add_keymap_handler(&ar->handlers, keymap);
-
-               }
-       }
-}
-
-/* spacetype; context changed */
-static void outliner_refresh(bContext *C, ScrArea *sa)
 {
        
 }
@@ -543,7 +524,6 @@ void ED_spacetype_outliner(void)
        st->new= outliner_new;
        st->free= outliner_free;
        st->init= outliner_init;
-       st->refresh= outliner_refresh;
        st->duplicate= outliner_duplicate;
        st->operatortypes= outliner_operatortypes;
        st->keymap= outliner_keymap;
@@ -551,7 +531,9 @@ void ED_spacetype_outliner(void)
        /* regions: main window */
        art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
        art->regionid = RGN_TYPE_WINDOW;
+       art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
        
+       art->init= outliner_main_area_init;
        art->draw= outliner_main_area_draw;
        art->free= outliner_main_area_free;
        BLI_addhead(&st->regiontypes, art);
@@ -559,12 +541,13 @@ void ED_spacetype_outliner(void)
        /* regions: header */
        art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
        art->regionid = RGN_TYPE_HEADER;
+       art->minsizey= HEADERY;
+       art->keymapflag= ED_KEYMAP_UI;
        
        art->draw= outliner_header_area_draw;
        art->free= outliner_header_area_free;
        BLI_addhead(&st->regiontypes, art);
        
-       
        BKE_spacetype_register(st);
 }
 
index 51466e229440b080513f9dd8b4d91ee6f0ae96da..a8fc955c485a400d1194ae082fde2cf1cf6da4ce 100644 (file)
@@ -103,31 +103,31 @@ static void time_draw_sfra_efra(const bContext *C, SpaceTime *stime, ARegion *ar
        fdrawline(PEFRA, v2d->cur.ymin, PEFRA, v2d->cur.ymax);
 }
 
-static void time_main_area_init(const bContext *C, ARegion *ar)
+/* add handlers, stuff you only do once or on area/region changes */
+static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
-       /* add handlers, stuff you only do once or on area/region changes */
+       ListBase *keymap;
+       
+       UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
+       
+       /* own keymap */
+       keymap= WM_keymap_listbase(wm, "TimeLine", SPACE_TIME, 0);      /* XXX weak? */
+       WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 }
 
-static void time_main_area_refresh(const bContext *C, ARegion *ar)
-{
-       /* refresh to match contextual changes */
-}
 
 static void time_main_area_draw(const bContext *C, ARegion *ar)
 {
-       /* draw entirely, windowsize changes should be handled here */
+       /* draw entirely, view changes should be handled here */
        SpaceTime *stime= C->area->spacedata.first;
        View2D *v2d= &ar->v2d;
        View2DGrid *grid;
        View2DScrollers *scrollers;
        float col[3];
-       int unit, winx, winy;
-       
-       // XXX this should become stored in regions too...
-       winx= ar->winrct.xmax - ar->winrct.xmin + 1;
-       winy= ar->winrct.ymax - ar->winrct.ymin + 1;
+       int unit;
        
-       UI_view2d_size_update(v2d, winx, winy);
+       /* XXX can be removed */
+       UI_view2d_size_update(v2d, ar->winx, ar->winy);
 
        /* clear and setup matrix */
        UI_GetThemeColor3fv(TH_BACK, col);
@@ -141,7 +141,7 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
 
        /* grid */
        unit= (stime->flag & TIME_DRAWFRAMES)? V2D_UNIT_FRAMES: V2D_UNIT_SECONDS;
-       grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_CLAMP, winx, winy);
+       grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_CLAMP, ar->winx, ar->winy);
        UI_view2d_grid_draw(C, v2d, grid, (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS));
        UI_view2d_grid_free(grid);
 
@@ -163,11 +163,12 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
 
 static void time_main_area_listener(ARegion *ar, wmNotifier *wmn)
 {
-       /* draw entirely, windowsize changes should be handled here */
+       /* context changes */
 }
 
 /* ************************ header time area region *********************** */
 
+
 static void time_header_area_draw(const bContext *C, ARegion *ar)
 {
        float col[3];
@@ -231,36 +232,10 @@ static void time_free(SpaceLink *sl)
 
 /* spacetype; init callback in ED_area_initialize() */
 /* init is called to (re)initialize an existing editor (file read, screen changes) */
+/* validate spacedata, add own area level handlers */
 static void time_init(wmWindowManager *wm, ScrArea *sa)
 {
-       ARegion *ar;
-       
-       /* add types to regions, check handlers */
-       for(ar= sa->regionbase.first; ar; ar= ar->next) {
-               
-               ar->type= ED_regiontype_from_id(sa->type, ar->regiontype);
-               
-               if(ar->handlers.first==NULL) {
-                       ListBase *keymap;
-                       
-                       /* XXX fixme, should be smarter */
-                       
-                       UI_add_region_handlers(&ar->handlers);
-                       
-                       keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
-                       WM_event_add_keymap_handler(&ar->handlers, keymap);
-                       
-                       /* own keymap */
-                       keymap= WM_keymap_listbase(wm, "TimeLine", sa->spacetype, 0);
-                       WM_event_add_keymap_handler(&ar->handlers, keymap);
-               }
-       }
-}
 
-/* spacetype; context changed */
-static void time_refresh(bContext *C, ScrArea *sa)
-{
-       
 }
 
 static SpaceLink *time_duplicate(SpaceLink *sl)
@@ -284,30 +259,31 @@ void ED_spacetype_time(void)
        st->new= time_new;
        st->free= time_free;
        st->init= time_init;
-       st->refresh= time_refresh;
        st->duplicate= time_duplicate;
        st->operatortypes= time_operatortypes;
-       st->keymap= time_keymap;
+       st->keymap= NULL;
        
        /* regions: main window */
        art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
        art->regionid = RGN_TYPE_WINDOW;
-
+       art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_MARKERS;
+       
        art->init= time_main_area_init;
-       art->refresh= time_main_area_refresh;
        art->draw= time_main_area_draw;
        art->listener= time_main_area_listener;
+       art->keymap= time_keymap;
        BLI_addhead(&st->regiontypes, art);
        
        /* regions: header */
        art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
        art->regionid = RGN_TYPE_HEADER;
+       art->minsizey= HEADERY;
+       art->keymapflag= ED_KEYMAP_UI;
        
        art->draw= time_header_area_draw;
        art->free= time_header_area_free;
        BLI_addhead(&st->regiontypes, art);
-       
-       
+               
        BKE_spacetype_register(st);
 }
 
index a9e3a382fbe5d90678ceb4f2f48ccb208592a35d..03a30e96e57d02eb21ccba7536c3f6fe38197155 100644 (file)
@@ -121,19 +121,7 @@ static void view3d_free(SpaceLink *sl)
 /* spacetype; init callback */
 static void view3d_init(struct wmWindowManager *wm, ScrArea *sa)
 {
-       ARegion *ar;
-       
-       /* add types to regions, handlers */
-       for(ar= sa->regionbase.first; ar; ar= ar->next) {
-               ar->type= ED_regiontype_from_id(sa->type, ar->regiontype);
-               
-       }
-}
 
-/* spacetype; context changed */
-static void view3d_refresh(bContext *C, ScrArea *sa)
-{
-       
 }
 
 static SpaceLink *view3d_duplicate(SpaceLink *sl)
@@ -187,7 +175,6 @@ void ED_spacetype_view3d(void)
        st->new= view3d_new;
        st->free= view3d_free;
        st->init= view3d_init;
-       st->refresh= view3d_refresh;
        st->duplicate= view3d_duplicate;
        st->operatortypes= view3d_operatortypes;
        st->keymap= view3d_keymap;
@@ -201,10 +188,10 @@ void ED_spacetype_view3d(void)
        /* regions: header */
        art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
        art->regionid = RGN_TYPE_HEADER;
+       art->minsizey= HEADERY;
        
        BLI_addhead(&st->regiontypes, art);
        
-       
        BKE_spacetype_register(st);
 }
 
index 17b14db2b0877f6c0e12f90be3921c855e8998a5..abc1041d6fec6abf2eb1988cb41db1798951f5e0 100644 (file)
@@ -122,18 +122,18 @@ typedef struct ARegion {
        
        View2D v2d;                                     /* 2D-View scrolling/zoom info (most regions are 2d anyways) */
        rcti winrct;                            /* coordinates of region */
+       short winx, winy;                       /* size */
        
        short swinid;
        short regiontype;                       /* window, header, etc. identifier for drawing */
        short alignment;                        /* how it should split */
-       short size;                                     /* current split size in pixels */
-       short minsize;                          /* set by spacedata's region init */
        short flag;                                     /* hide, ... */
        
        float fsize;                            /* current split size in float */
        
-       int pad;
-       short do_draw, do_refresh;      /* cached notifier events */
+       short do_draw;                          /* cached notifier events */
+       short pad;
+       int pad1;
        
        struct ARegionType *type;       /* callbacks for this region type */
        
index 2f53545f5442457cde3668a06bd713135f7f4d26..08c6a786f696d5c799e237061982cbe9ff940197 100644 (file)
@@ -72,6 +72,9 @@ ListBase      *WM_keymap_listbase     (wmWindowManager *wm, const char *nameid,
 
 
 struct wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, ListBase *keymap);
+                                               /* boundbox, optional subwindow boundbox for offset */
+struct wmEventHandler *WM_event_add_keymap_handler_bb(ListBase *handlers, ListBase *keymap, rcti *bb, rcti *swinbb);
+
 void           WM_event_remove_keymap_handler(ListBase *handlers, ListBase *keymap);
 
 struct wmEventHandler *WM_event_add_ui_handler(bContext *C, ListBase *handlers,
index 94df7abfed97d86d09e0de492d7fd8210d908d4f..54fbbacfaaa49239a0e2d64d44fee286fc16da6d 100644 (file)
@@ -193,18 +193,12 @@ static int wm_draw_update_test_window(wmWindow *win)
                return 1;
 
        for(ar=win->screen->regionbase.first; ar; ar= ar->next) {
-               /* cached notifiers */
-               if(ar->do_refresh)
-                       return 1;
                if(ar->swinid && ar->do_draw)
                        return 1;
        }
 
        for(sa= win->screen->areabase.first; sa; sa= sa->next) {
                for(ar=sa->regionbase.first; ar; ar= ar->next) {
-                       /* cached notifiers */
-                       if(ar->do_refresh)
-                               return 1;
                        if(ar->swinid && ar->do_draw)
                                return 1;
                }
@@ -239,10 +233,6 @@ void wm_draw_update(bContext *C)
                                for(ar=sa->regionbase.first; ar; ar= ar->next) {
                                        C->region= ar;
                                        
-                                       /* cached notifiers */
-                                       if(ar->do_refresh)
-                                               ED_region_do_refresh(C, ar);
-                                       
                                        if(ar->swinid && ar->do_draw) {
                                                ED_region_do_draw(C, ar);
                                                area_do_draw= 1;
@@ -265,10 +255,6 @@ void wm_draw_update(bContext *C)
                        for(ar=win->screen->regionbase.first; ar; ar= ar->next) {
                                C->region= ar;
                                
-                               /* cached notifiers */
-                               if(ar->do_refresh)
-                                       ED_region_do_refresh(C, ar);
-                               
                                if(ar->swinid && ar->do_draw)
                                        ED_region_do_draw(C, ar);
 
@@ -386,7 +372,6 @@ static int wm_eventmatch(wmEvent *winevent, wmKeymapItem *kmi)
        if(kmi->keymodifier)
                if(winevent->keymodifier!=kmi->keymodifier) return 0;
        
-       /* optional boundbox */
        
        return 1;
 }
@@ -480,6 +465,20 @@ static int wm_event_always_pass(wmEvent *event)
        return (event->type == TIMER);
 }
 
+static int handler_boundbox_test(wmEventHandler *handler, wmEvent *event)
+{
+       if(handler->bbwin) {
+               if(handler->bblocal) {
+                       rcti rect= *handler->bblocal;
+                       BLI_translate_rcti(&rect, handler->bbwin->xmin, handler->bbwin->ymin);
+                       return BLI_in_rcti(&rect, event->x, event->y);
+               }
+               else 
+                       return BLI_in_rcti(handler->bbwin, event->x, event->y);
+       }
+       return 1;
+}
+
 static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
 {
        wmEventHandler *handler, *nexthandler;
@@ -491,36 +490,40 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
        for(handler= handlers->first; handler; handler= nexthandler) {
                nexthandler= handler->next;
 
-               /* modal+blocking handler */
-               if(handler->flag & WM_HANDLER_BLOCKING)
-                       action= WM_HANDLER_BREAK;
+               /* optional boundbox */
+               if(handler_boundbox_test(handler, event)) {
+               
+                       /* modal+blocking handler */
+                       if(handler->flag & WM_HANDLER_BLOCKING)
+                               action= WM_HANDLER_BREAK;
 
-               if(handler->keymap) {
-                       wmKeymapItem *kmi;
-                       
-                       for(kmi= handler->keymap->first; kmi; kmi= kmi->next) {
-                               if(wm_eventmatch(event, kmi)) {
-                                       /* if(event->type!=MOUSEMOVE)
-                                               printf("handle evt %d win %d op %s\n", event->type, C->window->winid, kmi->idname); */
-                                       
-                                       event->keymap_idname= kmi->idname;      /* weak, but allows interactive callback to not use rawkey */
-                                       
-                                       action= wm_handler_operator_call(C, handlers, handler, event);
-                                       if(action==WM_HANDLER_BREAK)  /* not wm_event_always_pass(event) here, it denotes removed handler */
-                                               break;
+                       if(handler->keymap) {
+                               wmKeymapItem *kmi;
+                               
+                               for(kmi= handler->keymap->first; kmi; kmi= kmi->next) {
+                                       if(wm_eventmatch(event, kmi)) {
+                                               /* if(event->type!=MOUSEMOVE)
+                                                       printf("handle evt %d win %d op %s\n", event->type, C->window->winid, kmi->idname); */
+                                               
+                                               event->keymap_idname= kmi->idname;      /* weak, but allows interactive callback to not use rawkey */
+                                               
+                                               action= wm_handler_operator_call(C, handlers, handler, event);
+                                               if(action==WM_HANDLER_BREAK)  /* not wm_event_always_pass(event) here, it denotes removed handler */
+                                                       break;
+                                       }
                                }
                        }
-               }
-               else if(handler->ui_handle) {
-                       action= wm_handler_ui_call(C, handler, event);
-               }
-               else {
-                       /* modal, swallows all */
-                       action= wm_handler_operator_call(C, handlers, handler, event);
-               }
+                       else if(handler->ui_handle) {
+                               action= wm_handler_ui_call(C, handler, event);
+                       }
+                       else {
+                               /* modal, swallows all */
+                               action= wm_handler_operator_call(C, handlers, handler, event);
+                       }
 
-               if(!wm_event_always_pass(event) && action==WM_HANDLER_BREAK)
-                       break;
+                       if(!wm_event_always_pass(event) && action==WM_HANDLER_BREAK)
+                               break;
+               }
                
        }
        return action;
@@ -671,6 +674,15 @@ wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, ListBase *keymap
        return handler;
 }
 
+wmEventHandler *WM_event_add_keymap_handler_bb(ListBase *handlers, ListBase *keymap, rcti *bblocal, rcti *bbwin)
+{
+       wmEventHandler *handler= WM_event_add_keymap_handler(handlers, keymap);
+       handler->bblocal= bblocal;
+       handler->bbwin= bbwin;
+       
+       return handler;
+}
+
 void WM_event_remove_keymap_handler(ListBase *handlers, ListBase *keymap)
 {
        wmEventHandler *handler;
index 3346f0607a90099d6767a1b406626dbbbd55334e..db37f0754a07802f28af54726f651ae47abdb3c2 100644 (file)
@@ -164,7 +164,6 @@ void WM_exit(bContext *C)
        /* modal handlers are on window level freed, others too? */
        if(C && C->wm) {
                for(win= C->wm->windows.first; win; win= win->next) {
-                       ScrArea *sa;
                        ARegion *ar;
                        
                        C->window= win; /* needed by operator close callbacks */
@@ -173,11 +172,7 @@ void WM_exit(bContext *C)
                        for(ar= win->screen->regionbase.first; ar; ar= ar->next)
                                WM_event_remove_handlers(C, &ar->handlers);
                        
-                       for(sa= win->screen->areabase.first; sa; sa= sa->next) {
-                               WM_event_remove_handlers(C, &sa->handlers);
-                               for(ar= sa->regionbase.first; ar; ar= ar->next) 
-                                       WM_event_remove_handlers(C, &ar->handlers);
-                       }
+                       ED_screen_exit(C, win, win->screen);
                }
        }
        wm_operatortype_free();
index 508fe21b0397327b728e34b45baf3cabe2f24b91..50263b8084b122de403326d69188020358834e1b 100644 (file)
@@ -82,11 +82,10 @@ static void wm_ghostwindow_destroy(wmWindow *win)
        }
 }
 
-/* including window itself */
+/* including window itself, C can be NULL. 
+   ED_screen_exit should have been called */
 void wm_window_free(bContext *C, wmWindow *win)
 {
-       ED_screen_exit(C, win, win->screen);
-       
        /* update context */
        if(C) {
                if(C->wm->windrawable==win)
@@ -98,8 +97,6 @@ void wm_window_free(bContext *C, wmWindow *win)
                if(C->screen==win->screen)
                        C->screen= NULL;
        }       
-
-       /* XXX free screens */
        
        if(win->eventstate) MEM_freeN(win->eventstate);
 
index 616703888796a28040a564bc97a164b5ba1bb623..d4dddf8e2228a576267239f6650bc0f2d97f9cab 100644 (file)
@@ -45,10 +45,12 @@ typedef struct wmEventHandler {
        /* keymap handler */
        ListBase *keymap;                       /* pointer to builtin/custom keymaps */
        
+       rcti *bblocal, *bbwin;          /* optional local and windowspace bb */
+       
        /* modal operator handler */
-       wmOperator *op;                         /* for derived/modal handlers */
-       struct ScrArea *op_area;        /* for derived/modal handlers */
-       struct ARegion *op_region;      /* for derived/modal handlers */
+       wmOperator *op;                                         /* for derived/modal handlers */
+       struct ScrArea *op_area;                        /* for derived/modal handlers */
+       struct ARegion *op_region;                      /* for derived/modal handlers */
 
        /* ui handler */
        wmUIHandlerFunc ui_handle;              /* callback receiving events */