Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_edit.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c238
1 files changed, 184 insertions, 54 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index bbcee0415f8..c07d9108993 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -239,9 +239,10 @@ typedef struct ViewOpsData {
float ofs[3], obofs[3];
float reverse, dist0;
float grid, far;
+ short axis_snap; /* view rotate only */
int origx, origy, oldx, oldy;
- int origkey;
+ int origkey; /* the key that triggered the operator */
} ViewOpsData;
@@ -289,7 +290,7 @@ static void viewops_data(bContext *C, wmOperator *op, wmEvent *event)
QUATCOPY(vod->oldquat, rv3d->viewquat);
vod->origx= vod->oldx= event->x;
vod->origy= vod->oldy= event->y;
- vod->origkey= event->type;
+ vod->origkey= event->type; /* the key that triggered the operator. */
/* lookup, we dont pass on v3d to prevent confusement */
vod->grid= v3d->grid;
@@ -357,11 +358,52 @@ static float snapquats[39][6] = {
{0.0, 0.0, 0.0, 1.0, 0, 0}
};
+enum {
+ VIEW_PASS= 0,
+ VIEW_APPLY,
+ VIEW_CONFIRM
+};
+
+/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
+#define VIEW_MODAL_CONFIRM 1 /* used for all view operations */
+#define VIEWROT_MODAL_AXIS_SNAP_ENABLE 2
+#define VIEWROT_MODAL_AXIS_SNAP_DISABLE 3
+
+
+/* called in transform_ops.c, on each regeneration of keymaps */
+void viewrotate_modal_keymap(wmWindowManager *wm)
+{
+ static EnumPropertyItem modal_items[] = {
+ {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Cancel", ""},
+
+ {VIEWROT_MODAL_AXIS_SNAP_ENABLE, "AXIS_SNAP_ENABLE", 0, "Enable Axis Snap", ""},
+ {VIEWROT_MODAL_AXIS_SNAP_DISABLE, "AXIS_SNAP_DISABLE", 0, "Enable Axis Snap", ""},
+
+ {0, NULL, 0, NULL, NULL}};
+
+ wmKeyMap *keymap= WM_modalkeymap_get(wm, "View3D Rotate Modal");
-static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
+ /* this function is called for each spacetype, only needs to add map once */
+ if(keymap) return;
+
+ keymap= WM_modalkeymap_add(wm, "View3D Rotate Modal", modal_items);
+
+ /* items for modal map */
+ WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+ WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+
+ WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_AXIS_SNAP_ENABLE);
+ WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_AXIS_SNAP_DISABLE);
+
+ /* assign map to operators */
+ WM_modalkeymap_assign(keymap, "VIEW3D_OT_rotate");
+
+}
+
+static void viewrotate_apply(ViewOpsData *vod, int x, int y)
{
RegionView3D *rv3d= vod->rv3d;
- int use_sel= 0; /* XXX */
+ int use_sel= U.uiflag & USER_ORBIT_SELECTION;
rv3d->view= 0; /* need to reset everytime because of view snapping */
@@ -462,7 +504,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
}
/* check for view snap */
- if (ctrl){
+ if (vod->axis_snap){
int i;
float viewmat[3][3];
@@ -496,23 +538,41 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
static int viewrotate_modal(bContext *C, wmOperator *op, wmEvent *event)
{
ViewOpsData *vod= op->customdata;
+ short event_code= VIEW_PASS;
/* execute the events */
- switch(event->type) {
- case MOUSEMOVE:
- viewrotate_apply(vod, event->x, event->y, event->ctrl);
- break;
+ if(event->type==MOUSEMOVE) {
+ event_code= VIEW_APPLY;
+ }
+ else if(event->type==EVT_MODAL_MAP) {
+ switch (event->val) {
+ case VIEW_MODAL_CONFIRM:
+ event_code= VIEW_CONFIRM;
+ break;
+ case VIEWROT_MODAL_AXIS_SNAP_ENABLE:
+ vod->axis_snap= TRUE;
+ event_code= VIEW_APPLY;
+ break;
+ case VIEWROT_MODAL_AXIS_SNAP_DISABLE:
+ vod->axis_snap= FALSE;
+ event_code= VIEW_APPLY;
+ break;
+ }
+ }
+ else if(event->type==vod->origkey && event->val==KM_RELEASE) {
+ event_code= VIEW_CONFIRM;
+ }
- default:
- /* origkey may be zero when invoked from a button */
- if(ELEM3(event->type, ESCKEY, LEFTMOUSE, RIGHTMOUSE) || (event->type==vod->origkey && event->val==0)) {
- request_depth_update(CTX_wm_region_view3d(C));
+ if(event_code==VIEW_APPLY) {
+ viewrotate_apply(vod, event->x, event->y);
+ }
+ else if (event_code==VIEW_CONFIRM) {
+ request_depth_update(CTX_wm_region_view3d(C));
- MEM_freeN(vod);
- op->customdata= NULL;
+ MEM_freeN(vod);
+ op->customdata= NULL;
- return OPERATOR_FINISHED;
- }
+ return OPERATOR_FINISHED;
}
return OPERATOR_RUNNING_MODAL;
@@ -541,19 +601,19 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
}
/* add temp handler */
- WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+ WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
}
-void VIEW3D_OT_viewrotate(wmOperatorType *ot)
+void VIEW3D_OT_rotate(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Rotate view";
ot->description = "Rotate the view.";
- ot->idname= "VIEW3D_OT_viewrotate";
+ ot->idname= "VIEW3D_OT_rotate";
/* api callbacks */
ot->invoke= viewrotate_invoke;
@@ -566,6 +626,33 @@ void VIEW3D_OT_viewrotate(wmOperatorType *ot)
/* ************************ viewmove ******************************** */
+
+/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
+
+/* called in transform_ops.c, on each regeneration of keymaps */
+void viewmove_modal_keymap(wmWindowManager *wm)
+{
+ static EnumPropertyItem modal_items[] = {
+ {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
+
+ {0, NULL, 0, NULL, NULL}};
+
+ wmKeyMap *keymap= WM_modalkeymap_get(wm, "View3D Move Modal");
+
+ /* this function is called for each spacetype, only needs to add map once */
+ if(keymap) return;
+
+ keymap= WM_modalkeymap_add(wm, "View3D Move Modal", modal_items);
+
+ /* items for modal map */
+ WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+ WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+
+ /* assign map to operators */
+ WM_modalkeymap_assign(keymap, "VIEW3D_OT_move");
+}
+
+
static void viewmove_apply(ViewOpsData *vod, int x, int y)
{
if(vod->rv3d->persp==V3D_CAMOB) {
@@ -596,24 +683,35 @@ static void viewmove_apply(ViewOpsData *vod, int x, int y)
static int viewmove_modal(bContext *C, wmOperator *op, wmEvent *event)
{
+
ViewOpsData *vod= op->customdata;
+ short event_code= VIEW_PASS;
/* execute the events */
- switch(event->type) {
- case MOUSEMOVE:
- viewmove_apply(vod, event->x, event->y);
- break;
+ if(event->type==MOUSEMOVE) {
+ event_code= VIEW_APPLY;
+ }
+ else if(event->type==EVT_MODAL_MAP) {
+ switch (event->val) {
+ case VIEW_MODAL_CONFIRM:
+ event_code= VIEW_CONFIRM;
+ break;
+ }
+ }
+ else if(event->type==vod->origkey && event->val==KM_RELEASE) {
+ event_code= VIEW_CONFIRM;
+ }
- default:
- /* origkey may be zero when invoked from a button */
- if(ELEM3(event->type, ESCKEY, LEFTMOUSE, RIGHTMOUSE) || (event->type==vod->origkey && event->val==0)) {
- request_depth_update(CTX_wm_region_view3d(C));
+ if(event_code==VIEW_APPLY) {
+ viewmove_apply(vod, event->x, event->y);
+ }
+ else if (event_code==VIEW_CONFIRM) {
+ request_depth_update(CTX_wm_region_view3d(C));
- MEM_freeN(vod);
- op->customdata= NULL;
+ MEM_freeN(vod);
+ op->customdata= NULL;
- return OPERATOR_FINISHED;
- }
+ return OPERATOR_FINISHED;
}
return OPERATOR_RUNNING_MODAL;
@@ -625,19 +723,19 @@ static int viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event)
viewops_data(C, op, event);
/* add temp handler */
- WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+ WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
}
-void VIEW3D_OT_viewmove(wmOperatorType *ot)
+void VIEW3D_OT_move(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Move view";
ot->description = "Move the view.";
- ot->idname= "VIEW3D_OT_viewmove";
+ ot->idname= "VIEW3D_OT_move";
/* api callbacks */
ot->invoke= viewmove_invoke;
@@ -650,6 +748,29 @@ void VIEW3D_OT_viewmove(wmOperatorType *ot)
/* ************************ viewzoom ******************************** */
+/* called in transform_ops.c, on each regeneration of keymaps */
+void viewzoom_modal_keymap(wmWindowManager *wm)
+{
+ static EnumPropertyItem modal_items[] = {
+ {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
+
+ {0, NULL, 0, NULL, NULL}};
+
+ wmKeyMap *keymap= WM_modalkeymap_get(wm, "View3D Zoom Modal");
+
+ /* this function is called for each spacetype, only needs to add map once */
+ if(keymap) return;
+
+ keymap= WM_modalkeymap_add(wm, "View3D Zoom Modal", modal_items);
+
+ /* items for modal map */
+ WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+ WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
+
+ /* assign map to operators */
+ WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom");
+}
+
static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my)
{
RegionView3D *rv3d= ar->regiondata;
@@ -758,23 +879,33 @@ static void viewzoom_apply(ViewOpsData *vod, int x, int y)
static int viewzoom_modal(bContext *C, wmOperator *op, wmEvent *event)
{
ViewOpsData *vod= op->customdata;
+ short event_code= VIEW_PASS;
/* execute the events */
- switch(event->type) {
- case MOUSEMOVE:
- viewzoom_apply(vod, event->x, event->y);
- break;
+ if(event->type==MOUSEMOVE) {
+ event_code= VIEW_APPLY;
+ }
+ else if(event->type==EVT_MODAL_MAP) {
+ switch (event->val) {
+ case VIEW_MODAL_CONFIRM:
+ event_code= VIEW_CONFIRM;
+ break;
+ }
+ }
+ else if(event->type==vod->origkey && event->val==KM_RELEASE) {
+ event_code= VIEW_CONFIRM;
+ }
- default:
- /* origkey may be zero when invoked from a button */
- if(ELEM3(event->type, ESCKEY, LEFTMOUSE, RIGHTMOUSE) || (event->type==vod->origkey && event->val==0)) {
- request_depth_update(CTX_wm_region_view3d(C));
+ if(event_code==VIEW_APPLY) {
+ viewzoom_apply(vod, event->x, event->y);
+ }
+ else if (event_code==VIEW_CONFIRM) {
+ request_depth_update(CTX_wm_region_view3d(C));
- MEM_freeN(vod);
- op->customdata= NULL;
+ MEM_freeN(vod);
+ op->customdata= NULL;
- return OPERATOR_FINISHED;
- }
+ return OPERATOR_FINISHED;
}
return OPERATOR_RUNNING_MODAL;
@@ -823,7 +954,7 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
viewops_data(C, op, event);
/* add temp handler */
- WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+ WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
}
@@ -925,7 +1056,7 @@ static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.
void VIEW3D_OT_view_all(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "View home";
+ ot->name= "View All";
ot->description = "View all objects in scene.";
ot->idname= "VIEW3D_OT_view_all";
@@ -1064,7 +1195,7 @@ void VIEW3D_OT_view_center(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "View center";
+ ot->name= "View Selected";
ot->description = "Move the view to the selection center.";
ot->idname= "VIEW3D_OT_view_center";
@@ -1628,7 +1759,7 @@ static int viewpersportho_exec(bContext *C, wmOperator *op)
void VIEW3D_OT_view_persportho(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "View persp/ortho";
+ ot->name= "View Persp/Ortho";
ot->description = "Switch the current view from perspective/orthographic.";
ot->idname= "VIEW3D_OT_view_persportho";
@@ -1850,8 +1981,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
// XXX notifier for scene */
ED_area_tag_redraw(CTX_wm_area(C));
- /* prevent other mouse ops to fail */
- return OPERATOR_PASS_THROUGH;
+ return OPERATOR_FINISHED;
}
void VIEW3D_OT_cursor3d(wmOperatorType *ot)
@@ -2339,7 +2469,7 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode)
if (use_sel) {
QuatConj(q1); /* conj == inv for unit quat */
- VecSubf(v3d->ofs, v3d->ofs, obofs);
+ VecSubf(rv3d->ofs, rv3d->ofs, obofs);
QuatMulVecf(q1, rv3d->ofs);
VecAddf(rv3d->ofs, rv3d->ofs, obofs);
}