+class glComboButton(glButton):
+ def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
+ super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
+ self._imageIDs = imageIDs
+ self._tooltips = tooltips
+ self._comboCallback = callback
+ self._selection = 0
+
+ def _onComboOpenSelect(self):
+ self._base._focus = self
+
+ def draw(self):
+ if self._hidden:
+ return
+ self._selected = self.hasFocus()
+ super(glComboButton, self).draw()
+ if not self._selected:
+ return
+
+ bs = self._base._buttonSize / 2
+ pos = self._getPixelPos()
+
+ glPushMatrix()
+ glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
+ glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
+ glScalef(bs, bs, bs)
+ for n in xrange(0, len(self._imageIDs)):
+ cx = (self._imageIDs[n] % 4) / 4
+ cy = int(self._imageIDs[n] / 4) / 4
+ glEnable(GL_TEXTURE_2D)
+ glTranslatef(0, 1, 0)
+ if self._disabled:
+ glColor4ub(128,128,128,128)
+ else:
+ glColor4ub(255,255,255,255)
+ glBegin(GL_QUADS)
+ glTexCoord2f(cx+0.25, cy)
+ glVertex2f( 0.5,-0.5)
+ glTexCoord2f(cx, cy)
+ glVertex2f(-0.5,-0.5)
+ glTexCoord2f(cx, cy+0.25)
+ glVertex2f(-0.5, 0.5)
+ glTexCoord2f(cx+0.25, cy+0.25)
+ glVertex2f( 0.5, 0.5)
+ glEnd()
+ glDisable(GL_TEXTURE_2D)
+
+ glPushMatrix()
+ glColor4ub(0,0,0,255)
+ glTranslatef(-0.55, 0.1, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glPopMatrix()
+ glPopMatrix()
+
+ def getValue(self):
+ return self._selection
+
+ def OnMouseDown(self, x, y):
+ if self._hidden or self._disabled:
+ return False
+ if self.hasFocus():
+ bs = self._base._buttonSize / 2
+ pos = self._getPixelPos()
+ if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
+ self._selection = int((y - pos[1] - bs) / bs)
+ self._imageID = self._imageIDs[self._selection]
+ self._base._focus = None
+ self._comboCallback()
+ return True
+ return super(glComboButton, self).OnMouseDown(x, y)
+
+