Skip to content

Commit

Permalink
feat: add mouse-step values to lattice, screw, array_cubed, circular_…
Browse files Browse the repository at this point in the history
…array operators
  • Loading branch information
tristan-hm committed Sep 16, 2022
1 parent 1fcb674 commit 22e53de
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
21 changes: 20 additions & 1 deletion deform/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def modal(self, context, event):
elif no_stream(self.lattice_points_w_input_stream) and self.key_ctrl:
self.lattice_points_w += 1
self.dirty = True


elif self.key_step_down:
if no_stream(self.lattice_points_u_input_stream) and self.uniform:
Expand All @@ -165,6 +164,23 @@ def modal(self, context, event):
elif self.key_movement_passthrough:
return {'PASS_THROUGH'}

if get_preferences().enable_mouse_values:
if no_stream(self.lattice_points_u_input_stream) and self.uniform:
self.lattice_points_u = max(2, self.lattice_points_u + self.mouse_step)
self.lattice_points_v = self.lattice_points_u
self.lattice_points_w = self.lattice_points_u
self.dirty = True
elif not self.uniform:
if no_stream(self.lattice_points_u_input_stream) and self.key_no_modifiers:
self.lattice_points_u = max(2, self.lattice_points_u + self.mouse_step)
self.dirty = True
elif no_stream(self.lattice_points_v_input_stream) and self.key_alt:
self.lattice_points_v = max(2, self.lattice_points_v + self.mouse_step)
self.dirty = True
elif no_stream(self.lattice_points_w_input_stream) and self.key_ctrl:
self.lattice_points_w = max(2, self.lattice_points_w + self.mouse_step)
self.dirty = True

if self.dirty:
self.operate(context)

Expand Down Expand Up @@ -354,6 +370,7 @@ def draw_text_callback(self):
"(±1)",
active=(self.uniform or self.key_no_modifiers),
alt_mode=False,
mouse_value=True,
input_stream=self.lattice_points_u_input_stream)

draw_property(
Expand All @@ -362,6 +379,7 @@ def draw_text_callback(self):
"Alt (±1)",
active=(self.uniform or self.key_alt),
alt_mode=False,
mouse_value=True,
input_stream=self.lattice_points_v_input_stream)

draw_property(
Expand All @@ -370,6 +388,7 @@ def draw_text_callback(self):
"Ctrl (±1)",
active=(self.uniform or self.key_ctrl),
alt_mode=False,
mouse_value=True,
input_stream=self.lattice_points_w_input_stream)

draw_hint(
Expand Down
4 changes: 4 additions & 0 deletions extrusion/screw.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def modal(self, context, event):
elif no_stream(self.angle_input_stream) and self.key_alt:
self.angle = max(-360, min(360, self.angle + self.mouse_value_mag))
self.dirty = True
elif no_stream(self.segments_input_stream) and self.key_no_modifiers:
self.segments = max(3, self.segments + self.mouse_step)
self.dirty = True

if self.dirty:
self.operate(context)
Expand Down Expand Up @@ -320,6 +323,7 @@ def draw_text_callback(self):
"(±2) | Shift (±1)",
active=self.key_no_modifiers,
alt_mode=self.key_shift_no_modifiers,
mouse_value=True,
input_stream=self.segments_input_stream)

draw_property(
Expand Down
5 changes: 4 additions & 1 deletion lib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def capture_modifier_keys(cls, event=None, mouse_x=0):

cls.prev_mouse_travel_div = 0 if event == None else cls.mouse_travel_div
cls.mouse_travel_div = cls.mouse_travel // get_preferences().mouse_value_steps
cls.mouse_step = int(1 * copysign(1, cls.mouse_travel)) if cls.prev_mouse_travel_div != cls.mouse_travel_div else 0
if cls.prev_mouse_travel_div != cls.mouse_travel_div and abs(cls.mouse_travel) >= get_preferences().mouse_value_steps:
cls.mouse_step = int(1 * copysign(1, cls.mouse_travel))
else:
cls.mouse_step = 0

if event == None or cls.mouse_warped:
cls.mouse_delta = 0
Expand Down
16 changes: 15 additions & 1 deletion replicate/array_cubed.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,20 @@ def modal(self, context, event):
return {'PASS_THROUGH'}

if get_preferences().enable_mouse_values:
if self.key_ctrl:
if self.key_no_modifiers and abs(self.mouse_step) > 0:
if self.mouse_step > 0:
new_count = self.axes[self.axis][1] + (1 if self.axes[self.axis][2] >= 0 else -1)
elif self.mouse_step < 0:
new_count = self.axes[self.axis][1] - (1 if self.axes[self.axis][2] >= 0 else -1)

if new_count == 0:
self.axes[self.axis][1] = 2
self.axes[self.axis][2] = self.axes[self.axis][2] * -1
else:
self.axes[self.axis][1] = new_count

self.dirty = True
elif self.key_ctrl:
self.axes[self.axis][2] += self.mouse_value
self.dirty = True

Expand Down Expand Up @@ -262,6 +275,7 @@ def draw_text_callback(self):
"Alt (±1)",
active=self.key_no_modifiers,
alt_mode=False,
mouse_value=True,
input_stream=self.count_streams[self.axis])

draw_property(
Expand Down
4 changes: 4 additions & 0 deletions replicate/circular_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def modal(self, context, event):
elif no_stream(self.offset_input_stream) and self.key_ctrl:
self.offset += self.mouse_value
self.dirty = True
elif no_stream(self.count_input_stream) and self.key_no_modifiers:
self.count = max(2, self.count + self.mouse_step)
self.dirty = True

if self.dirty:
self.operate(context)
Expand Down Expand Up @@ -403,6 +406,7 @@ def draw_text_callback(self):
"(±2) | Shift (±1)",
active=self.key_no_modifiers,
alt_mode=self.key_shift_no_modifiers,
mouse_value=True,
input_stream=self.count_input_stream)

draw_property(
Expand Down

0 comments on commit 22e53de

Please sign in to comment.