Merge lp:~codeforger/simplegc/simplegc into lp:simplegc
- simplegc
- Merge into trunk
Proposed by
Sam Bull
Status: | Merged |
---|---|
Merged at revision: | 274 |
Proposed branch: | lp:~codeforger/simplegc/simplegc |
Merge into: | lp:simplegc |
Diff against target: |
996 lines (+713/-62) 9 files modified
example/test_lists.py (+68/-0) sgc/__init__.py (+6/-0) sgc/widgets/base_widget.py (+3/-0) sgc/widgets/button.py (+13/-16) sgc/widgets/composite/dialogs.py (+98/-0) sgc/widgets/lists.py (+383/-0) sgc/widgets/menu.py (+19/-12) sgc/widgets/opengl.py (+121/-32) sgc/widgets/radio_button.py (+2/-2) |
To merge this branch: | bzr merge lp:~codeforger/simplegc/simplegc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sam Bull | Needs Fixing | ||
Review via email: mp+115960@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Sam Bull (dreamsorcerer) wrote : | # |
My mistake, conflicts are with newer trunk. Resolve the conflicts, and also revert helloworld.py (this is for one of the tutorials, put you example code into test.py), _locals.py, base_widget.py, menu.py, radio_button.py.
Revision history for this message
Michael Rochester (codeforger) wrote : | # |
This merge also contains the new button style I invented, would you like me to revert that too?
lp:~codeforger/simplegc/simplegc
updated
- 273. By Michael Rochester
-
merge
- 274. By Michael Rochester
-
merge
- 275. By Michael Rochester
-
moved test code to test.py
- 276. By Michael Rochester
-
reverted /example/
helloworld. py - 277. By Michael Rochester
-
fixed my idiocy with test.py
- 278. By Michael Rochester
-
removed matrix.py as requested
Revision history for this message
Sam Bull (dreamsorcerer) wrote : | # |
> This merge also contains the new button style I invented, would you like me to
> revert that too?
Yes please.
lp:~codeforger/simplegc/simplegc
updated
- 279. By Michael Rochester
-
reverted button.py to the old buttons style
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'example/test_lists.py' | |||
2 | --- example/test_lists.py 1970-01-01 00:00:00 +0000 | |||
3 | +++ example/test_lists.py 2012-07-21 12:53:18 +0000 | |||
4 | @@ -0,0 +1,68 @@ | |||
5 | 1 | import sgc | ||
6 | 2 | from sgc.locals import * | ||
7 | 3 | |||
8 | 4 | import pygame | ||
9 | 5 | from pygame.locals import * | ||
10 | 6 | |||
11 | 7 | pygame.display.init() | ||
12 | 8 | pygame.font.init() | ||
13 | 9 | |||
14 | 10 | screen = sgc.surface.Screen((640,480)) | ||
15 | 11 | |||
16 | 12 | clock = pygame.time.Clock() | ||
17 | 13 | |||
18 | 14 | lst = sgc._List(width=(100),pos=(10,10),multi_selection=True,content=("hello","world","nice","to","meet","you")) | ||
19 | 15 | lst.add(0) | ||
20 | 16 | |||
21 | 17 | mullst = sgc._MultiList(pos=(10,150),columnwidth=(150,150),content=(["hello","world"],["nice","to"],["meet","you"])) | ||
22 | 18 | mullst.add(0) | ||
23 | 19 | |||
24 | 20 | listb = sgc.ListBox((100,100),pos=(150,10),multi_selection=True,content=("hello","world","nice","to","meet","you")) | ||
25 | 21 | listb.add(0) | ||
26 | 22 | |||
27 | 23 | list2 = sgc.ListBox((100,100),pos=(300,10),header="head",content=("hello","world","nice","to","meet","you")) | ||
28 | 24 | list2.add(0) | ||
29 | 25 | |||
30 | 26 | data = (["Hello","12Mb","30/06/2012"], | ||
31 | 27 | ["World","15Mb","30/06/2012"], | ||
32 | 28 | ["Nice","123Kb","19/06/2012"], | ||
33 | 29 | ["To","1.2Gb","29/06/2012"], | ||
34 | 30 | ["Meet","12Mb","25/06/2012"], | ||
35 | 31 | ["You","6Mb","30/06/2012"]) | ||
36 | 32 | |||
37 | 33 | |||
38 | 34 | mullist = sgc.MultiListBox((200,100), pos=(370,150), columnwidth=(150,50,100), content=data) | ||
39 | 35 | mullist.add(0) | ||
40 | 36 | |||
41 | 37 | head = ("Name","Size","Modified") | ||
42 | 38 | |||
43 | 39 | mullist2 = sgc.MultiListBox((100,100), pos=(100,300), multi_selection=True, header=head, columnwidth=(150,150,150), content=data) | ||
44 | 40 | mullist2.add(0) | ||
45 | 41 | |||
46 | 42 | def print_attr(): | ||
47 | 43 | x = mullist2.selected_text | ||
48 | 44 | print x | ||
49 | 45 | |||
50 | 46 | def print_pos(): | ||
51 | 47 | x = mullist2.selected_pos | ||
52 | 48 | print x | ||
53 | 49 | |||
54 | 50 | btn = sgc.Button(pos=(300,400), label="get attr") | ||
55 | 51 | btn.on_click = print_attr | ||
56 | 52 | btn.add(0) | ||
57 | 53 | |||
58 | 54 | btn2 = sgc.Button(pos=(300,300), label="get pos") | ||
59 | 55 | btn2.on_click = print_pos | ||
60 | 56 | btn2.add(0) | ||
61 | 57 | |||
62 | 58 | while True: | ||
63 | 59 | time = clock.tick(30) | ||
64 | 60 | |||
65 | 61 | for event in pygame.event.get(): | ||
66 | 62 | sgc.event(event) | ||
67 | 63 | if event.type == QUIT: | ||
68 | 64 | exit() | ||
69 | 65 | |||
70 | 66 | screen.fill((200,200,200)) | ||
71 | 67 | sgc.update(time) | ||
72 | 68 | pygame.display.flip() | ||
73 | 0 | 69 | ||
74 | === modified file 'sgc/__init__.py' | |||
75 | --- sgc/__init__.py 2012-07-19 13:33:13 +0000 | |||
76 | +++ sgc/__init__.py 2012-07-21 12:53:18 +0000 | |||
77 | @@ -21,12 +21,18 @@ | |||
78 | 21 | from widgets.boxes import VBox, HBox | 21 | from widgets.boxes import VBox, HBox |
79 | 22 | from widgets.button import Button | 22 | from widgets.button import Button |
80 | 23 | from widgets.container import Container | 23 | from widgets.container import Container |
81 | 24 | from widgets.composite.dialogs import DialogSaveQuit | ||
82 | 24 | from widgets.dialog import Dialog | 25 | from widgets.dialog import Dialog |
83 | 25 | from widgets.fps_counter import FPSCounter | 26 | from widgets.fps_counter import FPSCounter |
84 | 26 | from widgets.input_box import InputBox | 27 | from widgets.input_box import InputBox |
85 | 27 | from widgets.label import Label | 28 | from widgets.label import Label |
86 | 29 | from widgets.lists import MultiListBox | ||
87 | 30 | from widgets.lists import ListBox | ||
88 | 31 | from widgets.lists import _List | ||
89 | 32 | from widgets.lists import _MultiList | ||
90 | 28 | from widgets.menu import Menu | 33 | from widgets.menu import Menu |
91 | 29 | from widgets.radio_button import Radio | 34 | from widgets.radio_button import Radio |
92 | 30 | from widgets.scroll_box import ScrollBox | 35 | from widgets.scroll_box import ScrollBox |
93 | 31 | from widgets.settings import Keys | 36 | from widgets.settings import Keys |
94 | 32 | from widgets.switch import Switch | 37 | from widgets.switch import Switch |
95 | 38 | |||
96 | 33 | 39 | ||
97 | === modified file 'sgc/widgets/base_widget.py' | |||
98 | --- sgc/widgets/base_widget.py 2012-07-18 09:38:26 +0000 | |||
99 | +++ sgc/widgets/base_widget.py 2012-07-21 12:53:18 +0000 | |||
100 | @@ -237,6 +237,9 @@ | |||
101 | 237 | return surf | 237 | return surf |
102 | 238 | elif isinstance(surf, str): | 238 | elif isinstance(surf, str): |
103 | 239 | return pygame.image.load(surf).convert_alpha() | 239 | return pygame.image.load(surf).convert_alpha() |
104 | 240 | elif isinstance(surf, opengl.OpenGLImage): | ||
105 | 241 | self._custom_image = True | ||
106 | 242 | return surf | ||
107 | 240 | 243 | ||
108 | 241 | # Create base images | 244 | # Create base images |
109 | 242 | self._custom_image = False | 245 | self._custom_image = False |
110 | 243 | 246 | ||
111 | === modified file 'sgc/widgets/button.py' | |||
112 | --- sgc/widgets/button.py 2012-06-16 11:01:51 +0000 | |||
113 | +++ sgc/widgets/button.py 2012-07-21 12:53:18 +0000 | |||
114 | @@ -58,16 +58,15 @@ | |||
115 | 58 | # Clear previous renderings | 58 | # Clear previous renderings |
116 | 59 | del self._settings["label"][1:] | 59 | del self._settings["label"][1:] |
117 | 60 | label = self._settings["label"][0].split("\n") | 60 | label = self._settings["label"][0].split("\n") |
118 | 61 | f = Font["widget"] | ||
119 | 62 | h = f.get_ascent() | ||
120 | 63 | for count, line in enumerate(label): | 61 | for count, line in enumerate(label): |
122 | 64 | lbl = Simple(f.render(line, True, self._settings["label_col"])) | 62 | lbl = Simple(Font["widget"].render(line, True, |
123 | 63 | self._settings["label_col"])) | ||
124 | 65 | self._settings["label"].append(lbl) | 64 | self._settings["label"].append(lbl) |
127 | 66 | y = (self.rect.h - (h * len(label)) + f.get_descent()) / 2 + \ | 65 | y = (self.rect.h - (lbl.rect.h * len(label))) / 2 + \ |
128 | 67 | (h * count) | 66 | (lbl.rect.h * count) |
129 | 68 | lbl.rect.midtop = (self.rect.w/2, y) | 67 | lbl.rect.midtop = (self.rect.w/2, y) |
130 | 69 | 68 | ||
132 | 70 | def _draw_base(self, draw): | 69 | def _draw(self, draw): |
133 | 71 | # Frames around edge of button | 70 | # Frames around edge of button |
134 | 72 | x = min(self.image.get_size()) / 8 | 71 | x = min(self.image.get_size()) / 8 |
135 | 73 | self._frame_lt = ((0,0), (self.rect.w,0), (self.rect.w-x,x), | 72 | self._frame_lt = ((0,0), (self.rect.w,0), (self.rect.w-x,x), |
136 | @@ -81,18 +80,16 @@ | |||
137 | 81 | cols["over"] = [min(c*1.1, 255) for c in self._settings["col"]] | 80 | cols["over"] = [min(c*1.1, 255) for c in self._settings["col"]] |
138 | 82 | cols["down"] = [c*0.8 for c in self._settings["col"]] | 81 | cols["down"] = [c*0.8 for c in self._settings["col"]] |
139 | 83 | for img in cols: | 82 | for img in cols: |
149 | 84 | self._images[img].fill(cols[img]) | 83 | if not self._custom_image: |
150 | 85 | # Draw a frame around the edges of the button | 84 | self._images[img].fill(cols[img]) |
151 | 86 | frame_lt_c = [min(c*1.3,255) for c in cols[img]] | 85 | # Draw a frame around the edges of the button |
152 | 87 | frame_rb_c = [c*0.8 for c in cols[img]] | 86 | frame_lt_c = [min(c*1.3,255) for c in cols[img]] |
153 | 88 | draw.polygon(self._images[img], frame_lt_c, self._frame_lt) | 87 | frame_rb_c = [c*0.8 for c in cols[img]] |
154 | 89 | draw.polygon(self._images[img], frame_rb_c, self._frame_rb) | 88 | draw.polygon(self._images[img], frame_lt_c, self._frame_lt) |
155 | 90 | 89 | draw.polygon(self._images[img], frame_rb_c, self._frame_rb) | |
147 | 91 | def _draw_final(self, draw): | ||
148 | 92 | for img in self._images.values(): | ||
156 | 93 | # Blit label onto button | 90 | # Blit label onto button |
157 | 94 | for line in self._settings["label"][1:]: | 91 | for line in self._settings["label"][1:]: |
159 | 95 | img.blit(line.image, line.pos) | 92 | self._images[img].blit(line.image, line.pos) |
160 | 96 | self._draw_button() | 93 | self._draw_button() |
161 | 97 | 94 | ||
162 | 98 | def on_click(self): | 95 | def on_click(self): |
163 | 99 | 96 | ||
164 | === added directory 'sgc/widgets/composite' | |||
165 | === added file 'sgc/widgets/composite/__init__.py' | |||
166 | === added file 'sgc/widgets/composite/dialogs.py' | |||
167 | --- sgc/widgets/composite/dialogs.py 1970-01-01 00:00:00 +0000 | |||
168 | +++ sgc/widgets/composite/dialogs.py 2012-07-21 12:53:18 +0000 | |||
169 | @@ -0,0 +1,98 @@ | |||
170 | 1 | #!/usr/bin/env python | ||
171 | 2 | |||
172 | 3 | # Copyright (C) 2012 Michael Rochester | ||
173 | 4 | |||
174 | 5 | """ | ||
175 | 6 | Dialog composite widgets. A list of predefined common dialogs | ||
176 | 7 | |||
177 | 8 | """ | ||
178 | 9 | import sgc | ||
179 | 10 | from sgc.locals import * | ||
180 | 11 | |||
181 | 12 | from ..dialog import * | ||
182 | 13 | |||
183 | 14 | class DialogSaveQuit (Dialog): | ||
184 | 15 | """ | ||
185 | 16 | This dialog is designed to be called when a user tries to quit without saving. | ||
186 | 17 | It will emmit 2 GUI events: 'quit' and 'save'. | ||
187 | 18 | If the final option 'cancel' is selected, the dialog will remove its self. | ||
188 | 19 | """ | ||
189 | 20 | def _config(self, **kwargs): | ||
190 | 21 | """ | ||
191 | 22 | doctitle: ``str`` The text that will be used as the documents Title. | ||
192 | 23 | """ | ||
193 | 24 | if "init" in kwargs: | ||
194 | 25 | self.lbl = sgc.Label(pos=(10,10),text="The document has not been saved.\nWould you like to save the changes before quitting?", col=(20,20,20)) | ||
195 | 26 | self.btn_save = sgc.Button(pos=(200,100), label="Save") | ||
196 | 27 | self.btn_save.on_click = self.send_save | ||
197 | 28 | self.btn_quit = sgc.Button((200,50), pos=(0,100), label="Close without saving") | ||
198 | 29 | self.btn_quit.on_click = self.send_quit | ||
199 | 30 | self.btn_cancel = sgc.Button(pos=(310,100), label="Cancel") | ||
200 | 31 | self.btn_cancel.on_click = self.send_cancel | ||
201 | 32 | contain = sgc.Container(pos=(0,0), widgets=[self.lbl,self.btn_quit,self.btn_cancel,self.btn_save] ) | ||
202 | 33 | |||
203 | 34 | kwargs["widget"] = contain; | ||
204 | 35 | kwargs["title"]="Save changes?" | ||
205 | 36 | sgc.Dialog._config(self,**kwargs) | ||
206 | 37 | if "doctitle" in kwargs: | ||
207 | 38 | self.lbl.text = "The document \"" + kwargs["doctitle"] + "\" has not been saved.\nWould you like to save the changes before quitting?" | ||
208 | 39 | def send_quit(self): | ||
209 | 40 | ev = pygame.event.Event(GUI, {"gui_type": "quit", | ||
210 | 41 | "widget_type": self.__class__, | ||
211 | 42 | "widget":self}) | ||
212 | 43 | pygame.event.post(ev) | ||
213 | 44 | |||
214 | 45 | def send_save(self): | ||
215 | 46 | ev = pygame.event.Event(GUI, {"gui_type": "save", | ||
216 | 47 | "widget_type": self.__class__, | ||
217 | 48 | "widget":self}) | ||
218 | 49 | pygame.event.post(ev) | ||
219 | 50 | def send_cancel(self): | ||
220 | 51 | ev = pygame.event.Event(GUI, {"gui_type": "cancel", | ||
221 | 52 | "widget_type": self.__class__, | ||
222 | 53 | "widget":self}) | ||
223 | 54 | pygame.event.post(ev) | ||
224 | 55 | |||
225 | 56 | class DialogSave (Dialog): | ||
226 | 57 | """ | ||
227 | 58 | This dialog is designed to be called when a user tries to quit without saving. | ||
228 | 59 | It will emmit 2 GUI events: 'quit' and 'save'. | ||
229 | 60 | If the final option 'cancel' is selected, the dialog will remove its self. | ||
230 | 61 | """ | ||
231 | 62 | def _config(self, **kwargs): | ||
232 | 63 | """ | ||
233 | 64 | doctitle: ``str`` The text that will be used as the documents Title. | ||
234 | 65 | """ | ||
235 | 66 | if "init" in kwargs: | ||
236 | 67 | self.lbl = sgc.Label(pos=(10,10),text="The document has not been saved.\nWould you like to save the changes before quitting?", col=(20,20,20)) | ||
237 | 68 | self.btn_save = sgc.Button(pos=(200,100), label="Save") | ||
238 | 69 | self.btn_save.on_click = self.send_save | ||
239 | 70 | self.btn_quit = sgc.Button((200,50), pos=(0,100), label="Close without saving") | ||
240 | 71 | self.btn_quit.on_click = self.send_quit | ||
241 | 72 | self.btn_cancel = sgc.Button(pos=(310,100), label="Cancel") | ||
242 | 73 | self.btn_cancel.on_click = self.send_cancel | ||
243 | 74 | contain = sgc.Container(pos=(0,0), widgets=[self.lbl,self.btn_quit,self.btn_cancel,self.btn_save] ) | ||
244 | 75 | |||
245 | 76 | kwargs["widget"] = contain; | ||
246 | 77 | kwargs["title"]="Save changes?" | ||
247 | 78 | sgc.Dialog._config(self,**kwargs) | ||
248 | 79 | if "doctitle" in kwargs: | ||
249 | 80 | self.lbl.text = "The document \"" + kwargs["doctitle"] + "\" has not been saved.\nWould you like to save the changes before quitting?" | ||
250 | 81 | def send_quit(self): | ||
251 | 82 | ev = pygame.event.Event(GUI, {"gui_type": "quit", | ||
252 | 83 | "widget_type": self.__class__, | ||
253 | 84 | "widget":self}) | ||
254 | 85 | pygame.event.post(ev) | ||
255 | 86 | |||
256 | 87 | def send_save(self): | ||
257 | 88 | ev = pygame.event.Event(GUI, {"gui_type": "save", | ||
258 | 89 | "widget_type": self.__class__, | ||
259 | 90 | "widget":self}) | ||
260 | 91 | pygame.event.post(ev) | ||
261 | 92 | def send_cancel(self): | ||
262 | 93 | ev = pygame.event.Event(GUI, {"gui_type": "cancel", | ||
263 | 94 | "widget_type": self.__class__, | ||
264 | 95 | "widget":self}) | ||
265 | 96 | pygame.event.post(ev) | ||
266 | 97 | |||
267 | 98 | |||
268 | 0 | 99 | ||
269 | === added file 'sgc/widgets/lists.py' | |||
270 | --- sgc/widgets/lists.py 1970-01-01 00:00:00 +0000 | |||
271 | +++ sgc/widgets/lists.py 2012-07-21 12:53:18 +0000 | |||
272 | @@ -0,0 +1,383 @@ | |||
273 | 1 | #!/usr/bin/env python | ||
274 | 2 | |||
275 | 3 | # Copyright (C) 2012 Michael Rochester | ||
276 | 4 | |||
277 | 5 | import sgc | ||
278 | 6 | from sgc.locals import * | ||
279 | 7 | |||
280 | 8 | import pygame.mouse | ||
281 | 9 | from pygame.locals import * | ||
282 | 10 | |||
283 | 11 | from _locals import * | ||
284 | 12 | from base_widget import Simple | ||
285 | 13 | |||
286 | 14 | class _List(Simple): | ||
287 | 15 | |||
288 | 16 | _can_focus = True | ||
289 | 17 | _settings_default = {"col": (118, 45, 215), | ||
290 | 18 | "font": Font["widget"], | ||
291 | 19 | "padding": 3,"offset": 0,"width":None, | ||
292 | 20 | "mult": False} | ||
293 | 21 | |||
294 | 22 | |||
295 | 23 | def _config(self,**kwargs): | ||
296 | 24 | self.anchor = False | ||
297 | 25 | if "multi_selection" in kwargs: | ||
298 | 26 | self._settings["mult"] = kwargs["multi_selection"] | ||
299 | 27 | if "padding" in kwargs: | ||
300 | 28 | self._settings["padding"] = kwargs["padding"] | ||
301 | 29 | if "init" in kwargs: | ||
302 | 30 | self.color = (118, 45, 215) | ||
303 | 31 | self.contain = sgc.Container(border=self._settings["padding"]) | ||
304 | 32 | self.lbls=[] | ||
305 | 33 | self.selected=[] | ||
306 | 34 | if "col" in kwargs: | ||
307 | 35 | self.color = kwargs["col"] | ||
308 | 36 | if "font" in kwargs: | ||
309 | 37 | self._settings["font"] = kwargs["font"] | ||
310 | 38 | if "width" in kwargs: | ||
311 | 39 | self._settings["width"] = kwargs["width"] | ||
312 | 40 | if "content" in kwargs: | ||
313 | 41 | self.content = kwargs["content"] | ||
314 | 42 | self.texth = self._settings["font"].get_ascent()+\ | ||
315 | 43 | self._settings["font"].get_descent()+\ | ||
316 | 44 | (self._settings["padding"]*2) | ||
317 | 45 | p=0 | ||
318 | 46 | for string in kwargs["content"]: | ||
319 | 47 | lbl = sgc.Label(pos=(0,p),col=(10,10,10),text=string, | ||
320 | 48 | font=self._settings["font"]) | ||
321 | 49 | p+=self.texth | ||
322 | 50 | self.lbls.append(lbl) | ||
323 | 51 | self.contain.config(widgets=self.lbls) | ||
324 | 52 | if not hasattr(self, "image"): | ||
325 | 53 | self._create_base_images((self.contain.image.get_width() if | ||
326 | 54 | self._settings["width"] == None else self._settings["width"] | ||
327 | 55 | ,self.contain.image.get_height())) | ||
328 | 56 | |||
329 | 57 | def _event(self, event): | ||
330 | 58 | if event.type == MOUSEBUTTONDOWN and event.button == 1: | ||
331 | 59 | sel = self.colide_item(event.pos) | ||
332 | 60 | if sel > 0 and sel < len(self.content)+1: | ||
333 | 61 | if (pygame.key.get_mods() & KMOD_CTRL and self._settings["mult"]): | ||
334 | 62 | |||
335 | 63 | if sel in self.selected: | ||
336 | 64 | self.selected.remove(sel) | ||
337 | 65 | else: | ||
338 | 66 | self.selected.append(sel) | ||
339 | 67 | elif (pygame.key.get_mods() & KMOD_SHIFT | ||
340 | 68 | and self._settings["mult"] and self.anchor): | ||
341 | 69 | self.selected=[] | ||
342 | 70 | for new in range(abs(self.anchor-sel)+1): | ||
343 | 71 | self.selected.append(new+(min(self.anchor,sel))) | ||
344 | 72 | else: | ||
345 | 73 | self.anchor = sel | ||
346 | 74 | self.selected = [sel] | ||
347 | 75 | |||
348 | 76 | def update(self, time): | ||
349 | 77 | draw = self.get_draw() | ||
350 | 78 | |||
351 | 79 | self.contain.update(time) | ||
352 | 80 | self.image.fill((255,255,255)) | ||
353 | 81 | |||
354 | 82 | for sel in self.selected: | ||
355 | 83 | w = (self.image.get_width()) | ||
356 | 84 | selection = Simple((w, self.texth)) | ||
357 | 85 | selection.pos = (0,(sel-1)*self.texth+self._settings["padding"]) | ||
358 | 86 | selection.image.fill(self.color) | ||
359 | 87 | selection.image.set_alpha(100) | ||
360 | 88 | self.image.blit(selection.image, selection.pos) | ||
361 | 89 | self.image.blit(self.contain.image,(0,0)) | ||
362 | 90 | self.image.blit(self._images["image"],(0,0)) | ||
363 | 91 | |||
364 | 92 | def colide_item(self,pos): | ||
365 | 93 | pos = pos[1]-self.rect_abs.y | ||
366 | 94 | return ((pos-self._settings["padding"])/self.texth)+1 | ||
367 | 95 | |||
368 | 96 | def _focus_enter(self, focus): | ||
369 | 97 | self.color = self._settings["col"] | ||
370 | 98 | |||
371 | 99 | def _focus_exit(self): | ||
372 | 100 | self.color = (179,179,179) | ||
373 | 101 | |||
374 | 102 | @property | ||
375 | 103 | def selected_text(self): | ||
376 | 104 | return [self.content[x-1] for x in self.selected] | ||
377 | 105 | |||
378 | 106 | @property | ||
379 | 107 | def selected_pos(self): | ||
380 | 108 | return [x-1 for x in self.selected] | ||
381 | 109 | |||
382 | 110 | class ListBox(Simple): | ||
383 | 111 | |||
384 | 112 | _can_focus = True | ||
385 | 113 | _default_size = (100,100) | ||
386 | 114 | _settings_default = {"headfont": Font["widget"], | ||
387 | 115 | "offset": 0} | ||
388 | 116 | |||
389 | 117 | def _config(self,**kwargs): | ||
390 | 118 | if "header" in kwargs: | ||
391 | 119 | self._settings["header"] = kwargs["header"] | ||
392 | 120 | self._settings["offset"] = self._settings["headfont"].get_ascent()+\ | ||
393 | 121 | self._settings["headfont"].get_descent()+6 | ||
394 | 122 | if "init" in kwargs: | ||
395 | 123 | self.list = _List(width=self.image.get_width()) | ||
396 | 124 | self.scroll = sgc.ScrollBox((self.rect.w,self.rect.h-self._settings["offset"]),pos=(0,self._settings["offset"]),widget=self.list) | ||
397 | 125 | self.scroll._parent = self | ||
398 | 126 | self.list.config(**kwargs) | ||
399 | 127 | self.scroll.config(widget=self.list,**kwargs) | ||
400 | 128 | |||
401 | 129 | def _draw(self,draw): | ||
402 | 130 | if "header" in self._settings: | ||
403 | 131 | lbl = sgc.Label(pos=(0,0),col=(10,10,10), | ||
404 | 132 | text=self._settings["header"], | ||
405 | 133 | font=self._settings["headfont"]) | ||
406 | 134 | self._images["image"].blit(lbl.image,(3,1)) | ||
407 | 135 | draw.line(self._images["image"],(150,150,150), | ||
408 | 136 | (1,self._settings["offset"]), | ||
409 | 137 | (self.image.get_width()-2,self._settings["offset"])) | ||
410 | 138 | |||
411 | 139 | draw.line(self._images["image"],(150,150,150), | ||
412 | 140 | (1,0),(self.image.get_width()-2,0)) | ||
413 | 141 | draw.line(self._images["image"],(150,150,150), | ||
414 | 142 | (1,self.image.get_height()-1), | ||
415 | 143 | (self.image.get_width()-2,self.image.get_height()-1)) | ||
416 | 144 | draw.line(self._images["image"],(150,150,150), | ||
417 | 145 | (0,1),(0,self.image.get_height()-2)) | ||
418 | 146 | draw.line(self._images["image"],(150,150,150), | ||
419 | 147 | (self.image.get_width()-1,1), | ||
420 | 148 | (self.image.get_width()-1,self.image.get_height()-2)) | ||
421 | 149 | |||
422 | 150 | def _event(self, event): | ||
423 | 151 | self.scroll._event(event) | ||
424 | 152 | |||
425 | 153 | def update(self, time): | ||
426 | 154 | self.scroll.update(time) | ||
427 | 155 | self.image.fill((255,255,255)) | ||
428 | 156 | self.image.blit(self.scroll.image,(0,self._settings["offset"])) | ||
429 | 157 | self.image.blit(self._images["image"],(0,0)) | ||
430 | 158 | |||
431 | 159 | def _focus_enter(self, focus): | ||
432 | 160 | self.scroll._focus_enter(focus) | ||
433 | 161 | |||
434 | 162 | def _focus_exit(self): | ||
435 | 163 | self.scroll._focus_exit() | ||
436 | 164 | |||
437 | 165 | @property | ||
438 | 166 | def selected_text(self): | ||
439 | 167 | return [x for x in self.list.selected_text] | ||
440 | 168 | |||
441 | 169 | @property | ||
442 | 170 | def selected_pos(self): | ||
443 | 171 | return [x for x in self.list.selected] | ||
444 | 172 | |||
445 | 173 | |||
446 | 174 | class _MultiList(_List): | ||
447 | 175 | |||
448 | 176 | _can_focus = True | ||
449 | 177 | _settings_default = {"col": (118, 45, 215), | ||
450 | 178 | "font": Font["widget"], | ||
451 | 179 | "padding": 3,"offset": 0, | ||
452 | 180 | "mult": False,"colwid":False} | ||
453 | 181 | |||
454 | 182 | |||
455 | 183 | def _config(self,**kwargs): | ||
456 | 184 | self.anchor = False | ||
457 | 185 | if "multi_selection" in kwargs: | ||
458 | 186 | self._settings["mult"] = kwargs["multi_selection"] | ||
459 | 187 | if "padding" in kwargs: | ||
460 | 188 | self._settings["padding"] = kwargs["padding"] | ||
461 | 189 | if "init" in kwargs: | ||
462 | 190 | self.color = (118, 45, 215) | ||
463 | 191 | self.lbls=[] | ||
464 | 192 | self.selected=[] | ||
465 | 193 | if "col" in kwargs: | ||
466 | 194 | self.color = kwargs["col"] | ||
467 | 195 | if "font" in kwargs: | ||
468 | 196 | self._settings["font"] = kwargs["font"] | ||
469 | 197 | if "columnwidth" in kwargs: | ||
470 | 198 | self._settings["colwid"] = kwargs["columnwidth"] | ||
471 | 199 | if "content" in kwargs: | ||
472 | 200 | |||
473 | 201 | self.columns = [] | ||
474 | 202 | self.content = kwargs["content"] | ||
475 | 203 | self.texth = self._settings["font"].get_ascent()+\ | ||
476 | 204 | self._settings["font"].get_descent()+\ | ||
477 | 205 | (self._settings["padding"]*2) | ||
478 | 206 | w = [] | ||
479 | 207 | for x in range(len(kwargs["content"][0])): | ||
480 | 208 | labels = [] | ||
481 | 209 | p=0 | ||
482 | 210 | for y in range(len(kwargs["content"])): | ||
483 | 211 | lbl = sgc.Label(pos=(0,p),col=(10,10,10),text=kwargs["content"][y][x], | ||
484 | 212 | font=self._settings["font"]) | ||
485 | 213 | p+=self.texth | ||
486 | 214 | labels.append(lbl) | ||
487 | 215 | w.append(lbl) | ||
488 | 216 | self.lbls.append(labels) | ||
489 | 217 | if self._settings["colwid"]: | ||
490 | 218 | column = sgc.Container((self._settings["colwid"][x],len(kwargs["content"])*self.texth),widgets=labels) | ||
491 | 219 | else: | ||
492 | 220 | column = sgc.Container(widgets=labels) | ||
493 | 221 | self.columns.append(column) | ||
494 | 222 | |||
495 | 223 | self.contain = sgc.HBox(border=self._settings["padding"],widgets=self.columns) | ||
496 | 224 | self.rect.w = self.contain.rect.w | ||
497 | 225 | self.rect.h = self.contain.rect.h | ||
498 | 226 | if not hasattr(self, "image"): | ||
499 | 227 | self._create_base_images((self.contain.image.get_width() | ||
500 | 228 | ,self.contain.image.get_height())) | ||
501 | 229 | |||
502 | 230 | @property | ||
503 | 231 | def selected_text(self): | ||
504 | 232 | return [self.content[x-1] for x in self.selected] | ||
505 | 233 | |||
506 | 234 | @property | ||
507 | 235 | def selected_pos(self): | ||
508 | 236 | return [x-1 for x in self.selected] | ||
509 | 237 | |||
510 | 238 | class MultiListBox(ListBox): | ||
511 | 239 | |||
512 | 240 | _can_focus = True | ||
513 | 241 | _default_size = (100,100) | ||
514 | 242 | _settings_default = {"headfont": Font["widget"], | ||
515 | 243 | "offset": 0,"colwid": 100,"header":None} | ||
516 | 244 | |||
517 | 245 | |||
518 | 246 | def _config(self,**kwargs): | ||
519 | 247 | if "content" in kwargs: | ||
520 | 248 | self.content = kwargs["content"] | ||
521 | 249 | if "columnwidth" in kwargs: | ||
522 | 250 | self.colpos=[0] | ||
523 | 251 | self._settings["colwid"] = [c for c in kwargs["columnwidth"]] | ||
524 | 252 | for x in range(len(kwargs["columnwidth"])): | ||
525 | 253 | self.colpos.append((self.colpos[x]+self._settings["colwid"][x])) | ||
526 | 254 | if "header" in kwargs: | ||
527 | 255 | self._settings["header"] = kwargs["header"] | ||
528 | 256 | self._settings["offset"] = self._settings["headfont"].get_ascent()+\ | ||
529 | 257 | self._settings["headfont"].get_descent()+6 | ||
530 | 258 | |||
531 | 259 | |||
532 | 260 | if "init" in kwargs: | ||
533 | 261 | strings = pygame.cursors.sizer_x_strings | ||
534 | 262 | cursor = pygame.cursors.compile(strings) | ||
535 | 263 | size = (len(strings[0]), len(strings)) | ||
536 | 264 | hotspot = (size[0]/2, size[1]/2) | ||
537 | 265 | self._cursor = (size, hotspot) + cursor | ||
538 | 266 | self._cursor_set = False | ||
539 | 267 | |||
540 | 268 | self.move = False | ||
541 | 269 | self.mouse = False | ||
542 | 270 | self.resize = False | ||
543 | 271 | self.list = _MultiList() | ||
544 | 272 | self.scroll = sgc.ScrollBox((self.rect.w,self.rect.h-self._settings["offset"]),pos=(0,self._settings["offset"]),widget=self.list) | ||
545 | 273 | self.scroll._parent = self | ||
546 | 274 | if self._settings["colwid"] != 100: | ||
547 | 275 | kwargs["columnwidth"] = self._settings["colwid"] | ||
548 | 276 | if "content" not in kwargs: | ||
549 | 277 | kwargs["content"]=self.content | ||
550 | 278 | self.list.config(**kwargs) | ||
551 | 279 | if "init" in kwargs: | ||
552 | 280 | self.scroll.config(widget=self.list,**kwargs) | ||
553 | 281 | |||
554 | 282 | def _draw(self,draw): | ||
555 | 283 | |||
556 | 284 | if self._settings["header"]: | ||
557 | 285 | self.header = sgc.Simple((self.colpos[-1]+10,self._settings["offset"])) | ||
558 | 286 | for p, header in enumerate(self._settings["header"]): | ||
559 | 287 | lbl = sgc.Label((self._settings["colwid"][p],self._settings["offset"]),pos=(0,0), | ||
560 | 288 | text=header, | ||
561 | 289 | col=(10,10,10), | ||
562 | 290 | |||
563 | 291 | font=self._settings["headfont"]) | ||
564 | 292 | draw.rect(self.header.image,(255,255,255),((self.colpos[p],0),(self.colpos[p]+self._settings["colwid"][p],self._settings["offset"])),0) | ||
565 | 293 | self.header.image.blit(lbl.image,(self.colpos[p]+6*p+3,1)) | ||
566 | 294 | draw.line(self.header.image,(150,150,150), | ||
567 | 295 | (self.colpos[p]+6*(p),0), | ||
568 | 296 | (self.colpos[p]+6*(p),self._settings["offset"])) | ||
569 | 297 | |||
570 | 298 | |||
571 | 299 | draw.line(self._images["image"],(150,150,150), | ||
572 | 300 | (1,0),(self.image.get_width()-2,0)) | ||
573 | 301 | draw.line(self._images["image"],(150,150,150), | ||
574 | 302 | (1,self.image.get_height()-1), | ||
575 | 303 | (self.image.get_width()-2,self.image.get_height()-1)) | ||
576 | 304 | draw.line(self._images["image"],(150,150,150), | ||
577 | 305 | (0,1),(0,self.image.get_height()-2)) | ||
578 | 306 | draw.line(self._images["image"],(150,150,150), | ||
579 | 307 | (self.image.get_width()-1,1), | ||
580 | 308 | (self.image.get_width()-1,self.image.get_height()-2)) | ||
581 | 309 | self.image.fill((255,0,0)) | ||
582 | 310 | |||
583 | 311 | def _event(self, event): | ||
584 | 312 | if (event.type == MOUSEBUTTONDOWN and event.button == 1 | ||
585 | 313 | and (self.collidehead(event.pos)is not False)): | ||
586 | 314 | self.move = self.collidehead(event.pos) | ||
587 | 315 | self.mouse = event.pos[0] | ||
588 | 316 | elif event.type == MOUSEBUTTONUP: | ||
589 | 317 | if self.resize is not False and self.mouse is not False: | ||
590 | 318 | self.scroll = sgc.ScrollBox((self.rect.w,self.rect.h-self._settings["offset"]),pos=(0,self._settings["offset"]),widget=self.list) | ||
591 | 319 | self.scroll._parent = self | ||
592 | 320 | self.mouse = False | ||
593 | 321 | self.resize = False | ||
594 | 322 | elif event.type == MOUSEMOTION: | ||
595 | 323 | if self.collidehead(event.pos) is False and self._cursor_set==True: | ||
596 | 324 | self._remove_cursor() | ||
597 | 325 | self._cursor_set = False | ||
598 | 326 | elif self.collidehead(event.pos) is not False and self._cursor_set==False: | ||
599 | 327 | self._set_cursor(*self._cursor) | ||
600 | 328 | self._cursor_set = True | ||
601 | 329 | if self.resize is not False and self.mouse is not False: | ||
602 | 330 | dif = event.pos[0] - self.mouse | ||
603 | 331 | self.mouse = event.pos[0] | ||
604 | 332 | self._settings["colwid"][self.move]+=dif | ||
605 | 333 | if self._settings["colwid"][self.move] < 0: | ||
606 | 334 | self._settings["colwid"][self.move] = 0 | ||
607 | 335 | self.config(columnwidth=self._settings["colwid"], content=self.content) | ||
608 | 336 | self.list._create_base_images((self.list.rect.w, self.list.rect.h)) | ||
609 | 337 | elif self.mouse is not False: | ||
610 | 338 | if abs(event.pos[0] - self.mouse) > 4: | ||
611 | 339 | self.resize = True | ||
612 | 340 | self.scroll._event(event) | ||
613 | 341 | |||
614 | 342 | def collidehead(self,pos): | ||
615 | 343 | for p, x in enumerate(self.colpos[1:],1): | ||
616 | 344 | if (pos[0]-self.pos_abs[0]>=self.scroll._settings["widget"].pos[0]+x+6*p-2 and | ||
617 | 345 | pos[0]-self.pos_abs[0]<=self.scroll._settings["widget"].pos[0]+x+6*p+2 and | ||
618 | 346 | pos[1] < self.pos_abs[1]+self._settings["offset"] and | ||
619 | 347 | pos[1] > self.pos_abs[1]): | ||
620 | 348 | return p-1 | ||
621 | 349 | return False | ||
622 | 350 | |||
623 | 351 | def update(self, time): | ||
624 | 352 | self.scroll.update(time) | ||
625 | 353 | self.image.fill((255,255,255)) | ||
626 | 354 | self.image.blit(self.scroll.image,(0,self._settings["offset"])) | ||
627 | 355 | if self._settings["header"]: | ||
628 | 356 | self.image.blit(self.header.image,(self.scroll._settings["widget"].pos[0],0)) #MAYBE A HACK, PROBABLY | ||
629 | 357 | self.image.blit(self._images["image"],(0,0)) | ||
630 | 358 | |||
631 | 359 | def _focus_enter(self, focus): | ||
632 | 360 | self.scroll._focus_enter(focus) | ||
633 | 361 | |||
634 | 362 | def _focus_exit(self): | ||
635 | 363 | self.scroll._focus_exit() | ||
636 | 364 | |||
637 | 365 | @property | ||
638 | 366 | def selected_text(self): | ||
639 | 367 | return [x for x in self.list.selected_text] | ||
640 | 368 | |||
641 | 369 | @property | ||
642 | 370 | def selected_pos(self): | ||
643 | 371 | return [x for x in self.list.selected] | ||
644 | 372 | |||
645 | 373 | |||
646 | 374 | |||
647 | 375 | |||
648 | 376 | |||
649 | 377 | |||
650 | 378 | |||
651 | 379 | |||
652 | 380 | |||
653 | 381 | |||
654 | 382 | |||
655 | 383 | |||
656 | 0 | 384 | ||
657 | === modified file 'sgc/widgets/menu.py' | |||
658 | --- sgc/widgets/menu.py 2012-07-18 11:56:10 +0000 | |||
659 | +++ sgc/widgets/menu.py 2012-07-21 12:53:18 +0000 | |||
660 | @@ -120,18 +120,24 @@ | |||
661 | 120 | widgets.append(div) | 120 | widgets.append(div) |
662 | 121 | # Widget | 121 | # Widget |
663 | 122 | elif item[0].startswith("w:"): | 122 | elif item[0].startswith("w:"): |
676 | 123 | args = item[1] | 123 | args = self._get_args(item[1:]) |
677 | 124 | name = args.pop("name", None) | 124 | name = args.pop("name") |
678 | 125 | try: | 125 | f = args.pop("func") if ("func" in args) else None |
679 | 126 | # Try to load existing widget | 126 | if item[0].endswith("input_box"): |
680 | 127 | widget = eval(item[0][2:]) | 127 | widget = input_box.InputBox(**args) |
681 | 128 | except NameError: | 128 | elif item[0].endswith("button"): |
682 | 129 | # Try to import custom widget | 129 | if "surf" in args: |
683 | 130 | parts = item[0][2:].rpartition(".") | 130 | args["surf"] = eval(args["surf"]) |
684 | 131 | mod = __import__(parts[0]) | 131 | widget = button.Button(**args) |
685 | 132 | widget = getattr(mod, parts[2]) | 132 | elif item[0].endswith("radio"): |
686 | 133 | widget = widget(**args) | 133 | if "surf" in args: |
687 | 134 | if name: self._dict[name] = widget | 134 | args["surf"] = eval(args["surf"]) |
688 | 135 | widget = radio_button.Radio(**args) | ||
689 | 136 | elif item[0].endswith("label"): | ||
690 | 137 | widget = label.Label(**args) | ||
691 | 138 | self._dict[name] = widget | ||
692 | 139 | if f: widget.on_click = self._funcs[f] | ||
693 | 140 | widget.name = name | ||
694 | 135 | widgets.append(widget) | 141 | widgets.append(widget) |
695 | 136 | # Function | 142 | # Function |
696 | 137 | elif item[0].startswith("f:"): | 143 | elif item[0].startswith("f:"): |
697 | @@ -176,6 +182,7 @@ | |||
698 | 176 | def update(self, time): | 182 | def update(self, time): |
699 | 177 | menu = self._menus[self._curr_menu] | 183 | menu = self._menus[self._curr_menu] |
700 | 178 | menu.update(time) | 184 | menu.update(time) |
701 | 185 | self.image.fill(0) # Hack for OpenGL | ||
702 | 179 | if self._old_menu is not None: | 186 | if self._old_menu is not None: |
703 | 180 | self.image.blit(self._menus[self._old_menu].image, (0,0)) | 187 | self.image.blit(self._menus[self._old_menu].image, (0,0)) |
704 | 181 | menu.image.set_alpha(menu._fade) | 188 | menu.image.set_alpha(menu._fade) |
705 | 182 | 189 | ||
706 | === modified file 'sgc/widgets/opengl.py' | |||
707 | --- sgc/widgets/opengl.py 2011-09-22 09:41:10 +0000 | |||
708 | +++ sgc/widgets/opengl.py 2012-07-21 12:53:18 +0000 | |||
709 | @@ -1,9 +1,9 @@ | |||
710 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
711 | 2 | 2 | ||
713 | 3 | # Copyright (C) 2011 Sam Bull | 3 | # Copyright (C) 2011-2012 Sam Bull |
714 | 4 | 4 | ||
715 | 5 | """ | 5 | """ |
717 | 6 | Base widget, all widgets inherit from this. | 6 | OpenGL functions. |
718 | 7 | 7 | ||
719 | 8 | """ | 8 | """ |
720 | 9 | 9 | ||
721 | @@ -11,10 +11,11 @@ | |||
722 | 11 | from OpenGL.GL import * | 11 | from OpenGL.GL import * |
723 | 12 | import FTGL | 12 | import FTGL |
724 | 13 | 13 | ||
729 | 14 | from ..surface import SurfaceBase | 14 | from _locals import * |
730 | 15 | 15 | from matrix import Matrix | |
731 | 16 | 16 | ||
732 | 17 | class OpenGLImage(SurfaceBase): | 17 | |
733 | 18 | class OpenGLImage(): | ||
734 | 18 | """ | 19 | """ |
735 | 19 | Class used to emulate the interface of Surface for OpenGL drawing. | 20 | Class used to emulate the interface of Surface for OpenGL drawing. |
736 | 20 | 21 | ||
737 | @@ -28,39 +29,49 @@ | |||
738 | 28 | self._lock = False | 29 | self._lock = False |
739 | 29 | self.display_list = [] | 30 | self.display_list = [] |
740 | 30 | self._children = [] | 31 | self._children = [] |
745 | 31 | if parent: | 32 | self.matrix = Matrix() |
746 | 32 | self._parent = parent # Parent surface used for _abs | 33 | self._parent = parent # Parent surface used for _abs |
743 | 33 | else: | ||
744 | 34 | self._parent = self._default_screen | ||
747 | 35 | 34 | ||
749 | 36 | self._rect = Rect((0,0), (0,0)) | 35 | self.rect = Rect((0,0), (0,0)) |
750 | 37 | if isinstance(surf, (tuple,list)): | 36 | if isinstance(surf, (tuple,list)): |
752 | 38 | self._rect.size = surf | 37 | self.rect.size = surf |
753 | 39 | elif isinstance(surf, OpenGLFont): | 38 | elif isinstance(surf, OpenGLFont): |
755 | 40 | self._rect.size = (surf.size) | 39 | self.rect.size = (surf.size) |
756 | 41 | self.display_list.extend(surf.display_list) | 40 | self.display_list.extend(surf.display_list) |
757 | 42 | elif isinstance(surf, OpenGLImage): | 41 | elif isinstance(surf, OpenGLImage): |
759 | 43 | self._rect = surf._rect | 42 | self.matrix = surf.matrix.copy() |
760 | 43 | self.rect = Rect(surf.rect) | ||
761 | 44 | self._a = surf._a | 44 | self._a = surf._a |
764 | 45 | self.display_list = surf.display_list | 45 | self.display_list = surf.display_list[:] |
765 | 46 | self._children = surf._children | 46 | for child in surf._children: |
766 | 47 | self.blit(child.copy()) | ||
767 | 47 | 48 | ||
769 | 48 | def blit(self, surf, pos=None): | 49 | def blit(self, surf, pos=None, area=None): |
770 | 49 | assert isinstance(surf, OpenGLImage) | 50 | assert isinstance(surf, OpenGLImage) |
771 | 50 | if surf not in self._children: | 51 | if surf not in self._children: |
772 | 51 | if pos is not None: surf.pos = pos | 52 | if pos is not None: surf.pos = pos |
773 | 53 | surf.rect.topleft = surf.pos | ||
774 | 52 | surf._parent = self | 54 | surf._parent = self |
775 | 53 | self._children.append(surf) | 55 | self._children.append(surf) |
776 | 54 | 56 | ||
777 | 55 | def draw(self): | 57 | def draw(self): |
778 | 56 | glLoadIdentity() | 58 | glLoadIdentity() |
781 | 57 | if self.rect.w <= self._parent.rect.w and \ | 59 | if self._parent: |
782 | 58 | self.rect.h <= self._parent.rect.h: | 60 | r = self._parent.rect |
783 | 61 | else: | ||
784 | 62 | r = Rect(0,0,10000,10000) | ||
785 | 63 | if self.rect.w <= r.w and self.rect.h <= r.h: | ||
786 | 59 | # Mask the area, so nothing is drawn outside surface area. | 64 | # Mask the area, so nothing is drawn outside surface area. |
788 | 60 | bottom = self._default_screen.h - self.rect_abs.bottom | 65 | bottom = 480 - self.rect_abs.bottom # Screen height... |
789 | 61 | glScissor(self.rect_abs.x, bottom, | 66 | glScissor(self.rect_abs.x, bottom, |
790 | 62 | self.rect.w+1, self.rect.h+1) | 67 | self.rect.w+1, self.rect.h+1) |
791 | 63 | glTranslatef(self.pos_abs[0], self.pos_abs[1], 0) | 68 | glTranslatef(self.pos_abs[0], self.pos_abs[1], 0) |
792 | 69 | if not isinstance(self.matrix, (list, tuple)): | ||
793 | 70 | glMultMatrixf(self.matrix.to_opengl()) | ||
794 | 71 | else: | ||
795 | 72 | for m in self.matrix: | ||
796 | 73 | glMultMatrixf(m.to_opengl()) | ||
797 | 74 | |||
798 | 64 | for dl,col in self.display_list: | 75 | for dl,col in self.display_list: |
799 | 65 | if col is not None: glColor(col[0], col[1], col[2], self.a) | 76 | if col is not None: glColor(col[0], col[1], col[2], self.a) |
800 | 66 | glCallList(dl) | 77 | glCallList(dl) |
801 | @@ -73,7 +84,7 @@ | |||
802 | 73 | # Clear the surface | 84 | # Clear the surface |
803 | 74 | self.display_list = [] | 85 | self.display_list = [] |
804 | 75 | self._children = [] | 86 | self._children = [] |
806 | 76 | rect = Rect((0,0), self.size) | 87 | rect = Rect((0,0), self.rect.size) |
807 | 77 | if col != 0: | 88 | if col != 0: |
808 | 78 | col = [c/255. for c in col] | 89 | col = [c/255. for c in col] |
809 | 79 | dl = glGenLists(1) | 90 | dl = glGenLists(1) |
810 | @@ -86,7 +97,13 @@ | |||
811 | 86 | return OpenGLImage(self) | 97 | return OpenGLImage(self) |
812 | 87 | 98 | ||
813 | 88 | def get_size(self): | 99 | def get_size(self): |
815 | 89 | return self.size | 100 | return self.rect.size |
816 | 101 | |||
817 | 102 | def get_height(self): | ||
818 | 103 | return self.rect.h | ||
819 | 104 | |||
820 | 105 | def get_width(self): | ||
821 | 106 | return self.rect.w | ||
822 | 90 | 107 | ||
823 | 91 | def set_alpha(self, alpha): | 108 | def set_alpha(self, alpha): |
824 | 92 | self._a = alpha/255. | 109 | self._a = alpha/255. |
825 | @@ -127,7 +144,7 @@ | |||
826 | 127 | self._lock = False | 144 | self._lock = False |
827 | 128 | 145 | ||
828 | 129 | def replace(self, surf, **kwargs): | 146 | def replace(self, surf, **kwargs): |
830 | 130 | self._rect.size = surf.size | 147 | self.rect.size = surf.size |
831 | 131 | self.display_list = surf.display_list[:] | 148 | self.display_list = surf.display_list[:] |
832 | 132 | self._children = surf._children[:] | 149 | self._children = surf._children[:] |
833 | 133 | 150 | ||
834 | @@ -136,7 +153,33 @@ | |||
835 | 136 | if self._a is not None: | 153 | if self._a is not None: |
836 | 137 | return self._a | 154 | return self._a |
837 | 138 | else: | 155 | else: |
839 | 139 | return self._parent.a | 156 | if self._parent: |
840 | 157 | return self._parent.a | ||
841 | 158 | else: | ||
842 | 159 | return 1 | ||
843 | 160 | |||
844 | 161 | @property | ||
845 | 162 | def rect_abs(self): | ||
846 | 163 | if self._parent is None: | ||
847 | 164 | return self.rect | ||
848 | 165 | else: | ||
849 | 166 | p_abs = self._parent.pos_abs | ||
850 | 167 | p = (self.rect.x + p_abs[0], self.rect.y + p_abs[1]) | ||
851 | 168 | return Rect(p, self.rect.size) | ||
852 | 169 | |||
853 | 170 | @property | ||
854 | 171 | def pos(self): | ||
855 | 172 | return self.rect.topleft | ||
856 | 173 | @pos.setter | ||
857 | 174 | def pos(self, value): | ||
858 | 175 | self.rect.topleft = value | ||
859 | 176 | @property | ||
860 | 177 | def pos_abs(self): | ||
861 | 178 | if self._parent is None: | ||
862 | 179 | return self.rect.topleft | ||
863 | 180 | else: | ||
864 | 181 | p_abs = self._parent.pos_abs | ||
865 | 182 | return (self.rect.x + p_abs[0], self.rect.y + p_abs[1]) | ||
866 | 140 | 183 | ||
867 | 141 | # --- Dummy methods. Ignore. --- | 184 | # --- Dummy methods. Ignore. --- |
868 | 142 | 185 | ||
869 | @@ -152,17 +195,27 @@ | |||
870 | 152 | to an OpenGLImage object in the same manner as pygame.Font. | 195 | to an OpenGLImage object in the same manner as pygame.Font. |
871 | 153 | 196 | ||
872 | 154 | """ | 197 | """ |
874 | 155 | def __init__(self, font, size): | 198 | def __init__(self, font, size=16): |
875 | 199 | self.rect = Rect(0,0,0,0) | ||
876 | 156 | self._children = [] | 200 | self._children = [] |
880 | 157 | self.font = FTGL.TextureFont(font) | 201 | self.matrix = Matrix() |
881 | 158 | self.font.FaceSize(16) | 202 | self.display_list = [] |
882 | 159 | self.y_offset = self.font.line_height * .75 | 203 | if isinstance(font, OpenGLFont): |
883 | 204 | self.font = font.font | ||
884 | 205 | self.y_offset = font.y_offset | ||
885 | 206 | self.size = font.size | ||
886 | 207 | else: | ||
887 | 208 | self.font = FTGL.TextureFont(font) # BufferFont | ||
888 | 209 | self.font.FaceSize(size) | ||
889 | 210 | self.y_offset = self.font.line_height * .75 | ||
890 | 160 | 211 | ||
891 | 161 | def render(self, text, antialias, color, background=None): | 212 | def render(self, text, antialias, color, background=None): |
892 | 213 | temp = OpenGLImage((self.font.Advance(text.encode()), self.font.line_height)) | ||
893 | 162 | text = text.encode() | 214 | text = text.encode() |
894 | 163 | col = [c/255. for c in color] | 215 | col = [c/255. for c in color] |
895 | 164 | dl = glGenLists(1) | 216 | dl = glGenLists(1) |
896 | 165 | self.size = (self.font.Advance(text), self.font.line_height) | 217 | self.size = (self.font.Advance(text), self.font.line_height) |
897 | 218 | self.rect = Rect((0,0), self.size) | ||
898 | 166 | glNewList(dl, GL_COMPILE) | 219 | glNewList(dl, GL_COMPILE) |
899 | 167 | glPushMatrix() | 220 | glPushMatrix() |
900 | 168 | # Flip text right way up | 221 | # Flip text right way up |
901 | @@ -173,16 +226,33 @@ | |||
902 | 173 | self.font.Render(text) | 226 | self.font.Render(text) |
903 | 174 | glPopMatrix() | 227 | glPopMatrix() |
904 | 175 | glEndList() | 228 | glEndList() |
907 | 176 | self.display_list = [(dl, col)] | 229 | temp.display_list = [(dl, col)] |
908 | 177 | return self | 230 | return temp |
909 | 231 | |||
910 | 232 | def get_linesize(self): | ||
911 | 233 | """TODO""" | ||
912 | 234 | return self.rect.h | ||
913 | 235 | |||
914 | 236 | def get_ascent(self): | ||
915 | 237 | """TODO""" | ||
916 | 238 | return self.rect.h-4 | ||
917 | 239 | |||
918 | 240 | def get_descent(self): | ||
919 | 241 | """TODO""" | ||
920 | 242 | return -4 | ||
921 | 243 | |||
922 | 244 | def metrics(self, text): | ||
923 | 245 | """TODO""" | ||
924 | 246 | return [(0,0,0,0,10) for c in text] | ||
925 | 178 | 247 | ||
926 | 179 | class Draw(): | 248 | class Draw(): |
927 | 180 | """ | 249 | """ |
928 | 181 | Class to emulate the pygame.draw module. | 250 | Class to emulate the pygame.draw module. |
930 | 182 | Functions should work in the same manner. | 251 | Functions should work in the same manner, except where otherwise stated. |
931 | 183 | 252 | ||
932 | 184 | """ | 253 | """ |
933 | 185 | def rect(self, surf, col, rect, width=0): | 254 | def rect(self, surf, col, rect, width=0): |
934 | 255 | rect = Rect(rect) | ||
935 | 186 | col = [c/255. for c in col] | 256 | col = [c/255. for c in col] |
936 | 187 | dl = glGenLists(1) | 257 | dl = glGenLists(1) |
937 | 188 | glNewList(dl, GL_COMPILE) | 258 | glNewList(dl, GL_COMPILE) |
938 | @@ -220,6 +290,8 @@ | |||
939 | 220 | for v in pointlist: | 290 | for v in pointlist: |
940 | 221 | glVertex(v) | 291 | glVertex(v) |
941 | 222 | glEnd() | 292 | glEnd() |
942 | 293 | else: | ||
943 | 294 | raise NotImplementedError | ||
944 | 223 | glEndList() | 295 | glEndList() |
945 | 224 | surf.display_list.append((dl, col)) | 296 | surf.display_list.append((dl, col)) |
946 | 225 | 297 | ||
947 | @@ -235,10 +307,18 @@ | |||
948 | 235 | glVertex(pos) | 307 | glVertex(pos) |
949 | 236 | glEnd() | 308 | glEnd() |
950 | 237 | glDisable(GL_POINT_SMOOTH) | 309 | glDisable(GL_POINT_SMOOTH) |
952 | 238 | glPointSize() | 310 | #glPointSize() |
953 | 311 | else: | ||
954 | 312 | raise NotImplementedError | ||
955 | 239 | glEndList() | 313 | glEndList() |
956 | 240 | surf.display_list.append((dl, col)) | 314 | surf.display_list.append((dl, col)) |
957 | 241 | 315 | ||
958 | 316 | def ellipse(self, surf, col, rect, width=0): | ||
959 | 317 | raise NotImplementedError | ||
960 | 318 | |||
961 | 319 | def arc(self, surf, col, rect, start_angle, stop_angle, width=1): | ||
962 | 320 | raise NotImplementedError | ||
963 | 321 | |||
964 | 242 | def line(self, surf, col, start_pos, end_pos, width=1): | 322 | def line(self, surf, col, start_pos, end_pos, width=1): |
965 | 243 | col = [c/255. for c in col] | 323 | col = [c/255. for c in col] |
966 | 244 | dl = glGenLists(1) | 324 | dl = glGenLists(1) |
967 | @@ -251,5 +331,14 @@ | |||
968 | 251 | glEndList() | 331 | glEndList() |
969 | 252 | surf.display_list.append((dl, col)) | 332 | surf.display_list.append((dl, col)) |
970 | 253 | 333 | ||
971 | 334 | def lines(self, surf, col, closed, pointlist, width=1): | ||
972 | 335 | raise NotImplementedError | ||
973 | 336 | |||
974 | 337 | def aaline(self, surf, col, startpos, endpos, blend=1): | ||
975 | 338 | raise NotImplementedError | ||
976 | 339 | |||
977 | 340 | def aalines(self, surf, col, closed, pointlist, blend=1): | ||
978 | 341 | raise NotImplementedError | ||
979 | 342 | |||
980 | 254 | # Export Draw functions | 343 | # Export Draw functions |
981 | 255 | draw = Draw() | 344 | draw = Draw() |
982 | 256 | 345 | ||
983 | === modified file 'sgc/widgets/radio_button.py' | |||
984 | --- sgc/widgets/radio_button.py 2012-06-19 20:41:57 +0000 | |||
985 | +++ sgc/widgets/radio_button.py 2012-07-21 12:53:18 +0000 | |||
986 | @@ -73,8 +73,8 @@ | |||
987 | 73 | draw.circle(self._images["image"], (255,255,255), pos, r) | 73 | draw.circle(self._images["image"], (255,255,255), pos, r) |
988 | 74 | draw.circle(self._images["over"], self._settings["col"], pos, r) | 74 | draw.circle(self._images["over"], self._settings["col"], pos, r) |
989 | 75 | # Border circles | 75 | # Border circles |
992 | 76 | draw.circle(self._images["image"], (0,0,1), pos, r, 1) | 76 | draw.circle(self._images["image"], (0,0,1), pos, r) |
993 | 77 | draw.circle(self._images["over"], (0,0,1), pos, r, 1) | 77 | draw.circle(self._images["over"], (0,0,1), pos, r) |
994 | 78 | 78 | ||
995 | 79 | def _draw_active(self, draw, image): | 79 | def _draw_active(self, draw, image): |
996 | 80 | # Central dot for 'active' state | 80 | # Central dot for 'active' state |
Unresolved conflicts that should never have been committed.
Remove extra line breaks added into multiple files.
Remove matrix.py and revert opengl.py.