From: mar77i Date: Thu, 26 Dec 2024 19:36:15 +0000 (+0100) Subject: move FPSMixin to ui.py X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=e59748cf1c70e59ba1838b73f7c21a2af8d06ae4;p=zenbook_conf move FPSMixin to ui.py --- diff --git a/ui.py b/ui.py index 0f0a9d5..6a3715d 100644 --- a/ui.py +++ b/ui.py @@ -61,6 +61,30 @@ class UIParent: self.clock.tick(60) +class FPSMixin: + FPS_COLOR = "yellow" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.current_fps = None + + def update(self): + super().update() + new_fps = int(self.clock.get_fps()) + if self.current_fps != new_fps: + self.current_fps = new_fps + self.dirty = True + + def draw(self): + super().draw() + surf_size = self.surf.get_size() + fs = self.font.render(f"{int(self.current_fps)} FPS", True, self.FPS_COLOR) + fs_size = fs.get_size() + self.surf.blit( + fs, (surf_size[0] - fs_size[0] - 7, surf_size[1] - fs_size[1] - 7) + ) + + class UIChild: def __init__(self, parent): self.parent = parent diff --git a/zenbook_conf.py b/zenbook_conf.py index 8460cd0..56a262b 100755 --- a/zenbook_conf.py +++ b/zenbook_conf.py @@ -5,7 +5,7 @@ from functools import partial import pygame from bluetooth import BluetoothConf -from ui import Button, Icon, IconButton, Switch, UIParent +from ui import Button, FPSMixin, Icon, IconButton, Switch, UIParent from vector_assets import ( bluetooth, laptop_double, @@ -18,30 +18,6 @@ from xinput import XinputConf from xrandr import XrandrConf -class FPSMixin: - FPS_COLOR = "yellow" - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.current_fps = None - - def update(self): - super().update() - new_fps = int(self.clock.get_fps()) - if self.current_fps != new_fps: - self.current_fps = new_fps - self.dirty = True - - def draw(self): - super().draw() - surf_size = self.surf.get_size() - fs = self.font.render(f"{int(self.current_fps)} FPS", True, self.FPS_COLOR) - fs_size = fs.get_size() - self.surf.blit( - fs, (surf_size[0] - fs_size[0] - 7, surf_size[1] - fs_size[1] - 7) - ) - - class ZenbookConf(FPSMixin, UIParent): BACKGROUND_COLOR = 0x333333