From a41c84e7ce02b14a94534a1893cb6d8b3c71b5a5 Mon Sep 17 00:00:00 2001 From: Ireneusz Imiolek Date: Tue, 17 Nov 2020 19:38:02 +0000 Subject: [PATCH] The way window is resized was changed as it was reloading the screen every frame whilst resizing which proved problematic on some systems. --- classes/config.py | 2 +- classes/cversion.py | 2 +- eduactiv8.py | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/classes/config.py b/classes/config.py index 479239d..523d3ca 100644 --- a/classes/config.py +++ b/classes/config.py @@ -22,7 +22,7 @@ def __init__(self, android): self.fs_height = 768 self.debug_screen_size = None # [900,600] # size_limits - don't let window resizing get out of hand [min_w, min_h, max_w, max_h] - self.size_limits = [838, 570, 2000, 2000] + self.size_limits = [838, 570, 4000, 2000] # [670,480,2000,2000] #800 - minimum to fit all buttons, 2000 - with over 2000 pixels each way pygame is not redrawing very well # set total size of OS panels and window decorations on both sides - used in windowed version. Not so much important now with resizing enabled. # this will not be auto-detected diff --git a/classes/cversion.py b/classes/cversion.py index 04b28ed..d5138f9 100644 --- a/classes/cversion.py +++ b/classes/cversion.py @@ -1 +1 @@ -ver = "4.20.08" \ No newline at end of file +ver = "4.20.11" \ No newline at end of file diff --git a/eduactiv8.py b/eduactiv8.py index d58ce7f..7220ab0 100755 --- a/eduactiv8.py +++ b/eduactiv8.py @@ -441,11 +441,17 @@ def run(self): icon = pygame.image.load(os.path.join('res', 'icon', 'ico256.png')) pygame.display.set_icon(icon) + new_size = self.size[:] + resizing = False + frames_since_resize = 0 + # -------- Main Program Loop ----------- # wait = False while self.done is False: # uncomment the following line to test all activities across multiple languages as specified in the stresstest.py # stresstest.step(self) + + resizing_this_frame = False if android is not None: if android.check_pause(): wait = True @@ -498,13 +504,20 @@ def run(self): for event in pygame.event.get(): if event.type == pygame.QUIT or ( event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): - self.dialog.show_dialog(0, self.lang.d["Do you want to exit the game?"]) + self.done = True + self.done4good = True + # don't show dialog if closing with window manager or ESC + # self.dialog.show_dialog(0, self.lang.d["Do you want to exit the game?"]) elif event.type == pygame.VIDEORESIZE: if not self.config.fullscreen: - self.on_resize(list(event.size), info) + new_size = list(event.size) + resizing = True + resizing_this_frame = True elif event.type == pygame.KEYDOWN and event.key == pygame.K_f and ( event.mod & pygame.KMOD_LCTRL): - self.fullscreen_toggle(info) + # eduActiv8 crashes in fullscreen mode in pygame 2 so temporarily not available + if pygame.version.vernum[0] < 2: + self.fullscreen_toggle(info) elif event.type == pygame.KEYDOWN and event.key == pygame.K_F5: # refresh - reload level self.game_board.level.load_level() elif event.type == pygame.KEYDOWN and event.key == pygame.K_F8: @@ -577,9 +590,19 @@ def run(self): else: # let the game handle other events self.game_board.handle(event) + if resizing: + # changed the window resizing behaviour: + # only resize contents 15 frames after the user stopped resizing + if not resizing_this_frame: + frames_since_resize += 1 + if frames_since_resize > 15: + self.on_resize(new_size, info) + resizing = False + frames_since_resize = 0 + else: + frames_since_resize = 0 # checking if any of the subsurfaces need updating and updating them if needed - if self.redraw_needed[1]: info.draw(self.info_bar) self.redraw_needed[1] = False