Python blf.draw() Examples

The following are 30 code examples of blf.draw(). 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: 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 #3
Source File: mesh_pen_tool.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def draw(self, context):
        layout = self.layout

        if pt_buf.sws == 'on':
            layout.active = False
            layout.label('Pen Tool On')
        else:
            layout.label('Font:')
            row = layout.split(0.50, align = True)
            row.prop(context.scene.pt_custom_props, 'fs', text = 'Size', slider = True)
            row.prop(context.scene.pt_custom_props, 'a', text = 'Alpha', slider = True)
            layout.prop(context.scene.pt_custom_props, 'b0', text = 'Angles')
            layout.prop(context.scene.pt_custom_props, 'b1', text = 'Edge Length')
            layout.prop(context.scene.pt_custom_props, 'b2', text = 'Mouse Location 3d')
            row1 = layout.split(0.80, align = True)
            row1.operator('pt.op0_id', text = 'Draw')
            row1.operator('pt.op1_id', text = '?')

# ------ operator 0 ------ 
Example #4
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 #5
Source File: opengl.py    From BlenderPro with GNU General Public License v3.0 6 votes vote down vote up
def draw(self,obj_1,obj_2):
        p1 = (obj_1.matrix_world[0][3], obj_1.matrix_world[1][3],obj_1.matrix_world[2][3])
        p2 = (obj_2.matrix_world[0][3], obj_2.matrix_world[1][3],obj_2.matrix_world[2][3])
        
        dist = distance(p1,p2)
        
        if dist > 0:
            
            dim_text = unit.dim_as_string(dist)
            text_width = self.txt_width(dim_text)
            text_height = self.txt_height(dim_text)
            
            txtpoint3d = interpolate3d(p1, p2, math.fabs(dist / 2))
            txtpoint2d = view3d_utils.location_3d_to_region_2d(self.region, self.rv3d, txtpoint3d)
            
            self.draw_dim_box(txtpoint2d, (text_width,text_height))
            self.draw_dim_text(txtpoint2d, dim_text, (text_width,text_height)) 
Example #6
Source File: modal_utils.py    From leomoon-lightstudio with GNU General Public License v3.0 6 votes vote down vote up
def _draw(self, context, event):
        # first draw to reset buffer
        shader2Dcolor.uniform_float("color", (.5, .5, .5, .5))
        batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((0,0), (0,0))}).draw(shader2Dcolor)
        
        if self.draw_guide:
            shader2Dcolor.uniform_float("color", (.5, .5, .5, .5))
            batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((self._start_position[:]), (self._end_position[:]))}).draw(shader2Dcolor)

        if self.allow_xy_keys:
            if self.x_key:
                shader2Dcolor.uniform_float("color", (1, 0, 0, .5))
                batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((0, self._start_position.y), (context.area.width, self._start_position.y))}).draw(shader2Dcolor)
            elif self.y_key:
                shader2Dcolor.uniform_float("color", (0, 1, 0, .5))
                batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((self._start_position.x, 0), (self._start_position.x, context.area.height))}).draw(shader2Dcolor) 
Example #7
Source File: bl_ui_button.py    From bl_ui_widgets with GNU General Public License v3.0 6 votes vote down vote up
def draw(self):

        area_height = self.get_area_height()

        self.shader.bind()
        
        self.set_colors()
        
        bgl.glEnable(bgl.GL_BLEND)

        self.batch_panel.draw(self.shader) 

        self.draw_image()   

        bgl.glDisable(bgl.GL_BLEND)

        # Draw text
        self.draw_text(area_height) 
Example #8
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 #9
Source File: mesh_show_vgroup_weights.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def create_properties():
    bpy.types.WindowManager.show_vgroups_show_all = bpy.props.BoolProperty(
        name = "Show All Selected Vertices",
        description = "Show all vertices with vertex groups assigned to them",
        default=False)

    bpy.types.Mesh.assign_vgroup = bpy.props.StringProperty()

    bpy.types.Scene.show_vgroups_weights = bpy.props.BoolProperty(
        name="Show Vertex Groups/Weights",
        default=False)

    bpy.types.Scene.show_vgroups_weights_limit = bpy.props.IntProperty(
        name="Limit",
        description="Maximum number of weight overlays to draw",
        default=20,
        min=1,
        max=1000,
        soft_max=100)

# removal of ID-properties when script is disabled 
Example #10
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 #11
Source File: mesh_carver.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def DrawLeftText(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, yt + Sshadow_y, 0)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    blf.draw(font_id, text)
    blf.position(font_id, xt, 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 (Right position) 
Example #12
Source File: bl_ui_checkbox.py    From bl_ui_widgets with GNU General Public License v3.0 6 votes vote down vote up
def draw(self):

        area_height = self.get_area_height()
        self.shader_chb.bind()

        if self.is_checked:
            bgl.glLineWidth(3)
            self.shader_chb.uniform_float("color", self._cross_color)

            self.batch_cross.draw(self.shader_chb) 

        bgl.glLineWidth(2)
        self.shader_chb.uniform_float("color", self._box_color)

        self.batch_box.draw(self.shader_chb) 

        # Draw text
        self.draw_text(area_height) 
Example #13
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def draw(self, context, layout):
        if len(self.collection) == 0:
            if self.op_new:
                layout.operator(self.op_new, icon=self.icon)
            else:
                layout.label(
                    text="({})".format(self.data_name),
                    icon=self.icon)
            return

        row = layout.row(align=True)
        row.prop_menu_enum(self, "enum", text="", icon=self.icon)
        row.prop(self, "active", text="")
        if self.op_new:
            row.operator(self.op_new, text="", icon='ZOOMIN')
        if self.op_delete:
            row.operator(self.op_delete, text="", icon='X')
# end class
#============================================================================#
# ===== PROPERTY DEFINITIONS ===== #

# ===== TRANSFORM EXTRA OPTIONS ===== # 
Example #14
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 #15
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def draw(self, context):
        layout = self.layout

        settings = find_settings()
        tfm_opts = settings.transform_options

        v3d = context.space_data

        col = layout.column()
        col.prop(self, "pos", text="")

        row = layout.row()
        row.prop(tfm_opts, "use_relative_coords", text="Relative")
        row.prop(v3d, "transform_orientation", text="")

# Adapted from Chromoly's lock_cursor3d 
Example #16
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 #17
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 #18
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 #19
Source File: cm_draw.py    From CrowdMaster with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_2d(self, context):
    with bglWrapper:
        # draw text
        drawText2D((1.0, 1.0, 1.0, 1), "Hello Word ") 
Example #20
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 #21
Source File: mi_primitives.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            clean(context, self)  # clean old stuff

            if self.prim_type == 'Clone':
                if not context.selected_objects:
                    self.report({'WARNING'}, "No Selected Objects to Clone!")
                    return {'CANCELLED'}
                else:
                    self.objects_to_clone = context.selected_objects.copy()

            # the arguments we pass the the callback
            args = (self, context)

            # Add the region OpenGL drawing callback
            # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
            self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL')

            mi_settings = context.scene.mi_settings

            # Check if it's EDIT MODE
            if context.mode == 'EDIT_MESH':
                self.edit_obj = context.scene.objects.active

            # get all matrices of visible objects
            self.obj_matrices = ut_base.get_obj_dup_meshes(mi_settings.snap_objects, True, context, add_active_obj=True)

            context.window_manager.modal_handler_add(self)

            return {'RUNNING_MODAL'}

        else:
            self.report({'WARNING'}, "Active space must be a View3d")
            return {'CANCELLED'} 
Example #22
Source File: mi_primitives.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            clean(context, self)  # clean old stuff

            if self.prim_type == 'Clone':
                if not context.selected_objects:
                    self.report({'WARNING'}, "No Selected Objects to Clone!")
                    return {'CANCELLED'}
                else:
                    self.objects_to_clone = context.selected_objects.copy()

            # the arguments we pass the the callback
            args = (self, context)

            # Add the region OpenGL drawing callback
            # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
            self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL')

            mi_settings = context.scene.mi_settings

            # Check if it's EDIT MODE
            if context.mode == 'EDIT_MESH':
                self.edit_obj = context.active_object

            # get all matrices of visible objects
            self.obj_matrices = ut_base.get_obj_dup_meshes(mi_settings.snap_objects, True, context, add_active_obj=True)

            context.window_manager.modal_handler_add(self)

            return {'RUNNING_MODAL'}

        else:
            self.report({'WARNING'}, "Active space must be a View3d")
            return {'CANCELLED'} 
Example #23
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw(self, x, y, align=(0, 0)):
        xy = self.prepare_draw(x, y, align)
        if not xy:
            return

        draw_rect(xy[0], xy[1], w, h) 
Example #24
Source File: opengl.py    From BlenderPro with GNU General Public License v3.0 5 votes vote down vote up
def draw_dim_text(self,point2d,text,text_size):
        txt_color = (1, 1, 1, 1) #RGBA        
        
        text_x_loc = point2d[0] - (text_size[0]/2)
        text_y_loc = point2d[1] - (text_size[1]/2)
        
        text_dpi = get_dpi()
        blf.size(0, 12, text_dpi)
        blf.position(0,text_x_loc,text_y_loc,0)
        bgl.glColor4f(*txt_color)
        blf.draw(0, text) 
Example #25
Source File: ui.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def init_draw(context=None):
    if context == None:
        context = bpy.context
    if "stored_views_osd" not in context.window_manager:
        context.window_manager["stored_views_osd"] = False
    if not context.window_manager["stored_views_osd"]:
        context.window_manager["stored_views_osd"] = True
        bpy.ops.stored_views.draw() 
Example #26
Source File: space_view3d_game_props_visualiser.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback(self, context):
    # polling
    if context.mode == 'EDIT_MESH':
        return

    """
    # retrieving ID property data
    try:
        texts = context.scene['GamePropsVisualizer']
    except:
        return

    if not texts:
        return
    """

    texts = context.scene['GamePropsVisualizer']

    # draw
    i = 0

    blf.size(0, 12, 72)


    bgl.glColor3f(1.0, 1.0, 1.0)
    for ob in bpy.context.selected_objects:
        for pi,p in enumerate(ob.game.properties):
            blf.position(0, texts[i], texts[i+1] - (pi+1) * 14, 0)
            if p.type=='FLOAT':
                t=p.name+':  '+ str('%g' % p.value)
            else:
                t=p.name+':  '+ str(p.value)
            blf.draw(0, t)
            i += 2


# operator 
Example #27
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw(self, context):
        layout = self.layout
        settings = find_settings()
        row = layout.row()
        row.prop(self, "auto_register_keymaps", text="")
        row.prop(settings, "auto_register_keymaps")
        row.prop(settings, "free_coord_precision")
        row.prop(self, "use_cursor_monitor") 
Example #28
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw_text(x, y, value, font_id=0, align=(0, 0), font_height=None):
    value = str(value)

    if (align[0] != 0) or (align[1] != 0):
        dims = blf.dimensions(font_id, value)
        if font_height is not None:
            dims = (dims[0], font_height)
        x -= dims[0] * align[0]
        y -= dims[1] * align[1]

    x = int(math.floor(x + 0.5))
    y = int(math.floor(y + 0.5))

    blf.position(font_id, x, y, 0)
    blf.draw(font_id, value) 
Example #29
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw(self, x, y, align=(0, 0)):
        xy = self.prepare_draw(x, y, align)
        if not xy:
            return

        blf.position(self.font_id, xy[0], xy[1], 0)
        blf.draw(self.font_id, self.text) 
Example #30
Source File: help_display.py    From coa_tools with GNU General Public License v3.0 5 votes vote down vote up
def write_text(self,text,size=20,pos_y=0,color=(1,1,1,1)):
        start_pos = self.region_height - 60*self.scale_y
        lines = text.split("\n")
        
        pos_y = start_pos - (pos_y * self.scale_y)
        size = int(size * self.scale_y)
        
        bgl.glColor4f(color[0],color[1],color[2],color[3]*self.alpha_current)
        line_height = (size + size*.5) * self.scale_y
        for i,line in enumerate(lines):
            
            blf.position(self.font_id, 15+self.region_offset, pos_y-(line_height*i), 0)
            blf.size(self.font_id, size, 72)
            blf.draw(self.font_id, line)