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

View File

@ -43,24 +43,27 @@ class Input(GameChild):
self.suppressed = False self.suppressed = False
def is_suppressed(self): def is_suppressed(self):
""" '''
Return True if input is suppressed Return True if input is suppressed
""" '''
return self.suppressed return self.suppressed
def unsuppress_any_on_mods(self): def unsuppress_any_on_mods(self):
""" '''
Prevent modifier keys from triggering an any key event Prevent modifier keys from triggering an any key event
""" '''
self.suppressed_any_key_on_mods = False self.suppressed_any_key_on_mods = False
def suppress_any_key_on_mods(self): def suppress_any_key_on_mods(self):
""" '''
Allow modifier keys to trigger an any key event Allow modifier keys to trigger an any key event
""" '''
self.suppressed_any_key_on_mods = True self.suppressed_any_key_on_mods = True
def subscribe_to_events(self): 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, KEYDOWN)
self.subscribe(self.translate_key, KEYUP) self.subscribe(self.translate_key, KEYUP)
self.subscribe(self.translate_joy_button, JOYBUTTONDOWN) self.subscribe(self.translate_joy_button, JOYBUTTONDOWN)

View File

@ -557,3 +557,11 @@ def diagonal_to_rect(start, end):
sx, sy = start sx, sy = start
ex, ey = end ex, ey = end
return Rect(min(sx, ex), min(sy, ey), abs(sx - ex), abs(ex - ey)) 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