2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-03-20 14:52:58 +00:00
|
|
|
* ***** 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-03-20 14:52:58 +00:00
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation (2009).
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:20:01 +00:00
|
|
|
/** \file blender/makesrna/intern/rna_context.c
|
|
|
|
* \ingroup RNA
|
|
|
|
*/
|
|
|
|
|
2009-03-20 14:52:58 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "DNA_ID.h"
|
2009-07-15 19:19:43 +00:00
|
|
|
#include "DNA_userdef_types.h"
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
|
2009-03-20 14:52:58 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
2011-11-14 16:05:44 +00:00
|
|
|
#include "rna_internal.h" /* own include */
|
|
|
|
|
2009-08-16 03:40:00 +00:00
|
|
|
#ifdef RNA_RUNTIME
|
|
|
|
|
2009-03-20 14:52:58 +00:00
|
|
|
static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-04-22 18:39:44 +00:00
|
|
|
return rna_pointer_inherit_refine(ptr, &RNA_WindowManager, CTX_wm_manager(C));
|
2009-03-20 14:52:58 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 19:10:14 +00:00
|
|
|
static PointerRNA rna_Context_window_get(PointerRNA *ptr)
|
2009-03-20 14:52:58 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-04-22 18:39:44 +00:00
|
|
|
return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C));
|
2009-06-30 19:10:14 +00:00
|
|
|
}
|
2009-03-20 14:52:58 +00:00
|
|
|
|
|
|
|
static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-04-22 18:39:44 +00:00
|
|
|
return rna_pointer_inherit_refine(ptr, &RNA_Screen, CTX_wm_screen(C));
|
2009-03-20 14:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PointerRNA rna_Context_area_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-06-16 00:52:21 +00:00
|
|
|
PointerRNA newptr;
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_Area, CTX_wm_area(C), &newptr);
|
2009-06-16 00:52:21 +00:00
|
|
|
return newptr;
|
2009-03-20 14:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PointerRNA rna_Context_space_data_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-06-16 00:52:21 +00:00
|
|
|
PointerRNA newptr;
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_Space, CTX_wm_space_data(C), &newptr);
|
2009-06-16 00:52:21 +00:00
|
|
|
return newptr;
|
2009-03-20 14:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PointerRNA rna_Context_region_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-06-16 00:52:21 +00:00
|
|
|
PointerRNA newptr;
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_Region, CTX_wm_region(C), &newptr);
|
2009-06-16 00:52:21 +00:00
|
|
|
return newptr;
|
2009-03-20 14:52:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:54:02 +00:00
|
|
|
static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
|
2009-03-20 14:52:58 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2010-08-06 17:54:02 +00:00
|
|
|
|
|
|
|
/* only exists for one space still, no generic system yet */
|
2012-03-05 23:30:41 +00:00
|
|
|
if (CTX_wm_view3d(C)) {
|
2010-08-06 17:54:02 +00:00
|
|
|
PointerRNA newptr;
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_RegionView3D, CTX_wm_region_data(C), &newptr);
|
2010-08-06 17:54:02 +00:00
|
|
|
return newptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PointerRNA_NULL;
|
|
|
|
}
|
2009-03-20 14:52:58 +00:00
|
|
|
|
|
|
|
static PointerRNA rna_Context_main_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2010-09-02 04:53:05 +00:00
|
|
|
return rna_pointer_inherit_refine(ptr, &RNA_BlendData, CTX_data_main(C));
|
2009-03-20 14:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-03-20 14:52:58 +00:00
|
|
|
return rna_pointer_inherit_refine(ptr, &RNA_Scene, CTX_data_scene(C));
|
|
|
|
}
|
|
|
|
|
2009-07-01 22:25:49 +00:00
|
|
|
static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2012-03-05 23:30:41 +00:00
|
|
|
ptr->id.data = CTX_data_scene(C);
|
2009-07-01 22:25:49 +00:00
|
|
|
return rna_pointer_inherit_refine(ptr, &RNA_ToolSettings, CTX_data_tool_settings(C));
|
|
|
|
}
|
|
|
|
|
2011-10-26 21:30:08 +00:00
|
|
|
static PointerRNA rna_Context_user_preferences_get(PointerRNA *UNUSED(ptr))
|
2009-07-15 19:19:43 +00:00
|
|
|
{
|
|
|
|
PointerRNA newptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &newptr);
|
|
|
|
return newptr;
|
|
|
|
}
|
|
|
|
|
2009-08-16 03:40:00 +00:00
|
|
|
static int rna_Context_mode_get(PointerRNA *ptr)
|
2009-08-15 19:40:09 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
bContext *C = (bContext *)ptr->data;
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_data_mode_enum(C);
|
2009-08-15 19:40:09 +00:00
|
|
|
}
|
|
|
|
|
2009-03-20 14:52:58 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
void RNA_def_context(BlenderRNA *brna)
|
|
|
|
{
|
|
|
|
StructRNA *srna;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-08-16 03:40:00 +00:00
|
|
|
static EnumPropertyItem mode_items[] = {
|
|
|
|
{CTX_MODE_EDIT_MESH, "EDIT_MESH", 0, "Mesh Edit", ""},
|
|
|
|
{CTX_MODE_EDIT_CURVE, "EDIT_CURVE", 0, "Curve Edit", ""},
|
|
|
|
{CTX_MODE_EDIT_SURFACE, "EDIT_SURFACE", 0, "Surface Edit", ""},
|
|
|
|
{CTX_MODE_EDIT_TEXT, "EDIT_TEXT", 0, "Edit Edit", ""},
|
2012-03-05 23:30:41 +00:00
|
|
|
{CTX_MODE_EDIT_ARMATURE, "EDIT_ARMATURE", 0, "Armature Edit", ""}, /* PARSKEL reuse will give issues */
|
2009-08-16 03:40:00 +00:00
|
|
|
{CTX_MODE_EDIT_METABALL, "EDIT_METABALL", 0, "Metaball Edit", ""},
|
|
|
|
{CTX_MODE_EDIT_LATTICE, "EDIT_LATTICE", 0, "Lattice Edit", ""},
|
|
|
|
{CTX_MODE_POSE, "POSE", 0, "Pose ", ""},
|
|
|
|
{CTX_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""},
|
|
|
|
{CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
|
|
|
|
{CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""},
|
|
|
|
{CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""},
|
|
|
|
{CTX_MODE_PARTICLE, "PARTICLE", 0, "Particle", ""},
|
|
|
|
{CTX_MODE_OBJECT, "OBJECT", 0, "Object", ""},
|
2012-05-12 11:01:29 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
2009-08-16 03:40:00 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "Context", NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context");
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
RNA_def_struct_sdna(srna, "bContext");
|
2009-03-20 14:52:58 +00:00
|
|
|
|
|
|
|
/* WM */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "window_manager", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-03-20 14:52:58 +00:00
|
|
|
RNA_def_property_struct_type(prop, "WindowManager");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_manager_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-03-20 14:52:58 +00:00
|
|
|
RNA_def_property_struct_type(prop, "Window");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-03-20 14:52:58 +00:00
|
|
|
RNA_def_property_struct_type(prop, "Screen");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_screen_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "area", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-03-20 14:52:58 +00:00
|
|
|
RNA_def_property_struct_type(prop, "Area");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_area_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "space_data", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-03-20 14:52:58 +00:00
|
|
|
RNA_def_property_struct_type(prop, "Space");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_space_data_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "region", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-03-20 14:52:58 +00:00
|
|
|
RNA_def_property_struct_type(prop, "Region");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_region_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "region_data", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2010-08-06 17:54:02 +00:00
|
|
|
RNA_def_property_struct_type(prop, "RegionView3D");
|
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_region_data_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
|
|
|
/* Data */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2010-09-02 04:53:05 +00:00
|
|
|
RNA_def_property_struct_type(prop, "BlendData");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-03-20 14:52:58 +00:00
|
|
|
RNA_def_property_struct_type(prop, "Scene");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL, NULL);
|
2009-07-01 22:25:49 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
|
2009-07-01 22:25:49 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
|
|
RNA_def_property_struct_type(prop, "ToolSettings");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_tool_settings_get", NULL, NULL, NULL);
|
2009-07-01 22:25:49 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "user_preferences", PROP_POINTER, PROP_NONE);
|
2009-07-15 19:19:43 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
|
|
RNA_def_property_struct_type(prop, "UserPreferences");
|
2010-08-03 05:14:59 +00:00
|
|
|
RNA_def_property_pointer_funcs(prop, "rna_Context_user_preferences_get", NULL, NULL, NULL);
|
2009-08-15 19:40:09 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
|
2009-08-16 03:40:00 +00:00
|
|
|
RNA_def_property_enum_items(prop, mode_items);
|
2009-08-15 19:40:09 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2009-08-16 03:40:00 +00:00
|
|
|
RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", NULL, NULL);
|
2009-03-20 14:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|