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 * The Original Code is Copyright (C) 2008 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/editors/screen/area.c
35 #include "MEM_guardedalloc.h"
37 #include "DNA_userdef_types.h"
39 #include "BLI_blenlib.h"
41 #include "BLI_utildefines.h"
42 #include "BLI_linklist_stack.h"
45 #include "BKE_context.h"
46 #include "BKE_global.h"
47 #include "BKE_screen.h"
49 #include "RNA_access.h"
50 #include "RNA_types.h"
54 #include "wm_subwindow.h"
56 #include "ED_screen.h"
57 #include "ED_screen_types.h"
58 #include "ED_space_api.h"
61 #include "BIF_glutil.h"
64 #include "IMB_imbuf.h"
65 #include "IMB_imbuf_types.h"
66 #include "IMB_metadata.h"
68 #include "UI_interface.h"
69 #include "UI_interface_icons.h"
70 #include "UI_resources.h"
71 #include "UI_view2d.h"
73 #include "screen_intern.h"
75 extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
77 /* general area and region code */
79 static void region_draw_emboss(const ARegion *ar, const rcti *scirct)
83 /* translate scissor rect to region space */
84 rect.xmin = scirct->xmin - ar->winrct.xmin;
85 rect.ymin = scirct->ymin - ar->winrct.ymin;
86 rect.xmax = scirct->xmax - ar->winrct.xmin;
87 rect.ymax = scirct->ymax - ar->winrct.ymin;
91 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
94 glColor4ub(0, 0, 0, 30);
95 sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
98 glColor4ub(0, 0, 0, 30);
99 sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
102 glColor4ub(255, 255, 255, 30);
103 sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
106 glColor4ub(255, 255, 255, 30);
107 sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
112 void ED_region_pixelspace(ARegion *ar)
114 wmOrtho2_region_pixelspace(ar);
118 /* only exported for WM */
119 void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note)
121 /* generic notes first */
122 switch (note->category) {
124 if (note->data == ND_FILEREAD)
125 ED_region_tag_redraw(ar);
128 ED_region_tag_redraw(ar);
132 if (ar->type && ar->type->listener)
133 ar->type->listener(sc, sa, ar, note);
136 /* only exported for WM */
137 void ED_area_do_listen(bScreen *sc, ScrArea *sa, wmNotifier *note)
139 /* no generic notes? */
140 if (sa->type && sa->type->listener) {
141 sa->type->listener(sc, sa, note);
145 /* only exported for WM */
146 void ED_area_do_refresh(bContext *C, ScrArea *sa)
148 /* no generic notes? */
149 if (sa->type && sa->type->refresh) {
150 sa->type->refresh(C, sa);
152 sa->do_refresh = false;
156 * Action zones are only updated if the mouse is inside of them, but in some cases (currently only fullscreen icon)
157 * it might be needed to update their properties and redraw if the mouse isn't inside.
159 void ED_area_azones_update(ScrArea *sa, const int mouse_xy[2])
162 bool changed = false;
164 for (az = sa->actionzones.first; az; az = az->next) {
165 if (az->type == AZONE_FULLSCREEN) {
166 /* only if mouse is not hovering the azone */
167 if (BLI_rcti_isect_pt_v(&az->rect, mouse_xy) == false) {
171 /* can break since currently only this is handled here */
178 sa->flag &= ~AREA_FLAG_ACTIONZONES_UPDATE;
179 ED_area_tag_redraw(sa);
184 * \brief Corner widget use for quitting fullscreen.
186 static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, float alpha)
188 int x = x2 - ((float) x2 - x1) * 0.5f / UI_DPI_FAC;
189 int y = y2 - ((float) y2 - y1) * 0.5f / UI_DPI_FAC;
191 /* adjust the icon distance from the corner */
192 x += 36.0f / UI_DPI_FAC;
193 y += 36.0f / UI_DPI_FAC;
195 /* draws from the left bottom corner of the icon */
196 x -= UI_DPI_ICON_SIZE;
197 y -= UI_DPI_ICON_SIZE;
199 alpha = min_ff(alpha, 0.75f);
201 UI_icon_draw_aspect(x, y, ICON_FULLSCREEN_EXIT, 0.7f / UI_DPI_FAC, alpha);
204 * The click_rect is the same as defined in fullscreen_click_rcti_init
205 * Keep them both in sync */
207 if (G.debug_value == 1) {
209 float icon_size = UI_DPI_ICON_SIZE + 7 * UI_DPI_FAC;
210 char alpha_debug = 255 * alpha;
212 BLI_rcti_init(&click_rect, x, x + icon_size, y, y + icon_size);
214 glColor4ub(255, 0, 0, alpha_debug);
215 fdrawbox(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
216 glColor4ub(0, 255, 255, alpha_debug);
217 fdrawline(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
218 fdrawline(click_rect.xmin, click_rect.ymax, click_rect.xmax, click_rect.ymin);
223 * \brief Corner widgets use for dragging and splitting the view.
225 static void area_draw_azone(short x1, short y1, short x2, short y2)
230 dx = copysign(ceilf(0.3f * abs(dx)), dx);
231 dy = copysign(ceilf(0.3f * abs(dy)), dy);
234 glEnable(GL_LINE_SMOOTH);
236 glColor4ub(255, 255, 255, 180);
237 fdrawline(x1, y2, x2, y1);
238 glColor4ub(255, 255, 255, 130);
239 fdrawline(x1, y2 - dy, x2 - dx, y1);
240 glColor4ub(255, 255, 255, 80);
241 fdrawline(x1, y2 - 2 * dy, x2 - 2 * dx, y1);
243 glColor4ub(0, 0, 0, 210);
244 fdrawline(x1, y2 + 1, x2 + 1, y1);
245 glColor4ub(0, 0, 0, 180);
246 fdrawline(x1, y2 - dy + 1, x2 - dx + 1, y1);
247 glColor4ub(0, 0, 0, 150);
248 fdrawline(x1, y2 - 2 * dy + 1, x2 - 2 * dx + 1, y1);
250 glDisable(GL_LINE_SMOOTH);
254 static void region_draw_azone_icon(AZone *az)
256 GLUquadricObj *qobj = NULL;
257 short midx = az->x1 + (az->x2 - az->x1) / 2;
258 short midy = az->y1 + (az->y2 - az->y1) / 2;
260 qobj = gluNewQuadric();
263 glTranslatef(midx, midy, 0.0);
265 /* outlined circle */
266 glEnable(GL_LINE_SMOOTH);
268 glColor4f(1.f, 1.f, 1.f, 0.8f);
270 gluQuadricDrawStyle(qobj, GLU_FILL);
271 gluDisk(qobj, 0.0, 4.25f, 16, 1);
273 glColor4f(0.2f, 0.2f, 0.2f, 0.9f);
275 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
276 gluDisk(qobj, 0.0, 4.25f, 16, 1);
278 glDisable(GL_LINE_SMOOTH);
281 gluDeleteQuadric(qobj);
284 sdrawline(midx, midy - 2, midx, midy + 3);
285 sdrawline(midx - 2, midy, midx + 3, midy);
288 static void draw_azone_plus(float x1, float y1, float x2, float y2)
290 float width = 0.1f * U.widget_unit;
291 float pad = 0.2f * U.widget_unit;
293 glRectf((x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
294 glRectf(x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
295 glRectf((x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
298 static void region_draw_azone_tab_plus(AZone *az)
302 /* add code to draw region hidden as 'too small' */
304 case AE_TOP_TO_BOTTOMRIGHT:
305 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
307 case AE_BOTTOM_TO_TOPLEFT:
308 UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
310 case AE_LEFT_TO_TOPRIGHT:
311 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
313 case AE_RIGHT_TO_TOPLEFT:
314 UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
318 glColor4f(0.05f, 0.05f, 0.05f, 0.4f);
319 UI_draw_roundbox((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
323 glColor4f(0.8f, 0.8f, 0.8f, 0.4f);
324 draw_azone_plus((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2);
329 static void region_draw_azone_tab(AZone *az)
334 UI_GetThemeColor3fv(TH_HEADER, col);
335 glColor4f(col[0], col[1], col[2], 0.5f);
337 /* add code to draw region hidden as 'too small' */
339 case AE_TOP_TO_BOTTOMRIGHT:
340 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_RB_ALPHA);
342 UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
343 glColor4ub(0, 0, 0, 255);
344 UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
346 case AE_BOTTOM_TO_TOPLEFT:
347 UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
349 UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
350 glColor4ub(0, 0, 0, 255);
351 UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
353 case AE_LEFT_TO_TOPRIGHT:
354 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
356 UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
357 glColor4ub(0, 0, 0, 255);
358 UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
360 case AE_RIGHT_TO_TOPLEFT:
361 UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_RB_ALPHA);
363 UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
364 glColor4ub(0, 0, 0, 255);
365 UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
372 static void region_draw_azone_tria(AZone *az)
375 //UI_GetThemeColor3fv(TH_HEADER, col);
376 glColor4f(0.0f, 0.0f, 0.0f, 0.35f);
378 /* add code to draw region hidden as 'too small' */
380 case AE_TOP_TO_BOTTOMRIGHT:
381 ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y1, (float)(az->x1 + az->x2) / 2, (float)az->y2);
384 case AE_BOTTOM_TO_TOPLEFT:
385 ui_draw_anti_tria((float)az->x1, (float)az->y2, (float)az->x2, (float)az->y2, (float)(az->x1 + az->x2) / 2, (float)az->y1);
388 case AE_LEFT_TO_TOPRIGHT:
389 ui_draw_anti_tria((float)az->x2, (float)az->y1, (float)az->x2, (float)az->y2, (float)az->x1, (float)(az->y1 + az->y2) / 2);
392 case AE_RIGHT_TO_TOPLEFT:
393 ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x1, (float)az->y2, (float)az->x2, (float)(az->y1 + az->y2) / 2);
401 static void area_azone_tag_update(ScrArea *sa)
403 sa->flag |= AREA_FLAG_ACTIONZONES_UPDATE;
406 static void region_draw_azones(ScrArea *sa, ARegion *ar)
415 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
418 glTranslatef(-ar->winrct.xmin, -ar->winrct.ymin, 0.0f);
420 for (az = sa->actionzones.first; az; az = az->next) {
421 /* test if action zone is over this region */
423 BLI_rcti_init(&azrct, az->x1, az->x2, az->y1, az->y2);
425 if (BLI_rcti_isect(&ar->drawrct, &azrct, NULL)) {
426 if (az->type == AZONE_AREA) {
427 area_draw_azone(az->x1, az->y1, az->x2, az->y2);
429 else if (az->type == AZONE_REGION) {
432 /* only display tab or icons when the region is hidden */
433 if (az->ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
434 if (G.debug_value == 3)
435 region_draw_azone_icon(az);
436 else if (G.debug_value == 2)
437 region_draw_azone_tria(az);
438 else if (G.debug_value == 1)
439 region_draw_azone_tab(az);
441 region_draw_azone_tab_plus(az);
445 else if (az->type == AZONE_FULLSCREEN) {
446 area_draw_azone_fullscreen(az->x1, az->y1, az->x2, az->y2, az->alpha);
448 if (az->alpha != 0.0f) {
449 area_azone_tag_update(sa);
460 /* only exported for WM */
461 /* makes region ready for drawing, sets pixelspace */
462 void ED_region_set(const bContext *C, ARegion *ar)
464 wmWindow *win = CTX_wm_window(C);
465 ScrArea *sa = CTX_wm_area(C);
467 ar->drawrct = ar->winrct;
469 /* note; this sets state, so we can use wmOrtho and friends */
470 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, true);
472 UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
474 ED_region_pixelspace(ar);
478 /* only exported for WM */
479 void ED_region_do_draw(bContext *C, ARegion *ar)
481 wmWindow *win = CTX_wm_window(C);
482 ScrArea *sa = CTX_wm_area(C);
483 ARegionType *at = ar->type;
486 /* see BKE_spacedata_draw_locks() */
490 /* if no partial draw rect set, full rect */
491 if (ar->drawrct.xmin == ar->drawrct.xmax) {
492 ar->drawrct = ar->winrct;
496 /* extra clip for safety */
497 BLI_rcti_isect(&ar->winrct, &ar->drawrct, &ar->drawrct);
501 ar->do_draw |= RGN_DRAWING;
503 /* note; this sets state, so we can use wmOrtho and friends */
504 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, scissor_pad);
506 wmOrtho2_region_pixelspace(ar);
508 UI_SetTheme(sa ? sa->spacetype : 0, at->regionid);
510 /* optional header info instead? */
512 UI_ThemeClearColor(TH_HEADER);
513 glClear(GL_COLOR_BUFFER_BIT);
515 UI_ThemeColor(TH_TEXT);
516 BLF_draw_default(UI_UNIT_X, 0.4f * UI_UNIT_Y, 0.0f, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
522 /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
523 ED_region_pixelspace(ar);
525 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL);
527 region_draw_azones(sa, ar);
529 /* for debugging unneeded area redraws and partial redraw */
532 glColor4f(drand48(), drand48(), drand48(), 0.1f);
533 glRectf(ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
534 ar->drawrct.xmax - ar->winrct.xmin, ar->drawrct.ymax - ar->winrct.ymin);
538 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
540 UI_blocklist_free_inactive(C, &ar->uiblocks);
543 /* disable emboss when the area is full,
544 * unless we need to see division between regions (quad-split for eg) */
545 if (((win->screen->state == SCREENFULL) && (ar->alignment == RGN_ALIGN_NONE)) == 0) {
546 region_draw_emboss(ar, &ar->winrct);
551 /* **********************************
552 * maybe silly, but let's try for now
553 * to keep these tags protected
554 * ********************************** */
556 void ED_region_tag_redraw(ARegion *ar)
558 /* don't tag redraw while drawing, it shouldn't happen normally
559 * but python scripts can cause this to happen indirectly */
560 if (ar && !(ar->do_draw & RGN_DRAWING)) {
561 /* zero region means full region redraw */
562 ar->do_draw &= ~RGN_DRAW_PARTIAL;
563 ar->do_draw |= RGN_DRAW;
564 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
568 void ED_region_tag_redraw_overlay(ARegion *ar)
571 ar->do_draw_overlay = RGN_DRAW;
574 void ED_region_tag_refresh_ui(ARegion *ar)
577 ar->do_draw |= RGN_DRAW_REFRESH_UI;
581 void ED_region_tag_redraw_partial(ARegion *ar, const rcti *rct)
583 if (ar && !(ar->do_draw & RGN_DRAWING)) {
584 if (!(ar->do_draw & (RGN_DRAW | RGN_DRAW_PARTIAL))) {
585 /* no redraw set yet, set partial region */
586 ar->do_draw |= RGN_DRAW_PARTIAL;
589 else if (ar->drawrct.xmin != ar->drawrct.xmax) {
590 BLI_assert((ar->do_draw & RGN_DRAW_PARTIAL) != 0);
591 /* partial redraw already set, expand region */
592 BLI_rcti_union(&ar->drawrct, rct);
595 BLI_assert((ar->do_draw & RGN_DRAW) != 0);
596 /* Else, full redraw is already requested, nothing to do here. */
601 void ED_area_tag_redraw(ScrArea *sa)
606 for (ar = sa->regionbase.first; ar; ar = ar->next)
607 ED_region_tag_redraw(ar);
610 void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype)
615 for (ar = sa->regionbase.first; ar; ar = ar->next) {
616 if (ar->regiontype == regiontype) {
617 ED_region_tag_redraw(ar);
623 void ED_area_tag_refresh(ScrArea *sa)
626 sa->do_refresh = true;
629 /* *************************************************************** */
631 /* use NULL to disable it */
632 void ED_area_headerprint(ScrArea *sa, const char *str)
636 /* happens when running transform operators in backround mode */
640 for (ar = sa->regionbase.first; ar; ar = ar->next) {
641 if (ar->regiontype == RGN_TYPE_HEADER) {
643 if (ar->headerstr == NULL)
644 ar->headerstr = MEM_mallocN(UI_MAX_DRAW_STR, "headerprint");
645 BLI_strncpy(ar->headerstr, str, UI_MAX_DRAW_STR);
647 else if (ar->headerstr) {
648 MEM_freeN(ar->headerstr);
649 ar->headerstr = NULL;
651 ED_region_tag_redraw(ar);
656 /* ************************************************************ */
659 static void area_azone_initialize(wmWindow *win, bScreen *screen, ScrArea *sa)
663 /* reinitalize entirely, regions and fullscreen add azones too */
664 BLI_freelistN(&sa->actionzones);
666 if (screen->state != SCREENNORMAL) {
670 if (U.app_flag & USER_APP_LOCK_UI_LAYOUT) {
674 /* can't click on bottom corners on OS X, already used for resizing */
676 if (!(sa->totrct.xmin == 0 && sa->totrct.ymin == 0) || WM_window_is_fullscreen(win))
681 /* set area action zones */
682 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
683 BLI_addtail(&(sa->actionzones), az);
684 az->type = AZONE_AREA;
685 az->x1 = sa->totrct.xmin;
686 az->y1 = sa->totrct.ymin;
687 az->x2 = sa->totrct.xmin + (AZONESPOT - 1);
688 az->y2 = sa->totrct.ymin + (AZONESPOT - 1);
689 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
692 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
693 BLI_addtail(&(sa->actionzones), az);
694 az->type = AZONE_AREA;
695 az->x1 = sa->totrct.xmax;
696 az->y1 = sa->totrct.ymax;
697 az->x2 = sa->totrct.xmax - (AZONESPOT - 1);
698 az->y2 = sa->totrct.ymax - (AZONESPOT - 1);
699 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
702 static void fullscreen_azone_initialize(ScrArea *sa, ARegion *ar)
706 if (ar->regiontype != RGN_TYPE_WINDOW)
709 az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone");
710 BLI_addtail(&(sa->actionzones), az);
711 az->type = AZONE_FULLSCREEN;
715 az->x1 = ar->winrct.xmax - (AZONEFADEOUT - 1);
716 az->y1 = ar->winrct.ymax - (AZONEFADEOUT - 1);
717 az->x2 = ar->winrct.xmax;
718 az->y2 = ar->winrct.ymax;
719 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
722 #define AZONEPAD_EDGE (0.1f * U.widget_unit)
723 #define AZONEPAD_ICON (0.45f * U.widget_unit)
724 static void region_azone_edge(AZone *az, ARegion *ar)
727 case AE_TOP_TO_BOTTOMRIGHT:
728 az->x1 = ar->winrct.xmin;
729 az->y1 = ar->winrct.ymax - AZONEPAD_EDGE;
730 az->x2 = ar->winrct.xmax;
731 az->y2 = ar->winrct.ymax + AZONEPAD_EDGE;
733 case AE_BOTTOM_TO_TOPLEFT:
734 az->x1 = ar->winrct.xmin;
735 az->y1 = ar->winrct.ymin + AZONEPAD_EDGE;
736 az->x2 = ar->winrct.xmax;
737 az->y2 = ar->winrct.ymin - AZONEPAD_EDGE;
739 case AE_LEFT_TO_TOPRIGHT:
740 az->x1 = ar->winrct.xmin - AZONEPAD_EDGE;
741 az->y1 = ar->winrct.ymin;
742 az->x2 = ar->winrct.xmin + AZONEPAD_EDGE;
743 az->y2 = ar->winrct.ymax;
745 case AE_RIGHT_TO_TOPLEFT:
746 az->x1 = ar->winrct.xmax + AZONEPAD_EDGE;
747 az->y1 = ar->winrct.ymin;
748 az->x2 = ar->winrct.xmax - AZONEPAD_EDGE;
749 az->y2 = ar->winrct.ymax;
753 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
756 static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
761 /* count how many actionzones with along same edge are available.
762 * This allows for adding more action zones in the future without
763 * having to worry about correct offset */
764 for (azt = sa->actionzones.first; azt; azt = azt->next) {
765 if (azt->edge == az->edge) tot++;
769 case AE_TOP_TO_BOTTOMRIGHT:
770 az->x1 = ar->winrct.xmax - tot * 2 * AZONEPAD_ICON;
771 az->y1 = ar->winrct.ymax + AZONEPAD_ICON;
772 az->x2 = ar->winrct.xmax - tot * AZONEPAD_ICON;
773 az->y2 = ar->winrct.ymax + 2 * AZONEPAD_ICON;
775 case AE_BOTTOM_TO_TOPLEFT:
776 az->x1 = ar->winrct.xmin + AZONEPAD_ICON;
777 az->y1 = ar->winrct.ymin - 2 * AZONEPAD_ICON;
778 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_ICON;
779 az->y2 = ar->winrct.ymin - AZONEPAD_ICON;
781 case AE_LEFT_TO_TOPRIGHT:
782 az->x1 = ar->winrct.xmin - 2 * AZONEPAD_ICON;
783 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
784 az->x2 = ar->winrct.xmin - AZONEPAD_ICON;
785 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
787 case AE_RIGHT_TO_TOPLEFT:
788 az->x1 = ar->winrct.xmax + AZONEPAD_ICON;
789 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
790 az->x2 = ar->winrct.xmax + 2 * AZONEPAD_ICON;
791 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
795 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
797 /* if more azones on 1 spot, set offset */
798 for (azt = sa->actionzones.first; azt; azt = azt->next) {
800 if (ABS(az->x1 - azt->x1) < 2 && ABS(az->y1 - azt->y1) < 2) {
801 if (az->edge == AE_TOP_TO_BOTTOMRIGHT || az->edge == AE_BOTTOM_TO_TOPLEFT) {
809 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
815 #define AZONEPAD_TAB_PLUSW (0.7f * U.widget_unit)
816 #define AZONEPAD_TAB_PLUSH (0.7f * U.widget_unit)
818 /* region already made zero sized, in shape of edge */
819 static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar)
824 for (azt = sa->actionzones.first; azt; azt = azt->next) {
825 if (azt->edge == az->edge) tot++;
829 case AE_TOP_TO_BOTTOMRIGHT:
830 add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
831 az->x1 = ar->winrct.xmax - 2.5f * AZONEPAD_TAB_PLUSW;
832 az->y1 = ar->winrct.ymax - add;
833 az->x2 = ar->winrct.xmax - 1.5f * AZONEPAD_TAB_PLUSW;
834 az->y2 = ar->winrct.ymax - add + AZONEPAD_TAB_PLUSH;
836 case AE_BOTTOM_TO_TOPLEFT:
837 az->x1 = ar->winrct.xmax - 2.5f * AZONEPAD_TAB_PLUSW;
838 az->y1 = ar->winrct.ymin - AZONEPAD_TAB_PLUSH;
839 az->x2 = ar->winrct.xmax - 1.5f * AZONEPAD_TAB_PLUSW;
840 az->y2 = ar->winrct.ymin;
842 case AE_LEFT_TO_TOPRIGHT:
843 az->x1 = ar->winrct.xmin - AZONEPAD_TAB_PLUSH;
844 az->y1 = ar->winrct.ymax - 2.5f * AZONEPAD_TAB_PLUSW;
845 az->x2 = ar->winrct.xmin;
846 az->y2 = ar->winrct.ymax - 1.5f * AZONEPAD_TAB_PLUSW;
848 case AE_RIGHT_TO_TOPLEFT:
849 az->x1 = ar->winrct.xmax - 1;
850 az->y1 = ar->winrct.ymax - 2.5f * AZONEPAD_TAB_PLUSW;
851 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TAB_PLUSH;
852 az->y2 = ar->winrct.ymax - 1.5f * AZONEPAD_TAB_PLUSW;
855 /* rect needed for mouse pointer test */
856 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
860 #define AZONEPAD_TABW (0.9f * U.widget_unit)
861 #define AZONEPAD_TABH (0.35f * U.widget_unit)
863 /* region already made zero sized, in shape of edge */
864 static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar)
869 for (azt = sa->actionzones.first; azt; azt = azt->next) {
870 if (azt->edge == az->edge) tot++;
874 case AE_TOP_TO_BOTTOMRIGHT:
875 add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
876 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TABW;
877 az->y1 = ar->winrct.ymax - add;
878 az->x2 = ar->winrct.xmax - AZONEPAD_TABW;
879 az->y2 = ar->winrct.ymax - add + AZONEPAD_TABH;
881 case AE_BOTTOM_TO_TOPLEFT:
882 az->x1 = ar->winrct.xmin + AZONEPAD_TABW;
883 az->y1 = ar->winrct.ymin - AZONEPAD_TABH;
884 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TABW;
885 az->y2 = ar->winrct.ymin;
887 case AE_LEFT_TO_TOPRIGHT:
888 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TABH;
889 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
890 az->x2 = ar->winrct.xmin + 1;
891 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
893 case AE_RIGHT_TO_TOPLEFT:
894 az->x1 = ar->winrct.xmax - 1;
895 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
896 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TABH;
897 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
900 /* rect needed for mouse pointer test */
901 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
904 #define AZONEPAD_TRIAW (0.8f * U.widget_unit)
905 #define AZONEPAD_TRIAH (0.45f * U.widget_unit)
908 /* region already made zero sized, in shape of edge */
909 static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar)
914 for (azt = sa->actionzones.first; azt; azt = azt->next) {
915 if (azt->edge == az->edge) tot++;
919 case AE_TOP_TO_BOTTOMRIGHT:
920 add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
921 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TRIAW;
922 az->y1 = ar->winrct.ymax - add;
923 az->x2 = ar->winrct.xmax - AZONEPAD_TRIAW;
924 az->y2 = ar->winrct.ymax - add + AZONEPAD_TRIAH;
926 case AE_BOTTOM_TO_TOPLEFT:
927 az->x1 = ar->winrct.xmin + AZONEPAD_TRIAW;
928 az->y1 = ar->winrct.ymin - AZONEPAD_TRIAH;
929 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TRIAW;
930 az->y2 = ar->winrct.ymin;
932 case AE_LEFT_TO_TOPRIGHT:
933 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TRIAH;
934 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
935 az->x2 = ar->winrct.xmin + 1;
936 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
938 case AE_RIGHT_TO_TOPLEFT:
939 az->x1 = ar->winrct.xmax - 1;
940 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
941 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TRIAH;
942 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
945 /* rect needed for mouse pointer test */
946 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
950 static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge, const bool is_fullscreen)
953 const bool is_hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) == 0;
955 if (is_hidden || !is_fullscreen) {
956 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
957 BLI_addtail(&(sa->actionzones), az);
958 az->type = AZONE_REGION;
964 if (!is_fullscreen) {
965 if (G.debug_value == 3)
966 region_azone_icon(sa, az, ar);
967 else if (G.debug_value == 2)
968 region_azone_tria(sa, az, ar);
969 else if (G.debug_value == 1)
970 region_azone_tab(sa, az, ar);
972 region_azone_tab_plus(sa, az, ar);
976 region_azone_edge(az, ar);
982 /* *************************************************************** */
984 static void region_azone_add(ScrArea *sa, ARegion *ar, const int alignment, const bool is_fullscreen)
986 /* edge code (t b l r) is along which area edge azone will be drawn */
988 if (alignment == RGN_ALIGN_TOP)
989 region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT, is_fullscreen);
990 else if (alignment == RGN_ALIGN_BOTTOM)
991 region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen);
992 else if (alignment == RGN_ALIGN_RIGHT)
993 region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT, is_fullscreen);
994 else if (alignment == RGN_ALIGN_LEFT)
995 region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT, is_fullscreen);
998 /* dir is direction to check, not the splitting edge direction! */
999 static int rct_fits(const rcti *rect, char dir, int size)
1002 return BLI_rcti_size_x(rect) + 1 - size;
1005 return BLI_rcti_size_y(rect) + 1 - size;
1009 /* *************************************************************** */
1011 /* ar should be overlapping */
1012 /* function checks if some overlapping region was defined before - on same place */
1013 static void region_overlap_fix(ScrArea *sa, ARegion *ar)
1016 const int align = ar->alignment & ~RGN_SPLIT_PREV;
1019 /* find overlapping previous region on same place */
1020 for (ar1 = ar->prev; ar1; ar1 = ar1->prev) {
1021 if (ar1->overlap && ((ar1->alignment & RGN_SPLIT_PREV) == 0)) {
1022 align1 = ar1->alignment;
1023 if (BLI_rcti_isect(&ar1->winrct, &ar->winrct, NULL)) {
1024 if (align1 != align) {
1025 /* Left overlapping right or vice-versa, forbid this! */
1026 ar->flag |= RGN_FLAG_TOO_SMALL;
1029 /* Else, we have our previous region on same side. */
1035 /* translate or close */
1037 if (align1 == RGN_ALIGN_LEFT) {
1038 if (ar->winrct.xmax + ar1->winx > sa->winx - U.widget_unit) {
1039 ar->flag |= RGN_FLAG_TOO_SMALL;
1043 BLI_rcti_translate(&ar->winrct, ar1->winx, 0);
1046 else if (align1 == RGN_ALIGN_RIGHT) {
1047 if (ar->winrct.xmin - ar1->winx < U.widget_unit) {
1048 ar->flag |= RGN_FLAG_TOO_SMALL;
1052 BLI_rcti_translate(&ar->winrct, -ar1->winx, 0);
1057 /* At this point, 'ar' is in its final position and still open.
1058 * Make a final check it does not overlap any previous 'other side' region. */
1059 for (ar1 = ar->prev; ar1; ar1 = ar1->prev) {
1060 if (ar1->overlap && (ar1->alignment & RGN_SPLIT_PREV) == 0) {
1061 if ((ar1->alignment != align) && BLI_rcti_isect(&ar1->winrct, &ar->winrct, NULL)) {
1062 /* Left overlapping right or vice-versa, forbid this! */
1063 ar->flag |= RGN_FLAG_TOO_SMALL;
1070 /* overlapping regions only in the following restricted cases */
1071 static bool region_is_overlap(wmWindow *win, ScrArea *sa, ARegion *ar)
1073 if (U.uiflag2 & USER_REGION_OVERLAP) {
1074 if (WM_is_draw_triple(win)) {
1075 if (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_SEQ)) {
1076 if (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS))
1079 else if (sa->spacetype == SPACE_IMAGE) {
1080 if (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS, RGN_TYPE_PREVIEW))
1089 static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti *remainder, int quad)
1091 rcti *remainder_prev = remainder;
1092 int prefsizex, prefsizey;
1098 /* no returns in function, winrct gets set in the end again */
1099 BLI_rcti_init(&ar->winrct, 0, 0, 0, 0);
1101 /* for test; allow split of previously defined region */
1102 if (ar->alignment & RGN_SPLIT_PREV)
1104 remainder = &ar->prev->winrct;
1106 alignment = ar->alignment & ~RGN_SPLIT_PREV;
1108 /* set here, assuming userpref switching forces to call this again */
1109 ar->overlap = region_is_overlap(win, sa, ar);
1111 /* clear state flags first */
1112 ar->flag &= ~RGN_FLAG_TOO_SMALL;
1114 if (ar->next == NULL && alignment != RGN_ALIGN_QSPLIT)
1115 alignment = RGN_ALIGN_NONE;
1117 /* prefsize, for header we stick to exception (prevent dpi rounding error) */
1118 prefsizex = UI_DPI_FAC * (ar->sizex > 1 ? ar->sizex + 0.5f : ar->type->prefsizex);
1120 if (ar->regiontype == RGN_TYPE_HEADER) {
1121 prefsizey = ED_area_headersize();
1123 else if (ar->regiontype == RGN_TYPE_UI && sa->spacetype == SPACE_FILE) {
1124 prefsizey = UI_UNIT_Y * 2 + (UI_UNIT_Y / 2);
1127 prefsizey = UI_DPI_FAC * (ar->sizey > 1 ? ar->sizey + 0.5f : ar->type->prefsizey);
1131 if (ar->flag & RGN_FLAG_HIDDEN) {
1132 /* hidden is user flag */
1134 else if (alignment == RGN_ALIGN_FLOAT) {
1135 /* XXX floating area region, not handled yet here */
1137 else if (rct_fits(remainder, 'v', 1) < 0 || rct_fits(remainder, 'h', 1) < 0) {
1138 /* remainder is too small for any usage */
1139 ar->flag |= RGN_FLAG_TOO_SMALL;
1141 else if (alignment == RGN_ALIGN_NONE) {
1142 /* typically last region */
1143 ar->winrct = *remainder;
1144 BLI_rcti_init(remainder, 0, 0, 0, 0);
1146 else if (alignment == RGN_ALIGN_TOP || alignment == RGN_ALIGN_BOTTOM) {
1148 if (rct_fits(remainder, 'v', prefsizey) < 0) {
1149 ar->flag |= RGN_FLAG_TOO_SMALL;
1152 int fac = rct_fits(remainder, 'v', prefsizey);
1157 ar->winrct = *remainder;
1159 if (alignment == RGN_ALIGN_TOP) {
1160 ar->winrct.ymin = ar->winrct.ymax - prefsizey + 1;
1161 remainder->ymax = ar->winrct.ymin - 1;
1164 ar->winrct.ymax = ar->winrct.ymin + prefsizey - 1;
1165 remainder->ymin = ar->winrct.ymax + 1;
1169 else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
1171 if (rct_fits(remainder, 'h', prefsizex) < 0) {
1172 ar->flag |= RGN_FLAG_TOO_SMALL;
1175 int fac = rct_fits(remainder, 'h', prefsizex);
1180 ar->winrct = *remainder;
1182 if (alignment == RGN_ALIGN_RIGHT) {
1183 ar->winrct.xmin = ar->winrct.xmax - prefsizex + 1;
1184 if (ar->overlap == 0)
1185 remainder->xmax = ar->winrct.xmin - 1;
1188 ar->winrct.xmax = ar->winrct.xmin + prefsizex - 1;
1189 if (ar->overlap == 0)
1190 remainder->xmin = ar->winrct.xmax + 1;
1194 else if (alignment == RGN_ALIGN_VSPLIT || alignment == RGN_ALIGN_HSPLIT) {
1195 /* percentage subdiv*/
1196 ar->winrct = *remainder;
1198 if (alignment == RGN_ALIGN_HSPLIT) {
1199 if (rct_fits(remainder, 'h', prefsizex) > 4) {
1200 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1201 remainder->xmin = ar->winrct.xmax + 1;
1204 BLI_rcti_init(remainder, 0, 0, 0, 0);
1208 if (rct_fits(remainder, 'v', prefsizey) > 4) {
1209 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1210 remainder->ymin = ar->winrct.ymax + 1;
1213 BLI_rcti_init(remainder, 0, 0, 0, 0);
1217 else if (alignment == RGN_ALIGN_QSPLIT) {
1218 ar->winrct = *remainder;
1220 /* test if there's still 4 regions left */
1222 ARegion *artest = ar->next;
1226 artest->alignment = RGN_ALIGN_QSPLIT;
1227 artest = artest->next;
1232 /* let's stop adding regions */
1233 BLI_rcti_init(remainder, 0, 0, 0, 0);
1234 if (G.debug & G_DEBUG)
1235 printf("region quadsplit failed\n");
1242 if (quad == 1) { /* left bottom */
1243 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1244 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1246 else if (quad == 2) { /* left top */
1247 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1248 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1250 else if (quad == 3) { /* right bottom */
1251 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1252 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1254 else { /* right top */
1255 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1256 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1257 BLI_rcti_init(remainder, 0, 0, 0, 0);
1265 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1266 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1268 /* if region opened normally, we store this for hide/reveal usage */
1269 /* prevent rounding errors for UI_DPI_FAC mult and divide */
1270 if (ar->winx > 1) ar->sizex = (ar->winx + 0.5f) / UI_DPI_FAC;
1271 if (ar->winy > 1) ar->sizey = (ar->winy + 0.5f) / UI_DPI_FAC;
1273 /* exception for multiple overlapping regions on same spot */
1275 region_overlap_fix(sa, ar);
1277 /* set winrect for azones */
1278 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
1279 ar->winrct = *remainder;
1281 switch (alignment) {
1283 ar->winrct.ymin = ar->winrct.ymax;
1285 case RGN_ALIGN_BOTTOM:
1286 ar->winrct.ymax = ar->winrct.ymin;
1288 case RGN_ALIGN_RIGHT:
1289 ar->winrct.xmin = ar->winrct.xmax;
1291 case RGN_ALIGN_LEFT:
1293 /* prevent winrct to be valid */
1294 ar->winrct.xmax = ar->winrct.xmin;
1299 /* restore prev-split exception */
1300 if (ar->alignment & RGN_SPLIT_PREV) {
1302 remainder = remainder_prev;
1303 ar->prev->winx = BLI_rcti_size_x(&ar->prev->winrct) + 1;
1304 ar->prev->winy = BLI_rcti_size_y(&ar->prev->winrct) + 1;
1308 /* in end, add azones, where appropriate */
1309 if (ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
1310 /* The logic for this is: when the header takes up the full area,
1311 * disallow hiding it to view the main window.
1313 * Without this, you can drag down the file selectors header and hide it
1314 * by accident very easily (highly annoying!), the value 6 is arbitrary
1315 * but accounts for small common rounding problems when scaling the UI,
1316 * must be minimum '4' */
1319 if (ELEM(win->screen->state, SCREENNORMAL, SCREENMAXIMIZED)) {
1320 region_azone_add(sa, ar, alignment, false);
1323 region_azone_add(sa, ar, alignment, true);
1324 fullscreen_azone_initialize(sa, ar);
1328 region_rect_recursive(win, sa, ar->next, remainder, quad);
1331 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
1333 short rt = (short) U.pixelsize;
1335 if (sa->v1->vec.x > 0) sa->totrct.xmin = sa->v1->vec.x + rt;
1336 else sa->totrct.xmin = sa->v1->vec.x;
1337 if (sa->v4->vec.x < sizex - 1) sa->totrct.xmax = sa->v4->vec.x - rt;
1338 else sa->totrct.xmax = sa->v4->vec.x;
1340 if (sa->v1->vec.y > 0) sa->totrct.ymin = sa->v1->vec.y + rt;
1341 else sa->totrct.ymin = sa->v1->vec.y;
1342 if (sa->v2->vec.y < sizey - 1) sa->totrct.ymax = sa->v2->vec.y - rt;
1343 else sa->totrct.ymax = sa->v2->vec.y;
1346 sa->winx = BLI_rcti_size_x(&sa->totrct) + 1;
1347 sa->winy = BLI_rcti_size_y(&sa->totrct) + 1;
1351 /* used for area initialize below */
1352 static void region_subwindow(wmWindow *win, ARegion *ar, bool activate)
1354 bool hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) != 0;
1356 if ((ar->alignment & RGN_SPLIT_PREV) && ar->prev)
1357 hidden = hidden || (ar->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
1361 wm_subwindow_close(win, ar->swinid);
1364 else if (ar->swinid == 0) {
1365 ar->swinid = wm_subwindow_open(win, &ar->winrct, activate);
1368 wm_subwindow_position(win, ar->swinid, &ar->winrct, activate);
1372 static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
1374 /* note, add-handler checks if it already exists */
1376 /* XXX it would be good to have boundbox checks for some of these... */
1377 if (flag & ED_KEYMAP_UI) {
1378 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "User Interface", 0, 0);
1379 WM_event_add_keymap_handler(handlers, keymap);
1381 /* user interface widgets */
1382 UI_region_handlers_add(handlers);
1384 if (flag & ED_KEYMAP_VIEW2D) {
1385 /* 2d-viewport handling+manipulation */
1386 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "View2D", 0, 0);
1387 WM_event_add_keymap_handler(handlers, keymap);
1389 if (flag & ED_KEYMAP_MARKERS) {
1391 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Markers", 0, 0);
1393 /* time space only has this keymap, the others get a boundbox restricted map */
1394 if (sa->spacetype != SPACE_TIME) {
1396 /* same local check for all areas */
1397 static rcti rect = {0, 10000, 0, -1};
1398 rect.ymax = UI_MARKER_MARGIN_Y;
1399 ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
1401 WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
1405 WM_event_add_keymap_handler(handlers, keymap);
1407 if (flag & ED_KEYMAP_ANIMATION) {
1408 /* frame changing and timeline operators (for time spaces) */
1409 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Animation", 0, 0);
1410 WM_event_add_keymap_handler(handlers, keymap);
1412 if (flag & ED_KEYMAP_FRAMES) {
1413 /* frame changing/jumping (for all spaces) */
1414 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Frames", 0, 0);
1415 WM_event_add_keymap_handler(handlers, keymap);
1417 if (flag & ED_KEYMAP_GPENCIL) {
1419 /* NOTE: This is now 2 keymaps - One for basic functionality,
1420 * and one that only applies when "Edit Mode" is enabled
1423 * For now, it's easier to just include both,
1424 * since you hardly want one without the other.
1426 wmKeyMap *keymap_general = WM_keymap_find(wm->defaultconf, "Grease Pencil", 0, 0);
1427 wmKeyMap *keymap_edit = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Edit Mode", 0, 0);
1429 WM_event_add_keymap_handler(handlers, keymap_general);
1430 WM_event_add_keymap_handler(handlers, keymap_edit);
1432 if (flag & ED_KEYMAP_HEADER) {
1433 /* standard keymap for headers regions */
1434 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Header", 0, 0);
1435 WM_event_add_keymap_handler(handlers, keymap);
1440 /* called in screen_refresh, or screens_init, also area size changes */
1441 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
1446 /* set typedefinitions */
1447 sa->type = BKE_spacetype_from_id(sa->spacetype);
1449 if (sa->type == NULL) {
1450 sa->butspacetype = sa->spacetype = SPACE_VIEW3D;
1451 sa->type = BKE_spacetype_from_id(sa->spacetype);
1454 for (ar = sa->regionbase.first; ar; ar = ar->next)
1455 ar->type = BKE_regiontype_from_id(sa->type, ar->regiontype);
1458 area_calc_totrct(sa, WM_window_pixels_x(win), WM_window_pixels_y(win));
1460 /* clear all azones, add the area triange widgets */
1461 area_azone_initialize(win, win->screen, sa);
1463 /* region rect sizes */
1465 region_rect_recursive(win, sa, sa->regionbase.first, &rect, 0);
1467 /* default area handlers */
1468 ed_default_handlers(wm, sa, &sa->handlers, sa->type->keymapflag);
1469 /* checks spacedata, adds own handlers */
1471 sa->type->init(wm, sa);
1473 /* region windows, default and own handlers */
1474 for (ar = sa->regionbase.first; ar; ar = ar->next) {
1475 region_subwindow(win, ar, false);
1478 /* default region handlers */
1479 ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
1482 ar->type->init(wm, ar);
1485 /* prevent uiblocks to run */
1486 UI_blocklist_free(NULL, &ar->uiblocks);
1491 static void region_update_rect(ARegion *ar)
1493 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1494 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1496 /* v2d mask is used to subtract scrollbars from a 2d view. Needs initialize here. */
1497 BLI_rcti_init(&ar->v2d.mask, 0, ar->winx - 1, 0, ar->winy -1);
1501 * Call to move a popup window (keep OpenGL context free!)
1503 void ED_region_update_rect(bContext *C, ARegion *ar)
1505 wmWindow *win = CTX_wm_window(C);
1507 wm_subwindow_rect_set(win, ar->swinid, &ar->winrct);
1509 region_update_rect(ar);
1512 /* externally called for floating regions like menus */
1513 void ED_region_init(bContext *C, ARegion *ar)
1515 // ARegionType *at = ar->type;
1517 /* refresh can be called before window opened */
1518 region_subwindow(CTX_wm_window(C), ar, false);
1520 region_update_rect(ar);
1523 void ED_region_cursor_set(wmWindow *win, ScrArea *sa, ARegion *ar)
1525 if (ar && sa && ar->type && ar->type->cursor) {
1526 ar->type->cursor(win, sa, ar);
1529 WM_cursor_set(win, CURSOR_STD);
1533 /* for quick toggle, can skip fades */
1534 void region_toggle_hidden(bContext *C, ARegion *ar, const bool do_fade)
1536 ScrArea *sa = CTX_wm_area(C);
1538 ar->flag ^= RGN_FLAG_HIDDEN;
1540 if (do_fade && ar->overlap) {
1541 /* starts a timer, and in end calls the stuff below itself (region_sblend_invoke()) */
1542 region_blend_start(C, sa, ar);
1545 if (ar->flag & RGN_FLAG_HIDDEN)
1546 WM_event_remove_handlers(C, &ar->handlers);
1548 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1549 ED_area_tag_redraw(sa);
1553 /* exported to all editors, uses fading default */
1554 void ED_region_toggle_hidden(bContext *C, ARegion *ar)
1556 region_toggle_hidden(C, ar, true);
1560 * we swap spaces for fullscreen to keep all allocated data area vertices were set
1562 void ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free)
1566 const char spacetype = sa_dst->spacetype;
1567 const short flag_copy = HEADER_NO_PULLDOWN;
1569 sa_dst->headertype = sa_src->headertype;
1570 sa_dst->spacetype = sa_src->spacetype;
1571 sa_dst->type = sa_src->type;
1572 sa_dst->butspacetype = sa_src->butspacetype;
1574 sa_dst->flag = (sa_dst->flag & ~flag_copy) | (sa_src->flag & flag_copy);
1578 BKE_spacedata_freelist(&sa_dst->spacedata);
1580 BKE_spacedata_copylist(&sa_dst->spacedata, &sa_src->spacedata);
1582 /* Note; SPACE_EMPTY is possible on new screens */
1586 st = BKE_spacetype_from_id(spacetype);
1587 for (ar = sa_dst->regionbase.first; ar; ar = ar->next)
1588 BKE_area_region_free(st, ar);
1589 BLI_freelistN(&sa_dst->regionbase);
1591 st = BKE_spacetype_from_id(sa_src->spacetype);
1592 for (ar = sa_src->regionbase.first; ar; ar = ar->next) {
1593 ARegion *newar = BKE_area_region_copy(st, ar);
1594 BLI_addtail(&sa_dst->regionbase, newar);
1598 void ED_area_data_swap(ScrArea *sa_dst, ScrArea *sa_src)
1600 SWAP(short, sa_dst->headertype, sa_src->headertype);
1601 SWAP(char, sa_dst->spacetype, sa_src->spacetype);
1602 SWAP(SpaceType *, sa_dst->type, sa_src->type);
1603 SWAP(char, sa_dst->butspacetype, sa_src->butspacetype);
1606 SWAP(ListBase, sa_dst->spacedata, sa_src->spacedata);
1607 SWAP(ListBase, sa_dst->regionbase, sa_src->regionbase);
1610 /* *********** Space switching code *********** */
1612 void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
1614 ScrArea *tmp = MEM_callocN(sizeof(ScrArea), "addscrarea");
1616 ED_area_exit(C, sa1);
1617 ED_area_exit(C, sa2);
1619 ED_area_data_copy(tmp, sa1, false);
1620 ED_area_data_copy(sa1, sa2, true);
1621 ED_area_data_copy(sa2, tmp, true);
1622 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa1);
1623 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa2);
1625 BKE_screen_area_free(tmp);
1628 /* tell WM to refresh, cursor types etc */
1629 WM_event_add_mousemove(C);
1631 ED_area_tag_redraw(sa1);
1632 ED_area_tag_refresh(sa1);
1633 ED_area_tag_redraw(sa2);
1634 ED_area_tag_refresh(sa2);
1638 * \param skip_ar_exit Skip calling area exit callback. Set for opening temp spaces.
1640 void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exit)
1642 if (sa->spacetype != type) {
1646 /* store sa->type->exit callback */
1647 void *sa_exit = sa->type ? sa->type->exit : NULL;
1649 /* in some cases (opening temp space) we don't want to
1650 * call area exit callback, so we temporarily unset it */
1651 if (skip_ar_exit && sa->type) {
1652 sa->type->exit = NULL;
1655 ED_area_exit(C, sa);
1657 /* restore old area exit callback */
1658 if (skip_ar_exit && sa->type) {
1659 sa->type->exit = sa_exit;
1662 st = BKE_spacetype_from_id(type);
1663 slold = sa->spacedata.first;
1665 sa->spacetype = type;
1666 sa->butspacetype = type;
1669 /* check previously stored space */
1670 for (sl = sa->spacedata.first; sl; sl = sl->next)
1671 if (sl->spacetype == type)
1674 /* old spacedata... happened during work on 2.50, remove */
1675 if (sl && BLI_listbase_is_empty(&sl->regionbase)) {
1677 BLI_freelinkN(&sa->spacedata, sl);
1686 slold->regionbase = sa->regionbase;
1687 sa->regionbase = sl->regionbase;
1688 BLI_listbase_clear(&sl->regionbase);
1690 /* put in front of list */
1691 BLI_remlink(&sa->spacedata, sl);
1692 BLI_addhead(&sa->spacedata, sl);
1698 BLI_addhead(&sa->spacedata, sl);
1702 slold->regionbase = sa->regionbase;
1703 sa->regionbase = sl->regionbase;
1704 BLI_listbase_clear(&sl->regionbase);
1708 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1710 /* tell WM to refresh, cursor types etc */
1711 WM_event_add_mousemove(C);
1713 /* send space change notifier */
1714 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1716 ED_area_tag_refresh(sa);
1719 /* also redraw when re-used */
1720 ED_area_tag_redraw(sa);
1723 void ED_area_prevspace(bContext *C, ScrArea *sa)
1725 SpaceLink *sl = sa->spacedata.first;
1727 if (sl && sl->next) {
1728 ED_area_newspace(C, sa, sl->next->spacetype, false);
1730 /* keep old spacedata but move it to end, so calling
1731 * ED_area_prevspace once more won't open it again */
1732 BLI_remlink(&sa->spacedata, sl);
1733 BLI_addtail(&sa->spacedata, sl);
1739 sa->flag &= ~AREA_FLAG_STACKED_FULLSCREEN;
1741 ED_area_tag_redraw(sa);
1743 /* send space change notifier */
1744 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1747 /* returns offset for next button in header */
1748 int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
1750 ScrArea *sa = CTX_wm_area(C);
1751 bScreen *scr = CTX_wm_screen(C);
1753 int xco = 0.4 * U.widget_unit;
1755 RNA_pointer_create(&(scr->id), &RNA_Area, sa, &areaptr);
1757 uiDefButR(block, UI_BTYPE_MENU, 0, "", xco, yco, 1.6 * U.widget_unit, U.widget_unit,
1758 &areaptr, "type", 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
1760 return xco + 1.7 * U.widget_unit;
1763 /************************ standard UI regions ************************/
1765 void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int contextnr, const bool vertical)
1767 ScrArea *sa = CTX_wm_area(C);
1768 uiStyle *style = UI_style_get_dpi();
1772 View2D *v2d = &ar->v2d;
1773 View2DScrollers *scrollers;
1774 int x, y, xco, yco, w, em, triangle;
1775 bool is_context_new = 0;
1779 bool use_category_tabs = (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI)); /* XXX, should use some better check? */
1780 /* offset panels for small vertical tab area */
1781 const char *category = NULL;
1782 const int category_tabs_width = UI_PANEL_CATEGORY_MARGIN_WIDTH;
1785 BLI_SMALLSTACK_DECLARE(pt_stack, PanelType *);
1787 if (contextnr != -1)
1788 is_context_new = UI_view2d_tab_set(v2d, contextnr);
1790 /* before setting the view */
1792 /* only allow scrolling in vertical direction */
1793 v2d->keepofs |= V2D_LOCKOFS_X | V2D_KEEPOFS_Y;
1794 v2d->keepofs &= ~(V2D_LOCKOFS_Y | V2D_KEEPOFS_X);
1795 v2d->scroll &= ~(V2D_SCROLL_BOTTOM);
1796 v2d->scroll |= (V2D_SCROLL_RIGHT);
1799 /* for now, allow scrolling in both directions (since layouts are optimized for vertical,
1800 * they often don't fit in horizontal layout)
1802 v2d->keepofs &= ~(V2D_LOCKOFS_X | V2D_LOCKOFS_Y | V2D_KEEPOFS_X | V2D_KEEPOFS_Y);
1803 v2d->scroll |= (V2D_SCROLL_BOTTOM);
1804 v2d->scroll &= ~(V2D_SCROLL_RIGHT);
1807 scroll = v2d->scroll;
1810 /* collect panels to draw */
1811 for (pt = ar->type->paneltypes.last; pt; pt = pt->prev) {
1812 /* verify context */
1813 if (context && pt->context[0] && !STREQ(context, pt->context)) {
1818 if (pt->draw && (!pt->poll || pt->poll(C, pt))) {
1819 BLI_SMALLSTACK_PUSH(pt_stack, pt);
1824 /* collect categories */
1825 if (use_category_tabs) {
1826 UI_panel_category_clear_all(ar);
1828 /* gather unique categories */
1829 BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt)
1831 if (pt->category[0]) {
1832 if (!UI_panel_category_find(ar, pt->category)) {
1833 UI_panel_category_add(ar, pt->category);
1837 BLI_SMALLSTACK_ITER_END;
1839 if (!UI_panel_category_is_visible(ar)) {
1840 use_category_tabs = false;
1843 category = UI_panel_category_active_get(ar, true);
1844 margin_x = category_tabs_width;
1849 /* sortof hack - but we cannot predict the height of panels, until it's being generated */
1850 /* the layout engine works with fixed width (from v2d->cur), which is being set at end of the loop */
1851 /* in case scroller settings (hide flags) differ from previous, the whole loop gets done again */
1852 for (redo = 2; redo > 0; redo--) {
1855 w = BLI_rctf_size_x(&v2d->cur);
1856 em = (ar->type->prefsizex) ? 10 : 20; /* works out to 10*UI_UNIT_X or 20*UI_UNIT_X */
1860 em = (ar->type->prefsizex) ? 10 : 20;
1866 UI_panels_begin(C, ar);
1868 /* set view2d view matrix - UI_block_begin() stores it */
1869 UI_view2d_view_ortho(v2d);
1871 BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt)
1875 panel = UI_panel_find_by_type(ar, pt);
1877 if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) {
1878 if ((panel == NULL) || ((panel->flag & PNL_PIN) == 0)) {
1884 block = UI_block_begin(C, ar, pt->idname, UI_EMBOSS);
1885 panel = UI_panel_begin(sa, ar, block, pt, panel, &open);
1887 /* bad fixed values */
1888 triangle = (int)(UI_UNIT_Y * 1.1f);
1890 if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
1891 /* for enabled buttons */
1892 panel->layout = UI_block_layout(
1893 block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
1894 triangle, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, 0, style);
1896 pt->draw_header(C, panel);
1898 UI_block_layout_resolve(block, &xco, &yco);
1899 panel->labelofs = xco - triangle;
1900 panel->layout = NULL;
1903 panel->labelofs = 0;
1909 /* panel context can either be toolbar region or normal panels region */
1910 if (ar->regiontype == RGN_TYPE_TOOLS)
1911 panelContext = UI_LAYOUT_TOOLBAR;
1913 panelContext = UI_LAYOUT_PANEL;
1915 panel->layout = UI_block_layout(
1916 block, UI_LAYOUT_VERTICAL, panelContext,
1917 style->panelspace, 0, w - 2 * style->panelspace, em, 0, style);
1921 UI_block_layout_resolve(block, &xco, &yco);
1922 panel->layout = NULL;
1924 yco -= 2 * style->panelspace;
1925 UI_panel_end(block, w, -yco);
1929 UI_panel_end(block, w, 0);
1932 UI_block_end(C, block);
1934 BLI_SMALLSTACK_ITER_END;
1936 /* align panels and return size */
1937 UI_panels_end(C, ar, &x, &y);
1939 /* before setting the view */
1941 /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */
1942 if (v2d->cur.ymax < -FLT_EPSILON) {
1943 /* Clamp to lower view boundary */
1944 if (v2d->tot.ymin < -v2d->winy) {
1948 y = min_ii(y, v2d->cur.ymin);
1955 /* don't jump back when panels close or hide */
1956 if (!is_context_new) {
1957 if (v2d->tot.xmax > v2d->winx) {
1961 x = max_ii(x, v2d->cur.xmax);
1968 /* this also changes the 'cur' */
1969 UI_view2d_totRect_set(v2d, x, y);
1971 if (scroll != v2d->scroll) {
1972 /* Note: this code scales fine, but because of rounding differences, positions of elements
1973 * flip +1 or -1 pixel compared to redoing the entire layout again.
1974 * Leaving in commented code for future tests */
1976 UI_panels_scale(ar, BLI_rctf_size_x(&v2d->cur));
1987 /* view should be in pixelspace */
1988 UI_view2d_view_restore(C);
1990 UI_ThemeColor4((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
1991 glRecti(0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct) + 1);
1992 glDisable(GL_BLEND);
1995 UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
1996 glClear(GL_COLOR_BUFFER_BIT);
1999 /* reset line width for drawing tabs */
2003 UI_view2d_view_ortho(v2d);
2006 UI_panels_draw(C, ar);
2008 /* restore view matrix */
2009 UI_view2d_view_restore(C);
2011 if (use_category_tabs) {
2012 UI_panel_category_draw_all(ar, category);
2016 scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
2017 UI_view2d_scrollers_draw(C, v2d, scrollers);
2018 UI_view2d_scrollers_free(scrollers);
2021 void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
2025 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy);
2027 keymap = WM_keymap_find(wm->defaultconf, "View2D Buttons List", 0, 0);
2028 WM_event_add_keymap_handler(&ar->handlers, keymap);
2031 void ED_region_header(const bContext *C, ARegion *ar)
2033 uiStyle *style = UI_style_get_dpi();
2037 Header header = {NULL};
2038 int maxco, xco, yco;
2039 int headery = ED_area_headersize();
2042 UI_ThemeClearColor((ED_screen_area_active(C)) ? TH_HEADER : TH_HEADERDESEL);
2043 glClear(GL_COLOR_BUFFER_BIT);
2045 /* set view2d view matrix for scrolling (without scrollers) */
2046 UI_view2d_view_ortho(&ar->v2d);
2048 xco = maxco = 0.4f * UI_UNIT_X;
2049 yco = headery - floor(0.2f * UI_UNIT_Y);
2051 /* draw all headers types */
2052 for (ht = ar->type->headertypes.first; ht; ht = ht->next) {
2053 block = UI_block_begin(C, ar, ht->idname, UI_EMBOSS);
2054 layout = UI_block_layout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, UI_UNIT_Y, 1, 0, style);
2058 header.layout = layout;
2059 ht->draw(C, &header);
2062 xco = uiLayoutGetWidth(layout);
2067 UI_block_layout_resolve(block, &xco, &yco);
2073 UI_block_end(C, block);
2074 UI_block_draw(C, block);
2077 /* always as last */
2078 UI_view2d_totRect_set(&ar->v2d, maxco + UI_UNIT_X + 80, headery);
2080 /* restore view matrix? */
2081 UI_view2d_view_restore(C);
2084 void ED_region_header_init(ARegion *ar)
2086 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
2089 /* UI_UNIT_Y is defined as U variable now, depending dpi */
2090 int ED_area_headersize(void)
2092 return (int)(HEADERY * UI_DPI_FAC);
2095 void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], const bool full_redraw)
2097 const int header_height = UI_UNIT_Y;
2098 uiStyle *style = UI_style_get_dpi();
2099 int fontid = style->widget.uifont_id;
2103 /* background box */
2104 ED_region_visible_rect(ar, &rect);
2105 rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
2107 /* box fill entire width or just around text */
2109 rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
2111 rect.ymax = BLI_rcti_size_y(&ar->winrct);
2114 glGetIntegerv(GL_SCISSOR_BOX, scissor);
2115 glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin,
2116 BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1);
2119 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2120 glColor4fv(fill_color);
2121 glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
2122 glDisable(GL_BLEND);
2125 UI_ThemeColor(TH_TEXT_HI);
2126 BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2127 BLF_enable(fontid, BLF_CLIPPING);
2128 BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit, 0.0f);
2130 BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
2132 BLF_disable(fontid, BLF_CLIPPING);
2134 /* restore scissor as it was before */
2135 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
2138 #define MAX_METADATA_STR 1024
2140 static const char *meta_data_list[] =
2154 BLI_INLINE bool metadata_is_valid(ImBuf *ibuf, char *r_str, short index, int offset)
2156 return (IMB_metadata_get_field(ibuf->metadata, meta_data_list[index], r_str + offset, MAX_METADATA_STR - offset) && r_str[0]);
2159 static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const bool is_top)
2161 char temp_str[MAX_METADATA_STR];
2166 const float height = BLF_height_max(fontid);
2167 const float margin = height / 8;
2168 const float vertical_offset = (height + margin);
2170 /* values taking margins into account */
2171 const float descender = BLF_descender(fontid);
2172 const float xmin = (rect->xmin + margin);
2173 const float xmax = (rect->xmax - margin);
2174 const float ymin = (rect->ymin + margin) - descender;
2175 const float ymax = (rect->ymax - margin) - descender;
2178 for (i = 0; i < 4; i++) {
2181 bool do_newline = false;
2182 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]);
2183 if (metadata_is_valid(ibuf, temp_str, 0, len)) {
2184 BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f);
2185 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2189 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]);
2190 if (metadata_is_valid(ibuf, temp_str, 1, len)) {
2191 line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2192 BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f);
2193 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2198 ofs_y += vertical_offset;
2200 else if (i == 1 || i == 2) {
2201 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]);
2202 if (metadata_is_valid(ibuf, temp_str, i + 1, len)) {
2203 BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f);
2204 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2205 ofs_y += vertical_offset;
2207 } /* Note (wrapped) */
2209 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]);
2210 if (metadata_is_valid(ibuf, temp_str, i + 1, len)) {
2211 struct ResultBLF info;
2212 BLF_enable(fontid, BLF_WORD_WRAP);
2213 BLF_wordwrap(fontid, ibuf->x - (margin * 2));
2214 BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f);
2215 BLF_draw_ex(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX, &info);
2216 BLF_wordwrap(fontid, 0);
2217 BLF_disable(fontid, BLF_WORD_WRAP);
2218 ofs_y += vertical_offset * info.lines;
2222 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]);
2223 if (metadata_is_valid(ibuf, temp_str, i + 1, len)) {
2224 line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2225 BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f);
2226 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2227 ofs_y += vertical_offset;
2234 for (i = 5; i < 10; i++) {
2235 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]);
2236 if (metadata_is_valid(ibuf, temp_str, i, len)) {
2237 BLF_position(fontid, xmin + ofs_x, ymin, 0.0f);
2238 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2240 ofs_x += BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX) + UI_UNIT_X;
2246 static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top)
2248 const float height = BLF_height_max(fontid);
2249 const float margin = (height / 8);
2250 char str[MAX_METADATA_STR] = "";
2254 if (metadata_is_valid(ibuf, str, 0, 0) || metadata_is_valid(ibuf, str, 1, 0)) {
2257 for (i = 2; i < 5; i++) {
2258 if (metadata_is_valid(ibuf, str, i, 0)) {
2261 struct ResultBLF info;
2265 BLF_enable(fontid, BLF_WORD_WRAP);
2266 BLF_wordwrap(fontid, ibuf->x - (margin * 2));
2267 BLF_boundbox_ex(fontid, str, sizeof(str), &wrap.rect, &wrap.info);
2268 BLF_wordwrap(fontid, 0);
2269 BLF_disable(fontid, BLF_WORD_WRAP);
2271 count += wrap.info.lines;
2280 for (i = 5; i < 10; i++) {
2281 if (metadata_is_valid(ibuf, str, i, 0)) {
2288 return (height + margin) * count;
2294 #undef MAX_METADATA_STR
2296 void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy)
2300 uiStyle *style = UI_style_get_dpi();
2302 if (!ibuf->metadata)
2305 /* find window pixel coordinates of origin */
2308 /* offset and zoom using ogl */
2309 glTranslatef(x, y, 0.0f);
2310 glScalef(zoomx, zoomy, 1.0f);
2312 BLF_size(blf_mono_font, style->widgetlabel.points * 1.5f * U.pixelsize, U.dpi);
2314 /* *** upper box*** */
2316 /* get needed box height */
2317 box_y = metadata_box_height_get(ibuf, blf_mono_font, true);
2320 UI_ThemeColor(TH_METADATA_BG);
2323 BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymax, frame->ymax + box_y);
2325 glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2327 BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2328 BLF_enable(blf_mono_font, BLF_CLIPPING);
2330 UI_ThemeColor(TH_METADATA_TEXT);
2331 metadata_draw_imbuf(ibuf, &rect, blf_mono_font, true);
2333 BLF_disable(blf_mono_font, BLF_CLIPPING);
2337 /* *** lower box*** */
2339 box_y = metadata_box_height_get(ibuf, blf_mono_font, false);
2342 UI_ThemeColor(TH_METADATA_BG);
2344 /* set up box rect */
2345 BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymin - box_y, frame->ymin);
2347 glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2349 BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2350 BLF_enable(blf_mono_font, BLF_CLIPPING);
2352 UI_ThemeColor(TH_METADATA_TEXT);
2353 metadata_draw_imbuf(ibuf, &rect, blf_mono_font, false);
2355 BLF_disable(blf_mono_font, BLF_CLIPPING);
2361 void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
2363 float gridsize, gridstep = 1.0f / 32.0f;
2364 float fac, blendfac;
2367 /* the image is located inside (0, 0), (1, 1) as set by view2d */
2368 UI_ThemeColorShade(TH_BACK, 20);
2370 UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
2371 UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2);
2372 glRectf(x1, y1, x2, y2);
2374 /* gridsize adapted to zoom level */
2375 gridsize = 0.5f * (zoomx + zoomy);
2376 if (gridsize <= 0.0f)
2379 if (gridsize < 1.0f) {
2380 while (gridsize < 1.0f) {
2386 while (gridsize >= 4.0f) {
2392 /* the fine resolution level */
2393 blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
2394 CLAMP(blendfac, 0.0f, 1.0f);
2395 UI_ThemeColorShade(TH_BACK, (int)(20.0f * (1.0f - blendfac)));
2399 while (fac < 1.0f) {
2400 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
2401 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
2402 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
2403 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
2407 /* the large resolution level */
2408 UI_ThemeColor(TH_BACK);
2411 while (fac < 1.0f) {
2412 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
2413 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
2414 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
2415 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
2416 fac += 4.0f * gridstep;
2421 /* If the area has overlapping regions, it returns visible rect for Region *ar */
2422 /* rect gets returned in local region coordinates */
2423 void ED_region_visible_rect(ARegion *ar, rcti *rect)
2427 /* allow function to be called without area */
2433 /* check if a region overlaps with the current one */
2434 for (; arn; arn = arn->next) {
2435 if (ar != arn && arn->overlap) {
2436 if (BLI_rcti_isect(rect, &arn->winrct, NULL)) {
2438 /* overlap left, also check 1 pixel offset (2 regions on one side) */
2439 if (ABS(rect->xmin - arn->winrct.xmin) < 2)
2440 rect->xmin = arn->winrct.xmax;
2443 if (ABS(rect->xmax - arn->winrct.xmax) < 2)
2444 rect->xmax = arn->winrct.xmin;
2448 BLI_rcti_translate(rect, -ar->winrct.xmin, -ar->winrct.ymin);
2451 /* Cache display helpers */
2453 void ED_region_cache_draw_background(const ARegion *ar)
2455 glColor4ub(128, 128, 255, 64);
2456 glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
2459 void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
2461 uiStyle *style = UI_style_get();
2462 int fontid = style->widget.uifont_id;
2464 float font_dims[2] = {0.0f, 0.0f};
2467 BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
2468 BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
2470 BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
2472 glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
2474 UI_ThemeColor(TH_TEXT);
2475 BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
2476 BLF_draw(fontid, numstr, sizeof(numstr));
2479 void ED_region_cache_draw_cached_segments(const ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra)
2484 glColor4ub(128, 128, 255, 128);
2486 for (a = 0; a < num_segments; a++) {
2489 x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
2490 x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
2492 glRecti(x1, 0, x2, 8 * UI_DPI_FAC);