2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation (2008), Nathan Letwory
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_screen.c
31 #include "RNA_define.h"
32 #include "RNA_enum_types.h"
34 #include "rna_internal.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_scene_types.h"
39 EnumPropertyItem region_type_items[] = {
40 {RGN_TYPE_WINDOW, "WINDOW", 0, "Window", ""},
41 {RGN_TYPE_HEADER, "HEADER", 0, "Header", ""},
42 {RGN_TYPE_CHANNELS, "CHANNELS", 0, "Channels", ""},
43 {RGN_TYPE_TEMPORARY, "TEMPORARY", 0, "Temporary", ""},
44 {RGN_TYPE_UI, "UI", 0, "UI", ""},
45 {RGN_TYPE_TOOLS, "TOOLS", 0, "Tools", ""},
46 {RGN_TYPE_TOOL_PROPS, "TOOL_PROPS", 0, "Tool Properties", ""},
47 {RGN_TYPE_PREVIEW, "PREVIEW", 0, "Preview", ""},
48 {0, NULL, 0, NULL, NULL}
51 #include "ED_screen.h"
58 #include "BKE_global.h"
59 #include "BKE_depsgraph.h"
61 #include "UI_view2d.h"
64 # include "BPY_extern.h"
67 static void rna_Screen_scene_set(PointerRNA *ptr, PointerRNA value)
69 bScreen *sc = (bScreen *)ptr->data;
71 if (value.data == NULL)
74 sc->newscene = value.data;
77 static void rna_Screen_scene_update(bContext *C, PointerRNA *ptr)
79 bScreen *sc = (bScreen *)ptr->data;
81 /* exception: must use context so notifier gets to the right window */
84 BPy_BEGIN_ALLOW_THREADS;
87 ED_screen_set_scene(C, sc, sc->newscene);
90 BPy_END_ALLOW_THREADS;
93 WM_event_add_notifier(C, NC_SCENE | ND_SCENEBROWSE, sc->newscene);
95 if (G.debug & G_DEBUG)
96 printf("scene set %p\n", sc->newscene);
102 static void rna_Screen_redraw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
104 bScreen *screen = (bScreen *)ptr->data;
106 /* the settings for this are currently only available from a menu in the TimeLine, hence refresh=SPACE_TIME */
107 ED_screen_animation_timer_update(screen, screen->redraws_flag, SPACE_TIME);
111 static int rna_Screen_is_animation_playing_get(PointerRNA *UNUSED(ptr))
113 /* can be NULL on file load, T42619 */
114 wmWindowManager *wm = G.main->wm.first;
115 return wm ? (ED_screen_animation_playing(wm) != NULL) : 0;
118 static int rna_Screen_fullscreen_get(PointerRNA *ptr)
120 bScreen *sc = (bScreen *)ptr->data;
121 return (sc->state == SCREENMAXIMIZED);
124 /* UI compatible list: should not be needed, but for now we need to keep EMPTY
125 * at least in the static version of this enum for python scripts. */
126 static EnumPropertyItem *rna_Area_type_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr),
127 PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
129 /* +1 to skip SPACE_EMPTY */
130 return space_type_items + 1;
133 static int rna_Area_type_get(PointerRNA *ptr)
135 ScrArea *sa = (ScrArea *)ptr->data;
136 /* read from this instead of 'spacetype' for correct reporting: T41435 */
137 return sa->butspacetype;
140 static void rna_Area_type_set(PointerRNA *ptr, int value)
142 ScrArea *sa = (ScrArea *)ptr->data;
143 sa->butspacetype = value;
146 static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
148 wmWindowManager *wm = CTX_wm_manager(C);
150 bScreen *sc = (bScreen *)ptr->id.data;
151 ScrArea *sa = (ScrArea *)ptr->data;
153 /* XXX this call still use context, so we trick it to work in the right context */
154 for (win = wm->windows.first; win; win = win->next) {
155 if (sc == win->screen) {
156 wmWindow *prevwin = CTX_wm_window(C);
157 ScrArea *prevsa = CTX_wm_area(C);
158 ARegion *prevar = CTX_wm_region(C);
160 CTX_wm_window_set(C, win);
161 CTX_wm_area_set(C, sa);
162 CTX_wm_region_set(C, NULL);
164 ED_area_newspace(C, sa, sa->butspacetype);
165 ED_area_tag_redraw(sa);
167 /* It is possible that new layers becomes visible. */
168 if (sa->spacetype == SPACE_VIEW3D) {
169 DAG_on_visible_update(CTX_data_main(C), false);
172 CTX_wm_window_set(C, prevwin);
173 CTX_wm_area_set(C, prevsa);
174 CTX_wm_region_set(C, prevar);
180 static void rna_View2D_region_to_view(struct View2D *v2d, int x, int y, float result[2])
182 UI_view2d_region_to_view(v2d, x, y, &result[0], &result[1]);
185 static void rna_View2D_view_to_region(struct View2D *v2d, float x, float y, int clip, int result[2])
188 UI_view2d_view_to_region_clip(v2d, x, y, &result[0], &result[1]);
190 UI_view2d_view_to_region(v2d, x, y, &result[0], &result[1]);
196 static void rna_def_area_spaces(BlenderRNA *brna, PropertyRNA *cprop)
201 RNA_def_property_srna(cprop, "AreaSpaces");
202 srna = RNA_def_struct(brna, "AreaSpaces", NULL);
203 RNA_def_struct_sdna(srna, "ScrArea");
204 RNA_def_struct_ui_text(srna, "Area Spaces", "Collection of spaces");
206 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
207 RNA_def_property_pointer_sdna(prop, NULL, "spacedata.first");
208 RNA_def_property_struct_type(prop, "Space");
209 RNA_def_property_ui_text(prop, "Active Space", "Space currently being displayed in this area");
212 static void rna_def_area(BlenderRNA *brna)
218 srna = RNA_def_struct(brna, "Area", NULL);
219 RNA_def_struct_ui_text(srna, "Area", "Area in a subdivided screen, containing an editor");
220 RNA_def_struct_sdna(srna, "ScrArea");
222 prop = RNA_def_property(srna, "spaces", PROP_COLLECTION, PROP_NONE);
223 RNA_def_property_collection_sdna(prop, NULL, "spacedata", NULL);
224 RNA_def_property_struct_type(prop, "Space");
225 RNA_def_property_ui_text(prop, "Spaces",
226 "Spaces contained in this area, the first being the active space "
227 "(NOTE: Useful for example to restore a previously used 3D view space "
228 "in a certain area to get the old view orientation)");
229 rna_def_area_spaces(brna, prop);
231 prop = RNA_def_property(srna, "regions", PROP_COLLECTION, PROP_NONE);
232 RNA_def_property_collection_sdna(prop, NULL, "regionbase", NULL);
233 RNA_def_property_struct_type(prop, "Region");
234 RNA_def_property_ui_text(prop, "Regions", "Regions this area is subdivided in");
236 prop = RNA_def_property(srna, "show_menus", PROP_BOOLEAN, PROP_NONE);
237 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", HEADER_NO_PULLDOWN);
238 RNA_def_property_ui_text(prop, "Show Menus", "Show menus in the header");
240 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
241 RNA_def_property_enum_sdna(prop, NULL, "spacetype");
242 RNA_def_property_enum_items(prop, space_type_items);
243 RNA_def_property_enum_default(prop, SPACE_VIEW3D);
244 RNA_def_property_enum_funcs(prop, "rna_Area_type_get", "rna_Area_type_set", "rna_Area_type_itemf");
245 RNA_def_property_ui_text(prop, "Editor Type", "Current editor type for this area");
246 RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
247 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
248 RNA_def_property_update(prop, 0, "rna_Area_type_update");
250 prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
251 RNA_def_property_int_sdna(prop, NULL, "totrct.xmin");
252 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
253 RNA_def_property_ui_text(prop, "X Position", "The window relative vertical location of the area");
255 prop = RNA_def_property(srna, "y", PROP_INT, PROP_NONE);
256 RNA_def_property_int_sdna(prop, NULL, "totrct.ymin");
257 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
258 RNA_def_property_ui_text(prop, "Y Position", "The window relative horizontal location of the area");
260 prop = RNA_def_property(srna, "width", PROP_INT, PROP_UNSIGNED);
261 RNA_def_property_int_sdna(prop, NULL, "winx");
262 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
263 RNA_def_property_ui_text(prop, "Width", "Area width");
265 prop = RNA_def_property(srna, "height", PROP_INT, PROP_UNSIGNED);
266 RNA_def_property_int_sdna(prop, NULL, "winy");
267 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
268 RNA_def_property_ui_text(prop, "Height", "Area height");
270 RNA_def_function(srna, "tag_redraw", "ED_area_tag_redraw");
272 func = RNA_def_function(srna, "header_text_set", "ED_area_headerprint");
273 RNA_def_function_ui_description(func, "Set the header text");
274 RNA_def_string(func, "text", NULL, 0, "Text", "New string for the header, no argument clears the text");
277 static void rna_def_view2d_api(StructRNA *srna)
282 static const float view_default[2] = {0.0f, 0.0f};
283 static const int region_default[2] = {0.0f, 0.0f};
285 func = RNA_def_function(srna, "region_to_view", "rna_View2D_region_to_view");
286 RNA_def_function_ui_description(func, "Transform region coordinates to 2D view");
287 parm = RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "x", "Region x coordinate", -10000, 10000);
288 RNA_def_property_flag(parm, PROP_REQUIRED);
289 parm = RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "y", "Region y coordinate", -10000, 10000);
290 RNA_def_property_flag(parm, PROP_REQUIRED);
291 parm = RNA_def_float_array(func, "result", 2, view_default, -FLT_MAX, FLT_MAX, "Result", "View coordinates", -10000.0f, 10000.0f);
292 RNA_def_property_flag(parm, PROP_THICK_WRAP);
293 RNA_def_function_output(func, parm);
295 func = RNA_def_function(srna, "view_to_region", "rna_View2D_view_to_region");
296 RNA_def_function_ui_description(func, "Transform 2D view coordinates to region");
297 parm = RNA_def_float(func, "x", 0.0f, -FLT_MAX, FLT_MAX, "x", "2D View x coordinate", -10000.0f, 10000.0f);
298 RNA_def_property_flag(parm, PROP_REQUIRED);
299 parm = RNA_def_float(func, "y", 0.0f, -FLT_MAX, FLT_MAX, "y", "2D View y coordinate", -10000.0f, 10000.0f);
300 RNA_def_property_flag(parm, PROP_REQUIRED);
301 RNA_def_boolean(func, "clip", 1, "Clip", "Clip coordinates to the visible region");
302 parm = RNA_def_int_array(func, "result", 2, region_default, INT_MIN, INT_MAX, "Result", "Region coordinates", -10000, 10000);
303 RNA_def_property_flag(parm, PROP_THICK_WRAP);
304 RNA_def_function_output(func, parm);
307 static void rna_def_view2d(BlenderRNA *brna)
310 /* PropertyRNA *prop; */
312 srna = RNA_def_struct(brna, "View2D", NULL);
313 RNA_def_struct_ui_text(srna, "View2D", "Scroll and zoom for a 2D region");
314 RNA_def_struct_sdna(srna, "View2D");
316 /* TODO more View2D properties could be exposed here (read-only) */
318 rna_def_view2d_api(srna);
321 static void rna_def_region(BlenderRNA *brna)
326 srna = RNA_def_struct(brna, "Region", NULL);
327 RNA_def_struct_ui_text(srna, "Region", "Region in a subdivided screen area");
328 RNA_def_struct_sdna(srna, "ARegion");
330 prop = RNA_def_property(srna, "id", PROP_INT, PROP_NONE);
331 RNA_def_property_int_sdna(prop, NULL, "swinid");
332 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
333 RNA_def_property_ui_text(prop, "Region ID", "Unique ID for this region");
335 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
336 RNA_def_property_enum_sdna(prop, NULL, "regiontype");
337 RNA_def_property_enum_items(prop, region_type_items);
338 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
339 RNA_def_property_ui_text(prop, "Region Type", "Type of this region");
341 prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
342 RNA_def_property_int_sdna(prop, NULL, "winrct.xmin");
343 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
344 RNA_def_property_ui_text(prop, "X Position", "The window relative vertical location of the region");
346 prop = RNA_def_property(srna, "y", PROP_INT, PROP_NONE);
347 RNA_def_property_int_sdna(prop, NULL, "winrct.ymin");
348 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
349 RNA_def_property_ui_text(prop, "Y Position", "The window relative horizontal location of the region");
351 prop = RNA_def_property(srna, "width", PROP_INT, PROP_UNSIGNED);
352 RNA_def_property_int_sdna(prop, NULL, "winx");
353 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
354 RNA_def_property_ui_text(prop, "Width", "Region width");
356 prop = RNA_def_property(srna, "height", PROP_INT, PROP_UNSIGNED);
357 RNA_def_property_int_sdna(prop, NULL, "winy");
358 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
359 RNA_def_property_ui_text(prop, "Height", "Region height");
361 prop = RNA_def_property(srna, "view2d", PROP_POINTER, PROP_NONE);
362 RNA_def_property_pointer_sdna(prop, NULL, "v2d");
363 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
364 RNA_def_property_flag(prop, PROP_NEVER_NULL);
365 RNA_def_property_ui_text(prop, "View2D", "2D view of the region");
367 RNA_def_function(srna, "tag_redraw", "ED_region_tag_redraw");
370 static void rna_def_screen(BlenderRNA *brna)
375 srna = RNA_def_struct(brna, "Screen", "ID");
376 RNA_def_struct_sdna(srna, "Screen"); /* it is actually bScreen but for 2.5 the dna is patched! */
377 RNA_def_struct_ui_text(srna, "Screen", "Screen datablock, defining the layout of areas in a window");
378 RNA_def_struct_ui_icon(srna, ICON_SPLITSCREEN);
381 prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
382 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
383 RNA_def_property_pointer_funcs(prop, NULL, "rna_Screen_scene_set", NULL, NULL);
384 RNA_def_property_ui_text(prop, "Scene", "Active scene to be edited in the screen");
385 RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
386 RNA_def_property_update(prop, 0, "rna_Screen_scene_update");
389 prop = RNA_def_property(srna, "areas", PROP_COLLECTION, PROP_NONE);
390 RNA_def_property_collection_sdna(prop, NULL, "areabase", NULL);
391 RNA_def_property_struct_type(prop, "Area");
392 RNA_def_property_ui_text(prop, "Areas", "Areas the screen is subdivided into");
394 /* readonly status indicators */
395 prop = RNA_def_property(srna, "is_animation_playing", PROP_BOOLEAN, PROP_NONE);
396 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
397 RNA_def_property_boolean_funcs(prop, "rna_Screen_is_animation_playing_get", NULL);
398 RNA_def_property_ui_text(prop, "Animation Playing", "Animation playback is active");
400 prop = RNA_def_property(srna, "show_fullscreen", PROP_BOOLEAN, PROP_NONE);
401 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
402 RNA_def_property_boolean_funcs(prop, "rna_Screen_fullscreen_get", NULL);
403 RNA_def_property_ui_text(prop, "Maximize", "An area is maximized, filling this screen");
405 /* Define Anim Playback Areas */
406 prop = RNA_def_property(srna, "use_play_top_left_3d_editor", PROP_BOOLEAN, PROP_NONE);
407 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_REGION);
408 RNA_def_property_ui_text(prop, "Top-Left 3D Editor", "");
409 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
411 prop = RNA_def_property(srna, "use_play_3d_editors", PROP_BOOLEAN, PROP_NONE);
412 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_3D_WIN);
413 RNA_def_property_ui_text(prop, "All 3D View Editors", "");
414 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
416 prop = RNA_def_property(srna, "use_follow", PROP_BOOLEAN, PROP_NONE);
417 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_FOLLOW);
418 RNA_def_property_ui_text(prop, "Follow", "Follow current frame in editors that update");
419 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
421 prop = RNA_def_property(srna, "use_play_animation_editors", PROP_BOOLEAN, PROP_NONE);
422 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_ANIM_WIN);
423 RNA_def_property_ui_text(prop, "Animation Editors", "");
424 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
426 prop = RNA_def_property(srna, "use_play_properties_editors", PROP_BOOLEAN, PROP_NONE);
427 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_BUTS_WIN);
428 RNA_def_property_ui_text(prop, "Property Editors", "");
429 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
431 prop = RNA_def_property(srna, "use_play_image_editors", PROP_BOOLEAN, PROP_NONE);
432 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_ALL_IMAGE_WIN);
433 RNA_def_property_ui_text(prop, "Image Editors", "");
434 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
436 prop = RNA_def_property(srna, "use_play_sequence_editors", PROP_BOOLEAN, PROP_NONE);
437 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_SEQ);
438 RNA_def_property_ui_text(prop, "Sequencer Editors", "");
439 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
441 prop = RNA_def_property(srna, "use_play_node_editors", PROP_BOOLEAN, PROP_NONE);
442 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_NODES);
443 RNA_def_property_ui_text(prop, "Node Editors", "");
444 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
446 prop = RNA_def_property(srna, "use_play_clip_editors", PROP_BOOLEAN, PROP_NONE);
447 RNA_def_property_boolean_sdna(prop, NULL, "redraws_flag", TIME_CLIPS);
448 RNA_def_property_ui_text(prop, "Clip Editors", "");
449 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, "rna_Screen_redraw_update");
452 void RNA_def_screen(BlenderRNA *brna)
454 rna_def_screen(brna);
456 rna_def_region(brna);
457 rna_def_view2d(brna);