scale2x a surface arbitrary number of times in a row

This commit is contained in:
frank 2021-06-17 16:52:46 -04:00
parent 9838cdaac0
commit 317ea74c78
3 changed files with 22 additions and 16 deletions

View File

@ -19,8 +19,7 @@ class Delegate(GameChild):
config = self.get_configuration("event")
self.cancel_flag_key = config["cancel-flag-key"]
self.command_key = config["command-key"]
self.command_event_id = config["command-id-offset"] + \
globals()[config["user-event-id"]]
self.command_event_id = config["command-id-offset"] + globals()[config["user-event-id"]]
def disable(self):
self.enabled = False
@ -36,13 +35,10 @@ class Delegate(GameChild):
kind = evt.type
if kind in subscribers:
for subscriber in subscribers[kind]:
if not self.interpolator.is_gui_active() or \
hasattr(subscriber, "im_class") and \
(subscriber.im_class == Input or \
subscriber.im_class == \
if not self.interpolator.is_gui_active() or hasattr(subscriber, "im_class") and \
(subscriber.im_class == Input or subscriber.im_class == \
self.interpolator.gui.__class__):
self.print_debug("Passing %s to %s" % (evt,
subscriber))
self.print_debug("Passing %s to %s" % (evt, subscriber))
if not self.cancelling_propagation:
subscriber(evt)
else:
@ -79,8 +75,7 @@ class Delegate(GameChild):
if commands is not None:
if not self.command_in_list(evt, commands):
return False
return all(key in evt.dict and evt.dict[key] == value for \
key, value in attributes.items())
return all(key in evt.dict and evt.dict[key] == value for key, value in attributes.items())
def add_cancel_flag_to_attributes(self, attributes, cancel):
attributes[self.cancel_flag_key] = cancel

View File

@ -43,24 +43,27 @@ class Input(GameChild):
self.suppressed = False
def is_suppressed(self):
"""
'''
Return True if input is suppressed
"""
'''
return self.suppressed
def unsuppress_any_on_mods(self):
"""
'''
Prevent modifier keys from triggering an any key event
"""
'''
self.suppressed_any_key_on_mods = False
def suppress_any_key_on_mods(self):
"""
'''
Allow modifier keys to trigger an any key event
"""
'''
self.suppressed_any_key_on_mods = True
def subscribe_to_events(self):
'''
Tell Delegate to send keyboard, joystick and mouse buttons
'''
self.subscribe(self.translate_key, KEYDOWN)
self.subscribe(self.translate_key, KEYUP)
self.subscribe(self.translate_joy_button, JOYBUTTONDOWN)

View File

@ -557,3 +557,11 @@ def diagonal_to_rect(start, end):
sx, sy = start
ex, ey = end
return Rect(min(sx, ex), min(sy, ey), abs(sx - ex), abs(ex - ey))
def scale_2x_multiple(surface, times):
'''
Run the scale2x scale on a surface times number of times
'''
for _ in range(times):
surface = pygame.transform.scale2x(surface)
return surface