From: daid303 Date: Fri, 25 Jan 2013 10:52:21 +0000 (+0100) Subject: Add GL load file button, and improve the GLButton code a bit. X-Git-Tag: 13.03~78 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=d6c50322bdf41d5ce70a84b31bbf67ed53ebac88;p=cura.git Add GL load file button, and improve the GLButton code a bit. --- diff --git a/Cura/gui/preview3d.py b/Cura/gui/preview3d.py index 69b0828a..79ceeb68 100644 --- a/Cura/gui/preview3d.py +++ b/Cura/gui/preview3d.py @@ -111,10 +111,12 @@ class previewPanel(wx.Panel): self.scaleToolButton = openglGui.glButton(self.glCanvas, 2, 'Scale', 0,2, self.OnScaleSelect) self.resetRotationButton = openglGui.glButton(self.glCanvas, 4, 'Reset rotation', 1,0, self.OnRotateReset) - self.layFlatButton = openglGui.glButton(self.glCanvas, 5, 'Lay flat', 2,0, self.OnLayFlat) + self.layFlatButton = openglGui.glButton(self.glCanvas, 5, 'Lay flat', 2,0, self.OnLayFlat) - self.resetScaleButton = openglGui.glButton(self.glCanvas, 8, 'Scale reset', 1,0, self.OnScaleReset) - self.scaleMaxButton = openglGui.glButton(self.glCanvas, 9, 'Scale to machine size', 2,0, self.OnScaleMax) + self.resetScaleButton = openglGui.glButton(self.glCanvas, 8, 'Scale reset', 1,0, self.OnScaleReset) + self.scaleMaxButton = openglGui.glButton(self.glCanvas, 9, 'Scale to machine size', 2,0, self.OnScaleMax) + + self.openFileButton = openglGui.glButton(self.glCanvas, 3, 'Load file', -1,0, lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(1)) self.infoToolButton.setSelected(True) self.returnToModelViewAndUpdateModel() diff --git a/Cura/gui/util/openglGui.py b/Cura/gui/util/openglGui.py index ce362d5d..d5cfbc75 100644 --- a/Cura/gui/util/openglGui.py +++ b/Cura/gui/util/openglGui.py @@ -19,6 +19,7 @@ class glGuiPanel(glcanvas.GLCanvas): self._context = glcanvas.GLContext(self) self._glGuiControlList = [] self._buttonSize = 64 + self._allowDrag = False wx.EVT_PAINT(self, self._OnGuiPaint) wx.EVT_SIZE(self, self._OnSize) @@ -27,10 +28,17 @@ class glGuiPanel(glcanvas.GLCanvas): wx.EVT_MOTION(self, self._OnGuiMouseMotion) def _OnGuiMouseEvents(self,e): - if e.ButtonDown() and e.LeftIsDown(): - for ctrl in self._glGuiControlList: - if ctrl.OnMouseDown(e.GetX(), e.GetY()): - return + if e.ButtonDown(): + if e.LeftIsDown(): + for ctrl in self._glGuiControlList: + if ctrl.OnMouseDown(e.GetX(), e.GetY()): + return + self._allowDrag = True + print 1 + if e.ButtonUp(): + if not e.LeftIsDown() and not e.RightIsDown(): + self._allowDrag = False + print 0 def _OnGuiMouseMotion(self,e): self.Refresh() @@ -100,6 +108,17 @@ class glButton(object): def getSelected(self): return self._selected + def _getSize(self): + return self._parent._buttonSize + + def _getPixelPos(self): + bs = self._getSize() + x = self._x * bs * 1.3 + bs * 0.8 + y = self._y * bs * 1.3 + bs * 0.8 + if self._x < 0: + x = self._parent.GetSize().GetWidth() + x - bs * 0.2 + return x, y + def draw(self): global glButtonsTexture if self._hidden: @@ -110,9 +129,10 @@ class glButton(object): cx = (self._imageID % 4) / 4 cy = int(self._imageID / 4) / 4 bs = self._parent._buttonSize + pos = self._getPixelPos() glPushMatrix() - glTranslatef(self._x * bs * 1.3 + bs * 0.8, self._y * bs * 1.3 + bs * 0.8, 0) + glTranslatef(pos[0], pos[1], 0) glBindTexture(GL_TEXTURE_2D, glButtonsTexture) glEnable(GL_TEXTURE_2D) scale = 0.8 @@ -142,8 +162,9 @@ class glButton(object): def _checkHit(self, x, y): if self._hidden: return False - bs = self._parent._buttonSize - 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 + bs = self._getSize() + pos = self._getPixelPos() + return -bs * 0.5 <= x - pos[0] <= bs * 0.5 and -bs * 0.5 <= y - pos[1] <= bs * 0.5 def OnMouseMotion(self, x, y): if self._checkHit(x, y): @@ -155,3 +176,5 @@ class glButton(object): def OnMouseDown(self, x, y): if self._checkHit(x, y): self._callback() + return True + return False diff --git a/Cura/resources/images/glButtons.png b/Cura/resources/images/glButtons.png index 5da52833..b5f02a56 100644 Binary files a/Cura/resources/images/glButtons.png and b/Cura/resources/images/glButtons.png differ