Blender V5.3
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 "BLI_listbase.hh"
18
19# include "BKE_context.hh"
20# include "BKE_global.hh"
21# include "BKE_scene.hh"
22# include "BKE_screen.hh"
23
24# include "ED_fileselect.hh"
25# include "ED_screen.hh"
26# include "ED_text.hh"
27# include "ED_view3d.hh"
28
29# include "WM_api.hh"
30
31namespace blender {
32
33int rna_object_type_visibility_icon_get_common(int object_type_exclude_viewport,
34 const int *object_type_exclude_select)
35{
36 const int view_value = (object_type_exclude_viewport != 0);
37
38 if (object_type_exclude_select) {
39 /* Ignore selection values when view is off,
40 * intent is to show if visible objects aren't selectable. */
41 const int select_value = (*object_type_exclude_select & ~object_type_exclude_viewport) != 0;
42 return ICON_VIS_SEL_11 + (view_value << 1) + select_value;
43 }
44
45 return view_value ? ICON_HIDE_ON : ICON_HIDE_OFF;
46}
47
48static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d, bContext *C)
49{
50 bScreen *screen = id_cast<bScreen *>(id);
51
52 ScrArea *area;
53 ARegion *region;
54
55 area_region_from_regiondata(screen, rv3d, &area, &region);
56
57 if (area && region && area->spacetype == SPACE_VIEW3D) {
58 Main *bmain = CTX_data_main(C);
59 View3D *v3d = area->spacedata.first_as<View3D>();
61
62 for (wmWindow &win : wm->windows) {
63 if (WM_window_get_active_screen(&win) == screen) {
64 Scene *scene = WM_window_get_active_scene(&win);
66 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
67
68 ED_view3d_update_viewmat(depsgraph, scene, v3d, region, nullptr, nullptr, nullptr, false);
69 break;
70 }
71 }
72 }
73}
74
75static void rna_SpaceTextEditor_region_location_from_cursor(
76 ID *id, SpaceText *st, int line, int column, int r_pixel_pos[2])
77{
78 bScreen *screen = id_cast<bScreen *>(id);
79 ScrArea *area = BKE_screen_find_area_from_space(screen, reinterpret_cast<SpaceLink *>(st));
80 if (area) {
82 const int cursor_co[2] = {line, column};
83 if (!ED_space_text_region_location_from_cursor(st, region, cursor_co, r_pixel_pos)) {
84 r_pixel_pos[0] = r_pixel_pos[1] = -1;
85 }
86 }
87}
88
89static void rna_FileBrowser_deselect_all(SpaceFile *sfile, ReportList *reports)
90{
91 if (sfile->files == nullptr) {
92 /* Likely to happen in background mode.
93 * We could look into initializing this on demand, see: #141547. */
94 BKE_report(reports, RPT_ERROR, "Uninitialized file-list");
95 return;
96 }
98}
99
100} // namespace blender
101
102#else
103
104namespace blender {
105
107{
108 FunctionRNA *func;
109
110 func = RNA_def_function(srna, "update", "rna_RegionView3D_update");
112 RNA_def_function_ui_description(func, "Recalculate the view matrices");
113}
114
116{
117 FunctionRNA *func;
118 PropertyRNA *parm;
119
120 func = RNA_def_function(
121 srna, "cursor_location_from_region", "rna_SpaceNodeEditor_cursor_location_from_region");
122 RNA_def_function_ui_description(func, "Set the cursor location using region coordinates");
124 parm = RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "x", "Region x coordinate", -10000, 10000);
126 parm = RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "y", "Region y coordinate", -10000, 10000);
128}
129
131{
132 FunctionRNA *func;
133 PropertyRNA *parm;
134
135 func = RNA_def_function(
136 srna, "region_location_from_cursor", "rna_SpaceTextEditor_region_location_from_cursor");
138 func, "Retrieve the region position from the given line and character position");
140 parm = RNA_def_int(func, "line", 0, INT_MIN, INT_MAX, "Line", "Line index", 0, INT_MAX);
142 parm = RNA_def_int(func, "column", 0, INT_MIN, INT_MAX, "Column", "Column index", 0, INT_MAX);
144 parm = RNA_def_int_array(
145 func, "result", 2, nullptr, -1, INT_MAX, "", "Region coordinates", -1, INT_MAX);
146 RNA_def_function_output(func, parm);
147}
148
150 int noteflag,
151 const char *update_func)
152{
153 PropertyRNA *prop;
154
155 struct {
156 const char *name;
157 int type_mask;
158 const char *identifier[2];
159 const char *description[2];
160 } info[] = {
161 {"Mesh",
162 (1 << OB_MESH),
163 {"show_object_viewport_mesh", "show_object_select_mesh"},
164 {"Show mesh objects", "Allow selection of mesh objects"}},
165 {"Curve",
166 (1 << OB_CURVES_LEGACY),
167 {"show_object_viewport_curve", "show_object_select_curve"},
168 {"Show curves", "Allow selection of curves"}},
169 {"Surface",
170 (1 << OB_SURF),
171 {"show_object_viewport_surf", "show_object_select_surf"},
172 {"Show surfaces", "Allow selection of surfaces"}},
173 {"Meta",
174 (1 << OB_MBALL),
175 {"show_object_viewport_meta", "show_object_select_meta"},
176 {"Show metaballs", "Allow selection of metaballs"}},
177 {"Font",
178 (1 << OB_FONT),
179 {"show_object_viewport_font", "show_object_select_font"},
180 {"Show text objects", "Allow selection of text objects"}},
181 {"Hair Curves",
182 (1 << OB_CURVES),
183 {"show_object_viewport_curves", "show_object_select_curves"},
184 {"Show hair curves", "Allow selection of hair curves"}},
185 {"Point Cloud",
186 (1 << OB_POINTCLOUD),
187 {"show_object_viewport_pointcloud", "show_object_select_pointcloud"},
188 {"Show point clouds", "Allow selection of point clouds"}},
189 {"Volume",
190 (1 << OB_VOLUME),
191 {"show_object_viewport_volume", "show_object_select_volume"},
192 {"Show volumes", "Allow selection of volumes"}},
193 {"Armature",
194 (1 << OB_ARMATURE),
195 {"show_object_viewport_armature", "show_object_select_armature"},
196 {"Show armatures", "Allow selection of armatures"}},
197 {"Lattice",
198 (1 << OB_LATTICE),
199 {"show_object_viewport_lattice", "show_object_select_lattice"},
200 {"Show lattices", "Allow selection of lattices"}},
201 {"Empty",
202 (1 << OB_EMPTY),
203 {"show_object_viewport_empty", "show_object_select_empty"},
204 {"Show empties", "Allow selection of empties"}},
205 {"Grease Pencil",
206 (1 << OB_GREASE_PENCIL),
207 {"show_object_viewport_grease_pencil", "show_object_select_grease_pencil"},
208 {"Show Grease Pencil objects", "Allow selection of Grease Pencil objects"}},
209 {"Camera",
210 (1 << OB_CAMERA),
211 {"show_object_viewport_camera", "show_object_select_camera"},
212 {"Show cameras", "Allow selection of cameras"}},
213 {"Light",
214 (1 << OB_LAMP),
215 {"show_object_viewport_light", "show_object_select_light"},
216 {"Show lights", "Allow selection of lights"}},
217 {"Speaker",
218 (1 << OB_SPEAKER),
219 {"show_object_viewport_speaker", "show_object_select_speaker"},
220 {"Show speakers", "Allow selection of speakers"}},
221 {"Light Probe",
222 (1 << OB_LIGHTPROBE),
223 {"show_object_viewport_light_probe", "show_object_select_light_probe"},
224 {"Show light probes", "Allow selection of light probes"}},
225 };
226
227 const char *view_mask_member[2] = {
228 "object_type_exclude_viewport",
229 "object_type_exclude_select",
230 };
231 for (int mask_index = 0; mask_index < 2; mask_index++) {
232 for (int type_index = 0; type_index < ARRAY_SIZE(info); type_index++) {
233 prop = RNA_def_property(
234 srna, info[type_index].identifier[mask_index], PROP_BOOLEAN, PROP_NONE);
236 prop, nullptr, view_mask_member[mask_index], info[type_index].type_mask);
238 prop, info[type_index].name, info[type_index].description[mask_index]);
239 RNA_def_property_update(prop, noteflag, update_func);
240 }
241 }
242}
243
245{
246 FunctionRNA *func;
247 PropertyRNA *parm;
248
249 func = RNA_def_function(srna, "activate_asset_by_id", "ED_fileselect_activate_by_id");
251 func, "Activate and select the asset entry that represents the given ID");
252
253 parm = RNA_def_property(func, "id_to_activate", PROP_POINTER, PROP_NONE);
256
257 parm = RNA_def_boolean(
258 func,
259 "deferred",
260 false,
261 "",
262 "Whether to activate the ID immediately (false) or after the file browser refreshes (true)");
263
264 /* Select file by relative path. */
265 func = RNA_def_function(
266 srna, "activate_file_by_relative_path", "ED_fileselect_activate_by_relpath");
268 "Set active file and add to selection based on relative path to "
269 "current File Browser directory");
270 RNA_def_property(func, "relative_path", PROP_STRING, PROP_FILEPATH);
271
272 /* Deselect all files. */
273 func = RNA_def_function(srna, "deselect_all", "rna_FileBrowser_deselect_all");
275 RNA_def_function_ui_description(func, "Deselect all files");
276}
277
278} // namespace blender
279
280#endif
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define INT_MAX
BMesh Iterators.
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_api_region_view3d(StructRNA *srna)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
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)
@ FUNC_USE_REPORTS
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:980
@ FUNC_USE_CONTEXT
void rna_def_object_type_visibility_flags_common(StructRNA *srna, int noteflag, const char *update_func)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
Scene * WM_window_get_active_scene(const wmWindow *win)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
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 BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
wmWindowManager * CTX_wm_manager(const bContext *C)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void RNA_api_space_node(StructRNA *srna)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
bool ED_space_text_region_location_from_cursor(const SpaceText *st, const ARegion *region, const int cursor_co[2], int r_pixel_co[2])
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
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)
Main * CTX_data_main(const bContext *C)
void RNA_api_space_text(StructRNA *srna)
ARegion ARegion ScrArea * BKE_screen_find_area_from_space(const bScreen *screen, const SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
Definition screen.cc:1091
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_update(PropertyRNA *prop, int noteflag, const char *func)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PARM_REQUIRED
Definition RNA_types.hh:631
void ED_fileselect_deselect_all(SpaceFile *sfile)
Definition filesel.cc:649
bScreen * WM_window_get_active_screen(const wmWindow *win)
void RNA_api_space_filebrowser(StructRNA *srna)