1 from __future__ import absolute_import
2 from __future__ import division
9 from wx import glcanvas
11 OpenGL.ERROR_CHECKING = False
12 from OpenGL.GL import *
14 from Cura.gui.util import opengl
16 class glGuiControl(object):
17 def __init__(self, parent, pos):
19 self._base = parent._base
21 self._size = (0,0, 1, 1)
22 self._parent.add(self)
24 def setSize(self, x, y, w, h):
25 self._size = (x, y, w, h)
33 def updateLayout(self):
37 for n in xrange(self._parent._glGuiControlList.index(self) + 1, len(self._parent._glGuiControlList)):
38 if self._parent._glGuiControlList[n].setFocus():
40 for n in xrange(0, self._parent._glGuiControlList.index(self)):
41 if self._parent._glGuiControlList[n].setFocus():
44 def focusPrevious(self):
45 for n in xrange(self._parent._glGuiControlList.index(self) -1, -1, -1):
46 if self._parent._glGuiControlList[n].setFocus():
48 for n in xrange(len(self._parent._glGuiControlList) - 1, self._parent._glGuiControlList.index(self), -1):
49 if self._parent._glGuiControlList[n].setFocus():
56 return self._base._focus == self
58 def OnMouseUp(self, x, y):
61 def OnKeyChar(self, key):
64 class glGuiContainer(glGuiControl):
65 def __init__(self, parent, pos):
66 self._glGuiControlList = []
67 glGuiLayoutButtons(self)
68 super(glGuiContainer, self).__init__(parent, pos)
71 self._glGuiControlList.append(ctrl)
74 def OnMouseDown(self, x, y):
75 for ctrl in self._glGuiControlList:
76 if ctrl.OnMouseDown(x, y):
80 def OnMouseUp(self, x, y):
81 for ctrl in self._glGuiControlList:
82 if ctrl.OnMouseUp(x, y):
86 def OnMouseMotion(self, x, y):
88 for ctrl in self._glGuiControlList:
89 if ctrl.OnMouseMotion(x, y):
94 for ctrl in self._glGuiControlList:
97 def updateLayout(self):
99 for ctrl in self._glGuiControlList:
102 class glGuiPanel(glcanvas.GLCanvas):
103 def __init__(self, parent):
104 attribList = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24, glcanvas.WX_GL_STENCIL_SIZE, 8)
105 glcanvas.GLCanvas.__init__(self, parent, style=wx.WANTS_CHARS, attribList = attribList)
108 self._container = None
109 self._container = glGuiContainer(self, (0,0))
110 self._shownError = False
112 self._context = glcanvas.GLContext(self)
113 self._glButtonsTexture = None
114 self._glRobotTexture = None
115 self._buttonSize = 64
117 wx.EVT_PAINT(self, self._OnGuiPaint)
118 wx.EVT_SIZE(self, self._OnSize)
119 wx.EVT_ERASE_BACKGROUND(self, self._OnEraseBackground)
120 wx.EVT_LEFT_DOWN(self, self._OnGuiMouseLeftDown)
121 wx.EVT_LEFT_UP(self, self._OnGuiMouseLeftUp)
122 wx.EVT_MOTION(self, self._OnGuiMouseMotion)
123 wx.EVT_CHAR(self, self._OnGuiKeyChar)
124 wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
126 def _OnGuiKeyChar(self, e):
127 if self._focus is not None:
128 self._focus.OnKeyChar(e.GetKeyCode())
131 self.OnKeyChar(e.GetKeyCode())
133 def OnFocusLost(self, e):
137 def _OnGuiMouseLeftDown(self,e):
139 if self._container.OnMouseDown(e.GetX(), e.GetY()):
142 self.OnMouseLeftDown(e)
143 def _OnGuiMouseLeftUp(self, e):
144 if self._container.OnMouseUp(e.GetX(), e.GetY()):
147 self.OnMouseLeftUp(e)
149 def _OnGuiMouseMotion(self,e):
151 if not self._container.OnMouseMotion(e.GetX(), e.GetY()):
152 self.OnMouseMotion(e)
154 def _OnGuiPaint(self, e):
155 h = self.GetSize().GetHeight()
156 w = self.GetSize().GetWidth()
157 oldButtonSize = self._buttonSize
161 self._buttonSize = 32
163 self._buttonSize = 48
165 self._buttonSize = 64
167 self._buttonSize = 80
169 self._buttonSize = 96
170 if self._buttonSize != oldButtonSize:
171 self._container.updateLayout()
173 dc = wx.PaintDC(self)
175 self.SetCurrent(self._context)
181 errStr = 'An error has occurred during the 3D view drawing.'
182 tb = traceback.extract_tb(sys.exc_info()[2])
183 errStr += "\n%s: '%s'" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]))
184 for n in xrange(len(tb)-1, -1, -1):
186 errStr += "\n @ %s:%s:%d" % (os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
187 if not self._shownError:
188 wx.CallAfter(wx.MessageBox, errStr, '3D window error', wx.OK | wx.ICON_EXCLAMATION)
189 self._shownError = True
192 if self._glButtonsTexture is None:
193 self._glButtonsTexture = opengl.loadGLTexture('glButtons.png')
194 self._glRobotTexture = opengl.loadGLTexture('UltimakerRobot.png')
196 glDisable(GL_DEPTH_TEST)
198 glDisable(GL_LIGHTING)
199 glColor4ub(255,255,255,255)
201 glMatrixMode(GL_PROJECTION)
203 size = self.GetSize()
204 glOrtho(0, size.GetWidth()-1, size.GetHeight()-1, 0, -1000.0, 1000.0)
205 glMatrixMode(GL_MODELVIEW)
208 self._container.draw()
209 glBindTexture(GL_TEXTURE_2D, self._glRobotTexture)
210 glEnable(GL_TEXTURE_2D)
213 glTranslate(size.GetWidth() - 8,size.GetHeight() - 16,0)
214 s = self._buttonSize * 1.4
226 glDisable(GL_TEXTURE_2D)
229 def _OnEraseBackground(self,event):
230 #Workaround for windows background redraw flicker.
234 self._container.setSize(0, 0, self.GetSize().GetWidth(), self.GetSize().GetHeight())
235 self._container.updateLayout()
238 def OnMouseLeftDown(self,e):
240 def OnMouseLeftUp(self,e):
242 def OnMouseMotion(self, e):
244 def OnPaint(self, e):
246 def OnKeyChar(self, keycode):
250 if self._container is not None:
251 self._container.add(ctrl)
253 class glGuiLayoutButtons(object):
254 def __init__(self, parent):
255 self._parent = parent
256 self._parent._layout = self
259 bs = self._parent._base._buttonSize
260 x0, y0, w, h = self._parent.getSize()
262 for ctrl in self._parent._glGuiControlList:
265 x = w + pos[0] * gridSize - bs * 0.2
267 x = pos[0] * gridSize + bs * 0.2
269 y = h + pos[1] * gridSize * 1.2 - bs * 0.2
271 y = pos[1] * gridSize * 1.2 + bs * 0.2
272 ctrl.setSize(x, y, gridSize, gridSize)
274 def getLayoutSize(self):
275 _, _, w, h = self._parent.getSize()
278 class glGuiLayoutGrid(object):
279 def __init__(self, parent):
280 self._parent = parent
281 self._parent._layout = self
283 self._alignBottom = True
286 borderSize = self._parent._base._buttonSize * 0.2
287 x0, y0, w, h = self._parent.getSize()
292 for ctrl in self._parent._glGuiControlList:
294 w, h = ctrl.getMinSize()
298 widths[x] = max(widths[x], w)
302 heights[y] = max(heights[y], h)
303 self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
304 if self._alignBottom:
305 y0 -= self._size[1] - self._parent.getSize()[3]
306 self._parent.setSize(x0 - borderSize, y0 - borderSize, self._size[0], self._size[1])
307 for ctrl in self._parent._glGuiControlList:
311 for n in xrange(0, x):
315 for n in xrange(0, y):
319 ctrl.setSize(x1, y1, widths[x], heights[y])
321 def getLayoutSize(self):
324 class glButton(glGuiControl):
325 def __init__(self, parent, imageID, tooltip, pos, callback):
326 super(glButton, self).__init__(parent, pos)
327 self._tooltip = tooltip
328 self._parent = parent
329 self._imageID = imageID
330 self._callback = callback
331 self._selected = False
334 self._disabled = False
335 self._showExpandArrow = False
337 def setSelected(self, value):
338 self._selected = value
340 def setExpandArrow(self, value):
341 self._showExpandArrow = value
343 def setHidden(self, value):
346 def setDisabled(self, value):
347 self._disabled = value
349 def getSelected(self):
350 return self._selected
352 def getMinSize(self):
353 return self._base._buttonSize, self._base._buttonSize
355 def _getPixelPos(self):
356 x0, y0, w, h = self.getSize()
357 return x0 + w / 2, y0 + h / 2
363 cx = (self._imageID % 4) / 4
364 cy = int(self._imageID / 4) / 4
365 bs = self._base._buttonSize
366 pos = self._getPixelPos()
368 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
375 glColor4ub(128,128,128,128)
377 glColor4ub(255,255,255,255)
378 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, 0)
379 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
380 if self._showExpandArrow:
382 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)
384 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)
386 glTranslatef(pos[0], pos[1], 0)
387 glDisable(GL_TEXTURE_2D)
389 glTranslatef(0, -0.55*bs*scale, 0)
392 glColor4ub(60,60,60,255)
393 glTranslatef(-1, -1, 0)
394 opengl.glDrawStringCenter(self._tooltip)
395 glTranslatef(0, 2, 0)
396 opengl.glDrawStringCenter(self._tooltip)
397 glTranslatef(2, 0, 0)
398 opengl.glDrawStringCenter(self._tooltip)
399 glTranslatef(0, -2, 0)
400 opengl.glDrawStringCenter(self._tooltip)
403 glColor4ub(255,255,255,255)
404 opengl.glDrawStringCenter(self._tooltip)
407 def _checkHit(self, x, y):
408 if self._hidden or self._disabled:
410 bs = self.getMinSize()[0]
411 pos = self._getPixelPos()
412 return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5
414 def OnMouseMotion(self, x, y):
415 if self._checkHit(x, y):
421 def OnMouseDown(self, x, y):
422 if self._checkHit(x, y):
427 class glRadioButton(glButton):
428 def __init__(self, parent, imageID, tooltip, pos, group, callback):
429 super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
431 self._radioCallback = callback
432 self._group.append(self)
434 def setSelected(self, value):
435 self._selected = value
437 def _onRadioSelect(self):
438 self._base._focus = None
439 for ctrl in self._group:
441 ctrl.setSelected(False)
442 if self.getSelected():
443 self.setSelected(False)
445 self.setSelected(True)
446 self._radioCallback()
448 class glComboButton(glButton):
449 def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
450 super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
451 self._imageIDs = imageIDs
452 self._tooltips = tooltips
453 self._comboCallback = callback
456 def _onComboOpenSelect(self):
458 self._base._focus = None
460 self._base._focus = self
465 self._selected = self.hasFocus()
466 super(glComboButton, self).draw()
468 bs = self._base._buttonSize / 2
469 pos = self._getPixelPos()
471 if not self._selected:
475 glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
476 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
477 for n in xrange(0, len(self._imageIDs)):
478 glTranslatef(0, bs, 0)
479 glColor4ub(255,255,255,255)
480 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
481 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
482 glDisable(GL_TEXTURE_2D)
485 glTranslatef(-0.55*bs, 0.1*bs, 0)
488 glColor4ub(60,60,60,255)
489 glTranslatef(-1, -1, 0)
490 opengl.glDrawStringRight(self._tooltips[n])
491 glTranslatef(0, 2, 0)
492 opengl.glDrawStringRight(self._tooltips[n])
493 glTranslatef(2, 0, 0)
494 opengl.glDrawStringRight(self._tooltips[n])
495 glTranslatef(0, -2, 0)
496 opengl.glDrawStringRight(self._tooltips[n])
499 glColor4ub(255,255,255,255)
500 opengl.glDrawStringRight(self._tooltips[n])
505 return self._selection
507 def setValue(self, value):
508 self._selection = value
509 self._imageID = self._imageIDs[self._selection]
510 self._comboCallback()
512 def OnMouseDown(self, x, y):
513 if self._hidden or self._disabled:
516 bs = self._base._buttonSize / 2
517 pos = self._getPixelPos()
518 if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
519 self._selection = int((y - pos[1] - bs) / bs)
520 self._imageID = self._imageIDs[self._selection]
521 self._base._focus = None
522 self._comboCallback()
524 return super(glComboButton, self).OnMouseDown(x, y)
526 class glFrame(glGuiContainer):
527 def __init__(self, parent, pos):
528 super(glFrame, self).__init__(parent, pos)
529 self._selected = False
533 def setSelected(self, value):
534 self._selected = value
536 def setHidden(self, value):
539 def getSelected(self):
540 return self._selected
542 def getMinSize(self):
543 return self._base._buttonSize, self._base._buttonSize
545 def _getPixelPos(self):
546 x0, y0, w, h = self.getSize()
553 bs = self._parent._buttonSize
554 pos = self._getPixelPos()
557 glTranslatef(pos[0], pos[1], 0)
558 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
559 glEnable(GL_TEXTURE_2D)
561 size = self._layout.getLayoutSize()
562 glColor4ub(255,255,255,255)
568 # glVertex2f( size[0], 0)
572 # glVertex2f( 0, size[1])
574 # glVertex2f( size[0], size[1])
580 glTexCoord2f(0, tc/2)
582 glTexCoord2f(tc, tc/2)
585 glTexCoord2f(tc+tc, 0)
586 glVertex2f( size[0], 0)
588 glVertex2f( size[0] - bs, 0)
589 glTexCoord2f(tc, tc/2)
590 glVertex2f( size[0] - bs, bs)
591 glTexCoord2f(tc+tc, tc/2)
592 glVertex2f( size[0], bs)
594 glTexCoord2f(tc, tc/2)
595 glVertex2f( bs, size[1] - bs)
596 glTexCoord2f(0, tc/2)
597 glVertex2f( 0, size[1] - bs)
598 glTexCoord2f(0, tc/2+tc/2)
599 glVertex2f( 0, size[1])
600 glTexCoord2f(tc, tc/2+tc/2)
601 glVertex2f( bs, size[1])
603 glTexCoord2f(tc+tc, tc/2)
604 glVertex2f( size[0], size[1] - bs)
605 glTexCoord2f(tc, tc/2)
606 glVertex2f( size[0] - bs, size[1] - bs)
607 glTexCoord2f(tc, tc/2+tc/2)
608 glVertex2f( size[0] - bs, size[1])
609 glTexCoord2f(tc+tc, tc/2+tc/2)
610 glVertex2f( size[0], size[1])
613 glTexCoord2f(tc, tc/2)
614 glVertex2f( size[0]-bs, bs)
615 glTexCoord2f(tc, tc/2)
617 glTexCoord2f(tc, tc/2)
618 glVertex2f( bs, size[1]-bs)
619 glTexCoord2f(tc, tc/2)
620 glVertex2f( size[0]-bs, size[1]-bs)
623 glTexCoord2f(tc+tc, tc/2)
624 glVertex2f( size[0], bs)
625 glTexCoord2f(tc, tc/2)
626 glVertex2f( size[0]-bs, bs)
627 glTexCoord2f(tc, tc/2)
628 glVertex2f( size[0]-bs, size[1]-bs)
629 glTexCoord2f(tc+tc, tc/2)
630 glVertex2f( size[0], size[1]-bs)
633 glTexCoord2f(tc, tc/2)
635 glTexCoord2f(0, tc/2)
637 glTexCoord2f(0, tc/2)
638 glVertex2f( 0, size[1]-bs)
639 glTexCoord2f(tc, tc/2)
640 glVertex2f( bs, size[1]-bs)
644 glVertex2f( size[0]-bs, 0)
647 glTexCoord2f(tc, tc/2)
649 glTexCoord2f(tc, tc/2)
650 glVertex2f( size[0]-bs, bs)
653 glTexCoord2f(tc, tc/2)
654 glVertex2f( size[0]-bs, size[1]-bs)
655 glTexCoord2f(tc, tc/2)
656 glVertex2f( bs, size[1]-bs)
657 glTexCoord2f(tc, tc/2+tc/2)
658 glVertex2f( bs, size[1])
659 glTexCoord2f(tc, tc/2+tc/2)
660 glVertex2f( size[0]-bs, size[1])
663 glDisable(GL_TEXTURE_2D)
665 #Draw the controls on the frame
666 super(glFrame, self).draw()
668 def _checkHit(self, x, y):
671 pos = self._getPixelPos()
672 w, h = self._layout.getLayoutSize()
673 return 0 <= x - pos[0] <= w and 0 <= y - pos[1] <= h
675 def OnMouseMotion(self, x, y):
676 super(glFrame, self).OnMouseMotion(x, y)
677 if self._checkHit(x, y):
683 def OnMouseDown(self, x, y):
684 if self._checkHit(x, y):
685 super(glFrame, self).OnMouseDown(x, y)
689 class glLabel(glGuiControl):
690 def __init__(self, parent, label, pos):
692 super(glLabel, self).__init__(parent, pos)
694 def getMinSize(self):
695 w, h = opengl.glGetStringSize(self._label)
698 def _getPixelPos(self):
699 x0, y0, w, h = self.getSize()
703 x, y, w, h = self.getSize()
706 glTranslatef(x, y, 0)
708 # glColor4ub(255,255,255,128)
720 glTranslate(5, h - 5, 0)
721 glColor4ub(255,255,255,255)
722 opengl.glDrawStringLeft(self._label)
725 def _checkHit(self, x, y):
728 def OnMouseMotion(self, x, y):
731 def OnMouseDown(self, x, y):
734 class glNumberCtrl(glGuiControl):
735 def __init__(self, parent, value, pos, callback):
736 self._callback = callback
737 self._value = str(value)
740 self._inCallback = False
741 super(glNumberCtrl, self).__init__(parent, pos)
743 def setValue(self, value):
746 self._value = str(value)
748 def getMinSize(self):
749 w, h = opengl.glGetStringSize("VALUES")
752 def _getPixelPos(self):
753 x0, y0, w, h = self.getSize()
757 x, y, w, h = self.getSize()
760 glTranslatef(x, y, 0)
763 glColor4ub(255,255,255,255)
765 glColor4ub(255,255,255,192)
777 glTranslate(5, h - 5, 0)
778 glColor4ub(0,0,0,255)
779 opengl.glDrawStringLeft(self._value)
781 glTranslate(opengl.glGetStringSize(self._value[0:self._selectPos])[0] - 2, -1, 0)
782 opengl.glDrawStringLeft('|')
785 def _checkHit(self, x, y):
786 x1, y1, w, h = self.getSize()
787 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
789 def OnMouseMotion(self, x, y):
792 def OnMouseDown(self, x, y):
793 if self._checkHit(x, y):
798 def OnKeyChar(self, c):
799 self._inCallback = True
802 self._selectPos = max(0, self._selectPos)
803 if c == wx.WXK_RIGHT:
805 self._selectPos = min(self._selectPos, len(self._value))
808 value = float(self._value)
813 self._value = str(value)
814 self._callback(self._value)
817 value = float(self._value)
823 self._value = str(value)
824 self._callback(self._value)
825 if c == wx.WXK_BACK and self._selectPos > 0:
826 self._value = self._value[0:self._selectPos - 1] + self._value[self._selectPos:]
828 self._callback(self._value)
829 if c == wx.WXK_DELETE:
830 self._value = self._value[0:self._selectPos] + self._value[self._selectPos + 1:]
831 self._callback(self._value)
832 if c == wx.WXK_TAB or c == wx.WXK_NUMPAD_ENTER or c == wx.WXK_RETURN:
833 if wx.GetKeyState(wx.WXK_SHIFT):
837 if (ord('0') <= c <= ord('9') or c == ord('.')) and len(self._value) < self._maxLen:
838 self._value = self._value[0:self._selectPos] + chr(c) + self._value[self._selectPos:]
840 self._callback(self._value)
841 self._inCallback = False
844 self._base._focus = self
845 self._selectPos = len(self._value)
848 class glCheckbox(glGuiControl):
849 def __init__(self, parent, value, pos, callback):
850 self._callback = callback
854 self._inCallback = False
855 super(glCheckbox, self).__init__(parent, pos)
857 def setValue(self, value):
860 self._value = str(value)
865 def getMinSize(self):
868 def _getPixelPos(self):
869 x0, y0, w, h = self.getSize()
873 x, y, w, h = self.getSize()
876 glTranslatef(x, y, 0)
878 glColor3ub(255,255,255)
880 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 28)
882 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 29)
886 def _checkHit(self, x, y):
887 x1, y1, w, h = self.getSize()
888 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
890 def OnMouseMotion(self, x, y):
893 def OnMouseDown(self, x, y):
894 if self._checkHit(x, y):
895 self._value = not self._value
899 class glSlider(glGuiControl):
900 def __init__(self, parent, value, minValue, maxValue, pos, callback):
901 super(glSlider, self).__init__(parent, pos)
902 self._callback = callback
906 self._minValue = minValue
907 self._maxValue = maxValue
909 def setValue(self, value):
911 self._value = max(self._minValue, self._value)
912 self._value = min(self._maxValue, self._value)
917 def setRange(self, minValue, maxValue):
918 if maxValue < minValue:
920 self._minValue = minValue
921 self._maxValue = maxValue
922 self._value = max(minValue, self._value)
923 self._value = min(maxValue, self._value)
925 def getMinValue(self):
926 return self._minValue
928 def getMaxValue(self):
929 return self._maxValue
931 def setHidden(self, value):
934 def getMinSize(self):
935 return self._base._buttonSize * 0.2, self._base._buttonSize * 4
937 def _getPixelPos(self):
938 x0, y0, w, h = self.getSize()
939 minSize = self.getMinSize()
940 return x0 + w / 2 - minSize[0] / 2, y0 + h / 2 - minSize[1] / 2
946 w, h = self.getMinSize()
947 pos = self._getPixelPos()
950 glTranslatef(pos[0], pos[1], 0)
951 glDisable(GL_TEXTURE_2D)
953 glColor4ub(60,60,60,255)
955 glColor4ub(60,60,60,192)
957 glVertex2f( w/2,-h/2)
958 glVertex2f(-w/2,-h/2)
959 glVertex2f(-w/2, h/2)
960 glVertex2f( w/2, h/2)
963 glTranslate(0.0,scrollLength/2,0)
965 glColor4ub(0,0,0,255)
967 glTranslate(-w/2,opengl.glGetStringSize(str(self._minValue))[1]/2,0)
968 opengl.glDrawStringRight(str(self._minValue))
969 glTranslate(0,-scrollLength,0)
970 opengl.glDrawStringRight(str(self._maxValue))
971 if self._maxValue-self._minValue > 0:
972 glTranslate(w,scrollLength-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
973 opengl.glDrawStringLeft(str(self._value))
975 glColor4ub(255,255,255,240)
976 if self._maxValue - self._minValue != 0:
977 glTranslate(0.0,-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
979 glVertex2f( w/2,-w/2)
980 glVertex2f(-w/2,-w/2)
981 glVertex2f(-w/2, w/2)
982 glVertex2f( w/2, w/2)
986 def _checkHit(self, x, y):
989 pos = self._getPixelPos()
990 w, h = self.getMinSize()
991 return -w/2 <= x - pos[0] <= w/2 and -h/2 <= y - pos[1] <= h/2
994 self._base._focus = self
997 def OnMouseMotion(self, x, y):
999 w, h = self.getMinSize()
1000 scrollLength = h - w
1001 pos = self._getPixelPos()
1002 self.setValue(int(self._minValue + (self._maxValue - self._minValue) * -(y - pos[1] - scrollLength/2) / scrollLength))
1005 if self._checkHit(x, y):
1011 def OnMouseDown(self, x, y):
1012 if self._checkHit(x, y):
1014 self.OnMouseMotion(x, y)
1018 def OnMouseUp(self, x, y):
1020 self._base._focus = None