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 /source/blender/editors/gpencil
parent39663fd049f00a0dff5cf8d8737aece5efd77520 (diff)
Tool System: add grease pencil primitive tool
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c10
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c35
2 files changed, 32 insertions, 13 deletions
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);
}
/* *************************************************************** */