Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2016-02-08 16:44:02 +0300
committerJoshua Leung <aligorith@gmail.com>2016-02-08 16:45:36 +0300
commit52668c56b74f75c45a6b5176704dfd168fd3e6ac (patch)
treec818559d81985570dafa5ea746d25740af37b669 /source/blender/blenkernel
parent4bc070a5193f927551a7c2aebb8c6306308bee4e (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')
-rw-r--r--source/blender/blenkernel/BKE_gpencil.h5
-rw-r--r--source/blender/blenkernel/intern/gpencil.c29
2 files changed, 32 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index dc436288eff..24e330d927f 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -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.
*/
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;
}