Skip to content

Commit

Permalink
feat: add option to change overlay reset key behaviour to unlock inst…
Browse files Browse the repository at this point in the history
…ead of hard-reset
  • Loading branch information
tristan-hm authored Jun 25, 2024
1 parent 2422215 commit fe6efb5
Show file tree
Hide file tree
Showing 22 changed files with 171 additions and 110 deletions.
12 changes: 11 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ class NDPreferences(AddonPreferences):
default=True,
)

overlay_reset_key_behaviour: EnumProperty(
name="Overlay Reset Key Behaviour",
items=[
("RESET", "Reset", ""),
("UNLOCK", "Unlock", ""),
],
default="RESET",
)

overlay_pinned: BoolProperty(
name="Overlay Pinned",
default=False,
Expand Down Expand Up @@ -560,7 +569,8 @@ def draw_keymap(self, box):
overlay_prefs = [
"overlay_pin_key",
"overlay_pause_key",
"overlay_reset_key"]
"overlay_reset_key",
"overlay_reset_key_behaviour"]

column = box.column(align=True)
row = column.row()
Expand Down
22 changes: 13 additions & 9 deletions bevels/bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, add_smooth_by_angle, rectify_smooth_by_angle


Expand Down Expand Up @@ -74,21 +74,25 @@ def do_modal(self, context, event):

if self.key_reset:
if self.key_no_modifiers:
if has_stream(self.width_input_stream) and self.hard_stream_reset or no_stream(self.width_input_stream):
self.width = 0
self.dirty = True
self.width_input_stream = new_stream()
self.width = 0
self.dirty = True
elif self.key_alt:
if has_stream(self.segments_input_stream) and self.hard_stream_reset or no_stream(self.segments_input_stream):
self.segments = 1
self.dirty = True
self.segments_input_stream = new_stream()
self.segments = 1
self.dirty = True
elif self.key_ctrl:
if has_stream(self.profile_input_stream) and self.hard_stream_reset or no_stream(self.profile_input_stream):
self.profile = 0.5
self.dirty = True
self.profile_input_stream = new_stream()
self.profile = 0.5
self.dirty = True
elif self.key_ctrl_alt:
if has_stream(self.angle_input_stream) and self.hard_stream_reset or no_stream(self.angle_input_stream):
self.angle = int(get_preferences().default_smoothing_angle)
self.dirty = True
self.angle_input_stream = new_stream()
self.angle = int(get_preferences().default_smoothing_angle)
self.dirty = True

if pressed(event, {'H'}):
self.harden_normals = not self.harden_normals
Expand Down
22 changes: 13 additions & 9 deletions bevels/edge_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -74,21 +74,25 @@ def do_modal(self, context, event):

if self.key_reset:
if self.key_ctrl_alt:
if has_stream(self.weight_input_stream) and self.hard_stream_reset or no_stream(self.weight_input_stream):
self.weight = 0
self.dirty = True
self.weight_input_stream = new_stream()
self.weight = 0
self.dirty = True
elif self.key_alt:
if has_stream(self.segments_input_stream) and self.hard_stream_reset or no_stream(self.segments_input_stream):
self.segments = 1
self.dirty = True
self.segments_input_stream = new_stream()
self.segments = 1
self.dirty = True
elif self.key_ctrl:
if has_stream(self.profile_input_stream) and self.hard_stream_reset or no_stream(self.profile_input_stream):
self.profile = 0.5
self.dirty = True
self.profile_input_stream = new_stream()
self.profile = 0.5
self.dirty = True
elif self.key_no_modifiers:
if has_stream(self.width_input_stream) and self.hard_stream_reset or no_stream(self.width_input_stream):
self.width = 0.05 * self.unit_factor
self.dirty = True
self.width_input_stream = new_stream()
self.width = 0.05 * self.unit_factor
self.dirty = True

if pressed(event, {'H'}):
self.harden_normals = not self.harden_normals
Expand Down
17 changes: 10 additions & 7 deletions bevels/vertex_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -71,17 +71,20 @@ def do_modal(self, context, event):

if self.key_reset:
if self.key_no_modifiers:
if has_stream(self.width_input_stream) and self.hard_stream_reset or no_stream(self.width_input_stream):
self.width = 0
self.dirty = True
self.width_input_stream = new_stream()
self.width = 0
self.dirty = True
elif self.key_alt:
if has_stream(self.segments_input_stream) and self.hard_stream_reset or no_stream(self.segments_input_stream):
self.segments = 1
self.dirty = True
self.segments_input_stream = new_stream()
self.segments = 1
self.dirty = True
elif self.key_ctrl:
if has_stream(self.profile_input_stream) and self.hard_stream_reset or no_stream(self.profile_input_stream):
self.profile = 0.5
self.dirty = True
self.profile_input_stream = new_stream()
self.profile = 0.5
self.dirty = True

if pressed(event, {'W'}):
self.target_object.show_wire = not self.target_object.show_wire
Expand Down
7 changes: 4 additions & 3 deletions booleans/boolean_inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.collections import move_to_utils_collection, isolate_in_utils_collection
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_problematic_boolean_mods, rectify_smooth_by_angle


Expand All @@ -52,9 +52,10 @@ def do_modal(self, context, event):

if self.key_reset:
if self.key_no_modifiers:
if has_stream(self.thickness_input_stream) and self.hard_stream_reset or no_stream(self.thickness_input_stream):
self.thickness = 0
self.dirty = True
self.thickness_input_stream = new_stream()
self.thickness = 0
self.dirty = True

if pressed(event, {'M'}):
self.outset = not self.outset
Expand Down
28 changes: 16 additions & 12 deletions deform/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.preferences import get_preferences
from .. lib.collections import move_to_utils_collection, isolate_in_utils_collection, hide_utils_collection
from .. lib.math import generate_bounding_box, v3_average
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle


Expand All @@ -53,7 +53,7 @@ def do_modal(self, context, event):
if self.key_numeric_input:
if self.key_no_modifiers:
self.lattice_points_u_input_stream = update_stream(self.lattice_points_u_input_stream, event.type)
self.lattice_points_u = get_stream_value(self.lattice_points_u_input_stream, min_value=2)
self.lattice_points_u = int(get_stream_value(self.lattice_points_u_input_stream, min_value=2))

if self.uniform:
self.lattice_points_v_input_stream = self.lattice_points_u_input_stream
Expand All @@ -65,33 +65,37 @@ def do_modal(self, context, event):
self.dirty = True
elif self.key_alt:
self.lattice_points_v_input_stream = update_stream(self.lattice_points_v_input_stream, event.type)
self.lattice_points_v = get_stream_value(self.lattice_points_v_input_stream, min_value=2)
self.lattice_points_v = int(get_stream_value(self.lattice_points_v_input_stream, min_value=2))
self.dirty = True
elif self.key_ctrl:
self.lattice_points_w_input_stream = update_stream(self.lattice_points_w_input_stream, event.type)
self.lattice_points_w = get_stream_value(self.lattice_points_w_input_stream, min_value=2)
self.lattice_points_w = int(get_stream_value(self.lattice_points_w_input_stream, min_value=2))
self.dirty = True

elif self.key_reset:
if self.key_no_modifiers:
self.lattice_points_u_input_stream = new_stream()
self.lattice_points_u = 2
if has_stream(self.lattice_points_u_input_stream) and self.hard_stream_reset or no_stream(self.lattice_points_u_input_stream):
self.lattice_points_u = 2

if self.uniform:
if has_stream(self.lattice_points_u_input_stream) and self.hard_stream_reset or no_stream(self.lattice_points_u_input_stream):
self.lattice_points_v = 2
self.lattice_points_w = 2
self.lattice_points_v_input_stream = new_stream()
self.lattice_points_w_input_stream = new_stream()
self.lattice_points_v = 2
self.lattice_points_w = 2

self.lattice_points_u_input_stream = new_stream()
self.dirty = True
elif self.key_alt:
if has_stream(self.lattice_points_v_input_stream) and self.hard_stream_reset or no_stream(self.lattice_points_v_input_stream):
self.lattice_points_v = 2
self.dirty = True
self.lattice_points_v_input_stream = new_stream()
self.lattice_points_v = 2
self.dirty = True
elif self.key_ctrl:
if has_stream(self.lattice_points_w_input_stream) and self.hard_stream_reset or no_stream(self.lattice_points_w_input_stream):
self.lattice_points_w = 2
self.dirty = True
self.lattice_points_w_input_stream = new_stream()
self.lattice_points_w = 2
self.dirty = True

elif pressed(event, {'U'}):
self.uniform = not self.uniform
Expand Down
12 changes: 7 additions & 5 deletions deform/simple_deform.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.axis import init_axis, register_axis_handler, unregister_axis_handler
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle


Expand Down Expand Up @@ -67,13 +67,15 @@ def do_modal(self, context, event):
elif self.key_reset:
if self.key_no_modifiers:
if self.is_angular[self.methods[self.current_method]]:
if has_stream(self.angle_input_stream) and self.hard_stream_reset or no_stream(self.angle_input_stream):
self.angle = 0
self.dirty = True
self.angle_input_stream = new_stream()
self.angle = 0
else:
if has_stream(self.factor_input_stream) and self.hard_stream_reset or no_stream(self.factor_input_stream):
self.factor = 0
self.dirty = True
self.factor_input_stream = new_stream()
self.factor = 0

self.dirty = True

elif pressed(event, {'M'}):
self.current_method = (self.current_method + 1) % len(self.methods)
Expand Down
12 changes: 7 additions & 5 deletions extrusion/profile_extrude.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.axis import init_axis, register_axis_handler, unregister_axis_handler
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -63,13 +63,15 @@ def do_modal(self, context, event):

if self.key_reset:
if self.key_no_modifiers:
if has_stream(self.extrusion_length_input_stream) and self.hard_stream_reset or no_stream(self.extrusion_length_input_stream):
self.extrusion_length = 0
self.dirty = True
self.extrusion_length_input_stream = new_stream()
self.extrusion_length = 0
self.dirty = True
elif self.key_ctrl:
if has_stream(self.offset_input_stream) and self.hard_stream_reset or no_stream(self.offset_input_stream):
self.offset = 0
self.dirty = True
self.offset_input_stream = new_stream()
self.offset = 0
self.dirty = True

if pressed(event, {'A'}):
self.axis = (self.axis + 1) % 3
Expand Down
17 changes: 10 additions & 7 deletions extrusion/screw.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.axis import init_axis, register_axis_handler, unregister_axis_handler
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, add_smooth_by_angle, rectify_smooth_by_angle


Expand Down Expand Up @@ -70,17 +70,20 @@ def do_modal(self, context, event):

if self.key_reset:
if self.key_no_modifiers:
if has_stream(self.segments_input_stream) and self.hard_stream_reset or no_stream(self.segments_input_stream):
self.segments = 3
self.dirty = True
self.segments_input_stream = new_stream()
self.segments = 3
self.dirty = True
elif self.key_alt:
if has_stream(self.angle_input_stream) and self.hard_stream_reset or no_stream(self.angle_input_stream):
self.angle = 360
self.dirty = True
self.angle_input_stream = new_stream()
self.angle = 360
self.dirty = True
elif self.key_ctrl:
if has_stream(self.offset_input_stream) and self.hard_stream_reset or no_stream(self.offset_input_stream):
self.offset = 0
self.dirty = True
self.offset_input_stream = new_stream()
self.offset = 0
self.dirty = True

if pressed(event, {'A'}):
self.axis = (self.axis + 1) % 3
Expand Down
12 changes: 7 additions & 5 deletions extrusion/solidify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import init_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences, get_scene_unit_factor
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -61,13 +61,15 @@ def do_modal(self, context, event):

if self.key_reset:
if self.key_no_modifiers:
if has_stream(self.thickness_input_stream) and self.hard_stream_reset or no_stream(self.thickness_input_stream):
self.thickness = 0
self.dirty = True
self.thickness_input_stream = new_stream()
self.thickness = 0
self.dirty = True
elif self.key_ctrl:
if has_stream(self.offset_input_stream) and self.hard_stream_reset or no_stream(self.offset_input_stream):
self.offset = 0
self.dirty = True
self.offset_input_stream = new_stream()
self.offset = 0
self.dirty = True

if pressed(event, {'W'}):
self.weighting = self.weighting + 1 if self.weighting < 1 else -1
Expand Down
1 change: 1 addition & 0 deletions lib/base_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def invoke(self, context, event):
self.unit_step_hint = self.generate_step_hint(f"{(self.unit_scale * unit_increment_size):.2f}{self.unit_suffix}", f"{(self.unit_scale * 0.1 * unit_increment_size):.2f}{self.unit_suffix}")

self.extend_mouse_values = get_preferences().enable_mouse_values and get_preferences().extend_mouse_values
self.hard_stream_reset = get_preferences().overlay_reset_key_behaviour == 'RESET'

return self.do_invoke(context, event)

Expand Down
6 changes: 6 additions & 0 deletions lib/numeric_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def no_stream(input_stream):
return value is None


def has_stream(input_stream):
ok, value, raw = input_stream

return value is not None


def get_stream_value(input_stream, factor=1, default=0, min_value=-inf, max_value=inf):
ok, value, raw = input_stream

Expand Down
3 changes: 2 additions & 1 deletion lib/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod
blf.position(0, cls.overlay_x + (25 * cls.dpi_scalar), cls.overlay_y - ((40 * cls.dpi_scalar) + (cls.line_spacer * cls.line_step)), 0)

if is_value is not None:
blf.draw(0, "Manual Override — [{}] to reset.".format(get_preferences().overlay_reset_key))
reset_behaviour = get_preferences().overlay_reset_key_behaviour
blf.draw(0, "Manual Override — [{}] to {}.".format(get_preferences().overlay_reset_key, "reset" if reset_behaviour == "RESET" else "unlock"))
else:
blf.draw(0, metadata_content)

Expand Down
Loading

0 comments on commit fe6efb5

Please sign in to comment.