changeset 518:bbb2e246d0ad

Add cursor'ish thingy thing
author Neil Muller <drnlmuller@gmail.com>
date Sun, 18 Sep 2011 00:36:43 +0200
parents 8e8ee459f23e
children 2bc856561333
files mamba/widgets/text.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/widgets/text.py	Sun Sep 18 00:32:58 2011 +0200
+++ b/mamba/widgets/text.py	Sun Sep 18 00:36:43 2011 +0200
@@ -29,6 +29,7 @@
         if not isinstance(self.color, pygame.Color):
             self.color = pygame.Color(self.color)
         self.surface = self.font.render(self.text, True, self.color)
+        self.text_rect = self.surface.get_rect()
         width, height = self.surface.get_rect().size
         self.rect.width = max(self.rect.width, width)
         self.rect.height = max(self.rect.height, height)
@@ -50,7 +51,7 @@
     def prepare(self):
         super(TextButton, self).prepare()
         text = self.surface
-        text_rect = text.get_rect()
+        text_rect = self.text_rect
         self._focussed = self.focussed
         if self.disabled:
             color = pygame.Color('#666666')
@@ -119,3 +120,12 @@
         if self._focussed != self.focussed:
             self.prepare()
         super(EntryTextWidget, self).draw(surface)
+        if self.focussed:
+            text_rect = self.text_rect
+            # Warning, 00:30 AM code on the last Saturday
+            cur_start = text_rect.move(
+                    (self.rect.left + 2, self.rect.top + 3)).topright
+            cur_end = text_rect.move(
+                    (self.rect.left + 2, self.rect.top - 3)).bottomright
+            pygame.draw.line(surface, self.focus_color,
+                    cur_start, cur_end, 2)