mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Change clicking behavior in InteractiveScene
This commit is contained in:
parent
7476740980
commit
3c0d682efc
1 changed files with 29 additions and 21 deletions
|
@ -29,6 +29,11 @@ from manimlib.utils.family_ops import extract_mobject_family_members
|
||||||
from manimlib.utils.space_ops import get_norm
|
from manimlib.utils.space_ops import get_norm
|
||||||
from manimlib.utils.tex_file_writing import LatexError
|
from manimlib.utils.tex_file_writing import LatexError
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from manimlib.typing import Vect3
|
||||||
|
|
||||||
|
|
||||||
SELECT_KEY = 's'
|
SELECT_KEY = 's'
|
||||||
UNSELECT_KEY = 'u'
|
UNSELECT_KEY = 'u'
|
||||||
|
@ -68,7 +73,7 @@ class InteractiveScene(Scene):
|
||||||
"""
|
"""
|
||||||
corner_dot_config = dict(
|
corner_dot_config = dict(
|
||||||
color=WHITE,
|
color=WHITE,
|
||||||
radius=0.025,
|
radius=0.05,
|
||||||
glow_factor=2.0,
|
glow_factor=2.0,
|
||||||
)
|
)
|
||||||
selection_rectangle_stroke_color = WHITE
|
selection_rectangle_stroke_color = WHITE
|
||||||
|
@ -273,7 +278,7 @@ class InteractiveScene(Scene):
|
||||||
|
|
||||||
def get_corner_dots(self, mobject: Mobject) -> Mobject:
|
def get_corner_dots(self, mobject: Mobject) -> Mobject:
|
||||||
dots = DotCloud(**self.corner_dot_config)
|
dots = DotCloud(**self.corner_dot_config)
|
||||||
radius = self.corner_dot_config["radius"]
|
radius = float(self.corner_dot_config["radius"])
|
||||||
if mobject.get_depth() < 1e-2:
|
if mobject.get_depth() < 1e-2:
|
||||||
vects = [DL, UL, UR, DR]
|
vects = [DL, UL, UR, DR]
|
||||||
else:
|
else:
|
||||||
|
@ -389,7 +394,9 @@ class InteractiveScene(Scene):
|
||||||
for mob in reversed(self.get_selection_search_set()):
|
for mob in reversed(self.get_selection_search_set()):
|
||||||
if self.selection_rectangle.is_touching(mob):
|
if self.selection_rectangle.is_touching(mob):
|
||||||
additions.append(mob)
|
additions.append(mob)
|
||||||
self.add_to_selection(*additions)
|
if self.selection_rectangle.get_arc_length() < 1e-2:
|
||||||
|
break
|
||||||
|
self.toggle_from_selection(*additions)
|
||||||
|
|
||||||
def prepare_grab(self):
|
def prepare_grab(self):
|
||||||
mp = self.mouse_point.get_center()
|
mp = self.mouse_point.get_center()
|
||||||
|
@ -509,7 +516,6 @@ class InteractiveScene(Scene):
|
||||||
super().on_key_release(symbol, modifiers)
|
super().on_key_release(symbol, modifiers)
|
||||||
if chr(symbol) == SELECT_KEY:
|
if chr(symbol) == SELECT_KEY:
|
||||||
self.gather_new_selection()
|
self.gather_new_selection()
|
||||||
# self.remove(self.crosshair)
|
|
||||||
if chr(symbol) in GRAB_KEYS:
|
if chr(symbol) in GRAB_KEYS:
|
||||||
self.is_grabbing = False
|
self.is_grabbing = False
|
||||||
elif chr(symbol) == INFORMATION_KEY:
|
elif chr(symbol) == INFORMATION_KEY:
|
||||||
|
@ -518,7 +524,7 @@ class InteractiveScene(Scene):
|
||||||
self.prepare_resizing(about_corner=False)
|
self.prepare_resizing(about_corner=False)
|
||||||
|
|
||||||
# Mouse actions
|
# Mouse actions
|
||||||
def handle_grabbing(self, point: np.ndarray):
|
def handle_grabbing(self, point: Vect3):
|
||||||
diff = point - self.mouse_to_selection
|
diff = point - self.mouse_to_selection
|
||||||
if self.window.is_key_pressed(ord(GRAB_KEY)):
|
if self.window.is_key_pressed(ord(GRAB_KEY)):
|
||||||
self.selection.move_to(diff)
|
self.selection.move_to(diff)
|
||||||
|
@ -527,7 +533,7 @@ class InteractiveScene(Scene):
|
||||||
elif self.window.is_key_pressed(ord(Y_GRAB_KEY)):
|
elif self.window.is_key_pressed(ord(Y_GRAB_KEY)):
|
||||||
self.selection.set_y(diff[1])
|
self.selection.set_y(diff[1])
|
||||||
|
|
||||||
def handle_resizing(self, point: np.ndarray):
|
def handle_resizing(self, point: Vect3):
|
||||||
if not hasattr(self, "scale_about_point"):
|
if not hasattr(self, "scale_about_point"):
|
||||||
return
|
return
|
||||||
vect = point - self.scale_about_point
|
vect = point - self.scale_about_point
|
||||||
|
@ -547,15 +553,16 @@ class InteractiveScene(Scene):
|
||||||
about_point=self.scale_about_point
|
about_point=self.scale_about_point
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_sweeping_selection(self, point: np.ndarray):
|
def handle_sweeping_selection(self, point: Vect3):
|
||||||
mob = self.point_to_mobject(
|
mob = self.point_to_mobject(
|
||||||
point, search_set=self.get_selection_search_set(),
|
point,
|
||||||
|
search_set=self.get_selection_search_set(),
|
||||||
buff=SMALL_BUFF
|
buff=SMALL_BUFF
|
||||||
)
|
)
|
||||||
if mob is not None:
|
if mob is not None:
|
||||||
self.add_to_selection(mob)
|
self.add_to_selection(mob)
|
||||||
|
|
||||||
def choose_color(self, point: np.ndarray):
|
def choose_color(self, point: Vect3):
|
||||||
# Search through all mobject on the screen, not just the palette
|
# Search through all mobject on the screen, not just the palette
|
||||||
to_search = [
|
to_search = [
|
||||||
sm
|
sm
|
||||||
|
@ -568,10 +575,9 @@ class InteractiveScene(Scene):
|
||||||
self.selection.set_color(mob.get_color())
|
self.selection.set_color(mob.get_color())
|
||||||
self.remove(self.color_palette)
|
self.remove(self.color_palette)
|
||||||
|
|
||||||
def on_mouse_motion(self, point: np.ndarray, d_point: np.ndarray) -> None:
|
def on_mouse_motion(self, point: Vect3, d_point: Vect3) -> None:
|
||||||
super().on_mouse_motion(point, d_point)
|
super().on_mouse_motion(point, d_point)
|
||||||
ff_point = self.frame.to_fixed_frame_point(point)
|
self.crosshair.move_to(self.frame.to_fixed_frame_point(point))
|
||||||
self.crosshair.move_to(ff_point)
|
|
||||||
if self.is_grabbing:
|
if self.is_grabbing:
|
||||||
self.handle_grabbing(point)
|
self.handle_grabbing(point)
|
||||||
elif self.window.is_key_pressed(ord(RESIZE_KEY)):
|
elif self.window.is_key_pressed(ord(RESIZE_KEY)):
|
||||||
|
@ -579,17 +585,19 @@ class InteractiveScene(Scene):
|
||||||
elif self.window.is_key_pressed(ord(SELECT_KEY)) and self.window.is_key_pressed(SHIFT_SYMBOL):
|
elif self.window.is_key_pressed(ord(SELECT_KEY)) and self.window.is_key_pressed(SHIFT_SYMBOL):
|
||||||
self.handle_sweeping_selection(point)
|
self.handle_sweeping_selection(point)
|
||||||
|
|
||||||
def on_mouse_release(self, point: np.ndarray, button: int, mods: int) -> None:
|
def on_mouse_drag(
|
||||||
|
self,
|
||||||
|
point: Vect3,
|
||||||
|
d_point: Vect3,
|
||||||
|
buttons: int,
|
||||||
|
modifiers: int
|
||||||
|
) -> None:
|
||||||
|
super().on_mouse_drag(point, d_point, buttons, modifiers)
|
||||||
|
self.crosshair.move_to(self.frame.to_fixed_frame_point(point))
|
||||||
|
|
||||||
|
def on_mouse_release(self, point: Vect3, button: int, mods: int) -> None:
|
||||||
super().on_mouse_release(point, button, mods)
|
super().on_mouse_release(point, button, mods)
|
||||||
if self.color_palette in self.mobjects:
|
if self.color_palette in self.mobjects:
|
||||||
self.choose_color(point)
|
self.choose_color(point)
|
||||||
return
|
|
||||||
mobject = self.point_to_mobject(
|
|
||||||
point,
|
|
||||||
search_set=self.get_selection_search_set(),
|
|
||||||
buff=1e-4,
|
|
||||||
)
|
|
||||||
if mobject is not None:
|
|
||||||
self.toggle_from_selection(mobject)
|
|
||||||
else:
|
else:
|
||||||
self.clear_selection()
|
self.clear_selection()
|
||||||
|
|
Loading…
Add table
Reference in a new issue