[Bf-blender-cvs] [8582a432a59] greasepencil-object: GP: Add support for drawing control points [wip]
Charlie Jolly
noreply at git.blender.org
Sun Dec 9 01:59:50 CET 2018
Commit: 8582a432a597ac67eb0b710c75652547f38dcb80
Author: Charlie Jolly
Date: Sun Dec 9 00:59:17 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rB8582a432a597ac67eb0b710c75652547f38dcb80
GP: Add support for drawing control points [wip]
Also renamed variables top, bottom -> start, end
===================================================================
M source/blender/editors/gpencil/drawgpencil.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_primitive.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index b44c9105e10..be664888719 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -1430,6 +1430,23 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in
glDisable(GL_BLEND);
}
+static void gp_primitive_draw_point(const tGPcontrolpoint *cp)
+{
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ float color[4];
+ UI_GetThemeColor3fv(cp->color, color);
+ color[3] = 0.6f;
+ /* if drawing a single point, draw it larger */
+ GPU_point_size((float)cp->size);
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
+ immUniformColor4fv(color);
+ immBegin(GPU_PRIM_POINTS, 1);
+ immVertex3fv(pos, &cp->x);
+ immEnd();
+ immUnbindProgram();
+}
+
/* draw interpolate strokes (used only while operator is running) */
void ED_gp_draw_primitives(const bContext *C, tGPDprimitive *tgpi, const int type)
{
@@ -1484,6 +1501,17 @@ void ED_gp_draw_primitives(const bContext *C, tGPDprimitive *tgpi, const int typ
gp_draw_strokes(&tgpw);
}
}
+
+ /* draw cps, this is temporary code */
+ if (tgpi->draw_cp_points) {
+ tGPcontrolpoint *cps = tgpi->cp_points;
+ for (int i = 0; i < tgpi->tot_cp_points; i++) {
+ tGPcontrolpoint *cp = &cps[i];
+ if (cp->display)
+ gp_primitive_draw_point(cp);
+ }
+ }
+
GPU_blend(false);
}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 2b9cf181284..03fa1d068c4 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -155,20 +155,23 @@ typedef struct tGPDprimitive {
struct bGPDlayer *gpl; /* layer */
struct bGPDframe *gpf; /* frame */
int type; /* type of primitive */
- bool curve; /* type of primitive is a curve */
+ bool curve; /* type of primitive is a curve */
short cyclic; /* cyclic option */
short flip; /* flip option */
- tGPspoint *points; /* array of data-points for stroke */
+ tGPspoint *points; /* array of data-points for stroke */
+ tGPcontrolpoint *cp_points; /* array of control-points for stroke */
+ int tot_cp_points; /* array of control-points for stroke */
+ bool draw_cp_points; /* array of control-points for stroke */
int point_count; /* number of edges allocated */
int tot_stored_edges; /* stored number of polygon edges */
int tot_edges; /* number of polygon edges */
- int top[2]; /* first box corner */
- int bottom[2]; /* last box corner */
int origin[2]; /* initial box corner */
- int bezcp1[2]; /* first bezier control point */
- int bezcp2[2]; /* second bezier control point */
+ int start[2]; /* first box corner */
+ int end[2]; /* last box corner */
+ int cp1[2]; /* first control point */
+ int cp2[2]; /* second control point */
+ int sel_cp; /* flag to determine control point is selected */
int flag; /* flag to determine operations in progress */
- int sel_cp; /* flag to determine control point is selected */
int mvalo[2]; /* previous recorded mouse-position */
int lock_axis; /* lock to viewport axis */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index bd4d8e28e2f..bce0d06c92a 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -65,6 +65,7 @@
#include "BKE_report.h"
#include "UI_interface.h"
+#include "UI_resources.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -86,16 +87,17 @@
#define MIN_EDGES 2
#define MAX_EDGES 128
+#define MAX_CP 128
#define IDLE 0
#define IN_PROGRESS 1
-#define IN_CURVE_EDIT_BEZIER 2
+#define IN_CURVE_EDIT 2
-#define CURVE_CP_NONE 0
-#define CURVE_CP_T 1
-#define CURVE_CP_1 2
-#define CURVE_CP_2 3
-#define CURVE_CP_B 4
+#define SELECT_NONE 0
+#define SELECT_START 1
+#define SELECT_CP1 2
+#define SELECT_CP2 3
+#define SELECT_END 4
/* ************************************************ */
/* Core/Shared Utilities */
@@ -212,7 +214,7 @@ static bool gpencil_primitive_add_poll(bContext *C)
/* Allocate memory to stroke, adds MAX_EDGES on every call */
static void gpencil_primitive_allocate_memory(tGPDprimitive *tgpi) {
- tgpi->point_count += MAX_EDGES + 1;
+ tgpi->point_count += (MAX_EDGES + 1);
bGPDstroke *gpsf = tgpi->gpf->strokes.first;
gpsf->points = MEM_reallocN(gpsf->points, sizeof(bGPDspoint) * tgpi->point_count);
if (gpsf->dvert != NULL)
@@ -285,7 +287,18 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
}
-
+/* Helper: set control point */
+static void gp_primitive_set_cp(tGPDprimitive *tgpi, float p[2], int color, int size)
+{
+ if (tgpi->tot_cp_points < MAX_CP) {
+ tGPcontrolpoint *cp = &tgpi->cp_points[tgpi->tot_cp_points];
+ copy_v2_v2(&cp->x, p);
+ cp->color = color;
+ cp->display = true;
+ cp->size = MAX2(5, size);
+ tgpi->tot_cp_points += 1;
+ }
+}
/* ----------------------- */
/* Drawing Callbacks */
@@ -333,12 +346,12 @@ static void gpencil_primitive_status_indicators(bContext *C, tGPDprimitive *tgpi
if (tgpi->flag == IN_PROGRESS) {
BLI_snprintf(
status_str, sizeof(status_str), "%s: %d (%d, %d) (%d, %d)", msg_str, (int)tgpi->tot_edges,
- tgpi->top[0], tgpi->top[1], tgpi->bottom[0], tgpi->bottom[1]);
+ tgpi->start[0], tgpi->start[1], tgpi->end[0], tgpi->end[1]);
}
else {
BLI_snprintf(
status_str, sizeof(status_str), "%s: %d (%d, %d)", msg_str, (int)tgpi->tot_edges,
- tgpi->bottom[0], tgpi->bottom[1]);
+ tgpi->end[0], tgpi->end[1]);
}
}
}
@@ -346,12 +359,12 @@ static void gpencil_primitive_status_indicators(bContext *C, tGPDprimitive *tgpi
if (tgpi->flag == IN_PROGRESS) {
BLI_snprintf(
status_str, sizeof(status_str), "%s: (%d, %d) (%d, %d)", msg_str,
- tgpi->top[0], tgpi->top[1], tgpi->bottom[0], tgpi->bottom[1]);
+ tgpi->start[0], tgpi->start[1], tgpi->end[0], tgpi->end[1]);
}
else {
BLI_snprintf(
status_str, sizeof(status_str), "%s: (%d, %d)", msg_str,
- tgpi->bottom[0], tgpi->bottom[1]);
+ tgpi->end[0], tgpi->end[1]);
}
}
ED_workspace_status_text(C, status_str);
@@ -366,17 +379,17 @@ static void gp_primitive_rectangle(tGPDprimitive *tgpi, tGPspoint *points2D)
int i = tgpi->tot_stored_edges;
- points2D[i].x = (float)tgpi->top[0];
- points2D[i].y = (float)tgpi->top[1];
+ points2D[i].x = (float)tgpi->start[0];
+ points2D[i].y = (float)tgpi->start[1];
- points2D[i + 1].x = (float)tgpi->bottom[0];
- points2D[i + 1].y = (float)tgpi->top[1];
+ points2D[i + 1].x = (float)tgpi->end[0];
+ points2D[i + 1].y = (float)tgpi->start[1];
- points2D[i + 2].x = (float)tgpi->bottom[0];
- points2D[i + 2].y = (float)tgpi->bottom[1];
+ points2D[i + 2].x = (float)tgpi->end[0];
+ points2D[i + 2].y = (float)tgpi->end[1];
- points2D[i + 3].x = (float)tgpi->top[0];
- points2D[i + 3].y = (float)tgpi->bottom[1];
+ points2D[i + 3].x = (float)tgpi->start[0];
+ points2D[i + 3].y = (float)tgpi->end[1];
}
/* create a line */
@@ -386,27 +399,42 @@ static void gp_primitive_line(tGPDprimitive *tgpi, tGPspoint *points2D)
int i = tgpi->tot_stored_edges;
- points2D[i].x = (float)tgpi->top[0];
- points2D[i].y = (float)tgpi->top[1];
+ points2D[i].x = (float)tgpi->start[0];
+ points2D[i].y = (float)tgpi->start[1];
- points2D[i + 1].x = (float)tgpi->bottom[0];
- points2D[i + 1].y = (float)tgpi->bottom[1];
+ points2D[i + 1].x = (float)tgpi->end[0];
+ points2D[i + 1].y = (float)tgpi->end[1];
+}
+
+/* unused at the moment */
+void interp_v2_v2v2v2_quadratic(
+ float p[2], const float v1[2], const float v2[2], const float v3[2], const float u)
+{
+ float q0[2], q1[2];
+
+ interp_v2_v2v2(q0, v1, v2, u);
+ interp_v2_v2v2(q1, v2, v3, u);
+
+ interp_v2_v2v2(p, q0, q1, u);
}
/* create an arc */
static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D)
{
const int totpoints = (tgpi->tot_edges + tgpi->tot_stored_edges);
+
const float step = M_PI_2 / (float)(tgpi->tot_edges - 1);
float length[2];
- int start[2];
- int end[2];
+ float start[2];
+ float end[2];
+ float cp[2];
+ float origin[2];
float a = 0.0f;
- start[0] = tgpi->top[0];
- start[1] = tgpi->top[1];
- end[0] = tgpi->bottom[0];
- end[1] = tgpi->bottom[1];
+ copy_v2fl_v2i(start, tgpi->start);
+ copy_v2fl_v2i(end, tgpi->end);
+ copy_v2fl_v2i(cp, tgpi->cp1);
+ copy_v2fl_v2i(origin, tgpi->origin);
if (tgpi->flip) {
SWAP(int, end[0], start[0]);
@@ -416,6 +444,9 @@ static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D)
length[0] = end[0] - start[0];
length[1] = end[1] - start[1];
+ cp[0] = cp[0] - origin[0];
+ cp[1] = cp[1] - origin[1];
+
for (int i = tgpi->tot_stored_edges; i < totpoints; i++) {
tGPspoint *p2d = &points2D[i];
p2d->x = (start[0] + sinf(a) * length[0]);
@@ -429,20 +460,20 @@ static void gp_primitive_bezier(tGPDprimitive *tgpi, tGPspoint *points2D)
{
const int totpoints = (tgpi->tot_edges + tgpi->tot_stored_edges);
const float step = 1.0f / (float)(tgpi->tot_edges - 1);
- float cp1[2];
- float cp2[2];
- float cp3[2];
- float cp4[2];
+ float bcp1[2];
+ float bcp2[2];
+ float bcp3[2];
+ float bcp4[2];
float a = 0.0f;
- copy_v2fl_v2i(cp1, tgpi->top);
- copy_v2fl_v2i(cp2, tgpi->bezcp1);
- copy_v2fl_v2i(cp3, tgpi->bezcp2);
- copy_v2fl_v2i(cp4, tgpi->bottom);
+ copy_v2fl_v2i(bcp1, tgpi->start);
+ copy_v2fl_v2i(bcp2, tgpi->cp1);
+ copy_v2fl_v2i(bcp3, tgpi->cp2);
+ copy_v2fl_v2i(bcp4, tgpi->end);
for (int i = tgpi->tot_stored_edges; i < totpoints; i++)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list