Option not to select with un-hide
[blender.git] / source / blender / editors / gpencil / gpencil_data.c
index e915446e46184b3d2b4c5ebe9a07aea5a560cfc2..5bd5c9c74b96b98727c5ef1f53a0482f1798a6c0 100644 (file)
@@ -42,6 +42,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 #include "BLI_math.h"
+#include "BLI_string_utils.h"
 
 #include "BLT_translation.h"
 
@@ -75,9 +76,6 @@
 
 #include "gpencil_intern.h"
 
-/* maximum sizes of gp-session buffer */
-#define GP_STROKE_BUFFER_MAX    5000
-
 /* ************************************************ */
 /* Datablock Operators */
 
@@ -87,7 +85,8 @@
 static int gp_data_add_exec(bContext *C, wmOperator *op)
 {
        bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-       
+       ToolSettings *ts = CTX_data_tool_settings(C);
+
        if (gpd_ptr == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
                return OPERATOR_CANCELLED;
@@ -97,7 +96,16 @@ static int gp_data_add_exec(bContext *C, wmOperator *op)
                bGPdata *gpd = (*gpd_ptr);
                
                id_us_min(&gpd->id);
-               *gpd_ptr = gpencil_data_addnew(DATA_("GPencil"));
+               *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
+
+               /* if not exist brushes, create a new set */
+               if (ts) {
+                       if (BLI_listbase_is_empty(&ts->gp_brushes)) {
+                               /* create new brushes */
+                               BKE_gpencil_brush_init_presets(ts);
+                       }
+               }
+
        }
        
        /* notifiers */
@@ -111,7 +119,7 @@ void GPENCIL_OT_data_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Grease Pencil Add New";
        ot->idname = "GPENCIL_OT_data_add";
-       ot->description = "Add new Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil data-block";
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* callbacks */
@@ -159,7 +167,7 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Grease Pencil Unlink";
        ot->idname = "GPENCIL_OT_data_unlink";
-       ot->description = "Unlink active Grease Pencil datablock";
+       ot->description = "Unlink active Grease Pencil data-block";
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* callbacks */
@@ -177,17 +185,26 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
 static int gp_layer_add_exec(bContext *C, wmOperator *op)
 {
        bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-       
+       ToolSettings *ts = CTX_data_tool_settings(C);
+
        /* if there's no existing Grease-Pencil data there, add some */
        if (gpd_ptr == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
                return OPERATOR_CANCELLED;
        }
        if (*gpd_ptr == NULL)
-               *gpd_ptr = gpencil_data_addnew(DATA_("GPencil"));
+               *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
        
+       /* if not exist brushes, create a new set */
+       if (ts) {
+               if (BLI_listbase_is_empty(&ts->gp_brushes)) {
+                       /* create new brushes */
+                       BKE_gpencil_brush_init_presets(ts);
+               }
+       }
+
        /* add new layer now */
-       gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
+       BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
        
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -200,7 +217,7 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add New Layer";
        ot->idname = "GPENCIL_OT_layer_add";
-       ot->description = "Add new Grease Pencil layer for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil layer for the active Grease Pencil data-block";
        
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
@@ -214,7 +231,7 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot)
 static int gp_layer_remove_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+       bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
        
        /* sanity checks */
        if (ELEM(NULL, gpd, gpl))
@@ -230,12 +247,12 @@ static int gp_layer_remove_exec(bContext *C, wmOperator *op)
         * - if this is the only layer, this naturally becomes NULL
         */
        if (gpl->prev)
-               gpencil_layer_setactive(gpd, gpl->prev);
+               BKE_gpencil_layer_setactive(gpd, gpl->prev);
        else
-               gpencil_layer_setactive(gpd, gpl->next);
+               BKE_gpencil_layer_setactive(gpd, gpl->next);
        
        /* delete the layer now... */
-       gpencil_layer_delete(gpd, gpl);
+       BKE_gpencil_layer_delete(gpd, gpl);
        
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -267,7 +284,7 @@ enum {
 static int gp_layer_move_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+       bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
        
        int direction = RNA_enum_get(op->ptr, "type");
        
@@ -275,27 +292,17 @@ static int gp_layer_move_exec(bContext *C, wmOperator *op)
        if (ELEM(NULL, gpd, gpl))
                return OPERATOR_CANCELLED;
        
-       /* up or down? */
-       if (direction == GP_LAYER_MOVE_UP) {
-               /* up */
-               BLI_remlink(&gpd->layers, gpl);
-               BLI_insertlinkbefore(&gpd->layers, gpl->prev, gpl);
-       }
-       else {
-               /* down */
-               BLI_remlink(&gpd->layers, gpl);
-               BLI_insertlinkafter(&gpd->layers, gpl->next, gpl);
+       BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */
+       if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) {
+               WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
        }
        
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-       
        return OPERATOR_FINISHED;
 }
 
 void GPENCIL_OT_layer_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""},
                {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL}
@@ -321,7 +328,7 @@ void GPENCIL_OT_layer_move(wmOperatorType *ot)
 static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+       bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
        bGPDlayer *new_layer;
        
        /* sanity checks */
@@ -329,12 +336,12 @@ static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op))
                return OPERATOR_CANCELLED;
        
        /* make copy of layer, and add it immediately after the existing layer */
-       new_layer = gpencil_layer_duplicate(gpl);
+       new_layer = BKE_gpencil_layer_duplicate(gpl);
        BLI_insertlinkafter(&gpd->layers, gpl, new_layer);
        
        /* ensure new layer has a unique name, and is now the active layer */
        BLI_uniquename(&gpd->layers, new_layer, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(new_layer->info));
-       gpencil_layer_setactive(gpd, new_layer);
+       BKE_gpencil_layer_setactive(gpd, new_layer);
        
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -362,7 +369,7 @@ void GPENCIL_OT_layer_duplicate(wmOperatorType *ot)
 static int gp_hide_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *layer = gpencil_layer_getactive(gpd);
+       bGPDlayer *layer = BKE_gpencil_layer_getactive(gpd);
        bool unselected = RNA_boolean_get(op->ptr, "unselected");
        
        /* sanity checks */
@@ -416,18 +423,59 @@ static int gp_reveal_poll(bContext *C)
        return ED_gpencil_data_get_active(C) != NULL;
 }
 
-static int gp_reveal_exec(bContext *C, wmOperator *UNUSED(op))
+static void gp_reveal_select_frame(bContext *C, bGPDframe *frame, bool select)
+{
+       bGPDstroke *gps;
+       for (gps = frame->strokes.first; gps; gps = gps->next) {
+
+               /* only deselect strokes that are valid in this view */
+               if (ED_gpencil_stroke_can_use(C, gps)) {
+
+                       /* (de)select points */
+                       int i;
+                       bGPDspoint *pt;
+                       for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+                               SET_FLAG_FROM_TEST(pt->flag, select, GP_SPOINT_SELECT);
+                       }
+
+                       /* (de)select stroke */
+                       SET_FLAG_FROM_TEST(gps->flag, select, GP_STROKE_SELECT);
+               }
+       }
+}
+
+static int gp_reveal_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
        bGPDlayer *gpl;
-       
+       const bool select = RNA_boolean_get(op->ptr, "select");
+
        /* sanity checks */
        if (gpd == NULL)
                return OPERATOR_CANCELLED;
        
-       /* make all layers visible */
        for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-               gpl->flag &= ~GP_LAYER_HIDE;
+
+               if (gpl->flag & GP_LAYER_HIDE) {
+                       gpl->flag &= ~GP_LAYER_HIDE;
+
+                       /* select or deselect if requested, only on hidden layers */
+                       if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
+                               if (select) {
+                                       /* select all strokes on active frame only (same as select all operator) */
+                                       if (gpl->actframe) {
+                                               gp_reveal_select_frame(C, gpl->actframe, true);
+                                       }
+                               }
+                               else {
+                                       /* deselect strokes on all frames (same as deselect all operator) */
+                                       bGPDframe *gpf;
+                                       for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+                                               gp_reveal_select_frame(C, gpf, false);
+                                       }
+                               }
+                       }
+               }
        }
        
        /* notifiers */
@@ -449,6 +497,9 @@ void GPENCIL_OT_reveal(wmOperatorType *ot)
        
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_boolean(ot->srna, "select", true, "Select", "");
 }
 
 /* ***************** Lock/Unlock All Layers ************************ */
@@ -530,7 +581,7 @@ void GPENCIL_OT_unlock_all(wmOperatorType *ot)
 static int gp_isolate_layer_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *layer = gpencil_layer_getactive(gpd);
+       bGPDlayer *layer = BKE_gpencil_layer_getactive(gpd);
        bGPDlayer *gpl;
        int flags = GP_LAYER_LOCKED;
        bool isolate = false;
@@ -606,7 +657,7 @@ void GPENCIL_OT_layer_isolate(wmOperatorType *ot)
 static int gp_merge_layer_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *gpl_current = gpencil_layer_getactive(gpd);
+       bGPDlayer *gpl_current = BKE_gpencil_layer_getactive(gpd);
        bGPDlayer *gpl_next = gpl_current->next;
 
        if (ELEM(NULL, gpd, gpl_current, gpl_next)) {
@@ -626,13 +677,13 @@ static int gp_merge_layer_exec(bContext *C, wmOperator *op)
                bGPDframe *frame = BLI_ghash_lookup(gh_frames_cur, SET_INT_IN_POINTER(gpf->framenum));
                if (!frame) {
                        /* nothing found, create new */
-                       frame = gpencil_frame_addnew(gpl_current, gpf->framenum);
+                       frame = BKE_gpencil_frame_addnew(gpl_current, gpf->framenum);
                }
                /* add to tail all strokes */
                BLI_movelisttolist(&frame->strokes, &gpf->strokes);
        }
        /* Now delete next layer */
-       gpencil_layer_delete(gpd, gpl_next);
+       BKE_gpencil_layer_delete(gpd, gpl_next);
        BLI_ghash_free(gh_frames_cur, NULL, NULL);
 
        /* notifiers */
@@ -681,7 +732,7 @@ static int gp_layer_change_exec(bContext *C, wmOperator *op)
        /* Get layer or create new one */
        if (layer_num == -1) {
                /* Create layer */
-               gpl = gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
+               gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
        }
        else {
                /* Try to get layer */
@@ -694,7 +745,7 @@ static int gp_layer_change_exec(bContext *C, wmOperator *op)
        }
        
        /* Set active layer */
-       gpencil_layer_setactive(gpd, gpl);
+       BKE_gpencil_layer_setactive(gpd, gpl);
        
        /* updates */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -736,7 +787,7 @@ enum {
 static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+       bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
        bGPDstroke *gps;
 
        /* sanity checks */
@@ -747,7 +798,7 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
        bGPDframe *gpf = gpl->actframe;
        /* temp listbase to store selected strokes */
        ListBase selected = {NULL};
-       const int direction = RNA_enum_get(op->ptr, "type");
+       const int direction = RNA_enum_get(op->ptr, "direction");
 
        /* verify if any selected stroke is in the extreme of the stack and select to move */
        for (gps = gpf->strokes.first; gps; gps = gps->next) {
@@ -764,14 +815,12 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
                        /* some stroke is already at front*/
                        if ((direction == GP_STROKE_MOVE_TOP) || (direction == GP_STROKE_MOVE_UP)) {
                                if (gps == gpf->strokes.last) {
-                                       BKE_report(op->reports, RPT_ERROR, "Some selected stroke is already on top");
                                        return OPERATOR_CANCELLED;
                                }
                        }
                        /* some stroke is already at botom */
                        if ((direction == GP_STROKE_MOVE_BOTTOM) || (direction == GP_STROKE_MOVE_DOWN)) {
                                if (gps == gpf->strokes.first) {
-                                       BKE_report(op->reports, RPT_ERROR, "Some selected stroke is already on bottom");
                                        return OPERATOR_CANCELLED;
                                }
                        }
@@ -787,23 +836,21 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
                        for (LinkData *link = selected.first; link; link = link->next) {
                                gps = link->data;
                                BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkafter(&gpf->strokes, gpf->strokes.last, gps);
+                               BLI_addtail(&gpf->strokes, gps);
                        }
                        break;
                /* Bring Forward */
                case GP_STROKE_MOVE_UP:
                        for (LinkData *link = selected.last; link; link = link->prev) {
                                gps = link->data;
-                               BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkafter(&gpf->strokes, gps->next, gps);
+                               BLI_listbase_link_move(&gpf->strokes, gps, 1);
                        }
                        break;
-                       /* Send Backward */
+               /* Send Backward */
                case GP_STROKE_MOVE_DOWN:
                        for (LinkData *link = selected.first; link; link = link->next) {
                                gps = link->data;
-                               BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkbefore(&gpf->strokes, gps->prev, gps);
+                               BLI_listbase_link_move(&gpf->strokes, gps, -1);
                        }
                        break;
                /* Send to Back */
@@ -811,13 +858,15 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
                        for (LinkData *link = selected.last; link; link = link->prev) {
                                gps = link->data;
                                BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkbefore(&gpf->strokes, gpf->strokes.first, gps);
+                               BLI_addhead(&gpf->strokes, gps);
                        }
                        break;
                default:
                        BLI_assert(0);
                        break;
        }
+       BLI_freelistN(&selected);
+
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 
@@ -826,7 +875,7 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_stroke_arrange(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_STROKE_MOVE_UP, "UP", 0, "Bring Forward", ""},
                {GP_STROKE_MOVE_DOWN, "DOWN", 0, "Send Backward", ""},
                {GP_STROKE_MOVE_TOP, "TOP", 0, "Bring to Front", ""},
@@ -861,8 +910,8 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *UNUSED(op))
                return OPERATOR_CANCELLED;
        }
 
-       palette = gpencil_palette_getactive(gpd);
-       color = gpencil_palettecolor_getactive(palette);
+       palette = BKE_gpencil_palette_getactive(gpd);
+       color = BKE_gpencil_palettecolor_getactive(palette);
        if (ELEM(NULL, palette, color)) {
                return OPERATOR_CANCELLED;
        }
@@ -882,9 +931,9 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *UNUSED(op))
                                                continue;
 
                                        /* asign new color (only if different) */
-                                       if (STREQ(gps->colorname, color->info) == false) {
-                                               strcpy(gps->colorname, color->info);
-                                               gps->flag |= GP_STROKE_RECALC_COLOR;
+                                       if ((STREQ(gps->colorname, color->info) == false) || (gps->palcolor != color)) {
+                                               BLI_strncpy(gps->colorname, color->info, sizeof(gps->colorname));
+                                               gps->palcolor = color;
                                        }
                                }
                        }
@@ -919,7 +968,7 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op))
        if (ELEM(NULL, gpd))
                return OPERATOR_CANCELLED;
 
-       palette = gpencil_palette_getactive(gpd);
+       palette = BKE_gpencil_palette_getactive(gpd);
        if (ELEM(NULL, palette))
                return OPERATOR_CANCELLED;
 
@@ -965,430 +1014,6 @@ void GPENCIL_OT_stroke_lock_color(wmOperatorType *ot)
        ot->poll = gp_active_layer_poll;
 }
 
-/* ******************* Apply layer thickness change to Strokes ************************** */
-
-static int gp_stroke_apply_thickness_exec(bContext *C, wmOperator *UNUSED(op))
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *gpl = gpencil_layer_getactive(gpd);
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd, gpl, gpl->frames.first))
-               return OPERATOR_CANCELLED;
-
-       /* loop all strokes */
-       for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-               for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-                       /* Apply thickness */
-                       gps->thickness = gps->thickness + gpl->thickness;
-               }
-       }
-       /* clear value */
-       gpl->thickness = 0.0f;
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_apply_thickness(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Apply Stroke Thickness";
-       ot->idname = "GPENCIL_OT_stroke_apply_thickness";
-       ot->description = "Apply the thickness change of the layer to its strokes";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_apply_thickness_exec;
-       ot->poll = gp_active_layer_poll;
-}
-
-/* ******************* Close Strokes ************************** */
-
-enum {
-       GP_STROKE_CYCLIC_CLOSE = 1,
-       GP_STROKE_CYCLIC_OPEN = 2,
-       GP_STROKE_CYCLIC_TOGGLE = 3
-};
-
-static int gp_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-       const int type = RNA_enum_get(op->ptr, "type");
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd))
-               return OPERATOR_CANCELLED;
-
-       /* loop all selected strokes */
-       CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
-       {
-               for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) {
-                       bGPDpalettecolor *palcolor = gps->palcolor;
-
-                       /* skip strokes that are not selected or invalid for current view */
-                       if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false)
-                               continue;
-                       /* skip hidden or locked colors */
-                       if (!palcolor || (palcolor->flag & PC_COLOR_HIDE) || (palcolor->flag & PC_COLOR_LOCKED))
-                               continue;
-
-                       switch (type) {
-                               case GP_STROKE_CYCLIC_CLOSE:
-                                       /* Close all (enable) */
-                                       gps->flag |= GP_STROKE_CYCLIC;
-                                       break;
-                               case GP_STROKE_CYCLIC_OPEN:
-                                       /* Open all (disable) */
-                                       gps->flag &= ~GP_STROKE_CYCLIC;
-                                       break;
-                               case GP_STROKE_CYCLIC_TOGGLE:
-                                       /* Just toggle flag... */
-                                       gps->flag ^= GP_STROKE_CYCLIC;
-                                       break;
-                               default:
-                                       BLI_assert(0);
-                                       break;
-                       }
-               }
-       }
-       CTX_DATA_END;
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-/**
- * Similar to #CURVE_OT_cyclic_toggle or #MASK_OT_cyclic_toggle, but with
- * option to force opened/closed strokes instead of just toggle behavior.
- */
-void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
-{
-       static EnumPropertyItem cyclic_type[] = {
-               {GP_STROKE_CYCLIC_CLOSE, "CLOSE", 0, "Close all", ""},
-               {GP_STROKE_CYCLIC_OPEN, "OPEN", 0, "Open all", ""},
-               {GP_STROKE_CYCLIC_TOGGLE, "TOGGLE", 0, "Toggle", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       /* identifiers */
-       ot->name = "Set Cyclical State";
-       ot->idname = "GPENCIL_OT_stroke_cyclical_set";
-       ot->description = "Close or open the selected stroke adding an edge from last to first point";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_cyclical_set_exec;
-       ot->poll = gp_active_layer_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-       ot->prop = RNA_def_enum(ot->srna, "type", cyclic_type, GP_STROKE_CYCLIC_TOGGLE, "Type", "");
-}
-
-/* ******************* Stroke join ************************** */
-
-/* Helper: flip stroke */
-static void gpencil_flip_stroke(bGPDstroke *gps)
-{
-       bGPDspoint pt, *point, *point2;
-       int end = gps->totpoints - 1;
-
-       for (int i = 0; i < gps->totpoints / 2; i++) {
-               /* save first point */
-               point = &gps->points[i];
-               pt.x = point->x;
-               pt.y = point->y;
-               pt.z = point->z;
-               pt.flag = point->flag;
-               pt.pressure = point->pressure;
-               pt.strength = point->strength;
-               pt.time = point->time;
-
-               /* replace first point with last point */
-               point2 = &gps->points[end];
-               point->x = point2->x;
-               point->y = point2->y;
-               point->z = point2->z;
-               point->flag = point2->flag;
-               point->pressure = point2->pressure;
-               point->strength = point2->strength;
-               point->time = point2->time;
-
-               /* replace last point with first saved before */
-               point = &gps->points[end];
-               point->x = pt.x;
-               point->y = pt.y;
-               point->z = pt.z;
-               point->flag = pt.flag;
-               point->pressure = pt.pressure;
-               point->strength = pt.strength;
-               point->time = pt.time;
-
-               end--;
-       }
-}
-
-/* Helper: copy point between strokes */
-static void gpencil_stroke_copy_point(bGPDstroke *gps, bGPDspoint *point, float delta[3],
-                                      float pressure, float strength, float deltatime)
-{
-       bGPDspoint *newpoint;
-
-       gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1));
-       gps->totpoints++;
-
-       newpoint = &gps->points[gps->totpoints - 1];
-       newpoint->x = point->x * delta[0];
-       newpoint->y = point->y * delta[1];
-       newpoint->z = point->z * delta[2];
-       newpoint->flag = point->flag;
-       newpoint->pressure = pressure;
-       newpoint->strength = strength;
-       newpoint->time = point->time + deltatime;
-}
-
-/* Helper: join two strokes using the shortest distance (reorder stroke if necessary ) */
-static void gpencil_stroke_join_strokes(bGPDstroke *gps_a, bGPDstroke *gps_b)
-{
-       bGPDspoint point, *pt;
-       int i;
-       float delta[3] = {1.0f, 1.0f, 1.0f};
-       float deltatime = 0.0f;
-
-       /* sanity checks */
-       if (ELEM(NULL, gps_a, gps_b))
-               return;
-
-       if ((gps_a->totpoints == 0) || (gps_b->totpoints == 0))
-               return;
-
-       /* define start and end points of each stroke */
-       float sa[3], sb[3], ea[3], eb[3];
-       pt = &gps_a->points[0];
-       copy_v3_v3(sa, &pt->x);
-
-       pt = &gps_a->points[gps_a->totpoints - 1];
-       copy_v3_v3(ea, &pt->x);
-
-       pt = &gps_b->points[0];
-       copy_v3_v3(sb, &pt->x);
-       
-       pt = &gps_b->points[gps_b->totpoints - 1];
-       copy_v3_v3(eb, &pt->x);
-       /* review if need flip stroke B */
-       float ea_sb = len_squared_v3v3(ea, sb);
-       float ea_eb = len_squared_v3v3(ea, eb);
-       /* flip if distance to end point is shorter */
-       if (ea_eb < ea_sb) {
-               gpencil_flip_stroke(gps_b);
-       }
-
-       /* 1st: add one tail point to start invisible area */
-       point = gps_a->points[gps_a->totpoints - 1];
-       deltatime = point.time;
-       gpencil_stroke_copy_point(gps_a, &point, delta, 0.0f, 0.0f, 0.0f);
-
-       /* 2nd: add one head point to finish invisible area */
-       point = gps_b->points[0];
-       gpencil_stroke_copy_point(gps_a, &point, delta, 0.0f, 0.0f, deltatime);
-
-       /* 3rd: add all points */
-       for (i = 0, pt = gps_b->points; i < gps_b->totpoints && pt; i++, pt++) {
-               /* check if still room in buffer */
-               if (gps_a->totpoints <= GP_STROKE_BUFFER_MAX - 2) {
-                       gpencil_stroke_copy_point(gps_a, pt, delta, pt->pressure, pt->strength, deltatime);
-               }
-       }
-}
-
-enum {
-       GP_STROKE_JOIN = -1,
-       GP_STROKE_JOINCOPY = 1
-};
-
-static int gp_stroke_join_exec(bContext *C, wmOperator *op)
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *activegpl = gpencil_layer_getactive(gpd);
-       bGPDstroke *gps, *gpsn;
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *palcolor = gpencil_palettecolor_getactive(palette);
-
-       bGPDframe *gpf_a = NULL;
-       bGPDstroke *stroke_a = NULL;
-       bGPDstroke *stroke_b = NULL;
-       bGPDstroke *new_stroke = NULL;
-
-       int type = RNA_enum_get(op->ptr, "type");
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd))
-               return OPERATOR_CANCELLED;
-
-       if (activegpl->flag & GP_LAYER_LOCKED)
-               return OPERATOR_CANCELLED;
-
-       BLI_assert(ELEM(type, GP_STROKE_JOIN, GP_STROKE_JOINCOPY));
-
-
-       /* read all selected strokes */
-       bool first = false;
-       CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
-       {
-               bGPDframe *gpf = gpl->actframe;
-               for (gps = gpf->strokes.first; gps; gps = gpsn) {
-                       gpsn = gps->next;
-                       if (gps->flag & GP_STROKE_SELECT) {
-                               /* skip strokes that are invalid for current view */
-                               if (ED_gpencil_stroke_can_use(C, gps) == false) {
-                                       continue;
-                               }
-                               /* check if the color is editable */
-                               if (ED_gpencil_stroke_color_use(gpl, gps) == false) {
-                                       continue;
-                               }
-                               /* to join strokes, cyclic must be disabled */
-                               gps->flag &= ~GP_STROKE_CYCLIC;
-                               /* saves first frame and stroke */
-                               if (!first) {
-                                       first = true;
-                                       gpf_a = gpf;
-                                       stroke_a = gps;
-                               }
-                               else {
-                                       stroke_b = gps;
-                                       /* create a new stroke if was not created before (only created if something to join) */
-                                       if (new_stroke == NULL) {
-                                               new_stroke = MEM_dupallocN(stroke_a);
-                                               new_stroke->points = MEM_dupallocN(stroke_a->points);
-                                               new_stroke->triangles = NULL;
-                                               new_stroke->tot_triangles = 0;
-                                               new_stroke->flag |= GP_STROKE_RECALC_CACHES;
-                                               /* if new, set current color */
-                                               if (type == GP_STROKE_JOINCOPY) {
-                                                       new_stroke->palcolor = palcolor;
-                                                       strcpy(new_stroke->colorname, palcolor->info);
-                                                       new_stroke->flag |= GP_STROKE_RECALC_COLOR;
-                                               }
-                                       }
-                                       /* join new_stroke and stroke B. New stroke will contain all the previous data */
-                                       gpencil_stroke_join_strokes(new_stroke, stroke_b);
-
-                                       /* if join only, delete old strokes */
-                                       if (type == GP_STROKE_JOIN) {
-                                               if (stroke_a) {
-                                                       BLI_insertlinkbefore(&gpf_a->strokes, stroke_a, new_stroke);
-                                                       BLI_remlink(&gpf->strokes, stroke_a);
-                                                       free_gpencil_stroke(stroke_a);
-                                                       stroke_a = NULL;
-                                               }
-                                               if (stroke_b) {
-                                                       BLI_remlink(&gpf->strokes, stroke_b);
-                                                       free_gpencil_stroke(stroke_b);
-                                                       stroke_b = NULL;
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-       CTX_DATA_END;
-       /* add new stroke if was not added before */
-       if (type == GP_STROKE_JOINCOPY) {
-               if (new_stroke) {
-                       /* Add a new frame if needed */
-                       if (activegpl->actframe == NULL)
-                               activegpl->actframe = gpencil_frame_addnew(activegpl, gpf_a->framenum);
-
-                       BLI_addtail(&activegpl->actframe->strokes, new_stroke);
-               }
-       }
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_join(wmOperatorType *ot)
-{
-       static EnumPropertyItem join_type[] = {
-               {GP_STROKE_JOIN, "JOIN", 0, "Join", ""},
-               {GP_STROKE_JOINCOPY, "JOINCOPY", 0, "Join and Copy", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       /* identifiers */
-       ot->name = "Join Strokes";
-       ot->idname = "GPENCIL_OT_stroke_join";
-       ot->description = "Join selected strokes (optionally as new stroke)";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_join_exec;
-       ot->poll = gp_active_layer_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-       ot->prop = RNA_def_enum(ot->srna, "type", join_type, GP_STROKE_JOIN, "Type", "");
-}
-
-/* ******************* Stroke flip ************************** */
-
-static int gp_stroke_flip_exec(bContext *C, wmOperator *UNUSED(op))
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd))
-               return OPERATOR_CANCELLED;
-
-       /* read all selected strokes */
-       CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
-       {
-               bGPDframe *gpf = gpl->actframe;
-               for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-                       if (gps->flag & GP_STROKE_SELECT) {
-                               /* skip strokes that are invalid for current view */
-                               if (ED_gpencil_stroke_can_use(C, gps) == false) {
-                                       continue;
-                               }
-                               /* check if the color is editable */
-                               if (ED_gpencil_stroke_color_use(gpl, gps) == false) {
-                                       continue;
-                               }
-                               /* flip stroke */
-                               gpencil_flip_stroke(gps);
-                       }
-               }
-       }
-       CTX_DATA_END;
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_flip(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Flip Stroke";
-       ot->idname = "GPENCIL_OT_stroke_flip";
-       ot->description = "Change drawing direction of selected strokes";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_flip_exec;
-       ot->poll = gp_active_layer_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
 /* ************************************************ */
 /* Drawing Brushes Operators */
 
@@ -1405,7 +1030,7 @@ static int gp_brush_add_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
        /* add new brush now */
-       gpencil_brush_addnew(ts, DATA_("GP_Brush"), true);
+       BKE_gpencil_brush_addnew(ts, DATA_("GP_Brush"), true);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1418,7 +1043,7 @@ void GPENCIL_OT_brush_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add Brush";
        ot->idname = "GPENCIL_OT_brush_add";
-       ot->description = "Add new Grease Pencil drawing brush for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil drawing brush for the active Grease Pencil data-block";
 
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -1432,14 +1057,14 @@ void GPENCIL_OT_brush_add(wmOperatorType *ot)
 static int gp_brush_remove_exec(bContext *C, wmOperator *op)
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
-       bGPDbrush *brush = gpencil_brush_getactive(ts);
+       bGPDbrush *brush = BKE_gpencil_brush_getactive(ts);
 
        /* sanity checks */
        if (ELEM(NULL, ts, brush))
                return OPERATOR_CANCELLED;
 
-       if (BLI_listbase_count(&ts->gp_brushes) < 2) {
-               BKE_report(op->reports, RPT_ERROR, "Grease Pencil needs a brush. Unable to delete brush");
+       if (BLI_listbase_count_ex(&ts->gp_brushes, 2) < 2) {
+               BKE_report(op->reports, RPT_ERROR, "Grease Pencil needs a brush, unable to delete the last one");
                return OPERATOR_CANCELLED;
        }
 
@@ -1449,12 +1074,12 @@ static int gp_brush_remove_exec(bContext *C, wmOperator *op)
         * - if this is the only brush, this naturally becomes NULL
         */
        if (brush->prev)
-               gpencil_brush_setactive(ts, brush->prev);
+               BKE_gpencil_brush_setactive(ts, brush->prev);
        else
-               gpencil_brush_setactive(ts, brush->next);
+               BKE_gpencil_brush_setactive(ts, brush->next);
 
        /* delete the brush now... */
-       gpencil_brush_delete(ts, brush);
+       BKE_gpencil_brush_delete(ts, brush);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1465,7 +1090,7 @@ static int gp_brush_remove_exec(bContext *C, wmOperator *op)
 void GPENCIL_OT_brush_remove(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name = "Remove brush";
+       ot->name = "Remove Brush";
        ot->idname = "GPENCIL_OT_brush_remove";
        ot->description = "Remove active Grease Pencil drawing brush";
 
@@ -1501,7 +1126,7 @@ static int gp_brush_change_exec(bContext *C, wmOperator *op)
        /* Get brush or create new one */
        if (brush_num == -1) {
                /* Create brush */
-               brush = gpencil_brush_addnew(ts, DATA_("GP_Brush"), true);
+               brush = BKE_gpencil_brush_addnew(ts, DATA_("GP_Brush"), true);
        }
        else {
                /* Try to get brush */
@@ -1514,7 +1139,7 @@ static int gp_brush_change_exec(bContext *C, wmOperator *op)
        }
 
        /* Set active brush */
-       gpencil_brush_setactive(ts, brush);
+       BKE_gpencil_brush_setactive(ts, brush);
 
        /* updates */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1552,7 +1177,7 @@ enum {
 static int gp_brush_move_exec(bContext *C, wmOperator *op)
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
-       bGPDbrush *brush = gpencil_brush_getactive(ts);
+       bGPDbrush *brush = BKE_gpencil_brush_getactive(ts);
 
        int direction = RNA_enum_get(op->ptr, "type");
 
@@ -1584,7 +1209,7 @@ static int gp_brush_move_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_brush_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_BRUSH_MOVE_UP, "UP", 0, "Up", ""},
                {GP_BRUSH_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL }
@@ -1610,7 +1235,7 @@ void GPENCIL_OT_brush_move(wmOperatorType *ot)
 static int gp_brush_presets_create_exec(bContext *C, wmOperator *UNUSED(op))
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
-       gpencil_brush_init_presets(ts);
+       BKE_gpencil_brush_init_presets(ts);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1645,7 +1270,7 @@ static int gp_brush_copy_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
 
-       bGPDbrush *brush = gpencil_brush_getactive(ts);
+       bGPDbrush *brush = BKE_gpencil_brush_getactive(ts);
        bGPDbrush *newbrush;
 
        /* sanity checks */
@@ -1653,7 +1278,7 @@ static int gp_brush_copy_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
 
        /* create a brush and duplicate data */
-       newbrush = gpencil_brush_addnew(ts, brush->info, true);
+       newbrush = BKE_gpencil_brush_addnew(ts, brush->info, true);
        newbrush->thickness = brush->thickness;
        newbrush->draw_smoothfac = brush->draw_smoothfac;
        newbrush->draw_smoothlvl = brush->draw_smoothlvl;
@@ -1677,7 +1302,7 @@ static int gp_brush_copy_exec(bContext *C, wmOperator *op)
        newbrush->cur_strength = curvemapping_copy(brush->cur_strength);
        newbrush->cur_jitter = curvemapping_copy(brush->cur_jitter);
 
-       gpencil_brush_setactive(ts, newbrush);
+       BKE_gpencil_brush_setactive(ts, newbrush);
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 
@@ -1718,7 +1343,7 @@ static int gp_brush_select_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
 
-       gpencil_brush_setactive(ts, brush);
+       BKE_gpencil_brush_setactive(ts, brush);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1760,10 +1385,10 @@ static int gp_palette_add_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
        if (*gpd_ptr == NULL)
-               *gpd_ptr = gpencil_data_addnew(DATA_("GPencil"));
+               *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
 
        /* add new palette now */
-       gpencil_palette_addnew(*gpd_ptr, DATA_("GP_Palette"), true);
+       BKE_gpencil_palette_addnew(*gpd_ptr, DATA_("GP_Palette"), true);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1776,7 +1401,7 @@ void GPENCIL_OT_palette_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add Palette";
        ot->idname = "GPENCIL_OT_palette_add";
-       ot->description = "Add new Grease Pencil palette for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil palette for the active Grease Pencil data-block";
 
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -1790,14 +1415,14 @@ void GPENCIL_OT_palette_add(wmOperatorType *ot)
 static int gp_palette_remove_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
 
        /* sanity checks */
        if (ELEM(NULL, gpd, palette))
                return OPERATOR_CANCELLED;
 
-       if (BLI_listbase_count(&gpd->palettes) < 2) {
-               BKE_report(op->reports, RPT_ERROR, "Grease Pencil needs a palette. Unable to delete palette");
+       if (BLI_listbase_count_ex(&gpd->palettes, 2) < 2) {
+               BKE_report(op->reports, RPT_ERROR, "Grease Pencil needs a palette, unable to delete the last one");
                return OPERATOR_CANCELLED;
        }
 
@@ -1807,12 +1432,12 @@ static int gp_palette_remove_exec(bContext *C, wmOperator *op)
         * - if this is the only palette, this naturally becomes NULL
         */
        if (palette->prev)
-               gpencil_palette_setactive(gpd, palette->prev);
+               BKE_gpencil_palette_setactive(gpd, palette->prev);
        else
-               gpencil_palette_setactive(gpd, palette->next);
+               BKE_gpencil_palette_setactive(gpd, palette->next);
 
        /* delete the palette now... */
-       gpencil_palette_delete(gpd, palette);
+       BKE_gpencil_palette_delete(gpd, palette);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1859,7 +1484,7 @@ static int gp_palette_change_exec(bContext *C, wmOperator *op)
        /* Get palette or create new one */
        if (palette_num == -1) {
                /* Create palette */
-               palette = gpencil_palette_addnew(gpd, DATA_("GP_Palette"), true);
+               palette = BKE_gpencil_palette_addnew(gpd, DATA_("GP_Palette"), true);
        }
        else {
                /* Try to get palette */
@@ -1872,7 +1497,7 @@ static int gp_palette_change_exec(bContext *C, wmOperator *op)
        }
 
        /* Set active palette */
-       gpencil_palette_setactive(gpd, palette);
+       BKE_gpencil_palette_setactive(gpd, palette);
 
        /* updates */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1911,7 +1536,7 @@ static int gp_palette_lock_layer_exec(bContext *C, wmOperator *UNUSED(op))
        if (ELEM(NULL, gpd))
                return OPERATOR_CANCELLED;
 
-       palette = gpencil_palette_getactive(gpd);
+       palette = BKE_gpencil_palette_getactive(gpd);
        if (ELEM(NULL, palette))
                return OPERATOR_CANCELLED;
 
@@ -1972,15 +1597,15 @@ static int gp_palettecolor_add_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
        if (*gpd_ptr == NULL)
-               *gpd_ptr = gpencil_data_addnew(DATA_("GPencil"));
+               *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
 
        /* verify palette */
-       bGPDpalette *palette = gpencil_palette_getactive(*gpd_ptr);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(*gpd_ptr);
        if (palette == NULL)
-               palette = gpencil_palette_addnew(*gpd_ptr, DATA_("GP_Palette"), true);
+               palette = BKE_gpencil_palette_addnew(*gpd_ptr, DATA_("GP_Palette"), true);
 
        /* add new palette color now */
-       gpencil_palettecolor_addnew(palette, DATA_("Color"), true);
+       BKE_gpencil_palettecolor_addnew(palette, DATA_("Color"), true);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -1993,7 +1618,7 @@ void GPENCIL_OT_palettecolor_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add Palette Color";
        ot->idname = "GPENCIL_OT_palettecolor_add";
-       ot->description = "Add new Grease Pencil palette color for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil palette color for the active Grease Pencil data-block";
 
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -2007,8 +1632,8 @@ void GPENCIL_OT_palettecolor_add(wmOperatorType *ot)
 static int gp_palettecolor_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *color = gpencil_palettecolor_getactive(palette);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+       bGPDpalettecolor *color = BKE_gpencil_palettecolor_getactive(palette);
 
        /* sanity checks */
        if (ELEM(NULL, gpd, palette, color))
@@ -2019,15 +1644,15 @@ static int gp_palettecolor_remove_exec(bContext *C, wmOperator *UNUSED(op))
         * - if this is the only color, this naturally becomes NULL
         */
        if (color->prev)
-               gpencil_palettecolor_setactive(palette, color->prev);
+               BKE_gpencil_palettecolor_setactive(palette, color->prev);
        else
-               gpencil_palettecolor_setactive(palette, color->next);
+               BKE_gpencil_palettecolor_setactive(palette, color->next);
 
        /* delete the strokes */
-       gpencil_palettecolor_delete_strokes(gpd, color->info);
+       BKE_gpencil_palettecolor_delete_strokes(gpd, color->info);
 
        /* delete the palette color now... */
-       gpencil_palettecolor_delete(palette, color);
+       BKE_gpencil_palettecolor_delete(palette, color);
 
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -2054,8 +1679,8 @@ void GPENCIL_OT_palettecolor_remove(wmOperatorType *ot)
 static int gp_isolate_palettecolor_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *active_color = gpencil_palettecolor_getactive(palette);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+       bGPDpalettecolor *active_color = BKE_gpencil_palettecolor_getactive(palette);
        bGPDpalettecolor *palcolor;
 
        int flags = PC_COLOR_LOCKED;
@@ -2131,8 +1756,8 @@ void GPENCIL_OT_palettecolor_isolate(wmOperatorType *ot)
 static int gp_palettecolor_hide_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *palcolor = gpencil_palettecolor_getactive(palette);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+       bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
 
        bool unselected = RNA_boolean_get(op->ptr, "unselected");
 
@@ -2190,7 +1815,7 @@ static int gp_palettecolor_reveal_poll(bContext *C)
 static int gp_palettecolor_reveal_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
        bGPDpalettecolor *palcolor;
 
        /* sanity checks */
@@ -2228,7 +1853,7 @@ void GPENCIL_OT_palettecolor_reveal(wmOperatorType *ot)
 static int gp_palettecolor_lock_all_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
        bGPDpalettecolor *palcolor;
 
        /* sanity checks */
@@ -2266,7 +1891,7 @@ void GPENCIL_OT_palettecolor_lock_all(wmOperatorType *ot)
 static int gp_palettecolor_unlock_all_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
        bGPDpalettecolor *palcolor;
 
        /* sanity checks */
@@ -2309,8 +1934,8 @@ enum {
 static int gp_palettecolor_move_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *palcolor = gpencil_palettecolor_getactive(palette);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+       bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
 
        int direction = RNA_enum_get(op->ptr, "direction");
 
@@ -2341,7 +1966,7 @@ static int gp_palettecolor_move_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_palettecolor_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_COLOR_MOVE_UP, "UP", 0, "Up", ""},
                {GP_COLOR_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL}
@@ -2367,8 +1992,8 @@ void GPENCIL_OT_palettecolor_move(wmOperatorType *ot)
 static int gp_palettecolor_select_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *palcolor = gpencil_palettecolor_getactive(palette);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+       bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
 
        /* sanity checks */
        if (ELEM(NULL, gpd, palette, palcolor))
@@ -2426,8 +2051,8 @@ void GPENCIL_OT_palettecolor_select(wmOperatorType *ot)
 static int gp_palettecolor_copy_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDpalette *palette = gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *palcolor = gpencil_palettecolor_getactive(palette);
+       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+       bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
        bGPDpalettecolor *newcolor;
 
        /* sanity checks */
@@ -2435,7 +2060,7 @@ static int gp_palettecolor_copy_exec(bContext *C, wmOperator *UNUSED(op))
                return OPERATOR_CANCELLED;
 
        /* create a new color and duplicate data */
-       newcolor = gpencil_palettecolor_addnew(palette, palcolor->info, true);
+       newcolor = BKE_gpencil_palettecolor_addnew(palette, palcolor->info, true);
        copy_v4_v4(newcolor->color, palcolor->color);
        copy_v4_v4(newcolor->fill, palcolor->fill);
        newcolor->flag = palcolor->flag;