chiark / gitweb /
Change how the engine is interfaced from the python code. Put the GCode viewer in...
[cura.git] / Cura / gui / util / openglGui.py
index 25ae42253a6fd0afec53f00c7644a6f919ede4a1..c9b0eeebe684408fc0d1573e2f3cf0e14a7879dd 100644 (file)
@@ -1,18 +1,42 @@
 from __future__ import absolute_import
 from __future__ import division
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import wx
 import traceback
 import sys
 import os
+import time
 
 from wx import glcanvas
 import OpenGL
-OpenGL.ERROR_CHECKING = False
+#OpenGL.ERROR_CHECKING = False
 from OpenGL.GL import *
 
+from Cura.util import version
 from Cura.gui.util import opengl
 
+class animation(object):
+       def __init__(self, gui, start, end, runTime):
+               self._start = start
+               self._end = end
+               self._startTime = time.time()
+               self._runTime = runTime
+               gui._animationList.append(self)
+
+       def isDone(self):
+               return time.time() > self._startTime + self._runTime
+
+       def getPosition(self):
+               if self.isDone():
+                       return self._end
+               f = (time.time() - self._startTime) / self._runTime
+               ts = f*f
+               tc = f*f*f
+               #f = 6*tc*ts + -15*ts*ts + 10*tc
+               f = tc + -3*ts + 3*f
+               return self._start + (self._end - self._start) * f
+
 class glGuiControl(object):
        def __init__(self, parent, pos):
                self._parent = parent
@@ -71,9 +95,9 @@ class glGuiContainer(glGuiControl):
                self._glGuiControlList.append(ctrl)
                self.updateLayout()
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                for ctrl in self._glGuiControlList:
-                       if ctrl.OnMouseDown(x, y):
+                       if ctrl.OnMouseDown(x, y, button):
                                return True
                return False
 
@@ -101,7 +125,7 @@ class glGuiContainer(glGuiControl):
 
 class glGuiPanel(glcanvas.GLCanvas):
        def __init__(self, parent):
-               attribList = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24, glcanvas.WX_GL_STENCIL_SIZE, 8)
+               attribList = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24, glcanvas.WX_GL_STENCIL_SIZE, 8, 0)
                glcanvas.GLCanvas.__init__(self, parent, style=wx.WANTS_CHARS, attribList = attribList)
                self._base = self
                self._focus = None
@@ -114,35 +138,60 @@ class glGuiPanel(glcanvas.GLCanvas):
                self._glRobotTexture = None
                self._buttonSize = 64
 
+               self._animationList = []
+               self.glReleaseList = []
+               self._refreshQueued = False
+               self._idleCalled = False
+
                wx.EVT_PAINT(self, self._OnGuiPaint)
                wx.EVT_SIZE(self, self._OnSize)
                wx.EVT_ERASE_BACKGROUND(self, self._OnEraseBackground)
-               wx.EVT_LEFT_DOWN(self, self._OnGuiMouseLeftDown)
-               wx.EVT_LEFT_UP(self, self._OnGuiMouseLeftUp)
+               wx.EVT_LEFT_DOWN(self, self._OnGuiMouseDown)
+               wx.EVT_LEFT_DCLICK(self, self._OnGuiMouseDown)
+               wx.EVT_LEFT_UP(self, self._OnGuiMouseUp)
+               wx.EVT_RIGHT_DOWN(self, self._OnGuiMouseDown)
+               wx.EVT_RIGHT_DCLICK(self, self._OnGuiMouseDown)
+               wx.EVT_RIGHT_UP(self, self._OnGuiMouseUp)
+               wx.EVT_MIDDLE_DOWN(self, self._OnGuiMouseDown)
+               wx.EVT_MIDDLE_DCLICK(self, self._OnGuiMouseDown)
+               wx.EVT_MIDDLE_UP(self, self._OnGuiMouseUp)
                wx.EVT_MOTION(self, self._OnGuiMouseMotion)
-               wx.EVT_CHAR(self, self.OnKeyChar)
+               wx.EVT_CHAR(self, self._OnGuiKeyChar)
                wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
+               wx.EVT_IDLE(self, self._OnIdle)
+
+       def _OnIdle(self, e):
+               self._idleCalled = True
+               if len(self._animationList) > 0 or self._refreshQueued:
+                       self._refreshQueued = False
+                       for anim in self._animationList:
+                               if anim.isDone():
+                                       self._animationList.remove(anim)
+                       self.Refresh()
 
-       def OnKeyChar(self, e):
+       def _OnGuiKeyChar(self, e):
                if self._focus is not None:
                        self._focus.OnKeyChar(e.GetKeyCode())
                        self.Refresh()
+               else:
+                       self.OnKeyChar(e.GetKeyCode())
 
        def OnFocusLost(self, e):
                self._focus = None
                self.Refresh()
 
-       def _OnGuiMouseLeftDown(self,e):
+       def _OnGuiMouseDown(self,e):
                self.SetFocus()
-               if self._container.OnMouseDown(e.GetX(), e.GetY()):
+               if self._container.OnMouseDown(e.GetX(), e.GetY(), e.GetButton()):
                        self.Refresh()
                        return
-               self.OnMouseLeftDown(e)
-       def _OnGuiMouseLeftUp(self, e):
+               self.OnMouseDown(e)
+
+       def _OnGuiMouseUp(self, e):
                if self._container.OnMouseUp(e.GetX(), e.GetY()):
                        self.Refresh()
                        return
-               self.OnMouseLeftUp(e)
+               self.OnMouseUp(e)
 
        def _OnGuiMouseMotion(self,e):
                self.Refresh()
@@ -150,6 +199,7 @@ class glGuiPanel(glcanvas.GLCanvas):
                        self.OnMouseMotion(e)
 
        def _OnGuiPaint(self, e):
+               self._idleCalled = False
                h = self.GetSize().GetHeight()
                w = self.GetSize().GetWidth()
                oldButtonSize = self._buttonSize
@@ -171,19 +221,32 @@ class glGuiPanel(glcanvas.GLCanvas):
                dc = wx.PaintDC(self)
                try:
                        self.SetCurrent(self._context)
+                       for obj in self.glReleaseList:
+                               obj.release()
+                       del self.glReleaseList[:]
+                       renderStartTime = time.time()
                        self.OnPaint(e)
                        self._drawGui()
                        glFlush()
+                       if version.isDevVersion():
+                               renderTime = time.time() - renderStartTime
+                               if renderTime == 0:
+                                       renderTime = 0.001
+                               glLoadIdentity()
+                               glTranslate(10, self.GetSize().GetHeight() - 30, -1)
+                               glColor4f(0.2,0.2,0.2,0.5)
+                               opengl.glDrawStringLeft("fps:%d" % (1 / renderTime))
                        self.SwapBuffers()
                except:
-                       errStr = 'An error has occurred during the 3D view drawing.'
+                       errStr = _("An error has occurred during the 3D view drawing.")
                        tb = traceback.extract_tb(sys.exc_info()[2])
                        errStr += "\n%s: '%s'" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]))
                        for n in xrange(len(tb)-1, -1, -1):
                                locationInfo = tb[n]
                                errStr += "\n @ %s:%s:%d" % (os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
                        if not self._shownError:
-                               wx.CallAfter(wx.MessageBox, errStr, '3D window error', wx.OK | wx.ICON_EXCLAMATION)
+                               traceback.print_exc()
+                               wx.CallAfter(wx.MessageBox, errStr, _("3D window error"), wx.OK | wx.ICON_EXCLAMATION)
                                self._shownError = True
 
        def _drawGui(self):
@@ -193,6 +256,7 @@ class glGuiPanel(glcanvas.GLCanvas):
 
                glDisable(GL_DEPTH_TEST)
                glEnable(GL_BLEND)
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
                glDisable(GL_LIGHTING)
                glColor4ub(255,255,255,255)
 
@@ -204,25 +268,27 @@ class glGuiPanel(glcanvas.GLCanvas):
                glLoadIdentity()
 
                self._container.draw()
-               glBindTexture(GL_TEXTURE_2D, self._glRobotTexture)
-               glEnable(GL_TEXTURE_2D)
-               glPushMatrix()
-               glColor4f(1,1,1,1)
-               glTranslate(size.GetWidth() - 8,size.GetHeight() - 16,0)
-               s = self._buttonSize * 1.4
-               glScale(s,s,s)
-               glBegin(GL_QUADS)
-               glTexCoord2f(1, 0)
-               glVertex2f(0,-1)
-               glTexCoord2f(0, 0)
-               glVertex2f(-1,-1)
-               glTexCoord2f(0, 1)
-               glVertex2f(-1, 0)
-               glTexCoord2f(1, 1)
-               glVertex2f(0, 0)
-               glEnd()
-               glDisable(GL_TEXTURE_2D)
-               glPopMatrix()
+
+               # glBindTexture(GL_TEXTURE_2D, self._glRobotTexture)
+               # glEnable(GL_TEXTURE_2D)
+               # glPushMatrix()
+               # glColor4f(1,1,1,1)
+               # glTranslate(size.GetWidth(),size.GetHeight(),0)
+               # s = self._buttonSize * 1
+               # glScale(s,s,s)
+               # glTranslate(-1.2,-0.2,0)
+               # glBegin(GL_QUADS)
+               # glTexCoord2f(1, 0)
+               # glVertex2f(0,-1)
+               # glTexCoord2f(0, 0)
+               # glVertex2f(-1,-1)
+               # glTexCoord2f(0, 1)
+               # glVertex2f(-1, 0)
+               # glTexCoord2f(1, 1)
+               # glVertex2f(0, 0)
+               # glEnd()
+               # glDisable(GL_TEXTURE_2D)
+               # glPopMatrix()
 
        def _OnEraseBackground(self,event):
                #Workaround for windows background redraw flicker.
@@ -233,14 +299,27 @@ class glGuiPanel(glcanvas.GLCanvas):
                self._container.updateLayout()
                self.Refresh()
 
-       def OnMouseLeftDown(self,e):
+       def OnMouseDown(self,e):
                pass
-       def OnMouseLeftUp(self,e):
+       def OnMouseUp(self,e):
                pass
        def OnMouseMotion(self, e):
                pass
+       def OnKeyChar(self, keyCode):
+               pass
        def OnPaint(self, e):
                pass
+       def OnKeyChar(self, keycode):
+               pass
+
+       def QueueRefresh(self):
+               wx.CallAfter(self._queueRefresh)
+
+       def _queueRefresh(self):
+               if self._idleCalled:
+                       wx.CallAfter(self.Refresh)
+               else:
+                       self._refreshQueued = True
 
        def add(self, ctrl):
                if self._container is not None:
@@ -262,7 +341,7 @@ class glGuiLayoutButtons(object):
                        else:
                                x = pos[0] * gridSize + bs * 0.2
                        if pos[1] < 0:
-                               y = h + pos[1] * gridSize * 1.2 - bs * 0.2
+                               y = h + pos[1] * gridSize * 1.2 - bs * 0.0
                        else:
                                y = pos[1] * gridSize * 1.2 + bs * 0.2
                        ctrl.setSize(x, y, gridSize, gridSize)
@@ -318,7 +397,9 @@ class glGuiLayoutGrid(object):
                return self._size
 
 class glButton(glGuiControl):
-       def __init__(self, parent, imageID, tooltip, pos, callback):
+       def __init__(self, parent, imageID, tooltip, pos, callback, size = None):
+               self._buttonSize = size
+               self._hidden = False
                super(glButton, self).__init__(parent, pos)
                self._tooltip = tooltip
                self._parent = parent
@@ -326,22 +407,40 @@ class glButton(glGuiControl):
                self._callback = callback
                self._selected = False
                self._focus = False
-               self._hidden = False
                self._disabled = False
+               self._showExpandArrow = False
+               self._progressBar = None
+               self._altTooltip = ''
 
        def setSelected(self, value):
                self._selected = value
 
+       def setExpandArrow(self, value):
+               self._showExpandArrow = value
+
        def setHidden(self, value):
                self._hidden = value
 
        def setDisabled(self, value):
                self._disabled = value
 
+       def setProgressBar(self, value):
+               self._progressBar = value
+
+       def getProgressBar(self):
+               return self._progressBar
+
+       def setBottomText(self, value):
+               self._altTooltip = value
+
        def getSelected(self):
                return self._selected
 
        def getMinSize(self):
+               if self._hidden:
+                       return 0, 0
+               if self._buttonSize is not None:
+                       return self._buttonSize, self._buttonSize
                return self._base._buttonSize, self._base._buttonSize
 
        def _getPixelPos(self):
@@ -354,7 +453,7 @@ class glButton(glGuiControl):
 
                cx = (self._imageID % 4) / 4
                cy = int(self._imageID / 4) / 4
-               bs = self._base._buttonSize
+               bs = self.getMinSize()[0]
                pos = self._getPixelPos()
 
                glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
@@ -367,15 +466,64 @@ class glButton(glGuiControl):
                        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:
-                       glColor4ub(255,255,255,255)
                        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:
@@ -391,9 +539,9 @@ class glButton(glGuiControl):
                self._focus = False
                return False
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                if self._checkHit(x, y):
-                       self._callback()
+                       self._callback(button)
                        return True
                return False
 
@@ -407,7 +555,7 @@ class glRadioButton(glButton):
        def setSelected(self, value):
                self._selected = value
 
-       def _onRadioSelect(self):
+       def _onRadioSelect(self, button):
                self._base._focus = None
                for ctrl in self._group:
                        if ctrl != self:
@@ -416,7 +564,7 @@ class glRadioButton(glButton):
                        self.setSelected(False)
                else:
                        self.setSelected(True)
-               self._radioCallback()
+               self._radioCallback(button)
 
 class glComboButton(glButton):
        def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
@@ -426,7 +574,7 @@ class glComboButton(glButton):
                self._comboCallback = callback
                self._selection = 0
 
-       def _onComboOpenSelect(self):
+       def _onComboOpenSelect(self, button):
                if self.hasFocus():
                        self._base._focus = None
                else:
@@ -447,16 +595,29 @@ class glComboButton(glButton):
                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)):
-                       glTranslatef(0, 1, 0)
+                       glTranslatef(0, bs, 0)
                        glColor4ub(255,255,255,255)
-                       opengl.glDrawTexturedQuad(-0.5,-0.5,1,1, self._imageIDs[n])
+                       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)
-                       glTranslatef(-0.55, 0.1, 0)
                        opengl.glDrawStringRight(self._tooltips[n])
                        glPopMatrix()
                glPopMatrix()
@@ -466,9 +627,10 @@ class glComboButton(glButton):
 
        def setValue(self, value):
                self._selection = value
+               self._imageID = self._imageIDs[self._selection]
                self._comboCallback()
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                if self._hidden or self._disabled:
                        return False
                if self.hasFocus():
@@ -480,7 +642,7 @@ class glComboButton(glButton):
                                self._base._focus = None
                                self._comboCallback()
                                return True
-               return super(glComboButton, self).OnMouseDown(x, y)
+               return super(glComboButton, self).OnMouseDown(x, y, button)
 
 class glFrame(glGuiContainer):
        def __init__(self, parent, pos):
@@ -494,6 +656,9 @@ class glFrame(glGuiContainer):
 
        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
@@ -512,115 +677,9 @@ class glFrame(glGuiContainer):
                bs = self._parent._buttonSize
                pos = self._getPixelPos()
 
-               glPushMatrix()
-               glTranslatef(pos[0], pos[1], 0)
-               glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
-               glEnable(GL_TEXTURE_2D)
-
                size = self._layout.getLayoutSize()
                glColor4ub(255,255,255,255)
-               glBegin(GL_QUADS)
-               bs /= 2
-               tc = 1 / 4 / 2
-
-#              glTexCoord2f(1, 0)
-#              glVertex2f( size[0], 0)
-#              glTexCoord2f(0, 0)
-#              glVertex2f( 0, 0)
-#              glTexCoord2f(0, 1)
-#              glVertex2f( 0, size[1])
-#              glTexCoord2f(1, 1)
-#              glVertex2f( size[0], size[1])
-               #TopLeft
-               glTexCoord2f(tc, 0)
-               glVertex2f( bs, 0)
-               glTexCoord2f(0, 0)
-               glVertex2f( 0, 0)
-               glTexCoord2f(0, tc/2)
-               glVertex2f( 0, bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, bs)
-               #TopRight
-               glTexCoord2f(tc+tc, 0)
-               glVertex2f( size[0], 0)
-               glTexCoord2f(tc, 0)
-               glVertex2f( size[0] - bs, 0)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0] - bs, bs)
-               glTexCoord2f(tc+tc, tc/2)
-               glVertex2f( size[0], bs)
-               #BottomLeft
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, size[1] - bs)
-               glTexCoord2f(0, tc/2)
-               glVertex2f( 0, size[1] - bs)
-               glTexCoord2f(0, tc/2+tc/2)
-               glVertex2f( 0, size[1])
-               glTexCoord2f(tc, tc/2+tc/2)
-               glVertex2f( bs, size[1])
-               #BottomRight
-               glTexCoord2f(tc+tc, tc/2)
-               glVertex2f( size[0], size[1] - bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0] - bs, size[1] - bs)
-               glTexCoord2f(tc, tc/2+tc/2)
-               glVertex2f( size[0] - bs, size[1])
-               glTexCoord2f(tc+tc, tc/2+tc/2)
-               glVertex2f( size[0], size[1])
-
-               #Center
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0]-bs, bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, size[1]-bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0]-bs, size[1]-bs)
-
-               #Right
-               glTexCoord2f(tc+tc, tc/2)
-               glVertex2f( size[0], bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0]-bs, bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0]-bs, size[1]-bs)
-               glTexCoord2f(tc+tc, tc/2)
-               glVertex2f( size[0], size[1]-bs)
-
-               #Left
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, bs)
-               glTexCoord2f(0, tc/2)
-               glVertex2f( 0, bs)
-               glTexCoord2f(0, tc/2)
-               glVertex2f( 0, size[1]-bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, size[1]-bs)
-
-               #Top
-               glTexCoord2f(tc, 0)
-               glVertex2f( size[0]-bs, 0)
-               glTexCoord2f(tc, 0)
-               glVertex2f( bs, 0)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0]-bs, bs)
-
-               #Bottom
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( size[0]-bs, size[1]-bs)
-               glTexCoord2f(tc, tc/2)
-               glVertex2f( bs, size[1]-bs)
-               glTexCoord2f(tc, tc/2+tc/2)
-               glVertex2f( bs, size[1])
-               glTexCoord2f(tc, tc/2+tc/2)
-               glVertex2f( size[0]-bs, size[1])
-
-               glEnd()
-               glDisable(GL_TEXTURE_2D)
-               glPopMatrix()
+               opengl.glDrawStretchedQuad(pos[0], pos[1], size[0], size[1], bs*0.75, 0)
                #Draw the controls on the frame
                super(glFrame, self).draw()
 
@@ -639,17 +698,65 @@ class glFrame(glGuiContainer):
                self._focus = False
                return False
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                if self._checkHit(x, y):
-                       super(glFrame, self).OnMouseDown(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
@@ -687,7 +794,7 @@ class glLabel(glGuiControl):
        def OnMouseMotion(self, x, y):
                return False
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                return False
 
 class glNumberCtrl(glGuiControl):
@@ -748,7 +855,7 @@ class glNumberCtrl(glGuiControl):
        def OnMouseMotion(self, x, y):
                return False
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                if self._checkHit(x, y):
                        self.setFocus()
                        return True
@@ -788,7 +895,7 @@ class glNumberCtrl(glGuiControl):
                if c == wx.WXK_DELETE:
                        self._value = self._value[0:self._selectPos] + self._value[self._selectPos + 1:]
                        self._callback(self._value)
-               if c == wx.WXK_TAB:
+               if c == wx.WXK_TAB or c == wx.WXK_NUMPAD_ENTER or c == wx.WXK_RETURN:
                        if wx.GetKeyState(wx.WXK_SHIFT):
                                self.focusPrevious()
                        else:
@@ -849,7 +956,7 @@ class glCheckbox(glGuiControl):
        def OnMouseMotion(self, x, y):
                return False
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                if self._checkHit(x, y):
                        self._value = not self._value
                        return True
@@ -867,10 +974,12 @@ class glSlider(glGuiControl):
 
        def setValue(self, value):
                self._value = value
-               self._value = max(self._minValue, self._value)
-               self._value = min(self._maxValue, self._value)
 
        def getValue(self):
+               if self._value < self._minValue:
+                       return self._minValue
+               if self._value > self._maxValue:
+                       return self._maxValue
                return self._value
 
        def setRange(self, minValue, maxValue):
@@ -878,8 +987,6 @@ class glSlider(glGuiControl):
                        maxValue = minValue
                self._minValue = minValue
                self._maxValue = maxValue
-               self._value = max(minValue, self._value)
-               self._value = min(maxValue, self._value)
 
        def getMinValue(self):
                return self._minValue
@@ -919,21 +1026,23 @@ class glSlider(glGuiControl):
                glVertex2f( w/2, h/2)
                glEnd()
                scrollLength = h - w
+               if self._maxValue-self._minValue != 0:
+                       valueNormalized = ((self.getValue()-self._minValue)/(self._maxValue-self._minValue))
+               else:
+                       valueNormalized = 0
                glTranslate(0.0,scrollLength/2,0)
-               if self._focus:
+               if True:  # self._focus:
                        glColor4ub(0,0,0,255)
                        glPushMatrix()
                        glTranslate(-w/2,opengl.glGetStringSize(str(self._minValue))[1]/2,0)
                        opengl.glDrawStringRight(str(self._minValue))
                        glTranslate(0,-scrollLength,0)
                        opengl.glDrawStringRight(str(self._maxValue))
-                       if self._maxValue-self._minValue > 0:
-                               glTranslate(w,scrollLength-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
-                       opengl.glDrawStringLeft(str(self._value))
+                       glTranslate(w,scrollLength-scrollLength*valueNormalized,0)
+                       opengl.glDrawStringLeft(str(self.getValue()))
                        glPopMatrix()
                glColor4ub(255,255,255,240)
-               if self._maxValue - self._minValue != 0:
-                       glTranslate(0.0,-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
+               glTranslate(0.0,-scrollLength*valueNormalized,0)
                glBegin(GL_QUADS)
                glVertex2f( w/2,-w/2)
                glVertex2f(-w/2,-w/2)
@@ -967,7 +1076,7 @@ class glSlider(glGuiControl):
                self._focus = False
                return False
 
-       def OnMouseDown(self, x, y):
+       def OnMouseDown(self, x, y, button):
                if self._checkHit(x, y):
                        self.setFocus()
                        self.OnMouseMotion(x, y)