Blender V4.5
rna_space_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_object_types.h"
10
11#include "RNA_define.hh"
12
13#include "rna_internal.hh"
14
15#ifdef RNA_RUNTIME
16
17# include "BKE_global.hh"
18
19# include "ED_fileselect.hh"
20# include "ED_screen.hh"
21# include "ED_text.hh"
22
23int rna_object_type_visibility_icon_get_common(int object_type_exclude_viewport,
24 const int *object_type_exclude_select)
25{
26 const int view_value = (object_type_exclude_viewport != 0);
27
28 if (object_type_exclude_select) {
29 /* Ignore selection values when view is off,
30 * intent is to show if visible objects aren't selectable. */
31 const int select_value = (*object_type_exclude_select & ~object_type_exclude_viewport) != 0;
32 return ICON_VIS_SEL_11 + (view_value << 1) + select_value;
33 }
34
35 return view_value ? ICON_HIDE_ON : ICON_HIDE_OFF;
36}
37
38static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d, bContext *C)
39{
40 bScreen *screen = (bScreen *)id;
41
42 ScrArea *area;
43 ARegion *region;
44
45 area_region_from_regiondata(screen, rv3d, &area, &region);
46
47 if (area && region && area->spacetype == SPACE_VIEW3D) {
48 Main *bmain = CTX_data_main(C);
49 View3D *v3d = static_cast<View3D *>(area->spacedata.first);
51
52 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
53 if (WM_window_get_active_screen(win) == screen) {
56 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
57
58 ED_view3d_update_viewmat(depsgraph, scene, v3d, region, nullptr, nullptr, nullptr, false);
59 break;
60 }
61 }
62 }
63}
64
65static void rna_SpaceTextEditor_region_location_from_cursor(
66 ID *id, SpaceText *st, int line, int column, int r_pixel_pos[2])
67{
68 bScreen *screen = (bScreen *)id;
70 if (area) {
72 const int cursor_co[2] = {line, column};
73 if (!ED_space_text_region_location_from_cursor(st, region, cursor_co, r_pixel_pos)) {
74 r_pixel_pos[0] = r_pixel_pos[1] = -1;
75 }
76 }
77}
78
79#else
80
82{
83 FunctionRNA *func;
84
85 func = RNA_def_function(srna, "update", "rna_RegionView3D_update");
87 RNA_def_function_ui_description(func, "Recalculate the view matrices");
88}
89
91{
92 FunctionRNA *func;
93 PropertyRNA *parm;
94
95 func = RNA_def_function(
96 srna, "cursor_location_from_region", "rna_SpaceNodeEditor_cursor_location_from_region");
97 RNA_def_function_ui_description(func, "Set the cursor location using region coordinates");
99 parm = RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "x", "Region x coordinate", -10000, 10000);
101 parm = RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "y", "Region y coordinate", -10000, 10000);
103}
104
106{
107 FunctionRNA *func;
108 PropertyRNA *parm;
109
110 func = RNA_def_function(
111 srna, "region_location_from_cursor", "rna_SpaceTextEditor_region_location_from_cursor");
113 func, "Retrieve the region position from the given line and character position");
115 parm = RNA_def_int(func, "line", 0, INT_MIN, INT_MAX, "Line", "Line index", 0, INT_MAX);
117 parm = RNA_def_int(func, "column", 0, INT_MIN, INT_MAX, "Column", "Column index", 0, INT_MAX);
119 parm = RNA_def_int_array(
120 func, "result", 2, nullptr, -1, INT_MAX, "", "Region coordinates", -1, INT_MAX);
121 RNA_def_function_output(func, parm);
122}
123
125 int noteflag,
126 const char *update_func)
127{
128 PropertyRNA *prop;
129
130 struct {
131 const char *name;
132 int type_mask;
133 const char *identifier[2];
134 const char *description[2];
135 } info[] = {
136 {"Mesh",
137 (1 << OB_MESH),
138 {"show_object_viewport_mesh", "show_object_select_mesh"},
139 {"Show mesh objects", "Allow selection of mesh objects"}},
140 {"Curve",
141 (1 << OB_CURVES_LEGACY),
142 {"show_object_viewport_curve", "show_object_select_curve"},
143 {"Show curves", "Allow selection of curves"}},
144 {"Surface",
145 (1 << OB_SURF),
146 {"show_object_viewport_surf", "show_object_select_surf"},
147 {"Show surfaces", "Allow selection of surfaces"}},
148 {"Meta",
149 (1 << OB_MBALL),
150 {"show_object_viewport_meta", "show_object_select_meta"},
151 {"Show metaballs", "Allow selection of metaballs"}},
152 {"Font",
153 (1 << OB_FONT),
154 {"show_object_viewport_font", "show_object_select_font"},
155 {"Show text objects", "Allow selection of text objects"}},
156 {"Hair Curves",
157 (1 << OB_CURVES),
158 {"show_object_viewport_curves", "show_object_select_curves"},
159 {"Show hair curves", "Allow selection of hair curves"}},
160 {"Point Cloud",
161 (1 << OB_POINTCLOUD),
162 {"show_object_viewport_pointcloud", "show_object_select_pointcloud"},
163 {"Show point clouds", "Allow selection of point clouds"}},
164 {"Volume",
165 (1 << OB_VOLUME),
166 {"show_object_viewport_volume", "show_object_select_volume"},
167 {"Show volumes", "Allow selection of volumes"}},
168 {"Armature",
169 (1 << OB_ARMATURE),
170 {"show_object_viewport_armature", "show_object_select_armature"},
171 {"Show armatures", "Allow selection of armatures"}},
172 {"Lattice",
173 (1 << OB_LATTICE),
174 {"show_object_viewport_lattice", "show_object_select_lattice"},
175 {"Show lattices", "Allow selection of lattices"}},
176 {"Empty",
177 (1 << OB_EMPTY),
178 {"show_object_viewport_empty", "show_object_select_empty"},
179 {"Show empties", "Allow selection of empties"}},
180 {"Grease Pencil",
181 (1 << OB_GREASE_PENCIL),
182 {"show_object_viewport_grease_pencil", "show_object_select_grease_pencil"},
183 {"Show Grease Pencil objects", "Allow selection of Grease Pencil objects"}},
184 {"Camera",
185 (1 << OB_CAMERA),
186 {"show_object_viewport_camera", "show_object_select_camera"},
187 {"Show cameras", "Allow selection of cameras"}},
188 {"Light",
189 (1 << OB_LAMP),
190 {"show_object_viewport_light", "show_object_select_light"},
191 {"Show lights", "Allow selection of lights"}},
192 {"Speaker",
193 (1 << OB_SPEAKER),
194 {"show_object_viewport_speaker", "show_object_select_speaker"},
195 {"Show speakers", "Allow selection of speakers"}},
196 {"Light Probe",
197 (1 << OB_LIGHTPROBE),
198 {"show_object_viewport_light_probe", "show_object_select_light_probe"},
199 {"Show light probes", "Allow selection of light probes"}},
200 };
201
202 const char *view_mask_member[2] = {
203 "object_type_exclude_viewport",
204 "object_type_exclude_select",
205 };
206 for (int mask_index = 0; mask_index < 2; mask_index++) {
207 for (int type_index = 0; type_index < ARRAY_SIZE(info); type_index++) {
208 prop = RNA_def_property(
209 srna, info[type_index].identifier[mask_index], PROP_BOOLEAN, PROP_NONE);
211 prop, nullptr, view_mask_member[mask_index], info[type_index].type_mask);
213 prop, info[type_index].name, info[type_index].description[mask_index]);
214 RNA_def_property_update(prop, noteflag, update_func);
215 }
216 }
217}
218
220{
221 FunctionRNA *func;
222 PropertyRNA *parm;
223
224 func = RNA_def_function(srna, "activate_asset_by_id", "ED_fileselect_activate_by_id");
226 func, "Activate and select the asset entry that represents the given ID");
227
228 parm = RNA_def_property(func, "id_to_activate", PROP_POINTER, PROP_NONE);
231
232 parm = RNA_def_boolean(
233 func,
234 "deferred",
235 false,
236 "",
237 "Whether to activate the ID immediately (false) or after the file browser refreshes (true)");
238
239 /* Select file by relative path. */
240 func = RNA_def_function(
241 srna, "activate_file_by_relative_path", "ED_fileselect_activate_by_relpath");
243 "Set active file and add to selection based on relative path to "
244 "current File Browser directory");
245 RNA_def_property(func, "relative_path", PROP_STRING, PROP_FILEPATH);
246
247 /* Deselect all files. */
248 func = RNA_def_function(srna, "deselect_all", "ED_fileselect_deselect_all");
249 RNA_def_function_ui_description(func, "Deselect all files");
250}
251
252#endif
Main * CTX_data_main(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3427
ARegion ARegion ScrArea * BKE_screen_find_area_from_space(const bScreen *screen, const SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:840
#define LISTBASE_FOREACH(type, var, list)
#define ARRAY_SIZE(arr)
Object is a sort of wrapper for general info.
@ OB_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_LIGHTPROBE
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
bool ED_space_text_region_location_from_cursor(const SpaceText *st, const ARegion *region, const int cursor_co[2], int r_pixel_co[2])
void ED_view3d_update_viewmat(const Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, const float viewmat[4][4], const float winmat[4][4], const rcti *rect, bool offscreen)
@ PARM_REQUIRED
Definition RNA_types.hh:511
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:804
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:792
@ PROP_BOOLEAN
Definition RNA_types.hh:150
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
PropertyFlag
Definition RNA_types.hh:286
@ PROP_NONE
Definition RNA_types.hh:221
@ PROP_FILEPATH
Definition RNA_types.hh:224
#define C
Definition RandGen.cpp:29
BPy_StructRNA * depsgraph
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_function_flag(FunctionRNA *func, int flag)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
int rna_object_type_visibility_icon_get_common(int object_type_exclude_viewport, const int *object_type_exclude_select)
void rna_def_object_type_visibility_flags_common(StructRNA *srna, int noteflag, const char *update_func)
void RNA_api_region_view3d(StructRNA *srna)
void RNA_api_space_filebrowser(StructRNA *srna)
void RNA_api_space_node(StructRNA *srna)
void RNA_api_space_text(StructRNA *srna)
Definition DNA_ID.h:404
void * first
ListBase spacedata
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
Scene * WM_window_get_active_scene(const wmWindow *win)
bScreen * WM_window_get_active_screen(const wmWindow *win)