Skip to content

Commit

Permalink
fix game image issue in different window
Browse files Browse the repository at this point in the history
  • Loading branch information
ny committed Jun 23, 2023
1 parent 5ff1cf2 commit ca458c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 18 additions & 3 deletions ff_draw/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,24 @@ def __init__(self, main: "FFDraw"):
self.font_path = self.cfg.setdefault('font_path', r'res\PingFang.ttf')
self.font_size = self.cfg.setdefault('font_size', default_style.stlye_font_size)
self._label_counter = 0
self.game_image = game_image.GameImage(self)
self._game_image = {} # game_image.GameImage(self)
self.draw_update_call = set()
self.frame_cache = {}

self.game_hwnd = main.mem.hwnd
self.window_manager = game_window_manager.FFDWindowManager(self, self.font_size, None, self.font_path)

@property
def game_image(self) -> game_image.GameImage:
assert (current_window := self.window_manager.current_window), 'current_window is None'
if isinstance(current_window, game_window_manager.DrawWindow):
key = 0
else:
key = current_window.guid
if key not in self._game_image:
self._game_image[key] = game_image.GameImage(self)
return self._game_image[key]

def _init_everything_in_work_process(self):
if not glfw.init():
raise Exception("glfw can not be initialized")
Expand All @@ -107,7 +118,7 @@ def _init_everything_in_work_process(self):
panel_window.before_window_draw = self.panel.push_style
panel_window.after_window_draw = self.panel.pop_style
panel_window.on_want_close = self.panel.on_want_close
self.window_manager.draw_window = game_window_manager.DrawWindow(self.window_manager,self.game_hwnd)
self.window_manager.draw_window = game_window_manager.DrawWindow(self.window_manager, self.game_hwnd)
self.program = common_shader.get_common_shader()
self.models = models.Models()

Expand All @@ -117,7 +128,11 @@ def _update(self):
self._view = view.View()
self._view.projection_view, self._view.screen_size = self.main.mem.load_screen()
self.timer.update()
self.game_image.load_game_texture()
for k, i in tuple(self._game_image.items()):
if isinstance(k, int) or k in self.window_manager.windows:
i.load_game_texture()
else:
del self._game_image[k]
return self.window_manager.update()

def update(self):
Expand Down
6 changes: 6 additions & 0 deletions ff_draw/gui/game_window_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def update(self):
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glEnable(gl.GL_BLEND)

gl.glMatrixMode(gl.GL_MODELVIEW)
pv = gui.get_view().projection_view
gl.glLoadMatrixf(pv.to_list())

if gui.always_draw or win32gui.GetForegroundWindow() == self.game_hwnd:
window.set_window_cover(self.window, self.game_hwnd)
for draw_func in gui.draw_update_call.copy():
Expand Down Expand Up @@ -79,7 +83,9 @@ def __init__(self, gui: 'Drawing', *args, **kwargs):

def update(self):
if super().update():
self.current_window = self.draw_window
self.draw_window.update()
self.current_window = None
return True
else:
self.draw_window.close()
Expand Down

0 comments on commit ca458c7

Please sign in to comment.