From fe46d5ba7ac6679121acc08574955b22f7653fc7 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Thu, 27 Aug 2009 06:03:41 +0000 Subject: Grease Pencil: RNA Wrapping * Wrapped Grease Pencil datatypes in RNA. * Hooked up Grease Pencil access in RNA (i.e. via Main, ID, and Scene) TODO: Updates to properties are currently lacking property-update calls, since there's no good notifier for this. --- source/blender/makesrna/intern/makesrna.c | 1 + source/blender/makesrna/intern/rna_ID.c | 1 + source/blender/makesrna/intern/rna_action.c | 20 +- source/blender/makesrna/intern/rna_animation.c | 3 +- source/blender/makesrna/intern/rna_gpencil.c | 242 +++++++++++++++++++++++++ source/blender/makesrna/intern/rna_internal.h | 1 + source/blender/makesrna/intern/rna_main.c | 9 +- source/blender/makesrna/intern/rna_scene.c | 8 + 8 files changed, 272 insertions(+), 13 deletions(-) create mode 100644 source/blender/makesrna/intern/rna_gpencil.c (limited to 'source/blender/makesrna/intern') diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 0c90a28a0e9..bb7b6cbcd37 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1964,6 +1964,7 @@ RNAProcessItem PROCESS_ITEMS[]= { {"rna_curve.c", NULL, RNA_def_curve}, {"rna_fcurve.c", NULL, RNA_def_fcurve}, {"rna_fluidsim.c", NULL, RNA_def_fluidsim}, + {"rna_gpencil.c", NULL, RNA_def_gpencil}, {"rna_group.c", NULL, RNA_def_group}, {"rna_image.c", NULL, RNA_def_image}, {"rna_key.c", NULL, RNA_def_key}, diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index f6e0a2468c4..dd26391b11e 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -97,6 +97,7 @@ StructRNA *ID_code_to_RNA_type(short idcode) case ID_BR: return &RNA_Brush; case ID_CA: return &RNA_Camera; case ID_CU: return &RNA_Curve; + case ID_GD: return &RNA_GreasePencil; case ID_GR: return &RNA_Group; case ID_IM: return &RNA_Image; case ID_KE: return &RNA_Key; diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c index 3639d6d3fff..e376d3125e3 100644 --- a/source/blender/makesrna/intern/rna_action.c +++ b/source/blender/makesrna/intern/rna_action.c @@ -42,15 +42,15 @@ void rna_def_action_group(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - + srna= RNA_def_struct(brna, "ActionGroup", NULL); RNA_def_struct_sdna(srna, "bActionGroup"); RNA_def_struct_ui_text(srna, "Action Group", "Groups of F-Curves."); - + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_ui_text(prop, "Name", ""); RNA_def_struct_name_property(srna, prop); - + /* dna warns not to treat the Action Channel listbase in the Action Group struct like a normal listbase. I'll leave this here but comment out, for Joshua to review. He can probably shed some more light on why this is */ @@ -58,19 +58,19 @@ void rna_def_action_group(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "channels", NULL); RNA_def_property_struct_type(prop, "FCurve"); RNA_def_property_ui_text(prop, "Channels", "F-Curves in this group.");*/ - + prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", AGRP_SELECTED); RNA_def_property_ui_text(prop, "Selected", "Action Group is selected."); - + prop= RNA_def_property(srna, "locked", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", AGRP_PROTECTED); RNA_def_property_ui_text(prop, "Locked", "Action Group is locked."); - + prop= RNA_def_property(srna, "expanded", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", AGRP_EXPANDED); RNA_def_property_ui_text(prop, "Expanded", "Action Group is expanded."); - + prop= RNA_def_property(srna, "custom_color", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "customCol"); RNA_def_property_ui_text(prop, "Custom Color", "Index of custom color set."); @@ -85,17 +85,17 @@ void rna_def_action(BlenderRNA *brna) RNA_def_struct_sdna(srna, "bAction"); RNA_def_struct_ui_text(srna, "Action", "A collection of F-Curves for animation."); RNA_def_struct_ui_icon(srna, ICON_ACTION); - + prop= RNA_def_property(srna, "fcurves", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "curves", NULL); RNA_def_property_struct_type(prop, "FCurve"); RNA_def_property_ui_text(prop, "F-Curves", "The individual F-Curves that make up the Action."); - + prop= RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "groups", NULL); RNA_def_property_struct_type(prop, "ActionGroup"); RNA_def_property_ui_text(prop, "Groups", "Convenient groupings of F-Curves."); - + prop= RNA_def_property(srna, "pose_markers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "markers", NULL); RNA_def_property_struct_type(prop, "TimelineMarker"); diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c index 7652987ac86..e4bea893992 100644 --- a/source/blender/makesrna/intern/rna_animation.c +++ b/source/blender/makesrna/intern/rna_animation.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * Contributor(s): Blender Foundation (2008), Roland Hess + * Contributor(s): Blender Foundation (2009), Joshua Leung * * ***** END GPL LICENSE BLOCK ***** */ @@ -157,7 +157,6 @@ void rna_def_keyingset(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYINGSET_BUILTIN); RNA_def_property_ui_text(prop, "Built-In", "Keying Set is a built-in to Blender."); - /* TODO: for now, this is editable, but do we really want this to happen? */ prop= RNA_def_property(srna, "absolute", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYINGSET_ABSOLUTE); RNA_def_property_ui_text(prop, "Absolute", "Keying Set defines specific paths/settings to be keyframed (i.e. is not reliant on context info)"); diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c new file mode 100644 index 00000000000..2ef7d9d2d90 --- /dev/null +++ b/source/blender/makesrna/intern/rna_gpencil.c @@ -0,0 +1,242 @@ +/** + * $Id: rna_gpencil.c 22756 2009-08-25 04:05:37Z aligorith $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Contributor(s): Blender Foundation (2009), Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include + +#include "RNA_define.h" +#include "RNA_types.h" +#include "RNA_enum_types.h" + +#include "rna_internal.h" + +#include "DNA_gpencil_types.h" +#include "DNA_scene_types.h" + +#include "MEM_guardedalloc.h" + +#ifdef RNA_RUNTIME + +static int rna_GPencilLayer_active_frame_editable(PointerRNA *ptr) +{ + bGPDlayer *gpl= (bGPDlayer *)ptr->data; + + /* surely there must be other criteria too... */ + if (gpl->flag & GP_LAYER_LOCKED) + return 0; + else + return 1; +} + +void rna_GPencilLayer_active_set(PointerRNA *ptr, int value) +{ + bGPdata *gpd= ptr->id.data; + bGPDlayer *gpl= ptr->data; + + /* disabled all other layers anyway */ + if (GS(gpd->id.name) == ID_GD) { + bGPDlayer *gl; + + for (gl= gpd->layers.first; gl; gl= gl->next) + gl->flag &= ~GP_LAYER_ACTIVE; + } + + /* if enabling value, make it active */ + if (value) + gpl->flag |= GP_LAYER_ACTIVE; +} + +#else + +void rna_def_gpencil_stroke_point(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "GPencilStrokePoint", NULL); + RNA_def_struct_sdna(srna, "bGPDspoint"); + RNA_def_struct_ui_text(srna, "Grease Pencil Stroke Point", "Data point for freehand stroke curve."); + + prop= RNA_def_property(srna, "coordinates", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "x"); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Coordinates", ""); + + prop= RNA_def_property(srna, "pressure", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "pressure"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Pressure", "Pressure of tablet at point when drawing it."); +} + +void rna_def_gpencil_stroke(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "GPencilStroke", NULL); + RNA_def_struct_sdna(srna, "bGPDstroke"); + RNA_def_struct_ui_text(srna, "Grease Pencil Stroke", "Freehand curve defining part of a sketch."); + + /* Points */ + prop= RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "points", "totpoints"); + RNA_def_property_struct_type(prop, "GPencilStrokePoint"); + RNA_def_property_ui_text(prop, "Stroke Points", "Stroke data points"); + + /* Flags - Readonly type-info really... */ + // TODO... +} + +void rna_def_gpencil_frame(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "GPencilFrame", NULL); + RNA_def_struct_sdna(srna, "bGPDframe"); + RNA_def_struct_ui_text(srna, "Grease Pencil Frame", "Collection of related sketches on a particular frame"); + + /* Strokes */ + prop= RNA_def_property(srna, "strokes", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "strokes", NULL); + RNA_def_property_struct_type(prop, "GPencilStroke"); + RNA_def_property_ui_text(prop, "Strokes", "Freehand curves defining the sketch on this frame."); + + /* Frame Number */ + prop= RNA_def_property(srna, "frame_number", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "framenum"); + RNA_def_property_range(prop, MINFRAME, MAXFRAME); // XXX note: this cannot occur on the same frame as another sketch + RNA_def_property_ui_text(prop, "Frame Number", "The frame on which this sketch appears."); + + /* Flags */ + prop= RNA_def_property(srna, "paint_lock", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_FRAME_PAINT); // XXX should it be editable? + RNA_def_property_ui_text(prop, "Paint Lock", "Frame is being edited (painted on)."); + + prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_FRAME_SELECT); + RNA_def_property_ui_text(prop, "Selected", "Frame is selected for editing in the DopeSheet."); +} + +void rna_def_gpencil_layer(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "GPencilLayer", NULL); + RNA_def_struct_sdna(srna, "bGPDlayer"); + RNA_def_struct_ui_text(srna, "Grease Pencil Layer", "Collection of related sketches"); + + /* Name */ + prop= RNA_def_property(srna, "info", PROP_STRING, PROP_NONE); + RNA_def_property_ui_text(prop, "Info", "Description of layer"); + RNA_def_struct_name_property(srna, prop); + + /* Frames */ + prop= RNA_def_property(srna, "frames", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "frames", NULL); + RNA_def_property_struct_type(prop, "GPencilFrame"); + RNA_def_property_ui_text(prop, "Frames", "Sketches for this layer on different frames."); + + /* Active Frame */ + prop= RNA_def_property(srna, "active_frame", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "actframe"); + RNA_def_property_ui_text(prop, "Active Frame", "Frame currently being displayed for this layer."); + RNA_def_property_editable_func(prop, "rna_GPencilLayer_active_frame_editable"); + + /* Drawing Color */ + prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Color", "Color that all sketches in this layer are drawn with."); + + prop= RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "color[3]"); + RNA_def_property_range(prop, 0.3, 1.0f); + RNA_def_property_ui_text(prop, "Opacity", "Visibility of strokes."); + + /* Line Thickness */ + prop= RNA_def_property(srna, "line_thickness", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "thickness"); + RNA_def_property_range(prop, 1, 10); + RNA_def_property_ui_text(prop, "Thickness", "Thickness of strokes (in pixels)."); + + /* Onion-Skinning */ + prop= RNA_def_property(srna, "use_onion_skinning", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_ONIONSKIN); + RNA_def_property_ui_text(prop, "Use Onion Skinning", "Ghost frames on either side of frame."); + + prop= RNA_def_property(srna, "max_ghost_range", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "gstep"); + RNA_def_property_range(prop, 0, 120); + 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)"); + + /* Flags */ + prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_HIDE); + RNA_def_property_ui_text(prop, "Hide", "Layer doesn't get drawn."); + + prop= RNA_def_property(srna, "locked", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_LOCKED); + RNA_def_property_ui_text(prop, "Locked", "Layer is protected from further editing and/or frame changes."); + + prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_ACTIVE); + RNA_def_property_boolean_funcs(prop, NULL, "rna_GPencilLayer_active_set"); + RNA_def_property_ui_text(prop, "Active", "Layer is 'active' layer being edited."); + + prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_SELECT); + RNA_def_property_ui_text(prop, "Selected", "Layer is selected for editing in the DopeSheet."); + +} + +void rna_def_gpencil_data(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "GreasePencil", "ID"); + RNA_def_struct_sdna(srna, "bGPdata"); + RNA_def_struct_ui_text(srna, "Grease Pencil", "Freehand annotation sketchbook."); + //RNA_def_struct_ui_icon(srna, ICON_GPENCIL); + + /* Layers */ + prop= RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "layers", NULL); + RNA_def_property_struct_type(prop, "GPencilLayer"); + RNA_def_property_ui_text(prop, "Layers", "Similar to layers in Photoshop."); +} + +/* --- */ + +void RNA_def_gpencil(BlenderRNA *brna) +{ + rna_def_gpencil_data(brna); + + rna_def_gpencil_layer(brna); + rna_def_gpencil_frame(brna); + rna_def_gpencil_stroke(brna); + rna_def_gpencil_stroke_point(brna); +} + +#endif diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index bd28085692f..0a9ef9f90d1 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -130,6 +130,7 @@ void RNA_def_curve(struct BlenderRNA *brna); void RNA_def_fluidsim(struct BlenderRNA *brna); void RNA_def_fcurve(struct BlenderRNA *brna); void RNA_def_gameproperty(struct BlenderRNA *brna); +void RNA_def_gpencil(struct BlenderRNA *brna); void RNA_def_group(struct BlenderRNA *brna); void RNA_def_image(struct BlenderRNA *brna); void RNA_def_key(struct BlenderRNA *brna); diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 4a24027f7e9..82e460ea57d 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -207,6 +207,12 @@ static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA rna_iterator_listbase_begin(iter, &bmain->particle, NULL); } +static void rna_Main_gpencil_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Main *bmain= (Main*)ptr->data; + rna_iterator_listbase_begin(iter, &bmain->gpencil, NULL); +} + static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Main *bmain= (Main*)ptr->data; @@ -240,13 +246,14 @@ void RNA_def_main(BlenderRNA *brna) {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks.", NULL, NULL}, {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks.", NULL, NULL}, {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks.", NULL, NULL}, - {"keys", "ID", "rna_Main_key_begin", "Keys", "Key datablocks.", NULL, NULL}, + {"keys", "Key", "rna_Main_key_begin", "Keys", "Key datablocks.", NULL, NULL}, {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks.", NULL, NULL}, {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks.", NULL, NULL}, {"sounds", "ID", "rna_Main_sound_begin", "Sounds", "Sound datablocks.", NULL, NULL}, {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks.", NULL, NULL}, {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks.", NULL, NULL}, {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks.", NULL, NULL}, + {"gpencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil datablocks.", NULL, NULL}, {NULL, NULL, NULL, NULL, NULL, NULL, NULL}}; int i; diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 86ceee55f47..2408d9337e1 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -2067,6 +2067,14 @@ void RNA_def_scene(BlenderRNA *brna) prop= RNA_def_string(func, "statistics", "", 0, "Statistics", ""); RNA_def_function_return(func, prop); + /* Grease Pencil */ + prop= RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "gpd"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_struct_type(prop, "GreasePencil"); + RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil datablock"); + + /* Nestled Data */ rna_def_tool_settings(brna); rna_def_unit_settings(brna); rna_def_scene_render_data(brna); -- cgit v1.2.3