Blender  V2.93
rna_palette.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <stdlib.h>
22 
23 #include "BLI_utildefines.h"
24 
25 #include "RNA_access.h"
26 #include "RNA_define.h"
27 
28 #include "rna_internal.h"
29 
30 #include "WM_types.h"
31 
32 #ifdef RNA_RUNTIME
33 
34 # include "DNA_brush_types.h"
35 
36 # include "BKE_paint.h"
37 # include "BKE_report.h"
38 static PaletteColor *rna_Palette_color_new(Palette *palette)
39 {
40  PaletteColor *color = BKE_palette_color_add(palette);
41  return color;
42 }
43 
44 static void rna_Palette_color_remove(Palette *palette, ReportList *reports, PointerRNA *color_ptr)
45 {
46  PaletteColor *color = color_ptr->data;
47 
48  if (BLI_findindex(&palette->colors, color) == -1) {
50  reports, RPT_ERROR, "Palette '%s' does not contain color given", palette->id.name + 2);
51  return;
52  }
53 
54  BKE_palette_color_remove(palette, color);
55 
56  RNA_POINTER_INVALIDATE(color_ptr);
57 }
58 
59 static void rna_Palette_color_clear(Palette *palette)
60 {
61  BKE_palette_clear(palette);
62 }
63 
64 static PointerRNA rna_Palette_active_color_get(PointerRNA *ptr)
65 {
66  Palette *palette = ptr->data;
67  PaletteColor *color;
68 
69  color = BLI_findlink(&palette->colors, palette->active_color);
70 
71  if (color) {
73  }
74 
76 }
77 
78 static void rna_Palette_active_color_set(PointerRNA *ptr,
79  PointerRNA value,
80  struct ReportList *UNUSED(reports))
81 {
82  Palette *palette = ptr->data;
83  PaletteColor *color = value.data;
84 
85  /* -1 is ok for an unset index */
86  if (color == NULL) {
87  palette->active_color = -1;
88  }
89  else {
90  palette->active_color = BLI_findindex(&palette->colors, color);
91  }
92 }
93 
94 #else
95 
96 /* palette.colors */
97 static void rna_def_palettecolors(BlenderRNA *brna, PropertyRNA *cprop)
98 {
99  StructRNA *srna;
100  PropertyRNA *prop;
101 
102  FunctionRNA *func;
103  PropertyRNA *parm;
104 
105  RNA_def_property_srna(cprop, "PaletteColors");
106  srna = RNA_def_struct(brna, "PaletteColors", NULL);
107  RNA_def_struct_sdna(srna, "Palette");
108  RNA_def_struct_ui_text(srna, "Palette Splines", "Collection of palette colors");
109 
110  func = RNA_def_function(srna, "new", "rna_Palette_color_new");
111  RNA_def_function_ui_description(func, "Add a new color to the palette");
112  parm = RNA_def_pointer(func, "color", "PaletteColor", "", "The newly created color");
113  RNA_def_function_return(func, parm);
114 
115  func = RNA_def_function(srna, "remove", "rna_Palette_color_remove");
116  RNA_def_function_ui_description(func, "Remove a color from the palette");
118  parm = RNA_def_pointer(func, "color", "PaletteColor", "", "The color to remove");
121 
122  func = RNA_def_function(srna, "clear", "rna_Palette_color_clear");
123  RNA_def_function_ui_description(func, "Remove all colors from the palette");
124 
125  prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
126  RNA_def_property_struct_type(prop, "PaletteColor");
128  prop, "rna_Palette_active_color_get", "rna_Palette_active_color_set", NULL, NULL);
130  RNA_def_property_ui_text(prop, "Active Palette Color", "");
131 }
132 
134 {
135  StructRNA *srna;
136  PropertyRNA *prop;
137 
138  srna = RNA_def_struct(brna, "PaletteColor", NULL);
139  RNA_def_struct_ui_text(srna, "Palette Color", "");
140 
141  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
142  RNA_def_property_range(prop, 0.0, 1.0);
143  RNA_def_property_float_sdna(prop, NULL, "rgb");
144  RNA_def_property_array(prop, 3);
145  RNA_def_property_ui_text(prop, "Color", "");
147 
148  prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
149  RNA_def_property_range(prop, 0.0, 1.0);
150  RNA_def_property_float_sdna(prop, NULL, "value");
151  RNA_def_property_ui_text(prop, "Value", "");
153 
154  prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
155  RNA_def_property_range(prop, 0.0, 1.0);
156  RNA_def_property_float_sdna(prop, NULL, "value");
157  RNA_def_property_ui_text(prop, "Weight", "");
159 }
160 
161 static void rna_def_palette(BlenderRNA *brna)
162 {
163  StructRNA *srna;
164  PropertyRNA *prop;
165 
166  srna = RNA_def_struct(brna, "Palette", "ID");
167  RNA_def_struct_ui_text(srna, "Palette", "");
168  RNA_def_struct_ui_icon(srna, ICON_COLOR);
169 
170  prop = RNA_def_property(srna, "colors", PROP_COLLECTION, PROP_NONE);
171  RNA_def_property_struct_type(prop, "PaletteColor");
172  rna_def_palettecolors(brna, prop);
173 }
174 
176 {
177  /* *** Non-Animated *** */
179  rna_def_palettecolor(brna);
180  rna_def_palette(brna);
182 }
183 
184 #endif
void BKE_palette_color_remove(struct Palette *palette, struct PaletteColor *color)
Definition: paint.c:729
void BKE_palette_clear(struct Palette *palette)
Definition: paint.c:745
struct PaletteColor * BKE_palette_color_add(struct Palette *palette)
Definition: paint.c:757
void BKE_reportf(ReportList *reports, ReportType 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 RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:1425
StructRNA RNA_PaletteColor
@ PARM_RNAPTR
Definition: RNA_types.h:339
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_REPORTS
Definition: RNA_types.h:578
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROP_THICK_WRAP
Definition: RNA_types.h:270
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_COLOR_GAMMA
Definition: RNA_types.h:151
#define NC_SCENE
Definition: WM_types.h:279
#define ND_TOOLSETTINGS
Definition: WM_types.h:349
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
void RNA_define_animate_sdna(bool animate)
Definition: rna_define.c:766
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4159
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1555
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3462
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1757
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
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:3373
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1267
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2515
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
void RNA_def_palette(BlenderRNA *brna)
Definition: rna_palette.c:175
static void rna_def_palette(BlenderRNA *brna)
Definition: rna_palette.c:161
static void rna_def_palettecolor(BlenderRNA *brna)
Definition: rna_palette.c:133
static void rna_def_palettecolors(BlenderRNA *brna, PropertyRNA *cprop)
Definition: rna_palette.c:97
char name[66]
Definition: DNA_ID.h:283
int active_color
ListBase colors
void * data
Definition: RNA_types.h:52
PointerRNA * ptr
Definition: wm_files.c:3157