mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 05:24:22 +08:00
Add Mobject.has_updaters which is distinct from Mobject.suspend_updating
This commit is contained in:
@ -66,10 +66,8 @@ class Mobject(Container):
|
|||||||
self.family = [self]
|
self.family = [self]
|
||||||
if self.name is None:
|
if self.name is None:
|
||||||
self.name = self.__class__.__name__
|
self.name = self.__class__.__name__
|
||||||
self.time_based_updaters = []
|
|
||||||
self.non_time_updaters = []
|
|
||||||
self.check_for_updaters = False
|
|
||||||
|
|
||||||
|
self.init_updaters()
|
||||||
self.reset_points()
|
self.reset_points()
|
||||||
self.init_points()
|
self.init_points()
|
||||||
self.init_colors()
|
self.init_colors()
|
||||||
@ -115,7 +113,7 @@ class Mobject(Container):
|
|||||||
def assemble_family(self):
|
def assemble_family(self):
|
||||||
sub_families = [sm.get_family() for sm in self.submobjects]
|
sub_families = [sm.get_family() for sm in self.submobjects]
|
||||||
self.family = [self, *it.chain(*sub_families)]
|
self.family = [self, *it.chain(*sub_families)]
|
||||||
self.refresh_check_for_updater_status()
|
self.refresh_has_updater_status()
|
||||||
for parent in self.parents:
|
for parent in self.parents:
|
||||||
parent.assemble_family()
|
parent.assemble_family()
|
||||||
return self
|
return self
|
||||||
@ -237,9 +235,14 @@ class Mobject(Container):
|
|||||||
return self.target
|
return self.target
|
||||||
|
|
||||||
# Updating
|
# Updating
|
||||||
|
def init_updaters(self):
|
||||||
|
self.time_based_updaters = []
|
||||||
|
self.non_time_updaters = []
|
||||||
|
self.has_updaters = False
|
||||||
|
self.updating_suspended = False
|
||||||
|
|
||||||
def update(self, dt=0, recursive=True):
|
def update(self, dt=0, recursive=True):
|
||||||
if not self.check_for_updaters:
|
if not self.has_updaters or self.updating_suspended:
|
||||||
return self
|
return self
|
||||||
for updater in self.time_based_updaters:
|
for updater in self.time_based_updaters:
|
||||||
updater(self, dt)
|
updater(self, dt)
|
||||||
@ -260,10 +263,7 @@ class Mobject(Container):
|
|||||||
return self.time_based_updaters + self.non_time_updaters
|
return self.time_based_updaters + self.non_time_updaters
|
||||||
|
|
||||||
def get_family_updaters(self):
|
def get_family_updaters(self):
|
||||||
return list(it.chain(*[
|
return list(it.chain(*[sm.get_updaters() for sm in self.get_family()]))
|
||||||
sm.get_updaters()
|
|
||||||
for sm in self.get_family()
|
|
||||||
]))
|
|
||||||
|
|
||||||
def add_updater(self, update_function, index=None, call_updater=True):
|
def add_updater(self, update_function, index=None, call_updater=True):
|
||||||
if "dt" in get_parameters(update_function):
|
if "dt" in get_parameters(update_function):
|
||||||
@ -276,7 +276,9 @@ class Mobject(Container):
|
|||||||
else:
|
else:
|
||||||
updater_list.insert(index, update_function)
|
updater_list.insert(index, update_function)
|
||||||
|
|
||||||
self.resume_updating(call_updater=call_updater)
|
self.refresh_has_updater_status()
|
||||||
|
if call_updater:
|
||||||
|
self.update()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def remove_updater(self, update_function):
|
def remove_updater(self, update_function):
|
||||||
@ -301,14 +303,14 @@ class Mobject(Container):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def suspend_updating(self, recursive=True):
|
def suspend_updating(self, recursive=True):
|
||||||
self.check_for_updaters = False
|
self.updating_suspended = True
|
||||||
if recursive:
|
if recursive:
|
||||||
for submob in self.submobjects:
|
for submob in self.submobjects:
|
||||||
submob.suspend_updating(recursive)
|
submob.suspend_updating(recursive)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def resume_updating(self, recursive=True, call_updater=True):
|
def resume_updating(self, recursive=True, call_updater=True):
|
||||||
self.refresh_check_for_updater_status()
|
self.updating_suspended = False
|
||||||
if recursive:
|
if recursive:
|
||||||
for submob in self.submobjects:
|
for submob in self.submobjects:
|
||||||
submob.resume_updating(recursive)
|
submob.resume_updating(recursive)
|
||||||
@ -318,8 +320,8 @@ class Mobject(Container):
|
|||||||
self.update(dt=0, recursive=recursive)
|
self.update(dt=0, recursive=recursive)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def refresh_check_for_updater_status(self):
|
def refresh_has_updater_status(self):
|
||||||
self.check_for_updaters = len(self.get_family_updaters()) > 0
|
self.has_updaters = len(self.get_family_updaters()) > 0
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# Transforming operations
|
# Transforming operations
|
||||||
|
Reference in New Issue
Block a user