Skip to content

Commit

Permalink
feat: add active and alt_mode key indicators to operator overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed Jan 24, 2022
1 parent 1520b36 commit bde234c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 10 deletions.
40 changes: 36 additions & 4 deletions bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def modal(self, context, event):
radius_factor = 0.001 if event.shift else 0.01
thickness_factor = 0.001 if event.shift else 0.01

self.key_shift = event.shift
self.key_alt = event.alt
self.key_ctrl = event.ctrl

if event.type == 'MOUSEMOVE':
update_overlay(self, context, event)

Expand Down Expand Up @@ -66,6 +70,10 @@ def invoke(self, context, event):
self.thickness = 0.02
self.offset = 0

self.key_shift = False
self.key_alt = False
self.key_ctrl = False

self.add_object(context)
self.add_screw_x_modifier()
self.add_screw_z_modifer()
Expand Down Expand Up @@ -198,10 +206,34 @@ def revert(self, context):

def draw_text_callback(self):
draw_header(self, "ND — Bolt")
draw_property(self, "Segments: {}".format(self.segments), "(±1)")
draw_property(self, "Radius: {0:.0f}mm".format(self.radius * 1000), "Alt (±10mm) | Shift + Alt (±1mm)")
draw_property(self, "Thickness: {0:.0f}mm".format(self.thickness * 1000), "Ctrl (±10mm) | Shift + Ctrl (±1mm)")
draw_property(self, "Offset: {0:.3f}".format(self.offset), "Ctrl + Alt (±0.01) | Shift + Ctrl + Alt (±0.001)")

draw_property(
self,
"Segments: {}".format(self.segments),
"(±1)",
active=(not self.key_ctrl and not self.key_alt),
alt_mode=(not self.key_ctrl and not self.key_alt and self.key_shift))

draw_property(
self,
"Radius: {0:.0f}mm".format(self.radius * 1000),
"Alt (±10mm) | Shift + Alt (±1mm)",
active=(not self.key_ctrl and self.key_alt),
alt_mode=(not self.key_ctrl and self.key_alt and self.key_shift))

draw_property(
self,
"Thickness: {0:.0f}mm".format(self.thickness * 1000),
"Ctrl (±10mm) | Shift + Ctrl (±1mm)",
active=(self.key_ctrl and not self.key_alt),
alt_mode=(self.key_ctrl and not self.key_alt and self.key_shift))

draw_property(
self,
"Offset: {0:.3f}".format(self.offset),
"Ctrl + Alt (±0.01) | Shift + Ctrl + Alt (±0.001)",
active=(self.key_ctrl and self.key_alt),
alt_mode=(self.key_ctrl and self.key_alt and self.key_shift))

redraw_regions()

Expand Down
12 changes: 11 additions & 1 deletion faux_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ND_OT_faux_bevel(bpy.types.Operator):
def modal(self, context, event):
width_factor = 0.0001 if event.shift else 0.001

self.key_shift = event.shift

if event.type == 'MOUSEMOVE':
update_overlay(self, context, event)

Expand Down Expand Up @@ -47,6 +49,8 @@ def invoke(self, context, event):

self.width = 0.001

self.key_shift = False

self.add_bevel_modifier(context)
self.add_weighted_normal_modifer(context)

Expand Down Expand Up @@ -95,7 +99,13 @@ def revert(self, context):

def draw_text_callback(self):
draw_header(self, "ND — Faux Bevel")
draw_property(self, "Width: {0:.1f}mm".format(self.width * 1000), "(±1mm) | Shift (±0.1mm)")

draw_property(
self,
"Width: {0:.1f}mm".format(self.width * 1000),
"(±1mm) | Shift (±0.1mm)",
active=True,
alt_mode=self.key_shift)

redraw_regions()

Expand Down
20 changes: 17 additions & 3 deletions overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,29 @@ def draw_header(self, content):
self.property_step = 0


def draw_property(self, property_content, metadata_content):
def draw_property(self, property_content, metadata_content, active=False, alt_mode=False):
blf.size(0, 28, 72)

if active:
blf.color(0, 0.216, 0.686, 1.0, 1.0)
else:
blf.color(0, 1.0, 1.0, 1.0, 0.1)

blf.position(0, self.overlay_x, self.overlay_y - (38 + (self.property_spacer * self.property_step)), 0)

if alt_mode:
blf.draw(0, "◑")
else:
blf.draw(0, "●")

blf.size(0, 16, 72)
blf.color(0, 1.0, 1.0, 1.0, 1.0)
blf.position(0, self.overlay_x, self.overlay_y - (25 + (self.property_spacer * self.property_step)), 0)
blf.position(0, self.overlay_x + 25, self.overlay_y - (25 + (self.property_spacer * self.property_step)), 0)
blf.draw(0, property_content)

blf.size(0, 11, 72)
blf.color(0, 1.0, 1.0, 1.0, 0.3)
blf.position(0, self.overlay_x, self.overlay_y - (40 + (self.property_spacer * self.property_step)), 0)
blf.position(0, self.overlay_x + 25, self.overlay_y - (40 + (self.property_spacer * self.property_step)), 0)
blf.draw(0, metadata_content)

self.property_step += 1
22 changes: 20 additions & 2 deletions sketch_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def modal(self, context, event):
width_factor = 0.001 if event.shift else 0.01
segment_factor = 1 if event.shift else 2

self.key_shift = event.shift
self.key_alt = event.alt

if event.type == 'MOUSEMOVE':
update_overlay(self, context, event)

Expand Down Expand Up @@ -51,6 +54,9 @@ def invoke(self, context, event):
self.segments = 1
self.width = 0.001

self.key_shift = False
self.key_alt = False

self.add_vertex_group(context)
self.add_bevel_modifier(context)

Expand Down Expand Up @@ -112,8 +118,20 @@ def revert(self, context):

def draw_text_callback(self):
draw_header(self, "ND — Sketch Bevel")
draw_property(self, "Segments: {}".format(self.segments), "(±2) | Shift (±1)")
draw_property(self, "Width: {0:.0f}mm".format(self.width * 1000), "Alt (±10mm) | Shift + Alt (±1mm)")

draw_property(
self,
"Segments: {}".format(self.segments),
"(±2) | Shift (±1)",
active=(not self.key_alt),
alt_mode=(self.key_shift and not self.key_alt))

draw_property(
self,
"Width: {0:.0f}mm".format(self.width * 1000),
"Alt (±10mm) | Shift + Alt (±1mm)",
active=(self.key_alt),
alt_mode=(self.key_shift and self.key_alt))

redraw_regions()

Expand Down

0 comments on commit bde234c

Please sign in to comment.