[Bf-blender-cvs] [8d8f2e2] transform-manipulators: Support drawing arrow manipulators while translating
Julian Eisel
noreply at git.blender.org
Thu Oct 20 02:07:39 CEST 2016
Commit: 8d8f2e2e336838b70e3040de9249642a3e99e7b8
Author: Julian Eisel
Date: Thu Oct 20 02:04:58 2016 +0200
Branches: transform-manipulators
https://developer.blender.org/rB8d8f2e2e336838b70e3040de9249642a3e99e7b8
Support drawing arrow manipulators while translating
===================================================================
M source/blender/editors/space_view3d/view3d_transform_manipulators.c
M source/blender/windowmanager/manipulators/WM_manipulator_api.h
M source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
M source/blender/windowmanager/manipulators/intern/wm_manipulator.c
M source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c
===================================================================
diff --git a/source/blender/editors/space_view3d/view3d_transform_manipulators.c b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
index 8898d49..ece5819 100644
--- a/source/blender/editors/space_view3d/view3d_transform_manipulators.c
+++ b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
@@ -164,6 +164,23 @@ static void transform_manipulators_info_free(void *customdata)
/* init callback and helpers */
/**
+ * Custom handler for manipulator widgets
+ */
+static int transform_axis_manipulator_handler(
+ bContext *C, const wmEvent *UNUSED(event), wmManipulator *widget, const int UNUSED(flag))
+{
+ View3D *v3d = CTX_wm_view3d(C);
+ float origin[3];
+
+ /* update origin */
+ if (calculateTransformCenter(C, v3d->around, origin, NULL)) {
+ WM_manipulator_set_origin(widget, origin);
+ }
+
+ return OPERATOR_PASS_THROUGH;
+}
+
+/**
* Create and initialize a manipulator for \a axis.
*/
static void transform_axis_manipulator_init(TranformAxisManipulator *axis, wmManipulatorGroup *mgroup)
@@ -178,6 +195,7 @@ static void transform_axis_manipulator_init(TranformAxisManipulator *axis, wmMan
}
PointerRNA *ptr = WM_manipulator_set_operator(axis->manipulator, axis->op_name);
+ WM_manipulator_set_custom_handler(axis->manipulator, transform_axis_manipulator_handler);
if (RNA_struct_find_property(ptr, "constraint_axis")) {
RNA_boolean_set_array(ptr, "constraint_axis", axis->constraint);
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index 099ad7f..c2d194c 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -58,6 +58,9 @@ void WM_manipulator_delete(
void WM_manipulator_set_property(struct wmManipulator *, int slot, struct PointerRNA *ptr, const char *propname);
struct PointerRNA *WM_manipulator_set_operator(struct wmManipulator *, const char *opname);
+void WM_manipulator_set_custom_handler(
+ struct wmManipulator *manipulator,
+ int (*handler)(struct bContext *, const struct wmEvent *, struct wmManipulator *, const int));
void WM_manipulator_set_func_select(
struct wmManipulator *manipulator,
void (*select)(struct bContext *, struct wmManipulator *, const int action)); /* wmManipulatorSelectFunc */
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
index 6cdf982..5d5e401 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
@@ -32,6 +32,7 @@
#include "DNA_defs.h"
#include "DNA_listBase.h"
#include "DNA_userdef_types.h"
+#include "DNA_windowmanager_types.h"
#include "GPU_select.h"
@@ -39,6 +40,8 @@
#include "RNA_types.h"
+#include "WM_types.h"
+
#include "manipulator_library_intern.h"
#include "WM_manipulator_types.h"
#include "wm_manipulator_wmapi.h"
@@ -98,14 +101,13 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool UNUSED(sel
glPopMatrix();
}
-static void arrow_get_matrix(const ArrowManipulator *arrow, float r_mat[4][4])
+static void arrow_get_matrix(const ArrowManipulator *arrow, float r_rot[3][3], float r_mat[4][4])
{
const float up[3] = {0.0f, 0.0f, 1.0f};
- float rot[3][3];
- rotation_between_vecs_to_mat3(rot, up, arrow->direction);
+ rotation_between_vecs_to_mat3(r_rot, up, arrow->direction);
- copy_m4_m3(r_mat, rot);
+ copy_m4_m3(r_mat, r_rot);
copy_v3_v3(r_mat[3], arrow->manipulator.origin);
mul_mat3_m4_fl(r_mat, arrow->manipulator.scale);
}
@@ -113,10 +115,11 @@ static void arrow_get_matrix(const ArrowManipulator *arrow, float r_mat[4][4])
static void arrow_draw_intern(const ArrowManipulator *arrow, const bool select, const bool highlight)
{
float col[4];
+ float rot[3][3];
float mat[4][4];
manipulator_color_get(&arrow->manipulator, highlight, col);
- arrow_get_matrix(arrow, mat);
+ arrow_get_matrix(arrow, rot, mat);
glPushMatrix();
glMultMatrixf(mat);
@@ -128,6 +131,25 @@ static void arrow_draw_intern(const ArrowManipulator *arrow, const bool select,
glDisable(GL_BLEND);
glPopMatrix();
+
+ if (arrow->manipulator.interaction_data) {
+ ManipulatorInteraction *inter = arrow->manipulator.interaction_data;
+
+ copy_m4_m3(mat, rot);
+ copy_v3_v3(mat[3], inter->init_origin);
+ mul_mat3_m4_fl(mat, inter->init_scale);
+
+ glPushMatrix();
+ glMultMatrixf(mat);
+
+ glEnable(GL_BLEND);
+ glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
+ glTranslate3fv(arrow->manipulator.offset);
+ arrow_draw_geom(arrow, select);
+ glDisable(GL_BLEND);
+
+ glPopMatrix();
+ }
}
static void arrow_manipulator_render_3d_intersect(
@@ -143,6 +165,19 @@ static void arrow_manipulator_draw(const bContext *UNUSED(C), wmManipulator *man
arrow_draw_intern((ArrowManipulator *)manipulator, false, (manipulator->state & WM_MANIPULATOR_HIGHLIGHT) != 0);
}
+static int manipulator_arrow_invoke(bContext *UNUSED(C), const wmEvent *UNUSED(event), wmManipulator *manipulator)
+{
+ ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
+
+ inter->init_scale = manipulator->scale;
+// manipulator_arrow_get_final_pos(manipulator, inter->init_origin);
+ copy_v3_v3(inter->init_origin, manipulator->origin);
+
+ manipulator->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
/* -------------------------------------------------------------------- */
/** \name Arrow Manipulator API
*
@@ -154,6 +189,8 @@ wmManipulator *WM_arrow_manipulator_new(wmManipulatorGroup *mgroup, const char *
arrow->manipulator.draw = arrow_manipulator_draw;
arrow->manipulator.render_3d_intersection = arrow_manipulator_render_3d_intersect;
+ arrow->manipulator.invoke = manipulator_arrow_invoke;
+ arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE;
wm_manipulator_register(mgroup, &arrow->manipulator, idname);
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index eb63e7d..de93f68 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -207,6 +207,13 @@ PointerRNA *WM_manipulator_set_operator(wmManipulator *manipulator, const char *
return NULL;
}
+void WM_manipulator_set_custom_handler(
+ wmManipulator *manipulator,
+ int (*handler)(bContext *, const wmEvent *, wmManipulator *, const int))
+{
+ manipulator->handler = handler;
+}
+
/**
* \brief Set manipulator select callback.
*
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c b/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c
index 500092f..960a77f 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c
@@ -631,7 +631,7 @@ void wm_manipulatormap_set_active_manipulator(
if (ot) {
/* first activate the manipulator itself */
- if (manipulator->invoke && manipulator->handler) {
+ if (manipulator->invoke) {
manipulator->invoke(C, event, manipulator);
}
@@ -655,7 +655,7 @@ void wm_manipulatormap_set_active_manipulator(
}
}
else {
- if (manipulator->invoke && manipulator->handler) {
+ if (manipulator->invoke) {
manipulator->invoke(C, event, manipulator);
}
}
More information about the Bf-blender-cvs
mailing list