GP: Primitive: Changes from gp branch
F-key to change stroke brush size Fix random bias for jitter
This commit is contained in:
parent
275c627b5e
commit
e119868caa
|
@ -157,6 +157,7 @@ typedef struct tGPDprimitive {
|
|||
int type; /* type of primitive */
|
||||
int orign_type; /* original type of primitive */
|
||||
bool curve; /* type of primitive is a curve */
|
||||
int brush_size; /* brush size */
|
||||
short flip; /* flip option */
|
||||
tGPspoint *points; /* array of data-points for stroke */
|
||||
int point_count; /* number of edges allocated */
|
||||
|
|
|
@ -96,6 +96,7 @@
|
|||
#define IN_PROGRESS 1
|
||||
#define IN_CURVE_EDIT 2
|
||||
#define IN_MOVE 3
|
||||
#define IN_BRUSH_SIZE 4
|
||||
|
||||
#define SELECT_NONE 0
|
||||
#define SELECT_START 1
|
||||
|
@ -375,6 +376,10 @@ static void gpencil_primitive_add_segment(tGPDprimitive *tgpi)
|
|||
/* Helper: set control point */
|
||||
static void gp_primitive_set_cp(tGPDprimitive *tgpi, float p[2], float color[4], int size)
|
||||
{
|
||||
if (tgpi->flag == IN_PROGRESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
bGPDcontrolpoint *cp_points = tgpi->gpd->runtime.cp_points;
|
||||
|
||||
if (tgpi->gpd->runtime.tot_cp_points < MAX_CP) {
|
||||
|
@ -786,9 +791,10 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
|
|||
tGPspoint *p2d = &points2D[i];
|
||||
|
||||
/* set rnd value for reuse */
|
||||
if (p2d->rnd_dirty != true) {
|
||||
if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && (p2d->rnd_dirty != true)) {
|
||||
p2d->rnd[0] = BLI_rng_get_float(tgpi->rng);
|
||||
p2d->rnd[1] = BLI_rng_get_float(tgpi->rng);
|
||||
p2d->rnd[2] = BLI_rng_get_float(tgpi->rng);
|
||||
p2d->rnd_dirty = true;
|
||||
}
|
||||
|
||||
|
@ -842,7 +848,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
|
|||
svec[0] = -mvec[1];
|
||||
svec[1] = mvec[0];
|
||||
|
||||
if (p2d->rnd[0] > 0.5f) {
|
||||
if (p2d->rnd[1] > 0.5f) {
|
||||
mul_v2_fl(svec, -fac);
|
||||
}
|
||||
else {
|
||||
|
@ -856,10 +862,10 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
|
|||
(brush->gpencil_settings->draw_random_press > 0.0f))
|
||||
{
|
||||
if (p2d->rnd[0] > 0.5f) {
|
||||
pressure -= brush->gpencil_settings->draw_random_press * p2d->rnd[0];
|
||||
pressure -= brush->gpencil_settings->draw_random_press * p2d->rnd[1];
|
||||
}
|
||||
else {
|
||||
pressure += brush->gpencil_settings->draw_random_press * p2d->rnd[0];
|
||||
pressure += brush->gpencil_settings->draw_random_press * p2d->rnd[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -876,8 +882,8 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
|
|||
if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) &&
|
||||
(brush->gpencil_settings->draw_random_strength > 0.0f))
|
||||
{
|
||||
if (p2d->rnd[1] > 0.5f) {
|
||||
strength -= strength * brush->gpencil_settings->draw_random_strength * p2d->rnd[1];
|
||||
if (p2d->rnd[2] > 0.5f) {
|
||||
strength -= strength * brush->gpencil_settings->draw_random_strength * p2d->rnd[0];
|
||||
}
|
||||
else {
|
||||
strength += strength * brush->gpencil_settings->draw_random_strength * p2d->rnd[1];
|
||||
|
@ -1323,6 +1329,28 @@ static void gpencil_primitive_edit_event_handling(bContext *C, wmOperator *op, w
|
|||
}
|
||||
}
|
||||
|
||||
/* brush size */
|
||||
static void gpencil_primitive_size(tGPDprimitive *tgpi, bool reset)
|
||||
{
|
||||
Brush * brush = tgpi->brush;
|
||||
if (brush) {
|
||||
if (reset) {
|
||||
brush->size = tgpi->brush_size;
|
||||
tgpi->brush_size = 0;
|
||||
}
|
||||
else {
|
||||
if (tgpi->brush_size == 0) {
|
||||
tgpi->brush_size = brush->size;
|
||||
}
|
||||
float move[2];
|
||||
sub_v2_v2v2(move, tgpi->mval, tgpi->mvalo);
|
||||
int adjust = (move[1] > 0.0f) ? 1 : -1;
|
||||
brush->size += adjust * (int)fabsf(len_manhattan_v2(move));
|
||||
}
|
||||
CLAMP_MIN(brush->size, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* move */
|
||||
static void gpencil_primitive_move(tGPDprimitive *tgpi, bool reset)
|
||||
{
|
||||
|
@ -1385,6 +1413,29 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
|
|||
copy_v2_v2(tgpi->mvalo, tgpi->mval);
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
else if (tgpi->flag == IN_BRUSH_SIZE) {
|
||||
switch (event->type) {
|
||||
case MOUSEMOVE:
|
||||
gpencil_primitive_size(tgpi, false);
|
||||
gpencil_primitive_update(C, op, tgpi);
|
||||
break;
|
||||
case ESCKEY:
|
||||
case MIDDLEMOUSE:
|
||||
case LEFTMOUSE:
|
||||
tgpi->brush_size = 0;
|
||||
tgpi->flag = IN_CURVE_EDIT;
|
||||
break;
|
||||
case RIGHTMOUSE:
|
||||
if (event->val == KM_RELEASE) {
|
||||
tgpi->flag = IN_CURVE_EDIT;
|
||||
gpencil_primitive_size(tgpi, true);
|
||||
gpencil_primitive_update(C, op, tgpi);
|
||||
}
|
||||
break;
|
||||
}
|
||||
copy_v2_v2(tgpi->mvalo, tgpi->mval);
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
else if (tgpi->flag != IDLE) {
|
||||
gpencil_primitive_edit_event_handling(C, op, win, event, tgpi);
|
||||
}
|
||||
|
@ -1477,6 +1528,14 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
|
|||
}
|
||||
break;
|
||||
}
|
||||
case FKEY: /* brush thickness */
|
||||
{
|
||||
if ((event->val == KM_PRESS)) {
|
||||
tgpi->flag = IN_BRUSH_SIZE;
|
||||
WM_cursor_modal_set(win, BC_NS_SCROLLCURSOR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CKEY: /* curve mode */
|
||||
{
|
||||
if ((event->val == KM_PRESS) &&
|
||||
|
|
|
@ -79,7 +79,7 @@ typedef struct tGPspoint {
|
|||
float time; /* Time relative to stroke start (used when converting to path) */
|
||||
float uv_fac; /* factor of uv along the stroke */
|
||||
float uv_rot; /* uv rotation for dor mode */
|
||||
float rnd[2]; /* rnd value */
|
||||
float rnd[3]; /* rnd value */
|
||||
bool rnd_dirty; /* rnd flag */
|
||||
} tGPspoint;
|
||||
|
||||
|
|
Loading…
Reference in New Issue