Browse Source

Refactor KeyLogger to use a single FontManager instance for rendering text

master
Matteo Benedetto 4 months ago
parent
commit
9bc6f161d2
  1. 8
      key.py

8
key.py

@ -13,6 +13,7 @@ class KeyLogger:
self.window.show() self.window.show()
self.running = True self.running = True
self.key_down = True self.key_down = True
self.font = sdl2.ext.FontManager("assets/decterm.ttf", size=24)
def run(self): def run(self):
# Main loop # Main loop
@ -34,10 +35,11 @@ class KeyLogger:
# Update the window # Update the window
sdl2.ext.fill(self.window.get_surface(), sdl2.ext.Color(0, 0, 0)) sdl2.ext.fill(self.window.get_surface(), sdl2.ext.Color(0, 0, 0))
greeting = self.font.render("Press any key...", color=sdl2.ext.Color(255, 255, 255))
sdl2.SDL_BlitSurface(greeting, None, self.window.get_surface(), None)
if hasattr(self, 'message'): if hasattr(self, 'message'):
font = sdl2.ext.FontManager("assets/decterm.ttf", size=24) text_surface = self.font.render(self.message, color=sdl2.ext.Color(255, 255, 255))
text_surface = font.render(self.message, color=sdl2.ext.Color(255, 255, 255)) sdl2.SDL_BlitSurface(text_surface, None, self.window.get_surface(), sdl2.SDL_Rect(0, 30, 640, 480))
sdl2.SDL_BlitSurface(text_surface, None, self.window.get_surface(), None)
sdl2.SDL_UpdateWindowSurface(self.window.window) sdl2.SDL_UpdateWindowSurface(self.window.window)
# Refresh the window # Refresh the window

Loading…
Cancel
Save