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 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'])
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 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
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)
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_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 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)
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)
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)
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_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)
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()
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
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
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
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 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)
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 __render_text(size, x, y, s): # フォントサイズを指定 blf.size(0, size, 72) # 描画位置を指定 blf.position(0, x, y, 0) # テキストを描画 blf.draw(0, s)
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
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)
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)
def write(): """write on screen""" # retrieve timer global game_timer scene = logic.getCurrentScene() game_timer = int(active_camera["Timer"]) catched = bamboo_counter["catched"] total = bamboo_counter["total"] vortex = panda.power 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() bgl.glColor4f(1, 1, 1, 1) # BLF drawing routine font_id = logic.font_id blf.size(font_id, int(18 * (width/dpi) * 0.06), dpi) blf.position(font_id, width*0.02, height*0.95, 0) if game_timer < 60: blf.draw(font_id, "{0} : {1:02d}".format(l_timer,game_timer)) else: blf.draw(font_id, "{0} : {1}:{2:02d}".format(l_timer,game_timer//60,game_timer%60)) blf.position(font_id, width*0.02, height*0.90, 0) blf.draw(font_id, "{0} : {1}".format(l_level, level)) blf.position(font_id, width*0.02, height*0.85, 0) blf.draw(font_id, "{0} : {1} / {2}".format(l_score, catched, total)) blf.position(font_id, width*0.02, height*0.80, 0) blf.draw(font_id, "{0} : {1}".format(l_vortex, vortex))
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 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")
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(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)
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)
def draw_callback(self, context): if context.region != self.region: return box_size = 10 circle_size = 12 region = context.region rv3d = context.region_data bgl.glColor4f(1.0, 1.0, 1.0, 1.0) blf.position(0, 70, 30, 0) blf.draw(0, self.snap_type) # axis if self.axis is not None: blf.position(0, 70, 45, 0) blf.draw(0, str(math.degrees(self.axis))) bgl.glEnable(bgl.GL_BLEND) """# axis if self.axis is not None: v = vav.project(region, rv3d, self.points[-2]) bgl.glColor4f(1.0, 1.0, 1.0, 0.5) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glVertex2f() bgl.glVertex2f() bgl.glEnd() """ # snap bgl.glColor4f(1.0, 1.0, 1.0, 1.0) if self.snap_vector: v = vav.project(region, rv3d, self.snap_vector) if self.snap_grid: xmin = v[0] - box_size / 2 ymin = v[1] - box_size / 2 w = box_size h = box_size vagl.draw_box(xmin, ymin, w, h, poly=False) else: vagl.draw_circle(v[0], v[1], circle_size / 2, 16, poly=False) """# line bgl.glColor4f(1.0, 1.0, 1.0, 0.2) bgl.glBegin(bgl.GL_LINE_STRIP) for point in self.points[:len(self.points) - 1]: # [:-1]がバグってる bgl.glVertex2f(*vav.project(region, rv3d, point.co).to_2d()) bgl.glEnd() """ # line bgl.glColor4f(1.0, 1.0, 1.0, 0.2) for polyline in self.polylines: bgl.glBegin(bgl.GL_LINE_STRIP) for vec in polyline.point_coords: bgl.glVertex2f(*vav.project(region, rv3d, vec).to_2d()) bgl.glEnd() # point x_size2 = 3 bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glBegin(bgl.GL_LINES) for polyline in self.polylines: for vec in polyline.point_coords[1:]: v = vav.project(region, rv3d, vec) bgl.glVertex2f(v[0] - x_size2, v[1] - x_size2) bgl.glVertex2f(v[0] + x_size2, v[1] + x_size2) bgl.glVertex2f(v[0] - x_size2, v[1] + x_size2) bgl.glVertex2f(v[0] + x_size2, v[1] - x_size2) bgl.glEnd() # current line bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glBegin(bgl.GL_LINE_STRIP) for point in self.points[-2:]: bgl.glVertex2f(*vav.project(region, rv3d, point.co).to_2d()) bgl.glEnd() # mouse cross_size = 10 cross_ofs = 30 mco = self.mco bgl.glColor4f(1.0, 1.0, 1.0, 0.7) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(mco[0] + cross_ofs, mco[1]) # right bgl.glVertex2f(mco[0] + cross_ofs + cross_size, mco[1]) bgl.glVertex2f(mco[0] - cross_ofs, mco[1]) # left bgl.glVertex2f(mco[0] - cross_ofs - cross_size, mco[1]) bgl.glVertex2f(mco[0], mco[1] + cross_ofs) # top bgl.glVertex2f(mco[0], mco[1] + cross_ofs + cross_size) bgl.glVertex2f(mco[0], mco[1] - cross_ofs) # bottom bgl.glVertex2f(mco[0], mco[1] - cross_ofs - cross_size) bgl.glEnd()
def __render_message(size, x, y, msg): blf.size(0, size, 72) blf.position(0, x, y, 0) blf.draw(0, msg)
def draw_to_viewport(view_min, view_max, show_extra, label_counter, tilegrid, sprytile_data, cursor_loc, region, rv3d, middle_btn, context): """Draw the offscreen texture into the viewport""" # Prepare some data that will be used for drawing grid_size = SprytileGui.loaded_grid.grid tile_sel = SprytileGui.loaded_grid.tile_selection padding = SprytileGui.loaded_grid.padding margin = SprytileGui.loaded_grid.margin is_pixel = sprytile_utils.grid_is_single_pixel(SprytileGui.loaded_grid) # Draw work plane SprytileGui.draw_work_plane(grid_size, sprytile_data, cursor_loc, region, rv3d, middle_btn) # Setup GL for drawing the offscreen texture bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glBindTexture(bgl.GL_TEXTURE_2D, SprytileGui.texture) # Backup texture settings old_mag_filter = Buffer(bgl.GL_INT, 1) glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, old_mag_filter) old_wrap_S = Buffer(GL_INT, 1) old_wrap_T = Buffer(GL_INT, 1) glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, old_wrap_S) glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, old_wrap_T) # Set texture filter bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST) bgl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) bgl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glEnable(bgl.GL_BLEND) # Draw the preview tile if middle_btn is False: SprytileGui.draw_preview_tile(context, region, rv3d) # Calculate actual view size view_size = int(view_max.x - view_min.x), int(view_max.y - view_min.y) # Save the original scissor box, and then set new scissor setting scissor_box = bgl.Buffer(bgl.GL_INT, [4]) bgl.glGetIntegerv(bgl.GL_SCISSOR_BOX, scissor_box) bgl.glScissor( int(view_min.x) + scissor_box[0], int(view_min.y) + scissor_box[1], view_size[0], view_size[1]) # Draw the tile select UI SprytileGui.draw_tile_select_ui(view_min, view_max, view_size, SprytileGui.tex_size, grid_size, tile_sel, padding, margin, show_extra, is_pixel) # restore opengl defaults bgl.glScissor(scissor_box[0], scissor_box[1], scissor_box[2], scissor_box[3]) bgl.glLineWidth(1) bgl.glTexParameteriv(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, old_mag_filter) bgl.glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, old_wrap_S) bgl.glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, old_wrap_T) # Draw label font_id = 0 font_size = 16 pad = 5 if label_counter > 0: import math def ease_out_circ(t, b, c, d): t /= d t -= 1 return c * math.sqrt(1 - t * t) + b box_pad = font_size + (pad * 2) fade = label_counter fade = ease_out_circ(fade, 0, SprytileGui.label_frames, SprytileGui.label_frames) fade /= SprytileGui.label_frames bgl.glColor4f(0.0, 0.0, 0.0, 0.75 * fade) bgl.glBegin(bgl.GL_QUADS) uv = [(0, 0), (0, 1), (1, 1), (1, 0)] vtx = [(view_min.x, view_max.y), (view_min.x, view_max.y + box_pad), (view_max.x, view_max.y + +box_pad), (view_max.x, view_max.y)] for i in range(4): glTexCoord2f(uv[i][0], uv[i][1]) glVertex2f(vtx[i][0], vtx[i][1]) bgl.glEnd() bgl.glColor4f(1.0, 1.0, 1.0, 1.0 * fade) blf.size(font_id, font_size, 72) x_pos = view_min.x + pad y_pos = view_max.y + pad label_string = "%dx%d" % (tilegrid.grid[0], tilegrid.grid[1]) if tilegrid.name != "": label_string = "%s - %s" % (label_string, tilegrid.name) blf.position(font_id, x_pos, y_pos, 0) blf.draw(font_id, label_string) if tilegrid.grid[0] == 1 and tilegrid.grid[1] == 1: size_text = "%dx%d" % (tile_sel[2], tile_sel[3]) blf.size(font_id, font_size, 72) size = blf.dimensions(font_id, size_text) x_pos = view_max.x - size[0] - pad y_pos = view_max.y + pad blf.position(font_id, x_pos, y_pos, 0) blf.draw(font_id, size_text) bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_TEXTURE_2D) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): use_texture = self.use_texture if not use_texture: if context.region != self.region: return U = context.user_preferences prefs = MouseGesturePreferences.get_instance() dpi = U.system.dpi widget_unit = int((PIXEL_SIZE * dpi * 20 + 36) / 72) font_id = 0 theme_style = U.ui_styles[0] blf.size(font_id, theme_style.widget.points, dpi) bgl.glEnable(bgl.GL_BLEND) bgl.glColor3f(*U.themes['Default'].view_3d.space.text_hi) win = context.window w, h = win.width, win.height if use_texture: bgl.glDisable(bgl.GL_SCISSOR_TEST) with window_space(win): if use_texture: draw_texture(0, 0, w, h, self.texture_back) # draw origin coords = self.coords + [self.mco] bgl.glLineWidth(2) r1 = prefs.threshold r2 = r1 + 5 x, y = coords[0] bgl.glBegin(bgl.GL_LINES) for i in range(4): a = math.pi / 2 * i + math.pi / 4 bgl.glVertex2f(x + r1 * math.cos(a), y + r1 * math.sin(a)) bgl.glVertex2f(x + r2 * math.cos(a), y + r2 * math.sin(a)) 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 coords: bgl.glVertex2f(v[0], v[1]) bgl.glEnd() bgl.glLineStipple(1, 1) bgl.glDisable(bgl.GL_LINE_STIPPLE) if use_texture: bgl.glEnable(bgl.GL_SCISSOR_TEST) # draw txt xmin, ymin, xmax, ymax = self.region_drawing_rectangle( context, self.area, self.region) xmin += self.region.x ymin += self.region.y xmax += self.region.x ymax += self.region.y if self.area.type == 'VIEW_3D': if U.view.show_mini_axis: # view3d_draw.c: 1019: draw_selected_name() posx = xmin + widget_unit + U.view.mini_axis_size * 2 else: # view3d_draw.c: 928: draw_selected_name() posx = xmin + 1.5 * widget_unit posy = ymin + widget_unit * 1.5 else: posx = xmin + widget_unit * 0.5 posy = ymin + widget_unit * 0.5 char_space = 5 group = prefs.gesture_groups.get(self.group) use_relative = group and group.use_relative gesture = self.gesture_rel if use_relative else self.gesture_abs # 文字はregionに収まるように(はみ出すと見た目が悪いから) scissor_box = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_SCISSOR_BOX, scissor_box) bgl.glScissor(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1) with window_space(win): if gesture: x = posx for txt in gesture: blf.position(font_id, x, posy, 0) blf.draw(font_id, txt) text_width, text_height = blf.dimensions(font_id, txt) x += text_width + char_space if self.item: blf.position(font_id, posx, posy + widget_unit, 0) blf.draw(font_id, self.item.name) bgl.glScissor(*scissor_box) # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def drawInfosText(self, context): """Draw map infos on 3dview""" #Get contexts scn = context.scene area = context.area area3d = [reg for reg in area.regions if reg.type == 'WINDOW'][0] view3d = area.spaces.active reg3d = view3d.region_3d #Get area3d dimensions w, h = area3d.width, area3d.height cx = w / 2 #center x #Get map props stored in scene geoscn = GeoScene(scn) zoom = geoscn.zoom scale = geoscn.scale #Set text police and color font_id = 0 # ??? prefs = context.user_preferences.addons[PKG].preferences fontColor = prefs.fontColor bgl.glColor4f(*fontColor) #rgba #Draw title blf.position(font_id, cx - 25, 70, 0) #id, x, y, z blf.size(font_id, 15, 72) #id, point size, dpi blf.draw(font_id, "Map view") #Draw other texts blf.size(font_id, 12, 72) # thread progress and service status blf.position(font_id, cx - 45, 90, 0) blf.draw(font_id, self.progress) # zoom and scale values blf.position(font_id, cx - 50, 50, 0) blf.draw(font_id, "Zoom " + str(zoom) + " - Scale 1:" + str(int(scale))) # view3d distance dst = reg3d.view_distance if dst > 1000: dst /= 1000 unit = 'km' else: unit = 'm' blf.position(font_id, cx - 50, 30, 0) blf.draw(font_id, '3D View distance ' + str(int(dst)) + ' ' + unit) # cursor crs coords blf.position(font_id, cx - 45, 10, 0) blf.draw(font_id, str((int(self.posx), int(self.posy)))) bgl.glColor4f(255, 0, 0, 150) #rgba blf.size(font_id, 25, 72) blf.position(font_id, w - 100, 25, 0) if self.map.lockedZoom is not None: #blf.draw(font_id, "z lock " + str(self.map.lockedZoom)) blf.draw(font_id, "zLock")
bgl.glEnd() bgl.glColor4f(0, 1.0, 1.0, 1) for edge in mesh.edges: bgl.glBegin(bgl.GL_LINES) for vert in edge.vertices: bgl.glVertex2f((int)(500 + 80 * verts[vert].x), (int)(400 + 80 * verts[vert].y)) bgl.glEnd() # Draw a Text font_id = 0 bgl.glColor4f(1.0, 1.0, 0.0, 1.0) blf.size(font_id, 18, 72) blf.position(font_id, 0.5, 0.5, 0) blf.draw(font_id, "Hello World") # bgl.glFinish() bgl.glReadPixels(0, 0, WIDTH, HEIGHT, bgl.GL_RGBA, bgl.GL_FLOAT, buffer) # read image data out.pixels = buffer[:] # Assign image data img.gl_free() # free opengl image memory #reset bgl.glEnable(bgl.GL_SCISSOR_TEST) # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): if context.region.id != self.region_id: return # init font_id = 0 #blf.position(font_id, 80, 30, 0) blf.size(font_id, 11, context.user_preferences.system.dpi) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) ofsx = 70 # draw Dist blf.position(font_id, ofsx, 50, 0) text_dist = '{0:>6.4f}'.format(float(self.dist)) blf.draw(font_id, text_dist) # draw Expression if self.mc.inputexp: text_width, text_height = blf.dimensions(font_id, text_dist) posx = max(ofsx + text_width + 15, 150) self.mc.exp.draw_exp_strings(font_id, posx, 50, start='Exp: ', end='', col=(1.0, 1.0, 1.0, 1.0), errcol=(1.0, 0.6, 0.5, 1.0)) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) # draw Help l = [ '{Tab}:InputString', '{M-Mouse}:Lock', '{R}:ResetOrig', '{X,Y,Z}:Lock', '{M}:Mirror', '{WHEEL UP-DOWN, E}:OutlineMode', '{W}:PrecedeOutline' ] blf.position(font_id, 70, 30, 0) blf.draw(font_id, ', '.join(l)) # draw State l = [] if self.mirror: l.append('Mirror') l.append('OutlineMode:' + self.outlinemode.title()) if self.precedeoutline: l.append('PreceedOutline') if True in self.lock[:]: l.append('Lock:[{0:d},{1:d},{2:d}]'.format(*self.lock)) if l: blf.position(font_id, 70, 70, 0) blf.draw(font_id, ', '.join(l)) bgl.glEnable(bgl.GL_BLEND) # draw mouseco_init self.mc.draw_origin(5, raydirections=[0, math.pi], raylength=[10, 10]) # draw mouseco_rerative self.mc.draw_relative(5) # draw mouseco_lock self.mc.draw_lock_arrow(8, math.radians(110)) # 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_simple(text, xyz): fontid = FontManager._last_fontid blf.position(fontid, *xyz) return blf.draw(fontid, text)
def draw_preview_callback(self): # Search for View_3d window area = None if bpy.context.area.type != 'VIEW_3D': return bpy.context.area else: for oWindow in bpy.context.window_manager.windows: oScreen = oWindow.screen for oArea in oScreen.areas: if oArea.type == 'VIEW_3D': area = oArea modelsPosesColl = bpy.context.user_preferences.addons[ "phobos"].preferences.models_poses activeModelPoseIndex = bpy.context.scene.active_ModelPose if (len(modelsPosesColl) > 0) and area: # Draw a textured quad area_widths = [ region.width for region in bpy.context.area.regions if region.type == 'WINDOW' ] area_heights = [ region.height for region in bpy.context.area.regions if region.type == 'WINDOW' ] if (len(area_widths) > 0) and (len(area_heights) > 0): active_preview = modelsPosesColl[ bpy.data.images[activeModelPoseIndex].name] im = bpy.data.images[activeModelPoseIndex] view_width = area_widths[0] view_height = area_heights[0] tex_start_x = 50 tex_end_x = view_width - 50 tex_start_y = 50 tex_end_y = view_height - 50 if im.size[0] < view_width: diff = int((view_width - im.size[0]) / 2) tex_start_x = diff tex_end_x = diff + im.size[0] if im.size[1] < view_height: diff = int((view_height - im.size[1]) / 2) tex_start_y = diff tex_end_y = diff + im.size[1] # Draw information font_id = 0 # XXX, need to find out how best to get this. blf.position(font_id, tex_start_x, tex_end_y + 20, 0) blf.size(font_id, 20, 72) blf.draw(font_id, active_preview.label) tex = im.bindcode bgl.glEnable(bgl.GL_TEXTURE_2D) # if using blender 2.77 change tex to tex[0] bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex) # Background bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_QUADS) bgl.glColor4f(0, 0, 0, 0.3) bgl.glVertex2i(0, 0) bgl.glVertex2i(0, view_height) bgl.glVertex2i(view_width, view_height) bgl.glVertex2i(view_width, 0) # Draw Image bgl.glColor4f(1, 1, 1, 1) bgl.glTexCoord2f(0, 0) bgl.glVertex2i(int(tex_start_x), int(tex_start_y)) bgl.glTexCoord2f(0, 1) bgl.glVertex2i(int(tex_start_x), int(tex_end_y)) bgl.glTexCoord2f(1, 1) bgl.glVertex2i(int(tex_end_x), int(tex_end_y)) bgl.glTexCoord2f(1, 0) bgl.glVertex2i(int(tex_end_x), int(tex_start_y)) bgl.glEnd() # restore opengl defaults bgl.glColor4f(0.0, 0.0, 0.0, 1.0) bgl.glDisable(bgl.GL_QUADS) bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_TEXTURE_2D)
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()
def draw_callback_px(self, context): x, y = self.Conv3DtoScreen2D(context, self.ActiveVertex) # Draw an * at the active vertex blf.position(0, x, y, 0) blf.size(0, 26, 72) blf.draw(0, "*") #Draw Help yPos = 30 blf.size(0, 11, context.user_preferences.system.dpi) txtHelp1 = "{SHIFT}:Precision" txtHelp2 = "{WHEEL}:Change the vertex/edge" txtHelp3 = "{ALT}:Continuos slide" txtHelp4 = "{LEFT ARROW}:Reverse the movement" txtHelp5 = "{RIGHT ARROW}:Restore the movement" blf.position(0, 70, yPos, 0) blf.draw(0, txtHelp5) yPos += (int(blf.dimensions(0, txtHelp4)[1] * 2)) blf.position(0, 70, yPos, 0) blf.draw(0, txtHelp4) yPos += (int(blf.dimensions(0, txtHelp3)[1] * 2)) blf.position(0, 70, yPos, 0) blf.draw(0, txtHelp3) yPos += (int(blf.dimensions(0, txtHelp2)[1] * 2)) blf.position(0, 70, yPos, 0) blf.draw(0, txtHelp2) yPos += (int(blf.dimensions(0, txtHelp1)[1] * 2)) blf.position(0, 70, yPos, 0) blf.draw(0, txtHelp1) # Draw edge bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.1, 0.8, 1.0) bgl.glBegin(bgl.GL_LINES) for p in self.LinkedVertices1: bgl.glVertex2f(self.Vertex1.x2D, self.Vertex1.y2D) bgl.glVertex2f(p.x2D, p.y2D) for p in self.LinkedVertices2: bgl.glVertex2f(self.Vertex2.x2D, self.Vertex2.y2D) bgl.glVertex2f(p.x2D, p.y2D) bgl.glEnd()
def draw_callback_px(self, context): allocate_main_ui(self, context) shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') shader.bind() addon_prefs = context.preferences.addons[__package__].preferences # main window background main_window = self.areas["Main Window"] outline_color = addon_prefs.qcd_ogl_widget_menu_back_outline background_color = addon_prefs.qcd_ogl_widget_menu_back_inner draw_rounded_rect(main_window, shader, outline_color[:] + (1, ), outline=True) draw_rounded_rect(main_window, shader, background_color) # draw window title window_title = self.areas["Window Title"] x = window_title["vert"][0] y = window_title["vert"][1] h = window_title["height"] text = window_title["value"] text_color = addon_prefs.qcd_ogl_widget_menu_back_text font_id = 0 blf.position(font_id, x, y, 0) blf.size(font_id, int(h), 72) blf.color(font_id, text_color[0], text_color[1], text_color[2], 1) blf.draw(font_id, text) # refresh shader - not sure why this is needed shader.bind() in_tooltip_area = False tooltip_slot_idx = None for num in range(20): slot_num = num + 1 qcd_slot_name = internals.qcd_slots.get_name(f"{slot_num}") if qcd_slot_name: qcd_laycol = internals.layer_collections[qcd_slot_name]["ptr"] collection_objects = qcd_laycol.collection.objects selected_objects = get_move_selection() active_object = get_move_active() button_area = self.areas[f"Button {slot_num}"] # colors button_color = addon_prefs.qcd_ogl_widget_tool_inner icon_color = addon_prefs.qcd_ogl_widget_tool_text if not qcd_laycol.exclude: button_color = addon_prefs.qcd_ogl_widget_tool_inner_sel icon_color = addon_prefs.qcd_ogl_widget_tool_text_sel if mouse_in_area(self.mouse_pos, button_area): in_tooltip_area = True tooltip_slot_idx = slot_num mod = 0.1 if button_color[0] + mod > 1 or button_color[ 1] + mod > 1 or button_color[2] + mod > 1: mod = -mod button_color = (button_color[0] + mod, button_color[1] + mod, button_color[2] + mod, button_color[3]) # button roundness tl = tr = bl = br = 0 rounding = 5 if num < 10: if not internals.qcd_slots.contains(idx=f"{num+2}"): tr = rounding if not internals.qcd_slots.contains(idx=f"{num}"): tl = rounding else: if not internals.qcd_slots.contains(idx=f"{num+2}"): br = rounding if not internals.qcd_slots.contains(idx=f"{num}"): bl = rounding if num in [0, 5]: tl = rounding elif num in [4, 9]: tr = rounding elif num in [10, 15]: bl = rounding elif num in [14, 19]: br = rounding # draw button outline_color = addon_prefs.qcd_ogl_widget_tool_outline draw_rounded_rect(button_area, shader, outline_color[:] + (1, ), tl, tr, bl, br, outline=True) draw_rounded_rect(button_area, shader, button_color, tl, tr, bl, br) # ACTIVE OBJECT if active_object and active_object in selected_objects and active_object.name in collection_objects: active_object_indicator = self.areas[ f"Button {slot_num} Active Object Indicator"] vertices = get_circle_coords(active_object_indicator) shader.uniform_float("color", icon_color[:] + (1, )) batch = batch_for_shader(shader, 'TRI_FAN', {"pos": vertices}) bgl.glEnable(bgl.GL_BLEND) batch.draw(shader) bgl.glDisable(bgl.GL_BLEND) # SELECTED OBJECTS elif not set(selected_objects).isdisjoint(collection_objects): selected_object_indicator = self.areas[ f"Button {slot_num} Selected Object Indicator"] alpha = addon_prefs.qcd_ogl_selected_icon_alpha vertices = get_circle_coords(selected_object_indicator) shader.uniform_float("color", icon_color[:] + (alpha, )) batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": vertices}) bgl.glLineWidth(2 * scale_factor()) bgl.glEnable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_LINE_SMOOTH) bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST) batch.draw(shader) bgl.glDisable(bgl.GL_LINE_SMOOTH) bgl.glDisable(bgl.GL_BLEND) # OBJECTS elif collection_objects: object_indicator = self.areas[ f"Button {slot_num} Object Indicator"] alpha = addon_prefs.qcd_ogl_objects_icon_alpha vertices, indices = get_coords(object_indicator) shader.uniform_float("color", icon_color[:] + (alpha, )) batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices) bgl.glEnable(bgl.GL_BLEND) batch.draw(shader) bgl.glDisable(bgl.GL_BLEND) # X ICON else: X_icon = self.areas[f"X_icon {slot_num}"] X_icon_color = addon_prefs.qcd_ogl_widget_menu_back_text vertices, indices = get_x_coords(X_icon) shader.uniform_float("color", X_icon_color[:] + (1, )) batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices) bgl.glEnable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_POLYGON_SMOOTH) bgl.glHint(bgl.GL_POLYGON_SMOOTH_HINT, bgl.GL_NICEST) batch.draw(shader) bgl.glDisable(bgl.GL_POLYGON_SMOOTH) bgl.glDisable(bgl.GL_BLEND) if in_tooltip_area: if self.draw_tooltip: slot_name = internals.qcd_slots.get_name(f"{tooltip_slot_idx}") slot_string = f"QCD Slot {tooltip_slot_idx}: \"{slot_name}\"\n" hotkey_string = (" * LMB - Move objects to slot.\n" " * Shift+LMB - Toggle objects\' slot.") draw_tooltip(self, context, shader, f"{slot_string}{hotkey_string}") self.hover_time = None else: if not self.hover_time: self.hover_time = time.time()
def draw(text, xyz=None, fontsize=None, dpi=None, fontid=None): fontid = FontManager.load(fontid) if xyz: blf.position(fontid, *xyz) if fontsize: FontManager.size(fontsize, dpi=dpi, fontid=fontid) return blf.draw(fontid, text)
def draw_callback1_px(self, context): # Getting the first object and face that raycast hits: mode = self.mode np_print('mode:', mode) region = self.region np_print('region', region) rv3d = self.rv3d np_print('rv3d', rv3d) co2d = self.co2d np_print('self.co2d', co2d) co3d = 1 center = Vector((0, 0, 0)) normal = Vector((0.0, 0.0, 1.0)) scenecast = scene_cast(region, rv3d, co2d) np_print('scenecast', scenecast) hitob = scenecast[4] np_print('hitob', hitob) if mode == 0: instruct = 'paint material on object / objects' elif mode == 1: instruct = 'pick material to paint with' elif mode == 2: instruct = 'pick material to paint with' elif mode == 3: instruct = 'paint material on single face' elif mode == 4: instruct = 'paint material on object / objects' if hitob is not None: acob = bpy.context.scene.objects.active bpy.context.scene.objects.active = hitob slots = hitob.material_slots for i, s in enumerate(slots): hitob.active_material_index = i bpy.ops.object.material_slot_remove() if self.shader is not None: hitob.data.materials.append(self.shader) np_print(hitob.select) if hitob.select == True: np_print('true') for ob in self.selob: bpy.context.scene.objects.active = ob slots = ob.material_slots for i, s in enumerate(slots): ob.active_material_index = i bpy.ops.object.material_slot_remove() if self.shader is not None: ob.data.materials.append(self.shader) bpy.context.scene.objects.active = acob #bpy.context.scene.update() np_print('040') elif mode == 5: instruct = 'pick material to paint with' if hitob is not None: mat = None findex = scenecast[3] np_print('findex', findex) me = hitob.data np_print('me', me) bme = bmesh.new() bme.from_mesh(me) bme.faces.ensure_lookup_table() np_print('faces', bme.faces) np_print('face', bme.faces[findex]) bmeface = bme.faces[findex] matindex = bmeface.material_index np_print('material_index', matindex) slots = list(hitob.material_slots) np_print('slots', slots) np_print('len slots', len(slots)) np_print('slots', slots) if len(slots) == 0: self.shader = None self.shadername = 'None' elif slots[matindex].material is not None: self.shader = slots[matindex].material self.shadername = slots[matindex].material.name else: self.shader = None self.shadername = 'None' bpy.context.scene.objects.active = hitob hitob.active_material_index = matindex np_print('self.shader', self.shader) np_print('050') else: self.shader = None self.shadername = 'None' elif mode == 6: instruct = 'pick material to paint with' elif mode == 7: instruct = 'paint material on single face' if hitob is not None: acob = bpy.context.scene.objects.active bpy.context.scene.objects.active = hitob findex = scenecast[3] np_print('findex', findex) me = hitob.data np_print('me', me) bpy.ops.object.mode_set(mode='EDIT') bme = bmesh.from_edit_mesh(me) bme.faces.ensure_lookup_table() np_print('faces', bme.faces) np_print('face', bme.faces[findex]) bmeface = bme.faces[findex] slots = list(hitob.material_slots) np_print('slots', list(slots)) m = 0 if list(slots) == []: hitob.data.materials.append(None) slots = list(hitob.material_slots) for i, s in enumerate(slots): np_print('s', s) if s.name == self.shadername: m = 1 matindex = i elif s.material == None and self.shader == None: m = 1 matindex = i if m == 0: hitob.data.materials.append(self.shader) matindex = len(slots) - 1 hitob.active_material_index = matindex bpy.context.tool_settings.mesh_select_mode = False, False, True bpy.ops.mesh.select_all(action='DESELECT') bmeface.select = True bmesh.update_edit_mesh(me, True) bpy.ops.object.material_slot_assign() bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.object.mode_set(mode='OBJECT') bpy.context.scene.objects.active = acob # ON-SCREEN INSTRUCTIONS: keys_aff = 'LMB - paint object / objects, CTRL - take material, ALT - paint single face' keys_nav = 'MMB, SCROLL - navigate' keys_neg = 'ESC - quit' display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg) col_bg_fill_main_run = addon_settings_graph('col_bg_fill_main_run') col_bg_fill_main_nav = addon_settings_graph('col_bg_fill_main_nav') # Drawing the small icon near the cursor and the shader name: # First color is for lighter themes, second for default and darker themes: if mode in {1, 2, 5, 6}: square = [[17, 30], [17, 39], [26, 39], [26, 30]] cur = [[17, 36], [18, 35], [14, 31], [14, 30], [15, 30], [19, 34], [18, 35], [20, 37], [21, 37], [21, 36], [19, 34], [20, 33]] curpipe = [[18, 35], [14, 31], [14, 30], [15, 30], [19, 34], [18, 35]] curcap = [[18, 35], [20, 37], [21, 37], [21, 36], [19, 34], [18, 35]] scale = 2.8 col_square = col_bg_fill_main_run for co in square: co[0] = round((co[0] * scale), 0) - 35 + co2d[0] co[1] = round((co[1] * scale), 0) - 88 + co2d[1] for co in cur: co[0] = round((co[0] * scale), 0) - 25 + co2d[0] co[1] = round((co[1] * scale), 0) - 86 + co2d[1] for co in curcap: co[0] = round((co[0] * scale), 0) - 25 + co2d[0] co[1] = round((co[1] * scale), 0) - 86 + co2d[1] for co in curpipe: co[0] = round((co[0] * scale), 0) - 25 + co2d[0] co[1] = round((co[1] * scale), 0) - 86 + co2d[1] bgl.glColor4f(*col_square) bgl.glBegin(bgl.GL_TRIANGLE_FAN) for x, y in square: bgl.glVertex2f(x, y) bgl.glEnd() #bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glColor4f(1.0, 1.0, 1.0, 0.8) bgl.glBegin(bgl.GL_LINE_STRIP) for x, y in cur: bgl.glVertex2f(x, y) bgl.glEnd() if mode in {2, 6}: bgl.glColor4f(1.0, 0.5, 0.5, 1.0) bgl.glBegin(bgl.GL_TRIANGLE_FAN) for x, y in curcap: bgl.glVertex2f(x, y) bgl.glEnd() else: square = [[17, 30], [17, 39], [26, 39], [26, 30]] cur = [[18, 30], [21, 33], [18, 36], [14, 32], [16, 32], [18, 30]] curtip = [[14, 32], [16, 32], [15, 33], [14, 32]] curbag = [[18, 30], [15, 33], [21, 33], [18, 30]] scale = 2.8 if mode in (3, 7): col_square = col_bg_fill_main_nav else: col_square = (0.25, 0.35, 0.4, 0.87) for co in square: co[0] = round((co[0] * scale), 0) - 35 + co2d[0] co[1] = round((co[1] * scale), 0) - 88 + co2d[1] for co in cur: co[0] = round((co[0] * scale), 0) - 25 + co2d[0] co[1] = round((co[1] * scale), 0) - 84 + co2d[1] for co in curtip: co[0] = round((co[0] * scale), 0) - 25 + co2d[0] co[1] = round((co[1] * scale), 0) - 84 + co2d[1] for co in curbag: co[0] = round((co[0] * scale), 0) - 25 + co2d[0] co[1] = round((co[1] * scale), 0) - 84 + co2d[1] bgl.glColor4f(*col_square) bgl.glBegin(bgl.GL_TRIANGLE_FAN) for x, y in square: bgl.glVertex2f(x, y) bgl.glEnd() #bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glColor4f(1.0, 1.0, 1.0, 0.8) bgl.glBegin(bgl.GL_LINE_STRIP) for x, y in cur: bgl.glVertex2f(x, y) bgl.glEnd() ''' if mode in {3, 7}: bgl.glBegin(bgl.GL_TRIANGLE_FAN) for x,y in curtip: bgl.glVertex2f(x,y) bgl.glEnd() bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINE_STRIP) for x,y in curtip: bgl.glVertex2f(x,y) bgl.glEnd() bgl.glLineWidth(1) ''' if self.shader is not None: bgl.glBegin(bgl.GL_TRIANGLE_FAN) for x, y in curbag: bgl.glVertex2f(x, y) bgl.glEnd() bgl.glColor4f(0.25, 0.35, 0.4, 0.87) font_id = 0 blf.size(font_id, 15, 72) blf.position(font_id, co2d[0] + 47, co2d[1] - 3, 0) blf.draw(font_id, self.shadername) bgl.glColor4f(1.0, 1.0, 1.0, 0.8) font_id = 0 blf.size(font_id, 15, 72) blf.position(font_id, co2d[0] + 46, co2d[1] - 2, 0) blf.draw(font_id, self.shadername) # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_text(location, text, size=15, color=(1, 1, 1, 1)): font_id = 0 ui_scale = bpy.context.preferences.system.ui_scale blf.position(font_id, *location) blf.size(font_id, round(size * ui_scale), 72) blf.draw(font_id, text)
def drawCallback(self, context): # use ImageTexture.evaluate / get Image.pixels in case of View2D? # seems unnecessary to restore afterwards. bgl.glViewport(*self.viewport) bgl.glScissor(*self.viewport) b = bgl.Buffer(bgl.GL_FLOAT, 3) for p in itertools.chain(self.points, self.current_mouse_points): bgl.glReadPixels(p[0], p[1], 1, 1, bgl.GL_RGB, bgl.GL_FLOAT, b) p[-1] = self.convertColorspace(context, b.to_list()) points_drawn = 0 max_points_to_draw = PTS_LIMIT - self.remaining last_point_drawn = None for p in self.points: if points_drawn == max_points_to_draw: break self.drawPoint(*p[2:5]) last_point_drawn = p points_drawn += 1 # under cursor -> probably not wanted for p in self.current_mouse_points[:-1]: if points_drawn == max_points_to_draw: break self.drawPoint(*p[2:5]) last_point_drawn = p points_drawn += 1 segments_drawn = 0 if len(self.points) > 1: ps = iter(self.points) next(ps) for p1, p2 in zip(self.points, ps): if segments_drawn == max_points_to_draw - 1: break self.drawSegment(p1[2], p1[3], p2[2], p2[3], False) segments_drawn += 1 if self.current_mouse_points: p1 = self.points[-1] p2 = self.current_mouse_points[0] if segments_drawn < max_points_to_draw - 1: self.drawSegment(p1[2], p1[3], p2[2], p2[3], True) segments_drawn += 1 if len(self.current_mouse_points) > 1: ps = iter(self.current_mouse_points) next(ps) for p1, p2 in zip(self.current_mouse_points, ps): if segments_drawn == max_points_to_draw - 1: break self.drawSegment(p1[2], p1[3], p2[2], p2[3], True) segments_drawn += 1 if points_drawn == max_points_to_draw: # this means even the point under the cursor _is_ already # surnumerary, thus we have to draw the last segment in red if self.current_mouse_points: p1 = last_point_drawn p2 = self.current_mouse_points[-1] self.drawSegment(p1[2], p1[3], p2[2], p2[3], True, True) if context.window_manager.crd_show_values: for p, i in zip( itertools.chain(self.points, self.current_mouse_points), range(points_drawn)): blf.position(0, p[2] + 10, p[3] - 10, 0) bgl.glColor4f(0.8, 0.8, 0.8, 1.0) blf.size(0, 10, context.user_preferences.system.dpi) blf.draw(0, "(%.3f, %.3f, %.3f)" % tuple(p[-1])) if points_drawn <= max_points_to_draw: # we want to draw the current color anyways if self.current_mouse_points: p = self.current_mouse_points[-1] blf.position(0, p[2] + 10, p[3] - 10, 0) bgl.glColor4f(0.8, 0.8, 0.8, 1.0) blf.size(0, 10, context.user_preferences.system.dpi) blf.draw(0, "(%.3f, %.3f, %.3f)" % tuple(p[-1])) bgl.glColor4f(0.8, 0.8, 0.8, 1.0) blf.size(0, 20, context.user_preferences.system.dpi) if context.window_manager.crd_use_intermediate: blf.position(0, 10, 60, 0) blf.draw(0, "Oversamples:") blf.position(0, 160, 60, 0) blf.draw(0, str(context.window_manager.crd_intermediate_amount)) blf.position(0, 10, 30, 0) blf.draw(0, "Path Type:") blf.position(0, 160, 30, 0) blf.draw(0, { 'POLYLINE': "Polyline", 'CUBIC_SPLINE': "Cubic Spline" }[context.window_manager.crd_path_type])
def draw_callback_mode(self, context): settings = context.scene.OASettings if self.ctrl and not settings.shift: mode_title(context, "Replace") bgl.glLineWidth(1) tool_shelf_width = get_tool_shelf_width(bpy.context) # add the offset-width and offset-height for the first time if self.menu_offset['first_iteration']: for icon in self.menu: # iterate over icon, frame and hover for i in (1, 2, 3): # iterate over lower left and upper right corner for j in (0, 2): icon[i][0 + j] += tool_shelf_width icon[i][1 + j] += bpy.context.region.height self.menu_offset['first_iteration'] = False # add current offset-region-height and offset-tool-shelf-width # when the user altered the size of the 3d-view or toggled region_overlap elif any(( self.menu_offset['width'] != tool_shelf_width, self.menu_offset['height'] != bpy.context.region.height, self.menu_offset['region_overlap'] != bool( bpy.context.user_preferences.system.use_region_overlap), )): for icon in self.menu: # iterate over icon, frame and hover for i in (1, 2, 3): # iterate over lower left and upper right corner for j in (0, 2): icon[i][0 + j] += (tool_shelf_width - self.menu_offset['width']) icon[i][1 + j] += (bpy.context.region.height - self.menu_offset['height']) self.menu_offset['width'] = tool_shelf_width self.menu_offset['height'] = bpy.context.region.height self.menu_offset['region_overlap'] = bool( bpy.context.user_preferences.system.use_region_overlap) # draw frame bgl.glColor3f(0.1, 0.1, 0.1) for icon in self.menu: bgl.glRecti(icon[2][0], icon[2][1], icon[2][2], icon[2][3]) # draw icons if settings.valid_icon_file: bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.img.bindcode) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST) for icon in self.menu: bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE) bgl.glBegin(bgl.GL_QUADS) bgl.glTexCoord2f(icon[4][0][0], icon[4][0][1]) bgl.glVertex2f(icon[1][0], icon[1][1]) bgl.glTexCoord2f(icon[4][1][0], icon[4][1][1]) bgl.glVertex2f(icon[1][0], icon[1][3]) bgl.glTexCoord2f(icon[4][2][0], icon[4][2][1]) bgl.glVertex2f(icon[1][2], icon[1][3]) bgl.glTexCoord2f(icon[4][3][0], icon[4][3][1]) bgl.glVertex2f(icon[1][2], icon[1][1]) bgl.glEnd() bgl.glDisable(bgl.GL_TEXTURE_2D) else: # draw category and model_id if no icon file is provided # draw background bgl.glColor3f(0.2, 0.2, 0.2) for icon in self.menu: bgl.glRecti(icon[2][0] + 2, icon[2][1] + 2, icon[2][2] - 2, icon[2][3] - 2) font_id = 0 bgl.glColor4f(1, 1, 1, 1) for icon in self.menu: blf.position(font_id, icon[1][0] + 1, icon[1][1] + 8, 0) blf.size(font_id, int(settings.menu_icon_display_size / 3), 72) blf.draw( font_id, "{0: >2}".format(icon[0][1]) + "," + "{0: >2}".format(icon[0][2])) # draw hover effekt for icon in self.menu: # mouse hover icon if mouse_over_icon(icon[1], self.mouse): bgl.glColor3f(0.6, 0.6, 0.6) bgl.glLineWidth(2) rect_round_corners(icon[3][0], icon[3][1], icon[3][2], icon[3][3]) # restore opengl defaults bgl.glLineWidth(1) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): sel = bpy.context.selected_objects mode = Storage.mode startloc3d = Storage.startloc3d endloc3d = Storage.endloc3d region = context.region rv3d = context.region_data startloc2d = view3d_utils.location_3d_to_region_2d(region, rv3d, startloc3d) endloc2d = view3d_utils.location_3d_to_region_2d(region, rv3d, endloc3d) if startloc2d == None: startloc2d = (0.0, 0.0) endloc2d = (0.0, 0.0) print(startloc2d, endloc2d) dist = (mathutils.Vector(endloc3d) - mathutils.Vector(startloc3d)) dist = dist.length dist = str(abs(round(dist, 2))) numloc = [] numloc.append((startloc2d[0] + endloc2d[0]) / 2) numloc.append((startloc2d[1] + endloc2d[1]) / 2) if mode == 0: main = 'SELECT START POINT' if mode == 1: main = 'SELECT END POINT' bgl.glEnable(bgl.GL_BLEND) # First color is for lighter themes, second for default and darker themes: #bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glLineWidth(1.35) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glVertex2f(*startloc2d) bgl.glVertex2f(*endloc2d) bgl.glEnd() bgl.glColor4f(0.1, 0.1, 0.1, 1.0) if mode == 1: font_id = 0 blf.size(font_id, 20, 72) blf.position(font_id, numloc[0], numloc[1], 0) blf.draw(font_id, dist) bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0) font_id = 0 bgl.glColor4f(1, 1, 1, 0.25) blf.size(font_id, 88, 72) blf.position(font_id, 5, 75, 0) blf.draw(font_id, 'N') blf.size(font_id, 28, 72) blf.position(font_id, 22, 75, 0) blf.draw(font_id, 'P') bgl.glColor4f(1, 1, 1, 1) blf.position(font_id, 75, 125, 0) blf.size(font_id, 16, 72) blf.draw(font_id, main) bgl.glColor4f(0, 0.5, 0, 1) blf.size(font_id, 11, 72) blf.position(font_id, 75, 105, 0) blf.draw(font_id, 'LMB - select, CTRL - snap') blf.position(font_id, 75, 90, 0) blf.draw(font_id, 'MMB - change axis') #blf.position(font_id,75,75,0) #blf.draw(font_id,'NUMPAD - value') bgl.glColor4f(1, 0, 0, 1) blf.position(font_id, 75, 75, 0) blf.draw(font_id, 'ESC, RMB - quit')
def draw_text_2d(text, size=20, color=WHITE): bgl.glColor4f(*color) text_cursor.y -= size + 3 # behaves like command line blf.position(FONT_ID, text_cursor.x, text_cursor.y, 0) blf.size(FONT_ID, size, 72) blf.draw(FONT_ID, text)
def Draw_Callback_Px(self, context): td = bpy.context.scene.td """Draw on the viewports""" #drawing routine #Get Parameters region = bpy.context.region screen_texel_x = 2/region.width screen_texel_y = 2/region.height font_size = 12 offset_x = int(bpy.context.preferences.addons[__package__].preferences.offset_x) offset_y = int(bpy.context.preferences.addons[__package__].preferences.offset_y) anchor_pos = bpy.context.preferences.addons[__package__].preferences.anchor_pos font_id = 0 blf.size(font_id, font_size, 72) blf.color(font_id, 1, 1, 1, 1) bake_min_value = 0 bake_max_value = 0 bake_value_precision = 3 if td.bake_vc_mode == "TD_FACES_TO_VC" or td.bake_vc_mode == "TD_ISLANDS_TO_VC": bake_min_value = float(td.bake_vc_min_td) bake_max_value = float(td.bake_vc_max_td) elif td.bake_vc_mode == "UV_SPACE_TO_VC": bake_min_value = float(td.bake_vc_min_space) bake_max_value = float(td.bake_vc_max_space) if abs(bake_max_value - bake_min_value) <= 3: bake_value_precision = 5 elif abs(bake_max_value - bake_min_value) <= 12: bake_value_precision = 4 elif abs(bake_max_value - bake_min_value) <= 25: bake_value_precision = 3 elif abs(bake_max_value - bake_min_value) <= 50: bake_value_precision = 2 else: bake_value_precision = 1 #Calculate Text Position from Anchor if anchor_pos == 'LEFT_BOTTOM': font_start_pos_x = 0 + offset_x font_start_pos_y = 0 + offset_y elif anchor_pos == 'LEFT_TOP': font_start_pos_x = 0 + offset_x font_start_pos_y = region.height - offset_y - 15 elif anchor_pos == 'RIGHT_BOTTOM': font_start_pos_x = region.width - offset_x - 250 font_start_pos_y = 0 + offset_y else: font_start_pos_x = region.width - offset_x - 250 font_start_pos_y = region.height - offset_y - 15 #Draw TD Values in Viewport via BLF blf.position(font_id, font_start_pos_x, font_start_pos_y + 18, 0) blf.draw(font_id, str(round(bake_min_value, bake_value_precision))) blf.position(font_id, font_start_pos_x + 115, font_start_pos_y + 18, 0) blf.draw(font_id, str(round((bake_max_value - bake_min_value) * 0.5 + bake_min_value, bake_value_precision))) blf.position(font_id, font_start_pos_x + 240, font_start_pos_y + 18, 0) blf.draw(font_id, str(round(bake_max_value, bake_value_precision))) blf.position(font_id, font_start_pos_x + 52, font_start_pos_y - 15, 0) blf.draw(font_id, str(round((bake_max_value - bake_min_value) * 0.25 + bake_min_value, bake_value_precision))) blf.position(font_id, font_start_pos_x + 177, font_start_pos_y - 15, 0) blf.draw(font_id, str(round((bake_max_value - bake_min_value) * 0.75 + bake_min_value, bake_value_precision))) #Draw Gradient via shader vertex_shader = ''' in vec2 position; out vec3 pos; void main() { pos = vec3(position, 0.0f); gl_Position = vec4(position, 0.0f, 1.0f); } ''' fragment_shader = ''' uniform float pos_x_min; uniform float pos_x_max; in vec3 pos; void main() { vec4 b = vec4(0.0f, 0.0f, 1.0f, 1.0f); vec4 c = vec4(0.0f, 1.0f, 1.0f, 1.0f); vec4 g = vec4(0.0f, 1.0f, 0.0f, 1.0f); vec4 y = vec4(1.0f, 1.0f, 0.0f, 1.0f); vec4 r = vec4(1.0f, 0.0f, 0.0f, 1.0f); float pos_x_25 = (pos_x_max - pos_x_min) * 0.25 + pos_x_min; float pos_x_50 = (pos_x_max - pos_x_min) * 0.5 + pos_x_min; float pos_x_75 = (pos_x_max - pos_x_min) * 0.75 + pos_x_min; float blendColor1 = (pos.x - pos_x_min)/(pos_x_25 - pos_x_min); float blendColor2 = (pos.x - pos_x_25)/(pos_x_50 - pos_x_25); float blendColor3 = (pos.x - pos_x_50)/(pos_x_75 - pos_x_50); float blendColor4 = (pos.x - pos_x_75)/(pos_x_max - pos_x_75); gl_FragColor = (c * blendColor1 + b * (1 - blendColor1)) * step(pos.x, pos_x_25) + (g * blendColor2 + c * (1 - blendColor2)) * step(pos.x, pos_x_50) * step(pos_x_25, pos.x) + (y * blendColor3 + g * (1 - blendColor3)) * step(pos.x, pos_x_75) * step(pos_x_50, pos.x) + (r * blendColor4 + y * (1 - blendColor4)) * step(pos.x, pos_x_max) * step(pos_x_75, pos.x); } ''' gradient_x_min = screen_texel_x * offset_x gradient_x_max = screen_texel_x * (offset_x + 250) gradient_y_min = screen_texel_y * offset_y gradient_y_max = screen_texel_y * (offset_y + 15) if anchor_pos == 'LEFT_BOTTOM': vertices = ( (-1.0 + gradient_x_min, -1.0 + gradient_y_max), (-1.0 + gradient_x_max, -1.0 + gradient_y_max), (-1.0 + gradient_x_min, -1.0 + gradient_y_min), (-1.0 + gradient_x_max, -1.0 + gradient_y_min)) pos_x_min = -1.0 + gradient_x_min pos_x_max = -1.0 + gradient_x_max elif anchor_pos == 'LEFT_TOP': vertices = ( (-1.0 + gradient_x_min, 1.0 - gradient_y_max), (-1.0 + gradient_x_max, 1.0 - gradient_y_max), (-1.0 + gradient_x_min, 1.0 - gradient_y_min), (-1.0 + gradient_x_max, 1.0 - gradient_y_min)) pos_x_min = -1.0 + gradient_x_min pos_x_max = -1.0 +gradient_x_max elif anchor_pos == 'RIGHT_BOTTOM': vertices = ( (1.0 - gradient_x_min, -1.0 + gradient_y_max), (1.0 - gradient_x_max, -1.0 + gradient_y_max), (1.0 - gradient_x_min, -1.0 + gradient_y_min), (1.0 - gradient_x_max, -1.0 + gradient_y_min)) pos_x_min = 1.0 - gradient_x_max pos_x_max = 1.0 - gradient_x_min else: vertices = ( (1.0 - gradient_x_min, 1.0 - gradient_y_max), (1.0 - gradient_x_max, 1.0 - gradient_y_max), (1.0 - gradient_x_min, 1.0 - gradient_y_min), (1.0 - gradient_x_max, 1.0 - gradient_y_min)) pos_x_min = 1.0 - gradient_x_max pos_x_max = 1.0 - gradient_x_min indices = ( (0, 1, 2), (2, 1, 3)) shader = gpu.types.GPUShader(vertex_shader, fragment_shader) batch = batch_for_shader(shader, 'TRIS', {"position": vertices}, indices=indices) shader.bind() shader.uniform_float("pos_x_min", pos_x_min) shader.uniform_float("pos_x_max", pos_x_max) batch.draw(shader)
def draw_label(coords, text) : pos = pos_2d(coords) blf.position(font_id, pos.x, pos.y, 0) blf.draw(font_id, text)
def draw_2D(self, context): settings = common_utilities.get_settings() region,r3d = context.region,context.space_data.region_3d color_inactive = settings.theme_colors_mesh[settings.theme] color_selection = settings.theme_colors_selection[settings.theme] color_active = settings.theme_colors_active[settings.theme] color_frozen = settings.theme_colors_frozen[settings.theme] color_warning = settings.theme_colors_warning[settings.theme] bgl.glEnable(bgl.GL_POINT_SMOOTH) color_handle = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00) color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00) color_fill = (color_inactive[0], color_inactive[1], color_inactive[2], 0.20) if self.fsm_mode == 'sketch' and self.sketch: # Draw smoothing line (end of sketch to current mouse position) common_drawing_px.draw_polyline_from_points(context, [self.sketch_curpos, self.sketch[-1][0]], color_active, 1, "GL_LINE_SMOOTH") # Draw sketching stroke common_drawing_px.draw_polyline_from_points(context, [co[0] for co in self.sketch], color_selection, 2, "GL_LINE_STIPPLE") if self.fsm_mode in {'scale tool','rotate tool'}: # Draw a scale/rotate line from tool origin to current mouse position common_drawing_px.draw_polyline_from_points(context, [self.action_center, self.mode_pos], (0, 0, 0, 0.5), 1, "GL_LINE_STIPPLE") bgl.glLineWidth(1) if self.fsm_mode == 'brush scale tool': # scaling brush size self.sketch_brush.draw(context, color=(1, 1, 1, .5), linewidth=1, color_size=(1, 1, 1, 1)) elif self.fsm_mode not in {'grab tool','scale tool','rotate tool'} and not self.is_navigating: # draw the brush oriented to surface ray,hit = common_utilities.ray_cast_region2d_bvh(region, r3d, self.cur_pos, mesh_cache['bvh'], self.mx, settings) hit_p3d,hit_norm,hit_idx = hit if hit_idx != None: # and not self.hover_ed: mx = self.mx mxnorm = mx.transposed().inverted().to_3x3() hit_p3d = mx * hit_p3d hit_norm = mxnorm * hit_norm common_drawing_px.draw_circle(context, hit_p3d, hit_norm.normalized(), self.stroke_radius, (1,1,1,.5)) if self.fsm_mode == 'sketch' and self.sketch: ray,hit = common_utilities.ray_cast_region2d_bvh(region, r3d, self.sketch[0][0], mesh_cache['bvh'],self.mx, settings) hit_p3d,hit_norm,hit_idx = hit if hit_idx != None: mx = self.mx mxnorm = mx.transposed().inverted().to_3x3() hit_p3d = mx * hit_p3d hit_norm = mxnorm * hit_norm common_drawing_px.draw_circle(context, hit_p3d, hit_norm.normalized(), self.stroke_radius, (1,1,1,.5)) if self.hover_ed and False: #EXTEND to display hoverable edges color = (color_selection[0], color_selection[1], color_selection[2], 1.00) common_drawing_px.draw_bmedge(context, self.hover_ed, self.dest_obj.matrix_world, 2, color) if self.act_gedge: if settings.show_segment_count: bgl.glColor4f(*color_active) self.draw_gedge_info(self.act_gedge, context) if self.act_gpatch: if settings.show_segment_count: bgl.glColor4f(*color_active) self.draw_gpatch_info(self.act_gpatch, context) if True: txt = 'v:%d e:%d s:%d p:%d' % (len(self.polystrips.gverts), len(self.polystrips.gedges), len(self.polystrips.gedgeseries), len(self.polystrips.gpatches)) txt_width, txt_height = blf.dimensions(0, txt) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0,0,0,0.8) bgl.glBegin(bgl.GL_QUADS) bgl.glVertex2f(0, 0) bgl.glVertex2f(10+txt_width, 0) bgl.glVertex2f(10+txt_width, 10+txt_height) bgl.glVertex2f(0, 10+txt_height) bgl.glEnd() bgl.glColor4f(1,1,1,1) blf.position(0, 5, 5, 0) blf.draw(0, txt)
def draw_callback_px(self, context): if context.scene.OW_display_override: font_id = 0 # XXX, need to find out how best to get this blf.position(font_id, 28, bpy.context.area.height - 85, 0) blf.draw(font_id, "Override ON")
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]
def draw_callback_px(self, context): wm = context.window_manager sc = context.scene if not wm.do_show_tags: return ob = context.object if not ob: return if not ob.type == 'MESH': return # status font_id = 0 blf.position(font_id, 45, 45, 0) #blf.size(font_id, 20, 48) # 20, 72) blf.size(font_id, 15, 72) blf.draw(font_id, "displaying tags") # region reg = bpy.context.region r3d = bpy.context.space_data.region_3d # transformation matrix (local co => global co) T = ob.matrix_world.copy() # vert tags if len(ob.vtags)>0 and sc.pyfem_show_vtag: blf.size(font_id, sc.pyfem_vert_font, 72) r, g, b = sc.pyfem_vert_color bgl.glColor4f(r, g, b, 1.0) for v in ob.vtags.values(): if v.tag >= 0: continue pm = ob.data.vertices[v.idx].co co = view3d_utils.location_3d_to_region_2d(reg, r3d, T*pm) blf.position(font_id, co[0], co[1], 0) blf.draw(font_id, "%d"%v.tag) # edge tags if len(ob.etags)>0 and sc.pyfem_show_etag: blf.size(font_id, sc.pyfem_edge_font, 72) r, g, b = sc.pyfem_edge_color bgl.glColor4f(r, g, b, 1.0) for v in ob.etags.values(): if v.tag >= 0: continue pa = ob.data.vertices[v.v0].co pb = ob.data.vertices[v.v1].co pm = (pa+pb)/2.0 co = view3d_utils.location_3d_to_region_2d(reg, r3d, T*pm) blf.position(font_id, co[0], co[1], 0) blf.draw(font_id, "%d"%v.tag) # cell tags if len(ob.ctags)>0 and sc.pyfem_show_ctag: blf.size(font_id, sc.pyfem_cell_font, 72) r, g, b = sc.pyfem_cell_color bgl.glColor4f(r, g, b, 1.0) for v in ob.ctags.values(): if v.tag >= 0: continue c = ob.data.polygons[v.idx] pm = ob.data.vertices[c.vertices[0]].co.copy() for k in range(1, len(c.vertices)): pm += ob.data.vertices[c.vertices[k]].co pm /= float(len(c.vertices)) co = view3d_utils.location_3d_to_region_2d(reg, r3d, T*pm) blf.position(font_id, co[0], co[1], 0) blf.draw(font_id, "%d"%v.tag)
def addDraw(self, x, y, size, text, color): blf.position(font_id, x, y, 0) blf.size(font_id, size, 72) blf.color(font_id, color[0], color[1], color[2], 1) blf.draw(font_id, text)
def DRAW_Overlay(self, context): print('DRAW_Overlay_START', ';', 'NP020PL.flag = ', NP020PL.flag) flag = NP020PL.flag helper = NP020PL.helper region = bpy.context.region rv3d = bpy.context.region_data rw = region.width rh = region.height co2d = view3d_utils.location_3d_to_region_2d(region, rv3d, helper.location) frompoints = NP020PL.frompoints topoints = NP020PL.topoints col_line_main = (1.0, 1.0, 1.0, 1.0) col_line_shadow = (0.1, 0.1, 0.1, 0.25) #greys: mark_col_A = (0.25, 0.25, 0.25, 1.0) mark_col_B = (0.5, 0.5, 0.5, 1.0) mark_col_C = (0.75, 0.75, 0.75, 1.0) #marins mark_col_A = (0.25, 0.35, 0.4, 1.0) mark_col_B = (0.5, 0.6, 0.65, 1.0) mark_col_C = (0.67, 0.77, 0.82, 1.0) # writing the dots for recwidget widget at center of scene: r = 12 angstep = 20 psize = 25 pofsetx = 15 pofsety = 15 fsize = 20 fofsetx = -8 fofsety = -7 widget_circle = construct_circle_2d(r, angstep) if flag == 'RUNTRANSF0': instruct = 'place start for point a' keys_aff = 'LMB - select, CTRL - snap, ENT - change snap' frompoints[0] = helper.location elif flag == 'RUNTRANST0': instruct = 'place target for point a' keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value' topoints[0] = helper.location elif flag == 'RUNTRANSF1': instruct = 'place start for point b' keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align A (translate)' frompoints[1] = helper.location elif flag == 'RUNTRANST1': instruct = 'place target for point b' keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align A (translate)' topoints[1] = helper.location elif flag == 'RUNTRANSF2': instruct = 'place start for point c' keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align AB (translate, rotate)' frompoints[2] = helper.location elif flag == 'RUNTRANST2': instruct = 'place target for point c' keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align AB (translate, rotate)' topoints[2] = helper.location # ON-SCREEN INSTRUCTIONS: keys_nav = '' keys_neg = 'ESC - quit' display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg) # LINE: for i, frompoint in enumerate(frompoints): topoint = topoints[i] if frompoint != None and topoint != None: bgl.glColor4f(*col_line_shadow) bgl.glLineWidth(1.4) bgl.glBegin(bgl.GL_LINE_STRIP) frompoint = view3d_utils.location_3d_to_region_2d( region, rv3d, frompoint) topoint = view3d_utils.location_3d_to_region_2d( region, rv3d, topoint) bgl.glVertex2f((frompoint[0] - 1), (frompoint[1] - 1)) bgl.glVertex2f((topoint[0] - 1), (topoint[1] - 1)) bgl.glEnd() bgl.glColor4f(*col_line_main) bgl.glLineWidth(1.4) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glVertex2f(*frompoint) bgl.glVertex2f(*topoint) bgl.glEnd() # drawing of markers: i = 0 for point in frompoints: if point != None: point = view3d_utils.location_3d_to_region_2d(region, rv3d, point) point[0] = point[0] + pofsetx point[1] = point[1] + pofsety widget = [] for co in widget_circle: c = [0.0, 0.0] c[0] = co[0] + point[0] + pofsetx c[1] = co[1] + point[1] + pofsety widget.append(c) bgl.glEnable(bgl.GL_BLEND) if i == 0: bgl.glColor4f(*mark_col_A) mark = "A" elif i == 1: bgl.glColor4f(*mark_col_B) mark = "B" elif i == 2: bgl.glColor4f(*mark_col_C) mark = "C" ''' bgl.glLineWidth(1) bgl.glBegin(bgl.GL_LINE_STRIP) for co in widget: bgl.glVertex2f(*co) bgl.glVertex2f(*widget[len(widget) - 1]) bgl.glEnd() bgl.glBegin(bgl.GL_TRIANGLE_FAN) for co in widget: bgl.glVertex2f(*co) bgl.glEnd() ''' font_id = 0 bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(psize) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(*point) bgl.glEnd() bgl.glDisable(bgl.GL_POINT_SMOOTH) bgl.glColor4f(1.0, 1.0, 1.0, 0.75) blf.size(font_id, fsize, 72) blf.position(font_id, point[0] + fofsetx, point[1] + fofsety, 0) blf.draw(font_id, mark) i = i + 1 i = 0 for point in topoints: if point != None: point = view3d_utils.location_3d_to_region_2d(region, rv3d, point) point[0] = point[0] + pofsetx point[1] = point[1] + pofsety widget = [] for co in widget_circle: c = [0.0, 0.0] c[0] = co[0] + point[0] + pofsetx c[1] = co[1] + point[1] + pofsety widget.append(c) bgl.glEnable(bgl.GL_BLEND) if i == 0: bgl.glColor4f(*mark_col_A) mark = "A'" elif i == 1: bgl.glColor4f(*mark_col_B) mark = "B'" elif i == 2: bgl.glColor4f(*mark_col_C) mark = "C'" ''' bgl.glLineWidth(1) bgl.glBegin(bgl.GL_LINE_STRIP) for co in widget: bgl.glVertex2f(*co) bgl.glVertex2f(*widget[len(widget) - 1]) bgl.glEnd() bgl.glBegin(bgl.GL_TRIANGLE_FAN) for co in widget: bgl.glVertex2f(*co) bgl.glEnd() ''' font_id = 0 bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(psize) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(*point) bgl.glEnd() bgl.glDisable(bgl.GL_POINT_SMOOTH) bgl.glColor4f(1.0, 1.0, 1.0, 0.75) blf.size(font_id, fsize, 72) blf.position(font_id, point[0] + fofsetx, point[1] + fofsety, 0) blf.draw(font_id, mark) i = i + 1 #ENDING: bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_text(self, context, pos_x, pos_y, text): font_id = 0 blf.size(font_id, FONT_SIZE, 72) blf.position(font_id, pos_x, pos_y, 0) blf.draw(font_id, text)
def draw_callback_px(self, context): font_id = 0 alpha = context.scene.pen_tool_props.a font_size = context.scene.pen_tool_props.fs bgl.glColor4f(0.0, 0.6, 1.0, alpha) bgl.glPointSize(4.0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(pt_buf.x, pt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # location 3d if context.scene.pen_tool_props.b2 is True: mloc3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location) blf.position(font_id, pt_buf.x + 15, pt_buf.y - 15, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw( font_id, '(' + str(round(mloc3d[0], 4)) + ', ' + str(round(mloc3d[1], 4)) + ', ' + str(round(mloc3d[2], 4)) + ')') n = len(pt_buf.list_m_loc_3d) if n != 0: # add points bgl.glEnable(bgl.GL_BLEND) bgl.glPointSize(4.0) bgl.glBegin(bgl.GL_POINTS) for i in pt_buf.list_m_loc_3d: loc_0 = location_3d_to_region_2d(context.region, context.space_data.region_3d, i) bgl.glVertex2f(loc_0[0], loc_0[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # text next to the mouse m_loc_3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location) vec0 = pt_buf.list_m_loc_3d[-1] - m_loc_3d blf.position(font_id, pt_buf.x + 15, pt_buf.y + 15, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(vec0.length, 4))) # angle first after mouse if n >= 2: vec1 = pt_buf.list_m_loc_3d[-2] - pt_buf.list_m_loc_3d[-1] if vec0.length == 0.0 or vec1.length == 0.0: pass else: ang = vec0.angle(vec1) if round(degrees(ang), 2) == 180.0: text_0 = '0.0' elif round(degrees(ang), 2) == 0.0: text_0 = '180.0' else: text_0 = str(round(degrees(ang), 2)) loc_4 = location_3d_to_region_2d(context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1]) bgl.glColor4f(0.0, 1.0, 0.525, alpha) blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, text_0 + '') bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE) # enable line stipple bgl.glColor4f(0.0, 0.6, 1.0, alpha) # draw line between last point and mouse bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_LINES) loc_1 = location_3d_to_region_2d(context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1]) bgl.glVertex2f(loc_1[0], loc_1[1]) bgl.glVertex2f(pt_buf.x, pt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # draw lines between points bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_LINE_STRIP) for j in pt_buf.list_m_loc_3d: loc_2 = location_3d_to_region_2d(context.region, context.space_data.region_3d, j) bgl.glVertex2f(loc_2[0], loc_2[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_LINE_STIPPLE) # disable line stipple # draw line length between points if context.scene.pen_tool_props.b1 is True: for k in range(n - 1): loc_3 = location_3d_to_region_2d( context.region, context.space_data.region_3d, (pt_buf.list_m_loc_3d[k] + pt_buf.list_m_loc_3d[(k + 1) % n]) * 0.5) blf.position(font_id, loc_3[0] + 10, loc_3[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw( font_id, str( round((pt_buf.list_m_loc_3d[k] - pt_buf.list_m_loc_3d[(k + 1) % n]).length, 4))) # draw all angles if context.scene.pen_tool_props.b0 is True: for h in range(n - 1): if n >= 2: if h == 0: pass else: vec_ = pt_buf.list_m_loc_3d[h] - pt_buf.list_m_loc_3d[ (h - 1) % n] vec_1_ = pt_buf.list_m_loc_3d[h] vec_2_ = pt_buf.list_m_loc_3d[(h - 1) % n] if vec_.length == 0.0 or vec_1_.length == 0.0 or vec_2_.length == 0.0: pass else: ang = vec_.angle(vec_1_ - vec_2_) if round(degrees(ang)) == 0.0: pass else: loc_4 = location_3d_to_region_2d( context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[h]) bgl.glColor4f(0.0, 1.0, 0.525, alpha) blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(degrees(ang), 2)) + '') # tools on / off bgl.glColor4f(1.0, 1.0, 1.0, 1.0) blf.position(font_id, self.text_location, 20, 0) blf.size(font_id, 15, context.user_preferences.system.dpi) blf.draw(font_id, "Draw On") blf.position(font_id, self.text_location, 40, 0) blf.draw(font_id, "Extrude On" if pt_buf.ctrl else "Extrude Off")
def draw_callback_px(self, context): # circle graphic, text, and slider unify_settings = bpy.context.tool_settings.unified_paint_settings strength = unify_settings.strength if self.uni_str else self.brush.strength size = unify_settings.size if self.uni_size else self.brush.size if self.graphic: bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(self.brushcolor.r, self.brushcolor.g, self.brushcolor.b, strength * 0.25) bgl.glBegin(bgl.GL_POLYGON) for x, y in self.circlepoints: bgl.glVertex2i( int(size * x) + self.cur[0], int(size * y) + self.cur[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0) if self.text != 'NONE' and self.doingstr: if self.text == 'MEDIUM': fontsize = 11 elif self.text == 'LARGE': fontsize = 22 else: fontsize = 8 font_id = 0 blf.size(font_id, fontsize, 72) blf.shadow(font_id, 0, 0.0, 0.0, 0.0, 1.0) blf.enable(font_id, blf.SHADOW) if strength < 0.001: text = "0.001" else: text = str(strength)[0:5] textsize = blf.dimensions(font_id, text) xpos = self.start[0] + self.offset[0] ypos = self.start[1] + self.offset[1] bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(self.backcolor.r, self.backcolor.g, self.backcolor.b, 0.5) bgl.glBegin(bgl.GL_POLYGON) for x, y in self.rectpoints: bgl.glVertex2i( int(textsize[0] * x) + xpos, int(textsize[1] * y) + ypos) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0) blf.position(font_id, xpos, ypos, 0) blf.draw(font_id, text) blf.disable(font_id, blf.SHADOW) if self.slider != 'NONE' and self.doingstr: bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(self.backcolor.r, self.backcolor.g, self.backcolor.b, 0.5) xpos = self.start[0] + self.offset[0] - self.sliderwidth + ( 32 if self.text == 'MEDIUM' else 64 if self.text == 'LARGE' else 23) ypos = self.start[1] + self.offset[ 1] - self.sliderheight # + (1 if self.slider != 'SMALL' else 0) if strength <= 1.0: sliderscale = strength elif strength > 5.0: sliderscale = strength / 10 elif strength > 2.0: sliderscale = strength / 5 else: sliderscale = strength / 2 bgl.glBegin(bgl.GL_POLYGON) for x, y in self.rectpoints: bgl.glVertex2i( int(self.sliderwidth * x) + xpos, int(self.sliderheight * y) + ypos - 1) bgl.glEnd() bgl.glColor4f(self.frontcolor.r, self.frontcolor.g, self.frontcolor.b, 0.8) bgl.glBegin(bgl.GL_POLYGON) for x, y in self.rectpoints: bgl.glVertex2i( int(self.sliderwidth * x * sliderscale) + xpos, int(self.sliderheight * y * 0.75) + ypos) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)