GPencil: Fix size difference between radial control and Brush size

Due an internal scale of the brush size done by grease pencil
draw tool (this scale factor cannot be removed), the size of the
radial control is not equal to the actual stroke thickness and
this makes the radial size displayed useless.

This patch adds a new property that allows to pass the
path of the tool path and this value is used to apply
the correct scale to the radial size.

Reviewed By: mendio, frogstomp, pepeland, brecht

Differential Revision: https://developer.blender.org/D16866
This commit is contained in:
Antonio Vazquez 2023-01-05 18:59:09 +01:00
parent 59ce7bf5a9
commit 0fb12a9c2e
3 changed files with 36 additions and 3 deletions

View File

@ -1780,6 +1780,20 @@ float ED_gpencil_cursor_radius(bContext *C, int x, int y)
return radius;
}
float ED_gpencil_radial_control_scale(struct bContext *C,
struct Brush *brush,
float initial_value,
const int mval[2])
{
float scale_fac = 1.0f;
if ((brush && brush->gpencil_settings) && (brush->gpencil_tool == GPAINT_TOOL_DRAW)) {
float cursor_radius = ED_gpencil_cursor_radius(C, mval[0], mval[1]);
scale_fac = max_ff(cursor_radius, 1.0f) / max_ff(initial_value, 1.0f);
}
return scale_fac;
}
/**
* Helper callback for drawing the cursor itself.
*/

View File

@ -645,6 +645,10 @@ void ED_gpencil_stroke_close_by_distance(struct bGPDstroke *gps, float threshold
* Calculate the brush cursor size in world space.
*/
float ED_gpencil_cursor_radius(struct bContext *C, int x, int y);
float ED_gpencil_radial_control_scale(struct bContext *C,
struct Brush *brush,
float initial_value,
const int mval[2]);
#ifdef __cplusplus
}

View File

@ -73,6 +73,7 @@
#include "IMB_imbuf_types.h"
#include "ED_fileselect.h"
#include "ED_gpencil.h"
#include "ED_numinput.h"
#include "ED_screen.h"
#include "ED_undo.h"
@ -2191,6 +2192,7 @@ typedef struct {
int initial_co[2];
int slow_mouse[2];
bool slow_mode;
float scale_fac;
Dial *dial;
GPUTexture *texture;
ListBase orig_paintcursors;
@ -2244,7 +2246,7 @@ static void radial_control_update_header(wmOperator *op, bContext *C)
ED_area_status_text(area, msg);
}
static void radial_control_set_initial_mouse(RadialControl *rc, const wmEvent *event)
static void radial_control_set_initial_mouse(bContext *C, RadialControl *rc, const wmEvent *event)
{
float d[2] = {0, 0};
float zoom[2] = {1, 1};
@ -2279,6 +2281,15 @@ static void radial_control_set_initial_mouse(RadialControl *rc, const wmEvent *e
d[0] *= zoom[0];
d[1] *= zoom[1];
}
/* Grease pencil draw tool needs to rescale the cursor size. If we don't do that
* the size of the radial is not equals to the actual stroke size. */
if (rc->ptr.owner_id && GS(rc->ptr.owner_id->name) == ID_BR && rc->prop == &rna_Brush_size) {
rc->scale_fac = ED_gpencil_radial_control_scale(
C, (Brush *)rc->ptr.owner_id, rc->initial_value, event->mval);
}
else {
rc->scale_fac = 1.0f;
}
rc->initial_mouse[0] -= d[0];
rc->initial_mouse[1] -= d[1];
@ -2483,6 +2494,9 @@ static void radial_control_paint_cursor(bContext *UNUSED(C), int x, int y, void
GPU_matrix_scale_2fv(zoom);
}
/* Apply scale correction (used by grease pencil brushes). */
GPU_matrix_scale_2f(rc->scale_fac, rc->scale_fac);
/* draw rotated texture */
radial_control_paint_tex(rc, tex_radius, alpha);
@ -2816,7 +2830,7 @@ static int radial_control_invoke(bContext *C, wmOperator *op, const wmEvent *eve
}
rc->current_value = rc->initial_value;
radial_control_set_initial_mouse(rc, event);
radial_control_set_initial_mouse(C, rc, event);
radial_control_set_tex(rc);
rc->init_event = WM_userdef_event_type_from_keymap_type(event->type);
@ -3331,7 +3345,8 @@ static int redraw_timer_exec(bContext *C, wmOperator *op)
const int cfra = scene->r.cfra;
const char *infostr = "";
/* NOTE: Depsgraph is used to update scene for a new state, so no need to ensure evaluation here.
/* NOTE: Depsgraph is used to update scene for a new state, so no need to ensure evaluation
* here.
*/
struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);