From 0979c37ba8fd29771f47c830213c41e8596e28f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Sat, 5 Oct 2024 15:17:04 -0300 Subject: [PATCH] Measure tool - center area text horizontally --- src/bonsai/bonsai/bim/module/model/decorator.py | 5 +++-- src/bonsai/bonsai/bim/module/project/decorator.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/decorator.py b/src/bonsai/bonsai/bim/module/model/decorator.py index f4290948c5..5999e32763 100644 --- a/src/bonsai/bonsai/bim/module/model/decorator.py +++ b/src/bonsai/bonsai/bim/module/model/decorator.py @@ -583,7 +583,7 @@ class PolylineDecorator: # Area and Length text polyline_verts = [Vector((p.x, p.y, p.z)) for p in polyline_points] - center = sum(polyline_verts, Vector()) / len(polyline_verts) # center between all polyline points + center = sum(polyline_verts, Vector()) / len(polyline_verts) # Center between all polyline points area_text_coords = view3d_utils.location_3d_to_region_2d(region, rv3d, center) total_length_text_coords = view3d_utils.location_3d_to_region_2d(region, rv3d, polyline_verts[-1]) @@ -591,10 +591,11 @@ class PolylineDecorator: if measure_type == "AREA": if len(polyline_verts) < 3: return - blf.position(self.font_id, area_text_coords[0], area_text_coords[1], 0) value = polyline_data.area text = f"area: {value}" text_length = blf.dimensions(self.font_id, text) + area_text_coords[0] -= (text_length[0]/2) # Center text horizontally + blf.position(self.font_id, area_text_coords[0], area_text_coords[1], 0) self.draw_text_background(context, area_text_coords, text_length) blf.draw(self.font_id, text) diff --git a/src/bonsai/bonsai/bim/module/project/decorator.py b/src/bonsai/bonsai/bim/module/project/decorator.py index 48bf0aea9d..1f42ee8afa 100644 --- a/src/bonsai/bonsai/bim/module/project/decorator.py +++ b/src/bonsai/bonsai/bim/module/project/decorator.py @@ -360,7 +360,7 @@ class MeasureDecorator: # Area and Length text polyline_verts = [Vector((p.x, p.y, p.z)) for p in polyline_points] - center = sum(polyline_verts, Vector()) / len(polyline_verts) # center between all polyline points + center = sum(polyline_verts, Vector()) / len(polyline_verts) # Center between all polyline points area_text_coords = view3d_utils.location_3d_to_region_2d(region, rv3d, center) total_length_text_coords = view3d_utils.location_3d_to_region_2d(region, rv3d, polyline_verts[-1]) @@ -368,10 +368,11 @@ class MeasureDecorator: if measure_type == "AREA": if len(polyline_verts) < 3: return - blf.position(self.font_id, area_text_coords[0], area_text_coords[1], 0) value = polyline_data.area text = f"area: {value}" text_length = blf.dimensions(self.font_id, text) + area_text_coords[0] -= (text_length[0]/2) # Center text horizontally + blf.position(self.font_id, area_text_coords[0], area_text_coords[1], 0) self.draw_text_background(context, area_text_coords, text_length) blf.draw(self.font_id, text)