[Bf-blender-cvs] [e732ede] wiggly-widgets: Initial support for user defined Object Widgets

Julian Eisel noreply at git.blender.org
Fri Apr 10 17:09:05 CEST 2015


Commit: e732ede8bb74c405d3806bed0c157cce121da4db
Author: Julian Eisel
Date:   Fri Apr 10 17:08:10 2015 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBe732ede8bb74c405d3806bed0c157cce121da4db

Initial support for user defined Object Widgets

Adds a Panel to the Object Context in the Properties Editor, currently
only containing a Menu to Add widgets. The menu contains 4 items,
Translate, Rotate, Scale and Custom, whereby we currently only draw a
translate widget for all of them. So yes, basic drawing also works.

Important is, that this makes it possible for users to attach custom
widgets to Objects. (Only the manipulator for the selected object is
drawn).

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

M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_ops.c
M	source/blender/editors/transform/manipulator_widget.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesdna/DNA_widget_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_wm.c

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 3ff7a24..cd3bfd5 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -124,6 +124,16 @@ class OBJECT_PT_transform_locks(ObjectButtonsPanel, Panel):
             sub.active = ob.lock_rotations_4d
             sub.prop(ob, "lock_rotation_w", text="W")
 
+class OBJECT_PT_widgets(ObjectButtonsPanel, Panel):
+    bl_label = "Widgets"
+
+    def draw(self, context):
+        layout = self.layout
+
+        ob = context.object
+        wg = ob.wgroup
+
+        layout.operator_menu_enum("object.widget_add", "type")
 
 class OBJECT_PT_relations(ObjectButtonsPanel, Panel):
     bl_label = "Relations"
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 1267d85..a5edd05 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -172,6 +172,8 @@ typedef struct ManipulatorGroup {
 int WIDGETGROUP_manipulator_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype);
 void WIDGETGROUP_manipulator_update(const struct bContext *C, struct wmWidgetGroup *wgroup);
 
+void WIDGETGROUP_object_manipulator_draw(const struct bContext *C, struct wmWidgetGroup *wgroup);
+
 void BIF_draw_manipulator(const struct bContext *C);
 int BIF_do_manipulator(struct bContext *C, const struct wmEvent *event, struct wmOperator *op);
 
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index f7d51eb..15a682d 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -90,6 +90,7 @@
 #include "ED_screen.h"
 #include "ED_util.h"
 #include "ED_image.h"
+#include "ED_transform.h" /* for object manipulator widgets */
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -2001,6 +2002,54 @@ void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+static int WIDGETGROUP_object_manipulator_poll(const struct bContext *C, struct wmWidgetGroupType *wgrouptype)
+{
+	Object *ob = ED_object_active_context((bContext *)C);
+
+	if (ED_operator_object_active((bContext *)C)) {
+		if (STREQ(wgrouptype->idname, ob->id.name)) {
+			return true;
+		}
+	}
+	return false;
+}
+
+static int object_widget_add_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Object *ob = ED_object_active_context((bContext *)C);
+	wmWidgetGroupType *wgrouptype = WM_widgetgrouptype_new(WIDGETGROUP_object_manipulator_poll,
+	                                                       WIDGETGROUP_object_manipulator_draw,
+	                                                       CTX_data_main(C), "View3D", SPACE_VIEW3D,
+	                                                       RGN_TYPE_WINDOW, true);
+
+	/* assign the objects id name to the widget */
+	strcpy(wgrouptype->idname, ob->id.name);
+
+	return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_widget_add(wmOperatorType *ot)
+{
+	PropertyRNA *prop;
+
+	/* identifiers */
+	ot->name = "Add Widget";
+	ot->description = "Add a widget to the active object";
+	ot->idname = "OBJECT_OT_widget_add";
+
+	/* api callbacks */
+	ot->invoke = WM_menu_invoke;
+	ot->exec = object_widget_add_exec;
+	ot->poll = ED_operator_object_active;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	prop = RNA_def_enum(ot->srna, "type", wm_widget_type_items, 0, "Type", "Select the type of widget to add");
+	ot->prop = prop;
+}
+
 /* generic utility function */
 
 bool ED_object_editmode_calc_active_center(Object *obedit, const bool select_only, float r_center[3])
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index c9962be..0490371 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -97,6 +97,8 @@ void OBJECT_OT_game_property_clear(struct wmOperatorType *ot);
 void OBJECT_OT_logic_bricks_copy(struct wmOperatorType *ot);
 void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot);
 
+void OBJECT_OT_widget_add(wmOperatorType *ot);
+
 /* object_select.c */
 void OBJECT_OT_select_all(struct wmOperatorType *ot);
 void OBJECT_OT_select_random(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 8e5abdf..0169085 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -262,6 +262,8 @@ void ED_operatortypes_object(void)
 
 	WM_operatortype_append(OBJECT_OT_data_transfer);
 	WM_operatortype_append(OBJECT_OT_datalayout_transfer);
+
+	WM_operatortype_append(OBJECT_OT_widget_add);
 }
 
 void ED_operatormacros_object(void)
diff --git a/source/blender/editors/transform/manipulator_widget.c b/source/blender/editors/transform/manipulator_widget.c
index af26a49..c9dd765 100644
--- a/source/blender/editors/transform/manipulator_widget.c
+++ b/source/blender/editors/transform/manipulator_widget.c
@@ -66,6 +66,7 @@
 
 #include "ED_armature.h"
 #include "ED_curve.h"
+#include "ED_object.h"
 #include "ED_particle.h"
 #include "ED_view3d.h"
 #include "ED_screen.h"
@@ -2145,3 +2146,43 @@ void WIDGETGROUP_manipulator_update(const struct bContext *C, struct wmWidgetGro
 		MAN_ITER_AXES_END
 	}
 }
+
+void WIDGETGROUP_object_manipulator_draw(const struct bContext *C, struct wmWidgetGroup *wgroup)
+{
+	Object *ob = ED_object_active_context((bContext *)C);
+	ManipulatorGroup *manipulator = MEM_callocN(sizeof(ManipulatorGroup), "manipulator_data");
+	RegionView3D *rv3d = CTX_wm_region_view3d(C);
+	Scene *scene = CTX_data_scene(C);
+	wmWidget *axis;
+	short i;
+
+	float color_green[4] = {0.25f, 1.0f, 0.25f, 1.0f};
+	float color_red[4] = {1.0f, 0.25f, 0.25f, 1.0f};
+	float color_blue[4] = {0.25f, 0.25f, 1.0f, 1.0f};
+
+	if (ob->wgroup == NULL) {
+		ob->wgroup = wgroup;
+	}
+
+	/* XXX - share this stuff between manipulator draw methods */
+
+	copy_v3_v3(rv3d->twmat[3], scene->twcent);
+
+	manipulator->translate_x = WIDGET_arrow_new(wgroup, WIDGET_ARROW_STYLE_NORMAL);
+	WIDGET_arrow_set_color(manipulator->translate_x, color_red);
+	manipulator->translate_y = WIDGET_arrow_new(wgroup, WIDGET_ARROW_STYLE_NORMAL);
+	WIDGET_arrow_set_color(manipulator->translate_y, color_green);
+	manipulator->translate_z = WIDGET_arrow_new(wgroup, WIDGET_ARROW_STYLE_NORMAL);
+	WIDGET_arrow_set_color(manipulator->translate_z, color_blue);
+
+	test_manipulator_axis(C);
+	drawflags = rv3d->twdrawflag;    /* set in calc_manipulator_stats */
+
+	MAN_ITER_AXES_BEGIN(MAN_AXES_TRANSLATE)
+	{
+		WM_widget_set_origin(axis, rv3d->twmat[3]);
+		WIDGET_arrow_set_direction(axis, rv3d->twmat[i]);
+		WM_widget_flag_disable(axis, WM_WIDGET_HIDDEN);
+	}
+	MAN_ITER_AXES_END
+}
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 53a31e7..70ff7ec 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -145,7 +145,9 @@ typedef struct Object {
 	
 	bAnimVizSettings avs;	/* settings for visualization of object-transform animation */
 	bMotionPath *mpath;		/* motion path cache for this object */
-	
+
+	struct wmWidgetGroup *wgroup; /* group of widgets assigned to this object */
+
 	ListBase constraintChannels  DNA_DEPRECATED; // XXX deprecated... old animation system
 	ListBase effect  DNA_DEPRECATED;             // XXX deprecated... keep for readfile
 	ListBase defbase;   /* list of bDeformGroup (vertex groups) names and flag only */
diff --git a/source/blender/makesdna/DNA_widget_types.h b/source/blender/makesdna/DNA_widget_types.h
index fb2e96b..6d9c5c0 100644
--- a/source/blender/makesdna/DNA_widget_types.h
+++ b/source/blender/makesdna/DNA_widget_types.h
@@ -34,6 +34,16 @@
 
 #include "DNA_vec_types.h"
 
+struct bContext;
+struct wmEvent;
+
+typedef enum WidgetType {
+	WT_TRANSLATE = 0,
+	WT_ROTATE    = 1,
+	WT_SCALE     = 2,
+	WT_CUSTOM    = 3,
+} WidgetType;
+
 struct wmWidgetGroup {
 	struct wmWidgetGroup *next, *prev;
 
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 6ed61fc..481a509 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -675,6 +675,7 @@ extern StructRNA RNA_Window;
 extern StructRNA RNA_WindowManager;
 extern StructRNA RNA_WipeSequence;
 extern StructRNA RNA_WireframeModifier;
+extern StructRNA RNA_Widget;
 extern StructRNA RNA_WoodTexture;
 extern StructRNA RNA_World;
 extern StructRNA RNA_WorldAmbientOcclusion;
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index d3d3578..59deefc 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -138,6 +138,7 @@ extern EnumPropertyItem keymap_propvalue_items[];
 extern EnumPropertyItem operator_context_items[];
 
 extern EnumPropertyItem wm_report_items[];
+extern EnumPropertyItem wm_widget_type_items[];
 
 extern EnumPropertyItem transform_mode_types[];
 
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 1e3d274..fee1e96 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -2483,7 +2483,11 @@ static void rna_def_object(BlenderRNA *brna)
 	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Object_parent_bone_set");
 	RNA_def_property_ui_text(prop, "Parent Bone", "Name of parent bone in case of a bone parenting relation");
 	RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
-	
+
+	prop = RNA_def_property(srna, "wgroup", PROP_POINTER, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Widget Group", "Group of widgets assigned to the object");
+	RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+
 	/* Track and Up flags */
 	/* XXX: these have been saved here for a bit longer (after old track was removed),
 	 *      since some other tools still refer to this */
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list