Example #1
0
def draw_callback_px(self, context):
    from bgl import glColor3f
    font_id = 0  # XXX, need to find out how best to get this.
    blf.size(font_id, 12, 72)

    data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()

    if not data_matrix and not data_quat and not data_euler and not data_vector and not data_vector_array:

        # draw some text
        glColor3f(1.0, 0.0, 0.0)
        blf.position(font_id, 180, 10, 0)
        blf.draw(font_id, "Python Console has no mathutils definitions")
        return

    glColor3f(1.0, 1.0, 1.0)

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

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

    # vars for projection
    perspective_matrix = region3d.perspective_matrix.copy()

    def draw_text(text, vec):
        vec_4d = vec.to_4d()
        vec_4d *= perspective_matrix
        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)

    # points
    if data_vector:
        for key, vec in data_vector.items():
            draw_text(key, vec)

    # lines
    if data_vector_array:
        for key, vec in data_vector_array.items():
            draw_text(key, vec[0])

    # matrix
    if data_matrix:
        for key, mat in data_matrix.items():
            draw_text(key, mat[3])

    if data_quat:
        loc = context.scene.cursor_location.copy()
        for key, mat in data_quat.items():
            draw_text(key, loc)

    if data_euler:
        loc = context.scene.cursor_location.copy()
        for key, mat in data_euler.items():
            draw_text(key, loc)
Example #2
0
 def text_line(fx, fy, reduce, c, str):
     bgl.glColor4f(c[0], c[1], c[2], c[3])
     blf.position(0, fx, fy, 0)
     blf.draw(0, str)
     if reduce:
         fy -= 20
     return fy
Example #3
0
 def __render_text(size, x, y, s):
     # フォントサイズを指定
     blf.size(0, size, 72)
     # 描画位置を指定
     blf.position(0, x, y, 0)
     # テキストを描画
     blf.draw(0, s)
Example #4
0
File: font.py Project: DCubix/Compz
	def draw(self, text, x, y):
		if self.shadowed:
			blf.enable(self.id, blf.SHADOW)
			blf.shadow_offset(self.id, self.shadow_offset[0],
				self.shadow_offset[1])
			blf.shadow(self.id, 3, 0, 0, 0, 0.8)
		else:
			blf.disable(self.id, blf.SHADOW)

		_, h = self.measure("E]")

		blf.position(self.id, x, -y, 0)
		blf.size(self.id, int(self.size), 72)

		glPushMatrix()
		glLoadIdentity()
		# horrible hack for issue #1
		if Font.first:
			glTranslatef(0, h / 2 + 4, 0)
			Font.first = False
		else:
			glTranslatef(0, h, 0)
		glScalef(1, -1, 1)
		blf.draw(self.id, text)
		glPopMatrix()

		if self.shadowed:
			blf.disable(self.id, blf.SHADOW)
Example #5
0
def draw_callback_px(self, context):
    """Draw on the viewports"""
    # BLF drawing routine
    font_id = font_info["font_id"]
    blf.position(font_id, 2, 80, 0)
    blf.size(font_id, 50, 72)
    blf.draw(font_id, "Hello World")
def draw_rectangle_callback_px(not_used):
    import blf

    if len(bpy.data.movieclips) < 1:
        return

    scene = bpy.context.scene
    movieclip = bpy.data.movieclips[0]

    region, width, height = get_clipeditor_region()
    if not region:
        return

    viewport = Buffer(GL_INT, 4)
    glGetIntegerv(GL_VIEWPORT, viewport)

    # set identity matrices
    view_setup()

    draw_rectangle(region, width, height, 1.0)

    # restore opengl defaults
    view_reset(viewport)
    glColor4f(1.0, 1.0, 1.0, 1.0)


    # draw some text
    font_id = 0

    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, "Movie Clip: {0}".format(movieclip.name))
    def draw_callback_px(self, context):
        if context.region.id != self.region_id:
            return
        posx = 70
        posy1 = 30
        posy2 = 50
        text_interval = 5
        font_id = 0
        blf.size(font_id, 11, context.user_preferences.system.dpi)
        bgl.glEnable(bgl.GL_BLEND)
        if self.changing_mgtype:
            bgl.glColor4f(1.0, 1.0, 0.0, 1.0)
        else:
            bgl.glColor4f(1.0, 1.0, 1.0, 1.0)

        # draw origin
        bgl.glLineWidth(2)
        radius = path_threthold
        radius2 = radius + 5
        x, y, z = self.path[0]
        bgl.glBegin(bgl.GL_LINES)
        for i in range(4):
            r = math.pi / 2 * i + math.pi / 4
            bgl.glVertex2f(x + radius * math.cos(r), y + radius * math.sin(r))
            bgl.glVertex2f(x + radius2 * math.cos(r),
                           y + radius2 * math.sin(r))
        bgl.glEnd()
        bgl.glLineWidth(1)

        # draw lines
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glLineStipple(1, int(0b101010101010101))  # (factor, pattern)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for v in self.path:
            bgl.glVertex2f(v[0], v[1])
        bgl.glEnd()
        bgl.glLineStipple(1, 1)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)

        # draw txt
        if self.action or self.mgitem:
            x = posx
            for txt in self.action:
                blf.position(font_id, x, posy1, 0)
                blf.draw(font_id, txt)
                text_width, text_height = blf.dimensions(font_id, txt)
                x += text_width + text_interval
            if self.mgitem:
                blf.position(font_id, posx, posy2, 0)
                blf.draw(font_id, self.mgitem.name)
        else:
            #blf.position(font_id, posx, posy2, 0)
            #blf.draw(font_id, '[Mouse Gesture]')
            pass

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        blf.size(0, 11, context.user_preferences.system.dpi)
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
Example #9
0
def draw_text(text, x, y, size, color=(1, 1, 1, 0.5)):
    font_id = 0
    # bgl.glColor4f(*color)
    blf.color(font_id, color[0], color[1], color[2], color[3])
    blf.position(font_id, x, y, 0)
    blf.size(font_id, size, 72)
    blf.draw(font_id, text)
Example #10
0
def draw_text(text, position, align="LEFT"):
    """Draw 12pt white text at position (3D-Vector) aligned to the left"""
    pos = to_screen_coord(position)
    if pos is None:
        # we cannot draw because the point is not on the screen
        return

    # [PART VI]
    # BRIDGEKEEPER: Hee hee heh. Stop! What... is your name?
    # ARTHUR: It is 'Arthur', King of the Britons.
    # BRIDGEKEEPER: What... is your quest?
    # ARTHUR: To draw text on the screen.
    font_id = 0
    size = 12
    color = (1.0, 1.0, 1.0, 1.0)
    bgl.glColor4f(*color)
    blf.size(font_id, size, 72)

    if align == "CENTER":
        # get length of text, place text .5 of length to the left of the coord.
        text_width, text_height = blf.dimensions(font_id, text)
        pos.x -= text_width / 2

    blf.position(font_id, pos.x, pos.y, 0)

    # BRIDGEKEEPER: What... is the OpenGL command for drawing text?
    # ARTHUR: What do you mean? Blender's bfl module can do that for me!
    # BRIDGEKEEPER: Huh? I-- I didn't know that. Auuuuuuuugh!

    blf.draw(font_id, text)
Example #11
0
def draw_text(text, font_id, vec, region_data, x_offset=0, y_offset=0):
    """

    :param text:
    :type text:
    :param vec:
    :type vec:
    :param font_id:
    :type font_id:
    :param region_data: (region3d_perspective_matrix, region2d_mid_width, region2d_mid_height)
    :type region_data: tuple
    :param x_offset:
    :type x_offset:
    :param y_offset:
    :type y_offset:
    :return:
    :rtype:
    """
    vec_4d = region_data[0] * vec.to_4d()
    if vec_4d.w > 0.0:
        x = region_data[1] + region_data[1] * (vec_4d.x / vec_4d.w)
        y = region_data[2] + region_data[2] * (vec_4d.y / vec_4d.w)

        blf.position(font_id, x + 15.0 + x_offset, y - 4.0 + y_offset, 0.0)
        blf.draw(font_id, text)
	def redraw(self):

		drawregion = bpy.context.region

		rv3d = self.rv3ds[drawregion]
		vec = self.originvert.co.copy()
		vec.rotate(self.selobj.matrix_world)
		vec.rotate(self.selobj.matrix_world)
		self.space3d.cursor_location =  vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()

		bgl.glColor3f(1.0, 1.0, 0)
		bgl.glBegin(bgl.GL_POLYGON)
		x, y = self.getscreencoords(Vector(self.originvert.co), drawregion, rv3d)
		bgl.glVertex2f(x-2, y-2)
		bgl.glVertex2f(x-2, y+2)
		bgl.glVertex2f(x+2, y+2)
		bgl.glVertex2f(x+2, y-2)
		bgl.glEnd()

		bgl.glColor3f(1, 1, 0.7)
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, self.region.width, 0, self.region.height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
		blf.position(0, self.region.width/2 - 80, self.region.height - 20, 0)
		blf.size(0, 12, 72)
		blf.draw(0, "FastOrigin :  Enter confirms - ESC cancels")
Example #13
0
	def text( self, text, arg1=0, arg2=0, arg3=0 ):
		x = 0
		y = 0
		z = 0
		rx = 0
		ry = 0
		rz = 0

		if type( arg1 ) is mathutils.Vector():
			x = arg1.x
			y = arg1.y
			z = arg1.z
			if type( arg2 ) is mathutils.Vector():
				rx = arg2.x
				ry = arg2.y
				rz = arg2.z

		elif type( arg1 ) is bge.types.KX_GameObject or type( arg1 ) is str:
			if type( arg1 ) is str:
				arg1 = self.getObjectByName( arg1 )
			if arg1 is not 0:
				o = self.getPosition( arg1 )
				x = o.x
				y = o.y
				z = o.z
				# translation vector
				if type( arg2 ) is mathutils.Vector():
					x += arg2.x
					y += arg2.y
					z += arg2.z
				# rotation vector
				if type( arg3 ) is mathutils.Vector():
					rx = arg3.x
					ry = arg3.y
					rz = arg3.z
		
		elif type( arg1 ) is float and type( arg2 ) is float and type( arg3 ) is float:
			x = arg1
			y = arg2
			z = arg3

		elif type( arg1 ) is int and type( arg2 ) is int and type( arg3 ) is int:
			x = arg1
			y = arg2
			z = arg3
		
		width = bge.render.getWindowWidth()
		height = bge.render.getWindowHeight()
		ratiow = 1./width
		ratioh = 1./height
		bgl.glPushMatrix()
		bgl.glTranslatef( x,y,z )
#TODO transform angles to matrix!
		# bgl.glRotate( rx,ry,rz )
		bgl.glScalef( ratiow, ratioh, 0 )
		blf.position( self.font, 0,0,0 )
		blf.size( self.font, self.tsize, 300 )
		bgl.glColor3f( self.tcolor.x, self.tcolor.y, self.tcolor.z )
		blf.draw( self.font, text )
		bgl.glPopMatrix()
Example #14
0
def draw_callback_px(self, context):
    wm = context.window_manager
    sc = context.scene

    if not wm.polycount_run:
        return

    font_size  = sc.polycount_font_size
    pos_x, pos_y = get_display_location(context)

    # draw text in the 3d-view
    # ========================
    blf.size(0, sc.polycount_font_size, 72)
    r, g, b = sc.polycount_font_color
    bgl.glColor3f(r, g, b)

    view3dId = get_space_id(context.space_data)

    visible_tri_count = PolyCountOperator.visible_triangle_count.get(view3dId, -1)

    if visible_tri_count > -1:
        text = "All: " + format(visible_tri_count, 'd') + "triangles"
        text1height = blf.dimensions(0, text)[1]

        blf.position(0, pos_x, pos_y - text1height, 0)
        blf.draw(0, text)

    selection_tri_count = PolyCountOperator.selection_triangle_count.get(view3dId, -1);

    if selection_tri_count > 0:
        text = "Selection: " + format(selection_tri_count, ',d') + " triangles"
        text2height = blf.dimensions(0, text)[1]

        blf.position(0, pos_x, pos_y - text1height - text2height - 5, 0)
        blf.draw(0, text)
Example #15
0
def draw_text(x_pos, y_pos, display_text, rgb, fsize, right=False):
    gap = 12
    font_id = 0
    blf.size(font_id, fsize, 72)
    # height of one line
    mwidth, mheight = blf.dimensions(font_id, "Tp")  # uses high/low letters
    # split lines
    mylines = display_text.split("|")
    idx = len(mylines) - 1
    maxwidth = 0
    maxheight = len(mylines) * mheight
    # -------------------
    # Draw all lines
    # -------------------
    for line in mylines:
        text_width, text_height = blf.dimensions(font_id, line)
        if right is True:
            newx = x_pos - text_width - gap
        else:
            newx = x_pos
        # calculate new Y position
        new_y = y_pos + (mheight * idx)
        # Draw
        blf.position(font_id, newx, new_y, 0)
        bgl.glColor4f(rgb[0], rgb[1], rgb[2], rgb[3])
        blf.draw(font_id, " " + line)
        # sub line
        idx -= 1
        # saves max width
        if maxwidth < text_width:
            maxwidth = text_width

    return maxwidth, maxheight
Example #16
0
def draw_callback_px(self, context):
    scene = context.scene

    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, 18, 72)
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)

    # Shorten / cut off milliseconds
    time_total = str(timedelta(seconds = timer["total"]))
    pos = time_total.rfind(".")
    if pos != -1:
        time_total = time_total[0:pos+3]

    time_estimated = str(timedelta(seconds = (timer["average"] * (scene.frame_end - scene.frame_current))))
    pos = time_estimated.rfind(".")
    if pos != -1:
        time_estimated = time_estimated[0:pos]


    blf.draw(font_id, "Total render time " + time_total)
    if timer["is_rendering"] and scene.frame_current != scene.frame_start:
        blf.position(font_id, 15, 12, 0)
        blf.draw(font_id, "Estimated completion: " + time_estimated)

    # restore defaults
    blf.disable(font_id, blf.SHADOW)
Example #17
0
def general_func_callback(self,context):
    aspect, mid = menu_utils.view3d_get_size_and_mid(context)
        # draw some text
    blf.position(0, mid[0], mid[1]+100, 0)
    blf.size(0, 20, 72)
    blf.draw(0, self.message)
    menu_utils.blf_text_wrap(self.help, self.wrap, 0, 12 , 76, 10, aspect[1]-30)
def draw_callback_px(n_id, data):

    space = bpy.context.space_data
  
    ng_view = space.edit_tree
    # ng_view can be None
    if not ng_view:
        return
    ng_name = space.edit_tree.name
    if not (data['tree_name'] == ng_name):
        return
    if not isinstance(ng_view, node_tree.SverchCustomTree):
        return

    lines = data.get('content', 'no data')
    x, y = data.get('location', (120, 120))
    color = data.get('color', (0.1, 0.1, 0.1))
    font_id = 0
    text_height = 13

    # why does the text look so jagged?
    blf.size(font_id, text_height, 72)  # should check prefs.dpi
    bgl.glColor3f(*color)
    # x = 30  # region.width
    # y = region.height - 40
    ypos = y

    for line in lines:
        blf.position(0, x, ypos, 0)
        blf.draw(0, line)
        ypos -= (text_height * 1.3)
Example #19
0
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 #20
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):

    for n, area in enumerate(self.areas):
        if context.area.x == area.x and context.area.y == area.y:  #then this is where our mouse is
            
            font_id = 0  # XXX, need to find out how best to get this.
            height = context.region.height
            width = context.region.width
            dims = blf.dimensions(0, self.messages[n])
            #blf.position(font_id, 10, height - 10 - dims[1], 0)  #top left
            blf.position(font_id, width - 10 - 2* dims[0], 10 + dims[1]/2, 0)
            
            blf.size(font_id, 20, 72)
            blf.draw(font_id, self.messages[n])
        
            if (self.mouse_raw[0] > area.x and self.mouse_raw[0] < area.x + area.width) and \
                (self.mouse_raw[1] > area.y and self.mouse_raw[1] < area.y + area.height):
                #label the mouse
                dims = blf.dimensions(0,'MOUSE %i' %n)
                x = self.mouse_region_coord[0] - .5 * dims[0]
                y = self.mouse_region_coord[1] + dims[1]
                blf.position(font_id,x,y,0)
                blf.draw(font_id,'MOUSE %i' % n)
        
    
            if len(self.area_data[n]):
                N = len(self.areas)
                color = (n/N, .5*n/N, (1-n/N), 1)
                draw_3d_points_specific_region(context.region, context.space_data.region_3d, self.area_data[n], color, 3)
Example #22
0
    def draw_index(rgb, rgb2, index, vec, text=''):

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

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

        if draw_bg:
            polyline = get_points(index)

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

        ''' draw text '''
        txt_width, txt_height = blf.dimensions(0, index)
        bgl.glColor4f(*rgb)
        blf.position(0, x - (txt_width / 2), y - (txt_height / 2), 0)
        blf.draw(0, index)
def draw_callback(self, context):
    # polling
    if context.mode == 'EDIT_MESH':
        return
    # retrieving ID property data
    try:
        #print(context.scene['GamePropsVisualiser'])
        texts = context.scene['GamePropsVisualiser']
        
    except:
        return
    if not texts:
        return
    
    # 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
Example #24
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)
Example #25
0
def write_interaction_status():
    """
    Write the interaction status on Screen
    The status is stored in a property
    """
    cam = logic.getCurrentScene().active_camera

    # get the suffix of the human to reference the right objects
    suffix = cam.name[-4:] if cam.name[-4] == "." else ""
    
    hand = objects['Hand_Grab.R' + suffix]
    
    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    blf.size(font_id, int(windowHeight*0.04), 72)
    # draw a black shadow around the text
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
    blf.position(font_id, windowWidth*0.4, windowHeight*0.4,0)
    blf.draw(font_id, hand['Status'])
Example #26
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)
Example #27
0
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)
 def draw(self,context, settings):
     '''
     setings are the addon preferences for contour tools
     '''
     
     debug = settings.debug
     #settings = context.user_preferences.addons['contour_tools'].preferences
     
     #this should be moved to only happen if the view changes :-/  I'ts only
     #a few hundred calcs even with a lot of lines. Waste not want not.
     if self.head.world_position:
         self.head.screen_from_world(context)
     if self.tail.world_position:
         self.tail.screen_from_world(context)
     if self.plane_tan.world_position:
         self.plane_tan.screen_from_world(context)
         
     
     #draw connecting line
     points = [(self.head.x,self.head.y),(self.tail.x,self.tail.y)]
     if settings.show_edges:
         contour_utilities.draw_polyline_from_points(context, points, (0,.2,1,1), settings.line_thick, "GL_LINE_STIPPLE")
     
     #draw the two handles
     contour_utilities.draw_points(context, points, self.head.color, settings.handle_size)
     
     #draw the current plane point and the handle to change plane orientation
     if self.plane_pt:
         point1 = location_3d_to_region_2d(context.region, context.space_data.region_3d, self.plane_pt)
         point2 = (self.plane_tan.x, self.plane_tan.y)
         if settings.show_edges:
             contour_utilities.draw_polyline_from_points(context, [point1,point2], (0,.2,1,1), settings.line_thick, "GL_LINE_STIPPLE")
         contour_utilities.draw_points(context, [point2], self.plane_tan.color, settings.handle_size)
         contour_utilities.draw_points(context, [point1], self.head.color, settings.handle_size)
     
     #draw the raw contour vertices
     if (self.verts and self.verts_simple == []) or (debug > 0 and settings.show_verts):
         contour_utilities.draw_3d_points(context, self.verts, (0,1,.2,1), settings.raw_vert_size)
     
     #draw the simplified contour vertices and edges (rings)    
     if self.verts_simple:
         points = self.verts_simple.copy()
         if 0 in self.eds[-1]:
             points.append(self.verts_simple[0])
         
         if settings.show_ring_edges:
             contour_utilities.draw_polyline_from_3dpoints(context, points, (0,1,.2,1), settings.line_thick,"GL_LINE_STIPPLE")
         contour_utilities.draw_3d_points(context, self.verts_simple, (0,.2,1,1), settings.vert_size)
         if debug:
             if settings.vert_inds:
                 for i, point in enumerate(self.verts):
                     loc = location_3d_to_region_2d(context.region, context.space_data.region_3d, point)
                     blf.position(0, loc[0], loc[1], 0)
                     blf.draw(0, str(i))
                 
             if settings.simple_vert_inds:    
                 for i, point in enumerate(self.verts_simple):
                     loc = location_3d_to_region_2d(context.region, context.space_data.region_3d, point)
                     blf.position(0, loc[0], loc[1], 0)
                     blf.draw(0, str(i))
def draw_callback_px(self, context):
    #print("callback_px")
    # Maybe print a nice red circle in some corner

    bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

    FONT_RGBA = (0.8, 0.1, 0.1, 0.5)
    bgl.glColor4f(*FONT_RGBA)

    font_size = 11
    DPI = 72

    blf.size(0, font_size, DPI)
    msg = "Logging..."
    
    msg_w,msg_h = blf.dimensions(0, msg)

    pos_x = context.region.width - msg_w
    pos_y = font_size / 2
    blf.position(0, pos_x, pos_y, 0)
    #blf.position(0, 10, 10, 0)

    blf.draw(0, msg)

    bgl.glPopAttrib()

    pass
Example #30
0
    def drawLines(self):
        baseLineOffset = blf.dimensions(font, "V")[1]

        glColor4f(0, 0, 0, 1)
        for i, line in enumerate(self.lines):
            blf.position(font, self.boundary.left, self.boundary.top - i * self.lineHeight - baseLineOffset, 0)
            blf.draw(font, line)
Example #31
0
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.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    # BLF drawing routine
    font_id = logic.font_id
    blf.position(font_id, (width * 0.2), (height * 0.3), 0)
    blf.size(font_id, 50, 72)
    blf.draw(font_id, "Hello World")
Example #32
0
    def draw_text(self, ctx):
        font_id = 0
        font_size = 16
        dpi = ctx.preferences.system.dpi

        # pos = self.matrix_world @ Vector((0, 0, 0, 1))
        # pos = Vector((0, 0, 0.5))
        # region = ctx.region
        # region3d = ctx.region_data
        # pos = view3d_utils.location_3d_to_region_2d(region, region3d, pos)

        # text = self.text_label

        blf.size(font_id, font_size, dpi)
        blf.position(font_id, 0, 0, 0)
        blf.color(font_id, *self.color, self.alpha)
        blf.draw(font_id, "ABC")
Example #33
0
def draw_text(context, location, NUM_VERTS):

    bgl.glColor4f(1.0, 1.0, 1.0, 0.8)
    xpos, ypos = location
    font_id = 0
    blf.size(font_id, 12, 72)  # fine tune
    blf.position(font_id, location[0], location[1], 0)

    num_edges = str(NUM_VERTS - 1)
    if num_edges == str(1):
        postfix = " edge"
    else:
        postfix = " edges"

    display_text = str(NUM_VERTS) + " vert fillet, " + num_edges + postfix
    blf.draw(font_id, display_text)
    return
Example #34
0
def draw_text(mouse, text, color):
    dpi = int(bpy.context.user_preferences.system.pixel_size)

    bgl.glEnable(bgl.GL_BLEND)
    font_id = 0  # XXX, need to find out how best to get this.
    # draw some text
    bgl.glColor4f(0, 0, 0, 0.75)
    blf.blur(font_id, 5)
    blf.position(font_id, mouse[0] + 10 * dpi, mouse[1] - 20 * dpi, 0)
    blf.size(font_id, 8 * dpi, 96)
    blf.draw(font_id, text)

    bgl.glEnd()
    bgl.glColor4f(*color)
    blf.blur(font_id, 0)
    blf.draw(font_id, text)
    bgl.glDisable(bgl.GL_BLEND)
Example #35
0
    def draw(self):
        if not self.visible:
            return

        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 #36
0
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)
 def draw_postpixel(self):
     
     region = bpy.context.region
     rv3d = bpy.context.space_data.region_3d
     dpi = bpy.context.preferences.system.dpi
     blf.size(0, 20, dpi) #fond_id = 0
     for i,pt in enumerate(self.b_pts):
         if pt.label:
             if self.selected == i:
                 color = (0,1,1,1)
             else:
                 color = (1,0,0,1)
             #bgl.glColor4f(*color)
             vector2d = view3d_utils.location_3d_to_region_2d(region, rv3d, pt.location)
             if vector2d:
                 blf.position(0, vector2d[0] + 10, vector2d[1] - 5, 0)
                 blf.draw(0, pt.label) #font_id = 0
def write():
    """write on screen - it runs every frame"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

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

    # BLF fun
    font_id = logic.font_id
    blf.position(font_id, (width*0.2), (height*0.3), 0)
    blf.size(font_id, 50, 72)
    blf.draw(font_id, logic.text["text"])
Example #39
0
    def draw(self):
        bgl.glEnable(bgl.GL_BLEND)
        if self.batch_redraw or not self.batch:
            self.update_batch()
        bgl.glLineWidth(self.thickness)
        self.shader.bind()
        self.batch.draw(self.shader)
        bgl.glLineWidth(1)

        for text, location, size, color, dpi in self.text:
            blf.position(0, location[0], location[1], 0)
            blf.size(0, size, dpi)
            blf.color(0, *color)
            blf.shadow(0, 3, *self.font_shadow)
            blf.draw(0, text)

        bgl.glDisable(bgl.GL_BLEND)
def DrawHelp(htext, _uifactor):
    textsize = 14
    # blf.size(0, textsize, 72)
    # get leftbottom corner
    offset = textsize + 40
    columnoffs = 320 * _uifactor
    for line in reversed(htext):
        blf.color(0, 1.0, 1.0, 1.0, 1.0)
        blf.position(0, 60 * _uifactor, offset, 0)
        blf.draw(0, line[0])

        blf.color(0, 1.0, 0.86, 0.0, 1.0)
        textdim = blf.dimensions(0, line[1])
        coloffset = columnoffs - textdim[0]
        blf.position(0, coloffset, offset, 0)
        blf.draw(0, line[1])
        offset += 20 * _uifactor
Example #41
0
    def draw_index(r, g, b, index, center):

        vec = total_mat @ center  # order is important

        # dehomogenise

        vec = mathutils.Vector(
            (vec[0] / vec[3], vec[1] / vec[3], vec[2] / vec[3]))
        x = int(mid_x + vec[0] * width / 2)
        y = int(mid_y + vec[1] * height / 2)

        # bgl.glColorMask(1,1,1,1)
        blf.position(0, x, y, 0)
        if isinstance(index, float):
            blf.draw(0, '{:.2f}'.format(index))
        else:
            blf.draw(0, str(index))
Example #42
0
    def draw(self, highlighted: bool):
        bgl.glEnable(bgl.GL_BLEND)
        if highlighted:
            bgl.glColor4f(0.555, 0.555, 0.555, 0.8)
        else:
            bgl.glColor4f(0.447, 0.447, 0.447, 0.8)

        bgl.glRectf(self.x, self.y, self.x + self.width, self.y + self.height)

        texture = self.icon
        err = texture.gl_load(filter=bgl.GL_NEAREST, mag=bgl.GL_NEAREST)
        assert not err, 'OpenGL error: %i' % err

        bgl.glColor4f(0.0, 0.0, 1.0, 0.5)
        # bgl.glLineWidth(1.5)

        # ------ TEXTURE ---------#
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture.bindcode[0])
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        bgl.glColor4f(1, 1, 1, 1)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2d(0, 0)
        bgl.glVertex2d(self.x + self.icon_margin_x, self.y)
        bgl.glTexCoord2d(0, 1)
        bgl.glVertex2d(self.x + self.icon_margin_x, self.y + ICON_HEIGHT)
        bgl.glTexCoord2d(1, 1)
        bgl.glVertex2d(self.x + self.icon_margin_x + ICON_WIDTH,
                       self.y + ICON_HEIGHT)
        bgl.glTexCoord2d(1, 0)
        bgl.glVertex2d(self.x + self.icon_margin_x + ICON_WIDTH, self.y)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_TEXTURE_2D)
        bgl.glDisable(bgl.GL_BLEND)

        texture.gl_free()

        # draw some text
        font_id = 0
        blf.position(
            font_id,
            self.x + self.icon_margin_x + ICON_WIDTH + self.text_margin_x,
            self.y + ICON_HEIGHT * 0.5 - 0.25 * self.text_height, 0)
        blf.size(font_id, self.text_height, self.text_width)
        blf.draw(font_id, self.label_text)
Example #43
0
    def _draw(self):
        """Display the text"""
        linespacing = 1.2
        blf.size(self.fontid, self.pt_size, 72)

        glColor4f(self.color[0], self.color[1], self.color[2], self.color[3])

        for i, txt in enumerate([i for i in self._text.split('\n')]):
            blf.position(self.fontid, self.position[0],
                         self.position[1] - (self.size[1] * i * linespacing),
                         0)
            blf.draw(self.fontid, txt.replace('\t', '    '))
            self.dimension = list(
                blf.dimensions(self.fontid, txt.replace('\t', '    ')))[:]

        #draw children now
        Widget._draw(self)
Example #44
0
def draw_timer(context, pos_x, pos_y):

    sc = context.scene
    #calculate overall time
    overall_time = datetime.timedelta(
        seconds=int(time.time() - ScreencastKeysStatus.overall_time[0]))

    timer_color_r, timer_color_g, timer_color_b, timer_color_alpha = sc.screencast_keys_timer_color
    pos_x = context.region.width - (sc.screencast_keys_timer_size * 12) + 12
    pos_y = 10

    #draw time
    blf.size(0, sc.screencast_keys_timer_size, 72)
    blf.position(0, pos_x, pos_y, 0)
    bgl.glColor4f(timer_color_r, timer_color_g, timer_color_b,
                  timer_color_alpha)
    blf.draw(0, "Elapsed Time: %s" % (overall_time))
Example #45
0
def draw_callback_iops_aotf_px(self, context, _uidpi, _uifactor):
    prefs = bpy.context.preferences.addons['InteractionOps'].preferences
    tColor = prefs.text_color
    tKColor = prefs.text_color_key
    tCSize = prefs.text_size
    tCPosX = prefs.text_pos_x
    tCPosY = prefs.text_pos_y
    tShadow = prefs.text_shadow_toggle
    tSColor = prefs.text_shadow_color
    tSBlur = prefs.text_shadow_blur
    tSPosX = prefs.text_shadow_pos_x
    tSPosY = prefs.text_shadow_pos_y

    iops_text = (
        ("Face edge index", str(self.get_edge_idx(self.counter))),
        ("Align to axis", str(self.axis_rotate)),
    )

    # FontID
    font = 0
    blf.color(font, tColor[0], tColor[1], tColor[2], tColor[3])
    blf.size(font, tCSize, _uidpi)
    if tShadow:
        blf.enable(font, blf.SHADOW)
        blf.shadow(font, int(tSBlur), tSColor[0], tSColor[1], tSColor[2],
                   tSColor[3])
        blf.shadow_offset(font, tSPosX, tSPosY)
    else:
        blf.disable(0, blf.SHADOW)

    textsize = tCSize
    # get leftbottom corner
    offset = tCPosY
    columnoffs = (textsize * 10) * _uifactor
    for line in reversed(iops_text):
        blf.color(font, tColor[0], tColor[1], tColor[2], tColor[3])
        blf.position(font, tCPosX * _uifactor, offset, 0)
        blf.draw(font, line[0])

        blf.color(font, tKColor[0], tKColor[1], tKColor[2], tKColor[3])
        textdim = blf.dimensions(0, line[1])
        coloffset = columnoffs - textdim[0] + tCPosX
        blf.position(0, coloffset, offset, 0)
        blf.draw(font, line[1])
        offset += (tCSize + 5) * _uifactor
Example #46
0
def text(pos2d: Float2,
         display_text: typing.Union[str, typing.List[str]],
         rgba: Float4 = (1.0, 1.0, 1.0, 1.0),
         fsize=12,
         align='L'):
    """Draw text with the top-left corner at 'pos2d'."""

    dpi = bpy.context.preferences.system.dpi
    gap = 12
    x_pos, y_pos = pos2d
    font_id = 0
    blf.size(font_id, fsize, dpi)

    # Compute the height of one line.
    mwidth, mheight = blf.dimensions(font_id,
                                     "Tp")  # Use high and low letters.
    mheight *= 1.5

    # Split text into lines.
    if isinstance(display_text, str):
        mylines = display_text.split("\n")
    else:
        mylines = display_text
    maxwidth = 0
    maxheight = len(mylines) * mheight

    for idx, line in enumerate(mylines):
        text_width, text_height = blf.dimensions(font_id, line)
        if align == 'C':
            newx = x_pos - text_width / 2
        elif align == 'R':
            newx = x_pos - text_width - gap
        else:
            newx = x_pos

        # Draw
        blf.position(font_id, newx, y_pos - mheight * idx, 0)
        blf.color(font_id, rgba[0], rgba[1], rgba[2], rgba[3])
        blf.draw(font_id, " " + line)

        # saves max width
        if maxwidth < text_width:
            maxwidth = text_width

    return maxwidth, maxheight
Example #47
0
    def draw_text_box(
            self, x, y, text, origin="lower_left",
            col_back=None, col_inner=None, col_outline=None, col_text=None,
            back_show_shaded=False, back_shadetop=0, back_shadedown=0,
            inner_show_shaded=False, inner_shadetop=0, inner_shadedown=0,
            is_mono=False):
        """
        :param origin: x, yの基準がboxのどこにあるか。
                enum in ["upper", "upper_left", "left", "lower_left",
                         "lower", "lower_right", "right", "upper_right"]
        :type text: str
        """
        prefs = self.prefs
        widget_unit = self.widget_unit

        _, w, h = self.gen_text_position(text, is_mono).send(None)
        if "right" in origin:
            x -= w
        elif "left" not in origin:  # ["upper", "lower"]
            x -= w / 2
        if "upper" in origin:
            y -= h
        elif "lower" not in origin:  # ["left", "right"]
            y -= h / 2

        self.draw_box(x, y, w, h, col_back, col_inner, col_outline,
                      back_show_shaded, back_shadetop, back_shadedown,
                      inner_show_shaded, inner_shadetop, inner_shadedown)

        if is_mono:
            font_id = prefs.font_id_mono
        else:
            font_id = prefs.font_id
        lines = text.split("\n")
        if col_text:
            bgl.glColor4f(*col_text)
        g = self.gen_text_position(lines[0], is_mono)
        y2 = None
        for line in lines:
            if y2 is None:
                y2, _, _ = g.send(None)
            else:
                y2, _, _ = g.send(line)
            blf.position(font_id, x + widget_unit / 2, y + h + y2, 0)
            vagl.blf_draw(prefs.font_id, line)
def cursor_handler(context):

    global ticks
    global buf

    bgl.glGetIntegerv(bgl.GL_VIEWPORT, buf)
    width = buf[2]

    t = localtime()
    m = t[4]
    h = (t[3] % 12) + m / 60.0  # fractional hours
    twopi = 6.283

    # draw text
    font_id = 0
    blf.position(font_id, width - 100, 15, 0)
    blf.size(font_id, 12, 72)  # 12pt text at 72dpi screen
    blf.draw(font_id, strftime("%H:%M:%S", t))

    # 50% alpha, 2 pixel lines
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glLineWidth(2)

    # draw a clock in the lower right hand corner
    startx, starty = (width - 22.0, 22.0)
    smallhandx, smallhandy = (startx + 9 * sin(twopi * h / 12),
                              starty + 9 * cos(twopi * h / 12))
    bighandx, bighandy = (startx + 15 * sin(twopi * m / 60),
                          starty + 15 * cos(twopi * m / 60))
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(startx, starty)
    bgl.glVertex2f(bighandx, bighandy)
    bgl.glVertex2f(startx, starty)
    bgl.glVertex2f(smallhandx, smallhandy)
    # twelve small dots
    for x, y in ticks:
        bgl.glVertex2f(startx + 17 * x, starty + 17 * y)
        bgl.glVertex2f(startx + 18 * x, starty + 18 * y)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    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 #50
0
def draw_text(text="",
              position=(0, 0),
              size=200,
              horizontal_align="LEFT",
              vertical_align="BOTTOM",
              color=(0.2, 0.2, 0.2, 1.0),
              font_id=font_id):

    set_text_size(size, font_id)
    dimensions = blf.dimensions(font_id, text)

    if horizontal_align == "CENTER":
        position = (position[0] - dimensions[0] / 2, position[1])
    if vertical_align == "TOP":
        position = (position[0], position[1] - dimensions[1])
    glColor4f(*color)
    blf.position(font_id, int(position[0]), int(position[1]), 0)
    blf.draw(font_id, text)
def draw_callback(self, context):
    # polling
    if context.mode != "EDIT_MESH":
        return
    # retrieving ID property data
    try:
        texts = context.scene["IndexVisualiser"]
    except:
        return
    if not texts:
        return

    # draw
    blf.size(0, 13, 72)
    for i in range(0, len(texts), 7):
        bgl.glColor3f(texts[i], texts[i + 1], texts[i + 2])
        blf.position(0, texts[i + 4], texts[i + 5], texts[i + 6])
        blf.draw(0, str(int(texts[i + 3])))
Example #52
0
def draw_last_operator(context, pos_x, pos_y):

    wm = context.window_manager
    sc = context.scene
    font_color_r, font_color_g, font_color_b, font_color_alpha = sc.screencast_keys_text_color
    pos_x, pos_y = getDisplayLocation(context)

    if wm.operators:
        last_operator = wm.operators[-1].bl_label

        blf.enable(0, blf.SHADOW)
        blf.shadow_offset(0, 1, -1)
        blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.8)
        blf.size(0, sc.screencast_keys_font_size, 36)
        blf.position(0, pos_x - 14, pos_y - 30, 0)
        bgl.glColor4f(font_color_r, font_color_g, font_color_b, font_color_alpha * 0.8)
        blf.draw(0, "Last: %s" % (last_operator))
        blf.disable(0, blf.SHADOW)
Example #53
0
    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)
 def draw_gpatch_info(self, gpatch, context):
     cp,cnt = Vector(),0
     for p,_,_ in gpatch.pts:
         cp += p
         cnt += 1
     cp /= max(1,cnt)
     for i_ges,ges in enumerate(gpatch.gedgeseries):
         l = ges.n_quads
         p,c = Vector(),0
         for gvert in ges.cache_igverts:
             p += gvert.snap_pos
             c += 1
         p /= c
         txt = '%d' % l # '%d %d' % (i_ges,l)
         p2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, cp*0.2+p*0.8)
         txt_width, txt_height = blf.dimensions(0, txt)
         blf.position(0, p2d[0]-(txt_width/2), p2d[1]-(txt_height/2), 0)
         blf.draw(0, txt)
Example #55
0
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 #56
0
    def draw_callback_2d(self, op, context):

        # Draw text for primitive mode
        region = context.region
        text = "- Primitive mode -"

        subtext = self.shape.get_text(context)

        xt = int(region.width / 2.0)

        blf.size(0, 24, 72)
        blf.position(0, xt - blf.dimensions(0, text)[0] / 2, 60, 0)
        blf.draw(0, text)

        blf.size(1, 16, 72)
        blf.color(1, 1, 1, 1, 1)
        blf.position(1, xt - blf.dimensions(1, subtext)[0] / 2, 30, 1)
        blf.draw(1, subtext)
Example #57
0
    def DrawTextS(self,
                  x,
                  y,
                  text,
                  size,
                  color=(1.0, 1.0, 1.0, 1.0),
                  showdowColor=(0.1, 0.1, 0.1, 1.0),
                  font_id=0):
        blf.position(font_id, x, y, 0)
        r, g, b, a = color
        blf.color(font_id, r, g, b, a)
        blf.size(font_id, size, 72)

        sr, sg, sb, sa = showdowColor
        blf.shadow(0, 3, sr, sg, sb, sa)
        blf.enable(0, blf.SHADOW)
        blf.draw(font_id, text)
        blf.disable(0, blf.SHADOW)
    def draw_index(rgb, index, coord):

        vector3d = matrix_world * coord
        x, y = loc3d2d(region, rv3d, vector3d)

        index = str(index)
        polyline = get_points(index)
        ''' draw polygon '''
        bgl.glColor4f(0.103, 0.2, 0.2, 0.2)
        bgl.glBegin(bgl.GL_POLYGON)
        for pointx, pointy in polyline:
            bgl.glVertex2f(pointx + x, pointy + y)
        bgl.glEnd()
        ''' draw text '''
        txt_width, txt_height = blf.dimensions(0, index)
        bgl.glColor3f(*rgb)
        blf.position(0, x - (txt_width / 2), y - (txt_height / 2), 0)
        blf.draw(0, index)
def DynamicNodes_Arrange_DrawCallBack(self, context):
    bgl.glColor4f(0.6, 0.6, 0.7, 1)
    font_id = 0
    blf.size(font_id, 12, 0)
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 3, 0, 0, 0, 1)
    props = context.scene.DynamicNodes_Properties

    blf.position(font_id, 12, context.area.height - 50, 0)
    blf.draw(
        font_id,
        str(min(self.iteration_cnt, props.step1)) + '/' + str(props.step1))
    blf.position(font_id, 12, context.area.height - 70, 0)
    blf.draw(
        font_id,
        str(min(max(self.iteration_cnt - props.step1, 0), props.step2)) + '/' +
        str(props.step2))
    blf.position(font_id, 12, context.area.height - 90, 0)
    blf.draw(
        font_id,
        str(
            min(max(self.iteration_cnt - props.step1 - props.step2, 0),
                props.step3)) + '/' + str(props.step3))
    blf.position(font_id, 12, context.area.height - 110, 0)
    blf.draw(
        font_id,
        str(
            max(self.iteration_cnt - props.step1 - props.step2 - props.step3,
                0)) + '/' + str(props.step4))

    bgl.glBegin(bgl.GL_QUADS)
    bgl.glColor4f(0.7, 0.7, 1.0, 1.0)
    bgl.glVertex2i(8, context.area.height - 128)
    bgl.glVertex2i(52, context.area.height - 128)
    bgl.glVertex2i(52, context.area.height - 142)
    bgl.glVertex2i(8, context.area.height - 142)

    bgl.glColor4f(0.1, 0.1, 0.1, 1.0)
    bgl.glVertex2i(9, context.area.height - 129)
    bgl.glVertex2i(51, context.area.height - 129)
    bgl.glVertex2i(51, context.area.height - 141)
    bgl.glVertex2i(9, context.area.height - 141)

    progress = self.iteration_cnt / (props.step1 + props.step2 + props.step3 +
                                     props.step4)
    bgl.glColor4f(0.7, 0.7, 1.0, 1.0)
    bgl.glVertex2i(10, context.area.height - 130)
    bgl.glVertex2i(int(10 + progress * 40), context.area.height - 130)
    bgl.glVertex2i(int(10 + progress * 40), context.area.height - 140)
    bgl.glVertex2i(10, context.area.height - 140)
    bgl.glEnd()

    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    blf.disable(font_id, blf.SHADOW)
def draw_text(myobj, x_pos, y_pos, display_text, rgb, fsize, right=False):
    gap = 12
    font_id = 0
    blf.size(font_id, fsize, 72)
    # height of one line
    mwidth, mheight = blf.dimensions(font_id, "Tp")  # uses high/low letters

    # Calculate sum groups
    m = 0
    while "<#" in display_text:
        m += 1
        if m > 10:   # limit loop
            break
        i = display_text.index("<#")
        tag = display_text[i:i + 4]
        display_text = display_text.replace(tag, get_group_sum(myobj, tag.upper()))

    # split lines
    mylines = display_text.split("|")
    idx = len(mylines) - 1
    maxwidth = 0
    maxheight = len(mylines) * mheight
    # -------------------
    # Draw all lines
    # -------------------
    for line in mylines:
        text_width, text_height = blf.dimensions(font_id, line)
        if right is True:
            newx = x_pos - text_width - gap
        else:
            newx = x_pos
        # calculate new Y position
        new_y = y_pos + (mheight * idx)
        # Draw
        blf.position(font_id, newx, new_y, 0)
        bgl.glColor4f(rgb[0], rgb[1], rgb[2], rgb[3])
        blf.draw(font_id, " " + line)
        # sub line
        idx -= 1
        # saves max width
        if maxwidth < text_width:
            maxwidth = text_width

    return maxwidth, maxheight