4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Blender Foundation (2009), Joshua Leung
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_types.h"
29 #include "RNA_enum_types.h"
31 #include "rna_internal.h"
33 #include "DNA_gpencil_types.h"
34 #include "DNA_scene_types.h"
36 #include "MEM_guardedalloc.h"
40 static int rna_GPencilLayer_active_frame_editable(PointerRNA *ptr)
42 bGPDlayer *gpl= (bGPDlayer *)ptr->data;
44 /* surely there must be other criteria too... */
45 if (gpl->flag & GP_LAYER_LOCKED)
51 static void rna_GPencilLayer_active_set(PointerRNA *ptr, int value)
53 bGPdata *gpd= ptr->id.data;
54 bGPDlayer *gpl= ptr->data;
56 /* disabled all other layers anyway */
57 if (GS(gpd->id.name) == ID_GD) {
60 for (gl= gpd->layers.first; gl; gl= gl->next)
61 gl->flag &= ~GP_LAYER_ACTIVE;
64 /* if enabling value, make it active */
66 gpl->flag |= GP_LAYER_ACTIVE;
71 static void rna_def_gpencil_stroke_point(BlenderRNA *brna)
76 srna= RNA_def_struct(brna, "GPencilStrokePoint", NULL);
77 RNA_def_struct_sdna(srna, "bGPDspoint");
78 RNA_def_struct_ui_text(srna, "Grease Pencil Stroke Point", "Data point for freehand stroke curve.");
80 prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_NONE);
81 RNA_def_property_float_sdna(prop, NULL, "x");
82 RNA_def_property_array(prop, 3);
83 RNA_def_property_ui_text(prop, "Coordinates", "");
85 prop= RNA_def_property(srna, "pressure", PROP_FLOAT, PROP_NONE);
86 RNA_def_property_float_sdna(prop, NULL, "pressure");
87 RNA_def_property_range(prop, 0.0f, 1.0f);
88 RNA_def_property_ui_text(prop, "Pressure", "Pressure of tablet at point when drawing it.");
91 static void rna_def_gpencil_stroke(BlenderRNA *brna)
96 srna= RNA_def_struct(brna, "GPencilStroke", NULL);
97 RNA_def_struct_sdna(srna, "bGPDstroke");
98 RNA_def_struct_ui_text(srna, "Grease Pencil Stroke", "Freehand curve defining part of a sketch.");
101 prop= RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
102 RNA_def_property_collection_sdna(prop, NULL, "points", "totpoints");
103 RNA_def_property_struct_type(prop, "GPencilStrokePoint");
104 RNA_def_property_ui_text(prop, "Stroke Points", "Stroke data points");
106 /* Flags - Readonly type-info really... */
110 static void rna_def_gpencil_frame(BlenderRNA *brna)
115 srna= RNA_def_struct(brna, "GPencilFrame", NULL);
116 RNA_def_struct_sdna(srna, "bGPDframe");
117 RNA_def_struct_ui_text(srna, "Grease Pencil Frame", "Collection of related sketches on a particular frame");
120 prop= RNA_def_property(srna, "strokes", PROP_COLLECTION, PROP_NONE);
121 RNA_def_property_collection_sdna(prop, NULL, "strokes", NULL);
122 RNA_def_property_struct_type(prop, "GPencilStroke");
123 RNA_def_property_ui_text(prop, "Strokes", "Freehand curves defining the sketch on this frame.");
126 prop= RNA_def_property(srna, "frame_number", PROP_INT, PROP_NONE);
127 RNA_def_property_int_sdna(prop, NULL, "framenum");
128 RNA_def_property_range(prop, MINFRAME, MAXFRAME); // XXX note: this cannot occur on the same frame as another sketch
129 RNA_def_property_ui_text(prop, "Frame Number", "The frame on which this sketch appears.");
132 prop= RNA_def_property(srna, "paint_lock", PROP_BOOLEAN, PROP_NONE);
133 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_FRAME_PAINT); // XXX should it be editable?
134 RNA_def_property_ui_text(prop, "Paint Lock", "Frame is being edited (painted on).");
136 prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE);
137 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_FRAME_SELECT);
138 RNA_def_property_ui_text(prop, "Selected", "Frame is selected for editing in the DopeSheet.");
141 static void rna_def_gpencil_layer(BlenderRNA *brna)
146 srna= RNA_def_struct(brna, "GPencilLayer", NULL);
147 RNA_def_struct_sdna(srna, "bGPDlayer");
148 RNA_def_struct_ui_text(srna, "Grease Pencil Layer", "Collection of related sketches");
151 prop= RNA_def_property(srna, "info", PROP_STRING, PROP_NONE);
152 RNA_def_property_ui_text(prop, "Info", "Description of layer");
153 RNA_def_struct_name_property(srna, prop);
156 prop= RNA_def_property(srna, "frames", PROP_COLLECTION, PROP_NONE);
157 RNA_def_property_collection_sdna(prop, NULL, "frames", NULL);
158 RNA_def_property_struct_type(prop, "GPencilFrame");
159 RNA_def_property_ui_text(prop, "Frames", "Sketches for this layer on different frames.");
162 prop= RNA_def_property(srna, "active_frame", PROP_POINTER, PROP_NONE);
163 RNA_def_property_pointer_sdna(prop, NULL, "actframe");
164 RNA_def_property_ui_text(prop, "Active Frame", "Frame currently being displayed for this layer.");
165 RNA_def_property_editable_func(prop, "rna_GPencilLayer_active_frame_editable");
168 prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
169 RNA_def_property_array(prop, 3);
170 RNA_def_property_ui_text(prop, "Color", "Color that all sketches in this layer are drawn with.");
172 prop= RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_NONE);
173 RNA_def_property_float_sdna(prop, NULL, "color[3]");
174 RNA_def_property_range(prop, 0.3, 1.0f);
175 RNA_def_property_ui_text(prop, "Opacity", "Visibility of strokes.");
178 prop= RNA_def_property(srna, "line_thickness", PROP_INT, PROP_NONE);
179 RNA_def_property_int_sdna(prop, NULL, "thickness");
180 RNA_def_property_range(prop, 1, 10);
181 RNA_def_property_ui_text(prop, "Thickness", "Thickness of strokes (in pixels).");
184 prop= RNA_def_property(srna, "use_onion_skinning", PROP_BOOLEAN, PROP_NONE);
185 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_ONIONSKIN);
186 RNA_def_property_ui_text(prop, "Use Onion Skinning", "Ghost frames on either side of frame.");
188 prop= RNA_def_property(srna, "max_ghost_range", PROP_INT, PROP_NONE);
189 RNA_def_property_int_sdna(prop, NULL, "gstep");
190 RNA_def_property_range(prop, 0, 120);
191 RNA_def_property_ui_text(prop, "Max Ghost Range", "Maximum number of frames on either side of the active frame to show. (0 = just show the 'first' available sketch on either side)");
194 prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
195 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_HIDE);
196 RNA_def_property_ui_text(prop, "Hide", "Layer doesn't get drawn.");
198 prop= RNA_def_property(srna, "locked", PROP_BOOLEAN, PROP_NONE);
199 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_LOCKED);
200 RNA_def_property_ui_text(prop, "Locked", "Layer is protected from further editing and/or frame changes.");
202 prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
203 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_ACTIVE);
204 RNA_def_property_boolean_funcs(prop, NULL, "rna_GPencilLayer_active_set");
205 RNA_def_property_ui_text(prop, "Active", "Layer is 'active' layer being edited.");
207 prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE);
208 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_SELECT);
209 RNA_def_property_ui_text(prop, "Selected", "Layer is selected for editing in the DopeSheet.");
211 // XXX keep this option?
212 prop= RNA_def_property(srna, "show_points", PROP_BOOLEAN, PROP_NONE);
213 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_DRAWDEBUG);
214 RNA_def_property_ui_text(prop, "Show Points", "Draw the points which make up the strokes (for debugging purposes).");
218 static void rna_def_gpencil_data(BlenderRNA *brna)
223 srna= RNA_def_struct(brna, "GreasePencil", "ID");
224 RNA_def_struct_sdna(srna, "bGPdata");
225 RNA_def_struct_ui_text(srna, "Grease Pencil", "Freehand annotation sketchbook.");
226 RNA_def_struct_ui_icon(srna, ICON_GREASEPENCIL);
229 prop= RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
230 RNA_def_property_collection_sdna(prop, NULL, "layers", NULL);
231 RNA_def_property_struct_type(prop, "GPencilLayer");
232 RNA_def_property_ui_text(prop, "Layers", "Similar to layers in Photoshop.");
235 prop= RNA_def_property(srna, "view_space_draw", PROP_BOOLEAN, PROP_NONE);
236 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GP_DATA_VIEWALIGN);
237 RNA_def_property_ui_text(prop, "Stick to View", "Newly drawn strokes get added in view space (i.e. sketches stick to data when view is manipulated).");
242 void RNA_def_gpencil(BlenderRNA *brna)
244 rna_def_gpencil_data(brna);
246 rna_def_gpencil_layer(brna);
247 rna_def_gpencil_frame(brna);
248 rna_def_gpencil_stroke(brna);
249 rna_def_gpencil_stroke_point(brna);