diff options
author | Joshua Leung <aligorith@gmail.com> | 2016-02-08 16:44:02 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2016-02-08 16:45:36 +0300 |
commit | 52668c56b74f75c45a6b5176704dfd168fd3e6ac (patch) | |
tree | c818559d81985570dafa5ea746d25740af37b669 /source/blender/blenkernel/intern/gpencil.c | |
parent | 4bc070a5193f927551a7c2aebb8c6306308bee4e (diff) |
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
Diffstat (limited to 'source/blender/blenkernel/intern/gpencil.c')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index afdac83f68a..485c4f5b29f 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -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; } |