Mercurial > pyntnclick
annotate pyntnclick/widgets/text.py @ 792:bdaffaa8b6bf pyntnclick
Loading and saving! (Plus a bunch of other stuff to make it possible.)
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 27 Jan 2013 12:43:28 +0200 |
parents | efa58c92b304 |
children | bcc9277a23e6 |
rev | line source |
---|---|
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
1 from textwrap import wrap |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
2 |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
3 import pygame |
559
b7d8b89de71a
Rip out keyboard handling
Stefano Rivera <stefano@rivera.za.net>
parents:
558
diff
changeset
|
4 from pygame.constants import SRCALPHA |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
5 |
670
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
6 from pyntnclick.widgets.base import Widget, Button, convert_color |
638
d1ec9e739e23
Make TextWidget work (probably)
Stefano Rivera <stefano@rivera.za.net>
parents:
602
diff
changeset
|
7 |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
8 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
9 class TextWidget(Widget): |
644 | 10 def __init__(self, rect, gd, text, fontname=None, fontsize=None, |
11 color=None): | |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
638
diff
changeset
|
12 super(TextWidget, self).__init__(rect, gd) |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
13 self.text = text |
644 | 14 constants = self.gd.constants |
670
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
15 self.fontname = fontname or constants.font |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
16 self.fontsize = fontsize or constants.font_size |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
17 self.color = color or constants.text_color |
792
bdaffaa8b6bf
Loading and saving! (Plus a bunch of other stuff to make it possible.)
Jeremy Thurgood <firxen@gmail.com>
parents:
726
diff
changeset
|
18 self.visible = True |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
19 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
20 def prepare(self): |
641
dae56fc7b902
Remove a hacked resorce from TextWidget
Stefano Rivera <stefano@rivera.za.net>
parents:
639
diff
changeset
|
21 self.font = self.resource.get_font(self.fontname, self.fontsize) |
670
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
22 self.color = convert_color(self.color) |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
23 self.surface = self.font.render(self.text, True, self.color) |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
24 self.text_rect = self.surface.get_rect() |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
25 width, height = self.surface.get_rect().size |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
26 self.rect.width = max(self.rect.width, width) |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
27 self.rect.height = max(self.rect.height, height) |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
28 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
29 def draw(self, surface): |
792
bdaffaa8b6bf
Loading and saving! (Plus a bunch of other stuff to make it possible.)
Jeremy Thurgood <firxen@gmail.com>
parents:
726
diff
changeset
|
30 if self.visible: |
bdaffaa8b6bf
Loading and saving! (Plus a bunch of other stuff to make it possible.)
Jeremy Thurgood <firxen@gmail.com>
parents:
726
diff
changeset
|
31 self.do_prepare() |
bdaffaa8b6bf
Loading and saving! (Plus a bunch of other stuff to make it possible.)
Jeremy Thurgood <firxen@gmail.com>
parents:
726
diff
changeset
|
32 surface.blit(self.surface, self.rect) |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
33 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
34 |
644 | 35 class LabelWidget(TextWidget): |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
36 def __init__(self, rect, gd, *args, **kwargs): |
644 | 37 constants = gd.constants |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
38 self.padding = kwargs.pop('padding', constants.label_padding) |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
39 self.border = kwargs.pop('border', constants.label_border) |
670
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
40 self.bg_color = convert_color( |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
41 kwargs.pop('bg_color', constants.label_bg_color)) |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
42 self.border_color = convert_color( |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
43 kwargs.pop('border_color', constants.label_border_color)) |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
44 super(LabelWidget, self).__init__(rect, gd, *args, **kwargs) |
644 | 45 |
46 def prepare(self): | |
47 super(LabelWidget, self).prepare() | |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
48 self.rect.width += 2 * self.padding |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
49 self.rect.height += 2 * self.padding |
644 | 50 new_surface = pygame.Surface(self.rect.size) |
51 new_surface = new_surface.convert_alpha() | |
52 new_surface.fill(self.bg_color) | |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
53 new_surface.blit(self.surface, self.surface.get_rect().move( |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
54 (self.padding, self.padding))) |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
55 if self.border: |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
56 pygame.draw.rect(new_surface, self.border_color, |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
57 new_surface.get_rect(), |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
58 self.border) |
644 | 59 self.surface = new_surface |
60 | |
61 def draw(self, surface): | |
726
efa58c92b304
Move prepare out of __init__ and into everywhere else
Neil Muller <neil@dip.sun.ac.za>
parents:
693
diff
changeset
|
62 self.do_prepare() |
644 | 63 surface.blit(self.surface, self.rect) |
64 | |
65 | |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
66 class TextButton(Button, TextWidget): |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
67 def __init__(self, rect, gd, *args, **kwargs): |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
68 constants = gd.constants |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
69 self.padding = kwargs.pop('padding', constants.label_padding) |
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
70 self.border = kwargs.pop('border', constants.label_border) |
670
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
71 |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
72 kwargs['color'] = convert_color( |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
73 kwargs.pop('color', constants.button_color)) |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
74 self.disabled_color = convert_color( |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
75 kwargs.pop('disabled_color', constants.button_disabled_color)) |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
76 self.bg_color = convert_color( |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
77 kwargs.pop('bg_color', constants.button_bg_color)) |
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
78 |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
79 super(TextButton, self).__init__(rect, gd, *args, **kwargs) |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
80 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
81 def prepare(self): |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
82 super(TextButton, self).prepare() |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
83 text = self.surface |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
84 text_rect = self.text_rect |
666
de3f6ad0da9d
Better looking labels, and more use of constants
Stefano Rivera <stefano@rivera.za.net>
parents:
665
diff
changeset
|
85 color = self.disabled_color if self.disabled else self.color |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
86 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
87 width = text_rect.width + self.padding * 2 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
88 height = text_rect.height + self.padding * 2 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
89 self.rect.width = max(self.rect.width, width) |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
90 self.rect.height = max(self.rect.height, height) |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
91 self.surface = pygame.Surface(self.rect.size, SRCALPHA) |
670
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
92 self.surface.fill(self.bg_color) |
665 | 93 offset = ( |
94 (self.rect.width - width) / 2 + self.padding, | |
95 (self.rect.height - height) / 2 + self.padding) | |
96 self.surface.blit(text, text.get_rect().move(offset)) | |
670
fe7023750b20
Add convert_color function
Stefano Rivera <stefano@rivera.za.net>
parents:
666
diff
changeset
|
97 |
665 | 98 if self.border: |
99 pygame.draw.rect(self.surface, color, self.surface.get_rect(), | |
100 self.border) | |
555
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
101 |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
102 def draw(self, surface): |
c0474fe18b96
Copy in widgets from mamba (currently unused)
Stefano Rivera <stefano@rivera.za.net>
parents:
diff
changeset
|
103 super(TextButton, self).draw(surface) |
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
104 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
105 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
106 class WrappedTextLabel(LabelWidget): |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
107 """A Label Widget that wraps the text to a given maximum width""" |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
108 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
109 def __init__(self, rect, gd, *args, **kwargs): |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
110 self.max_width = kwargs.pop('max_width', gd.constants.screen[0] - 50) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
111 self._wrap_width = None |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
112 self._text_lines = None |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
113 super(WrappedTextLabel, self).__init__(rect, gd, *args, **kwargs) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
114 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
115 def prepare(self): |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
116 if self._wrap_width is None: |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
117 # Start without wrapping |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
118 self._wrap_width = len(self.text) + 1 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
119 self._text_lines = [self.text] |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
120 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
121 self.font = self.resource.get_font(self.fontname, self.fontsize) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
122 self.color = convert_color(self.color) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
123 self._render() |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
124 self.text_rect = self.surface.get_rect() |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
125 width, height = self.surface.get_rect().size |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
126 while width > self.max_width: |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
127 # Very simplistic approach |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
128 self._wrap_width = self._wrap_width / 2 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
129 self._text_lines = wrap(self.text, self._wrap_width) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
130 self._render() |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
131 width, height = self.surface.get_rect().size |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
132 self.rect.width = max(self.rect.width, width) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
133 self.rect.height = max(self.rect.height, height) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
134 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
135 if self.border: |
688
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
136 pygame.draw.rect(self.surface, self.border_color, |
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
137 self.surface.get_rect(), |
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
138 self.border) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
139 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
140 def _render(self): |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
141 surfaces = [] |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
142 width = 0 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
143 height = 0 |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
144 for line in self._text_lines: |
688
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
145 line_surf = self.font.render(line, True, self.color) |
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
146 surfaces.append(line_surf) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
147 width = max(line_surf.get_rect().width, width) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
148 height += line_surf.get_rect().height |
688
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
149 |
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
150 width += 2 * self.padding |
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
151 height += 2 * self.padding |
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
152 |
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
153 self.surface = pygame.Surface((width, height)) |
688
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
154 self.surface = self.surface.convert_alpha() |
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
155 self.surface.fill(self.bg_color) |
688
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
156 height = self.padding |
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
157 for line_surf in surfaces: |
688
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
158 rect = pygame.Rect((self.padding, height), |
6892d36dad75
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
Stefano Rivera <stefano@rivera.za.net>
parents:
679
diff
changeset
|
159 (line_surf.get_rect().size)) |
679
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
160 self.surface.blit(line_surf, rect) |
fa168b5e2624
The return of the message dialog (and there was much rejoicing)
Neil Muller <neil@dip.sun.ac.za>
parents:
670
diff
changeset
|
161 height += line_surf.get_rect().height |