Exemplo n.º 1
0
 def paint_block(R=M, G=M, B=M):
     y = 1.0-float(self.index)/(blocks/2.0)
     bw = 2.0/w
     bh = 2.0/blocks
     self.index += 1
     for i in range(w):
         v = float(i)/float(w)
         r = normv(R*v)
         g = normv(G*v)
         b = normv(B*v)
         glColor3f(r, g, b)
         x = -1+float(i)/(w//2)
         glRectf(x, y, x+bw, y+bh)
Exemplo n.º 2
0
    def draw_tool_chain(self):
        font_scale = 0.00015
        glMatrixMode(GL_MODELVIEW)

        glColor(0, 0, 0)
        glLineWidth(5)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        glColor(1, 1, 1)
        glLineWidth(1)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        if len(self.model_objects) == 4 and \
           self.model_objects[0] == self.model_objects[3]:
            num = 3
        else:
            num = 4

        glColor(0, 0, 0)
        glLineWidth(9)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glRectf(-10, -20, 114, 130)
            glPopMatrix()

        glColor(1, 1, 1)
        glLineWidth(1)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(str(index + 1)))
            glPopMatrix()
Exemplo n.º 3
0
    def draw_tool_chain(self):
        font_scale = 0.00015
        glMatrixMode(GL_MODELVIEW)

        glColor(0, 0, 0)
        glLineWidth(5)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        glColor(1, 1, 1)
        glLineWidth(1)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        if len(self.model_objects) == 4 and \
           self.model_objects[0] == self.model_objects[3]:
            num = 3
        else:
            num = 4

        glColor(0, 0, 0)
        glLineWidth(9)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glRectf(-10, -20, 114, 130)
            glPopMatrix()

        glColor(1, 1, 1)
        glLineWidth(1)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(str(index+1)))
            glPopMatrix()
Exemplo n.º 4
0
 def _drawframe(self):
     """Draw a frame around the GuiObject"""
     framedata = self._getFrameData()
     color, plastic, x, y = framedata["color"], framedata["plastic"], \
         framedata["x"], framedata["y"]
     glColor3f(*(c - plastic for c in color))
     glRectf(0.0, 1.0, 1.0, 1.0 - x)
     # top
     glRectf(0.0, 0.0, y, 1.0)
     # left
     glColor3f(*(c + plastic for c in color))
     glRectf(0.0, 0.0, 1.0, x)
     # bottom
     glRectf(1.0, 0.0, 1.0 - y, 1.0)
Exemplo n.º 5
0
 def _drawframe(self):
     """Draw a frame around the GuiObject"""
     framedata = self._getFrameData()
     color, plastic, x, y = framedata["color"], framedata["plastic"], \
         framedata["x"], framedata["y"]
     glColor3f(*(c - plastic for c in color))
     glRectf(0.0, 1.0, 1.0, 1.0 - x)
     # top
     glRectf(0.0, 0.0, y, 1.0)
     # left
     glColor3f(*(c + plastic for c in color))
     glRectf(0.0, 0.0, 1.0, x)
     # bottom
     glRectf(1.0, 0.0, 1.0 - y, 1.0)
Exemplo n.º 6
0
    def draw(self):
        """
        Draws the rulers.
        """

        width = self.glpane.width
        height = self.glpane.height

        # These 3 attrs (scale, aspect, and ruler_position) are checked to
        # determine if they've changed. If any of them have,
        # getRulerDrawingParameters() must be called to get new drawing parms.
        if (
            (self.scale != self.glpane.scale)
            or (self.zoomFactor != self.glpane.zoomFactor)
            or (self.aspect != self.glpane.aspect)
            or (self.ruler_position != env.prefs[rulerPosition_prefs_key])
        ):

            self.scale = self.glpane.scale
            self.zoomFactor = self.glpane.zoomFactor
            self.aspect = self.glpane.aspect
            self.ruler_position = env.prefs[rulerPosition_prefs_key]

            self.ruler_drawing_params = getRulerDrawingParameters(
                width, height, self.aspect, self.scale, self.zoomFactor, self.ruler_position
            )

        (
            draw_ticks_and_text,
            units_text,
            units_format,
            units_scale,
            unit_label_inc,
            long_tickmark_inc,
            medium_tickmark_inc,
            num_vert_ticks,
            num_horz_ticks,
            tickmark_spacing_multiplier,
            ruler_origin,
            ruler_start_pt,
            units_text_origin,
            origin_square_pt1,
            origin_square_pt2,
            vr_thickness,
            vr_tickmark_spacing,
            vr_long_tick_len,
            vr_medium_tick_len,
            vr_short_tick_len,
            vr_rect_pt1,
            vr_rect_pt2,
            vr_line_pt1,
            vr_line_pt2,
            vr_units_x_offset,
            vr_units_y_offset,
            hr_thickness,
            hr_tickmark_spacing,
            hr_long_tick_len,
            hr_medium_tick_len,
            hr_short_tick_len,
            hr_rect_pt1,
            hr_rect_pt2,
            hr_line_pt1,
            hr_line_pt2,
            hr_units_x_offset,
            hr_units_y_offset,
        ) = self.ruler_drawing_params

        ruler_color = env.prefs[rulerColor_prefs_key]
        ruler_opacity = env.prefs[rulerOpacity_prefs_key]

        # These may become user preferences in the future.
        tickmark_color = darkgray
        text_color = black

        # Set up 2D (window) coordinate system.
        # Bruce - please review this section.
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()  # needed!
        gluOrtho2D(0.0, float(width), 0.0, float(height))
        glMatrixMode(GL_MODELVIEW)
        # About this glMatrixMode(GL_MODELVIEW) call, Bruce wrote in a review:
        # The only reason this is desirable (it's not really needed) is if,
        # when someone is editing the large body of drawing code after this,
        # they inadvertently do something which is only correct if the matrix
        # mode is GL_MODELVIEW (e.g. if they use glTranslate to shift a ruler
        # or tickmark position). Most of our drawing code assumes it can do
        # this, so a typical NE1 OpenGL programmer may naturally assume this,
        # which is why it's good to leave the matrix mode as GL_MODELVIEW when
        # entering into a large hunk of ordinary drawing code (especially if
        # it might call other drawing functions, now or in the future).
        # Mark 2008-03-03

        glDisable(GL_LIGHTING)
        glDisable(GL_DEPTH_TEST)
        # Note: disabling GL_DEPTH_TEST is not honored by the 3d version of
        # glpane.renderText -- ruler text can still be obscured by
        # previously drawn less-deep model objects.
        # But the 2d call of renderText in part.py does honor this.
        # The Qt doc says why, if I guess how to interpret it:
        #   http://doc.trolltech.com/4.3/qglwidget.html#renderText
        # says, for the 3d version of renderText only (passing three model
        # coords as opposed to two window coords):
        #   Note that this function only works properly if GL_DEPTH_TEST
        #   is enabled, and you have a properly initialized depth buffer.
        # Possible fixes:
        # - revise ruler_origin to be very close to the screen,
        #   and hope that this disable is merely ignored, not a messup;
        # - or, use the 2d version of the function.
        # I did the latter fix (2d renderText, below) and it seems to work.
        # [bruce 081204 comment]

        # Suppress writing into the depth buffer so anything behind the ruler
        # can still be highlighted/selected.
        glDepthMask(GL_FALSE)

        # == Draw v/h ruler rectangles in the user defined color and opacity.

        glColor4fv(list(ruler_color) + [ruler_opacity])
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glRectf(origin_square_pt1[0], origin_square_pt1[1], origin_square_pt2[0], origin_square_pt2[1])  # Origin square
        if env.prefs[displayVertRuler_prefs_key]:
            glRectf(vr_rect_pt1[0], vr_rect_pt1[1], vr_rect_pt2[0], vr_rect_pt2[1])  # Vertical ruler
        if env.prefs[displayHorzRuler_prefs_key]:
            glRectf(hr_rect_pt1[0], hr_rect_pt1[1], hr_rect_pt2[0], hr_rect_pt2[1])  # Horizontal ruler

        glDisable(GL_BLEND)

        # Set color of ruler lines, tick marks and text.
        glColor3fv(tickmark_color)
        self.glpane.qglColor(RGBf_to_QColor(text_color))

        # Draw unit of measurement in corner (A or nm).
        # piotr 080326: replaced drawText with drawCenteredText
        self.drawCenteredText(units_text, units_text_origin)

        # Kludge alert. Finish drawing ruler edge(s) if we will not be
        # drawing the ruler tick marks and text (only happens when the user
        # is zoomed out to an "absurd scale factor").
        if not draw_ticks_and_text:
            if env.prefs[displayVertRuler_prefs_key]:
                self.drawLine(vr_line_pt1, vr_line_pt2)
            if env.prefs[displayHorzRuler_prefs_key]:
                self.drawLine(hr_line_pt1, hr_line_pt2)

        # == Draw vertical ruler line(s) and tick marks

        if env.prefs[displayVertRuler_prefs_key] and draw_ticks_and_text:

            # Draw vertical line along right/left edge of ruler.
            self.drawLine(vr_line_pt1, vr_line_pt2)

            # Initialize pt1 and pt2, the tick mark endpoints. The first tick
            # mark will span the entire width of the ruler,  which serves as a
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(-vr_thickness, 0.0, 0.0)

            # Draw vertical ruler tickmarks, including numeric unit labels
            for tick_num in range(num_horz_ticks + 1):

                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)

                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 + V(vr_units_x_offset, vr_units_y_offset, 0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)

                # Update tickmark endpoints for next tickmark.
                pt1 = ruler_start_pt + V(0.0, vr_tickmark_spacing * tickmark_spacing_multiplier * (tick_num + 1), 0.0)

                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(vr_long_tick_len, 0.0, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(vr_medium_tick_len, 0.0, 0.0)
                else:
                    pt2 = pt1 + V(vr_short_tick_len, 0.0, 0.0)

            # End vertical ruler

        # == Draw horizontal ruler line(s) and tick marks

        if env.prefs[displayHorzRuler_prefs_key] and draw_ticks_and_text:
            # Draw horizontal line along top/bottom edge of ruler.
            self.drawLine(hr_line_pt1, hr_line_pt2)

            # Initialize pt1 and pt2, the tick mark endpoints. The first tick
            # mark will span the entire width of the ruler,  which serves as a
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(0.0, -hr_thickness, 0.0)

            # Draw horizontal ruler (with vertical) tickmarks, including its
            # numeric unit labels
            for tick_num in range(num_vert_ticks + 1):

                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)

                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 + V(hr_units_x_offset, hr_units_y_offset, 0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)

                # Update tickmark endpoints for next tickmark.
                pt1 = ruler_start_pt + V(hr_tickmark_spacing * tickmark_spacing_multiplier * (tick_num + 1), 0.0, 0.0)

                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_long_tick_len, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_medium_tick_len, 0.0)
                else:
                    pt2 = pt1 + V(0.0, hr_short_tick_len, 0.0)

            # End horizontal ruler

        # Restore OpenGL state.
        glDepthMask(GL_TRUE)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)
        glDepthMask(GL_TRUE)
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        return  # from drawRulers
Exemplo n.º 7
0
    def draw(self):
        """
        Draws the rulers.
        """
        
        width = self.glpane.width
        height = self.glpane.height
        
        # These 3 attrs (scale, aspect, and ruler_position) are checked to 
        # determine if they've changed. If any of them have, 
        # getRulerDrawingParameters() must be called to get new drawing parms.
        if (self.scale  != self.glpane.scale) or \
           (self.zoomFactor  != self.glpane.zoomFactor) or \
           (self.aspect != self.glpane.aspect) or \
           (self.ruler_position != env.prefs[rulerPosition_prefs_key]):
            
            self.scale = self.glpane.scale
            self.zoomFactor = self.glpane.zoomFactor
            self.aspect = self.glpane.aspect
            self.ruler_position = env.prefs[rulerPosition_prefs_key]
    
            self.ruler_drawing_params = \
                getRulerDrawingParameters(width, height, self.aspect,
                                          self.scale, self.zoomFactor, 
                                          self.ruler_position)
            
        (draw_ticks_and_text,
         units_text, 
         units_format,
         units_scale,
         unit_label_inc,
         long_tickmark_inc,
         medium_tickmark_inc,
         num_vert_ticks,
         num_horz_ticks,
         tickmark_spacing_multiplier,
         ruler_origin, ruler_start_pt, 
         units_text_origin, origin_square_pt1, origin_square_pt2, 
         vr_thickness, vr_tickmark_spacing,
         vr_long_tick_len, vr_medium_tick_len, vr_short_tick_len,
         vr_rect_pt1, vr_rect_pt2,
         vr_line_pt1, vr_line_pt2,
         vr_units_x_offset, vr_units_y_offset,
         hr_thickness, hr_tickmark_spacing,
         hr_long_tick_len, hr_medium_tick_len, hr_short_tick_len,
         hr_rect_pt1, hr_rect_pt2,
         hr_line_pt1, hr_line_pt2,
         hr_units_x_offset, hr_units_y_offset) = self.ruler_drawing_params
            
        ruler_color = env.prefs[rulerColor_prefs_key]
        ruler_opacity = env.prefs[rulerOpacity_prefs_key]
        
        # These may become user preferences in the future.
        tickmark_color = darkgray
        text_color = black
        
        # Set up 2D (window) coordinate system.
        # Bruce - please review this section.
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity() # needed!
        gluOrtho2D(0.0, float(width), 0.0, float(height))
        glMatrixMode(GL_MODELVIEW)
        # About this glMatrixMode(GL_MODELVIEW) call, Bruce wrote in a review:
        # The only reason this is desirable (it's not really needed) is if, 
        # when someone is editing the large body of drawing code after this, 
        # they inadvertently do something which is only correct if the matrix 
        # mode is GL_MODELVIEW (e.g. if they use glTranslate to shift a ruler
        # or tickmark position). Most of our drawing code assumes it can do 
        # this, so a typical NE1 OpenGL programmer may naturally assume this,
        # which is why it's good to leave the matrix mode as GL_MODELVIEW when
        # entering into a large hunk of ordinary drawing code (especially if
        # it might call other drawing functions, now or in the future).
        # Mark 2008-03-03
        
        glDisable(GL_LIGHTING)
        glDisable(GL_DEPTH_TEST)
        
        # Suppress writing into the depth buffer so anything behind the ruler
        # can still be highlighted/selected.
        glDepthMask(GL_FALSE) 
        
        # Draw v/h ruler rectangles in the user defined color and opacity. #####
    
        glColor4fv(list(ruler_color) + [ruler_opacity])
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glRectf(origin_square_pt1[0], origin_square_pt1[1], 
                origin_square_pt2[0], origin_square_pt2[1]) # Origin square
        if env.prefs[displayVertRuler_prefs_key]:
            glRectf(vr_rect_pt1[0], vr_rect_pt1[1], 
                    vr_rect_pt2[0], vr_rect_pt2[1]) # Vertical ruler
        if env.prefs[displayHorzRuler_prefs_key]:
            glRectf(hr_rect_pt1[0], hr_rect_pt1[1], 
                    hr_rect_pt2[0], hr_rect_pt2[1]) # Horizontal ruler

        glDisable(GL_BLEND)
        
        # Set color of ruler lines, tick marks and text.
        glColor3fv(tickmark_color)
        self.glpane.qglColor(RGBf_to_QColor(text_color))
        
        # Draw unit of measurement in corner (A or nm).
        # piotr 080326: replaced drawText with drawCenteredText
        self.drawCenteredText(units_text, units_text_origin)
        
        # Kludge alert. Finish drawing ruler edge(s) if we will not be
        # drawing the ruler tick marks and text (only happens when the user
        # is zoomed out to an "absured scale factor".
        if not draw_ticks_and_text:
            if env.prefs[displayVertRuler_prefs_key]:
                self.drawLine(vr_line_pt1, vr_line_pt2)
            if env.prefs[displayHorzRuler_prefs_key]:
                self.drawLine(hr_line_pt1, hr_line_pt2)
            
        # Draw vertical ruler line(s) and tick marks ##########################
        
        if env.prefs[displayVertRuler_prefs_key] and draw_ticks_and_text:
        
            # Draw vertical line along right/left edge of ruler.
            self.drawLine(vr_line_pt1, vr_line_pt2)
            
            # Initialize pt1 and pt2, the tick mark endpoints. The first tick 
            # mark will span the entire width of the ruler,  which serves as a 
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(-vr_thickness, 0.0, 0.0)
            
            # Draw vertical ruler tickmarks, including numeric unit labels
            for tick_num in range(num_horz_ticks + 1):
                
                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)
                
                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 \
                                     + V(vr_units_x_offset, 
                                         vr_units_y_offset, 
                                         0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)
                    
                # Update tickmark endpoints for next tickmark.
                pt1 = ruler_start_pt + \
                    V(0.0, 
                      vr_tickmark_spacing * tickmark_spacing_multiplier
                      * (tick_num + 1),
                      0.0)
                
                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(vr_long_tick_len, 0.0, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(vr_medium_tick_len, 0.0, 0.0)
                else:
                    pt2 = pt1 + V(vr_short_tick_len, 0.0, 0.0)
        
            # End vertical ruler
        
        # Draw horizontal ruler line(s) and tick marks #########################
        
        if env.prefs[displayHorzRuler_prefs_key] and draw_ticks_and_text:
            # Draw horizontal line along top/bottom edge of ruler.
            self.drawLine(hr_line_pt1, hr_line_pt2)
            
            # Initialize pt1 and pt2, the tick mark endpoints. The first tick
            # mark will span the entire width of the ruler,  which serves as a 
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(0.0, -hr_thickness, 0.0) 
        
            # Draw horizontal ruler (with vertical) tickmarks, including its
            # numeric unit labels
            for tick_num in range(num_vert_ticks + 1):
                
                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)
                
                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 \
                                     + V(hr_units_x_offset, 
                                         hr_units_y_offset, 
                                         0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)
                    
                # Update tickmark endpoints for next tickmark.
                pt1 = \
                    ruler_start_pt + \
                    V(hr_tickmark_spacing * tickmark_spacing_multiplier
                      * (tick_num + 1),
                      0.0,
                      0.0)
                
                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_long_tick_len, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_medium_tick_len, 0.0)
                else:
                    pt2 = pt1 + V(0.0, hr_short_tick_len, 0.0)
            
            # End horizontal ruler
        
        # Restore OpenGL state.
        glDepthMask(GL_TRUE) 
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)
        glDepthMask(GL_TRUE)
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        return # from drawRulers
Exemplo n.º 8
0
Arquivo: draw.py Projeto: Zildj1an/bui
def draw_rectangle(color, x1, y1, x2=None, y2=None, width=None, height=None):
    x2, y2 = check_input(x1, y1, x2, y2, width, height)
    
    set_color(color)
    glRectf(x1, y1, x2, y2)