1 from __future__ import absolute_import
2 from __future__ import division
5 OpenGL.ERROR_CHECKING = False
6 from OpenGL.GL import *
8 from Cura.gui.util import opengl
10 glButtonsTexture = None
12 class glButton(object):
13 def __init__(self, parent, imageID, x, y, callback):
15 self._imageID = imageID
18 self._callback = callback
19 self._parent.glButtonList.append(self)
20 self._selected = False
24 def setSelected(self, value):
25 self._selected = value
27 def setHidden(self, value):
30 def getSelected(self):
34 global glButtonsTexture
37 if glButtonsTexture is None:
38 glButtonsTexture = opengl.loadGLTexture('glButtons.png')
40 cx = (self._imageID % 4) / 4
41 cy = int(self._imageID / 4) / 4
42 bs = self._parent.buttonSize
45 glTranslatef(self._x * bs * 1.3 + bs * 0.8, self._y * bs * 1.3 + bs * 0.8, 0)
46 glBindTexture(GL_TEXTURE_2D, glButtonsTexture)
47 glEnable(GL_TEXTURE_2D)
53 glScalef(bs * scale, bs * scale, bs * scale)
55 glTexCoord2f(cx+0.25, cy)
59 glTexCoord2f(cx, cy+0.25)
61 glTexCoord2f(cx+0.25, cy+0.25)
64 glDisable(GL_TEXTURE_2D)
67 def _checkHit(self, x, y):
70 bs = self._parent.buttonSize
71 return -bs * 0.5 <= x - (self._x * bs * 1.3 + bs * 0.8) <= bs * 0.5 and -bs * 0.5 <= y - (self._y * bs * 1.3 + bs * 0.8) <= bs * 0.5
73 def OnMouseMotion(self, x, y):
74 if self._checkHit(x, y):
80 def OnMouseDown(self, x, y):
81 if self._checkHit(x, y):