Blender  V2.59
rna_screen.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_screen.c 36782 2011-05-19 15:18:40Z campbellbarton $
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), Nathan Letwory
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include <stdlib.h>
00031 #include <stddef.h>
00032 
00033 #include "RNA_define.h"
00034 #include "RNA_enum_types.h"
00035 
00036 #include "rna_internal.h"
00037 
00038 #include "DNA_screen_types.h"
00039 #include "DNA_scene_types.h"
00040 
00041 EnumPropertyItem region_type_items[] = {
00042         {RGN_TYPE_WINDOW, "WINDOW", 0, "Window", ""},
00043         {RGN_TYPE_HEADER, "HEADER", 0, "Header", ""},
00044         {RGN_TYPE_CHANNELS, "CHANNELS", 0, "Channels", ""},
00045         {RGN_TYPE_TEMPORARY, "TEMPORARY", 0, "Temporary", ""},
00046         {RGN_TYPE_UI, "UI", 0, "UI", ""},
00047         {RGN_TYPE_TOOLS, "TOOLS", 0, "Tools", ""},
00048         {RGN_TYPE_TOOL_PROPS, "TOOL_PROPS", 0, "Tool Properties", ""},
00049         {RGN_TYPE_PREVIEW, "PREVIEW", 0, "Preview", ""},
00050         {0, NULL, 0, NULL, NULL}};
00051 
00052 #include "ED_screen.h"
00053 
00054 #include "WM_api.h"
00055 #include "WM_types.h"
00056 
00057 #ifdef RNA_RUNTIME
00058 
00059 
00060 static void rna_Screen_scene_set(PointerRNA *ptr, PointerRNA value)
00061 {
00062         bScreen *sc= (bScreen*)ptr->data;
00063 
00064         if(value.data == NULL)
00065                 return;
00066 
00067         /* exception: can't set screens inside of area/region handers */
00068         sc->newscene= value.data;
00069 }
00070 
00071 static void rna_Screen_scene_update(bContext *C, PointerRNA *ptr)
00072 {
00073         bScreen *sc= (bScreen*)ptr->data;
00074 
00075         /* exception: can't set screens inside of area/region handers */
00076         if(sc->newscene) {
00077                 WM_event_add_notifier(C, NC_SCENE|ND_SCENEBROWSE, sc->newscene);
00078                 sc->newscene= NULL;
00079         }
00080 }
00081 
00082 static void rna_Screen_redraw_update(Main *bmain, Scene *scene, PointerRNA *ptr)
00083 {
00084         bScreen *screen= (bScreen*)ptr->data;
00085 
00086         /* the settings for this are currently only available from a menu in the TimeLine, hence refresh=SPACE_TIME */
00087         ED_screen_animation_timer_update(screen, screen->redraws_flag, SPACE_TIME);
00088 }
00089 
00090 
00091 static int rna_Screen_is_animation_playing_get(PointerRNA *ptr)
00092 {
00093         bScreen *sc= (bScreen*)ptr->data;
00094         return (sc->animtimer != NULL);
00095 }
00096 
00097 static int rna_Screen_fullscreen_get(PointerRNA *ptr)
00098 {
00099         bScreen *sc= (bScreen*)ptr->data;
00100         return (sc->full != 0);
00101 }
00102 
00103 static void rna_Area_type_set(PointerRNA *ptr, int value)
00104 {
00105         ScrArea *sa= (ScrArea*)ptr->data;
00106         sa->butspacetype= value;
00107 }
00108 
00109 static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
00110 {
00111         ScrArea *sa= (ScrArea*)ptr->data;
00112 
00113         ED_area_newspace(C, sa, sa->butspacetype); /* XXX - this uses the window */
00114         ED_area_tag_redraw(sa);
00115 }
00116 
00117 #else
00118 
00119 /* Area.spaces */
00120 static void rna_def_area_spaces(BlenderRNA *brna, PropertyRNA *cprop)
00121 {
00122         StructRNA *srna;
00123         PropertyRNA *prop;
00124 
00125         RNA_def_property_srna(cprop, "AreaSpaces");
00126         srna= RNA_def_struct(brna, "AreaSpaces", NULL);
00127         RNA_def_struct_sdna(srna, "ScrArea");
00128         RNA_def_struct_ui_text(srna, "Area Spaces", "Collection of spaces");
00129 
00130         prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
00131         RNA_def_property_pointer_sdna(prop, NULL, "spacedata.first");
00132         RNA_def_property_struct_type(prop, "Space");
00133         RNA_def_property_ui_text(prop, "Active Space", "Space currently being displayed in this area");
00134 }
00135 
00136 static void rna_def_area(BlenderRNA *brna)
00137 {
00138         StructRNA *srna;
00139         PropertyRNA *prop;
00140         FunctionRNA *func;
00141 
00142         srna= RNA_def_struct(brna, "Area", NULL);
00143         RNA_def_struct_ui_text(srna, "Area", "Area in a subdivided screen, containing an editor");
00144         RNA_def_struct_sdna(srna, "ScrArea");
00145 
00146         prop= RNA_def_property(srna, "spaces", PROP_COLLECTION, PROP_NONE);
00147         RNA_def_property_collection_sdna(prop, NULL, "spacedata", NULL);
00148         RNA_def_property_struct_type(prop, "Space");
00149         RNA_def_property_ui_text(prop, "Spaces", "Spaces contained in this area, the first being the active space. NOTE: Useful for example to restore a previously used 3d view space in a certain area to get the old view orientation.");
00150         rna_def_area_spaces(brna, prop);
00151 
00152         prop= RNA_def_property(srna, "regions", PROP_COLLECTION, PROP_NONE);
00153         RNA_def_property_collection_sdna(prop, NULL, "regionbase", NULL);
00154         RNA_def_property_struct_type(prop, "Region");
00155         RNA_def_property_ui_text(prop, "Regions", "Regions this area is subdivided in");
00156 
00157         prop= RNA_def_property(srna, "show_menus", PROP_BOOLEAN, PROP_NONE);
00158         RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", HEADER_NO_PULLDOWN);
00159         RNA_def_property_ui_text(prop, "Show Menus", "Show menus in the header");
00160 
00161         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00162         RNA_def_property_enum_sdna(prop, NULL, "spacetype");
00163         RNA_def_property_enum_items(prop, space_type_items);
00164         RNA_def_property_enum_funcs(prop, NULL, "rna_Area_type_set", NULL);
00165         RNA_def_property_ui_text(prop, "Type", "Space type");
00166         RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
00167         RNA_def_property_update(prop, 0, "rna_Area_type_update");
00168 
00169         prop= RNA_def_property(srna, "width", PROP_INT, PROP_UNSIGNED);
00170         RNA_def_property_int_sdna(prop, NULL, "winx");
00171         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00172         RNA_def_property_ui_text(prop, "Width", "Area width");
00173 
00174         prop= RNA_def_property(srna, "height", PROP_INT, PROP_UNSIGNED);
00175         RNA_def_property_int_sdna(prop, NULL, "winy");
00176         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00177         RNA_def_property_ui_text(prop, "Height", "Area height");
00178 
00179         RNA_def_function(srna, "tag_redraw", "ED_area_tag_redraw");
00180 
00181         func= RNA_def_function(srna, "header_text_set", "ED_area_headerprint");
00182         RNA_def_function_ui_description(func, "Set the header text");
00183         RNA_def_string(func, "text", NULL, 0, "Text", "New string for the header, no argument clears the text.");
00184 }
00185 
00186 static void rna_def_region(BlenderRNA *brna)
00187 {
00188         StructRNA *srna;
00189         PropertyRNA *prop;
00190 
00191         srna= RNA_def_struct(brna, "Region", NULL);
00192         RNA_def_struct_ui_text(srna, "Region", "Region in a subdivided screen area");
00193         RNA_def_struct_sdna(srna, "ARegion");
00194 
00195         prop= RNA_def_property(srna, "id", PROP_INT, PROP_NONE);
00196         RNA_def_property_int_sdna(prop, NULL, "swinid");
00197         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00198         RNA_def_property_ui_text(prop, "Region ID", "Unique ID for this region");
00199 
00200         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00201         RNA_def_property_enum_sdna(prop, NULL, "regiontype");
00202         RNA_def_property_enum_items(prop, region_type_items);
00203         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00204         RNA_def_property_ui_text(prop, "Region Type", "Type of this region");
00205 
00206         prop= RNA_def_property(srna, "width", PROP_INT, PROP_UNSIGNED);
00207         RNA_def_property_int_sdna(prop, NULL, "winx");
00208         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00209         RNA_def_property_ui_text(prop, "Width", "Region width");
00210 
00211         prop= RNA_def_property(srna, "height", PROP_INT, PROP_UNSIGNED);
00212         RNA_def_property_int_sdna(prop, NULL, "winy");
00213         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00214         RNA_def_property_ui_text(prop, "Height", "Region height");
00215 
00216         RNA_def_function(srna, "tag_redraw", "ED_region_tag_redraw");
00217 }
00218 
00219 static void rna_def_screen(BlenderRNA *brna)
00220 {
00221         StructRNA *srna;
00222         PropertyRNA *prop;
00223 
00224         srna= RNA_def_struct(brna, "Screen", "ID");
00225         RNA_def_struct_sdna(srna, "Screen"); /* it is actually bScreen but for 2.5 the dna is patched! */
00226         RNA_def_struct_ui_text(srna, "Screen", "Screen datablock, defining the layout of areas in a window");
00227         RNA_def_struct_ui_icon(srna, ICON_SPLITSCREEN);
00228 
00229         /* pointers */
00230         prop= RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
00231         RNA_def_property_flag(prop, PROP_EDITABLE|PROP_NEVER_NULL);
00232         RNA_def_property_pointer_funcs(prop, NULL, "rna_Screen_scene_set", NULL, NULL);
00233         RNA_def_property_ui_text(prop, "Scene", "Active scene to be edited in the screen");
00234         RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
00235         RNA_def_property_update(prop, 0, "rna_Screen_scene_update");
00236 
00237         /* collections */
00238         prop= RNA_def_property(srna, "areas", PROP_COLLECTION, PROP_NONE);
00239         RNA_def_property_collection_sdna(prop, NULL, "areabase", NULL);
00240         RNA_def_property_struct_type(prop, "Area");
00241         RNA_def_property_ui_text(prop, "Areas", "Areas the screen is subdivided into");
00242 
00243         /* readonly status indicators */
00244         prop= RNA_def_property(srna, "is_animation_playing", PROP_BOOLEAN, PROP_NONE);
00245         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00246         RNA_def_property_boolean_funcs(prop, "rna_Screen_is_animation_playing_get", NULL);
00247         RNA_def_property_ui_text(prop, "Animation Playing", "Animation playback is active");
00248 
00249         prop= RNA_def_property(srna, "show_fullscreen", PROP_BOOLEAN, PROP_NONE);
00250         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00251         RNA_def_property_boolean_funcs(prop, "rna_Screen_fullscreen_get", NULL);
00252         RNA_def_property_ui_text(prop, "Fullscreen", "An area is maximised, filling this screen");
00253 
00254         /* Define Anim Playback Areas */
00255         prop= RNA_def_property(srna, "use_play_top_left_3d_editor", PROP_BOOLEAN, PROP_NONE);
00256         RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_REGION);
00257         RNA_def_property_ui_text(prop, "Top-Left 3D Editor", "");
00258         RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TIME, "rna_Screen_redraw_update");
00259 
00260         prop= RNA_def_property(srna, "use_play_3d_editors", PROP_BOOLEAN, PROP_NONE);
00261         RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_3D_WIN);
00262         RNA_def_property_ui_text(prop, "All 3D View Editors", "");
00263         RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TIME, "rna_Screen_redraw_update");
00264 
00265         prop= RNA_def_property(srna, "use_play_animation_editors", PROP_BOOLEAN, PROP_NONE);
00266         RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_ANIM_WIN);
00267         RNA_def_property_ui_text(prop, "Animation Editors", "");
00268         RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TIME, "rna_Screen_redraw_update");
00269 
00270         prop= RNA_def_property(srna, "use_play_properties_editors", PROP_BOOLEAN, PROP_NONE);
00271         RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_BUTS_WIN);
00272         RNA_def_property_ui_text(prop, "Property Editors", "");
00273         RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TIME, "rna_Screen_redraw_update");
00274 
00275         prop= RNA_def_property(srna, "use_play_image_editors", PROP_BOOLEAN, PROP_NONE);
00276         RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_IMAGE_WIN);
00277         RNA_def_property_ui_text(prop, "Image Editors", "");
00278         RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TIME, "rna_Screen_redraw_update");
00279 
00280         prop= RNA_def_property(srna, "use_play_sequence_editors", PROP_BOOLEAN, PROP_NONE);
00281         RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_SEQ);
00282         RNA_def_property_ui_text(prop, "Sequencer Editors", "");
00283         RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TIME, "rna_Screen_redraw_update");
00284 
00285         prop= RNA_def_property(srna, "use_play_node_editors", PROP_BOOLEAN, PROP_NONE);
00286         RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_NODES);
00287         RNA_def_property_ui_text(prop, "Node Editors", "");
00288         RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TIME, "rna_Screen_redraw_update");
00289 }
00290 
00291 void RNA_def_screen(BlenderRNA *brna)
00292 {
00293         rna_def_screen(brna);
00294         rna_def_area(brna);
00295         rna_def_region(brna);
00296 }
00297 
00298 #endif
00299