Esempio n. 1
0
    def drawGL(self,**kargs):
        self.decorations = []
        n = len(self.cl.colors)
        pf.debug("NUMBER OF COLORS: %s" % n)
        x1 = float(self.x)
        x2 = float(self.x+self.w)
        y0 = float(self.y)
        dy = float(self.h)/n
        
        # colors
        y1 = y0
        #GL.glLineWidth(1.5)
        for i,c in enumerate(self.cl.colors):
            y2 = y0 + (i+1)*dy
            GL.glColor3f(*c)
            GL.glRectf(x1,y1,x2,y2)   
            y1 = y2
            
        if self.nlabel > 0 or self.ngrid > 0:
            GL.glColor3f(*colors.black)

        # labels
        if self.nlabel > 0:
            fh = gluttext.glutFontHeight(self.font)
            pf.debug("FONT HEIGHT %s" % fh)
            # minimum label distance
            dh = fh + self.ygap
            maxlabel = float(self.h)/dh # maximum n umber of labels
            if self.nlabel <= maxlabel:
                dh = float(self.h)/self.nlabel # respect requested number
                
            if self.lefttext:
                x1 = x1 - self.xgap
                gravity = 'W'
            else:
                x1 = x2 + self.xgap
                gravity = 'E'

            # FOR 3-VALUE SCALES THIS SHOULD BE DONE IN TWO PARTS,
            # FROM THE CENTER OUTWARDS, AND THEN ADDING THE
            # MIN AND MAX VALUES
            for i,v in enumerate(self.cl.limits):
                y2 = y0 + i*dy
                if y2 >= y1 or i == 0 or i == len(self.cl.limits)-1:
                    if y2 >= self.y+self.h-dh/2 and i < len(self.cl.limits)-1:
                        continue
                    t = Text(("%%.%df" % self.dec) % (v*self.scale),x1,round(y2),font=self.font,gravity=gravity)
                    self.decorations.append(t)
                    t.drawGL(**kargs)
                    y1 = y2 + dh

        # grid: after values, to be on top
        if self.ngrid > 0:
            if self.linewidth is not None:
                GL.glLineWidth(self.linewidth)
            drawGrid(self.x,self.y,self.x+self.w,self.y+self.h,1,self.ngrid)
Esempio n. 2
0
    def drawGL(self,mode='wireframe',color=None):
        #from draw import drawText
        n = len(self.cl.colors)
        GD.debug("NUMBER OF COLORS: %s" % n)
        x1 = float(self.x)
        x2 = float(self.x+self.w)
        y0 = float(self.y)
        dy = float(self.h)/n
        # colors
        y1 = y0
        GL.glLineWidth(1.5)
        for i,c in enumerate(self.cl.colors):
            y2 = y0 + (i+1)*dy
            GL.glColor3f(*c)
            GL.glRectf(x1,y1,x2,y2)   
            y1 = y2
        # values
        if self.lefttext:
            x1 = x1 - self.xgap
            gravity = 'W'
        else:
            x1 = x2 + self.xgap
            gravity = 'E'
        fh = gluttext.glutFontHeight(self.font)
        GD.debug("FONT HEIGHT %s" % fh)
        dh = fh + self.ygap # vert. distance between successive labels
        #y0 -= 0.25*fh  # 0.5*fh seems more logic, but character pos is biased
        GL.glColor3f(*colors.black)
        self.decorations = []

        # FOR 3-VALUE SCALES THIS SHOULD BE DONE IN TWO PARTS,
        # FROM THE CENTER OUTWARDS, AND THEN ADDING THE
        # MIN AND MAX VALUES
        for i,v in enumerate(self.cl.limits):
            y2 = y0 + i*dy
            if y2 >= y1 or i == 0 or i == len(self.cl.limits)-1:
                if y2 >= self.y+self.h-dh and i < len(self.cl.limits)-1:
                    continue
                t = Text(("%%.%df" % self.dec) % (v*self.scale),x1,y2,font=self.font,gravity=gravity)
                self.decorations.append(t)
                t.drawGL(mode,color)
                y1 = y2 + dh

        # grid: after values, to be on top
        if self.linewidth is not None:
            GL.glLineWidth(self.linewidth)
        if self.grid:
            drawGrid(self.x,self.y,self.x+self.w,self.y+self.h,1,self.grid)
Esempio n. 3
0
 def drawGL(self, mode="wireframe", color=None):
     # from draw import drawText
     n = len(self.cl.colors)
     x1 = float(self.x)
     x2 = float(self.x + self.w)
     y0 = float(self.y)
     dy = float(self.h) / n
     # colors
     y1 = y0
     GD.debug("START COLORS AT %s" % y0)
     GL.glLineWidth(1.5)
     for i, c in enumerate(self.cl.colors):
         y2 = y0 + (i + 1) * dy
         GL.glColor3f(*c)
         GL.glRectf(x1, y1, x2, y2)
         y1 = y2
     # values
     if self.lefttext:
         x1 = x1 - self.xgap
         gravity = "W"
     else:
         x1 = x2 + self.xgap
         gravity = "E"
     fh = gluttext.glutFontHeight(self.font)
     GD.debug("FONT HEIGHT %s" % fh)
     dh = fh + self.ygap  # vert. distance between successive labels
     # y0 -= 0.25*fh  # 0.5*fh seems more logic, but character pos is biased
     GD.debug("FIRST TEXT AT %s" % y0)
     GL.glColor3f(*colors.black)
     self.decorations = []
     for i, v in enumerate(self.cl.limits):
         y2 = y0 + i * dy
         GD.debug("next y = %s" % y2)
         if y2 >= y1 or i == 0:
             GD.debug("drawing at %s" % y2)
             t = Text(("%%.%df" % self.dec) % (v * self.scale), x1, y2, font=self.font, gravity=gravity)
             self.decorations.append(t)
             t.drawGL(mode, color)
             y1 = y2 + dh
     # grid: after values, to be on top
     if self.linewidth is not None:
         GL.glLineWidth(self.linewidth)
     if self.grid:
         drawGrid(self.x, self.y, self.x + self.w, self.y + self.h, 1, self.grid)
Esempio n. 4
0
    def drawGL(self, **kargs):
        self.decorations = []
        n = len(self.cl.colors)
        pf.debug("NUMBER OF COLORS: %s" % n)
        x1 = float(self.x)
        x2 = float(self.x + self.w)
        y0 = float(self.y)
        dy = float(self.h) / n

        # colors
        y1 = y0
        #GL.glLineWidth(1.5)
        for i, c in enumerate(self.cl.colors):
            y2 = y0 + (i + 1) * dy
            GL.glColor3f(*c)
            GL.glRectf(x1, y1, x2, y2)
            y1 = y2

        if self.nlabel > 0 or self.ngrid > 0:
            GL.glColor3f(*colors.black)

        # labels
        if self.nlabel > 0:
            fh = gluttext.glutFontHeight(self.font)
            pf.debug("FONT HEIGHT %s" % fh)
            # minimum label distance
            dh = fh + self.ygap
            maxlabel = float(self.h) / dh  # maximum n umber of labels
            if self.nlabel <= maxlabel:
                dh = float(self.h) / self.nlabel  # respect requested number

            if self.lefttext:
                x1 = x1 - self.xgap
                gravity = 'W'
            else:
                x1 = x2 + self.xgap
                gravity = 'E'

            # FOR 3-VALUE SCALES THIS SHOULD BE DONE IN TWO PARTS,
            # FROM THE CENTER OUTWARDS, AND THEN ADDING THE
            # MIN AND MAX VALUES
            for i, v in enumerate(self.cl.limits):
                y2 = y0 + i * dy
                if y2 >= y1 or i == 0 or i == len(self.cl.limits) - 1:
                    if y2 >= self.y + self.h - dh / 2 and i < len(
                            self.cl.limits) - 1:
                        continue
                    t = Text(("%%.%df" % self.dec) % (v * self.scale),
                             x1,
                             round(y2),
                             font=self.font,
                             gravity=gravity)
                    self.decorations.append(t)
                    t.drawGL(**kargs)
                    y1 = y2 + dh

        # grid: after values, to be on top
        if self.ngrid > 0:
            if self.linewidth is not None:
                GL.glLineWidth(self.linewidth)
            drawGrid(self.x, self.y, self.x + self.w, self.y + self.h, 1,
                     self.ngrid)