From 317ea74c7818e7d81cb4cd23f1fac3f5c095de10 Mon Sep 17 00:00:00 2001 From: frank <420@shampoo.ooo> Date: Thu, 17 Jun 2021 16:52:46 -0400 Subject: [PATCH] scale2x a surface arbitrary number of times in a row --- pgfw/Delegate.py | 15 +++++---------- pgfw/Input.py | 15 +++++++++------ pgfw/extension.py | 8 ++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pgfw/Delegate.py b/pgfw/Delegate.py index ca516ca..7cd8216 100644 --- a/pgfw/Delegate.py +++ b/pgfw/Delegate.py @@ -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 diff --git a/pgfw/Input.py b/pgfw/Input.py index 7a446dc..0ba552f 100644 --- a/pgfw/Input.py +++ b/pgfw/Input.py @@ -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) diff --git a/pgfw/extension.py b/pgfw/extension.py index 6d5a7c9..903bcb7 100644 --- a/pgfw/extension.py +++ b/pgfw/extension.py @@ -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