def draw_string(self, color1, color2, left, bottom, text, max_option, divide = 1): """ Draw the text like 'option : key' or just 'option' """ font_id = 0 ui_scale = bpy.context.preferences.system.ui_scale blf.enable(font_id,blf.SHADOW) blf.shadow(font_id, 0, 0.0, 0.0, 0.0, 1.0) blf.shadow_offset(font_id,2,-2) line_height = (blf.dimensions(font_id, "gM")[1] * 1.45) y_offset = 5 # Test if the text is a list formatted like : ('option', 'key') if isinstance(text,list): spacer_text = " : " spacer_width = blf.dimensions(font_id, spacer_text)[0] for string in text: blf.position(font_id, (left), (bottom + y_offset), 0) blf.color(font_id, *color1) blf.draw(font_id, string[0]) blf.position(font_id, (left + max_option), (bottom + y_offset), 0) blf.draw(font_id, spacer_text) blf.color(font_id, *color2) blf.position(font_id, (left + max_option + spacer_width), (bottom + y_offset), 0) blf.draw(font_id, string[1]) y_offset += line_height else: # The text is formatted like : ('option') blf.position(font_id, left, (bottom + y_offset), 0) blf.color(font_id, *color1) blf.draw(font_id, text) y_offset += line_height blf.disable(font_id,blf.SHADOW)
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)
def __render(self, context): prefs = context.user_preferences.addons[__name__].preferences region, space = ShowObjectName.__get_region_space( context, 'VIEW_3D', 'WINDOW', 'VIEW_3D' ) if (region is None) or (space is None): return # オブジェクトの位置にオブジェクト名を表示 objs = [o for o in bpy.data.objects] # オブジェクトの位置座標(3D座標)をリージョン座標(2D座標)に変換 locs_on_screen = [ view3d_utils.location_3d_to_region_2d( region, space.region_3d, o.location ) for o in objs ] blf.shadow(0, 3, 0.1, 0.1, 0.1, 1.0) blf.shadow_offset(0, 1, -1) blf.enable(0, blf.SHADOW) for obj, loc in zip(objs, locs_on_screen): # 表示範囲外なら表示しない if loc is not None: ShowObjectName.__render_message( prefs.font_size_2, loc.x, loc.y, obj.name ) blf.disable(0, blf.SHADOW) # マウスカーソルの位置に向けて発したレイと交差するオブジェクト名を表示 blf.shadow(0, 3, 0.0, 1.0, 0.0, 0.5) blf.shadow_offset(0, 2, -2) blf.enable(0, blf.SHADOW) ShowObjectName.__render_message( prefs.font_size_1, prefs.left_top[0], region.height - prefs.left_top[1], "Intersect" ) blf.disable(0, blf.SHADOW) # ray_castが可能なオブジェクトモード時のみ表示 if context.mode == 'OBJECT': for i, o in enumerate(self.__intersected_objs): ShowObjectName.__render_message( int(prefs.font_size_1 * 0.8), prefs.left_top[0], (region.height - prefs.left_top[1] - int(prefs.font_size_1 * 1.3) - i * int(prefs.font_size_1 * 0.9)), o.name ) else: ShowObjectName.__render_message( int(prefs.font_size_1 * 0.8), prefs.left_top[0], (region.height - prefs.left_top[1] - int(prefs.font_size_1 * 1.3)), "Objectモード以外では利用できません" )
def draw_callback_px(self, context, pos): val = self.cyl_sides hpos, vpos = 64, 64 if pos: hpos = pos - 110 if val: font_id = 0 blf.enable(font_id, 4) blf.position(font_id, hpos, vpos + 64, 0) blf.color(font_id, self.hcol[0], self.hcol[1], self.hcol[2], self.hcol[3]) blf.size(font_id, 20, 72) blf.shadow(font_id, 5, 0, 0, 0, 1) blf.shadow_offset(font_id, 1, -1) blf.draw(font_id, "Cylinder Sides: " + str(val)) blf.size(font_id, 15, 72) blf.position(font_id, hpos, vpos + 40, 0) blf.color(font_id, self.tcol[0], self.tcol[1], self.tcol[2], self.tcol[3]) blf.draw(font_id, "Increment: Mouse Wheel Up / Down") blf.position(font_id, hpos, vpos + 20, 0) blf.draw(font_id, "Apply: LMB, RMB, Esc, Enter or Spacebar") blf.size(font_id, 10, 72) blf.position(font_id, hpos, vpos, 0) blf.color(font_id, self.scol[0], self.scol[1], self.scol[2], self.scol[3]) blf.draw( font_id, "Navigation: Blender (-MMB) or Ind.Std (Alt-) Defaults Pass-Through" ) else: return {'CANCELLED'}
def draw_callback(self, context): init_offset = get_init_display_offset() offset_x = init_offset[0] offset_y = bpy.context.region.height - init_offset[1] area = bpy.context.area tools_region = None header_region = None if area.spaces[0].overlay.show_overlays == False: return for region in area.regions: if region.type == 'TOOLS': tools_region = region elif region.type == 'HEADER': header_region = region if bpy.context.region.y != header_region.y: offset_y -= header_region.height if area.spaces[0].show_region_toolbar and tools_region != None: offset_x += tools_region.width if version >= (2, 90, 0) and area.spaces[0].overlay.show_stats: offset_y -= 108 blf.position(font_id, offset_x, offset_y, 0) blf.size(font_id, font_size, font_dpi) blf.enable(font_id, blf.SHADOW) blf.shadow(font_id, 3, 0, 0, 0, font_shadow_alpha) blf.shadow_offset(font_id, 1, -2) blf.draw(font_id, get_collection_string(bpy.context.view_layer.objects.active))
def _draw_pixels(self, context, depsgraph): scene = depsgraph.scene w = context.region.width h = context.region.height # Draw text area that RenderMan is running. if get_pref('draw_ipr_text', False) and not self.rman_render.rman_is_viewport_rendering: pos_x = w / 2 - 100 pos_y = 20 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, 32, 36) blf.position(0, pos_x, pos_y, 0) blf.color(0, 1.0, 0.0, 0.0, 1.0) blf.draw(0, "%s" % ('RenderMan Interactive Mode Running')) blf.disable(0, blf.SHADOW) if not self.rman_render.rman_is_viewport_rendering: return # Bind shader that converts from scene linear to display space, bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE_MINUS_SRC_ALPHA) self.bind_display_space_shader(scene) self.rman_render.draw_pixels(w, h) self.unbind_display_space_shader() bgl.glDisable(bgl.GL_BLEND)
def displayShadow(): blf.enable(font_id, blf.SHADOW) blf.shadow(font_id, 3, getValue('shadowColor')[0], getValue('shadowColor')[1], getValue('shadowColor')[2], 0.8) blf.shadow_offset(font_id, getValue('shOffsetX'), getValue('shOffsetY'))
def h_draw_text(fid, text, bounds, color, margin=0, font_size=16, text_align=0, vertical_align=0, shadow=False, clip=True): text = str(text) width = render.getWindowWidth() height = render.getWindowHeight() #bgl.glColor4f(*(1, 0, 0, 1)) #h_draw_quad_wire(bounds) if clip: h_clip_begin(bounds) blf.size(fid, font_size, 72) if shadow: blf.enable(fid, blf.SHADOW) blf.shadow(fid, 3, 0.0, 0.0, 0.0, 1.0) blf.shadow_offset(fid, 0, -1) else: blf.disable(fid, blf.SHADOW) bgl.glPushMatrix() # Fix upside-down text =) w, h = blf.dimensions(fid, text) bgl.glTranslated(0.0, h, 0.0) bgl.glScalef(1.0, -1.0, 1.0) bgl.glColor4f(*color) texts = text.split("\n") yn = 0 if vertical_align == 0: yn = margin elif vertical_align == 1: yn = bounds[3]/2-(h*len(texts))/2 elif vertical_align == 2: yn = (bounds[3]-(h*len(texts)))-margin for i in range(len(texts)): texts[i] = texts[i].replace("\t", " ") wl, hl = blf.dimensions(fid, texts[i]) xn = 0 if text_align == 0: xn = margin elif text_align == 1: xn = bounds[2]/2-wl/2 elif text_align == 2: xn = (bounds[2]-wl)-margin blf.position(fid, bounds[0]+xn, -bounds[1]-(i*h)-yn, 1) blf.draw(fid, texts[i]) bgl.glScalef(1.0, 1.0, 1.0) bgl.glPopMatrix() if clip: h_clip_end()
def __render_working_hours(self, context): sc = context.scene props = sc.cwh_props prefs = context.user_preferences.addons[__name__].preferences # 表示するオブジェクトが選択されていない場合は、描画しない if sc.cwh_prop_object == '': return # リージョン幅を取得するため、描画先のリージョンを得る region = CalculateWorkingHours.__get_region( context, 'VIEW_3D', 'WINDOW' ) # 描画先のリージョンへ文字列を描画 if region is not None: # 影の効果を設定 blf.shadow(0, 3, 0.0, 1.0, 0.0, 0.5) # 影の位置を設定 blf.shadow_offset(0, 2, -2) # 影の効果を有効化 blf.enable(0, blf.SHADOW) CalculateWorkingHours.__render_message( int(prefs.font_size * 1.3), prefs.left_top[0], region.height - prefs.left_top[1], "Working Hour" ) # 影の効果を無効化 blf.disable(0, blf.SHADOW) CalculateWorkingHours.__render_message( prefs.font_size, prefs.left_top[0], region.height - int(prefs.left_top[1] + prefs.font_size * 1.5), "Object: " + sc.cwh_prop_object ) CalculateWorkingHours.__render_message( prefs.font_size, prefs.left_top[0], region.height - int( prefs.left_top[1] + prefs.font_size * (1.5 + 2.5) ), "Object Mode: " + CalculateWorkingHours.__make_time_fmt( props.working_hour_db[sc.cwh_prop_object]['OBJECT'] ) ) CalculateWorkingHours.__render_message( prefs.font_size, prefs.left_top[0], region.height - int( prefs.left_top[1] + prefs.font_size * (1.5 + 4.0) ), "Edit Mode: " + CalculateWorkingHours.__make_time_fmt( props.working_hour_db[sc.cwh_prop_object]['EDIT'] ) )
def draw_ui(self, context, _uidpi, _uifactor): def get_target(): if self.target == context.scene.cursor: return "3D Cursor" elif self.target == context.view_layer.objects.active: return "Active object" 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 _target = get_target() iops_text = ( ("Look at", str(_target)), ("Look at axis", str(self.look_axis[0])), ("Match cursor's rotation", str(self.rotate)), ("Align to cursor's pos", "F3"), ("Visual origin helper", "F4"), ) # 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 * 15) * _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
def draw_callback_px(self, context, pos): hpos, vpos = 64, 64 if pos: hpos = pos - 10 font_id = 0 blf.enable(font_id, 4) blf.position(font_id, hpos, vpos - 25, 0) blf.color(font_id, self.scol[0], self.scol[1], self.scol[2], self.scol[3]) blf.size(font_id, 13, 72) blf.shadow(font_id, 5, 0, 0, 0, 1) blf.shadow_offset(font_id, 1, -1) blf.draw(font_id, "[ Quick Origin Move ]")
def __render_each_data(context, data): sc = context.scene # setup rendering region for area in bpy.context.screen.areas: if area.type == "VIEW_3D": break else: return for region in area.regions: if region.type == "WINDOW": break else: return for space in area.spaces: if space.type == "VIEW_3D": break else: return loc_on_screen = view3d_utils.location_3d_to_region_2d( region, space.region_3d, data[1]) rect = get_canvas(context, loc_on_screen, len(str(data[0])), sc.iv_font_size) positions = [ [rect.x0, rect.y0], [rect.x0, rect.y1], [rect.x1, rect.y1], [rect.x1, rect.y0] ] # render box bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_QUADS) box_color_r, box_color_g, box_color_b, box_color_a = sc.iv_box_color bgl.glColor4f(box_color_r, box_color_g, box_color_b, box_color_a) for (v1, v2) in positions: bgl.glVertex2f(v1, v2) bgl.glEnd() # render index font_size = sc.iv_font_size blf.size(0, font_size, 72) blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 1, -1) blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.0) blf.position(0, rect.x0 + (rect.x1 - rect.x0) * 0.18, rect.y0 + (rect.y1 - rect.y0) * 0.24, 0) text_color_r, text_color_g, text_color_b, text_color_a = sc.iv_text_color bgl.glColor4f(text_color_r, text_color_g, text_color_b, text_color_a) blf.draw(0, str(data[0])) blf.blur(0, 0) blf.disable(0, blf.SHADOW)
def draw_text(text: str, font: int, size: int, x: int, y: int, horizontal: str, vertical: str, shadow: bool): ''' Draw two aligned columns of text. Args: text: List of tuples of two strings. font: ID returned by blf.load or 0. size: How large the font should be. x, y: Pixel on the active area. horizontal: 'LEFT', 'CENTER', or 'RIGHT'. vertical: 'BOTTOM', 'CENTER', or 'TOP'. shadow: Whether to add a dropshadow. ''' blf.size(font, size, 72) widths_l = [blf.dimensions(font, line[0])[0] for line in text] widths_r = [blf.dimensions(font, line[1])[0] for line in text] height = blf.dimensions(font, 'A')[1] * 2 space = height * 0.5 y += height * 0.25 if horizontal == 'LEFT': x += max(widths_l) + space elif horizontal == 'RIGHT': x -= max(widths_r) + space if vertical == 'BOTTOM': y += height * len(text) elif vertical == 'CENTER': y += height * len(text) * 0.5 if shadow: blf.enable(font, blf.SHADOW) blf.shadow(font, 5, 0, 0, 0, 1) blf.shadow_offset(font, 1, -1) for index, line in enumerate(text): offset = (index + 2) * height left, right = line width = widths_l[index] blf.position(font, x - width - space, y - offset, 0) blf.draw(font, left) blf.position(font, x + space, y - offset, 0) blf.draw(font, right) if shadow: blf.disable(font, blf.SHADOW)
def draw_text(font_id, location, text, color): x, y = location r, g, b = color blf.position(font_id, x, y, 0) level = 5 # 3, 5 or 0 blf.color(font_id, r, g, b, 1.0) blf.enable(font_id, blf.SHADOW) blf.shadow(font_id, level, 0, 0, 0, 1) blf.shadow_offset(font_id, 1, -1) blf.draw(font_id, text) blf.disable(font_id, blf.SHADOW)
def draw_text(text, font_id, color, shadow=False, color_shadow=None): blf.enable(font_id, blf.SHADOW) # Draw shadow. if shadow: blf.shadow_offset(font_id, 3, -3) blf.shadow(font_id, 5, *color_shadow, 1.0) # Draw text. compat.set_blf_font_color(font_id, *color, 1.0) blf.draw(font_id, text) blf.disable(font_id, blf.SHADOW)
def draw_callback_px(self, context): addon_prefs = context.preferences.addons["rotate_an_hdri"].preferences if addon_prefs.show_angle: r, g, b, a = addon_prefs.text_color angle = get_hdri_rotation_angle(context) width = context.area.width font_id = 0 blf.enable(font_id, blf.SHADOW) blf.shadow(font_id, 3, 0, 0, 0, 0.7) blf.shadow_offset(font_id, 2, -2) blf.color(font_id, r, g, b, a) blf.position(font_id, width / 2, 60, 0) blf.size(font_id, 30, addon_prefs.text_size) blf.draw(font_id, f"{(math.degrees(angle)):.1f}°")
def draw(self): pr = prefs().overlay if pr.shadow: a = 1 blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 1, -1) blf.shadow(0, 5, 0.0, 0.0, 0.0, a * 0.4 * self.alpha) for p in self.painters: p.draw() if pr.shadow: blf.disable(0, blf.SHADOW)
def _drawDisplayMessage(self, context): """ Message telling user to move the window the HMD display """ from bgl import glColor4f window = context.window width = window.width height = window.height glColor4f(1.0, 1.0, 1.0, 1.0) font_id = 0 # draw some text x = int(0.1 * width) y = int(0.5 * height) font_size = int(width * 0.035) line_gap = int(font_size * 1.5) from blf import ( SHADOW, enable, shadow, shadow_offset, position, size, draw, disable, ) enable(font_id, SHADOW) shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0) shadow_offset(font_id, -2, -2) size(font_id, font_size, 72) if self._is_mac: position(font_id, x, y + line_gap, 0) draw(font_id, "1. Move this window to the external HMD display") position(font_id, x, y, 0) draw(font_id, "2. Set this window to fullscreen (Alt + F11)") position(font_id, x, y - line_gap, 0) draw(font_id, "3. Select \"Start\" in the main window") else: position(font_id, x, y, 0) draw(font_id, "1. Move this window to the external HMD display") position(font_id, x, y - line_gap, 0) draw(font_id, "2. Select \"Start\" in the main window") disable(font_id, SHADOW)
def draw_iops_text(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 = ( ("World space group", "F1"), ("Local space for active", "F2"), ("World space for active", "F3"), ("Origin to World center", "W"), ("Selected to World center", "M"), ("Pick up active object", "Shift + LMB Click"), ) # 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 * 21) * _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
def draw(self, context): w = context.region.width h = context.region.height # Draw text area that PRMan is running. pos_x = w / 2 - 100 pos_y = 20 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, 32, 36) blf.position(0, pos_x, pos_y, 0) bgl.glColor4f(1.0, 0.0, 0.0, 1.0) blf.draw(0, "%s" % ('PRMan Interactive Mode Running')) blf.disable(0, blf.SHADOW)
def _draw_handler(space): r, g, b, a = space.color p = 1 if space.timer.t >= 0.3 else space.timer.t / 0.3 if space.shadow: blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 1, -1) blf.shadow(0, 5, 0.0, 0.0, 0.0, a * 0.4 * p) global _line_y _line_y = 0 if space.text: _draw_line(space, r, g, b, a * p) blf.disable(0, blf.SHADOW)
def draw_callback(self, context): # polling if context.mode != "EDIT_MESH" or len( context.active_object.vertex_groups) == 0: return # retrieving ID property data try: texts = context.active_object.data["show_vgroup_verts"] weights = context.active_object.data["show_vgroup_weights"] except: return if not texts: return bm = bmesh.from_edit_mesh(context.active_object.data) if bm.select_mode == {'VERT'} and bm.select_history.active is not None: active_vert = bm.select_history.active else: active_vert = None # draw blf.size(0, 13, 72) blf.enable(0, blf.SHADOW) blf.shadow(0, 3, 0.0, 0.0, 0.0, 1.0) blf.shadow_offset(0, 2, -2) 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, "Vertex " + str(int(texts[i + 3])) + ":") font_y = texts[i + 5] group_name = "" for j in range(0, len(weights), 3): if int(weights[j]) == int(texts[i + 3]): font_y -= 13 blf.position(0, texts[i + 4] + 10, font_y, texts[i + 6]) for group in context.active_object.vertex_groups: if group.index == int(weights[j + 1]): group_name = group.name break blf.draw(0, group_name + ": %.3f" % weights[j + 2]) if group_name == "": font_y -= 13 blf.position(0, texts[i + 4] + 10, font_y, texts[i + 6]) blf.draw(0, "No Groups") # restore defaults blf.disable(0, blf.SHADOW)
def draw_callback(self, context): # polling if context.mode != "EDIT_MESH" or len(context.active_object.vertex_groups) == 0: return # retrieving ID property data try: texts = context.active_object.data["show_vgroup_verts"] weights = context.active_object.data["show_vgroup_weights"] except: return if not texts: return bm = bmesh.from_edit_mesh(context.active_object.data) if bm.select_mode == {'VERT'} and bm.select_history.active is not None: active_vert = bm.select_history.active else: active_vert = None # draw blf.size(0, 13, 72) blf.enable(0, blf.SHADOW) blf.shadow(0, 3, 0.0, 0.0, 0.0, 1.0) blf.shadow_offset(0, 2, -2) 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, "Vertex " + str(int(texts[i+3])) + ":") font_y = texts[i+5] group_name = "" for j in range(0, len(weights), 3): if int(weights[j]) == int(texts[i+3]): font_y -= 13 blf.position(0, texts[i+4] + 10, font_y, texts[i+6]) for group in context.active_object.vertex_groups: if group.index == int(weights[j+1]): group_name = group.name break blf.draw(0, group_name + ": %.3f" % weights[j+2]) if group_name == "": font_y -= 13 blf.position(0, texts[i+4] + 10, font_y, texts[i+6]) blf.draw(0, "No Groups") # restore defaults blf.disable(0, blf.SHADOW)
def __render(self, context): prefs = context.user_preferences.addons[__name__].preferences region, space = ShowObjectName.__get_region_space( context, 'VIEW_3D', 'WINDOW', 'VIEW_3D') if (region is None) or (space is None): return # オブジェクトの位置にオブジェクト名を表示 objs = [o for o in bpy.data.objects] # オブジェクトの位置座標(3D座標)をリージョン座標(2D座標)に変換 locs_on_screen = [ view3d_utils.location_3d_to_region_2d(region, space.region_3d, o.location) for o in objs ] blf.shadow(0, 3, 0.1, 0.1, 0.1, 1.0) blf.shadow_offset(0, 1, -1) blf.enable(0, blf.SHADOW) for obj, loc in zip(objs, locs_on_screen): # 表示範囲外なら表示しない if loc is not None: ShowObjectName.__render_message(prefs.font_size_2, loc.x, loc.y, obj.name) blf.disable(0, blf.SHADOW) # マウスカーソルの位置に向けて発したレイと交差するオブジェクト名を表示 blf.shadow(0, 3, 0.0, 1.0, 0.0, 0.5) blf.shadow_offset(0, 2, -2) blf.enable(0, blf.SHADOW) ShowObjectName.__render_message(prefs.font_size_1, prefs.left_top[0], region.height - prefs.left_top[1], "Intersect") blf.disable(0, blf.SHADOW) # ray_castが可能なオブジェクトモード時のみ表示 if context.mode == 'OBJECT': for i, o in enumerate(self.__intersected_objs): ShowObjectName.__render_message( int(prefs.font_size_1 * 0.8), prefs.left_top[0], (region.height - prefs.left_top[1] - int(prefs.font_size_1 * 1.3) - i * int(prefs.font_size_1 * 0.9)), o.name) else: ShowObjectName.__render_message( int(prefs.font_size_1 * 0.8), prefs.left_top[0], (region.height - prefs.left_top[1] - int(prefs.font_size_1 * 1.3)), "Objectモード以外では利用できません")
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
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)
def __render(self, context): # リージョン幅を取得するため、描画先のリージョンを得る region = RenderText.__get_region(context, 'VIEW_3D', 'WINDOW') # 描画先のリージョンへテキストを描画 if region is not None: # 影の効果を設定 blf.shadow(0, 3, 0.0, 1.0, 0.0, 0.5) # 影の位置を設定 blf.shadow_offset(0, 2, -2) # 影の効果を有効化 blf.enable(0, blf.SHADOW) RenderText.__render_text(40, 40, region.height - 120, "Hello Blender world!!") # 影の効果を無効化 blf.disable(0, blf.SHADOW) RenderText.__render_text(30, 40, region.height - 180, "Suzanne on your lap")
def _draw_text(space): p = 1 if space.timer.t >= 0.3 else space.timer.t / 0.3 if space.shadow: blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 1, -1) if space.text: table = Table(space.text, space) for i in range(0, table.num_rows()): for j in range(0, table.num_cols(i)): r, g, b, a = space.color if j % 2 == 0 else space.color2 if space.shadow: blf.shadow(0, 5, 0.0, 0.0, 0.0, a * 0.4 * p) _draw_table(space, table, i, j, r, g, b, a * p) blf.disable(0, blf.SHADOW)
def draw_text(text, pos_x, pos_y, align="LEFT", font=0, font_size=12, color=(1, 1, 1, 1)): blf.size(font, font_size, 0) blf.color(font, *color) blf.enable(font, blf.SHADOW) blf.shadow_offset(font, 1, -1) blf.shadow(font, 3, *(0, 0, 0, 1)) if align == "RIGHT": width, height = blf.dimensions(font, text) blf.position(font, pos_x - width, pos_y, 0) else: blf.position(font, pos_x, pos_y, 0) blf.draw(font, text)
def __render(self, context): # リージョン幅を取得するため、描画先のリージョンを得る region = RenderText.__get_region(context, 'VIEW_3D', 'WINDOW') # 描画先のリージョンへテキストを描画 if region is not None: # 影の効果を設定 blf.shadow(0, 3, 0.0, 1.0, 0.0, 0.5) # 影の位置を設定 blf.shadow_offset(0, 2, -2) # 影の効果を有効化 blf.enable(0, blf.SHADOW) RenderText.__render_text( 40, 40, region.height - 120, "Hello Blender world!!" ) # 影の効果を無効化 blf.disable(0, blf.SHADOW) RenderText.__render_text( 30, 40, region.height - 180, "Suzanne on your lap" )
def draw_func(ignore): # Only draw when allowed... space_data = bpy.context.space_data if not (space_data.overlay.show_overlays and space_data.overlay.show_text): return # Setup font and scaling parameters... font_id = draw_settings["font_id"] font_size = draw_settings["font_size"] ui_scale = bpy.context.preferences.system.ui_scale blf.size(font_id, round(font_size * ui_scale), 72) blf.enable(font_id, blf.SHADOW) blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 0.9) blf.shadow_offset(font_id, 1, -1) line_height = blf.dimensions(font_id, "M")[1] * 1.55 # Draw all the things... draw_stats(font_id, line_height, ui_scale)
def _draw(): preferences = addon_preferences.get() if not preferences: return font_id = 0 font_size = preferences.server_notification_size padding = 20 blf.color(font_id, 1, 1, 1, 1) blf.enable(font_id, blf.SHADOW) blf.shadow(font_id, 0, 0, 0, 0, 1) blf.shadow_offset(font_id, 4, 4) y = padding blf.size(font_id, font_size, 72) with _notifications_lock: for notification in _notifications: blf.position(font_id, padding, y, 0) blf.draw(font_id, str(notification)) y += font_size + padding
def draw_callback_2d(self, context): region = context.region rv3d = context.region_data # Draw text to indicate that Lumiere is active text = "- Lumiere -" xt = int(region.width / 2.0) blf.size(0, 24, 72) blf.shadow(0, 3, 0, 0, 0, 1) blf.shadow_offset(0,0,0) blf.enable(0,blf.SHADOW) blf.position(0, xt - blf.dimensions(0, text)[0] / 2, 40 , 0) blf.draw(0, text) blf.disable(0,blf.SHADOW) # Create a circle using a tri fan if self.light_selected and (context.active_object is not None): light = context.active_object color = context.preferences.themes[0].view_3d.object_active circle_hit = location_3d_to_region_2d(region, rv3d, light.Lumiere.hit) circle_radius = (circle_hit[0] + 4, circle_hit[1] + 4) steps = 8 tris_coords, indices = draw_circle(circle_hit, circle_radius, steps) draw_shader(self, color, 1.0, 'TRI_FAN', tris_coords, size=1) if self.shadow: circle_hit = location_3d_to_region_2d(region, rv3d, light.Lumiere.shadow) circle_radius = (circle_hit[0] + 3, circle_hit[1] + 3) tris_coords, indices = draw_circle(circle_hit, circle_radius, steps) draw_shader(self, color, 1.0, 'TRI_FAN', tris_coords, size=1) # Draw circle on boundingbox center of the targer object elif light.Lumiere.reflect_angle == "Estimated" and light.parent: circle_hit = location_3d_to_region_2d(region, rv3d, light.Lumiere.bbox_center) circle_radius = (circle_hit[0] + 3, circle_hit[1] + 3) steps = 8 tris_coords, indices = draw_circle(circle_hit, circle_radius, steps) draw_shader(self, color, 1, 'TRI_FAN', tris_coords, size=1)
return region //! [get_region] @staticmethod def __render(self, context): # リージョン幅を取得するため、描画先のリージョンを得る region = RenderText.__get_region(context, 'VIEW_3D', 'WINDOW') //! [call_render_region] # 描画先のリージョンへテキストを描画 if region is not None: # 影の効果を設定 blf.shadow(0, 3, 0.0, 1.0, 0.0, 0.5) # 影の位置を設定 blf.shadow_offset(0, 2, -2) # 影の効果を有効化 blf.enable(0, blf.SHADOW) RenderText.__render_text( 40, 40, region.height - 120, "Hello Blender world!!" ) # 影の効果を無効化 blf.disable(0, blf.SHADOW) RenderText.__render_text( 30, 40, region.height - 180, "Suzanne on your lap" ) //! [call_render_region] def invoke(self, context, event): sc = context.scene if context.area.type == 'VIEW_3D':
def shadow_offset(xy, fontid=None): return blf.shadow_offset(FontManager.load(fontid), *xy)
def draw(self, parent, context): #get the addon settings/prefs settings = context.user_preferences.addons['piemenus'].preferences #grab the biggest text dimensions that we already calced previously biggestdimensionX = self.biggest_dim_x biggestdimensionY = self.biggest_dim_y for it in self.sliders: #draw some text above it. blf.size(0, self.text_size, self.text_dpi) dimension = blf.dimensions(0, it.id) x = it.x - dimension[0]*.5 y = it.y + (it.height + dimension[1])* 0.5 + 2 # Draw text blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 0, 0) blf.shadow(0, 5, 0.0, 0.0, 0.0, 1.0) bgl.glColor3f(self.rt, self.gt, self.bt) blf.position(0, x, y, 0) blf.draw(0, it.id) blf.disable(0, blf.SHADOW) #draw left side one color bgl.glColor4f(self.rsSelected,self.gsSelected, self.bsSelected,1.0) pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, it.screen_left) #draw the right side another color bgl.glColor4f(self.rsInner,self.gsInner, self.bsInner,1.0) pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, it.screen_right) #Draw box outline bgl.glColor4f(self.rsOutline,self.gsOutline, self.bsOutline,1.0) pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, it.screen_left) pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, it.screen_right) #put the text on top blf.enable(0, blf.KERNING_DEFAULT) prop_text = str(getattr(it.data, it.prop, 0))[0:4] #prop_text = "Test" dimensions2 = blf.dimensions(0,prop_text) x2 =it.x - dimensions2[0] * 0.5 y2 = it.y - dimensions2[1] * 0.5 blf.position(0, x2, y2, 0) bgl.glColor4f(self.rt, self.gt, self.bt, 1.0) blf.draw(0, prop_text) blf.disable(0, blf.KERNING_DEFAULT) for it in self.menu_items: sel = it == parent.current it_poll = it.poll(context) # center item on the circle #x = (self.menu_x + it.x) - (dimension[0] * 0.5) #y = (self.menu_y + it.y) - (dimension[1] * 0.5) blf.size(0, self.text_size, self.text_dpi) dimension = blf.dimensions(0, it.id) #needed for box centering x = (it.x) - (biggestdimensionX * 0.5) y = (it.y) - (biggestdimensionY * 0.5) #needed offset for text centering blf.size(0, self.text_size, self.text_dpi) dimension = blf.dimensions(0, it.id) xt = ((biggestdimensionX-dimension[0]) * 0.5) yt = ((biggestdimensionY-dimension[1]) * 0.5) # Draw background buttons if sel and it_poll: bgl.glColor4f(self.ris, self.gis, self.bis, self.ais) else: bgl.glColor4f(self.ri, self.gi, self.bi, self.ai) #self.gl_pie_slice(bgl.GL_POLYGON, 8, it, x,y,30,90) #*** #http://www.opengl.org/archives/resources/faq/technical/rasterization.htm#rast0120 #self._round_box(bgl.GL_POLYGON, x - 20, y - 5, x + biggestdimensionX + 20, y + biggestdimensionY + 5) if it.screen_poly_bound: shape = it.screen_poly_bound pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, shape) bgl.glColor4f(self.ro, self.go, self.bo, 1.0) pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, shape) bgl.glColor4f(self.ri, self.gi, self.bi, self.ai) #draw the circle if settings.clockBool: self._circle_(bgl.GL_TRIANGLE_FAN, (self.menu_x), (self.menu_y), 20) #draw the circle outline bgl.glColor4f(self.ro, self.go, self.bo, 1.0) self._circle_(bgl.GL_LINE_LOOP, (self.menu_x), (self.menu_y), 20) self._pointer_(bgl.GL_TRIANGLE_STRIP, (self.menu_x), (self.menu_y), self.pointerangle ) # Draw text blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 0, 0) blf.shadow(0, 5, 0.0, 0.0, 0.0, 1.0) if it_poll: bgl.glColor3f(self.rt, self.gt, self.bt) else: # grayed out bgl.glColor3f(0.5, 0.5, 0.5) blf.position(0, x+xt, y+yt, 0) blf.draw(0, it.id) blf.disable(0, blf.SHADOW) #bind the named texure to GL_TEXTURE_2D #http://stackoverflow.com/questions/11217121/how-to-manage-memory-with-texture-in-opengl bgl.glBindTexture(bgl.GL_TEXTURE_2D, settings.pieIconBindcode) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glEnable(bgl.GL_BLEND) for it in self.menu_items: bgl.glColor4f(1, 1, 1, 1) if it.icon: #place the icon quad verts = it.screen_icon_quad bgl.glBegin(bgl.GL_QUADS) bgl.glTexCoord2f(it.tex_coords[0][0],it.tex_coords[0][1]) bgl.glVertex2f(verts[0][0],verts[0][1]) bgl.glTexCoord2f(it.tex_coords[1][0],it.tex_coords[1][1]) bgl.glVertex2f(verts[1][0],verts[1][1]) bgl.glTexCoord2f(it.tex_coords[2][0],it.tex_coords[2][1]) bgl.glVertex2f(verts[2][0],verts[2][1]) bgl.glTexCoord2f(it.tex_coords[3][0],it.tex_coords[3][1]) bgl.glVertex2f(verts[3][0],verts[3][1]) bgl.glEnd() #TODO #text value in center? #labe over top? bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_TEXTURE_2D)
def draw_callback_px_text(self, context): wm = context.window_manager sc = context.scene if not wm.screencast_keys_keys: return font_size = sc.screencast_keys_font_size mouse_size = sc.screencast_keys_mouse_size box_draw = sc.screencast_keys_box_draw pos_x, pos_y = getDisplayLocation(context) label_time_max = sc.screencast_keys_fade_time # draw text in the 3D View blf.size(0, sc.screencast_keys_font_size, 72) blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 1, -1) blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.8) font_color_r, font_color_g, font_color_b, font_color_alpha = sc.screencast_keys_text_color final = 0 row_count = len(self.key) keypos_x = pos_x if sc.screencast_keys_mouse_position == 'left': keypos_x += mouse_size * MOUSE_RATIO * 1.7 if sc.screencast_keys_mouse != 'icon': keypos_x -= mouse_size * MOUSE_RATIO if sc.screencast_keys_mouse_position == 'right' and sc.screencast_keys_mouse != 'icon': keypos_x = pos_x shift = 0 # we want to make sure we can shift vertically the text if the mouse is big, # but don't care if aligned to right if mouse_size > font_size*row_count and not sc.screencast_keys_mouse_position == 'right': shift = (mouse_size - font_size*row_count) / 2 text_width, text_height = 0,0 row_count = 0 alpha = 1.0 for i in range(len(self.key)): label_time = time.time() - self.time[i] if label_time < label_time_max: # only display key-presses of last 2 seconds if label_time > (label_time_max / 1.2): blf.blur(0, 1) if label_time > (label_time_max / 1.1): blf.blur(0, 3) keypos_y = pos_y + shift + font_size*(i+0.1) blf.position(0, keypos_x, keypos_y , 0) alpha = min(1.0, max(0.0, label_time_max * (label_time_max - label_time))) bgl.glColor4f(font_color_r, font_color_g, font_color_b, font_color_alpha * alpha) blf.draw(0, self.key[i]) text_width, text_height = getBoundingBox(text_width, text_height, self.key[i]) row_count += 1 final = i + 1 else: break # remove blurriness # disable shadows so they don't appear all over blender blf.blur(0,0) blf.disable(0, blf.SHADOW) # get rid of status texts that aren't displayed anymore self.key = self.key[:final] self.time = self.time[:final] # draw graphical representation of the mouse if sc.screencast_keys_mouse == 'icon': for shape in ["mouse", "left_button", "middle_button", "right_button"]: draw_mouse(context, shape, "outline", font_color_alpha * 0.4) final = 0 for i in range(len(self.mouse)): click_time = time.time() - self.mouse_time[i] if click_time < 2: shape = map_mouse_event(self.mouse[i]) if shape: alpha = min(1.0, max(0.0, 2 * (2 - click_time))) draw_mouse(context, shape, "filled", alpha) final = i + 1 else: break # get rid of mouse clicks that aren't displayed anymore self.mouse = self.mouse[:final] self.mouse_time = self.mouse_time[:final]