Tool System: add grease pencil primitive tool
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/* *************************************************************** */
|
||||
|
||||
Reference in New Issue
Block a user