[Bf-blender-cvs] [c918a8ba28f] greasepencil-experimental: GP: Draw: Speedline guides
Charlie Jolly
noreply at git.blender.org
Fri Jan 4 10:48:03 CET 2019
Commit: c918a8ba28f03709208247ed156729d4a591f7b0
Author: Charlie Jolly
Date: Wed Jan 2 17:57:07 2019 +0000
Branches: greasepencil-experimental
https://developer.blender.org/rBc918a8ba28f03709208247ed156729d4a591f7b0
GP: Draw: Speedline guides
Initial commit for artist feedback.
Provides drawing guides or constraints for drawing lines.
Notes:
UI Panel in 3D view. Some settings only have keyboard access at the moment.
Alt-C: Screen space position of circular guide
C: Circular guide
L: Parallel line guide
M: Flip direction 90° degrees
V: Freehand mode (turn off)
J/K: For line guide, rotate guide (alt 45°, shift 15°)
Alt-L: Set angle to that of the last stroke (useful to align to freehand strokes)
Ctrl-L: Set angle to 0°
Todo:
On screen guidelines
===================================================================
M release/scripts/presets/keyconfig/keymap_data/blender_default.py
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 3912afa8f89..e3955959a8d 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3039,7 +3039,24 @@ def km_grease_pencil_stroke_paint_draw_brush(params):
# Erase
("gpencil.draw", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
{"properties": [("mode", 'ERASER'), ("wait_for_input", False)]}),
-
+ # Constrain Guides Speedlines
+ # Freehand
+ ("gpencil.draw", {"type": 'J', "value": 'PRESS'}, None),
+ ("gpencil.draw", {"type": 'J', "value": 'PRESS', "alt": True}, None),
+ ("gpencil.draw", {"type": 'J', "value": 'PRESS', "shift": True}, None),
+ ("gpencil.draw", {"type": 'K', "value": 'PRESS'}, None),
+ ("gpencil.draw", {"type": 'K', "value": 'PRESS', "alt": True}, None),
+ ("gpencil.draw", {"type": 'K', "value": 'PRESS', "shift": True}, None),
+ ("gpencil.draw", {"type": 'L', "value": 'PRESS'}, None),
+ ("gpencil.draw", {"type": 'L', "value": 'PRESS', "alt": True}, None),
+ ("gpencil.draw", {"type": 'L', "value": 'PRESS', "ctrl": True}, None),
+ ("gpencil.draw", {"type": 'V', "value": 'PRESS'}, None),
+ # Mirror or flip
+ ("gpencil.draw", {"type": 'M', "value": 'PRESS'}, None),
+ # Mode
+ ("gpencil.draw", {"type": 'C', "value": 'PRESS'}, None),
+ # Set reference point
+ ("gpencil.draw", {"type": 'C', "value": 'PRESS', "alt": True}, None),
# Tablet Mappings for Drawing ------------------ */
# For now, only support direct drawing using the eraser, as most users using a tablet
# may still want to use that as their primary pointing device!
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 47863156898..a4e0cd4a20e 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -245,6 +245,18 @@ class VIEW3D_HT_header(Header):
text=lk_name,
icon=lk_icon,
)
+
+ if object_mode in {'PAINT_GPENCIL'}:
+ if context.workspace.tools.from_space_view3d_mode(object_mode).name == "Draw":
+ settings = tool_settings.gpencil_sculpt
+ row = layout.row(align=True)
+ row.prop(settings, "use_speed_guide", text="", icon='GRID')
+ sub = row.row(align=True)
+ sub.enabled = settings.use_speed_guide
+ sub.popover(
+ panel="VIEW3D_PT_gpencil_guide",
+ text="Guides"
+ )
layout.separator_spacer()
@@ -5320,7 +5332,30 @@ class VIEW3D_PT_gpencil_lock(Panel):
col = row.column()
col.prop(context.tool_settings.gpencil_sculpt, "lock_axis", expand=True)
+
+class VIEW3D_PT_gpencil_guide(Panel):
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'HEADER'
+ bl_label = "Guides"
+
+ @staticmethod
+ def draw(self, context):
+ settings = context.tool_settings.gpencil_sculpt
+
+ layout = self.layout
+ layout.label(text="Guides")
+
+ row = layout.row()
+ col = row.column()
+ col.prop(settings, "guide_type", expand=True)
+
+ row = col.row(align=True)
+ row.active = bool(settings.guide_type == "PARALLEL");
+ row.prop(settings, "guide_angle")
+
+ col.prop(settings, "guide_flip")
+
class VIEW3D_PT_overlay_gpencil_options(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'HEADER'
@@ -5790,6 +5825,7 @@ classes = (
VIEW3D_PT_snapping,
VIEW3D_PT_gpencil_origin,
VIEW3D_PT_gpencil_lock,
+ VIEW3D_PT_gpencil_guide,
VIEW3D_PT_transform_orientations,
VIEW3D_PT_overlay_gpencil_options,
VIEW3D_PT_context_properties,
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 2c071493fb1..20e93494fc9 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -157,6 +157,7 @@ typedef struct tGPsdata {
float mval[2]; /* current mouse-position */
float mvalo[2]; /* previous recorded mouse-position */
+ float mvali[2]; /* initial recorded mouse-position */
float pressure; /* current stylus pressure */
float opressure; /* previous stylus pressure */
@@ -182,7 +183,7 @@ typedef struct tGPsdata {
Brush *brush; /* current drawing brush */
Brush *eraser; /* default eraser brush */
- short straight[2]; /* 1: line horizontal, 2: line vertical, other: not defined, second element position */
+ short straight[2]; /* 1: line horizontal, 2: line vertical, 3: speed lines, other: not defined, second element position */
int lock_axis; /* lock drawing to one axis */
bool disable_fill; /* the stroke is no fill mode */
@@ -2536,10 +2537,21 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
}
}
+/* Helper to rotate point around origin */
+static void gp_rotate_v2_v2v2fl(float v[2], const float p[2], const float origin[2], const float angle)
+{
+ float pt[2];
+ float r[2];
+ sub_v2_v2v2(pt, p, origin);
+ rotate_v2_v2fl(r, pt, angle);
+ add_v2_v2v2(v, r, origin);
+}
+
/* handle draw event */
static void gpencil_draw_apply_event(bContext *C, wmOperator *op, const wmEvent *event, Depsgraph *depsgraph, float x, float y)
{
tGPsdata *p = op->customdata;
+ ToolSettings *ts = p->scene->toolsettings;
PointerRNA itemptr;
float mousef[2];
int tablet = 0;
@@ -2553,7 +2565,14 @@ static void gpencil_draw_apply_event(bContext *C, wmOperator *op, const wmEvent
p->shift = event->shift;
/* verify key status for straight lines */
- if ((event->alt > 0) && (RNA_boolean_get(op->ptr, "disable_straight") == false)) {
+
+ if (ts->gp_sculpt.use_speed_guide) {
+ if (p->straight[0] == 0) {
+ p->straight[0] = 3;
+ p->straight[1] = ts->gp_sculpt.guide_type;
+ }
+ }
+ else if ((event->alt > 0) && (RNA_boolean_get(op->ptr, "disable_straight") == false)) {
if (p->straight[0] == 0) {
int dx = (int)fabsf(p->mval[0] - p->mvalo[0]);
int dy = (int)fabsf(p->mval[1] - p->mvalo[1]);
@@ -2622,12 +2641,12 @@ static void gpencil_draw_apply_event(bContext *C, wmOperator *op, const wmEvent
if (p->flags & GP_PAINTFLAG_FIRSTRUN) {
p->flags &= ~GP_PAINTFLAG_FIRSTRUN;
- p->mvalo[0] = p->mval[0];
- p->mvalo[1] = p->mval[1];
+ copy_v2_v2(p->mvalo, p->mval);
p->opressure = p->pressure;
p->inittime = p->ocurtime = p->curtime;
p->straight[0] = 0;
p->straight[1] = 0;
+ copy_v2_v2(p->mvali, p->mval); /* save initial mouse */
/* special exception here for too high pressure values on first touch in
* windows for some tablets, then we just skip first touch...
@@ -2638,7 +2657,40 @@ static void gpencil_draw_apply_event(bContext *C, wmOperator *op, const wmEvent
/* check if alt key is pressed and limit to straight lines */
if ((p->paintmode != GP_PAINTMODE_ERASER) && (p->straight[0] != 0)) {
- if (p->straight[0] == 1) {
+ if (p->straight[0] == 3) {
+ /* speed_guide */
+ int spdmode = p->straight[1];
+ bool flip = ts->gp_sculpt.guide_flip;
+ if (spdmode == 0) {
+ /* speed_guide - use single origin point */
+ float origin[2];
+ RNA_float_get_array(op->ptr, "guide_origin", origin);
+ if (!flip) {
+ /* speed_guide - constrain to rings (distance from origin) */
+ float distance;
+ distance = len_v2v2(p->mvali, origin);
+ dist_ensure_v2_v2fl(p->mval, origin, distance);
+ }
+ else {
+ /* speed_guide - constrain in lines (direction from origin) */
+ closest_to_line_v2(p->mval, p->mval, p->mvali, origin);
+ }
+ }
+ else if (spdmode == 1) {
+ /* speed_guide - use angle of direction */
+ float point[2];
+ float unit[2];
+ float angle;
+ copy_v2_v2(unit, p->mvali);
+ unit[0] += 1.0f; /* start from horizontal */
+ angle = ts->gp_sculpt.guide_angle;
+ if (flip)
+ angle += M_PI_2; /* rotate 90 degrees */
+ gp_rotate_v2_v2v2fl(point, unit, p->mvali, angle);
+ closest_to_line_v2(p->mval, p->mval, p->mvali, point);
+ }
+ }
+ else if (p->straight[0] == 1) {
/* horizontal */
p->mval[1] = p->straight[1]; /* replace y */
}
@@ -2743,6 +2795,74 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
/* ------------------------------- */
+static void gpencil_guide_event_handling(bContext *C, wmOperator *op, const wmEvent *event, tGPsdata *p)
+{
+ ToolSettings *ts = p->scene->toolsettings;
+ if ((event->type == VKEY) && (event->val == KM_PRESS)) {
+ /* Freehand mode, turn off speed guide */
+ ts->gp_sculpt.use_speed_guide = false;
+ }
+ else if ((event->type == MKEY) && (event->val == KM_PRESS)) {
+ /* Flip direction */
+ copy_v2_v2(p->mvali, p->mval);
+ ts->gp_sculpt.guide_flip ^= 1;
+ }
+ else if ((event->type == LKEY) && (event->val == KM_PRESS)) {
+ /* Line guides */
+ ts->gp_sculpt.use_speed_guide = true;
+ copy_v2_v2(p->mvali, p->mval);
+ if (event->ctrl) {
+ ts->gp_sculpt.guide_angle = 0.0f;
+ ts->gp_sculpt.guide_type = GP_GUIDE_PARALLEL;
+ ts->gp_sculpt.guide_flip = 0;
+ }
+ else if (event->alt) {
+ ts->gp_sculpt.guide_type = GP_GUIDE_PARALLEL;
+ ts->gp_sculpt.guide_angle = RNA_float_get(op->ptr, "guide_last_angle");
+ ts->gp_sculpt.guide_flip = 0;
+ }
+ else if (ts->gp_sculpt.guide_type == 1) {
+ ts->gp_sculpt.guide_flip ^= 1;
+ }
+ else {
+ ts->gp_sculpt.guide_type = GP_GUIDE_PARALLEL;
+ ts->gp_sculpt.guide_flip = 0;
+ }
+
+ }
+ else if ((event->type == CKEY) && (event->val == KM_PRESS)) {
+ /* Point guide */
+ ts->gp_sculpt.use_speed_guide = true;
+ copy_v2_v2(p->mvali, p->mval);
+ if (event->alt) {
+ float origin[2];
+ copy_v2fl_v2i(origin, event->mval);
+ RNA_float_set_array(op->ptr, "guide_origin", origin);
+ ts->gp_sculpt.guide_type = GP_GUIDE_CIRCULAR;
+ ts->gp_sculpt.guide_flip = 0;
+ }
+ else if (ts->gp_sculpt.guide_ty
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list