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):
294 def OnKeyChar(self, keycode):
298 if self._container is not None:
299 self._container.add(ctrl)
301 class glGuiLayoutButtons(object):
302 def __init__(self, parent):
303 self._parent = parent
304 self._parent._layout = self
307 bs = self._parent._base._buttonSize
308 x0, y0, w, h = self._parent.getSize()
310 for ctrl in self._parent._glGuiControlList:
313 x = w + pos[0] * gridSize - bs * 0.2
315 x = pos[0] * gridSize + bs * 0.2
317 y = h + pos[1] * gridSize * 1.2 - bs * 0.2
319 y = pos[1] * gridSize * 1.2 + bs * 0.2
320 ctrl.setSize(x, y, gridSize, gridSize)
322 def getLayoutSize(self):
323 _, _, w, h = self._parent.getSize()
326 class glGuiLayoutGrid(object):
327 def __init__(self, parent):
328 self._parent = parent
329 self._parent._layout = self
331 self._alignBottom = True
334 borderSize = self._parent._base._buttonSize * 0.2
335 x0, y0, w, h = self._parent.getSize()
340 for ctrl in self._parent._glGuiControlList:
342 w, h = ctrl.getMinSize()
346 widths[x] = max(widths[x], w)
350 heights[y] = max(heights[y], h)
351 self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
352 if self._alignBottom:
353 y0 -= self._size[1] - self._parent.getSize()[3]
354 self._parent.setSize(x0 - borderSize, y0 - borderSize, self._size[0], self._size[1])
355 for ctrl in self._parent._glGuiControlList:
359 for n in xrange(0, x):
363 for n in xrange(0, y):
367 ctrl.setSize(x1, y1, widths[x], heights[y])
369 def getLayoutSize(self):
372 class glButton(glGuiControl):
373 def __init__(self, parent, imageID, tooltip, pos, callback, size = None):
374 self._buttonSize = size
375 super(glButton, self).__init__(parent, pos)
376 self._tooltip = tooltip
377 self._parent = parent
378 self._imageID = imageID
379 self._callback = callback
380 self._selected = False
383 self._disabled = False
384 self._showExpandArrow = False
385 self._progressBar = 0.0
387 def setSelected(self, value):
388 self._selected = value
390 def setExpandArrow(self, value):
391 self._showExpandArrow = value
393 def setHidden(self, value):
396 def setDisabled(self, value):
397 self._disabled = value
399 def setProgressBar(self, value):
400 self._progressBar = value
402 def getSelected(self):
403 return self._selected
405 def getMinSize(self):
406 if self._buttonSize is not None:
407 return self._buttonSize, self._buttonSize
408 return self._base._buttonSize, self._base._buttonSize
410 def _getPixelPos(self):
411 x0, y0, w, h = self.getSize()
412 return x0 + w / 2, y0 + h / 2
418 cx = (self._imageID % 4) / 4
419 cy = int(self._imageID / 4) / 4
420 bs = self.getMinSize()[0]
421 pos = self._getPixelPos()
423 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
430 glColor4ub(128,128,128,128)
432 glColor4ub(255,255,255,255)
433 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, 0)
434 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
435 if self._showExpandArrow:
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)
439 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)
441 glTranslatef(pos[0], pos[1], 0)
442 glDisable(GL_TEXTURE_2D)
444 glTranslatef(0, -0.55*bs*scale, 0)
447 glColor4ub(60,60,60,255)
448 glTranslatef(-1, -1, 0)
449 opengl.glDrawStringCenter(self._tooltip)
450 glTranslatef(0, 2, 0)
451 opengl.glDrawStringCenter(self._tooltip)
452 glTranslatef(2, 0, 0)
453 opengl.glDrawStringCenter(self._tooltip)
454 glTranslatef(0, -2, 0)
455 opengl.glDrawStringCenter(self._tooltip)
458 glColor4ub(255,255,255,255)
459 opengl.glDrawStringCenter(self._tooltip)
461 if 0.0 < self._progressBar < 1.0:
462 glColor4ub(255,255,255,192)
464 opengl.glDrawTexturedQuad(pos[0]-bs/2, pos[1]+bs/2, bs, bs / 4, 0)
465 opengl.glDrawTexturedQuad(pos[0]-bs/2, pos[1]+bs/2, bs * self._progressBar, bs / 4, 0)
468 def _checkHit(self, x, y):
469 if self._hidden or self._disabled:
471 bs = self.getMinSize()[0]
472 pos = self._getPixelPos()
473 return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5
475 def OnMouseMotion(self, x, y):
476 if self._checkHit(x, y):
482 def OnMouseDown(self, x, y, button):
483 if self._checkHit(x, y):
484 self._callback(button)
488 class glRadioButton(glButton):
489 def __init__(self, parent, imageID, tooltip, pos, group, callback):
490 super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
492 self._radioCallback = callback
493 self._group.append(self)
495 def setSelected(self, value):
496 self._selected = value
498 def _onRadioSelect(self, button):
499 self._base._focus = None
500 for ctrl in self._group:
502 ctrl.setSelected(False)
503 if self.getSelected():
504 self.setSelected(False)
506 self.setSelected(True)
507 self._radioCallback(button)
509 class glComboButton(glButton):
510 def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
511 super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
512 self._imageIDs = imageIDs
513 self._tooltips = tooltips
514 self._comboCallback = callback
517 def _onComboOpenSelect(self):
519 self._base._focus = None
521 self._base._focus = self
526 self._selected = self.hasFocus()
527 super(glComboButton, self).draw()
529 bs = self._base._buttonSize / 2
530 pos = self._getPixelPos()
532 if not self._selected:
536 glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
537 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
538 for n in xrange(0, len(self._imageIDs)):
539 glTranslatef(0, bs, 0)
540 glColor4ub(255,255,255,255)
541 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
542 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
543 glDisable(GL_TEXTURE_2D)
546 glTranslatef(-0.55*bs, 0.1*bs, 0)
549 glColor4ub(60,60,60,255)
550 glTranslatef(-1, -1, 0)
551 opengl.glDrawStringRight(self._tooltips[n])
552 glTranslatef(0, 2, 0)
553 opengl.glDrawStringRight(self._tooltips[n])
554 glTranslatef(2, 0, 0)
555 opengl.glDrawStringRight(self._tooltips[n])
556 glTranslatef(0, -2, 0)
557 opengl.glDrawStringRight(self._tooltips[n])
560 glColor4ub(255,255,255,255)
561 opengl.glDrawStringRight(self._tooltips[n])
566 return self._selection
568 def setValue(self, value):
569 self._selection = value
570 self._imageID = self._imageIDs[self._selection]
571 self._comboCallback()
573 def OnMouseDown(self, x, y, button):
574 if self._hidden or self._disabled:
577 bs = self._base._buttonSize / 2
578 pos = self._getPixelPos()
579 if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
580 self._selection = int((y - pos[1] - bs) / bs)
581 self._imageID = self._imageIDs[self._selection]
582 self._base._focus = None
583 self._comboCallback()
585 return super(glComboButton, self).OnMouseDown(x, y, button)
587 class glFrame(glGuiContainer):
588 def __init__(self, parent, pos):
589 super(glFrame, self).__init__(parent, pos)
590 self._selected = False
594 def setSelected(self, value):
595 self._selected = value
597 def setHidden(self, value):
600 def getSelected(self):
601 return self._selected
603 def getMinSize(self):
604 return self._base._buttonSize, self._base._buttonSize
606 def _getPixelPos(self):
607 x0, y0, w, h = self.getSize()
614 bs = self._parent._buttonSize
615 pos = self._getPixelPos()
617 size = self._layout.getLayoutSize()
618 glColor4ub(255,255,255,255)
619 opengl.glDrawStretchedQuad(pos[0], pos[1], size[0], size[1], bs*0.75, 0)
620 #Draw the controls on the frame
621 super(glFrame, self).draw()
623 def _checkHit(self, x, y):
626 pos = self._getPixelPos()
627 w, h = self._layout.getLayoutSize()
628 return 0 <= x - pos[0] <= w and 0 <= y - pos[1] <= h
630 def OnMouseMotion(self, x, y):
631 super(glFrame, self).OnMouseMotion(x, y)
632 if self._checkHit(x, y):
638 def OnMouseDown(self, x, y, button):
639 if self._checkHit(x, y):
640 super(glFrame, self).OnMouseDown(x, y, button)
644 class glNotification(glFrame):
645 def __init__(self, parent, pos):
647 super(glNotification, self).__init__(parent, pos)
648 glGuiLayoutGrid(self)._alignBottom = False
649 self._label = glLabel(self, "Notification", (0, 0))
650 self._button = glButton(self, 30, "", (1, 0), self.onClose, 25)
651 self._padding = glLabel(self, "", (0, 1))
654 def setSize(self, x, y, w, h):
655 w, h = self._layout.getLayoutSize()
656 baseSize = self._base.GetSizeTuple()
657 if self._anim is not None:
658 super(glNotification, self).setSize(baseSize[0] / 2 - w / 2, baseSize[1] - self._anim.getPosition() - self._base._buttonSize * 0.2, 1, 1)
660 super(glNotification, self).setSize(baseSize[0] / 2 - w / 2, baseSize[1] - self._base._buttonSize * 0.2, 1, 1)
663 self.setSize(0,0,0,0)
665 super(glNotification, self).draw()
667 def message(self, text):
668 if self._anim is not None:
669 self._anim = animation(self._base, self._anim.getPosition(), 25, 1)
671 self._anim = animation(self._base, -20, 25, 1)
672 self.setHidden(False)
673 self._label.setLabel(text)
676 def onClose(self, button):
677 if self._anim is not None:
678 self._anim = animation(self._base, self._anim.getPosition(), -20, 1)
680 self._anim = animation(self._base, 25, -20, 1)
682 class glLabel(glGuiControl):
683 def __init__(self, parent, label, pos):
685 super(glLabel, self).__init__(parent, pos)
687 def setLabel(self, label):
690 def getMinSize(self):
691 w, h = opengl.glGetStringSize(self._label)
694 def _getPixelPos(self):
695 x0, y0, w, h = self.getSize()
699 x, y, w, h = self.getSize()
702 glTranslatef(x, y, 0)
704 # glColor4ub(255,255,255,128)
716 glTranslate(5, h - 5, 0)
717 glColor4ub(255,255,255,255)
718 opengl.glDrawStringLeft(self._label)
721 def _checkHit(self, x, y):
724 def OnMouseMotion(self, x, y):
727 def OnMouseDown(self, x, y, button):
730 class glNumberCtrl(glGuiControl):
731 def __init__(self, parent, value, pos, callback):
732 self._callback = callback
733 self._value = str(value)
736 self._inCallback = False
737 super(glNumberCtrl, self).__init__(parent, pos)
739 def setValue(self, value):
742 self._value = str(value)
744 def getMinSize(self):
745 w, h = opengl.glGetStringSize("VALUES")
748 def _getPixelPos(self):
749 x0, y0, w, h = self.getSize()
753 x, y, w, h = self.getSize()
756 glTranslatef(x, y, 0)
759 glColor4ub(255,255,255,255)
761 glColor4ub(255,255,255,192)
773 glTranslate(5, h - 5, 0)
774 glColor4ub(0,0,0,255)
775 opengl.glDrawStringLeft(self._value)
777 glTranslate(opengl.glGetStringSize(self._value[0:self._selectPos])[0] - 2, -1, 0)
778 opengl.glDrawStringLeft('|')
781 def _checkHit(self, x, y):
782 x1, y1, w, h = self.getSize()
783 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
785 def OnMouseMotion(self, x, y):
788 def OnMouseDown(self, x, y, button):
789 if self._checkHit(x, y):
794 def OnKeyChar(self, c):
795 self._inCallback = True
798 self._selectPos = max(0, self._selectPos)
799 if c == wx.WXK_RIGHT:
801 self._selectPos = min(self._selectPos, len(self._value))
804 value = float(self._value)
809 self._value = str(value)
810 self._callback(self._value)
813 value = float(self._value)
819 self._value = str(value)
820 self._callback(self._value)
821 if c == wx.WXK_BACK and self._selectPos > 0:
822 self._value = self._value[0:self._selectPos - 1] + self._value[self._selectPos:]
824 self._callback(self._value)
825 if c == wx.WXK_DELETE:
826 self._value = self._value[0:self._selectPos] + self._value[self._selectPos + 1:]
827 self._callback(self._value)
828 if c == wx.WXK_TAB or c == wx.WXK_NUMPAD_ENTER or c == wx.WXK_RETURN:
829 if wx.GetKeyState(wx.WXK_SHIFT):
833 if (ord('0') <= c <= ord('9') or c == ord('.')) and len(self._value) < self._maxLen:
834 self._value = self._value[0:self._selectPos] + chr(c) + self._value[self._selectPos:]
836 self._callback(self._value)
837 self._inCallback = False
840 self._base._focus = self
841 self._selectPos = len(self._value)
844 class glCheckbox(glGuiControl):
845 def __init__(self, parent, value, pos, callback):
846 self._callback = callback
850 self._inCallback = False
851 super(glCheckbox, self).__init__(parent, pos)
853 def setValue(self, value):
856 self._value = str(value)
861 def getMinSize(self):
864 def _getPixelPos(self):
865 x0, y0, w, h = self.getSize()
869 x, y, w, h = self.getSize()
872 glTranslatef(x, y, 0)
874 glColor3ub(255,255,255)
876 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 28)
878 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 29)
882 def _checkHit(self, x, y):
883 x1, y1, w, h = self.getSize()
884 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
886 def OnMouseMotion(self, x, y):
889 def OnMouseDown(self, x, y, button):
890 if self._checkHit(x, y):
891 self._value = not self._value
895 class glSlider(glGuiControl):
896 def __init__(self, parent, value, minValue, maxValue, pos, callback):
897 super(glSlider, self).__init__(parent, pos)
898 self._callback = callback
902 self._minValue = minValue
903 self._maxValue = maxValue
905 def setValue(self, value):
907 self._value = max(self._minValue, self._value)
908 self._value = min(self._maxValue, self._value)
913 def setRange(self, minValue, maxValue):
914 if maxValue < minValue:
916 self._minValue = minValue
917 self._maxValue = maxValue
918 self._value = max(minValue, self._value)
919 self._value = min(maxValue, self._value)
921 def getMinValue(self):
922 return self._minValue
924 def getMaxValue(self):
925 return self._maxValue
927 def setHidden(self, value):
930 def getMinSize(self):
931 return self._base._buttonSize * 0.2, self._base._buttonSize * 4
933 def _getPixelPos(self):
934 x0, y0, w, h = self.getSize()
935 minSize = self.getMinSize()
936 return x0 + w / 2 - minSize[0] / 2, y0 + h / 2 - minSize[1] / 2
942 w, h = self.getMinSize()
943 pos = self._getPixelPos()
946 glTranslatef(pos[0], pos[1], 0)
947 glDisable(GL_TEXTURE_2D)
949 glColor4ub(60,60,60,255)
951 glColor4ub(60,60,60,192)
953 glVertex2f( w/2,-h/2)
954 glVertex2f(-w/2,-h/2)
955 glVertex2f(-w/2, h/2)
956 glVertex2f( w/2, h/2)
959 glTranslate(0.0,scrollLength/2,0)
961 glColor4ub(0,0,0,255)
963 glTranslate(-w/2,opengl.glGetStringSize(str(self._minValue))[1]/2,0)
964 opengl.glDrawStringRight(str(self._minValue))
965 glTranslate(0,-scrollLength,0)
966 opengl.glDrawStringRight(str(self._maxValue))
967 if self._maxValue-self._minValue > 0:
968 glTranslate(w,scrollLength-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
969 opengl.glDrawStringLeft(str(self._value))
971 glColor4ub(255,255,255,240)
972 if self._maxValue - self._minValue != 0:
973 glTranslate(0.0,-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
975 glVertex2f( w/2,-w/2)
976 glVertex2f(-w/2,-w/2)
977 glVertex2f(-w/2, w/2)
978 glVertex2f( w/2, w/2)
982 def _checkHit(self, x, y):
985 pos = self._getPixelPos()
986 w, h = self.getMinSize()
987 return -w/2 <= x - pos[0] <= w/2 and -h/2 <= y - pos[1] <= h/2
990 self._base._focus = self
993 def OnMouseMotion(self, x, y):
995 w, h = self.getMinSize()
997 pos = self._getPixelPos()
998 self.setValue(int(self._minValue + (self._maxValue - self._minValue) * -(y - pos[1] - scrollLength/2) / scrollLength))
1001 if self._checkHit(x, y):
1007 def OnMouseDown(self, x, y, button):
1008 if self._checkHit(x, y):
1010 self.OnMouseMotion(x, y)
1014 def OnMouseUp(self, x, y):
1016 self._base._focus = None