Mask Editor: Add toggle for mask spline drawing

Adds an overlay option to show/hide the spline points & lines of masks in the Mask Editor.

It also moves the "smooth" option up (its position left of the selection dropdown was missleading).

{F11847272}

This emerged from a discussion in https://developer.blender.org/D12776

Differential Revision: https://developer.blender.org/D13314
This commit is contained in:
Simon Lenz 2022-06-16 10:13:03 +02:00 committed by Sergey Sharybin
parent 5946ea938a
commit df2ab4e758
Notes: blender-bot 2023-02-14 06:00:51 +01:00
Referenced by issue #101954, Regression: Geometry Node: Delete hair curves from end and set radius form sample nearest surface create incorrect shifting of radius on viewport render
Referenced by issue #101501, Drawing Masks in Image Editor gone?
20 changed files with 182 additions and 41 deletions

View File

@ -231,9 +231,13 @@ class MASK_PT_display:
layout = self.layout
space_data = context.space_data
layout.prop(space_data, "show_mask_smooth", text="Smooth")
row = layout.row(align=True)
row.prop(space_data, "show_mask_smooth", text="Smooth")
row.prop(space_data, "mask_display_type", text="")
row.prop(space_data, "show_mask_spline", text="Spline")
sub = row.row()
sub.active = space_data.show_mask_spline
sub.prop(space_data, "mask_display_type", text="")
row = layout.row(align=True)
row.prop(space_data, "show_mask_overlay", text="Overlay")
sub = row.row()

View File

@ -25,7 +25,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 2
#define BLENDER_FILE_SUBVERSION 3
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -30,6 +30,7 @@
#include "DNA_gpencil_modifier_types.h"
#include "DNA_lineart_types.h"
#include "DNA_listBase.h"
#include "DNA_mask_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
@ -3096,6 +3097,21 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 303, 3)) {
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_CLIP) {
((SpaceClip *)sl)->mask_info.draw_flag |= MASK_DRAWFLAG_SPLINE;
}
else if (sl->spacetype == SPACE_IMAGE) {
((SpaceImage *)sl)->mask_info.draw_flag |= MASK_DRAWFLAG_SPLINE;
}
}
}
}
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -23,6 +23,7 @@
#include "DNA_curveprofile_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_light_types.h"
#include "DNA_mask_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@ -185,6 +186,7 @@ static void blo_update_defaults_screen(bScreen *screen,
SpaceClip *sclip = area->spacedata.first;
sclip->around = V3D_AROUND_CENTER_MEDIAN;
sclip->mask_info.blend_factor = 0.7f;
sclip->mask_info.draw_flag = MASK_DRAWFLAG_SPLINE;
}
}

View File

@ -48,12 +48,27 @@ bool ED_space_clip_tracking_poll(struct bContext *C);
* It is not required to have mask opened for editing. */
bool ED_space_clip_maskedit_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space is Space Clip.
* - It is set to Mask mode.
* - Mask has visible and editable splines.
*
* It is not required to have mask opened for editing. */
bool ED_space_clip_maskedit_visible_splines_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space is Space Clip.
* - It is set to Mask mode.
* - The space has mask opened. */
bool ED_space_clip_maskedit_mask_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space is Space Clip.
* - It is set to Mask mode.
* - The space has mask opened.
* - Mask has visible and editable splines. */
bool ED_space_clip_maskedit_mask_visible_splines_poll(struct bContext *C);
void ED_space_clip_get_size(struct SpaceClip *sc, int *width, int *height);
void ED_space_clip_get_size_fl(struct SpaceClip *sc, float size[2]);
void ED_space_clip_get_zoom(struct SpaceClip *sc,

View File

@ -150,9 +150,26 @@ bool ED_space_image_maskedit_poll(struct bContext *C);
* - Current space is Image Editor.
* - The image editor is not a UV Editor.
* - It is set to Mask mode.
* - Mask has visible and editable splines.
*
* It is not required to have mask opened for editing. */
bool ED_space_image_maskedit_visible_splines_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space is Image Editor.
* - The image editor is not an UV Editor.
* - It is set to Mask mode.
* - The space has mask opened. */
bool ED_space_image_maskedit_mask_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space is Image Editor.
* - The image editor is not an UV Editor.
* - It is set to Mask mode.
* - The space has mask opened.
* - Mask has visible and editable splines. */
bool ED_space_image_maskedit_mask_visible_splines_poll(struct bContext *C);
bool ED_space_image_cursor_poll(struct bContext *C);
/**

View File

@ -29,12 +29,27 @@ struct wmKeyConfig;
* It is not required to have mask opened for editing. */
bool ED_maskedit_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space supports mask editing.
* - The space is configured to interact with mask.
* - Mask has visible and editable splines.
*
* It is not required to have mask opened for editing. */
bool ED_maskedit_visible_splines_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space supports mask editing.
* - The space is configured to interact with mask.
* - The space has mask open for editing. */
bool ED_maskedit_mask_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space supports mask editing.
* - The space is configured to interact with mask.
* - The space has mask opened.
* - Mask has visible and editable splines. */
bool ED_maskedit_mask_visible_splines_poll(struct bContext *C);
void ED_mask_deselect_all(const struct bContext *C);
void ED_operatortypes_mask(void);

View File

@ -583,7 +583,7 @@ void MASK_OT_add_vertex(wmOperatorType *ot)
/* api callbacks */
ot->exec = add_vertex_exec;
ot->invoke = add_vertex_invoke;
ot->poll = ED_maskedit_poll;
ot->poll = ED_maskedit_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -862,7 +862,7 @@ void MASK_OT_primitive_circle_add(wmOperatorType *ot)
/* api callbacks */
ot->exec = primitive_circle_add_exec;
ot->invoke = primitive_add_invoke;
ot->poll = ED_maskedit_poll;
ot->poll = ED_maskedit_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -897,7 +897,7 @@ void MASK_OT_primitive_square_add(wmOperatorType *ot)
/* api callbacks */
ot->exec = primitive_square_add_exec;
ot->invoke = primitive_add_invoke;
ot->poll = ED_maskedit_poll;
ot->poll = ED_maskedit_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@ -776,7 +776,9 @@ void ED_mask_draw_region(
}
/* draw! */
draw_mask_layers(C, mask_eval, draw_flag, draw_type, width, height);
if (draw_flag & MASK_DRAWFLAG_SPLINE) {
draw_mask_layers(C, mask_eval, draw_flag, draw_type, width, height);
}
if (do_draw_cb) {
ED_region_draw_cb_draw(C, region, REGION_DRAW_POST_VIEW);

View File

@ -42,6 +42,22 @@ bool ED_maskedit_poll(bContext *C)
return false;
}
bool ED_maskedit_visible_splines_poll(bContext *C)
{
ScrArea *area = CTX_wm_area(C);
if (area) {
switch (area->spacetype) {
case SPACE_CLIP:
return ED_space_clip_maskedit_visible_splines_poll(C);
case SPACE_SEQ:
return ED_space_sequencer_maskedit_poll(C);
case SPACE_IMAGE:
return ED_space_image_maskedit_visible_splines_poll(C);
}
}
return false;
}
bool ED_maskedit_mask_poll(bContext *C)
{
ScrArea *area = CTX_wm_area(C);
@ -58,6 +74,22 @@ bool ED_maskedit_mask_poll(bContext *C)
return false;
}
bool ED_maskedit_mask_visible_splines_poll(bContext *C)
{
const ScrArea *area = CTX_wm_area(C);
if (area) {
switch (area->spacetype) {
case SPACE_CLIP:
return ED_space_clip_maskedit_mask_visible_splines_poll(C);
case SPACE_SEQ:
return ED_space_sequencer_maskedit_mask_poll(C);
case SPACE_IMAGE:
return ED_space_image_maskedit_mask_visible_splines_poll(C);
}
}
return false;
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -907,7 +907,7 @@ void MASK_OT_slide_point(wmOperatorType *ot)
/* api callbacks */
ot->invoke = slide_point_invoke;
ot->modal = slide_point_modal;
ot->poll = ED_maskedit_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1297,7 +1297,7 @@ void MASK_OT_slide_spline_curvature(wmOperatorType *ot)
/* api callbacks */
ot->invoke = slide_spline_curvature_invoke;
ot->modal = slide_spline_curvature_modal;
ot->poll = ED_maskedit_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1336,7 +1336,7 @@ void MASK_OT_cyclic_toggle(wmOperatorType *ot)
/* api callbacks */
ot->exec = cyclic_toggle_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1493,7 +1493,7 @@ void MASK_OT_delete(wmOperatorType *ot)
/* api callbacks */
ot->invoke = WM_operator_confirm;
ot->exec = delete_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1551,7 +1551,7 @@ void MASK_OT_switch_direction(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_switch_direction_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1613,7 +1613,7 @@ void MASK_OT_normals_make_consistent(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_normals_make_consistent_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1693,7 +1693,7 @@ void MASK_OT_handle_type_set(wmOperatorType *ot)
/* api callbacks */
ot->invoke = WM_menu_invoke;
ot->exec = set_handle_type_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1849,7 +1849,7 @@ void MASK_OT_feather_weight_clear(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_feather_weight_clear_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -2043,7 +2043,7 @@ void MASK_OT_duplicate(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_duplicate_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -2084,7 +2084,7 @@ void MASK_OT_copy_splines(wmOperatorType *ot)
static bool paste_splines_poll(bContext *C)
{
if (ED_maskedit_mask_poll(C)) {
if (ED_maskedit_mask_visible_splines_poll(C)) {
return BKE_mask_clipboard_is_empty() == false;
}

View File

@ -62,7 +62,7 @@ void MASK_OT_parent_clear(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_parent_clear_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@ -222,7 +222,7 @@ void MASK_OT_select_all(wmOperatorType *ot)
/* api callbacks */
ot->exec = select_all_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -398,7 +398,7 @@ void MASK_OT_select(wmOperatorType *ot)
/* api callbacks */
ot->exec = select_exec;
ot->invoke = select_invoke;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
ot->get_name = ED_select_pick_get_name;
/* flags */
@ -504,7 +504,7 @@ void MASK_OT_select_box(wmOperatorType *ot)
ot->invoke = WM_gesture_box_invoke;
ot->exec = box_select_exec;
ot->modal = WM_gesture_box_modal;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_UNDO;
@ -627,7 +627,7 @@ void MASK_OT_select_lasso(wmOperatorType *ot)
ot->invoke = WM_gesture_lasso_invoke;
ot->modal = WM_gesture_lasso_modal;
ot->exec = clip_lasso_select_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
ot->cancel = WM_gesture_lasso_cancel;
/* flags */
@ -745,7 +745,7 @@ void MASK_OT_select_circle(wmOperatorType *ot)
ot->invoke = WM_gesture_circle_invoke;
ot->modal = WM_gesture_circle_modal;
ot->exec = circle_select_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
ot->get_name = ED_select_circle_get_name;
/* flags */
@ -809,7 +809,7 @@ void MASK_OT_select_linked_pick(wmOperatorType *ot)
/* api callbacks */
ot->invoke = mask_select_linked_pick_invoke;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -864,7 +864,7 @@ void MASK_OT_select_linked(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_select_linked_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -963,7 +963,7 @@ void MASK_OT_select_more(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_select_more_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -983,7 +983,7 @@ void MASK_OT_select_less(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_select_less_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@ -67,7 +67,7 @@ void MASK_OT_shape_key_insert(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_shape_key_insert_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -113,7 +113,7 @@ void MASK_OT_shape_key_clear(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_shape_key_clear_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -197,7 +197,7 @@ void MASK_OT_shape_key_feather_reset(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_shape_key_feather_reset_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -356,7 +356,7 @@ void MASK_OT_shape_key_rekey(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_shape_key_rekey_exec;
ot->poll = ED_maskedit_mask_poll;
ot->poll = ED_maskedit_mask_visible_splines_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@ -102,6 +102,16 @@ bool ED_space_clip_maskedit_poll(bContext *C)
return false;
}
bool ED_space_clip_maskedit_visible_splines_poll(bContext *C)
{
if (!ED_space_clip_maskedit_poll(C)) {
return false;
}
const SpaceClip *space_clip = CTX_wm_space_clip(C);
return space_clip->mask_info.draw_flag & MASK_DRAWFLAG_SPLINE;
}
bool ED_space_clip_maskedit_mask_poll(bContext *C)
{
if (ED_space_clip_maskedit_poll(C)) {
@ -117,6 +127,16 @@ bool ED_space_clip_maskedit_mask_poll(bContext *C)
return false;
}
bool ED_space_clip_maskedit_mask_visible_splines_poll(bContext *C)
{
if (!ED_space_clip_maskedit_mask_poll(C)) {
return false;
}
const SpaceClip *space_clip = CTX_wm_space_clip(C);
return space_clip->mask_info.draw_flag & MASK_DRAWFLAG_SPLINE;
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -483,6 +483,16 @@ bool ED_space_image_maskedit_poll(bContext *C)
return false;
}
bool ED_space_image_maskedit_visible_splines_poll(bContext *C)
{
if (!ED_space_image_maskedit_poll(C)) {
return false;
}
const SpaceImage *space_image = CTX_wm_space_image(C);
return space_image->mask_info.draw_flag & MASK_DRAWFLAG_SPLINE;
}
bool ED_space_image_paint_curve(const bContext *C)
{
SpaceImage *sima = CTX_wm_space_image(C);
@ -508,6 +518,16 @@ bool ED_space_image_maskedit_mask_poll(bContext *C)
return false;
}
bool ED_space_image_maskedit_mask_visible_splines_poll(bContext *C)
{
if (!ED_space_image_maskedit_mask_poll(C)) {
return false;
}
const SpaceImage *space_image = CTX_wm_space_image(C);
return space_image->mask_info.draw_flag & MASK_DRAWFLAG_SPLINE;
}
bool ED_space_image_cursor_poll(bContext *C)
{
return ED_operator_uvedit_space_image(C) || ED_space_image_maskedit_poll(C) ||

View File

@ -261,18 +261,10 @@ void createTransMaskingData(bContext *C, TransInfo *t)
tc->data_len = 0;
if (!mask) {
if (!ED_maskedit_mask_visible_splines_poll(C)) {
return;
}
if (t->spacetype == SPACE_CLIP) {
SpaceClip *sc = t->area->spacedata.first;
MovieClip *clip = ED_space_clip_get_clip(sc);
if (!clip) {
return;
}
}
/* count */
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
MaskSpline *spline;

View File

@ -198,6 +198,7 @@ enum {
/* SpaceClip->mask_draw_flag */
#define MASK_DRAWFLAG_SMOOTH (1 << 0)
#define MASK_DRAWFLAG_OVERLAY (1 << 1)
#define MASK_DRAWFLAG_SPLINE (1 << 2)
/* copy of eSpaceImage_UVDT */
/* SpaceClip->mask_draw_type */

View File

@ -15,7 +15,7 @@
#define _DNA_DEFAULT_MaskSpaceInfo \
{ \
.draw_flag = 0, \
.draw_flag = MASK_DRAWFLAG_SPLINE, \
.draw_type = MASK_DT_OUTLINE, \
.overlay_mode = MASK_OVERLAY_ALPHACHANNEL, \
.blend_factor = 0.7f, \

View File

@ -3483,6 +3483,11 @@ static void rna_def_space_mask_info(StructRNA *srna, int noteflag, const char *m
RNA_def_property_ui_text(prop, "Display Smooth Splines", "");
RNA_def_property_update(prop, noteflag, NULL);
prop = RNA_def_property(srna, "show_mask_spline", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mask_info.draw_flag", MASK_DRAWFLAG_SPLINE);
RNA_def_property_ui_text(prop, "Show Mask Spline", "");
RNA_def_property_update(prop, noteflag, NULL);
prop = RNA_def_property(srna, "show_mask_overlay", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mask_info.draw_flag", MASK_DRAWFLAG_OVERLAY);
RNA_def_property_ui_text(prop, "Show Mask Overlay", "");