[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39066] trunk/blender/source/blender/ editors: fix for icon scaling with the DPI setting

Campbell Barton ideasman42 at gmail.com
Fri Aug 5 12:45:33 CEST 2011


Revision: 39066
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39066
Author:   campbellbarton
Date:     2011-08-05 10:45:32 +0000 (Fri, 05 Aug 2011)
Log Message:
-----------
fix for icon scaling with the DPI setting
- icons were scaling by the sqrt(dpi)/8.48528, but infact they only need to be scaled by (dpi/72).
- UI_icon_get_width value was being used without multiplying by dpi scale.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_icons.c
    trunk/blender/source/blender/editors/interface/interface_widgets.c

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2011-08-05 09:46:04 UTC (rev 39065)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2011-08-05 10:45:32 UTC (rev 39066)
@@ -164,6 +164,9 @@
 /* scale fixed button widths by this to account for DPI
  * 8.4852 == sqrtf(72.0f)) */
 #define UI_DPI_FAC (sqrtf((float)U.dpi) / 8.48528137423857f)
+#define UI_DPI_ICON_FAC (((float)U.dpi) / 72.0f)
+/* 16 to copy ICON_DEFAULT_HEIGHT */
+#define UI_DPI_ICON_SIZE ((float)16 * UI_DPI_ICON_FAC)
 
 /* Button types, bits stored in 1 value... and a short even!
 - bits 0-4:  bitnr (0-31)

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-08-05 09:46:04 UTC (rev 39065)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-08-05 10:45:32 UTC (rev 39066)
@@ -1290,7 +1290,7 @@
 	else if(ELEM(but->type, TEX, SEARCH_MENU)) {
 		startx += 5;
 		if (but->flag & UI_HAS_ICON)
-			startx += 16;
+			startx += UI_DPI_ICON_SIZE;
 	}
 	
 	/* mouse dragged outside the widget to the left */

Modified: trunk/blender/source/blender/editors/interface/interface_icons.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_icons.c	2011-08-05 09:46:04 UTC (rev 39065)
+++ trunk/blender/source/blender/editors/interface/interface_icons.c	2011-08-05 10:45:32 UTC (rev 39066)
@@ -742,6 +742,7 @@
 	return di;
 }
 
+/* note!, returns unscaled by DPI, may need to multiply result by UI_DPI_ICON_FAC */
 int UI_icon_get_width(int icon_id)
 {
 	Icon *icon = NULL;
@@ -952,7 +953,7 @@
 	Icon *icon = NULL;
 	DrawInfo *di = NULL;
 	IconImage *iimg;
-	float fdraw_size= UI_DPI_FAC*draw_size;
+	float fdraw_size= UI_DPI_ICON_FAC*draw_size;
 	int w, h;
 	
 	icon = BKE_icon_get(icon_id);

Modified: trunk/blender/source/blender/editors/interface/interface_widgets.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_widgets.c	2011-08-05 09:46:04 UTC (rev 39065)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c	2011-08-05 10:45:32 UTC (rev 39066)
@@ -771,7 +771,6 @@
 
 
 /* icons have been standardized... and this call draws in untransformed coordinates */
-#define ICON_HEIGHT		UI_DPI_FAC*16.0f
 
 static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect)
 {
@@ -791,15 +790,15 @@
 	if(aspect != but->aspect) {
 		/* prevent scaling up icon in pupmenu */
 		if (aspect < 1.0f) {			
-			height= ICON_HEIGHT;
+			height= UI_DPI_ICON_SIZE;
 			aspect = 1.0f;
 			
 		}
 		else 
-			height= ICON_HEIGHT/aspect;
+			height= UI_DPI_ICON_SIZE/aspect;
 	}
 	else
-		height= ICON_HEIGHT;
+		height= UI_DPI_ICON_SIZE;
 	
 	/* calculate blend color */
 	if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) {
@@ -866,7 +865,7 @@
 	int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
 	int okwidth= rect->xmax-rect->xmin - border;
 	
-	if (but->flag & UI_HAS_ICON) okwidth -= 16;
+	if (but->flag & UI_HAS_ICON) okwidth -= UI_DPI_ICON_SIZE;
 	
 	/* need to set this first */
 	uiStyleFontSet(fstyle);
@@ -1149,7 +1148,7 @@
 		if (but->flag & UI_HAS_ICON) {
 			widget_draw_icon(but, but->icon+but->iconadd, 1.0f, rect);
 			
-			rect->xmin += UI_icon_get_width(but->icon+but->iconadd);
+			rect->xmin += (int)((float)UI_icon_get_width(but->icon+but->iconadd) * UI_DPI_ICON_FAC);
 			
 			if(but->editstr || (but->flag & UI_TEXT_LEFT)) 
 				rect->xmin += 5;
@@ -3133,7 +3132,7 @@
 	
 	/* text location offset */
 	rect->xmin+=5;
-	if(iconid) rect->xmin+= ICON_HEIGHT;
+	if(iconid) rect->xmin+= UI_DPI_ICON_SIZE;
 
 	/* cut string in 2 parts? */
 	cpoin= strchr(name, '|');
@@ -3158,7 +3157,7 @@
 
 	if(iconid) {
 		int xs= rect->xmin+4;
-		int ys= 1 + (rect->ymin+rect->ymax- ICON_HEIGHT)/2;
+		int ys= 1 + (rect->ymin+rect->ymax- UI_DPI_ICON_SIZE)/2;
 		glEnable(GL_BLEND);
 		UI_icon_draw_aspect(xs, ys, iconid, 1.2f, 0.5f); /* XXX scale weak get from fstyle? */
 		glDisable(GL_BLEND);




More information about the Bf-blender-cvs mailing list