The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Demo / sgi / gl / glstdwin / glstdwdraw.py
blob4ddc7a67cb73995a680e2790810ee30657c4c04a
1 # Define drawing operations for GL stdwin
3 import gl
4 import fm
5 from GL import LO_XOR, LO_SRC
6 from glstdwin import MASK
8 class DrawingObject:
10 def _init(self, win):
11 self.fg = win._fg
12 self.bg = win._bg
13 self.font = win._font
14 self.size = win._size
15 self.width, self.height = win._area[1]
16 gl.winset(win._gid)
17 gl.color(self.fg)
18 return self
20 def setfont(self, fontname):
21 self.font = fm.findfont(fontname).scalefont(self.size)
23 def setsize(self, size):
24 ratio = float(size) / float(self.size)
25 self.size = size
26 self.font = self.font.scalefont(ratio)
28 def setfgcolor(self, color):
29 self.fg = color
30 gl.color(self.fg)
32 def setbgcolor(self, color):
33 self.bg = color
35 def cliprect(self, area):
36 #print 'cliprect', area
37 (left, top), (right, bottom) = area
38 gl.scrmask(left, right, self.height-bottom, self.height-top)
40 def noclip(self):
41 #print 'noclip()'
42 gl.scrmask(0, self.width, 0, self.height)
44 def paint(self, ((left, top), (right, bottom))):
45 gl.rectf(left, top, right, bottom)
47 def box(self, ((left, top), (right, bottom))):
48 #print 'box', ((left, top), (right, bottom))
49 gl.rect(left, top, right, bottom)
51 def circle(self, (h, v), radius):
52 gl.circ(h, v, radius)
54 def elarc(self, center, (rh, rv), (a1, a2)):
55 pass # XXX
57 def erase(self, ((left, top), (right, bottom))):
58 #print 'erase', ((left, top), (right, bottom))
59 gl.color(self.bg)
60 gl.rectf(left, top, right, bottom)
61 gl.color(self.fg)
63 def invert(self, ((left, top), (right, bottom))):
64 #print 'invert', ((h0, v0), (h1, v1))
65 gl.logicop(LO_XOR)
66 gl.color(self.bg)
67 gl.rectf(left, top, right, bottom)
68 gl.color(self.fg)
69 gl.logicop(LO_SRC)
71 def line(self, (h0, v0), (h1, v1)):
72 #print 'line', ((h0, v0), (h1, v1))
73 gl.bgnline()
74 gl.v2i(h0, v0)
75 gl.v2i(h1, v1)
76 gl.endline()
78 def xorline(self, (h0, v0), (h1, v1)):
79 #print 'xorline', ((h0, v0), (h1, v1))
80 gl.logicop(LO_XOR)
81 gl.color(self.bg)
82 gl.bgnline()
83 gl.v2i(h0, v0)
84 gl.v2i(h1, v1)
85 gl.endline()
86 gl.color(self.fg)
87 gl.logicop(LO_SRC)
89 def point(self, (h, v)):
90 #print 'point', (h, v)
91 gl.bgnpoint()
92 gl.v2i(h, v)
93 gl.endpoint()
95 def text(self, (h, v), string):
96 #print 'text', ((h, v), string)
97 if h < 0:
98 # If the point is outside the window
99 # the whole string isn't drawn.
100 # Skip the beginning of the string.
101 # XXX What if the font is bigger than 20 pixels?
102 i, n = 0, len(string)
103 while h < -MASK and i < n:
104 h = h + self.font.getstrwidth(string[i])
105 i = i + 1
106 string = string[i:]
107 gl.cmov2(h, v + self.baseline())
108 self.font.setfont()
109 fm.prstr(string)
111 def shade(self, (h, v), percent):
112 pass # XXX
114 def baseline(self):
115 (printermatched, fixed_width, xorig, yorig, xsize, ysize, \
116 height, nglyphs) = self.font.getfontinfo()
117 return height - yorig
119 def lineheight(self):
120 (printermatched, fixed_width, xorig, yorig, xsize, ysize, \
121 height, nglyphs) = self.font.getfontinfo()
122 return height
124 def textbreak(self, string, width):
125 # XXX Slooooow!
126 n = len(string)
127 nwidth = self.textwidth(string[:n])
128 while nwidth > width:
129 n = n-1
130 nwidth = self.textwidth(string[:n])
131 return n
133 def textwidth(self, string):
134 return self.font.getstrwidth(string)