Refactor KeyLogger to use a single FontManager instance for rendering text
This commit is contained in:
@@ -13,6 +13,7 @@ class KeyLogger:
|
||||
self.window.show()
|
||||
self.running = True
|
||||
self.key_down = True
|
||||
self.font = sdl2.ext.FontManager("assets/decterm.ttf", size=24)
|
||||
|
||||
def run(self):
|
||||
# Main loop
|
||||
@@ -34,10 +35,11 @@ class KeyLogger:
|
||||
|
||||
# Update the window
|
||||
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'):
|
||||
font = sdl2.ext.FontManager("assets/decterm.ttf", size=24)
|
||||
text_surface = font.render(self.message, color=sdl2.ext.Color(255, 255, 255))
|
||||
sdl2.SDL_BlitSurface(text_surface, None, self.window.get_surface(), None)
|
||||
text_surface = self.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_UpdateWindowSurface(self.window.window)
|
||||
# Refresh the window
|
||||
|
||||
|
||||
Reference in New Issue
Block a user