Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / screen / screen_context.c
index 99c71da..b553306 100644 (file)
@@ -85,7 +85,8 @@ const char *screen_context_dir[] = {
        "sequences", "selected_sequences", "selected_editable_sequences", /* sequencer */
        "gpencil_data", "gpencil_data_owner", /* grease pencil data */
        "visible_gpencil_layers", "editable_gpencil_layers", "editable_gpencil_strokes",
-       "active_gpencil_layer", "active_gpencil_frame",
+       "active_gpencil_layer", "active_gpencil_frame", "active_gpencil_palette", 
+       "active_gpencil_palettecolor", "active_gpencil_brush",
        "active_operator",
        NULL};
 
@@ -116,7 +117,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        }
        else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) {
                const unsigned int lay = context_layers(sc, scene, sa);
-               int visible_objects = CTX_data_equals(member, "visible_objects");
+               const bool visible_objects = CTX_data_equals(member, "visible_objects");
 
                for (base = scene->base.first; base; base = base->next) {
                        if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) && (base->lay & lay)) {
@@ -131,7 +132,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        }
        else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) {
                const unsigned int lay = context_layers(sc, scene, sa);
-               int selectable_objects = CTX_data_equals(member, "selectable_objects");
+               const bool selectable_objects = CTX_data_equals(member, "selectable_objects");
 
                for (base = scene->base.first; base; base = base->next) {
                        if (base->lay & lay) {
@@ -148,7 +149,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        }
        else if (CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
                const unsigned int lay = context_layers(sc, scene, sa);
-               int selected_objects = CTX_data_equals(member, "selected_objects");
+               const bool selected_objects = CTX_data_equals(member, "selected_objects");
 
                for (base = scene->base.first; base; base = base->next) {
                        if ((base->flag & SELECT) && (base->lay & lay)) {
@@ -163,7 +164,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        }
        else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
                const unsigned int lay = context_layers(sc, scene, sa);
-               int selected_editable_objects = CTX_data_equals(member, "selected_editable_objects");
+               const bool selected_editable_objects = CTX_data_equals(member, "selected_editable_objects");
 
                for (base = scene->base.first; base; base = base->next) {
                        if ((base->flag & SELECT) && (base->lay & lay)) {
@@ -182,7 +183,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        }
        else if (CTX_data_equals(member, "editable_objects") || CTX_data_equals(member, "editable_bases")) {
                const unsigned int lay = context_layers(sc, scene, sa);
-               int editable_objects = CTX_data_equals(member, "editable_objects");
+               const bool editable_objects = CTX_data_equals(member, "editable_objects");
                
                /* Visible + Editable, but not necessarily selected */
                for (base = scene->base.first; base; base = base->next) {
@@ -201,7 +202,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        else if (CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) {
                bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
                EditBone *ebone, *flipbone = NULL;
-               int editable_bones = CTX_data_equals(member, "editable_bones");
+               const bool editable_bones = CTX_data_equals(member, "editable_bones");
                
                if (arm && arm->edbo) {
                        /* Attention: X-Axis Mirroring is also handled here... */
@@ -243,7 +244,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        else if (CTX_data_equals(member, "selected_bones") || CTX_data_equals(member, "selected_editable_bones")) {
                bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
                EditBone *ebone, *flipbone = NULL;
-               int selected_editable_bones = CTX_data_equals(member, "selected_editable_bones");
+               const bool selected_editable_bones = CTX_data_equals(member, "selected_editable_bones");
                
                if (arm && arm->edbo) {
                        /* Attention: X-Axis Mirroring is also handled here... */
@@ -460,7 +461,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
                bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
                
                if (gpd) {
-                       bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+                       bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
                        
                        if (gpl) {
                                CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl);
@@ -468,12 +469,50 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
                        }
                }
        }
+       else if (CTX_data_equals(member, "active_gpencil_palette")) {
+               /* XXX: see comment for gpencil_data case... */
+               bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
+
+               if (gpd) {
+                       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+
+                       if (palette) {
+                               CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPalette, palette);
+                               return 1;
+                       }
+               }
+       }
+       else if (CTX_data_equals(member, "active_gpencil_palettecolor")) {
+               /* XXX: see comment for gpencil_data case... */
+               bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
+
+               if (gpd) {
+                       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
+
+                       if (palette) {
+                               bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
+                               if (palcolor) {
+                                       CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPaletteColor, palcolor);
+                                       return 1;
+                               }
+                       }
+               }
+       }
+       else if (CTX_data_equals(member, "active_gpencil_brush")) {
+               /* XXX: see comment for gpencil_data case... */
+               bGPDbrush *brush = BKE_gpencil_brush_getactive(scene->toolsettings);
+
+               if (brush) {
+                       CTX_data_pointer_set(result, NULL, &RNA_GPencilBrush, brush);
+                       return 1;
+               }
+       }
        else if (CTX_data_equals(member, "active_gpencil_frame")) {
                /* XXX: see comment for gpencil_data case... */
                bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
                
                if (gpd) {
-                       bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+                       bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
                        
                        if (gpl) {
                                CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl->actframe);
@@ -527,6 +566,11 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
                                        
                                        for (gps = gpf->strokes.first; gps; gps = gps->next) {
                                                if (ED_gpencil_stroke_can_use_direct(sa, gps)) {
+                                                       /* check if the color is editable */
+                                                       if (ED_gpencil_stroke_color_use(gpl, gps) == false) {
+                                                               continue;
+                                                       }
+
                                                        CTX_data_list_add(result, &gpd->id, &RNA_GPencilStroke, gps);
                                                }
                                        }