summaryrefslogtreecommitdiffstats
path: root/Demo/sgi/gl/glstdwin/glstdwdraw.py
blob: 4ddc7a67cb73995a680e2790810ee30657c4c04a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Define drawing operations for GL stdwin

import gl
import fm
from GL import LO_XOR, LO_SRC
from glstdwin import MASK

class DrawingObject:
	#
	def _init(self, win):
		self.fg = win._fg
		self.bg = win._bg
		self.font = win._font
		self.size = win._size
		self.width, self.height = win._area[1]
		gl.winset(win._gid)
		gl.color(self.fg)
		return self
	#
	def setfont(self, fontname):
		self.font = fm.findfont(fontname).scalefont(self.size)
	#
	def setsize(self, size):
		ratio = float(size) / float(self.size)
		self.size = size
		self.font = self.font.scalefont(ratio)
	#
	def setfgcolor(self, color):
		self.fg = color
		gl.color(self.fg)
	#
	def setbgcolor(self, color):
		self.bg = color
	#
	def cliprect(self, area):
		#print 'cliprect', area
		(left, top), (right, bottom) = area
		gl.scrmask(left, right, self.height-bottom, self.height-top)
	#
	def noclip(self):
		#print 'noclip()'
		gl.scrmask(0, self.width, 0, self.height)
	#
	def paint(self, ((left, top), (right, bottom))):
		gl.rectf(left, top, right, bottom)
	#
	def box(self, ((left, top), (right, bottom))):
		#print 'box', ((left, top), (right, bottom))
		gl.rect(left, top, right, bottom)
	#
	def circle(self, (h, v), radius):
		gl.circ(h, v, radius)
	#
	def elarc(self, center, (rh, rv), (a1, a2)):
		pass # XXX
	#
	def erase(self, ((left, top), (right, bottom))):
		#print 'erase', ((left, top), (right, bottom))
		gl.color(self.bg)
		gl.rectf(left, top, right, bottom)
		gl.color(self.fg)
	#
	def invert(self, ((left, top), (right, bottom))):
		#print 'invert', ((h0, v0), (h1, v1))
		gl.logicop(LO_XOR)
		gl.color(self.bg)
		gl.rectf(left, top, right, bottom)
		gl.color(self.fg)
		gl.logicop(LO_SRC)
	#
	def line(self, (h0, v0), (h1, v1)):
		#print 'line', ((h0, v0), (h1, v1))
		gl.bgnline()
		gl.v2i(h0, v0)
		gl.v2i(h1, v1)
		gl.endline()
	#
	def xorline(self, (h0, v0), (h1, v1)):
		#print 'xorline', ((h0, v0), (h1, v1))
		gl.logicop(LO_XOR)
		gl.color(self.bg)
		gl.bgnline()
		gl.v2i(h0, v0)
		gl.v2i(h1, v1)
		gl.endline()
		gl.color(self.fg)
		gl.logicop(LO_SRC)
	#
	def point(self, (h, v)):
		#print 'point', (h, v)
		gl.bgnpoint()
		gl.v2i(h, v)
		gl.endpoint()
	#
	def text(self, (h, v), string):
		#print 'text', ((h, v), string)
		if h < 0:
			# If the point is outside the window
			# the whole string isn't drawn.
			# Skip the beginning of the string.
			# XXX What if the font is bigger than 20 pixels?
			i, n = 0, len(string)
			while h < -MASK and i < n:
				h = h + self.font.getstrwidth(string[i])
				i = i + 1
			string = string[i:]
		gl.cmov2(h, v + self.baseline())
		self.font.setfont()
		fm.prstr(string)
	#
	def shade(self, (h, v), percent):
		pass # XXX
	#
	def baseline(self):
		(printermatched, fixed_width, xorig, yorig, xsize, ysize, \
			height, nglyphs) = self.font.getfontinfo()
		return height - yorig
	#
	def lineheight(self):
		(printermatched, fixed_width, xorig, yorig, xsize, ysize, \
			height, nglyphs) = self.font.getfontinfo()
		return height
	#
	def textbreak(self, string, width):
		# XXX Slooooow!
		n = len(string)
		nwidth = self.textwidth(string[:n])
		while nwidth > width:
			n = n-1
			nwidth = self.textwidth(string[:n])
		return n
	#
	def textwidth(self, string):
		return self.font.getstrwidth(string)
	#