Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/api/Label.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/Label.py')
-rwxr-xr-xsrc/api/Label.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/api/Label.py b/src/api/Label.py
new file mode 100755
index 0000000..c762868
--- /dev/null
+++ b/src/api/Label.py
@@ -0,0 +1,32 @@
+import pygame
+
+class CLabel(pygame.sprite.Sprite):
+ """ a basic label
+ properties:
+ font: font to use
+ text: text to display
+ fgColor: foreground color
+ bgColor: background color
+ center: position of label's center
+ size: (width, height) of label
+ """
+
+ def __init__(self, fontName = "freesansbold.ttf"):
+ pygame.sprite.Sprite.__init__(self)
+ self.font = pygame.font.Font(fontName, 20)
+ self.text = "Button"
+ self.fgColor = ((0x00, 0x00, 0x00))
+ self.bgColor = ((0xFF, 0xFF, 0xFF))
+ self.center = (400, 100)
+ self.size = (150, 30)
+
+ def update(self):
+ self.image = pygame.Surface(self.size)
+ self.image.fill(self.bgColor)
+ fontSurface = self.font.render(self.text, True, self.fgColor, self.bgColor)
+ #center the text
+ xPos = (self.image.get_width() - fontSurface.get_width())/2
+
+ self.image.blit(fontSurface, (xPos, 0))
+ self.rect = self.image.get_rect()
+ self.rect.center = self.center \ No newline at end of file