GP: Add keymap 1 and 2 for select mode

This commit is contained in:
Antonio Vazquez 2018-09-20 11:56:41 +02:00
parent 67a6cb665e
commit add8e1c018
3 changed files with 77 additions and 30 deletions

View File

@ -96,6 +96,37 @@
/* ************************************************ */
/* Stroke Edit Mode Management */
/* poll callback for all stroke editing operators */
static bool gp_stroke_edit_poll(bContext *C)
{
/* edit only supported with grease pencil objects */
Object *ob = CTX_data_active_object(C);
if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
return false;
}
/* NOTE: this is a bit slower, but is the most accurate... */
return CTX_DATA_COUNT(C, editable_gpencil_strokes) != 0;
}
/* poll callback to verify edit mode in 3D view only */
static bool gp_strokes_edit3d_poll(bContext *C)
{
/* edit only supported with grease pencil objects */
Object *ob = CTX_data_active_object(C);
if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
return false;
}
/* 2 Requirements:
* - 1) Editable GP data
* - 2) 3D View only
*/
return (gp_stroke_edit_poll(C) && ED_operator_view3d_active(C));
}
static bool gpencil_editmode_toggle_poll(bContext *C)
{
/* edit only supported with grease pencil objects */
@ -196,6 +227,43 @@ void GPENCIL_OT_editmode_toggle(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
/* set select mode */
static int gpencil_selectmode_toggle_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
ToolSettings *ts = CTX_data_tool_settings(C);
const int mode = RNA_int_get(op->ptr, "mode");
/* Just set mode */
ts->gpencil_selectmode = mode;
WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL);
DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
return OPERATOR_FINISHED;
}
void GPENCIL_OT_selectmode_toggle(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name = "Select Mode Toggle";
ot->idname = "GPENCIL_OT_selectmode_toggle";
ot->description = "Set selection mode for Grease Pencil strokes";
/* callbacks */
ot->exec = gpencil_selectmode_toggle_exec;
ot->poll = gp_strokes_edit3d_poll;
/* flags */
ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
/* properties */
prop = RNA_def_int(ot->srna, "mode", 0, 0, 1, "Select mode", "Select mode", 0, 1);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
/* Stroke Paint Mode Management */
static bool gpencil_paintmode_toggle_poll(bContext *C)
@ -472,36 +540,6 @@ void GPENCIL_OT_weightmode_toggle(wmOperatorType *ot)
/* ************************************************ */
/* Stroke Editing Operators */
/* poll callback for all stroke editing operators */
static bool gp_stroke_edit_poll(bContext *C)
{
/* edit only supported with grease pencil objects */
Object *ob = CTX_data_active_object(C);
if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
return false;
}
/* NOTE: this is a bit slower, but is the most accurate... */
return CTX_DATA_COUNT(C, editable_gpencil_strokes) != 0;
}
/* poll callback to verify edit mode in 3D view only */
static bool gp_strokes_edit3d_poll(bContext *C)
{
/* edit only supported with grease pencil objects */
Object *ob = CTX_data_active_object(C);
if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
return false;
}
/* 2 Requirements:
* - 1) Editable GP data
* - 2) 3D View only
*/
return (gp_stroke_edit_poll(C) && ED_operator_view3d_active(C));
}
/* ************ Stroke Hide selection Toggle ************** */
static int gpencil_hideselect_toggle_exec(bContext *C, wmOperator *UNUSED(op))

View File

@ -287,6 +287,7 @@ typedef enum eGPencil_PaintModes {
/* stroke editing ----- */
void GPENCIL_OT_editmode_toggle(struct wmOperatorType *ot);
void GPENCIL_OT_selectmode_toggle(struct wmOperatorType *ot);
void GPENCIL_OT_paintmode_toggle(struct wmOperatorType *ot);
void GPENCIL_OT_sculptmode_toggle(struct wmOperatorType *ot);
void GPENCIL_OT_weightmode_toggle(struct wmOperatorType *ot);

View File

@ -458,6 +458,13 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
/* toggle edit mode */
WM_keymap_add_item(keymap, "GPENCIL_OT_editmode_toggle", TABKEY, KM_PRESS, 0, 0);
/* select mode */
kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_selectmode_toggle", ONEKEY, KM_PRESS,0 , 0);
RNA_int_set(kmi->ptr, "mode", 0);
kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_selectmode_toggle", TWOKEY, KM_PRESS, 0, 0);
RNA_int_set(kmi->ptr, "mode", 1);
}
/* keys for draw with a drawing brush (no fill) */
@ -673,6 +680,7 @@ void ED_operatortypes_gpencil(void)
/* Editing (Strokes) ------------ */
WM_operatortype_append(GPENCIL_OT_editmode_toggle);
WM_operatortype_append(GPENCIL_OT_selectmode_toggle);
WM_operatortype_append(GPENCIL_OT_paintmode_toggle);
WM_operatortype_append(GPENCIL_OT_sculptmode_toggle);
WM_operatortype_append(GPENCIL_OT_weightmode_toggle);