[Bf-blender-cvs] [6060185] temp_widgets_update_tagging: Port UV transform manipulator to new update system
Julian Eisel
noreply at git.blender.org
Wed May 11 00:14:24 CEST 2016
Commit: 60601853edc932a8e11cc0ddbdc52bacdf24dd06
Author: Julian Eisel
Date: Tue May 10 23:56:15 2016 +0200
Branches: temp_widgets_update_tagging
https://developer.blender.org/rB60601853edc932a8e11cc0ddbdc52bacdf24dd06
Port UV transform manipulator to new update system
Greatly reduces number of operatations happening on re-draw.
===================================================================
M source/blender/editors/include/ED_transform.h
M source/blender/editors/space_image/space_image.c
M source/blender/editors/transform/transform_manipulator.c
M source/blender/editors/transform/transform_manipulator2d.c
===================================================================
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 72f757c..37c6902 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -170,8 +170,10 @@ void WIDGETGROUP_manipulator_draw_prepare(const struct bContext *C, struct wmWid
void WIDGETGROUP_object_manipulator_init(const struct bContext *C, struct wmWidgetGroup *wgroup);
int WIDGETGROUP_object_manipulator_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype);
-void WIDGETGROUP_manipulator2d_init(const struct bContext *C, struct wmWidgetGroup *wgroup);
int WIDGETGROUP_manipulator2d_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype);
+void WIDGETGROUP_manipulator2d_init(const struct bContext *C, struct wmWidgetGroup *wgroup);
+void WIDGETGROUP_manipulator2d_refresh(const struct bContext *C, struct wmWidgetGroup *wgroup);
+void WIDGETGROUP_manipulator2d_draw_prepare(const struct bContext *C, struct wmWidgetGroup *wgroup);
/* Snapping */
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 91ddd07..8182df4 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -592,10 +592,12 @@ static void image_widgets(void)
wmWidgetMapType *wmaptype = WM_widgetmaptype_ensure(&wmap_params);
- WM_widgetgrouptype_register_ptr(
+ WM_widgetgrouptype_register_ptr_update(
NULL, wmaptype,
WIDGETGROUP_manipulator2d_poll,
WIDGETGROUP_manipulator2d_init,
+ WIDGETGROUP_manipulator2d_refresh,
+ WIDGETGROUP_manipulator2d_draw_prepare,
WM_widgetgroup_keymap_common,
"UV Transform Manipulator");
}
@@ -826,8 +828,15 @@ static void image_main_region_draw(const bContext *C, ARegion *ar)
static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar, wmNotifier *wmn)
{
+ wmWidgetMap *wmap = WM_widgetmap_find(ar, &(const struct wmWidgetMapType_Params) {
+ "Image_UV", SPACE_IMAGE, RGN_TYPE_WINDOW, 0});
+
/* context changes */
switch (wmn->category) {
+ case NC_GEOM:
+ if (ELEM(wmn->data, ND_DATA, ND_SELECT))
+ WM_widgetmap_tag_refresh(wmap);
+ break;
case NC_GPENCIL:
if (ELEM(wmn->action, NA_EDITED, NA_SELECTED))
ED_region_tag_redraw(ar);
@@ -837,6 +846,7 @@ static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion
case NC_IMAGE:
if (wmn->action == NA_PAINTING)
ED_region_tag_redraw(ar);
+ WM_widgetmap_tag_refresh(wmap);
break;
case NC_MATERIAL:
if (wmn->data == ND_SHADING_LINKS) {
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 92d8149..b0fc83d 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1352,6 +1352,7 @@ void WIDGETGROUP_manipulator_draw_prepare(const bContext *C, wmWidgetGroup *wgro
MAN_ITER_AXES_BEGIN(axis, axis_idx)
{
const short axis_type = manipulator_get_axis_type(man, axis);
+ /* XXX maybe unset _HIDDEN flag on redraw? */
if (manipulator_is_axis_visible(v3d, rv3d, axis_type, axis_idx)) {
WM_widget_set_flag(axis, WM_WIDGET_HIDDEN, false);
}
diff --git a/source/blender/editors/transform/transform_manipulator2d.c b/source/blender/editors/transform/transform_manipulator2d.c
index 9cafcbd..d3b3192 100644
--- a/source/blender/editors/transform/transform_manipulator2d.c
+++ b/source/blender/editors/transform/transform_manipulator2d.c
@@ -72,9 +72,26 @@ enum {
typedef struct ManipulatorGroup2D {
wmWidget *translate_x,
*translate_y;
+
+ /* Current origin in view space, used to update widget origin for possible view changes */
+ float origin[2];
} ManipulatorGroup2D;
+/* **************** Utilities **************** */
+
+/* loop over axes */
+#define MAN2D_ITER_AXES_BEGIN(axis, axis_idx) \
+ { \
+ wmWidget *axis; \
+ int axis_idx; \
+ for (axis_idx = 0; axis_idx < MAN2D_AXIS_LAST; axis_idx++) { \
+ axis = manipulator2d_get_axis_from_index(man, axis_idx);
+
+#define MAN2D_ITER_AXES_END \
+ } \
+ } ((void)0)
+
static wmWidget *manipulator2d_get_axis_from_index(const ManipulatorGroup2D *man, const short axis_idx)
{
BLI_assert(IN_RANGE_INCL(axis_idx, (float)MAN2D_AXIS_TRANS_X, (float)MAN2D_AXIS_TRANS_Y));
@@ -121,9 +138,11 @@ static ManipulatorGroup2D *manipulatorgroup2d_init(wmWidgetGroup *wgroup)
return man;
}
+/**
+ * Calculates origin in view space, use with #manipulator2d_origin_to_view.
+ */
static void manipulator2d_calc_origin(const bContext *C, float *r_origin)
{
- ARegion *ar = CTX_wm_region(C);
SpaceImage *sima = CTX_wm_space_image(C);
Image *ima = ED_space_image(sima);
@@ -133,7 +152,13 @@ static void manipulator2d_calc_origin(const bContext *C, float *r_origin)
else {
ED_uvedit_center(CTX_data_scene(C), ima, CTX_data_edit_object(C), r_origin, sima->around);
}
- /* view space coordinates */
+}
+
+/**
+ * Convert origin (or any other point) from view to region space.
+ */
+BLI_INLINE void manipulator2d_origin_to_region(ARegion *ar, float *r_origin)
+{
UI_view2d_view_to_region_fl(&ar->v2d, r_origin[0], r_origin[1], &r_origin[0], &r_origin[1]);
}
@@ -146,6 +171,7 @@ static int manipulator2d_handler(bContext *C, const wmEvent *UNUSED(event), wmWi
float origin[3];
manipulator2d_calc_origin(C, origin);
+ manipulator2d_origin_to_region(ar, origin);
WM_widget_set_origin(widget, origin);
ED_region_tag_redraw(ar);
@@ -153,18 +179,16 @@ static int manipulator2d_handler(bContext *C, const wmEvent *UNUSED(event), wmWi
return OPERATOR_PASS_THROUGH;
}
-void WIDGETGROUP_manipulator2d_init(const bContext *C, wmWidgetGroup *wgroup)
+void WIDGETGROUP_manipulator2d_init(const bContext *UNUSED(C), wmWidgetGroup *wgroup)
{
ManipulatorGroup2D *man = manipulatorgroup2d_init(wgroup);
- float col[4], col_hi[4];
- float origin[3];
-
- manipulator2d_calc_origin(C, origin);
+ wgroup->customdata = man;
- for (int axis_idx = 0; axis_idx < MAN2D_AXIS_LAST; axis_idx++) {
- wmWidget *axis = manipulator2d_get_axis_from_index(man, axis_idx);
+ MAN2D_ITER_AXES_BEGIN(axis, axis_idx)
+ {
const float offset[3] = {0.0f, 0.2f};
+ float col[4], col_hi[4];
manipulator2d_get_axis_color(axis_idx, col, col_hi);
/* custom handler! */
@@ -175,22 +199,46 @@ void WIDGETGROUP_manipulator2d_init(const bContext *C, wmWidgetGroup *wgroup)
WM_widget_set_offset(axis, offset);
WM_widget_set_line_width(axis, MANIPULATOR_AXIS_LINE_WIDTH);
WM_widget_set_scale(axis, U.widget_scale);
- WM_widget_set_origin(axis, origin);
WM_widget_set_colors(axis, col, col_hi);
/* assign operator */
PointerRNA *ptr = WM_widget_set_operator(axis, "TRANSFORM_OT_translate");
- int constraint[3];
- zero_v3_int(constraint);
+ int constraint[3] = {0.0f};
constraint[(axis_idx + 1) % 2] = 1;
if (RNA_struct_find_property(ptr, "constraint_axis"))
RNA_boolean_set_array(ptr, "constraint_axis", constraint);
RNA_boolean_set(ptr, "release_confirm", 1);
}
+ MAN2D_ITER_AXES_END;
+}
+
+void WIDGETGROUP_manipulator2d_refresh(const bContext *C, wmWidgetGroup *wgroup)
+{
+ ManipulatorGroup2D *man = wgroup->customdata;
+ float origin[3];
+
+ manipulator2d_calc_origin(C, origin);
+ copy_v2_v2(man->origin, origin);
+}
+
+void WIDGETGROUP_manipulator2d_draw_prepare(const bContext *C, wmWidgetGroup *wgroup)
+{
+ ManipulatorGroup2D *man = wgroup->customdata;
+ float origin[3] = {UNPACK2(man->origin), 0.0f};
+
+ manipulator2d_origin_to_region(CTX_wm_region(C), origin);
- MEM_freeN(man);
+ MAN2D_ITER_AXES_BEGIN(axis, axis_idx)
+ {
+ WM_widget_set_origin(axis, origin);
+ }
+ MAN2D_ITER_AXES_END;
}
+/* TODO (Julian)
+ * - Called on every redraw, better to do a more simple poll and check for selection in _refresh
+ * - UV editing only, could be expanded for other things.
+ */
int WIDGETGROUP_manipulator2d_poll(const bContext *C, wmWidgetGroupType *UNUSED(wgrouptype))
{
SpaceImage *sima = CTX_wm_space_image(C);
More information about the Bf-blender-cvs
mailing list