Added a copy of SGC
This commit is contained in:
parent
90ff7ceba8
commit
52eb18994d
22 changed files with 3283 additions and 0 deletions
55
sgc/widgets/fps_counter.py
Normal file
55
sgc/widgets/fps_counter.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (C) 2010-2012 Sam Bull
|
||||
|
||||
"""
|
||||
FPS counter, display current FPS performance to the user.
|
||||
|
||||
"""
|
||||
|
||||
from _locals import *
|
||||
from base_widget import Simple
|
||||
|
||||
class FPSCounter(Simple):
|
||||
|
||||
"""
|
||||
FPS counter
|
||||
|
||||
"""
|
||||
|
||||
_default_size = (80, 30)
|
||||
_settings_default = {"label": "", "clock": None}
|
||||
|
||||
def _config(self, **kwargs):
|
||||
"""
|
||||
clock: ``pygame.time.Clock`` Clock used to time the game loop.
|
||||
label: ``str`` Text to display in front of the value.
|
||||
|
||||
"""
|
||||
if "clock" in kwargs:
|
||||
self._settings["clock"] = kwargs["clock"]
|
||||
if "label" in kwargs:
|
||||
self._settings["label"] = kwargs["label"]
|
||||
|
||||
def toggle(self):
|
||||
"""Toggle the FPS counter, adding or removing this widget."""
|
||||
if self.active():
|
||||
if self._fade is not None:
|
||||
if self._fade_up:
|
||||
self.remove()
|
||||
else:
|
||||
self.add()
|
||||
else:
|
||||
self.remove()
|
||||
else:
|
||||
self.add()
|
||||
|
||||
def update(self, time):
|
||||
"""Update counter each frame."""
|
||||
text = Simple(Font["widget"].render(
|
||||
self._settings["label"] +
|
||||
str(round(self._settings["clock"].get_fps(), 1)),
|
||||
True, Font.col))
|
||||
text.rect.center = (self.rect.w/2, self.rect.h/2)
|
||||
self.image.fill(0)
|
||||
self.image.blit(text.image, text.pos)
|
Loading…
Add table
Add a link
Reference in a new issue