Skip to content

Commit

Permalink
Allow stretched-resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Apr 21, 2022
1 parent 78a7078 commit b4b72d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions manimlib/constants.py
Expand Up @@ -74,6 +74,7 @@
# For keyboard interactions
CTRL_SYMBOL = 65508
SHIFT_SYMBOL = 65505
COMMAND_SYMBOL = 65517
DELETE_SYMBOL = 65288
ARROW_SYMBOLS = list(range(65361, 65365))

Expand Down
24 changes: 17 additions & 7 deletions manimlib/scene/interactive_scene.py
Expand Up @@ -6,7 +6,7 @@
from manimlib.constants import MANIM_COLORS, WHITE
from manimlib.constants import ORIGIN, UP, DOWN, LEFT, RIGHT, DL, UL, UR, DR
from manimlib.constants import FRAME_WIDTH, SMALL_BUFF
from manimlib.constants import SHIFT_SYMBOL, DELETE_SYMBOL, ARROW_SYMBOLS
from manimlib.constants import SHIFT_SYMBOL, CTRL_SYMBOL, DELETE_SYMBOL, ARROW_SYMBOLS
from manimlib.constants import SHIFT_MODIFIER, COMMAND_MODIFIER
from manimlib.mobject.mobject import Mobject
from manimlib.mobject.geometry import Rectangle
Expand Down Expand Up @@ -258,6 +258,7 @@ def prepare_resizing(self, about_corner=False):
self.scale_about_point = center
self.scale_ref_vect = mp - self.scale_about_point
self.scale_ref_width = self.selection.get_width()
self.scale_ref_height = self.selection.get_height()

# Event handlers

Expand Down Expand Up @@ -367,13 +368,22 @@ def on_mouse_motion(self, point: np.ndarray, d_point: np.ndarray) -> None:
self.selection.set_y((point - self.mouse_to_selection)[1])
# Scale selection
elif self.window.is_key_pressed(ord(RESIZE_KEY)):
# TODO, allow for scaling about the opposite corner
vect = point - self.scale_about_point
scalar = get_norm(vect) / get_norm(self.scale_ref_vect)
self.selection.set_width(
scalar * self.scale_ref_width,
about_point=self.scale_about_point
)
if self.window.is_key_pressed(CTRL_SYMBOL):
for i in (0, 1):
scalar = vect[i] / self.scale_ref_vect[i]
self.selection.rescale_to_fit(
scalar * [self.scale_ref_width, self.scale_ref_height][i],
dim=i,
about_point=self.scale_about_point,
stretch=True,
)
else:
scalar = get_norm(vect) / get_norm(self.scale_ref_vect)
self.selection.set_width(
scalar * self.scale_ref_width,
about_point=self.scale_about_point
)
# Add to selection
elif self.window.is_key_pressed(ord(SELECT_KEY)) and self.window.is_key_pressed(SHIFT_SYMBOL):
mob = self.point_to_mobject(
Expand Down

0 comments on commit b4b72d1

Please sign in to comment.