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"
43 #include "BLF_translation.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"
60 #include "ED_fileselect.h"
63 #include "BIF_glutil.h"
66 #include "UI_interface.h"
67 #include "UI_resources.h"
68 #include "UI_view2d.h"
70 #include "screen_intern.h"
72 extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
74 /* general area and region code */
76 static void region_draw_emboss(ARegion *ar, rcti *scirct)
80 /* translate scissor rect to region space */
81 rect.xmin = scirct->xmin - ar->winrct.xmin;
82 rect.ymin = scirct->ymin - ar->winrct.ymin;
83 rect.xmax = scirct->xmax - ar->winrct.xmin;
84 rect.ymax = scirct->ymax - ar->winrct.ymin;
88 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
91 glColor4ub(0, 0, 0, 30);
92 sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
95 glColor4ub(0, 0, 0, 30);
96 sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
99 glColor4ub(255, 255, 255, 30);
100 sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
103 glColor4ub(255, 255, 255, 30);
104 sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
109 void ED_region_pixelspace(ARegion *ar)
111 int width = BLI_rcti_size_x(&ar->winrct) + 1;
112 int height = BLI_rcti_size_y(&ar->winrct) + 1;
114 wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
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 * \brief Corner widgets use for dragging and splitting the view.
158 static void area_draw_azone(short x1, short y1, short x2, short y2)
163 dx = copysign(ceilf(0.3f * fabsf(dx)), dx);
164 dy = copysign(ceilf(0.3f * fabsf(dy)), dy);
167 glEnable(GL_LINE_SMOOTH);
169 glColor4ub(255, 255, 255, 180);
170 fdrawline(x1, y2, x2, y1);
171 glColor4ub(255, 255, 255, 130);
172 fdrawline(x1, y2 - dy, x2 - dx, y1);
173 glColor4ub(255, 255, 255, 80);
174 fdrawline(x1, y2 - 2 * dy, x2 - 2 * dx, y1);
176 glColor4ub(0, 0, 0, 210);
177 fdrawline(x1, y2 + 1, x2 + 1, y1);
178 glColor4ub(0, 0, 0, 180);
179 fdrawline(x1, y2 - dy + 1, x2 - dx + 1, y1);
180 glColor4ub(0, 0, 0, 150);
181 fdrawline(x1, y2 - 2 * dy + 1, x2 - 2 * dx + 1, y1);
183 glDisable(GL_LINE_SMOOTH);
187 static void region_draw_azone_icon(AZone *az)
189 GLUquadricObj *qobj = NULL;
190 short midx = az->x1 + (az->x2 - az->x1) / 2;
191 short midy = az->y1 + (az->y2 - az->y1) / 2;
193 qobj = gluNewQuadric();
196 glTranslatef(midx, midy, 0.0);
198 /* outlined circle */
199 glEnable(GL_LINE_SMOOTH);
201 glColor4f(1.f, 1.f, 1.f, 0.8f);
203 gluQuadricDrawStyle(qobj, GLU_FILL);
204 gluDisk(qobj, 0.0, 4.25f, 16, 1);
206 glColor4f(0.2f, 0.2f, 0.2f, 0.9f);
208 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
209 gluDisk(qobj, 0.0, 4.25f, 16, 1);
211 glDisable(GL_LINE_SMOOTH);
214 gluDeleteQuadric(qobj);
217 sdrawline(midx, midy - 2, midx, midy + 3);
218 sdrawline(midx - 2, midy, midx + 3, midy);
221 static void draw_azone_plus(float x1, float y1, float x2, float y2)
223 float width = 0.1f * U.widget_unit;
224 float pad = 0.2f * U.widget_unit;
226 glRectf((x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
227 glRectf(x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
228 glRectf((x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
231 static void region_draw_azone_tab_plus(AZone *az)
235 /* add code to draw region hidden as 'too small' */
237 case AE_TOP_TO_BOTTOMRIGHT:
238 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
240 case AE_BOTTOM_TO_TOPLEFT:
241 uiSetRoundBox(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
243 case AE_LEFT_TO_TOPRIGHT:
244 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
246 case AE_RIGHT_TO_TOPLEFT:
247 uiSetRoundBox(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
251 glColor4f(0.05f, 0.05f, 0.05f, 0.4f);
252 uiRoundBox((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
256 glColor4f(0.8f, 0.8f, 0.8f, 0.4f);
257 draw_azone_plus((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2);
262 static void region_draw_azone_tab(AZone *az)
267 UI_GetThemeColor3fv(TH_HEADER, col);
268 glColor4f(col[0], col[1], col[2], 0.5f);
270 /* add code to draw region hidden as 'too small' */
272 case AE_TOP_TO_BOTTOMRIGHT:
273 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_RB_ALPHA);
275 uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
276 glColor4ub(0, 0, 0, 255);
277 uiRoundRect((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
279 case AE_BOTTOM_TO_TOPLEFT:
280 uiSetRoundBox(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
282 uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
283 glColor4ub(0, 0, 0, 255);
284 uiRoundRect((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
286 case AE_LEFT_TO_TOPRIGHT:
287 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
289 uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
290 glColor4ub(0, 0, 0, 255);
291 uiRoundRect((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
293 case AE_RIGHT_TO_TOPLEFT:
294 uiSetRoundBox(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_RB_ALPHA);
296 uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
297 glColor4ub(0, 0, 0, 255);
298 uiRoundRect((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
305 static void region_draw_azone_tria(AZone *az)
308 //UI_GetThemeColor3fv(TH_HEADER, col);
309 glColor4f(0.0f, 0.0f, 0.0f, 0.35f);
311 /* add code to draw region hidden as 'too small' */
313 case AE_TOP_TO_BOTTOMRIGHT:
314 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);
317 case AE_BOTTOM_TO_TOPLEFT:
318 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);
321 case AE_LEFT_TO_TOPRIGHT:
322 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);
325 case AE_RIGHT_TO_TOPLEFT:
326 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);
334 static void region_draw_azones(ScrArea *sa, ARegion *ar)
342 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
345 glTranslatef(-ar->winrct.xmin, -ar->winrct.ymin, 0.0f);
347 for (az = sa->actionzones.first; az; az = az->next) {
348 /* test if action zone is over this region */
350 BLI_rcti_init(&azrct, az->x1, az->x2, az->y1, az->y2);
352 if (BLI_rcti_isect(&ar->drawrct, &azrct, NULL)) {
353 if (az->type == AZONE_AREA) {
354 area_draw_azone(az->x1, az->y1, az->x2, az->y2);
356 else if (az->type == AZONE_REGION) {
359 /* only display tab or icons when the region is hidden */
360 if (az->ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
361 if (G.debug_value == 3)
362 region_draw_azone_icon(az);
363 else if (G.debug_value == 2)
364 region_draw_azone_tria(az);
365 else if (G.debug_value == 1)
366 region_draw_azone_tab(az);
368 region_draw_azone_tab_plus(az);
380 /* only exported for WM */
381 /* makes region ready for drawing, sets pixelspace */
382 void ED_region_set(const bContext *C, ARegion *ar)
384 wmWindow *win = CTX_wm_window(C);
385 ScrArea *sa = CTX_wm_area(C);
387 ar->drawrct = ar->winrct;
389 /* note; this sets state, so we can use wmOrtho and friends */
390 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct);
392 UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
394 ED_region_pixelspace(ar);
398 /* only exported for WM */
399 void ED_region_do_draw(bContext *C, ARegion *ar)
401 wmWindow *win = CTX_wm_window(C);
402 ScrArea *sa = CTX_wm_area(C);
403 ARegionType *at = ar->type;
405 /* see BKE_spacedata_draw_locks() */
409 /* if no partial draw rect set, full rect */
410 if (ar->drawrct.xmin == ar->drawrct.xmax)
411 ar->drawrct = ar->winrct;
413 /* extra clip for safety (intersect the rects, could use API func) */
414 ar->drawrct.xmin = max_ii(ar->winrct.xmin, ar->drawrct.xmin);
415 ar->drawrct.ymin = max_ii(ar->winrct.ymin, ar->drawrct.ymin);
416 ar->drawrct.xmax = min_ii(ar->winrct.xmax, ar->drawrct.xmax);
417 ar->drawrct.ymax = min_ii(ar->winrct.ymax, ar->drawrct.ymax);
420 /* note; this sets state, so we can use wmOrtho and friends */
421 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct);
423 UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
425 /* optional header info instead? */
427 UI_ThemeClearColor(TH_HEADER);
428 glClear(GL_COLOR_BUFFER_BIT);
430 UI_ThemeColor(TH_TEXT);
431 BLF_draw_default(UI_UNIT_X, 0.4f * UI_UNIT_Y, 0.0f, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
437 /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
438 ED_region_pixelspace(ar);
440 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL);
442 region_draw_azones(sa, ar);
444 /* for debugging unneeded area redraws and partial redraw */
447 glColor4f(drand48(), drand48(), drand48(), 0.1f);
448 glRectf(ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
449 ar->drawrct.xmax - ar->winrct.xmin, ar->drawrct.ymax - ar->winrct.ymin);
454 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
456 uiFreeInactiveBlocks(C, &ar->uiblocks);
459 region_draw_emboss(ar, &ar->winrct);
462 /* **********************************
463 * maybe silly, but let's try for now
464 * to keep these tags protected
465 * ********************************** */
467 void ED_region_tag_redraw(ARegion *ar)
470 /* zero region means full region redraw */
471 ar->do_draw = RGN_DRAW;
472 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
476 void ED_region_tag_redraw_overlay(ARegion *ar)
479 ar->do_draw_overlay = RGN_DRAW;
482 void ED_region_tag_redraw_partial(ARegion *ar, rcti *rct)
486 /* no redraw set yet, set partial region */
487 ar->do_draw = RGN_DRAW_PARTIAL;
490 else if (ar->drawrct.xmin != ar->drawrct.xmax) {
491 /* partial redraw already set, expand region */
492 BLI_rcti_union(&ar->drawrct, rct);
497 void ED_area_tag_redraw(ScrArea *sa)
502 for (ar = sa->regionbase.first; ar; ar = ar->next)
503 ED_region_tag_redraw(ar);
506 void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype)
511 for (ar = sa->regionbase.first; ar; ar = ar->next) {
512 if (ar->regiontype == regiontype) {
513 ED_region_tag_redraw(ar);
519 void ED_area_tag_refresh(ScrArea *sa)
522 sa->do_refresh = TRUE;
525 /* *************************************************************** */
527 /* use NULL to disable it */
528 void ED_area_headerprint(ScrArea *sa, const char *str)
532 /* happens when running transform operators in backround mode */
536 for (ar = sa->regionbase.first; ar; ar = ar->next) {
537 if (ar->regiontype == RGN_TYPE_HEADER) {
539 if (ar->headerstr == NULL)
540 ar->headerstr = MEM_mallocN(256, "headerprint");
541 BLI_strncpy(ar->headerstr, str, 256);
543 else if (ar->headerstr) {
544 MEM_freeN(ar->headerstr);
545 ar->headerstr = NULL;
547 ED_region_tag_redraw(ar);
552 /* ************************************************************ */
555 static void area_azone_initialize(bScreen *screen, ScrArea *sa)
559 /* reinitalize entirely, regions add azones too */
560 BLI_freelistN(&sa->actionzones);
562 if (screen->full != SCREENNORMAL) {
566 /* set area action zones */
567 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
568 BLI_addtail(&(sa->actionzones), az);
569 az->type = AZONE_AREA;
570 az->x1 = sa->totrct.xmin;
571 az->y1 = sa->totrct.ymin;
572 az->x2 = sa->totrct.xmin + (AZONESPOT - 1);
573 az->y2 = sa->totrct.ymin + (AZONESPOT - 1);
574 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
576 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
577 BLI_addtail(&(sa->actionzones), az);
578 az->type = AZONE_AREA;
579 az->x1 = sa->totrct.xmax;
580 az->y1 = sa->totrct.ymax;
581 az->x2 = sa->totrct.xmax - (AZONESPOT - 1);
582 az->y2 = sa->totrct.ymax - (AZONESPOT - 1);
583 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
586 #define AZONEPAD_EDGE (0.1f * U.widget_unit)
587 #define AZONEPAD_ICON (0.45f * U.widget_unit)
588 static void region_azone_edge(AZone *az, ARegion *ar)
591 case AE_TOP_TO_BOTTOMRIGHT:
592 az->x1 = ar->winrct.xmin;
593 az->y1 = ar->winrct.ymax - AZONEPAD_EDGE;
594 az->x2 = ar->winrct.xmax;
595 az->y2 = ar->winrct.ymax + AZONEPAD_EDGE;
597 case AE_BOTTOM_TO_TOPLEFT:
598 az->x1 = ar->winrct.xmin;
599 az->y1 = ar->winrct.ymin + AZONEPAD_EDGE;
600 az->x2 = ar->winrct.xmax;
601 az->y2 = ar->winrct.ymin - AZONEPAD_EDGE;
603 case AE_LEFT_TO_TOPRIGHT:
604 az->x1 = ar->winrct.xmin - AZONEPAD_EDGE;
605 az->y1 = ar->winrct.ymin;
606 az->x2 = ar->winrct.xmin + AZONEPAD_EDGE;
607 az->y2 = ar->winrct.ymax;
609 case AE_RIGHT_TO_TOPLEFT:
610 az->x1 = ar->winrct.xmax + AZONEPAD_EDGE;
611 az->y1 = ar->winrct.ymin;
612 az->x2 = ar->winrct.xmax - AZONEPAD_EDGE;
613 az->y2 = ar->winrct.ymax;
617 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
620 static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
625 /* count how many actionzones with along same edge are available.
626 * This allows for adding more action zones in the future without
627 * having to worry about correct offset */
628 for (azt = sa->actionzones.first; azt; azt = azt->next) {
629 if (azt->edge == az->edge) tot++;
633 case AE_TOP_TO_BOTTOMRIGHT:
634 az->x1 = ar->winrct.xmax - tot * 2 * AZONEPAD_ICON;
635 az->y1 = ar->winrct.ymax + AZONEPAD_ICON;
636 az->x2 = ar->winrct.xmax - tot * AZONEPAD_ICON;
637 az->y2 = ar->winrct.ymax + 2 * AZONEPAD_ICON;
639 case AE_BOTTOM_TO_TOPLEFT:
640 az->x1 = ar->winrct.xmin + AZONEPAD_ICON;
641 az->y1 = ar->winrct.ymin - 2 * AZONEPAD_ICON;
642 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_ICON;
643 az->y2 = ar->winrct.ymin - AZONEPAD_ICON;
645 case AE_LEFT_TO_TOPRIGHT:
646 az->x1 = ar->winrct.xmin - 2 * AZONEPAD_ICON;
647 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
648 az->x2 = ar->winrct.xmin - AZONEPAD_ICON;
649 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
651 case AE_RIGHT_TO_TOPLEFT:
652 az->x1 = ar->winrct.xmax + AZONEPAD_ICON;
653 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
654 az->x2 = ar->winrct.xmax + 2 * AZONEPAD_ICON;
655 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
659 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
661 /* if more azones on 1 spot, set offset */
662 for (azt = sa->actionzones.first; azt; azt = azt->next) {
664 if (ABS(az->x1 - azt->x1) < 2 && ABS(az->y1 - azt->y1) < 2) {
665 if (az->edge == AE_TOP_TO_BOTTOMRIGHT || az->edge == AE_BOTTOM_TO_TOPLEFT) {
673 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
679 #define AZONEPAD_TAB_PLUSW (0.7f * U.widget_unit)
680 #define AZONEPAD_TAB_PLUSH (0.7f * U.widget_unit)
682 /* region already made zero sized, in shape of edge */
683 static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar)
688 for (azt = sa->actionzones.first; azt; azt = azt->next) {
689 if (azt->edge == az->edge) tot++;
693 case AE_TOP_TO_BOTTOMRIGHT:
694 if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
695 az->x1 = ar->winrct.xmax - 2.5f * AZONEPAD_TAB_PLUSW;
696 az->y1 = ar->winrct.ymax - add;
697 az->x2 = ar->winrct.xmax - 1.5f * AZONEPAD_TAB_PLUSW;
698 az->y2 = ar->winrct.ymax - add + AZONEPAD_TAB_PLUSH;
700 case AE_BOTTOM_TO_TOPLEFT:
701 az->x1 = ar->winrct.xmax - 2.5f * AZONEPAD_TAB_PLUSW;
702 az->y1 = ar->winrct.ymin - AZONEPAD_TAB_PLUSH;
703 az->x2 = ar->winrct.xmax - 1.5f * AZONEPAD_TAB_PLUSW;
704 az->y2 = ar->winrct.ymin;
706 case AE_LEFT_TO_TOPRIGHT:
707 az->x1 = ar->winrct.xmin - AZONEPAD_TAB_PLUSH;
708 az->y1 = ar->winrct.ymax - 2.5f * AZONEPAD_TAB_PLUSW;
709 az->x2 = ar->winrct.xmin;
710 az->y2 = ar->winrct.ymax - 1.5f * AZONEPAD_TAB_PLUSW;
712 case AE_RIGHT_TO_TOPLEFT:
713 az->x1 = ar->winrct.xmax - 1;
714 az->y1 = ar->winrct.ymax - 2.5f * AZONEPAD_TAB_PLUSW;
715 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TAB_PLUSH;
716 az->y2 = ar->winrct.ymax - 1.5f * AZONEPAD_TAB_PLUSW;
719 /* rect needed for mouse pointer test */
720 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
724 #define AZONEPAD_TABW (0.9f * U.widget_unit)
725 #define AZONEPAD_TABH (0.35f * U.widget_unit)
727 /* region already made zero sized, in shape of edge */
728 static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar)
733 for (azt = sa->actionzones.first; azt; azt = azt->next) {
734 if (azt->edge == az->edge) tot++;
738 case AE_TOP_TO_BOTTOMRIGHT:
739 if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
740 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TABW;
741 az->y1 = ar->winrct.ymax - add;
742 az->x2 = ar->winrct.xmax - AZONEPAD_TABW;
743 az->y2 = ar->winrct.ymax - add + AZONEPAD_TABH;
745 case AE_BOTTOM_TO_TOPLEFT:
746 az->x1 = ar->winrct.xmin + AZONEPAD_TABW;
747 az->y1 = ar->winrct.ymin - AZONEPAD_TABH;
748 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TABW;
749 az->y2 = ar->winrct.ymin;
751 case AE_LEFT_TO_TOPRIGHT:
752 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TABH;
753 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
754 az->x2 = ar->winrct.xmin + 1;
755 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
757 case AE_RIGHT_TO_TOPLEFT:
758 az->x1 = ar->winrct.xmax - 1;
759 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
760 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TABH;
761 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
764 /* rect needed for mouse pointer test */
765 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
768 #define AZONEPAD_TRIAW (0.8f * U.widget_unit)
769 #define AZONEPAD_TRIAH (0.45f * U.widget_unit)
772 /* region already made zero sized, in shape of edge */
773 static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar)
778 for (azt = sa->actionzones.first; azt; azt = azt->next) {
779 if (azt->edge == az->edge) tot++;
783 case AE_TOP_TO_BOTTOMRIGHT:
784 if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
785 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TRIAW;
786 az->y1 = ar->winrct.ymax - add;
787 az->x2 = ar->winrct.xmax - AZONEPAD_TRIAW;
788 az->y2 = ar->winrct.ymax - add + AZONEPAD_TRIAH;
790 case AE_BOTTOM_TO_TOPLEFT:
791 az->x1 = ar->winrct.xmin + AZONEPAD_TRIAW;
792 az->y1 = ar->winrct.ymin - AZONEPAD_TRIAH;
793 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TRIAW;
794 az->y2 = ar->winrct.ymin;
796 case AE_LEFT_TO_TOPRIGHT:
797 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TRIAH;
798 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
799 az->x2 = ar->winrct.xmin + 1;
800 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
802 case AE_RIGHT_TO_TOPLEFT:
803 az->x1 = ar->winrct.xmax - 1;
804 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
805 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TRIAH;
806 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
809 /* rect needed for mouse pointer test */
810 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
814 static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge)
818 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
819 BLI_addtail(&(sa->actionzones), az);
820 az->type = AZONE_REGION;
824 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
825 if (G.debug_value == 3)
826 region_azone_icon(sa, az, ar);
827 else if (G.debug_value == 2)
828 region_azone_tria(sa, az, ar);
829 else if (G.debug_value == 1)
830 region_azone_tab(sa, az, ar);
832 region_azone_tab_plus(sa, az, ar);
835 region_azone_edge(az, ar);
841 /* *************************************************************** */
843 static void region_azone_add(ScrArea *sa, ARegion *ar, int alignment)
845 /* edge code (t b l r) is along which area edge azone will be drawn */
847 if (alignment == RGN_ALIGN_TOP)
848 region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT);
849 else if (alignment == RGN_ALIGN_BOTTOM)
850 region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT);
851 else if (alignment == RGN_ALIGN_RIGHT)
852 region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT);
853 else if (alignment == RGN_ALIGN_LEFT)
854 region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT);
857 /* dir is direction to check, not the splitting edge direction! */
858 static int rct_fits(rcti *rect, char dir, int size)
861 return BLI_rcti_size_x(rect) - size;
864 return BLI_rcti_size_y(rect) - size;
868 /* *************************************************************** */
870 /* ar should be overlapping */
871 /* function checks if some overlapping region was defined before - on same place */
872 static void region_overlap_fix(ScrArea *sa, ARegion *ar)
874 ARegion *ar1 = ar->prev;
876 /* find overlapping previous region on same place */
879 if ((ar1->alignment & RGN_SPLIT_PREV) == 0)
880 if (BLI_rcti_isect(&ar1->winrct, &ar->winrct, NULL))
886 /* translate or close */
888 int align1 = ar1->alignment & ~RGN_SPLIT_PREV;
890 if (align1 == RGN_ALIGN_LEFT) {
891 if (ar->winrct.xmax + ar1->winx > sa->winx - U.widget_unit)
892 ar->flag |= RGN_FLAG_TOO_SMALL;
894 BLI_rcti_translate(&ar->winrct, ar1->winx, 0);
896 else if (align1 == RGN_ALIGN_RIGHT) {
897 if (ar->winrct.xmin - ar1->winx < U.widget_unit)
898 ar->flag |= RGN_FLAG_TOO_SMALL;
900 BLI_rcti_translate(&ar->winrct, -ar1->winx, 0);
908 /* overlapping regions only in the following restricted cases */
909 static int region_is_overlap(wmWindow *win, ScrArea *sa, ARegion *ar)
911 if (U.uiflag2 & USER_REGION_OVERLAP) {
912 if (WM_is_draw_triple(win)) {
913 if (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_SEQ)) {
914 if (ELEM3(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS))
917 else if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) {
918 if (ELEM4(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS, RGN_TYPE_PREVIEW))
927 static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti *remainder, int quad)
929 rcti *remainder_prev = remainder;
930 int prefsizex, prefsizey;
936 /* no returns in function, winrct gets set in the end again */
937 BLI_rcti_init(&ar->winrct, 0, 0, 0, 0);
939 /* for test; allow split of previously defined region */
940 if (ar->alignment & RGN_SPLIT_PREV)
942 remainder = &ar->prev->winrct;
944 alignment = ar->alignment & ~RGN_SPLIT_PREV;
946 /* set here, assuming userpref switching forces to call this again */
947 ar->overlap = region_is_overlap(win, sa, ar);
949 /* clear state flags first */
950 ar->flag &= ~RGN_FLAG_TOO_SMALL;
952 if (ar->next == NULL && alignment != RGN_ALIGN_QSPLIT)
953 alignment = RGN_ALIGN_NONE;
955 /* prefsize, for header we stick to exception (prevent dpi rounding error) */
956 prefsizex = UI_DPI_FAC * (ar->sizex > 1 ? ar->sizex + 0.5f : ar->type->prefsizex);
958 if (ar->regiontype == RGN_TYPE_HEADER) {
959 prefsizey = ED_area_headersize();
961 else if (ar->regiontype == RGN_TYPE_UI && sa->spacetype == SPACE_FILE) {
962 prefsizey = UI_UNIT_Y * 2 + (UI_UNIT_Y / 2);
965 prefsizey = UI_DPI_FAC * (ar->sizey > 1 ? ar->sizey + 0.5f : ar->type->prefsizey);
969 if (ar->flag & RGN_FLAG_HIDDEN) {
970 /* hidden is user flag */
972 else if (alignment == RGN_ALIGN_FLOAT) {
973 /* XXX floating area region, not handled yet here */
975 else if (rct_fits(remainder, 'v', 1) < 0 || rct_fits(remainder, 'h', 1) < 0) {
976 /* remainder is too small for any usage */
977 ar->flag |= RGN_FLAG_TOO_SMALL;
979 else if (alignment == RGN_ALIGN_NONE) {
980 /* typically last region */
981 ar->winrct = *remainder;
982 BLI_rcti_init(remainder, 0, 0, 0, 0);
984 else if (alignment == RGN_ALIGN_TOP || alignment == RGN_ALIGN_BOTTOM) {
986 if (rct_fits(remainder, 'v', prefsizey) < 0) {
987 ar->flag |= RGN_FLAG_TOO_SMALL;
990 int fac = rct_fits(remainder, 'v', prefsizey);
995 ar->winrct = *remainder;
997 if (alignment == RGN_ALIGN_TOP) {
998 ar->winrct.ymin = ar->winrct.ymax - prefsizey + 1;
999 remainder->ymax = ar->winrct.ymin - 1;
1002 ar->winrct.ymax = ar->winrct.ymin + prefsizey - 1;
1003 remainder->ymin = ar->winrct.ymax + 1;
1007 else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
1009 if (rct_fits(remainder, 'h', prefsizex) < 0) {
1010 ar->flag |= RGN_FLAG_TOO_SMALL;
1013 int fac = rct_fits(remainder, 'h', prefsizex);
1018 ar->winrct = *remainder;
1020 if (alignment == RGN_ALIGN_RIGHT) {
1021 ar->winrct.xmin = ar->winrct.xmax - prefsizex + 1;
1022 if (ar->overlap == 0)
1023 remainder->xmax = ar->winrct.xmin - 1;
1026 ar->winrct.xmax = ar->winrct.xmin + prefsizex - 1;
1027 if (ar->overlap == 0)
1028 remainder->xmin = ar->winrct.xmax + 1;
1032 else if (alignment == RGN_ALIGN_VSPLIT || alignment == RGN_ALIGN_HSPLIT) {
1033 /* percentage subdiv*/
1034 ar->winrct = *remainder;
1036 if (alignment == RGN_ALIGN_HSPLIT) {
1037 if (rct_fits(remainder, 'h', prefsizex) > 4) {
1038 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1039 remainder->xmin = ar->winrct.xmax + 1;
1042 BLI_rcti_init(remainder, 0, 0, 0, 0);
1046 if (rct_fits(remainder, 'v', prefsizey) > 4) {
1047 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1048 remainder->ymin = ar->winrct.ymax + 1;
1051 BLI_rcti_init(remainder, 0, 0, 0, 0);
1055 else if (alignment == RGN_ALIGN_QSPLIT) {
1056 ar->winrct = *remainder;
1058 /* test if there's still 4 regions left */
1060 ARegion *artest = ar->next;
1064 artest->alignment = RGN_ALIGN_QSPLIT;
1065 artest = artest->next;
1070 /* let's stop adding regions */
1071 BLI_rcti_init(remainder, 0, 0, 0, 0);
1072 if (G.debug & G_DEBUG)
1073 printf("region quadsplit failed\n");
1080 if (quad == 1) { /* left bottom */
1081 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1082 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1084 else if (quad == 2) { /* left top */
1085 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1086 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1088 else if (quad == 3) { /* right bottom */
1089 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1090 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1092 else { /* right top */
1093 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1094 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1095 BLI_rcti_init(remainder, 0, 0, 0, 0);
1103 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1104 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1106 /* if region opened normally, we store this for hide/reveal usage */
1107 /* prevent rounding errors for UI_DPI_FAC mult and divide */
1108 if (ar->winx > 1) ar->sizex = (ar->winx + 0.5f) / UI_DPI_FAC;
1109 if (ar->winy > 1) ar->sizey = (ar->winy + 0.5f) / UI_DPI_FAC;
1111 /* exception for multiple overlapping regions on same spot */
1113 region_overlap_fix(sa, ar);
1115 /* set winrect for azones */
1116 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
1117 ar->winrct = *remainder;
1119 if (alignment == RGN_ALIGN_TOP)
1120 ar->winrct.ymin = ar->winrct.ymax;
1121 else if (alignment == RGN_ALIGN_BOTTOM)
1122 ar->winrct.ymax = ar->winrct.ymin;
1123 else if (alignment == RGN_ALIGN_RIGHT)
1124 ar->winrct.xmin = ar->winrct.xmax;
1125 else if (alignment == RGN_ALIGN_LEFT)
1126 ar->winrct.xmax = ar->winrct.xmin;
1127 else /* prevent winrct to be valid */
1128 ar->winrct.xmax = ar->winrct.xmin;
1131 /* restore prev-split exception */
1132 if (ar->alignment & RGN_SPLIT_PREV) {
1134 remainder = remainder_prev;
1135 ar->prev->winx = BLI_rcti_size_x(&ar->prev->winrct) + 1;
1136 ar->prev->winy = BLI_rcti_size_y(&ar->prev->winrct) + 1;
1140 /* in end, add azones, where appropriate */
1141 if (ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
1142 /* The logic for this is: when the header takes up the full area,
1143 * disallow hiding it to view the main window.
1145 * Without this, you can drag down the file selectors header and hide it
1146 * by accident very easily (highly annoying!), the value 6 is arbitrary
1147 * but accounts for small common rounding problems when scaling the UI,
1148 * must be minimum '4' */
1151 region_azone_add(sa, ar, alignment);
1154 region_rect_recursive(win, sa, ar->next, remainder, quad);
1157 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
1159 short rt = U.pixelsize > 1.0f ? 1 : 0;
1161 if (sa->v1->vec.x > 0) sa->totrct.xmin = sa->v1->vec.x + 1 + rt;
1162 else sa->totrct.xmin = sa->v1->vec.x;
1163 if (sa->v4->vec.x < sizex - 1) sa->totrct.xmax = sa->v4->vec.x - 1 - rt;
1164 else sa->totrct.xmax = sa->v4->vec.x;
1166 if (sa->v1->vec.y > 0) sa->totrct.ymin = sa->v1->vec.y + 1 + rt;
1167 else sa->totrct.ymin = sa->v1->vec.y;
1168 if (sa->v2->vec.y < sizey - 1) sa->totrct.ymax = sa->v2->vec.y - 1 - rt;
1169 else sa->totrct.ymax = sa->v2->vec.y;
1172 sa->winx = BLI_rcti_size_x(&sa->totrct) + 1;
1173 sa->winy = BLI_rcti_size_y(&sa->totrct) + 1;
1177 /* used for area initialize below */
1178 static void region_subwindow(wmWindow *win, ARegion *ar)
1180 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
1182 wm_subwindow_close(win, ar->swinid);
1185 else if (ar->swinid == 0)
1186 ar->swinid = wm_subwindow_open(win, &ar->winrct);
1188 wm_subwindow_position(win, ar->swinid, &ar->winrct);
1191 static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
1193 /* note, add-handler checks if it already exists */
1195 /* XXX it would be good to have boundbox checks for some of these... */
1196 if (flag & ED_KEYMAP_UI) {
1197 /* user interface widgets */
1198 UI_add_region_handlers(handlers);
1200 if (flag & ED_KEYMAP_VIEW2D) {
1201 /* 2d-viewport handling+manipulation */
1202 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "View2D", 0, 0);
1203 WM_event_add_keymap_handler(handlers, keymap);
1205 if (flag & ED_KEYMAP_MARKERS) {
1207 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Markers", 0, 0);
1209 /* time space only has this keymap, the others get a boundbox restricted map */
1210 if (sa->spacetype != SPACE_TIME) {
1212 static rcti rect = {0, 10000, 0, 30}; /* same local check for all areas */
1213 ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
1215 WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
1219 WM_event_add_keymap_handler(handlers, keymap);
1221 if (flag & ED_KEYMAP_ANIMATION) {
1222 /* frame changing and timeline operators (for time spaces) */
1223 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Animation", 0, 0);
1224 WM_event_add_keymap_handler(handlers, keymap);
1226 if (flag & ED_KEYMAP_FRAMES) {
1227 /* frame changing/jumping (for all spaces) */
1228 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Frames", 0, 0);
1229 WM_event_add_keymap_handler(handlers, keymap);
1231 if (flag & ED_KEYMAP_GPENCIL) {
1233 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Grease Pencil", 0, 0);
1234 WM_event_add_keymap_handler(handlers, keymap);
1236 if (flag & ED_KEYMAP_HEADER) {
1237 /* standard keymap for headers regions */
1238 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Header", 0, 0);
1239 WM_event_add_keymap_handler(handlers, keymap);
1244 /* called in screen_refresh, or screens_init, also area size changes */
1245 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
1250 /* set typedefinitions */
1251 sa->type = BKE_spacetype_from_id(sa->spacetype);
1253 if (sa->type == NULL) {
1254 sa->butspacetype = sa->spacetype = SPACE_VIEW3D;
1255 sa->type = BKE_spacetype_from_id(sa->spacetype);
1258 for (ar = sa->regionbase.first; ar; ar = ar->next)
1259 ar->type = BKE_regiontype_from_id(sa->type, ar->regiontype);
1262 area_calc_totrct(sa, WM_window_pixels_x(win), WM_window_pixels_y(win));
1264 /* clear all azones, add the area triange widgets */
1265 area_azone_initialize(win->screen, sa);
1267 /* region rect sizes */
1269 region_rect_recursive(win, sa, sa->regionbase.first, &rect, 0);
1271 /* default area handlers */
1272 ed_default_handlers(wm, sa, &sa->handlers, sa->type->keymapflag);
1273 /* checks spacedata, adds own handlers */
1275 sa->type->init(wm, sa);
1277 /* region windows, default and own handlers */
1278 for (ar = sa->regionbase.first; ar; ar = ar->next) {
1279 region_subwindow(win, ar);
1282 /* default region handlers */
1283 ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
1286 ar->type->init(wm, ar);
1289 /* prevent uiblocks to run */
1290 uiFreeBlocks(NULL, &ar->uiblocks);
1295 /* externally called for floating regions like menus */
1296 void ED_region_init(bContext *C, ARegion *ar)
1298 // ARegionType *at = ar->type;
1300 /* refresh can be called before window opened */
1301 region_subwindow(CTX_wm_window(C), ar);
1303 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1304 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1306 /* v2d mask is used to subtract scrollbars from a 2d view. Needs initialize here. */
1307 BLI_rcti_init(&ar->v2d.mask, 0, ar->winx - 1, 0, ar->winy -1);
1310 wmOrtho2(-0.01f, ar->winx - 0.01f, -0.01f, ar->winy - 0.01f);
1314 /* for quick toggle, can skip fades */
1315 void region_toggle_hidden(bContext *C, ARegion *ar, int do_fade)
1317 ScrArea *sa = CTX_wm_area(C);
1319 ar->flag ^= RGN_FLAG_HIDDEN;
1321 if (do_fade && ar->overlap) {
1322 /* starts a timer, and in end calls the stuff below itself (region_sblend_invoke()) */
1323 region_blend_start(C, sa, ar);
1326 if (ar->flag & RGN_FLAG_HIDDEN)
1327 WM_event_remove_handlers(C, &ar->handlers);
1329 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1330 ED_area_tag_redraw(sa);
1334 /* exported to all editors, uses fading default */
1335 void ED_region_toggle_hidden(bContext *C, ARegion *ar)
1337 region_toggle_hidden(C, ar, 1);
1340 /* sa2 to sa1, we swap spaces for fullscreen to keep all allocated data */
1341 /* area vertices were set */
1342 void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
1346 int spacetype = sa1->spacetype;
1348 sa1->headertype = sa2->headertype;
1349 sa1->spacetype = sa2->spacetype;
1350 sa1->type = sa2->type;
1351 sa1->butspacetype = sa2->butspacetype;
1353 if (swap_space == 1) {
1354 SWAP(ListBase, sa1->spacedata, sa2->spacedata);
1355 /* exception: ensure preview is reset */
1356 // if (sa1->spacetype == SPACE_VIEW3D)
1357 // XXX BIF_view3d_previewrender_free(sa1->spacedata.first);
1359 else if (swap_space == 2) {
1360 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
1363 BKE_spacedata_freelist(&sa1->spacedata);
1364 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
1367 /* Note; SPACE_EMPTY is possible on new screens */
1370 if (swap_space == 1) {
1371 SWAP(ListBase, sa1->regionbase, sa2->regionbase);
1374 if (swap_space < 2) {
1375 st = BKE_spacetype_from_id(spacetype);
1376 for (ar = sa1->regionbase.first; ar; ar = ar->next)
1377 BKE_area_region_free(st, ar);
1378 BLI_freelistN(&sa1->regionbase);
1381 st = BKE_spacetype_from_id(sa2->spacetype);
1382 for (ar = sa2->regionbase.first; ar; ar = ar->next) {
1383 ARegion *newar = BKE_area_region_copy(st, ar);
1384 BLI_addtail(&sa1->regionbase, newar);
1389 /* *********** Space switching code *********** */
1391 void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
1393 ScrArea *tmp = MEM_callocN(sizeof(ScrArea), "addscrarea");
1395 ED_area_exit(C, sa1);
1396 ED_area_exit(C, sa2);
1398 area_copy_data(tmp, sa1, 2);
1399 area_copy_data(sa1, sa2, 0);
1400 area_copy_data(sa2, tmp, 0);
1401 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa1);
1402 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa2);
1404 BKE_screen_area_free(tmp);
1407 /* tell WM to refresh, cursor types etc */
1408 WM_event_add_mousemove(C);
1410 ED_area_tag_redraw(sa1);
1411 ED_area_tag_refresh(sa1);
1412 ED_area_tag_redraw(sa2);
1413 ED_area_tag_refresh(sa2);
1416 void ED_area_newspace(bContext *C, ScrArea *sa, int type)
1418 if (sa->spacetype != type) {
1423 ED_area_exit(C, sa);
1425 st = BKE_spacetype_from_id(type);
1426 slold = sa->spacedata.first;
1428 sa->spacetype = type;
1429 sa->butspacetype = type;
1432 /* check previously stored space */
1433 for (sl = sa->spacedata.first; sl; sl = sl->next)
1434 if (sl->spacetype == type)
1437 /* old spacedata... happened during work on 2.50, remove */
1438 if (sl && sl->regionbase.first == NULL) {
1440 BLI_freelinkN(&sa->spacedata, sl);
1450 slold->regionbase = sa->regionbase;
1451 sa->regionbase = sl->regionbase;
1452 sl->regionbase.first = sl->regionbase.last = NULL;
1454 /* put in front of list */
1455 BLI_remlink(&sa->spacedata, sl);
1456 BLI_addhead(&sa->spacedata, sl);
1462 BLI_addhead(&sa->spacedata, sl);
1466 slold->regionbase = sa->regionbase;
1467 sa->regionbase = sl->regionbase;
1468 sl->regionbase.first = sl->regionbase.last = NULL;
1472 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1474 /* tell WM to refresh, cursor types etc */
1475 WM_event_add_mousemove(C);
1477 /* send space change notifier */
1478 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1480 ED_area_tag_refresh(sa);
1483 /* also redraw when re-used */
1484 ED_area_tag_redraw(sa);
1487 void ED_area_prevspace(bContext *C, ScrArea *sa)
1489 SpaceLink *sl = (sa) ? sa->spacedata.first : CTX_wm_space_data(C);
1491 if (sl && sl->next) {
1492 /* workaround for case of double prevspace, render window
1493 * with a file browser on top of it */
1494 if (sl->next->spacetype == SPACE_FILE && sl->next->next)
1495 ED_area_newspace(C, sa, sl->next->next->spacetype);
1497 ED_area_newspace(C, sa, sl->next->spacetype);
1503 ED_area_tag_redraw(sa);
1505 /* send space change notifier */
1506 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1509 /* returns offset for next button in header */
1510 int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
1512 ScrArea *sa = CTX_wm_area(C);
1513 bScreen *scr = CTX_wm_screen(C);
1515 int xco = 0.4 * U.widget_unit;
1517 RNA_pointer_create(&(scr->id), &RNA_Area, sa, &areaptr);
1519 uiDefButR(block, MENU, 0, NULL, xco, yco, 1.5 * U.widget_unit, U.widget_unit,
1520 &areaptr, "type", 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
1522 return xco + 1.7 * U.widget_unit;
1525 int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
1527 ScrArea *sa = CTX_wm_area(C);
1528 int xco = 0.4 * U.widget_unit;
1532 xco = ED_area_header_switchbutton(C, block, yco);
1534 uiBlockSetEmboss(block, UI_EMBOSSN);
1536 if (sa->flag & HEADER_NO_PULLDOWN) {
1537 but = uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
1538 ICON_DISCLOSURE_TRI_RIGHT,
1539 xco, yco, U.widget_unit, U.widget_unit * 0.9f,
1540 &(sa->flag), 0, 0, 0, 0,
1541 TIP_("Show pulldown menus"));
1544 but = uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
1545 ICON_DISCLOSURE_TRI_DOWN,
1546 xco, yco, U.widget_unit, U.widget_unit * 0.9f,
1547 &(sa->flag), 0, 0, 0, 0,
1548 TIP_("Hide pulldown menus"));
1551 uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
1553 uiBlockSetEmboss(block, UI_EMBOSS);
1555 return xco + U.widget_unit;
1558 /************************ standard UI regions ************************/
1560 void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
1562 ScrArea *sa = CTX_wm_area(C);
1563 uiStyle *style = UI_GetStyleDraw();
1567 View2D *v2d = &ar->v2d;
1568 View2DScrollers *scrollers;
1569 int x, y, xco, yco, w, em, triangle, open, newcontext = 0;
1574 newcontext = UI_view2d_tab_set(v2d, contextnr);
1576 /* before setting the view */
1578 /* only allow scrolling in vertical direction */
1579 v2d->keepofs |= V2D_LOCKOFS_X | V2D_KEEPOFS_Y;
1580 v2d->keepofs &= ~(V2D_LOCKOFS_Y | V2D_KEEPOFS_X);
1581 v2d->scroll &= ~(V2D_SCROLL_BOTTOM);
1582 v2d->scroll |= (V2D_SCROLL_RIGHT);
1585 /* for now, allow scrolling in both directions (since layouts are optimized for vertical,
1586 * they often don't fit in horizontal layout)
1588 v2d->keepofs &= ~(V2D_LOCKOFS_X | V2D_LOCKOFS_Y | V2D_KEEPOFS_X | V2D_KEEPOFS_Y);
1589 v2d->scroll |= (V2D_SCROLL_BOTTOM);
1590 v2d->scroll &= ~(V2D_SCROLL_RIGHT);
1593 scroll = v2d->scroll;
1595 /* sortof hack - but we cannot predict the height of panels, until it's being generated */
1596 /* the layout engine works with fixed width (from v2d->cur), which is being set at end of the loop */
1597 /* in case scroller settings (hide flags) differ from previous, the whole loop gets done again */
1598 for (redo = 2; redo > 0; redo--) {
1601 w = BLI_rctf_size_x(&v2d->cur);
1602 em = (ar->type->prefsizex) ? UI_UNIT_Y / 2 : UI_UNIT_Y;
1606 em = (ar->type->prefsizex) ? UI_UNIT_Y / 2 : UI_UNIT_Y;
1610 uiBeginPanels(C, ar);
1612 /* set view2d view matrix - uiBeginBlock() stores it */
1613 UI_view2d_view_ortho(v2d);
1615 for (pt = ar->type->paneltypes.first; pt; pt = pt->next) {
1616 /* verify context */
1618 if (pt->context[0] && strcmp(context, pt->context) != 0)
1622 if (pt->draw && (!pt->poll || pt->poll(C, pt))) {
1623 block = uiBeginBlock(C, ar, pt->idname, UI_EMBOSS);
1624 panel = uiBeginPanel(sa, ar, block, pt, &open);
1626 /* bad fixed values */
1627 triangle = (int)(UI_UNIT_Y * 1.1f);
1629 if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
1630 /* for enabled buttons */
1631 panel->layout = uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
1632 triangle, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, style);
1634 pt->draw_header(C, panel);
1636 uiBlockLayoutResolve(block, &xco, &yco);
1637 panel->labelofs = xco - triangle;
1638 panel->layout = NULL;
1641 panel->labelofs = 0;
1647 /* panel context can either be toolbar region or normal panels region */
1648 if (ar->regiontype == RGN_TYPE_TOOLS)
1649 panelContext = UI_LAYOUT_TOOLBAR;
1651 panelContext = UI_LAYOUT_PANEL;
1653 panel->layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, panelContext,
1654 style->panelspace, 0, w - 2 * style->panelspace, em, style);
1658 uiBlockLayoutResolve(block, &xco, &yco);
1659 panel->layout = NULL;
1661 yco -= 2 * style->panelspace;
1662 uiEndPanel(block, w, -yco);
1666 uiEndPanel(block, w, 0);
1669 uiEndBlock(C, block);
1673 /* align panels and return size */
1674 uiEndPanels(C, ar, &x, &y);
1676 /* before setting the view */
1678 /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */
1679 if (v2d->cur.ymax < - 0.001f)
1680 y = min_ii(y, v2d->cur.ymin);
1685 /* don't jump back when panels close or hide */
1687 x = max_ii(x, v2d->cur.xmax);
1691 /* this also changes the 'cur' */
1692 UI_view2d_totRect_set(v2d, x, y);
1694 if (scroll != v2d->scroll) {
1695 /* Note: this code scales fine, but because of rounding differences, positions of elements
1696 * flip +1 or -1 pixel compared to redoing the entire layout again.
1697 * Leaving in commented code for future tests */
1698 /* uiScalePanels(ar, BLI_rctf_size_x(&v2d->cur));
1709 /* view should be in pixelspace */
1710 UI_view2d_view_restore(C);
1712 UI_ThemeColor4((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
1713 glRecti(0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct));
1714 glDisable(GL_BLEND);
1717 UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
1718 glClear(GL_COLOR_BUFFER_BIT);
1723 UI_view2d_view_ortho(v2d);
1726 uiDrawPanels(C, ar);
1728 /* restore view matrix */
1729 UI_view2d_view_restore(C);
1732 scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1733 UI_view2d_scrollers_draw(C, v2d, scrollers);
1734 UI_view2d_scrollers_free(scrollers);
1737 void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
1741 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy);
1743 keymap = WM_keymap_find(wm->defaultconf, "View2D Buttons List", 0, 0);
1744 WM_event_add_keymap_handler(&ar->handlers, keymap);
1747 void ED_region_header(const bContext *C, ARegion *ar)
1749 uiStyle *style = UI_GetStyleDraw();
1753 Header header = {NULL};
1754 int maxco, xco, yco;
1755 int headery = ED_area_headersize();
1758 UI_ThemeClearColor((ED_screen_area_active(C)) ? TH_HEADER : TH_HEADERDESEL);
1759 glClear(GL_COLOR_BUFFER_BIT);
1761 /* set view2d view matrix for scrolling (without scrollers) */
1762 UI_view2d_view_ortho(&ar->v2d);
1764 xco = maxco = 0.4f * UI_UNIT_X;
1765 yco = headery - floor(0.2f * UI_UNIT_Y);
1767 /* draw all headers types */
1768 for (ht = ar->type->headertypes.first; ht; ht = ht->next) {
1769 block = uiBeginBlock(C, ar, ht->idname, UI_EMBOSS);
1770 layout = uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, UI_UNIT_Y, 1, style);
1774 header.layout = layout;
1775 ht->draw(C, &header);
1778 xco = uiLayoutGetWidth(layout);
1783 uiBlockLayoutResolve(block, &xco, &yco);
1789 uiEndBlock(C, block);
1790 uiDrawBlock(C, block);
1793 /* always as last */
1794 UI_view2d_totRect_set(&ar->v2d, maxco + UI_UNIT_X + 80, headery);
1796 /* restore view matrix? */
1797 UI_view2d_view_restore(C);
1800 void ED_region_header_init(ARegion *ar)
1802 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
1805 /* UI_UNIT_Y is defined as U variable now, depending dpi */
1806 int ED_area_headersize(void)
1808 return (int)(1.3f * UI_UNIT_Y);
1811 void ED_region_info_draw(ARegion *ar, const char *text, int block, float fill_color[4])
1813 const int header_height = UI_UNIT_Y;
1814 uiStyle *style = UI_GetStyleDraw();
1815 int fontid = style->widget.uifont_id;
1819 /* background box */
1820 ED_region_visible_rect(ar, &rect);
1821 rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
1823 /* box fill entire width or just around text */
1825 rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text) + 1.2f * U.widget_unit);
1827 rect.ymax = BLI_rcti_size_y(&ar->winrct);
1830 glGetIntegerv(GL_SCISSOR_BOX, scissor);
1831 glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin,
1832 BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1);
1835 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1836 glColor4fv(fill_color);
1837 glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
1838 glDisable(GL_BLEND);
1841 UI_ThemeColor(TH_TEXT_HI);
1842 BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
1843 BLF_enable(fontid, BLF_CLIPPING);
1844 BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit, 0.0f);
1846 BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
1848 BLF_disable(fontid, BLF_CLIPPING);
1850 /* restore scissor as it was before */
1851 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1854 void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
1856 float gridsize, gridstep = 1.0f / 32.0f;
1857 float fac, blendfac;
1860 /* the image is located inside (0, 0), (1, 1) as set by view2d */
1861 UI_ThemeColorShade(TH_BACK, 20);
1863 UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
1864 UI_view2d_to_region_no_clip(&ar->v2d, 1.0f, 1.0f, &x2, &y2);
1865 glRectf(x1, y1, x2, y2);
1867 /* gridsize adapted to zoom level */
1868 gridsize = 0.5f * (zoomx + zoomy);
1869 if (gridsize <= 0.0f)
1872 if (gridsize < 1.0f) {
1873 while (gridsize < 1.0f) {
1879 while (gridsize >= 4.0f) {
1885 /* the fine resolution level */
1886 blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
1887 CLAMP(blendfac, 0.0f, 1.0f);
1888 UI_ThemeColorShade(TH_BACK, (int)(20.0f * (1.0f - blendfac)));
1892 while (fac < 1.0f) {
1893 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
1894 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
1895 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
1896 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
1900 /* the large resolution level */
1901 UI_ThemeColor(TH_BACK);
1904 while (fac < 1.0f) {
1905 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
1906 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
1907 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
1908 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
1909 fac += 4.0f * gridstep;
1914 /* If the area has overlapping regions, it returns visible rect for Region *ar */
1915 /* rect gets returned in local region coordinates */
1916 void ED_region_visible_rect(ARegion *ar, rcti *rect)
1920 /* allow function to be called without area */
1926 /* check if a region overlaps with the current one */
1927 for (; arn; arn = arn->next) {
1928 if (ar != arn && arn->overlap) {
1929 if (BLI_rcti_isect(rect, &arn->winrct, NULL)) {
1931 /* overlap left, also check 1 pixel offset (2 regions on one side) */
1932 if (ABS(rect->xmin - arn->winrct.xmin) < 2)
1933 rect->xmin = arn->winrct.xmax;
1936 if (ABS(rect->xmax - arn->winrct.xmax) < 2)
1937 rect->xmax = arn->winrct.xmin;
1941 BLI_rcti_translate(rect, -ar->winrct.xmin, -ar->winrct.ymin);