Blender  V2.93
rna_space_api.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "RNA_access.h"
22 #include "RNA_define.h"
23 
24 #include "rna_internal.h"
25 
26 #ifdef RNA_RUNTIME
27 
28 # include "BKE_global.h"
29 
30 # include "ED_fileselect.h"
31 # include "ED_screen.h"
32 # include "ED_text.h"
33 
34 static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d, bContext *C)
35 {
36  bScreen *screen = (bScreen *)id;
37 
38  ScrArea *area;
39  ARegion *region;
40 
41  area_region_from_regiondata(screen, rv3d, &area, &region);
42 
43  if (area && region && area->spacetype == SPACE_VIEW3D) {
44  Main *bmain = CTX_data_main(C);
45  View3D *v3d = area->spacedata.first;
47  wmWindow *win;
48 
49  for (win = wm->windows.first; win; win = win->next) {
50  if (WM_window_get_active_screen(win) == screen) {
52  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
53  Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
54 
55  ED_view3d_update_viewmat(depsgraph, scene, v3d, region, NULL, NULL, NULL, false);
56  break;
57  }
58  }
59  }
60 }
61 
62 static void rna_SpaceTextEditor_region_location_from_cursor(
63  ID *id, SpaceText *st, int line, int column, int r_pixel_pos[2])
64 {
65  bScreen *screen = (bScreen *)id;
67  if (area) {
69  const int cursor_co[2] = {line, column};
70  ED_text_region_location_from_cursor(st, region, cursor_co, r_pixel_pos);
71  }
72 }
73 
74 #else
75 
77 {
78  FunctionRNA *func;
79 
80  func = RNA_def_function(srna, "update", "rna_RegionView3D_update");
82  RNA_def_function_ui_description(func, "Recalculate the view matrices");
83 }
84 
86 {
87  FunctionRNA *func;
88  PropertyRNA *parm;
89 
90  func = RNA_def_function(
91  srna, "cursor_location_from_region", "rna_SpaceNodeEditor_cursor_location_from_region");
92  RNA_def_function_ui_description(func, "Set the cursor location using region coordinates");
94  parm = RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "x", "Region x coordinate", -10000, 10000);
96  parm = RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "y", "Region y coordinate", -10000, 10000);
98 }
99 
101 {
102  FunctionRNA *func;
103  PropertyRNA *parm;
104 
105  func = RNA_def_function(
106  srna, "region_location_from_cursor", "rna_SpaceTextEditor_region_location_from_cursor");
108  func, "Retrieve the region position from the given line and character position");
110  parm = RNA_def_int(func, "line", 0, INT_MIN, INT_MAX, "Line", "Line index", 0, INT_MAX);
112  parm = RNA_def_int(func, "column", 0, INT_MIN, INT_MAX, "Column", "Column index", 0, INT_MAX);
114  parm = RNA_def_int_array(
115  func, "result", 2, NULL, -1, INT_MAX, "", "Region coordinates", -1, INT_MAX);
116  RNA_def_function_output(func, parm);
117 }
118 
120 {
121  FunctionRNA *func;
122  PropertyRNA *parm;
123 
124  func = RNA_def_function(srna, "activate_asset_by_id", "ED_fileselect_activate_by_id");
125  RNA_def_function_ui_description(func, "Activate the asset entry that represents the given ID");
126 
127  parm = RNA_def_property(func, "id_to_activate", PROP_POINTER, PROP_NONE);
128  RNA_def_property_struct_type(parm, "ID");
130 
131  parm = RNA_def_boolean(
132  func,
133  "deferred",
134  0,
135  "",
136  "Whether to activate the ID immediately (false) or after the file browser refreshes (true)");
137 }
138 
139 #endif
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct Depsgraph * BKE_scene_ensure_depsgraph(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer)
Definition: scene.c:3526
struct ARegion * BKE_area_find_region_type(const struct ScrArea *area, int type)
struct ScrArea * BKE_screen_find_area_from_space(struct bScreen *screen, struct SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
bool ED_text_region_location_from_cursor(struct SpaceText *st, struct ARegion *region, const int cursor_co[2], int r_pixel_co[2])
void ED_view3d_update_viewmat(struct Depsgraph *depsgraph, const struct Scene *scene, struct View3D *v3d, struct ARegion *region, const float viewmat[4][4], const float winmat[4][4], const struct rcti *rect, bool offscreen)
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_CONTEXT
Definition: RNA_types.h:577
@ FUNC_USE_SELF_ID
Definition: RNA_types.h:565
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_NONE
Definition: RNA_types.h:113
#define C
Definition: RandGen.cpp:39
Scene scene
const Depsgraph * depsgraph
static void area(int d1, int d2, int e1, int e2, float weights[2])
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3643
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
Definition: rna_define.c:4327
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
void RNA_api_region_view3d(StructRNA *srna)
Definition: rna_space_api.c:76
void RNA_api_space_filebrowser(StructRNA *srna)
void RNA_api_space_node(StructRNA *srna)
Definition: rna_space_api.c:85
void RNA_api_space_text(StructRNA *srna)
Definition: DNA_ID.h:273
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct wmWindow * next
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2372
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
Definition: wm_window.c:2286
Scene * WM_window_get_active_scene(const wmWindow *win)
Definition: wm_window.c:2249