4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
32 #include "MEM_guardedalloc.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_userdef_types.h"
37 #include "BLI_blenlib.h"
38 #include "BLI_arithb.h"
41 #include "BKE_context.h"
42 #include "BKE_global.h"
43 #include "BKE_screen.h"
44 #include "BKE_utildefines.h"
48 #include "wm_subwindow.h"
50 #include "ED_screen.h"
51 #include "ED_screen_types.h"
55 #include "BIF_glutil.h"
58 #include "UI_interface.h"
59 #include "UI_resources.h"
60 #include "UI_view2d.h"
62 #ifndef DISABLE_PYTHON
63 #include "BPY_extern.h"
66 #include "screen_intern.h"
68 /* general area and region code */
70 static void region_draw_emboss(ARegion *ar, rcti *scirct)
74 /* translate scissor rect to region space */
75 rect.xmin= scirct->xmin - ar->winrct.xmin;
76 rect.ymin= scirct->ymin - ar->winrct.ymin;
77 rect.xmax= scirct->xmax - ar->winrct.xmin;
78 rect.ymax= scirct->ymax - ar->winrct.ymin;
82 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
85 glColor4ub(0,0,0, 50);
86 sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
89 glColor4ub(0,0,0, 80);
90 sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
93 glColor4ub(255,255,255, 60);
94 sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
97 glColor4ub(255,255,255, 50);
98 sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
100 glDisable( GL_BLEND );
103 void ED_region_pixelspace(ARegion *ar)
105 int width= ar->winrct.xmax-ar->winrct.xmin+1;
106 int height= ar->winrct.ymax-ar->winrct.ymin+1;
108 wmOrtho2(-0.375, (float)width-0.375, -0.375, (float)height-0.375);
112 /* only exported for WM */
113 void ED_region_do_listen(ARegion *ar, wmNotifier *note)
115 /* generic notes first */
116 switch(note->category) {
118 if(note->data==ND_FILEREAD)
119 ED_region_tag_redraw(ar);
122 ED_region_tag_redraw(ar);
125 if(note->action==NA_EDITED)
126 ED_region_tag_redraw(ar);
129 if(ar->type && ar->type->listener)
130 ar->type->listener(ar, note);
134 /* only exported for WM */
135 void ED_area_do_listen(ScrArea *sa, wmNotifier *note)
137 /* no generic notes? */
138 if(sa->type && sa->type->listener) {
139 sa->type->listener(sa, note);
143 /* only exported for WM */
144 void ED_area_do_refresh(bContext *C, ScrArea *sa)
146 /* no generic notes? */
147 if(sa->type && sa->type->refresh) {
148 sa->type->refresh(C, sa);
153 /* based on screen region draw tags, set draw tags in azones, and future region tabs etc */
154 /* only exported for WM */
155 void ED_area_overdraw_flush(bContext *C, ScrArea *sa, ARegion *ar)
159 for(az= sa->actionzones.first; az; az= az->next) {
162 if(az->type==AZONE_AREA) {
163 xs= (az->x1+az->x2)/2;
164 ys= (az->y1+az->y2)/2;
172 if(BLI_in_rcti(&ar->winrct, xs, ys)) {
178 static void area_draw_azone(short x1, short y1, short x2, short y2)
185 float dx= 0.3f*(xmax-xmin);
186 float dy= 0.3f*(ymax-ymin);
188 glColor4ub(255, 255, 255, 80);
189 fdrawline(xmin, ymax, xmax, ymin);
190 fdrawline(xmin, ymax-dy, xmax-dx, ymin);
191 fdrawline(xmin, ymax-2*dy, xmax-2*dx, ymin);
193 glColor4ub(0, 0, 0, 150);
194 fdrawline(xmin, ymax+1, xmax+1, ymin);
195 fdrawline(xmin, ymax-dy+1, xmax-dx+1, ymin);
196 fdrawline(xmin, ymax-2*dy+1, xmax-2*dx+1, ymin);
199 static void region_draw_azone(ScrArea *sa, AZone *az)
201 if(az->ar==NULL) return;
203 UI_SetTheme(sa->spacetype, az->ar->type->regionid);
205 UI_ThemeColor(TH_BACK);
206 glBegin(GL_TRIANGLES);
207 glVertex2s(az->x1, az->y1);
208 glVertex2s(az->x2, az->y2);
209 glVertex2s(az->x3, az->y3);
212 UI_ThemeColorShade(TH_BACK, 50);
213 sdrawline(az->x1, az->y1, az->x3, az->y3);
215 UI_ThemeColorShade(TH_BACK, -50);
216 sdrawline(az->x2, az->y2, az->x3, az->y3);
221 /* only exported for WM */
222 void ED_area_overdraw(bContext *C)
224 wmWindow *win= CTX_wm_window(C);
225 bScreen *screen= CTX_wm_screen(C);
228 /* Draw AZones, in screenspace */
229 wmSubWindowSet(win, screen->mainwin);
231 glEnable( GL_BLEND );
232 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
234 for(sa= screen->areabase.first; sa; sa= sa->next) {
236 for(az= sa->actionzones.first; az; az= az->next) {
238 if(az->type==AZONE_AREA)
239 area_draw_azone(az->x1, az->y1, az->x2, az->y2);
240 else if(az->type==AZONE_REGION)
241 region_draw_azone(sa, az);
247 glDisable( GL_BLEND );
251 /* get scissor rect, checking overlapping regions */
252 static void region_scissor_winrct(ARegion *ar, rcti *winrct)
256 if(ELEM(ar->alignment, RGN_OVERLAP_LEFT, RGN_OVERLAP_RIGHT))
262 if(BLI_isect_rcti(winrct, &ar->winrct, NULL)) {
263 if(ar->flag & RGN_FLAG_HIDDEN);
264 else if(ar->alignment & RGN_SPLIT_PREV);
265 else if(ar->alignment==RGN_OVERLAP_LEFT) {
266 winrct->xmin= ar->winrct.xmax + 1;
268 else if(ar->alignment==RGN_OVERLAP_RIGHT) {
269 winrct->xmax= ar->winrct.xmin - 1;
276 /* only exported for WM */
277 /* makes region ready for drawing, sets pixelspace */
278 void ED_region_set(const bContext *C, ARegion *ar)
280 wmWindow *win= CTX_wm_window(C);
281 ScrArea *sa= CTX_wm_area(C);
284 /* checks other overlapping regions */
285 region_scissor_winrct(ar, &winrct);
289 /* note; this sets state, so we can use wmOrtho and friends */
290 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct);
292 UI_SetTheme(sa?sa->spacetype:0, ar->type?ar->type->regionid:0);
294 ED_region_pixelspace(ar);
298 /* only exported for WM */
299 void ED_region_do_draw(bContext *C, ARegion *ar)
301 wmWindow *win= CTX_wm_window(C);
302 ScrArea *sa= CTX_wm_area(C);
303 ARegionType *at= ar->type;
306 /* checks other overlapping regions */
307 region_scissor_winrct(ar, &winrct);
309 /* if no partial draw rect set, full rect */
310 if(ar->drawrct.xmin == ar->drawrct.xmax)
313 /* extra clip for safety */
314 ar->drawrct.xmin= MAX2(winrct.xmin, ar->drawrct.xmin);
315 ar->drawrct.ymin= MAX2(winrct.ymin, ar->drawrct.ymin);
316 ar->drawrct.xmax= MIN2(winrct.xmax, ar->drawrct.xmax);
317 ar->drawrct.ymax= MIN2(winrct.ymax, ar->drawrct.ymax);
320 /* note; this sets state, so we can use wmOrtho and friends */
321 wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct);
323 UI_SetTheme(sa?sa->spacetype:0, ar->type?ar->type->regionid:0);
325 /* optional header info instead? */
328 UI_GetThemeColor3fv(TH_HEADER, col);
329 glClearColor(col[0], col[1], col[2], 0.0);
330 glClear(GL_COLOR_BUFFER_BIT);
332 UI_ThemeColor(TH_TEXT);
333 BLF_draw_default(20, 8, 0.0f, ar->headerstr);
339 uiFreeInactiveBlocks(C, &ar->uiblocks);
342 region_draw_emboss(ar, &winrct);
344 /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
345 ED_region_pixelspace(ar);
348 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
351 /* **********************************
352 maybe silly, but let's try for now
353 to keep these tags protected
354 ********************************** */
356 void ED_region_tag_redraw(ARegion *ar)
359 /* zero region means full region redraw */
361 memset(&ar->drawrct, 0, sizeof(ar->drawrct));
365 void ED_region_tag_redraw_partial(ARegion *ar, rcti *rct)
369 /* no redraw set yet, set partial region */
373 else if(ar->drawrct.xmin != ar->drawrct.xmax) {
374 /* partial redraw already set, expand region */
375 ar->drawrct.xmin= MIN2(ar->drawrct.xmin, rct->xmin);
376 ar->drawrct.ymin= MIN2(ar->drawrct.ymin, rct->ymin);
377 ar->drawrct.xmax= MAX2(ar->drawrct.xmax, rct->xmax);
378 ar->drawrct.ymax= MAX2(ar->drawrct.ymax, rct->ymax);
383 void ED_area_tag_redraw(ScrArea *sa)
388 for(ar= sa->regionbase.first; ar; ar= ar->next)
389 ED_region_tag_redraw(ar);
392 void ED_area_tag_refresh(ScrArea *sa)
398 /* *************************************************************** */
400 /* use NULL to disable it */
401 void ED_area_headerprint(ScrArea *sa, const char *str)
405 for(ar= sa->regionbase.first; ar; ar= ar->next) {
406 if(ar->regiontype==RGN_TYPE_HEADER) {
408 if(ar->headerstr==NULL)
409 ar->headerstr= MEM_mallocN(256, "headerprint");
410 BLI_strncpy(ar->headerstr, str, 256);
412 else if(ar->headerstr) {
413 MEM_freeN(ar->headerstr);
416 ED_region_tag_redraw(ar);
421 /* ************************************************************ */
425 static void area_azone_initialize(ScrArea *sa)
429 /* reinitalize entirely, regions add azones too */
430 BLI_freelistN(&sa->actionzones);
432 /* set area action zones */
433 az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
434 BLI_addtail(&(sa->actionzones), az);
435 az->type= AZONE_AREA;
436 az->x1= sa->totrct.xmin;
437 az->y1= sa->totrct.ymin;
438 az->x2= sa->totrct.xmin + AZONESPOT-1;
439 az->y2= sa->totrct.ymin + AZONESPOT-1;
440 BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
442 az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
443 BLI_addtail(&(sa->actionzones), az);
444 az->type= AZONE_AREA;
445 az->x1= sa->totrct.xmax+1;
446 az->y1= sa->totrct.ymax+1;
447 az->x2= sa->totrct.xmax-AZONESPOT+1;
448 az->y2= sa->totrct.ymax-AZONESPOT+1;
449 BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
452 static void region_azone_initialize(ScrArea *sa, ARegion *ar, char edge)
456 az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
457 BLI_addtail(&(sa->actionzones), az);
458 az->type= AZONE_REGION;
463 az->x1= ar->winrct.xmin+AZONESPOT;
464 az->y1= ar->winrct.ymax;
465 az->x2= ar->winrct.xmin+2*AZONESPOT;
466 az->y2= ar->winrct.ymax;
467 az->x3= (az->x1+az->x2)/2;
468 az->y3= az->y2+AZONESPOT/2;
469 BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y3);
472 az->x1= ar->winrct.xmin+AZONESPOT;
473 az->y1= ar->winrct.ymin;
474 az->x2= ar->winrct.xmin+2*AZONESPOT;
475 az->y2= ar->winrct.ymin;
476 az->x3= (az->x1+az->x2)/2;
477 az->y3= az->y2-AZONESPOT/2;
478 BLI_init_rcti(&az->rect, az->x1, az->x2, az->y3, az->y1);
481 az->x1= ar->winrct.xmin;
482 az->y1= ar->winrct.ymax-AZONESPOT;
483 az->x2= ar->winrct.xmin;
484 az->y2= ar->winrct.ymax-2*AZONESPOT;
485 az->x3= az->x2-AZONESPOT/2;
486 az->y3= (az->y1+az->y2)/2;
487 BLI_init_rcti(&az->rect, az->x3, az->x1, az->y1, az->y2);
489 else { // if(edge=='r') {
490 az->x1= ar->winrct.xmax;
491 az->y1= ar->winrct.ymax-AZONESPOT;
492 az->x2= ar->winrct.xmax;
493 az->y2= ar->winrct.ymax-2*AZONESPOT;
494 az->x3= az->x2+AZONESPOT/2;
495 az->y3= (az->y1+az->y2)/2;
496 BLI_init_rcti(&az->rect, az->x1, az->x3, az->y1, az->y2);
499 /* if more azones on 1 spot, set offset */
500 for(azt= sa->actionzones.first; azt; azt= azt->next) {
502 if(az->x1==azt->x1 && az->y1==azt->y1) {
503 if(edge=='t' || edge=='b') {
507 BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y3);
513 BLI_init_rcti(&az->rect, az->x1, az->x3, az->y1, az->y2);
522 /* *************************************************************** */
524 static void region_azone_add(ScrArea *sa, ARegion *ar, int alignment)
526 /* edge code (t b l r) is where azone will be drawn */
528 if(alignment==RGN_ALIGN_TOP)
529 region_azone_initialize(sa, ar, 'b');
530 else if(alignment==RGN_ALIGN_BOTTOM)
531 region_azone_initialize(sa, ar, 't');
532 else if(ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT))
533 region_azone_initialize(sa, ar, 'l');
534 else if(ELEM(alignment, RGN_ALIGN_LEFT, RGN_OVERLAP_LEFT))
535 region_azone_initialize(sa, ar, 'r');
539 /* dir is direction to check, not the splitting edge direction! */
540 static int rct_fits(rcti *rect, char dir, int size)
543 return rect->xmax-rect->xmin - size;
546 return rect->ymax-rect->ymin - size;
550 static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int quad)
552 rcti *remainder_prev= remainder;
553 int prefsizex, prefsizey;
559 /* no returns in function, winrct gets set in the end again */
560 BLI_init_rcti(&ar->winrct, 0, 0, 0, 0);
562 /* for test; allow split of previously defined region */
563 if(ar->alignment & RGN_SPLIT_PREV)
565 remainder= &ar->prev->winrct;
567 alignment = ar->alignment & ~RGN_SPLIT_PREV;
569 /* clear state flags first */
570 ar->flag &= ~RGN_FLAG_TOO_SMALL;
572 if(ar->next==NULL && alignment!=RGN_ALIGN_QSPLIT)
573 alignment= RGN_ALIGN_NONE;
575 prefsizex= ar->type->minsizex;
576 prefsizey= ar->type->minsizey;
578 /* hidden is user flag */
579 if(ar->flag & RGN_FLAG_HIDDEN);
580 /* XXX floating area region, not handled yet here */
581 else if(alignment == RGN_ALIGN_FLOAT);
582 /* remainder is too small for any usage */
583 else if( rct_fits(remainder, 'v', 1)<0 || rct_fits(remainder, 'h', 1) < 0 ) {
584 ar->flag |= RGN_FLAG_TOO_SMALL;
586 else if(alignment==RGN_ALIGN_NONE) {
587 /* typically last region */
588 ar->winrct= *remainder;
589 BLI_init_rcti(remainder, 0, 0, 0, 0);
591 else if(alignment==RGN_ALIGN_TOP || alignment==RGN_ALIGN_BOTTOM) {
593 if( rct_fits(remainder, 'v', prefsizey) < 0 ) {
594 ar->flag |= RGN_FLAG_TOO_SMALL;
597 int fac= rct_fits(remainder, 'v', prefsizey);
602 ar->winrct= *remainder;
604 if(alignment==RGN_ALIGN_TOP) {
605 ar->winrct.ymin= ar->winrct.ymax - prefsizey + 1;
606 remainder->ymax= ar->winrct.ymin - 1;
609 ar->winrct.ymax= ar->winrct.ymin + prefsizey - 1;
610 remainder->ymin= ar->winrct.ymax + 1;
614 else if( ELEM4(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT, RGN_OVERLAP_LEFT, RGN_OVERLAP_RIGHT)) {
616 if( rct_fits(remainder, 'h', prefsizex) < 0 ) {
617 ar->flag |= RGN_FLAG_TOO_SMALL;
620 int fac= rct_fits(remainder, 'h', prefsizex);
625 ar->winrct= *remainder;
627 if(ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT)) {
628 ar->winrct.xmin= ar->winrct.xmax - prefsizex + 1;
629 if(alignment==RGN_ALIGN_RIGHT)
630 remainder->xmax= ar->winrct.xmin - 1;
633 ar->winrct.xmax= ar->winrct.xmin + prefsizex - 1;
634 if(alignment==RGN_ALIGN_LEFT)
635 remainder->xmin= ar->winrct.xmax + 1;
639 else if(alignment==RGN_ALIGN_VSPLIT || alignment==RGN_ALIGN_HSPLIT) {
640 /* percentage subdiv*/
641 ar->winrct= *remainder;
643 if(alignment==RGN_ALIGN_HSPLIT) {
644 if( rct_fits(remainder, 'h', prefsizex) > 4) {
645 ar->winrct.xmax= (remainder->xmin+remainder->xmax)/2;
646 remainder->xmin= ar->winrct.xmax+1;
649 BLI_init_rcti(remainder, 0, 0, 0, 0);
653 if( rct_fits(remainder, 'v', prefsizey) > 4) {
654 ar->winrct.ymax= (remainder->ymin+remainder->ymax)/2;
655 remainder->ymin= ar->winrct.ymax+1;
658 BLI_init_rcti(remainder, 0, 0, 0, 0);
662 else if(alignment==RGN_ALIGN_QSPLIT) {
663 ar->winrct= *remainder;
665 /* test if there's still 4 regions left */
667 ARegion *artest= ar->next;
671 artest->alignment= RGN_ALIGN_QSPLIT;
672 artest= artest->next;
677 /* let's stop adding regions */
678 BLI_init_rcti(remainder, 0, 0, 0, 0);
679 printf("region quadsplit failed\n");
684 if(quad==1) { /* left bottom */
685 ar->winrct.xmax = (remainder->xmin + remainder->xmax)/2;
686 ar->winrct.ymax = (remainder->ymin + remainder->ymax)/2;
688 else if(quad==2) { /* left top */
689 ar->winrct.xmax = (remainder->xmin + remainder->xmax)/2;
690 ar->winrct.ymin = 1 + (remainder->ymin + remainder->ymax)/2;
692 else if(quad==3) { /* right bottom */
693 ar->winrct.xmin = 1 + (remainder->xmin + remainder->xmax)/2;
694 ar->winrct.ymax = (remainder->ymin + remainder->ymax)/2;
696 else { /* right top */
697 ar->winrct.xmin = 1 + (remainder->xmin + remainder->xmax)/2;
698 ar->winrct.ymin = 1 + (remainder->ymin + remainder->ymax)/2;
699 BLI_init_rcti(remainder, 0, 0, 0, 0);
707 ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
708 ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
710 /* restore test exception */
711 if(ar->alignment & RGN_SPLIT_PREV) {
713 remainder= remainder_prev;
714 ar->prev->winx= ar->prev->winrct.xmax - ar->prev->winrct.xmin + 1;
715 ar->prev->winy= ar->prev->winrct.ymax - ar->prev->winrct.ymin + 1;
719 /* set winrect for azones */
720 if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
721 ar->winrct= *remainder;
723 if(alignment==RGN_ALIGN_TOP)
724 ar->winrct.ymin= ar->winrct.ymax;
725 else if(alignment==RGN_ALIGN_BOTTOM)
726 ar->winrct.ymax= ar->winrct.ymin;
727 else if(ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT))
728 ar->winrct.xmin= ar->winrct.xmax;
729 else if(ELEM(alignment, RGN_ALIGN_LEFT, RGN_OVERLAP_LEFT))
730 ar->winrct.xmax= ar->winrct.xmin;
731 else /* prevent winrct to be valid */
732 ar->winrct.xmax= ar->winrct.xmin;
734 /* in end, add azones, where appropriate */
735 region_azone_add(sa, ar, alignment);
738 region_rect_recursive(sa, ar->next, remainder, quad);
741 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
743 short rt= CLAMPIS(G.rt, 0, 16);
745 if(sa->v1->vec.x>0) sa->totrct.xmin= sa->v1->vec.x+1+rt;
746 else sa->totrct.xmin= sa->v1->vec.x;
747 if(sa->v4->vec.x<sizex-1) sa->totrct.xmax= sa->v4->vec.x-1-rt;
748 else sa->totrct.xmax= sa->v4->vec.x;
750 if(sa->v1->vec.y>0) sa->totrct.ymin= sa->v1->vec.y+1+rt;
751 else sa->totrct.ymin= sa->v1->vec.y;
752 if(sa->v2->vec.y<sizey-1) sa->totrct.ymax= sa->v2->vec.y-1-rt;
753 else sa->totrct.ymax= sa->v2->vec.y;
756 sa->winx= sa->totrct.xmax-sa->totrct.xmin+1;
757 sa->winy= sa->totrct.ymax-sa->totrct.ymin+1;
761 /* used for area initialize below */
762 static void region_subwindow(wmWindowManager *wm, wmWindow *win, ARegion *ar)
764 if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
766 wm_subwindow_close(win, ar->swinid);
769 else if(ar->swinid==0)
770 ar->swinid= wm_subwindow_open(win, &ar->winrct);
772 wm_subwindow_position(win, ar->swinid, &ar->winrct);
775 static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int flag)
777 /* note, add-handler checks if it already exists */
779 // XXX it would be good to have boundbox checks for some of these...
780 if(flag & ED_KEYMAP_UI) {
781 UI_add_region_handlers(handlers);
783 if(flag & ED_KEYMAP_VIEW2D) {
784 ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
785 WM_event_add_keymap_handler(handlers, keymap);
787 if(flag & ED_KEYMAP_MARKERS) {
788 ListBase *keymap= WM_keymap_listbase(wm, "Markers", 0, 0);
789 WM_event_add_keymap_handler(handlers, keymap);
790 // XXX need boundbox check urgently!!!
792 if(flag & ED_KEYMAP_ANIMATION) {
793 ListBase *keymap= WM_keymap_listbase(wm, "Animation", 0, 0);
794 WM_event_add_keymap_handler(handlers, keymap);
796 if(flag & ED_KEYMAP_FRAMES) {
797 ListBase *keymap= WM_keymap_listbase(wm, "Frames", 0, 0);
798 WM_event_add_keymap_handler(handlers, keymap);
803 /* called in screen_refresh, or screens_init, also area size changes */
804 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
809 /* set typedefinitions */
810 sa->type= BKE_spacetype_from_id(sa->spacetype);
813 sa->butspacetype= sa->spacetype= SPACE_VIEW3D;
814 sa->type= BKE_spacetype_from_id(sa->spacetype);
817 for(ar= sa->regionbase.first; ar; ar= ar->next)
818 ar->type= BKE_regiontype_from_id(sa->type, ar->regiontype);
821 area_calc_totrct(sa, win->sizex, win->sizey);
823 /* clear all azones, add the area triange widgets */
824 area_azone_initialize(sa);
826 /* region rect sizes */
828 region_rect_recursive(sa, sa->regionbase.first, &rect, 0);
830 /* default area handlers */
831 ed_default_handlers(wm, &sa->handlers, sa->type->keymapflag);
832 /* checks spacedata, adds own handlers */
834 sa->type->init(wm, sa);
836 /* region windows, default and own handlers */
837 for(ar= sa->regionbase.first; ar; ar= ar->next) {
838 region_subwindow(wm, win, ar);
841 /* default region handlers */
842 ed_default_handlers(wm, &ar->handlers, ar->type->keymapflag);
845 ar->type->init(wm, ar);
848 /* prevent uiblocks to run */
849 uiFreeBlocks(NULL, &ar->uiblocks);
855 /* externally called for floating regions like menus */
856 void ED_region_init(bContext *C, ARegion *ar)
858 // ARegionType *at= ar->type;
860 /* refresh can be called before window opened */
861 region_subwindow(CTX_wm_manager(C), CTX_wm_window(C), ar);
863 ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
864 ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
868 wmOrtho2(-0.01f, ar->winx-0.01f, -0.01f, ar->winy-0.01f);
873 /* sa2 to sa1, we swap spaces for fullscreen to keep all allocated data */
874 /* area vertices were set */
875 void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
880 sa1->headertype= sa2->headertype;
881 sa1->spacetype= sa2->spacetype;
882 sa1->butspacetype= sa2->butspacetype;
884 if(swap_space == 1) {
885 SWAP(ListBase, sa1->spacedata, sa2->spacedata);
886 /* exception: ensure preview is reset */
887 // if(sa1->spacetype==SPACE_VIEW3D)
888 // XXX BIF_view3d_previewrender_free(sa1->spacedata.first);
890 else if (swap_space == 2) {
891 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
894 BKE_spacedata_freelist(&sa1->spacedata);
895 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
898 /* Note; SPACE_EMPTY is possible on new screens */
902 st= BKE_spacetype_from_id(sa1->spacetype);
903 for(ar= sa1->regionbase.first; ar; ar= ar->next)
904 BKE_area_region_free(st, ar);
905 BLI_freelistN(&sa1->regionbase);
908 st= BKE_spacetype_from_id(sa2->spacetype);
909 for(ar= sa2->regionbase.first; ar; ar= ar->next) {
910 ARegion *newar= BKE_area_region_copy(st, ar);
911 BLI_addtail(&sa1->regionbase, newar);
915 /* *********** Space switching code *********** */
917 void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
919 ScrArea *tmp= MEM_callocN(sizeof(ScrArea), "addscrarea");
921 ED_area_exit(C, sa1);
922 ED_area_exit(C, sa2);
924 tmp->spacetype= sa1->spacetype;
925 tmp->butspacetype= sa1->butspacetype;
926 BKE_spacedata_copyfirst(&tmp->spacedata, &sa1->spacedata);
928 area_copy_data(tmp, sa1, 2);
929 area_copy_data(sa1, sa2, 0);
930 area_copy_data(sa2, tmp, 0);
931 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa1);
932 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa2);
934 BKE_screen_area_free(tmp);
937 /* tell WM to refresh, cursor types etc */
938 WM_event_add_mousemove(C);
940 ED_area_tag_redraw(sa1);
941 ED_area_tag_refresh(sa1);
942 ED_area_tag_redraw(sa2);
943 ED_area_tag_refresh(sa2);
946 void ED_area_newspace(bContext *C, ScrArea *sa, int type)
948 if(sa->spacetype != type) {
955 st= BKE_spacetype_from_id(type);
956 slold= sa->spacedata.first;
959 sa->butspacetype= type;
962 /* check previously stored space */
963 for (sl= sa->spacedata.first; sl; sl= sl->next)
964 if(sl->spacetype==type)
967 /* old spacedata... happened during work on 2.50, remove */
968 if(sl && sl->regionbase.first==NULL) {
970 BLI_freelinkN(&sa->spacedata, sl);
977 slold->regionbase= sa->regionbase;
978 sa->regionbase= sl->regionbase;
979 sl->regionbase.first= sl->regionbase.last= NULL;
981 /* put in front of list */
982 BLI_remlink(&sa->spacedata, sl);
983 BLI_addhead(&sa->spacedata, sl);
989 BLI_addhead(&sa->spacedata, sl);
993 slold->regionbase= sa->regionbase;
994 sa->regionbase= sl->regionbase;
995 sl->regionbase.first= sl->regionbase.last= NULL;
999 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1001 /* tell WM to refresh, cursor types etc */
1002 WM_event_add_mousemove(C);
1004 ED_area_tag_redraw(sa);
1005 ED_area_tag_refresh(sa);
1009 void ED_area_prevspace(bContext *C)
1011 SpaceLink *sl= CTX_wm_space_data(C);
1012 ScrArea *sa= CTX_wm_area(C);
1015 #if 0 // XXX needs to be space type specific
1016 if(sfile->spacetype==SPACE_FILE) {
1017 if(sfile->pupmenu) {
1018 MEM_freeN(sfile->pupmenu);
1019 sfile->pupmenu= NULL;
1026 #if 0 // XXX check whether this is still needed
1027 if (sfile->spacetype == SPACE_SCRIPT) {
1028 SpaceScript *sc = (SpaceScript *)sfile;
1029 if (sc->script) sc->script->flags &=~SCRIPT_FILESEL;
1033 ED_area_newspace(C, sa, sl->next->spacetype);
1036 ED_area_newspace(C, sa, SPACE_INFO);
1038 ED_area_tag_redraw(sa);
1041 static char *windowtype_pup(void)
1044 "Window type:%t" //14
1049 "|Graph Editor %x2" //54
1050 "|DopeSheet %x12" //73
1051 "|NLA Editor %x13" //94
1055 "|UV/Image Editor %x6" //117
1057 "|Video Sequence Editor %x8" //143
1058 "|Timeline %x15" //163
1059 // "|Audio Window %x11" //163
1060 "|Text Editor %x9" //179
1065 "|User Preferences %x7" //213
1066 "|Outliner %x3" //232
1067 "|Buttons Window %x4" //251
1069 "|Logic Editor %x17"
1072 "|File Browser %x5" //290
1076 // "|Scripts Window %x14"//313
1081 static void spacefunc(struct bContext *C, void *arg1, void *arg2)
1083 ED_area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
1084 ED_area_tag_redraw(CTX_wm_area(C));
1087 /* returns offset for next button in header */
1088 int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
1090 ScrArea *sa= CTX_wm_area(C);
1094 but= uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D,
1095 windowtype_pup(), xco, yco, XIC+10, YIC,
1096 &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0,
1097 "Displays Current Window Type. "
1098 "Click for menu of available types.");
1099 uiButSetFunc(but, spacefunc, NULL, NULL);
1101 return xco + XIC + 14;
1104 int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
1106 ScrArea *sa= CTX_wm_area(C);
1109 xco= ED_area_header_switchbutton(C, block, yco);
1111 uiBlockSetEmboss(block, UI_EMBOSSN);
1113 if (sa->flag & HEADER_NO_PULLDOWN) {
1114 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
1115 ICON_DISCLOSURE_TRI_RIGHT,
1117 &(sa->flag), 0, 0, 0, 0,
1118 "Show pulldown menus");
1121 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
1122 ICON_DISCLOSURE_TRI_DOWN,
1124 &(sa->flag), 0, 0, 0, 0,
1125 "Hide pulldown menus");
1128 uiBlockSetEmboss(block, UI_EMBOSS);
1133 /************************ standard UI regions ************************/
1135 void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *context, int contextnr)
1137 ScrArea *sa= CTX_wm_area(C);
1138 uiStyle *style= U.uistyles.first;
1142 View2D *v2d= &ar->v2d;
1143 View2DScrollers *scrollers;
1145 int xco, yco, x, y, miny=0, w, em, header, triangle, open, newcontext= 0;
1148 newcontext= UI_view2d_tab_set(v2d, contextnr);
1151 w= v2d->cur.xmax - v2d->cur.xmin;
1152 em= (ar->type->minsizex)? 10: 20;
1156 em= (ar->type->minsizex)? 10: 20;
1160 y= -style->panelouter;
1163 uiBeginPanels(C, ar);
1165 /* set view2d view matrix for scrolling (without scrollers) */
1166 UI_view2d_view_ortho(C, v2d);
1168 for(pt= ar->type->paneltypes.first; pt; pt= pt->next) {
1169 /* verify context */
1171 if(pt->context[0] && strcmp(context, pt->context) != 0)
1175 if(pt->draw && (!pt->poll || pt->poll(C, pt))) {
1176 block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS);
1177 panel= uiBeginPanel(sa, ar, block, pt, &open);
1179 /* bad fixed values */
1180 header= (pt->flag & PNL_NO_HEADER)? 0: 20;
1186 if(pt->draw_header && header && (open || vertical)) {
1187 /* for enabled buttons */
1188 panel->layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
1189 triangle, header+style->panelspace, header, 1, style);
1191 pt->draw_header(C, panel);
1193 uiBlockLayoutResolve(C, block, &xco, &yco);
1194 panel->labelofs= xco - triangle;
1195 panel->layout= NULL;
1199 panel->layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
1200 style->panelspace, 0, w-2*style->panelspace, em, style);
1204 uiBlockLayoutResolve(C, block, &xco, &yco);
1205 panel->layout= NULL;
1207 yco -= 2*style->panelspace;
1208 uiEndPanel(block, w, -yco);
1212 uiEndPanel(block, w, 0);
1215 uiEndBlock(C, block);
1218 if(pt->flag & PNL_NO_HEADER)
1221 y += yco-style->panelouter;
1225 miny= MIN2(y, yco-style->panelouter-header);
1235 /* in case there are no panels */
1236 if(x == 0 || y == 0) {
1242 UI_GetThemeColor3fv(TH_BACK, col);
1243 glClearColor(col[0], col[1], col[2], 0.0);
1244 glClear(GL_COLOR_BUFFER_BIT);
1246 /* before setting the view */
1248 v2d->keepofs |= V2D_LOCKOFS_X|V2D_KEEPOFS_Y;
1249 v2d->keepofs &= ~(V2D_LOCKOFS_Y|V2D_KEEPOFS_X);
1251 // don't jump back when panels close or hide
1253 y= MAX2(-y, -v2d->cur.ymin);
1258 v2d->keepofs |= V2D_LOCKOFS_Y|V2D_KEEPOFS_X;
1259 v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_KEEPOFS_Y);
1261 // don't jump back when panels close or hide
1263 x= MAX2(x, v2d->cur.xmax);
1267 // +V2D_SCROLL_HEIGHT is workaround to set the actual height
1268 UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
1271 UI_view2d_view_ortho(C, v2d);
1273 /* this does the actual drawing! */
1276 /* restore view matrix */
1277 UI_view2d_view_restore(C);
1280 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1281 UI_view2d_scrollers_draw(C, v2d, scrollers);
1282 UI_view2d_scrollers_free(scrollers);
1285 void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
1289 // XXX quick hacks for files saved with 2.5 already (i.e. the builtin defaults file)
1290 // scrollbars for button regions
1291 ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
1292 ar->v2d.keepzoom |= V2D_KEEPZOOM;
1294 // correctly initialised User-Prefs?
1295 if(!(ar->v2d.align & V2D_ALIGN_NO_POS_Y))
1296 ar->v2d.flag &= ~V2D_IS_INITIALISED;
1298 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy);
1300 keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0);
1301 WM_event_add_keymap_handler(&ar->handlers, keymap);
1304 void ED_region_header(const bContext *C, ARegion *ar)
1306 uiStyle *style= U.uistyles.first;
1310 Header header = {0};
1315 if(ED_screen_area_active(C))
1316 UI_GetThemeColor3fv(TH_HEADER, col);
1318 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
1320 glClearColor(col[0], col[1], col[2], 0.0);
1321 glClear(GL_COLOR_BUFFER_BIT);
1323 /* set view2d view matrix for scrolling (without scrollers) */
1324 UI_view2d_view_ortho(C, &ar->v2d);
1329 /* draw all headers types */
1330 for(ht= ar->type->headertypes.first; ht; ht= ht->next) {
1331 block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
1332 layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, HEADERY-6, 1, style);
1336 header.layout= layout;
1337 ht->draw(C, &header);
1340 uiBlockLayoutResolve(C, block, &xco, &yco);
1341 uiEndBlock(C, block);
1342 uiDrawBlock(C, block);
1345 /* always as last */
1346 UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
1348 /* restore view matrix? */
1349 UI_view2d_view_restore(C);
1352 void ED_region_header_init(ARegion *ar)
1354 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);