[Bf-blender-cvs] [41b580619b9] greasepencil-object: GP: Primitive: Enable manipulators for Line/Box/Circle
Charlie Jolly
noreply at git.blender.org
Fri Dec 14 02:33:30 CET 2018
Commit: 41b580619b9c89c5e1d3962e877db3a483d0ae69
Author: Charlie Jolly
Date: Fri Dec 14 01:24:56 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rB41b580619b9c89c5e1d3962e877db3a483d0ae69
GP: Primitive: Enable manipulators for Line/Box/Circle
Based on GP team feedback, all primitive tools have consistent behaviour.
Additionally:
AKEY extends Line, Arc and Curve.
CKEY changes type to Curve/Arc (toggle).
LKEY changes type to Line.
GKEY moves shape.
===================================================================
M source/blender/editors/gpencil/gpencil_primitive.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 8eda301e2df..35167ad1b61 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -95,6 +95,7 @@
#define IDLE 0
#define IN_PROGRESS 1
#define IN_CURVE_EDIT 2
+#define IN_MOVE 3
#define SELECT_NONE 0
#define SELECT_START 1
@@ -104,7 +105,11 @@
#define BIG_SIZE_CTL 15
#define MID_SIZE_CTL 10
-#define SMALL_SIZE_CTL 8
+#define SMALL_SIZE_CTL 8
+
+#define MOVE_NONE 0
+#define MOVE_ENDS 1
+#define MOVE_CP 2
/* ************************************************ */
/* Core/Shared Utilities */
@@ -291,7 +296,6 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
/* Random generator, only init once. */
tgpi->rng = BLI_rng_new((uint)0);
-
}
/* add new segment to curve */
@@ -410,8 +414,15 @@ static void gp_primitive_rectangle(tGPDprimitive *tgpi, tGPspoint *points2D)
mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
float color[4];
+ UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
+ gp_primitive_set_cp(tgpi, tgpi->end, color, BIG_SIZE_CTL);
+ if (tgpi->tot_stored_edges) {
+ UI_GetThemeColor4fv(TH_REDALERT, color);
+ gp_primitive_set_cp(tgpi, tgpi->start, color, SMALL_SIZE_CTL);
+ }
+ else
+ gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
UI_GetThemeColor4fv(TH_REDALERT, color);
- gp_primitive_set_cp(tgpi, tgpi->origin, color, SMALL_SIZE_CTL);
gp_primitive_set_cp(tgpi, tgpi->midpoint, color, SMALL_SIZE_CTL);
}
@@ -437,11 +448,16 @@ static void gp_primitive_line(tGPDprimitive *tgpi, tGPspoint *points2D)
interp_v2_v2v2(&p2d->x, tgpi->start, tgpi->end, a);
a += step;
}
-
- float color[4];
+ }
+ float color[4];
+ UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
+ gp_primitive_set_cp(tgpi, tgpi->end, color, BIG_SIZE_CTL);
+ if (tgpi->tot_stored_edges) {
UI_GetThemeColor4fv(TH_REDALERT, color);
- gp_primitive_set_cp(tgpi, tgpi->origin, color, SMALL_SIZE_CTL);
+ gp_primitive_set_cp(tgpi, tgpi->start, color, SMALL_SIZE_CTL);
}
+ else
+ gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
}
/* unused at the moment */
@@ -485,15 +501,15 @@ static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D)
}
float color[4];
UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
- gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
gp_primitive_set_cp(tgpi, tgpi->end, color, BIG_SIZE_CTL);
- /*UI_GetThemeColor4fv(TH_REDALERT, color);
- gp_primitive_set_cp(tgpi, tgpi->midpoint, color, SMALL_SIZE_CTL);
- gp_primitive_set_cp(tgpi, corner, color, SMALL_SIZE_CTL);
- gp_primitive_set_cp(tgpi, tgpi->cp2, color, SMALL_SIZE_CTL);*/
+ if (tgpi->tot_stored_edges) {
+ UI_GetThemeColor4fv(TH_REDALERT, color);
+ gp_primitive_set_cp(tgpi, tgpi->start, color, SMALL_SIZE_CTL);
+ }
+ else
+ gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
UI_GetThemeColor4fv(TH_GP_VERTEX_SELECT, color);
gp_primitive_set_cp(tgpi, tgpi->cp1, color, BIG_SIZE_CTL * 0.9f);
-
}
/* create a bezier */
@@ -519,8 +535,13 @@ static void gp_primitive_bezier(tGPDprimitive *tgpi, tGPspoint *points2D)
}
float color[4];
UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
- gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
gp_primitive_set_cp(tgpi, tgpi->end, color, BIG_SIZE_CTL);
+ if (tgpi->tot_stored_edges) {
+ UI_GetThemeColor4fv(TH_REDALERT, color);
+ gp_primitive_set_cp(tgpi, tgpi->start, color, SMALL_SIZE_CTL);
+ }
+ else
+ gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
UI_GetThemeColor4fv(TH_GP_VERTEX_SELECT, color);
gp_primitive_set_cp(tgpi, tgpi->cp1, color, BIG_SIZE_CTL * 0.9f);
gp_primitive_set_cp(tgpi, tgpi->cp2, color, BIG_SIZE_CTL * 0.9f);
@@ -548,10 +569,10 @@ static void gp_primitive_circle(tGPDprimitive *tgpi, tGPspoint *points2D)
a += step;
}
float color[4];
+ UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
+ gp_primitive_set_cp(tgpi, tgpi->end, color, BIG_SIZE_CTL);
+ gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
UI_GetThemeColor4fv(TH_REDALERT, color);
- gp_primitive_set_cp(tgpi, tgpi->start, color, SMALL_SIZE_CTL);
- gp_primitive_set_cp(tgpi, tgpi->end, color, SMALL_SIZE_CTL);
- gp_primitive_set_cp(tgpi, tgpi->origin, color, SMALL_SIZE_CTL);
gp_primitive_set_cp(tgpi, center, color, SMALL_SIZE_CTL);
}
@@ -579,8 +600,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* compute screen-space coordinates for points */
tGPspoint *points2D = tgpi->points;
-
-
+
switch (tgpi->type) {
case GP_STROKE_BOX:
gp_primitive_rectangle(tgpi, points2D);
@@ -598,7 +618,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
gp_primitive_bezier(tgpi, points2D);
default:
break;
- }
+ }
/* convert screen-coordinates to 3D coordinates */
gp_session_validatebuffer(tgpi);
@@ -746,8 +766,6 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
else {
add_v2_fl(&p2d->x, fac);
}
-
-
}
/* apply randomness to pressure */
@@ -1103,16 +1121,16 @@ static void gpencil_primitive_to_square(tGPDprimitive *tgpi, const float x, cons
}
/* Helper to rotate point around origin */
-static void gp_rotate_v2_v2v2fl(float v[2], const float a[2], const float origin[2], const float angle)
+static void gp_rotate_v2_v2v2fl(float v[2], const float p[2], const float origin[2], const float angle)
{
- float p[2];
+ float pt[2];
float r[2];
- sub_v2_v2v2(p, a, origin);
- rotate_v2_v2fl(r, p, angle);
+ sub_v2_v2v2(pt, p, origin);
+ rotate_v2_v2fl(r, pt, angle);
add_v2_v2v2(v, r, origin);
}
-/* Helper to rotate line around it's centre */
+/* Helper to rotate line around line centre */
static void gp_primitive_rotate_line(float va[2], float vb[2], const float a[2], const float b[2], const float angle)
{
float midpoint[2];
@@ -1124,126 +1142,29 @@ static void gp_primitive_rotate_line(float va[2], float vb[2], const float a[2],
/* Helper to update cps */
static void gp_primitive_update_cps(tGPDprimitive *tgpi)
{
- if (tgpi->type == GP_STROKE_ARC) {
+ if (!tgpi->curve) {
mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
-
- if (tgpi->flip) {
- gp_primitive_rotate_line(tgpi->cp1, tgpi->cp2, tgpi->start, tgpi->end, M_PI_2);
- }
- else {
- gp_primitive_rotate_line(tgpi->cp1, tgpi->cp2, tgpi->end, tgpi->start, M_PI_2);
- }
+ copy_v2_v2(tgpi->cp1, tgpi->midpoint);
+ copy_v2_v2(tgpi->cp2, tgpi->cp1);
}
else if (tgpi->type == GP_STROKE_CURVE) {
mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
copy_v2_v2(tgpi->cp1, tgpi->midpoint);
copy_v2_v2(tgpi->cp2, tgpi->cp1);
}
-}
-
-#define MOVE_NONE 0
-#define MOVE_ENDS 1
-#define MOVE_CP 2
-
-/* arc event handling */
-static void gpencil_primitive_arc_event_handling(bContext *C, wmOperator *op, wmWindow *win, const wmEvent *event, tGPDprimitive *tgpi) {
- /* calculate nearest point then set cursor */
- int move = MOVE_NONE;
- float a = len_v2v2(tgpi->mval, tgpi->start);
- float b = len_v2v2(tgpi->mval, tgpi->end);
-
-
- if (tgpi->flag == IN_CURVE_EDIT) {
- if ((a < 10.0f && tgpi->tot_stored_edges == 0) || b < 10.0f) {
- move = MOVE_ENDS;
- WM_cursor_modal_set(win, BC_RING_CURSOR);
- }
- else {
- move = MOVE_CP;
- WM_cursor_modal_set(win, BC_HANDCURSOR);
- }
- }
-
- switch (event->type) {
- case MOUSEMOVE:
- if ((event->val == KM_PRESS) && tgpi->sel_cp != SELECT_NONE) {
- if (tgpi->sel_cp == SELECT_START && tgpi->tot_stored_edges == 0) {
- copy_v2_v2(tgpi->start, tgpi->mval);
- }
- else if (tgpi->sel_cp == SELECT_END) {
- copy_v2_v2(tgpi->end, tgpi->mval);
- }
- else if (tgpi->sel_cp == SELECT_CP1) {
- float dx = (tgpi->mval[0] - tgpi->mvalo[0]);
- float dy = (tgpi->mval[1] - tgpi->mvalo[1]);
- tgpi->cp1[0] += dx;
- tgpi->cp1[1] += dy;
- }
- copy_v2_v2(tgpi->mvalo, tgpi->mval);
-
- /* update screen */
- gpencil_primitive_update(C, op, tgpi);
- }
- else if ((tgpi->flag == IN_PROGRESS)) {
- gp_primitive_update_cps(tgpi);
- copy_v2_v2(tgpi->mvalo, tgpi->mval);
- gpencil_primitive_update(C, op, tgpi);
- }
- break;
- case LEFTMOUSE:
- if ((event->val == KM_PRESS)) {
- copy_v2_v2(tgpi->mvalo, tgpi->mval);
- /* find nearest cp based on stroke end points */
- if (move == MOVE_ENDS)
- tgpi->sel_cp = (a < b) ? SELECT_START : SELECT_END;
- else if (move == MOVE_CP)
- tgpi->sel_cp = SELECT_CP1;
- else
- tgpi->sel_cp = SELECT_NONE;
- break;
- }
- else if ((event->val == KM_RELEASE) && (tgpi->flag == IN_PROGRESS)) {
- /* set control points and enter edit mode */
- tgpi->flag = IN_CURVE_EDIT;
- gp_primitive_update_cps(tgpi);
- gpencil_primitive_update(C, op, tgpi);
+ else if (tgpi->type == GP_STROKE_ARC) {
+ if (tgpi->flip) {
+ gp_primitive_rotate_line(tgpi->cp1, tgpi->cp2, tgpi->start, tgpi->end, M_PI_2);
}
else {
- tgpi->sel_cp = SELECT_NONE;
- }
- break;
- case FKEY:
- {
- if ((event->val == KM_RELEASE)) {
- tgpi->flip ^= 1;
-
- if ((tgpi->flag == IN_PROGRESS)) {
- gp_primitive_update_cps(tgpi);
- }
- else if ((tgpi->flag == IN_CURVE_EDIT)) {
- mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
- tgpi->cp1[0] = tgpi->midpoint[0] - (tgpi->cp1[0] - tgpi->midpoint[0]);
- tgpi->cp1[1] = tgpi->midpoint[1] - (tgpi->cp1[1] - tgpi->midpoint[1]);
- }
- gpencil_primitive_update(C, op, tgpi);
- }
- break;
- }
- case AKEY:
- if (tgpi->flag == IN_CURVE_EDIT) {
- tgpi->flag = IN_PROGRESS;
- gpencil_primitive_add_segment(tgpi);
- copy_v2_v2(tgpi->start, tgpi->end);
- copy_v2_v2(tgpi->origin, tgpi->start);
- gp_primitive_update_cps(tgpi);
- copy_v2_v2(tgpi->mvalo, tgpi->mval);
+ gp_primitive_rotate_line(tgpi->cp1, tgpi->cp2, tgpi->end, tgpi->start, M_PI_2);
}
- break;
}
}
-/* bezier event handling */
-static void gpencil_primitive_bezier_event_handling(bContext *C, wmOperator *op, wmWindow *win, const wmEvent *event, tGPDprimitive *tgpi) {
+/* edit event handling */
+static void gpencil_primitive_edit_event_handling(bContext *C, wmOperator *op, wmWindow *win, const wmEvent *event, tGPDprimitive *tgpi)
+{
/* calcu
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list