Python blf.position() Examples

The following are 30 code examples of blf.position(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module blf , or try the search function .
Example #1
Source File: edit_mesh.py    From coa_tools with GNU General Public License v3.0 7 votes vote down vote up
def draw_callback_text(self):
        obj = bpy.context.active_object
        ### draw text for edge length detection
        if self.shift and self.point_type == "EDGE":
            p1 = obj.matrix_world * self.verts_edges_data[0]
            p2 = obj.matrix_world * self.verts_edges_data[1]
            length = (p1-p2).magnitude

            font_id = 0
            line = str(round(length,2))
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glColor4f(1,1,1,1)

            blf.position(font_id, self.mouse_2d_x-15, self.mouse_2d_y+30, 0)
            blf.size(font_id, 20, 72)
            blf.draw(font_id, line)

        if self.mode == "EDIT_MESH":
            draw_edit_mode(self,bpy.context,color=[1.0, 0.39, 0.41, 1.0],text="Edit Mesh Mode",offset=-20)
        elif self.mode == "DRAW_BONE_SHAPE":
            draw_edit_mode(self,bpy.context,color=[1.0, 0.39, 0.41, 1.0],text="Draw Bone Shape",offset=-20) 
Example #2
Source File: align_pick_points.py    From object_alignment with GNU General Public License v3.0 6 votes vote down vote up
def draw_callback_px(self, context):

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

    # draw some text
    y = context.region.height
    dims = blf.dimensions(0, 'A')

    blf.position(font_id, 10, y - 20 - dims[1], 0)
    blf.size(font_id, 20, 72)

    if context.area.x == self.area_align.x:
        blf.draw(font_id, "Align: "+ self.align_msg)
        points = [self.obj_align.matrix_world * p for p in self.align_points]
        color = (1,0,0,1)
    else:
        blf.draw(font_id, "Base: " + self.base_msg)
        points = [self.obj_align.matrix_world * p for p in self.base_points]
        color = (0,1,0,1)

    draw_3d_points_revised(context, points, color, 4)

    for i, vec in enumerate(points):
        ind = str(i)
        draw_3d_text(context, font_id, ind, vec) 
Example #3
Source File: operator_modal_draw.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #4
Source File: mesh_carver.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def DrawRightText(text, xt, yt, Size, Color, self):
    font_id = 0
    # Decalage Ombre
    Sshadow_x = 2
    Sshadow_y = -2

    blf.size(font_id, Size, 72)
    blf.position(font_id, xt + Sshadow_x - blf.dimensions(font_id, text)[0], yt + Sshadow_y, 0)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    blf.draw(font_id, text)
    blf.position(font_id, xt - blf.dimensions(font_id, text)[0], yt, 0)
    if Color is not None:
        mColor = mathutils.Color((Color[0], Color[1], Color[2]))
        bgl.glColor4f(mColor.r, mColor.g, mColor.b, 1.0)
    else:
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    blf.draw(font_id, text)


# Opengl draws 
Example #5
Source File: mesh_carver.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def DrawCenterText(text, xt, yt, Size, Color, self):
    font_id = 0
    # Decalage Ombre
    Sshadow_x = 2
    Sshadow_y = -2

    blf.size(font_id, Size, 72)
    blf.position(font_id, xt + Sshadow_x - blf.dimensions(font_id, text)[0] / 2, yt + Sshadow_y, 0)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    blf.draw(font_id, text)
    blf.position(font_id, xt - blf.dimensions(font_id, text)[0] / 2, yt, 0)
    if Color is not None:
        mColor = mathutils.Color((Color[0], Color[1], Color[2]))
        bgl.glColor4f(mColor.r, mColor.g, mColor.b, 1.0)
    else:
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    blf.draw(font_id, text)


# Draw text (Left position) 
Example #6
Source File: operator_modal_draw.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #7
Source File: archipack_gl.py    From archipack with GNU General Public License v3.0 6 votes vote down vote up
def draw(self, context, render=False):

        # print("draw_text %s %s" % (self.text, type(self).__name__))
        self.render = render
        p = self.position_2d_from_coord(context, self.pts[0], render)
        # dirty fast assignment
        dpi, font_id = context.user_preferences.system.dpi, 0
        bgl.glColor4f(*self.colour)
        if self.angle != 0:
            blf.enable(font_id, blf.ROTATION)
            blf.rotation(font_id, self.angle)
        blf.size(font_id, self.font_size, dpi)
        blf.position(font_id, p.x, p.y, 0)
        blf.draw(font_id, self.text)
        if self.angle != 0:
            blf.disable(font_id, blf.ROTATION) 
Example #8
Source File: ui.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def _draw_callback_px(self, context):

    try:
        print("SELF", self)
    except:
        print("red err?")

    r_width = context.region.width
    r_height = context.region.height
    font_id = 0  # TODO: need to find out how best to get font_id

    blf.size(font_id, 11, 72)
    text_size = blf.dimensions(0, self.view_name)

    text_x = r_width - text_size[0] - 10
    text_y = r_height - text_size[1] - 8
    blf.position(font_id, text_x, text_y, 0)
    blf.draw(font_id, self.view_name) 
Example #9
Source File: onscreen_text.py    From jewelcraft with GNU General Public License v3.0 6 votes vote down vote up
def onscreen_warning(self, x, y):
        gamma = self.gamma_correction

        fontid = 1
        blf.size(fontid, self.prefs.view_font_size_report, 72)
        blf.color(fontid, *gamma((1.0, 0.3, 0.3, 1.0)))

        _, font_h = blf.dimensions(fontid, "Row Height")
        font_row_height = font_h * 2
        y += font_h

        for row in self.warn:
            y -= font_row_height

            blf.position(fontid, x, y, 0.0)
            blf.draw(fontid, row)

        return y 
Example #10
Source File: __init__.py    From retopology-polystrips with GNU General Public License v2.0 6 votes vote down vote up
def rotate_tool_gvert_neighbors(self, command, eventd):
        if command == 'init':
            self.footer = 'Rotating GVerts'
            self.tool_data = [(gv,Vector(gv.position)) for gv in self.sel_gvert.get_inner_gverts()]
        elif command == 'commit':
            pass
        elif command == 'undo':
            for gv,p in self.tool_data:
                gv.position = p
                gv.update()
        else:
            ang = command
            q = Quaternion(self.sel_gvert.snap_norm, ang)
            p = self.sel_gvert.position
            for gv,up in self.tool_data:
                gv.position = p+q*(up-p)
                gv.update() 
Example #11
Source File: __init__.py    From retopology-polystrips with GNU General Public License v2.0 6 votes vote down vote up
def scale_tool_gvert(self, command, eventd):
        if command == 'init':
            self.footer = 'Scaling GVerts'
            sgv = self.sel_gvert
            lgv = [ge.gvert1 if ge.gvert0==sgv else ge.gvert2 for ge in sgv.get_gedges() if ge]
            self.tool_data = [(gv,Vector(gv.position)) for gv in lgv]
        elif command == 'commit':
            pass
        elif command == 'undo':
            for gv,p in self.tool_data:
                gv.position = p
                gv.update()
            self.sel_gvert.update()
            self.sel_gvert.update_visibility(eventd['r3d'], update_gedges=True)
        else:
            m = command
            sgv = self.sel_gvert
            p = sgv.position
            for ge in sgv.get_gedges():
                if not ge: continue
                gv = ge.gvert1 if ge.gvert0 == self.sel_gvert else ge.gvert2
                gv.position = p + (gv.position-p) * m
                gv.update()
            sgv.update()
            self.sel_gvert.update_visibility(eventd['r3d'], update_gedges=True) 
Example #12
Source File: utilities.py    From object_alignment with GNU General Public License v3.0 6 votes vote down vote up
def draw_3d_text(context, font_id, text, vec):
    region = context.region
    region3d = context.space_data.region_3d


    region_mid_width = region.width / 2.0
    region_mid_height = region.height / 2.0

    perspective_matrix = region3d.perspective_matrix.copy()
    vec_4d = perspective_matrix * vec.to_4d()
    if vec_4d.w > 0.0:
        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)

        blf.position(font_id, x + 3.0, y - 4.0, 0.0)
        blf.draw(font_id, text)


################################################
############# RAYCASTING AND SNAPPING ##########
################################################

# Jon Denning for Retopoflow 
Example #13
Source File: fsc_add_object_op.py    From fast-sculpt with GNU General Public License v3.0 6 votes vote down vote up
def draw_callback_2d(self, op, context):

        # Draw text for add object mode
        header = "- Add Object Mode (Type: " + context.scene.add_object_type + ") -"
        text = "Ctrl + Left Click = Add | Esc = Exit"

        blf.color(1, 1, 1, 1, 1)
        blf.size(0, 20, 72)
        blf.size(1, 16, 72)

        region = context.region
        xt = int(region.width / 2.0)

        blf.position(0, xt - blf.dimensions(0, header)[0] / 2, 50 , 0)
        blf.draw(0, header)

        blf.position(1, xt - blf.dimensions(1, text)[0] / 2, 20 , 0)
        blf.draw(1, text) 
Example #14
Source File: display.py    From phobos with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def draw_text(text, position, color=(1.0, 1.0, 1.0, 1.0), size=14, dpi=150, font_id=0):
    """

    Args:
      text: 
      position: 
      color: (Default value = (1.0)
      1.0: 
      1.0): 
      size: (Default value = 14)
      dpi: (Default value = 150)
      font_id: (Default value = 0)

    Returns:

    """
    bgl.glColor4f(*color)
    blf.position(font_id, *position, 0.25)
    blf.size(font_id, size, dpi)
    blf.draw(font_id, text) 
Example #15
Source File: animation_motion_trail.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def get_location(frame, display_ob, offset_ob, curves):
    if offset_ob:
        bpy.context.scene.frame_set(frame)
        display_mat = getattr(display_ob, "matrix", False)
        if not display_mat:
            # posebones have "matrix", objects have "matrix_world"
            display_mat = display_ob.matrix_world
        if offset_ob:
            loc = display_mat.to_translation() + \
                offset_ob.matrix_world.to_translation()
        else:
            loc = display_mat.to_translation()
    else:
        fcx, fcy, fcz = curves
        locx = fcx.evaluate(frame)
        locy = fcy.evaluate(frame)
        locz = fcz.evaluate(frame)
        loc = mathutils.Vector([locx, locy, locz])

    return(loc)


# get position of keyframes and handles at the start of dragging 
Example #16
Source File: archipack_gl.py    From archipack with GNU General Public License v3.0 6 votes vote down vote up
def instructions(self, context, title, explanation, shortcuts):
        """
            position from bottom to top
        """
        prefs = self.get_prefs(context)

        self.explanation.label = explanation
        self.title.label = title

        self.shortcuts = []

        for key, label in shortcuts:
            key = GlText(d=2, label=key,
                font_size=prefs.feedback_size_shortcut,
                colour=prefs.feedback_colour_key)
            label = GlText(d=2, label=' : ' + label,
                font_size=prefs.feedback_size_shortcut,
                colour=prefs.feedback_colour_shortcut)
            ks = key.text_size(context)
            ls = label.text_size(context)
            self.shortcuts.append([key, ks, label, ls]) 
Example #17
Source File: material_advanded_override_v1-5.py    From Blender_add-ons with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(self, context):
    if context.scene.OW_display_override:
        font_id = 0  # XXX, need to find out how best to get this
        blf.position(font_id, 28, bpy.context.area.height-85, 0)
        blf.draw(font_id, "Override ON")
        
############
# Layout 
Example #18
Source File: mi_primitives.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def replace_prim(old_prim, segments, prim_type, context):
    loc, rot, scale = old_prim.location.copy(), old_prim.rotation_euler.copy(), old_prim.scale.copy()
    #old_matrix = old_prim.matrix_world.copy()

    # remove old primitive
    objs = bpy.data.objects
    objs.remove(objs[old_prim.name], True)

    # new primitive
    if prim_type == 'Plane':
        bpy.ops.mesh.primitive_plane_add(radius=1)
    elif prim_type == 'Cube':
        bpy.ops.mesh.primitive_cube_add(radius=1)
    elif prim_type == 'Circle':
        bpy.ops.mesh.primitive_circle_add(radius=1, vertices=segments[0], fill_type='NGON')
    elif prim_type == 'Sphere':
        bpy.ops.mesh.primitive_uv_sphere_add(size=1, segments=segments[0], ring_count=segments[1])
    elif prim_type == 'Cylinder':
        bpy.ops.mesh.primitive_cylinder_add(radius=1, vertices=segments[0])
    elif prim_type == 'Cone':
        bpy.ops.mesh.primitive_cone_add(radius1=1, vertices=segments[0])
    elif prim_type == 'Capsule':
        add_mesh_capsule.add_capsule(1, 1, segments[1], segments[0], context)

    new_prim = bpy.context.object
    #new_prim.matrix_world = old_matrix
    new_prim.location, new_prim.rotation_euler, new_prim.scale = loc, rot, scale

    return new_prim


# auto pick position and axis 
Example #19
Source File: mi_primitives.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def replace_prim(old_prim, segments, prim_type, context):
    loc, rot, scale = old_prim.location.copy(), old_prim.rotation_euler.copy(), old_prim.scale.copy()
    #old_matrix = old_prim.matrix_world.copy()

    # remove old primitive
    objs = bpy.data.objects
    objs.remove(old_prim)

    # new primitive
    if prim_type == 'Plane':
        bpy.ops.mesh.primitive_plane_add(size=2)
    elif prim_type == 'Cube':
        bpy.ops.mesh.primitive_cube_add(size=2)
    elif prim_type == 'Circle':
        bpy.ops.mesh.primitive_circle_add(radius=1, vertices=segments[0], fill_type='NGON')
    elif prim_type == 'Sphere':
        bpy.ops.mesh.primitive_uv_sphere_add(radius=1, segments=segments[0], ring_count=segments[1])
    elif prim_type == 'Cylinder':
        bpy.ops.mesh.primitive_cylinder_add(radius=1, vertices=segments[0])
    elif prim_type == 'Cone':
        bpy.ops.mesh.primitive_cone_add(radius1=1, vertices=segments[0])
    elif prim_type == 'Capsule':
        add_mesh_capsule.add_capsule(1, 1, segments[1], segments[0], context)

    new_prim = bpy.context.object
    #new_prim.matrix_world = old_matrix
    new_prim.location, new_prim.rotation_euler, new_prim.scale = loc, rot, scale

    return new_prim


# auto pick position and axis 
Example #20
Source File: material_advanded_override_v0-6.py    From Blender_add-ons with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(self, context):
    if context.scene.OW_display_override:
        font_id = 0  # XXX, need to find out how best to get this
        blf.position(font_id, 28, bpy.context.area.height-85, 0)
        blf.draw(font_id, "Override ON")
        
# 
Example #21
Source File: material_advanded_override_v1-6.py    From Blender_add-ons with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(self, context):
    if context.scene.OW_display_override:
        font_id = 0  # XXX, need to find out how best to get this
        blf.position(font_id, 28, bpy.context.area.height-85, 0)
        blf.draw(font_id, "Override ON")
        
############
# Layout 
Example #22
Source File: material_advanced_override_v1-2.py    From Blender_add-ons with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(self, context):
    if context.scene.OW_display_override:
        font_id = 0  # XXX, need to find out how best to get this
        blf.position(font_id, 28, bpy.context.area.height-85, 0)
        blf.draw(font_id, "Override ON")
        
############
# Layout 
Example #23
Source File: material_advanced_override_v0-7.py    From Blender_add-ons with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(self, context):
    if context.scene.OW_display_override:
        font_id = 0  # XXX, need to find out how best to get this
        blf.position(font_id, 28, bpy.context.area.height-85, 0)
        blf.draw(font_id, "Override ON")
        
# 
Example #24
Source File: onscreen_text.py    From jewelcraft with GNU General Public License v3.0 5 votes vote down vote up
def onscreen_gem_table(self, x, y, color=(0.95, 0.95, 0.95, 1.0), is_viewport=True):
        gamma = self.gamma_correction if is_viewport else lambda x: x
        color = gamma(color)

        fontid = 1
        blf.size(fontid, self.prefs.view_font_size_report, 72)
        blf.color(fontid, *color)

        _, font_h = blf.dimensions(fontid, "Row Height")
        font_baseline = font_h * 0.4
        font_row_height = font_h * 2
        box_size = font_h * 1.5
        y += font_baseline

        for row, color in self.gems_fmt:
            y -= font_row_height

            shader.bind()
            shader.uniform_float("color", color)
            batch_font = batch_for_shader(shader, "TRI_FAN", {"pos": self.rect_coords(x, y, box_size, box_size)})
            batch_font.draw(shader)

            blf.position(fontid, x + font_row_height, y + font_baseline, 0.0)
            blf.draw(fontid, row)

        return y 
Example #25
Source File: cm_draw.py    From CrowdMaster with GNU General Public License v3.0 5 votes vote down vote up
def drawText2D(color, text):
    font_id = 0  # XXX, need to find out how best to get this.
    # draw some text
    bgl.glColor4f(*color)
    blf.position(font_id, 20, 70, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, text) 
Example #26
Source File: fontmanager.py    From addon_common with GNU General Public License v3.0 5 votes vote down vote up
def position(xyz, fontid=None):
        return blf.position(FontManager.load(fontid), *xyz) 
Example #27
Source File: fontmanager.py    From addon_common with GNU General Public License v3.0 5 votes vote down vote up
def draw(text, xyz=None, fontsize=None, dpi=None, fontid=None):
        fontid = FontManager.load(fontid)
        if xyz: blf.position(fontid, *xyz)
        if fontsize: FontManager.size(fontsize, dpi=dpi, fontid=fontid)
        return blf.draw(fontid, text) 
Example #28
Source File: textRenderExample.py    From FlowState with GNU General Public License v3.0 5 votes vote down vote up
def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    #bgl.glColor(1,1,1,1)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    # BLF drawing routine
    font_id = logic.font_id
    RED = (1, 0, 0, 1)
    pcol = ("Blue ", RED)
    #blf.color(font_id, 1, 1, 0, 0.5)
    blf.blur(font_id,500)
    blf.rotation(font_id, 90)
    blf.position(font_id, (width * 0.5), (height * 0.5), 0.5)
    blf.size(font_id, 20, 100)
    blf.draw(font_id, "Hello World1")
    blf.size(font_id, 50, 72)
    blf.position(font_id, (width * 0.0), (height * 0.5), 0.5)
    blf.draw(font_id, "Hello World2") 
Example #29
Source File: bl_ui_textbox.py    From bl_ui_widgets with GNU General Public License v3.0 5 votes vote down vote up
def draw_text(self, area_height):
        blf.size(0, self._text_size, 72)
        size = blf.dimensions(0, self._text)

        textpos_y = area_height - \
            self._textpos[1] - (self.height + size[1]) / 2.0
        blf.position(
            0, self._textpos[0] + (self.width - size[0]) / 2.0, textpos_y + 1, 0)

        r, g, b, a = self._text_color
        blf.color(0, r, g, b, a)

        blf.draw(0, self._text) 
Example #30
Source File: bl_ui_label.py    From bl_ui_widgets with GNU General Public License v3.0 5 votes vote down vote up
def draw(self):
        area_height = self.get_area_height()

        blf.size(0, self._text_size, 72)
        size = blf.dimensions(0, self._text)
    
        textpos_y = area_height - self.y_screen - self.height
        blf.position(0, self.x_screen, textpos_y, 0)

        r, g, b, a = self._text_color

        blf.color(0, r, g, b, a)
            
        blf.draw(0, self._text)