[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53120] trunk/blender/source/blender/ editors: Nicer function for drawing text in 3d window:

Ton Roosendaal ton at blender.org
Tue Dec 18 14:59:50 CET 2012


Revision: 53120
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53120
Author:   ton
Date:     2012-12-18 13:59:47 +0000 (Tue, 18 Dec 2012)
Log Message:
-----------
Nicer function for drawing text in 3d window:

ED_region_visible_rect(ar, rect)
Returns the visible rect inside a region, subtracting the overlapping UI regions.

Added with minimal overhead, only called once per region draw.

Also fixes the 'Auto Key' warning print in 3d window (was behind properties)

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_screen.h
    trunk/blender/source/blender/editors/screen/area.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/editors/transform/transform.c

Modified: trunk/blender/source/blender/editors/include/ED_screen.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_screen.h	2012-12-18 13:46:37 UTC (rev 53119)
+++ trunk/blender/source/blender/editors/include/ED_screen.h	2012-12-18 13:59:47 UTC (rev 53120)
@@ -67,7 +67,7 @@
 void    ED_region_info_draw(struct ARegion *ar, const char *text, int block, float alpha);
 void    ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy);
 float	ED_region_blend_factor(struct ARegion *ar);
-int		ED_region_overlapping_offset(struct ARegion *ar);
+void	ED_region_visible_rect(struct ARegion *ar, struct rcti *rect);
 
 
 /* spaces */

Modified: trunk/blender/source/blender/editors/screen/area.c
===================================================================
--- trunk/blender/source/blender/editors/screen/area.c	2012-12-18 13:46:37 UTC (rev 53119)
+++ trunk/blender/source/blender/editors/screen/area.c	2012-12-18 13:59:47 UTC (rev 53120)
@@ -1835,7 +1835,7 @@
 	rcti rect;
 
 	/* background box */
-	rect = ar->winrct;
+	ED_region_visible_rect(ar, &rect);
 	rect.xmin = 0;
 	rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
 
@@ -1856,7 +1856,7 @@
 
 	/* text */
 	UI_ThemeColor(TH_TEXT_HI);
-	BLF_position(fontid, 12 + ED_region_overlapping_offset(ar), rect.ymin + 5, 0.0f);
+	BLF_position(fontid, 12, rect.ymin + 5, 0.0f);
 	BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
 }
 
@@ -1920,22 +1920,31 @@
 	glEnd();
 }
 
-/* checks overlapping region for labels, axes, icons */
-int ED_region_overlapping_offset(ARegion *ar)
+/* If the area has overlapping regions, it returns visible rect for Region *ar */
+/* rect gets returned in local region coordinates */
+void ED_region_visible_rect(ARegion *ar, rcti *rect)
 {
 	ARegion *arn = ar;
 	
-	/* too lazy to pass on area listbase */
+	/* allow function to be called without area */
 	while (arn->prev)
 		arn = arn->prev;
 	
+	*rect = ar->winrct;
+	
 	/* check if a region overlaps with the current one */
 	for (; arn; arn = arn->next) {
-		if (ar != arn)
-			if (ar->winrct.xmin == arn->winrct.xmin)
-				if (ar->winrct.ymin == arn->winrct.ymin)
-					return arn->winrct.xmax - arn->winrct.xmin;
+		if (ar != arn && arn->overlap) {
+			if (BLI_rcti_isect(rect, &arn->winrct, NULL)) {
+				/* overlap left */
+				if (rect->xmin == arn->winrct.xmin)
+					rect->xmin = arn->winrct.xmax;
+				/* overlap right */
+				if (rect->xmax == arn->winrct.xmax)
+					rect->xmax = arn->winrct.xmin;
+			}
+		}
 	}
-	return 0;
+	BLI_rcti_translate(rect, -ar->winrct.xmin, -ar->winrct.ymin);
 }
 

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2012-12-18 13:46:37 UTC (rev 53119)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2012-12-18 13:59:47 UTC (rev 53120)
@@ -592,18 +592,20 @@
 
 /* Draw a live substitute of the view icon, which is always shown
  * colors copied from transform_manipulator.c, we should keep these matching. */
-static void draw_view_axis(ARegion *ar, RegionView3D *rv3d)
+static void draw_view_axis(RegionView3D *rv3d, rcti *rect)
 {
 	const float k = U.rvisize;   /* axis size */
 	const float toll = 0.5;      /* used to see when view is quasi-orthogonal */
-	const float startx = k + 1.0f + ED_region_overlapping_offset(ar); /* axis center in screen coordinates, x=y */
-	const float starty = k + 1.0f;
+	float startx = k + 1.0f; /* axis center in screen coordinates, x=y */
+	float starty = k + 1.0f;
 	float ydisp = 0.0;          /* vertical displacement to allow obj info text */
 	int bright = 25 * (float)U.rvibright + 5; /* axis alpha (rvibright has range 0-10) */
-
 	float vec[3];
 	float dx, dy;
 	
+	startx += rect->xmin;
+	starty += rect->ymin;
+	
 	/* thickness of lines is proportional to k */
 	glLineWidth(2);
 
@@ -776,7 +778,7 @@
 	glDepthMask(1);
 }
 
-static void draw_view_icon(ARegion *ar, RegionView3D *rv3d)
+static void draw_view_icon(RegionView3D *rv3d, rcti *rect)
 {
 	BIFIconID icon;
 	
@@ -791,7 +793,7 @@
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); 
 	
-	UI_icon_draw(5.0 + ED_region_overlapping_offset(ar), 5.0, icon);
+	UI_icon_draw(5.0 + rect->xmin, 5.0 + rect->ymin, icon);
 	
 	glDisable(GL_BLEND);
 }
@@ -846,7 +848,7 @@
 	return name;
 }
 
-static void draw_viewport_name(ARegion *ar, View3D *v3d)
+static void draw_viewport_name(ARegion *ar, View3D *v3d, rcti *rect)
 {
 	RegionView3D *rv3d = ar->regiondata;
 	const char *name = view3d_get_name(v3d, rv3d);
@@ -859,17 +861,17 @@
 
 	if (name) {
 		UI_ThemeColor(TH_TEXT_HI);
-		BLF_draw_default_ascii(U.widget_unit + ED_region_overlapping_offset(ar),  ar->winy - U.widget_unit, 0.0f, name, sizeof(tmpstr));
+		BLF_draw_default_ascii(U.widget_unit + rect->xmin,  rect->ymax - U.widget_unit, 0.0f, name, sizeof(tmpstr));
 	}
 }
 
 /* draw info beside axes in bottom left-corner: 
  * framenum, object name, bone name (if available), marker name (if available)
  */
-static void draw_selected_name(ARegion *ar, Scene *scene, Object *ob)
+static void draw_selected_name(Scene *scene, Object *ob, rcti *rect)
 {
 	char info[256], *markern;
-	short offset = 30 + ED_region_overlapping_offset(ar);
+	short offset = 30 + rect->xmin;
 	
 	/* get name of marker on current frame (if available) */
 	markern = BKE_scene_find_marker_name(scene, CFRA);
@@ -952,7 +954,7 @@
 	}
 	
 	if (U.uiflag & USER_SHOW_ROTVIEWICON)
-		offset = U.widget_unit + (U.rvisize * 2) + ED_region_overlapping_offset(ar);
+		offset = U.widget_unit + (U.rvisize * 2) + rect->xmin;
 
 	BLF_draw_default(offset, 0.5f * U.widget_unit, 0.0f, info, sizeof(info));
 }
@@ -2812,7 +2814,7 @@
 /* NOTE: the info that this uses is updated in ED_refresh_viewport_fps(), 
  * which currently gets called during SCREEN_OT_animation_step.
  */
-static void draw_viewport_fps(Scene *scene, ARegion *ar)
+static void draw_viewport_fps(Scene *scene, rcti *rect)
 {
 	ScreenFrameRateInfo *fpsi = scene->fps_info;
 	float fps;
@@ -2857,7 +2859,7 @@
 		BLI_snprintf(printable, sizeof(printable), "fps: %i", (int)(fps + 0.5f));
 	}
 	
-	BLF_draw_default_ascii(U.widget_unit,  ar->winy - U.widget_unit, 0.0f, printable, sizeof(printable));
+	BLF_draw_default_ascii(rect->xmin + U.widget_unit,  rect->ymax - U.widget_unit, 0.0f, printable, sizeof(printable));
 }
 
 static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const char **grid_unit);
@@ -3166,6 +3168,10 @@
 	Scene *scene = CTX_data_scene(C);
 	View3D *v3d = CTX_wm_view3d(C);
 	RegionView3D *rv3d = CTX_wm_region_view3d(C);
+	rcti rect;
+	
+	/* local coordinate visible rect inside region, to accomodate overlapping ui */
+	ED_region_visible_rect(ar, &rect);
 
 	if (rv3d->persp == RV3D_CAMOB) {
 		drawviewborder(scene, ar, v3d);
@@ -3193,13 +3199,13 @@
 		drawcursor(scene, ar, v3d);
 
 		if (U.uiflag & USER_SHOW_ROTVIEWICON)
-			draw_view_axis(ar, rv3d);
+			draw_view_axis(rv3d, &rect);
 		else
-			draw_view_icon(ar, rv3d);
+			draw_view_icon(rv3d, &rect);
 
 		ob = OBACT;
 		if (U.uiflag & USER_DRAWVIEWINFO)
-			draw_selected_name(ar, scene, ob);
+			draw_selected_name(scene, ob, &rect);
 	}
 
 	if (rv3d->render_engine) {
@@ -3209,10 +3215,10 @@
 
 	if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
 		if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_playing(wm)) {
-			draw_viewport_fps(scene, ar);
+			draw_viewport_fps(scene, &rect);
 		}
 		else if (U.uiflag & USER_SHOW_VIEWPORTNAME) {
-			draw_viewport_name(ar, v3d);
+			draw_viewport_name(ar, v3d, &rect);
 		}
 
 		if (grid_unit) { /* draw below the viewport name */
@@ -3223,8 +3229,8 @@
 				BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
 			}
 
-			BLF_draw_default_ascii(ED_region_overlapping_offset(ar) + U.widget_unit,
-			                       ar->winy - (USER_SHOW_VIEWPORTNAME ? 2 * U.widget_unit : U.widget_unit), 0.0f,
+			BLF_draw_default_ascii(rect.xmin + U.widget_unit,
+			                       rect.ymax - (USER_SHOW_VIEWPORTNAME ? 2 * U.widget_unit : U.widget_unit), 0.0f,
 			                       numstr[0] ? numstr : grid_unit, sizeof(numstr));
 		}
 	}

Modified: trunk/blender/source/blender/editors/transform/transform.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform.c	2012-12-18 13:46:37 UTC (rev 53119)
+++ trunk/blender/source/blender/editors/transform/transform.c	2012-12-18 13:59:47 UTC (rev 53120)
@@ -1585,14 +1585,17 @@
 /* just draw a little warning message in the top-right corner of the viewport to warn that autokeying is enabled */
 static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
 {
+	rcti rect;
 	const char printable[] = "Auto Keying On";
 	float      printable_size[2];
 	int xco, yco;
 
+	ED_region_visible_rect(ar, &rect);
+	
 	BLF_width_and_height_default(printable, &printable_size[0], &printable_size[1]);
 	
-	xco = ar->winx - (int)printable_size[0] - 10;
-	yco = ar->winy - (int)printable_size[1] - 10;
+	xco = rect.xmax - (int)printable_size[0] - 10;
+	yco = rect.ymax - (int)printable_size[1] - 10;
 	
 	/* warning text (to clarify meaning of overlays)
 	 * - original color was red to match the icon, but that clashes badly with a less nasty border




More information about the Bf-blender-cvs mailing list