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 self.glReleaseList = []
119 wx.EVT_PAINT(self, self._OnGuiPaint)
120 wx.EVT_SIZE(self, self._OnSize)
121 wx.EVT_ERASE_BACKGROUND(self, self._OnEraseBackground)
122 wx.EVT_LEFT_DOWN(self, self._OnGuiMouseDown)
123 wx.EVT_LEFT_UP(self, self._OnGuiMouseUp)
124 wx.EVT_RIGHT_DOWN(self, self._OnGuiMouseDown)
125 wx.EVT_RIGHT_UP(self, self._OnGuiMouseUp)
126 wx.EVT_MIDDLE_DOWN(self, self._OnGuiMouseDown)
127 wx.EVT_MIDDLE_UP(self, self._OnGuiMouseUp)
128 wx.EVT_MOTION(self, self._OnGuiMouseMotion)
129 wx.EVT_CHAR(self, self._OnGuiKeyChar)
130 wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
132 def _OnGuiKeyChar(self, e):
133 if self._focus is not None:
134 self._focus.OnKeyChar(e.GetKeyCode())
137 self.OnKeyChar(e.GetKeyCode())
139 def OnFocusLost(self, e):
143 def _OnGuiMouseDown(self,e):
145 if self._container.OnMouseDown(e.GetX(), e.GetY()):
150 def _OnGuiMouseUp(self, e):
151 if self._container.OnMouseUp(e.GetX(), e.GetY()):
156 def _OnGuiMouseMotion(self,e):
158 if not self._container.OnMouseMotion(e.GetX(), e.GetY()):
159 self.OnMouseMotion(e)
161 def _OnGuiPaint(self, e):
162 h = self.GetSize().GetHeight()
163 w = self.GetSize().GetWidth()
164 oldButtonSize = self._buttonSize
168 self._buttonSize = 32
170 self._buttonSize = 48
172 self._buttonSize = 64
174 self._buttonSize = 80
176 self._buttonSize = 96
177 if self._buttonSize != oldButtonSize:
178 self._container.updateLayout()
180 dc = wx.PaintDC(self)
182 self.SetCurrent(self._context)
183 for obj in self.glReleaseList:
185 del self.glReleaseList[:]
191 errStr = 'An error has occurred during the 3D view drawing.'
192 tb = traceback.extract_tb(sys.exc_info()[2])
193 errStr += "\n%s: '%s'" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]))
194 for n in xrange(len(tb)-1, -1, -1):
196 errStr += "\n @ %s:%s:%d" % (os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
197 if not self._shownError:
198 wx.CallAfter(wx.MessageBox, errStr, '3D window error', wx.OK | wx.ICON_EXCLAMATION)
199 self._shownError = True
202 if self._glButtonsTexture is None:
203 self._glButtonsTexture = opengl.loadGLTexture('glButtons.png')
204 self._glRobotTexture = opengl.loadGLTexture('UltimakerRobot.png')
206 glDisable(GL_DEPTH_TEST)
208 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
209 glDisable(GL_LIGHTING)
210 glColor4ub(255,255,255,255)
212 glMatrixMode(GL_PROJECTION)
214 size = self.GetSize()
215 glOrtho(0, size.GetWidth()-1, size.GetHeight()-1, 0, -1000.0, 1000.0)
216 glMatrixMode(GL_MODELVIEW)
219 self._container.draw()
220 glBindTexture(GL_TEXTURE_2D, self._glRobotTexture)
221 glEnable(GL_TEXTURE_2D)
224 glTranslate(size.GetWidth() - 8,size.GetHeight() - 16,0)
225 s = self._buttonSize * 1.4
237 glDisable(GL_TEXTURE_2D)
240 def _OnEraseBackground(self,event):
241 #Workaround for windows background redraw flicker.
245 self._container.setSize(0, 0, self.GetSize().GetWidth(), self.GetSize().GetHeight())
246 self._container.updateLayout()
249 def OnMouseDown(self,e):
251 def OnMouseUp(self,e):
253 def OnMouseMotion(self, e):
255 def OnKeyChar(self, keyCode):
257 def OnPaint(self, e):
261 if self._container is not None:
262 self._container.add(ctrl)
264 class glGuiLayoutButtons(object):
265 def __init__(self, parent):
266 self._parent = parent
267 self._parent._layout = self
270 bs = self._parent._base._buttonSize
271 x0, y0, w, h = self._parent.getSize()
273 for ctrl in self._parent._glGuiControlList:
276 x = w + pos[0] * gridSize - bs * 0.2
278 x = pos[0] * gridSize + bs * 0.2
280 y = h + pos[1] * gridSize * 1.2 - bs * 0.2
282 y = pos[1] * gridSize * 1.2 + bs * 0.2
283 ctrl.setSize(x, y, gridSize, gridSize)
285 def getLayoutSize(self):
286 _, _, w, h = self._parent.getSize()
289 class glGuiLayoutGrid(object):
290 def __init__(self, parent):
291 self._parent = parent
292 self._parent._layout = self
294 self._alignBottom = True
297 borderSize = self._parent._base._buttonSize * 0.2
298 x0, y0, w, h = self._parent.getSize()
303 for ctrl in self._parent._glGuiControlList:
305 w, h = ctrl.getMinSize()
309 widths[x] = max(widths[x], w)
313 heights[y] = max(heights[y], h)
314 self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
315 if self._alignBottom:
316 y0 -= self._size[1] - self._parent.getSize()[3]
317 self._parent.setSize(x0 - borderSize, y0 - borderSize, self._size[0], self._size[1])
318 for ctrl in self._parent._glGuiControlList:
322 for n in xrange(0, x):
326 for n in xrange(0, y):
330 ctrl.setSize(x1, y1, widths[x], heights[y])
332 def getLayoutSize(self):
335 class glButton(glGuiControl):
336 def __init__(self, parent, imageID, tooltip, pos, callback):
337 super(glButton, self).__init__(parent, pos)
338 self._tooltip = tooltip
339 self._parent = parent
340 self._imageID = imageID
341 self._callback = callback
342 self._selected = False
345 self._disabled = False
346 self._showExpandArrow = False
348 def setSelected(self, value):
349 self._selected = value
351 def setExpandArrow(self, value):
352 self._showExpandArrow = value
354 def setHidden(self, value):
357 def setDisabled(self, value):
358 self._disabled = value
360 def getSelected(self):
361 return self._selected
363 def getMinSize(self):
364 return self._base._buttonSize, self._base._buttonSize
366 def _getPixelPos(self):
367 x0, y0, w, h = self.getSize()
368 return x0 + w / 2, y0 + h / 2
374 cx = (self._imageID % 4) / 4
375 cy = int(self._imageID / 4) / 4
376 bs = self._base._buttonSize
377 pos = self._getPixelPos()
379 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
386 glColor4ub(128,128,128,128)
388 glColor4ub(255,255,255,255)
389 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, 0)
390 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
391 if self._showExpandArrow:
393 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)
395 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)
397 glTranslatef(pos[0], pos[1], 0)
398 glDisable(GL_TEXTURE_2D)
400 glTranslatef(0, -0.55*bs*scale, 0)
403 glColor4ub(60,60,60,255)
404 glTranslatef(-1, -1, 0)
405 opengl.glDrawStringCenter(self._tooltip)
406 glTranslatef(0, 2, 0)
407 opengl.glDrawStringCenter(self._tooltip)
408 glTranslatef(2, 0, 0)
409 opengl.glDrawStringCenter(self._tooltip)
410 glTranslatef(0, -2, 0)
411 opengl.glDrawStringCenter(self._tooltip)
414 glColor4ub(255,255,255,255)
415 opengl.glDrawStringCenter(self._tooltip)
418 def _checkHit(self, x, y):
419 if self._hidden or self._disabled:
421 bs = self.getMinSize()[0]
422 pos = self._getPixelPos()
423 return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5
425 def OnMouseMotion(self, x, y):
426 if self._checkHit(x, y):
432 def OnMouseDown(self, x, y):
433 if self._checkHit(x, y):
438 class glRadioButton(glButton):
439 def __init__(self, parent, imageID, tooltip, pos, group, callback):
440 super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
442 self._radioCallback = callback
443 self._group.append(self)
445 def setSelected(self, value):
446 self._selected = value
448 def _onRadioSelect(self):
449 self._base._focus = None
450 for ctrl in self._group:
452 ctrl.setSelected(False)
453 if self.getSelected():
454 self.setSelected(False)
456 self.setSelected(True)
457 self._radioCallback()
459 class glComboButton(glButton):
460 def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
461 super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
462 self._imageIDs = imageIDs
463 self._tooltips = tooltips
464 self._comboCallback = callback
467 def _onComboOpenSelect(self):
469 self._base._focus = None
471 self._base._focus = self
476 self._selected = self.hasFocus()
477 super(glComboButton, self).draw()
479 bs = self._base._buttonSize / 2
480 pos = self._getPixelPos()
482 if not self._selected:
486 glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
487 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
488 for n in xrange(0, len(self._imageIDs)):
489 glTranslatef(0, bs, 0)
490 glColor4ub(255,255,255,255)
491 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
492 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
493 glDisable(GL_TEXTURE_2D)
496 glTranslatef(-0.55*bs, 0.1*bs, 0)
499 glColor4ub(60,60,60,255)
500 glTranslatef(-1, -1, 0)
501 opengl.glDrawStringRight(self._tooltips[n])
502 glTranslatef(0, 2, 0)
503 opengl.glDrawStringRight(self._tooltips[n])
504 glTranslatef(2, 0, 0)
505 opengl.glDrawStringRight(self._tooltips[n])
506 glTranslatef(0, -2, 0)
507 opengl.glDrawStringRight(self._tooltips[n])
510 glColor4ub(255,255,255,255)
511 opengl.glDrawStringRight(self._tooltips[n])
516 return self._selection
518 def setValue(self, value):
519 self._selection = value
520 self._imageID = self._imageIDs[self._selection]
521 self._comboCallback()
523 def OnMouseDown(self, x, y):
524 if self._hidden or self._disabled:
527 bs = self._base._buttonSize / 2
528 pos = self._getPixelPos()
529 if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
530 self._selection = int((y - pos[1] - bs) / bs)
531 self._imageID = self._imageIDs[self._selection]
532 self._base._focus = None
533 self._comboCallback()
535 return super(glComboButton, self).OnMouseDown(x, y)
537 class glFrame(glGuiContainer):
538 def __init__(self, parent, pos):
539 super(glFrame, self).__init__(parent, pos)
540 self._selected = False
544 def setSelected(self, value):
545 self._selected = value
547 def setHidden(self, value):
550 def getSelected(self):
551 return self._selected
553 def getMinSize(self):
554 return self._base._buttonSize, self._base._buttonSize
556 def _getPixelPos(self):
557 x0, y0, w, h = self.getSize()
564 bs = self._parent._buttonSize
565 pos = self._getPixelPos()
568 glTranslatef(pos[0], pos[1], 0)
569 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
570 glEnable(GL_TEXTURE_2D)
572 size = self._layout.getLayoutSize()
573 glColor4ub(255,255,255,255)
579 # glVertex2f( size[0], 0)
583 # glVertex2f( 0, size[1])
585 # glVertex2f( size[0], size[1])
591 glTexCoord2f(0, tc/2)
593 glTexCoord2f(tc, tc/2)
596 glTexCoord2f(tc+tc, 0)
597 glVertex2f( size[0], 0)
599 glVertex2f( size[0] - bs, 0)
600 glTexCoord2f(tc, tc/2)
601 glVertex2f( size[0] - bs, bs)
602 glTexCoord2f(tc+tc, tc/2)
603 glVertex2f( size[0], bs)
605 glTexCoord2f(tc, tc/2)
606 glVertex2f( bs, size[1] - bs)
607 glTexCoord2f(0, tc/2)
608 glVertex2f( 0, size[1] - bs)
609 glTexCoord2f(0, tc/2+tc/2)
610 glVertex2f( 0, size[1])
611 glTexCoord2f(tc, tc/2+tc/2)
612 glVertex2f( bs, size[1])
614 glTexCoord2f(tc+tc, tc/2)
615 glVertex2f( size[0], size[1] - bs)
616 glTexCoord2f(tc, tc/2)
617 glVertex2f( size[0] - bs, size[1] - bs)
618 glTexCoord2f(tc, tc/2+tc/2)
619 glVertex2f( size[0] - bs, size[1])
620 glTexCoord2f(tc+tc, tc/2+tc/2)
621 glVertex2f( size[0], size[1])
624 glTexCoord2f(tc, tc/2)
625 glVertex2f( size[0]-bs, bs)
626 glTexCoord2f(tc, tc/2)
628 glTexCoord2f(tc, tc/2)
629 glVertex2f( bs, size[1]-bs)
630 glTexCoord2f(tc, tc/2)
631 glVertex2f( size[0]-bs, size[1]-bs)
634 glTexCoord2f(tc+tc, tc/2)
635 glVertex2f( size[0], bs)
636 glTexCoord2f(tc, tc/2)
637 glVertex2f( size[0]-bs, bs)
638 glTexCoord2f(tc, tc/2)
639 glVertex2f( size[0]-bs, size[1]-bs)
640 glTexCoord2f(tc+tc, tc/2)
641 glVertex2f( size[0], size[1]-bs)
644 glTexCoord2f(tc, tc/2)
646 glTexCoord2f(0, tc/2)
648 glTexCoord2f(0, tc/2)
649 glVertex2f( 0, size[1]-bs)
650 glTexCoord2f(tc, tc/2)
651 glVertex2f( bs, size[1]-bs)
655 glVertex2f( size[0]-bs, 0)
658 glTexCoord2f(tc, tc/2)
660 glTexCoord2f(tc, tc/2)
661 glVertex2f( size[0]-bs, bs)
664 glTexCoord2f(tc, tc/2)
665 glVertex2f( size[0]-bs, size[1]-bs)
666 glTexCoord2f(tc, tc/2)
667 glVertex2f( bs, size[1]-bs)
668 glTexCoord2f(tc, tc/2+tc/2)
669 glVertex2f( bs, size[1])
670 glTexCoord2f(tc, tc/2+tc/2)
671 glVertex2f( size[0]-bs, size[1])
674 glDisable(GL_TEXTURE_2D)
676 #Draw the controls on the frame
677 super(glFrame, self).draw()
679 def _checkHit(self, x, y):
682 pos = self._getPixelPos()
683 w, h = self._layout.getLayoutSize()
684 return 0 <= x - pos[0] <= w and 0 <= y - pos[1] <= h
686 def OnMouseMotion(self, x, y):
687 super(glFrame, self).OnMouseMotion(x, y)
688 if self._checkHit(x, y):
694 def OnMouseDown(self, x, y):
695 if self._checkHit(x, y):
696 super(glFrame, self).OnMouseDown(x, y)
700 class glLabel(glGuiControl):
701 def __init__(self, parent, label, pos):
703 super(glLabel, self).__init__(parent, pos)
705 def getMinSize(self):
706 w, h = opengl.glGetStringSize(self._label)
709 def _getPixelPos(self):
710 x0, y0, w, h = self.getSize()
714 x, y, w, h = self.getSize()
717 glTranslatef(x, y, 0)
719 # glColor4ub(255,255,255,128)
731 glTranslate(5, h - 5, 0)
732 glColor4ub(255,255,255,255)
733 opengl.glDrawStringLeft(self._label)
736 def _checkHit(self, x, y):
739 def OnMouseMotion(self, x, y):
742 def OnMouseDown(self, x, y):
745 class glNumberCtrl(glGuiControl):
746 def __init__(self, parent, value, pos, callback):
747 self._callback = callback
748 self._value = str(value)
751 self._inCallback = False
752 super(glNumberCtrl, self).__init__(parent, pos)
754 def setValue(self, value):
757 self._value = str(value)
759 def getMinSize(self):
760 w, h = opengl.glGetStringSize("VALUES")
763 def _getPixelPos(self):
764 x0, y0, w, h = self.getSize()
768 x, y, w, h = self.getSize()
771 glTranslatef(x, y, 0)
774 glColor4ub(255,255,255,255)
776 glColor4ub(255,255,255,192)
788 glTranslate(5, h - 5, 0)
789 glColor4ub(0,0,0,255)
790 opengl.glDrawStringLeft(self._value)
792 glTranslate(opengl.glGetStringSize(self._value[0:self._selectPos])[0] - 2, -1, 0)
793 opengl.glDrawStringLeft('|')
796 def _checkHit(self, x, y):
797 x1, y1, w, h = self.getSize()
798 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
800 def OnMouseMotion(self, x, y):
803 def OnMouseDown(self, x, y):
804 if self._checkHit(x, y):
809 def OnKeyChar(self, c):
810 self._inCallback = True
813 self._selectPos = max(0, self._selectPos)
814 if c == wx.WXK_RIGHT:
816 self._selectPos = min(self._selectPos, len(self._value))
819 value = float(self._value)
824 self._value = str(value)
825 self._callback(self._value)
828 value = float(self._value)
834 self._value = str(value)
835 self._callback(self._value)
836 if c == wx.WXK_BACK and self._selectPos > 0:
837 self._value = self._value[0:self._selectPos - 1] + self._value[self._selectPos:]
839 self._callback(self._value)
840 if c == wx.WXK_DELETE:
841 self._value = self._value[0:self._selectPos] + self._value[self._selectPos + 1:]
842 self._callback(self._value)
843 if c == wx.WXK_TAB or c == wx.WXK_NUMPAD_ENTER or c == wx.WXK_RETURN:
844 if wx.GetKeyState(wx.WXK_SHIFT):
848 if (ord('0') <= c <= ord('9') or c == ord('.')) and len(self._value) < self._maxLen:
849 self._value = self._value[0:self._selectPos] + chr(c) + self._value[self._selectPos:]
851 self._callback(self._value)
852 self._inCallback = False
855 self._base._focus = self
856 self._selectPos = len(self._value)
859 class glCheckbox(glGuiControl):
860 def __init__(self, parent, value, pos, callback):
861 self._callback = callback
865 self._inCallback = False
866 super(glCheckbox, self).__init__(parent, pos)
868 def setValue(self, value):
871 self._value = str(value)
876 def getMinSize(self):
879 def _getPixelPos(self):
880 x0, y0, w, h = self.getSize()
884 x, y, w, h = self.getSize()
887 glTranslatef(x, y, 0)
889 glColor3ub(255,255,255)
891 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 28)
893 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 29)
897 def _checkHit(self, x, y):
898 x1, y1, w, h = self.getSize()
899 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
901 def OnMouseMotion(self, x, y):
904 def OnMouseDown(self, x, y):
905 if self._checkHit(x, y):
906 self._value = not self._value
910 class glSlider(glGuiControl):
911 def __init__(self, parent, value, minValue, maxValue, pos, callback):
912 super(glSlider, self).__init__(parent, pos)
913 self._callback = callback
917 self._minValue = minValue
918 self._maxValue = maxValue
920 def setValue(self, value):
922 self._value = max(self._minValue, self._value)
923 self._value = min(self._maxValue, self._value)
928 def setRange(self, minValue, maxValue):
929 if maxValue < minValue:
931 self._minValue = minValue
932 self._maxValue = maxValue
933 self._value = max(minValue, self._value)
934 self._value = min(maxValue, self._value)
936 def getMinValue(self):
937 return self._minValue
939 def getMaxValue(self):
940 return self._maxValue
942 def setHidden(self, value):
945 def getMinSize(self):
946 return self._base._buttonSize * 0.2, self._base._buttonSize * 4
948 def _getPixelPos(self):
949 x0, y0, w, h = self.getSize()
950 minSize = self.getMinSize()
951 return x0 + w / 2 - minSize[0] / 2, y0 + h / 2 - minSize[1] / 2
957 w, h = self.getMinSize()
958 pos = self._getPixelPos()
961 glTranslatef(pos[0], pos[1], 0)
962 glDisable(GL_TEXTURE_2D)
964 glColor4ub(60,60,60,255)
966 glColor4ub(60,60,60,192)
968 glVertex2f( w/2,-h/2)
969 glVertex2f(-w/2,-h/2)
970 glVertex2f(-w/2, h/2)
971 glVertex2f( w/2, h/2)
974 glTranslate(0.0,scrollLength/2,0)
976 glColor4ub(0,0,0,255)
978 glTranslate(-w/2,opengl.glGetStringSize(str(self._minValue))[1]/2,0)
979 opengl.glDrawStringRight(str(self._minValue))
980 glTranslate(0,-scrollLength,0)
981 opengl.glDrawStringRight(str(self._maxValue))
982 if self._maxValue-self._minValue > 0:
983 glTranslate(w,scrollLength-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
984 opengl.glDrawStringLeft(str(self._value))
986 glColor4ub(255,255,255,240)
987 if self._maxValue - self._minValue != 0:
988 glTranslate(0.0,-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
990 glVertex2f( w/2,-w/2)
991 glVertex2f(-w/2,-w/2)
992 glVertex2f(-w/2, w/2)
993 glVertex2f( w/2, w/2)
997 def _checkHit(self, x, y):
1000 pos = self._getPixelPos()
1001 w, h = self.getMinSize()
1002 return -w/2 <= x - pos[0] <= w/2 and -h/2 <= y - pos[1] <= h/2
1005 self._base._focus = self
1008 def OnMouseMotion(self, x, y):
1010 w, h = self.getMinSize()
1011 scrollLength = h - w
1012 pos = self._getPixelPos()
1013 self.setValue(int(self._minValue + (self._maxValue - self._minValue) * -(y - pos[1] - scrollLength/2) / scrollLength))
1016 if self._checkHit(x, y):
1022 def OnMouseDown(self, x, y):
1023 if self._checkHit(x, y):
1025 self.OnMouseMotion(x, y)
1029 def OnMouseUp(self, x, y):
1031 self._base._focus = None