2.5
authorTon Roosendaal <ton@blender.org>
Sun, 4 Jan 2009 19:17:34 +0000 (19:17 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 4 Jan 2009 19:17:34 +0000 (19:17 +0000)
Small cleanup in region-based cursor handling.
- callback was in spacetype, now in regiontype
- made screen listener catch ND_MODE notifier and
  call the active region cursor callback, if it's there.

source/blender/blenkernel/BKE_screen.h
source/blender/editors/screen/screen_edit.c
source/blender/editors/space_text/space_text.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/windowmanager/intern/wm_event_system.c

index ab91612defe7798dd50dd2d3addd452ff657904e..04b27f7bf3c057ef08bd091b15f3bcb2249dfd38 100644 (file)
@@ -75,8 +75,6 @@ typedef struct SpaceType {
        void            (*operatortypes)(void);
        /* add default items to WM keymap */
        void            (*keymap)(struct wmWindowManager *);
-       /* sets default cursor per region */
-       void            (*cursor)(struct wmWindow *win, struct ARegion *ar);
 
        /* return context data */
        int                     (*context)(const struct bContext *, const void *, struct bContextDataResult *);
@@ -111,7 +109,9 @@ typedef struct ARegionType {
        void            (*operatortypes)(void);
        /* add own items to keymap */
        void            (*keymap)(struct wmWindowManager *);
-       
+       /* allows default cursor per region */
+       void            (*cursor)(struct wmWindow *, struct ScrArea *, struct ARegion *ar);
+
        /* return context data */
        int                     (*context)(const struct bContext *, const void *, struct bContextDataResult *);
 
index 97f45ff05bf4e25ec8e283939d9d63fb4cfc422f..a838e833883411ae8f81371733eb404d32354153 100644 (file)
@@ -907,6 +907,24 @@ bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
        return newsc;
 }
 
+/* screen sets cursor based on swinid */
+static void region_cursor_set(wmWindow *win, int swinid)
+{
+       ScrArea *sa= win->screen->areabase.first;
+       
+       for(;sa; sa= sa->next) {
+               ARegion *ar= sa->regionbase.first;
+               for(;ar; ar= ar->next) {
+                       if(ar->swinid == swinid) {
+                               if(ar->type && ar->type->cursor)
+                                       ar->type->cursor(win, sa, ar);
+                               else
+                                       WM_cursor_set(win, CURSOR_STD);
+                               return;
+                       }
+               }
+       }
+}
 
 void ED_screen_do_listen(wmWindow *win, wmNotifier *note)
 {
@@ -919,6 +937,9 @@ void ED_screen_do_listen(wmWindow *win, wmNotifier *note)
                case NC_SCREEN:
                        if(note->action==NA_EDITED)
                                win->screen->do_draw= win->screen->do_refresh= 1;
+               case NC_SCENE:
+                       if(note->data==ND_MODE)
+                               region_cursor_set(win, note->swinid);                           
                        break;
        }
 }
@@ -1145,18 +1166,7 @@ void ED_screen_set_subwinactive(wmWindow *win, wmEvent *event)
                        screen_cursor_set(win, event);
                }
                else if(oldswin!=scr->subwinactive) {
-                       /* cursor space type switching */
-                       for(sa= scr->areabase.first; sa; sa= sa->next) {
-                               for(ar= sa->regionbase.first; ar; ar= ar->next) {
-                                       if(ar->swinid==scr->subwinactive) {
-                                               if(sa->type->cursor)
-                                                       sa->type->cursor(win, ar);
-                                               else 
-                                                       WM_cursor_set(win, CURSOR_STD);
-                                       }
-                               }
-                                       
-                       }
+                       region_cursor_set(win, scr->subwinactive);
                }
        }
 }
index 14caafe722ee3b605615df91dcdb292f0d64ec0c..4187bd13cb1179dad77cc97e699933a0e5b688fe 100644 (file)
@@ -157,12 +157,9 @@ static void text_operatortypes(void)
        
 }
 
-static void text_cursor(wmWindow *win, ARegion *ar)
+static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
 {
-       if(ar->regiontype==RGN_TYPE_WINDOW)
-               WM_cursor_set(win, BC_TEXTEDITCURSOR);
-       else
-               WM_cursor_set(win, CURSOR_STD);
+       WM_cursor_set(win, BC_TEXTEDITCURSOR);
 }
 
 static void text_keymap(struct wmWindowManager *wm)
@@ -216,7 +213,6 @@ void ED_spacetype_text(void)
        st->init= text_init;
        st->duplicate= text_duplicate;
        st->operatortypes= text_operatortypes;
-       st->cursor= text_cursor;
        st->keymap= text_keymap;
        
        /* regions: main window */
@@ -226,6 +222,7 @@ void ED_spacetype_text(void)
        art->draw= text_main_area_draw;
        art->listener= text_main_area_listener;
        art->keymapflag= ED_KEYMAP_VIEW2D;
+       art->cursor= text_cursor;
 
        BLI_addhead(&st->regiontypes, art);
        
index 9ca07e15e010245d080d9fb132b8f42e3fbf106c..507a4d9735f6e8bded54dab964a5f07287726e18 100644 (file)
@@ -271,6 +271,19 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
        }
 }
 
+/* concept is to retrieve cursor type context-less */
+static void view3d_main_area_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
+{
+       Scene *scene= win->screen->scene;
+
+       if(scene->obedit) {
+               WM_cursor_set(win, CURSOR_EDIT);
+       }
+       else {
+               WM_cursor_set(win, CURSOR_STD);
+       }
+}
+
 /* add handlers, stuff you only do once or on area/region changes */
 static void view3d_header_area_init(wmWindowManager *wm, ARegion *ar)
 {
@@ -391,6 +404,7 @@ void ED_spacetype_view3d(void)
        art->draw= view3d_main_area_draw;
        art->init= view3d_main_area_init;
        art->listener= view3d_main_area_listener;
+       art->cursor= view3d_main_area_cursor;
        BLI_addhead(&st->regiontypes, art);
        
        /* regions: header */
index caa4731a5244f86c33897f70935db6946a28d572..843137cbec1ccac13f9998f9f56a4bc28d626190 100644 (file)
@@ -867,7 +867,7 @@ void wm_event_do_handlers(bContext *C)
                                
                                /* XXX to solve, here screen handlers? */
                                if(!wm_event_always_pass(event))
-                                       ED_screen_set_subwinactive(win, event); /* state variables in screen */
+                                       ED_screen_set_subwinactive(win, event); /* state variables in screen, cursors */
                                
                                for(sa= win->screen->areabase.first; sa; sa= sa->next) {
                                        if(wm_event_always_pass(event) || wm_event_prev_inside_i(event, &sa->totrct)) {