Blender  V2.59
rna_camera.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_camera.c 37457 2011-06-13 20:21:48Z dingto $
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 (2008).
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_camera_types.h"
00037 
00038 #include "BLI_math.h"
00039 
00040 #include "WM_types.h"
00041 
00042 #ifdef RNA_RUNTIME
00043 
00044 #include "BKE_object.h"
00045 
00046 /* only for rad/deg conversion! can remove later */
00047 static float rna_Camera_angle_get(PointerRNA *ptr)
00048 {
00049         Camera *cam= ptr->id.data;
00050 
00051         return lens_to_angle(cam->lens);
00052 }
00053 
00054 static void rna_Camera_angle_set(PointerRNA *ptr, float value)
00055 {
00056         Camera *cam= ptr->id.data;
00057         cam->lens= angle_to_lens(value);
00058 }
00059 
00060 #else
00061 
00062 void RNA_def_camera(BlenderRNA *brna)
00063 {
00064         StructRNA *srna;
00065         PropertyRNA *prop;
00066         static EnumPropertyItem prop_type_items[] = {
00067                 {CAM_PERSP, "PERSP", 0, "Perspective", ""},
00068                 {CAM_ORTHO, "ORTHO", 0, "Orthographic", ""},
00069                 {0, NULL, 0, NULL, NULL}};
00070         static EnumPropertyItem prop_draw_type_extra_items[] = {
00071                 {CAM_DTX_CENTER, "CENTER", 0, "Center", ""},
00072                 {CAM_DTX_CENTER_DIAG, "CENTER_DIAGONAL", 0, "Center Diagonal", ""},
00073                 {CAM_DTX_THIRDS, "THIRDS", 0, "Thirds", ""},
00074                 {CAM_DTX_GOLDEN, "GOLDEN", 0, "Golden", ""},
00075                 {CAM_DTX_GOLDEN_TRI_A, "GOLDEN_TRIANGLE_A", 0, "Golden Triangle A", ""},
00076                 {CAM_DTX_GOLDEN_TRI_B, "GOLDEN_TRIANGLE_B", 0, "Golden Triangle B", ""},
00077                 {CAM_DTX_HARMONY_TRI_A, "HARMONY_TRIANGLE_A", 0, "Harmonious Triangle A", ""},
00078                 {CAM_DTX_HARMONY_TRI_B, "HARMONY_TRIANGLE_B", 0, "Harmonious Triangle B", ""},
00079                 {0, NULL, 0, NULL, NULL}};
00080         static EnumPropertyItem prop_lens_unit_items[] = {
00081                 {0, "MILLIMETERS", 0, "Millimeters", ""},
00082                 {CAM_ANGLETOGGLE, "DEGREES", 0, "Degrees", ""},
00083                 {0, NULL, 0, NULL, NULL}};
00084 
00085         srna= RNA_def_struct(brna, "Camera", "ID");
00086         RNA_def_struct_ui_text(srna, "Camera", "Camera datablock for storing camera settings");
00087         RNA_def_struct_ui_icon(srna, ICON_CAMERA_DATA);
00088 
00089         /* Enums */
00090         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00091         RNA_def_property_enum_items(prop, prop_type_items);
00092         RNA_def_property_ui_text(prop, "Type", "Camera types");
00093         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00094 
00095         prop= RNA_def_property(srna, "show_guide", PROP_ENUM, PROP_NONE);
00096         RNA_def_property_enum_sdna(prop, NULL, "dtx");
00097         RNA_def_property_enum_items(prop, prop_draw_type_extra_items);
00098         RNA_def_property_flag(prop, PROP_ENUM_FLAG);
00099         RNA_def_property_ui_text(prop, "Composition Guides",  "Draw overlay");
00100         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00101         
00102         /* Number values */
00103 
00104         prop= RNA_def_property(srna, "passepartout_alpha", PROP_FLOAT, PROP_FACTOR);
00105         RNA_def_property_float_sdna(prop, NULL, "passepartalpha");
00106         RNA_def_property_ui_text(prop, "Passepartout Alpha", "Opacity (alpha) of the darkened overlay in Camera view");
00107         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00108 
00109         prop= RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE);
00110         RNA_def_property_float_sdna(prop, NULL, "clipsta");
00111         RNA_def_property_range(prop, 0.001f, FLT_MAX);
00112         RNA_def_property_ui_text(prop, "Clip Start", "Camera near clipping distance");
00113         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00114 
00115         prop= RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE);
00116         RNA_def_property_float_sdna(prop, NULL, "clipend");
00117         RNA_def_property_range(prop, 1.0f, FLT_MAX);
00118         RNA_def_property_ui_text(prop, "Clip End", "Camera far clipping distance");
00119         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00120 
00121         prop= RNA_def_property(srna, "lens", PROP_FLOAT, PROP_NONE);
00122         RNA_def_property_float_sdna(prop, NULL, "lens");
00123         RNA_def_property_range(prop, 1.0f, 5000.0f);
00124         RNA_def_property_ui_text(prop, "Focal Length", "Perspective Camera lens value in millimeters");
00125         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00126         
00127         prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
00128         RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0));
00129         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
00130         RNA_def_property_ui_text(prop, "Angle", "Perspective Camera lens field of view in degrees");
00131         RNA_def_property_float_funcs(prop, "rna_Camera_angle_get", "rna_Camera_angle_set", NULL); /* only for deg/rad conversion */
00132         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00133 
00134         prop= RNA_def_property(srna, "ortho_scale", PROP_FLOAT, PROP_NONE);
00135         RNA_def_property_float_sdna(prop, NULL, "ortho_scale");
00136         RNA_def_property_range(prop, 0.01f, 4000.0f);
00137         RNA_def_property_ui_text(prop, "Orthographic Scale", "Orthographic Camera scale (similar to zoom)");
00138         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00139 
00140         prop= RNA_def_property(srna, "draw_size", PROP_FLOAT, PROP_DISTANCE);
00141         RNA_def_property_float_sdna(prop, NULL, "drawsize");
00142         RNA_def_property_range(prop, 0.01f, 1000.0f);
00143         RNA_def_property_ui_range(prop, 0.01, 100, 1, 2);
00144         RNA_def_property_ui_text(prop, "Draw Size", "Apparent size of the Camera object in the 3D View");
00145         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00146 
00147         prop= RNA_def_property(srna, "shift_x", PROP_FLOAT, PROP_NONE);
00148         RNA_def_property_float_sdna(prop, NULL, "shiftx");
00149         RNA_def_property_range(prop, -10.0f, 10.0f);
00150         RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3);
00151         RNA_def_property_ui_text(prop, "Shift X", "Perspective Camera horizontal shift");
00152         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00153 
00154         prop= RNA_def_property(srna, "shift_y", PROP_FLOAT, PROP_NONE);
00155         RNA_def_property_float_sdna(prop, NULL, "shifty");
00156         RNA_def_property_range(prop, -10.0f, 10.0f);
00157         RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3);
00158         RNA_def_property_ui_text(prop, "Shift Y", "Perspective Camera vertical shift");
00159         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00160 
00161         prop= RNA_def_property(srna, "dof_distance", PROP_FLOAT, PROP_DISTANCE);
00162         RNA_def_property_float_sdna(prop, NULL, "YF_dofdist");
00163         RNA_def_property_range(prop, 0.0f, 5000.0f);
00164         RNA_def_property_ui_text(prop, "DOF Distance", "Distance to the focus point for depth of field");
00165         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00166 
00167         /* flag */
00168         prop= RNA_def_property(srna, "show_limits", PROP_BOOLEAN, PROP_NONE);
00169         RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWLIMITS);
00170         RNA_def_property_ui_text(prop, "Show Limits", "Draw the clipping range and focus point on the camera");
00171         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00172 
00173         prop= RNA_def_property(srna, "show_mist", PROP_BOOLEAN, PROP_NONE);
00174         RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWMIST);
00175         RNA_def_property_ui_text(prop, "Show Mist", "Draw a line from the Camera to indicate the mist area");
00176         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00177 
00178         prop= RNA_def_property(srna, "show_passepartout", PROP_BOOLEAN, PROP_NONE);
00179         RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWPASSEPARTOUT);
00180         RNA_def_property_ui_text(prop, "Show Passepartout", "Show a darkened overlay outside the image area in Camera view");
00181         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00182 
00183         prop= RNA_def_property(srna, "show_title_safe", PROP_BOOLEAN, PROP_NONE);
00184         RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWTITLESAFE);
00185         RNA_def_property_ui_text(prop, "Show Title Safe", "Show indicators for the title safe zone in Camera view");
00186         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00187 
00188         prop= RNA_def_property(srna, "show_name", PROP_BOOLEAN, PROP_NONE);
00189         RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWNAME);
00190         RNA_def_property_ui_text(prop, "Show Name", "Show the active Camera's name in Camera view");
00191         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00192 
00193         prop= RNA_def_property(srna, "lens_unit", PROP_ENUM, PROP_NONE);
00194         RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
00195         RNA_def_property_enum_items(prop, prop_lens_unit_items);
00196         RNA_def_property_ui_text(prop, "Lens Unit", "Unit to edit lens in for the user interface");
00197 
00198         prop= RNA_def_property(srna, "use_panorama", PROP_BOOLEAN, PROP_NONE);
00199         RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_PANORAMA);
00200         RNA_def_property_ui_text(prop, "Panorama", "Render the scene with a cylindrical camera for pseudo-fisheye lens effects");
00201         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00202 
00203         /* pointers */
00204         rna_def_animdata_common(srna);
00205 
00206         prop= RNA_def_property(srna, "dof_object", PROP_POINTER, PROP_NONE);
00207         RNA_def_property_struct_type(prop, "Object");
00208         RNA_def_property_pointer_sdna(prop, NULL, "dof_ob");
00209         RNA_def_property_flag(prop, PROP_EDITABLE);
00210         RNA_def_property_ui_text(prop, "DOF Object", "Use this object to define the depth of field focal point");
00211         RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
00212 }
00213 
00214 #endif
00215