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_DCLICK(self, self._OnGuiMouseDown)
124 wx.EVT_LEFT_UP(self, self._OnGuiMouseUp)
125 wx.EVT_RIGHT_DOWN(self, self._OnGuiMouseDown)
126 wx.EVT_RIGHT_DCLICK(self, self._OnGuiMouseDown)
127 wx.EVT_RIGHT_UP(self, self._OnGuiMouseUp)
128 wx.EVT_MIDDLE_DOWN(self, self._OnGuiMouseDown)
129 wx.EVT_MIDDLE_DCLICK(self, self._OnGuiMouseDown)
130 wx.EVT_MIDDLE_UP(self, self._OnGuiMouseUp)
131 wx.EVT_MOTION(self, self._OnGuiMouseMotion)
132 wx.EVT_CHAR(self, self._OnGuiKeyChar)
133 wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
135 def _OnGuiKeyChar(self, e):
136 if self._focus is not None:
137 self._focus.OnKeyChar(e.GetKeyCode())
140 self.OnKeyChar(e.GetKeyCode())
142 def OnFocusLost(self, e):
146 def _OnGuiMouseDown(self,e):
148 if self._container.OnMouseDown(e.GetX(), e.GetY()):
153 def _OnGuiMouseUp(self, e):
154 if self._container.OnMouseUp(e.GetX(), e.GetY()):
159 def _OnGuiMouseMotion(self,e):
161 if not self._container.OnMouseMotion(e.GetX(), e.GetY()):
162 self.OnMouseMotion(e)
164 def _OnGuiPaint(self, e):
165 h = self.GetSize().GetHeight()
166 w = self.GetSize().GetWidth()
167 oldButtonSize = self._buttonSize
171 self._buttonSize = 32
173 self._buttonSize = 48
175 self._buttonSize = 64
177 self._buttonSize = 80
179 self._buttonSize = 96
180 if self._buttonSize != oldButtonSize:
181 self._container.updateLayout()
183 dc = wx.PaintDC(self)
185 self.SetCurrent(self._context)
186 for obj in self.glReleaseList:
188 del self.glReleaseList[:]
194 errStr = 'An error has occurred during the 3D view drawing.'
195 tb = traceback.extract_tb(sys.exc_info()[2])
196 errStr += "\n%s: '%s'" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]))
197 for n in xrange(len(tb)-1, -1, -1):
199 errStr += "\n @ %s:%s:%d" % (os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
200 if not self._shownError:
201 wx.CallAfter(wx.MessageBox, errStr, '3D window error', wx.OK | wx.ICON_EXCLAMATION)
202 self._shownError = True
205 if self._glButtonsTexture is None:
206 self._glButtonsTexture = opengl.loadGLTexture('glButtons.png')
207 self._glRobotTexture = opengl.loadGLTexture('UltimakerRobot.png')
209 glDisable(GL_DEPTH_TEST)
211 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
212 glDisable(GL_LIGHTING)
213 glColor4ub(255,255,255,255)
215 glMatrixMode(GL_PROJECTION)
217 size = self.GetSize()
218 glOrtho(0, size.GetWidth()-1, size.GetHeight()-1, 0, -1000.0, 1000.0)
219 glMatrixMode(GL_MODELVIEW)
222 self._container.draw()
223 glBindTexture(GL_TEXTURE_2D, self._glRobotTexture)
224 glEnable(GL_TEXTURE_2D)
227 glTranslate(size.GetWidth() - 8,size.GetHeight() - 16,0)
228 s = self._buttonSize * 1.4
240 glDisable(GL_TEXTURE_2D)
243 def _OnEraseBackground(self,event):
244 #Workaround for windows background redraw flicker.
248 self._container.setSize(0, 0, self.GetSize().GetWidth(), self.GetSize().GetHeight())
249 self._container.updateLayout()
252 def OnMouseDown(self,e):
254 def OnMouseUp(self,e):
256 def OnMouseMotion(self, e):
258 def OnKeyChar(self, keyCode):
260 def OnPaint(self, e):
264 if self._container is not None:
265 self._container.add(ctrl)
267 class glGuiLayoutButtons(object):
268 def __init__(self, parent):
269 self._parent = parent
270 self._parent._layout = self
273 bs = self._parent._base._buttonSize
274 x0, y0, w, h = self._parent.getSize()
276 for ctrl in self._parent._glGuiControlList:
279 x = w + pos[0] * gridSize - bs * 0.2
281 x = pos[0] * gridSize + bs * 0.2
283 y = h + pos[1] * gridSize * 1.2 - bs * 0.2
285 y = pos[1] * gridSize * 1.2 + bs * 0.2
286 ctrl.setSize(x, y, gridSize, gridSize)
288 def getLayoutSize(self):
289 _, _, w, h = self._parent.getSize()
292 class glGuiLayoutGrid(object):
293 def __init__(self, parent):
294 self._parent = parent
295 self._parent._layout = self
297 self._alignBottom = True
300 borderSize = self._parent._base._buttonSize * 0.2
301 x0, y0, w, h = self._parent.getSize()
306 for ctrl in self._parent._glGuiControlList:
308 w, h = ctrl.getMinSize()
312 widths[x] = max(widths[x], w)
316 heights[y] = max(heights[y], h)
317 self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
318 if self._alignBottom:
319 y0 -= self._size[1] - self._parent.getSize()[3]
320 self._parent.setSize(x0 - borderSize, y0 - borderSize, self._size[0], self._size[1])
321 for ctrl in self._parent._glGuiControlList:
325 for n in xrange(0, x):
329 for n in xrange(0, y):
333 ctrl.setSize(x1, y1, widths[x], heights[y])
335 def getLayoutSize(self):
338 class glButton(glGuiControl):
339 def __init__(self, parent, imageID, tooltip, pos, callback):
340 super(glButton, self).__init__(parent, pos)
341 self._tooltip = tooltip
342 self._parent = parent
343 self._imageID = imageID
344 self._callback = callback
345 self._selected = False
348 self._disabled = False
349 self._showExpandArrow = False
351 def setSelected(self, value):
352 self._selected = value
354 def setExpandArrow(self, value):
355 self._showExpandArrow = value
357 def setHidden(self, value):
360 def setDisabled(self, value):
361 self._disabled = value
363 def getSelected(self):
364 return self._selected
366 def getMinSize(self):
367 return self._base._buttonSize, self._base._buttonSize
369 def _getPixelPos(self):
370 x0, y0, w, h = self.getSize()
371 return x0 + w / 2, y0 + h / 2
377 cx = (self._imageID % 4) / 4
378 cy = int(self._imageID / 4) / 4
379 bs = self._base._buttonSize
380 pos = self._getPixelPos()
382 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
389 glColor4ub(128,128,128,128)
391 glColor4ub(255,255,255,255)
392 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, 0)
393 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
394 if self._showExpandArrow:
396 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)
398 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)
400 glTranslatef(pos[0], pos[1], 0)
401 glDisable(GL_TEXTURE_2D)
403 glTranslatef(0, -0.55*bs*scale, 0)
406 glColor4ub(60,60,60,255)
407 glTranslatef(-1, -1, 0)
408 opengl.glDrawStringCenter(self._tooltip)
409 glTranslatef(0, 2, 0)
410 opengl.glDrawStringCenter(self._tooltip)
411 glTranslatef(2, 0, 0)
412 opengl.glDrawStringCenter(self._tooltip)
413 glTranslatef(0, -2, 0)
414 opengl.glDrawStringCenter(self._tooltip)
417 glColor4ub(255,255,255,255)
418 opengl.glDrawStringCenter(self._tooltip)
421 def _checkHit(self, x, y):
422 if self._hidden or self._disabled:
424 bs = self.getMinSize()[0]
425 pos = self._getPixelPos()
426 return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5
428 def OnMouseMotion(self, x, y):
429 if self._checkHit(x, y):
435 def OnMouseDown(self, x, y):
436 if self._checkHit(x, y):
441 class glRadioButton(glButton):
442 def __init__(self, parent, imageID, tooltip, pos, group, callback):
443 super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
445 self._radioCallback = callback
446 self._group.append(self)
448 def setSelected(self, value):
449 self._selected = value
451 def _onRadioSelect(self):
452 self._base._focus = None
453 for ctrl in self._group:
455 ctrl.setSelected(False)
456 if self.getSelected():
457 self.setSelected(False)
459 self.setSelected(True)
460 self._radioCallback()
462 class glComboButton(glButton):
463 def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
464 super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
465 self._imageIDs = imageIDs
466 self._tooltips = tooltips
467 self._comboCallback = callback
470 def _onComboOpenSelect(self):
472 self._base._focus = None
474 self._base._focus = self
479 self._selected = self.hasFocus()
480 super(glComboButton, self).draw()
482 bs = self._base._buttonSize / 2
483 pos = self._getPixelPos()
485 if not self._selected:
489 glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
490 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
491 for n in xrange(0, len(self._imageIDs)):
492 glTranslatef(0, bs, 0)
493 glColor4ub(255,255,255,255)
494 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
495 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
496 glDisable(GL_TEXTURE_2D)
499 glTranslatef(-0.55*bs, 0.1*bs, 0)
502 glColor4ub(60,60,60,255)
503 glTranslatef(-1, -1, 0)
504 opengl.glDrawStringRight(self._tooltips[n])
505 glTranslatef(0, 2, 0)
506 opengl.glDrawStringRight(self._tooltips[n])
507 glTranslatef(2, 0, 0)
508 opengl.glDrawStringRight(self._tooltips[n])
509 glTranslatef(0, -2, 0)
510 opengl.glDrawStringRight(self._tooltips[n])
513 glColor4ub(255,255,255,255)
514 opengl.glDrawStringRight(self._tooltips[n])
519 return self._selection
521 def setValue(self, value):
522 self._selection = value
523 self._imageID = self._imageIDs[self._selection]
524 self._comboCallback()
526 def OnMouseDown(self, x, y):
527 if self._hidden or self._disabled:
530 bs = self._base._buttonSize / 2
531 pos = self._getPixelPos()
532 if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
533 self._selection = int((y - pos[1] - bs) / bs)
534 self._imageID = self._imageIDs[self._selection]
535 self._base._focus = None
536 self._comboCallback()
538 return super(glComboButton, self).OnMouseDown(x, y)
540 class glFrame(glGuiContainer):
541 def __init__(self, parent, pos):
542 super(glFrame, self).__init__(parent, pos)
543 self._selected = False
547 def setSelected(self, value):
548 self._selected = value
550 def setHidden(self, value):
553 def getSelected(self):
554 return self._selected
556 def getMinSize(self):
557 return self._base._buttonSize, self._base._buttonSize
559 def _getPixelPos(self):
560 x0, y0, w, h = self.getSize()
567 bs = self._parent._buttonSize
568 pos = self._getPixelPos()
571 glTranslatef(pos[0], pos[1], 0)
572 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
573 glEnable(GL_TEXTURE_2D)
575 size = self._layout.getLayoutSize()
576 glColor4ub(255,255,255,255)
582 # glVertex2f( size[0], 0)
586 # glVertex2f( 0, size[1])
588 # glVertex2f( size[0], size[1])
594 glTexCoord2f(0, tc/2)
596 glTexCoord2f(tc, tc/2)
599 glTexCoord2f(tc+tc, 0)
600 glVertex2f( size[0], 0)
602 glVertex2f( size[0] - bs, 0)
603 glTexCoord2f(tc, tc/2)
604 glVertex2f( size[0] - bs, bs)
605 glTexCoord2f(tc+tc, tc/2)
606 glVertex2f( size[0], bs)
608 glTexCoord2f(tc, tc/2)
609 glVertex2f( bs, size[1] - bs)
610 glTexCoord2f(0, tc/2)
611 glVertex2f( 0, size[1] - bs)
612 glTexCoord2f(0, tc/2+tc/2)
613 glVertex2f( 0, size[1])
614 glTexCoord2f(tc, tc/2+tc/2)
615 glVertex2f( bs, size[1])
617 glTexCoord2f(tc+tc, tc/2)
618 glVertex2f( size[0], size[1] - bs)
619 glTexCoord2f(tc, tc/2)
620 glVertex2f( size[0] - bs, size[1] - bs)
621 glTexCoord2f(tc, tc/2+tc/2)
622 glVertex2f( size[0] - bs, size[1])
623 glTexCoord2f(tc+tc, tc/2+tc/2)
624 glVertex2f( size[0], size[1])
627 glTexCoord2f(tc, tc/2)
628 glVertex2f( size[0]-bs, bs)
629 glTexCoord2f(tc, tc/2)
631 glTexCoord2f(tc, tc/2)
632 glVertex2f( bs, size[1]-bs)
633 glTexCoord2f(tc, tc/2)
634 glVertex2f( size[0]-bs, size[1]-bs)
637 glTexCoord2f(tc+tc, tc/2)
638 glVertex2f( size[0], bs)
639 glTexCoord2f(tc, tc/2)
640 glVertex2f( size[0]-bs, bs)
641 glTexCoord2f(tc, tc/2)
642 glVertex2f( size[0]-bs, size[1]-bs)
643 glTexCoord2f(tc+tc, tc/2)
644 glVertex2f( size[0], size[1]-bs)
647 glTexCoord2f(tc, tc/2)
649 glTexCoord2f(0, tc/2)
651 glTexCoord2f(0, tc/2)
652 glVertex2f( 0, size[1]-bs)
653 glTexCoord2f(tc, tc/2)
654 glVertex2f( bs, size[1]-bs)
658 glVertex2f( size[0]-bs, 0)
661 glTexCoord2f(tc, tc/2)
663 glTexCoord2f(tc, tc/2)
664 glVertex2f( size[0]-bs, bs)
667 glTexCoord2f(tc, tc/2)
668 glVertex2f( size[0]-bs, size[1]-bs)
669 glTexCoord2f(tc, tc/2)
670 glVertex2f( bs, size[1]-bs)
671 glTexCoord2f(tc, tc/2+tc/2)
672 glVertex2f( bs, size[1])
673 glTexCoord2f(tc, tc/2+tc/2)
674 glVertex2f( size[0]-bs, size[1])
677 glDisable(GL_TEXTURE_2D)
679 #Draw the controls on the frame
680 super(glFrame, self).draw()
682 def _checkHit(self, x, y):
685 pos = self._getPixelPos()
686 w, h = self._layout.getLayoutSize()
687 return 0 <= x - pos[0] <= w and 0 <= y - pos[1] <= h
689 def OnMouseMotion(self, x, y):
690 super(glFrame, self).OnMouseMotion(x, y)
691 if self._checkHit(x, y):
697 def OnMouseDown(self, x, y):
698 if self._checkHit(x, y):
699 super(glFrame, self).OnMouseDown(x, y)
703 class glLabel(glGuiControl):
704 def __init__(self, parent, label, pos):
706 super(glLabel, self).__init__(parent, pos)
708 def getMinSize(self):
709 w, h = opengl.glGetStringSize(self._label)
712 def _getPixelPos(self):
713 x0, y0, w, h = self.getSize()
717 x, y, w, h = self.getSize()
720 glTranslatef(x, y, 0)
722 # glColor4ub(255,255,255,128)
734 glTranslate(5, h - 5, 0)
735 glColor4ub(255,255,255,255)
736 opengl.glDrawStringLeft(self._label)
739 def _checkHit(self, x, y):
742 def OnMouseMotion(self, x, y):
745 def OnMouseDown(self, x, y):
748 class glNumberCtrl(glGuiControl):
749 def __init__(self, parent, value, pos, callback):
750 self._callback = callback
751 self._value = str(value)
754 self._inCallback = False
755 super(glNumberCtrl, self).__init__(parent, pos)
757 def setValue(self, value):
760 self._value = str(value)
762 def getMinSize(self):
763 w, h = opengl.glGetStringSize("VALUES")
766 def _getPixelPos(self):
767 x0, y0, w, h = self.getSize()
771 x, y, w, h = self.getSize()
774 glTranslatef(x, y, 0)
777 glColor4ub(255,255,255,255)
779 glColor4ub(255,255,255,192)
791 glTranslate(5, h - 5, 0)
792 glColor4ub(0,0,0,255)
793 opengl.glDrawStringLeft(self._value)
795 glTranslate(opengl.glGetStringSize(self._value[0:self._selectPos])[0] - 2, -1, 0)
796 opengl.glDrawStringLeft('|')
799 def _checkHit(self, x, y):
800 x1, y1, w, h = self.getSize()
801 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
803 def OnMouseMotion(self, x, y):
806 def OnMouseDown(self, x, y):
807 if self._checkHit(x, y):
812 def OnKeyChar(self, c):
813 self._inCallback = True
816 self._selectPos = max(0, self._selectPos)
817 if c == wx.WXK_RIGHT:
819 self._selectPos = min(self._selectPos, len(self._value))
822 value = float(self._value)
827 self._value = str(value)
828 self._callback(self._value)
831 value = float(self._value)
837 self._value = str(value)
838 self._callback(self._value)
839 if c == wx.WXK_BACK and self._selectPos > 0:
840 self._value = self._value[0:self._selectPos - 1] + self._value[self._selectPos:]
842 self._callback(self._value)
843 if c == wx.WXK_DELETE:
844 self._value = self._value[0:self._selectPos] + self._value[self._selectPos + 1:]
845 self._callback(self._value)
846 if c == wx.WXK_TAB or c == wx.WXK_NUMPAD_ENTER or c == wx.WXK_RETURN:
847 if wx.GetKeyState(wx.WXK_SHIFT):
851 if (ord('0') <= c <= ord('9') or c == ord('.')) and len(self._value) < self._maxLen:
852 self._value = self._value[0:self._selectPos] + chr(c) + self._value[self._selectPos:]
854 self._callback(self._value)
855 self._inCallback = False
858 self._base._focus = self
859 self._selectPos = len(self._value)
862 class glCheckbox(glGuiControl):
863 def __init__(self, parent, value, pos, callback):
864 self._callback = callback
868 self._inCallback = False
869 super(glCheckbox, self).__init__(parent, pos)
871 def setValue(self, value):
874 self._value = str(value)
879 def getMinSize(self):
882 def _getPixelPos(self):
883 x0, y0, w, h = self.getSize()
887 x, y, w, h = self.getSize()
890 glTranslatef(x, y, 0)
892 glColor3ub(255,255,255)
894 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 28)
896 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 29)
900 def _checkHit(self, x, y):
901 x1, y1, w, h = self.getSize()
902 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
904 def OnMouseMotion(self, x, y):
907 def OnMouseDown(self, x, y):
908 if self._checkHit(x, y):
909 self._value = not self._value
913 class glSlider(glGuiControl):
914 def __init__(self, parent, value, minValue, maxValue, pos, callback):
915 super(glSlider, self).__init__(parent, pos)
916 self._callback = callback
920 self._minValue = minValue
921 self._maxValue = maxValue
923 def setValue(self, value):
925 self._value = max(self._minValue, self._value)
926 self._value = min(self._maxValue, self._value)
931 def setRange(self, minValue, maxValue):
932 if maxValue < minValue:
934 self._minValue = minValue
935 self._maxValue = maxValue
936 self._value = max(minValue, self._value)
937 self._value = min(maxValue, self._value)
939 def getMinValue(self):
940 return self._minValue
942 def getMaxValue(self):
943 return self._maxValue
945 def setHidden(self, value):
948 def getMinSize(self):
949 return self._base._buttonSize * 0.2, self._base._buttonSize * 4
951 def _getPixelPos(self):
952 x0, y0, w, h = self.getSize()
953 minSize = self.getMinSize()
954 return x0 + w / 2 - minSize[0] / 2, y0 + h / 2 - minSize[1] / 2
960 w, h = self.getMinSize()
961 pos = self._getPixelPos()
964 glTranslatef(pos[0], pos[1], 0)
965 glDisable(GL_TEXTURE_2D)
967 glColor4ub(60,60,60,255)
969 glColor4ub(60,60,60,192)
971 glVertex2f( w/2,-h/2)
972 glVertex2f(-w/2,-h/2)
973 glVertex2f(-w/2, h/2)
974 glVertex2f( w/2, h/2)
977 glTranslate(0.0,scrollLength/2,0)
979 glColor4ub(0,0,0,255)
981 glTranslate(-w/2,opengl.glGetStringSize(str(self._minValue))[1]/2,0)
982 opengl.glDrawStringRight(str(self._minValue))
983 glTranslate(0,-scrollLength,0)
984 opengl.glDrawStringRight(str(self._maxValue))
985 if self._maxValue-self._minValue > 0:
986 glTranslate(w,scrollLength-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
987 opengl.glDrawStringLeft(str(self._value))
989 glColor4ub(255,255,255,240)
990 if self._maxValue - self._minValue != 0:
991 glTranslate(0.0,-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
993 glVertex2f( w/2,-w/2)
994 glVertex2f(-w/2,-w/2)
995 glVertex2f(-w/2, w/2)
996 glVertex2f( w/2, w/2)
1000 def _checkHit(self, x, y):
1003 pos = self._getPixelPos()
1004 w, h = self.getMinSize()
1005 return -w/2 <= x - pos[0] <= w/2 and -h/2 <= y - pos[1] <= h/2
1008 self._base._focus = self
1011 def OnMouseMotion(self, x, y):
1013 w, h = self.getMinSize()
1014 scrollLength = h - w
1015 pos = self._getPixelPos()
1016 self.setValue(int(self._minValue + (self._maxValue - self._minValue) * -(y - pos[1] - scrollLength/2) / scrollLength))
1019 if self._checkHit(x, y):
1025 def OnMouseDown(self, x, y):
1026 if self._checkHit(x, y):
1028 self.OnMouseMotion(x, y)
1032 def OnMouseUp(self, x, y):
1034 self._base._focus = None