UI: ignore events in empty region overlap areas
[blender.git] / source / blender / editors / include / ED_screen.h
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  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup editors
22  */
23
24 #ifndef __ED_SCREEN_H__
25 #define __ED_SCREEN_H__
26
27 #include "DNA_screen_types.h"
28 #include "DNA_space_types.h"
29 #include "DNA_view2d_types.h"
30 #include "DNA_view3d_types.h"
31 #include "DNA_workspace_types.h"
32
33 #include "DNA_object_enums.h"
34
35 #include "BLI_compiler_attrs.h"
36
37 struct ARegion;
38 struct Depsgraph;
39 struct IDProperty;
40 struct Main;
41 struct MenuType;
42 struct PropertyRNA;
43 struct Scene;
44 struct SpaceLink;
45 struct ViewLayer;
46 struct WorkSpace;
47 struct WorkSpaceInstanceHook;
48 struct bContext;
49 struct bScreen;
50 struct rcti;
51 struct uiBlock;
52 struct uiLayout;
53 struct wmEvent;
54 struct wmKeyConfig;
55 struct wmMsgBus;
56 struct wmMsgSubscribeKey;
57 struct wmMsgSubscribeValue;
58 struct wmNotifier;
59 struct wmOperatorType;
60 struct wmWindow;
61 struct wmWindowManager;
62
63 /* regions */
64 void ED_region_do_listen(struct wmWindow *win,
65                          struct ScrArea *sa,
66                          struct ARegion *ar,
67                          struct wmNotifier *note,
68                          const Scene *scene);
69 void ED_region_do_layout(struct bContext *C, struct ARegion *ar);
70 void ED_region_do_draw(struct bContext *C, struct ARegion *ar);
71 void ED_region_exit(struct bContext *C, struct ARegion *ar);
72 void ED_region_pixelspace(struct ARegion *ar);
73 void ED_region_update_rect(struct ARegion *ar);
74 void ED_region_init(struct ARegion *ar);
75 void ED_region_tag_redraw(struct ARegion *ar);
76 void ED_region_tag_redraw_partial(struct ARegion *ar, const struct rcti *rct);
77 void ED_region_tag_redraw_overlay(struct ARegion *ar);
78 void ED_region_tag_redraw_no_rebuild(struct ARegion *ar);
79 void ED_region_tag_refresh_ui(struct ARegion *ar);
80
81 void ED_region_panels_init(struct wmWindowManager *wm, struct ARegion *ar);
82 void ED_region_panels_ex(const struct bContext *C,
83                          struct ARegion *ar,
84                          const char *contexts[],
85                          int contextnr,
86                          const bool vertical);
87 void ED_region_panels(const struct bContext *C, struct ARegion *ar);
88 void ED_region_panels_layout_ex(const struct bContext *C,
89                                 struct ARegion *ar,
90                                 const char *contexts[],
91                                 int contextnr,
92                                 const bool vertical);
93 void ED_region_panels_layout(const struct bContext *C, struct ARegion *ar);
94 void ED_region_panels_draw(const struct bContext *C, struct ARegion *ar);
95
96 void ED_region_header_init(struct ARegion *ar);
97 void ED_region_header(const struct bContext *C, struct ARegion *ar);
98 void ED_region_header_layout(const struct bContext *C, struct ARegion *ar);
99 void ED_region_header_draw(const struct bContext *C, struct ARegion *ar);
100
101 void ED_region_cursor_set(struct wmWindow *win, struct ScrArea *sa, struct ARegion *ar);
102 void ED_region_toggle_hidden(struct bContext *C, struct ARegion *ar);
103 void ED_region_visibility_change_update(struct bContext *C,
104                                         struct ScrArea *sa,
105                                         struct ARegion *ar);
106 /* screen_ops.c */
107 void ED_region_visibility_change_update_animated(struct bContext *C,
108                                                  struct ScrArea *sa,
109                                                  struct ARegion *ar);
110
111 void ED_region_info_draw(struct ARegion *ar,
112                          const char *text,
113                          float fill_color[4],
114                          const bool full_redraw);
115 void ED_region_info_draw_multiline(ARegion *ar,
116                                    const char *text_array[],
117                                    float fill_color[4],
118                                    const bool full_redraw);
119 void ED_region_image_metadata_draw(
120     int x, int y, struct ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy);
121 void ED_region_image_metadata_panel_draw(struct ImBuf *ibuf, struct uiLayout *layout);
122 void ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy);
123 float ED_region_blend_alpha(struct ARegion *ar);
124 void ED_region_visible_rect(struct ARegion *ar, struct rcti *rect);
125 bool ED_region_is_overlap(int spacetype, int regiontype);
126
127 int ED_region_snap_size_test(const struct ARegion *ar);
128 bool ED_region_snap_size_apply(struct ARegion *ar, int snap_flag);
129
130 /* message_bus callbacks */
131 void ED_region_do_msg_notify_tag_redraw(struct bContext *C,
132                                         struct wmMsgSubscribeKey *msg_key,
133                                         struct wmMsgSubscribeValue *msg_val);
134 void ED_area_do_msg_notify_tag_refresh(struct bContext *C,
135                                        struct wmMsgSubscribeKey *msg_key,
136                                        struct wmMsgSubscribeValue *msg_val);
137
138 void ED_area_do_mgs_subscribe_for_tool_header(const struct bContext *C,
139                                               struct WorkSpace *workspace,
140                                               struct Scene *scene,
141                                               struct bScreen *screen,
142                                               struct ScrArea *sa,
143                                               struct ARegion *ar,
144                                               struct wmMsgBus *mbus);
145
146 /* message bus */
147 void ED_region_message_subscribe(struct bContext *C,
148                                  struct WorkSpace *workspace,
149                                  struct Scene *scene,
150                                  struct bScreen *screen,
151                                  struct ScrArea *sa,
152                                  struct ARegion *ar,
153                                  struct wmMsgBus *mbus);
154
155 /* spaces */
156 void ED_spacetypes_keymap(struct wmKeyConfig *keyconf);
157 int ED_area_header_switchbutton(const struct bContext *C, struct uiBlock *block, int yco);
158
159 /* areas */
160 void ED_area_initialize(struct wmWindowManager *wm, struct wmWindow *win, struct ScrArea *sa);
161 void ED_area_exit(struct bContext *C, struct ScrArea *sa);
162 int ED_screen_area_active(const struct bContext *C);
163 void ED_screen_global_areas_refresh(struct wmWindow *win);
164 void ED_screen_global_areas_sync(struct wmWindow *win);
165 void ED_area_do_listen(struct wmWindow *win, ScrArea *sa, struct wmNotifier *note, Scene *scene);
166 void ED_area_tag_redraw(ScrArea *sa);
167 void ED_area_tag_redraw_no_rebuild(ScrArea *sa);
168 void ED_area_tag_redraw_regiontype(ScrArea *sa, int type);
169 void ED_area_tag_refresh(ScrArea *sa);
170 void ED_area_do_refresh(struct bContext *C, ScrArea *sa);
171 struct AZone *ED_area_azones_update(ScrArea *sa, const int mouse_xy[]);
172 void ED_area_status_text(ScrArea *sa, const char *str);
173 void ED_area_newspace(struct bContext *C, ScrArea *sa, int type, const bool skip_ar_exit);
174 void ED_area_prevspace(struct bContext *C, ScrArea *sa);
175 void ED_area_swapspace(struct bContext *C, ScrArea *sa1, ScrArea *sa2);
176 int ED_area_headersize(void);
177 int ED_area_header_alignment_or_fallback(const ScrArea *area, int fallback);
178 int ED_area_header_alignment(const ScrArea *area);
179 int ED_area_footersize(void);
180 int ED_area_footer_alignment_or_fallback(const ScrArea *area, int fallback);
181 int ED_area_footer_alignment(const ScrArea *area);
182 int ED_area_global_size_y(const ScrArea *area);
183 int ED_area_global_min_size_y(const ScrArea *area);
184 int ED_area_global_max_size_y(const ScrArea *area);
185 bool ED_area_is_global(const ScrArea *area);
186 int ED_region_global_size_y(void);
187 void ED_area_update_region_sizes(struct wmWindowManager *wm,
188                                  struct wmWindow *win,
189                                  struct ScrArea *area);
190
191 ScrArea *ED_screen_areas_iter_first(const struct wmWindow *win, const bScreen *screen);
192 ScrArea *ED_screen_areas_iter_next(const bScreen *screen, const ScrArea *area);
193 /**
194  * Iterate over all areas visible in the screen (screen as in everything
195  * visible in the window, not just bScreen).
196  * \note Skips global areas with flag GLOBAL_AREA_IS_HIDDEN.
197  */
198 #define ED_screen_areas_iter(win, screen, area_name) \
199   for (ScrArea *area_name = ED_screen_areas_iter_first(win, screen); area_name != NULL; \
200        area_name = ED_screen_areas_iter_next(screen, area_name))
201 #define ED_screen_verts_iter(win, screen, vert_name) \
202   for (ScrVert *vert_name = (win)->global_areas.vertbase.first ? \
203                                 (win)->global_areas.vertbase.first : \
204                                 screen->vertbase.first; \
205        vert_name != NULL; \
206        vert_name = (vert_name == (win)->global_areas.vertbase.last) ? (screen)->vertbase.first : \
207                                                                       vert_name->next)
208
209 /* screens */
210 void ED_screens_initialize(struct Main *bmain, struct wmWindowManager *wm);
211 void ED_screen_draw_edges(struct wmWindow *win);
212 void ED_screen_draw_join_shape(struct ScrArea *sa1, struct ScrArea *sa2);
213 void ED_screen_draw_split_preview(struct ScrArea *sa, const int dir, const float fac);
214 void ED_screen_refresh(struct wmWindowManager *wm, struct wmWindow *win);
215 void ED_screen_ensure_updated(struct wmWindowManager *wm,
216                               struct wmWindow *win,
217                               struct bScreen *screen);
218 void ED_screen_do_listen(struct bContext *C, struct wmNotifier *note);
219 bool ED_screen_change(struct bContext *C, struct bScreen *sc);
220 void ED_screen_scene_change(struct bContext *C, struct wmWindow *win, struct Scene *scene);
221 void ED_screen_set_active_region(struct bContext *C, struct wmWindow *win, const int xy[2]);
222 void ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
223 void ED_screen_animation_timer(struct bContext *C, int redraws, int refresh, int sync, int enable);
224 void ED_screen_animation_timer_update(struct bScreen *screen, int redraws, int refresh);
225 void ED_screen_restore_temp_type(struct bContext *C, ScrArea *sa);
226 ScrArea *ED_screen_full_newspace(struct bContext *C, ScrArea *sa, int type);
227 void ED_screen_full_prevspace(struct bContext *C, ScrArea *sa);
228 void ED_screen_full_restore(struct bContext *C, ScrArea *sa);
229 struct ScrArea *ED_screen_state_toggle(struct bContext *C,
230                                        struct wmWindow *win,
231                                        struct ScrArea *sa,
232                                        const short state);
233 void ED_screens_header_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
234 void ED_screens_footer_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
235 void ED_screens_navigation_bar_tools_menu_create(struct bContext *C,
236                                                  struct uiLayout *layout,
237                                                  void *arg);
238 bool ED_screen_stereo3d_required(const struct bScreen *screen, const struct Scene *scene);
239 Scene *ED_screen_scene_find(const struct bScreen *screen, const struct wmWindowManager *wm);
240 Scene *ED_screen_scene_find_with_window(const struct bScreen *screen,
241                                         const struct wmWindowManager *wm,
242                                         struct wmWindow **r_window);
243 ScrArea *ED_screen_area_find_with_spacedata(const bScreen *screen,
244                                             const struct SpaceLink *sl,
245                                             const bool only_visible);
246 struct wmWindow *ED_screen_window_find(const struct bScreen *screen,
247                                        const struct wmWindowManager *wm);
248 void ED_screen_preview_render(const struct bScreen *screen,
249                               int size_x,
250                               int size_y,
251                               unsigned int *r_rect) ATTR_NONNULL();
252
253 /* workspaces */
254 struct WorkSpace *ED_workspace_add(struct Main *bmain, const char *name) ATTR_NONNULL();
255 bool ED_workspace_change(struct WorkSpace *workspace_new,
256                          struct bContext *C,
257                          struct wmWindowManager *wm,
258                          struct wmWindow *win) ATTR_NONNULL();
259 struct WorkSpace *ED_workspace_duplicate(struct WorkSpace *workspace_old,
260                                          struct Main *bmain,
261                                          struct wmWindow *win);
262 bool ED_workspace_delete(struct WorkSpace *workspace,
263                          struct Main *bmain,
264                          struct bContext *C,
265                          struct wmWindowManager *wm) ATTR_NONNULL();
266 void ED_workspace_scene_data_sync(struct WorkSpaceInstanceHook *hook, Scene *scene) ATTR_NONNULL();
267 struct WorkSpaceLayout *ED_workspace_layout_add(struct Main *bmain,
268                                                 struct WorkSpace *workspace,
269                                                 struct wmWindow *win,
270                                                 const char *name) ATTR_NONNULL();
271 struct WorkSpaceLayout *ED_workspace_layout_duplicate(struct Main *bmain,
272                                                       struct WorkSpace *workspace,
273                                                       const struct WorkSpaceLayout *layout_old,
274                                                       struct wmWindow *win) ATTR_NONNULL();
275 bool ED_workspace_layout_delete(struct WorkSpace *workspace,
276                                 struct WorkSpaceLayout *layout_old,
277                                 struct bContext *C) ATTR_NONNULL();
278 bool ED_workspace_layout_cycle(struct WorkSpace *workspace,
279                                const short direction,
280                                struct bContext *C) ATTR_NONNULL();
281
282 void ED_workspace_status_text(struct bContext *C, const char *str);
283
284 /* anim */
285 void ED_update_for_newframe(struct Main *bmain, struct Depsgraph *depsgraph);
286
287 void ED_refresh_viewport_fps(struct bContext *C);
288 int ED_screen_animation_play(struct bContext *C, int sync, int mode);
289 bScreen *ED_screen_animation_playing(const struct wmWindowManager *wm);
290 bScreen *ED_screen_animation_no_scrub(const struct wmWindowManager *wm);
291
292 /* screen keymaps */
293 void ED_operatortypes_screen(void);
294 void ED_keymap_screen(struct wmKeyConfig *keyconf);
295 /* workspace keymaps */
296 void ED_operatortypes_workspace(void);
297
298 /* operators; context poll callbacks */
299 bool ED_operator_screenactive(struct bContext *C);
300 bool ED_operator_screen_mainwinactive(struct bContext *C);
301 bool ED_operator_areaactive(struct bContext *C);
302 bool ED_operator_regionactive(struct bContext *C);
303
304 bool ED_operator_scene(struct bContext *C);
305 bool ED_operator_scene_editable(struct bContext *C);
306 bool ED_operator_objectmode(struct bContext *C);
307
308 bool ED_operator_view3d_active(struct bContext *C);
309 bool ED_operator_region_view3d_active(struct bContext *C);
310 bool ED_operator_animview_active(struct bContext *C);
311 bool ED_operator_outliner_active(struct bContext *C);
312 bool ED_operator_outliner_active_no_editobject(struct bContext *C);
313 bool ED_operator_file_active(struct bContext *C);
314 bool ED_operator_action_active(struct bContext *C);
315 bool ED_operator_buttons_active(struct bContext *C);
316 bool ED_operator_node_active(struct bContext *C);
317 bool ED_operator_node_editable(struct bContext *C);
318 bool ED_operator_graphedit_active(struct bContext *C);
319 bool ED_operator_sequencer_active(struct bContext *C);
320 bool ED_operator_sequencer_active_editable(struct bContext *C);
321 bool ED_operator_image_active(struct bContext *C);
322 bool ED_operator_nla_active(struct bContext *C);
323 bool ED_operator_info_active(struct bContext *C);
324 bool ED_operator_console_active(struct bContext *C);
325
326 bool ED_operator_object_active(struct bContext *C);
327 bool ED_operator_object_active_editable(struct bContext *C);
328 bool ED_operator_object_active_editable_mesh(struct bContext *C);
329 bool ED_operator_object_active_editable_font(struct bContext *C);
330 bool ED_operator_editmesh(struct bContext *C);
331 bool ED_operator_editmesh_view3d(struct bContext *C);
332 bool ED_operator_editmesh_region_view3d(struct bContext *C);
333 bool ED_operator_editmesh_auto_smooth(struct bContext *C);
334 bool ED_operator_editarmature(struct bContext *C);
335 bool ED_operator_editcurve(struct bContext *C);
336 bool ED_operator_editcurve_3d(struct bContext *C);
337 bool ED_operator_editsurf(struct bContext *C);
338 bool ED_operator_editsurfcurve(struct bContext *C);
339 bool ED_operator_editsurfcurve_region_view3d(struct bContext *C);
340 bool ED_operator_editfont(struct bContext *C);
341 bool ED_operator_editlattice(struct bContext *C);
342 bool ED_operator_editmball(struct bContext *C);
343 bool ED_operator_uvedit(struct bContext *C);
344 bool ED_operator_uvedit_space_image(struct bContext *C);
345 bool ED_operator_uvmap(struct bContext *C);
346 bool ED_operator_posemode_exclusive(struct bContext *C);
347 bool ED_operator_posemode_context(struct bContext *C);
348 bool ED_operator_posemode(struct bContext *C);
349 bool ED_operator_posemode_local(struct bContext *C);
350 bool ED_operator_mask(struct bContext *C);
351 bool ED_operator_camera(struct bContext *C);
352
353 /* screen_user_menu.c */
354
355 bUserMenu **ED_screen_user_menus_find(const struct bContext *C, uint *r_len);
356 struct bUserMenu *ED_screen_user_menu_ensure(struct bContext *C);
357
358 struct bUserMenuItem_Op *ED_screen_user_menu_item_find_operator(struct ListBase *lb,
359                                                                 const struct wmOperatorType *ot,
360                                                                 struct IDProperty *prop,
361                                                                 short opcontext);
362 struct bUserMenuItem_Menu *ED_screen_user_menu_item_find_menu(struct ListBase *lb,
363                                                               const struct MenuType *mt);
364 struct bUserMenuItem_Prop *ED_screen_user_menu_item_find_prop(struct ListBase *lb,
365                                                               const char *context_data_path,
366                                                               const char *prop_id,
367                                                               int prop_index);
368
369 void ED_screen_user_menu_item_add_operator(struct ListBase *lb,
370                                            const char *ui_name,
371                                            const struct wmOperatorType *ot,
372                                            const struct IDProperty *prop,
373                                            short opcontext);
374 void ED_screen_user_menu_item_add_menu(struct ListBase *lb,
375                                        const char *ui_name,
376                                        const struct MenuType *mt);
377 void ED_screen_user_menu_item_add_prop(ListBase *lb,
378                                        const char *ui_name,
379                                        const char *context_data_path,
380                                        const char *prop_id,
381                                        int prop_index);
382
383 void ED_screen_user_menu_item_remove(struct ListBase *lb, struct bUserMenuItem *umi);
384 void ED_screen_user_menu_register(void);
385
386 /* Cache display helpers */
387
388 void ED_region_cache_draw_background(const struct ARegion *ar);
389 void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y);
390 void ED_region_cache_draw_cached_segments(const struct ARegion *ar,
391                                           const int num_segments,
392                                           const int *points,
393                                           const int sfra,
394                                           const int efra);
395
396 /* area_utils.c */
397 void ED_region_generic_tools_region_message_subscribe(const struct bContext *C,
398                                                       struct WorkSpace *workspace,
399                                                       struct Scene *scene,
400                                                       struct bScreen *screen,
401                                                       struct ScrArea *sa,
402                                                       struct ARegion *ar,
403                                                       struct wmMsgBus *mbus);
404 int ED_region_generic_tools_region_snap_size(const struct ARegion *ar, int size, int axis);
405
406 /* area_query.c */
407 bool ED_region_overlap_isect_x(const ARegion *ar, const int event_x);
408 bool ED_region_overlap_isect_y(const ARegion *ar, const int event_y);
409 bool ED_region_overlap_isect_xy(const ARegion *ar, const int event_xy[2]);
410 bool ED_region_overlap_isect_x_with_margin(const ARegion *ar, const int event_x, const int margin);
411 bool ED_region_overlap_isect_y_with_margin(const ARegion *ar, const int event_y, const int margin);
412 bool ED_region_overlap_isect_xy_with_margin(const ARegion *ar,
413                                             const int event_xy[2],
414                                             const int margin);
415
416 bool ED_region_contains_xy(const struct ARegion *ar, const int event_xy[2]);
417
418 /* interface_region_hud.c */
419 struct ARegionType *ED_area_type_hud(int space_type);
420 void ED_area_type_hud_clear(struct wmWindowManager *wm, ScrArea *sa_keep);
421 void ED_area_type_hud_ensure(struct bContext *C, struct ScrArea *sa);
422
423 /* default keymaps, bitflags (matches order of evaluation). */
424 enum {
425   ED_KEYMAP_UI = (1 << 1),
426   ED_KEYMAP_GIZMO = (1 << 2),
427   ED_KEYMAP_TOOL = (1 << 3),
428   ED_KEYMAP_VIEW2D = (1 << 4),
429   ED_KEYMAP_MARKERS = (1 << 5),
430   ED_KEYMAP_ANIMATION = (1 << 6),
431   ED_KEYMAP_FRAMES = (1 << 7),
432   ED_KEYMAP_HEADER = (1 << 8),
433   ED_KEYMAP_GPENCIL = (1 << 9),
434   ED_KEYMAP_FOOTER = (1 << 10),
435 };
436
437 /* SCREEN_OT_space_context_cycle direction */
438 enum {
439   SPACE_CONTEXT_CYCLE_PREV,
440   SPACE_CONTEXT_CYCLE_NEXT,
441 };
442
443 #endif /* __ED_SCREEN_H__ */