Commit: fde0e44aa44d9d820751b4598b8c469c89352383
Author: Antonio Vazquez
Date:   Tue Mar 13 15:16:17 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBfde0e44aa44d9d820751b4598b8c469c89352383

Use Brush default color for cursor

If the brush has assigned a default color, the cursor must use this color, not 
the context default color.

===================================================================

M       source/blender/blenkernel/BKE_gpencil.h
M       source/blender/blenkernel/intern/gpencil.c
M       source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M       source/blender/editors/gpencil/gpencil_paint.c
M       source/blender/editors/gpencil/gpencil_utils.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_gpencil.h 
b/source/blender/blenkernel/BKE_gpencil.h
index 3b781e8f0a4..83a97c0a0df 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -150,7 +150,7 @@ void BKE_gpencil_paletteslot_set_palette(struct bGPdata 
*gpd, struct bGPDpalette
 struct bGPDpaletteref *BKE_gpencil_paletteslot_add(struct bGPdata *gpd, struct 
Palette *palette);
 struct bGPDpaletteref *BKE_gpencil_paletteslot_addnew(struct Main *bmain, 
struct bGPdata *gpd, const char name[]);
 struct bGPDpaletteref *BKE_gpencil_paletteslot_validate(struct Main *bmain, 
struct bGPdata *gpd);
-struct PaletteColor *BKE_gpencil_get_color_from_brush(struct bGPdata *gpd, 
struct Brush *brush);
+struct PaletteColor *BKE_gpencil_get_color_from_brush(struct bGPdata *gpd, 
struct Brush *brush, bool add);
 
 /* Palettes - Deprecated (2.78-2.79) */
 void BKE_gpencil_free_palettes(struct ListBase *list);
diff --git a/source/blender/blenkernel/intern/gpencil.c 
b/source/blender/blenkernel/intern/gpencil.c
index cac976f0b85..723922b13d8 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1281,12 +1281,12 @@ bGPDpaletteref *BKE_gpencil_paletteslot_addnew(Main 
*bmain, bGPdata *gpd, const
        return BKE_gpencil_paletteslot_add(gpd, palette);
 }
 
-PaletteColor *BKE_gpencil_get_color_from_brush(bGPdata *gpd, Brush *brush)
+PaletteColor *BKE_gpencil_get_color_from_brush(bGPdata *gpd, Brush *brush, 
bool add)
 {
        bGPDpaletteref *palslot = NULL;
        PaletteColor *palcolor = NULL;
 
-       if ((brush->palette) && (brush->colorname)) {
+       if ((gpd) && (gpd->palette_slots.first) && (brush) && (brush->palette) 
&& (brush->colorname)) {
 
                /* verify paletteslots has this palette */
                for (bGPDpaletteref *slot = gpd->palette_slots.first; slot; 
slot = slot->next) {
@@ -1297,6 +1297,9 @@ PaletteColor *BKE_gpencil_get_color_from_brush(bGPdata 
*gpd, Brush *brush)
                }
                /* add slot */
                if (palslot == NULL) {
+                       if (!add) {
+                               return NULL;
+                       }
                        palslot = BKE_gpencil_paletteslot_add(gpd, NULL);
                        palslot->palette = brush->palette;
                }
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index bd22260b7a4..ca5aae452e9 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -864,7 +864,7 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data 
*e_data, void *vedata, T
        float obscale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
 
        /* if the brush has a palette and color defined, use these and not 
current defaults */
-       palcolor = BKE_gpencil_get_color_from_brush(gpd, brush);
+       palcolor = BKE_gpencil_get_color_from_brush(gpd, brush, false);
        if (palcolor == NULL) {
                bGPDpaletteref *palslot = 
BKE_gpencil_paletteslot_get_active(gpd);
                palcolor = BKE_palette_color_get_active((palslot) ? 
palslot->palette : NULL);
diff --git a/source/blender/editors/gpencil/gpencil_paint.c 
b/source/blender/editors/gpencil/gpencil_paint.c
index d39d4fb2a89..aa6b7f8df53 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1570,7 +1570,7 @@ static void gp_init_palette(tGPsdata *p)
        PaletteColor *palcolor = NULL;
        
        /* if the brush has a palette and color defined, use these and not 
current defaults */
-       palcolor = BKE_gpencil_get_color_from_brush(gpd, brush);
+       palcolor = BKE_gpencil_get_color_from_brush(gpd, brush, true);
 
        /* if no brush defaults, get palette and color info
         * NOTE: _validate() ensures that everything we need will exist...
diff --git a/source/blender/editors/gpencil/gpencil_utils.c 
b/source/blender/editors/gpencil/gpencil_utils.c
index 301d551aed4..e8e1a290c2b 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1355,11 +1355,14 @@ static void gp_brush_drawcursor(bContext *C, int x, int 
y, void *customdata)
        bGPDpaletteref *palslot = NULL;
        Palette *palette = NULL;
        PaletteColor *palcolor = NULL;
-       palslot = BKE_gpencil_paletteslot_get_active(gpd);
-       if (palslot) {
-               palette = palslot->palette;
-               if (palette) {
-                       palcolor = BKE_palette_color_get_active(palette);
+       palcolor = BKE_gpencil_get_color_from_brush(gpd, 
CTX_data_active_gpencil_brush(C), false);
+       if (palcolor == NULL) {
+               palslot = BKE_gpencil_paletteslot_get_active(gpd);
+               if (palslot) {
+                       palette = palslot->palette;
+                       if (palette) {
+                               palcolor = 
BKE_palette_color_get_active(palette);
+                       }
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to