Debian Codegraph @

ui.py

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 import sys, pygame
2 from pygame.locals import *
3 from OpenGL.GL import *
4 from OpenGL.GLU import *
5 from OpenGL.GLUT import *
6
7 import fonts, pyglyph
8
9 class UserInterface:
10
11 def twod_setup(self, colour=(0,0,0)):
12 # set up 2d mode
13 glMatrixMode(GL_PROJECTION)
14 glLoadIdentity()
15 x, y = self.viewport
16 glViewport(0, 0, x, y)
17 glOrtho(0, x, 0, y, -50, 50)
18 glMatrixMode(GL_MODELVIEW)
19 colour += (0,)
20 glClearColor(*colour)
21 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
22 glLoadIdentity()
23 glDisable(GL_LIGHTING)
24 glDisable(GL_DEPTH_TEST)
25
26
27 def ok_dialog(self, text):
28 text = pyglyph.layout_text(text, font=fonts.sans40)
29 x, y = self.viewport
30
31 self.twod_setup()
32
33 glBegin(GL_QUADS)
34 glColor4f(.9, .9, .9, 1)
35 glVertex2f(x/2 - 300, y/2-100)
36 glVertex2f(x/2 + 300, y/2-100)
37 glVertex2f(x/2 + 300, y/2+100)
38 glVertex2f(x/2 - 300, y/2+100)
39 glEnd()
40
41 pyglyph.begin()
42 text.draw(pos=(x/2, y/2),
43 anchor=(pyglyph.Align.center, pyglyph.Align.center))
44 pyglyph.end()
45
46 pygame.display.flip()
47
48 while 1:
49 for e in pygame.event.get():
50 if e.type == QUIT: sys.exit()
51 if e.type == MOUSEBUTTONDOWN: return
52 if not hasattr(e, 'key'): continue
53 if e.key == K_RETURN: return
54 if e.key == K_ESCAPE: return
55
56 def fade(self, dir, ts, ts_max):
57 # fade to black
58 glMatrixMode(GL_PROJECTION)
59 glLoadIdentity()
60 x, y = self.viewport
61 glOrtho(0, x, 0, y, -1, 1)
62 glMatrixMode(GL_MODELVIEW)
63 glDisable(GL_LIGHTING)
64 glDisable(GL_DEPTH_TEST)
65 glEnable(GL_BLEND)
66 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
67 glLoadIdentity()
68
69 glBegin(GL_QUADS)
70 if dir == 'out':
71 glColor(0, 0, 0, min(1, float(ts)/ts_max))
72 else:
73 glColor(0, 0, 0, max(0, 1 - float(ts)/ts_max))
74 glVertex(0, 0, 0)
75 glVertex(0, y, 0)
76 glVertex(x, y, 0)
77 glVertex(x, 0, 0)
78 glEnd()
79