Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-09 09:05:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-09 09:12:07 +0300
commit80a7c57e5e8d4ea9bec6597a49a1e606875e5d7b (patch)
treed764e017c9f3b6a749ffb904cdf5ee46e1ded542
parent39663fd049f00a0dff5cf8d8737aece5efd77520 (diff)
Tool System: add grease pencil primitive tool
-rw-r--r--release/scripts/startup/bl_ui/space_toolsystem_toolbar.py45
-rw-r--r--release/scripts/startup/bl_ui/space_topbar.py3
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c10
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c35
4 files changed, 79 insertions, 14 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 8ea25a99d6c..1664a6067b9 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1215,6 +1215,45 @@ class _defs_gpencil_paint:
),
)
+ @ToolDef.from_fn
+ def line():
+ return dict(
+ text="Line",
+ icon="ops.gpencil.primitive_line",
+ widget=None,
+ keymap=(
+ ("gpencil.primitive",
+ dict(type='LINE', wait_for_input=False),
+ dict(type='EVT_TWEAK_A', value='ANY')),
+ ),
+ )
+
+ @ToolDef.from_fn
+ def box():
+ return dict(
+ text="Box",
+ icon="ops.gpencil.primitive_box",
+ widget=None,
+ keymap=(
+ ("gpencil.primitive",
+ dict(type='BOX', wait_for_input=False),
+ dict(type='EVT_TWEAK_A', value='ANY')),
+ ),
+ )
+
+ @ToolDef.from_fn
+ def circle():
+ return dict(
+ text="Circle",
+ icon="ops.gpencil.primitive_circle",
+ widget=None,
+ keymap=(
+ ("gpencil.primitive",
+ dict(type='CIRCLE', wait_for_input=False),
+ dict(type='EVT_TWEAK_A', value='ANY')),
+ ),
+ )
+
class _defs_gpencil_edit:
@ToolDef.from_fn
@@ -1804,7 +1843,13 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
_defs_weight_paint.gradient,
],
'GPENCIL_PAINT': [
+ _defs_view3d_generic.cursor,
+ None,
_defs_gpencil_paint.generate_from_brushes,
+ None,
+ _defs_gpencil_paint.line,
+ _defs_gpencil_paint.box,
+ _defs_gpencil_paint.circle,
],
'GPENCIL_EDIT': [
_defs_view3d_generic.cursor,
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index f343dae4076..c6eb047558a 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -146,7 +146,8 @@ class TOPBAR_HT_lower_bar(Header):
# layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
pass
elif tool_mode == 'GPENCIL_PAINT':
- layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_paint", category="")
+ if (tool is not None) and tool.has_datablock:
+ layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_paint", category="")
elif tool_mode == 'GPENCIL_SCULPT':
layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_sculpt", category="")
elif tool_mode == 'GPENCIL_WEIGHT':
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index c2e078ff600..a343d9d680d 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -46,6 +46,7 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_toolsystem.h"
#include "RNA_access.h"
@@ -91,7 +92,8 @@ static bool gp_stroke_paintmode_draw_poll(bContext *C)
Brush *brush = BKE_brush_getactive_gpencil(ts);
return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) &&
(brush && brush->gpencil_settings) &&
- (brush->gpencil_tool == GPAINT_TOOL_DRAW));
+ (brush->gpencil_tool == GPAINT_TOOL_DRAW) &&
+ WM_toolsystem_active_tool_is_brush(C));
}
/* Poll callback for stroke painting (erase brush) */
@@ -103,7 +105,8 @@ static bool gp_stroke_paintmode_erase_poll(bContext *C)
Brush *brush = BKE_brush_getactive_gpencil(ts);
return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) &&
(brush && brush->gpencil_settings) &&
- (brush->gpencil_tool == GPAINT_TOOL_ERASE));
+ (brush->gpencil_tool == GPAINT_TOOL_ERASE) &&
+ WM_toolsystem_active_tool_is_brush(C));
}
/* Poll callback for stroke painting (fill) */
@@ -115,7 +118,8 @@ static bool gp_stroke_paintmode_fill_poll(bContext *C)
Brush *brush = BKE_brush_getactive_gpencil(ts);
return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) &&
(brush && brush->gpencil_settings) &&
- (brush->gpencil_tool == GPAINT_TOOL_FILL));
+ (brush->gpencil_tool == GPAINT_TOOL_FILL) &&
+ WM_toolsystem_active_tool_is_brush(C));
}
/* Poll callback for stroke sculpting mode */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 0e15e9f0a4e..752e0dc6857 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -411,6 +411,15 @@ static void gpencil_primitive_update(bContext *C, wmOperator *op, tGPDprimitive
/* ----------------------- */
+static void gpencil_primitive_interaction_begin(tGPDprimitive *tgpi, const wmEvent *event)
+{
+ tgpi->top[0] = event->mval[0];
+ tgpi->top[1] = event->mval[1];
+
+ tgpi->bottom[0] = event->mval[0];
+ tgpi->bottom[1] = event->mval[1];
+}
+
/* Exit and free memory */
static void gpencil_primitive_exit(bContext *C, wmOperator *op)
{
@@ -498,7 +507,7 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
/* ----------------------- */
/* Invoke handler: Initialize the operator */
-static int gpencil_primitive_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int gpencil_primitive_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
bGPdata *gpd = CTX_data_gpencil_data(C);
@@ -508,6 +517,12 @@ static int gpencil_primitive_invoke(bContext *C, wmOperator *op, const wmEvent *
gpencil_primitive_init(C, op);
tgpi = op->customdata;
+ const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
+ if (!is_modal) {
+ tgpi->flag = IN_PROGRESS;
+ gpencil_primitive_interaction_begin(tgpi, event);
+ }
+
/* if in tools region, wait till we get to the main (3d-space)
* region before allowing drawing to take place.
*/
@@ -531,7 +546,7 @@ static int gpencil_primitive_invoke(bContext *C, wmOperator *op, const wmEvent *
}
/* Helper to complete a primitive */
-static void gpencil_primitive_done(bContext *C, wmOperator *op, wmWindow *win, tGPDprimitive *tgpi)
+static void gpencil_primitive_interaction_end(bContext *C, wmOperator *op, wmWindow *win, tGPDprimitive *tgpi)
{
bGPDframe *gpf;
bGPDstroke *gps;
@@ -589,17 +604,12 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
/* start drawing primitive */
/* TODO: Ignore if not in main region yet */
tgpi->flag = IN_PROGRESS;
-
- tgpi->top[0] = event->mval[0];
- tgpi->top[1] = event->mval[1];
-
- tgpi->bottom[0] = event->mval[0];
- tgpi->bottom[1] = event->mval[1];
+ gpencil_primitive_interaction_begin(tgpi, event);
}
else if ((event->val == KM_RELEASE) && (tgpi->flag == IN_PROGRESS)) {
/* stop drawing primitive */
tgpi->flag = IDLE;
- gpencil_primitive_done(C, op, win, tgpi);
+ gpencil_primitive_interaction_end(C, op, win, tgpi);
/* done! */
return OPERATOR_FINISHED;
}
@@ -612,7 +622,7 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
case RETKEY: /* confirm */
{
tgpi->flag = IDLE;
- gpencil_primitive_done(C, op, win, tgpi);
+ gpencil_primitive_interaction_end(C, op, win, tgpi);
/* done! */
return OPERATOR_FINISHED;
}
@@ -735,8 +745,13 @@ void GPENCIL_OT_primitive(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;
/* properties */
+ PropertyRNA *prop;
+
RNA_def_int(ot->srna, "edges", 4, MIN_EDGES, MAX_EDGES, "Edges", "Number of polygon edges", MIN_EDGES, MAX_EDGES);
RNA_def_enum(ot->srna, "type", primitive_type, GP_STROKE_BOX, "Type", "Type of shape");
+
+ prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
/* *************************************************************** */