1 # Define drawing operations for GL stdwin
5 from GL
import LO_XOR
, LO_SRC
6 from glstdwin
import MASK
15 self
.width
, self
.height
= win
._area
[1]
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
)
26 self
.font
= self
.font
.scalefont(ratio
)
28 def setfgcolor(self
, color
):
32 def setbgcolor(self
, 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
)
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
):
54 def elarc(self
, center
, (rh
, rv
), (a1
, a2
)):
57 def erase(self
, ((left
, top
), (right
, bottom
))):
58 #print 'erase', ((left, top), (right, bottom))
60 gl
.rectf(left
, top
, right
, bottom
)
63 def invert(self
, ((left
, top
), (right
, bottom
))):
64 #print 'invert', ((h0, v0), (h1, v1))
67 gl
.rectf(left
, top
, right
, bottom
)
71 def line(self
, (h0
, v0
), (h1
, v1
)):
72 #print 'line', ((h0, v0), (h1, v1))
78 def xorline(self
, (h0
, v0
), (h1
, v1
)):
79 #print 'xorline', ((h0, v0), (h1, v1))
89 def point(self
, (h
, v
)):
90 #print 'point', (h, v)
95 def text(self
, (h
, v
), string
):
96 #print 'text', ((h, v), string)
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
])
107 gl
.cmov2(h
, v
+ self
.baseline())
111 def shade(self
, (h
, v
), percent
):
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()
124 def textbreak(self
, string
, width
):
127 nwidth
= self
.textwidth(string
[:n
])
128 while nwidth
> width
:
130 nwidth
= self
.textwidth(string
[:n
])
133 def textwidth(self
, string
):
134 return self
.font
.getstrwidth(string
)