예제 #1
0
def draw_callback_px(self, context):
    if self.moves % 3 == 0 and len(self.colors) < 32:
        self.mouse_path.append(self.mouse_pos)
        view = get_viewport()
        x, y = self.mouse_pos
        c = bgl.Buffer(bgl.GL_FLOAT, 4)
        bgl.glReadPixels(x + view[0], y + view[1], 1, 1, bgl.GL_RGB,
                         bgl.GL_FLOAT, c)
        self.colors.append(c.to_list())

    # 50% alpha, 2 pixel width line

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1, 1, 1, 0.5)
    bgl.glLineWidth(4)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #2
0
def draw_select(self, context):
    """
    Draw a box around each selected strip in the preview window
    """
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(4)

    theme = context.user_preferences.themes['Default']
    active_color = theme.view_3d.object_active
    select_color = theme.view_3d.object_selected
    opacity = 0.9 - (self.seconds / self.fadeout_duration)

    active_strip = context.scene.sequence_editor.active_strip

    offset_x, offset_y, fac, preview_zoom = get_preview_offset()

    for strip in context.selected_sequences:
        if strip == active_strip:
            bgl.glColor4f(active_color[0], active_color[1], active_color[2],
                          opacity)
        else:
            bgl.glColor4f(select_color[0], select_color[1], select_color[2],
                          opacity)

        bgl.glBegin(bgl.GL_LINE_LOOP)
        corners = get_strip_corners(strip)
        for corner in corners:
            corner_x = int(corner[0] * preview_zoom * fac) + offset_x
            corner_y = int(corner[1] * preview_zoom * fac) + offset_y
            bgl.glVertex2i(corner_x, corner_y)
        bgl.glEnd()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #3
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(.7, .7, .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.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)
예제 #4
0
def draw_callback(self, context):

    scene = context.scene
    x = int(round(context.region.width * 0.01 + (self._t_target - scene.frame_start) * self._ppf))
    string = str(self._t_target)
    string = string[0 : string.index(".") + 3]
    font_id = 0  # XXX, need to find out how best to get this.

    # draw marker
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1, 0, 0, 1)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(x, 17)
    bgl.glVertex2i(x, context.region.height)
    bgl.glEnd()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    # draw frame number
    if self._show_frame_indicator:
        blf.position(font_id, x + 5, 21, 0)
        blf.size(font_id, 12, 72)
        blf.draw(font_id, string)
예제 #5
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, str(self.mouse_pos[0]) + ',' + str(self.mouse_pos[1]))
    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 1.0, 0.0, 0.5)
    bgl.glLineWidth(2)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.poly_points:
        bgl.glVertex2i(x, y)
    bgl.glColor4f(1.0, 0.0, 0.0, 0.5)
    bgl.glVertex2i(self.mouse_pos[0], self.mouse_pos[1])
    bgl.glEnd()
    bgl.glPointSize(4.0)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glColor4f(0.0, 1.0, 1.0, 0.5)
    for obj, point in self.visible_objects:
        bgl.glVertex2f(point[0], point[1])
    for vert, point in self.verts:
        bgl.glVertex2f(point[0], point[1])
    bgl.glEnd()
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #6
0
def draw_callback_px(self, context):
    #print("mouse points", self.mouse_path[len(self.mouse_path)-1])

    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, "Mouse " + str(self.mouse_path[len(self.mouse_path)-1]))
    x1=bpy.context.scene['xmin']
    y1=bpy.context.scene['ymin']
    x2=self.mouse_path[len(self.mouse_path)-1][0]
    y2=self.mouse_path[len(self.mouse_path)-1][1]

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.8, 0.0, 0.8, 0.5)
    bgl.glLineWidth(3)

    if bpy.context.scene['SupIzq']:
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2i(x1, y1)
        bgl.glVertex2i(x2, y1)
        bgl.glVertex2i(x2, y2)
        bgl.glVertex2i(x1, y2)
        bgl.glVertex2i(x1, y1)
        bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #7
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)
def draw_callback_px(self, context):
    print("mouse points", len(self.mouse_path))

    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()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #9
0
def draw_callback_px(self, context):
    print("mouse points", len(self.mouse_path))

    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()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #10
0
def draw_callback(self, context):

    scene = context.scene
    x = int(
        round(context.region.width * 0.01 +
              (self._t_target - scene.frame_start) * self._ppf))
    string = str(self._t_target)
    string = string[0:string.index('.') + 3]
    font_id = 0  # XXX, need to find out how best to get this.

    # draw marker
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1, 0, 0, 1)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(x, 17)
    bgl.glVertex2i(x, context.region.height)
    bgl.glEnd()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    # draw frame number
    if self._show_frame_indicator:
        blf.position(font_id, x + 5, 21, 0)
        blf.size(font_id, 12, 72)
        blf.draw(font_id, string)
def draw_callback_px(self, context):
    if self.moves % 3 == 0 and len(self.colors) < 32:
        self.mouse_path.append(self.mouse_pos)
        view = get_viewport()
        x, y = self.mouse_pos
        c = bgl.Buffer(bgl.GL_FLOAT, 4)
        bgl.glReadPixels(x + view[0], y + view[1], 1, 1, bgl.GL_RGB, bgl.GL_FLOAT, c)
        self.colors.append(c.to_list())

    # 50% alpha, 2 pixel width line

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1, 1, 1, 0.5)
    bgl.glLineWidth(4)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #12
0
 def Rectangle(self, x0, y0, x1, y1, colour, width=2, style=bgl.GL_LINE):
     self._start_line(colour, width, style)
     bgl.glVertex2i(x0, y0)
     bgl.glVertex2i(x1, y0)
     bgl.glVertex2i(x1, y1)
     bgl.glVertex2i(x0, y1)
     bgl.glVertex2i(x0, y0)
     self._end()
 def Rectangle(self, x0, y0, x1, y1, colour, width=2, style=bgl.GL_LINE):
     self._start_line(colour, width, style)
     bgl.glVertex2i(x0, y0)
     bgl.glVertex2i(x1, y0)
     bgl.glVertex2i(x1, y1)
     bgl.glVertex2i(x0, y1)
     bgl.glVertex2i(x0, y0)
     self._end()
예제 #14
0
 def draw_line(origin, length, thickness, vertical=False):
     """Drawing lines with polys, its faster"""
     x = (origin[0] + thickness) if vertical else (origin[0] + length)
     y = (origin[1] + length) if vertical else (origin[1] + thickness)
     bgl.glBegin(bgl.GL_QUADS)
     for v1, v2 in [origin, (x, origin[1]), (x, y), (origin[0], y)]:
         bgl.glVertex2i(v1, v2)
     bgl.glEnd()
     return
예제 #15
0
 def draw_line(origin, length, thickness, vertical=False):
     """Drawing lines with polys, its faster"""
     x = (origin[0] + thickness) if vertical else (origin[0] + length)
     y = (origin[1] + length) if vertical else (origin[1] + thickness)
     bgl.glBegin(bgl.GL_QUADS)
     for v1, v2 in [origin, (x, origin[1]), (x, y), (origin[0], y)]:
         bgl.glVertex2i(v1, v2)
     bgl.glEnd()
     return
def draw_callback_px(self, context):

    bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
    # glPushAttrib is done to return everything to normal after drawing

    bgl.glLineStipple(10, 0x9999)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.8)
    bgl.glLineWidth(5)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()
    bgl.glPopAttrib()

    bgl.glEnable(bgl.GL_BLEND)

    # ...api_current/bpy.types.Area.html?highlight=bpy.types.area
    header_height = context.area.regions[0].height # 26px
    width = context.area.width
    height = context.area.height - header_height

    p1_2d = (0,0)
    p2_2d = (width, height)
    p3_2d = (width, 0)
    p4_2d = (0, height)

    # green line
    bgl.glLineWidth(3)

    draw_line_2d((0.0, 1.0, 0.0, 0.8), p1_2d, p2_2d)

    # yellow line
    bgl.glLineWidth(5)
    draw_line_2d((1.0, 1.0, 0.0, 0.8), p3_2d, p4_2d) 

    # white circle
    bgl.glLineWidth(4)
    draw_circle_2d((1.0, 1.0, 1.0, 0.8), width/2, height/2, 70, 360)

    # red circle
    bgl.glLineWidth(5)
    draw_circle_2d((1.0, 0.0, 0.0, 0.4), width/2, height/2, 230, 5)

    # draw text
    draw_typo_2d((1.0, 1.0, 1.0, 1), "Hello Word " + str(len(self.mouse_path)))

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #17
0
def draw_callback_px(self, context):

    bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
    # glPushAttrib is done to return everything to normal after drawing

    bgl.glLineStipple(10, 0x9999)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.8)
    bgl.glLineWidth(5)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()
    bgl.glPopAttrib()

    bgl.glEnable(bgl.GL_BLEND)

    # ...api_current/bpy.types.Area.html?highlight=bpy.types.area
    header_height = context.area.regions[0].height  # 26px
    width = context.area.width
    height = context.area.height - header_height

    p1_2d = (0, 0)
    p2_2d = (width, height)
    p3_2d = (width, 0)
    p4_2d = (0, height)

    # green line
    bgl.glLineWidth(3)

    draw_line_2d((0.0, 1.0, 0.0, 0.8), p1_2d, p2_2d)

    # yellow line
    bgl.glLineWidth(5)
    draw_line_2d((1.0, 1.0, 0.0, 0.8), p3_2d, p4_2d)

    # white circle
    bgl.glLineWidth(4)
    draw_circle_2d((1.0, 1.0, 1.0, 0.8), width / 2, height / 2, 70, 360)

    # red circle
    bgl.glLineWidth(5)
    draw_circle_2d((1.0, 0.0, 0.0, 0.4), width / 2, height / 2, 230, 5)

    # draw text
    draw_typo_2d((1.0, 1.0, 1.0, 1), "Hello Word " + str(len(self.mouse_path)))

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #18
0
    def draw_callback_px(self):
        self.font_id = 0  # XXX, need to find out how best to get this.
        global_pos = self.region_height - 60
        # draw some text
        headline_color = [1.0, 0.9, 0.6, 1.0]
        
        ### draw gradient overlay
        bgl.glEnable(bgl.GL_BLEND)
        
        line_width = 10
        bgl.glLineWidth(line_width)
        width = int(525/line_width)
        start_at = .2
        for i in range(width):
            bgl.glBegin(bgl.GL_LINE_STRIP)
            alpha = (width-i)/width/(1-start_at)

            if i > width*start_at:
                bgl.glColor4f(0.0, 0.0, 0.0, .7*self.alpha_current*alpha)
            else:
                bgl.glColor4f(0.0, 0.0, 0.0, .7*self.alpha_current)
            x = (i*line_width) + self.region_offset
            y = self.region_height
            bgl.glVertex2i(x, 0)
            bgl.glVertex2i(x, y)
            bgl.glEnd()

        
        ### draw hotkeys        
        self.write_text("Hotkeys - Object Mode",size=20,pos_y=global_pos,color=headline_color)
        self.write_text("   F   -   Contextual Pie Menu",size=15,pos_y=global_pos-20)
        
        self.write_text("Hotkeys - Object Outliner",size=20,pos_y=global_pos-60,color=headline_color)
        self.write_text("   Ctrl + Click    -   Add Item to Selection",size=15,pos_y=global_pos-80)
        self.write_text("   Shift + Click   -   Multi Selection",size=15,pos_y=global_pos-100)
        
        self.write_text("Hotkeys - Keyframing",size=20,pos_y=global_pos-160,color=headline_color)
        self.write_text("   Ctrl + Click on Key Operator    -   Opens Curve Interpolation Options",size=15,pos_y=global_pos-180)
        
        self.write_text("Hotkeys - Edit Armature Mode",size=20,pos_y=global_pos-240,color=headline_color)
        self.write_text("   Click + Drag    -   Draw Bone",size=15,pos_y=global_pos-260)
        self.write_text("   Shift + Click + Drag    -   Draw Bone locked to 45 Angle",size=15,pos_y=global_pos-280)
        self.write_text("   Alt + Click    -    Bind Sprite to selected Bones",size=15,pos_y=global_pos-300)
        self.write_text("   ESC/Tab    -    Exit Armature Mode",size=15,pos_y=global_pos-320)
        
        self.write_text("Hotkeys - Edit Mesh Mode",size=20,pos_y=global_pos-380,color=headline_color)
        self.write_text("   Click + Drag    -   Draw Vertex Contour",size=15,pos_y=global_pos-400)
        self.write_text("   Alt + Click on Vertex   -   Close Contour",size=15,pos_y=global_pos-420)
        self.write_text("   ESC/Tab    -    Exit Mesh Mode",size=15,pos_y=global_pos-440)
        
        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #19
0
def draw_texture(x, y, w, h, texture, mode=None):
    mode_bak = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetIntegerv(bgl.GL_DRAW_BUFFER, mode_bak)
    if mode is not None:
        bgl.glDrawBuffer(mode)

    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture)

    bgl.glColor4d(1.0, 1.0, 1.0, 1.0)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glTexCoord2d(0.0, 0.0)
    bgl.glVertex2i(x, y)
    bgl.glTexCoord2d(1.0, 0.0)
    bgl.glVertex2i(x + w, y)
    bgl.glTexCoord2d(1.0, 1.0)
    bgl.glVertex2i(x + w, y + h)
    bgl.glTexCoord2d(0.0, 1.0)
    bgl.glVertex2i(x, y + h)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    if mode is not None:
        bgl.glDrawBuffer(mode_bak[0])
예제 #20
0
def draw_texture(x, y, w, h, texture, mode=None):
    mode_bak = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetIntegerv(bgl.GL_DRAW_BUFFER, mode_bak)
    if mode is not None:
        bgl.glDrawBuffer(mode)

    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture)

    bgl.glColor4d(1.0, 1.0, 1.0, 1.0)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glTexCoord2d(0.0, 0.0)
    bgl.glVertex2i(x, y)
    bgl.glTexCoord2d(1.0, 0.0)
    bgl.glVertex2i(x + w, y)
    bgl.glTexCoord2d(1.0, 1.0)
    bgl.glVertex2i(x + w, y + h)
    bgl.glTexCoord2d(0.0, 1.0)
    bgl.glVertex2i(x, y + h)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    if mode is not None:
        bgl.glDrawBuffer(mode_bak[0])
예제 #21
0
def drawloop(x1, y1, x2, y2):
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex2i(x1, y2)
    bgl.glVertex2i(x2, y2)
    bgl.glVertex2i(x2, y1)
    bgl.glVertex2i(x1, y1)
    bgl.glEnd()
예제 #22
0
def li3D_legend(self, context, simnode, connode, geonode):
    scene = context.scene
    try:
        if scene.vi_leg_display != True or scene.vi_display == 0 or (scene.wr_disp_panel != 1 and scene.li_disp_panel != 2 and scene.ss_disp_panel != 2) or scene.frame_current not in range(scene.fs, scene.fe + 1):
            return
        else:
            if max(simnode['maxres']) > 100:
                resvals = ['{:.0f}'.format(min(simnode['minres'])+i*(max(simnode['maxres'])-min(simnode['minres']))/19) for i in range(20)]
            else:
                resvals = ['{:.1f}'.format(min(simnode['minres'])+i*(max(simnode['maxres'])-min(simnode['minres']))/19) for i in range(20)]
    
            height = context.region.height
            lenres = len(resvals[-1])
            font_id = 0
            vi_func.drawpoly(20, height - 40, 70 + lenres*8, height - 520)
            vi_func.drawloop(19, height - 40, 70 + lenres*8, height - 520)
    
            for i in range(20):
                h = 0.75 - 0.75*(i/19)
                if connode:
                    bgl.glColor4f(colorsys.hsv_to_rgb(h, 1.0, 1.0)[0], colorsys.hsv_to_rgb(h, 1.0, 1.0)[1], colorsys.hsv_to_rgb(h, 1.0, 1.0)[2], 1.0)
                else:
                    bgl.glColor4f(i/19, i/19, i/19, 1)
                bgl.glBegin(bgl.GL_POLYGON)
                bgl.glVertex2i(20, (i*20)+height - 460)
                bgl.glVertex2i(60, (i*20)+height - 460)
                bgl.glVertex2i(60, (i*20)+height - 440)
                bgl.glVertex2i(20, (i*20)+height - 440)
                bgl.glEnd()
                blf.size(font_id, 20, 48)
                bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
                blf.position(font_id, 65, (i*20)+height - 455, 0)
                blf.draw(font_id, "  "*(lenres - len(resvals[i]) ) + resvals[i])    
            blf.size(font_id, 20, 56)
    
            cu = connode['unit'] if connode else '% Sunlit'    
            vi_func.drawfont(cu, font_id, 0, height, 25, 57)
            bgl.glLineWidth(1)
            bgl.glDisable(bgl.GL_BLEND)
            height = context.region.height
            font_id = 0
            if scene.frame_current in range(scene.fs, scene.fe + 1):
                findex = scene.frame_current - scene.frame_start if simnode['Animation'] != 'Static' else 0
                bgl.glColor4f(0.0, 0.0, 0.0, 0.8)
                blf.size(font_id, 20, 48)
                if context.active_object and (context.active_object.get('lires') or context.active_object.get('licalc')):
                    vi_func.drawfont("Ave: {:.1f}".format(context.active_object['oave'][str(scene.frame_current)]), font_id, 0, height, 22, 480)
                    vi_func.drawfont("Max: {:.1f}".format(context.active_object['omax'][str(scene.frame_current)]), font_id, 0, height, 22, 495)
                    vi_func.drawfont("Min: {:.1f}".format(context.active_object['omin'][str(scene.frame_current)]), font_id, 0, height, 22, 510)
                else:
                    vi_func.drawfont("Ave: {:.1f}".format(simnode['avres'][findex]), font_id, 0, height, 22, 480)
                    vi_func.drawfont("Max: {:.1f}".format(simnode['maxres'][findex]), font_id, 0, height, 22, 495)
                    vi_func.drawfont("Min: {:.1f}".format(simnode['minres'][findex]), font_id, 0, height, 22, 510)
    
    except Exception as e:
        print(e, 'Turning off legend display')
        scene.vi_leg_display = 0
        scene.update()
예제 #23
0
def viwr_legend(self, context, simnode):
    scene = context.scene
    if scene.vi_leg_display != True or scene.vi_display == 0:
        return
    else:
        try:
            resvals = [
                '{0:.0f} to {1:.0f}'.format(2 * i, 2 * (i + 1))
                for i in range(simnode['nbins'])
            ]
            resvals[-1] = resvals[
                -1][:-int(len('{:.0f}'.format(simnode['maxres'])))] + u"\u221E"
            height, lenres, font_id = context.region.height, len(
                resvals[-1]), 0
            drawpoly(20, height - 40, 70 + lenres * 8,
                     height - (simnode['nbins'] + 6) * 20)
            drawloop(19, height - 40, 70 + lenres * 8,
                     height - (simnode['nbins'] + 6) * 20)
            cm = matplotlib.cm.jet if simnode.wrtype in (
                '0', '1') else matplotlib.cm.hot
            for i in range(simnode['nbins']):
                bgl.glColor4f(*cm(i * 1 / (simnode['nbins'] - 1), 1))
                bgl.glBegin(bgl.GL_POLYGON)
                bgl.glVertex2i(
                    20, height - 70 - (simnode['nbins'] * 20) + (i * 20))
                bgl.glVertex2i(
                    60, height - 70 - (simnode['nbins'] * 20) + (i * 20))
                bgl.glVertex2i(
                    60, height - 50 - (simnode['nbins'] * 20) + (i * 20))
                bgl.glVertex2i(
                    20, height - 50 - (simnode['nbins'] * 20) + (i * 20))
                bgl.glEnd()
                blf.size(font_id, 20, 48)
                bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
                blf.position(font_id, 65,
                             height - 65 - (simnode['nbins'] * 20) + (i * 20),
                             0)
                blf.draw(font_id,
                         "  " * (lenres - len(resvals[i])) + resvals[i])

            blf.size(font_id, 20, 56)
            cu = 'Speed (m/s)'
            drawfont(cu, font_id, 0, height, 25, 57)
            bgl.glLineWidth(1)
            bgl.glDisable(bgl.GL_BLEND)
            height = context.region.height
            font_id = 0
            bgl.glColor4f(0.0, 0.0, 0.0, 0.8)
            blf.size(font_id, 20, 48)
            drawfont("Ave: {:.1f}".format(simnode['avres']), font_id, 0,
                     height, 22, simnode['nbins'] * 20 + 85)
            drawfont("Max: {:.1f}".format(simnode['maxres']), font_id, 0,
                     height, 22, simnode['nbins'] * 20 + 100)
            drawfont("Min: {:.1f}".format(simnode['minres']), font_id, 0,
                     height, 22, simnode['nbins'] * 20 + 115)
        except:
            scene.vi_display = 0
예제 #24
0
 def draw_border(self):
     self.on_set_foreground()
     bgl.glLineWidth(2)
     bgl.glBegin(bgl.GL_LINE_LOOP)
     bgl.glVertex2i(self.ox, self.oy)
     bgl.glVertex2i(self.ox, self.oy + self.dy)
     bgl.glVertex2i(self.ox + self.dx, self.oy + self.dy)
     bgl.glVertex2i(self.ox + self.dx, self.oy)     
     bgl.glEnd()
예제 #25
0
def outline_region(region, color):

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_SMOOTH)
    bgl.glColor4f(*color)
    lw = 4 // 2
    bgl.glLineWidth(lw * 4)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(lw, lw)
    bgl.glVertex2i(region.width - lw, lw)
    bgl.glVertex2i(region.width - lw, region.height - lw)
    bgl.glVertex2i(lw, region.height - lw)
    bgl.glVertex2i(lw, lw)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_LINE_SMOOTH)
예제 #26
0
def draw_callback_px(self, context):
    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINES)
    if self.started:
        bgl.glVertex2i(self.start_vertex[0], self.start_vertex[1])
        bgl.glVertex2i(self.end_vertex[0], self.end_vertex[1])

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #27
0
def drawpoly(x1, y1, x2, y2):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.8)
    bgl.glBegin(bgl.GL_POLYGON)
    bgl.glVertex2i(x1, y2)
    bgl.glVertex2i(x2, y2)
    bgl.glVertex2i(x2, y1)
    bgl.glVertex2i(x1, y1)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
예제 #28
0
def draw_border(self, context):
    region = context.region

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_SMOOTH)
    bgl.glColor4f(1, 1, 1, 0.75)
    lw = 2
    bgl.glLineWidth(lw)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(lw, lw)
    bgl.glVertex2i(region.width - lw, lw)
    bgl.glVertex2i(region.width - lw, region.height - lw)
    bgl.glVertex2i(lw, region.height - lw)
    bgl.glVertex2i(lw, lw)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_LINE_SMOOTH)
예제 #29
0
def draw_gl_line(context,pts,width,dash,color): #pts matrix_world
    bgl.glLineWidth(width)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(color[0],color[1],color[2],color[3])
    if dash:
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
    # Draw  stuff.
    bgl.glBegin(bgl.GL_LINE_STRIP) 
   
    for pt in pts:
        bgl.glVertex2i(pt[0], pt[1])       
    bgl.glEnd()
    
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    bgl.glDisable(bgl.GL_LINE_STIPPLE)
예제 #30
0
def draw_callback_px(self, context):
    bpy.context.scene.retopo_wire.useRetopoWire = True  #Uses Draw Xray Addon to Render vertices while in edge mode
    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINES)
    if self.started:
        bgl.glVertex2i(self.start_vertex[0], self.start_vertex[1])
        bgl.glVertex2i(self.end_vertex[0], self.end_vertex[1])

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #31
0
def draw_callback_px(self, context):
    """From blender's operator_modal_draw.py modal operator template"""
    if self.do_draw:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        bgl.glLineWidth(1)

        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2i(int(self.draw_start.x), int(self.draw_start.y))
        bgl.glVertex2i(int(self.draw_end.x), int(self.draw_end.y))

        bgl.glEnd()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #32
0
def draw_callback_px(self, context):

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.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(self.startX, y)

    for x, y in self.mouse_path:
        bgl.glVertex2i(x, self.startY)

    bgl.glEnd()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 0.0, 0.0, 1.0)
예제 #33
0
def draw_callback_px(self, context):
    """From blender's operator_modal_draw.py modal operator template"""
    if self.do_draw:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        bgl.glLineWidth(1)

        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2i(int(self.draw_start.x), int(self.draw_start.y))
        bgl.glVertex2i(int(self.draw_end.x), int(self.draw_end.y))

        bgl.glEnd()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #34
0
def li3D_legend(self, context, simnode, connode, geonode):
    scene = context.scene
    fc = str(scene.frame_current)
    try:
        if scene.vi_leg_display != True or scene.vi_display == 0 or (scene.wr_disp_panel != 1 and scene.li_disp_panel != 2 and scene.ss_disp_panel != 2) or scene.frame_current not in range(scene.fs, scene.fe + 1):
            return
        else:
            resvals = [('{:.1f}', '{:.0f}')[scene.vi_leg_max >= 100].format(scene.vi_leg_min+i*(scene.vi_leg_max - scene.vi_leg_min)/19) for i in range(20)]    
            height = context.region.height
            lenres = len(resvals[-1])
            font_id = 0
            drawpoly(20, height - 40, 70 + lenres*8, height - 520)
            drawloop(19, height - 40, 70 + lenres*8, height - 520)
    
            for i in range(20):
                h = 0.75 - 0.75*(i/19)
                if connode:
                    bgl.glColor4f(colorsys.hsv_to_rgb(h, 1.0, 1.0)[0], colorsys.hsv_to_rgb(h, 1.0, 1.0)[1], colorsys.hsv_to_rgb(h, 1.0, 1.0)[2], 1.0)
                else:
                    bgl.glColor4f(i/19, i/19, i/19, 1)
                bgl.glBegin(bgl.GL_POLYGON)
                bgl.glVertex2i(20, (i*20)+height - 460)
                bgl.glVertex2i(60, (i*20)+height - 460)
                bgl.glVertex2i(60, (i*20)+height - 440)
                bgl.glVertex2i(20, (i*20)+height - 440)
                bgl.glEnd()
                blf.size(font_id, 20, 48)
                bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
                blf.position(font_id, 65, (i*20)+height - 455, 0)
                blf.draw(font_id, "  "*(lenres - len(resvals[i]) ) + resvals[i])    
            blf.size(font_id, 20, 56) 
#            print(connode)
#            cu = connode['unit'] if connode else '% Sunlit'    
            drawfont(scene['liparams']['unit'], font_id, 0, height, 25, 57)
            bgl.glLineWidth(1)
            bgl.glDisable(bgl.GL_BLEND)
            height = context.region.height
            font_id = 0
            bgl.glColor4f(0.0, 0.0, 0.0, 0.8)
            blf.size(font_id, 20, 48)
            if context.active_object and context.active_object.get('lires'):
                drawfont("Ave: {:.1f}".format(context.active_object['oave'][fc]), font_id, 0, height, 22, 480)
                drawfont("Max: {:.1f}".format(context.active_object['omax'][fc]), font_id, 0, height, 22, 495)
                drawfont("Min: {:.1f}".format(context.active_object['omin'][fc]), font_id, 0, height, 22, 510)
            else:
                drawfont("Ave: {:.1f}".format(simnode['avres'][fc]), font_id, 0, height, 22, 480)
                drawfont("Max: {:.1f}".format(simnode['maxres'][fc]), font_id, 0, height, 22, 495)
                drawfont("Min: {:.1f}".format(simnode['minres'][fc]), font_id, 0, height, 22, 510)
    
    except Exception as e:
        print(e, 'Turning off legend display')
        scene.vi_leg_display = 0
        scene.update()
예제 #35
0
def draw_rect_px(self, context):
    if len(self.strokes) < 2:
        return
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)
    bgl.glColor4f(0.75, 0.75, 0.75, 1.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    sx, sy = self.strokes[0]["mouse"]
    ex, ey = self.strokes[-1]["mouse"]
    bgl.glVertex2i(int(sx), int(sy))
    bgl.glVertex2i(int(sx), int(ey))
    bgl.glVertex2i(int(ex), int(ey))
    bgl.glVertex2i(int(ex), int(sy))
    bgl.glVertex2i(int(sx), int(sy))
    bgl.glEnd()
    #  restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #36
0
def draw_pen_px(self, context):
    if len(self.strokes) < 1:
        return
    bgl.glEnable(bgl.GL_BLEND)
    width = context.scene.quicker_props.bevel_depth
    tool_setting = context.scene.tool_settings
    rad = 5 * tool_setting.curve_paint_settings.radius_max * width * 10
    pre = [stroke for stroke in self.strokes]
    a = []
    a.append(self.strokes[0])
    a.extend(pre)
    pre = a
    bgl.glLineWidth(1)
    bgl.glColor4f(0.75, 0.75, 0.75, 1.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for n, stroke in enumerate(self.strokes):  # Size line
        x, y = stroke["mouse"]
        pres = stroke["pressure"]
        p = pre[n]
        px, py = p["mouse"]
        ang = math.atan2(y - py, x - px)
        pos = ang + PI_H
        x = x + math.cos(pos) * rad * pres
        y = y + math.sin(pos) * rad * pres
        bgl.glVertex2i(int(x), int(y))
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for n, stroke in enumerate(self.strokes):  # Size line
        x, y = stroke["mouse"]
        pres = stroke["pressure"]
        p = pre[n]
        px, py = p["mouse"]
        ang = math.atan2(y - py, x - px)
        neg = ang - PI_H
        x = x + math.cos(neg) * rad * pres
        y = y + math.sin(neg) * rad * pres
        bgl.glVertex2i(int(x), int(y))
    bgl.glEnd()
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #37
0
def draw_callback_axis(self, context):

    # X AXIS
    bgl.glEnable(bgl.GL_BLEND)
    if self.snap_axis_x:
        bgl.glColor4f(1.0, 0.0, 0.0, 0.7)
        bgl.glLineWidth(1)
    elif self.middlemouse:
        bgl.glColor4f(1.0, 0.0, 0.0, 0.3)
        bgl.glLineWidth(1)
    else:
        bgl.glColor4f(0.0, 0.0, 0.0, 0.0)
        bgl.glLineWidth(0)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x in range(context.area.width):
        bgl.glVertex2i(x, self.init_pos_y)
    bgl.glEnd()

    # Y AXIS
    bgl.glEnable(bgl.GL_BLEND)
    if self.snap_axis_y:
        bgl.glColor4f(0.0, 1.0, 0.0, 0.7)
        bgl.glLineWidth(1)
    elif self.middlemouse:
        bgl.glColor4f(0.0, 1.0, 0.0, 0.3)
        bgl.glLineWidth(1)
    else:
        bgl.glColor4f(0.0, 0.0, 0.0, 0.0)
        bgl.glLineWidth(0)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for y in range(context.area.height):
        bgl.glVertex2i(self.init_pos_x, y)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #38
0
    def draw_lines(self, args):
        self, context = args

        # draw confirmed lines
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glLineWidth(self.thickness)

        bgl.glColor4f(*colorcodes[self.color], self.alpha)
        bgl.glBegin(bgl.GL_LINE_STRIP)

        for x, y in self.mouse_coords:
            bgl.glVertex2i(int(x), int(y))
        bgl.glEnd()

        # draw preview line
        if self.mouse_coords:
            # see https://blender.stackexchange.com/a/21526/33919
            bgl.glPushAttrib(bgl.GL_ENABLE_BIT)

            bgl.glLineStipple(1, 0x9999)
            bgl.glEnable(bgl.GL_LINE_STIPPLE)

            # 50% alpha, 2 pixel width line
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glColor4f(*colorcodes[self.color], 0.4)
            bgl.glLineWidth(self.thickness)

            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in [
                    self.mouse_coords[-1],
                    mathutils.Vector((self.mouse_x, self.mouse_y))
            ]:
                bgl.glVertex2i(int(x), int(y))

            bgl.glEnd()
            bgl.glPopAttrib()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #39
0
def defilento(self):

    pat = self._pattern

    pat_one = pat << 1
    pat = pat >> 15
    pat |= pat_one & 0xFFFF

    self._pattern = pat

    bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glLineStipple(55, self._pattern)

    width = abs(math.sin(time.time()) * 11.0)
    bgl.glLineWidth(width)

       # 2D drawing code example
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(0, 0)
    bgl.glVertex2i(80, 100)
    bgl.glEnd()
예제 #40
0
def draw_callback_px(self, context):
    """Modally called function that draws the lines as they are streamed.
    Firstly updates the viewport's text.
    Then draws the line based on points in self.point_path.
    """
    print("data points", len(self.point_path))

    # get region so can draw intermediate lines
    region = context.region
    rv3d = context.space_data.region_3d


    draw_text_on_viewport("{} vertices added, timestamp {}"
                          .format(str(len(self.point_path)), str(self.latest_ts)))
    # set the line parameters
    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)

    # draw the line here.....
    bgl.glBegin(bgl.GL_LINE_STRIP)
    # start from the origin for visual purposes
    for i in [0]:
        vertex = loc3d2d(region, rv3d, (i, i, i))
        print('vertex is', vertex)
        bgl.glVertex2f(vertex[0], vertex[1])

    for i, loc3d in enumerate(self.point_path):
        loc2d = loc3d2d(region, rv3d, loc3d)
        print(loc2d[0], loc2d[1], 'is the viewport coordinates')
        bgl.glVertex2i(math.floor(loc2d[0]), math.floor(loc2d[1]))
        #bgl.glVertex2i(math.floor(loc2d[0]%10), math.floor(loc2d[1]%10))

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #41
0
def sync_draw_callback(self, context):
    # polling
    if context.mode != "EDIT_MESH":
        return

    # draw vertices
    bgl.glColor4f(1.0, 0.0, 0.0, 1.0)
    bgl.glPointSize(4)
    bgl.glBegin(bgl.GL_POINTS)
    for x, y in self.position_vertices:
        bgl.glVertex2i(x, y)
    bgl.glEnd()

    # draw edges
    bgl.glColor4f(1.0, 0.0, 0.0, 1.0)
    bgl.glLineWidth(1.5)
    bgl.glBegin(bgl.GL_LINES)
    for x, y in self.position_edges:
        bgl.glVertex2i(x, y)
    bgl.glEnd()
    bgl.glLineWidth(1)

    # draw faces
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 0.0, 0.0, 0.3)
    bgl.glBegin(bgl.GL_QUADS)
    for x, y in self.position_faces:
        bgl.glVertex2i(x, y)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
예제 #42
0
def draw_callback_px(self, context):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)

    if context.scene.curve_freehand.use_pressure:
        from mathutils import noise
        pt_a = self.mouse_path[0]
        for i in range(1, len(self.mouse_path)):
            # weak but good enough for preview
            pt_b = self.mouse_path[i]
            bgl.glPointSize(1 + (pt_a[2] * 40.0))
            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex2i(pt_a[0], pt_a[1])
            bgl.glVertex2i(pt_b[0], pt_b[1])
            bgl.glEnd()
            pt_a = pt_b
    else:
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for pt in self.mouse_path:
            bgl.glVertex2i(pt[0], pt[1])
        bgl.glEnd()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #43
0
def draw_callback(self, context):
    r, g, b = context.tool_settings.image_paint.brush.cursor_color_add
    #x0, y0, x1, y1 = context.window_manager["straight_line"]
    start = self.stroke[0]
    end = self.stroke[-1]

    x0 = start["mouse"][0]
    y0 = start["mouse"][1]

    x1 = end["mouse"][0]
    y1 = end["mouse"][1]

    # draw straight line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(r, g, b, 1.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(x0, y0)
    bgl.glVertex2i(x1, y1)
    bgl.glEnd()
    # restore opengl defaults
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #44
0
    def draw_callback_abc(self, context):
        font_id = 0

        scene = context.scene
        region = context.region
        rv3d = context.region_data

        obj_matrix_world = self.obj.matrix_world

        a_3d = obj_matrix_world * self.obj.data.vertices[self.snap_points[self.index].a].co
        b_3d = obj_matrix_world * self.obj.data.vertices[self.snap_points[self.index].b].co
        c_3d = obj_matrix_world * self.obj.data.vertices[self.snap_points[self.index].c].co
        
        a_2d = tuple(map(ceil, view3d_utils.location_3d_to_region_2d(region, rv3d, a_3d)))
        b_2d = tuple(map(ceil, view3d_utils.location_3d_to_region_2d(region, rv3d, b_3d)))
        c_2d = tuple(map(ceil, view3d_utils.location_3d_to_region_2d(region, rv3d, c_3d)))

        bgl.glColor3f(0.0, 0.0, 0.0)
        bgl.glPointSize(8)
        bgl.glBegin(bgl.GL_POINTS)
        for x, y in (a_2d, b_2d, c_2d):
            bgl.glVertex2i(x, y)
        bgl.glEnd()

        bgl.glPointSize(4)
        bgl.glColor3f(0.9, 0.1, 0.1)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex2i(a_2d[0], a_2d[1])
        bgl.glEnd()

        bgl.glColor3f(0.1, 0.9, 0.1)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex2i(b_2d[0], b_2d[1])
        bgl.glEnd()

        bgl.glColor3f(0.3, 0.3, 0.9)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex2i(c_2d[0], c_2d[1])
        bgl.glEnd()

        # restore opengl defaults
        bgl.glPointSize(1)
        bgl.glLineWidth(1)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #45
0
def rect_round_corners(x1,y1, x2,y2):
    k = 2 # length of edge ~ border-radius

    bgl.glBegin(bgl.GL_LINE_STRIP)

    bgl.glVertex2i(x1, y1 + k)
    bgl.glVertex2i(x1, y2 - k)
    bgl.glVertex2i(x1 + k, y2)
    bgl.glVertex2i(x2 - k, y2)
    bgl.glVertex2i(x2, y2 - k)
    bgl.glVertex2i(x2, y1 + k)
    bgl.glVertex2i(x2 - k, y1)
    bgl.glVertex2i(x1 + k, y1)
    bgl.glVertex2i(x1, y1 + k)

    bgl.glEnd()
예제 #46
0
def rad_3D_legend(self, context):
    scene = bpy.context.scene
    if bpy.context.scene['metric'] == 2:
        lenres = int(math.floor(math.log10(max(scene['resmax']))) + 2)
    else:
        lenres = int(math.floor(math.log10(max(scene['resmax']))) + 2)
    font_id = 0  
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    bgl.glLineWidth(2)
    bgl.glBegin(bgl.GL_POLYGON)                  
    bgl.glVertex2i(20, 20)
    bgl.glVertex2i(70 + lenres*7, 20)
    bgl.glVertex2i(70 + lenres*7, 440)
    bgl.glVertex2i(20, 440)
    bgl.glEnd()
    
    for i in range(20):
        h = 0.75 - 0.75*(i/19)
        bgl.glColor4f(colorsys.hsv_to_rgb(h, 1.0, 1.0)[0], colorsys.hsv_to_rgb(h, 1.0, 1.0)[1], colorsys.hsv_to_rgb(h, 1.0, 1.0)[2], 1.0)
        bgl.glBegin(bgl.GL_POLYGON)                  
        bgl.glVertex2i(20, (i*20)+20)
        bgl.glVertex2i(60, (i*20)+20)
        bgl.glVertex2i(60, (i*20)+40)
        bgl.glVertex2i(20, (i*20)+40)
        bgl.glEnd()
        if bpy.context.scene['metric'] == 2:
            singlelenres = int(math.log10(math.floor(min(scene['resmin'])+i*(max(scene['resmax'])-min(scene['resmin']))/19)+1))
        else:
            singlelenres = int(math.log10(math.floor(min(scene['resmin'])+i*(max(scene['resmax'])-min(scene['resmin']))/19)+1))
        blf.position(font_id, 60, (i*20)+25, 0)
        blf.size(font_id, 20, 48)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        if bpy.context.scene['metric'] == 2:
            blf.draw(font_id, "  "*(lenres - singlelenres - 2) + str(round(min(scene['resmin'])+i*(max(scene['resmax'])-min(scene['resmin']))/19, 1)+1))
        else:
            blf.draw(font_id, "  "*(lenres - singlelenres - 1) + str(int(min(scene['resmin'])+i*(max(scene['resmax'])-min(scene['resmin']))/19)+1))        
        
    blf.position(font_id, 25, 425, 0)
    blf.size(font_id, 20, 56)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    blf.draw(font_id, scene['unit'])
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)   
예제 #47
0
def draw_edit_mode(self,context,color=[0.41, 0.38, 1.0, 1.0],text="Edit Shapekey Mode",offset=0):
    region = context.region
    x = region.width
    y = region.height
    
    scale = x / 1200
    scale = clamp(scale,.5,1.5)
    
    r_offset = 0
    if context.user_preferences.system.use_region_overlap:
        r_offset = context.area.regions[1].width

    ### draw box behind text
    b_width = int(240*scale)
    b_height = int(36*scale)
    
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(color[0],color[1],color[2],color[3])
    
    bgl.glBegin(bgl.GL_QUADS)
    bgl.glVertex2i(x-b_width, 0)
    bgl.glVertex2i(x, 0)
    bgl.glVertex2i(x, b_height)
    bgl.glVertex2i(x-b_width, b_height)
    bgl.glVertex2i(x-b_width, 0) 
    bgl.glEnd()
    
    ### draw edit type
    font_id = 0  # XXX, need to find out how best to get this.
    bgl.glColor4f(0.041613, 0.041613, 0.041613, 1.000000)
    text_offset = int((220+offset)*scale)
    text_y_offset = int(11 * scale)
    blf.position(font_id, x-text_offset, text_y_offset, 0)
    blf.size(font_id, 20, int(72*scale))
    blf.draw(font_id, text)
    
    ### draw viewport outline
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(color[0],color[1],color[2],color[3])
    bgl.glLineWidth(4)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(r_offset, 0)
    bgl.glVertex2i(r_offset+x, 0)
    bgl.glVertex2i(r_offset+x, y)
    bgl.glVertex2i(r_offset+0, y)
    bgl.glVertex2i(r_offset, 0)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #48
0
def drawZoomBox(self, context):

	bgl.glEnable(bgl.GL_BLEND)
	bgl.glColor4f(0, 0, 0, 0.5)
	bgl.glLineWidth(2)

	if self.zoomBoxMode and not self.zoomBoxDrag:
		# before selection starts draw infinite cross
		bgl.glBegin(bgl.GL_LINES)

		px, py = self.zb_xmax, self.zb_ymax

		bgl.glVertex2i(0, py)
		bgl.glVertex2i(context.area.width, py)

		bgl.glVertex2i(px, 0)
		bgl.glVertex2i(px, context.area.height)

		bgl.glEnd()

	elif self.zoomBoxMode and self.zoomBoxDrag:
		# when selecting draw dashed line box
		bgl.glEnable(bgl.GL_LINE_STIPPLE)
		bgl.glLineStipple(2, 0x3333)
		bgl.glBegin(bgl.GL_LINE_LOOP)

		bgl.glVertex2i(self.zb_xmin, self.zb_ymin)
		bgl.glVertex2i(self.zb_xmin, self.zb_ymax)
		bgl.glVertex2i(self.zb_xmax, self.zb_ymax)
		bgl.glVertex2i(self.zb_xmax, self.zb_ymin)

		bgl.glEnd()

		bgl.glDisable(bgl.GL_LINE_STIPPLE)


	# restore opengl defaults
	bgl.glLineWidth(1)
	bgl.glDisable(bgl.GL_BLEND)
	bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #49
0
def draw_UI(self, context):
    # creates all lines and appends them to a list, then draws these to the UI
    font_id = 0
    lines = []
    
    if self.switch:
        blf.position(font_id, self.initial_mouse_region[0]+5, self.current_mouse_region[1]+8, 0)
        blf.size(font_id, 20, 38)
        blf.draw(font_id, str(round(self.offset, 3)))
        
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(1.0, 1.0, 1.0, 0.2)
        bgl.glLineWidth(2)
        
        length = 0
        while length < abs(self.current_mouse_region[0] - self.initial_mouse_region[0])-10:
            
            if self.current_mouse_region[0] - self.initial_mouse_region[0] >= 0:
                lines.append([(self.initial_mouse_region[0]+length+4, self.current_mouse_region[1]),
                              (self.initial_mouse_region[0]+length+10, self.current_mouse_region[1])])
                
            else:
                lines.append([(self.initial_mouse_region[0]-length-4, self.current_mouse_region[1]),
                              (self.initial_mouse_region[0]-length-10, self.current_mouse_region[1])])
            length +=10
            
        lines.append([(self.initial_mouse_region[0]+1, self.current_mouse_region[1]+15),
                  (self.initial_mouse_region[0]+1, self.current_mouse_region[1]-8)])
        
    else:
        blf.position(font_id, self.current_mouse_region[0]+5, self.initial_mouse_region[1]+8, 0)
        blf.size(font_id, 20, 38)
        blf.draw(font_id, str(round(self.displace, 3)))
        
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(1.0, 1.0, 1.0, 0.2)
        bgl.glLineWidth(2)
        
        length = 0
        while length < abs(self.current_mouse_region[1] - self.initial_mouse_region[1])-10:
            
            if self.current_mouse_region[1] - self.initial_mouse_region[1] >= 0:
                lines.append([(self.current_mouse_region[0], self.initial_mouse_region[1]+length+4),
                              (self.current_mouse_region[0], self.initial_mouse_region[1]+length+10)])
                
            else:
                lines.append([(self.current_mouse_region[0], self.initial_mouse_region[1]-length-4),
                              (self.current_mouse_region[0], self.initial_mouse_region[1]-length-10)])
            length +=10
        
        lines.append([(self.current_mouse_region[0]+15, self.initial_mouse_region[1]+1),
                  (self.current_mouse_region[0]-8, self.initial_mouse_region[1]+1)])
    
    
    # draw lines
    for i in lines:
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x, y in i:
            bgl.glVertex2i(x, y)
        bgl.glEnd()
 
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #50
0
    def draw_callback(self, context):
        
        if context.mode not in ['OBJECT', 'POSE']:
            return
        
        area = MotionPath.get_area(context, 'VIEW_3D')
        
        if not self._is_2d or not area:
            return
        
        LINE_WIDTH = 1
        POINT_SIZE = 1
        STAR_SIZE = 10
        CROSS_SIZE = 7.07106781186547
                
        # draw line
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor3f(self.props.color.r, self.props.color.g, self.props.color.b)
        bgl.glLineWidth(LINE_WIDTH)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for sample in self._samples:
            if sample._proj is not None:
                bgl.glVertex2i(int(sample._proj.x), int(sample._proj.y))
        bgl.glEnd()
        
        feature_count = 1
        
        # draw points
        bgl.glPointSize(POINT_SIZE)
        for sample in self._samples:
            
            if sample._proj is None:
                continue
            
            x = sample._proj.x
            y = sample._proj.y
            
#            if self._features_type_color:
#                if sample._flag == 'MINMAX_X':
#                    bgl.glColor3f(0, 1, 0)
#                elif sample._flag == 'MINMAX_Y':
#                    bgl.glColor3f(1, 1, 0)
#                elif sample._flag == 'MINMAX_XY':
#                    bgl.glColor3f(1, 0, 0)
#                elif sample._flag == 'CLEANED':
#                    bgl.glColor3f(0, 0, 1)
#                elif sample._flag in {'START', 'END'}:
#                    bgl.glColor3f(1, 0, 1)
            
            if sample._flag in {'MINMAX_X', 'MINMAX_Y', 'MINMAX_XY', 'START', 'END'}:
                # shape
                if self.props.features_shape == 'star':
                    bgl.glBegin(bgl.GL_LINES)
                    bgl.glVertex2i(int(x - STAR_SIZE), int(y))
                    bgl.glVertex2i(int(x + STAR_SIZE + 1), int(y))
                    bgl.glVertex2i(int(x), int(y - STAR_SIZE))
                    bgl.glVertex2i(int(x), int(y + STAR_SIZE + 1))
                    bgl.glEnd()
                    
                    blf.position(0, int(x) + 15, int(y) - 5, 0)
                    blf.size(0, 14, 72)
                    blf.draw(0, str(feature_count))
                    
                elif self.props.features_shape == 'cross':
                    bgl.glBegin(bgl.GL_LINES)
                    bgl.glVertex2i(int(x - CROSS_SIZE), int(y - CROSS_SIZE))
                    bgl.glVertex2i(int(x + CROSS_SIZE + 1), int(y + CROSS_SIZE + 1))
                    bgl.glVertex2i(int(x - CROSS_SIZE), int(y + CROSS_SIZE))
                    bgl.glVertex2i(int(x + CROSS_SIZE + 1), int(y - CROSS_SIZE - 1))
                    bgl.glEnd()
                    
                    blf.position(0, int(x) + 15, int(y) - 5, 0)
                    blf.size(0, 14, 72)
                    blf.draw(0, str(feature_count))
                
                feature_count += 1
                
            else:
                # point
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glVertex2i(int(x), int(y))
                bgl.glEnd()
        
        area.tag_redraw()
예제 #51
0
def draw_callback(x_offset, y_offset, slider_width, slider_height):
    ''' draw sliders on the screen conditionally '''
    context = bpy.context
    area = context.area
    region = context.region
    rv3d = context.space_data.region_3d
    anim_color =\
        context.user_preferences.themes[0].user_interface.wcol_state.inner_anim
    key_color =\
        context.user_preferences.themes[0].user_interface.wcol_state.inner_key
    if area.type == 'VIEW_3D':
        if context.mode == 'POSE' and context.active_pose_bone:

            x0, y0, x_start, x_end, y_start, y_min, y_max, bone, items =\
                locator(
                    context, x_offset, y_offset, slider_width, slider_height)
            bgl.glEnable(bgl.GL_BLEND)

            font_id = 0  # XXX, need to find out how best to get this.           

            for index, prop in enumerate(items):
                animated, keyframed = is_animated(context, prop)
                prop_min = bone["_RNA_UI"][prop]["min"]
                prop_max = bone["_RNA_UI"][prop]["max"]
                offset = index * 40
                
                
                bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
                # draw some text
                blf.position(font_id, x_end + 10, y_start - offset, 0)
                blf.size(font_id, 12, 72)
                if animated:
                    color = key_color if keyframed else anim_color
                    bgl.glColor4f(color[0], color[1], color[2], 0.9)
                blf.draw(font_id, '{} {:.3f}'.format(prop,bone[prop]))

                bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
                bgl.glLineWidth(1)
                
                bgl.glBegin(bgl.GL_LINE_STRIP)
                bgl.glVertex2i(x_start, y_start - offset )
                bgl.glVertex2i(x_end, y_start - offset)
                bgl.glEnd()
                
                bgl.glLineWidth(2)

                bgl.glBegin(bgl.GL_LINE_STRIP)
                bgl.glVertex2i(x_start, y_min - offset)
                bgl.glVertex2i(x_start, y_max - offset)
                bgl.glEnd()

                bgl.glBegin(bgl.GL_LINE_STRIP)
                bgl.glVertex2i(x_end, y_min - offset)
                bgl.glVertex2i(x_end, y_max - offset)
                bgl.glEnd()
                
                bgl.glColor4f(1.0, 0.0, 0.0, 0.8)
                bgl.glLineWidth(3)
                
                bgl.glBegin(bgl.GL_LINE_STRIP)
                percent = (bone[prop] - prop_min) / (prop_max - prop_min)
                value = x_start + int(percent * slider_width)
                bgl.glVertex2i(value - 2, y_start - 2 - offset)
                bgl.glVertex2i(value + 2, y_start - 2 - offset)
                bgl.glVertex2i(value + 2, y_start + 2 - offset)
                bgl.glVertex2i(value - 2, y_start + 2 - offset)       
                bgl.glEnd()
            # restore opengl defaults
            bgl.glLineWidth(1)
            bgl.glDisable(bgl.GL_BLEND)
            bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    def drawPoint(x, y, main=True):
        r = 6 if main else 3

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor3f(1.0, 1.0, 1.0)
        bgl.glVertex2i(x - r, y)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x, y + r)

        bgl.glVertex2i(x + r, y)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x, y - r)

        bgl.glColor3f(0.0, 0.0, 0.0)
        bgl.glVertex2i(x, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y)

        bgl.glVertex2i(x, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y)
        bgl.glEnd()
예제 #53
0
파일: poses.py 프로젝트: Amudtogal/phobos
def draw_preview_callback(self):
    """TODO Missing documentation"""

    # Search for View_3d window
    area = None
    if bpy.context.area.type != 'VIEW_3D':
        return bpy.context.area
    else:
        for oWindow in bpy.context.window_manager.windows:
            oScreen = oWindow.screen
            for oArea in oScreen.areas:
                if oArea.type == 'VIEW_3D':
                    area = oArea

    modelsPosesColl = bUtils.getPhobosPreferences().models_poses
    activeModelPoseIndex = bpy.context.scene.active_ModelPose

    if (len(modelsPosesColl) > 0) and area:

        # Draw a textured quad
        area_widths = [
            region.width for region in bpy.context.area.regions if region.type == 'WINDOW'
        ]
        area_heights = [
            region.height for region in bpy.context.area.regions if region.type == 'WINDOW'
        ]
        if (len(area_widths) > 0) and (len(area_heights) > 0):

            active_preview = modelsPosesColl[bpy.data.images[activeModelPoseIndex].name]
            im = bpy.data.images[activeModelPoseIndex]

            view_width = area_widths[0]
            view_height = area_heights[0]
            tex_start_x = 50
            tex_end_x = view_width - 50
            tex_start_y = 50
            tex_end_y = view_height - 50
            if im.size[0] < view_width:
                diff = int((view_width - im.size[0]) / 2)
                tex_start_x = diff
                tex_end_x = diff + im.size[0]
            if im.size[1] < view_height:
                diff = int((view_height - im.size[1]) / 2)
                tex_start_y = diff
                tex_end_y = diff + im.size[1]

            # Draw information
            font_id = 0  # XXX, need to find out how best to get this.
            blf.position(font_id, tex_start_x, tex_end_y + 20, 0)
            blf.size(font_id, 20, 72)
            blf.draw(font_id, active_preview.label)

            tex = im.bindcode
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            # if using blender 2.77 change tex to tex[0]
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex)

            # Background
            bgl.glEnable(bgl.GL_BLEND)

            bgl.glBegin(bgl.GL_QUADS)
            bgl.glColor4f(0, 0, 0, 0.3)
            bgl.glVertex2i(0, 0)
            bgl.glVertex2i(0, view_height)
            bgl.glVertex2i(view_width, view_height)
            bgl.glVertex2i(view_width, 0)

            # Draw Image
            bgl.glColor4f(1, 1, 1, 1)
            bgl.glTexCoord2f(0, 0)
            bgl.glVertex2i(int(tex_start_x), int(tex_start_y))
            bgl.glTexCoord2f(0, 1)
            bgl.glVertex2i(int(tex_start_x), int(tex_end_y))
            bgl.glTexCoord2f(1, 1)
            bgl.glVertex2i(int(tex_end_x), int(tex_end_y))
            bgl.glTexCoord2f(1, 0)
            bgl.glVertex2i(int(tex_end_x), int(tex_start_y))
            bgl.glEnd()

            # restore opengl defaults
            bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
            bgl.glDisable(bgl.GL_QUADS)
            bgl.glDisable(bgl.GL_BLEND)
            bgl.glDisable(bgl.GL_TEXTURE_2D)
예제 #54
0
def draw_callback_px(self, context):
    """Draws Code Editors Minimap and indentation marks"""

    def draw_line(origin, length, thickness, vertical=False):
        """Drawing lines with polys, its faster"""
        x = (origin[0] + thickness) if vertical else (origin[0] + length)
        y = (origin[1] + length) if vertical else (origin[1] + thickness)
        bgl.glBegin(bgl.GL_QUADS)
        for v1, v2 in [origin, (x, origin[1]), (x, y), (origin[0], y)]:
            bgl.glVertex2i(v1, v2)
        bgl.glEnd()
        return

    # abort if another text editor
    if self.area == context.area and self.window == context.window:
        bgl.glEnable(bgl.GL_BLEND)
    else:
        return

    start = time.clock()

    # init params
    font_id = 0
    self.width = next(region.width for region in context.area.regions if region.type == "WINDOW")
    self.height = next(region.height for region in context.area.regions if region.type == "WINDOW")
    dpi_r = context.user_preferences.system.dpi / 72.0
    self.left_edge = self.width - round(dpi_r * (self.width + 5 * self.minimap_width) / 10.0)
    self.right_edge = self.width - round(dpi_r * 15)
    self.opacity = min(max(0, (self.width - self.min_width) / 100.0), 1)

    # compute character dimensions
    mcw = dpi_r * self.minimap_symbol_width  # minimap char width
    mlh = round(dpi_r * self.minimap_line_height)  # minimap line height
    fs = context.space_data.font_size
    cw = round(dpi_r * round(2 + 0.6 * (fs - 4)))  # char width
    ch = round(dpi_r * round(2 + 1.3 * (fs - 2) + ((fs % 10) == 0)))  # char height

    # panel background box
    self.tab_width = round(dpi_r * 25) if (self.tabs and len(bpy.data.texts) > 1) else 0
    bgl.glColor4f(self.background.r, self.background.g, self.background.b, (1 - self.bg_opacity) * self.opacity)
    bgl.glBegin(bgl.GL_QUADS)
    for x, y in [
        (self.left_edge - self.tab_width, self.height),
        (self.right_edge, self.height),
        (self.right_edge, 0),
        (self.left_edge - self.tab_width, 0),
    ]:
        bgl.glVertex2i(x, y)
    bgl.glEnd()

    # line numbers background
    space = context.space_data
    if space.text:
        lines = len(space.text.lines)
        lines_digits = len(str(lines)) if space.show_line_numbers else 0
        self.line_bar_width = int(dpi_r * 5) + cw * (lines_digits)
        bgl.glColor4f(self.background.r, self.background.g, self.background.b, 1)
        bgl.glBegin(bgl.GL_QUADS)
        for x, y in [(0, self.height), (self.line_bar_width, self.height), (self.line_bar_width, 0), (0, 0)]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()
        # shadow
        bgl.glLineWidth(1.0 * dpi_r)
        for id, intensity in enumerate([0.2, 0.1, 0.07, 0.05, 0.03, 0.02, 0.01]):
            bgl.glColor4f(0.0, 0.0, 0.0, intensity)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in [(self.line_bar_width + id, 0), (self.line_bar_width + id, self.height)]:
                bgl.glVertex2i(x, y)
            bgl.glEnd()

    # minimap shadow
    for id, intensity in enumerate([0.2, 0.1, 0.07, 0.05, 0.03, 0.02, 0.01]):
        bgl.glColor4f(0.0, 0.0, 0.0, intensity * self.opacity)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x, y in [(self.left_edge - id - self.tab_width, 0), (self.left_edge - id - self.tab_width, self.height)]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()

    # divider
    if self.tab_width:
        bgl.glColor4f(0.0, 0.0, 0.0, 0.2 * self.opacity)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x, y in [(self.left_edge, 0), (self.left_edge, self.height)]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()

    # if there is text in window
    if space.text and self.opacity:

        # minimap horizontal sliding based on text block length
        max_slide = max(0, mlh * (lines + self.height / ch) - self.height)
        self.slide = int(max_slide * space.top / lines)
        minimap_top_line = int(self.slide / mlh)
        minimap_bot_line = int((self.height + self.slide) / mlh)

        # draw minimap visible box
        if self.in_minimap:
            bgl.glColor4f(1.0, 1.0, 1.0, 0.1 * self.opacity)
        else:
            bgl.glColor4f(1.0, 1.0, 1.0, 0.07 * self.opacity)
        bgl.glBegin(bgl.GL_QUADS)
        for x, y in [
            (self.left_edge, self.height - mlh * space.top + self.slide),
            (self.right_edge, self.height - mlh * space.top + self.slide),
            (self.right_edge, self.height - mlh * (space.top + space.visible_lines) + self.slide),
            (self.left_edge, self.height - mlh * (space.top + space.visible_lines) + self.slide),
        ]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()

        # draw minimap code
        for segment in self.segments[:-1]:
            bgl.glColor4f(segment["col"][0], segment["col"][1], segment["col"][2], 0.4 * self.opacity)
            for id, element in enumerate(segment["elements"][minimap_top_line:minimap_bot_line]):
                loc_y = mlh * (id + minimap_top_line + 3) - self.slide
                for sub_element in element:
                    draw_line(
                        (self.left_edge + int(mcw * (sub_element[0] + 4)), self.height - loc_y),
                        int(mcw * (sub_element[1] - sub_element[0])),
                        int(0.5 * mlh),
                    )

        # minimap code marks
        bgl.glColor4f(
            self.segments[-2]["col"][0],
            self.segments[-2]["col"][1],
            self.segments[-2]["col"][2],
            0.3 * self.block_trans * self.opacity,
        )
        for id, element in enumerate(self.segments[-2]["elements"]):
            for sub_element in element:
                if sub_element[2] >= space.top or id < space.top + space.visible_lines:
                    draw_line(
                        (self.left_edge + int(mcw * (sub_element[0] + 4)), self.height - mlh * (id + 3) + self.slide),
                        -int(mlh * (sub_element[2] - id - 1)),
                        int(0.5 * mlh),
                        True,
                    )

    # draw dotted indentation marks
    bgl.glLineWidth(1.0 * dpi_r)
    if space.text:
        bgl.glColor4f(
            self.segments[0]["col"][0], self.segments[0]["col"][1], self.segments[0]["col"][2], self.indent_trans
        )
        for id, element in enumerate(self.segments[-1]["elements"][space.top : space.top + space.visible_lines]):
            loc_y = id
            for sub_element in element:
                draw_line(
                    (int(dpi_r * 10) + cw * (lines_digits + sub_element[0] + 4), self.height - ch * (loc_y)),
                    -ch,
                    int(1 * dpi_r),
                    True,
                )

        # draw code block marks
        bgl.glColor4f(
            self.segments[-2]["col"][0], self.segments[-2]["col"][1], self.segments[-2]["col"][2], self.block_trans
        )
        for id, element in enumerate(self.segments[-2]["elements"]):
            for sub_element in element:
                if sub_element[2] >= space.top or id < space.top + space.visible_lines:
                    bgl.glBegin(bgl.GL_LINE_STRIP)
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0])), self.height - ch * (id + 1 - space.top)
                    )
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0])),
                        self.height - int(ch * (sub_element[2] - space.top)),
                    )
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0] + 1)),
                        self.height - int(ch * (sub_element[2] - space.top)),
                    )
                    bgl.glEnd()

    # tab dividers
    if self.tab_width and self.opacity:
        self.tab_height = min(200, int(self.height / len(bpy.data.texts)))
        y_loc = self.height - 5
        for text in bpy.data.texts:
            # tab selection
            if text.name == self.in_tab:
                bgl.glColor4f(1.0, 1.0, 1.0, 0.05 * self.opacity)
                bgl.glBegin(bgl.GL_QUADS)
                for x, y in [
                    (self.left_edge - self.tab_width, y_loc),
                    (self.left_edge, y_loc),
                    (self.left_edge, y_loc - self.tab_height),
                    (self.left_edge - self.tab_width, y_loc - self.tab_height),
                ]:
                    bgl.glVertex2i(x, y)
                bgl.glEnd()
            # tab active
            if context.space_data.text and text.name == context.space_data.text.name:
                bgl.glColor4f(1.0, 1.0, 1.0, 0.05 * self.opacity)
                bgl.glBegin(bgl.GL_QUADS)
                for x, y in [
                    (self.left_edge - self.tab_width, y_loc),
                    (self.left_edge, y_loc),
                    (self.left_edge, y_loc - self.tab_height),
                    (self.left_edge - self.tab_width, y_loc - self.tab_height),
                ]:
                    bgl.glVertex2i(x, y)
                bgl.glEnd()
            bgl.glColor4f(0.0, 0.0, 0.0, 0.2 * self.opacity)
            y_loc -= self.tab_height
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in [(self.left_edge - self.tab_width, y_loc), (self.left_edge, y_loc)]:
                bgl.glVertex2i(x, y)
            bgl.glEnd()

    # draw fps
    #    bgl.glColor4f(1, 1, 1, 0.2)
    #    blf.size(font_id, fs, int(dpi_r*72))
    #    blf.position(font_id, self.left_edge-50, 5, 0)
    #    blf.draw(font_id, str(round(1/(time.clock() - start),3)))

    # draw line numbers
    if space.text:
        bgl.glColor4f(self.segments[0]["col"][0], self.segments[0]["col"][1], self.segments[0]["col"][2], 0.5)
        for id in range(space.top, min(space.top + space.visible_lines + 1, lines + 1)):
            if self.in_line_bar and self.segments[-2]["elements"][id - 1]:
                bgl.glColor4f(self.segments[-2]["col"][0], self.segments[-2]["col"][1], self.segments[-2]["col"][2], 1)
                blf.position(
                    font_id, 2 + int(0.5 * cw * (len(str(lines)) - 1)), self.height - ch * (id - space.top) + 3, 0
                )
                # blf.draw(font_id, '→')
                blf.draw(font_id, "↓")
                bgl.glColor4f(self.segments[0]["col"][0], self.segments[0]["col"][1], self.segments[0]["col"][2], 0.5)
            else:
                blf.position(
                    font_id,
                    2 + int(0.5 * cw * (len(str(lines)) - len(str(id)))),
                    self.height - ch * (id - space.top) + 3,
                    0,
                )
                blf.draw(font_id, str(id))

    # draw file names
    if self.tab_width:
        blf.enable(font_id, blf.ROTATION)
        blf.rotation(font_id, 1.570796)
        y_loc = self.height
        for text in bpy.data.texts:
            text_max_length = max(2, int((self.tab_height - 40) / cw))
            name = text.name[:text_max_length]
            if text_max_length < len(text.name):
                name += "..."
            bgl.glColor4f(
                self.segments[0]["col"][0],
                self.segments[0]["col"][1],
                self.segments[0]["col"][2],
                (0.7 if text.name == self.in_tab else 0.4) * self.opacity,
            )
            blf.position(
                font_id,
                self.left_edge - round((self.tab_width - ch) / 2.0) - 5,
                round(y_loc - (self.tab_height / 2) - cw * len(name) / 2),
                0,
            )
            blf.draw(font_id, name)
            y_loc -= self.tab_height

    # restore opengl defaults
    bgl.glColor4f(0, 0, 0, 1)
    bgl.glLineWidth(1.0)
    bgl.glDisable(bgl.GL_BLEND)
    blf.disable(font_id, blf.ROTATION)
    return
예제 #55
0
def draw_callback_px(self, context):
    font_id = 0  # XXX, need to find out how best to get this.

    region = context.region

    # Tente de positionner le texte au milieu de la fenetre (à refaire)
    xt = int(region.width / 2.0)
    yt = 70

    # Position et affichage du texte du mode en cours avec les infos dessous (Voir pour mieux centrer le texte)
    blf.position(font_id, xt - blf.dimensions(font_id, "CREATE")[0], 65 + yt, 0)
    blf.size(font_id, 20, 82)
    bgl.glColor4f(0.900, 0.4, 0.00, 1.0)
    blf.draw(font_id, "CREATE")

    bgl.glLineWidth(2)
    bgl.glColor4f(0.900, 0.4, 0.00, 1.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(int(xt - blf.dimensions(font_id, "CREATE")[0] + 0), 55 + yt)
    bgl.glVertex2i(int(xt - blf.dimensions(font_id, "CREATE")[0] + 200), 55 + yt)
    bgl.glEnd()

    # Selon le mode, l'ecriture change de largeur donc le centre est décalé. Ca permet de "réparer" les erreurs.
    xt = xt - blf.dimensions(font_id, "CREATE")[0]

    # Affichage des infos
    blf.size(font_id, 20, 50)
    blf.position(font_id, xt + 15, 35 + yt, 0)
    bgl.glColor4f(0.912, 0.919, 0.994, 1.0)
    if(self.CreateMode == 0):
        blf.draw(font_id, "Type Rectangle [SPACE]")
    if(self.CreateMode == 1):
        blf.draw(font_id, "Type Circle [SPACE]")
    if(self.CreateMode == 2):
        if(self.Closed == False):
            blf.draw(font_id, "Type Line [SPACE] ([C] to close geometry)")
        else:
            blf.draw(font_id, "Type closed Line [SPACE] ([C] to open geometry) ")

    if(self.CreateMode == 0):
        blf.size(font_id, 20, 50)
        blf.position(font_id, xt + 15, 15 + yt, 0)
        bgl.glColor4f(0.912, 0.919, 0.994, 1.0)
        blf.draw(font_id, "Dimension (MouseMove)")
        blf.position(font_id, xt + 15, -5 + yt, 0)
        bgl.glColor4f(0.912, 0.919, 0.994, 1.0)
        blf.draw(font_id, "Move all (Alt + MouseMove)")

    if(self.CreateMode == 1):
        blf.size(font_id, 20, 50)
        blf.position(font_id, xt + 15, 15 + yt, 0)
        bgl.glColor4f(0.912, 0.919, 0.994, 1.0)
        blf.draw(font_id, "Rotation (Ctrl + MouseWheel)")
        blf.position(font_id, xt + 15, -5 + yt, 0)
        blf.draw(font_id, "Definition (MouseWheel)")
        blf.position(font_id, xt + 15, -25 + yt, 0)
        blf.draw(font_id, "Move all (Alt + MouseMove)")

    if(self.CreateMode == 2):
        blf.size(font_id, 20, 50)
        blf.position(font_id, xt + 15, 15 + yt, 0)
        bgl.glColor4f(0.912, 0.919, 0.994, 1.0)
        blf.draw(font_id, "New point (Left Mouse)")
        blf.position(font_id, xt + 15, -5 + yt, 0)
        blf.draw(font_id, "Move all (Alt + MouseMove)")
        blf.position(font_id, xt + 15, -25 + yt, 0)
        blf.draw(font_id, "Incremental (Ctrl)")

    # Mode, couleur et largeur des lignes
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.812, 0.519, 0.094, 0.5)
    bgl.glLineWidth(2)

    # Permet de smoother les points pour les arrondir
    bgl.glEnable(bgl.GL_POINT_SMOOTH)
    if(self.bDone):
        # Affichage des primitives selon le type de découpe choisie

        if(len(self.mouse_path) > 1):
            x0 = self.mouse_path[0][0]
            y0 = self.mouse_path[0][1]
            x1 = self.mouse_path[1][0]
            y1 = self.mouse_path[1][1]

        # Affichage de la ligne de coupe
        if(self.CreateMode == 2):
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in self.mouse_path:
                bgl.glVertex2i(x + self.xpos, y + self.ypos)
            bgl.glEnd()

            bgl.glPointSize(6)
            bgl.glBegin(bgl.GL_POINTS)
            for x, y in self.mouse_path:
                bgl.glVertex2i(x + self.xpos, y + self.ypos)
            bgl.glEnd()

        # Affichage du rectange de découpe
        if(self.CreateMode == 0):
            bgl.glColor4f(0.812, 0.519, 0.094, 0.5)
            # Selon si on appuie sur SHIFT, le rectangle est plein ou pas
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glVertex2i(x0 + self.xpos, y0 + self.ypos)
            bgl.glVertex2i(x1 + self.xpos, y0 + self.ypos)
            bgl.glVertex2i(x1 + self.xpos, y1 + self.ypos)
            bgl.glVertex2i(x0 + self.xpos, y1 + self.ypos)
            bgl.glEnd()

            bgl.glPointSize(6)
            bgl.glColor4f(0.812, 0.519, 0.094, 1.0)
            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex2i(x0 + self.xpos, y0 + self.ypos)
            bgl.glVertex2i(x1 + self.xpos, y0 + self.ypos)
            bgl.glVertex2i(x1 + self.xpos, y1 + self.ypos)
            bgl.glVertex2i(x0 + self.xpos, y1 + self.ypos)
            bgl.glEnd()

        # Affichage du cercle
        if(self.CreateMode == 1):
            DEG2RAD = 3.14159 / 180
            v0 = mathutils.Vector((self.mouse_path[0][0], self.mouse_path[0][1], 0))
            v1 = mathutils.Vector((self.mouse_path[1][0], self.mouse_path[1][1], 0))
            v0 -= v1
            radius = self.mouse_path[1][0] - self.mouse_path[0][0]
            DEG2RAD = 3.14159 / (180 / self.stepAngle[self.step])
            if(self.ctrl):
                shift = (3.14159 / (360 / self.stepAngle[self.step])) * self.stepRotation
            else:
                shift = (self.mouse_path[1][1] - self.mouse_path[0][1]) / 50

            # Selon si on appuie sur SHIFT, le cercle est plein ou pas
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
            bgl.glVertex2i(x0 + self.xpos, y0 + self.ypos)
            for i in range(0, int(360 / self.stepAngle[self.step])):
                degInRad = i * DEG2RAD
                bgl.glVertex2i(x0 + self.xpos + int(math.cos(degInRad + shift) * radius), y0 + self.ypos + int(math.sin(degInRad + shift) * radius))
            bgl.glVertex2i(x0 + self.xpos + int(math.cos(0 + shift) * radius), y0 + self.ypos + int(math.sin(0 + shift) * radius))
            bgl.glEnd()

    # Opengl par défaut
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    bgl.glDisable(bgl.GL_POINT_SMOOTH)
예제 #56
0
def draw_callback_px(self, context):
    # circle graphic, text, and slider
    unify_settings = bpy.context.tool_settings.unified_paint_settings
    strength = unify_settings.strength if self.uni_str else self.brush.strength
    size = unify_settings.size if self.uni_size else self.brush.size
    
    if self.graphic:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(self.brushcolor.r, self.brushcolor.g, self.brushcolor.b, strength * 0.25)
        bgl.glBegin(bgl.GL_POLYGON)
        for x, y in self.circlepoints:
            bgl.glVertex2i(int(size * x) + self.cur[0], int(size * y) + self.cur[1])
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    
    if self.text != 'NONE' and self.doingstr:
        if self.text == 'MEDIUM':
            fontsize = 11
        elif self.text == 'LARGE':
            fontsize = 22
        else:
            fontsize = 8
        
        font_id = 0
        blf.size(font_id, fontsize, 72)
        blf.shadow(font_id, 0, 0.0, 0.0, 0.0, 1.0)
        blf.enable(font_id, blf.SHADOW)
        
        if strength < 0.001:
            text = "0.001"
        else:
            text = str(strength)[0:5]
        textsize = blf.dimensions(font_id, text)
        
        xpos = self.start[0] + self.offset[0]
        ypos = self.start[1] + self.offset[1]
        
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(self.backcolor.r, self.backcolor.g, self.backcolor.b, 0.5)
        
        bgl.glBegin(bgl.GL_POLYGON)
        for x, y in self.rectpoints:
            bgl.glVertex2i(int(textsize[0] * x) + xpos, int(textsize[1] * y) + ypos)
        bgl.glEnd()
        
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        
        blf.position(font_id, xpos, ypos, 0)
        blf.draw(font_id, text)
        
        blf.disable(font_id, blf.SHADOW)
    
    if self.slider != 'NONE' and self.doingstr:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(self.backcolor.r, self.backcolor.g, self.backcolor.b, 0.5)
        
        xpos = self.start[0] + self.offset[0] - self.sliderwidth + (32 if self.text == 'MEDIUM' else 64 if self.text == 'LARGE' else 23)
        ypos = self.start[1] + self.offset[1] - self.sliderheight# + (1 if self.slider != 'SMALL' else 0)
        
        if strength <= 1.0:
            sliderscale = strength
        elif strength > 5.0:
            sliderscale = strength / 10
        elif strength > 2.0:
            sliderscale = strength / 5
        else:
            sliderscale = strength / 2
        
        bgl.glBegin(bgl.GL_POLYGON)
        for x, y in self.rectpoints:
            bgl.glVertex2i(int(self.sliderwidth * x) + xpos, int(self.sliderheight * y) + ypos - 1)
        bgl.glEnd()
        
        bgl.glColor4f(self.frontcolor.r, self.frontcolor.g, self.frontcolor.b, 0.8)
        
        bgl.glBegin(bgl.GL_POLYGON)
        for x, y in self.rectpoints:
            bgl.glVertex2i(int(self.sliderwidth * x * sliderscale) + xpos, int(self.sliderheight * y * 0.75) + ypos)
        bgl.glEnd()
        
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)