[Bf-blender-cvs] [c2bb750] wiggly-widgets: UV Editing Transform Manipulator (WIP)

Julian Eisel noreply at git.blender.org
Fri Feb 26 15:03:04 CET 2016


Commit: c2bb7504c56498fa3bcd2e2c3961da0e7e66fca7
Author: Julian Eisel
Date:   Fri Feb 26 14:43:58 2016 +0100
Branches: wiggly-widgets
https://developer.blender.org/rBc2bb7504c56498fa3bcd2e2c3961da0e7e66fca7

UV Editing Transform Manipulator (WIP)

This commit adds an initial (but definitely usable) transform manipulator for UV editing in the UV/Image Editor. Only translate is supported for now.

Remaining ToDo's:
* Intersection test is not working completely yet - only arrow line is used (which for some reason isn't working completely either)
* Add rotate and scale manipulator
* Add screen space translation widget (would be unconstrained actually)
* Add toggles to enable/disable and changing transformation type
* Some of the math added for intersection tests could become BLI_math functions

===================================================================

M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_vector.c
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/include/ED_uvedit.h
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/transform/CMakeLists.txt
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_manipulator.c
A	source/blender/editors/transform/transform_manipulator2d.c
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/widgets/WM_widget_library.h
A	source/blender/windowmanager/widgets/intern/widget_library/arrow2d_widget.c
M	source/blender/windowmanager/widgets/intern/widget_library/widget_library_intern.h
M	source/blender/windowmanager/widgets/intern/widget_library/widget_library_utils.c
M	source/blender/windowmanager/widgets/intern/wm_widget.c
M	source/blender/windowmanager/widgets/intern/wm_widget_intern.h

===================================================================

diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index c51446d..539cd1b 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -291,6 +291,7 @@ void ortho_basis_v3v3_v3(float r_n1[3], float r_n2[3], const float n[3]);
 void ortho_v3_v3(float p[3], const float v[3]);
 void ortho_v2_v2(float p[2], const float v[2]);
 void bisect_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]);
+void rotate_v2_v2fl(float r[2], const float p[2], const float angle);
 void rotate_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle);
 void rotate_normalized_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle);
 
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 8d33e04..059ee0a 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -705,6 +705,20 @@ void ortho_v2_v2(float p[2], const float v[2])
 	p[1] =  v[0];
 }
 
+/**
+ * Rotate a point \a p by \a angle around origin (0, 0)
+ */
+void rotate_v2_v2fl(float r[2], const float p[2], const float angle)
+{
+	const float co = cosf(angle);
+	const float si = sinf(angle);
+
+	BLI_assert(r != p);
+
+	r[0] = co * p[0] - si * p[1];
+	r[1] = si * p[0] + co * p[1];
+}
+
 /* Rotate a point p by angle theta around an arbitrary axis r
  * http://local.wasp.uwa.edu.au/~pbourke/geometry/
  */
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index b175f7f..1fd2093 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -158,7 +158,7 @@ int BIF_countTransformOrientation(const struct bContext *C);
 void Transform_Properties(struct wmOperatorType *ot, int flags);
 
 
-/* view3d manipulators */
+/* transform manipulators */
 
 int WIDGETGROUP_manipulator_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype);
 void WIDGETGROUP_manipulator_create(const struct bContext *C, struct wmWidgetGroup *wgroup);
@@ -166,6 +166,9 @@ void WIDGETGROUP_manipulator_create(const struct bContext *C, struct wmWidgetGro
 void WIDGETGROUP_object_manipulator_create(const struct bContext *C, struct wmWidgetGroup *wgroup);
 int WIDGETGROUP_object_manipulator_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype);
 
+void WIDGETGROUP_manipulator2d_create(const struct bContext *C, struct wmWidgetGroup *wgroup);
+int WIDGETGROUP_manipulator2d_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype);
+
 
 /* Snapping */
 
diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h
index 5356838..c5577c5 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -51,6 +51,7 @@ void ED_keymap_uvedit(struct wmKeyConfig *keyconf);
 
 void ED_uvedit_assign_image(struct Main *bmain, struct Scene *scene, struct Object *obedit, struct Image *ima, struct Image *previma);
 bool ED_uvedit_minmax(struct Scene *scene, struct Image *ima, struct Object *obedit, float min[2], float max[2]);
+bool ED_uvedit_center(Scene *scene, Image *ima, struct Object *obedit, float cent[2], char mode);
 void ED_uvedit_select_all(struct BMesh *bm);
 
 bool ED_object_get_active_image(struct Object *ob, int mat_nr,
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index ccf9e82..c9c47f1 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -57,6 +57,7 @@
 #include "ED_space_api.h"
 #include "ED_screen.h"
 #include "ED_uvedit.h"
+#include "ED_transform.h"
 
 #include "BIF_gl.h"
 
@@ -579,6 +580,24 @@ static int image_context(const bContext *C, const char *member, bContextDataResu
 	return 0;
 }
 
+static void image_widgets(void)
+{
+	const struct wmWidgetMapType_Params wmap_params = {
+		.idname = "Image_UV",
+		.spaceid = SPACE_IMAGE, .regionid = RGN_TYPE_WINDOW,
+		.flag = 0,
+	};
+
+	wmWidgetMapType *wmaptype = WM_widgetmaptype_ensure(&wmap_params);
+
+	WM_widgetgrouptype_register_ptr(
+	        NULL, wmaptype,
+	        WIDGETGROUP_manipulator2d_poll,
+	        WIDGETGROUP_manipulator2d_create,
+	        WM_widgetgroup_keymap_common,
+	        "Manipulator Widgets");
+}
+
 /************************** main region ***************************/
 
 /* sets up the fields of the View2D from zoom and offset */
@@ -642,6 +661,14 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
 	// image space manages own v2d
 	// UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
 
+	/* widgets */
+	if (BLI_listbase_is_empty(&ar->widgetmaps)) {
+		wmWidgetMap *wmap = WM_widgetmap_from_type(&(const struct wmWidgetMapType_Params) {
+		        "Image_UV", SPACE_IMAGE, RGN_TYPE_WINDOW, 0});
+		BLI_addhead(&ar->widgetmaps, wmap);
+	}
+	WM_widgetmaps_add_handlers(ar);
+
 	/* mask polls mode */
 	keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
 	WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
@@ -667,7 +694,6 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
 	WM_event_add_keymap_handler(&ar->handlers, keymap);
 	keymap = WM_keymap_find(wm->defaultconf, "Image", SPACE_IMAGE, 0);
 	WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
-
 }
 
 static void image_main_region_draw(const bContext *C, ARegion *ar)
@@ -783,6 +809,9 @@ static void image_main_region_draw(const bContext *C, ARegion *ar)
 		UI_view2d_view_restore(C);
 	}
 
+	WM_widgetmap_widgets_update(C, ar->widgetmaps.first);
+	WM_widgetmap_widgets_draw(C, ar->widgetmaps.first, false, true);
+
 	draw_image_cache(C, ar);
 
 	/* scrollers? */
@@ -1000,6 +1029,7 @@ void ED_spacetype_image(void)
 	st->refresh = image_refresh;
 	st->listener = image_listener;
 	st->context = image_context;
+	st->widgets = image_widgets;
 	
 	/* regions: main window */
 	art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt
index f3047c0..8a553c4 100644
--- a/source/blender/editors/transform/CMakeLists.txt
+++ b/source/blender/editors/transform/CMakeLists.txt
@@ -46,6 +46,7 @@ set(SRC
 	transform_generics.c
 	transform_input.c
 	transform_manipulator.c
+	transform_manipulator2d.c
 	transform_ops.c
 	transform_orientations.c
 	transform_snap.c
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index dfc851d..02522e3 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -616,7 +616,10 @@ void flushTransMasking(TransInfo *t);
 void flushTransPaintCurve(TransInfo *t);
 void restoreBones(TransInfo *t);
 
-/*********************** exported from transform_manipulator.c ********** */
+/*********************** transform_manipulator.c ********** */
+
+#define MANIPULATOR_AXIS_LINE_WIDTH 2.0
+
 bool gimbal_axis(struct Object *ob, float gmat[3][3]); /* return 0 when no gimbal for selection */
 
 /*********************** TransData Creation and General Handling *********** */
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index b541dbe..0acefbd 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -64,7 +64,7 @@
 
 #include "WM_api.h"
 #include "WM_types.h"
-#include "wm.h"
+#include "wm.h" /* XXX */
 
 #include "ED_armature.h"
 #include "ED_curve.h"
@@ -105,8 +105,6 @@
 #define TW_AXIS_DOT_MIN 0.02f
 #define TW_AXIS_DOT_MAX 0.1f
 
-#define MAN_AXIS_LINE_WIDTH 2.0
-
 /* axes as index */
 enum {
 	MAN_AXIS_TRANS_X = 0,
@@ -1185,14 +1183,14 @@ void WIDGETGROUP_manipulator_create(const struct bContext *C, struct wmWidgetGro
 				WIDGET_arrow_set_direction(axis, rv3d->twmat[aidx_norm]);
 				WIDGET_arrow_set_line_len(axis, len);
 				WM_widget_set_offset(axis, start_co);
-				WM_widget_set_line_width(axis, MAN_AXIS_LINE_WIDTH);
+				WM_widget_set_line_width(axis, MANIPULATOR_AXIS_LINE_WIDTH);
 				break;
 			}
 			case MAN_AXIS_ROT_X:
 			case MAN_AXIS_ROT_Y:
 			case MAN_AXIS_ROT_Z:
 				WIDGET_dial_set_up_vector(axis, rv3d->twmat[aidx_norm]);
-				WM_widget_set_line_width(axis, MAN_AXIS_LINE_WIDTH);
+				WM_widget_set_line_width(axis, MANIPULATOR_AXIS_LINE_WIDTH);
 				break;
 			case MAN_AXIS_TRANS_XY:
 			case MAN_AXIS_TRANS_YZ:
@@ -1261,6 +1259,10 @@ int WIDGETGROUP_manipulator_poll(const struct bContext *C, struct wmWidgetGroupT
 	        ((v3d->twtype & (V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE | V3D_MANIP_SCALE)) != 0));
 }
 
+
+/* -------------------------------------------------------------------- */
+/* Custom Object Manipulator (unfinished - unsure if this will stay) */
+
 void WIDGETGROUP_object_manipulator_create(const struct bContext *C, struct wmWidgetGroup *wgroup)
 {
 	Object *ob = ED_object_active_context((bContext *)C);
diff --git a/source/blender/editors/transform/transform_manipulator2d.c b/source/blender/editors/transform/transform_manipulator2d.c
new file mode 100644
index 0000000..e7bdb35
--- /dev/null
+++ b/source/blender/editors/transform/transform_manipulator2d.c
@@ -0,0 +1,226 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list