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.OnKeyChar)
124 wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
126 def OnKeyChar(self, e):
127 if self._focus is not None:
128 self._focus.OnKeyChar(e.GetKeyCode())
131 def OnFocusLost(self, e):
135 def _OnGuiMouseLeftDown(self,e):
137 if self._container.OnMouseDown(e.GetX(), e.GetY()):
140 self.OnMouseLeftDown(e)
141 def _OnGuiMouseLeftUp(self, e):
142 if self._container.OnMouseUp(e.GetX(), e.GetY()):
145 self.OnMouseLeftUp(e)
147 def _OnGuiMouseMotion(self,e):
149 if not self._container.OnMouseMotion(e.GetX(), e.GetY()):
150 self.OnMouseMotion(e)
152 def _OnGuiPaint(self, e):
153 h = self.GetSize().GetHeight()
154 w = self.GetSize().GetWidth()
155 oldButtonSize = self._buttonSize
159 self._buttonSize = 32
161 self._buttonSize = 48
163 self._buttonSize = 64
165 self._buttonSize = 80
167 self._buttonSize = 96
168 if self._buttonSize != oldButtonSize:
169 self._container.updateLayout()
171 dc = wx.PaintDC(self)
173 self.SetCurrent(self._context)
179 errStr = 'An error has occurred during the 3D view drawing.'
180 tb = traceback.extract_tb(sys.exc_info()[2])
181 errStr += "\n%s: '%s'" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]))
182 for n in xrange(len(tb)-1, -1, -1):
184 errStr += "\n @ %s:%s:%d" % (os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
185 if not self._shownError:
186 wx.CallAfter(wx.MessageBox, errStr, '3D window error', wx.OK | wx.ICON_EXCLAMATION)
187 self._shownError = True
190 if self._glButtonsTexture is None:
191 self._glButtonsTexture = opengl.loadGLTexture('glButtons.png')
192 self._glRobotTexture = opengl.loadGLTexture('UltimakerRobot.png')
194 glDisable(GL_DEPTH_TEST)
196 glDisable(GL_LIGHTING)
197 glColor4ub(255,255,255,255)
199 glMatrixMode(GL_PROJECTION)
201 size = self.GetSize()
202 glOrtho(0, size.GetWidth()-1, size.GetHeight()-1, 0, -1000.0, 1000.0)
203 glMatrixMode(GL_MODELVIEW)
206 self._container.draw()
207 glBindTexture(GL_TEXTURE_2D, self._glRobotTexture)
208 glEnable(GL_TEXTURE_2D)
211 glTranslate(size.GetWidth() - 8,size.GetHeight() - 16,0)
212 s = self._buttonSize * 1.4
224 glDisable(GL_TEXTURE_2D)
227 def _OnEraseBackground(self,event):
228 #Workaround for windows background redraw flicker.
232 self._container.setSize(0, 0, self.GetSize().GetWidth(), self.GetSize().GetHeight())
233 self._container.updateLayout()
236 def OnMouseLeftDown(self,e):
238 def OnMouseLeftUp(self,e):
240 def OnMouseMotion(self, e):
242 def OnPaint(self, e):
246 if self._container is not None:
247 self._container.add(ctrl)
249 class glGuiLayoutButtons(object):
250 def __init__(self, parent):
251 self._parent = parent
252 self._parent._layout = self
255 bs = self._parent._base._buttonSize
256 x0, y0, w, h = self._parent.getSize()
258 for ctrl in self._parent._glGuiControlList:
261 x = w + pos[0] * gridSize - bs * 0.2
263 x = pos[0] * gridSize + bs * 0.2
265 y = h + pos[1] * gridSize * 1.2 - bs * 0.2
267 y = pos[1] * gridSize * 1.2 + bs * 0.2
268 ctrl.setSize(x, y, gridSize, gridSize)
270 def getLayoutSize(self):
271 _, _, w, h = self._parent.getSize()
274 class glGuiLayoutGrid(object):
275 def __init__(self, parent):
276 self._parent = parent
277 self._parent._layout = self
279 self._alignBottom = True
282 borderSize = self._parent._base._buttonSize * 0.2
283 x0, y0, w, h = self._parent.getSize()
288 for ctrl in self._parent._glGuiControlList:
290 w, h = ctrl.getMinSize()
294 widths[x] = max(widths[x], w)
298 heights[y] = max(heights[y], h)
299 self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
300 if self._alignBottom:
301 y0 -= self._size[1] - self._parent.getSize()[3]
302 self._parent.setSize(x0 - borderSize, y0 - borderSize, self._size[0], self._size[1])
303 for ctrl in self._parent._glGuiControlList:
307 for n in xrange(0, x):
311 for n in xrange(0, y):
315 ctrl.setSize(x1, y1, widths[x], heights[y])
317 def getLayoutSize(self):
320 class glButton(glGuiControl):
321 def __init__(self, parent, imageID, tooltip, pos, callback):
322 super(glButton, self).__init__(parent, pos)
323 self._tooltip = tooltip
324 self._parent = parent
325 self._imageID = imageID
326 self._callback = callback
327 self._selected = False
330 self._disabled = False
332 def setSelected(self, value):
333 self._selected = value
335 def setHidden(self, value):
338 def setDisabled(self, value):
339 self._disabled = value
341 def getSelected(self):
342 return self._selected
344 def getMinSize(self):
345 return self._base._buttonSize, self._base._buttonSize
347 def _getPixelPos(self):
348 x0, y0, w, h = self.getSize()
349 return x0 + w / 2, y0 + h / 2
355 cx = (self._imageID % 4) / 4
356 cy = int(self._imageID / 4) / 4
357 bs = self._base._buttonSize
358 pos = self._getPixelPos()
360 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
367 glColor4ub(128,128,128,128)
369 glColor4ub(255,255,255,255)
370 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, 0)
371 opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
373 glTranslatef(pos[0], pos[1], 0)
374 glDisable(GL_TEXTURE_2D)
376 glTranslatef(0, -0.55*bs*scale, 0)
379 glColor4ub(60,60,60,255)
380 glTranslatef(-1, -1, 0)
381 opengl.glDrawStringCenter(self._tooltip)
382 glTranslatef(0, 2, 0)
383 opengl.glDrawStringCenter(self._tooltip)
384 glTranslatef(2, 0, 0)
385 opengl.glDrawStringCenter(self._tooltip)
386 glTranslatef(0, -2, 0)
387 opengl.glDrawStringCenter(self._tooltip)
390 glColor4ub(255,255,255,255)
391 opengl.glDrawStringCenter(self._tooltip)
394 def _checkHit(self, x, y):
395 if self._hidden or self._disabled:
397 bs = self.getMinSize()[0]
398 pos = self._getPixelPos()
399 return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5
401 def OnMouseMotion(self, x, y):
402 if self._checkHit(x, y):
408 def OnMouseDown(self, x, y):
409 if self._checkHit(x, y):
414 class glRadioButton(glButton):
415 def __init__(self, parent, imageID, tooltip, pos, group, callback):
416 super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
418 self._radioCallback = callback
419 self._group.append(self)
421 def setSelected(self, value):
422 self._selected = value
424 def _onRadioSelect(self):
425 self._base._focus = None
426 for ctrl in self._group:
428 ctrl.setSelected(False)
429 if self.getSelected():
430 self.setSelected(False)
432 self.setSelected(True)
433 self._radioCallback()
435 class glComboButton(glButton):
436 def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
437 super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
438 self._imageIDs = imageIDs
439 self._tooltips = tooltips
440 self._comboCallback = callback
443 def _onComboOpenSelect(self):
445 self._base._focus = None
447 self._base._focus = self
452 self._selected = self.hasFocus()
453 super(glComboButton, self).draw()
455 bs = self._base._buttonSize / 2
456 pos = self._getPixelPos()
458 if not self._selected:
462 glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
463 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
464 for n in xrange(0, len(self._imageIDs)):
465 glTranslatef(0, bs, 0)
466 glColor4ub(255,255,255,255)
467 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
468 opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
469 glDisable(GL_TEXTURE_2D)
472 glTranslatef(-0.55*bs, 0.1*bs, 0)
475 glColor4ub(60,60,60,255)
476 glTranslatef(-1, -1, 0)
477 opengl.glDrawStringRight(self._tooltips[n])
478 glTranslatef(0, 2, 0)
479 opengl.glDrawStringRight(self._tooltips[n])
480 glTranslatef(2, 0, 0)
481 opengl.glDrawStringRight(self._tooltips[n])
482 glTranslatef(0, -2, 0)
483 opengl.glDrawStringRight(self._tooltips[n])
486 glColor4ub(255,255,255,255)
487 opengl.glDrawStringRight(self._tooltips[n])
492 return self._selection
494 def setValue(self, value):
495 self._selection = value
496 self._imageID = self._imageIDs[self._selection]
497 self._comboCallback()
499 def OnMouseDown(self, x, y):
500 if self._hidden or self._disabled:
503 bs = self._base._buttonSize / 2
504 pos = self._getPixelPos()
505 if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
506 self._selection = int((y - pos[1] - bs) / bs)
507 self._imageID = self._imageIDs[self._selection]
508 self._base._focus = None
509 self._comboCallback()
511 return super(glComboButton, self).OnMouseDown(x, y)
513 class glFrame(glGuiContainer):
514 def __init__(self, parent, pos):
515 super(glFrame, self).__init__(parent, pos)
516 self._selected = False
520 def setSelected(self, value):
521 self._selected = value
523 def setHidden(self, value):
526 def getSelected(self):
527 return self._selected
529 def getMinSize(self):
530 return self._base._buttonSize, self._base._buttonSize
532 def _getPixelPos(self):
533 x0, y0, w, h = self.getSize()
540 bs = self._parent._buttonSize
541 pos = self._getPixelPos()
544 glTranslatef(pos[0], pos[1], 0)
545 glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
546 glEnable(GL_TEXTURE_2D)
548 size = self._layout.getLayoutSize()
549 glColor4ub(255,255,255,255)
555 # glVertex2f( size[0], 0)
559 # glVertex2f( 0, size[1])
561 # glVertex2f( size[0], size[1])
567 glTexCoord2f(0, tc/2)
569 glTexCoord2f(tc, tc/2)
572 glTexCoord2f(tc+tc, 0)
573 glVertex2f( size[0], 0)
575 glVertex2f( size[0] - bs, 0)
576 glTexCoord2f(tc, tc/2)
577 glVertex2f( size[0] - bs, bs)
578 glTexCoord2f(tc+tc, tc/2)
579 glVertex2f( size[0], bs)
581 glTexCoord2f(tc, tc/2)
582 glVertex2f( bs, size[1] - bs)
583 glTexCoord2f(0, tc/2)
584 glVertex2f( 0, size[1] - bs)
585 glTexCoord2f(0, tc/2+tc/2)
586 glVertex2f( 0, size[1])
587 glTexCoord2f(tc, tc/2+tc/2)
588 glVertex2f( bs, size[1])
590 glTexCoord2f(tc+tc, tc/2)
591 glVertex2f( size[0], size[1] - bs)
592 glTexCoord2f(tc, tc/2)
593 glVertex2f( size[0] - bs, size[1] - bs)
594 glTexCoord2f(tc, tc/2+tc/2)
595 glVertex2f( size[0] - bs, size[1])
596 glTexCoord2f(tc+tc, tc/2+tc/2)
597 glVertex2f( size[0], size[1])
600 glTexCoord2f(tc, tc/2)
601 glVertex2f( size[0]-bs, bs)
602 glTexCoord2f(tc, tc/2)
604 glTexCoord2f(tc, tc/2)
605 glVertex2f( bs, size[1]-bs)
606 glTexCoord2f(tc, tc/2)
607 glVertex2f( size[0]-bs, size[1]-bs)
610 glTexCoord2f(tc+tc, tc/2)
611 glVertex2f( size[0], bs)
612 glTexCoord2f(tc, tc/2)
613 glVertex2f( size[0]-bs, bs)
614 glTexCoord2f(tc, tc/2)
615 glVertex2f( size[0]-bs, size[1]-bs)
616 glTexCoord2f(tc+tc, tc/2)
617 glVertex2f( size[0], size[1]-bs)
620 glTexCoord2f(tc, tc/2)
622 glTexCoord2f(0, tc/2)
624 glTexCoord2f(0, tc/2)
625 glVertex2f( 0, size[1]-bs)
626 glTexCoord2f(tc, tc/2)
627 glVertex2f( bs, size[1]-bs)
631 glVertex2f( size[0]-bs, 0)
634 glTexCoord2f(tc, tc/2)
636 glTexCoord2f(tc, tc/2)
637 glVertex2f( size[0]-bs, bs)
640 glTexCoord2f(tc, tc/2)
641 glVertex2f( size[0]-bs, size[1]-bs)
642 glTexCoord2f(tc, tc/2)
643 glVertex2f( bs, size[1]-bs)
644 glTexCoord2f(tc, tc/2+tc/2)
645 glVertex2f( bs, size[1])
646 glTexCoord2f(tc, tc/2+tc/2)
647 glVertex2f( size[0]-bs, size[1])
650 glDisable(GL_TEXTURE_2D)
652 #Draw the controls on the frame
653 super(glFrame, self).draw()
655 def _checkHit(self, x, y):
658 pos = self._getPixelPos()
659 w, h = self._layout.getLayoutSize()
660 return 0 <= x - pos[0] <= w and 0 <= y - pos[1] <= h
662 def OnMouseMotion(self, x, y):
663 super(glFrame, self).OnMouseMotion(x, y)
664 if self._checkHit(x, y):
670 def OnMouseDown(self, x, y):
671 if self._checkHit(x, y):
672 super(glFrame, self).OnMouseDown(x, y)
676 class glLabel(glGuiControl):
677 def __init__(self, parent, label, pos):
679 super(glLabel, self).__init__(parent, pos)
681 def getMinSize(self):
682 w, h = opengl.glGetStringSize(self._label)
685 def _getPixelPos(self):
686 x0, y0, w, h = self.getSize()
690 x, y, w, h = self.getSize()
693 glTranslatef(x, y, 0)
695 # glColor4ub(255,255,255,128)
707 glTranslate(5, h - 5, 0)
708 glColor4ub(255,255,255,255)
709 opengl.glDrawStringLeft(self._label)
712 def _checkHit(self, x, y):
715 def OnMouseMotion(self, x, y):
718 def OnMouseDown(self, x, y):
721 class glNumberCtrl(glGuiControl):
722 def __init__(self, parent, value, pos, callback):
723 self._callback = callback
724 self._value = str(value)
727 self._inCallback = False
728 super(glNumberCtrl, self).__init__(parent, pos)
730 def setValue(self, value):
733 self._value = str(value)
735 def getMinSize(self):
736 w, h = opengl.glGetStringSize("VALUES")
739 def _getPixelPos(self):
740 x0, y0, w, h = self.getSize()
744 x, y, w, h = self.getSize()
747 glTranslatef(x, y, 0)
750 glColor4ub(255,255,255,255)
752 glColor4ub(255,255,255,192)
764 glTranslate(5, h - 5, 0)
765 glColor4ub(0,0,0,255)
766 opengl.glDrawStringLeft(self._value)
768 glTranslate(opengl.glGetStringSize(self._value[0:self._selectPos])[0] - 2, -1, 0)
769 opengl.glDrawStringLeft('|')
772 def _checkHit(self, x, y):
773 x1, y1, w, h = self.getSize()
774 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
776 def OnMouseMotion(self, x, y):
779 def OnMouseDown(self, x, y):
780 if self._checkHit(x, y):
785 def OnKeyChar(self, c):
786 self._inCallback = True
789 self._selectPos = max(0, self._selectPos)
790 if c == wx.WXK_RIGHT:
792 self._selectPos = min(self._selectPos, len(self._value))
795 value = float(self._value)
800 self._value = str(value)
801 self._callback(self._value)
804 value = float(self._value)
810 self._value = str(value)
811 self._callback(self._value)
812 if c == wx.WXK_BACK and self._selectPos > 0:
813 self._value = self._value[0:self._selectPos - 1] + self._value[self._selectPos:]
815 self._callback(self._value)
816 if c == wx.WXK_DELETE:
817 self._value = self._value[0:self._selectPos] + self._value[self._selectPos + 1:]
818 self._callback(self._value)
820 if wx.GetKeyState(wx.WXK_SHIFT):
824 if (ord('0') <= c <= ord('9') or c == ord('.')) and len(self._value) < self._maxLen:
825 self._value = self._value[0:self._selectPos] + chr(c) + self._value[self._selectPos:]
827 self._callback(self._value)
828 self._inCallback = False
831 self._base._focus = self
832 self._selectPos = len(self._value)
835 class glCheckbox(glGuiControl):
836 def __init__(self, parent, value, pos, callback):
837 self._callback = callback
841 self._inCallback = False
842 super(glCheckbox, self).__init__(parent, pos)
844 def setValue(self, value):
847 self._value = str(value)
852 def getMinSize(self):
855 def _getPixelPos(self):
856 x0, y0, w, h = self.getSize()
860 x, y, w, h = self.getSize()
863 glTranslatef(x, y, 0)
865 glColor3ub(255,255,255)
867 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 28)
869 opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 29)
873 def _checkHit(self, x, y):
874 x1, y1, w, h = self.getSize()
875 return 0 <= x - x1 <= w and 0 <= y - y1 <= h
877 def OnMouseMotion(self, x, y):
880 def OnMouseDown(self, x, y):
881 if self._checkHit(x, y):
882 self._value = not self._value
886 class glSlider(glGuiControl):
887 def __init__(self, parent, value, minValue, maxValue, pos, callback):
888 super(glSlider, self).__init__(parent, pos)
889 self._callback = callback
893 self._minValue = minValue
894 self._maxValue = maxValue
896 def setValue(self, value):
898 self._value = max(self._minValue, self._value)
899 self._value = min(self._maxValue, self._value)
904 def setRange(self, minValue, maxValue):
905 if maxValue < minValue:
907 self._minValue = minValue
908 self._maxValue = maxValue
909 self._value = max(minValue, self._value)
910 self._value = min(maxValue, self._value)
912 def getMinValue(self):
913 return self._minValue
915 def getMaxValue(self):
916 return self._maxValue
918 def setHidden(self, value):
921 def getMinSize(self):
922 return self._base._buttonSize * 0.2, self._base._buttonSize * 4
924 def _getPixelPos(self):
925 x0, y0, w, h = self.getSize()
926 minSize = self.getMinSize()
927 return x0 + w / 2 - minSize[0] / 2, y0 + h / 2 - minSize[1] / 2
933 w, h = self.getMinSize()
934 pos = self._getPixelPos()
937 glTranslatef(pos[0], pos[1], 0)
938 glDisable(GL_TEXTURE_2D)
940 glColor4ub(60,60,60,255)
942 glColor4ub(60,60,60,192)
944 glVertex2f( w/2,-h/2)
945 glVertex2f(-w/2,-h/2)
946 glVertex2f(-w/2, h/2)
947 glVertex2f( w/2, h/2)
950 glTranslate(0.0,scrollLength/2,0)
952 glColor4ub(0,0,0,255)
954 glTranslate(-w/2,opengl.glGetStringSize(str(self._minValue))[1]/2,0)
955 opengl.glDrawStringRight(str(self._minValue))
956 glTranslate(0,-scrollLength,0)
957 opengl.glDrawStringRight(str(self._maxValue))
958 if self._maxValue-self._minValue > 0:
959 glTranslate(w,scrollLength-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
960 opengl.glDrawStringLeft(str(self._value))
962 glColor4ub(255,255,255,240)
963 if self._maxValue - self._minValue != 0:
964 glTranslate(0.0,-scrollLength*((self._value-self._minValue)/(self._maxValue-self._minValue)),0)
966 glVertex2f( w/2,-w/2)
967 glVertex2f(-w/2,-w/2)
968 glVertex2f(-w/2, w/2)
969 glVertex2f( w/2, w/2)
973 def _checkHit(self, x, y):
976 pos = self._getPixelPos()
977 w, h = self.getMinSize()
978 return -w/2 <= x - pos[0] <= w/2 and -h/2 <= y - pos[1] <= h/2
981 self._base._focus = self
984 def OnMouseMotion(self, x, y):
986 w, h = self.getMinSize()
988 pos = self._getPixelPos()
989 self.setValue(int(self._minValue + (self._maxValue - self._minValue) * -(y - pos[1] - scrollLength/2) / scrollLength))
992 if self._checkHit(x, y):
998 def OnMouseDown(self, x, y):
999 if self._checkHit(x, y):
1001 self.OnMouseMotion(x, y)
1005 def OnMouseUp(self, x, y):
1007 self._base._focus = None