def OnDraw(self): # Get colormaps that apply par = self.parent if par is None: return elif isinstance(par, (BaseFigure, Axes)): mapables = par.FindObjects(Colormapable) elif isinstance(par, ColormapEditor): mapables = par.GetMapables() elif isinstance(par, ClimEditor): mapables = par.GetMapables() else: mapables = [] # Get the last one mapable = None if mapables: mapable = mapables[-1] # get dimensions w,h = self.position.size # Calc map direction if w > h: texCords = [0,0,1,1] else: texCords = [1,0,0,1] # draw plane if mapable: # Use it's colormap texture mapable._EnableColormap() # Disable alpha channel (by not blending) gl.glDisable(gl.GL_BLEND) gl.glColor(1.0, 1.0, 1.0, 1.0) # Draw quads gl.glBegin(gl.GL_QUADS) gl.glTexCoord1f(texCords[0]); gl.glVertex2f(0,0) gl.glTexCoord1f(texCords[1]); gl.glVertex2f(0,h) gl.glTexCoord1f(texCords[2]); gl.glVertex2f(w,h) gl.glTexCoord1f(texCords[3]); gl.glVertex2f(w,0) gl.glEnd() # Clean up gl.glEnable(gl.GL_BLEND) gl.glFlush() mapable._DisableColormap() # prepare gl.glDisable(gl.GL_LINE_SMOOTH) # draw edges if self.edgeWidth and self.edgeColor: clr = self.edgeColor gl.glColor(clr[0], clr[1], clr[2], 1.0) gl.glLineWidth(self.edgeWidth) # gl.glBegin(gl.GL_LINE_LOOP) gl.glVertex2f(0,0) gl.glVertex2f(0,h) gl.glVertex2f(w,h) gl.glVertex2f(w,0) gl.glEnd() if hasattr(mapable, 'clim'): # Draw ticks if w>h: p0 = Point(0, h) p1 = Point(w, h) delta = Point(0,3) halign, valign = 0, 0 xoffset, yoffset = -8, -2 else: p0 = Point(w, h) p1 = Point(w, 0) delta = Point(3,0) halign, valign = -1, 0 xoffset, yoffset = 5, -8 # Get tickmarks ticks, ticksPos, ticksText = GetTicks(p0, p1, mapable.clim) newLabelPool = {} linePieces = Pointset(2) for tick, pos, text in zip(ticks, ticksPos, ticksText): pos2 = pos + delta # Add line piece linePieces.append(pos); linePieces.append(pos2) # Create or reuse label if tick in self._labelPool: label = self._labelPool.pop(tick) else: label = Label(self, ' '+text+' ') label.bgcolor = '' # Position label and set text alignment newLabelPool[tick] = label label.halign, label.valign = halign, valign label.position.x = pos2.x + xoffset label.position.w = 16 label.position.y = pos2.y + yoffset # Clean up label pool for label in list(self._labelPool.values()): label.Destroy() self._labelPool = newLabelPool # Draw line pieces # prepare gl.glLineWidth(1) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(linePieces.data) gl.glDrawArrays(gl.GL_LINES, 0, len(linePieces)) gl.glDisableClientState(gl.GL_VERTEX_ARRAY) # clean up gl.glEnable(gl.GL_LINE_SMOOTH)
def OnDraw(self): # Draw bg color and edges Box.OnDraw(self) # Margin d1 = 2 d2 = d1+1 # Get normalize limits t1, t2 = self._getNormalizedSliderLimits() # Get widget shape w, h = self.position.size # Calculate real dimensions of patch if w > h: x1, x2 = max(d2, t1*w), min(w-d1, t2*w) y1, y2 = d1, h-d2 # dots1 = self._dots1 + Point(x1, 0) dots2 = self._dots2 + Point(x2, 0) # diff = abs(x1-x2) # self._label.textAngle = 0 else: x1, x2 = d2, w-d1 y1, y2 = max(d1, t1*h), min(h-d2, t2*h) # dots1 = self._dots1 + Point(0, y1) dots2 = self._dots2 + Point(0, y2) # diff = abs(y1-y2) # self._label.textAngle = -90 # Draw slider bit clr = self._frontColor gl.glColor(clr[0], clr[1], clr[2], 1.0) # gl.glBegin(gl.GL_POLYGON) gl.glVertex2f(x1,y1) gl.glVertex2f(x1,y2) gl.glVertex2f(x2,y2) gl.glVertex2f(x2,y1) gl.glEnd() # Draw dots if True: # Prepare gl.glColor(0,0,0,1) gl.glPointSize(1) gl.glDisable(gl.GL_POINT_SMOOTH) # Draw gl.glEnableClientState(gl.GL_VERTEX_ARRAY) if isinstance(self, RangeSlider) and diff>5: gl.glVertexPointerf(dots1.data) gl.glDrawArrays(gl.GL_POINTS, 0, len(dots1)) if diff>5: gl.glVertexPointerf(dots2.data) gl.glDrawArrays(gl.GL_POINTS, 0, len(dots2)) gl.glDisableClientState(gl.GL_VERTEX_ARRAY) if self._showTicks: # Reset color to black gl.glColor(0,0,0,1) # Draw ticks if w>h: p0 = Point(0, h) p1 = Point(w, h) delta = Point(0,3) halign, valign = 0, 0 xoffset, yoffset = -8, -2 else: p0 = Point(w, h) p1 = Point(w, 0) delta = Point(3,0) halign, valign = -1, 0 xoffset, yoffset = 5, -8 # Get tickmarks ticks, ticksPos, ticksText = GetTicks(p0, p1, self._fullRange) newLabelPool = {} linePieces = Pointset(2) for tick, pos, text in zip(ticks, ticksPos, ticksText): pos2 = pos + delta # Add line piece linePieces.append(pos); linePieces.append(pos2) # Create or reuse label if tick in self._labelPool: label = self._labelPool.pop(tick) else: label = Label(self, ' '+text+' ') label.bgcolor = '' # Position label and set text alignment newLabelPool[tick] = label label.halign, label.valign = halign, valign label.position.x = pos2.x + xoffset label.position.w = 16 label.position.y = pos2.y + yoffset # Clean up label pool for label in self._labelPool.values(): label.Destroy() self._labelPool = newLabelPool # Draw line pieces gl.glLineWidth(1) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glVertexPointerf(linePieces.data) gl.glDrawArrays(gl.GL_LINES, 0, len(linePieces)) gl.glDisableClientState(gl.GL_VERTEX_ARRAY)