Blender  V3.3
rna_palette.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdlib.h>
8 
9 #include "BLI_utildefines.h"
10 
11 #include "RNA_access.h"
12 #include "RNA_define.h"
13 
14 #include "rna_internal.h"
15 
16 #include "WM_types.h"
17 
18 #ifdef RNA_RUNTIME
19 
20 # include "DNA_brush_types.h"
21 
22 # include "BKE_paint.h"
23 # include "BKE_report.h"
24 static PaletteColor *rna_Palette_color_new(Palette *palette)
25 {
26  if (ID_IS_LINKED(palette) || ID_IS_OVERRIDE_LIBRARY(palette)) {
27  return NULL;
28  }
29 
31  return color;
32 }
33 
34 static void rna_Palette_color_remove(Palette *palette, ReportList *reports, PointerRNA *color_ptr)
35 {
36  if (ID_IS_LINKED(palette) || ID_IS_OVERRIDE_LIBRARY(palette)) {
37  return;
38  }
39 
40  PaletteColor *color = color_ptr->data;
41 
42  if (BLI_findindex(&palette->colors, color) == -1) {
44  reports, RPT_ERROR, "Palette '%s' does not contain color given", palette->id.name + 2);
45  return;
46  }
47 
49 
50  RNA_POINTER_INVALIDATE(color_ptr);
51 }
52 
53 static void rna_Palette_color_clear(Palette *palette)
54 {
55  if (ID_IS_LINKED(palette) || ID_IS_OVERRIDE_LIBRARY(palette)) {
56  return;
57  }
58 
59  BKE_palette_clear(palette);
60 }
61 
62 static PointerRNA rna_Palette_active_color_get(PointerRNA *ptr)
63 {
64  Palette *palette = ptr->data;
66 
67  color = BLI_findlink(&palette->colors, palette->active_color);
68 
69  if (color) {
70  return rna_pointer_inherit_refine(ptr, &RNA_PaletteColor, color);
71  }
72 
74 }
75 
76 static void rna_Palette_active_color_set(PointerRNA *ptr,
77  PointerRNA value,
78  struct ReportList *UNUSED(reports))
79 {
80  Palette *palette = ptr->data;
81  PaletteColor *color = value.data;
82 
83  /* -1 is ok for an unset index */
84  if (color == NULL) {
85  palette->active_color = -1;
86  }
87  else {
88  palette->active_color = BLI_findindex(&palette->colors, color);
89  }
90 }
91 
92 #else
93 
94 /* palette.colors */
95 static void rna_def_palettecolors(BlenderRNA *brna, PropertyRNA *cprop)
96 {
97  StructRNA *srna;
98  PropertyRNA *prop;
99 
100  FunctionRNA *func;
101  PropertyRNA *parm;
102 
103  RNA_def_property_srna(cprop, "PaletteColors");
104  srna = RNA_def_struct(brna, "PaletteColors", NULL);
105  RNA_def_struct_sdna(srna, "Palette");
106  RNA_def_struct_ui_text(srna, "Palette Splines", "Collection of palette colors");
107 
108  func = RNA_def_function(srna, "new", "rna_Palette_color_new");
109  RNA_def_function_ui_description(func, "Add a new color to the palette");
110  parm = RNA_def_pointer(func, "color", "PaletteColor", "", "The newly created color");
111  RNA_def_function_return(func, parm);
112 
113  func = RNA_def_function(srna, "remove", "rna_Palette_color_remove");
114  RNA_def_function_ui_description(func, "Remove a color from the palette");
116  parm = RNA_def_pointer(func, "color", "PaletteColor", "", "The color to remove");
119 
120  func = RNA_def_function(srna, "clear", "rna_Palette_color_clear");
121  RNA_def_function_ui_description(func, "Remove all colors from the palette");
122 
123  prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
124  RNA_def_property_struct_type(prop, "PaletteColor");
126  prop, "rna_Palette_active_color_get", "rna_Palette_active_color_set", NULL, NULL);
128  RNA_def_property_ui_text(prop, "Active Palette Color", "");
129 }
130 
132 {
133  StructRNA *srna;
134  PropertyRNA *prop;
135 
136  srna = RNA_def_struct(brna, "PaletteColor", NULL);
137  RNA_def_struct_ui_text(srna, "Palette Color", "");
138 
139  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
140  RNA_def_property_range(prop, 0.0, 1.0);
141  RNA_def_property_float_sdna(prop, NULL, "rgb");
143  RNA_def_property_array(prop, 3);
144  RNA_def_property_ui_text(prop, "Color", "");
146 
147  prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
148  RNA_def_property_range(prop, 0.0, 1.0);
149  RNA_def_property_float_sdna(prop, NULL, "value");
150  RNA_def_property_ui_text(prop, "Value", "");
152 
153  prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
154  RNA_def_property_range(prop, 0.0, 1.0);
155  RNA_def_property_float_sdna(prop, NULL, "value");
156  RNA_def_property_ui_text(prop, "Weight", "");
158 }
159 
160 static void rna_def_palette(BlenderRNA *brna)
161 {
162  StructRNA *srna;
163  PropertyRNA *prop;
164 
165  srna = RNA_def_struct(brna, "Palette", "ID");
166  RNA_def_struct_ui_text(srna, "Palette", "");
167  RNA_def_struct_ui_icon(srna, ICON_COLOR);
168 
169  prop = RNA_def_property(srna, "colors", PROP_COLLECTION, PROP_NONE);
170  RNA_def_property_struct_type(prop, "PaletteColor");
171  rna_def_palettecolors(brna, prop);
172 }
173 
175 {
176  /* *** Non-Animated *** */
178  rna_def_palettecolor(brna);
179  rna_def_palette(brna);
181 }
182 
183 #endif
void BKE_palette_color_remove(struct Palette *palette, struct PaletteColor *color)
Definition: paint.c:742
void BKE_palette_clear(struct Palette *palette)
Definition: paint.c:758
struct PaletteColor * BKE_palette_color_add(struct Palette *palette)
Definition: paint.c:770
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define UNUSED(x)
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
#define RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:744
@ PARM_RNAPTR
Definition: RNA_types.h:354
@ PARM_REQUIRED
Definition: RNA_types.h:352
@ FUNC_USE_REPORTS
Definition: RNA_types.h:663
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_POINTER
Definition: RNA_types.h:64
@ PROP_COLLECTION
Definition: RNA_types.h:65
@ PROP_THICK_WRAP
Definition: RNA_types.h:285
@ PROP_EDITABLE
Definition: RNA_types.h:189
@ PROP_LIB_EXCEPTION
Definition: RNA_types.h:195
@ PROP_NEVER_NULL
Definition: RNA_types.h:239
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_COLOR_GAMMA
Definition: RNA_types.h:165
#define NC_SCENE
Definition: WM_types.h:328
#define ND_TOOLSETTINGS
Definition: WM_types.h:397
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:186
void RNA_define_animate_sdna(bool animate)
Definition: rna_define.c:748
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4170
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1526
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4312
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4273
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3474
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1237
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1048
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1539
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1737
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1772
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4347
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2900
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4342
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3385
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1245
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2493
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1518
void RNA_def_palette(BlenderRNA *brna)
Definition: rna_palette.c:174
static void rna_def_palette(BlenderRNA *brna)
Definition: rna_palette.c:160
static void rna_def_palettecolor(BlenderRNA *brna)
Definition: rna_palette.c:131
static void rna_def_palettecolors(BlenderRNA *brna, PropertyRNA *cprop)
Definition: rna_palette.c:95
char name[66]
Definition: DNA_ID.h:378
int active_color
ListBase colors
void * data
Definition: RNA_types.h:38
PointerRNA * ptr
Definition: wm_files.c:3480