GPencil: Layers with alpha = 0 should not be editable
[blender.git] / source / blender / blenkernel / intern / gpencil.c
index afdac83f68a78f5cb6c3ea20faaf177b45049d75..485c4f5b29f05a5743d5105b31b268abfe5b7900 100644 (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;
 }