+ if self._disabled:
+ glColor4ub(128,128,128,128)
+ else:
+ glColor4ub(255,255,255,255)
+ opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, 0)
+ opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
+ if self._showExpandArrow:
+ if self._selected:
+ opengl.glDrawTexturedQuad(pos[0]+bs*scale/2-bs*scale/4*1.2, pos[1]-bs*scale/2*1.2, bs*scale/4, bs*scale/4, 1)
+ else:
+ opengl.glDrawTexturedQuad(pos[0]+bs*scale/2-bs*scale/4*1.2, pos[1]-bs*scale/2*1.2, bs*scale/4, bs*scale/4, 1, 2)
+ glPushMatrix()
+ glTranslatef(pos[0], pos[1], 0)
+ glDisable(GL_TEXTURE_2D)
+ if self._focus:
+ glTranslatef(0, -0.55*bs*scale, 0)
+
+ glPushMatrix()
+ glColor4ub(60,60,60,255)
+ glTranslatef(-1, -1, 0)
+ opengl.glDrawStringCenter(self._tooltip)
+ glTranslatef(0, 2, 0)
+ opengl.glDrawStringCenter(self._tooltip)
+ glTranslatef(2, 0, 0)
+ opengl.glDrawStringCenter(self._tooltip)
+ glTranslatef(0, -2, 0)
+ opengl.glDrawStringCenter(self._tooltip)
+ glPopMatrix()
+
+ glColor4ub(255,255,255,255)
+ opengl.glDrawStringCenter(self._tooltip)
+ glPopMatrix()
+ progress = self._progressBar
+ if progress is not None:
+ glColor4ub(60,60,60,255)
+ opengl.glDrawQuad(pos[0]-bs/2, pos[1]+bs/2, bs, bs / 4)
+ glColor4ub(255,255,255,255)
+ opengl.glDrawQuad(pos[0]-bs/2+2, pos[1]+bs/2+2, (bs - 5) * progress + 1, bs / 4 - 4)
+ elif len(self._altTooltip) > 0:
+ glPushMatrix()
+ glTranslatef(pos[0], pos[1], 0)
+ glTranslatef(0, 0.6*bs, 0)
+ glTranslatef(0, 6, 0)
+ #glTranslatef(0.6*bs*scale, 0, 0)
+
+ for line in self._altTooltip.split('\n'):
+ glPushMatrix()
+ glColor4ub(60,60,60,255)
+ glTranslatef(-1, -1, 0)
+ opengl.glDrawStringCenter(line)
+ glTranslatef(0, 2, 0)
+ opengl.glDrawStringCenter(line)
+ glTranslatef(2, 0, 0)
+ opengl.glDrawStringCenter(line)
+ glTranslatef(0, -2, 0)
+ opengl.glDrawStringCenter(line)
+ glPopMatrix()
+
+ glColor4ub(255,255,255,255)
+ opengl.glDrawStringCenter(line)
+ glTranslatef(0, 18, 0)
+ glPopMatrix()
+
+ def _checkHit(self, x, y):
+ if self._hidden or self._disabled:
+ return False
+ bs = self.getMinSize()[0]
+ pos = self._getPixelPos()
+ return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5
+
+ def OnMouseMotion(self, x, y):
+ if self._checkHit(x, y):
+ self._focus = True
+ return True
+ self._focus = False
+ return False
+
+ def OnMouseDown(self, x, y, button):
+ if self._checkHit(x, y):
+ self._callback(button)
+ return True
+ return False
+
+class glRadioButton(glButton):
+ def __init__(self, parent, imageID, tooltip, pos, group, callback):
+ super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
+ self._group = group
+ self._radioCallback = callback
+ self._group.append(self)
+
+ def setSelected(self, value):
+ self._selected = value
+
+ def _onRadioSelect(self, button):
+ self._base._focus = None
+ for ctrl in self._group:
+ if ctrl != self:
+ ctrl.setSelected(False)
+ if self.getSelected():
+ self.setSelected(False)
+ else:
+ self.setSelected(True)
+ self._radioCallback(button)
+
+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, button):
+ if self.hasFocus():
+ self._base._focus = None
+ else:
+ self._base._focus = self
+
+ def draw(self):
+ if self._hidden:
+ return
+ self._selected = self.hasFocus()
+ super(glComboButton, self).draw()
+
+ bs = self._base._buttonSize / 2
+ pos = self._getPixelPos()
+
+ if not self._selected:
+ return
+
+ glPushMatrix()
+ glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
+ glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
+ for n in xrange(0, len(self._imageIDs)):
+ glTranslatef(0, bs, 0)
+ glColor4ub(255,255,255,255)
+ opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
+ opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
+ glDisable(GL_TEXTURE_2D)
+
+ glPushMatrix()
+ glTranslatef(-0.55*bs, 0.1*bs, 0)
+
+ glPushMatrix()
+ glColor4ub(60,60,60,255)
+ glTranslatef(-1, -1, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glTranslatef(0, 2, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glTranslatef(2, 0, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glTranslatef(0, -2, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glPopMatrix()
+
+ glColor4ub(255,255,255,255)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glPopMatrix()
+ glPopMatrix()
+
+ def getValue(self):
+ return self._selection
+
+ def setValue(self, value):
+ self._selection = value
+ self._imageID = self._imageIDs[self._selection]
+ self._comboCallback()
+
+ def OnMouseDown(self, x, y, button):
+ 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, button)
+
+class glFrame(glGuiContainer):
+ def __init__(self, parent, pos):
+ super(glFrame, self).__init__(parent, pos)
+ self._selected = False
+ self._focus = False
+ self._hidden = False
+
+ def setSelected(self, value):
+ self._selected = value
+
+ def setHidden(self, value):
+ self._hidden = value
+ for child in self._glGuiControlList:
+ if self._base._focus == child:
+ self._base._focus = None
+
+ def getSelected(self):
+ return self._selected
+
+ def getMinSize(self):
+ return self._base._buttonSize, self._base._buttonSize
+
+ def _getPixelPos(self):
+ x0, y0, w, h = self.getSize()
+ return x0, y0
+
+ def draw(self):
+ if self._hidden:
+ return
+
+ bs = self._parent._buttonSize
+ pos = self._getPixelPos()
+
+ size = self._layout.getLayoutSize()
+ glColor4ub(255,255,255,255)
+ opengl.glDrawStretchedQuad(pos[0], pos[1], size[0], size[1], bs*0.75, 0)
+ #Draw the controls on the frame
+ super(glFrame, self).draw()
+
+ def _checkHit(self, x, y):
+ if self._hidden:
+ return False
+ pos = self._getPixelPos()
+ w, h = self._layout.getLayoutSize()
+ return 0 <= x - pos[0] <= w and 0 <= y - pos[1] <= h
+
+ def OnMouseMotion(self, x, y):
+ super(glFrame, self).OnMouseMotion(x, y)
+ if self._checkHit(x, y):
+ self._focus = True
+ return True
+ self._focus = False
+ return False
+
+ def OnMouseDown(self, x, y, button):
+ if self._checkHit(x, y):
+ super(glFrame, self).OnMouseDown(x, y, button)
+ return True
+ return False
+
+class glNotification(glFrame):
+ def __init__(self, parent, pos):
+ self._anim = None
+ super(glNotification, self).__init__(parent, pos)
+ glGuiLayoutGrid(self)._alignBottom = False
+ self._label = glLabel(self, "Notification", (0, 0))
+ self._buttonExtra = glButton(self, 31, "???", (1, 0), self.onExtraButton, 25)
+ self._button = glButton(self, 30, "", (2, 0), self.onClose, 25)
+ self._padding = glLabel(self, "", (0, 1))
+ self.setHidden(True)
+
+ def setSize(self, x, y, w, h):
+ w, h = self._layout.getLayoutSize()
+ baseSize = self._base.GetSizeTuple()
+ if self._anim is not None:
+ super(glNotification, self).setSize(baseSize[0] / 2 - w / 2, baseSize[1] - self._anim.getPosition() - self._base._buttonSize * 0.2, 1, 1)
+ else:
+ super(glNotification, self).setSize(baseSize[0] / 2 - w / 2, baseSize[1] - self._base._buttonSize * 0.2, 1, 1)
+
+ def draw(self):
+ self.setSize(0,0,0,0)
+ self.updateLayout()
+ super(glNotification, self).draw()
+
+ def message(self, text, extraButtonCallback = None, extraButtonIcon = None, extraButtonTooltip = None):
+ self._anim = animation(self._base, -20, 25, 1)
+ self.setHidden(False)
+ self._label.setLabel(text)
+ self._buttonExtra.setHidden(extraButtonCallback is None)
+ self._buttonExtra._imageID = extraButtonIcon
+ self._buttonExtra._tooltip = extraButtonTooltip
+ self._extraButtonCallback = extraButtonCallback
+ self._base._queueRefresh()
+ self.updateLayout()
+
+ def onExtraButton(self, button):
+ self.onClose(button)
+ self._extraButtonCallback()
+
+ def onClose(self, button):
+ if self._anim is not None:
+ self._anim = animation(self._base, self._anim.getPosition(), -20, 1)
+ else:
+ self._anim = animation(self._base, 25, -20, 1)
+
+class glLabel(glGuiControl):
+ def __init__(self, parent, label, pos):
+ self._label = label
+ super(glLabel, self).__init__(parent, pos)
+
+ def setLabel(self, label):
+ self._label = label
+
+ def getMinSize(self):
+ w, h = opengl.glGetStringSize(self._label)
+ return w + 10, h + 4
+
+ def _getPixelPos(self):
+ x0, y0, w, h = self.getSize()
+ return x0, y0
+
+ def draw(self):
+ x, y, w, h = self.getSize()
+
+ glPushMatrix()
+ glTranslatef(x, y, 0)
+
+# glColor4ub(255,255,255,128)
+# glBegin(GL_QUADS)
+# glTexCoord2f(1, 0)
+# glVertex2f( w, 0)
+# glTexCoord2f(0, 0)
+# glVertex2f( 0, 0)
+# glTexCoord2f(0, 1)
+# glVertex2f( 0, h)
+# glTexCoord2f(1, 1)
+# glVertex2f( w, h)
+# glEnd()
+
+ glTranslate(5, h - 5, 0)