Cycles: svn merge -r39457:39669 https://svn.blender.org/svnroot/bf-blender/trunk...
[blender-staging.git] / source / blender / editors / screen / area.c
index 758a2b1d8ef219dc7893128827d8b8addbd8f54e..8bb808f9641fca856355c391ddbe128075587c85 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/screen/area.c
+ *  \ingroup edscr
+ */
+
+
 #include <string.h>
 #include <stdio.h>
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
-#include "BKE_utildefines.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -48,6 +53,7 @@
 
 #include "ED_screen.h"
 #include "ED_screen_types.h"
+#include "ED_space_api.h"
 #include "ED_types.h"
 #include "ED_fileselect.h" 
 
 
 /* general area and region code */
 
-static void region_draw_emboss(ARegion *ar, rcti *scirct)
-{
-       rcti rect;
-       
-       /* translate scissor rect to region space */
-       rect.xmin= scirct->xmin - ar->winrct.xmin;
-       rect.ymin= scirct->ymin - ar->winrct.ymin;
-       rect.xmax= scirct->xmax - ar->winrct.xmin;
-       rect.ymax= scirct->ymax - ar->winrct.ymin;
-       
-       /* set transp line */
-       glEnable( GL_BLEND );
-       glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
-       
-       /* right  */
-       glColor4ub(0,0,0, 50);
-       sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
-       
-       /* bottom  */
-       glColor4ub(0,0,0, 80);
-       sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
-       
-       /* top  */
-       glColor4ub(255,255,255, 60);
-       sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
-
-       /* left  */
-       glColor4ub(255,255,255, 50);
-       sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
-       
-       glDisable( GL_BLEND );
-}
-
 void ED_region_pixelspace(ARegion *ar)
 {
        int width= ar->winrct.xmax-ar->winrct.xmin+1;
        int height= ar->winrct.ymax-ar->winrct.ymin+1;
        
-       wmOrtho2(-0.375, (float)width-0.375, -0.375, (float)height-0.375);
+       wmOrtho2(-0.375f, (float)width-0.375f, -0.375f, (float)height-0.375f);
        glLoadIdentity();
 }
 
@@ -117,12 +90,6 @@ void ED_region_do_listen(ARegion *ar, wmNotifier *note)
                case NC_WINDOW:
                        ED_region_tag_redraw(ar);
                        break;
-#ifndef WM_FAST_DRAW
-               case NC_SCREEN:
-                       if(note->action==NA_EDITED)
-                               ED_region_tag_redraw(ar);
-                       break;
-#endif
        }
 
        if(ar->type && ar->type->listener)
@@ -150,7 +117,7 @@ void ED_area_do_refresh(bContext *C, ScrArea *sa)
 
 /* based on screen region draw tags, set draw tags in azones, and future region tabs etc */
 /* only exported for WM */
-void ED_area_overdraw_flush(bContext *C, ScrArea *sa, ARegion *ar)
+void ED_area_overdraw_flush(ScrArea *sa, ARegion *ar)
 {
        AZone *az;
        
@@ -169,37 +136,23 @@ void ED_area_overdraw_flush(bContext *C, ScrArea *sa, ARegion *ar)
 
 static void area_draw_azone(short x1, short y1, short x2, short y2)
 {
-       float xmin = x1;
-       float xmax = x2-2;
-       float ymin = y1-1;
-       float ymax = y2-3;
-       
-       float dx= 0.3f*(xmax-xmin);
-       float dy= 0.3f*(ymax-ymin);
-       
-       glColor4ub(255, 255, 255, 80);
-       fdrawline(xmin, ymax, xmax, ymin);
-       fdrawline(xmin, ymax-dy, xmax-dx, ymin);
-       fdrawline(xmin, ymax-2*dy, xmax-2*dx, ymin);
-       
-       glColor4ub(0, 0, 0, 150);
-       fdrawline(xmin, ymax+1, xmax+1, ymin);
-       fdrawline(xmin, ymax-dy+1, xmax-dx+1, ymin);
-       fdrawline(xmin, ymax-2*dy+1, xmax-2*dx+1, ymin);
+       int dx= floor(0.9f*(x2-x1));
+       int dy= floor(0.9f*(y2-y1));
+
+       glColor4f(0.0f, 0.0f, 0.0f, 0.25f);
+       glBegin(GL_TRIANGLES);
+       glVertex2f(x1, y1);
+       glVertex2f(x1+dx, y1);
+       glVertex2f(x1, y1+dy);
+       glEnd();
 }
 
-
-static void region_draw_azone(ScrArea *sa, AZone *az)
+static void region_draw_azone_icon(AZone *az)
 {
        GLUquadricObj *qobj = NULL; 
        short midx = az->x1 + (az->x2 - az->x1)/2;
        short midy = az->y1 + (az->y2 - az->y1)/2;
-       
-       if(az->ar==NULL) return;
-       
-       /* only display action zone icons when the region is hidden */
-       if (!(az->ar->flag & RGN_FLAG_HIDDEN)) return;
-       
+               
        qobj = gluNewQuadric();
        
        glPushMatrix();         
@@ -228,6 +181,79 @@ static void region_draw_azone(ScrArea *sa, AZone *az)
        sdrawline(midx-2, midy, midx+3, midy);
 }
 
+static void region_draw_azone_tab(AZone *az)
+{
+       float col[3];
+       
+       glEnable(GL_BLEND);
+       UI_GetThemeColor3fv(TH_HEADER, col);
+       glColor4f(col[0], col[1], col[2], 0.5f);
+       
+       /* add code to draw region hidden as 'too small' */
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       uiSetRoundBox(3 + 16);
+                       
+                       uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
+                       glColor4ub(0, 0, 0, 255);
+                       uiRoundRect((float)az->x1, 0.3f+(float)az->y1, (float)az->x2, 0.3f+(float)az->y2, 4.0f);
+                       break;
+               case AE_BOTTOM_TO_TOPLEFT:
+                       uiSetRoundBox(12 + 16);
+                       
+                       uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
+                       glColor4ub(0, 0, 0, 255);
+                       uiRoundRect((float)az->x1, 0.3f+(float)az->y1, (float)az->x2, 0.3f+(float)az->y2, 4.0f);
+                       break;
+               case AE_LEFT_TO_TOPRIGHT:
+                       uiSetRoundBox(9 + 16);
+                       
+                       uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
+                       glColor4ub(0, 0, 0, 255);
+                       uiRoundRect((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
+                       break;
+               case AE_RIGHT_TO_TOPLEFT:
+                       uiSetRoundBox(6 + 16);
+                       
+                       uiDrawBoxShade(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
+                       glColor4ub(0, 0, 0, 255);
+                       uiRoundRect((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
+                       break;
+       }
+       
+       glDisable(GL_BLEND);
+}
+
+static void region_draw_azone_tria(AZone *az)
+{
+       extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
+       
+       glEnable(GL_BLEND);
+       //UI_GetThemeColor3fv(TH_HEADER, col);
+       glColor4f(0.0f, 0.0f, 0.0f, 0.35f);
+       
+       /* add code to draw region hidden as 'too small' */
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       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);
+                       break;
+                       
+               case AE_BOTTOM_TO_TOPLEFT:
+                       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);
+                       break;
+
+               case AE_LEFT_TO_TOPRIGHT:
+                       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);
+                       break;
+                       
+               case AE_RIGHT_TO_TOPLEFT:
+                       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);
+                       break;
+                       
+       }
+       
+       glDisable(GL_BLEND);
+}
 
 /* only exported for WM */
 void ED_area_overdraw(bContext *C)
@@ -249,7 +275,22 @@ void ED_area_overdraw(bContext *C)
                                if(az->type==AZONE_AREA) {
                                        area_draw_azone(az->x1, az->y1, az->x2, az->y2);
                                } else if(az->type==AZONE_REGION) {
-                                       region_draw_azone(sa, az);
+                                       if(0) {
+                                       
+                                       if(az->ar) {
+                                               /* only display tab or icons when the region is hidden */
+                                               if (az->ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
+                                       
+                                                       if(G.rt==2)
+                                                               region_draw_azone_tria(az);
+                                                       else if(G.rt==1)
+                                                               region_draw_azone_tab(az);
+                                                       else
+                                                               region_draw_azone_icon(az);
+                                               }
+                                       }
+
+                                       }
                                }
                                
                                az->do_draw= 0;
@@ -315,6 +356,10 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
        ARegionType *at= ar->type;
        rcti winrct;
        
+       /* see BKE_spacedata_draw_locks() */
+       if(at->do_lock)
+               return;
+       
        /* checks other overlapping regions */
        region_scissor_winrct(ar, &winrct);
        
@@ -331,6 +376,9 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
        
        /* note; this sets state, so we can use wmOrtho and friends */
        wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct);
+
+       ar->do_draw= 0;
+       memset(&ar->drawrct, 0, sizeof(ar->drawrct));
        
        UI_SetTheme(sa?sa->spacetype:0, ar->type?ar->type->regionid:0);
        
@@ -340,22 +388,21 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
                glClear(GL_COLOR_BUFFER_BIT);
                
                UI_ThemeColor(TH_TEXT);
-               BLF_draw_default(20, 8, 0.0f, ar->headerstr);
+               BLF_draw_default(20, 8, 0.0f, ar->headerstr, 65535); /* XXX, use real length */
        }
        else if(at->draw) {
                at->draw(C, ar);
        }
+
+       ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL);
        
        uiFreeInactiveBlocks(C, &ar->uiblocks);
        
-       if(sa)
-               region_draw_emboss(ar, &winrct);
+       /*if(sa)
+               region_draw_emboss(ar, &winrct);*/
        
        /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
        ED_region_pixelspace(ar);
-       
-       ar->do_draw= 0;
-       memset(&ar->drawrct, 0, sizeof(ar->drawrct));
 }
 
 /* **********************************
@@ -372,6 +419,12 @@ void ED_region_tag_redraw(ARegion *ar)
        }
 }
 
+void ED_region_tag_redraw_overlay(ARegion *ar)
+{
+       if(ar)
+               ar->do_draw_overlay= RGN_DRAW;
+}
+
 void ED_region_tag_redraw_partial(ARegion *ar, rcti *rct)
 {
        if(ar) {
@@ -399,6 +452,19 @@ void ED_area_tag_redraw(ScrArea *sa)
                        ED_region_tag_redraw(ar);
 }
 
+void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype)
+{
+       ARegion *ar;
+       
+       if(sa) {
+               for(ar= sa->regionbase.first; ar; ar= ar->next) {
+                       if(ar->regiontype == regiontype) {
+                               ED_region_tag_redraw(ar);
+                       }
+               }
+       }
+}
+
 void ED_area_tag_refresh(ScrArea *sa)
 {
        if(sa)
@@ -411,7 +477,11 @@ void ED_area_tag_refresh(ScrArea *sa)
 void ED_area_headerprint(ScrArea *sa, const char *str)
 {
        ARegion *ar;
-       
+
+       /* happens when running transform operators in backround mode */
+       if(sa == NULL)
+               return;
+
        for(ar= sa->regionbase.first; ar; ar= ar->next) {
                if(ar->regiontype==RGN_TYPE_HEADER) {
                        if(str) {
@@ -431,7 +501,6 @@ void ED_area_headerprint(ScrArea *sa, const char *str)
 /* ************************************************************ */
 
 
-#define AZONESPOT              12
 static void area_azone_initialize(ScrArea *sa) 
 {
        AZone *az;
@@ -445,8 +514,8 @@ static void area_azone_initialize(ScrArea *sa)
        az->type= AZONE_AREA;
        az->x1= sa->totrct.xmin;
        az->y1= sa->totrct.ymin;
-       az->x2= sa->totrct.xmin + AZONESPOT-1;
-       az->y2= sa->totrct.ymin + AZONESPOT-1;
+       az->x2= sa->totrct.xmin + AZONESPOT;
+       az->y2= sa->totrct.ymin + AZONESPOT;
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
        
        az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
@@ -454,132 +523,164 @@ static void area_azone_initialize(ScrArea *sa)
        az->type= AZONE_AREA;
        az->x1= sa->totrct.xmax+1;
        az->y1= sa->totrct.ymax+1;
-       az->x2= sa->totrct.xmax-AZONESPOT+1;
-       az->y2= sa->totrct.ymax-AZONESPOT+1;
+       az->x2= sa->totrct.xmax-AZONESPOT;
+       az->y2= sa->totrct.ymax-AZONESPOT;
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
 }
 
 #define AZONEPAD_EDGE  4
-#define AZONEPAD_ICON  8
+#define AZONEPAD_ICON  9
 static void region_azone_edge(AZone *az, ARegion *ar)
 {
-       if(az->edge=='t') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymax - AZONEPAD_EDGE;
-               az->x2= ar->winrct.xmax;
-               az->y2= ar->winrct.ymax;
-       }
-       else if(az->edge=='b') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymin + AZONEPAD_EDGE;
-               az->x2= ar->winrct.xmax;
-               az->y2= ar->winrct.ymin;
-       }
-       else if(az->edge=='l') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymin;
-               az->x2= ar->winrct.xmin + AZONEPAD_EDGE;
-               az->y2= ar->winrct.ymax;
-       }
-       else { // if(az->edge=='r') {
-               az->x1= ar->winrct.xmax;
-               az->y1= ar->winrct.ymin;
-               az->x2= ar->winrct.xmax - AZONEPAD_EDGE;
-               az->y2= ar->winrct.ymax;
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymax - AZONEPAD_EDGE;
+                       az->x2= ar->winrct.xmax;
+                       az->y2= ar->winrct.ymax;
+                       break;
+               case AE_BOTTOM_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymin + AZONEPAD_EDGE;
+                       az->x2= ar->winrct.xmax;
+                       az->y2= ar->winrct.ymin;
+                       break;
+               case AE_LEFT_TO_TOPRIGHT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymin;
+                       az->x2= ar->winrct.xmin + AZONEPAD_EDGE;
+                       az->y2= ar->winrct.ymax;
+                       break;
+               case AE_RIGHT_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmax;
+                       az->y1= ar->winrct.ymin;
+                       az->x2= ar->winrct.xmax - AZONEPAD_EDGE;
+                       az->y2= ar->winrct.ymax;
+                       break;
        }
 
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
 }
 
-static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
+#define AZONEPAD_TABW  18
+#define AZONEPAD_TABH  7
+
+/* region already made zero sized, in shape of edge */
+static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar)
 {
        AZone *azt;
-       int tot=0;
+       int tot= 0, add;
        
        for(azt= sa->actionzones.first; azt; azt= azt->next) {
                if(azt->edge == az->edge) tot++;
        }
        
-       if(az->edge=='t') {
-               az->x1= ar->winrct.xmax - tot*2*AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax + AZONEPAD_ICON;
-               az->x2= ar->winrct.xmax - tot*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax + 2*AZONEPAD_ICON;
-       }
-       else if(az->edge=='b') {
-               az->x1= ar->winrct.xmin + AZONEPAD_ICON;
-               az->y1= ar->winrct.ymin - 2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmin + 2*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymin - AZONEPAD_ICON;
-       }
-       else if(az->edge=='l') {
-               az->x1= ar->winrct.xmin - 2*AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmin - AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
-       }
-       else { // if(az->edge=='r') {
-               az->x1= ar->winrct.xmax + AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmax + 2*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       if(ar->winrct.ymax == sa->totrct.ymin) add= 1; else add= 0;
+                       az->x1= ar->winrct.xmax - 2*AZONEPAD_TABW;
+                       az->y1= ar->winrct.ymax - add;
+                       az->x2= ar->winrct.xmax - AZONEPAD_TABW;
+                       az->y2= ar->winrct.ymax - add + AZONEPAD_TABH;
+                       break;
+               case AE_BOTTOM_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmin + AZONEPAD_TABW;
+                       az->y1= ar->winrct.ymin - AZONEPAD_TABH;
+                       az->x2= ar->winrct.xmin + 2*AZONEPAD_TABW;
+                       az->y2= ar->winrct.ymin;
+                       break;
+               case AE_LEFT_TO_TOPRIGHT:
+                       az->x1= ar->winrct.xmin + 1 - AZONEPAD_TABH;
+                       az->y1= ar->winrct.ymax - 2*AZONEPAD_TABW;
+                       az->x2= ar->winrct.xmin + 1;
+                       az->y2= ar->winrct.ymax - AZONEPAD_TABW;
+                       break;
+               case AE_RIGHT_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmax - 1;
+                       az->y1= ar->winrct.ymax - 2*AZONEPAD_TABW;
+                       az->x2= ar->winrct.xmax - 1 + AZONEPAD_TABH;
+                       az->y2= ar->winrct.ymax - AZONEPAD_TABW;
+                       break;
        }
-
+       /* rect needed for mouse pointer test */
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
+}      
+
+#define AZONEPAD_TRIAW 16
+#define AZONEPAD_TRIAH 9
+
+
+/* region already made zero sized, in shape of edge */
+static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar)
+{
+       AZone *azt;
+       int tot= 0, add;
        
-       /* if more azones on 1 spot, set offset */
        for(azt= sa->actionzones.first; azt; azt= azt->next) {
-               if(az!=azt) {
-                       if( ABS(az->x1-azt->x1) < 2 && ABS(az->y1-azt->y1) < 2) {
-                               if(az->edge=='t' || az->edge=='b') {
-                                       az->x1+= AZONESPOT;
-                                       az->x2+= AZONESPOT;
-                                       BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
-                               }
-                               else {
-                                       az->y1-= AZONESPOT;
-                                       az->y2-= AZONESPOT;
-                                       BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
-                               }
-                       }
-               }
+               if(azt->edge == az->edge) tot++;
        }
-}
+       
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       if(ar->winrct.ymax == sa->totrct.ymin) add= 1; else add= 0;
+                       az->x1= ar->winrct.xmax - 2*AZONEPAD_TRIAW;
+                       az->y1= ar->winrct.ymax - add;
+                       az->x2= ar->winrct.xmax - AZONEPAD_TRIAW;
+                       az->y2= ar->winrct.ymax - add + AZONEPAD_TRIAH;
+                       break;
+                       case AE_BOTTOM_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmin + AZONEPAD_TRIAW;
+                       az->y1= ar->winrct.ymin - AZONEPAD_TRIAH;
+                       az->x2= ar->winrct.xmin + 2*AZONEPAD_TRIAW;
+                       az->y2= ar->winrct.ymin;
+                       break;
+                       case AE_LEFT_TO_TOPRIGHT:
+                       az->x1= ar->winrct.xmin + 1 - AZONEPAD_TRIAH;
+                       az->y1= ar->winrct.ymax - 2*AZONEPAD_TRIAW;
+                       az->x2= ar->winrct.xmin + 1;
+                       az->y2= ar->winrct.ymax - AZONEPAD_TRIAW;
+                       break;
+                       case AE_RIGHT_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmax - 1;
+                       az->y1= ar->winrct.ymax - 2*AZONEPAD_TRIAW;
+                       az->x2= ar->winrct.xmax - 1 + AZONEPAD_TRIAH;
+                       az->y2= ar->winrct.ymax - AZONEPAD_TRIAW;
+                       break;
+       }
+       /* rect needed for mouse pointer test */
+       BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
+}      
 
-static void region_azone_initialize(ScrArea *sa, ARegion *ar, char edge) 
+
+static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge) 
 {
-       AZone *az;
-       
-       az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
-       BLI_addtail(&(sa->actionzones), az);
-       az->type= AZONE_REGION;
-       az->ar= ar;
-       az->edge= edge;
-       
-       if (ar->flag & RGN_FLAG_HIDDEN) {
-               region_azone_icon(sa, az, ar);
-       } else {
+       if(!(ar->flag & RGN_FLAG_HIDDEN)) {
+               AZone *az;
+               
+               az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
+               BLI_addtail(&(sa->actionzones), az);
+               az->type= AZONE_REGION;
+               az->ar= ar;
+               az->edge= edge;
+               
                region_azone_edge(az, ar);
        }
-       
 }
 
-
 /* *************************************************************** */
 
 static void region_azone_add(ScrArea *sa, ARegion *ar, int alignment)
 {
-        /* edge code (t b l r) is where azone will be drawn */
+        /* edge code (t b l r) is along which area edge azone will be drawn */
        
        if(alignment==RGN_ALIGN_TOP)
-               region_azone_initialize(sa, ar, 'b');
+               region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT);
        else if(alignment==RGN_ALIGN_BOTTOM)
-               region_azone_initialize(sa, ar, 't');
+               region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT);
        else if(ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT))
-               region_azone_initialize(sa, ar, 'l');
+               region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT);
        else if(ELEM(alignment, RGN_ALIGN_LEFT, RGN_OVERLAP_LEFT))
-               region_azone_initialize(sa, ar, 'r');
-                                                               
+               region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT);
 }
 
 /* dir is direction to check, not the splitting edge direction! */
@@ -618,8 +719,12 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int
        if(ar->next==NULL && alignment!=RGN_ALIGN_QSPLIT)
                alignment= RGN_ALIGN_NONE;
        
+       /* prefsize, for header we stick to exception */
        prefsizex= ar->sizex?ar->sizex:ar->type->prefsizex;
-       prefsizey= ar->sizey?ar->sizey:ar->type->prefsizey;
+       if(ar->regiontype==RGN_TYPE_HEADER)
+               prefsizey= ar->type->prefsizey;
+       else
+               prefsizey= ar->sizey?ar->sizey:ar->type->prefsizey;
        
        /* hidden is user flag */
        if(ar->flag & RGN_FLAG_HIDDEN);
@@ -754,15 +859,6 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int
        ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
        ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
        
-       /* restore test exception */
-       if(ar->alignment & RGN_SPLIT_PREV) {
-               if(ar->prev) {
-                       remainder= remainder_prev;
-                       ar->prev->winx= ar->prev->winrct.xmax - ar->prev->winrct.xmin + 1;
-                       ar->prev->winy= ar->prev->winrct.ymax - ar->prev->winrct.ymin + 1;
-               }
-       }
-
        /* set winrect for azones */
        if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
                ar->winrct= *remainder;
@@ -778,16 +874,36 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int
                else /* prevent winrct to be valid */
                        ar->winrct.xmax= ar->winrct.xmin;
        }
-       /* in end, add azones, where appropriate */
-       region_azone_add(sa, ar, alignment);
 
+       /* restore prev-split exception */
+       if(ar->alignment & RGN_SPLIT_PREV) {
+               if(ar->prev) {
+                       remainder= remainder_prev;
+                       ar->prev->winx= ar->prev->winrct.xmax - ar->prev->winrct.xmin + 1;
+                       ar->prev->winy= ar->prev->winrct.ymax - ar->prev->winrct.ymin + 1;
+               }
+       }
+       
+       /* in end, add azones, where appropriate */
+       if(ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
+               /* The logic for this is: when the header takes up the full area,
+                * disallow hiding it to view the main window.
+                *
+                * Without this, you can drag down the file selectors header and hide it
+                * by accident very easily (highly annoying!), the value 6 is arbitrary
+                * but accounts for small common rounding problems when scaling the UI,
+                * must be minimum '4' */
+       }
+       else {
+               region_azone_add(sa, ar, alignment);
+       }
 
        region_rect_recursive(sa, ar->next, remainder, quad);
 }
 
 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
 {
-       short rt= CLAMPIS(G.rt, 0, 16);
+       short rt= 0; // CLAMPIS(G.rt, 0, 16);
 
        if(sa->v1->vec.x>0) sa->totrct.xmin= sa->v1->vec.x+1+rt;
        else sa->totrct.xmin= sa->v1->vec.x;
@@ -806,7 +922,7 @@ static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
 
 
 /* used for area initialize below */
-static void region_subwindow(wmWindowManager *wm, wmWindow *win, ARegion *ar)
+static void region_subwindow(wmWindow *win, ARegion *ar)
 {
        if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
                if(ar->swinid)
@@ -819,7 +935,7 @@ static void region_subwindow(wmWindowManager *wm, wmWindow *win, ARegion *ar)
                wm_subwindow_position(win, ar->swinid, &ar->winrct);
 }
 
-static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int flag)
+static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
 {
        /* note, add-handler checks if it already exists */
        
@@ -836,8 +952,18 @@ static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int fla
        if(flag & ED_KEYMAP_MARKERS) {
                /* time-markers */
                wmKeyMap *keymap= WM_keymap_find(wm->defaultconf, "Markers", 0, 0);
-               WM_event_add_keymap_handler(handlers, keymap);
-               // XXX need boundbox check urgently!!!
+               
+               /* time space only has this keymap, the others get a boundbox restricted map */
+               if(sa->spacetype!=SPACE_TIME) {
+                       ARegion *ar;
+                       static rcti rect= {0, 10000, 0, 30};    /* same local check for all areas */
+                       ar= BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+                       if(ar) {
+                               WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
+                       }
+               }
+               else
+                       WM_event_add_keymap_handler(handlers, keymap);
        }
        if(flag & ED_KEYMAP_ANIMATION) {
                /* frame changing and timeline operators (for time spaces) */
@@ -890,18 +1016,18 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
        region_rect_recursive(sa, sa->regionbase.first, &rect, 0);
        
        /* default area handlers */
-       ed_default_handlers(wm, &sa->handlers, sa->type->keymapflag);
+       ed_default_handlers(wm, sa, &sa->handlers, sa->type->keymapflag);
        /* checks spacedata, adds own handlers */
        if(sa->type->init)
                sa->type->init(wm, sa);
        
        /* region windows, default and own handlers */
        for(ar= sa->regionbase.first; ar; ar= ar->next) {
-               region_subwindow(wm, win, ar);
+               region_subwindow(win, ar);
                
                if(ar->swinid) {
                        /* default region handlers */
-                       ed_default_handlers(wm, &ar->handlers, ar->type->keymapflag);
+                       ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
                        /* own handlers */
                        if(ar->type->init)
                                ar->type->init(wm, ar);
@@ -911,6 +1037,9 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
                        uiFreeBlocks(NULL, &ar->uiblocks);      
                }
                
+               /* rechecks 2d matrix for header on dpi changing, do not do for other regions, it resets view && blocks view2d operator polls (ton) */
+               if(ar->regiontype==RGN_TYPE_HEADER)
+                       ar->v2d.flag &= ~V2D_IS_INITIALISED;
        }
 }
 
@@ -920,7 +1049,7 @@ void ED_region_init(bContext *C, ARegion *ar)
 //     ARegionType *at= ar->type;
        
        /* refresh can be called before window opened */
-       region_subwindow(CTX_wm_manager(C), CTX_wm_window(C), ar);
+       region_subwindow(CTX_wm_window(C), ar);
        
        ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
        ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
@@ -935,7 +1064,6 @@ void ED_region_toggle_hidden(bContext *C, ARegion *ar)
        ScrArea *sa= CTX_wm_area(C);
 
        ar->flag ^= RGN_FLAG_HIDDEN;
-       ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
 
        if(ar->flag & RGN_FLAG_HIDDEN)
                WM_event_remove_handlers(C, &ar->handlers);
@@ -1044,6 +1172,9 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type)
                if(sl && sl->regionbase.first==NULL) {
                        st->free(sl);
                        BLI_freelinkN(&sa->spacedata, sl);
+                       if(slold == sl) {
+                               slold= NULL;
+                       }
                        sl= NULL;
                }
                
@@ -1077,25 +1208,20 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type)
                /* tell WM to refresh, cursor types etc */
                WM_event_add_mousemove(C);
                                
-               /*send space change notifyer*/
+               /*send space change notifier*/
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_CHANGED, sa);
-
-               ED_area_tag_redraw(sa);
+               
                ED_area_tag_refresh(sa);
        }
+       
+       /* also redraw when re-used */
+       ED_area_tag_redraw(sa);
 }
 
 void ED_area_prevspace(bContext *C, ScrArea *sa)
 {
        SpaceLink *sl = (sa) ? sa->spacedata.first : CTX_wm_space_data(C);
 
-       /* Special handling of filebrowser to stop background thread for
-          thumbnail creation - don't want to waste cpu resources if not showing
-          the filebrowser */
-       if (sl->spacetype == SPACE_FILE) {
-               ED_fileselect_exit(C, (SpaceFile*)sl);
-       }
-
        if(sl->next) {
                /* workaround for case of double prevspace, render window
                   with a file browser on top of it */
@@ -1109,11 +1235,11 @@ void ED_area_prevspace(bContext *C, ScrArea *sa)
        }
        ED_area_tag_redraw(sa);
 
-       /*send space change notifyer*/
+       /*send space change notifier*/
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_CHANGED, sa);
 }
 
-static char *editortype_pup(void)
+static const char *editortype_pup(void)
 {
        return(
                   "Editor type:%t"
@@ -1148,16 +1274,16 @@ static char *editortype_pup(void)
                   
                   "|%l"
                   
-                  "|Console %x18"
+                  "|Python Console %x18"
                   );
 }
 
-static void spacefunc(struct bContext *C, void *arg1, void *arg2)
+static void spacefunc(struct bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
 {
        ED_area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
        ED_area_tag_redraw(CTX_wm_area(C));
 
-       /*send space change notifyer*/
+       /*send space change notifier*/
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_CHANGED, CTX_wm_area(C));
 }
 
@@ -1169,19 +1295,21 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
        int xco= 8;
        
        but= uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D, 
-                                                  editortype_pup(), xco, yco, XIC+10, YIC
+                                                  editortype_pup(), xco, yco, UI_UNIT_X+10, UI_UNIT_Y
                                                   &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
                                                   "Displays current editor type. "
                                                   "Click for menu of available types");
        uiButSetFunc(but, spacefunc, NULL, NULL);
+       uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
        
-       return xco + XIC + 14;
+       return xco + UI_UNIT_X + 14;
 }
 
 int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
 {
        ScrArea *sa= CTX_wm_area(C);
        int xco= 8;
+       uiBut *but;
        
        if (!sa->full)
                xco= ED_area_header_switchbutton(C, block, yco);
@@ -1189,49 +1317,38 @@ int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
        uiBlockSetEmboss(block, UI_EMBOSSN);
 
        if (sa->flag & HEADER_NO_PULLDOWN) {
-               uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
+               but= uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
                                                 ICON_DISCLOSURE_TRI_RIGHT,
-                                                xco,yco,XIC,YIC-2,
+                                                xco,yco,UI_UNIT_X,UI_UNIT_Y-2,
                                                 &(sa->flag), 0, 0, 0, 0, 
                                                 "Show pulldown menus");
        }
        else {
-               uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
+               but= uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0,
                                                 ICON_DISCLOSURE_TRI_DOWN,
-                                                xco,yco,XIC,YIC-2,
+                                                xco,yco,UI_UNIT_X,UI_UNIT_Y-2,
                                                 &(sa->flag), 0, 0, 0, 0, 
                                                 "Hide pulldown menus");
        }
 
+       uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
+
        uiBlockSetEmboss(block, UI_EMBOSS);
        
-       return xco + XIC;
+       return xco + UI_UNIT_X;
 }
 
 /************************ standard UI regions ************************/
 
-void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *context, int contextnr)
+static void region_panels_layout(const bContext *C, ARegion *ar, int vertical, const char *context, int w, int em, int *r_x, int *r_y)
 {
        ScrArea *sa= CTX_wm_area(C);
-       uiStyle *style= U.uistyles.first;
-       uiBlock *block;
        PanelType *pt;
        Panel *panel;
-       View2D *v2d= &ar->v2d;
-       View2DScrollers *scrollers;
-       int xco, yco, x, y, miny=0, w, em, header, triangle, open, newcontext= 0;
-
-       if(contextnr >= 0)
-               newcontext= UI_view2d_tab_set(v2d, contextnr);
-
-       if(vertical) {
-               w= v2d->cur.xmax - v2d->cur.xmin;
-               em= (ar->type->prefsizex)? 10: 20;
-       }
-       else {
-               w= UI_PANEL_WIDTH;
-               em= (ar->type->prefsizex)? 10: 20;
-       }
+       uiBlock *block;
+       uiStyle *style= U.uistyles.first;
+       int x, y, miny=0, xco, yco;
+       int open, header, triangle;
 
        x= 0;
        y= -style->panelouter;
@@ -1239,9 +1356,6 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
        /* create panels */
        uiBeginPanels(C, ar);
 
-       /* set view2d view matrix for scrolling (without scrollers) */
-       UI_view2d_view_ortho(C, v2d);
-
        for(pt= ar->type->paneltypes.first; pt; pt= pt->next) {
                /* verify context */
                if(context)
@@ -1254,8 +1368,8 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
                        panel= uiBeginPanel(sa, ar, block, pt, &open);
 
                        /* bad fixed values */
-                       header= (pt->flag & PNL_NO_HEADER)? 0: 20;
-                       triangle= 22;
+                       header= (pt->flag & PNL_NO_HEADER)? 0: UI_UNIT_Y;
+                       triangle= (int)(UI_UNIT_Y * 1.1f);
 
                        if(vertical)
                                y -= header;
@@ -1271,6 +1385,9 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
                                panel->labelofs= xco - triangle;
                                panel->layout= NULL;
                        }
+                       else {
+                               panel->labelofs= 0;
+                       }
 
                        if(open) {
                                short panelContext;
@@ -1323,6 +1440,40 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
                y= UI_PANEL_WIDTH;
        }
 
+       uiEndPanels(C, ar);
+
+       *r_x = x;
+       *r_y = y;
+}
+
+void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
+{
+       View2D *v2d= &ar->v2d;
+       View2DScrollers *scrollers;
+       int x, y, w, em, newcontext= 0, need_scrollers;
+
+       if(contextnr >= 0)
+               newcontext= UI_view2d_tab_set(v2d, contextnr);
+
+       if(vertical) {
+               w= v2d->cur.xmax - v2d->cur.xmin;
+               em= (ar->type->prefsizex)? UI_UNIT_Y/2: UI_UNIT_Y;
+       }
+       else {
+               w= UI_PANEL_WIDTH;
+               em= (ar->type->prefsizex)? UI_UNIT_Y/2: UI_UNIT_Y;
+       }
+
+       /* try to draw without scrollbars */
+       UI_view2d_view_ortho(v2d);
+
+       region_panels_layout(C, ar, vertical, context, ar->winx, em, &x, &y);
+
+       /* if it doesn't fit, draw again in smaller space with scrollers */
+       need_scrollers = (abs(y) > ar->winy);
+       if(need_scrollers)
+               region_panels_layout(C, ar, vertical, context, ar->winx-V2D_SCROLL_WIDTH, em, &x, &y);
+
        /* clear */
        UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW)?TH_PREVIEW_BACK:TH_BACK);
        glClear(GL_COLOR_BUFFER_BIT);
@@ -1332,8 +1483,9 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
                /* only allow scrolling in vertical direction */
                v2d->keepofs |= V2D_LOCKOFS_X|V2D_KEEPOFS_Y;
                v2d->keepofs &= ~(V2D_LOCKOFS_Y|V2D_KEEPOFS_X);
-               v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
-               v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
+               v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_VERTICAL_HIDE);
+               if(!need_scrollers)
+                       v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
                
                // don't jump back when panels close or hide
                if(!newcontext)
@@ -1348,8 +1500,9 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
                v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_LOCKOFS_Y|V2D_KEEPOFS_X|V2D_KEEPOFS_Y);
                //v2d->keepofs |= V2D_LOCKOFS_Y|V2D_KEEPOFS_X;
                //v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_KEEPOFS_Y);
-               v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
-               v2d->scroll &= ~V2D_SCROLL_HORIZONTAL_HIDE;
+               v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_VERTICAL_HIDE);
+               if(!need_scrollers)
+                       v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
                
                // don't jump back when panels close or hide
                if(!newcontext)
@@ -1359,20 +1512,23 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
 
        // +V2D_SCROLL_HEIGHT is workaround to set the actual height
        UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
+       UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
 
        /* set the view */
-       UI_view2d_view_ortho(C, v2d);
+       UI_view2d_view_ortho(v2d);
 
        /* this does the actual drawing! */
-       uiEndPanels(C, ar);
+       uiDrawPanels(C, ar);
        
        /* restore view matrix */
        UI_view2d_view_restore(C);
        
        /* scrollers */
-       scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
-       UI_view2d_scrollers_draw(C, v2d, scrollers);
-       UI_view2d_scrollers_free(scrollers);
+       if(need_scrollers) {
+               scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+               UI_view2d_scrollers_draw(C, v2d, scrollers);
+               UI_view2d_scrollers_free(scrollers);
+       }
 }
 
 void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
@@ -1402,23 +1558,24 @@ void ED_region_header(const bContext *C, ARegion *ar)
        uiBlock *block;
        uiLayout *layout;
        HeaderType *ht;
-       Header header = {0};
+       Header header = {NULL};
        int maxco, xco, yco;
+       int headery= ED_area_headersize();
 
        /* clear */     
        UI_ThemeClearColor((ED_screen_area_active(C))?TH_HEADER:TH_HEADERDESEL);
        glClear(GL_COLOR_BUFFER_BIT);
        
        /* set view2d view matrix for scrolling (without scrollers) */
-       UI_view2d_view_ortho(C, &ar->v2d);
+       UI_view2d_view_ortho(&ar->v2d);
 
        xco= maxco= 8;
-       yco= HEADERY-3;
+       yco= headery-4;
 
        /* draw all headers types */
        for(ht= ar->type->headertypes.first; ht; ht= ht->next) {
-               block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
-               layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, HEADERY-6, 1, style);
+               block= uiBeginBlock(C, ar, ht->idname, UI_EMBOSS);
+               layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, UI_UNIT_Y, 1, style);
 
                if(ht->draw) {
                        header.type= ht;
@@ -1442,7 +1599,7 @@ void ED_region_header(const bContext *C, ARegion *ar)
        }
 
        /* always as last  */
-       UI_view2d_totRect_set(&ar->v2d, maxco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
+       UI_view2d_totRect_set(&ar->v2d, maxco+UI_UNIT_X+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
 
        /* restore view matrix? */
        UI_view2d_view_restore(C);
@@ -1453,3 +1610,8 @@ void ED_region_header_init(ARegion *ar)
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
 }
 
+/* UI_UNIT_Y is defined as U variable now, depending dpi */
+int ED_area_headersize(void)
+{
+       return UI_UNIT_Y+6;
+}