2.5
authorTon Roosendaal <ton@blender.org>
Fri, 26 Dec 2008 19:07:31 +0000 (19:07 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 26 Dec 2008 19:07:31 +0000 (19:07 +0000)
- Added 3d cursor operator (no exec, waiting for vector property!)
- Added default editor callbacks, for the poll() function.

Example:

   ot->poll= ED_operator_view3d_active;

I'll add later more, per module, such as OBJECT_active, which
can be called without WM active

source/blender/editors/include/ED_screen.h
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_outliner/outliner.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/windowmanager/intern/wm_event_system.c

index 414921950c33ba15cbf24c1c0c9bdd020719f860..1f3d156d0b2ab513545a0e46d488e7636e0d446d 100644 (file)
@@ -84,6 +84,17 @@ int          ED_operator_screenactive(struct bContext *C);
 int            ED_operator_screen_mainwinactive(struct bContext *C);
 int            ED_operator_areaactive(struct bContext *C);
 
+int            ED_operator_view3d_active(struct bContext *C);
+int            ED_operator_timeline_active(struct bContext *C);
+int            ED_operator_outliner_active(struct bContext *C);
+int            ED_operator_file_active(struct bContext *C);
+int            ED_operator_action_active(struct bContext *C);
+int            ED_operator_buttons_active(struct bContext *C);
+int            ED_operator_node_active(struct bContext *C);
+int            ED_operator_ipo_active(struct bContext *C);
+int            ED_operator_sequencer_active(struct bContext *C);
+
+
 /* default keymaps, bitflags */
 #define ED_KEYMAP_UI           1
 #define ED_KEYMAP_VIEW2D       2
index 1846ea3972d64f1d326f5ec1ded7de7e7408b213..6dfb99397f733cdcec068d12f37fcebfffc8e2f7 100644 (file)
@@ -75,6 +75,66 @@ int ED_operator_screen_mainwinactive(bContext *C)
        return 1;
 }
 
+static int ed_spacetype_test(bContext *C, int type)
+{
+       if(ED_operator_areaactive(C)) {
+               SpaceLink *sl= (SpaceLink *)CTX_wm_space_data(C);
+               return sl && (sl->spacetype == type);
+       }
+       return 0;
+}
+
+int ED_operator_view3d_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_VIEW3D);
+}
+
+int ED_operator_timeline_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_TIME);
+}
+
+int ED_operator_outliner_active(bContext *C)
+{
+       if(ed_spacetype_test(C, SPACE_OOPS)) {
+               SpaceOops *so= (SpaceOops *)CTX_wm_space_data(C);
+               return so->spacetype == SO_OUTLINER;
+       }
+       return 0;
+}
+
+int ED_operator_file_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_FILE);
+}
+
+int ED_operator_action_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_ACTION);
+}
+
+int ED_operator_buttons_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_BUTS);
+}
+
+int ED_operator_node_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_NODE);
+}
+
+int ED_operator_ipo_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_IPO);
+}
+
+int ED_operator_sequencer_active(bContext *C)
+{
+       return ed_spacetype_test(C, SPACE_SEQ);
+}
+
+
+
 /* *************************** action zone operator ************************** */
 
 /* operator state vars used:  
index e3a0999ebf572a9e0b70bd7568165e8be45c6bcf..5c6f25b841c3e29874b3e248c5c3a9e2b84365d9 100644 (file)
@@ -2155,7 +2155,7 @@ void OUTLINER_OT_activate_click(wmOperatorType *ot)
        
        ot->invoke= outliner_activate_click;
        
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_outliner_active;
 }
 
 
index 8b7da3e24dc2128cdadc1613c057cf86408cfddc..1cee3dcf2a14cd7299ccc4528731aca70088d682 100644 (file)
@@ -407,7 +407,7 @@ void VIEW3D_OT_viewrotate(wmOperatorType *ot)
        /* api callbacks */
        ot->invoke= viewrotate_invoke;
        ot->modal= viewrotate_modal;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 }
 
 /* ************************ viewmove ******************************** */
@@ -482,7 +482,7 @@ void VIEW3D_OT_viewmove(wmOperatorType *ot)
        /* api callbacks */
        ot->invoke= viewmove_invoke;
        ot->modal= viewmove_modal;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 }
 
 /* ************************ viewzoom ******************************** */
@@ -668,7 +668,7 @@ void VIEW3D_OT_viewzoom(wmOperatorType *ot)
        ot->invoke= viewzoom_invoke;
        ot->exec= viewzoom_exec;
        ot->modal= viewzoom_modal;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 
        RNA_def_property(ot->srna, "delta", PROP_INT, PROP_NONE);
 }
@@ -743,7 +743,7 @@ void VIEW3D_OT_viewhome(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= viewhome_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 
        RNA_def_property(ot->srna, "center", PROP_BOOLEAN, PROP_NONE);
 }
@@ -871,7 +871,7 @@ void VIEW3D_OT_viewcenter(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= viewcenter_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 }
 
 /* ********************* Changing view operator ****************** */
@@ -1093,7 +1093,7 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= viewnumpad_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
        ot->flag= OPTYPE_REGISTER;
 
        prop = RNA_def_property(ot->srna, "viewnum", PROP_ENUM, PROP_NONE);
@@ -1195,7 +1195,7 @@ void VIEW3D_OT_clipping(wmOperatorType *ot)
        ot->exec= view3d_clipping_exec;
        ot->modal= WM_border_select_modal;
 
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 
        /* rna */
        RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
@@ -1364,6 +1364,75 @@ void view3d_border_zoom(Scene *scene, ARegion *ar, View3D *v3d)
        smooth_view(NULL, NULL, NULL, new_ofs, NULL, &new_dist, NULL); // XXX
 }
 
+/* ***************** 3d cursor cursor op ******************* */
+
+/* mx my in region coords */
+static int set_3dcursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Scene *scene= CTX_data_scene(C);
+       ARegion *ar= CTX_wm_region(C);
+       View3D *v3d= (View3D *)CTX_wm_space_data(C);
+       float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3];
+       short mx, my, lr_click=0, mval[2];
+       short ctrl= 0; // XXX
+       
+       fp= give_cursor(scene, v3d);
+       
+       if(G.obedit && ctrl) lr_click= 1;
+       VECCOPY(oldcurs, fp);
+       
+       mx= event->x - ar->winrct.xmin;
+       my= event->y - ar->winrct.ymin;
+       project_short_noclip(ar, v3d, fp, mval);
+       
+       initgrabz(v3d, fp[0], fp[1], fp[2]);
+       
+       if(mval[0]!=IS_CLIPPED) {
+               
+               window_to_3d(ar, v3d, dvec, mval[0]-mx, mval[1]-my);
+               VecSubf(fp, fp, dvec);
+       }
+       else {
+               
+               dx= ((float)(mx-(ar->winx/2)))*v3d->zfac/(ar->winx/2);
+               dy= ((float)(my-(ar->winy/2)))*v3d->zfac/(ar->winy/2);
+               
+               fz= v3d->persmat[0][3]*fp[0]+ v3d->persmat[1][3]*fp[1]+ v3d->persmat[2][3]*fp[2]+ v3d->persmat[3][3];
+               fz= fz/v3d->zfac;
+               
+               fp[0]= (v3d->persinv[0][0]*dx + v3d->persinv[1][0]*dy+ v3d->persinv[2][0]*fz)-v3d->ofs[0];
+               fp[1]= (v3d->persinv[0][1]*dx + v3d->persinv[1][1]*dy+ v3d->persinv[2][1]*fz)-v3d->ofs[1];
+               fp[2]= (v3d->persinv[0][2]*dx + v3d->persinv[1][2]*dy+ v3d->persinv[2][2]*fz)-v3d->ofs[2];
+       }
+       
+       if(lr_click) {
+               // XXX          if(G.obedit->type==OB_MESH) add_click_mesh();
+               //              else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addvert_Nurb(0);
+               //              else if (G.obedit->type==OB_ARMATURE) addvert_armature();
+               VECCOPY(fp, oldcurs);
+       }
+       // XXX notifier for scene */
+       ED_region_tag_redraw(ar);
+       
+       /* prevent other mouse ops to fail */
+       return OPERATOR_PASS_THROUGH;
+}
+
+void VIEW3D_OT_cursor3d(wmOperatorType *ot)
+{
+       
+       /* identifiers */
+       ot->name= "Set 3D Cursor";
+       ot->idname= "VIEW3D_OT_cursor3d";
+       
+       /* api callbacks */
+       ot->invoke= set_3dcursor_invoke;
+       
+       ot->poll= ED_operator_view3d_active;
+       
+       /* rna later */
+
+}
 
 
 /* ************************* below the line! *********************** */
index a36a04cf6be30b057f71a83fe141b29bca5c66ad..962d36926cd6e2feb38b56af29c7fd63eebf64d5 100644 (file)
@@ -79,6 +79,7 @@ void VIEW3D_OT_viewhome(struct wmOperatorType *ot);
 void VIEW3D_OT_viewnumpad(struct wmOperatorType *ot);
 void VIEW3D_OT_viewcenter(struct wmOperatorType *ot);
 void VIEW3D_OT_clipping(struct wmOperatorType *ot);
+void VIEW3D_OT_cursor3d(struct wmOperatorType *ot);
 
 /* drawobject.c */
 void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag);
index 0e3e2c73fe91430362f4b039f915432a9f07b160..9aa931c35abf3b63fb93b2d5c1770cc8d954b05d 100644 (file)
@@ -72,12 +72,15 @@ void view3d_operatortypes(void)
        WM_operatortype_append(VIEW3D_OT_clipping);
        WM_operatortype_append(VIEW3D_OT_circle_select);
        WM_operatortype_append(VIEW3D_OT_smoothview);
+       WM_operatortype_append(VIEW3D_OT_cursor3d);
 }
 
 void view3d_keymap(wmWindowManager *wm)
 {
        ListBase *keymap= WM_keymap_listbase(wm, "View3D", SPACE_VIEW3D, 0);
        
+       WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0);
+       
        WM_keymap_verify_item(keymap, "VIEW3D_OT_viewrotate", MIDDLEMOUSE, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "VIEW3D_OT_viewmove", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
        WM_keymap_verify_item(keymap, "VIEW3D_OT_viewzoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
index 1d1bef89d202f3692870e564a32c55d61f8f0965..dd6899ea12f95622e6dbbfa587a6a63107a66a14 100644 (file)
@@ -679,49 +679,6 @@ void view3d_lasso_select(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][
        
 }
 
-/* mx my in region coords */
-void mouse_cursor(Scene *scene, ARegion *ar, View3D *v3d, short mx, short my)
-{
-       float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3];
-       short lr_click=0, mval[2];
-       short ctrl= 0; // XXX
-       
-       fp= give_cursor(scene, v3d);
-       
-       if(G.obedit && ctrl) lr_click= 1;
-       VECCOPY(oldcurs, fp);
-       
-       project_short_noclip(ar, v3d, fp, mval);
-
-       initgrabz(v3d, fp[0], fp[1], fp[2]);
-       
-       if(mval[0]!=IS_CLIPPED) {
-               
-               window_to_3d(ar, v3d, dvec, mval[0]-mx, mval[1]-my);
-               VecSubf(fp, fp, dvec);
-               
-       }
-       else {
-
-               dx= ((float)(mx-(ar->winx/2)))*v3d->zfac/(ar->winx/2);
-               dy= ((float)(my-(ar->winy/2)))*v3d->zfac/(ar->winy/2);
-               
-               fz= v3d->persmat[0][3]*fp[0]+ v3d->persmat[1][3]*fp[1]+ v3d->persmat[2][3]*fp[2]+ v3d->persmat[3][3];
-               fz= fz/v3d->zfac;
-               
-               fp[0]= (v3d->persinv[0][0]*dx + v3d->persinv[1][0]*dy+ v3d->persinv[2][0]*fz)-v3d->ofs[0];
-               fp[1]= (v3d->persinv[0][1]*dx + v3d->persinv[1][1]*dy+ v3d->persinv[2][1]*fz)-v3d->ofs[1];
-               fp[2]= (v3d->persinv[0][2]*dx + v3d->persinv[1][2]*dy+ v3d->persinv[2][2]*fz)-v3d->ofs[2];
-       }
-       
-       if(lr_click) {
-// XXX         if(G.obedit->type==OB_MESH) add_click_mesh();
-//             else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addvert_Nurb(0);
-//             else if (G.obedit->type==OB_ARMATURE) addvert_armature();
-               VECCOPY(fp, oldcurs);
-       }
-       
-}
 
 void deselectall(Scene *scene, View3D *v3d)    /* is toggle */
 {
@@ -1303,7 +1260,7 @@ void VIEW3D_OT_select(wmOperatorType *ot)
        
        /* api callbacks */
        ot->invoke= view3d_select_invoke;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 }
 
 /* ********************  border and circle ************************************** */
@@ -1671,7 +1628,7 @@ void VIEW3D_OT_borderselect(wmOperatorType *ot)
        ot->exec= view3d_borderselect_exec;
        ot->modal= WM_border_select_modal;
        
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
        
        /* rna */
        RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
@@ -1895,7 +1852,7 @@ void VIEW3D_OT_circle_select(wmOperatorType *ot)
        ot->invoke= WM_gesture_circle_invoke;
        ot->modal= WM_gesture_circle_modal;
        ot->exec= view3d_circle_select;
-       ot->poll= WM_operator_winactive;
+       ot->poll= ED_operator_view3d_active;
        
        RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
index 9b5b2cf621182d854fc1182a227153c0dec23cef..cfd3fbba7b5ec871f726c580c8f6638eaa7cb164 100644 (file)
@@ -298,7 +298,7 @@ void VIEW3D_OT_smoothview(wmOperatorType *ot)
        /* api callbacks */
        ot->invoke= view3d_smoothview_invoke;
        
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
 }
 
 /* ********************************** */
index eeda0226dd95d6c2fea0ec295ca627ec81f251cc..f37c901b842c1c50a40bf7588d11e213961a8c99 100644 (file)
@@ -481,6 +481,12 @@ static int wm_eventmatch(wmEvent *winevent, wmKeymapItem *kmi)
                else
                        kmitype= RIGHTMOUSE;
        }
+       if(kmitype==ACTIONMOUSE) {
+               if(U.flag & USER_LMOUSESELECT)
+                       kmitype= RIGHTMOUSE;
+               else
+                       kmitype= LEFTMOUSE;
+       }
        
        /* the matching rules */
        if(winevent->type!=kmitype) return 0;