Python blf.dimensions() Examples

The following are 30 code examples of blf.dimensions(). 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: 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 #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: 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 #4
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 #5
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 #6
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 #7
Source File: draw.py    From blender-power-sequencer with GNU General Public License v3.0 5 votes vote down vote up
def draw_text(x, y, size, text, justify="left", color=(1.0, 1.0, 1.0, 1.0)):
    font_id = 0
    blf.color(font_id, *color)
    if justify == "right":
        text_width, text_height = blf.dimensions(font_id, text)
    else:
        text_width = 0
    blf.position(font_id, x - text_width, y, 0)
    blf.size(font_id, size, 72)
    blf.draw(font_id, text) 
Example #8
Source File: bl_ui_button.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 #9
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) 
Example #10
Source File: bl_ui_textbox.py    From bl_ui_widgets with GNU General Public License v3.0 5 votes vote down vote up
def get_carret_pos_px(self):

        size_all = blf.dimensions(0, self._text)
        size_to_carret = blf.dimensions(0, self._text[:self._carret_pos])
        return self.x_screen + (self.width / 2.0) - (size_all[0] / 2.0) + size_to_carret[0] 
Example #11
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 #12
Source File: bl_ui_checkbox.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], textpos_y, 0)

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

        blf.draw(0, self._text) 
Example #13
Source File: fontmanager.py    From addon_common with GNU General Public License v3.0 5 votes vote down vote up
def dimensions(text, fontid=None):
        return blf.dimensions(FontManager.load(fontid), text) 
Example #14
Source File: modal_utils.py    From leomoon-lightstudio with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, loc, text, size=15):
        self.font_size = size
        self.font_color = (.25, .25, .25, 1)
        self.bg_color = (.5, .5, .5, 1)
        self.bg_color_selected = (.7, .7, .7, 1)
        self.font_id = len(Button.buttons)
        self.text = text
        blf.color(self.font_id, *self.font_color)
        blf.position(self.font_id, *loc, 0)
        blf.size(self.font_id, self.font_size, 72)
        self.dimensions = blf.dimensions(self.font_id, text)
        self.function = lambda args : None

        super().__init__(loc, self.dimensions[0]+5, self.dimensions[1]+5)
        Button.buttons.append(self) 
Example #15
Source File: archipack_gl.py    From archipack with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
            d=3,
            colour=(0.0, 0.0, 0.0, 1.0)):
        # nth dimensions of input coords 3=word coords 2=pixel screen coords
        self.d = d
        self.pos_2d = Vector((0, 0))
        self.colour_inactive = colour 
Example #16
Source File: archipack_gl.py    From archipack with GNU General Public License v3.0 5 votes vote down vote up
def text_size(self, context):
        """
            overall on-screen size in pixels
        """
        dpi, font_id = context.user_preferences.system.dpi, 0
        if self.angle != 0:
            blf.enable(font_id, blf.ROTATION)
            blf.rotation(font_id, self.angle)
        blf.aspect(font_id, 1.0)
        blf.size(font_id, self.font_size, dpi)
        x, y = blf.dimensions(font_id, self.text)
        if self.angle != 0:
            blf.disable(font_id, blf.ROTATION)
        return Vector((x, y)) 
Example #17
Source File: display.py    From phobos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_message(text, msgtype, slot, opacity=1.0, offset=0):
    """

    Args:
      text: 
      msgtype: 
      slot: 
      opacity: (Default value = 1.0)
      offset: (Default value = 0)

    Returns:

    """
    blf.size(0, 6, 150)
    width = bpy.context.region.width
    start = width - blf.dimensions(0, text)[0] - 6
    points = (
        (start, slotlower[slot]),
        (width - 2, slotlower[slot]),
        (width - 2, slotlower[slot] + slotheight - 4),
        (start, slotlower[slot] + slotheight - 4),
    )
    draw_2dpolygon(points, fillcolor=(*colors[msgtype], 0.2 * opacity))
    draw_text(text, (start + 2, slotlower[slot] + 4), size=6, color=(1, 1, 1, opacity))
    if slot == 0 and offset > 0:
        # draw_text(str(offset) + ' \u25bc', (start - 30, slotlower[0] + 4), size=6, color=(1, 1, 1, opacity))
        draw_text('+' + str(offset), (start - 30, slotlower[0] + 4), size=6, color=(1, 1, 1, 1)) 
Example #18
Source File: scv_op.py    From shortcut_VUr with GNU General Public License v3.0 5 votes vote down vote up
def draw_text(self, font_size, font_color, context):
        font_id = 0
        create_font(font_id, font_size, font_color)

        text = str(self.key_input)

        ox = context.scene.cursor_offset_x
        oy = context.scene.cursor_offset_y

        # default left dock
        xpos_text = 12 + ox
        ypos_text = 30 + oy

        if context.scene.h_dock == "1":

            # right dock
            text_extent = blf.dimensions(font_id, text)
            xpos_text = context.region.width - text_extent[0] - 28 - ox 

        elif context.scene.h_dock == "2":

            # center dock
            ypos_text = 30
            text_extent = blf.dimensions(font_id, text)
            xpos_text = (context.region.width - text_extent[0]) / 2.0

        elif context.scene.h_dock == "3":

            offset_buttons = 120
            if context.scene.show_buttons == False:
                offset_buttons = 70

            oy = context.scene.cursor_offset_y + offset_buttons

            text_extent = blf.dimensions(font_id, text)
            xpos_text = self.mouse_input.mouse_x - (text_extent[0] / 2.0) + ox
            ypos_text = self.mouse_input.mouse_y - oy

        draw_text(text, xpos_text, ypos_text, font_id) 
Example #19
Source File: fc_immediate_mode_op.py    From fast-carve with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(tmp, self, context):
        
        region = context.region
        
        draw_bg(region)
            
        xt = int(region.width / 2.0)
                
        if self._mode == 0:
            mode = "Difference"
        elif self._mode == 1:
            mode = "Union"
        else:
            mode = "Slice"
        
        text = "Mode (M): {0}".format(mode)
        
        # Big font
        font_id = 0
        create_font(font_id, 25)
        
        # Small font 
        s_font_id = 1
        create_font(s_font_id, 10)
        
        draw_text(text, xt - blf.dimensions(font_id, text)[0] / 2, 60, font_id)
        
        text_info = "Apply: Space | Finish: Esc"
        draw_text(text_info, xt- blf.dimensions(s_font_id, text_info)[0] / 2, 30, s_font_id) 
Example #20
Source File: __init__.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw_unit(data, config):
	font = config.font_main
	sx = data.sx - 1
	text = number_adjust_column(10.0 ** data.unit_pow, data.unit_pow)

	blf.size(font.id, font.size, font.dpi)
	text_width, text_height = blf.dimensions(font.id, text)
	px = sx - text_width - font.offset * 2
	glColor4f(*config.color_background)
	glRectf(px, 0, sx, text_height + font.offset * 2)
	glColor4f(*config.color_main)
	draw_box(px, 0, text_width + font.offset * 2, text_height + font.offset * 2)
	blf.position(font.id, px + font.offset, font.offset, 0)
	blf.draw(font.id, text) 
Example #21
Source File: polystrips_draw.py    From retopology-polystrips with GNU General Public License v2.0 5 votes vote down vote up
def draw_gedge_text(gedge,context, text):
    l = len(gedge.cache_igverts)
    if l > 4:
        n_quads = math.floor(l/2) + 1
        mid_vert_ind = math.floor(l/2)
        mid_vert = gedge.cache_igverts[mid_vert_ind]
        position_3d = mid_vert.position + 1.5 * mid_vert.tangent_y * mid_vert.radius
    else:
        position_3d = (gedge.gvert0.position + gedge.gvert3.position)/2
    
    position_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d,position_3d)
    txt_width, txt_height = blf.dimensions(0, text)
    blf.position(0, position_2d[0]-(txt_width/2), position_2d[1]-(txt_height/2), 0)
    blf.draw(0, text) 
Example #22
Source File: ops.py    From Screencast-Keys with GNU General Public License v3.0 5 votes vote down vote up
def draw_text_background(text, font_id, x, y, background_color):
    width = blf.dimensions(font_id, text)[0]
    height = blf.dimensions(font_id, string.printable)[1]
    margin = height * 0.2

    draw_rect(x, y - margin, x + width, y + height - margin, background_color) 
Example #23
Source File: ops.py    From Screencast-Keys with GNU General Public License v3.0 5 votes vote down vote up
def get_text_offset_for_alignment(cls, font_id, text, context):
        tw = blf.dimensions(font_id, text)[0]

        return cls.get_offset_for_alignment(tw, context) 
Example #24
Source File: utils.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(self, context):
    font_id = 0  # XXX, need to find out how best to get this.

    offset = 10
    text_height = 10
    text_length = int(len(self.mouse_text) * 7.3)
    
    if self.header_text != "":
        blf.size(font_id, 17, 72)
        text_w, text_h = blf.dimensions(font_id,self.header_text)
        blf.position(font_id, context.area.width/2 - text_w/2, context.area.height - 50, 0)
        blf.draw(font_id, self.header_text)

    # 50% alpha, 2 pixel width line
    if self.mouse_text != "":
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
        bgl.glLineWidth(10)
    
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2i(self.mouse_loc[0]-offset-5, self.mouse_loc[1]+offset)
        bgl.glVertex2i(self.mouse_loc[0]+text_length-offset, self.mouse_loc[1]+offset)
        bgl.glVertex2i(self.mouse_loc[0]+text_length-offset, self.mouse_loc[1]+offset+text_height)
        bgl.glVertex2i(self.mouse_loc[0]-offset-5, self.mouse_loc[1]+offset+text_height)
        bgl.glEnd()
        
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        blf.position(font_id, self.mouse_loc[0]-offset, self.mouse_loc[1]+offset, 0)
        blf.size(font_id, 15, 72)
        blf.draw(font_id, self.mouse_text)
        
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #25
Source File: view.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw_exp_strings(self, font_id, ofsx, ofsy, minwidth=40, \
						 pertition=',  ', start='', end='',
						 col=None, errcol=None):
		if start:
			if col:
				bgl.glColor4f(*col)
			blf.position(font_id, ofsx, ofsy, 0)
			blf.draw(font_id, start)
			text_width, text_height = blf.dimensions(font_id, start)
			ofsx += text_width
		for i, string in enumerate(self.exp_strings):
			value = self.get_exp_value(i)
			if col and value is not None:
				bgl.glColor4f(*col)
			elif errcol and value is None:
				bgl.glColor4f(*errcol)
			name = self.exp_names[i]
			text = name.format(exp=string)
			if len(self.exp_strings) > 1 and 0 < i < len(exp_strings) - 1:
				text = text + pertition
			blf.position(font_id, ofsx, ofsy, 0)
			blf.draw(font_id, text)
			text_width, text_height = blf.dimensions(font_id, text)
			text_width = max(minwidth, text_width)
			# caret
			if i == self.caret[0]:
				if col:
					bgl.glColor4f(*col)
				t = name.split('{')[0] + string[:self.caret[1]]
				t_width, t_height = blf.dimensions(font_id, t)
				x = ofsx + t_width
				glRectf(x, ofsy - 4, x + 1, ofsy + 14)
			ofsx += text_width
			if end and i == len(self.exp_strings) - 1:
				if col:
					bgl.glColor4f(*col)
				blf.position(font_id, ofsx, ofsy, 0)
				blf.draw(font_id, end) 
Example #26
Source File: __init__.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def blf_text_height_max(fontid):
		text_width, text_height = blf.dimensions(fontid,
							  reduce(lambda x, y: x+chr(y), range(32, 127), ''))
		return text_height 
Example #27
Source File: modal_utils.py    From leomoon-lightstudio with GNU General Public License v3.0 5 votes vote down vote up
def _move_buttons(self):
        self.button_exit.loc = Vector((
            self.point_rb.x - self.button_exit.dimensions[0]/4,
            self.point_lt.y - self.button_exit.dimensions[1]/4,
        ))

        self.button_send_to_bottom.loc = Vector((
            self.point_lt.x + self.button_send_to_bottom.dimensions[0]/2,
            self.point_rb.y - self.button_exit.dimensions[1]/2,
        )) 
Example #28
Source File: __init__.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def text_draw_position_along_line(text, font, origin_vec, offset_vec, \
								  text_offset=None):
	# in 2D, retrun 3D
	text_width, text_height = blf.dimensions(font.id, text)
	if text_offset is None:
		text_offset = font.offset
	l = offset_vec.length
	offset_vec_normalized = offset_vec.normalized()
	v = (offset_vec_normalized[0] * (text_width / 2 + text_offset),
		  (offset_vec_normalized[1] * text_height / 2 + text_offset))
	vec = Vector([origin_vec[0] + offset_vec[0] + v[0] - text_width / 2, \
				  origin_vec[1] + offset_vec[1] + v[1] - text_height / 2, 0])
	return vec 
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 set_text(self, text):
        self.text = str(text)
        dims = blf.dimensions(self.font_id, self.text)
        self.w = dims[0]
        dims = blf.dimensions(self.font_id, "dp") # fontheight
        self.h = dims[1] 
Example #30
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)