[Bf-blender-cvs] [1b94b3d] master: WM: Add utility wmOrtho2_*** funcs

Campbell Barton noreply at git.blender.org
Wed Sep 10 05:39:00 CEST 2014


Commit: 1b94b3d49c83db16297bd445b19e7384084386d4
Author: Campbell Barton
Date:   Wed Sep 10 13:24:31 2014 +1000
Branches: master
https://developer.blender.org/rB1b94b3d49c83db16297bd445b19e7384084386d4

WM: Add utility wmOrtho2_*** funcs

Currently there are inconsistencies with pixel alignment.
but this commit has no functional changes.

- wmOrtho2_region_ui for UI/Text.
- wmOrtho2_region_pixelspace for 2D drawing.
- wmOrtho2_pixelspace - when the region isn't used.

===================================================================

M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_regions.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_subwindow.c

===================================================================

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 695c886..b987f97 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1347,8 +1347,8 @@ void uiDrawBlock(const bContext *C, uiBlock *block)
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
 	glLoadIdentity();
-	
-	wmOrtho2(-0.01f, ar->winx - 0.01f, -0.01f, ar->winy - 0.01f);
+
+	wmOrtho2_region_ui(ar);
 	
 	/* back */
 	if (block->flag & UI_BLOCK_RADIAL)
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 1960c77..efcbc2a 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1020,7 +1020,7 @@ static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
 	uiSearchboxData *data = ar->regiondata;
 	
 	/* pixel space */
-	wmOrtho2(-0.01f, ar->winx - 0.01f, -0.01f, ar->winy - 0.01f);
+	wmOrtho2_region_ui(ar);
 
 	if (data->noback == false)
 		ui_draw_search_back(NULL, NULL, &data->bbox);  /* style not used yet */
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 05418d8..739e7be 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -107,10 +107,7 @@ static void region_draw_emboss(ARegion *ar, rcti *scirct)
 
 void ED_region_pixelspace(ARegion *ar)
 {
-	int width  = BLI_rcti_size_x(&ar->winrct) + 1;
-	int height = BLI_rcti_size_y(&ar->winrct) + 1;
-	
-	wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
+	wmOrtho2_region_pixelspace(ar);
 	glLoadIdentity();
 }
 
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index b760d9f..0358c1a 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3056,7 +3056,8 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
 		
 		glaDefine2DArea(&ar->winrct);
 		/* ortho at pixel level curarea */
-		wmOrtho2(-GLA_PIXEL_OFS, ar->winx - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, ar->winy - GLA_PIXEL_OFS);
+		/* almost #wmOrtho2_region_pixelspace, but no +1 px */
+		wmOrtho2_pixelspace(ar->winx, ar->winy);
 		
 		x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
 		y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof;
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 35b7fb4..e1cd334 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -361,6 +361,10 @@ void		wmSubWindowScissorSet	(struct wmWindow *win, int swinid, const struct rcti
 void		wmFrustum			(float x1, float x2, float y1, float y2, float n, float f);
 void		wmOrtho				(float x1, float x2, float y1, float y2, float n, float f);
 void		wmOrtho2			(float x1, float x2, float y1, float y2);
+			/* use for conventions (avoid hard-coded offsets all over) */
+void		wmOrtho2_region_pixelspace(const struct ARegion *ar);
+void		wmOrtho2_region_ui(const struct ARegion *ar);
+void		wmOrtho2_pixelspace(const float x, const float y);
 
 			/* utilities */
 void		WM_framebuffer_index_set(int index);
diff --git a/source/blender/windowmanager/intern/wm_subwindow.c b/source/blender/windowmanager/intern/wm_subwindow.c
index db4459b..e26bcac 100644
--- a/source/blender/windowmanager/intern/wm_subwindow.c
+++ b/source/blender/windowmanager/intern/wm_subwindow.c
@@ -215,7 +215,7 @@ int wm_subwindow_open(wmWindow *win, const rcti *winrct)
 	
 	/* extra service */
 	wm_swin_size_get(swin, &width, &height);
-	wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
+	wmOrtho2_pixelspace(width, height);
 	glLoadIdentity();
 
 	return swin->swinid;
@@ -272,7 +272,7 @@ void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct)
 		/* extra service */
 		wmSubWindowSet(win, swinid);
 		wm_swin_size_get(swin, &width, &height);
-		wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
+		wmOrtho2_pixelspace(width, height);
 	}
 	else {
 		printf("%s: Internal error, bad winid: %d\n", __func__, swinid);
@@ -319,7 +319,7 @@ void wmSubWindowScissorSet(wmWindow *win, int swinid, const rcti *srct, bool src
 	else
 		glScissor(_curswin->winrct.xmin, _curswin->winrct.ymin, width, height);
 	
-	wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
+	wmOrtho2_pixelspace(width, height);
 	glLoadIdentity();
 	
 	glFlush();
@@ -358,6 +358,35 @@ void wmOrtho2(float x1, float x2, float y1, float y2)
 	wmOrtho(x1, x2, y1, y2, -100, 100);
 }
 
+static void wmOrtho2_offset(const float x, const float y, const float ofs)
+{
+	wmOrtho2(ofs, x + ofs, ofs, y + ofs);
+}
+
+/**
+ * default pixel alignment.
+ */
+void wmOrtho2_region_pixelspace(const struct ARegion *ar)
+{
+	wmOrtho2_offset(ar->winx + 1, ar->winy + 1, -GLA_PIXEL_OFS);
+}
+
+void wmOrtho2_pixelspace(const float x, const float y)
+{
+	wmOrtho2_offset(x, y, -GLA_PIXEL_OFS);
+}
+
+/**
+ * use for drawing uiBlock, any UI elements and text.
+ * \note prevents blurry text with multi-sample (FSAA), see T41749
+ */
+void wmOrtho2_region_ui(const ARegion *ar)
+{
+	/* note, intentionally no '+ 1',
+	 * as with wmOrtho2_region_pixelspace */
+	wmOrtho2_offset(ar->winx, ar->winy, -0.01f);
+}
+
 /* *************************** Framebuffer color depth, for selection codes ********************** */
 
 #ifdef __APPLE__




More information about the Bf-blender-cvs mailing list