Commit: 369cd8521b8782cb009cf583c5e71f9b0da36fc8
Author: Campbell Barton
Date:   Tue Aug 29 19:15:36 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB369cd8521b8782cb009cf583c5e71f9b0da36fc8

Manipulator: new cage2d manipulator

Adding alongside the existing one for now,
but it should eventually replace it.

Uses a matrix instead of (position + scale),
written so rotation can be done more easily.

Currently has a primitive handle for rotation, supports corner scaling.

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

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/cage2d_rotate_manipulator.c
M       source/blender/editors/space_api/spacetypes.c

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

diff --git a/source/blender/editors/include/ED_manipulator_library.h 
b/source/blender/editors/include/ED_manipulator_library.h
index 25566899319..f283973a144 100644
--- a/source/blender/editors/include/ED_manipulator_library.h
+++ b/source/blender/editors/include/ED_manipulator_library.h
@@ -34,6 +34,7 @@
 void ED_manipulatortypes_arrow_2d(void);
 void ED_manipulatortypes_arrow_3d(void);
 void ED_manipulatortypes_cage_2d(void);
+void ED_manipulatortypes_cage_2d_rotate(void);
 void ED_manipulatortypes_dial_3d(void);
 void ED_manipulatortypes_grab_3d(void);
 void ED_manipulatortypes_facemap_3d(void);
@@ -103,6 +104,13 @@ enum {
        ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X   = 2,
        ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y   = 3,
        ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y   = 4,
+       /* Corners */
+       ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y = 5,
+       ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y = 6,
+       ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y = 7,
+       ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y = 8,
+
+       ED_MANIPULATOR_CAGE2D_PART_ROTATE = 9,
 };
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/manipulator_library/CMakeLists.txt 
b/source/blender/editors/manipulator_library/CMakeLists.txt
index 0604946dc24..43783eb3e4a 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/cage2d_rotate_manipulator.c
        manipulator_types/cage2d_manipulator.c
        manipulator_types/dial3d_manipulator.c
        manipulator_types/grab3d_manipulator.c
diff --git 
a/source/blender/editors/manipulator_library/manipulator_types/cage2d_rotate_manipulator.c
 
b/source/blender/editors/manipulator_library/manipulator_types/cage2d_rotate_manipulator.c
new file mode 100644
index 00000000000..0406d3a0972
--- /dev/null
+++ 
b/source/blender/editors/manipulator_library/manipulator_types/cage2d_rotate_manipulator.c
@@ -0,0 +1,617 @@
+/*
+ * ***** 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.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file cage2d_manipulator.c
+ *  \ingroup wm
+ *
+ * \name Cage Manipulator
+ *
+ * 2D Manipulator
+ *
+ * \brief Rectangular manipulator acting as a 'cage' around its content.
+ * Interacting scales or translates the manipulator.
+ */
+
+#include "BIF_gl.h"
+
+#include "BKE_context.h"
+
+#include "BLI_math.h"
+#include "BLI_rect.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+#include "GPU_matrix.h"
+#include "GPU_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_select.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/* own includes */
+#include "../manipulator_library_intern.h"
+
+#define MANIPULATOR_RESIZER_WIDTH  20.0f
+
+/* -------------------------------------------------------------------- */
+
+static void rect_transform_draw_corners(
+        const rctf *r, const float offsetx, const float offsety, const float 
color[3])
+{
+       uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", 
GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformColor3fv(color);
+
+       immBegin(GWN_PRIM_LINES, 16);
+
+       immVertex2f(pos, r->xmin, r->ymin + offsety);
+       immVertex2f(pos, r->xmin, r->ymin);
+       immVertex2f(pos, r->xmin, r->ymin);
+       immVertex2f(pos, r->xmin + offsetx, r->ymin);
+
+       immVertex2f(pos, r->xmax, r->ymin + offsety);
+       immVertex2f(pos, r->xmax, r->ymin);
+       immVertex2f(pos, r->xmax, r->ymin);
+       immVertex2f(pos, r->xmax - offsetx, r->ymin);
+
+       immVertex2f(pos, r->xmax, r->ymax - offsety);
+       immVertex2f(pos, r->xmax, r->ymax);
+       immVertex2f(pos, r->xmax, r->ymax);
+       immVertex2f(pos, r->xmax - offsetx, r->ymax);
+
+       immVertex2f(pos, r->xmin, r->ymax - offsety);
+       immVertex2f(pos, r->xmin, r->ymax);
+       immVertex2f(pos, r->xmin, r->ymax);
+       immVertex2f(pos, r->xmin + offsetx, r->ymax);
+
+       immEnd();
+
+       immUnbindProgram();
+}
+
+static void rect_transform_draw_interaction(
+        const float color[4], const int highlighted,
+        const float size[2], const float margin[2],
+        const float line_width)
+{
+       /* 4 verts for translate, otherwise only 3 are used. */
+       float verts[4][2];
+       uint verts_len = 0;
+
+       switch (highlighted) {
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X:
+                       ARRAY_SET_ITEMS(verts[0], -size[0] + margin[0], 
-size[1]);
+                       ARRAY_SET_ITEMS(verts[1], -size[0],             
-size[1]);
+                       ARRAY_SET_ITEMS(verts[2], -size[0],              
size[1]);
+                       verts_len = 3;
+                       break;
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X:
+                       ARRAY_SET_ITEMS(verts[0], size[0] - margin[0], 
-size[1]);
+                       ARRAY_SET_ITEMS(verts[1], size[0],             
-size[1]);
+                       ARRAY_SET_ITEMS(verts[2], size[0],              
size[1]);
+                       verts_len = 3;
+                       break;
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y:
+                       ARRAY_SET_ITEMS(verts[0], -size[0], -size[1] + 
margin[1]);
+                       ARRAY_SET_ITEMS(verts[1], -size[0], -size[1]);
+                       ARRAY_SET_ITEMS(verts[2], size[0],  -size[1]);
+                       verts_len = 3;
+                       break;
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y:
+                       ARRAY_SET_ITEMS(verts[0], -size[0], size[1] - 
margin[1]);
+                       ARRAY_SET_ITEMS(verts[1], -size[0], size[1]);
+                       ARRAY_SET_ITEMS(verts[2], size[0],  size[1]);
+                       verts_len = 3;
+                       break;
+
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y:
+                       ARRAY_SET_ITEMS(verts[0], -size[0] + margin[0], 
-size[1]);
+                       ARRAY_SET_ITEMS(verts[1], -size[0] + margin[0], 
-size[1] + margin[1]);
+                       ARRAY_SET_ITEMS(verts[2], -size[0],             
-size[1] + margin[1]);
+                       verts_len = 3;
+                       break;
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y:
+                       ARRAY_SET_ITEMS(verts[0], -size[0] + margin[0], 
size[1]);
+                       ARRAY_SET_ITEMS(verts[1], -size[0] + margin[0], size[1] 
- margin[1]);
+                       ARRAY_SET_ITEMS(verts[2], -size[0],             size[1] 
- margin[1]);
+                       verts_len = 3;
+                       break;
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y:
+                       ARRAY_SET_ITEMS(verts[0], size[0] - margin[0], 
-size[1]);
+                       ARRAY_SET_ITEMS(verts[1], size[0] - margin[0], -size[1] 
+ margin[1]);
+                       ARRAY_SET_ITEMS(verts[2], size[0],             -size[1] 
+ margin[1]);
+                       verts_len = 3;
+                       break;
+               case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y:
+                       ARRAY_SET_ITEMS(verts[0], size[0] - margin[0], size[1]);
+                       ARRAY_SET_ITEMS(verts[1], size[0] - margin[0], size[1] 
- margin[1]);
+                       ARRAY_SET_ITEMS(verts[2], size[0],             size[1] 
- margin[1]);
+                       verts_len = 3;
+                       break;
+
+               case ED_MANIPULATOR_CAGE2D_PART_ROTATE:
+               {
+                       const float rotate_pt[2] = {0.0f, size[1] + margin[1]};
+                       const rctf r_rotate = {
+                               .xmin = rotate_pt[0] - margin[0] / 2.0f,
+                               .xmax = rotate_pt[0] + margin[0] / 2.0f,
+                               .ymin = rotate_pt[1] - margin[1] / 2.0f,
+                               .ymax = rotate_pt[1] + margin[1] / 2.0f,
+                       };
+
+                       ARRAY_SET_ITEMS(verts[0], r_rotate.xmin, r_rotate.ymin);
+                       ARRAY_SET_ITEMS(verts[1], r_rotate.xmin, r_rotate.ymax);
+                       ARRAY_SET_ITEMS(verts[2], r_rotate.xmax, r_rotate.ymax);
+                       ARRAY_SET_ITEMS(verts[3], r_rotate.xmax, r_rotate.ymin);
+                       verts_len = 4;
+                       break;
+               }
+
+               /* Only used for 3D view selection, never displayed to the 
user. */
+               case ED_MANIPULATOR_CAGE2D_PART_TRANSLATE:
+                       ARRAY_SET_ITEMS(verts[0], -size[0], -size[1]);
+                       ARRAY_SET_ITEMS(verts[1], -size[0],  size[1]);
+                       ARRAY_SET_ITEMS(verts[2], size[0],   size[1]);
+                       ARRAY_SET_ITEMS(verts[3], size[0],  -size[1]);
+                       verts_len = 4;
+                       break;
+               default:
+                       return;
+       }
+
+       Gwn_VertFormat *format = immVertexFormat();
+       struct {
+               uint pos, col;
+       } attr_id = {
+               .pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, 
GWN_FETCH_FLOAT),
+               .col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 
3, GWN_FETCH_FLOAT),
+       };
+       immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+       if (highlighted == ED_MANIPULATOR_CAGE2D_PART_TRANSLATE) {
+               immBegin(GWN_PRIM_TRI_FAN, 4);
+               immAttrib3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+               for (uint i = 0; i < verts_len; i++) {
+                       immVertex2fv(attr_id.pos, verts[i]);
+               }
+               immEnd();
+       }
+       else {
+               glLineWidth(line_width + 3.0f);
+
+               immBegin(GWN_PRIM_LINE_STRIP, verts_len);
+               immAttrib3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+               for (uint i = 0; i < verts_len; i++) {
+                       immVertex2fv(attr_id.pos, verts[i]);
+               }
+               immEnd();
+
+               glLineWidth(line_width);
+
+               immBegin(GWN_PRIM_LINE_STRIP, verts_len);
+               immAttrib3fv(attr_id.col, color);
+               for (uint i = 0; i < verts_len; i++) {
+                       immVertex2fv(attr_id.pos, verts[i]);
+               }
+               immEnd();
+       }
+
+       immUnbindProgram();
+
+}
+
+static void manipulator_rect_transform_draw_intern(
+        wmManipulator *mpr, const bool select, const bool highlight, const int 
select_id)
+{
+       // const bool use_clamp = (mpr->parent_mgroup->type->flag & 
WM_MANIPULATORGROUPTYPE_3D) == 0;
+       float dims[2];
+       RNA_float_get_array(mpr->ptr, "dimensions", dims);
+       const float w = dims[0] * (1.0f + (1.0f / 3.0f));
+       const float h = dims[1] * (1.0f + (1.0f / 3.0f));
+       float matrix_final[4][4];
+
+       const int transform_flag = RNA_enum_get(mpr->ptr, "transform");
+
+       float aspx = 1.0f, aspy = 1.0f;
+       const float size[2] = {w / 2.0f, h / 2.0f};
+       const rctf r = {
+               .xmin = -size[0],
+               .ymin = -size[1],
+               .xmax =

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to