Blender  V3.3
gpencil_add_blank.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2017 Blender Foundation. */
3 
8 #include "BLI_math.h"
9 #include "BLI_utildefines.h"
10 
11 #include "DNA_gpencil_types.h"
12 #include "DNA_material_types.h"
13 #include "DNA_object_types.h"
14 #include "DNA_scene_types.h"
15 
16 #include "BKE_context.h"
17 #include "BKE_gpencil.h"
18 #include "BKE_gpencil_geom.h"
19 #include "BKE_main.h"
20 #include "BKE_material.h"
21 
22 #include "BLT_translation.h"
23 
24 #include "DEG_depsgraph.h"
25 
26 #include "ED_gpencil.h"
27 
28 /* Definition of the most important info from a color */
29 typedef struct ColorTemplate {
30  const char *name;
31  float line[4];
32  float fill[4];
34 
35 /* Add color an ensure duplications (matched by name) */
36 static int gpencil_stroke_material(Main *bmain, Object *ob, const ColorTemplate *pct)
37 {
38  int index;
39  Material *ma = BKE_gpencil_object_material_ensure_by_name(bmain, ob, DATA_(pct->name), &index);
40 
41  copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
43 
44  copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
46 
47  return index;
48 }
49 
50 /* ***************************************************************** */
51 /* Stroke Geometry */
52 
53 /* ***************************************************************** */
54 /* Color Data */
55 
57  N_("Black"),
58  {0.0f, 0.0f, 0.0f, 1.0f},
59  {0.0f, 0.0f, 0.0f, 0.0f},
60 };
61 
62 /* ***************************************************************** */
63 /* Blank API */
64 
65 void ED_gpencil_create_blank(bContext *C, Object *ob, float UNUSED(mat[4][4]))
66 {
67  Main *bmain = CTX_data_main(C);
69  bGPdata *gpd = (bGPdata *)ob->data;
70 
71  /* create colors */
72  int color_black = gpencil_stroke_material(bmain, ob, &gp_stroke_material_black);
73 
74  /* set first color as active and in brushes */
75  ob->actcol = color_black + 1;
76 
77  /* layers */
78  bGPDlayer *layer = BKE_gpencil_layer_addnew(gpd, "GP_Layer", true, false);
79 
80  /* frames */
82 
83  /* update depsgraph */
86 }
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct bGPDframe * BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe)
Definition: gpencil.c:514
struct Material * BKE_gpencil_object_material_ensure_by_name(struct Main *bmain, struct Object *ob, const char *name, int *r_index)
Definition: gpencil.c:2228
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive, bool add_to_header)
Definition: gpencil.c:621
General operations, lookup, etc. for materials.
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define UNUSED(x)
#define DATA_(msgid)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
@ GP_DATA_CACHE_IS_DIRTY
Object is a sort of wrapper for general info.
#define C
Definition: RandGen.cpp:25
Scene scene
void ED_gpencil_create_blank(bContext *C, Object *ob, float UNUSED(mat[4][4]))
static const ColorTemplate gp_stroke_material_black
static int gpencil_stroke_material(Main *bmain, Object *ob, const ColorTemplate *pct)
struct ColorTemplate ColorTemplate
const char * name
Definition: BKE_main.h:121
struct MaterialGPencilStyle * gp_style
void * data
struct RenderData r
#define N_(msgid)