1 from __future__ import absolute_import
2 from __future__ import division
10 from wx import glcanvas
12 OpenGL.ERROR_CHECKING = False
13 from OpenGL.GL import *
15 from Cura.gui.util import opengl
17 class animation(object):
18 def __init__(self, gui, start, end, runTime):
21 self._startTime = time.time()
22 self._runTime = runTime
23 gui._animationList.append(self)
26 return time.time() > self._startTime + self._runTime
28 def getPosition(self):
31 f = (time.time() - self._startTime) / self._runTime
34 #f = 6*tc*ts + -15*ts*ts + 10*tc
36 return self._start + (self._end - self._start) * f
38 class glGuiControl(object):
39 def __init__(self, parent, pos):
41 self._base = parent._base
43 self._size = (0,0, 1, 1)
44 self._parent.add(self)
46 def setSize(self, x, y, w, h):
47 self._size = (x, y, w, h)
55 def updateLayout(self):
59 for n in xrange(self._parent._glGuiControlList.index(self) + 1, len(self._parent._glGuiControlList)):
60 if self._parent._glGuiControlList[n].setFocus():
62 for n in xrange(0, self._parent._glGuiControlList.index(self)):
63 if self._parent._glGuiControlList[n].setFocus():
66 def focusPrevious(self):
67 for n in xrange(self._parent._glGuiControlList.index(self) -1, -1, -1):
68 if self._parent._glGuiControlList[n].setFocus():
70 for n in xrange(len(self._parent._glGuiControlList) - 1, self._parent._glGuiControlList.index(self), -1):
71 if self._parent._glGuiControlList[n].setFocus():
78 return self._base._focus == self
80 def OnMouseUp(self, x, y):
83 def OnKeyChar(self, key):
86 class glGuiContainer(glGuiControl):
87 def __init__(self, parent, pos):
88 self._glGuiControlList = []
89 glGuiLayoutButtons(self)
90 super(glGuiContainer, self).__init__(parent, pos)
93 self._glGuiControlList.append(ctrl)
96 def OnMouseDown(self, x, y, button):
97 for ctrl in self._glGuiControlList:
98 if ctrl.OnMouseDown(x, y, button):
102 def OnMouseUp(self, x, y):
103 for ctrl in self._glGuiControlList:
104 if ctrl.OnMouseUp(x, y):
108 def OnMouseMotion(self, x, y):
110 for ctrl in self._glGuiControlList:
111 if ctrl.OnMouseMotion(x, y):
116 for ctrl in self._glGuiControlList:
119 def updateLayout(self):
120 self._layout.update()
121 for ctrl in self._glGuiControlList:
124 class glGuiPanel(glcanvas.GLCanvas):
125 def __init__(self, parent):
126 attribList = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 32, glcanvas.WX_GL_STENCIL_SIZE, 8)
127 glcanvas.GLCanvas.__init__(self, parent, style=wx.WANTS_CHARS, attribList = attribList)
130 self._container = None
131 self._container = glGuiContainer(self, (0,0))
132 self._shownError = False
134 self._context = glcanvas.GLContext(self)
135 self._glButtonsTexture = None
136 self._glRobotTexture = None
137 self._buttonSize = 64
139 self._animationList = []
140 self.glReleaseList = []
142 wx.EVT_PAINT(self, self._OnGuiPaint)
143 wx.EVT_SIZE(self, self._OnSize)
144 wx.EVT_ERASE_BACKGROUND(self, self._OnEraseBackground)
145 wx.EVT_LEFT_DOWN(self, self._OnGuiMouseDown)
146 wx.EVT_LEFT_DCLICK(self, self._OnGuiMouseDown)
147 wx.EVT_LEFT_UP(self, self._OnGuiMouseUp)
148 wx.EVT_RIGHT_DOWN(self, self._OnGuiMouseDown)
149 wx.EVT_RIGHT_DCLICK(self, self._OnGuiMouseDown)
150 wx.EVT_RIGHT_UP(self, self._OnGuiMouseUp)
151 wx.EVT_MIDDLE_DOWN(self, self._OnGuiMouseDown)
152 wx.EVT_MIDDLE_DCLICK(self, self._OnGuiMouseDown)
153 wx.EVT_MIDDLE_UP(self, self._OnGuiMouseUp)
154 wx.EVT_MOTION(self, self._OnGuiMouseMotion)
155 wx.EVT_CHAR(self, self._OnGuiKeyChar)
156 wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
157 wx.EVT_IDLE(self, self._OnIdle)
159 def _OnIdle(self, e):
160 if len(self._animationList) > 0:
161 for anim in self._animationList:
163 self._animationList.remove(anim)
166 def _OnGuiKeyChar(self, e):
167 if self._focus is not None:
168 self._focus.OnKeyChar(e.GetKeyCode())
171 self.OnKeyChar(e.GetKeyCode())
173 def OnFocusLost(self, e):
177 def _OnGuiMouseDown(self,e):
179 if self._container.OnMouseDown(e.GetX(), e.GetY(), e.GetButton()):
184 def _OnGuiMouseUp(self, e):
185 if self._container.OnMouseUp(e.GetX(), e.GetY()):
190 def _OnGuiMouseMotion(self,e):
192 if not self._container.OnMouseMotion(e.GetX(), e.GetY()):
193 self.OnMouseMotion(e)
195 def _OnGuiPaint(self, e):
196 h = self.GetSize().GetHeight()
197 w = self.GetSize().GetWidth()
198 oldButtonSize = self._buttonSize
202 self._buttonSize = 32
204 self._buttonSize = 48
206 self._buttonSize = 64
208 self._buttonSize = 80
210 self._buttonSize = 96
211 if self._buttonSize != oldButtonSize:
212 self._container.updateLayout()
214 dc = wx.PaintDC(self)
216 self.SetCurrent(self._context)
217 for obj in self.glReleaseList:
219 del self.glReleaseList[:]
225 errStr = 'An error has occurred during the 3D view drawing.'
226 tb = traceback.extract_tb(sys.exc_info()[2])
227 errStr += "\n%s: '%s'" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]))
228 for n in xrange(len(tb)-1, -1, -1):
230 errStr += "\n @ %s:%s:%d" % (os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
231 if not self._shownError:
232 wx.CallAfter(wx.MessageBox, errStr, '3D window error', wx.OK | wx.ICON_EXCLAMATION)
233 self._shownError = True
236 if self._glButtonsTexture is None:
237 self._glButtonsTexture = opengl.loadGLTexture('glButtons.png')
238 self._glRobotTexture = opengl.loadGLTexture('UltimakerRobot.png')
240 glDisable(GL_DEPTH_TEST)
242 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
243 glDisable(GL_LIGHTING)
244 glColor4ub(255,255,255,255)
246 glMatrixMode(GL_PROJECTION)
248 size = self.GetSize()
249 glOrtho(0, size.GetWidth()-1, size.GetHeight()-1, 0, -1000.0, 1000.0)
250 glMatrixMode(GL_MODELVIEW)
253 self._container.draw()
255 glBindTexture(GL_TEXTURE_2D, self._glRobotTexture)
256 glEnable(GL_TEXTURE_2D)
259 glTranslate(size.GetWidth() - 8,size.GetHeight() - 16,0)
260 s = self._buttonSize * 1.4
272 glDisable(GL_TEXTURE_2D)
275 def _OnEraseBackground(self,event):
276 #Workaround for windows background redraw flicker.
280 self._container.setSize(0, 0, self.GetSize().GetWidth(), self.GetSize().GetHeight())
281 self._container.updateLayout()
284 def OnMouseDown(self,e):
286 def OnMouseUp(self,e):
288 def OnMouseMotion(self, e):
290 def OnKeyChar(self, keyCode):
292 def OnPaint(self, e):
296 if self._container is not None:
297 self._container.add(ctrl)
299 class glGuiLayoutButtons(object):
300 def __init__(self, parent):
301 self._parent = parent
302 self._parent._layout = self
305 bs = self._parent._base._buttonSize
306 x0, y0, w, h = self._parent.getSize()
308 for ctrl in self._parent._glGuiControlList:
311 x = w + pos[0] * gridSize - bs * 0.2
313 x = pos[0] * gridSize + bs * 0.2
315 y = h + pos[1] * gridSize * 1.2 - bs * 0.2
317 y = pos[1] * gridSize * 1.2 + bs * 0.2
318 ctrl.setSize(x, y, gridSize, gridSize)
320 def getLayoutSize(self):
321 _, _, w, h = self._parent.getSize()
324 class glGuiLayoutGrid(object):
325 def __init__(self, parent):
326 self._parent = parent
327 self._parent._layout = self
329 self._alignBottom = True
332 borderSize = self._parent._base._buttonSize * 0.2
333 x0, y0, w, h = self._parent.getSize()
338 for ctrl in self._parent._glGuiControlList:
340 w, h = ctrl.getMinSize()
344 widths[x] = max(widths[x], w)
348 heights[y] = max(heights[y], h)
349 self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
350 if self._alignBottom:
351 y0 -= self._size[1] - self._parent.getSize()[3]
352 self._parent.setSize(x0 - borderSize, y0 - borderSize, self._size[0], self._size[1])
353 for ctrl in self._parent._glGuiControlList:
357 for n in xrange(0, x):
361 for n in xrange(0, y):
365 ctrl.setSize(x1, y1, widths[x], heights[y])
367 def getLayoutSize(self):
370 class glButton(glGuiControl):
371 def __init__(self, parent, imageID, tooltip, pos, callback, size = None):
372 self._buttonSize = size
373 super(glButton, self).__init__(parent, pos)
374 self._tooltip = tooltip
375 self._parent = parent
376 self._imageID = imageID
377 self._callback = callback
378 self._selected = False
381 self._disabled = False
382 self._showExpandArrow = False
383 self._progressBar = 0.0
385 def setSelected(self, value):
386 self._selected = value
388 def setExpandArrow(self, value):
389 self._showExpandArrow = value
391 def setHidden(self, value):
394 def setDisabled(self, value):
395 self._disabled = value
397 def setProgressBar(self, value):
398 self._progressBar = value
400 def getSelected(self):
401 return self._selected
403 def getMinSize(self):
404 if self._buttonSize is not None:
405 return self._buttonSize, self._buttonSize
406 return self._base._buttonSize, self._base._buttonSize
408 def _getPixelPos(self):
409 x0, y0, w, h = self.getSize()
410 return x0 + w / 2, y0 + h / 2
416 cx = (self._imageID % 4) / 4
417 cy = int(self._imageID / 4) / 4
418 bs = self.getMinSize()[0]
419 pos = self._getPixelPos()
421 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
428 glColor4ub(128,128,128,128)
430 glColor4ub(255,255,255,255)
431 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, 0)
432 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
433 if self._showExpandArrow:
435 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)
437 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)
439 glTranslatef(pos[0], pos[1], 0)
440 glDisable(GL_TEXTURE_2D)
442 glTranslatef(0, -0.55*bs*scale, 0)
445 glColor4ub(60,60,60,255)
446 glTranslatef(-1, -1, 0)
447 opengl.glDrawStringCenter(self._tooltip)
448 glTranslatef(0, 2, 0)
449 opengl.glDrawStringCenter(self._tooltip)
450 glTranslatef(2, 0, 0)
451 opengl.glDrawStringCenter(self._tooltip)
452 glTranslatef(0, -2, 0)
453 opengl.glDrawStringCenter(self._tooltip)
456 glColor4ub(255,255,255,255)
457 opengl.glDrawStringCenter(self._tooltip)
459 if 0.0 < self._progressBar < 1.0:
460 glColor4ub(255,255,255,192)
462 opengl.glDrawTexturedQuad(pos[0]-bs/2, pos[1]+bs/2, bs, bs / 4, 0)
463 opengl.glDrawTexturedQuad(pos[0]-bs/2, pos[1]+bs/2, bs * self._progressBar, bs / 4, 0)
466 def _checkHit(self, x, y):
467 if self._hidden or self._disabled:
469 bs = self.getMinSize()[0]
470 pos = self._getPixelPos()
471 return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5
473 def OnMouseMotion(self, x, y):
474 if self._checkHit(x, y):
480 def OnMouseDown(self, x, y, button):
481 if self._checkHit(x, y):
482 self._callback(button)
486 class glRadioButton(glButton):
487 def __init__(self, parent, imageID, tooltip, pos, group, callback):
488 super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
490 self._radioCallback = callback
491 self._group.append(self)
493 def setSelected(self, value):
494 self._selected = value
496 def _onRadioSelect(self, button):
497 self._base._focus = None
498 for ctrl in self._group:
500 ctrl.setSelected(False)
501 if self.getSelected():
502 self.setSelected(False)
504 self.setSelected(True)
505 self._radioCallback(button)
507 class glComboButton(glButton):
508 def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
509 super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
510 self._imageIDs = imageIDs
511 self._tooltips = tooltips
512 self._comboCallback = callback
515 def _onComboOpenSelect(self):
517 self._base._focus = None
519 self._base._focus = self
524 self._selected = self.hasFocus()
525 super(glComboButton, self).draw()
527 bs = self._base._buttonSize / 2
528 pos = self._getPixelPos()
530 if not self._selected:
534 glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
535 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
536 for n in xrange(0, len(self._imageIDs)):
537 glTranslatef(0, bs, 0)
538 glColor4ub(255,255,255,255)
539 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
540 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
541 glDisable(GL_TEXTURE_2D)
544 glTranslatef(-0.55*bs, 0.1*bs, 0)
547 glColor4ub(60,60,60,255)
548 glTranslatef(-1, -1, 0)
549 opengl.glDrawStringRight(self._tooltips[n])
550 glTranslatef(0, 2, 0)
551 opengl.glDrawStringRight(self._tooltips[n])
552 glTranslatef(2, 0, 0)
553 opengl.glDrawStringRight(self._tooltips[n])
554 glTranslatef(0, -2, 0)
555 opengl.glDrawStringRight(self._tooltips[n])
558 glColor4ub(255,255,255,255)
559 opengl.glDrawStringRight(self._tooltips[n])
564 return self._selection
566 def setValue(self, value):
567 self._selection = value
568 self._imageID = self._imageIDs[self._selection]
569 self._comboCallback()
571 def OnMouseDown(self, x, y, button):
572 if self._hidden or self._disabled:
575 bs = self._base._buttonSize / 2
576 pos = self._getPixelPos()
577 if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
578 self._selection = int((y - pos[1] - bs) / bs)
579 self._imageID = self._imageIDs[self._selection]
580 self._base._focus = None
581 self._comboCallback()
583 return super(glComboButton, self).OnMouseDown(x, y, button)
585 class glFrame(glGuiContainer):
586 def __init__(self, parent, pos):
587 super(glFrame, self).__init__(parent, pos)
588 self._selected = False
592 def setSelected(self, value):
593 self._selected = value
595 def setHidden(self, value):
598 def getSelected(self):
599 return self._selected
601 def getMinSize(self):
602 return self._base._buttonSize, self._base._buttonSize
604 def _getPixelPos(self):
605 x0, y0, w, h = self.getSize()
612 bs = self._parent._buttonSize
613 pos = self._getPixelPos()
615 size = self._layout.getLayoutSize()
616 glColor4ub(255,255,255,255)
617 opengl.glDrawStretchedQuad(pos[0], pos[1], size[0], size[1], bs*0.75, 0)
618 #Draw the controls on the frame
619 super(glFrame, self).draw()
621 def _checkHit(self, x, y):
624 pos = self._getPixelPos()
625 w, h = self._layout.getLayoutSize()
626 return 0 <= x - pos[0] <= w and 0 <= y - pos[1] <= h
628 def OnMouseMotion(self, x, y):
629 super(glFrame, self).OnMouseMotion(x, y)
630 if self._checkHit(x, y):
636 def OnMouseDown(self, x, y, button):
637 if self._checkHit(x, y):
638 super(glFrame, self).OnMouseDown(x, y, button)
642 class glNotification(glFrame):
643 def __init__(self, parent, pos):
645 super(glNotification, self).__init__(parent, pos)
646 glGuiLayoutGrid(self)._alignBottom = False
647 self._label = glLabel(self, "Notification", (0, 0))
648 self._button = glButton(self, 30, "", (1, 0), self.onClose, 25)
649 self._padding = glLabel(self, "", (0, 1))
652 def setSize(self, x, y, w, h):
653 w, h = self._layout.getLayoutSize()
654 baseSize = self._base.GetSizeTuple()
655 if self._anim is not None:
656 super(glNotification, self).setSize(baseSize[0] / 2 - w / 2, baseSize[1] - self._anim.getPosition() - self._base._buttonSize * 0.2, 1, 1)
658 super(glNotification, self).setSize(baseSize[0] / 2 - w / 2, baseSize[1] - self._base._buttonSize * 0.2, 1, 1)
661 self.setSize(0,0,0,0)
663 super(glNotification, self).draw()
665 def message(self, text):
666 if self._anim is not None:
667 self._anim = animation(self._base, self._anim.getPosition(), 25, 1)
669 self._anim = animation(self._base, -20, 25, 1)
670 self.setHidden(False)
671 self._label.setLabel(text)
674 def onClose(self, button):
675 if self._anim is not None:
676 self._anim = animation(self._base, self._anim.getPosition(), -20, 1)
678 self._anim = animation(self._base, 25, -20, 1)
680 class glLabel(glGuiControl):
681 def __init__(self, parent, label, pos):
683 super(glLabel, self).__init__(parent, pos)
685 def setLabel(self, label):
688 def getMinSize(self):
689 w, h = opengl.glGetStringSize(self._label)
692 def _getPixelPos(self):
693 x0, y0, w, h = self.getSize()
697 x, y, w, h = self.getSize()
700 glTranslatef(x, y, 0)
702 # glColor4ub(255,255,255,128)
714 glTranslate(5, h - 5, 0)
715 glColor4ub(255,255,255,255)
716 opengl.glDrawStringLeft(self._label)
719 def _checkHit(self, x, y):
722 def OnMouseMotion(self, x, y):
725 def OnMouseDown(self, x, y, button):
728 class glNumberCtrl(glGuiControl):
729 def __init__(self, parent, value, pos, callback):
730 self._callback = callback
731 self._value = str(value)
734 self._inCallback = False
735 super(glNumberCtrl, self).__init__(parent, pos)
737 def setValue(self, value):
740 self._value = str(value)
742 def getMinSize(self):
743 w, h = opengl.glGetStringSize("VALUES")
746 def _getPixelPos(self):
747 x0, y0, w, h = self.getSize()
751 x, y, w, h = self.getSize()
754 glTranslatef(x, y, 0)
757 glColor4ub(255,255,255,255)
759 glColor4ub(255,255,255,192)
771 glTranslate(5, h - 5, 0)
772 glColor4ub(0,0,0,255)
773 opengl.glDrawStringLeft(self._value)
775 glTranslate(opengl.glGetStringSize(self._value[0:self._selectPos])[0] - 2, -1, 0)
776 opengl.glDrawStringLeft('|')
779 def _checkHit(self, x, y):
780 x1, y1, w, h = self.getSize()
781 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
783 def OnMouseMotion(self, x, y):
786 def OnMouseDown(self, x, y, button):
787 if self._checkHit(x, y):
792 def OnKeyChar(self, c):
793 self._inCallback = True
796 self._selectPos = max(0, self._selectPos)
797 if c == wx.WXK_RIGHT:
799 self._selectPos = min(self._selectPos, len(self._value))
802 value = float(self._value)
807 self._value = str(value)
808 self._callback(self._value)
811 value = float(self._value)
817 self._value = str(value)
818 self._callback(self._value)
819 if c == wx.WXK_BACK and self._selectPos > 0:
820 self._value = self._value[0:self._selectPos - 1] + self._value[self._selectPos:]
822 self._callback(self._value)
823 if c == wx.WXK_DELETE:
824 self._value = self._value[0:self._selectPos] + self._value[self._selectPos + 1:]
825 self._callback(self._value)
826 if c == wx.WXK_TAB or c == wx.WXK_NUMPAD_ENTER or c == wx.WXK_RETURN:
827 if wx.GetKeyState(wx.WXK_SHIFT):
831 if (ord('0') <= c <= ord('9') or c == ord('.')) and len(self._value) < self._maxLen:
832 self._value = self._value[0:self._selectPos] + chr(c) + self._value[self._selectPos:]
834 self._callback(self._value)
835 self._inCallback = False
838 self._base._focus = self
839 self._selectPos = len(self._value)
842 class glCheckbox(glGuiControl):
843 def __init__(self, parent, value, pos, callback):
844 self._callback = callback
848 self._inCallback = False
849 super(glCheckbox, self).__init__(parent, pos)
851 def setValue(self, value):
854 self._value = str(value)
859 def getMinSize(self):
862 def _getPixelPos(self):
863 x0, y0, w, h = self.getSize()
867 x, y, w, h = self.getSize()
870 glTranslatef(x, y, 0)
872 glColor3ub(255,255,255)
874 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 28)
876 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 29)
880 def _checkHit(self, x, y):
881 x1, y1, w, h = self.getSize()
882 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
884 def OnMouseMotion(self, x, y):
887 def OnMouseDown(self, x, y, button):
888 if self._checkHit(x, y):
889 self._value = not self._value
893 class glSlider(glGuiControl):
894 def __init__(self, parent, value, minValue, maxValue, pos, callback):
895 super(glSlider, self).__init__(parent, pos)
896 self._callback = callback
900 self._minValue = minValue
901 self._maxValue = maxValue
903 def setValue(self, value):
905 self._value = max(self._minValue, self._value)
906 self._value = min(self._maxValue, self._value)
911 def setRange(self, minValue, maxValue):
912 if maxValue < minValue:
914 self._minValue = minValue
915 self._maxValue = maxValue
916 self._value = max(minValue, self._value)
917 self._value = min(maxValue, self._value)
919 def getMinValue(self):
920 return self._minValue
922 def getMaxValue(self):
923 return self._maxValue
925 def setHidden(self, value):
928 def getMinSize(self):
929 return self._base._buttonSize * 0.2, self._base._buttonSize * 4
931 def _getPixelPos(self):
932 x0, y0, w, h = self.getSize()
933 minSize = self.getMinSize()
934 return x0 + w / 2 - minSize[0] / 2, y0 + h / 2 - minSize[1] / 2
940 w, h = self.getMinSize()
941 pos = self._getPixelPos()
944 glTranslatef(pos[0], pos[1], 0)
945 glDisable(GL_TEXTURE_2D)
947 glColor4ub(60,60,60,255)
949 glColor4ub(60,60,60,192)
951 glVertex2f( w/2,-h/2)
952 glVertex2f(-w/2,-h/2)
953 glVertex2f(-w/2, h/2)
954 glVertex2f( w/2, h/2)
957 glTranslate(0.0,scrollLength/2,0)
959 glColor4ub(0,0,0,255)
961 glTranslate(-w/2,opengl.glGetStringSize(str(self._minValue))[1]/2,0)
962 opengl.glDrawStringRight(str(self._minValue))
963 glTranslate(0,-scrollLength,0)
964 opengl.glDrawStringRight(str(self._maxValue))
965 if self._maxValue-self._minValue > 0:
966 glTranslate(w,scrollLength-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
967 opengl.glDrawStringLeft(str(self._value))
969 glColor4ub(255,255,255,240)
970 if self._maxValue - self._minValue != 0:
971 glTranslate(0.0,-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
973 glVertex2f( w/2,-w/2)
974 glVertex2f(-w/2,-w/2)
975 glVertex2f(-w/2, w/2)
976 glVertex2f( w/2, w/2)
980 def _checkHit(self, x, y):
983 pos = self._getPixelPos()
984 w, h = self.getMinSize()
985 return -w/2 <= x - pos[0] <= w/2 and -h/2 <= y - pos[1] <= h/2
988 self._base._focus = self
991 def OnMouseMotion(self, x, y):
993 w, h = self.getMinSize()
995 pos = self._getPixelPos()
996 self.setValue(int(self._minValue + (self._maxValue - self._minValue) * -(y - pos[1] - scrollLength/2) / scrollLength))
999 if self._checkHit(x, y):
1005 def OnMouseDown(self, x, y, button):
1006 if self._checkHit(x, y):
1008 self.OnMouseMotion(x, y)
1012 def OnMouseUp(self, x, y):
1014 self._base._focus = None