GPencil: Layers with alpha = 0 should not be editable

* Added a new API function to test if a GPencil layer is visible or not
* Replaced all editability checks with this new "super check"
* Replaced all magic number thresholds for opacity visiblity with a single define
This commit is contained in:
2016-02-09 02:44:02 +13:00
parent 4bc070a519
commit 52668c56b7
9 changed files with 43 additions and 19 deletions

View File

@@ -58,6 +58,11 @@ struct bGPdata *gpencil_data_duplicate(struct bGPdata *gpd, bool internal_copy);
void gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe *gpf);
/* Stroke and Fill - Alpha Visibility Threshold */
#define GPENCIL_ALPHA_OPACITY_THRESH 0.001f
bool gpencil_layer_is_editable(const struct bGPDlayer *gpl);
/* How gpencil_layer_getframe() should behave when there
* is no existing GP-Frame on the frame requested.
*/

View File

@@ -435,16 +435,41 @@ void gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf)
/* -------- GP-Layer API ---------- */
/* Check if the given layer is able to be edited or not */
bool gpencil_layer_is_editable(const bGPDlayer *gpl)
{
/* Sanity check */
if (gpl == NULL)
return false;
/* Layer must be: Visible + Editable */
if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0) {
/* Opacity must be sufficiently high that it is still "visible"
* Otherwise, it's not really "visible" to the user, so no point editing...
*/
if ((gpl->color[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gpl->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH)) {
return true;
}
}
/* Something failed */
return false;
}
/* Look up the gp-frame on the requested frame number, but don't add a new one */
bGPDframe *BKE_gpencil_layer_find_frame(bGPDlayer *gpl, int cframe)
{
bGPDframe *gpf;
/* Search in reverse order, since this is often used for playback/adding,
* where it's less likely that we're interested in the earlier frames
*/
for (gpf = gpl->frames.last; gpf; gpf = gpf->prev) {
if (gpf->framenum == cframe) {
return gpf;
}
}
return NULL;
}

View File

@@ -993,7 +993,7 @@ static void gp_draw_data_layers(bGPdata *gpd, int offsx, int offsy, int winx, in
/* fill strokes... */
// XXX: this is not a very good limit
GP_DRAWFLAG_APPLY((gpl->fill[3] > 0.001f), GP_DRAWDATA_FILL);
GP_DRAWFLAG_APPLY((gpl->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH), GP_DRAWDATA_FILL);
#undef GP_DRAWFLAG_APPLY
/* draw 'onionskins' (frame left + right) */

View File

@@ -1118,9 +1118,7 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso)
/* go through each layer, and ensure that we've got a valid frame to use */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* only editable and visible layers are considered */
if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 &&
(gpl->actframe != NULL))
{
if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
bGPDframe *gpf = gpl->actframe;
/* Make a new frame to work on if the layer's frame and the current scene frame don't match up

View File

@@ -391,7 +391,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
/* no active layer - let's just create one */
gpl = gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
}
else if (gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) {
else if (gpencil_layer_is_editable(gpl) == false) {
BKE_report(op->reports, RPT_ERROR, "Can not paste strokes when active layer is hidden or locked");
return OPERATOR_CANCELLED;
}

View File

@@ -931,7 +931,7 @@ static void gp_stroke_doeraser(tGPsdata *p)
bGPDframe *gpf = gpl->actframe;
/* only affect layer if it's editable (and visible) */
if (gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) {
if (gpencil_layer_is_editable(gpl) == false) {
continue;
}
else if (gpf == NULL) {
@@ -1220,7 +1220,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode)
bGPDlayer *gpl;
for (gpl = p->gpd->layers.first; gpl; gpl = gpl->next) {
/* Skip if layer not editable */
if (gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED))
if (gpencil_layer_is_editable(gpl) == false)
continue;
/* Add a new frame if needed (and based off the active frame,

View File

@@ -511,7 +511,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
bGPDlayer *gpl;
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0) {
if (gpencil_layer_is_editable(gpl)) {
CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
}
}
@@ -527,7 +527,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
bGPDlayer *gpl;
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 && (gpl->actframe)) {
if (gpencil_layer_is_editable(gpl) && (gpl->actframe)) {
bGPDframe *gpf = gpl->actframe;
bGPDstroke *gps;

View File

@@ -7645,9 +7645,7 @@ static void createTransGPencil(bContext *C, TransInfo *t)
*/
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* only editable and visible layers are considered */
if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 &&
(gpl->actframe != NULL))
{
if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
bGPDframe *gpf = gpl->actframe;
bGPDstroke *gps;
@@ -7701,9 +7699,7 @@ static void createTransGPencil(bContext *C, TransInfo *t)
/* Second Pass: Build transdata array */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* only editable and visible layers are considered */
if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 &&
(gpl->actframe != NULL))
{
if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
bGPDframe *gpf = gpl->actframe;
bGPDstroke *gps;

View File

@@ -145,7 +145,7 @@ static int rna_GPencilLayer_is_stroke_visible_get(PointerRNA *ptr)
* about this limit for showing/not showing
*/
bGPDlayer *gpl = (bGPDlayer *)ptr->data;
return (gpl->color[3] > 0.001f);
return (gpl->color[3] > GPENCIL_ALPHA_OPACITY_THRESH);
}
static int rna_GPencilLayer_is_fill_visible_get(PointerRNA *ptr)
@@ -154,7 +154,7 @@ static int rna_GPencilLayer_is_fill_visible_get(PointerRNA *ptr)
* about this limit for showing/not showing
*/
bGPDlayer *gpl = (bGPDlayer *)ptr->data;
return (gpl->fill[3] > 0.001f);
return (gpl->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH);
}
static PointerRNA rna_GPencil_active_layer_get(PointerRNA *ptr)