Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributor(s): Blender Foundation (2009), Joshua Leung 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 #include <stdlib.h> 00029 00030 #include "RNA_define.h" 00031 00032 #include "rna_internal.h" 00033 00034 #include "DNA_gpencil_types.h" 00035 #include "DNA_scene_types.h" 00036 00037 #include "MEM_guardedalloc.h" 00038 00039 #include "WM_types.h" 00040 00041 #ifdef RNA_RUNTIME 00042 00043 static int rna_GPencilLayer_active_frame_editable(PointerRNA *ptr) 00044 { 00045 bGPDlayer *gpl= (bGPDlayer *)ptr->data; 00046 00047 /* surely there must be other criteria too... */ 00048 if (gpl->flag & GP_LAYER_LOCKED) 00049 return 0; 00050 else 00051 return 1; 00052 } 00053 00054 static PointerRNA rna_GPencil_active_layer_get(PointerRNA *ptr) 00055 { 00056 bGPdata *gpd= ptr->id.data; 00057 00058 if (GS(gpd->id.name) == ID_GD) { /* why would this ever be not GD */ 00059 bGPDlayer *gl; 00060 00061 for (gl= gpd->layers.first; gl; gl= gl->next) { 00062 if(gl->flag & GP_LAYER_ACTIVE) { 00063 break; 00064 } 00065 } 00066 00067 if(gl) { 00068 return rna_pointer_inherit_refine(ptr, &RNA_GPencilLayer, gl); 00069 } 00070 } 00071 00072 return rna_pointer_inherit_refine(ptr, NULL, NULL); 00073 } 00074 00075 static void rna_GPencil_active_layer_set(PointerRNA *ptr, PointerRNA value) 00076 { 00077 bGPdata *gpd= ptr->id.data; 00078 00079 if (GS(gpd->id.name) == ID_GD) { /* why would this ever be not GD */ 00080 bGPDlayer *gl; 00081 00082 for (gl= gpd->layers.first; gl; gl= gl->next) { 00083 if(gl == value.data) { 00084 gl->flag |= GP_LAYER_ACTIVE; 00085 } 00086 else { 00087 gl->flag &= ~GP_LAYER_ACTIVE; 00088 } 00089 } 00090 } 00091 } 00092 00093 void rna_GPencilLayer_info_set(PointerRNA *ptr, const char *value) 00094 { 00095 bGPdata *gpd= ptr->id.data; 00096 bGPDlayer *gpl= ptr->data; 00097 00098 /* copy the new name into the name slot */ 00099 BLI_strncpy_utf8(gpl->info, value, sizeof(gpl->info)); 00100 00101 BLI_uniquename(&gpd->layers, gpl, "GP_Layer", '.', offsetof(bGPDlayer, info), sizeof(gpl->info)); 00102 } 00103 00104 #else 00105 00106 static void rna_def_gpencil_stroke_point(BlenderRNA *brna) 00107 { 00108 StructRNA *srna; 00109 PropertyRNA *prop; 00110 00111 srna= RNA_def_struct(brna, "GPencilStrokePoint", NULL); 00112 RNA_def_struct_sdna(srna, "bGPDspoint"); 00113 RNA_def_struct_ui_text(srna, "Grease Pencil Stroke Point", "Data point for freehand stroke curve"); 00114 00115 prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ); 00116 RNA_def_property_float_sdna(prop, NULL, "x"); 00117 RNA_def_property_array(prop, 3); 00118 RNA_def_property_ui_text(prop, "Coordinates", ""); 00119 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00120 00121 prop= RNA_def_property(srna, "pressure", PROP_FLOAT, PROP_NONE); 00122 RNA_def_property_float_sdna(prop, NULL, "pressure"); 00123 RNA_def_property_range(prop, 0.0f, 1.0f); 00124 RNA_def_property_ui_text(prop, "Pressure", "Pressure of tablet at point when drawing it"); 00125 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00126 } 00127 00128 static void rna_def_gpencil_stroke(BlenderRNA *brna) 00129 { 00130 StructRNA *srna; 00131 PropertyRNA *prop; 00132 00133 srna= RNA_def_struct(brna, "GPencilStroke", NULL); 00134 RNA_def_struct_sdna(srna, "bGPDstroke"); 00135 RNA_def_struct_ui_text(srna, "Grease Pencil Stroke", "Freehand curve defining part of a sketch"); 00136 00137 /* Points */ 00138 prop= RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); 00139 RNA_def_property_collection_sdna(prop, NULL, "points", "totpoints"); 00140 RNA_def_property_struct_type(prop, "GPencilStrokePoint"); 00141 RNA_def_property_ui_text(prop, "Stroke Points", "Stroke data points"); 00142 00143 /* Flags - Readonly type-info really... */ 00144 // TODO... 00145 } 00146 00147 static void rna_def_gpencil_frame(BlenderRNA *brna) 00148 { 00149 StructRNA *srna; 00150 PropertyRNA *prop; 00151 00152 srna= RNA_def_struct(brna, "GPencilFrame", NULL); 00153 RNA_def_struct_sdna(srna, "bGPDframe"); 00154 RNA_def_struct_ui_text(srna, "Grease Pencil Frame", "Collection of related sketches on a particular frame"); 00155 00156 /* Strokes */ 00157 prop= RNA_def_property(srna, "strokes", PROP_COLLECTION, PROP_NONE); 00158 RNA_def_property_collection_sdna(prop, NULL, "strokes", NULL); 00159 RNA_def_property_struct_type(prop, "GPencilStroke"); 00160 RNA_def_property_ui_text(prop, "Strokes", "Freehand curves defining the sketch on this frame"); 00161 00162 /* Frame Number */ 00163 prop= RNA_def_property(srna, "frame_number", PROP_INT, PROP_NONE); 00164 RNA_def_property_int_sdna(prop, NULL, "framenum"); 00165 RNA_def_property_range(prop, MINFRAME, MAXFRAME); // XXX note: this cannot occur on the same frame as another sketch 00166 RNA_def_property_ui_text(prop, "Frame Number", "The frame on which this sketch appears"); 00167 00168 /* Flags */ 00169 prop= RNA_def_property(srna, "is_edited", PROP_BOOLEAN, PROP_NONE); 00170 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_FRAME_PAINT); // XXX should it be editable? 00171 RNA_def_property_ui_text(prop, "Paint Lock", "Frame is being edited (painted on)"); 00172 00173 prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE); 00174 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_FRAME_SELECT); 00175 RNA_def_property_ui_text(prop, "Select", "Frame is selected for editing in the DopeSheet"); 00176 } 00177 00178 static void rna_def_gpencil_layer(BlenderRNA *brna) 00179 { 00180 StructRNA *srna; 00181 PropertyRNA *prop; 00182 00183 srna= RNA_def_struct(brna, "GPencilLayer", NULL); 00184 RNA_def_struct_sdna(srna, "bGPDlayer"); 00185 RNA_def_struct_ui_text(srna, "Grease Pencil Layer", "Collection of related sketches"); 00186 00187 /* Name */ 00188 prop= RNA_def_property(srna, "info", PROP_STRING, PROP_NONE); 00189 RNA_def_property_ui_text(prop, "Info", "Layer name"); 00190 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GPencilLayer_info_set"); 00191 RNA_def_struct_name_property(srna, prop); 00192 00193 /* Frames */ 00194 prop= RNA_def_property(srna, "frames", PROP_COLLECTION, PROP_NONE); 00195 RNA_def_property_collection_sdna(prop, NULL, "frames", NULL); 00196 RNA_def_property_struct_type(prop, "GPencilFrame"); 00197 RNA_def_property_ui_text(prop, "Frames", "Sketches for this layer on different frames"); 00198 00199 /* Active Frame */ 00200 prop= RNA_def_property(srna, "active_frame", PROP_POINTER, PROP_NONE); 00201 RNA_def_property_pointer_sdna(prop, NULL, "actframe"); 00202 RNA_def_property_ui_text(prop, "Active Frame", "Frame currently being displayed for this layer"); 00203 RNA_def_property_editable_func(prop, "rna_GPencilLayer_active_frame_editable"); 00204 00205 /* Drawing Color */ 00206 prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); 00207 RNA_def_property_array(prop, 3); 00208 RNA_def_property_range(prop, 0.0f, 1.0f); 00209 RNA_def_property_ui_text(prop, "Color", "Color for all strokes in this layer"); 00210 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00211 00212 prop= RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE); 00213 RNA_def_property_float_sdna(prop, NULL, "color[3]"); 00214 RNA_def_property_range(prop, 0.3, 1.0f); 00215 RNA_def_property_ui_text(prop, "Opacity", "Layer Opacity"); 00216 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00217 00218 /* Line Thickness */ 00219 prop= RNA_def_property(srna, "line_width", PROP_INT, PROP_NONE); 00220 RNA_def_property_int_sdna(prop, NULL, "thickness"); 00221 RNA_def_property_range(prop, 1, 10); 00222 RNA_def_property_ui_text(prop, "Thickness", "Thickness of strokes (in pixels)"); 00223 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00224 00225 /* Onion-Skinning */ 00226 prop= RNA_def_property(srna, "use_onion_skinning", PROP_BOOLEAN, PROP_NONE); 00227 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_ONIONSKIN); 00228 RNA_def_property_ui_text(prop, "Use Onion Skinning", "Ghost frames on either side of frame"); 00229 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00230 00231 prop= RNA_def_property(srna, "ghost_range_max", PROP_INT, PROP_NONE); 00232 RNA_def_property_int_sdna(prop, NULL, "gstep"); 00233 RNA_def_property_range(prop, 0, 120); 00234 RNA_def_property_ui_text(prop, "Max Ghost Range", "Maximum number of frames on either side of the active frame to show (0 = show the 'first' available sketch on either side)"); 00235 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00236 00237 /* Flags */ 00238 prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); 00239 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_HIDE); 00240 RNA_def_property_ui_text(prop, "Hide", "Set layer Visibility"); 00241 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00242 00243 prop= RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE); 00244 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_LOCKED); 00245 RNA_def_property_ui_text(prop, "Locked", "Protect layer from further editing and/or frame changes"); 00246 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00247 00248 prop= RNA_def_property(srna, "lock_frame", PROP_BOOLEAN, PROP_NONE); 00249 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_FRAMELOCK); 00250 RNA_def_property_ui_text(prop, "Frame Locked", "Lock current frame displayed by layer"); 00251 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00252 00253 /* expose as layers.active */ 00254 /* 00255 prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE); 00256 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_ACTIVE); 00257 RNA_def_property_boolean_funcs(prop, NULL, "rna_GPencilLayer_active_set"); 00258 RNA_def_property_ui_text(prop, "Active", "Set active layer for editing"); 00259 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00260 */ 00261 00262 prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE); 00263 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_SELECT); 00264 RNA_def_property_ui_text(prop, "Select", "Layer is selected for editing in the DopeSheet"); 00265 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00266 00267 // XXX keep this option? 00268 prop= RNA_def_property(srna, "show_points", PROP_BOOLEAN, PROP_NONE); 00269 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_DRAWDEBUG); 00270 RNA_def_property_ui_text(prop, "Show Points", "Draw the points which make up the strokes (for debugging purposes)"); 00271 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00272 00273 /* X-Ray */ 00274 prop= RNA_def_property(srna, "show_x_ray", PROP_BOOLEAN, PROP_NONE); 00275 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GP_LAYER_NO_XRAY); 00276 RNA_def_property_ui_text(prop, "X Ray", ""); 00277 RNA_def_property_update(prop, NC_SCREEN|ND_GPENCIL, NULL); 00278 } 00279 00280 static void rna_def_gpencil_layers(BlenderRNA *brna, PropertyRNA *cprop) 00281 { 00282 StructRNA *srna; 00283 PropertyRNA *prop; 00284 00285 // FunctionRNA *func; 00286 // PropertyRNA *parm; 00287 00288 RNA_def_property_srna(cprop, "GreasePencilLayers"); 00289 srna= RNA_def_struct(brna, "GreasePencilLayers", NULL); 00290 RNA_def_struct_sdna(srna, "bGPdata"); 00291 RNA_def_struct_ui_text(srna, "Grease Pencil Layers", "Collection of grease pencil layers"); 00292 00293 #if 0 00294 func= RNA_def_function(srna, "new", "rna_GPencil_layer_new"); 00295 RNA_def_function_ui_description(func, "Add a new spline to the curve"); 00296 parm= RNA_def_enum(func, "type", curve_type_items, CU_POLY, "", "type for the new spline"); 00297 RNA_def_property_flag(parm, PROP_REQUIRED); 00298 parm= RNA_def_pointer(func, "spline", "Spline", "", "The newly created spline"); 00299 RNA_def_function_return(func, parm); 00300 00301 func= RNA_def_function(srna, "remove", "rna_GPencil_layer_remove"); 00302 RNA_def_function_ui_description(func, "Remove a spline from a curve"); 00303 RNA_def_function_flag(func, FUNC_USE_REPORTS); 00304 parm= RNA_def_pointer(func, "spline", "Spline", "", "The spline to remove"); 00305 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); 00306 #endif 00307 00308 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); 00309 RNA_def_property_struct_type(prop, "GreasePencil"); 00310 RNA_def_property_pointer_funcs(prop, "rna_GPencil_active_layer_get", "rna_GPencil_active_layer_set", NULL, NULL); 00311 RNA_def_property_flag(prop, PROP_EDITABLE); 00312 RNA_def_property_ui_text(prop, "Active Layer", "Active grease pencil layer"); 00313 } 00314 00315 static void rna_def_gpencil_data(BlenderRNA *brna) 00316 { 00317 StructRNA *srna; 00318 PropertyRNA *prop; 00319 00320 static EnumPropertyItem draw_mode_items[] = { 00321 {GP_DATA_VIEWALIGN, "CURSOR", 0, "Cursor", "Draw stroke at the 3D cursor"}, 00322 {0, "VIEW", 0, "View", "Stick stroke to the view "}, /* weird, GP_DATA_VIEWALIGN is inverted */ 00323 {GP_DATA_VIEWALIGN|GP_DATA_DEPTH_VIEW, "SURFACE", 0, "Surface", "Stick stroke to surfaces"}, 00324 {GP_DATA_VIEWALIGN|GP_DATA_DEPTH_STROKE, "STROKE", 0, "Stroke", "Stick stroke to other strokes"}, 00325 {0, NULL, 0, NULL, NULL}}; 00326 00327 srna= RNA_def_struct(brna, "GreasePencil", "ID"); 00328 RNA_def_struct_sdna(srna, "bGPdata"); 00329 RNA_def_struct_ui_text(srna, "Grease Pencil", "Freehand annotation sketchbook"); 00330 RNA_def_struct_ui_icon(srna, ICON_GREASEPENCIL); 00331 00332 /* Layers */ 00333 prop= RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE); 00334 RNA_def_property_collection_sdna(prop, NULL, "layers", NULL); 00335 RNA_def_property_struct_type(prop, "GPencilLayer"); 00336 RNA_def_property_ui_text(prop, "Layers", ""); 00337 rna_def_gpencil_layers(brna, prop); 00338 00339 /* Flags */ 00340 prop= RNA_def_property(srna, "draw_mode", PROP_ENUM, PROP_NONE); 00341 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag"); 00342 RNA_def_property_enum_items(prop, draw_mode_items); 00343 RNA_def_property_ui_text(prop, "Draw Mode", ""); 00344 00345 prop= RNA_def_property(srna, "use_stroke_endpoints", PROP_BOOLEAN, PROP_NONE); 00346 RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_DEPTH_STROKE_ENDPOINTS); 00347 RNA_def_property_ui_text(prop, "Only Endpoints", "Only use the first and last parts of the stroke for snapping"); 00348 00349 00350 } 00351 00352 /* --- */ 00353 00354 void RNA_def_gpencil(BlenderRNA *brna) 00355 { 00356 rna_def_gpencil_data(brna); 00357 00358 rna_def_gpencil_layer(brna); 00359 rna_def_gpencil_frame(brna); 00360 rna_def_gpencil_stroke(brna); 00361 rna_def_gpencil_stroke_point(brna); 00362 } 00363 00364 #endif