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