Exemple #1
0
    def OnDraw(self):
        Box.OnDraw(self)

        # Create color dict
        colors = {
            self._allLines[0]: (1, 0, 0),
            self._allLines[1]: (0, 1, 0),
            self._allLines[2]: (0, 0, 1),
            self._allLines[3]: (0, 0, 0)
        }

        # prepare scaling
        gl.glPushMatrix()
        w, h = self.position.size
        gl.glScale(w, h, 1)

        # prepare
        gl.glPointSize(7)
        gl.glLineWidth(1)
        gl.glEnable(gl.GL_POINT_SMOOTH)  # round points
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)

        # Draw lines
        for line in self._allLines:
            if len(line) and line is not self._line:
                gl.glColor(*colors[line])
                gl.glVertexPointerf(line.data)
                gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(line))

        # Draw the line under control (using a thicker line)
        gl.glColor(*colors[self._line])
        gl.glLineWidth(2)
        gl.glVertexPointerf(self._line.data)
        gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(self._line))

        # draw nodes
        gl.glColor(*colors[self._line])
        gl.glVertexPointerf(self._nodes.data)
        gl.glDrawArrays(gl.GL_POINTS, 0, len(self._nodes))

        # clean up
        gl.glPopMatrix()
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        gl.glDisable(gl.GL_POINT_SMOOTH)
Exemple #2
0
 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)