Skip to content

Commit

Permalink
feat: add toggleable "halt" mode to all operators, allowing event / k…
Browse files Browse the repository at this point in the history
…eybinding passthrough
  • Loading branch information
tristan-hm committed Feb 5, 2022
1 parent 16c5634 commit 1ec0942
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 21 deletions.
15 changes: 13 additions & 2 deletions generators/ring_and_bolt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
import bmesh
from math import radians
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.objects import add_single_vertex_object, align_object_to_3d_cursor
from .. lib.events import capture_modifier_keys

Expand All @@ -20,9 +20,16 @@ def modal(self, context, event):
width_factor = (self.base_width_factor / 10.0) if self.key_shift else self.base_width_factor
segment_factor = 1 if self.key_shift else 2

if self.key_toggle_operator_passthrough:
toggle_operator_passthrough(self)

if self.key_toggle_pin_overlay:
toggle_pin_overlay(self)

if self.operator_passthrough:
self.update_overlay_wrapper(context, event)
return {'PASS_THROUGH'}

elif self.key_increase_factor:
if self.key_alt:
self.base_inner_radius_factor = min(1, self.base_inner_radius_factor * 10.0)
Expand Down Expand Up @@ -66,11 +73,15 @@ def modal(self, context, event):
return {'PASS_THROUGH'}

self.operate(context)
update_overlay(self, context, event, x_offset=300, lines=3)
self.update_overlay_wrapper(context, event)

return {'RUNNING_MODAL'}


def update_overlay_wrapper(self, context, event):
update_overlay(self, context, event, x_offset=300, lines=3)


def invoke(self, context, event):
self.base_inner_radius_factor = 0.001
self.base_width_factor = 0.001
Expand Down
1 change: 1 addition & 0 deletions lib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def capture_modifier_keys(cls, event=None):
cls.key_shift =False if event is None else event.shift
cls.key_shift_no_modifiers = False if event is None else event.shift and cls.key_no_modifiers
cls.key_toggle_pin_overlay = False if event is None else event.type == 'P' and event.value == 'PRESS'
cls.key_toggle_operator_passthrough = False if event is None else event.type == 'BACK_SLASH' and event.value == 'PRESS'
cls.key_increase_factor = False if event is None else event.type in {'PLUS', 'EQUAL', 'NUMPAD_PLUS'} and event.value == 'PRESS'
cls.key_decrease_factor = False if event is None else event.type in {'MINUS', 'NUMPAD_MINUS'} and event.value == 'PRESS'
cls.key_step_up = False if event is None else event.type == 'WHEELUPMOUSE'
Expand Down
56 changes: 49 additions & 7 deletions lib/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def toggle_pin_overlay(cls):
cls.pin_overlay = not cls.pin_overlay


def toggle_operator_passthrough(cls):
cls.operator_passthrough = not cls.operator_passthrough


def init_overlay(cls, event):
cls.overlay_offset_x = 25
cls.overlay_offset_y = -15
Expand All @@ -49,6 +53,7 @@ def init_overlay(cls, event):
cls.overlay_y = event.mouse_y - cls.region_offset_y + cls.overlay_offset_y

cls.pin_overlay = False
cls.operator_passthrough = False


def update_overlay(cls, context, event, x_offset=400, lines=1):
Expand Down Expand Up @@ -77,8 +82,19 @@ def update_overlay(cls, context, event, x_offset=400, lines=1):


def draw_header(cls):
if cls.operator_passthrough:
blf.size(0, 12, 72)
blf.color(0, .933, 0.231, 0.169, 1.0)
blf.position(0, cls.overlay_x + 1, cls.overlay_y + 26, 0)
blf.draw(0, "HALTED")

blf.size(0, 24, 72)
blf.color(0, 1.0, 0.529, 0.216, 1.0)

if cls.operator_passthrough:
blf.color(0, .933, 0.231, 0.169, 1.0)
else:
blf.color(0, 1.0, 0.529, 0.216, 1.0)

blf.position(0, cls.overlay_x, cls.overlay_y, 0)
blf.draw(0, "ND — " + cls.bl_label)

Expand All @@ -88,7 +104,9 @@ def draw_header(cls):
def draw_property(cls, property_content, metadata_content, active=False, alt_mode=False):
blf.size(0, 28, 72)

if active:
if cls.operator_passthrough:
blf.color(0, 1.0, 1.0, 1.0, 0.2)
elif active:
blf.color(0, 0.216, 0.686, 1.0, 1.0)
else:
blf.color(0, 1.0, 1.0, 1.0, 0.1)
Expand All @@ -101,12 +119,22 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod
blf.draw(0, "●")

blf.size(0, 16, 72)
blf.color(0, 1.0, 1.0, 1.0, 1.0)

if cls.operator_passthrough:
blf.color(0, 1.0, 1.0, 1.0, 0.2)
else:
blf.color(0, 1.0, 1.0, 1.0, 1.0)

blf.position(0, cls.overlay_x + 25, cls.overlay_y - (25 + (cls.line_spacer * cls.line_step)), 0)
blf.draw(0, property_content)

blf.size(0, 11, 72)
blf.color(0, 1.0, 1.0, 1.0, 0.3)

if cls.operator_passthrough:
blf.color(0, 1.0, 1.0, 1.0, 0.2)
else:
blf.color(0, 1.0, 1.0, 1.0, 0.3)

blf.position(0, cls.overlay_x + 25, cls.overlay_y - (40 + (cls.line_spacer * cls.line_step)), 0)
blf.draw(0, metadata_content)

Expand All @@ -116,17 +144,31 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod
def draw_hint(cls, hint_content, metadata_content):
blf.size(0, 22, 72)

blf.color(0, 1.0, 1.0, 1.0, 0.5)
if cls.operator_passthrough:
blf.color(0, 1.0, 1.0, 1.0, 0.2)
else:
blf.color(0, 1.0, 1.0, 1.0, 0.5)

blf.position(0, cls.overlay_x - 3, cls.overlay_y - (36 + (cls.line_spacer * cls.line_step)), 0)
blf.draw(0, "◈")

blf.size(0, 16, 72)
blf.color(0, 1.0, 1.0, 1.0, 1.0)

if cls.operator_passthrough:
blf.color(0, 1.0, 1.0, 1.0, 0.2)
else:
blf.color(0, 1.0, 1.0, 1.0, 1.0)

blf.position(0, cls.overlay_x + 25, cls.overlay_y - (25 + (cls.line_spacer * cls.line_step)), 0)
blf.draw(0, hint_content)

blf.size(0, 11, 72)
blf.color(0, 1.0, 1.0, 1.0, 0.3)

if cls.operator_passthrough:
blf.color(0, 1.0, 1.0, 1.0, 0.2)
else:
blf.color(0, 1.0, 1.0, 1.0, 0.3)

blf.position(0, cls.overlay_x + 25, cls.overlay_y - (40 + (cls.line_spacer * cls.line_step)), 0)
blf.draw(0, metadata_content)

Expand Down
15 changes: 13 additions & 2 deletions power_mods/screw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
import bmesh
from math import radians
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.events import capture_modifier_keys


Expand All @@ -19,9 +19,16 @@ def modal(self, context, event):
angle_factor = 1 if self.key_shift else 10
offset_factor = (self.base_offset_factor / 10.0) if self.key_shift else self.base_offset_factor

if self.key_toggle_operator_passthrough:
toggle_operator_passthrough(self)

if self.key_toggle_pin_overlay:
toggle_pin_overlay(self)

if self.operator_passthrough:
self.update_overlay_wrapper(context, event)
return {'PASS_THROUGH'}

elif self.key_increase_factor:
if self.key_ctrl_alt:
self.base_offset_factor = min(1, self.base_offset_factor * 10.0)
Expand Down Expand Up @@ -70,10 +77,14 @@ def modal(self, context, event):
return {'PASS_THROUGH'}

self.operate(context)
update_overlay(self, context, event, x_offset=360, lines=4)
self.update_overlay_wrapper(context, event)

return {'RUNNING_MODAL'}


def update_overlay_wrapper(self, context, event):
update_overlay(self, context, event, x_offset=340, lines=4)


def invoke(self, context, event):
self.base_offset_factor = 0.01
Expand Down
15 changes: 13 additions & 2 deletions power_mods/solidify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
import bmesh
from math import radians
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.events import capture_modifier_keys


Expand All @@ -18,9 +18,16 @@ def modal(self, context, event):
thickness_factor = (self.base_thickness_factor / 10.0) if self.key_shift else self.base_thickness_factor
offset_factor = (self.base_offset_factor / 10.0) if self.key_shift else self.base_offset_factor

if self.key_toggle_operator_passthrough:
toggle_operator_passthrough(self)

if self.key_toggle_pin_overlay:
toggle_pin_overlay(self)

if self.operator_passthrough:
self.update_overlay_wrapper(context, event)
return {'PASS_THROUGH'}

elif self.key_increase_factor:
if self.key_ctrl:
self.base_offset_factor = min(1, self.base_offset_factor * 10.0)
Expand Down Expand Up @@ -63,10 +70,14 @@ def modal(self, context, event):
return {'PASS_THROUGH'}

self.operate(context)
update_overlay(self, context, event, x_offset=300, lines=3)
self.update_overlay_wrapper(context, event)

return {'RUNNING_MODAL'}


def update_overlay_wrapper(self, context, event):
update_overlay(self, context, event, x_offset=300, lines=3)


def invoke(self, context, event):
self.base_thickness_factor = 0.01
Expand Down
15 changes: 13 additions & 2 deletions power_mods/weighted_normal_bevel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
import bmesh
from math import radians
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property
from .. lib.events import capture_modifier_keys


Expand All @@ -17,9 +17,16 @@ def modal(self, context, event):

width_factor = (self.base_width_factor / 10.0) if event.shift else self.base_width_factor

if self.key_toggle_operator_passthrough:
toggle_operator_passthrough(self)

if self.key_toggle_pin_overlay:
toggle_pin_overlay(self)

if self.operator_passthrough:
self.update_overlay_wrapper(context, event)
return {'PASS_THROUGH'}

elif self.key_increase_factor:
self.base_width_factor = min(1, self.base_width_factor * 10.0)

Expand All @@ -46,10 +53,14 @@ def modal(self, context, event):
return {'PASS_THROUGH'}

self.operate(context)
update_overlay(self, context, event, x_offset=270, lines=1)
self.update_overlay_wrapper(context, event)

return {'RUNNING_MODAL'}


def update_overlay_wrapper(self, context, event):
update_overlay(self, context, event, x_offset=270, lines=1)


def invoke(self, context, event):
self.base_width_factor = 0.001
Expand Down
15 changes: 13 additions & 2 deletions sketching/blank_sketch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bpy
import bmesh
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_hint
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_hint
from .. lib.objects import add_single_vertex_object, align_object_to_3d_cursor
from .. lib.events import capture_modifier_keys

Expand All @@ -15,9 +15,16 @@ class ND_OT_blank_sketch(bpy.types.Operator):
def modal(self, context, event):
capture_modifier_keys(self, event)

if self.key_toggle_operator_passthrough:
toggle_operator_passthrough(self)

if self.key_toggle_pin_overlay:
toggle_pin_overlay(self)

if self.operator_passthrough:
self.update_overlay_wrapper(context, event)
return {'PASS_THROUGH'}

elif self.key_confirm_alternative:
self.finish(context)

Expand All @@ -44,11 +51,15 @@ def modal(self, context, event):
elif self.key_movement_passthrough:
return {'PASS_THROUGH'}

update_overlay(self, context, event, x_offset=280, lines=1)
self.update_overlay_wrapper(context, event)

return {'RUNNING_MODAL'}


def update_overlay_wrapper(self, context, event):
update_overlay(self, context, event, x_offset=280, lines=1)


def invoke(self, context, event):
add_single_vertex_object(self, context, "Sketch")
align_object_to_3d_cursor(self, context)
Expand Down
15 changes: 13 additions & 2 deletions sketching/face_sketch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bpy
import bmesh
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_hint, draw_property
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_hint, draw_property
from .. lib.math import averaged_vector, create_rotation_matrix_from_face
from .. lib.viewport import set_3d_cursor
from .. lib.events import capture_modifier_keys
Expand All @@ -16,9 +16,16 @@ class ND_OT_face_sketch(bpy.types.Operator):
def modal(self, context, event):
capture_modifier_keys(self, event)

if self.key_toggle_operator_passthrough:
toggle_operator_passthrough(self)

if self.key_toggle_pin_overlay:
toggle_pin_overlay(self)

if self.operator_passthrough:
self.update_overlay_wrapper(context, event)
return {'PASS_THROUGH'}

elif self.key_step_up:
if self.key_alt:
self.face_operation_mode = (self.face_operation_mode + 1) % 2
Expand All @@ -44,10 +51,14 @@ def modal(self, context, event):
elif self.key_movement_passthrough:
return {'PASS_THROUGH'}

update_overlay(self, context, event, x_offset=320, lines=2)
self.update_overlay_wrapper(context, event)

return {'RUNNING_MODAL'}


def update_overlay_wrapper(self, context, event):
update_overlay(self, context, event, x_offset=320, lines=2)


def invoke(self, context, event):
self.face_operation_mode = 0 # Sketch Only (0), Extract & Sketch (1)
Expand Down
Loading

0 comments on commit 1ec0942

Please sign in to comment.