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"
42 #include "BLI_utildefines.h"
44 #include "BLF_translation.h"
46 #include "BKE_context.h"
47 #include "BKE_global.h"
48 #include "BKE_screen.h"
52 #include "wm_subwindow.h"
54 #include "ED_screen.h"
55 #include "ED_screen_types.h"
56 #include "ED_space_api.h"
58 #include "ED_fileselect.h"
61 #include "BIF_glutil.h"
64 #include "UI_interface.h"
65 #include "UI_resources.h"
66 #include "UI_view2d.h"
68 #include "screen_intern.h"
70 /* general area and region code */
72 static void region_draw_emboss(ARegion *ar, rcti *scirct)
76 /* translate scissor rect to region space */
77 rect.xmin = scirct->xmin - ar->winrct.xmin;
78 rect.ymin = scirct->ymin - ar->winrct.ymin;
79 rect.xmax = scirct->xmax - ar->winrct.xmin;
80 rect.ymax = scirct->ymax - ar->winrct.ymin;
84 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
87 glColor4ub(0, 0, 0, 30);
88 sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
91 glColor4ub(0, 0, 0, 30);
92 sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
95 glColor4ub(255, 255, 255, 30);
96 sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
99 glColor4ub(255, 255, 255, 30);
100 sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
105 void ED_region_pixelspace(ARegion *ar)
107 int width = BLI_rcti_size_x(&ar->winrct) + 1;
108 int height = BLI_rcti_size_y(&ar->winrct) + 1;
110 wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
114 /* only exported for WM */
115 void ED_region_do_listen(ARegion *ar, wmNotifier *note)
117 /* generic notes first */
118 switch (note->category) {
120 if (note->data == ND_FILEREAD)
121 ED_region_tag_redraw(ar);
124 ED_region_tag_redraw(ar);
128 if (ar->type && ar->type->listener)
129 ar->type->listener(ar, note);
132 /* only exported for WM */
133 void ED_area_do_listen(ScrArea *sa, wmNotifier *note)
135 /* no generic notes? */
136 if (sa->type && sa->type->listener) {
137 sa->type->listener(sa, note);
141 /* only exported for WM */
142 void ED_area_do_refresh(bContext *C, ScrArea *sa)
144 /* no generic notes? */
145 if (sa->type && sa->type->refresh) {
146 sa->type->refresh(C, sa);
148 sa->do_refresh = FALSE;
151 /* based on screen region draw tags, set draw tags in azones, and future region tabs etc */
152 /* only exported for WM */
153 void ED_area_overdraw_flush(ScrArea *sa, ARegion *ar)
157 for (az = sa->actionzones.first; az; az = az->next) {
160 xs = (az->x1 + az->x2) / 2;
161 ys = (az->y1 + az->y2) / 2;
164 if (BLI_rcti_isect_pt(&ar->winrct, xs, ys)) {
171 * \brief Corner widgets use for dragging and splitting the view.
173 static void area_draw_azone(short x1, short y1, short x2, short y2)
178 dx = copysign(ceilf(0.3f * fabsf(dx)), dx);
179 dy = copysign(ceilf(0.3f * fabsf(dy)), dy);
182 glEnable(GL_LINE_SMOOTH);
184 glColor4ub(255, 255, 255, 180);
185 fdrawline(x1, y2, x2, y1);
186 glColor4ub(255, 255, 255, 130);
187 fdrawline(x1, y2 - dy, x2 - dx, y1);
188 glColor4ub(255, 255, 255, 80);
189 fdrawline(x1, y2 - 2 * dy, x2 - 2 * dx, y1);
191 glColor4ub(0, 0, 0, 210);
192 fdrawline(x1, y2 + 1, x2 + 1, y1);
193 glColor4ub(0, 0, 0, 180);
194 fdrawline(x1, y2 - dy + 1, x2 - dx + 1, y1);
195 glColor4ub(0, 0, 0, 150);
196 fdrawline(x1, y2 - 2 * dy + 1, x2 - 2 * dx + 1, y1);
198 glDisable(GL_LINE_SMOOTH);
202 static void region_draw_azone_icon(AZone *az)
204 GLUquadricObj *qobj = NULL;
205 short midx = az->x1 + (az->x2 - az->x1) / 2;
206 short midy = az->y1 + (az->y2 - az->y1) / 2;
208 qobj = gluNewQuadric();
211 glTranslatef(midx, midy, 0.0);
213 /* outlined circle */
214 glEnable(GL_LINE_SMOOTH);
216 glColor4f(1.f, 1.f, 1.f, 0.8f);
218 gluQuadricDrawStyle(qobj, GLU_FILL);
219 gluDisk(qobj, 0.0, 4.25f, 16, 1);
221 glColor4f(0.2f, 0.2f, 0.2f, 0.9f);
223 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
224 gluDisk(qobj, 0.0, 4.25f, 16, 1);
226 glDisable(GL_LINE_SMOOTH);
229 gluDeleteQuadric(qobj);
232 sdrawline(midx, midy - 2, midx, midy + 3);
233 sdrawline(midx - 2, midy, midx + 3, midy);
236 static void draw_azone_plus(float x1, float y1, float x2, float y2)
241 glRectf((x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
242 glRectf(x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
243 glRectf((x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
246 static void region_draw_azone_tab_plus(AZone *az)
248 extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
252 /* add code to draw region hidden as 'too small' */
254 case AE_TOP_TO_BOTTOMRIGHT:
255 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
257 case AE_BOTTOM_TO_TOPLEFT:
258 uiSetRoundBox(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
260 case AE_LEFT_TO_TOPRIGHT:
261 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
263 case AE_RIGHT_TO_TOPLEFT:
264 uiSetRoundBox(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
268 glColor4f(0.05f, 0.05f, 0.05f, 0.4f);
269 uiRoundBox((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
273 glColor4f(0.8f, 0.8f, 0.8f, 0.4f);
274 draw_azone_plus((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2);
279 static void region_draw_azone_tab(AZone *az)
284 UI_GetThemeColor3fv(TH_HEADER, col);
285 glColor4f(col[0], col[1], col[2], 0.5f);
287 /* add code to draw region hidden as 'too small' */
289 case AE_TOP_TO_BOTTOMRIGHT:
290 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_RB_ALPHA);
292 uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
293 glColor4ub(0, 0, 0, 255);
294 uiRoundRect((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
296 case AE_BOTTOM_TO_TOPLEFT:
297 uiSetRoundBox(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
299 uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
300 glColor4ub(0, 0, 0, 255);
301 uiRoundRect((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
303 case AE_LEFT_TO_TOPRIGHT:
304 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
306 uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
307 glColor4ub(0, 0, 0, 255);
308 uiRoundRect((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
310 case AE_RIGHT_TO_TOPLEFT:
311 uiSetRoundBox(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_RB_ALPHA);
313 uiDrawBoxShade(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 uiRoundRect((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
322 static void region_draw_azone_tria(AZone *az)
324 extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
327 //UI_GetThemeColor3fv(TH_HEADER, col);
328 glColor4f(0.0f, 0.0f, 0.0f, 0.35f);
330 /* add code to draw region hidden as 'too small' */
332 case AE_TOP_TO_BOTTOMRIGHT:
333 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);
336 case AE_BOTTOM_TO_TOPLEFT:
337 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);
340 case AE_LEFT_TO_TOPRIGHT:
341 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);
344 case AE_RIGHT_TO_TOPLEFT:
345 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);
353 /* only exported for WM */
354 void ED_area_overdraw(bContext *C)
356 wmWindow *win = CTX_wm_window(C);
357 bScreen *screen = CTX_wm_screen(C);
360 /* Draw AZones, in screenspace */
361 wmSubWindowSet(win, screen->mainwin);
364 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
366 for (sa = screen->areabase.first; sa; sa = sa->next) {
368 for (az = sa->actionzones.first; az; az = az->next) {
370 if (az->type == AZONE_AREA) {
371 area_draw_azone(az->x1, az->y1, az->x2, az->y2);
373 else if (az->type == AZONE_REGION) {
376 /* only display tab or icons when the region is hidden */
377 if (az->ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
378 if (G.debug_value == 3)
379 region_draw_azone_icon(az);
380 else if (G.debug_value == 2)
381 region_draw_azone_tria(az);
382 else if (G.debug_value == 1)
383 region_draw_azone_tab(az);
385 region_draw_azone_tab_plus(az);
398 /* get scissor rect, checking overlapping regions */
399 void region_scissor_winrct(ARegion *ar, rcti *winrct)
401 *winrct = ar->winrct;
403 if (ELEM(ar->alignment, RGN_OVERLAP_LEFT, RGN_OVERLAP_RIGHT))
409 if (BLI_rcti_isect(winrct, &ar->winrct, NULL)) {
410 if (ar->flag & RGN_FLAG_HIDDEN) {
413 else if (ar->alignment & RGN_SPLIT_PREV) {
416 else if (ar->alignment == RGN_OVERLAP_LEFT) {
417 winrct->xmin = ar->winrct.xmax + 1;
419 else if (ar->alignment == RGN_OVERLAP_RIGHT) {
420 winrct->xmax = ar->winrct.xmin - 1;
427 /* only exported for WM */
428 /* makes region ready for drawing, sets pixelspace */
429 void ED_region_set(const bContext *C, ARegion *ar)
431 wmWindow *win = CTX_wm_window(C);
432 ScrArea *sa = CTX_wm_area(C);
435 /* checks other overlapping regions */
436 region_scissor_winrct(ar, &winrct);
438 ar->drawrct = winrct;
440 /* note; this sets state, so we can use wmOrtho and friends */
441 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct);
443 UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
445 ED_region_pixelspace(ar);
449 /* only exported for WM */
450 void ED_region_do_draw(bContext *C, ARegion *ar)
452 wmWindow *win = CTX_wm_window(C);
453 ScrArea *sa = CTX_wm_area(C);
454 ARegionType *at = ar->type;
457 /* see BKE_spacedata_draw_locks() */
461 /* checks other overlapping regions */
462 region_scissor_winrct(ar, &winrct);
464 /* if no partial draw rect set, full rect */
465 if (ar->drawrct.xmin == ar->drawrct.xmax)
466 ar->drawrct = winrct;
468 /* extra clip for safety */
469 ar->drawrct.xmin = MAX2(winrct.xmin, ar->drawrct.xmin);
470 ar->drawrct.ymin = MAX2(winrct.ymin, ar->drawrct.ymin);
471 ar->drawrct.xmax = MIN2(winrct.xmax, ar->drawrct.xmax);
472 ar->drawrct.ymax = MIN2(winrct.ymax, ar->drawrct.ymax);
475 /* note; this sets state, so we can use wmOrtho and friends */
476 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct);
478 UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
480 /* optional header info instead? */
482 UI_ThemeClearColor(TH_HEADER);
483 glClear(GL_COLOR_BUFFER_BIT);
485 UI_ThemeColor(TH_TEXT);
486 BLF_draw_default(20, 8, 0.0f, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
492 /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
493 ED_region_pixelspace(ar);
495 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL);
498 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
500 uiFreeInactiveBlocks(C, &ar->uiblocks);
503 region_draw_emboss(ar, &winrct);
506 /* **********************************
507 * maybe silly, but let's try for now
508 * to keep these tags protected
509 * ********************************** */
511 void ED_region_tag_redraw(ARegion *ar)
514 /* zero region means full region redraw */
515 ar->do_draw = RGN_DRAW;
516 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
520 void ED_region_tag_redraw_overlay(ARegion *ar)
523 ar->do_draw_overlay = RGN_DRAW;
526 void ED_region_tag_redraw_partial(ARegion *ar, rcti *rct)
530 /* no redraw set yet, set partial region */
531 ar->do_draw = RGN_DRAW_PARTIAL;
534 else if (ar->drawrct.xmin != ar->drawrct.xmax) {
535 /* partial redraw already set, expand region */
536 ar->drawrct.xmin = MIN2(ar->drawrct.xmin, rct->xmin);
537 ar->drawrct.ymin = MIN2(ar->drawrct.ymin, rct->ymin);
538 ar->drawrct.xmax = MAX2(ar->drawrct.xmax, rct->xmax);
539 ar->drawrct.ymax = MAX2(ar->drawrct.ymax, rct->ymax);
544 void ED_area_tag_redraw(ScrArea *sa)
549 for (ar = sa->regionbase.first; ar; ar = ar->next)
550 ED_region_tag_redraw(ar);
553 void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype)
558 for (ar = sa->regionbase.first; ar; ar = ar->next) {
559 if (ar->regiontype == regiontype) {
560 ED_region_tag_redraw(ar);
566 void ED_area_tag_refresh(ScrArea *sa)
569 sa->do_refresh = TRUE;
572 /* *************************************************************** */
574 /* use NULL to disable it */
575 void ED_area_headerprint(ScrArea *sa, const char *str)
579 /* happens when running transform operators in backround mode */
583 for (ar = sa->regionbase.first; ar; ar = ar->next) {
584 if (ar->regiontype == RGN_TYPE_HEADER) {
586 if (ar->headerstr == NULL)
587 ar->headerstr = MEM_mallocN(256, "headerprint");
588 BLI_strncpy(ar->headerstr, str, 256);
590 else if (ar->headerstr) {
591 MEM_freeN(ar->headerstr);
592 ar->headerstr = NULL;
594 ED_region_tag_redraw(ar);
599 /* ************************************************************ */
602 static void area_azone_initialize(bScreen *screen, ScrArea *sa)
606 /* reinitalize entirely, regions add azones too */
607 BLI_freelistN(&sa->actionzones);
609 if (screen->full != SCREENNORMAL) {
613 /* set area action zones */
614 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
615 BLI_addtail(&(sa->actionzones), az);
616 az->type = AZONE_AREA;
617 az->x1 = sa->totrct.xmin - 1;
618 az->y1 = sa->totrct.ymin - 1;
619 az->x2 = sa->totrct.xmin + (AZONESPOT - 1);
620 az->y2 = sa->totrct.ymin + (AZONESPOT - 1);
621 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
623 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
624 BLI_addtail(&(sa->actionzones), az);
625 az->type = AZONE_AREA;
626 az->x1 = sa->totrct.xmax + 1;
627 az->y1 = sa->totrct.ymax + 1;
628 az->x2 = sa->totrct.xmax - (AZONESPOT - 1);
629 az->y2 = sa->totrct.ymax - (AZONESPOT - 1);
630 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
633 #define AZONEPAD_EDGE 4
634 #define AZONEPAD_ICON 9
635 static void region_azone_edge(AZone *az, ARegion *ar)
638 case AE_TOP_TO_BOTTOMRIGHT:
639 az->x1 = ar->winrct.xmin;
640 az->y1 = ar->winrct.ymax - AZONEPAD_EDGE;
641 az->x2 = ar->winrct.xmax;
642 az->y2 = ar->winrct.ymax;
644 case AE_BOTTOM_TO_TOPLEFT:
645 az->x1 = ar->winrct.xmin;
646 az->y1 = ar->winrct.ymin + AZONEPAD_EDGE;
647 az->x2 = ar->winrct.xmax;
648 az->y2 = ar->winrct.ymin;
650 case AE_LEFT_TO_TOPRIGHT:
651 az->x1 = ar->winrct.xmin;
652 az->y1 = ar->winrct.ymin;
653 az->x2 = ar->winrct.xmin + AZONEPAD_EDGE;
654 az->y2 = ar->winrct.ymax;
656 case AE_RIGHT_TO_TOPLEFT:
657 az->x1 = ar->winrct.xmax;
658 az->y1 = ar->winrct.ymin;
659 az->x2 = ar->winrct.xmax - AZONEPAD_EDGE;
660 az->y2 = ar->winrct.ymax;
664 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
667 static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
672 /* count how many actionzones with along same edge are available.
673 * This allows for adding more action zones in the future without
674 * having to worry about correct offset */
675 for (azt = sa->actionzones.first; azt; azt = azt->next) {
676 if (azt->edge == az->edge) tot++;
680 case AE_TOP_TO_BOTTOMRIGHT:
681 az->x1 = ar->winrct.xmax - tot * 2 * AZONEPAD_ICON;
682 az->y1 = ar->winrct.ymax + AZONEPAD_ICON;
683 az->x2 = ar->winrct.xmax - tot * AZONEPAD_ICON;
684 az->y2 = ar->winrct.ymax + 2 * AZONEPAD_ICON;
686 case AE_BOTTOM_TO_TOPLEFT:
687 az->x1 = ar->winrct.xmin + AZONEPAD_ICON;
688 az->y1 = ar->winrct.ymin - 2 * AZONEPAD_ICON;
689 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_ICON;
690 az->y2 = ar->winrct.ymin - AZONEPAD_ICON;
692 case AE_LEFT_TO_TOPRIGHT:
693 az->x1 = ar->winrct.xmin - 2 * AZONEPAD_ICON;
694 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
695 az->x2 = ar->winrct.xmin - AZONEPAD_ICON;
696 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
698 case AE_RIGHT_TO_TOPLEFT:
699 az->x1 = ar->winrct.xmax + AZONEPAD_ICON;
700 az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
701 az->x2 = ar->winrct.xmax + 2 * AZONEPAD_ICON;
702 az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
706 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
708 /* if more azones on 1 spot, set offset */
709 for (azt = sa->actionzones.first; azt; azt = azt->next) {
711 if (ABS(az->x1 - azt->x1) < 2 && ABS(az->y1 - azt->y1) < 2) {
712 if (az->edge == AE_TOP_TO_BOTTOMRIGHT || az->edge == AE_BOTTOM_TO_TOPLEFT) {
720 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
726 #define AZONEPAD_TAB_PLUSW 14
727 #define AZONEPAD_TAB_PLUSH 14
729 /* region already made zero sized, in shape of edge */
730 static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar)
735 for (azt = sa->actionzones.first; azt; azt = azt->next) {
736 if (azt->edge == az->edge) tot++;
740 case AE_TOP_TO_BOTTOMRIGHT:
741 if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
742 az->x1 = ar->winrct.xmax - 2.5 * AZONEPAD_TAB_PLUSW;
743 az->y1 = ar->winrct.ymax - add;
744 az->x2 = ar->winrct.xmax - 1.5 * AZONEPAD_TAB_PLUSW;
745 az->y2 = ar->winrct.ymax - add + AZONEPAD_TAB_PLUSH;
747 case AE_BOTTOM_TO_TOPLEFT:
748 az->x1 = ar->winrct.xmax - 2.5 * AZONEPAD_TAB_PLUSW;
749 az->y1 = ar->winrct.ymin - AZONEPAD_TAB_PLUSH;
750 az->x2 = ar->winrct.xmax - 1.5 * AZONEPAD_TAB_PLUSW;
751 az->y2 = ar->winrct.ymin;
753 case AE_LEFT_TO_TOPRIGHT:
754 az->x1 = ar->winrct.xmin - AZONEPAD_TAB_PLUSH;
755 az->y1 = ar->winrct.ymax - 2.5 * AZONEPAD_TAB_PLUSW;
756 az->x2 = ar->winrct.xmin;
757 az->y2 = ar->winrct.ymax - 1.5 * AZONEPAD_TAB_PLUSW;
759 case AE_RIGHT_TO_TOPLEFT:
760 az->x1 = ar->winrct.xmax - 1;
761 az->y1 = ar->winrct.ymax - 2.5 * AZONEPAD_TAB_PLUSW;
762 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TAB_PLUSH;
763 az->y2 = ar->winrct.ymax - 1.5 * AZONEPAD_TAB_PLUSW;
766 /* rect needed for mouse pointer test */
767 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
771 #define AZONEPAD_TABW 18
772 #define AZONEPAD_TABH 7
774 /* region already made zero sized, in shape of edge */
775 static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar)
780 for (azt = sa->actionzones.first; azt; azt = azt->next) {
781 if (azt->edge == az->edge) tot++;
785 case AE_TOP_TO_BOTTOMRIGHT:
786 if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
787 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TABW;
788 az->y1 = ar->winrct.ymax - add;
789 az->x2 = ar->winrct.xmax - AZONEPAD_TABW;
790 az->y2 = ar->winrct.ymax - add + AZONEPAD_TABH;
792 case AE_BOTTOM_TO_TOPLEFT:
793 az->x1 = ar->winrct.xmin + AZONEPAD_TABW;
794 az->y1 = ar->winrct.ymin - AZONEPAD_TABH;
795 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TABW;
796 az->y2 = ar->winrct.ymin;
798 case AE_LEFT_TO_TOPRIGHT:
799 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TABH;
800 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
801 az->x2 = ar->winrct.xmin + 1;
802 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
804 case AE_RIGHT_TO_TOPLEFT:
805 az->x1 = ar->winrct.xmax - 1;
806 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
807 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TABH;
808 az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
811 /* rect needed for mouse pointer test */
812 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
815 #define AZONEPAD_TRIAW 16
816 #define AZONEPAD_TRIAH 9
819 /* region already made zero sized, in shape of edge */
820 static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar)
825 for (azt = sa->actionzones.first; azt; azt = azt->next) {
826 if (azt->edge == az->edge) tot++;
830 case AE_TOP_TO_BOTTOMRIGHT:
831 if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
832 az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TRIAW;
833 az->y1 = ar->winrct.ymax - add;
834 az->x2 = ar->winrct.xmax - AZONEPAD_TRIAW;
835 az->y2 = ar->winrct.ymax - add + AZONEPAD_TRIAH;
837 case AE_BOTTOM_TO_TOPLEFT:
838 az->x1 = ar->winrct.xmin + AZONEPAD_TRIAW;
839 az->y1 = ar->winrct.ymin - AZONEPAD_TRIAH;
840 az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TRIAW;
841 az->y2 = ar->winrct.ymin;
843 case AE_LEFT_TO_TOPRIGHT:
844 az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TRIAH;
845 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
846 az->x2 = ar->winrct.xmin + 1;
847 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
849 case AE_RIGHT_TO_TOPLEFT:
850 az->x1 = ar->winrct.xmax - 1;
851 az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
852 az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TRIAH;
853 az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
856 /* rect needed for mouse pointer test */
857 BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
861 static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge)
865 az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
866 BLI_addtail(&(sa->actionzones), az);
867 az->type = AZONE_REGION;
871 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
872 if (G.debug_value == 3)
873 region_azone_icon(sa, az, ar);
874 else if (G.debug_value == 2)
875 region_azone_tria(sa, az, ar);
876 else if (G.debug_value == 1)
877 region_azone_tab(sa, az, ar);
879 region_azone_tab_plus(sa, az, ar);
882 region_azone_edge(az, ar);
888 /* *************************************************************** */
890 static void region_azone_add(ScrArea *sa, ARegion *ar, int alignment)
892 /* edge code (t b l r) is along which area edge azone will be drawn */
894 if (alignment == RGN_ALIGN_TOP)
895 region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT);
896 else if (alignment == RGN_ALIGN_BOTTOM)
897 region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT);
898 else if (ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT))
899 region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT);
900 else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_OVERLAP_LEFT))
901 region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT);
904 /* dir is direction to check, not the splitting edge direction! */
905 static int rct_fits(rcti *rect, char dir, int size)
908 return BLI_rcti_size_x(rect) - size;
911 return BLI_rcti_size_y(rect) - size;
915 static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int quad)
917 rcti *remainder_prev = remainder;
918 int prefsizex, prefsizey;
924 /* no returns in function, winrct gets set in the end again */
925 BLI_rcti_init(&ar->winrct, 0, 0, 0, 0);
927 /* for test; allow split of previously defined region */
928 if (ar->alignment & RGN_SPLIT_PREV)
930 remainder = &ar->prev->winrct;
932 alignment = ar->alignment & ~RGN_SPLIT_PREV;
934 /* clear state flags first */
935 ar->flag &= ~RGN_FLAG_TOO_SMALL;
937 if (ar->next == NULL && alignment != RGN_ALIGN_QSPLIT)
938 alignment = RGN_ALIGN_NONE;
940 /* prefsize, for header we stick to exception */
941 prefsizex = ar->sizex ? ar->sizex : ar->type->prefsizex;
942 if (ar->regiontype == RGN_TYPE_HEADER) {
943 prefsizey = ar->type->prefsizey;
945 else if (ar->regiontype == RGN_TYPE_UI && sa->spacetype == SPACE_FILE) {
946 prefsizey = UI_UNIT_Y * 2 + (UI_UNIT_Y / 2);
949 prefsizey = ar->sizey ? ar->sizey : ar->type->prefsizey;
953 if (ar->flag & RGN_FLAG_HIDDEN) {
954 /* hidden is user flag */
956 else if (alignment == RGN_ALIGN_FLOAT) {
957 /* XXX floating area region, not handled yet here */
959 else if (rct_fits(remainder, 'v', 1) < 0 || rct_fits(remainder, 'h', 1) < 0) {
960 /* remainder is too small for any usage */
961 ar->flag |= RGN_FLAG_TOO_SMALL;
963 else if (alignment == RGN_ALIGN_NONE) {
964 /* typically last region */
965 ar->winrct = *remainder;
966 BLI_rcti_init(remainder, 0, 0, 0, 0);
968 else if (alignment == RGN_ALIGN_TOP || alignment == RGN_ALIGN_BOTTOM) {
970 if (rct_fits(remainder, 'v', prefsizey) < 0) {
971 ar->flag |= RGN_FLAG_TOO_SMALL;
974 int fac = rct_fits(remainder, 'v', prefsizey);
979 ar->winrct = *remainder;
981 if (alignment == RGN_ALIGN_TOP) {
982 ar->winrct.ymin = ar->winrct.ymax - prefsizey + 1;
983 remainder->ymax = ar->winrct.ymin - 1;
986 ar->winrct.ymax = ar->winrct.ymin + prefsizey - 1;
987 remainder->ymin = ar->winrct.ymax + 1;
991 else if (ELEM4(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT, RGN_OVERLAP_LEFT, RGN_OVERLAP_RIGHT)) {
993 if (rct_fits(remainder, 'h', prefsizex) < 0) {
994 ar->flag |= RGN_FLAG_TOO_SMALL;
997 int fac = rct_fits(remainder, 'h', prefsizex);
1002 ar->winrct = *remainder;
1004 if (ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT)) {
1005 ar->winrct.xmin = ar->winrct.xmax - prefsizex + 1;
1006 if (alignment == RGN_ALIGN_RIGHT)
1007 remainder->xmax = ar->winrct.xmin - 1;
1010 ar->winrct.xmax = ar->winrct.xmin + prefsizex - 1;
1011 if (alignment == RGN_ALIGN_LEFT)
1012 remainder->xmin = ar->winrct.xmax + 1;
1016 else if (alignment == RGN_ALIGN_VSPLIT || alignment == RGN_ALIGN_HSPLIT) {
1017 /* percentage subdiv*/
1018 ar->winrct = *remainder;
1020 if (alignment == RGN_ALIGN_HSPLIT) {
1021 if (rct_fits(remainder, 'h', prefsizex) > 4) {
1022 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1023 remainder->xmin = ar->winrct.xmax + 1;
1026 BLI_rcti_init(remainder, 0, 0, 0, 0);
1030 if (rct_fits(remainder, 'v', prefsizey) > 4) {
1031 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1032 remainder->ymin = ar->winrct.ymax + 1;
1035 BLI_rcti_init(remainder, 0, 0, 0, 0);
1039 else if (alignment == RGN_ALIGN_QSPLIT) {
1040 ar->winrct = *remainder;
1042 /* test if there's still 4 regions left */
1044 ARegion *artest = ar->next;
1048 artest->alignment = RGN_ALIGN_QSPLIT;
1049 artest = artest->next;
1054 /* let's stop adding regions */
1055 BLI_rcti_init(remainder, 0, 0, 0, 0);
1056 if (G.debug & G_DEBUG)
1057 printf("region quadsplit failed\n");
1062 if (quad == 1) { /* left bottom */
1063 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1064 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1066 else if (quad == 2) { /* left top */
1067 ar->winrct.xmax = BLI_rcti_cent_x(remainder);
1068 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1070 else if (quad == 3) { /* right bottom */
1071 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1072 ar->winrct.ymax = BLI_rcti_cent_y(remainder);
1074 else { /* right top */
1075 ar->winrct.xmin = BLI_rcti_cent_x(remainder) + 1;
1076 ar->winrct.ymin = BLI_rcti_cent_y(remainder) + 1;
1077 BLI_rcti_init(remainder, 0, 0, 0, 0);
1085 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1086 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1088 /* set winrect for azones */
1089 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
1090 ar->winrct = *remainder;
1092 if (alignment == RGN_ALIGN_TOP)
1093 ar->winrct.ymin = ar->winrct.ymax;
1094 else if (alignment == RGN_ALIGN_BOTTOM)
1095 ar->winrct.ymax = ar->winrct.ymin;
1096 else if (ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT))
1097 ar->winrct.xmin = ar->winrct.xmax;
1098 else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_OVERLAP_LEFT))
1099 ar->winrct.xmax = ar->winrct.xmin;
1100 else /* prevent winrct to be valid */
1101 ar->winrct.xmax = ar->winrct.xmin;
1104 /* restore prev-split exception */
1105 if (ar->alignment & RGN_SPLIT_PREV) {
1107 remainder = remainder_prev;
1108 ar->prev->winx = BLI_rcti_size_x(&ar->prev->winrct) + 1;
1109 ar->prev->winy = BLI_rcti_size_y(&ar->prev->winrct) + 1;
1113 /* in end, add azones, where appropriate */
1114 if (ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
1115 /* The logic for this is: when the header takes up the full area,
1116 * disallow hiding it to view the main window.
1118 * Without this, you can drag down the file selectors header and hide it
1119 * by accident very easily (highly annoying!), the value 6 is arbitrary
1120 * but accounts for small common rounding problems when scaling the UI,
1121 * must be minimum '4' */
1124 region_azone_add(sa, ar, alignment);
1127 region_rect_recursive(sa, ar->next, remainder, quad);
1130 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
1132 short rt = 0; // CLAMPIS(G.debug_value, 0, 16);
1134 if (sa->v1->vec.x > 0) sa->totrct.xmin = sa->v1->vec.x + 1 + rt;
1135 else sa->totrct.xmin = sa->v1->vec.x;
1136 if (sa->v4->vec.x < sizex - 1) sa->totrct.xmax = sa->v4->vec.x - 1 - rt;
1137 else sa->totrct.xmax = sa->v4->vec.x;
1139 if (sa->v1->vec.y > 0) sa->totrct.ymin = sa->v1->vec.y + 1 + rt;
1140 else sa->totrct.ymin = sa->v1->vec.y;
1141 if (sa->v2->vec.y < sizey - 1) sa->totrct.ymax = sa->v2->vec.y - 1 - rt;
1142 else sa->totrct.ymax = sa->v2->vec.y;
1145 sa->winx = BLI_rcti_size_x(&sa->totrct) + 1;
1146 sa->winy = BLI_rcti_size_y(&sa->totrct) + 1;
1150 /* used for area initialize below */
1151 static void region_subwindow(wmWindow *win, ARegion *ar)
1153 if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
1155 wm_subwindow_close(win, ar->swinid);
1158 else if (ar->swinid == 0)
1159 ar->swinid = wm_subwindow_open(win, &ar->winrct);
1161 wm_subwindow_position(win, ar->swinid, &ar->winrct);
1164 static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
1166 /* note, add-handler checks if it already exists */
1168 /* XXX it would be good to have boundbox checks for some of these... */
1169 if (flag & ED_KEYMAP_UI) {
1170 /* user interface widgets */
1171 UI_add_region_handlers(handlers);
1173 if (flag & ED_KEYMAP_VIEW2D) {
1174 /* 2d-viewport handling+manipulation */
1175 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "View2D", 0, 0);
1176 WM_event_add_keymap_handler(handlers, keymap);
1178 if (flag & ED_KEYMAP_MARKERS) {
1180 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Markers", 0, 0);
1182 /* time space only has this keymap, the others get a boundbox restricted map */
1183 if (sa->spacetype != SPACE_TIME) {
1185 static rcti rect = {0, 10000, 0, 30}; /* same local check for all areas */
1186 ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
1188 WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
1192 WM_event_add_keymap_handler(handlers, keymap);
1194 if (flag & ED_KEYMAP_ANIMATION) {
1195 /* frame changing and timeline operators (for time spaces) */
1196 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Animation", 0, 0);
1197 WM_event_add_keymap_handler(handlers, keymap);
1199 if (flag & ED_KEYMAP_FRAMES) {
1200 /* frame changing/jumping (for all spaces) */
1201 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Frames", 0, 0);
1202 WM_event_add_keymap_handler(handlers, keymap);
1204 if (flag & ED_KEYMAP_GPENCIL) {
1206 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Grease Pencil", 0, 0);
1207 WM_event_add_keymap_handler(handlers, keymap);
1209 if (flag & ED_KEYMAP_HEADER) {
1210 /* standard keymap for headers regions */
1211 wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Header", 0, 0);
1212 WM_event_add_keymap_handler(handlers, keymap);
1217 /* called in screen_refresh, or screens_init, also area size changes */
1218 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
1223 /* set typedefinitions */
1224 sa->type = BKE_spacetype_from_id(sa->spacetype);
1226 if (sa->type == NULL) {
1227 sa->butspacetype = sa->spacetype = SPACE_VIEW3D;
1228 sa->type = BKE_spacetype_from_id(sa->spacetype);
1231 for (ar = sa->regionbase.first; ar; ar = ar->next)
1232 ar->type = BKE_regiontype_from_id(sa->type, ar->regiontype);
1235 area_calc_totrct(sa, win->sizex, win->sizey);
1237 /* clear all azones, add the area triange widgets */
1238 area_azone_initialize(win->screen, sa);
1240 /* region rect sizes */
1242 region_rect_recursive(sa, sa->regionbase.first, &rect, 0);
1244 /* default area handlers */
1245 ed_default_handlers(wm, sa, &sa->handlers, sa->type->keymapflag);
1246 /* checks spacedata, adds own handlers */
1248 sa->type->init(wm, sa);
1250 /* region windows, default and own handlers */
1251 for (ar = sa->regionbase.first; ar; ar = ar->next) {
1252 region_subwindow(win, ar);
1255 /* default region handlers */
1256 ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
1259 ar->type->init(wm, ar);
1262 /* prevent uiblocks to run */
1263 uiFreeBlocks(NULL, &ar->uiblocks);
1266 /* rechecks 2d matrix for header on dpi changing, do not do for other regions, it resets view && blocks view2d operator polls (ton) */
1267 if (ar->regiontype == RGN_TYPE_HEADER)
1268 ar->v2d.flag &= ~V2D_IS_INITIALISED;
1272 /* externally called for floating regions like menus */
1273 void ED_region_init(bContext *C, ARegion *ar)
1275 // ARegionType *at= ar->type;
1277 /* refresh can be called before window opened */
1278 region_subwindow(CTX_wm_window(C), ar);
1280 ar->winx = BLI_rcti_size_x(&ar->winrct) + 1;
1281 ar->winy = BLI_rcti_size_y(&ar->winrct) + 1;
1284 wmOrtho2(-0.01f, ar->winx - 0.01f, -0.01f, ar->winy - 0.01f);
1288 void ED_region_toggle_hidden(bContext *C, ARegion *ar)
1290 ScrArea *sa = CTX_wm_area(C);
1292 ar->flag ^= RGN_FLAG_HIDDEN;
1294 if (ar->flag & RGN_FLAG_HIDDEN)
1295 WM_event_remove_handlers(C, &ar->handlers);
1297 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1298 ED_area_tag_redraw(sa);
1301 /* sa2 to sa1, we swap spaces for fullscreen to keep all allocated data */
1302 /* area vertices were set */
1303 void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
1307 int spacetype = sa1->spacetype;
1309 sa1->headertype = sa2->headertype;
1310 sa1->spacetype = sa2->spacetype;
1311 sa1->butspacetype = sa2->butspacetype;
1313 if (swap_space == 1) {
1314 SWAP(ListBase, sa1->spacedata, sa2->spacedata);
1315 /* exception: ensure preview is reset */
1316 // if (sa1->spacetype == SPACE_VIEW3D)
1317 // XXX BIF_view3d_previewrender_free(sa1->spacedata.first);
1319 else if (swap_space == 2) {
1320 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
1323 BKE_spacedata_freelist(&sa1->spacedata);
1324 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
1327 /* Note; SPACE_EMPTY is possible on new screens */
1330 if (swap_space == 1) {
1331 SWAP(ListBase, sa1->regionbase, sa2->regionbase);
1334 if (swap_space < 2) {
1335 st = BKE_spacetype_from_id(spacetype);
1336 for (ar = sa1->regionbase.first; ar; ar = ar->next)
1337 BKE_area_region_free(st, ar);
1338 BLI_freelistN(&sa1->regionbase);
1341 st = BKE_spacetype_from_id(sa2->spacetype);
1342 for (ar = sa2->regionbase.first; ar; ar = ar->next) {
1343 ARegion *newar = BKE_area_region_copy(st, ar);
1344 BLI_addtail(&sa1->regionbase, newar);
1349 /* *********** Space switching code *********** */
1351 void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
1353 ScrArea *tmp = MEM_callocN(sizeof(ScrArea), "addscrarea");
1355 ED_area_exit(C, sa1);
1356 ED_area_exit(C, sa2);
1358 area_copy_data(tmp, sa1, 2);
1359 area_copy_data(sa1, sa2, 0);
1360 area_copy_data(sa2, tmp, 0);
1361 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa1);
1362 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa2);
1364 BKE_screen_area_free(tmp);
1367 /* tell WM to refresh, cursor types etc */
1368 WM_event_add_mousemove(C);
1370 ED_area_tag_redraw(sa1);
1371 ED_area_tag_refresh(sa1);
1372 ED_area_tag_redraw(sa2);
1373 ED_area_tag_refresh(sa2);
1376 void ED_area_newspace(bContext *C, ScrArea *sa, int type)
1378 if (sa->spacetype != type) {
1383 ED_area_exit(C, sa);
1385 st = BKE_spacetype_from_id(type);
1386 slold = sa->spacedata.first;
1388 sa->spacetype = type;
1389 sa->butspacetype = type;
1392 /* check previously stored space */
1393 for (sl = sa->spacedata.first; sl; sl = sl->next)
1394 if (sl->spacetype == type)
1397 /* old spacedata... happened during work on 2.50, remove */
1398 if (sl && sl->regionbase.first == NULL) {
1400 BLI_freelinkN(&sa->spacedata, sl);
1410 slold->regionbase = sa->regionbase;
1411 sa->regionbase = sl->regionbase;
1412 sl->regionbase.first = sl->regionbase.last = NULL;
1414 /* put in front of list */
1415 BLI_remlink(&sa->spacedata, sl);
1416 BLI_addhead(&sa->spacedata, sl);
1422 BLI_addhead(&sa->spacedata, sl);
1426 slold->regionbase = sa->regionbase;
1427 sa->regionbase = sl->regionbase;
1428 sl->regionbase.first = sl->regionbase.last = NULL;
1432 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1434 /* tell WM to refresh, cursor types etc */
1435 WM_event_add_mousemove(C);
1437 /* send space change notifier */
1438 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1440 ED_area_tag_refresh(sa);
1443 /* also redraw when re-used */
1444 ED_area_tag_redraw(sa);
1447 void ED_area_prevspace(bContext *C, ScrArea *sa)
1449 SpaceLink *sl = (sa) ? sa->spacedata.first : CTX_wm_space_data(C);
1452 /* workaround for case of double prevspace, render window
1453 * with a file browser on top of it */
1454 if (sl->next->spacetype == SPACE_FILE && sl->next->next)
1455 ED_area_newspace(C, sa, sl->next->next->spacetype);
1457 ED_area_newspace(C, sa, sl->next->spacetype);
1460 ED_area_newspace(C, sa, SPACE_INFO);
1462 ED_area_tag_redraw(sa);
1464 /* send space change notifier */
1465 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
1468 static const char *editortype_pup(void)
1470 const char *types = N_(
1483 "|UV/Image Editor %x6"
1485 "|Video Sequence Editor %x8"
1486 "|Movie Clip Editor %x20"
1489 "|Logic Editor %x17"
1495 "|User Preferences %x19"
1504 "|Python Console %x18"
1507 return IFACE_(types);
1510 static void spacefunc(struct bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
1512 ED_area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
1513 ED_area_tag_redraw(CTX_wm_area(C));
1515 /* send space change notifier */
1516 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, CTX_wm_area(C));
1519 /* returns offset for next button in header */
1520 int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
1522 ScrArea *sa = CTX_wm_area(C);
1526 but = uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D,
1527 editortype_pup(), xco, yco, UI_UNIT_X + 10, UI_UNIT_Y,
1528 &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0,
1529 TIP_("Display current editor type (click for a menu of available types)"));
1530 uiButSetFunc(but, spacefunc, NULL, NULL);
1531 uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
1533 return xco + UI_UNIT_X + 14;
1536 int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
1538 ScrArea *sa = CTX_wm_area(C);
1543 xco = ED_area_header_switchbutton(C, block, yco);
1545 uiBlockSetEmboss(block, UI_EMBOSSN);
1547 if (sa->flag & HEADER_NO_PULLDOWN) {
1548 but = uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
1549 ICON_DISCLOSURE_TRI_RIGHT,
1550 xco, yco, UI_UNIT_X, UI_UNIT_Y - 2,
1551 &(sa->flag), 0, 0, 0, 0,
1552 "Show pulldown menus");
1555 but = uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
1556 ICON_DISCLOSURE_TRI_DOWN,
1557 xco, yco, UI_UNIT_X, UI_UNIT_Y - 2,
1558 &(sa->flag), 0, 0, 0, 0,
1559 "Hide pulldown menus");
1562 uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
1564 uiBlockSetEmboss(block, UI_EMBOSS);
1566 return xco + UI_UNIT_X;
1569 /************************ standard UI regions ************************/
1571 void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
1573 ScrArea *sa = CTX_wm_area(C);
1574 uiStyle *style = UI_GetStyle();
1578 View2D *v2d = &ar->v2d;
1579 View2DScrollers *scrollers;
1580 int x, y, xco, yco, w, em, triangle, open, newcontext = 0;
1583 newcontext = UI_view2d_tab_set(v2d, contextnr);
1586 w = BLI_rctf_size_x(&v2d->cur);
1587 em = (ar->type->prefsizex) ? UI_UNIT_Y / 2 : UI_UNIT_Y;
1591 em = (ar->type->prefsizex) ? UI_UNIT_Y / 2 : UI_UNIT_Y;
1595 uiBeginPanels(C, ar);
1597 /* set view2d view matrix for scrolling (without scrollers) */
1598 UI_view2d_view_ortho(v2d);
1600 for (pt = ar->type->paneltypes.first; pt; pt = pt->next) {
1601 /* verify context */
1603 if (pt->context[0] && strcmp(context, pt->context) != 0)
1607 if (pt->draw && (!pt->poll || pt->poll(C, pt))) {
1608 block = uiBeginBlock(C, ar, pt->idname, UI_EMBOSS);
1609 panel = uiBeginPanel(sa, ar, block, pt, &open);
1611 /* bad fixed values */
1612 triangle = (int)(UI_UNIT_Y * 1.1f);
1614 if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
1615 /* for enabled buttons */
1616 panel->layout = uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
1617 triangle, UI_UNIT_Y + style->panelspace + 2, UI_UNIT_Y, 1, style);
1619 pt->draw_header(C, panel);
1621 uiBlockLayoutResolve(block, &xco, &yco);
1622 panel->labelofs = xco - triangle;
1623 panel->layout = NULL;
1626 panel->labelofs = 0;
1632 /* panel context can either be toolbar region or normal panels region */
1633 if (ar->regiontype == RGN_TYPE_TOOLS)
1634 panelContext = UI_LAYOUT_TOOLBAR;
1636 panelContext = UI_LAYOUT_PANEL;
1638 panel->layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, panelContext,
1639 style->panelspace, 0, w - 2 * style->panelspace, em, style);
1643 uiBlockLayoutResolve(block, &xco, &yco);
1644 panel->layout = NULL;
1646 yco -= 2 * style->panelspace;
1647 uiEndPanel(block, w, -yco);
1651 uiEndPanel(block, w, 0);
1654 uiEndBlock(C, block);
1658 /* align panels and return size */
1659 uiEndPanels(C, ar, &x, &y);
1662 UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
1663 glClear(GL_COLOR_BUFFER_BIT);
1665 /* before setting the view */
1667 /* only allow scrolling in vertical direction */
1668 v2d->keepofs |= V2D_LOCKOFS_X | V2D_KEEPOFS_Y;
1669 v2d->keepofs &= ~(V2D_LOCKOFS_Y | V2D_KEEPOFS_X);
1670 v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
1671 v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
1673 /* don't jump back when panels close or hide */
1675 y = MAX2(-y, -v2d->cur.ymin);
1680 /* for now, allow scrolling in both directions (since layouts are optimized for vertical,
1681 * they often don't fit in horizontal layout)
1683 v2d->keepofs &= ~(V2D_LOCKOFS_X | V2D_LOCKOFS_Y | V2D_KEEPOFS_X | V2D_KEEPOFS_Y);
1684 //v2d->keepofs |= V2D_LOCKOFS_Y|V2D_KEEPOFS_X;
1685 //v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_KEEPOFS_Y);
1686 v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
1687 v2d->scroll &= ~V2D_SCROLL_HORIZONTAL_HIDE;
1689 /* don't jump back when panels close or hide */
1691 x = MAX2(x, v2d->cur.xmax);
1695 /* +V2D_SCROLL_HEIGHT is workaround to set the actual height */
1696 UI_view2d_totRect_set(v2d, x + V2D_SCROLL_WIDTH, y + V2D_SCROLL_HEIGHT);
1699 UI_view2d_view_ortho(v2d);
1702 uiDrawPanels(C, ar);
1704 /* restore view matrix */
1705 UI_view2d_view_restore(C);
1708 scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1709 UI_view2d_scrollers_draw(C, v2d, scrollers);
1710 UI_view2d_scrollers_free(scrollers);
1713 void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
1717 /* XXX quick hacks for files saved with 2.5 already (i.e. the builtin defaults file)
1718 * scrollbars for button regions */
1719 ar->v2d.scroll |= (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
1720 ar->v2d.scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
1721 ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
1722 ar->v2d.keepzoom |= V2D_KEEPZOOM;
1724 /* correctly initialized User-Prefs? */
1725 if (!(ar->v2d.align & V2D_ALIGN_NO_POS_Y))
1726 ar->v2d.flag &= ~V2D_IS_INITIALISED;
1728 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy);
1730 keymap = WM_keymap_find(wm->defaultconf, "View2D Buttons List", 0, 0);
1731 WM_event_add_keymap_handler(&ar->handlers, keymap);
1734 void ED_region_header(const bContext *C, ARegion *ar)
1736 uiStyle *style = UI_GetStyle();
1740 Header header = {NULL};
1741 int maxco, xco, yco;
1742 int headery = ED_area_headersize();
1745 UI_ThemeClearColor((ED_screen_area_active(C)) ? TH_HEADER : TH_HEADERDESEL);
1746 glClear(GL_COLOR_BUFFER_BIT);
1748 /* set view2d view matrix for scrolling (without scrollers) */
1749 UI_view2d_view_ortho(&ar->v2d);
1754 /* draw all headers types */
1755 for (ht = ar->type->headertypes.first; ht; ht = ht->next) {
1756 block = uiBeginBlock(C, ar, ht->idname, UI_EMBOSS);
1757 layout = uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, UI_UNIT_Y, 1, style);
1761 header.layout = layout;
1762 ht->draw(C, &header);
1765 xco = uiLayoutGetWidth(layout);
1770 uiBlockLayoutResolve(block, &xco, &yco);
1776 uiEndBlock(C, block);
1777 uiDrawBlock(C, block);
1780 /* always as last */
1781 UI_view2d_totRect_set(&ar->v2d, maxco + UI_UNIT_X + 80, BLI_rctf_size_y(&ar->v2d.tot));
1783 /* restore view matrix? */
1784 UI_view2d_view_restore(C);
1787 void ED_region_header_init(ARegion *ar)
1789 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
1792 /* UI_UNIT_Y is defined as U variable now, depending dpi */
1793 int ED_area_headersize(void)
1795 return UI_UNIT_Y + 6;
1798 void ED_region_info_draw(ARegion *ar, const char *text, int block, float alpha)
1800 const int header_height = 18;
1801 uiStyle *style = UI_GetStyle();
1802 int fontid = style->widget.uifont_id;
1805 BLF_size(fontid, 11.0f, 72);
1807 /* background box */
1810 rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
1813 rect.xmax = BLI_rcti_size_x(&ar->winrct);
1816 rect.xmax = rect.xmin + BLF_width(fontid, text) + 24;
1819 rect.ymax = BLI_rcti_size_y(&ar->winrct);
1822 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1823 glColor4f(0.0f, 0.0f, 0.0f, alpha);
1824 glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
1825 glDisable(GL_BLEND);
1828 UI_ThemeColor(TH_TEXT_HI);
1829 BLF_position(fontid, 12, rect.ymin + 5, 0.0f);
1830 BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
1833 void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
1835 float gridsize, gridstep = 1.0f / 32.0f;
1836 float fac, blendfac;
1839 /* the image is located inside (0, 0), (1, 1) as set by view2d */
1840 UI_ThemeColorShade(TH_BACK, 20);
1842 UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
1843 UI_view2d_to_region_no_clip(&ar->v2d, 1.0f, 1.0f, &x2, &y2);
1844 glRectf(x1, y1, x2, y2);
1846 /* gridsize adapted to zoom level */
1847 gridsize = 0.5f * (zoomx + zoomy);
1848 if (gridsize <= 0.0f)
1851 if (gridsize < 1.0f) {
1852 while (gridsize < 1.0f) {
1858 while (gridsize >= 4.0f) {
1864 /* the fine resolution level */
1865 blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
1866 CLAMP(blendfac, 0.0f, 1.0f);
1867 UI_ThemeColorShade(TH_BACK, (int)(20.0f * (1.0f - blendfac)));
1871 while (fac < 1.0f) {
1872 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
1873 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
1874 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
1875 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
1879 /* the large resolution level */
1880 UI_ThemeColor(TH_BACK);
1883 while (fac < 1.0f) {
1884 glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
1885 glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
1886 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
1887 glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
1888 fac += 4.0f * gridstep;