[Bf-blender-cvs] [468ac903176] blender2.8: Manipulator: view3d navigation buttons

Campbell Barton noreply at git.blender.org
Fri Dec 15 18:21:18 CET 2017


Commit: 468ac9031765681cde42e9132d16c799158e7aba
Author: Campbell Barton
Date:   Sat Dec 16 03:57:20 2017 +1100
Branches: blender2.8
https://developer.blender.org/rB468ac9031765681cde42e9132d16c799158e7aba

Manipulator: view3d navigation buttons

Added for Blender101 template.
Disabled by default, enable as a preference.

Exposes rotate, pan, zoom, persp-ortho & camera toggle.

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/editors/include/ED_manipulator_library.h
M	source/blender/editors/manipulator_library/CMakeLists.txt
A	source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/space_view3d/CMakeLists.txt
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_intern.h
A	source/blender/editors/space_view3d/view3d_manipulator_navigate.c
A	source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 31f0886e8b1..0abb1876798 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -287,6 +287,7 @@ class USERPREF_PT_interface(Panel):
         #col.prop(view, "open_left_mouse_delay", text="Hold LMB")
         #col.prop(view, "open_right_mouse_delay", text="Hold RMB")
         col.prop(view, "show_manipulator")
+        col.prop(view, "show_manipulator_navigate")
         ## Currently not working
         # col.prop(view, "show_manipulator_shaded")
         sub = col.column()
diff --git a/source/blender/editors/include/ED_manipulator_library.h b/source/blender/editors/include/ED_manipulator_library.h
index 80703321490..7166292147e 100644
--- a/source/blender/editors/include/ED_manipulator_library.h
+++ b/source/blender/editors/include/ED_manipulator_library.h
@@ -33,6 +33,7 @@
 /* initialize manipulators */
 void ED_manipulatortypes_arrow_2d(void);
 void ED_manipulatortypes_arrow_3d(void);
+void ED_manipulatortypes_button_2d(void);
 void ED_manipulatortypes_cage_2d(void);
 void ED_manipulatortypes_cage_3d(void);
 void ED_manipulatortypes_dial_3d(void);
diff --git a/source/blender/editors/manipulator_library/CMakeLists.txt b/source/blender/editors/manipulator_library/CMakeLists.txt
index 9f7df8c6425..86e1bb3b6d7 100644
--- a/source/blender/editors/manipulator_library/CMakeLists.txt
+++ b/source/blender/editors/manipulator_library/CMakeLists.txt
@@ -47,6 +47,7 @@ set(SRC
 	geometry/geom_dial_manipulator.c
 	manipulator_types/arrow2d_manipulator.c
 	manipulator_types/arrow3d_manipulator.c
+	manipulator_types/button2d_manipulator.c
 	manipulator_types/cage2d_manipulator.c
 	manipulator_types/cage3d_manipulator.c
 	manipulator_types/dial3d_manipulator.c
diff --git a/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
new file mode 100644
index 00000000000..32c1dbae0a6
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
@@ -0,0 +1,202 @@
+/*
+ * ***** 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 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file button2d_manipulator.c
+ *  \ingroup wm
+ *
+ * \name Button Manipulator
+ *
+ * 3D Manipulator, also works in 2D views.
+ *
+ * \brief Single click button action for use in manipulator groups.
+ *
+ * Note: currently only very basic icon buttons supported.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_interface_icons.h"
+#include "UI_resources.h"
+
+/* own includes */
+#include "../manipulator_geometry.h"
+#include "../manipulator_library_intern.h"
+
+typedef struct ButtonManipulator3D {
+	wmManipulator manipulator;
+	/* Added to 'matrix_basis' when calculating the matrix. */
+	float prop_co[3];
+} ButtonManipulator3D;
+
+#define DIAL_RESOLUTION 32
+
+/* -------------------------------------------------------------------- */
+
+static void button_geom_draw(
+        const wmManipulator *mpr, const float color[4], const bool select)
+{
+	glLineWidth(mpr->line_width);
+
+	Gwn_VertFormat *format = immVertexFormat();
+	uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+	immUniformColor4fv(color);
+
+	/* TODO, other draw styles */
+	imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
+
+	immUnbindProgram();
+
+	UNUSED_VARS(select);
+}
+
+static void button3d_draw_intern(
+        const bContext *UNUSED(C), wmManipulator *mpr,
+        const bool select, const bool highlight)
+{
+	float color[4];
+	float matrix_final[4][4];
+
+	manipulator_color_get(mpr, highlight, color);
+	WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+	gpuPushMatrix();
+	gpuMultMatrix(matrix_final);
+
+	glEnable(GL_BLEND);
+	button_geom_draw(mpr, color, select);
+	gpuPopMatrix();
+
+
+	if (select == false) {
+		int icon = RNA_enum_get(mpr->ptr, "icon");
+		if (icon != ICON_NONE) {
+			UI_icon_draw(
+			        mpr->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * U.pixelsize,
+			        mpr->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * U.pixelsize,
+			        icon);
+		}
+	}
+	glDisable(GL_BLEND);
+}
+
+static void manipulator_button_draw_select(const bContext *C, wmManipulator *mpr, int select_id)
+{
+	GPU_select_load_id(select_id);
+	button3d_draw_intern(C, mpr, true, false);
+}
+
+static void manipulator_button_draw(const bContext *C, wmManipulator *mpr)
+{
+	const bool is_highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+
+	glEnable(GL_BLEND);
+	button3d_draw_intern(C, mpr, false, is_highlight);
+	glDisable(GL_BLEND);
+}
+
+static int manipulator_button_test_select(
+        bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+	float point_local[2];
+
+	if (0) {
+		/* correct, but unnecessarily slow. */
+		if (manipulator_window_project_2d(
+		        C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, true, point_local) == false)
+		{
+			return -1;
+		}
+	}
+	else {
+		copy_v2_v2(point_local, (float [2]){UNPACK2(event->mval)});
+		sub_v2_v2(point_local, mpr->matrix_basis[3]);
+		mul_v2_fl(point_local, 1.0f / mpr->scale_basis);
+	}
+
+	/* The 'mpr->scale_final' is already applied when projecting. */
+	if (len_squared_v2(point_local) < 1.0f) {
+		return 0;
+	}
+
+	return -1;
+}
+
+static int manipulator_button_cursor_get(wmManipulator *UNUSED(mpr))
+{
+	return BC_HANDCURSOR;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Button Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_button_2d(wmManipulatorType *wt)
+{
+	/* identifiers */
+	wt->idname = "MANIPULATOR_WT_button_2d";
+
+	/* api callbacks */
+	wt->draw = manipulator_button_draw;
+	wt->draw_select = manipulator_button_draw_select;
+	wt->test_select = manipulator_button_test_select;
+	wt->cursor_get = manipulator_button_cursor_get;
+
+	wt->struct_size = sizeof(ButtonManipulator3D);
+
+	/* rna */
+	PropertyRNA *prop;
+	prop = RNA_def_property(wt->srna, "icon", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_items(prop, rna_enum_icon_items);
+	RNA_def_property_ui_text(prop, "Icon", "Override automatic icon of the item");
+}
+
+void ED_manipulatortypes_button_2d(void)
+{
+	WM_manipulatortype_append(MANIPULATOR_WT_button_2d);
+}
+
+/** \} */ // Button Manipulator API
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index 32f6ac40d12..e417026640e 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -127,6 +127,7 @@ void ED_spacetypes_init(void)
 	ED_operatortypes_ui();
 
 	/* manipulator types */
+	ED_manipulatortypes_button_2d();
 	ED_manipulatortypes_dial_3d();
 	ED_manipulatortypes_grab_3d();
 	ED_manipulatortypes_arrow_2d();
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index de8380aa8bb..11ef781b229 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -64,6 +64,8 @@ set(SRC
 	view3d_manipulator_empty.c
 	view3d_manipulator_forcefield.c
 	view3d_manipulator_lamp.c
+	view3d_manipulator_navigate.c
+	view3d_manipulator_navigate_type.c
 	view3d_manipulator_ruler.c
 	view3d_ops.c
 	view3d_project.c
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 984ab82ee60..3430351b756 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -729,6 +729,9 @@ static void view3d_widgets(void)
 
 	WM_manipulatorgrouptype_append(VIEW3D_WGT_ruler);
 	WM_manipulatortype_append(VIEW3D_WT_ruler_item);
+
+	WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_navigate);
+	WM_manipulatortype_append(VIEW3D_WT_navigate_rotate);
 }
 
 
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index a7368a84eb6..ee0b628fdad 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -153,7 +153,7 @@ void draw_object_select(
         const struct EvaluationContext *eval_ctx, Scene *scene, struct ViewLayer *view_layer, struct ARegion *ar, View3D *v3d,
         Base *base, const short dflag);
 
-void draw_mesh_object_outline(View3D *v3d, Object *ob, struct DerivedMesh *dm, const unsigned char ob_wire_col[4]);
+void draw_mesh_object_outline(View3D *v3d, struct Object *ob, struct DerivedMesh *dm, const unsigned char ob_wire_col[4]);
 
 bool draw_glsl_material(Scene *scene, struct ViewLayer *view_layer, struct Object *ob, View3D *v3d, const char dt);
 void draw_object_instance(const struct EvaluationContext *eval_ctx, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, struct Object *ob, const char dt, 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list