Blender V4.3
rna_palette.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdlib>
10
11#include "BLI_utildefines.h"
12
13#include "RNA_access.hh"
14#include "RNA_define.hh"
15
16#include "rna_internal.hh"
17
18#include "WM_types.hh"
19
20#ifdef RNA_RUNTIME
21
22# include "DNA_brush_types.h"
23
24# include "BKE_paint.hh"
25# include "BKE_report.hh"
26static PaletteColor *rna_Palette_color_new(Palette *palette)
27{
28 if (!ID_IS_EDITABLE(palette) || ID_IS_OVERRIDE_LIBRARY(palette)) {
29 return nullptr;
30 }
31
32 PaletteColor *color = BKE_palette_color_add(palette);
33 return color;
34}
35
36static void rna_Palette_color_remove(Palette *palette, ReportList *reports, PointerRNA *color_ptr)
37{
38 if (!ID_IS_EDITABLE(palette) || ID_IS_OVERRIDE_LIBRARY(palette)) {
39 return;
40 }
41
42 PaletteColor *color = static_cast<PaletteColor *>(color_ptr->data);
43
44 if (BLI_findindex(&palette->colors, color) == -1) {
46 reports, RPT_ERROR, "Palette '%s' does not contain color given", palette->id.name + 2);
47 return;
48 }
49
50 BKE_palette_color_remove(palette, color);
51
52 RNA_POINTER_INVALIDATE(color_ptr);
53}
54
55static void rna_Palette_color_clear(Palette *palette)
56{
57 if (!ID_IS_EDITABLE(palette) || ID_IS_OVERRIDE_LIBRARY(palette)) {
58 return;
59 }
60
61 BKE_palette_clear(palette);
62}
63
64static PointerRNA rna_Palette_active_color_get(PointerRNA *ptr)
65{
66 Palette *palette = static_cast<Palette *>(ptr->data);
68
69 color = static_cast<PaletteColor *>(BLI_findlink(&palette->colors, palette->active_color));
70
71 if (color) {
72 return rna_pointer_inherit_refine(ptr, &RNA_PaletteColor, color);
73 }
74
75 return rna_pointer_inherit_refine(ptr, nullptr, nullptr);
76}
77
78static void rna_Palette_active_color_set(PointerRNA *ptr,
79 PointerRNA value,
80 ReportList * /*reports*/)
81{
82 Palette *palette = static_cast<Palette *>(ptr->data);
83 const PaletteColor *color = static_cast<const PaletteColor *>(value.data);
84
85 /* -1 is ok for an unset index */
86 if (color == nullptr) {
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 */
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", nullptr);
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", nullptr, nullptr);
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", nullptr);
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, nullptr, "rgb");
145 RNA_def_property_array(prop, 3);
146 RNA_def_property_ui_text(prop, "Color", "");
148
149 prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
150 RNA_def_property_range(prop, 0.0, 1.0);
151 RNA_def_property_float_sdna(prop, nullptr, "value");
152 RNA_def_property_ui_text(prop, "Value", "");
154
155 prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
156 RNA_def_property_range(prop, 0.0, 1.0);
157 RNA_def_property_float_sdna(prop, nullptr, "value");
158 RNA_def_property_ui_text(prop, "Weight", "");
160}
161
162static void rna_def_palette(BlenderRNA *brna)
163{
164 StructRNA *srna;
165 PropertyRNA *prop;
166
167 srna = RNA_def_struct(brna, "Palette", "ID");
168 RNA_def_struct_ui_text(srna, "Palette", "");
169 RNA_def_struct_ui_icon(srna, ICON_COLOR);
170
171 prop = RNA_def_property(srna, "colors", PROP_COLLECTION, PROP_NONE);
172 RNA_def_property_struct_type(prop, "PaletteColor");
173 rna_def_palettecolors(brna, prop);
174}
175
177{
178 /* *** Non-Animated *** */
181 rna_def_palette(brna);
183}
184
185#endif
PaletteColor * BKE_palette_color_add(Palette *palette)
Definition paint.cc:1392
void BKE_palette_color_remove(Palette *palette, PaletteColor *color)
Definition paint.cc:1364
void BKE_palette_clear(Palette *palette)
Definition paint.cc:1380
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:658
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:683
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 Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves 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 Invert a color
#define RNA_POINTER_INVALIDATE(ptr)
ParameterFlag
Definition RNA_types.hh:396
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_LIB_EXCEPTION
Definition RNA_types.hh:213
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:175
#define NC_SCENE
Definition WM_types.hh:345
#define ND_TOOLSETTINGS
Definition WM_types.hh:416
PointerRNA rna_pointer_inherit_refine(const PointerRNA *ptr, StructRNA *type, void *data)
void RNA_define_animate_sdna(bool animate)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_palette(BlenderRNA *brna)
static void rna_def_palette(BlenderRNA *brna)
static void rna_def_palettecolor(BlenderRNA *brna)
static void rna_def_palettecolors(BlenderRNA *brna, PropertyRNA *cprop)
char name[66]
Definition DNA_ID.h:425
ListBase colors
void * data
Definition RNA_types.hh:42
PointerRNA * ptr
Definition wm_files.cc:4126