Esempio n. 1
0
def draw_circle_select(m_coords, radius = 16, p_col = (0.7,0.8,1.0,0.6), enabled = False, sub = False):
    if(enabled):
        f_col = p_col
        if sub:
            f_col = (1.0, 0.5, 0.4, 0.6)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_POLYGON)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]/3)

        point_x = m_coords[0]
        point_y = m_coords[1]

        radius = int(radius)

        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360/(radius*2)) / 180 * 3.14159), point_y + radius * math.sin(x * (360/(radius*2)) / 180 * 3.14159))
        bgl.glEnd()

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3])
        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360 / (radius * 2)) / 180 * 3.14159),
                           point_y + radius * math.sin(x * (360 / (radius * 2)) / 180 * 3.14159))

        bgl.glEnd()
        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context):
    
    font_id = 0  # XXX, need to find out how best to get this.
 
    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))
 
    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)
 
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)
 
    bgl.glEnd()
    
    # 50% alpha, 2 pixel width line
    
    bgl.glColor4f(0.0, 1, 0.0, 1)
    bgl.glPointSize(5)
    bgl.glBegin(bgl.GL_POINTS)
    for v in self.spline_end_dict:
        bgl.glVertex2f(v[0], v[1])
        
    bgl.glEnd()
 
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Esempio n. 3
0
    def draw(self, context, render=False):
        """
            render flag when rendering
        """

        # print("draw_line %s" % (type(self).__name__))
        bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
        if self.style == bgl.GL_LINE_STIPPLE:
            bgl.glLineStipple(1, 0x9999)
        bgl.glEnable(self.style)
        bgl.glEnable(bgl.GL_BLEND)
        if render:
            # enable anti-alias on lines
            bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glColor4f(*self.colour)
        bgl.glLineWidth(self.width)
        if self.closed:
            bgl.glBegin(bgl.GL_LINE_LOOP)
        else:
            bgl.glBegin(bgl.GL_LINE_STRIP)

        for pt in self.pts:
            x, y = self.position_2d_from_coord(context, pt, render)
            bgl.glVertex2f(x, y)
        self._end()
Esempio n. 4
0
def cursor_history_draw(cls,context):
    cc = context.scene.cursor_history

    draw = 0
    if hasattr(cc, "historyDraw"):
        draw = cc.historyDraw

    if(draw):
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glShadeModel(bgl.GL_FLAT)
        alpha = 1-PHI_INV
        # History Trace
        if cc.historyPosition[0]<0:
            return
        bgl.glBegin(bgl.GL_LINE_STRIP)
        ccc = 0
        for iii in range(cc.historyWindow+1):
            ix_rel = iii - int(cc.historyWindow / 2)
            ix = cc.historyPosition[0] + ix_rel
            if(ix<0 or ix>=len(cc.historyLocation)):
                continue
            ppp = region3d_get_2d_coordinates(context, cc.historyLocation[ix])
            if(ix_rel<=0):
                bgl.glColor4f(0, 0, 0, alpha)
            else:
                bgl.glColor4f(1, 0, 0, alpha)
            bgl.glVertex2f(ppp[0], ppp[1])
            ccc = ccc + 1
        bgl.glEnd()
Esempio n. 5
0
def draw_polyline(points, width=2, color=(1.0, 1.0, 1.0, 1.0)):
    """Draw polyline, points = [(x1, y1, z1), (x2, y2, z2),...]"""

    # [PART V]
    # BRIDGEKEEPER: Stop! What... is your name?
    # GALAHAD: 'Sir Galahad of Camelot'.
    # BRIDGEKEEPER: What... is your line width?
    # GALAHAD: width.
    bgl.glLineWidth(width)

    # BRIDGEKEEPER: What... is your favorite color?
    # GALAHAD: color. No, *colo-- auuuuuuuugh!
    # color is a 4-tuple of floats, don't forget unpacking with *!
    bgl.glColor4f(*color)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points:
        vector2d = to_screen_coord(coord)
        if vector2d:
            # if coord is not in the visible area (e.g. behind the camera)
            # to_screen_coord returns None => don't draw this Vertex
            bgl.glVertex2f(*vector2d)
        else:
            # stop drawing this line if vertex is invalid
            bgl.glEnd()
            # then start a new line
            bgl.glBegin(bgl.GL_LINE_STRIP)
            # note that the next vertex might be invalid too,
            # so no new line is drawn
    bgl.glEnd()
Esempio n. 6
0
def draw_dot(position, size, color):
    glColor4f(*color)
    glEnable(GL_BLEND)
    glPointSize(size)
    glBegin(GL_POINTS)
    glVertex2f(*position)
    glEnd()
Esempio n. 7
0
 def draw_line(v1, v2):
     if len(v1) == 3:
         bgl.glVertex3f(*v1)
         bgl.glVertex3f(*v2)
     else:
         bgl.glVertex2f(*v1)
         bgl.glVertex2f(*v2)
Esempio n. 8
0
def draw_polyline_from_points(context, points, color, thickness, LINE_TYPE):
    '''
    a simple way to draw a line
    args:
        points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        thickness: integer? maybe a float
        LINE_TYPE:  eg...bgl.GL_LINE_STIPPLE or 
    '''
    
    if LINE_TYPE == "GL_LINE_STIPPLE":  
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)  
    bgl.glEnable(bgl.GL_BLEND)
    
    current_width = bgl.GL_LINE_WIDTH
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    
    for coord in points:  
        bgl.glVertex2f(*coord)  
    
    bgl.glEnd()  
    bgl.glLineWidth(1)  
    if LINE_TYPE == "GL_LINE_STIPPLE":  
        bgl.glDisable(bgl.GL_LINE_STIPPLE)  
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines  
      
    return
Esempio n. 9
0
def draw_arc(x, y, radius, start_angle, end_angle, edgenum=16):
    # 三時から反時計回りに描画 angle:radians
    l = draw_arc_get_vectors(x, y, radius, start_angle, end_angle, edgenum)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for v in l:
        bgl.glVertex2f(*v)
    bgl.glEnd()
Esempio n. 10
0
 def draw_borders(x=0, y=0, w=30, h=10, color=(0.0, 0.0, 0.0, 1.0)):
     # function to draw a border color around the texture
     bgl.glColor4f(*color)
     bgl.glBegin(bgl.GL_LINE_LOOP)
     for coord in [(x, y), (x + w, y), (w + x, y - h), (x, y - h)]:
         bgl.glVertex2f(*coord)
     bgl.glEnd()
Esempio n. 11
0
def draw_button(mx, my, x0, y0, width, height):
    color_r = 0.0
    color_g = 0.0
    color_b = 0.0
    color_a = 0.5
    x1 = x0 + width
    y1 = y0 - height/2
    y0 += height/2
    
    hover = False
    if x0 <= mx <= x1 and y1 <= my <= y0:
        color_r = 0.0
        color_g = 0.5
        color_b = 1.0
        color_a = 0.8
        hover = True
    
    positions = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]]
    settings = [[bgl.GL_QUADS, min(0.0, color_a)], [bgl.GL_LINE_LOOP, min(0.0, color_a)]]
    for mode, box_alpha in settings:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(mode)
        bgl.glColor4f(color_r, color_g, color_b, color_a)
        for v1, v2 in positions:
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()
        
    return hover
Esempio n. 12
0
def draw_callback_px(self, context):
    if(self.ShowCursor):
        region = bpy.context.region
        rv3d = bpy.context.space_data.region_3d
        view_width = context.region.width
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glLineWidth(2)
        bgl.glColor4f(1.0, 0.8, 0.0, 1.0)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        idx = 0
        for i in range(int(len(self.CLR_C)/3)):
            vector3d = (self.CLR_C[idx * 3] * self.CRadius + self.CurLoc.x,self.CLR_C[idx * 3  + 1] * self.CRadius + self.CurLoc.y,self.CLR_C[idx * 3 + 2] * self.CRadius + self.CurLoc.z)
            vector2d = bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, vector3d)
            bgl.glVertex2f(*vector2d)
            idx += 1
        bgl.glEnd()
        bgl.glBegin(bgl.GL_LINE_STRIP)
        idx = 0
        for i in range(int(len(self.CLR_C)/3)):
            vector3d = (self.CLR_C[idx * 3] * self.CRadius/3.0 + self.CurLoc.x,self.CLR_C[idx * 3  + 1] * self.CRadius/3.0 + self.CurLoc.y,self.CLR_C[idx * 3 + 2] * self.CRadius/3.0 + self.CurLoc.z)
            vector2d = bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, vector3d)
            bgl.glVertex2f(*vector2d)
            idx += 1
        bgl.glEnd()
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Esempio n. 13
0
def screen_v3dBGL_overlay(context, args):

    if not args[2]:
        return

    alpha = args[3]
    

    region = context.region
    region3d = context.space_data.region_3d

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

    for matrix, color in args[0]:
        r, g, b = color
        bgl.glColor4f(r, g, b, alpha)
        bgl.glBegin(bgl.GL_QUADS)
        M = Matrix(matrix)
        for x, y in [(-.5, .5), (.5 ,.5), (.5 ,-.5), (-.5 ,-.5)]:
            vector3d = M * Vector((x, y, 0))
            vector2d = loc3d2d(region, region3d, vector3d)
            bgl.glVertex2f(*vector2d)

        bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Esempio n. 14
0
def draw_3d_points_and_index(context, points, color, size):
    '''
    draw a bunch of dots
    args:
        points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        size: integer? maybe a float
    '''
    points_2d = [location_3d_to_region_2d(context.region, context.space_data.region_3d, loc) for loc in points]
   
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points_2d:
        #TODO:  Debug this problem....perhaps loc_3d is returning points off of the screen.
        if coord:
            bgl.glVertex2f(*coord) 
        else:
            continue
    
    bgl.glEnd()
    blf.size(0, 14, 72)
    for i, coord in enumerate(points_2d):
        blf.position(0,coord[0]+3, coord[1]+3, 0)
        blf.draw(0,str(i))
        
    return
Esempio n. 15
0
    def draw_texture(x=0, y=0, w=30, h=10, texname=texname):
        # function to draw a texture
        bgl.glDisable(bgl.GL_DEPTH_TEST)

        act_tex = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGetIntegerv(bgl.GL_TEXTURE_2D, act_tex)

        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glActiveTexture(bgl.GL_TEXTURE0)
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, texname)

        texco = [(0, 1), (1, 1), (1, 0), (0, 0)]
        verco = [(x, y), (x + w, y), (x + w, y - h), (x, y - h)]

        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
        bgl.glBegin(bgl.GL_QUADS)
        for i in range(4):
            bgl.glTexCoord3f(texco[i][0], texco[i][1], 0.0)
            bgl.glVertex2f(verco[i][0], verco[i][1])
        bgl.glEnd()

        # restoring settings
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, act_tex[0])
        bgl.glDisable(bgl.GL_TEXTURE_2D)
Esempio n. 16
0
def draw_callback(self, context):
    mid = int(360 * self.recv / self.fsize)
    cx = 200
    cy = 30
    blf.position(0, 230, 23, 0)
    blf.size(0, 20, 72)
    blf.draw(0, "{0:2d}% of {1}".format(100 * self.recv // self.fsize, self.hfsize))

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.7, 0.7, 0.7, 0.8)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glVertex2i(cx, cy)
    for i in range(mid):
        x = cx + 20 * math.sin(math.radians(float(i)))
        y = cy + 20 * math.cos(math.radians(float(i)))
        bgl.glVertex2f(x, y)
    bgl.glEnd()

    bgl.glColor4f(0.0, 0.0, 0.0, 0.6)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glVertex2i(cx, cy)
    for i in range(mid, 360):
        x = cx + 20 * math.sin(math.radians(float(i)))
        y = cy + 20 * math.cos(math.radians(float(i)))
        bgl.glVertex2f(x, y)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Esempio n. 17
0
def draw_polyline_from_3dpoints(context, points_3d, color, thickness, LINE_TYPE):
    '''
    a simple way to draw a line
    slow...becuase it must convert to screen every time
    but allows you to pan and zoom around
    
    args:
        points_3d: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        thickness: integer? maybe a float
        LINE_TYPE:  eg...bgl.GL_LINE_STIPPLE or 
    '''
    points = [location_3d_to_region_2d(context.region, context.space_data.region_3d, loc) for loc in points_3d]
    if LINE_TYPE == "GL_LINE_STIPPLE":  
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)  
    bgl.glEnable(bgl.GL_BLEND)
    
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points:  
        bgl.glVertex2f(*coord)  
    
    bgl.glEnd()  
      
    if LINE_TYPE == "GL_LINE_STIPPLE":  
        bgl.glDisable(bgl.GL_LINE_STIPPLE)  
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines  
        bgl.glLineWidth(1)
    return
Esempio n. 18
0
def h_draw_arc(cx, cy, r, start_angle, arc_angle, color=(1,1,1,1), segs=12):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    start_angle = math.radians(start_angle)
    arc_angle = math.radians(arc_angle)
    
    theta = arc_angle / (segs-1)
    
    tangencial_factor = math.tan(theta)
    radial_factor = math.cos(theta)
    
    x = r * math.cos(start_angle)
    y = r * math.sin(start_angle)
    
    bgl.glColor4f(*color)
    bgl.glBegin(bgl.GL_POLYGON)
    
    bgl.glVertex2f(cx, cy)
    for i in range(segs):
        bgl.glVertex2f(x + cx, y + cy)
        
        tx = -y
        ty = x
        
        x += tx * tangencial_factor
        y += ty * tangencial_factor
        x *= radial_factor
        y *= radial_factor

    bgl.glEnd()
    
    bgl.glDisable(bgl.GL_BLEND)
Esempio n. 19
0
    def draw_index(rgb, rgb2, index, vec, text=''):

        vec_4d = perspective_matrix * vec.to_4d()
        if vec_4d.w <= 0.0:
            return

        x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w)
        y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w)
        if text:
            index = str(text[0])
        else:
            index = str(index)

        if draw_bg:
            polyline = get_points(index)

            ''' draw polygon '''
            bgl.glColor4f(*rgb2)
            bgl.glBegin(bgl.GL_POLYGON)
            for pointx, pointy in polyline:
                bgl.glVertex2f(pointx+x, pointy+y)
            bgl.glEnd()

        ''' draw text '''
        txt_width, txt_height = blf.dimensions(0, index)
        bgl.glColor4f(*rgb)
        blf.position(0, x - (txt_width / 2), y - (txt_height / 2), 0)
        blf.draw(0, index)
Esempio n. 20
0
 def draw_postpixel(self):
     Point_to_Point2D = self.rfcontext.Point_to_Point2D
     self.drawing.point_size(10)
     bgl.glBegin(bgl.GL_POINTS)
     for (mv, e) in self.moves3D:
         bgl.glColor4f(e, 0.1, 0.1, 1.0)
         bgl.glVertex2f(*Point_to_Point2D(mv.co))
     bgl.glEnd()
def draw_triangle(x=0, y=0, w=30, h=10, color=(1.0, 0.3, 0.3, 1.0)):

    bgl.glColor4f(*color)       
    bgl.glBegin(bgl.GL_TRIANGLES)

    for coord in [(x, y), (x+w, y), (x + (w/2), y-h)]:
        bgl.glVertex2f(*coord)
    bgl.glEnd()
Esempio n. 22
0
    def draw_rect(x=0, y=0, w=30, h=10, color=(0.0, 0.0, 0.0, 1.0)):

        bgl.glColor4f(*color)
        bgl.glBegin(bgl.GL_POLYGON)

        for coord in [(x, y), (x + w, y), (w + x, y - h), (x, y - h)]:
            bgl.glVertex2f(*coord)
        bgl.glEnd()
Esempio n. 23
0
 def draw_angled_line(color, angle, bx, by):
     x = math.cos(angle) * radius
     y = math.sin(angle) * radius
     bgl.glColor4f(color[0], color[1], color[2], color[3])
     bgl.glBegin(bgl.GL_LINES)
     bgl.glVertex2f(bx, by)
     bgl.glVertex2f(bx + x, by + y)
     bgl.glEnd()
Esempio n. 24
0
 def draw_gl_strip(coords, line_thickness):
     bgl.glLineWidth(line_thickness)
     bgl.glBegin(bgl.GL_LINES)
     for coord in coords:
         vector3d = matrix_world * coord
         vector2d = loc3d2d(region, rv3d, vector3d)
         bgl.glVertex2f(*vector2d)
     bgl.glEnd()
Esempio n. 25
0
 def draw(self, thickness=2, color=(0.2, 0.2, 0.2, 1.0)):
     glLineWidth(thickness)
     glColor4f(*color)
     glBegin(GL_LINES)
     glVertex2f(*self.start)
     glVertex2f(*self.end)
     glEnd()
     glLineWidth(1)
Esempio n. 26
0
def draw_line(start, end, thickness, color):
    glLineWidth(thickness)
    glColor4f(*color)
    glBegin(GL_LINES)
    glVertex2f(*start)
    glVertex2f(*end)
    glEnd()
    glLineWidth(1)
Esempio n. 27
0
def crosshairs():
    """
    Show crosshais in Manipulation Mode
    Use the OpenGL-Wrapper to draw the image
    """
    
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth/2
    y = windowHeight * 0.5 - imageHeight/2
    
    gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]]
    
    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)      
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)   
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)   
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)      
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, crosshairs_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
       bgl.glTexCoord2f(texco[i][0], texco[i][1])
       bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
    def draw_texture(cls, _, context):
        sc = context.scene

        if not cls.is_running(context):
            return

        # no textures are selected
        if sc.muv_texture_projection_tex_image == "None":
            return

        # get texture to be renderred
        img = bpy.data.images[sc.muv_texture_projection_tex_image]

        # setup rendering region
        rect = _get_canvas(context, sc.muv_texture_projection_tex_magnitude)
        positions = [
            [rect.x0, rect.y0],
            [rect.x0, rect.y1],
            [rect.x1, rect.y1],
            [rect.x1, rect.y0]
        ]
        tex_coords = [
            [0.0, 0.0],
            [0.0, 1.0],
            [1.0, 1.0],
            [1.0, 0.0]
        ]

        # OpenGL configuration
        if compat.check_version(2, 80, 0) >= 0:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            bgl.glActiveTexture(bgl.GL_TEXTURE0)
            if img.bindcode:
                bind = img.bindcode
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
        else:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            if img.bindcode:
                bind = img.bindcode[0]
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
                bgl.glTexEnvi(
                    bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                    bgl.GL_MODULATE)

        # render texture
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor4f(1.0, 1.0, 1.0,
                      sc.muv_texture_projection_tex_transparency)
        for (v1, v2), (u, v) in zip(positions, tex_coords):
            bgl.glTexCoord2f(u, v)
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()
def cursor_history_draw(cls,context):
    cc = context.scene.cursor_history

    draw = 0
    if hasattr(cc, "historyDraw"):
        draw = cc.historyDraw
    if hasattr(cc, "historyEnabled"):
        if(not cc.historyEnabled[0]):
            draw = 0

    if(draw):
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glShadeModel(bgl.GL_FLAT)
        alpha = 1-PHI_INV
        # History Trace
        if cc.historyPosition[0]<0:
            return
        bgl.glBegin(bgl.GL_LINE_STRIP)
        ccc = 0
        p2 = Vector(CursorAccess.getCursor())
        pp = None
        pn = None
        for iii in range(cc.historyWindow+1):
            ix_rel = iii - int(cc.historyWindow / 2)
            ix = cc.historyPosition[0] + ix_rel
            if(ix<0 or ix>=len(cc.historyLocation)):
                continue
            ppp = region3d_get_2d_coordinates(context, cc.historyLocation[ix])
            if(ix_rel==-1):
                pp = Vector(cc.historyLocation[ix])
            if(ix_rel==1):
                pn = Vector(cc.historyLocation[ix])
            if(ix_rel<=0):
                bgl.glColor4f(0, 0, 0, alpha)
            else:
                bgl.glColor4f(1, 0, 0, alpha)
            bgl.glVertex2f(ppp[0], ppp[1])
            ccc = ccc + 1
        bgl.glEnd()
        
        # Distance of last step
        y=10
        if(pn):
            bgl.glColor4f(1, 0, 0, PHI_INV)
            location=region3d_get_2d_coordinates(context, p2)
            blf.size(0, 10, 72)  # Prevent font size to randomly change.
            d = (p2-pn).length
            blf.position(0, location[0]+10, location[1]+y, 0)
            blf.draw(0, str(round(d,PRECISION)))
            y = y + 10;
        if(pp):
            bgl.glColor4f(0, 0, 0, PHI_INV)
            location=region3d_get_2d_coordinates(context, p2)
            blf.size(0, 10, 72)  # Prevent font size to randomly change.
            d = (p2-pp).length
            blf.position(0, location[0]+10, location[1]+y, 0)
            blf.draw(0, str(round(d,PRECISION)))
 def Polygon(self, pts, colour):
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*colour)
     bgl.glBegin(bgl.GL_POLYGON)
     for pt in pts:
         x, y = pt
         bgl.glVertex2f(x, y)
     self._end()
Esempio n. 31
0
def draw_callback_px_box(self, context):
    wm = context.window_manager
    sc = context.scene
    pos_x, pos_y = 0, 0  #getDisplayLocation(context)

    # get text-width/height to resize the box

    # Got the size right, now draw box using proper colors
    box_color_r, box_color_g, box_color_b, box_color_alpha = .2, .6, .2, .1  #sc.screencast_keys_box_color
    if hasattr(bpy.ops.object.print3d.__class__, 'print3d_processes'):
        processes = bpy.ops.object.print3d.__class__.print3d_processes
        i = 0
        for p in processes:

            #proc=p[1].proc
            readthread = p[0]
            tcom = p[1]
            progress = tcom.progress * .01
            box_width = context.region.width * progress
            offset_y = 80
            bar_height = 30
            x0 = 0  # max(0, pos_x - padding_x)
            y0 = context.region.height - offset_y - bar_height * i  # max(0, pos_y - padding_y)
            x1 = box_width
            y1 = bar_height + y0
            positions = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]]
            settings = [[bgl.GL_QUADS, min(0.0, box_color_alpha)],
                        [bgl.GL_LINE_LOOP,
                         min(0.0, box_color_alpha)]]
            #print('boxie')
            for mode, box_alpha in settings:
                bgl.glEnable(bgl.GL_BLEND)
                bgl.glBegin(mode)
                bgl.glColor4f(box_color_r, box_color_g, box_color_b,
                              box_color_alpha)
                for v1, v2 in positions:
                    bgl.glVertex2f(v1, v2)
                bgl.glEnd()

            #TEXT HERE
            #calculate overall time

            timer_color_r, timer_color_g, timer_color_b, timer_color_alpha = .9, .9, .9, .5
            pos_x = 20
            pos_y = context.region.height - offset_y - bar_height * i + int(
                bar_height * .3)

            #draw time
            blf.size(0, int(bar_height * .45), 72)
            blf.position(0, pos_x, pos_y, 0)
            bgl.glColor4f(timer_color_r, timer_color_g, timer_color_b,
                          timer_color_alpha)
            blf.draw(0, "Slicing %s : %s %%" % (tcom.obname, tcom.outtext))
            i += 1
Esempio n. 32
0
def img_editor_draw_callback_px(self, context):

    # draw text
    if len(self.pixel_coords) == 0:
        draw_typo_2d((1.0, 1.0, 1.0, 1), "Click on Ala/Condyle")
    elif len(self.pixel_coords) == 1:
        draw_typo_2d((1.0, 1.0, 1.0, 1), "Click on Frankfurt/OrbitalRidge")
    elif len(self.pixel_coords) == 2:
        draw_typo_2d((1.0, 1.0, 1.0, 1), "Click Ref Point 1 (LEFT)")
    elif len(self.pixel_coords) == 3:
        draw_typo_2d((1.0, 1.0, 1.0, 1), "Click Ref Point 1 (RIGHT)")
    elif len(self.pixel_coords) == 4:
        draw_typo_2d((1.0, 1.0, 1.0, 1), "Click Ref Point 1 (TOP)")
    elif len(self.pixel_coords) == 5:
        draw_typo_2d((1.0, 1.0, 1.0, 1), "Click Ref Point 1 (BOTTOM)")

    #draw the user clicked points on the image
    bgl.glPointSize(5)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glColor4f(0.8, 0.2, 0.5, 1.0)
    for pix in self.pixel_coords:
        img_x, img_y = pix[0], pix[1]
        img_size = self.imgeditor_area.spaces.active.image.size
        rx, ry = context.region.view2d.view_to_region(
            img_x / img_size[0], (img_size[1] - img_y) / img_size[1],
            clip=True)

        if rx and ry:
            bgl.glVertex2f(rx, ry)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glPointSize(1)
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    font_id = 0
    for pix in self.pixel_coords:
        img_x, img_y = pix[0], pix[1]
        img_size = self.imgeditor_area.spaces.active.image.size

        rx, ry = context.region.view2d.view_to_region(
            img_x / img_size[0], (img_size[1] - img_y) / img_size[1],
            clip=True)

        blf.position(font_id, rx + 5, ry + 5, 0)
        text = str((round(pix[0]), round(pix[1])))

        blf.draw(font_id, text)

        blf.position(font_id, rx + 5, ry + 20, 0)
        text = str((round(pix[0]), round(pix[1])))
Esempio n. 33
0
def h_draw_circle(x, y, r, color, segs=16):
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glColor4f(*color)
    for i in range(segs):
        theta = 2.0 * 3.1415926 * float(i) / float(segs)
        tx = r * math.cos(theta)
        ty = r * math.sin(theta)
        
        bgl.glVertex2f(tx+x, ty+y)
    
    bgl.glEnd()
Esempio n. 34
0
def h_draw_circle_wire(x, y, r, segs=16):
    bgl.glLineWidth(0.5)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    
    for i in range(segs):
        theta = 2.0 * 3.1415926 * float(i) / float(segs)
        tx = r * math.cos(theta)
        ty = r * math.sin(theta)
        
        bgl.glVertex2f(tx+x, ty+y)
    
    bgl.glEnd()
Esempio n. 35
0
    def __render_each_data(context, data):
        sc = context.scene
        # setup rendering region
        for area in bpy.context.screen.areas:
            if area.type == "VIEW_3D":
                break
        else:
            return
        for region in area.regions:
            if region.type == "WINDOW":
                break
        else:
            return
        for space in area.spaces:
            if space.type == "VIEW_3D":
                break
        else:
            return
        loc_on_screen = view3d_utils.location_3d_to_region_2d(
            region,
            space.region_3d,
            data[1])

        rect = get_canvas(context, loc_on_screen, len(str(data[0])), sc.iv_font_size)
        positions = [
            [rect.x0, rect.y0],
            [rect.x0, rect.y1],
            [rect.x1, rect.y1],
            [rect.x1, rect.y0]
        ]

        # render box
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_QUADS)
        box_color_r, box_color_g, box_color_b, box_color_a = sc.iv_box_color
        bgl.glColor4f(box_color_r, box_color_g, box_color_b, box_color_a)
        for (v1, v2) in positions:
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()

        # render index
        font_size = sc.iv_font_size
        blf.size(0, font_size, 72)
        blf.enable(0, blf.SHADOW)
        blf.shadow_offset(0, 1, -1)
        blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.0)
        blf.position(0, rect.x0 + (rect.x1 - rect.x0) * 0.18, rect.y0 + (rect.y1 - rect.y0) * 0.24, 0)
        text_color_r, text_color_g, text_color_b, text_color_a = sc.iv_text_color
        bgl.glColor4f(text_color_r, text_color_g, text_color_b, text_color_a)
        blf.draw(0, str(data[0]))
        blf.blur(0, 0)
        blf.disable(0, blf.SHADOW)
Esempio n. 36
0
    def draw_bb(self, context):
        props = context.scene.pt_props
        x0, y0 = props.start
        x1, y1 = props.end

        verts = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]]

        bgl.glLineWidth(1)
        bgl.glBegin(bgl.GL_LINE_LOOP)
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        for (x, y) in verts:
            bgl.glVertex2f(x, y)
        bgl.glEnd()
Esempio n. 37
0
def draw_point(p, color=(0, 0, 0, 1), size=4):
    bgl.glPointSize(size)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glColor4f(
        color[0],
        color[1],
        color[2],
        color[3],
    )
    bgl.glVertex2f(p[0], p[1])
    bgl.glEnd()
    restore_bgl()
Esempio n. 38
0
def draw_circle(x, y, radius, subdivide, poly=False):
    r = 0.0
    dr = math.pi * 2 / subdivide
    if poly:
        subdivide += 1
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        bgl.glVertex2f(x, y)
    else:
        bgl.glBegin(bgl.GL_LINE_LOOP)
    for i in range(subdivide):
        bgl.glVertex2f(x + radius * math.cos(r), y + radius * math.sin(r))
        r += dr
    bgl.glEnd()
Esempio n. 39
0
def draw2D_arrow(p0: Point2D, p1: Point2D):
    d = (p0 - p1) * 0.25
    c = Vec2D((d.y, -d.x))
    p2 = p1 + d + c
    p3 = p1 + d - c

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*p0)
    bgl.glVertex2f(*p1)
    bgl.glVertex2f(*p2)
    bgl.glVertex2f(*p1)
    bgl.glVertex2f(*p3)
    bgl.glEnd()
Esempio n. 40
0
 def draw_line(self, v1, v2):
     """
     Draws a line between the 2D position v1 and the 2D position v2
     :param v1: First 2D point of the line
     :param v2: Second 2D point of the line
     """
     if v1 and v2:
         bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
         bgl.glBegin(bgl.GL_LINES)
         bgl.glVertex2f(*v1)
         bgl.glVertex2f(*v2)
         bgl.glEnd()
     return
Esempio n. 41
0
def simple_grid_xy(x, y, args):
    func = args[0]
    back_color, grid_color, line_color = args[1]
    scale = args[2]

    def draw_rect(x=0, y=0, w=30, h=10, color=(0.0, 0.0, 0.0, 1.0)):

        bgl.glColor4f(*color)
        bgl.glBegin(bgl.GL_POLYGON)

        for coord in [(x, y), (x + w, y), (w + x, y - h), (x, y - h)]:
            bgl.glVertex2f(*coord)
        bgl.glEnd()

    size = 140 * scale

    # draw bg fill
    draw_rect(x=x, y=y, w=size, h=size, color=back_color)

    # draw grid
    bgl.glColor4f(*grid_color)
    num_divs = 8
    offset = size / num_divs
    line_parts_x = []
    line_parts_y = []
    for i in range(num_divs + 1):
        xpos1 = x + (i * offset)
        ypos1 = y
        ypos2 = y - size
        line_parts_x.extend([[xpos1, ypos1], [xpos1, ypos2]])

        ypos = y - (i * offset)
        line_parts_y.extend([[x, ypos], [x + size, ypos]])

    bgl.glLineWidth(0.8)
    bgl.glBegin(bgl.GL_LINES)
    for coord in line_parts_x + line_parts_y:
        bgl.glVertex2f(*coord)
    bgl.glEnd()

    # draw graph-line
    bgl.glColor4f(*line_color)
    bgl.glLineWidth(2.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    num_points = 100
    seg_diff = 1 / num_points
    for i in range(num_points + 1):
        _px = x + ((i * seg_diff) * size)
        _py = y - (1 - func(i * seg_diff) * size) - size
        bgl.glVertex2f(_px, _py)
    bgl.glEnd()
Esempio n. 42
0
def draw_call(self, context):
    global x_loc
    global y_loc

    width = 30
    height = 30

    """if start_draw == True:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glLineWidth(4)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glColor4f(0.0, 0.0, 0.0, 0.75)
        for x, y in self.draw_mouse_path:
            bgl.glVertex2i(x, y)

        bgl.glEnd()"""

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.98)
    font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    blf.position(font_id, 25, 20, 0)
    blf.size(font_id, 20, 57)
    blf.draw(font_id, "Press Enter to Confirm")

    blf.position(font_id, 40, 7, 0)
    blf.size(font_id, 20, 40)
    blf.draw(font_id, "Kaleidoscope Modal 0.1")

    bgl.glBegin(bgl.GL_QUADS)
    bgl.glColor3f(c[0][0], c[0][1], c[0][2])
    bgl.glVertex3f(x_loc+10,y_loc+10,0)
    bgl.glVertex3f(x_loc+10+width,y_loc+10,0)
    bgl.glVertex3f(x_loc+10+width,y_loc+height+10,0)
    bgl.glVertex3f(x_loc+10,y_loc+height+10,0)
    bgl.glEnd()

    if c[0][0] < 0.1 and c[0][1] < 0.1 and c[0][2] < 0.1:
        bgl.glColor3f(1, 1, 1)
    else:
        bgl.glColor3f(0, 0, 0)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(x_loc+10-1, y_loc+10-1)
    bgl.glVertex2f(x_loc+10+width+1, y_loc+10-1)
    bgl.glVertex2f(x_loc+10+width, y_loc+10+height+1)
    bgl.glVertex2f(x_loc+10-1, y_loc+10+height)
    bgl.glVertex2f(x_loc+10-1, y_loc+10-1)
    bgl.glEnd()
def color_placing():
    """
    Draw the green rectangle via OpenGL-Wrapper
    """
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth / 2
    y = windowHeight * 0.5 - imageHeight / 2

    gl_position = [[x, y], [x + imageWidth, y],
                   [x + imageWidth, y + imageHeight], [x, y + imageHeight]]

    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf,
                                         "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()

    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Draw the colored quad
    bgl.glColor4f(0, 1, 0, 0.25)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
        bgl.glTexCoord2f(texco[i][0], texco[i][1])
        bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
Esempio n. 44
0
    def draw_active_item_background(self):
        prefs = self.prefs
        colors = prefs.colors
        menu = self.menu
        items = menu.current_items
        widget_unit = self.widget_unit

        if menu.active_index == -1 or not menu.is_valid_click:
            return
        if not items[menu.active_index]:
            return

        r_icon = self.icon_box_size / 2

        i = menu.active_index
        subdiv = 32 if len(items) <= 2 else 16
        if 0:
            angle_start, angle_end = menu.item_boundary_angles[i]
        else:
            pie_angle = math.pi * 2 / len(items)
            angle_start = math.pi * 0.5 - pie_angle * i + pie_angle / 2
            angle_end = angle_start - pie_angle
        angle_subdiv = (angle_start - angle_end) / subdiv
        x, y = menu.co
        bgl.glColor4f(*colors.pie_sel)
        if menu.draw_type == 'SIMPLE':
            if len(menu.menu_items) <= 4:
                r1 = menu.radius_ - widget_unit * 0.2
            else:
                # この辺は適当
                _, rect = self.calc_item_rect(
                    int(len(menu.menu_items) / 4) - 1, "DUMMY", 'NONE')
                v = Vector((rect[0], rect[1]))
                r1 = (rect[1] - menu.co[1]) - widget_unit * 0.2
            # r2 = menu.radius_ + r_icon * 2 + widget_unit * 0.2
            r2 = r1 + r_icon * 2 + widget_unit * 0.4
        else:
            r1 = menu.radius_ - widget_unit * 0.2
            r2 = menu.radius_ + r_icon * 2 + widget_unit * 0.2

        # r1 = prefs.menu_radius_center + widget_unit * 0.5
        # r2 = prefs.menu_radius_center + widget_unit * 0.8
        # bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glBegin(bgl.GL_QUAD_STRIP)
        for m in range(subdiv + 1):
            ang = angle_start - angle_subdiv * m
            cosf = math.cos(ang)
            sinf = math.sin(ang)
            bgl.glVertex2f(x + r1 * cosf, y + r1 * sinf)
            bgl.glVertex2f(x + r2 * cosf, y + r2 * sinf)
        bgl.glEnd()
Esempio n. 45
0
def h_draw_gradient_rect(bounds, gradient, border_width=1, border_radius=0, border_color=(0, 0, 0, 1), wire=False):
    if len(gradient.colors) != len(gradient.offsets): return
    
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    h_mask_begin(bounds, border_radius)
    
    mode = bgl.GL_LINE_STRIP if wire else bgl.GL_TRIANGLE_STRIP
    
    bgl.glBegin(mode)
    if gradient.orientation == 0: # HOR
        for i in range(len(gradient.colors)):
            bgl.glColor4f(*gradient.colors[i])
            x = (bounds[2] * clamp(gradient.offsets[i], 0.0, 1.0)) + bounds[0]
            bgl.glVertex2f(x, bounds[1])
            bgl.glVertex2f(x, bounds[1]+bounds[3])
    elif gradient.orientation == 1: # VER
        for i in range(len(gradient.colors)):
            bgl.glColor4f(*gradient.colors[i])
            y = (bounds[3] * clamp(gradient.offsets[i], 0.0, 1.0)) + bounds[1]
            bgl.glVertex2f(bounds[0], y)
            bgl.glVertex2f(bounds[0]+bounds[2], y)
    bgl.glEnd()
        
    h_mask_end()
    
    if border_width > 0:
        h_round_rect_wire(bounds, border_radius, color=border_color, width=border_width)
    
    bgl.glDisable(bgl.GL_BLEND)
Esempio n. 46
0
def draw_outline_or_region(mode, points):
    '''
        arg: mode either bgl.GL_POLYGON or bgl.GL_LINE_LOOP
        color will need to be set beforehand using theme colors. eg
        bgl.glColor4f(self.ri, self.gi, self.bi, self.ai)
        '''

    bgl.glBegin(mode)

    # start with corner right-bottom
    for i in range(0, len(points)):
        bgl.glVertex2f(points[i][0], points[i][1])

    bgl.glEnd()
    def draw_Cartesian(self):  #vertices):
        ob = bpy.context.scene.objects.active.location
        rgn = bpy.context.region
        rv3d = bpy.context.space_data.region_3d
        #bgl.glClear()

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glLineWidth(4)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        v3d = Vector((0, 0, 0))
        v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
        bgl.glVertex2f(*v2d)
        bgl.glColor4f(100, 0.0, 0.0, 1)
        v3d = mathutils.Vector((ob.x, 0, 0))
        v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
        bgl.glVertex2f(*v2d)
        bgl.glColor4f(0, 100.0, 0.0, 1)
        v3d = mathutils.Vector((ob.x, ob.y, 0))
        v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
        bgl.glVertex2f(*v2d)
        bgl.glColor4f(0, 0.0, 100.0, 1)
        v3d = mathutils.Vector((ob.x, ob.y, ob.z))
        v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
        bgl.glVertex2f(*v2d)
        bgl.glEnd()
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)

        bgl.glColor4f(1, 1, 1, 1)
        self.draw_value(Vector((ob.x / 2, 0, 0)), str(round(ob.x, 2)))
        self.draw_value(Vector((ob.x, ob.y / 2, 0)), str(round(ob.y, 2)))
        self.draw_value(Vector((ob.x, ob.y, ob.z / 2)), str(round(ob.z, 2)))
Esempio n. 48
0
def draw_sun(x, y, radius, subdivide=16, raydirections=(),
             raylength=10, raystartoffset=0):
    draw_circle(x, y, radius, subdivide)
    bgl.glBegin(bgl.GL_LINES)
    if isinstance(raylength, (int, float)):
        llist = [raylength for i in range(len(raydirections))]
    else:
        llist = raylength
    for i, angle in enumerate(raydirections):
        bgl.glVertex2f(x + (radius + raystartoffset) * math.cos(angle), \
                       y + (radius + raystartoffset) * math.sin(angle))
        bgl.glVertex2f(x + (radius + llist[i]) * math.cos(angle), \
                       y + (radius + llist[i]) * math.sin(angle))
    bgl.glEnd()
Esempio n. 49
0
 def draw_preview(self):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     
     bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
     bgl.glColor4f(0,0,0.2,0.5)
     bgl.glVertex2f(-1, -1)
     bgl.glVertex2f( 1, -1)
     bgl.glColor4f(0,0,0.2,0)
     bgl.glVertex2f( 1,  1)
     bgl.glVertex2f(-1,  1)
     bgl.glEnd()
     
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPopAttrib()
Esempio n. 50
0
 def draw_postpixel(self):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
     
     bgl.glEnable(bgl.GL_BLEND)
     
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     
     bgl.glColor4f(1,0,0,0.2)    # TODO: use window background color??
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
     bgl.glVertex2f(-1, -1)
     bgl.glVertex2f( 1, -1)
     bgl.glVertex2f( 1,  1)
     bgl.glVertex2f(-1,  1)
     bgl.glEnd()
     
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPopAttrib()
Esempio n. 51
0
 def draw_callback_px(tmp, self, context):
     color = bpy.context.tool_settings.image_paint.brush.cursor_color_add
     
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(color[0], color[1], color[2], .5)
     bgl.glLineWidth(1)
     
     bgl.glEnable(bgl.GL_LINE_SMOOTH)
     
     ### draw curve gradient
     ring_count = 12
     segements = 36
             
     for j in range(ring_count):
         bgl.glBegin(bgl.GL_QUAD_STRIP)
         for i in range(segements+1):
             curve = self.brush.curve.curves[0]
             curve_pos = (j*(1/ring_count))
             curve_pos = min(curve_pos,1.0)
             curve_pos = max(curve_pos,0.0)
             curve_pos2 = curve_pos + (1/ring_count)
             curve_pos2 = min(curve_pos2,1.0)
             curve_pos2 = max(curve_pos2,0.0)
             
             alpha1 = curve.evaluate(curve_pos)
             alpha2 = curve.evaluate(curve_pos2)
             
             offset = self.mouse_pos_init
             angle = 2*pi/segements
             size = self.brush_size * (j+1)*(1/ring_count)
             size2 = self.brush_size * j*(1/ring_count)
             point1 = offset + Vector((size* cos(i*angle),(size* sin(i*angle))))
             point2 = offset + Vector((size2* cos(i*angle),(size2* sin(i*angle))))
             
             bgl.glColor4f(self.brush_color[0], self.brush_color[1], self.brush_color[2], alpha2)
             bgl.glVertex2f(point1[0],point1[1])
             bgl.glColor4f(self.brush_color[0], self.brush_color[1], self.brush_color[2], alpha1)
             bgl.glVertex2f(point2[0],point2[1])        
         
         bgl.glEnd()
     
     ### draw brush circles
     bgl.glColor4f(color[0], color[1], color[2], .5)
     bgl.glLineWidth(1)
     bgl.glBegin(bgl.GL_LINE_LOOP)
     segements = 42
     for i in range(segements):
         bgl.glVertex2f(self.mouse_pos_init.x + self.brush_size*cos(i*(2*pi/segements)),self.mouse_pos_init.y + self.brush_size*sin(i*(2*pi/segements)))
     bgl.glEnd()
     
     bgl.glBegin(bgl.GL_LINE_LOOP)
     segements = 42
     for i in range(segements):
         bgl.glVertex2f(self.mouse_pos_init.x + self.brush_size_init*cos(i*(2*pi/segements)),self.mouse_pos_init.y + self.brush_size_init*sin(i*(2*pi/segements)))
     bgl.glEnd()
     
     # restore opengl defaults
     bgl.glLineWidth(1)
     bgl.glDisable(bgl.GL_BLEND)
     bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Esempio n. 52
0
def draw_underline_in_strip(strip_coords, pixel_size_x, color):
    from bgl import glColor4f, glRectf, glEnable, glDisable, GL_BLEND
    import bgl

    context = bpy.context

    # Strip coords
    s_x1, s_y1, s_x2, s_y2 = strip_coords

    # be careful not to draw over the current frame line
    cf_x = context.scene.frame_current_final

    bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_LINE_BIT)

    glColor4f(*color)
    glEnable(GL_BLEND)
    bgl.glLineWidth(2)
    bgl.glBegin(bgl.GL_LINES)

    bgl.glVertex2f(s_x1, s_y1)
    if s_x1 < cf_x < s_x2:
        # Bad luck, the line passes our strip
        bgl.glVertex2f(cf_x - pixel_size_x, s_y1)
        bgl.glVertex2f(cf_x + pixel_size_x, s_y1)
    bgl.glVertex2f(s_x2, s_y1)

    bgl.glEnd()
    bgl.glPopAttrib()
Esempio n. 53
0
    def draw(self):
        Widget.draw(self)

        if self.texture is None:
            return

        self.texture.bind()

        bgl.glBegin(bgl.GL_QUADS)
        self.color.apply()

        bgl.glTexCoord2f(0, 0)
        bgl.glVertex2f(self.padding.x, self.padding.h)

        bgl.glTexCoord2f(1, 0)
        bgl.glVertex2f(self.allocation.w - self.padding.w, self.padding.h)

        bgl.glTexCoord2f(1, 1)
        bgl.glVertex2f(self.allocation.w - self.padding.w,
                       self.allocation.h - self.padding.y)

        bgl.glTexCoord2f(0, 1)
        bgl.glVertex2f(self.padding.x, self.allocation.h - self.padding.y)

        bgl.glEnd()
        self.texture.unbind()
Esempio n. 54
0
def draw_image_data(file_path, center_coord):

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_TEXTURE_2D)

    image  = load_image_to_data(file_path)
    width = get_image_width(image)
    height = get_image_height(image)

    top_left = (center_coord[0] - width/2, center_coord[1] - height/2)
    top_right = (center_coord[0] + width/2, center_coord[1] - height/2)
    bottom_right = (center_coord[0] + width/2, center_coord[1] + height/2)
    bottom_left = center_coord(0 - width/2, center_coord[1] + height/2)

    bind_image(image)
    
    bgl.glBegin(bgl.GL_QUADS)
    bgl.glTexCoord2f(0.0, 0.0)
    bgl.glVertex2f(*top_left)

    bgl.glTexCoord2f(1.0, 0.0)
    bgl.glVertex2f(*top_right)

    bgl.glTexCoord2f(1.0, 1.0)
    bgl.glVertex2f(*bottom_right)

    bgl.glTexCoord2f(0.0, 1.0)
    bgl.glVertex2f(*bottom_left)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_TEXTURE_2D)
    bgl.glDisable(bgl.GL_BLEND)
Esempio n. 55
0
def h_draw_texture(id, w, h, bounds, coords):    
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, id)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    bgl.glColor4f(*(1,1,1,1))
    
    B = bounds
    C = coords
    
    D = [
        (C[0][0]/w, C[0][1]/h),
        (C[1][0]/w, C[1][1]/h),
        (C[2][0]/w, C[2][1]/h),
        (C[3][0]/w, C[3][1]/h),
    ]
    #print(D)
    
    bgl.glBegin(bgl.GL_QUADS)
    bgl.glTexCoord2f(D[0][0], D[0][1])    
    bgl.glVertex2f(B[0], B[1])
    
    bgl.glTexCoord2f(D[1][0], D[1][1])    
    bgl.glVertex2f(B[0]+B[2], B[1])
    
    bgl.glTexCoord2f(D[2][0], D[2][1])    
    bgl.glVertex2f(B[0]+B[2], B[1]+B[3])
    
    bgl.glTexCoord2f(D[3][0], D[3][1])    
    bgl.glVertex2f(B[0], B[1]+B[3])
    bgl.glEnd()

    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
    bgl.glDisable(bgl.GL_TEXTURE_2D)
Esempio n. 56
0
def draw2d_polyline(points, color, thickness, stipple=False):
    if stipple:
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points: bgl.glVertex2f(*coord)
    bgl.glEnd()
    bgl.glLineWidth(1)
    if stipple:
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines
def display_line_between_two_points(region, rv3d, p1_3d, p2_3d):

    bgl.glEnable(bgl.GL_BLEND)

    p1_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, p1_3d)
    p2_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, p2_3d)

    if p1_2d is None:
        p1_2d = (0.0, 0.0)
        p2_2d = (0.0, 0.0)

    col_line_main = addon_settings_graph('col_line_main')
    col_line_shadow = addon_settings_graph('col_line_shadow')

    bgl.glColor4f(*col_line_shadow)
    bgl.glLineWidth(1.4)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f((p1_2d[0] - 1), (p1_2d[1] - 1))
    bgl.glVertex2f((p2_2d[0] - 1), (p2_2d[1] - 1))
    bgl.glEnd()
    bgl.glColor4f(*col_line_main)
    bgl.glLineWidth(1.4)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*p1_2d)
    bgl.glVertex2f(*p2_2d)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_BLEND)
Esempio n. 58
0
def draw_rounded_box(x, y, w, h, round_radius, fill=False, fill_color=None):

    def circle_verts_num(r):
        """Get number of verticies for circle optimized for drawing."""

        num_verts = 32
        threshold = 2.0  # pixcel
        while True:
            if r * 2 * math.pi / num_verts > threshold:
                return num_verts
            num_verts -= 4
            if num_verts < 1:
                return 1

    num_verts = circle_verts_num(round_radius)
    n = int(num_verts / 4) + 1
    dangle = math.pi * 2 / num_verts

    x_origin = [
        x + round_radius,
        x + w - round_radius,
        x + w - round_radius,
        x + round_radius,
    ]
    y_origin = [
        y + round_radius,
        y + round_radius,
        y + h - round_radius,
        y + h - round_radius,
    ]
    angle_start = [
        math.pi * 1.0,
        math.pi * 1.5,
        math.pi * 0.0,
        math.pi * 0.5,
    ]

    if fill:
        bgl.glColor3f(*fill_color)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    else:
        bgl.glBegin(bgl.GL_LINE_LOOP)
    for x0, y0, angle in zip(x_origin, y_origin, angle_start):
        for _ in range(n):
            x = x0 + round_radius * math.cos(angle)
            y = y0 + round_radius * math.sin(angle)
            bgl.glVertex2f(x, y)
            angle += dangle
    bgl.glEnd()
    bgl.glColor3f(1.0, 1.0, 1.0)
Esempio n. 59
0
def draw_box(xmin, ymin, w, h, poly=False):
    bgl.glBegin(bgl.GL_QUADS if poly else bgl.GL_LINE_LOOP)
    bgl.glVertex2f(xmin, ymin)
    bgl.glVertex2f(xmin + w, ymin)
    bgl.glVertex2f(xmin + w, ymin + h)
    bgl.glVertex2f(xmin, ymin + h)
    bgl.glEnd()
Esempio n. 60
0
def draw_point(position, size=2, color=(1.0, 0.2, 0.2, 1.0)):
    """Draw single red point"""

    bgl.glEnable(bgl.GL_POINT_SMOOTH)
    bgl.glPointSize(size)
    bgl.glColor4f(*color)

    vec2d = to_screen_coord(position)
    if vec2d:
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex2f(*vec2d)
        bgl.glEnd()

    bgl.glDisable(bgl.GL_POINT_SMOOTH)