Skip to content

Commit

Permalink
Rewrite & amend symmetry state, overlay & editing
Browse files Browse the repository at this point in the history
Fairly substantial refactoring - summary of user-facing changes:

Disable button (w. trashcan icon) always drawn, when in edit mode.

Disable button positioned as close to _symmetry center_ as possible,
rather than as close to the _viewport center_ as possible. This is so
that it can be used as an indicator for the location of the symmetry
center, when the center is outside the viewport. Note that for the
original symmetry mode, the location of the center had no relevance.

When in edit mode, there is now a center marker that can be used to
move the symmetry center by dragging - takes priority over individual
axes.

Statusbar messages now update correctly (minor thinko in old code,
_last_msg_zone not always updated when moving to default zone).

For the Rotational and Snowflake modes - axes are drawn for each line,
rather than drawing the same axes as for Vertical+Horizontal.

Axes are highlighted correctly when hovered over when in edit mode,
regardless of view transformation (old checks were made in display
space rather than model space).

When adjusting transformation based on a single axis, the change to
the center is locked based on the model-space angle of the axis,
meaning that e.g. dragging a vertical axis will only affect the
x-coordinate of the center, regardless of view transformation,
but dragging a "vertical" axis with a non-90° angle will change
both the x- and y-coordinates of the center.

The TiledDrawWidget get_move_cursor_name_for_edge method has been
refactored as part of this commit. It now uses the related functions
in lib.alg, and no longer returns the distance.
The symmetry gui code was the only user of that method.

Positional scaling of alpha values when in edit mode is removed.
Instead, the alpha value is clamped to a minimum of 25% opacity,
except for when the alpha value is edited.

== Internal refactoring and bug fixes ==

An "unset state" is now flagged separately instead of using None
for center coordinates. State setters simplified accordingly.

Use a tuple for center coordinates.
Use `handler_block` to avoid event cycles.
Only call symmetry_state_changed with parameters that have actually
changed, and set the remaining ones to None - allowing more granular
handling in the event listeners.
  • Loading branch information
jplloyd committed Jul 3, 2020
1 parent bfab5b3 commit 7d95cfa
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 681 deletions.
43 changes: 22 additions & 21 deletions gui/document.py
Expand Up @@ -1846,30 +1846,31 @@ def rotate_centered_cb(self, action, *test):

def symmetry_active_toggled_cb(self, action):
"""Handle changes to the SymmetryActive toggle"""
already_active = bool(self.model.layer_stack.symmetry_active)
stack = self.model.layer_stack
center = None
want_active = bool(action.get_active())
if want_active and not already_active:

# When going from an unset state to an active state, the symmetry
# center (model coordinates) is set based on the center of the viewport
if stack.symmetry_unset and want_active:
stack.symmetry_unset = False
alloc = self.tdw.get_allocation()
axis_x_pos = self.model.layer_stack.symmetry_x
axis_y_pos = self.model.layer_stack.symmetry_y
if axis_x_pos is None or axis_y_pos is None:
center_disp = alloc.width / 2.0, alloc.height / 2.0
center_model = self.tdw.display_to_model(*center_disp)
axis_x_pos = center_model[0]
axis_y_pos = center_model[1]
self.model.layer_stack.symmetry_x = axis_x_pos
self.model.layer_stack.symmetry_y = axis_y_pos
if want_active != already_active:
self.model.layer_stack.symmetry_active = want_active

def _symmetry_state_changed_cb(self, layerstack, active, x, y,
sym_type, rot_sym_lines, sym_angle):
dx, dy = alloc.width / 2.0, alloc.height / 2.0
center = self.tdw.display_to_model(dx, dy)

already_active = stack.symmetry_active
if want_active != already_active or center is not None:
stack.set_symmetry_state(want_active, center=center)

def _symmetry_state_changed_cb(
self, stack, active, center, sym_type, sym_lines, sym_angle):
"""Update the SymmetryActive toggle on model state changes"""
symm_toggle = self.action_group.get_action("SymmetryActive")
symm_toggle_active = bool(symm_toggle.get_active())
model_symm_active = bool(active)
if symm_toggle_active != model_symm_active:
symm_toggle.set_active(model_symm_active)
if active is not None:
symm_toggle = self.action_group.get_action("SymmetryActive")
symm_toggle_active = bool(symm_toggle.get_active())
model_symm_active = bool(active)
if symm_toggle_active != model_symm_active:
symm_toggle.set_active(model_symm_active)

## More viewport manipulation

Expand Down

0 comments on commit 7d95cfa

Please sign in to comment.