home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / gl / glstdwin / glstdwdraw.py < prev    next >
Text File  |  1992-12-14  |  3KB  |  136 lines

  1. # Define drawing operations for GL stdwin
  2.  
  3. import gl
  4. import fm
  5. from GL import LO_XOR, LO_SRC
  6. from glstdwin import MASK
  7.  
  8. class DrawingObject:
  9.     #
  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
  19.     #
  20.     def setfont(self, fontname):
  21.         self.font = fm.findfont(fontname).scalefont(self.size)
  22.     #
  23.     def setsize(self, size):
  24.         ratio = float(size) / float(self.size)
  25.         self.size = size
  26.         self.font = self.font.scalefont(ratio)
  27.     #
  28.     def setfgcolor(self, color):
  29.         self.fg = color
  30.         gl.color(self.fg)
  31.     #
  32.     def setbgcolor(self, color):
  33.         self.bg = color
  34.     #
  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)
  39.     #
  40.     def noclip(self):
  41.         #print 'noclip()'
  42.         gl.scrmask(0, self.width, 0, self.height)
  43.     #
  44.     def paint(self, ((left, top), (right, bottom))):
  45.         gl.rectf(left, top, right, bottom)
  46.     #
  47.     def box(self, ((left, top), (right, bottom))):
  48.         #print 'box', ((left, top), (right, bottom))
  49.         gl.rect(left, top, right, bottom)
  50.     #
  51.     def circle(self, (h, v), radius):
  52.         gl.circ(h, v, radius)
  53.     #
  54.     def elarc(self, center, (rh, rv), (a1, a2)):
  55.         pass # XXX
  56.     #
  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)
  62.     #
  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)
  70.     #
  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()
  77.     #
  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)
  88.     #
  89.     def point(self, (h, v)):
  90.         #print 'point', (h, v)
  91.         gl.bgnpoint()
  92.         gl.v2i(h, v)
  93.         gl.endpoint()
  94.     #
  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)
  110.     #
  111.     def shade(self, (h, v), percent):
  112.         pass # XXX
  113.     #
  114.     def baseline(self):
  115.         (printermatched, fixed_width, xorig, yorig, xsize, ysize, \
  116.             height, nglyphs) = self.font.getfontinfo()
  117.         return height - yorig
  118.     #
  119.     def lineheight(self):
  120.         (printermatched, fixed_width, xorig, yorig, xsize, ysize, \
  121.             height, nglyphs) = self.font.getfontinfo()
  122.         return height
  123.     #
  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
  132.     #
  133.     def textwidth(self, string):
  134.         return self.font.getstrwidth(string)
  135.     #
  136.