2.5
authorTon Roosendaal <ton@blender.org>
Wed, 3 Dec 2008 19:33:42 +0000 (19:33 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 3 Dec 2008 19:33:42 +0000 (19:33 +0000)
Fun commit for test: the Repeat Last option.
Only the split-area Operator is now added on stack, so that's the only
one that works. Just split an area, and press F4 to repeat it anywhere.

source/blender/editors/include/ED_screen.h
source/blender/editors/screen/area.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_time/time_ops.c
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_event_system.c

index a8e39f51ed469316b474f0c5bb7d1c85a86d37ea..2514c4c90fd8af24db52e2b75293a87cb5a6680b 100644 (file)
@@ -43,7 +43,7 @@ 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(struct bContext *C, ARegion *ar);
+void   ED_region_pixelspace(const struct bContext *C, ARegion *ar);
 
 /* spaces */
 void   ED_spacetypes_init(void);
index 62876cfbbf0b1afe7e29d7bda34b6d8e941b5a30..7a5fa0cb7278967347565b6289744513c5f0d09b 100644 (file)
@@ -90,7 +90,7 @@ static void region_draw_emboss(ARegion *ar)
        glDisable( GL_BLEND );
 }
 
-void ED_region_pixelspace(bContext *C, ARegion *ar)
+void ED_region_pixelspace(const bContext *C, ARegion *ar)
 {
        int width= ar->winrct.xmax-ar->winrct.xmin+1;
        int height= ar->winrct.ymax-ar->winrct.ymin+1;
index 881f7719e1e23ea89fafad7320abe6b195065d84..0066ee5736b687fb255e4cc15d9be61d6fd6c7d1 100644 (file)
@@ -678,7 +678,8 @@ typedef struct sAreaSplitData
        int origval;                    /* for move areas */
        int bigger, smaller;    /* constraints for moving new edge */
        int delta;                              /* delta move edge */
-       
+       int origmin, origsize;  /* to calculate fac, for property storage */
+
        ScrEdge *nedge;                 /* new edge */
        ScrArea *sarea;                 /* start area */
        ScrArea *narea;                 /* new area */
@@ -705,6 +706,8 @@ static int area_split_init(bContext *C, wmOperator *op)
        op->customdata= sd;
        
        sd->sarea= C->area;
+       sd->origsize= dir=='v' ? C->area->winx:C->area->winy;
+       sd->origmin = dir=='v' ? C->area->totrct.xmin:C->area->totrct.ymin;
        
        return 1;
 }
@@ -877,6 +880,7 @@ static int area_split_cancel(bContext *C, wmOperator *op)
 static int area_split_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
        sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
+       float fac;
        int dir;
 
        /* execute the events */
@@ -887,6 +891,9 @@ static int area_split_modal(bContext *C, wmOperator *op, wmEvent *event)
                        sd->delta= (dir == 'v')? event->x - sd->origval: event->y - sd->origval;
                        area_move_apply_do(C, sd->origval, sd->delta, dir, sd->bigger, sd->smaller);
                        
+                       fac= (dir == 'v') ? event->x-sd->origmin : event->y-sd->origmin;
+                       RNA_float_set(op->ptr, "fac", fac / (float)sd->origsize);
+                       
                        WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
                        break;
                        
@@ -920,7 +927,8 @@ void ED_SCR_OT_area_split(wmOperatorType *ot)
        ot->modal= area_split_modal;
        
        ot->poll= ED_operator_areaactive;
-
+       ot->flag= OPTYPE_REGISTER;
+       
        /* rna */
        prop= RNA_def_property(ot->srna, "dir", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_items(prop, prop_direction_items);
@@ -1210,6 +1218,33 @@ void ED_SCR_OT_area_join(wmOperatorType *ot)
        RNA_def_property_int_default(prop, -100);
 }
 
+/* ************** repeat last operator ***************************** */
+
+static int repeat_last_exec(bContext *C, wmOperator *op)
+{
+       wmOperator *lastop= C->wm->operators.last;
+       
+       if(lastop) {
+               printf("repeat %s\n", op->type->idname);
+               lastop->type->exec(C, lastop);
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+void ED_SCR_OT_repeat_last(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Repeat Last";
+       ot->idname= "ED_SCR_OT_repeat_last";
+       
+       /* api callbacks */
+       ot->exec= repeat_last_exec;
+       
+       ot->poll= ED_operator_screenactive;
+       
+}
+
 /* ************** border select operator (template) ***************************** */
 
 /* operator state vars used: (added by default WM callbacks)   
@@ -1276,6 +1311,7 @@ void ED_operatortypes_screen(void)
        /* generic UI stuff */
        WM_operatortype_append(ED_SCR_OT_cursor_type);
        WM_operatortype_append(ED_SCR_OT_actionzone);
+       WM_operatortype_append(ED_SCR_OT_repeat_last);
        
        /* screen tools */
        WM_operatortype_append(ED_SCR_OT_area_move);
@@ -1302,5 +1338,6 @@ void ED_keymap_screen(wmWindowManager *wm)
        WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_area_join", EVT_ACTIONZONE, 0, 0, 0);       /* action tria */ 
        WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_area_rip", RKEY, KM_PRESS, KM_ALT, 0);
 
+       WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_repeat_last", F4KEY, KM_PRESS, 0, 0);
 }
 
index 207804dae3e3ca69a4b9a424561e6bde13611893..86ff9d9b0abec1c8cd81889c875d6a9801c7a844 100644 (file)
@@ -85,7 +85,7 @@ static void change_frame_apply(bContext *C, wmOperator *op)
        if(cfra!=CFRA)
                CFRA= cfra;
        
-       WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
+       WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
        /* XXX: add WM_NOTE_TIME_CHANGED? */
 }
 
index 4a5407b2d66cd9d4c6dc1753308bc044eca71a3b..7c1532210d904db12e0d0299f9a0fc5f40b4b183 100644 (file)
@@ -75,8 +75,8 @@ void wm_operator_register(wmWindowManager *wm, wmOperator *op)
        int tot;
 
        if(op->ptr) {
-               MEM_freeN(op->ptr);
-               op->ptr= NULL;
+       //      MEM_freeN(op->ptr);
+       //      op->ptr= NULL;
        }
        
        BLI_addtail(&wm->operators, op);
index 265ee79131297d99e3bd00481d27c6e4f85224b7..201a7452bbc98d7e5367d199cf9e28fbdf6100de 100644 (file)
@@ -602,21 +602,14 @@ void WM_event_set_handler_flag(wmEventHandler *handler, int flag)
 
 wmEventHandler *WM_event_add_modal_handler(bContext *C, ListBase *handlers, wmOperator *op)
 {
-       /* debug test; operator not in registry */
-       if(op->type->flag & OPTYPE_REGISTER) {
-               printf("error: handler (%s) cannot be modal, was registered\n", op->type->idname);
-       }
-       else {
-               wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event handler");
-               handler->op= op;
-               handler->op_area= C->area;              /* means frozen screen context for modal handlers! */
-               handler->op_region= C->region;
-               
-               BLI_addhead(handlers, handler);
-               
-               return handler;
-       }
-       return NULL;
+       wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event handler");
+       handler->op= op;
+       handler->op_area= C->area;              /* means frozen screen context for modal handlers! */
+       handler->op_region= C->region;
+       
+       BLI_addhead(handlers, handler);
+       
+       return handler;
 }
 
 wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, ListBase *keymap)