2.5
authorTon Roosendaal <ton@blender.org>
Wed, 17 Dec 2008 17:33:45 +0000 (17:33 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 17 Dec 2008 17:33:45 +0000 (17:33 +0000)
Added screen-set notifier. Works for arrow keys now. For those who
know the messy old code, admire the simple 2-function call method
now :) Only context setting is messy a bit, that'll be solved.

Also: removed redundant code, and move freeing window handlers up
one level; windows can keep their handlers while screen switches.

source/blender/editors/include/ED_screen.h
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/windowmanager/intern/wm_init_exit.c

index 7b4dd41..2c0101f 100644 (file)
@@ -72,6 +72,7 @@ void  ED_screen_do_listen(struct wmWindow *win, struct wmNotifier *note);
 bScreen *ED_screen_duplicate(struct wmWindow *win, struct bScreen *sc);
 void   ED_screen_set_subwinactive(struct wmWindow *win, struct wmEvent *event);
 void   ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
+void   ED_screen_set(struct bContext *C, struct bScreen *sc);
 
 void   ED_operatortypes_screen(void);
 void   ED_keymap_screen(struct wmWindowManager *wm);
index 13c0f54..b325bb8 100644 (file)
@@ -1048,7 +1048,6 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
        for(sa= screen->areabase.first; sa; sa= sa->next)
                ED_area_exit(C, sa);
 
-       WM_event_remove_handlers(C, &window->handlers);
        C->window= prevwin;
 }
 
@@ -1153,3 +1152,31 @@ int ED_screen_area_active(const bContext *C)
        }       
        return 0;
 }
+
+/* operator call, WM + Window + screen already existed before */
+/* Do NOT call in area/region queues! */
+void ED_screen_set(bContext *C, bScreen *sc)
+{
+       
+       if(sc->full) {                          /* find associated full */
+               bScreen *sc1;
+               for(sc1= G.main->screen.first; sc1; sc1= sc1->id.next) {
+                       ScrArea *sa= sc1->areabase.first;
+                       if(sa->full==sc) {
+                               sc= sc1;
+                               break;
+                       }
+               }
+               if(sc1==NULL) printf("setscreen error\n");
+       }
+       
+       if (C->screen != sc) {
+               ED_screen_exit(C, C->window, C->screen);
+               C->window->screen= sc;
+               C->screen= sc;
+               
+               ED_screen_refresh(C->wm, C->window);
+               WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
+       }
+}
+
index 23f850e..615e655 100644 (file)
@@ -857,6 +857,49 @@ void ED_SCR_OT_frame_offset(wmOperatorType *ot)
        RNA_def_property(ot->srna, "delta", PROP_INT, PROP_NONE);
 }
 
+/* ************** switch screen operator ***************************** */
+
+
+/* function to be called outside UI context, or for redo */
+static int screen_set_exec(bContext *C, wmOperator *op)
+{
+       bScreen *screen= C->screen;
+       int delta= RNA_int_get(op->ptr, "delta");
+       
+       if(delta==1) {
+               screen= screen->id.next;
+               if(screen==NULL) screen= G.main->screen.first;
+       }
+       else if(delta== -1) {
+               screen= screen->id.prev;
+               if(screen==NULL) screen= G.main->screen.last;
+       }
+       else {
+               screen= NULL;
+       }
+       
+       if(screen) {
+               ED_screen_set(C, screen);
+               return OPERATOR_FINISHED;
+       }
+       return OPERATOR_CANCELLED;
+}
+
+void ED_SCR_OT_screen_set(wmOperatorType *ot)
+{
+       ot->name = "Set Screen";
+       ot->idname = "ED_SCR_OT_screen_set";
+       
+       ot->exec= screen_set_exec;
+       ot->poll= ED_operator_screenactive;
+       
+       /* rna */
+       RNA_def_property(ot->srna, "screen", PROP_POINTER, PROP_NONE);
+       RNA_def_property(ot->srna, "delta", PROP_INT, PROP_NONE);
+}
+
+
+
 /* ************** join area operator ********************************************** */
 
 /* operator state vars used:  
@@ -1312,7 +1355,8 @@ void ED_operatortypes_screen(void)
        WM_operatortype_append(ED_SCR_OT_area_rip);
        WM_operatortype_append(ED_SCR_OT_region_split);
        WM_operatortype_append(ED_SCR_OT_region_flip);
-               
+       WM_operatortype_append(ED_SCR_OT_screen_set);
+       
        /*frame changes*/
        WM_operatortype_append(ED_SCR_OT_frame_offset);
 
@@ -1332,10 +1376,13 @@ void ED_keymap_screen(wmWindowManager *wm)
        WM_keymap_verify_item(keymap, "ED_SCR_OT_area_split", EVT_ACTIONZONE, 0, 0, 0); /* action tria */
        WM_keymap_verify_item(keymap, "ED_SCR_OT_area_join", EVT_ACTIONZONE, 0, 0, 0);  /* action tria */ 
        WM_keymap_verify_item(keymap, "ED_SCR_OT_area_rip", RKEY, KM_PRESS, KM_ALT, 0);
+       RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_screen_set", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", 1);
+       RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_screen_set", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", -1);
 
         /* tests */
        RNA_enum_set(WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, 0, 0)->ptr, "dir", 'h');
        RNA_enum_set(WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "dir", 'v');
+                                                 
        /*frame offsets*/
        RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_frame_offset", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 10);
        RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_frame_offset", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", -10);
index 4d170ce..8727a9c 100644 (file)
@@ -167,14 +167,9 @@ 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) {
-                       ARegion *ar;
                        
                        C->window= win; /* needed by operator close callbacks */
                        WM_event_remove_handlers(C, &win->handlers);
-                       
-                       for(ar= win->screen->regionbase.first; ar; ar= ar->next)
-                               WM_event_remove_handlers(C, &ar->handlers);
-                       
                        ED_screen_exit(C, win, win->screen);
                }
        }