Cursor transform
ActivePublic

Authored by Campbell Barton (campbellbarton) on Jul 4 2014, 11:13 PM.
Tags
None
Subscribers
None
1diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
2index 41ff9b8..e7805ad 100644
3--- a/source/blender/editors/include/ED_transform.h
4+++ b/source/blender/editors/include/ED_transform.h
5@@ -98,6 +98,7 @@ enum TfmMode {
6​ #define CTX_NDOF (1 << 5)
7​ #define CTX_MOVIECLIP (1 << 6)
8​ #define CTX_MASK (1 << 7)
9+#define CTX_CURSOR (1 << 8)
10
11​ /* Standalone call to get the transformation center corresponding to the current situation
12​ * returns 1 if successful, 0 otherwise (usually means there's no selection)
13@@ -145,6 +146,7 @@ int BIF_countTransformOrientation(const struct bContext *C);
14​ #define P_CORRECT_UV (1 << 8)
15​ #define P_NO_DEFAULTS (1 << 10)
16​ #define P_NO_TEXSPACE (1 << 11)
17+#define P_CURSOR (1 << 12)
18
19​ void Transform_Properties(struct wmOperatorType *ot, int flags);
20
21diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
22index e3260db..8d425d2 100644
23--- a/source/blender/editors/space_view3d/view3d_edit.c
24+++ b/source/blender/editors/space_view3d/view3d_edit.c
25@@ -4435,7 +4435,7 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
26​ }
27​ }
28
29-static void view3d_cursor3d_update(bContext *C, const int *mval)
30+static void view3d_cursor3d_update(bContext *C, const int mval[2])
31​ {
32​ Scene *scene = CTX_data_scene(C);
33​ View3D *v3d = CTX_wm_view3d(C);
34@@ -4468,8 +4468,14 @@ static int view3d_cursor3d_modal(bContext *C, wmOperator *op, const wmEvent *eve
35
36​ switch (event->type) {
37​ case MOUSEMOVE:
38- view3d_cursor3d_update(C, event->mval);
39- break;
40+ {
41+ PointerRNA ptr;
42+ WM_operator_properties_create(&ptr, "TRANSFORM_OT_translate");
43+ RNA_boolean_set(&ptr, "use_cursor", true);
44+ WM_operator_name_call(C, "TRANSFORM_OT_translate", WM_OP_INVOKE_DEFAULT, &ptr);
45+
46+ return OPERATOR_FINISHED;
47+ }
48​ case LEFTMOUSE:
49​ return OPERATOR_FINISHED;
50​ }
51diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
52index 32ba4ba..2a259f7 100644
53--- a/source/blender/editors/transform/transform.c
54+++ b/source/blender/editors/transform/transform.c
55@@ -1457,6 +1457,9 @@ int transformEvent(TransInfo *t, const wmEvent *event)
56​ handled = true;
57​ }
58​ break;
59+ case LEFTMOUSE: /* XXX!!! - ONLY FOR TESTING */
60+ t->state = TRANS_CONFIRM;
61+ handled = true;
62​ case LEFTALTKEY:
63​ case RIGHTALTKEY:
64​ if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
65@@ -1833,8 +1836,6 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
66​ static void drawTransformPixel(const struct bContext *UNUSED(C), ARegion *ar, void *arg)
67​ {
68​ TransInfo *t = arg;
69- Scene *scene = t->scene;
70- Object *ob = OBACT;
71
72​ /* draw autokeyframing hint in the corner
73​ * - only draw if enabled (advanced users may be distracted/annoyed),
74@@ -1844,6 +1845,9 @@ static void drawTransformPixel(const struct bContext *UNUSED(C), ARegion *ar, vo
75​ if ((U.autokey_flag & AUTOKEY_FLAG_NOWARNING) == 0) {
76​ if (ar == t->ar) {
77​ if (t->flag & (T_OBJECT | T_POSE)) {
78+ Scene *scene = t->scene;
79+ Object *ob = OBACT;
80+
81​ if (ob && autokeyframe_cfra_can_key(scene, &ob->id)) {
82​ drawAutoKeyWarning(t, ar);
83​ }
84diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
85index ab0d977..b69198a 100644
86--- a/source/blender/editors/transform/transform_conversions.c
87+++ b/source/blender/editors/transform/transform_conversions.c
88@@ -317,6 +317,47 @@ static void createTransTexspace(TransInfo *t)
89​ copy_v3_v3(td->ext->isize, td->ext->size);
90​ }
91
92+static void createTransCursor(TransInfo *t)
93+{
94+ Scene *scene = t->scene;
95+ TransData *td;
96+ View3D *v3d = t->view;
97+ float *cursor;
98+ Object *ob;
99+
100+ ob = OBACT;
101+
102+ if (t->spacetype != SPACE_VIEW3D) {
103+ t->total = 0;
104+ return;
105+ }
106+
107+ ob = OBACT;
108+ cursor = ED_view3d_cursor3d_get(scene, v3d);
109+
110+ t->total = 1;
111+ td = t->data = MEM_callocN(sizeof(TransData), "TransTexspace");
112+ td->ext = t->ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
113+
114+ td->flag = TD_SELECTED;
115+ copy_v3_v3(td->center, cursor);
116+
117+ if (ob) {
118+ unit_m3(td->mtx);
119+ copy_m3_m4(td->axismtx, ob->obmat);
120+ normalize_m3(td->axismtx);
121+ pseudoinverse_m3_m3(td->smtx, td->mtx, PSEUDOINVERSE_EPSILON);
122+ }
123+ else {
124+ unit_m3(td->mtx);
125+ unit_m3(td->axismtx);
126+ unit_m3(td->smtx);
127+ }
128+
129+ td->loc = cursor;
130+ copy_v3_v3(td->iloc, td->loc);
131+}
132+
133​ /* ********************* edge (for crease) ***** */
134
135​ static void createTransEdge(TransInfo *t)
136@@ -5430,7 +5471,10 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
137​ /* early out when nothing happened */
138​ if (t->total == 0 || t->mode == TFM_DUMMY)
139​ return;
140-
141+
142+ if (t->options & CTX_CURSOR)
143+ return;
144+
145​ if (t->spacetype == SPACE_VIEW3D) {
146​ if (t->obedit) {
147​ if (canceled == 0) {
148@@ -6967,7 +7011,10 @@ void createTransData(bContext *C, TransInfo *t)
149​ Object *ob = OBACT;
150
151​ /* if tests must match recalcData for correct updates */
152- if (t->options & CTX_TEXTURE) {
153+ if (t->options & CTX_CURSOR) {
154+ createTransCursor(t);
155+ }
156+ else if (t->options & CTX_TEXTURE) {
157​ t->flag |= T_TEXTURE;
158​ createTransTexspace(t);
159​ }
160diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
161index 6eb8821..3212811 100644
162--- a/source/blender/editors/transform/transform_generics.c
163+++ b/source/blender/editors/transform/transform_generics.c
164@@ -956,7 +956,10 @@ static void recalcData_sequencer(TransInfo *t)
165​ void recalcData(TransInfo *t)
166​ {
167​ /* if tests must match createTransData for correct updates */
168- if (t->options & CTX_TEXTURE) {
169+ if (t->options & CTX_CURSOR) {
170+ /* pass */
171+ }
172+ else if (t->options & CTX_TEXTURE) {
173​ recalcData_objects(t);
174​ }
175​ else if (t->options & CTX_EDGE) {
176@@ -1138,6 +1141,12 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
177​ }
178​ }
179
180+ if (op && (prop = RNA_struct_find_property(op->ptr, "use_cursor")) && RNA_property_is_set(op->ptr, prop)) {
181+ if (RNA_property_boolean_get(op->ptr, prop)) {
182+ t->options |= CTX_CURSOR;
183+ }
184+ }
185+
186​ /* Assign the space type, some exceptions for running in different mode */
187​ if (sa == NULL) {
188​ /* background mode */
189diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
190index 7bdbbf7..905654c 100644
191--- a/source/blender/editors/transform/transform_ops.c
192+++ b/source/blender/editors/transform/transform_ops.c
193@@ -556,6 +556,10 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
194​ /*prop =*/ RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
195​ //RNA_def_property_flag(prop, PROP_HIDDEN);
196​ }
197+
198+ if (flags & P_CURSOR) {
199+ RNA_def_boolean(ot->srna, "use_cursor", 0, "Cursor", "");
200+ }
201​ }
202
203​ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
204@@ -575,7 +579,7 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
205
206​ RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
207
208- Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS);
209+ Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_CURSOR);
210​ }
211
212​ static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
Campbell Barton (campbellbarton) changed the title of this paste from untitled to Cursor transform.
Campbell Barton (campbellbarton) updated the paste's language from autodetect to diff.