Fix T49097: GP ruler data reinstances GP_Palette Color
authorAntonioya <blendergit@gmail.com>
Tue, 16 Aug 2016 20:28:34 +0000 (22:28 +0200)
committerAntonioya <blendergit@gmail.com>
Tue, 16 Aug 2016 20:29:13 +0000 (22:29 +0200)
If the ruler is saved, a new color was created for each ruler. With the
change, a color is created for the first instance, and it reused in the
following instances. The default color is the current default color for
GP.

source/blender/editors/space_view3d/view3d_ruler.c

index 37b068e3e4906c3c59e0d41d728b3482371f77f4..dda1a64726c53ab9c63cab344dccddd379ce9ce6 100644 (file)
@@ -297,6 +297,8 @@ static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
        bGPDlayer *gpl;
        bGPDframe *gpf;
        bGPDstroke *gps;
+       bGPDpalette *palette;
+       bGPDpalettecolor *palcolor;
        RulerItem *ruler_item;
        const char *ruler_name = RULER_ID;
        bool changed = false;
@@ -312,6 +314,17 @@ static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
                gpl->flag |= GP_LAYER_HIDE;
        }
 
+       /* try to get active palette or create a new one */
+       palette = BKE_gpencil_palette_getactive(scene->gpd);
+       if (palette == NULL) {
+               palette = BKE_gpencil_palette_addnew(scene->gpd, DATA_("GP_Palette"), true);
+       }
+       /* try to get color with the ruler name or create a new one */
+       palcolor = BKE_gpencil_palettecolor_getbyname(palette, (char *)ruler_name);
+       if (palcolor == NULL) {
+               palcolor = BKE_gpencil_palettecolor_addnew(palette, (char *)ruler_name, true);
+       }
+       
        gpf = BKE_gpencil_layer_getframe(gpl, CFRA, true);
        BKE_gpencil_free_strokes(gpf);
 
@@ -342,6 +355,9 @@ static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
                        }
                }
                gps->flag = GP_STROKE_3DSPACE;
+               /* assign color to stroke */
+               strcpy(gps->colorname, palcolor->info);
+               gps->palcolor = palcolor;
                BLI_addtail(&gpf->strokes, gps);
                changed = true;
        }