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"
67 #include "UI_interface.h"
68 #include "UI_interface_icons.h"
69 #include "UI_resources.h"
70 #include "UI_view2d.h"
72 #include "screen_intern.h"
74 extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
76 /* general area and region code */
78 static void region_draw_emboss(ARegion *ar, rcti *scirct)
82 /* translate scissor rect to region space */
83 rect.xmin = scirct->xmin - ar->winrct.xmin;
84 rect.ymin = scirct->ymin - ar->winrct.ymin;
85 rect.xmax = scirct->xmax - ar->winrct.xmin;
86 rect.ymax = scirct->ymax - ar->winrct.ymin;
90 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
93 glColor4ub(0, 0, 0, 30);
94 sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
97 glColor4ub(0, 0, 0, 30);
98 sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
101 glColor4ub(255, 255, 255, 30);
102 sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
105 glColor4ub(255, 255, 255, 30);
106 sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
111 void ED_region_pixelspace(ARegion *ar)
113 wmOrtho2_region_pixelspace(ar);
117 /* only exported for WM */
118 void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note)
120 /* generic notes first */
121 switch (note->category) {
123 if (note->data == ND_FILEREAD)
124 ED_region_tag_redraw(ar);
127 ED_region_tag_redraw(ar);
131 if (ar->type && ar->type->listener)
132 ar->type->listener(sc, sa, ar, note);
135 /* only exported for WM */
136 void ED_area_do_listen(bScreen *sc, ScrArea *sa, wmNotifier *note)
138 /* no generic notes? */
139 if (sa->type && sa->type->listener) {
140 sa->type->listener(sc, sa, note);
144 /* only exported for WM */
145 void ED_area_do_refresh(bContext *C, ScrArea *sa)
147 /* no generic notes? */
148 if (sa->type && sa->type->refresh) {
149 sa->type->refresh(C, sa);
151 sa->do_refresh = false;
155 * \brief Corner widget use for quitting fullscreen.
157 static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, float alpha)
159 int x = x2 - ((float) x2 - x1) * 0.5f / UI_DPI_FAC;
160 int y = y2 - ((float) y2 - y1) * 0.5f / UI_DPI_FAC;
162 /* adjust the icon distance from the corner */
163 x += 36.0f / UI_DPI_FAC;
164 y += 36.0f / UI_DPI_FAC;
166 /* draws from the left bottom corner of the icon */
167 x -= UI_DPI_ICON_SIZE;
168 y -= UI_DPI_ICON_SIZE;
170 alpha = min_ff(alpha, 0.75f);
172 UI_icon_draw_aspect(x, y, ICON_FULLSCREEN_EXIT, 0.7f / UI_DPI_FAC, alpha);
175 * The click_rect is the same as defined in fullscreen_click_rcti_init
176 * Keep them both in sync */
178 if (G.debug_value == 1) {
180 float icon_size = UI_DPI_ICON_SIZE + 7 * UI_DPI_FAC;
181 char alpha_debug = 255 * alpha;
183 BLI_rcti_init(&click_rect, x, x + icon_size, y, y + icon_size);
185 glColor4ub(255, 0, 0, alpha_debug);
186 fdrawbox(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
187 glColor4ub(0, 255, 255, alpha_debug);
188 fdrawline(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
189 fdrawline(click_rect.xmin, click_rect.ymax, click_rect.xmax, click_rect.ymin);
194 * \brief Corner widgets use for dragging and splitting the view.
196 static void area_draw_azone(short x1, short y1, short x2, short y2)
201 dx = copysign(ceilf(0.3f * abs(dx)), dx);
202 dy = copysign(ceilf(0.3f * abs(dy)), dy);
205 glEnable(GL_LINE_SMOOTH);
207 glColor4ub(255, 255, 255, 180);
208 fdrawline(x1, y2, x2, y1);
209 glColor4ub(255, 255, 255, 130);
210 fdrawline(x1, y2 - dy, x2 - dx, y1);
211 glColor4ub(255, 255, 255, 80);
212 fdrawline(x1, y2 - 2 * dy, x2 - 2 * dx, y1);
214 glColor4ub(0, 0, 0, 210);
215 fdrawline(x1, y2 + 1, x2 + 1, y1);
216 glColor4ub(0, 0, 0, 180);
217 fdrawline(x1, y2 - dy + 1, x2 - dx + 1, y1);
218 glColor4ub(0, 0, 0, 150);
219 fdrawline(x1, y2 - 2 * dy + 1, x2 - 2 * dx + 1, y1);
221 glDisable(GL_LINE_SMOOTH);
225 static void region_draw_azone_icon(AZone *az)
227 GLUquadricObj *qobj = NULL;
228 short midx = az->x1 + (az->x2 - az->x1) / 2;
229 short midy = az->y1 + (az->y2 - az->y1) / 2;
231 qobj = gluNewQuadric();
234 glTranslatef(midx, midy, 0.0);
236 /* outlined circle */
237 glEnable(GL_LINE_SMOOTH);
239 glColor4f(1.f, 1.f, 1.f, 0.8f);
241 gluQuadricDrawStyle(qobj, GLU_FILL);
242 gluDisk(qobj, 0.0, 4.25f, 16, 1);
244 glColor4f(0.2f, 0.2f, 0.2f, 0.9f);
246 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
247 gluDisk(qobj, 0.0, 4.25f, 16, 1);
249 glDisable(GL_LINE_SMOOTH);
252 gluDeleteQuadric(qobj);
255 sdrawline(midx, midy - 2, midx, midy + 3);
256 sdrawline(midx - 2, midy, midx + 3, midy);
259 static void draw_azone_plus(float x1, float y1, float x2, float y2)
261 float width = 0.1f * U.widget_unit;
262 float pad = 0.2f * U.widget_unit;
264 glRectf((x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
265 glRectf(x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
266 glRectf((x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
269 static void region_draw_azone_tab_plus(AZone *az)
273 /* add code to draw region hidden as 'too small' */
275 case AE_TOP_TO_BOTTOMRIGHT:
276 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
278 case AE_BOTTOM_TO_TOPLEFT:
279 UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
281 case AE_LEFT_TO_TOPRIGHT:
282 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
284 case AE_RIGHT_TO_TOPLEFT:
285 UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
289 glColor4f(0.05f, 0.05f, 0.05f, 0.4f);
290 UI_draw_roundbox((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
294 glColor4f(0.8f, 0.8f, 0.8f, 0.4f);
295 draw_azone_plus((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2);
300 static void region_draw_azone_tab(AZone *az)
305 UI_GetThemeColor3fv(TH_HEADER, col);
306 glColor4f(col[0], col[1], col[2], 0.5f);
308 /* add code to draw region hidden as 'too small' */
310 case AE_TOP_TO_BOTTOMRIGHT:
311 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_RB_ALPHA);
313 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);
314 glColor4ub(0, 0, 0, 255);
315 UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
317 case AE_BOTTOM_TO_TOPLEFT:
318 UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
320 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);
321 glColor4ub(0, 0, 0, 255);
322 UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
324 case AE_LEFT_TO_TOPRIGHT:
325 UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
327 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);
328 glColor4ub(0, 0, 0, 255);
329 UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
331 case AE_RIGHT_TO_TOPLEFT:
332 UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_RB_ALPHA);
334 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);
335 glColor4ub(0, 0, 0, 255);
336 UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
343 static void region_draw_azone_tria(AZone *az)
346 //UI_GetThemeColor3fv(TH_HEADER, col);
347 glColor4f(0.0f, 0.0f, 0.0f, 0.35f);
349 /* add code to draw region hidden as 'too small' */
351 case AE_TOP_TO_BOTTOMRIGHT:
352 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);
355 case AE_BOTTOM_TO_TOPLEFT:
356 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);
359 case AE_LEFT_TO_TOPRIGHT:
360 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);
363 case AE_RIGHT_TO_TOPLEFT:
364 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);
372 static void region_draw_azones(ScrArea *sa, ARegion *ar)
380 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
383 glTranslatef(-ar->winrct.xmin, -ar->winrct.ymin, 0.0f);
385 for (az = sa->actionzones.first; az; az = az->next) {
386 /* test if action zone is over this region */
388 BLI_rcti_init(&azrct, az->x1, az->x2, az->y1, az->y2);
390 if (BLI_rcti_isect(&ar->drawrct, &azrct, NULL)) {
391 if (az->type == AZONE_AREA) {
392 area_draw_azone(az->x1, az->y1, az->x2, az->y2);
394 else if (az->type == AZONE_REGION) {
397 /* only display tab or icons when the region is hidden */
398 if (az->ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
399 if (G.debug_value == 3)
400 region_draw_azone_icon(az);
401 else if (G.debug_value == 2)
402 region_draw_azone_tria(az);
403 else if (G.debug_value == 1)
404 region_draw_azone_tab(az);
406 region_draw_azone_tab_plus(az);
410 else if (az->type == AZONE_FULLSCREEN) {
411 area_draw_azone_fullscreen(az->x1, az->y1, az->x2, az->y2, az->alpha);
421 /* only exported for WM */
422 /* makes region ready for drawing, sets pixelspace */
423 void ED_region_set(const bContext *C, ARegion *ar)
425 wmWindow *win = CTX_wm_window(C);
426 ScrArea *sa = CTX_wm_area(C);
428 ar->drawrct = ar->winrct;
430 /* note; this sets state, so we can use wmOrtho and friends */
431 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, true);
433 UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
435 ED_region_pixelspace(ar);
439 /* only exported for WM */
440 void ED_region_do_draw(bContext *C, ARegion *ar)
442 wmWindow *win = CTX_wm_window(C);
443 ScrArea *sa = CTX_wm_area(C);
444 ARegionType *at = ar->type;
447 /* see BKE_spacedata_draw_locks() */
451 /* if no partial draw rect set, full rect */
452 if (ar->drawrct.xmin == ar->drawrct.xmax) {
453 ar->drawrct = ar->winrct;
457 /* extra clip for safety */
458 BLI_rcti_isect(&ar->winrct, &ar->drawrct, &ar->drawrct);
462 ar->do_draw |= RGN_DRAWING;
464 /* note; this sets state, so we can use wmOrtho and friends */
465 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, scissor_pad);
467 wmOrtho2_region_ui(ar);
469 UI_SetTheme(sa ? sa->spacetype : 0, at->regionid);
471 /* optional header info instead? */
473 UI_ThemeClearColor(TH_HEADER);
474 glClear(GL_COLOR_BUFFER_BIT);
476 UI_ThemeColor(TH_TEXT);
477 BLF_draw_default(UI_UNIT_X, 0.4f * UI_UNIT_Y, 0.0f, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
483 /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
484 ED_region_pixelspace(ar);
486 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL);
488 region_draw_azones(sa, ar);
490 /* for debugging unneeded area redraws and partial redraw */
493 glColor4f(drand48(), drand48(), drand48(), 0.1f);
494 glRectf(ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
495 ar->drawrct.xmax - ar->winrct.xmin, ar->drawrct.ymax - ar->winrct.ymin);
499 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
501 UI_blocklist_free_inactive(C, &ar->uiblocks);
503 if (sa && (win->screen->state != SCREENFULL)) {
504 region_draw_emboss(ar, &ar->winrct);
508 /* **********************************
509 * maybe silly, but let's try for now
510 * to keep these tags protected
511 * ********************************** */
513 void ED_region_tag_redraw(ARegion *ar)
515 /* don't tag redraw while drawing, it shouldn't happen normally
516 * but python scripts can cause this to happen indirectly */
517 if (ar && !(ar->do_draw & RGN_DRAWING)) {
518 /* zero region means full region redraw */
519 ar->do_draw &= ~RGN_DRAW_PARTIAL;
520 ar->do_draw |= RGN_DRAW;
521 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
525 void ED_region_tag_redraw_overlay(ARegion *ar)
528 ar->do_draw_overlay = RGN_DRAW;
531 void ED_region_tag_refresh_ui(ARegion *ar)
534 ar->do_draw |= RGN_DRAW_REFRESH_UI;
538 void ED_region_tag_redraw_partial(ARegion *ar, rcti *rct)
540 if (ar && !(ar->do_draw & RGN_DRAWING)) {
541 if (!(ar->do_draw & RGN_DRAW)) {
542 /* no redraw set yet, set partial region */
543 ar->do_draw |= RGN_DRAW_PARTIAL;
546 else if (ar->drawrct.xmin != ar->drawrct.xmax) {
547 /* partial redraw already set, expand region */
548 BLI_rcti_union(&ar->drawrct, rct);
553 void ED_area_tag_redraw(ScrArea *sa)
558 for (ar = sa->regionbase.first; ar; ar = ar->next)
559 ED_region_tag_redraw(ar);
562 void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype)
567 for (ar = sa->regionbase.first; ar; ar = ar->next) {
568 if (ar->regiontype == regiontype) {
569 ED_region_tag_redraw(ar);
575 void ED_area_tag_refresh(ScrArea *sa)
578 sa->do_refresh = true;
581 /* *************************************************************** */
583 /* use NULL to disable it */
584 void ED_area_headerprint(ScrArea *sa, const char *str)
588 /* happens when running transform operators in backround mode */
592 for (ar = sa->regionbase.first; ar; ar = ar->next) {
593 if (ar->regiontype == RGN_TYPE_HEADER) {
595 if (ar->headerstr == NULL)
596 ar->headerstr = MEM_mallocN(256, "headerprint");
597 BLI_strncpy(ar->headerstr, str, 256);
599 else if (ar->headerstr) {
600 MEM_freeN(ar->headerstr);
601 ar->headerstr = NULL;
603 ED_region_tag_redraw(ar);
608 /* ************************************************************ */
611 static void area_azone_initialize(wmWindow *win, bScreen *screen, ScrArea *sa)
615 /* reinitalize entirely, regions and fullscreen add azones too */
616 BLI_freelistN(&sa->actionzones);
618 if (screen->state != SCREENNORMAL) {
622 /* can't click on bottom corners on OS X, already used for resizing */
624 if (!(sa->totrct.xmin == 0 && sa->totrct.ymin == 0) || WM_window_is_fullscreen(win))
629 /* set area action zones */
630 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
631 BLI_addtail(&(sa->actionzones), az);
632 az->type = AZONE_AREA;
633 az->x1 = sa->totrct.xmin;
634 az->y1 = sa->totrct.ymin;
635 az->x2 = sa->totrct.xmin + (AZONESPOT - 1);
636 az->y2 = sa->totrct.ymin + (AZONESPOT - 1);
637 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
640 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
641 BLI_addtail(&(sa->actionzones), az);
642 az->type = AZONE_AREA;
643 az->x1 = sa->totrct.xmax;
644 az->y1 = sa->totrct.ymax;
645 az->x2 = sa->totrct.xmax - (AZONESPOT - 1);
646 az->y2 = sa->totrct.ymax - (AZONESPOT - 1);
647 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
650 static void fullscreen_azone_initialize(ScrArea *sa, ARegion *ar)
654 if (ar->regiontype != RGN_TYPE_WINDOW)
657 az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone");
658 BLI_addtail(&(sa->actionzones), az);
659 az->type = AZONE_FULLSCREEN;
663 az->x1 = ar->winrct.xmax - (AZONEFADEOUT - 1);
664 az->y1 = ar->winrct.ymax - (AZONEFADEOUT - 1);
665 az->x2 = ar->winrct.xmax;
666 az->y2 = ar->winrct.ymax;
667 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
670 #define AZONEPAD_EDGE (0.1f * U.widget_unit)
671 #define AZONEPAD_ICON (0.45f * U.widget_unit)
672 static void region_azone_edge(AZone *az, ARegion *ar)
675 case AE_TOP_TO_BOTTOMRIGHT:
676 az->x1 = ar->winrct.xmin;
677 az->y1 = ar->winrct.ymax - AZONEPAD_EDGE;
678 az->x2 = ar->winrct.xmax;
679 az->y2 = ar->winrct.ymax + AZONEPAD_EDGE;
681 case AE_BOTTOM_TO_TOPLEFT:
682 az->x1 = ar->winrct.xmin;
683 az->y1 = ar->winrct.ymin + AZONEPAD_EDGE;
684 az->x2 = ar->winrct.xmax;
685 az->y2 = ar->winrct.ymin - AZONEPAD_EDGE;
687 case AE_LEFT_TO_TOPRIGHT:
688 az->x1 = ar->winrct.xmin - AZONEPAD_EDGE;
689 az->y1 = ar->winrct.ymin;
690 az->x2 = ar->winrct.xmin + AZONEPAD_EDGE;
691 az->y2 = ar->winrct.ymax;
693 case AE_RIGHT_TO_TOPLEFT:
694 az->x1 = ar->winrct.xmax + AZONEPAD_EDGE;
695 az->y1 = ar->winrct.ymin;
696 az->x2 = ar->winrct.xmax - AZONEPAD_EDGE;
697 az->y2 = ar->winrct.ymax;
701 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
704 static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
709 /* count how many actionzones with along same edge are available.
710 * This allows for adding more action zones in the future without
711 * having to worry about correct offset */
712 for (azt = sa->actionzones.first; azt; azt = azt->next) {
713 if (azt->edge == az->edge) tot++;
717 case AE_TOP_TO_BOTTOMRIGHT:
718 az->x1 = ar->winrct.xmax - tot * 2 * AZONEPAD_ICON;
719 az->y1 = ar->winrct.ymax + AZONEPAD_ICON;
720 az->x2 = ar->winrct.xmax - tot * AZONEPAD_ICON;
721 az->y2 = ar->winrct.ymax + 2 * AZONEPAD_ICON;
723 case AE_BOTTOM_TO_TOPLEFT:
724 az->x1 = ar->winrct.xmin + AZONEPAD_ICON;
725 az->y1 = ar->winrct.ymin - 2 * AZONEPAD_ICON;
726 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_ICON;
727 az->y2 = ar->winrct.ymin - AZONEPAD_ICON;
729 case AE_LEFT_TO_TOPRIGHT:
730 az->x1 = ar->winrct.xmin - 2 * AZONEPAD_ICON;
731 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
732 az->x2 = ar->winrct.xmin - AZONEPAD_ICON;
733 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
735 case AE_RIGHT_TO_TOPLEFT:
736 az->x1 = ar->winrct.xmax + AZONEPAD_ICON;
737 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
738 az->x2 = ar->winrct.xmax + 2 * AZONEPAD_ICON;
739 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
743 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
745 /* if more azones on 1 spot, set offset */
746 for (azt = sa->actionzones.first; azt; azt = azt->next) {
748 if (ABS(az->x1 - azt->x1) < 2 && ABS(az->y1 - azt->y1) < 2) {
749 if (az->edge == AE_TOP_TO_BOTTOMRIGHT || az->edge == AE_BOTTOM_TO_TOPLEFT) {
757 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
763 #define AZONEPAD_TAB_PLUSW (0.7f * U.widget_unit)
764 #define AZONEPAD_TAB_PLUSH (0.7f * U.widget_unit)
766 /* region already made zero sized, in shape of edge */
767 static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar)
772 for (azt = sa->actionzones.first; azt; azt = azt->next) {
773 if (azt->edge == az->edge) tot++;
777 case AE_TOP_TO_BOTTOMRIGHT:
778 add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
779 az->x1 = ar->winrct.xmax - 2.5f * AZONEPAD_TAB_PLUSW;
780 az->y1 = ar->winrct.ymax - add;
781 az->x2 = ar->winrct.xmax - 1.5f * AZONEPAD_TAB_PLUSW;
782 az->y2 = ar->winrct.ymax - add + AZONEPAD_TAB_PLUSH;
784 case AE_BOTTOM_TO_TOPLEFT:
785 az->x1 = ar->winrct.xmax - 2.5f * AZONEPAD_TAB_PLUSW;
786 az->y1 = ar->winrct.ymin - AZONEPAD_TAB_PLUSH;
787 az->x2 = ar->winrct.xmax - 1.5f * AZONEPAD_TAB_PLUSW;
788 az->y2 = ar->winrct.ymin;
790 case AE_LEFT_TO_TOPRIGHT:
791 az->x1 = ar->winrct.xmin - AZONEPAD_TAB_PLUSH;
792 az->y1 = ar->winrct.ymax - 2.5f * AZONEPAD_TAB_PLUSW;
793 az->x2 = ar->winrct.xmin;
794 az->y2 = ar->winrct.ymax - 1.5f * AZONEPAD_TAB_PLUSW;
796 case AE_RIGHT_TO_TOPLEFT:
797 az->x1 = ar->winrct.xmax - 1;
798 az->y1 = ar->winrct.ymax - 2.5f * AZONEPAD_TAB_PLUSW;
799 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TAB_PLUSH;
800 az->y2 = ar->winrct.ymax - 1.5f * AZONEPAD_TAB_PLUSW;
803 /* rect needed for mouse pointer test */
804 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
808 #define AZONEPAD_TABW (0.9f * U.widget_unit)
809 #define AZONEPAD_TABH (0.35f * U.widget_unit)
811 /* region already made zero sized, in shape of edge */
812 static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar)
817 for (azt = sa->actionzones.first; azt; azt = azt->next) {
818 if (azt->edge == az->edge) tot++;
822 case AE_TOP_TO_BOTTOMRIGHT:
823 add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
824 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TABW;
825 az->y1 = ar->winrct.ymax - add;
826 az->x2 = ar->winrct.xmax - AZONEPAD_TABW;
827 az->y2 = ar->winrct.ymax - add + AZONEPAD_TABH;
829 case AE_BOTTOM_TO_TOPLEFT:
830 az->x1 = ar->winrct.xmin + AZONEPAD_TABW;
831 az->y1 = ar->winrct.ymin - AZONEPAD_TABH;
832 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TABW;
833 az->y2 = ar->winrct.ymin;
835 case AE_LEFT_TO_TOPRIGHT:
836 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TABH;
837 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
838 az->x2 = ar->winrct.xmin + 1;
839 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
841 case AE_RIGHT_TO_TOPLEFT:
842 az->x1 = ar->winrct.xmax - 1;
843 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
844 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TABH;
845 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
848 /* rect needed for mouse pointer test */
849 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
852 #define AZONEPAD_TRIAW (0.8f * U.widget_unit)
853 #define AZONEPAD_TRIAH (0.45f * U.widget_unit)
856 /* region already made zero sized, in shape of edge */
857 static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar)
862 for (azt = sa->actionzones.first; azt; azt = azt->next) {
863 if (azt->edge == az->edge) tot++;
867 case AE_TOP_TO_BOTTOMRIGHT:
868 add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
869 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TRIAW;
870 az->y1 = ar->winrct.ymax - add;
871 az->x2 = ar->winrct.xmax - AZONEPAD_TRIAW;
872 az->y2 = ar->winrct.ymax - add + AZONEPAD_TRIAH;
874 case AE_BOTTOM_TO_TOPLEFT:
875 az->x1 = ar->winrct.xmin + AZONEPAD_TRIAW;
876 az->y1 = ar->winrct.ymin - AZONEPAD_TRIAH;
877 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TRIAW;
878 az->y2 = ar->winrct.ymin;
880 case AE_LEFT_TO_TOPRIGHT:
881 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TRIAH;
882 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
883 az->x2 = ar->winrct.xmin + 1;
884 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
886 case AE_RIGHT_TO_TOPLEFT:
887 az->x1 = ar->winrct.xmax - 1;
888 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
889 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TRIAH;
890 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
893 /* rect needed for mouse pointer test */
894 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
898 static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge, const bool is_fullscreen)
901 const bool is_hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) == 0;
903 if (is_hidden || !is_fullscreen) {
904 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
905 BLI_addtail(&(sa->actionzones), az);
906 az->type = AZONE_REGION;
912 if (!is_fullscreen) {
913 if (G.debug_value == 3)
914 region_azone_icon(sa, az, ar);
915 else if (G.debug_value == 2)
916 region_azone_tria(sa, az, ar);
917 else if (G.debug_value == 1)
918 region_azone_tab(sa, az, ar);
920 region_azone_tab_plus(sa, az, ar);
924 region_azone_edge(az, ar);
930 /* *************************************************************** */
932 static void region_azone_add(ScrArea *sa, ARegion *ar, const int alignment, const bool is_fullscreen)
934 /* edge code (t b l r) is along which area edge azone will be drawn */
936 if (alignment == RGN_ALIGN_TOP)
937 region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT, is_fullscreen);
938 else if (alignment == RGN_ALIGN_BOTTOM)
939 region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen);
940 else if (alignment == RGN_ALIGN_RIGHT)
941 region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT, is_fullscreen);
942 else if (alignment == RGN_ALIGN_LEFT)
943 region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT, is_fullscreen);
946 /* dir is direction to check, not the splitting edge direction! */
947 static int rct_fits(rcti *rect, char dir, int size)
950 return BLI_rcti_size_x(rect) + 1 - size;
953 return BLI_rcti_size_y(rect) + 1 - size;
957 /* *************************************************************** */
959 /* ar should be overlapping */
960 /* function checks if some overlapping region was defined before - on same place */
961 static void region_overlap_fix(ScrArea *sa, ARegion *ar)
964 const int align = ar->alignment & ~RGN_SPLIT_PREV;
967 /* find overlapping previous region on same place */
968 for (ar1 = ar->prev; ar1; ar1 = ar1->prev) {
969 if (ar1->overlap && ((ar1->alignment & RGN_SPLIT_PREV) == 0)) {
970 align1 = ar1->alignment;
971 if (BLI_rcti_isect(&ar1->winrct, &ar->winrct, NULL)) {
972 if (align1 != align) {
973 /* Left overlapping right or vice-versa, forbid this! */
974 ar->flag |= RGN_FLAG_TOO_SMALL;
977 /* Else, we have our previous region on same side. */
983 /* translate or close */
985 if (align1 == RGN_ALIGN_LEFT) {
986 if (ar->winrct.xmax + ar1->winx > sa->winx - U.widget_unit) {
987 ar->flag |= RGN_FLAG_TOO_SMALL;
991 BLI_rcti_translate(&ar->winrct, ar1->winx, 0);
994 else if (align1 == RGN_ALIGN_RIGHT) {
995 if (ar->winrct.xmin - ar1->winx < U.widget_unit) {
996 ar->flag |= RGN_FLAG_TOO_SMALL;
1000 BLI_rcti_translate(&ar->winrct, -ar1->winx, 0);
1005 /* At this point, 'ar' is in its final position and still open.
1006 * Make a final check it does not overlap any previous 'other side' region. */
1007 for (ar1 = ar->prev; ar1; ar1 = ar1->prev) {
1008 if (ar1->overlap && (ar1->alignment & RGN_SPLIT_PREV) == 0) {
1009 if ((ar1->alignment != align) && BLI_rcti_isect(&ar1->winrct, &ar->winrct, NULL)) {
1010 /* Left overlapping right or vice-versa, forbid this! */
1011 ar->flag |= RGN_FLAG_TOO_SMALL;
1018 /* overlapping regions only in the following restricted cases */
1019 static bool region_is_overlap(wmWindow *win, ScrArea *sa, ARegion *ar)
1021 if (U.uiflag2 & USER_REGION_OVERLAP) {
1022 if (WM_is_draw_triple(win)) {
1023 if (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_SEQ)) {
1024 if (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS))
1027 else if (sa->spacetype == SPACE_IMAGE) {
1028 if (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS, RGN_TYPE_PREVIEW))
1037 static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti *remainder, int quad)
1039 rcti *remainder_prev = remainder;
1040 int prefsizex, prefsizey;
1046 /* no returns in function, winrct gets set in the end again */
1047 BLI_rcti_init(&ar->winrct, 0, 0, 0, 0);
1049 /* for test; allow split of previously defined region */
1050 if (ar->alignment & RGN_SPLIT_PREV)
1052 remainder = &ar->prev->winrct;
1054 alignment = ar->alignment & ~RGN_SPLIT_PREV;
1056 /* set here, assuming userpref switching forces to call this again */
1057 ar->overlap = region_is_overlap(win, sa, ar);
1059 /* clear state flags first */
1060 ar->flag &= ~RGN_FLAG_TOO_SMALL;
1062 if (ar->next == NULL && alignment != RGN_ALIGN_QSPLIT)
1063 alignment = RGN_ALIGN_NONE;
1065 /* prefsize, for header we stick to exception (prevent dpi rounding error) */
1066 prefsizex = UI_DPI_FAC * (ar->sizex > 1 ? ar->sizex + 0.5f : ar->type->prefsizex);
1068 if (ar->regiontype == RGN_TYPE_HEADER) {
1069 prefsizey = ED_area_headersize();
1071 else if (ar->regiontype == RGN_TYPE_UI && sa->spacetype == SPACE_FILE) {
1072 prefsizey = UI_UNIT_Y * 2 + (UI_UNIT_Y / 2);
1075 prefsizey = UI_DPI_FAC * (ar->sizey > 1 ? ar->sizey + 0.5f : ar->type->prefsizey);
1079 if (ar->flag & RGN_FLAG_HIDDEN) {
1080 /* hidden is user flag */
1082 else if (alignment == RGN_ALIGN_FLOAT) {
1083 /* XXX floating area region, not handled yet here */
1085 else if (rct_fits(remainder, 'v', 1) < 0 || rct_fits(remainder, 'h', 1) < 0) {
1086 /* remainder is too small for any usage */
1087 ar->flag |= RGN_FLAG_TOO_SMALL;
1089 else if (alignment == RGN_ALIGN_NONE) {
1090 /* typically last region */
1091 ar->winrct = *remainder;
1092 BLI_rcti_init(remainder, 0, 0, 0, 0);
1094 else if (alignment == RGN_ALIGN_TOP || alignment == RGN_ALIGN_BOTTOM) {
1096 if (rct_fits(remainder, 'v', prefsizey) < 0) {
1097 ar->flag |= RGN_FLAG_TOO_SMALL;
1100 int fac = rct_fits(remainder, 'v', prefsizey);
1105 ar->winrct = *remainder;
1107 if (alignment == RGN_ALIGN_TOP) {
1108 ar->winrct.ymin = ar->winrct.ymax - prefsizey + 1;
1109 remainder->ymax = ar->winrct.ymin - 1;
1112 ar->winrct.ymax = ar->winrct.ymin + prefsizey - 1;
1113 remainder->ymin = ar->winrct.ymax + 1;
1117 else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
1119 if (rct_fits(remainder, 'h', prefsizex) < 0) {
1120 ar->flag |= RGN_FLAG_TOO_SMALL;
1123 int fac = rct_fits(remainder, 'h', prefsizex);
1128 ar->winrct = *remainder;
1130 if (alignment == RGN_ALIGN_RIGHT) {
1131 ar->winrct.xmin = ar->winrct.xmax - prefsizex + 1;
1132 if (ar->overlap == 0)
1133 remainder->xmax = ar->winrct.xmin - 1;
1136 ar->winrct.xmax = ar->winrct.xmin + prefsizex - 1;
1137 if (ar->overlap == 0)
1138 remainder->xmin = ar->winrct.xmax + 1;
1142 else if (alignment == RGN_ALIGN_VSPLIT || alignment == RGN_ALIGN_HSPLIT) {
1143 /* percentage subdiv*/
1144 ar->winrct = *remainder;
1146 if (alignment == RGN_ALIGN_HSPLIT) {
1147 if (rct_fits(remainder, 'h', prefsizex) > 4) {
1148 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1149 remainder->xmin = ar->winrct.xmax + 1;
1152 BLI_rcti_init(remainder, 0, 0, 0, 0);
1156 if (rct_fits(remainder, 'v', prefsizey) > 4) {
1157 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1158 remainder->ymin = ar->winrct.ymax + 1;
1161 BLI_rcti_init(remainder, 0, 0, 0, 0);
1165 else if (alignment == RGN_ALIGN_QSPLIT) {
1166 ar->winrct = *remainder;
1168 /* test if there's still 4 regions left */
1170 ARegion *artest = ar->next;
1174 artest->alignment = RGN_ALIGN_QSPLIT;
1175 artest = artest->next;
1180 /* let's stop adding regions */
1181 BLI_rcti_init(remainder, 0, 0, 0, 0);
1182 if (G.debug & G_DEBUG)
1183 printf("region quadsplit failed\n");
1190 if (quad == 1) { /* left bottom */
1191 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1192 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1194 else if (quad == 2) { /* left top */
1195 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1196 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1198 else if (quad == 3) { /* right bottom */
1199 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1200 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1202 else { /* right top */
1203 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1204 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1205 BLI_rcti_init(remainder, 0, 0, 0, 0);
1213 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1214 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1216 /* if region opened normally, we store this for hide/reveal usage */
1217 /* prevent rounding errors for UI_DPI_FAC mult and divide */
1218 if (ar->winx > 1) ar->sizex = (ar->winx + 0.5f) / UI_DPI_FAC;
1219 if (ar->winy > 1) ar->sizey = (ar->winy + 0.5f) / UI_DPI_FAC;
1221 /* exception for multiple overlapping regions on same spot */
1223 region_overlap_fix(sa, ar);
1225 /* set winrect for azones */
1226 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
1227 ar->winrct = *remainder;
1229 if (alignment == RGN_ALIGN_TOP)
1230 ar->winrct.ymin = ar->winrct.ymax;
1231 else if (alignment == RGN_ALIGN_BOTTOM)
1232 ar->winrct.ymax = ar->winrct.ymin;
1233 else if (alignment == RGN_ALIGN_RIGHT)
1234 ar->winrct.xmin = ar->winrct.xmax;
1235 else if (alignment == RGN_ALIGN_LEFT)
1236 ar->winrct.xmax = ar->winrct.xmin;
1237 else /* prevent winrct to be valid */
1238 ar->winrct.xmax = ar->winrct.xmin;
1241 /* restore prev-split exception */
1242 if (ar->alignment & RGN_SPLIT_PREV) {
1244 remainder = remainder_prev;
1245 ar->prev->winx = BLI_rcti_size_x(&ar->prev->winrct) + 1;
1246 ar->prev->winy = BLI_rcti_size_y(&ar->prev->winrct) + 1;
1250 /* in end, add azones, where appropriate */
1251 if (ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
1252 /* The logic for this is: when the header takes up the full area,
1253 * disallow hiding it to view the main window.
1255 * Without this, you can drag down the file selectors header and hide it
1256 * by accident very easily (highly annoying!), the value 6 is arbitrary
1257 * but accounts for small common rounding problems when scaling the UI,
1258 * must be minimum '4' */
1261 if (ELEM(win->screen->state, SCREENNORMAL, SCREENMAXIMIZED)) {
1262 region_azone_add(sa, ar, alignment, false);
1265 region_azone_add(sa, ar, alignment, true);
1266 fullscreen_azone_initialize(sa, ar);
1270 region_rect_recursive(win, sa, ar->next, remainder, quad);
1273 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
1275 short rt = (short) U.pixelsize;
1277 if (sa->v1->vec.x > 0) sa->totrct.xmin = sa->v1->vec.x + rt;
1278 else sa->totrct.xmin = sa->v1->vec.x;
1279 if (sa->v4->vec.x < sizex - 1) sa->totrct.xmax = sa->v4->vec.x - rt;
1280 else sa->totrct.xmax = sa->v4->vec.x;
1282 if (sa->v1->vec.y > 0) sa->totrct.ymin = sa->v1->vec.y + rt;
1283 else sa->totrct.ymin = sa->v1->vec.y;
1284 if (sa->v2->vec.y < sizey - 1) sa->totrct.ymax = sa->v2->vec.y - rt;
1285 else sa->totrct.ymax = sa->v2->vec.y;
1288 sa->winx = BLI_rcti_size_x(&sa->totrct) + 1;
1289 sa->winy = BLI_rcti_size_y(&sa->totrct) + 1;
1293 /* used for area initialize below */
1294 static void region_subwindow(wmWindow *win, ARegion *ar)
1296 bool hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) != 0;
1298 if ((ar->alignment & RGN_SPLIT_PREV) && ar->prev)
1299 hidden = hidden || (ar->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
1303 wm_subwindow_close(win, ar->swinid);
1306 else if (ar->swinid == 0)
1307 ar->swinid = wm_subwindow_open(win, &ar->winrct);
1309 wm_subwindow_position(win, ar->swinid, &ar->winrct);
1312 static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
1314 /* note, add-handler checks if it already exists */
1316 /* XXX it would be good to have boundbox checks for some of these... */
1317 if (flag & ED_KEYMAP_UI) {
1318 /* user interface widgets */
1319 UI_region_handlers_add(handlers);
1321 if (flag & ED_KEYMAP_VIEW2D) {
1322 /* 2d-viewport handling+manipulation */
1323 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "View2D", 0, 0);
1324 WM_event_add_keymap_handler(handlers, keymap);
1326 if (flag & ED_KEYMAP_MARKERS) {
1328 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Markers", 0, 0);
1330 /* time space only has this keymap, the others get a boundbox restricted map */
1331 if (sa->spacetype != SPACE_TIME) {
1333 /* same local check for all areas */
1334 static rcti rect = {0, 10000, 0, -1};
1335 rect.ymax = UI_MARKER_MARGIN_Y;
1336 ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
1338 WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
1342 WM_event_add_keymap_handler(handlers, keymap);
1344 if (flag & ED_KEYMAP_ANIMATION) {
1345 /* frame changing and timeline operators (for time spaces) */
1346 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Animation", 0, 0);
1347 WM_event_add_keymap_handler(handlers, keymap);
1349 if (flag & ED_KEYMAP_FRAMES) {
1350 /* frame changing/jumping (for all spaces) */
1351 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Frames", 0, 0);
1352 WM_event_add_keymap_handler(handlers, keymap);
1354 if (flag & ED_KEYMAP_GPENCIL) {
1356 /* NOTE: This is now 2 keymaps - One for basic functionality,
1357 * and one that only applies when "Edit Mode" is enabled
1360 * For now, it's easier to just include both,
1361 * since you hardly want one without the other.
1363 wmKeyMap *keymap_general = WM_keymap_find(wm->defaultconf, "Grease Pencil", 0, 0);
1364 wmKeyMap *keymap_edit = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Edit Mode", 0, 0);
1366 WM_event_add_keymap_handler(handlers, keymap_general);
1367 WM_event_add_keymap_handler(handlers, keymap_edit);
1369 if (flag & ED_KEYMAP_HEADER) {
1370 /* standard keymap for headers regions */
1371 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Header", 0, 0);
1372 WM_event_add_keymap_handler(handlers, keymap);
1377 /* called in screen_refresh, or screens_init, also area size changes */
1378 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
1383 /* set typedefinitions */
1384 sa->type = BKE_spacetype_from_id(sa->spacetype);
1386 if (sa->type == NULL) {
1387 sa->butspacetype = sa->spacetype = SPACE_VIEW3D;
1388 sa->type = BKE_spacetype_from_id(sa->spacetype);
1391 for (ar = sa->regionbase.first; ar; ar = ar->next)
1392 ar->type = BKE_regiontype_from_id(sa->type, ar->regiontype);
1395 area_calc_totrct(sa, WM_window_pixels_x(win), WM_window_pixels_y(win));
1397 /* clear all azones, add the area triange widgets */
1398 area_azone_initialize(win, win->screen, sa);
1400 /* region rect sizes */
1402 region_rect_recursive(win, sa, sa->regionbase.first, &rect, 0);
1404 /* default area handlers */
1405 ed_default_handlers(wm, sa, &sa->handlers, sa->type->keymapflag);
1406 /* checks spacedata, adds own handlers */
1408 sa->type->init(wm, sa);
1410 /* region windows, default and own handlers */
1411 for (ar = sa->regionbase.first; ar; ar = ar->next) {
1412 region_subwindow(win, ar);
1415 /* default region handlers */
1416 ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
1419 ar->type->init(wm, ar);
1422 /* prevent uiblocks to run */
1423 UI_blocklist_free(NULL, &ar->uiblocks);
1428 static void region_update_rect(ARegion *ar)
1430 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1431 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1433 /* v2d mask is used to subtract scrollbars from a 2d view. Needs initialize here. */
1434 BLI_rcti_init(&ar->v2d.mask, 0, ar->winx - 1, 0, ar->winy -1);
1438 * Call to move a popup window (keep OpenGL context free!)
1440 void ED_region_update_rect(bContext *C, ARegion *ar)
1442 wmWindow *win = CTX_wm_window(C);
1444 wm_subwindow_rect_set(win, ar->swinid, &ar->winrct);
1446 region_update_rect(ar);
1449 /* externally called for floating regions like menus */
1450 void ED_region_init(bContext *C, ARegion *ar)
1452 // ARegionType *at = ar->type;
1454 /* refresh can be called before window opened */
1455 region_subwindow(CTX_wm_window(C), ar);
1457 region_update_rect(ar);
1460 /* for quick toggle, can skip fades */
1461 void region_toggle_hidden(bContext *C, ARegion *ar, const bool do_fade)
1463 ScrArea *sa = CTX_wm_area(C);
1465 ar->flag ^= RGN_FLAG_HIDDEN;
1467 if (do_fade && ar->overlap) {
1468 /* starts a timer, and in end calls the stuff below itself (region_sblend_invoke()) */
1469 region_blend_start(C, sa, ar);
1472 if (ar->flag & RGN_FLAG_HIDDEN)
1473 WM_event_remove_handlers(C, &ar->handlers);
1475 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1476 ED_area_tag_redraw(sa);
1480 /* exported to all editors, uses fading default */
1481 void ED_region_toggle_hidden(bContext *C, ARegion *ar)
1483 region_toggle_hidden(C, ar, true);
1487 * we swap spaces for fullscreen to keep all allocated data area vertices were set
1489 void ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free)
1493 const char spacetype = sa_dst->spacetype;
1494 const short flag_copy = HEADER_NO_PULLDOWN;
1496 sa_dst->headertype = sa_src->headertype;
1497 sa_dst->spacetype = sa_src->spacetype;
1498 sa_dst->type = sa_src->type;
1499 sa_dst->butspacetype = sa_src->butspacetype;
1501 sa_dst->flag = (sa_dst->flag & ~flag_copy) | (sa_src->flag & flag_copy);
1505 BKE_spacedata_freelist(&sa_dst->spacedata);
1507 BKE_spacedata_copylist(&sa_dst->spacedata, &sa_src->spacedata);
1509 /* Note; SPACE_EMPTY is possible on new screens */
1513 st = BKE_spacetype_from_id(spacetype);
1514 for (ar = sa_dst->regionbase.first; ar; ar = ar->next)
1515 BKE_area_region_free(st, ar);
1516 BLI_freelistN(&sa_dst->regionbase);
1518 st = BKE_spacetype_from_id(sa_src->spacetype);
1519 for (ar = sa_src->regionbase.first; ar; ar = ar->next) {
1520 ARegion *newar = BKE_area_region_copy(st, ar);
1521 BLI_addtail(&sa_dst->regionbase, newar);
1525 void ED_area_data_swap(ScrArea *sa_dst, ScrArea *sa_src)
1527 SWAP(short, sa_dst->headertype, sa_src->headertype);
1528 SWAP(char, sa_dst->spacetype, sa_src->spacetype);
1529 SWAP(SpaceType *, sa_dst->type, sa_src->type);
1530 SWAP(char, sa_dst->butspacetype, sa_src->butspacetype);
1533 SWAP(ListBase, sa_dst->spacedata, sa_src->spacedata);
1534 SWAP(ListBase, sa_dst->regionbase, sa_src->regionbase);
1537 /* *********** Space switching code *********** */
1539 void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
1541 ScrArea *tmp = MEM_callocN(sizeof(ScrArea), "addscrarea");
1543 ED_area_exit(C, sa1);
1544 ED_area_exit(C, sa2);
1546 ED_area_data_copy(tmp, sa1, false);
1547 ED_area_data_copy(sa1, sa2, true);
1548 ED_area_data_copy(sa2, tmp, true);
1549 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa1);
1550 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa2);
1552 BKE_screen_area_free(tmp);
1555 /* tell WM to refresh, cursor types etc */
1556 WM_event_add_mousemove(C);
1558 ED_area_tag_redraw(sa1);
1559 ED_area_tag_refresh(sa1);
1560 ED_area_tag_redraw(sa2);
1561 ED_area_tag_refresh(sa2);
1564 void ED_area_newspace(bContext *C, ScrArea *sa, int type)
1566 if (sa->spacetype != type) {
1571 ED_area_exit(C, sa);
1573 st = BKE_spacetype_from_id(type);
1574 slold = sa->spacedata.first;
1576 sa->spacetype = type;
1577 sa->butspacetype = type;
1580 /* check previously stored space */
1581 for (sl = sa->spacedata.first; sl; sl = sl->next)
1582 if (sl->spacetype == type)
1585 /* old spacedata... happened during work on 2.50, remove */
1586 if (sl && BLI_listbase_is_empty(&sl->regionbase)) {
1588 BLI_freelinkN(&sa->spacedata, sl);
1597 slold->regionbase = sa->regionbase;
1598 sa->regionbase = sl->regionbase;
1599 BLI_listbase_clear(&sl->regionbase);
1601 /* put in front of list */
1602 BLI_remlink(&sa->spacedata, sl);
1603 BLI_addhead(&sa->spacedata, sl);
1609 BLI_addhead(&sa->spacedata, sl);
1613 slold->regionbase = sa->regionbase;
1614 sa->regionbase = sl->regionbase;
1615 BLI_listbase_clear(&sl->regionbase);
1619 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1621 /* tell WM to refresh, cursor types etc */
1622 WM_event_add_mousemove(C);
1624 /* send space change notifier */
1625 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1627 ED_area_tag_refresh(sa);
1630 /* also redraw when re-used */
1631 ED_area_tag_redraw(sa);
1634 void ED_area_prevspace(bContext *C, ScrArea *sa)
1636 SpaceLink *sl = sa->spacedata.first;
1638 if (sl && sl->next) {
1639 /* workaround for case of double prevspace, render window
1640 * with a file browser on top of it */
1641 if (sl->next->spacetype == SPACE_FILE && sl->next->next)
1642 ED_area_newspace(C, sa, sl->next->next->spacetype);
1644 ED_area_newspace(C, sa, sl->next->spacetype);
1650 sa->flag &= ~AREA_FLAG_STACKED_FULLSCREEN;
1652 ED_area_tag_redraw(sa);
1654 /* send space change notifier */
1655 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1658 /* returns offset for next button in header */
1659 int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
1661 ScrArea *sa = CTX_wm_area(C);
1662 bScreen *scr = CTX_wm_screen(C);
1664 int xco = 0.4 * U.widget_unit;
1666 RNA_pointer_create(&(scr->id), &RNA_Area, sa, &areaptr);
1668 uiDefButR(block, UI_BTYPE_MENU, 0, "", xco, yco, 1.5 * U.widget_unit, U.widget_unit,
1669 &areaptr, "type", 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
1671 return xco + 1.7 * U.widget_unit;
1674 /************************ standard UI regions ************************/
1676 void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
1678 ScrArea *sa = CTX_wm_area(C);
1679 uiStyle *style = UI_style_get_dpi();
1683 View2D *v2d = &ar->v2d;
1684 View2DScrollers *scrollers;
1685 int x, y, xco, yco, w, em, triangle;
1686 bool is_context_new = 0;
1690 bool use_category_tabs = (ar->regiontype == RGN_TYPE_TOOLS); /* XXX, should use some better check? */
1691 /* offset panels for small vertical tab area */
1692 const char *category = NULL;
1693 const int category_tabs_width = UI_PANEL_CATEGORY_MARGIN_WIDTH;
1696 BLI_SMALLSTACK_DECLARE(pt_stack, PanelType *);
1698 if (contextnr != -1)
1699 is_context_new = UI_view2d_tab_set(v2d, contextnr);
1701 /* before setting the view */
1703 /* only allow scrolling in vertical direction */
1704 v2d->keepofs |= V2D_LOCKOFS_X | V2D_KEEPOFS_Y;
1705 v2d->keepofs &= ~(V2D_LOCKOFS_Y | V2D_KEEPOFS_X);
1706 v2d->scroll &= ~(V2D_SCROLL_BOTTOM);
1707 v2d->scroll |= (V2D_SCROLL_RIGHT);
1710 /* for now, allow scrolling in both directions (since layouts are optimized for vertical,
1711 * they often don't fit in horizontal layout)
1713 v2d->keepofs &= ~(V2D_LOCKOFS_X | V2D_LOCKOFS_Y | V2D_KEEPOFS_X | V2D_KEEPOFS_Y);
1714 v2d->scroll |= (V2D_SCROLL_BOTTOM);
1715 v2d->scroll &= ~(V2D_SCROLL_RIGHT);
1718 scroll = v2d->scroll;
1721 /* collect panels to draw */
1722 for (pt = ar->type->paneltypes.last; pt; pt = pt->prev) {
1723 /* verify context */
1724 if (context && pt->context[0] && !STREQ(context, pt->context)) {
1729 if (pt->draw && (!pt->poll || pt->poll(C, pt))) {
1730 BLI_SMALLSTACK_PUSH(pt_stack, pt);
1735 /* collect categories */
1736 if (use_category_tabs) {
1737 UI_panel_category_clear_all(ar);
1739 /* gather unique categories */
1740 BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt)
1742 if (pt->category[0]) {
1743 if (!UI_panel_category_find(ar, pt->category)) {
1744 UI_panel_category_add(ar, pt->category);
1748 BLI_SMALLSTACK_ITER_END;
1750 if (!UI_panel_category_is_visible(ar)) {
1751 use_category_tabs = false;
1754 category = UI_panel_category_active_get(ar, true);
1755 margin_x = category_tabs_width;
1760 /* sortof hack - but we cannot predict the height of panels, until it's being generated */
1761 /* the layout engine works with fixed width (from v2d->cur), which is being set at end of the loop */
1762 /* in case scroller settings (hide flags) differ from previous, the whole loop gets done again */
1763 for (redo = 2; redo > 0; redo--) {
1766 w = BLI_rctf_size_x(&v2d->cur);
1767 em = (ar->type->prefsizex) ? 10 : 20; /* works out to 10*UI_UNIT_X or 20*UI_UNIT_X */
1771 em = (ar->type->prefsizex) ? 10 : 20;
1777 UI_panels_begin(C, ar);
1779 /* set view2d view matrix - UI_block_begin() stores it */
1780 UI_view2d_view_ortho(v2d);
1782 BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt)
1786 panel = UI_panel_find_by_type(ar, pt);
1788 if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) {
1789 if ((panel == NULL) || ((panel->flag & PNL_PIN) == 0)) {
1795 block = UI_block_begin(C, ar, pt->idname, UI_EMBOSS);
1796 panel = UI_panel_begin(sa, ar, block, pt, panel, &open);
1798 /* bad fixed values */
1799 triangle = (int)(UI_UNIT_Y * 1.1f);
1801 if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
1802 /* for enabled buttons */
1803 panel->layout = UI_block_layout(
1804 block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
1805 triangle, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, 0, style);
1807 pt->draw_header(C, panel);
1809 UI_block_layout_resolve(block, &xco, &yco);
1810 panel->labelofs = xco - triangle;
1811 panel->layout = NULL;
1814 panel->labelofs = 0;
1820 /* panel context can either be toolbar region or normal panels region */
1821 if (ar->regiontype == RGN_TYPE_TOOLS)
1822 panelContext = UI_LAYOUT_TOOLBAR;
1824 panelContext = UI_LAYOUT_PANEL;
1826 panel->layout = UI_block_layout(
1827 block, UI_LAYOUT_VERTICAL, panelContext,
1828 style->panelspace, 0, w - 2 * style->panelspace, em, 0, style);
1832 UI_block_layout_resolve(block, &xco, &yco);
1833 panel->layout = NULL;
1835 yco -= 2 * style->panelspace;
1836 UI_panel_end(block, w, -yco);
1840 UI_panel_end(block, w, 0);
1843 UI_block_end(C, block);
1845 BLI_SMALLSTACK_ITER_END;
1847 /* align panels and return size */
1848 UI_panels_end(C, ar, &x, &y);
1850 /* before setting the view */
1852 /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */
1853 if (v2d->cur.ymax < - 0.001f)
1854 y = min_ii(y, v2d->cur.ymin);
1859 /* don't jump back when panels close or hide */
1860 if (!is_context_new)
1861 x = max_ii(x, v2d->cur.xmax);
1865 /* this also changes the 'cur' */
1866 UI_view2d_totRect_set(v2d, x, y);
1868 if (scroll != v2d->scroll) {
1869 /* Note: this code scales fine, but because of rounding differences, positions of elements
1870 * flip +1 or -1 pixel compared to redoing the entire layout again.
1871 * Leaving in commented code for future tests */
1873 UI_panels_scale(ar, BLI_rctf_size_x(&v2d->cur));
1884 /* view should be in pixelspace */
1885 UI_view2d_view_restore(C);
1887 UI_ThemeColor4((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
1888 glRecti(0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct));
1889 glDisable(GL_BLEND);
1892 UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
1893 glClear(GL_COLOR_BUFFER_BIT);
1898 UI_view2d_view_ortho(v2d);
1901 UI_panels_draw(C, ar);
1903 /* restore view matrix */
1904 UI_view2d_view_restore(C);
1906 if (use_category_tabs) {
1907 UI_panel_category_draw_all(ar, category);
1911 scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1912 UI_view2d_scrollers_draw(C, v2d, scrollers);
1913 UI_view2d_scrollers_free(scrollers);
1916 void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
1920 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy);
1922 keymap = WM_keymap_find(wm->defaultconf, "View2D Buttons List", 0, 0);
1923 WM_event_add_keymap_handler(&ar->handlers, keymap);
1926 void ED_region_header(const bContext *C, ARegion *ar)
1928 uiStyle *style = UI_style_get_dpi();
1932 Header header = {NULL};
1933 int maxco, xco, yco;
1934 int headery = ED_area_headersize();
1937 UI_ThemeClearColor((ED_screen_area_active(C)) ? TH_HEADER : TH_HEADERDESEL);
1938 glClear(GL_COLOR_BUFFER_BIT);
1940 /* set view2d view matrix for scrolling (without scrollers) */
1941 UI_view2d_view_ortho(&ar->v2d);
1943 xco = maxco = 0.4f * UI_UNIT_X;
1944 yco = headery - floor(0.2f * UI_UNIT_Y);
1946 /* draw all headers types */
1947 for (ht = ar->type->headertypes.first; ht; ht = ht->next) {
1948 block = UI_block_begin(C, ar, ht->idname, UI_EMBOSS);
1949 layout = UI_block_layout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, UI_UNIT_Y, 1, 0, style);
1953 header.layout = layout;
1954 ht->draw(C, &header);
1957 xco = uiLayoutGetWidth(layout);
1962 UI_block_layout_resolve(block, &xco, &yco);
1968 UI_block_end(C, block);
1969 UI_block_draw(C, block);
1972 /* always as last */
1973 UI_view2d_totRect_set(&ar->v2d, maxco + UI_UNIT_X + 80, headery);
1975 /* restore view matrix? */
1976 UI_view2d_view_restore(C);
1979 void ED_region_header_init(ARegion *ar)
1981 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
1984 /* UI_UNIT_Y is defined as U variable now, depending dpi */
1985 int ED_area_headersize(void)
1987 return (int)(HEADERY * UI_DPI_FAC);
1990 void ED_region_info_draw(ARegion *ar, const char *text, int block, float fill_color[4])
1992 const int header_height = UI_UNIT_Y;
1993 uiStyle *style = UI_style_get_dpi();
1994 int fontid = style->widget.uifont_id;
1998 /* background box */
1999 ED_region_visible_rect(ar, &rect);
2000 rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
2002 /* box fill entire width or just around text */
2004 rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
2006 rect.ymax = BLI_rcti_size_y(&ar->winrct);
2009 glGetIntegerv(GL_SCISSOR_BOX, scissor);
2010 glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin,
2011 BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1);
2014 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2015 glColor4fv(fill_color);
2016 glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
2017 glDisable(GL_BLEND);
2020 UI_ThemeColor(TH_TEXT_HI);
2021 BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2022 BLF_enable(fontid, BLF_CLIPPING);
2023 BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit, 0.0f);
2025 BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
2027 BLF_disable(fontid, BLF_CLIPPING);
2029 /* restore scissor as it was before */
2030 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
2033 #define MAX_METADATA_STR 1024
2035 const char *meta_data_list[] =
2049 BLI_INLINE bool metadata_is_valid(ImBuf *ibuf, char *r_str, short index, int offset)
2051 return (IMB_metadata_get_field(ibuf, meta_data_list[index], r_str + offset, MAX_METADATA_STR - offset) && r_str[0]);
2054 static void metadata_draw_imbuf(ImBuf *ibuf, rcti rect, int fontid, const bool is_top, float factor)
2056 char temp_str[MAX_METADATA_STR];
2061 const float height = BLF_height_max(fontid);
2064 for (i = 0; i < 4; i++) {
2067 bool do_newline = false;
2068 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]);
2069 if (metadata_is_valid(ibuf, temp_str, 0, len)) {
2070 BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
2071 rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
2072 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2076 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]);
2077 if (metadata_is_valid(ibuf, temp_str, 1, len)) {
2078 line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2079 BLF_position(fontid, rect.xmax - line_width - (0.2f * U.widget_unit),
2080 rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
2081 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2086 ofs_y += (height + (0.2f * U.widget_unit));
2089 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]);
2090 if (metadata_is_valid(ibuf, temp_str, i + 1, len)) {
2091 BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
2092 rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
2093 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2094 ofs_y += (height + (0.2f * U.widget_unit));
2098 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]);
2099 if (metadata_is_valid(ibuf, temp_str, i + 1, len)) {
2100 BLF_position(fontid, rect.xmax + (0.2f * U.widget_unit),
2101 rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
2102 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2103 ofs_y += (height + (0.2f * U.widget_unit));
2110 for (i = 5; i < 10; i++) {
2111 len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]);
2112 if (metadata_is_valid(ibuf, temp_str, i, len)) {
2113 const int line_height = height;
2114 BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit) + ofs_x,
2115 rect.ymin - line_height + factor * (1.5f * U.widget_unit), 0.0f);
2116 BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
2118 ofs_x += BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX) + UI_UNIT_X;
2124 static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top)
2126 char str[MAX_METADATA_STR];
2131 for (i = 0; i < 5 ; i++) {
2132 if (metadata_is_valid(ibuf, str, i, 0)) {
2133 height += BLF_height(fontid, str, strlen(str));
2138 for (i = 5; i < 10; i++) {
2139 if (metadata_is_valid(ibuf, str, i, 0)) {
2140 height += BLF_height(fontid, str, strlen(str));
2146 return (height + (0.2f * U.widget_unit));
2152 #undef MAX_METADATA_STR
2154 void ED_region_image_metadata_draw(ARegion *ar, ImBuf *ibuf, float zoomx, float zoomy)
2156 uiStyle *style = UI_style_get_dpi();
2157 int fontid = style->widget.uifont_id;
2162 if (!ibuf->metadata)
2165 /* find window pixel coordinates of origin */
2166 UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
2170 /* offset and zoom using ogl */
2171 glTranslatef(x, y, 0.0f);
2172 glScalef(zoomx, zoomy, 1.0f);
2174 BLF_size(fontid, style->widgetlabel.points, U.dpi * zoomy);
2176 /* *** upper box*** */
2178 /* get needed box height */
2179 box_y = metadata_box_height_get(ibuf, fontid, true);
2182 UI_ThemeColor(TH_METADATA_BG);
2185 BLI_rcti_init(&rect, 0, ibuf->x, ibuf->y, ibuf->y + box_y);
2187 glRecti(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2189 BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2190 BLF_enable(fontid, BLF_CLIPPING);
2192 UI_ThemeColor(TH_METADATA_TEXT);
2193 metadata_draw_imbuf(ibuf, rect, fontid, true, zoomy);
2195 BLF_disable(fontid, BLF_CLIPPING);
2199 /* *** lower box*** */
2201 box_y = metadata_box_height_get(ibuf, fontid, false);
2204 UI_ThemeColor(TH_METADATA_BG);
2206 /* set up box rect */
2207 BLI_rcti_init(&rect, 0, ibuf->x, -box_y, 0);
2209 glRecti(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2211 BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
2212 BLF_enable(fontid, BLF_CLIPPING);
2214 UI_ThemeColor(TH_METADATA_TEXT);
2215 metadata_draw_imbuf(ibuf, rect, fontid, false, zoomy);
2217 BLF_disable(fontid, BLF_CLIPPING);
2223 void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
2225 float gridsize, gridstep = 1.0f / 32.0f;
2226 float fac, blendfac;
2229 /* the image is located inside (0, 0), (1, 1) as set by view2d */
2230 UI_ThemeColorShade(TH_BACK, 20);
2232 UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
2233 UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2);
2234 glRectf(x1, y1, x2, y2);
2236 /* gridsize adapted to zoom level */
2237 gridsize = 0.5f * (zoomx + zoomy);
2238 if (gridsize <= 0.0f)
2241 if (gridsize < 1.0f) {
2242 while (gridsize < 1.0f) {
2248 while (gridsize >= 4.0f) {
2254 /* the fine resolution level */
2255 blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
2256 CLAMP(blendfac, 0.0f, 1.0f);
2257 UI_ThemeColorShade(TH_BACK, (int)(20.0f * (1.0f - blendfac)));
2261 while (fac < 1.0f) {
2262 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
2263 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
2264 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
2265 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
2269 /* the large resolution level */
2270 UI_ThemeColor(TH_BACK);
2273 while (fac < 1.0f) {
2274 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
2275 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
2276 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
2277 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
2278 fac += 4.0f * gridstep;
2283 /* If the area has overlapping regions, it returns visible rect for Region *ar */
2284 /* rect gets returned in local region coordinates */
2285 void ED_region_visible_rect(ARegion *ar, rcti *rect)
2289 /* allow function to be called without area */
2295 /* check if a region overlaps with the current one */
2296 for (; arn; arn = arn->next) {
2297 if (ar != arn && arn->overlap) {
2298 if (BLI_rcti_isect(rect, &arn->winrct, NULL)) {
2300 /* overlap left, also check 1 pixel offset (2 regions on one side) */
2301 if (ABS(rect->xmin - arn->winrct.xmin) < 2)
2302 rect->xmin = arn->winrct.xmax;
2305 if (ABS(rect->xmax - arn->winrct.xmax) < 2)
2306 rect->xmax = arn->winrct.xmin;
2310 BLI_rcti_translate(rect, -ar->winrct.xmin, -ar->winrct.ymin);
2313 /* Cache display helpers */
2315 void ED_region_cache_draw_background(const ARegion *ar)
2317 glColor4ub(128, 128, 255, 64);
2318 glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
2321 void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
2323 uiStyle *style = UI_style_get();
2324 int fontid = style->widget.uifont_id;
2326 float font_dims[2] = {0.0f, 0.0f};
2329 BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
2330 BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
2332 BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
2334 glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
2336 UI_ThemeColor(TH_TEXT);
2337 BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
2338 BLF_draw(fontid, numstr, sizeof(numstr));
2341 void ED_region_cache_draw_cached_segments(const ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra)
2346 glColor4ub(128, 128, 255, 128);
2348 for (a = 0; a < num_segments; a++) {
2351 x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
2352 x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
2354 glRecti(x1, 0, x2, 8 * UI_DPI_FAC);