Polytool: creates a decorator to show instructions on the screen.

This commit is contained in:
Bruno Perdigão
2024-08-26 16:45:30 -03:00
parent 197d0b3258
commit 48b74ebb76
3 changed files with 42 additions and 2 deletions
@@ -307,13 +307,15 @@ class PolylineDecorator:
angle_snap_mat = None
angle_snap_loc = None
use_default_container = False
instructions = None
@classmethod
def install(cls, context):
if cls.is_installed:
cls.uninstall()
handler = cls()
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_input_panel, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_on_screen_menu, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_measurements, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(SpaceView3D.draw_handler_add(handler, (context,), "WINDOW", "POST_VIEW"))
cls.is_installed = True
@@ -354,6 +356,10 @@ class PolylineDecorator:
cls.plane_origin = plane_origin
cls.plane_normal = plane_normal
@classmethod
def set_instructions(cls, instructions):
cls.instructions = instructions
@classmethod
def calculate_distance_and_angle(cls, context, is_input_on):
@@ -556,7 +562,7 @@ class PolylineDecorator:
self.addon_prefs = tool.Blender.get_addon_preferences()
self.font_id = 0
self.font_id = 1
blf.size(self.font_id, 12)
blf.enable(self.font_id, blf.SHADOW)
blf.shadow(self.font_id, 6, 0, 0, 0, 1)
@@ -592,6 +598,23 @@ class PolylineDecorator:
blf.position(self.font_id, coords_angle[0], coords_angle[1], 0)
blf.draw(self.font_id, "a: " + measurement_prop[i].angle)
def draw_on_screen_menu(self, context):
region = context.region
self.addon_prefs = tool.Blender.get_addon_preferences()
self.font_id = 2
blf.size(self.font_id, 12)
blf.enable(self.font_id, blf.SHADOW)
blf.shadow(self.font_id, 6, 0, 0, 0, 1)
color = self.addon_prefs.decorations_colour
blf.color(self.font_id, *color)
text_w, text_h = blf.dimensions(0, self.instructions)
position = (region.width / 2) - (text_w / 2)
blf.position(self.font_id, position, 10, 0)
blf.draw(self.font_id, self.instructions)
def __call__(self, context):
self.addon_prefs = tool.Blender.get_addon_preferences()
@@ -325,6 +325,13 @@ class DrawPolylineWall(bpy.types.Operator):
self.input_panel = {"D": "", "A": "", "X": "", "Y": ""}
self.snap_angle = None
self.snapping_points = []
self.instructions = """TAB: Cycle Input
M: Modify Snap Point
C: Close
Backspace: Remove
X Y: Axis
Shift: Lock axis
"""
def recalculate_inputs(self, context):
if self.number_input:
@@ -518,6 +525,7 @@ class DrawPolylineWall(bpy.types.Operator):
tool.Snap.set_use_default_container(True)
PolylineDecorator.set_use_default_container(True)
tool.Snap.set_snap_plane_method("XY")
PolylineDecorator.set_instructions(self.instructions)
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
self.visible_objs = tool.Raycast.get_visible_objects(context)
for obj in self.visible_objs:
@@ -2334,6 +2334,14 @@ class MeasureTool(bpy.types.Operator):
self.input_panel = {"D": "", "A": "", "X": "", "Y": "", "Z": ""}
self.snap_angle = None
self.snapping_points = []
self.instructions = """TAB: Cycle Input
M: Modify Snap Point
C: Close
Backspace: Remove
X Y Z: Axis
S-(X Y Z): Plane
Shift: Lock axis
"""
def recalculate_inputs(self, context):
if self.number_input:
@@ -2520,6 +2528,7 @@ class MeasureTool(bpy.types.Operator):
PolylineDecorator.set_use_default_container(False)
tool.Snap.set_snap_plane_method(None)
tool.Snap.set_snap_axis_method(None)
PolylineDecorator.set_instructions(self.instructions)
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
self.visible_objs = tool.Raycast.get_visible_objects(context)
for obj in self.visible_objs: