2.5
- 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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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! *********************** */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/* ********************************** */
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user