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モード以外では利用できません"
            )
Beispiel #2
0
	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)
Beispiel #3
0
def draw_callback_px(self, context):
    scene = context.scene

    font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 18, 72)
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)

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

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


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

    # restore defaults
    blf.disable(font_id, blf.SHADOW)
    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']
                )
            )
Beispiel #5
0
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 draw_callback_px(self, context):
    col = self.textcolor
    font_id = 0
    
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 0, 0.0, 0.0, 0.0, 1.0)
    blf.position(font_id, 64, 24, 0)
    blf.size(font_id, 11, 72)
    
    blf.draw(font_id, self.nearname)
    
    blf.disable(font_id, blf.SHADOW)
    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)
Beispiel #8
0
 def text_size(self, context):
     """
         overall on-screen size in pixels
     """
     dpi, font_id = context.user_preferences.system.dpi, 0
     if self.angle != 0:
         blf.enable(font_id, blf.ROTATION)
         blf.rotation(font_id, self.angle)
     blf.aspect(font_id, 1.0)
     blf.size(font_id, self.font_size, dpi)
     x, y = blf.dimensions(font_id, self.text)
     if self.angle != 0:
         blf.disable(font_id, blf.ROTATION)
     return Vector((x, y))
    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)
Beispiel #10
0
    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)
Beispiel #11
0
    def draw(self, context, render=False):

        # print("draw_text %s %s" % (self.text, type(self).__name__))
        self.render = render
        x, y = self.position_2d_from_coord(context, self.pts[0], render)
        # dirty fast assignment
        dpi, font_id = context.user_preferences.system.dpi, 0
        bgl.glColor4f(*self.colour)
        if self.angle != 0:
            blf.enable(font_id, blf.ROTATION)
            blf.rotation(font_id, self.angle)
        blf.size(font_id, self.font_size, dpi)
        blf.position(font_id, x, y, 0)
        blf.draw(font_id, self.text)
        if self.angle != 0:
            blf.disable(font_id, blf.ROTATION)
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_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)
Beispiel #14
0
def draw_callback_px(self, context):
    scene = context.scene

    font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 18, 72)
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)

    blf.draw(font_id, "Total render time " + str(timedelta(seconds = timer["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: " + str(timedelta(seconds = (timer["average"] * (scene.frame_end - scene.frame_current)))))

    # restore defaults
    blf.disable(font_id, blf.SHADOW)
Beispiel #15
0
    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"
            )
Beispiel #16
0
    def draw(self, context, render=False):

        # print("draw_text %s %s" % (self.text, type(self).__name__))
        self.render = render
        p = self.position_2d_from_coord(context, self.pts[0], render)

        # dirty fast assignment
        dpi, font_id = context.preferences.system.dpi, 0

        # self.cbuff[0:4] = self.colour

        # bgl.glEnableClientState(bgl.GL_COLOR_ARRAY)
        # bgl.glColorPointer(4, bgl.GL_FLOAT, 0, self.cbuff)
        blf.color(0, *self.colour)
        if self.angle != 0:
            blf.enable(font_id, blf.ROTATION)
            blf.rotation(font_id, self.angle)
        blf.size(font_id, self.font_size, dpi)
        blf.position(font_id, p.x, p.y, 0)
        blf.draw(font_id, self.text)
        if self.angle != 0:
            blf.disable(font_id, blf.ROTATION)
Beispiel #17
0
    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 disable_word_wrap(fontid=None):
     return blf.disable(FontManager.load(fontid), blf.WORD_WRAP)
 def disable_shadow(fontid=None):
     return blf.disable(FontManager.load(fontid), blf.SHADOW)
Beispiel #20
0
 def disable_clipping(self, fontid):
     return blf.disable(fontid, blf.CLIPPING)
Beispiel #21
0
 def disable_rotation(fontid=None):
     return blf.disable(FontManager.load(fontid), blf.ROTATION)
Beispiel #22
0
def _draw_3dview_report(window, area, region):
    """Draws reports in 3d views.

    :param window: window of 3D viewport
    :type window: bpy.types.Window
    :param area: area of 3D viewport
    :type area: bpy.types.Area
    :param region: region of 3D viewport
    :type region: bpy.types.Region
    """
    from io_scs_tools.operators.wm import SCS_TOOLS_OT_Show3DViewReport as _Show3DViewReport

    # no reported lines, we don't draw anything
    if not _Show3DViewReport.has_lines():
        return

    # calculate dynamic left and top margins
    if bpy.context.preferences.system.use_region_overlap:
        pos_x = 75
        # try to find tools region and properly adopt position X
        for reg in area.regions:
            if reg.type == 'TOOLS':
                pos_x = reg.width + 20
                break
        pos_y = region.height - 105
    else:
        pos_x = 20
        pos_y = region.height - 80

    # draw BT banner
    (bindcode, width,
     height) = _Show3DViewReport.get_scs_banner_img_data(window)

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    draw_texture_2d(bindcode, (pos_x - 5, pos_y), width, height)
    bgl.glDisable(bgl.GL_BLEND)

    # draw control buttons, if controls are enabled
    if _Show3DViewReport.has_controls(window):

        blf.size(0, 20, 72)
        blf.color(0, .8, .8, .8, 1)

        # set x and y offsets to report operator, so that area calculations for buttons can be calculated properly
        # considering dynamic left and top margins.
        _Show3DViewReport.set_btns_xy_offset(pos_x, region.height - pos_y)

        # draw close button
        _primitive.draw_rect_2d(
            ((pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[3]),
             (pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[3])),
            (.25, .25, .25, 1))

        # draw close button text
        blf.position(0, pos_x + _OP_consts.View3DReport.CLOSE_BTN_TEXT_POS[0],
                     pos_y - _OP_consts.View3DReport.CLOSE_BTN_TEXT_POS[1], 0)
        blf.draw(0, _OP_consts.View3DReport.CLOSE_BTN_TEXT)

        # draw hide button
        _primitive.draw_rect_2d(
            ((pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[3]),
             (pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[3])),
            (.25, .25, .25, 1))

        # draw hide button text
        blf.position(0, pos_x + _OP_consts.View3DReport.HIDE_BTN_TEXT_POS[0],
                     pos_y - _OP_consts.View3DReport.HIDE_BTN_TEXT_POS[1], 0)
        blf.draw(0, _OP_consts.View3DReport.HIDE_BTN_TEXT)

        # draw scroll controls
        if _Show3DViewReport.is_scrolled() and _Show3DViewReport.is_shown():

            blf.size(0, 16, 72)

            # draw scroll up button
            _primitive.draw_rect_2d(
                ((pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[3]),
                 (pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[3])),
                (.25, .25, .25, 1))

            # draw scroll up button text
            blf.position(
                0, pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_TEXT_POS[0],
                pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_TEXT_POS[1], 0)
            blf.draw(0, _OP_consts.View3DReport.SCROLLUP_BTN_TEXT)

            # draw scroll down button
            _primitive.draw_rect_2d(
                ((pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[3]),
                 (pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[3])),
                (.25, .25, .25, 1))

            # draw scroll down button text
            blf.position(
                0, pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_TEXT_POS[0],
                pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_TEXT_POS[1], 0)
            blf.draw(0, _OP_consts.View3DReport.SCROLLDOWN_BTN_TEXT)

    # draw version string
    pos_y -= 12
    blf.size(0, 10, 72)
    blf.color(0, .952, .635, .062, 1)
    blf.position(0, pos_x, pos_y, 0)
    blf.draw(0, _info_utils.get_combined_ver_str(only_version_numbers=True))
    pos_y -= 20

    # draw actual operator title and message if shown
    if _Show3DViewReport.is_shown():

        blf.size(0, 12, 72)
        blf.color(0, 1, 1, 1, 1)
        blf.shadow(0, 5, 0, 0, 0, 1)

        if _Show3DViewReport.get_title() != "":
            blf.position(0, pos_x, pos_y, 0)
            blf.draw(0, _Show3DViewReport.get_title())
            pos_y -= 15

        blf.enable(0, blf.SHADOW)
        _Show3DViewReport.set_out_of_bounds(False)
        for line in _Show3DViewReport.get_lines():

            # finish printing if running out of space
            if pos_y - 60 < 0:
                blf.position(0, pos_x, pos_y, 0)
                blf.draw(0, "...")
                pos_y -= 15
                _Show3DViewReport.set_out_of_bounds(True)
                break

            blf.position(0, pos_x, pos_y, 0)
            if "ERROR" in line:
                blf.shadow(0, 5, 0.5, 0., 0, 1)
            elif "WARNING" in line:
                blf.shadow(0, 5, 0.3, 0.15, 0, 1)

            blf.draw(0, line)
            pos_y -= 15

        blf.disable(0, blf.SHADOW)
Beispiel #23
0
def draw_screen_cast_HUD(context):
    p = get_prefs()
    operators = get_last_operators(context,
                                   debug=False)[-p.screencast_operator_count:]

    font = 0
    scale = context.preferences.view.ui_scale * get_prefs().HUD_scale

    # initiate the horizontal offset based on the presence of the tools bar
    tools = [r for r in context.area.regions if r.type == 'TOOLS']
    offset_x = tools[0].width if tools else 0

    # then add some more depending on wether the addon prefix is used
    offset_x += 7 if p.screencast_show_addon else 15

    # initiate the vertical offset based on the height of the redo panel, use a 50px base offset
    redo = [r for r in context.area.regions if r.type == 'HUD']
    offset_y = redo[0].height + 50 if redo else 50

    # emphasize the last op
    emphasize = 1.25

    # get addon prefix offset, based on widest possiblestring 'MM', and based on empasized last op's size
    if p.screencast_show_addon:
        blf.size(font, round(p.screencast_fontsize * scale * emphasize), 72)
        addon_offset_x = blf.dimensions(font, 'MM')[0]
    else:
        addon_offset_x = 0

    y = 0
    hgap = 10

    for idx, (addon, label, idname, prop) in enumerate(reversed(operators)):
        size = round(p.screencast_fontsize * scale *
                     (emphasize if idx == 0 else 1))
        vgap = round(size / 2)

        color = green if idname.startswith(
            'machin3.') and p.screencast_highlight_machin3 else white
        alpha = (len(operators) - idx) / len(operators)

        # enable shadowing for the last op and idname
        if idx == 0:
            blf.enable(font, blf.SHADOW)

            blf.shadow_offset(font, 3, -3)
            blf.shadow(font, 5, *black, 1.0)

        # label

        text = f"{label}: {prop}" if prop else label

        x = offset_x + addon_offset_x
        y = offset_y * scale if idx == 0 else y + (
            blf.dimensions(font, text)[1] + vgap)

        blf.size(font, size, 72)
        blf.color(font, *color, alpha)
        blf.position(font, x, y, 0)

        blf.draw(font, text)

        # idname

        if p.screencast_show_idname:
            x += blf.dimensions(font, text)[0] + hgap

            blf.size(font, size - 2, 72)
            blf.color(font, *color, alpha * 0.3)
            blf.position(font, x, y, 0)

            blf.draw(font, f"{idname}")

            # reset size
            blf.size(font, size, 72)

        # diable shadowing, we don't want to use it for the addon prefix or for the other ops
        if idx == 0:
            blf.disable(font, blf.SHADOW)

        # addon prefix

        if addon and p.screencast_show_addon:
            blf.size(font, size, 72)

            x = offset_x + addon_offset_x - blf.dimensions(
                font, addon)[0] - (hgap / 2)

            blf.color(font, *white, alpha * 0.3)
            blf.position(font, x, y, 0)

            blf.draw(font, addon)

        if idx == 0:
            y += blf.dimensions(font, text)[1]
Beispiel #24
0
def _draw_3dview_report(region):
    """Draws reports in 3d views.

    :param region: region of 3D viewport
    :type region: bpy.types.Region
    """
    pos = region.height - 62

    if _Show3DViewReportOperator.has_lines():

        glEnable(GL_TEXTURE_2D)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glBindTexture(GL_TEXTURE_2D, _Show3DViewReportOperator.get_scs_logo_img_bindcode())

        # draw BT logo
        glBegin(GL_POLYGON)
        glColor3f(1, 1, 1)
        glTexCoord2f(0, 1)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[0], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[2], 0)
        glTexCoord2f(1, 1)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[1], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[2], 0)
        glTexCoord2f(1, 0)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[1], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[3], 0)
        glTexCoord2f(0, 0)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[0], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[3], 0)
        glEnd()

        glDisable(GL_TEXTURE_2D)

        # draw version string
        blf.size(0, 10, 72)
        glColor3f(.952, .635, .062)
        blf.position(0, 20, pos, 0)
        blf.draw(0, _info_utils.get_combined_ver_str(only_version_numbers=True))
        pos -= 20

        # draw actual operator title and message if shown
        if _Show3DViewReportOperator.is_shown():

            blf.size(0, 12, 72)
            glColor3f(1, 1, 1)
            blf.shadow(0, 5, 0, 0, 0, 1)

            if _Show3DViewReportOperator.get_title() != "":
                blf.position(0, 20, pos, 0)
                blf.draw(0, _Show3DViewReportOperator.get_title())
                pos -= 15

            blf.enable(0, blf.SHADOW)
            for line in _Show3DViewReportOperator.get_lines():

                # finish printing if running out of space
                if pos - 60 < 0:
                    blf.position(0, 20, pos, 0)
                    blf.draw(0, "...")
                    break

                blf.position(0, 20, pos, 0)
                if "ERROR" in line:
                    blf.shadow(0, 5, 0.5, 0., 0, 1)
                elif "WARNING" in line:
                    blf.shadow(0, 5, 0.3, 0.15, 0, 1)

                blf.draw(0, line)
                pos -= 15

            blf.disable(0, blf.SHADOW)

        # draw control buttons if controls are enabled
        if _Show3DViewReportOperator.has_controls():

            # draw close button
            glColor3f(.4, .4, .4)
            glBegin(GL_POLYGON)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[0], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[1], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[1], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[3], 0)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[0], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[3], 0)
            glEnd()

            # draw hide button
            glBegin(GL_POLYGON)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[0], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[1], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[1], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[3], 0)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[0], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[3], 0)
            glEnd()

            # gather texts and positions
            close_btn_text_pos = _OP_consts.View3DReport.CLOSE_BTN_TEXT_POS[int(not _Show3DViewReportOperator.is_shown())]
            close_btn_text = _OP_consts.View3DReport.CLOSE_BTN_TEXT[int(not _Show3DViewReportOperator.is_shown())]

            hide_btn_text_pos = _OP_consts.View3DReport.HIDE_BTN_TEXT_POS[int(not _Show3DViewReportOperator.is_shown())]
            hide_btn_text = _OP_consts.View3DReport.HIDE_BTN_TEXT[int(not _Show3DViewReportOperator.is_shown())]

            blf.size(0, 15, 72)

            # draw close button text
            glColor3f(1, 1, 1)
            blf.position(0, close_btn_text_pos[0], region.height - close_btn_text_pos[1], 0)
            blf.draw(0, close_btn_text)

            # draw hide button text
            blf.position(0, hide_btn_text_pos[0], region.height - hide_btn_text_pos[1], 0)
            blf.draw(0, hide_btn_text)
Beispiel #25
0
	def draw(self):
		if self.visible == False: return
		module.post_draw_step += 1
		
		cam = self.scene.active_camera
		orth = cam.ortho_scale
		
		height = render.getWindowHeight()
		width = render.getWindowWidth()
		near = cam.near
		far = cam.far
		h = cam.worldPosition.z
		font_id = Label._fontname_id[self._font]
		unit = width/orth
		self._glunit = unit
		rpos = self._position - cam.worldPosition
		
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, width, 0, height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
		
		bgl.glEnable(bgl.GL_BLEND)
		bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
		bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1)
		
		#Z AXIS
		oh = (far-near)/2
		ortho_unit = 1/oh
		dh = oh

		pos = list([width/2+rpos[0]*unit, height/2+rpos[1]*unit, dh*ortho_unit + rpos[2]*ortho_unit])
		if self._lastscale != self.scale or True:
			blf.size(font_id, int(self.scale.x*unit), 72)
		else:
			if self._lastorth != orth:
				sc = (float(self._lastorth) / float(orth)) * self.scale.x
				bgl.glScalef(sc,sc,1)
				print(str(self._lastorth) + " " + str(orth))
				pos[0] /= sc
				pos[1] /= sc
				
			else:
				self._lastorth = orth
		
		x, y = blf.dimensions(font_id, self._text) #NOTE: Always after blf.size()
		
		if self.align == ALIGN_CENTER:
			pos[0] -= (x)/2 * math.cos(self._rotation.z)
			pos[1] -= x/2 * math.sin(self._rotation.z)
		if self.align == ALIGN_RIGHT:
			pos[0] -= x * math.cos(self._rotation.z)
			pos[1] -= x * math.sin(self._rotation.z)
			
		if self.middle_height == True:
			pos[0] -= y/4 * math.sin(self._rotation.z)
			pos[1] -= y/4 * math.cos(self._rotation.z)
		
		blf.position(font_id, pos[0], pos[1], pos[2])
		blf.enable(font_id, blf.ROTATION)
		if self.rotation.z > 0.01 or self.rotation.z < -0.01:
			blf.rotation(font_id, self._rotation.z)
		else:
			blf.rotation(font_id, 0)
		
		if self.shadow == True:
			blf.position(font_id, pos[0]+self.shadow_offset[0], pos[1]+self.shadow_offset[1], pos[2])
			bgl.glColor4f(*self.shadow_color)
			blf.blur(font_id, self.shadow_blur)
			blf.draw(font_id, self._text)
			blf.position(font_id, pos[0], pos[1], pos[2])
			
		bgl.glColor4f(*self._color)
		blf.blur(font_id, self.blur)
		blf.draw(font_id, self._text)
		
		blf.disable(font_id, blf.ROTATION)
		
		self._lastscale = self.scale
Beispiel #26
0
    def draw(self):
        if self.visible == False: return
        module.post_draw_step += 1

        cam = self.scene.active_camera
        orth = cam.ortho_scale

        height = render.getWindowHeight()
        width = render.getWindowWidth()
        near = cam.near
        far = cam.far
        h = cam.worldPosition.z
        font_id = Label._fontname_id[self._font]
        unit = width / orth
        self._glunit = unit
        rpos = self._position - cam.worldPosition

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

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
        bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1)

        #Z AXIS
        oh = (far - near) / 2
        ortho_unit = 1 / oh
        dh = oh

        pos = list([
            width / 2 + rpos[0] * unit, height / 2 + rpos[1] * unit,
            dh * ortho_unit + rpos[2] * ortho_unit
        ])
        if self._lastscale != self.scale or True:
            blf.size(font_id, int(self.scale.x * unit), 72)
        else:
            if self._lastorth != orth:
                sc = (float(self._lastorth) / float(orth)) * self.scale.x
                bgl.glScalef(sc, sc, 1)
                print(str(self._lastorth) + " " + str(orth))
                pos[0] /= sc
                pos[1] /= sc

            else:
                self._lastorth = orth

        x, y = blf.dimensions(font_id,
                              self._text)  #NOTE: Always after blf.size()

        if self.align == ALIGN_CENTER:
            pos[0] -= (x) / 2 * math.cos(self._rotation.z)
            pos[1] -= x / 2 * math.sin(self._rotation.z)
        if self.align == ALIGN_RIGHT:
            pos[0] -= x * math.cos(self._rotation.z)
            pos[1] -= x * math.sin(self._rotation.z)

        if self.middle_height == True:
            pos[0] -= y / 4 * math.sin(self._rotation.z)
            pos[1] -= y / 4 * math.cos(self._rotation.z)

        blf.position(font_id, pos[0], pos[1], pos[2])
        blf.enable(font_id, blf.ROTATION)
        if self.rotation.z > 0.01 or self.rotation.z < -0.01:
            blf.rotation(font_id, self._rotation.z)
        else:
            blf.rotation(font_id, 0)

        if self.shadow == True:
            blf.position(font_id, pos[0] + self.shadow_offset[0],
                         pos[1] + self.shadow_offset[1], pos[2])
            bgl.glColor4f(*self.shadow_color)
            blf.blur(font_id, self.shadow_blur)
            blf.draw(font_id, self._text)
            blf.position(font_id, pos[0], pos[1], pos[2])

        bgl.glColor4f(*self._color)
        blf.blur(font_id, self.blur)
        blf.draw(font_id, self._text)

        blf.disable(font_id, blf.ROTATION)

        self._lastscale = self.scale
Beispiel #27
0
def draw_callback_px(self, context):
    """Draws Code Editors Minimap and indentation marks"""

    def draw_line(origin, length, thickness, vertical=False):
        """Drawing lines with polys, its faster"""
        x = (origin[0] + thickness) if vertical else (origin[0] + length)
        y = (origin[1] + length) if vertical else (origin[1] + thickness)
        bgl.glBegin(bgl.GL_QUADS)
        for v1, v2 in [origin, (x, origin[1]), (x, y), (origin[0], y)]:
            bgl.glVertex2i(v1, v2)
        bgl.glEnd()
        return

    # abort if another text editor
    if self.area == context.area and self.window == context.window:
        bgl.glEnable(bgl.GL_BLEND)
    else:
        return

    start = time.clock()

    # init params
    font_id = 0
    self.width = next(region.width for region in context.area.regions if region.type == "WINDOW")
    self.height = next(region.height for region in context.area.regions if region.type == "WINDOW")
    dpi_r = context.user_preferences.system.dpi / 72.0
    self.left_edge = self.width - round(dpi_r * (self.width + 5 * self.minimap_width) / 10.0)
    self.right_edge = self.width - round(dpi_r * 15)
    self.opacity = min(max(0, (self.width - self.min_width) / 100.0), 1)

    # compute character dimensions
    mcw = dpi_r * self.minimap_symbol_width  # minimap char width
    mlh = round(dpi_r * self.minimap_line_height)  # minimap line height
    fs = context.space_data.font_size
    cw = round(dpi_r * round(2 + 0.6 * (fs - 4)))  # char width
    ch = round(dpi_r * round(2 + 1.3 * (fs - 2) + ((fs % 10) == 0)))  # char height

    # panel background box
    self.tab_width = round(dpi_r * 25) if (self.tabs and len(bpy.data.texts) > 1) else 0
    bgl.glColor4f(self.background.r, self.background.g, self.background.b, (1 - self.bg_opacity) * self.opacity)
    bgl.glBegin(bgl.GL_QUADS)
    for x, y in [
        (self.left_edge - self.tab_width, self.height),
        (self.right_edge, self.height),
        (self.right_edge, 0),
        (self.left_edge - self.tab_width, 0),
    ]:
        bgl.glVertex2i(x, y)
    bgl.glEnd()

    # line numbers background
    space = context.space_data
    if space.text:
        lines = len(space.text.lines)
        lines_digits = len(str(lines)) if space.show_line_numbers else 0
        self.line_bar_width = int(dpi_r * 5) + cw * (lines_digits)
        bgl.glColor4f(self.background.r, self.background.g, self.background.b, 1)
        bgl.glBegin(bgl.GL_QUADS)
        for x, y in [(0, self.height), (self.line_bar_width, self.height), (self.line_bar_width, 0), (0, 0)]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()
        # shadow
        bgl.glLineWidth(1.0 * dpi_r)
        for id, intensity in enumerate([0.2, 0.1, 0.07, 0.05, 0.03, 0.02, 0.01]):
            bgl.glColor4f(0.0, 0.0, 0.0, intensity)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in [(self.line_bar_width + id, 0), (self.line_bar_width + id, self.height)]:
                bgl.glVertex2i(x, y)
            bgl.glEnd()

    # minimap shadow
    for id, intensity in enumerate([0.2, 0.1, 0.07, 0.05, 0.03, 0.02, 0.01]):
        bgl.glColor4f(0.0, 0.0, 0.0, intensity * self.opacity)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x, y in [(self.left_edge - id - self.tab_width, 0), (self.left_edge - id - self.tab_width, self.height)]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()

    # divider
    if self.tab_width:
        bgl.glColor4f(0.0, 0.0, 0.0, 0.2 * self.opacity)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x, y in [(self.left_edge, 0), (self.left_edge, self.height)]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()

    # if there is text in window
    if space.text and self.opacity:

        # minimap horizontal sliding based on text block length
        max_slide = max(0, mlh * (lines + self.height / ch) - self.height)
        self.slide = int(max_slide * space.top / lines)
        minimap_top_line = int(self.slide / mlh)
        minimap_bot_line = int((self.height + self.slide) / mlh)

        # draw minimap visible box
        if self.in_minimap:
            bgl.glColor4f(1.0, 1.0, 1.0, 0.1 * self.opacity)
        else:
            bgl.glColor4f(1.0, 1.0, 1.0, 0.07 * self.opacity)
        bgl.glBegin(bgl.GL_QUADS)
        for x, y in [
            (self.left_edge, self.height - mlh * space.top + self.slide),
            (self.right_edge, self.height - mlh * space.top + self.slide),
            (self.right_edge, self.height - mlh * (space.top + space.visible_lines) + self.slide),
            (self.left_edge, self.height - mlh * (space.top + space.visible_lines) + self.slide),
        ]:
            bgl.glVertex2i(x, y)
        bgl.glEnd()

        # draw minimap code
        for segment in self.segments[:-1]:
            bgl.glColor4f(segment["col"][0], segment["col"][1], segment["col"][2], 0.4 * self.opacity)
            for id, element in enumerate(segment["elements"][minimap_top_line:minimap_bot_line]):
                loc_y = mlh * (id + minimap_top_line + 3) - self.slide
                for sub_element in element:
                    draw_line(
                        (self.left_edge + int(mcw * (sub_element[0] + 4)), self.height - loc_y),
                        int(mcw * (sub_element[1] - sub_element[0])),
                        int(0.5 * mlh),
                    )

        # minimap code marks
        bgl.glColor4f(
            self.segments[-2]["col"][0],
            self.segments[-2]["col"][1],
            self.segments[-2]["col"][2],
            0.3 * self.block_trans * self.opacity,
        )
        for id, element in enumerate(self.segments[-2]["elements"]):
            for sub_element in element:
                if sub_element[2] >= space.top or id < space.top + space.visible_lines:
                    draw_line(
                        (self.left_edge + int(mcw * (sub_element[0] + 4)), self.height - mlh * (id + 3) + self.slide),
                        -int(mlh * (sub_element[2] - id - 1)),
                        int(0.5 * mlh),
                        True,
                    )

    # draw dotted indentation marks
    bgl.glLineWidth(1.0 * dpi_r)
    if space.text:
        bgl.glColor4f(
            self.segments[0]["col"][0], self.segments[0]["col"][1], self.segments[0]["col"][2], self.indent_trans
        )
        for id, element in enumerate(self.segments[-1]["elements"][space.top : space.top + space.visible_lines]):
            loc_y = id
            for sub_element in element:
                draw_line(
                    (int(dpi_r * 10) + cw * (lines_digits + sub_element[0] + 4), self.height - ch * (loc_y)),
                    -ch,
                    int(1 * dpi_r),
                    True,
                )

        # draw code block marks
        bgl.glColor4f(
            self.segments[-2]["col"][0], self.segments[-2]["col"][1], self.segments[-2]["col"][2], self.block_trans
        )
        for id, element in enumerate(self.segments[-2]["elements"]):
            for sub_element in element:
                if sub_element[2] >= space.top or id < space.top + space.visible_lines:
                    bgl.glBegin(bgl.GL_LINE_STRIP)
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0])), self.height - ch * (id + 1 - space.top)
                    )
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0])),
                        self.height - int(ch * (sub_element[2] - space.top)),
                    )
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0] + 1)),
                        self.height - int(ch * (sub_element[2] - space.top)),
                    )
                    bgl.glEnd()

    # tab dividers
    if self.tab_width and self.opacity:
        self.tab_height = min(200, int(self.height / len(bpy.data.texts)))
        y_loc = self.height - 5
        for text in bpy.data.texts:
            # tab selection
            if text.name == self.in_tab:
                bgl.glColor4f(1.0, 1.0, 1.0, 0.05 * self.opacity)
                bgl.glBegin(bgl.GL_QUADS)
                for x, y in [
                    (self.left_edge - self.tab_width, y_loc),
                    (self.left_edge, y_loc),
                    (self.left_edge, y_loc - self.tab_height),
                    (self.left_edge - self.tab_width, y_loc - self.tab_height),
                ]:
                    bgl.glVertex2i(x, y)
                bgl.glEnd()
            # tab active
            if context.space_data.text and text.name == context.space_data.text.name:
                bgl.glColor4f(1.0, 1.0, 1.0, 0.05 * self.opacity)
                bgl.glBegin(bgl.GL_QUADS)
                for x, y in [
                    (self.left_edge - self.tab_width, y_loc),
                    (self.left_edge, y_loc),
                    (self.left_edge, y_loc - self.tab_height),
                    (self.left_edge - self.tab_width, y_loc - self.tab_height),
                ]:
                    bgl.glVertex2i(x, y)
                bgl.glEnd()
            bgl.glColor4f(0.0, 0.0, 0.0, 0.2 * self.opacity)
            y_loc -= self.tab_height
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in [(self.left_edge - self.tab_width, y_loc), (self.left_edge, y_loc)]:
                bgl.glVertex2i(x, y)
            bgl.glEnd()

    # draw fps
    #    bgl.glColor4f(1, 1, 1, 0.2)
    #    blf.size(font_id, fs, int(dpi_r*72))
    #    blf.position(font_id, self.left_edge-50, 5, 0)
    #    blf.draw(font_id, str(round(1/(time.clock() - start),3)))

    # draw line numbers
    if space.text:
        bgl.glColor4f(self.segments[0]["col"][0], self.segments[0]["col"][1], self.segments[0]["col"][2], 0.5)
        for id in range(space.top, min(space.top + space.visible_lines + 1, lines + 1)):
            if self.in_line_bar and self.segments[-2]["elements"][id - 1]:
                bgl.glColor4f(self.segments[-2]["col"][0], self.segments[-2]["col"][1], self.segments[-2]["col"][2], 1)
                blf.position(
                    font_id, 2 + int(0.5 * cw * (len(str(lines)) - 1)), self.height - ch * (id - space.top) + 3, 0
                )
                # blf.draw(font_id, '→')
                blf.draw(font_id, "↓")
                bgl.glColor4f(self.segments[0]["col"][0], self.segments[0]["col"][1], self.segments[0]["col"][2], 0.5)
            else:
                blf.position(
                    font_id,
                    2 + int(0.5 * cw * (len(str(lines)) - len(str(id)))),
                    self.height - ch * (id - space.top) + 3,
                    0,
                )
                blf.draw(font_id, str(id))

    # draw file names
    if self.tab_width:
        blf.enable(font_id, blf.ROTATION)
        blf.rotation(font_id, 1.570796)
        y_loc = self.height
        for text in bpy.data.texts:
            text_max_length = max(2, int((self.tab_height - 40) / cw))
            name = text.name[:text_max_length]
            if text_max_length < len(text.name):
                name += "..."
            bgl.glColor4f(
                self.segments[0]["col"][0],
                self.segments[0]["col"][1],
                self.segments[0]["col"][2],
                (0.7 if text.name == self.in_tab else 0.4) * self.opacity,
            )
            blf.position(
                font_id,
                self.left_edge - round((self.tab_width - ch) / 2.0) - 5,
                round(y_loc - (self.tab_height / 2) - cw * len(name) / 2),
                0,
            )
            blf.draw(font_id, name)
            y_loc -= self.tab_height

    # restore opengl defaults
    bgl.glColor4f(0, 0, 0, 1)
    bgl.glLineWidth(1.0)
    bgl.glDisable(bgl.GL_BLEND)
    blf.disable(font_id, blf.ROTATION)
    return
Beispiel #28
0
 def disable_kerning_default(fontid=None):
     # note: not a listed option in docs for `blf.disable`, but see `blf.word_wrap`
     return blf.disable(FontManager.load(fontid), blf.KERNING_DEFAULT)
Beispiel #29
0
 def disable(option, fontid=None):
     return blf.disable(FontManager.load(fontid), option)
Beispiel #30
0
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

    vertices = []
    colors = []
    indices = []

    text = ""
    font_id = 0
    do_text = False

    if self.graphic:
        # circle inside brush
        starti = len(vertices)
        for x, y in circlepoints:
            vertices.append(
                (int(size * x) + self.cur[0], int(size * y) + self.cur[1]))
            colors.append((self.brushcolor.r, self.brushcolor.g,
                           self.brushcolor.b, strength * 0.25))
        for i in circleindices:
            indices.append((starti + i[0], starti + i[1], starti + i[2]))

    if self.text != 'NONE' and self.doingstr:
        if self.text == 'MEDIUM':
            fontsize = 11
        elif self.text == 'LARGE':
            fontsize = 22
        else:
            fontsize = 8

        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]
        blf.position(font_id, xpos, ypos, 0)

        # rectangle behind text
        starti = len(vertices)
        # rectpoints: (0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)
        for x, y in rectpoints:
            vertices.append(
                (int(textsize[0] * x) + xpos, int(textsize[1] * y) + ypos))
            colors.append(
                (self.backcolor.r, self.backcolor.g, self.backcolor.b, 0.5))
        indices.extend(((starti, starti + 1, starti + 2), (starti + 2, starti,
                                                           starti + 3)))

        do_text = True

    if self.slider != 'NONE' and self.doingstr:
        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

        # slider back rect
        starti = len(vertices)
        # rectpoints: (0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)
        for x, y in rectpoints:
            vertices.append((int(self.sliderwidth * x) + xpos,
                             int(self.sliderheight * y) + ypos - 1))
            colors.append(
                (self.backcolor.r, self.backcolor.g, self.backcolor.b, 0.5))
        indices.extend(((starti, starti + 1, starti + 2), (starti + 2, starti,
                                                           starti + 3)))

        # slider front rect
        starti = len(vertices)
        # rectpoints: (0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)
        for x, y in rectpoints:
            vertices.append((int(self.sliderwidth * x * sliderscale) + xpos,
                             int(self.sliderheight * y * 0.75) + ypos))
            colors.append(
                (self.frontcolor.r, self.frontcolor.g, self.frontcolor.b, 0.8))
        indices.extend(((starti, starti + 1, starti + 2), (starti + 2, starti,
                                                           starti + 3)))

    shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
    batch = batch_for_shader(shader,
                             'TRIS', {
                                 "pos": vertices,
                                 "color": colors
                             },
                             indices=indices)

    bgl.glEnable(bgl.GL_BLEND)
    shader.bind()
    batch.draw(shader)
    bgl.glDisable(bgl.GL_BLEND)

    if do_text:
        blf.draw(font_id, text)
        blf.disable(font_id, blf.SHADOW)
    def __render(cls, context):

        if not cls.is_valid_context(context):
            return

        for region in context.area.regions:
            if region.type == 'WINDOW':
                break
        else:
            return

        scene = context.scene
        ruvi_props = scene.ruvi_properties
        uv_select_sync = scene.tool_settings.use_uv_select_sync
        bg_color = (0.0, 0.0, 0.0, 0.3)
        blf.shadow(0, 3, 1.0, 0.0, 0.0, 1.0)
        blf.shadow_offset(0, 2, -2)

        [me, bm, uv_layer] = cls.__init_bmesh(context)

        for f in bm.faces:
            if not f.select and not uv_select_sync:
                continue

            selected_loops_count = 0
            uvc = Vector([0.0, 0.0])  #center uv of the face

            for loop1 in f.loops:

                uv1 = loop1[uv_layer].uv
                uvc += uv1  #loop1[uv_layer].uv
                if not loop1[uv_layer].select and not uv_select_sync:
                    continue
                selected_loops_count += 1

                # Draw Vert index
                if ruvi_props.verts:
                    if uv_select_sync and not loop1.vert.select:
                        continue

                    #cls.__draw_vert_index(
                    cls.__render_text_index(
                        context,
                        region,
                        loop1.vert.index,
                        uv1,
                        bg_color=bg_color,
                    )

                # Get next loop parameter
                loop2, *arg = cls.__get_2nd_loop(loop1, uv_layer)
                if loop2 is None:
                    continue
                uv2, uvm, uvt, uvn = arg

                blf.enable(0, blf.ROTATION)

                # Draw Edge index
                if ruvi_props.edges:
                    if (not uv_select_sync and loop2[uv_layer].select) \
                            or (uv_select_sync and loop2.vert.select
                                                and loop1.edge.select):

                        cls.__render_text_index(
                            context,
                            region,
                            loop1.edge.index,
                            uvm,
                            uvt=uvt,
                            uvn=uvn,
                            bg_color=bg_color,
                        )

                blf.enable(0, blf.SHADOW)

                # Draw Loop index
                if ruvi_props.loops and not uv_select_sync:

                    cls.__render_text_index(context,
                                            region,
                                            loop1.index,
                                            uvm,
                                            uvt=uvt,
                                            uvn=uvn,
                                            loop_offset=(1.0, 1.5))

                blf.disable(0, blf.ROTATION)
                blf.disable(0, blf.SHADOW)

            # Draw Face index
            if ruvi_props.faces and (
                (not uv_select_sync and selected_loops_count) or
                (uv_select_sync and f.select)):

                cls.__render_text_index(
                    context,
                    region,
                    f.index,
                    uvc / len(f.loops),
                )
Beispiel #32
0
    def draw_label(self,
                   context,
                   text,
                   pos,
                   dir,
                   gap=4,
                   center=True,
                   vcenter=False):
        """Draw text label

        Args:
          pos: bottom-center

        aligned and centered at segment middle
        """
        # 0 is the default font, but we're fancier than that
        font_id = self.font_id

        dpi = context.preferences.system.dpi

        color = context.scene.DocProperties.decorations_colour

        ang = -Vector((1, 0)).angle_signed(dir)
        cos = math.cos(ang)
        sin = math.sin(ang)

        # Horrific prototype code
        factor = self.camera_zoom_to_factor(
            context.space_data.region_3d.view_camera_zoom)
        camera_width_px = factor * context.region.width
        mm_to_px = camera_width_px / self.camera_width_mm
        # 0.004118616 is a magic constant number I visually discovered to get the right number.
        # In particular it works only for the OpenGOST font and produces a 2.5mm font size.
        # It probably should be dynamically calculated using system.dpi or something.
        # font_size = 16 <-- this is a good default
        font_size = int(0.004118616 * mm_to_px)

        blf.size(font_id, font_size, dpi)

        w, h = 0, 0
        if center or vcenter:
            w, h = blf.dimensions(font_id, text)

        if center:
            # horizontal centering
            pos -= Vector((cos, sin)) * w * 0.5

        if vcenter:
            # vertical centering
            pos -= Vector((-sin, cos)) * h * 0.5

        if gap:
            # side-shifting
            pos += Vector((-sin, cos)) * gap

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

        blf.rotation(font_id, ang)
        blf.color(font_id, *color)
        # blf.enable(font_id, blf.SHADOW)
        # blf.shadow(font_id, 5, 0, 0, 0, 1)
        # blf.shadow_offset(font_id, 1, -1)
        blf.draw(font_id, text)
        blf.disable(font_id, blf.ROTATION)
Beispiel #33
0
def display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg):


    userpref = bpy.context.user_preferences
    system = userpref.system
    rwtools = 0
    rwui = 0

    np_print(system.window_draw_method, system.use_region_overlap)


    if system.use_region_overlap:
        if system.window_draw_method in ('TRIPLE_BUFFER', 'AUTOMATIC') :

            area = bpy.context.area
            np_print('GO', area.regions)
            for r in area.regions:
                if r.type == 'TOOLS':
                    rwtools = r.width
                elif r.type == 'UI':
                    rwui = r.width

    np_print('rwtools', rwtools, 'rwui', rwui)
    field_keys_y = 46
    field_keys_x = 80
    rw = region.width
    rh = region.height
    np_print('rw, rh', rw, rh)

    expand = False
    crop = False

    len_aff_max = rw - 140 - rwtools - rwui
    len_aff = len(keys_aff) * 5
    len_neg = len(keys_neg) * 5
    len_ins = len(instruct) * 18
    if len_aff > len_aff_max: expand = True

    rw_min = 480
    rh_min = 280
    if rw - rwtools - rwui < rw_min or rh < rh_min: crop = True


    version = '020'
    font_id = 0

    keys_aff_1 = copy.deepcopy(keys_aff)
    keys_aff_2 = ' '
    if expand:
        keys_aff_1 = ''
        keys_aff_2 = ''
        np_print('len(keys_aff)', len(keys_aff))
        stop = 0
        for i in range (0, len(keys_aff)-1):
            #np_print(keys_aff[i])
            if keys_aff[i] == ',' and i * 5 <= len_aff_max and i > stop:
                stop = i
        np_print('stop', stop)
        for i in range(0, stop + 1):
            keys_aff_1 = keys_aff_1 + keys_aff[i]
        for i in range(stop + 2, len(keys_aff)):
            keys_aff_2 = keys_aff_2 + keys_aff[i]
        np_print(keys_aff_1)
        np_print(keys_aff_2)


    field_keys_aff_1 = [[field_keys_x + rwtools, field_keys_y + 21], [field_keys_x + rwtools, field_keys_y + 39], [rw - int(field_keys_x / 2) - rwui, field_keys_y + 39], [rw - int(field_keys_x / 2) - rwui, field_keys_y + 21]]
    field_keys_aff_2 = copy.deepcopy(field_keys_aff_1)
    field_keys_neg = [[field_keys_x + rwtools, field_keys_y], [field_keys_x + rwtools, field_keys_y + 18], [rw - int(field_keys_x / 2) - rwui, field_keys_y + 18], [rw - int(field_keys_x / 2) - rwui, field_keys_y]]
    if expand:
        field_keys_aff_2 = copy.deepcopy(field_keys_neg)
        field_keys_neg = [[field_keys_x + rwtools, field_keys_y - 21], [field_keys_x + rwtools, field_keys_y - 3], [rw - int(field_keys_x / 2) - rwui, field_keys_y - 3], [rw - int(field_keys_x / 2) - rwui, field_keys_y - 21]]

    size_font_np = 25
    size_font_instruct = 21
    size_font_keys = 11
    len_np_ins = len_ins + int(size_font_np * 2.1)

    pos_font_np_x = (rw - len_np_ins / 2) / 2 + rwtools / 2 - rwui / 2
    pos_font_np_y = 150
    if crop: pos_font_np_y = 75
    pos_font_instruct_x = pos_font_np_x + int(size_font_np * 2.1)
    pos_font_instruct_y = pos_font_np_y + 4
    pos_font_keys_aff_1_x = field_keys_x + 8 + rwtools
    pos_font_keys_aff_1_y = field_keys_y + 26
    pos_font_keys_aff_2_x = copy.deepcopy(pos_font_keys_aff_1_x)
    pos_font_keys_aff_2_y = copy.deepcopy(pos_font_keys_aff_1_y)
    pos_font_keys_nav_x = field_keys_x + 8 + rwtools
    pos_font_keys_nav_y = field_keys_y + 5
    pos_font_keys_neg_x = rw - 52 - len_neg - rwui
    np_print('len_neg', len_neg)
    np_print('pos_font_keys_neg_x', pos_font_keys_neg_x)
    pos_font_keys_neg_y = field_keys_y + 5
    if expand:
        pos_font_keys_aff_2_x = field_keys_x + 8 + rwtools
        pos_font_keys_aff_2_y = field_keys_y + 5
        pos_font_keys_nav_x = field_keys_x + 8 + rwtools
        pos_font_keys_nav_y = field_keys_y - 16
        pos_font_keys_neg_x = rw - 52 - len_neg - rwui
        pos_font_keys_neg_y = field_keys_y - 16 - rwui

    col_font_np = addon_settings_graph()['col_font_np']
    col_font_instruct_main = addon_settings_graph()['col_font_instruct_main']
    col_font_instruct_shadow = addon_settings_graph()['col_font_instruct_shadow']
    col_font_keys = addon_settings_graph()['col_font_keys']
    col_field_keys_aff = addon_settings_graph()['col_field_keys_aff']
    col_field_keys_neg = addon_settings_graph()['col_field_keys_neg']



    # instructions - NP:

    bgl.glColor4f(*col_font_np)
    blf.size(font_id, size_font_np, 72)
    blf.position(font_id, pos_font_np_x, pos_font_np_y, 0)
    blf.draw(font_id, 'NP')

    blf.enable(font_id, ROTATION)
    ang = radians(90)
    blf.size(font_id, int(size_font_np / 2.2), 72)
    blf.rotation(font_id, ang)
    blf.position(font_id, pos_font_np_x + int(size_font_np * 1.72) , pos_font_np_y - 2, 0)
    blf.draw(font_id, version)
    blf.disable(font_id, ROTATION)

    # instructions - instruct:

    bgl.glColor4f(*col_font_instruct_shadow)
    blf.position(font_id, pos_font_instruct_x + 1, pos_font_instruct_y - 1, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glColor4f(*col_font_instruct_main)
    blf.position(font_id, pos_font_instruct_x, pos_font_instruct_y, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glDisable(bgl.GL_BLEND)

    # instructions - keys - backdrop fields:

    bgl.glEnable(bgl.GL_BLEND)

    if crop == False:

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_1:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_2:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_neg)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_neg:
            bgl.glVertex2f(*co)
        bgl.glEnd()


        # instructions - keys - writing:

        bgl.glColor4f(*col_font_keys)
        blf.size(font_id, size_font_keys, 72)

        blf.position(font_id, pos_font_keys_aff_1_x, pos_font_keys_aff_1_y, 0)
        blf.draw(font_id, keys_aff_1)

        blf.position(font_id, pos_font_keys_aff_2_x, pos_font_keys_aff_2_y, 0)
        blf.draw(font_id, keys_aff_2)

        blf.position(font_id, pos_font_keys_nav_x, pos_font_keys_nav_y, 0)
        blf.draw(font_id, keys_nav)

        blf.position(font_id, pos_font_keys_neg_x, pos_font_keys_neg_y, 0)
        blf.draw(font_id, keys_neg)
Beispiel #34
0
 def disable_shadow(fontid=None):
     return blf.disable(FontManager.load(fontid), blf.SHADOW)
Beispiel #35
0
def linumdisplay(disp_op, context, simnode, connode, geonode):
    scene = context.scene
    if not scene.vi_display:
        return
    try:
        if obcalclist:
            pass
    except:
        obreslist = [ob for ob in scene.objects if ob.type == 'MESH'  and 'lightarray' not in ob.name and ob.hide == False and ob.layers[scene.active_layer] == True and ob.get('licalc') == 1 and ob.lires == 1]
        obcalclist = [ob for ob in scene.objects if ob.type == 'MESH' and 'lightarray' not in ob.name and ob.hide == False and ob.layers[scene.active_layer] == True and ob.get('licalc') == 1 and ob.lires == 0]

    if (scene.li_disp_panel != 2 and scene.ss_disp_panel != 2) or scene.vi_display_rp != True \
         or (bpy.context.active_object not in (obcalclist+obreslist) and scene.vi_display_sel_only == True)  \
         or (bpy.context.active_object and bpy.context.active_object.mode == 'EDIT'):
        return
    
    if not context.space_data.region_3d.is_perspective:
        disp_op.report({'ERROR'},"Switch to prespective view mode for number display")
        return
    if scene.frame_current not in range(scene.fs, scene.fe + 1) and scene.vi_display:
        disp_op.report({'ERROR'},"Outside result frame range")
        return
    
    if bpy.context.active_object:
        if bpy.context.active_object.type == 'MESH' and bpy.context.active_object.mode != 'OBJECT':
             bpy.context.active_object.mode = 'OBJECT'
    
    blf.enable(0, 4)
    blf.shadow(0, 5, scene.vi_display_rp_fsh[0], scene.vi_display_rp_fsh[1], scene.vi_display_rp_fsh[2], scene.vi_display_rp_fsh[3])
    bgl.glColor4f(*scene.vi_display_rp_fc[:])
    blf.size(0, scene.vi_display_rp_fs, 72)
    bgl.glColor3f = scene.vi_display_rp_fc
    cp = geonode.cpoint if geonode else simnode.cpoint
    fn = context.scene.frame_current - scene.fs
    mid_x, mid_y, width, height = vi_func.viewdesc(context)

    if scene.vi_display_sel_only == False:
        obd = obreslist if len(obreslist) > 0 else obcalclist
    else:
        oblist = obreslist if len(obreslist) > 0 else obcalclist
        obd = [context.active_object] if context.active_object in oblist else []

    for ob in obd:
        if ob.active_shape_key_index != fn+1:
            ob.active_shape_key_index = fn+1
        obm = ob.data
        ob_mat = ob.matrix_world
        view_mat = context.space_data.region_3d.perspective_matrix
        view_pos = [vmi*scene['cs'] * 2 for vmi in (view_mat.inverted()[0][3], view_mat.inverted()[1][3], view_mat.inverted()[2][3])]

        if cp == "0" or not geonode:
            faces = [f for f in ob.data.polygons if f.select == True] if ob.lires else [f for f in ob.data.polygons if ob.data.materials[f.material_index].vi_shadow] if simnode.bl_label == 'VI Shadow Study' else [f for f in ob.data.polygons if f.select == True] if ob.lires else [f for f in ob.data.polygons if ob.data.materials[f.material_index].livi_sense]
            if scene.vi_display_vis_only:
                faces = [f for f in faces if not scene.ray_cast(ob_mat*((vi_func.face_centre(ob, len(obreslist), f)))+ 0.01*(ob_mat*f.normal-ob.location), view_pos)[0]]
        else:
            fverts = set(sum([list(f.vertices[:]) for f in ob.data.polygons if f.select], []))
            verts = [ob.data.vertices[v] for v in fverts if not scene.ray_cast(ob_mat*vi_func.v_pos(ob, v) + 0.01*ob_mat*ob.data.vertices[v].normal,view_pos)[0]] if scene.vi_display_vis_only else [ob.data.vertices[v] for v in fverts] 
            loops = []
            for v in verts:
                for f in [f for f in ob.data.polygons if f.select == True]:
                    if v.index in f.vertices:
                        loops.append(f.loop_indices[list(f.vertices).index(v.index)])
                        break

        total_mat = view_mat*ob_mat
        if cp == "0" or not geonode:            
            for f in faces:
                vsum = mathutils.Vector((0, 0, 0))
                for v in f.vertices:
                    vsum = ob.active_shape_key.data[v].co + vsum if len(obreslist) > 0 else ob.data.vertices[v].co + vsum
                fc = vsum/len(f.vertices)
                if not f.hide:
                    loop_index = f.loop_indices[0]
                    if len(set(obm.vertex_colors[fn].data[loop_index].color[:])) > 0:
                        if (total_mat*fc)[2] > 0:
                            col, maxval, minval = obm.vertex_colors[fn].data[loop_index].color, max(simnode['maxres']), min(simnode['minres'])
                            if geonode:
                                val = abs(min(simnode['minres']) + (1 - (1.333333*colorsys.rgb_to_hsv(*[col[i]/255 for i in range(3)])[0]))*(maxval - minval))
                                vi_func.draw_index(context, scene.vi_leg_display, mid_x, mid_y, width, height, ('{:.1f}', '{:.0f}')[val > 100].format(val), total_mat*fc.to_4d())
                            else:
                                vi_func.draw_index(context, scene.vi_leg_display, mid_x, mid_y, width, height, '{:.0f}'.format(abs(col[0]*100)), total_mat*fc.to_4d())
        elif cp == "1":
            for v, vert in enumerate(verts):
                vpos = ob.active_shape_key.data[vert.index].co if len(obreslist) > 0 else vert.co
                if len(set(obm.vertex_colors[fn].data[vert.index].color[:])) > 0:
                    if (total_mat*vpos)[2] > 0:
                        vi_func.draw_index(context, scene.vi_leg_display, mid_x, mid_y, width, height, ('{:.1f}', '{:.0f}')[max(simnode['maxres']) > 100].format(abs(min(simnode['minres']) + int((1 - (1.333333*colorsys.rgb_to_hsv(obm.vertex_colors[fn].data[loops[v]].color[0]/255, obm.vertex_colors[fn].data[loops[v]].color[1]/255, obm.vertex_colors[fn].data[loops[v]].color[2]/255)[0]))*(max(simnode['maxres']) - min(simnode['minres']))))), total_mat*vpos.to_4d())
    blf.disable(0, 4)
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]
Beispiel #37
0
def display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg):

    rw = region.width
    rh = region.height
    print('rw, rh', rw, rh)

    expand = False
    crop = False

    len_aff_max = rw - 140
    len_aff = len(keys_aff) * 5
    len_neg = len(keys_neg) * 5
    len_ins = len(instruct) * 18
    if len_aff > len_aff_max: expand = True

    rw_min = 480
    rh_min = 280
    if rw < rw_min or rh < rh_min: crop = True


    version = '020'
    font_id = 0

    keys_aff_1 = copy.deepcopy(keys_aff)
    keys_aff_2 = ' '
    if expand:
        keys_aff_1 = ''
        keys_aff_2 = ''
        print('len(keys_aff)', len(keys_aff))
        stop = 0
        for i in range (0, len(keys_aff)-1):
            #print(keys_aff[i])
            if keys_aff[i] == ',' and i * 5 <= len_aff_max and i > stop:
                stop = i
        print ('stop', stop)
        for i in range(0, stop + 1):
            keys_aff_1 = keys_aff_1 + keys_aff[i]
        for i in range(stop + 2, len(keys_aff)):
            keys_aff_2 = keys_aff_2 + keys_aff[i]
        print(keys_aff_1)
        print(keys_aff_2)

    field_keys_y = 46
    field_keys_x = 80
    field_keys_aff_1 = [[field_keys_x, field_keys_y + 21], [field_keys_x, field_keys_y + 39], [rw - int(field_keys_x / 2), field_keys_y + 39], [rw - int(field_keys_x / 2), field_keys_y + 21]]
    field_keys_aff_2 = copy.deepcopy(field_keys_aff_1)
    field_keys_neg = [[field_keys_x, field_keys_y], [field_keys_x, field_keys_y + 18], [rw - field_keys_x / 2, field_keys_y + 18], [rw - field_keys_x / 2, field_keys_y]]
    if expand:
        field_keys_aff_2 = copy.deepcopy(field_keys_neg)
        field_keys_neg = [[field_keys_x, field_keys_y - 21], [field_keys_x, field_keys_y - 3], [rw - field_keys_x / 2, field_keys_y - 3], [rw - field_keys_x / 2, field_keys_y - 21]]

    size_font_np = 25
    size_font_instruct = 21
    size_font_keys = 11
    len_np_ins = len_ins + int(size_font_np * 2.1)

    pos_font_np_x = (rw - (len_np_ins / 2)) / 2
    pos_font_np_y = 150
    if crop: pos_font_np_y = 75
    pos_font_instruct_x = pos_font_np_x + int(size_font_np * 2.1)
    pos_font_instruct_y = pos_font_np_y + 4
    pos_font_keys_aff_1_x = field_keys_x + 8
    pos_font_keys_aff_1_y = field_keys_y + 26
    pos_font_keys_aff_2_x = copy.deepcopy(pos_font_keys_aff_1_x)
    pos_font_keys_aff_2_y = copy.deepcopy(pos_font_keys_aff_1_y)
    pos_font_keys_nav_x = field_keys_x + 8
    pos_font_keys_nav_y = field_keys_y + 5
    pos_font_keys_neg_x = rw - 52 - len_neg
    print ('len_neg', len_neg)
    print ('pos_font_keys_neg_x', pos_font_keys_neg_x)
    pos_font_keys_neg_y = field_keys_y + 5
    if expand:
        pos_font_keys_aff_2_x = field_keys_x + 8
        pos_font_keys_aff_2_y = field_keys_y + 5
        pos_font_keys_nav_x = field_keys_x + 8
        pos_font_keys_nav_y = field_keys_y - 16
        pos_font_keys_neg_x = rw - 52 - len_neg
        pos_font_keys_neg_y = field_keys_y - 16

    col_font_np = addon_settings_graph()['col_font_np']
    col_font_instruct_main = addon_settings_graph()['col_font_instruct_main']
    col_font_instruct_shadow = addon_settings_graph()['col_font_instruct_shadow']
    col_font_keys = addon_settings_graph()['col_font_keys']
    col_field_keys_aff = addon_settings_graph()['col_field_keys_aff']
    col_field_keys_neg = addon_settings_graph()['col_field_keys_neg']



    # instructions - NP:

    bgl.glColor4f(*col_font_np)
    blf.size(font_id, size_font_np, 72)
    blf.position(font_id, pos_font_np_x, pos_font_np_y, 0)
    blf.draw(font_id, 'NP')

    blf.enable(font_id, ROTATION)
    ang = radians(90)
    blf.size(font_id, int(size_font_np / 2.2), 72)
    blf.rotation(font_id, ang)
    blf.position(font_id, pos_font_np_x + int(size_font_np * 1.72) , pos_font_np_y - 2, 0)
    blf.draw(font_id, version)
    blf.disable(font_id, ROTATION)

    # instructions - instruct:

    bgl.glColor4f(*col_font_instruct_shadow)
    blf.position(font_id, pos_font_instruct_x + 1, pos_font_instruct_y - 1, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glColor4f(*col_font_instruct_main)
    blf.position(font_id, pos_font_instruct_x, pos_font_instruct_y, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glDisable(bgl.GL_BLEND)

    # instructions - keys - backdrop fields:

    bgl.glEnable(bgl.GL_BLEND)

    if crop == False:

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_1:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_2:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_neg)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_neg:
            bgl.glVertex2f(*co)
        bgl.glEnd()


        # instructions - keys - writing:

        bgl.glColor4f(*col_font_keys)
        blf.size(font_id, size_font_keys, 72)

        blf.position(font_id, pos_font_keys_aff_1_x, pos_font_keys_aff_1_y, 0)
        blf.draw(font_id, keys_aff_1)

        blf.position(font_id, pos_font_keys_aff_2_x, pos_font_keys_aff_2_y, 0)
        blf.draw(font_id, keys_aff_2)

        blf.position(font_id, pos_font_keys_nav_x, pos_font_keys_nav_y, 0)
        blf.draw(font_id, keys_nav)

        blf.position(font_id, pos_font_keys_neg_x, pos_font_keys_neg_y, 0)
        blf.draw(font_id, keys_neg)
 def disable_rotation(fontid=None):
     return blf.disable(FontManager.load(fontid), blf.ROTATION)
Beispiel #39
0
        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':
            # 開始ボタンが押された時の処理
            if sc.rt_running is False:
                sc.rt_running = True
                self.__handle_add(context)
                print("サンプル3-5: テキストの描画を開始しました。")
            # 終了ボタンが押された時の処理
            else:
Beispiel #40
0
 def disable_clipping(self):
     blf.disable(self.font_id, blf.CLIPPING)
 def disable(option, fontid=None):
     return blf.disable(FontManager.load(fontid), option)
Beispiel #42
0
def linumdisplay(disp_op, context, simnode, connode, geonode):
    scene = context.scene    
    if not scene.vi_display:
        return
    if scene.frame_current not in range(scene.fs, scene.fe + 1):
        disp_op.report({'INFO'},"Outside result frame range")
        return

    obreslist = [ob for ob in scene.objects if ob.type == 'MESH'  and 'lightarray' not in ob.name and ob.hide == False and ob.layers[scene.active_layer] == True and ob.get('lires')]
                    
    if (scene.li_disp_panel != 2 and scene.ss_disp_panel != 2) or scene.vi_display_rp != True \
         or (bpy.context.active_object not in obreslist and scene.vi_display_sel_only == True)  \
         or (bpy.context.active_object and bpy.context.active_object.mode == 'EDIT'):
        return
        
    objmode()    
    blf.enable(0, 4)
    blf.shadow(0, 5, scene.vi_display_rp_fsh[0], scene.vi_display_rp_fsh[1], scene.vi_display_rp_fsh[2], scene.vi_display_rp_fsh[3])
    bgl.glColor4f(*scene.vi_display_rp_fc[:])
    blf.size(0, scene.vi_display_rp_fs, 72)
    bgl.glColor3f = scene.vi_display_rp_fc
    fn = context.scene.frame_current - scene.fs
    mid_x, mid_y, width, height = viewdesc(context)
    view_mat = context.space_data.region_3d.perspective_matrix
#    view_pivot = context.region_data.view_location bpy.context.active_object.location if bpy.context.active_object and context.user_preferences.view.use_rotate_around_active else context.region_data.view_location
    view_pivot = context.region_data.view_location

    if context.space_data.region_3d.is_perspective:
        vw = mathutils.Vector((-view_mat[3][0], -view_mat[3][1], -view_mat[3][2])).normalized()
        view_location = view_pivot + (vw * bpy.context.region_data.view_distance)    
    else:
        vw =  mathutils.Vector((0.0, 0.0, 1.0))
        vw.rotate(bpy.context.region_data.view_rotation)
        view_location = view_pivot + vw.normalized()*bpy.context.region_data.view_distance * 100       

    if scene.vi_display_sel_only == False:
        obd = obreslist
    else:
        obd = [context.active_object] if context.active_object in obreslist else []

    for ob in obd:
        if ob.data.shape_keys and str(fn) in [sk.name for sk in ob.data.shape_keys.key_blocks] and ob.active_shape_key.name != str(fn):
            ob.active_shape_key_index = [sk.name for sk in ob.data.shape_keys.key_blocks].index(str(fn))

        obm = ob.data
        omw = ob.matrix_world
        total_mat = view_mat * omw
        bm = bmesh.new()
        bm.from_mesh(obm)
        bm.transform(omw)

        if scene['liparams']['cp'] == "0":
            livires = bm.faces.layers.float['res{}'.format(scene.frame_current)]
            if not scene.vi_disp_3d:
                faces = [f for f in bm.faces if not f.hide and mathutils.Vector.angle(vw, view_location - f.calc_center_median()) < pi * 0.5]
                faces = [f for f in faces if not scene.ray_cast(f.calc_center_median() + scene.vi_display_rp_off * f.normal, view_location)[0]] if scene.vi_display_vis_only else faces
                fcs = [view_mat*f.calc_center_bounds().to_4d() for f in faces]
            else:
                sk = bm.verts.layers.shape[scene.frame_current]
                faces = [f for f in bm.faces if f.select and not f.hide]
                fpos = [skfpos(ob, scene.frame_current, [v.index for v in f.verts]) for f in faces]
                faces = [f for fi, f in enumerate(faces) if mathutils.Vector.angle(vw, view_location - f.calc_center_median()) < pi * 0.5]
                fpos = [skfpos(ob, scene.frame_current, [v.index for v in f.verts]) for f in faces]
                faces = [f for fi, f in enumerate(faces) if not scene.ray_cast(fpos[fi] + scene.vi_display_rp_off * f.normal, view_location)[0]] if scene.vi_display_vis_only else faces
                fpos = [skfpos(ob, scene.frame_current, [v.index for v in f.verts]) for f in faces]
                fcs = [view_mat*fpos[fi].to_4d() for fi, f in enumerate(faces)]
            res = [f[livires] for f in faces]
            draw_index(context, scene.vi_leg_display, mid_x, mid_y, width, height, fcs, res)
        else:
            livires = bm.verts.layers.float['res{}'.format(scene.frame_current)]              
            if not scene.vi_disp_3d:
                verts = [v for v in bm.verts if not v.hide and mathutils.Vector.angle(vw, view_location - v.co) < pi * 0.5]
                verts = [v for v in verts if not scene.ray_cast(v.co + scene.vi_display_rp_off * v.normal, view_location)[0]] if scene.vi_display_vis_only else verts
                vcs = [view_mat*v.co.to_4d() for v in verts]                
            else:
                verts = [v for v in bm.verts if not v.hide and mathutils.Vector.angle(vw, view_location - omw*(ob.data.shape_keys.key_blocks[str(scene.frame_current)].data[v.index].co)) < pi * 0.5]
                verts = [v for v in verts if not scene.ray_cast(omw*(ob.data.shape_keys.key_blocks[str(scene.frame_current)].data[v.index].co) + scene.vi_display_rp_off * v.normal, view_location)[0]] if scene.vi_display_vis_only else verts
                vcs = [total_mat*ob.data.shape_keys.key_blocks[str(scene.frame_current)].data[v.index].co.to_4d() for v in verts]
            res = [v[livires] for v in verts]
            draw_index(context, scene.vi_leg_display, mid_x, mid_y, width, height, vcs, res)

        bm.free()
    blf.disable(0, 4)
 def disable_clipping(fontid=None):
     return blf.disable(FontManager.load(fontid), blf.CLIPPING)
Beispiel #44
0
def draw_custom_2d_elements():
    """Draws custom 2D elements from cache.
    """
    context = bpy.context
    scs_globals = _get_scs_globals()

    region = context.region
    region_3d = context.region_data
    space = context.space_data
    area = context.area
    window = context.window

    # draw 3d view import/export reports
    _draw_3dview_report(window, area, region)

    # cache & get valid locators for current region boundaries
    locators = _cache_custom_2d_elements(region, region_3d, space)

    # no locators, we can safely finish here
    if not locators:
        return

    font_id = 0  # default font
    blf.size(font_id, 12, 72)
    blf.color(font_id, scs_globals.info_text_color[0],
              scs_globals.info_text_color[1], scs_globals.info_text_color[2],
              1.0)
    blf.word_wrap(font_id, 999)
    blf.enable(font_id, blf.WORD_WRAP)

    persp_matrix_str = str(region_3d.perspective_matrix)

    # LOCATOR NAMES
    if scs_globals.display_info == 'locnames':
        for obj in locators:
            loc_2d = _2d_elements_cache.get_locator_location_2d(
                obj, persp_matrix_str)
            _primitive.draw_text(obj.name, font_id, loc_2d.x, loc_2d.y)

    # LOCATOR COMPREHENSIVE INFO
    elif scs_globals.display_info == 'locinfo':
        for obj in locators:
            loc_2d = _2d_elements_cache.get_locator_location_2d(
                obj, persp_matrix_str)
            loc_info = _2d_elements_cache.get_locator_info(obj)
            _primitive.draw_text(loc_info, font_id, loc_2d.x, loc_2d.y)

    # LOCATOR BOUNDARY NODES
    elif scs_globals.display_info == 'locnodes':
        for obj in locators:
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                loc_2d = _2d_elements_cache.get_locator_location_2d(
                    obj, persp_matrix_str)
                _primitive.draw_text(
                    str(obj.scs_props.locator_prefab_np_boundary_node),
                    font_id, loc_2d.x, loc_2d.y)

    # LOCATOR BOUNDARY LANES
    elif scs_globals.display_info == 'loclanes':
        for obj in locators:
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                if obj.scs_props.locator_prefab_np_boundary != 'no':
                    np_boundary_i = int(
                        obj.scs_props.locator_prefab_np_boundary)
                    if np_boundary_i == 0:
                        continue

                    loc_2d = _2d_elements_cache.get_locator_location_2d(
                        obj, persp_matrix_str)
                    _primitive.draw_text(
                        str(obj.scs_props.enum_np_boundary_items[np_boundary_i]
                            [1]), font_id, loc_2d.x, loc_2d.y)

    blf.disable(font_id, blf.WORD_WRAP)
 def disable_kerning_default(fontid=None):
     # note: not a listed option in docs for `blf.disable`, but see `blf.word_wrap`
     return blf.disable(FontManager.load(fontid), blf.KERNING_DEFAULT)
def display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg):

    userpref = bpy.context.user_preferences
    system = userpref.system
    rwtools = 0
    rwui = 0

    np_print(system.window_draw_method, system.use_region_overlap)

    if system.use_region_overlap:
        if system.window_draw_method in ('TRIPLE_BUFFER', 'AUTOMATIC'):

            area = bpy.context.area
            np_print('GO', area.regions)
            for r in area.regions:
                if r.type == 'TOOLS':
                    rwtools = r.width
                elif r.type == 'UI':
                    rwui = r.width

    np_print('rwtools', rwtools, 'rwui', rwui)
    field_keys_y = 46
    field_keys_x = 80
    rw = region.width
    rh = region.height
    np_print('rw, rh', rw, rh)

    expand = False
    crop = False

    len_aff_max = rw - 140 - rwtools - rwui
    len_aff = len(keys_aff) * 5
    len_neg = len(keys_neg) * 5
    len_ins = len(instruct) * 18
    if len_aff > len_aff_max: expand = True

    rw_min = 480
    rh_min = 280
    if rw - rwtools - rwui < rw_min or rh < rh_min: crop = True

    version = '020'
    font_id = 0

    keys_aff_1 = copy.deepcopy(keys_aff)
    keys_aff_2 = ' '
    if expand:
        keys_aff_1 = ''
        keys_aff_2 = ''
        np_print('len(keys_aff)', len(keys_aff))
        stop = 0
        for i in range(0, len(keys_aff) - 1):
            #np_print(keys_aff[i])
            if keys_aff[i] == ',' and i * 5 <= len_aff_max and i > stop:
                stop = i
        np_print('stop', stop)
        for i in range(0, stop + 1):
            keys_aff_1 = keys_aff_1 + keys_aff[i]
        for i in range(stop + 2, len(keys_aff)):
            keys_aff_2 = keys_aff_2 + keys_aff[i]
        np_print(keys_aff_1)
        np_print(keys_aff_2)

    field_keys_aff_1 = [[field_keys_x + rwtools, field_keys_y + 21],
                        [field_keys_x + rwtools, field_keys_y + 39],
                        [rw - int(field_keys_x / 2) - rwui, field_keys_y + 39],
                        [rw - int(field_keys_x / 2) - rwui, field_keys_y + 21]]
    field_keys_aff_2 = copy.deepcopy(field_keys_aff_1)
    field_keys_neg = [[field_keys_x + rwtools, field_keys_y],
                      [field_keys_x + rwtools, field_keys_y + 18],
                      [rw - int(field_keys_x / 2) - rwui, field_keys_y + 18],
                      [rw - int(field_keys_x / 2) - rwui, field_keys_y]]
    if expand:
        field_keys_aff_2 = copy.deepcopy(field_keys_neg)
        field_keys_neg = [
            [field_keys_x + rwtools, field_keys_y - 21],
            [field_keys_x + rwtools, field_keys_y - 3],
            [rw - int(field_keys_x / 2) - rwui, field_keys_y - 3],
            [rw - int(field_keys_x / 2) - rwui, field_keys_y - 21]
        ]

    size_font_np = 25
    size_font_instruct = 21
    size_font_keys = 11
    len_np_ins = len_ins + int(size_font_np * 2.1)

    pos_font_np_x = (rw - len_np_ins / 2) / 2 + rwtools / 2 - rwui / 2
    pos_font_np_y = 150
    if crop: pos_font_np_y = 75
    pos_font_instruct_x = pos_font_np_x + int(size_font_np * 2.1)
    pos_font_instruct_y = pos_font_np_y + 4
    pos_font_keys_aff_1_x = field_keys_x + 8 + rwtools
    pos_font_keys_aff_1_y = field_keys_y + 26
    pos_font_keys_aff_2_x = copy.deepcopy(pos_font_keys_aff_1_x)
    pos_font_keys_aff_2_y = copy.deepcopy(pos_font_keys_aff_1_y)
    pos_font_keys_nav_x = field_keys_x + 8 + rwtools
    pos_font_keys_nav_y = field_keys_y + 5
    pos_font_keys_neg_x = rw - 52 - len_neg - rwui
    np_print('len_neg', len_neg)
    np_print('pos_font_keys_neg_x', pos_font_keys_neg_x)
    pos_font_keys_neg_y = field_keys_y + 5
    if expand:
        pos_font_keys_aff_2_x = field_keys_x + 8 + rwtools
        pos_font_keys_aff_2_y = field_keys_y + 5
        pos_font_keys_nav_x = field_keys_x + 8 + rwtools
        pos_font_keys_nav_y = field_keys_y - 16
        pos_font_keys_neg_x = rw - 52 - len_neg - rwui
        pos_font_keys_neg_y = field_keys_y - 16 - rwui

    col_font_np = addon_settings_graph('col_font_np')
    col_font_instruct_main = addon_settings_graph('col_font_instruct_main')
    col_font_instruct_shadow = addon_settings_graph('col_font_instruct_shadow')
    col_font_keys = addon_settings_graph('col_font_keys')
    col_field_keys_aff = addon_settings_graph('col_field_keys_aff')
    col_field_keys_neg = addon_settings_graph('col_field_keys_neg')

    # instructions - NP:

    bgl.glColor4f(*col_font_np)
    blf.size(font_id, size_font_np, 72)
    blf.position(font_id, pos_font_np_x, pos_font_np_y, 0)
    blf.draw(font_id, 'NP')

    blf.enable(font_id, ROTATION)
    ang = radians(90)
    blf.size(font_id, int(size_font_np / 2.2), 72)
    blf.rotation(font_id, ang)
    blf.position(font_id, pos_font_np_x + int(size_font_np * 1.72),
                 pos_font_np_y - 2, 0)
    blf.draw(font_id, version)
    blf.disable(font_id, ROTATION)

    # instructions - instruct:

    bgl.glColor4f(*col_font_instruct_shadow)
    blf.position(font_id, pos_font_instruct_x + 1, pos_font_instruct_y - 1, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glColor4f(*col_font_instruct_main)
    blf.position(font_id, pos_font_instruct_x, pos_font_instruct_y, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glDisable(bgl.GL_BLEND)

    # instructions - keys - backdrop fields:

    bgl.glEnable(bgl.GL_BLEND)

    if crop == False:

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_1:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_2:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_neg)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_neg:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        # instructions - keys - writing:

        bgl.glColor4f(*col_font_keys)
        blf.size(font_id, size_font_keys, 72)

        blf.position(font_id, pos_font_keys_aff_1_x, pos_font_keys_aff_1_y, 0)
        blf.draw(font_id, keys_aff_1)

        blf.position(font_id, pos_font_keys_aff_2_x, pos_font_keys_aff_2_y, 0)
        blf.draw(font_id, keys_aff_2)

        blf.position(font_id, pos_font_keys_nav_x, pos_font_keys_nav_y, 0)
        blf.draw(font_id, keys_nav)

        blf.position(font_id, pos_font_keys_neg_x, pos_font_keys_neg_y, 0)
        blf.draw(font_id, keys_neg)
Beispiel #47
0
def display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg):

    rw = region.width
    rh = region.height
    print('rw, rh', rw, rh)

    expand = False
    crop = False

    len_aff_max = rw - 140
    len_aff = len(keys_aff) * 5
    len_neg = len(keys_neg) * 5
    len_ins = len(instruct) * 18
    if len_aff > len_aff_max: expand = True

    rw_min = 480
    rh_min = 280
    if rw < rw_min or rh < rh_min: crop = True

    version = '020'
    font_id = 0

    keys_aff_1 = copy.deepcopy(keys_aff)
    keys_aff_2 = ' '
    if expand:
        keys_aff_1 = ''
        keys_aff_2 = ''
        print('len(keys_aff)', len(keys_aff))
        stop = 0
        for i in range(0, len(keys_aff) - 1):
            #print(keys_aff[i])
            if keys_aff[i] == ',' and i * 5 <= len_aff_max and i > stop:
                stop = i
        print('stop', stop)
        for i in range(0, stop + 1):
            keys_aff_1 = keys_aff_1 + keys_aff[i]
        for i in range(stop + 2, len(keys_aff)):
            keys_aff_2 = keys_aff_2 + keys_aff[i]
        print(keys_aff_1)
        print(keys_aff_2)

    field_keys_y = 46
    field_keys_x = 80
    field_keys_aff_1 = [[field_keys_x, field_keys_y + 21],
                        [field_keys_x, field_keys_y + 39],
                        [rw - int(field_keys_x / 2), field_keys_y + 39],
                        [rw - int(field_keys_x / 2), field_keys_y + 21]]
    field_keys_aff_2 = copy.deepcopy(field_keys_aff_1)
    field_keys_neg = [[field_keys_x, field_keys_y],
                      [field_keys_x, field_keys_y + 18],
                      [rw - field_keys_x / 2, field_keys_y + 18],
                      [rw - field_keys_x / 2, field_keys_y]]
    if expand:
        field_keys_aff_2 = copy.deepcopy(field_keys_neg)
        field_keys_neg = [[field_keys_x, field_keys_y - 21],
                          [field_keys_x, field_keys_y - 3],
                          [rw - field_keys_x / 2, field_keys_y - 3],
                          [rw - field_keys_x / 2, field_keys_y - 21]]

    size_font_np = 25
    size_font_instruct = 21
    size_font_keys = 11
    len_np_ins = len_ins + int(size_font_np * 2.1)

    pos_font_np_x = (rw - (len_np_ins / 2)) / 2
    pos_font_np_y = 150
    if crop: pos_font_np_y = 75
    pos_font_instruct_x = pos_font_np_x + int(size_font_np * 2.1)
    pos_font_instruct_y = pos_font_np_y + 4
    pos_font_keys_aff_1_x = field_keys_x + 8
    pos_font_keys_aff_1_y = field_keys_y + 26
    pos_font_keys_aff_2_x = copy.deepcopy(pos_font_keys_aff_1_x)
    pos_font_keys_aff_2_y = copy.deepcopy(pos_font_keys_aff_1_y)
    pos_font_keys_nav_x = field_keys_x + 8
    pos_font_keys_nav_y = field_keys_y + 5
    pos_font_keys_neg_x = rw - 52 - len_neg
    print('len_neg', len_neg)
    print('pos_font_keys_neg_x', pos_font_keys_neg_x)
    pos_font_keys_neg_y = field_keys_y + 5
    if expand:
        pos_font_keys_aff_2_x = field_keys_x + 8
        pos_font_keys_aff_2_y = field_keys_y + 5
        pos_font_keys_nav_x = field_keys_x + 8
        pos_font_keys_nav_y = field_keys_y - 16
        pos_font_keys_neg_x = rw - 52 - len_neg
        pos_font_keys_neg_y = field_keys_y - 16

    col_font_np = addon_settings_graph()['col_font_np']
    col_font_instruct_main = addon_settings_graph()['col_font_instruct_main']
    col_font_instruct_shadow = addon_settings_graph(
    )['col_font_instruct_shadow']
    col_font_keys = addon_settings_graph()['col_font_keys']
    col_field_keys_aff = addon_settings_graph()['col_field_keys_aff']
    col_field_keys_neg = addon_settings_graph()['col_field_keys_neg']

    # instructions - NP:

    bgl.glColor4f(*col_font_np)
    blf.size(font_id, size_font_np, 72)
    blf.position(font_id, pos_font_np_x, pos_font_np_y, 0)
    blf.draw(font_id, 'NP')

    blf.enable(font_id, ROTATION)
    ang = radians(90)
    blf.size(font_id, int(size_font_np / 2.2), 72)
    blf.rotation(font_id, ang)
    blf.position(font_id, pos_font_np_x + int(size_font_np * 1.72),
                 pos_font_np_y - 2, 0)
    blf.draw(font_id, version)
    blf.disable(font_id, ROTATION)

    # instructions - instruct:

    bgl.glColor4f(*col_font_instruct_shadow)
    blf.position(font_id, pos_font_instruct_x + 1, pos_font_instruct_y - 1, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glColor4f(*col_font_instruct_main)
    blf.position(font_id, pos_font_instruct_x, pos_font_instruct_y, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glDisable(bgl.GL_BLEND)

    # instructions - keys - backdrop fields:

    bgl.glEnable(bgl.GL_BLEND)

    if crop == False:

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_1:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_2:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_neg)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_neg:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        # instructions - keys - writing:

        bgl.glColor4f(*col_font_keys)
        blf.size(font_id, size_font_keys, 72)

        blf.position(font_id, pos_font_keys_aff_1_x, pos_font_keys_aff_1_y, 0)
        blf.draw(font_id, keys_aff_1)

        blf.position(font_id, pos_font_keys_aff_2_x, pos_font_keys_aff_2_y, 0)
        blf.draw(font_id, keys_aff_2)

        blf.position(font_id, pos_font_keys_nav_x, pos_font_keys_nav_y, 0)
        blf.draw(font_id, keys_nav)

        blf.position(font_id, pos_font_keys_neg_x, pos_font_keys_neg_y, 0)
        blf.draw(font_id, keys_neg)
Beispiel #48
0
def _draw_3dview_report(region):
    """Draws reports in 3d views.

    :param region: region of 3D viewport
    :type region: bpy.types.Region
    """
    if _Show3DViewReportOperator.has_lines():

        blf.size(0, 15, 72)
        pos = region.height - 40

        # draw Close control
        glColor3f(.2, .2, .2)
        glBegin(GL_POLYGON)
        glVertex3f(20, pos + 2, 0)
        glVertex3f(94, pos + 2, 0)
        glVertex3f(94, pos - 22, 0)
        glVertex3f(20, pos - 22, 0)
        glEnd()

        glColor3f(1, 1, 1)
        blf.position(0, 25, pos - 15, 0)
        blf.draw(0, "[X] Close")

        glColor3f(.2, .2, .2)
        glBegin(GL_POLYGON)
        glVertex3f(100, pos + 2, 0)
        glVertex3f(250, pos + 2, 0)
        glVertex3f(250, pos - 22, 0)
        glVertex3f(100, pos - 22, 0)
        glEnd()

        # draw Show/Hide control and actual reports if exists
        glColor3f(1, 1, 1)
        blf.position(0, 105, pos - 15, 0)
        if _Show3DViewReportOperator.is_shown():
            blf.draw(0, "[+] Show | [  ] Hide")

            blf.enable(0, blf.SHADOW)
            blf.size(0, 12, 72)
            glColor3f(1, 1, 1)
            pos -= 40
            for line in _Show3DViewReportOperator.get_lines():

                # finish printing if running out of space
                if pos - 60 < 0:
                    blf.position(0, 20, pos, 0)
                    blf.draw(0, "...")
                    break

                blf.position(0, 20, pos, 0)
                if "ERROR" in line:
                    blf.shadow(0, 5, 0.5, 0., 0, 1)
                elif "WARNING" in line:
                    blf.shadow(0, 5, 0.3, 0.15, 0, 1)

                blf.draw(0, line)
                pos -= 15
            blf.disable(0, blf.SHADOW)
        else:
            blf.draw(0, "[  ] Show | [+] Hide")
Beispiel #49
0
def draw_callback_px_optimized(op:Boss_OT_base_ui):
    uip:uiParams.uiParams = op.uip

    bgl.glEnable(bgl.GL_BLEND)

    try:
        _shader = None
        for panel in uip.ui_drawable:
            geo = panel.geo

            if not geo:
                continue

            batch = geo._batched if geo._batched else geo.newbatch()

            if _shader == geo.shader:
                pass
            else:
                _shader = geo.shader
                _shader.bind()

            if geo.geoData.image_path == '':
                pass
            else:
                bgl.glActiveTexture(bgl.GL_TEXTURE0)
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, geo.imageData.bindcode)

                geo.shader.uniform_int("image", 0)

            if geo.clipRect:
                geo.shader.uniform_float(
                    'clipRect',
                    panel.clipRect._clipRect
                )
            batch.draw(geo.shader)

        _shader = None

        blf.size(g_font_id, g_font_size, g_dpi)
        blf.color(g_font_id, *g_font_color)

        is_clipping_enabled = False

        for panel in uip.ui_drawable_texts:
            t = panel._text

            blf.position(g_font_id, t.xPos, t.yPos, 0)

            if t.clipRect:
                if is_clipping_enabled:
                    pass
                else:
                    blf.enable(g_font_id, blf.CLIPPING)
                    is_clipping_enabled = True
                blf.clipping(g_font_id, *t.clipRect._clipRect)
            else:
                if is_clipping_enabled:
                    blf.disable(g_font_id, blf.CLIPPING)
                    is_clipping_enabled = False

            blf.draw(g_font_id, t.text)

        if is_clipping_enabled:
            blf.disable(g_font_id, blf.CLIPPING)

    except Exception as e:
        print('*' * 25, 'Drawing failed: ', '*' * 25)
        op.msg(f'{e} ... Drawing Failed, check console for details', 2)
        print(str(e))
        print(traceback.format_exc())
        print('*' * 25, 'drawing failed: ', '*' * 25)
        op.quit()

    if op.display_text:
        for dt in op.display_text:
            dt.draw()

    if uip.globalToolTipImagePath:
        showGlobalImageToolTip(uip)

    if uip.globalToolTip:
        showGlobalTextToolTip(uip)

    if uip._canDrawCursor:
        uip.cursor.draw()

    bgl.glDisable(bgl.GL_BLEND)
Beispiel #50
0
def draw_callback_px_text(self, context):
    scene = bpy.context.scene

    panel_prefs = bpy.context.user_preferences.addons[__package__].preferences

    font_path = blf.load(panel_prefs.filepath_all)
    font_path_0 = blf.load(panel_prefs.filepath_0)
    font_path_1 = blf.load(panel_prefs.filepath_1)
    font_path_2 = blf.load(panel_prefs.filepath_2)
    font_path_3 = blf.load(panel_prefs.filepath_3)
    font_path_4 = blf.load(panel_prefs.filepath_4)
    font_path_5 = blf.load(panel_prefs.filepath_5)
    font_path_6 = blf.load(panel_prefs.filepath_6)
    font_path_7 = blf.load(panel_prefs.filepath_7)

    text_width_title = panel_prefs.text_width_title
    text_height_title = panel_prefs.text_height_title
    text_pos_x = panel_prefs.text_pos_x
    text_pos_y = panel_prefs.text_pos_y

    # HEADER AND SHELFS #
    hheader = context.area.regions[0].height  # 26px
    tpanel = context.area.regions[1].width
    npanel = context.area.regions[3].width

    # zero out tpanel width, if region overlap it turned on
    if context.user_preferences.system.use_region_overlap:
        tpanel = 0

    # fetch real space in between
    self.REALx = context.area.width - npanel - tpanel
    self.REALy = context.area.height + hheader

    text_shadow = panel_prefs.text_shadow
    text_shadow_color = panel_prefs.text_shadow_color
    text_shadow_alpha = panel_prefs.text_shadow_alpha
    text_shadow_x = panel_prefs.text_shadow_x
    text_shadow_y = panel_prefs.text_shadow_y

    # TITLE 0 #
    if panel_prefs.dodraw == "ZERO":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_0_pos_x = panel_prefs.text_0_pos_x
            text_0_pos_y = panel_prefs.text_0_pos_y
        else:
            text_0_pos_x = panel_prefs.text_pos_x
            text_0_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_0_width_title = panel_prefs.text_0_width_title
            text_0_height_title = panel_prefs.text_0_height_title
        else:
            text_0_width_title = panel_prefs.text_width_title
            text_0_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_0_color = panel_prefs.text_0_color
            bgl.glColor3f(*text_0_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_0 = font_path
            else:
                font_id_0 = font_path_0
        else:
            font_id_0 = 0

        # FILEPATH FIELD #
        text_0_text = panel_prefs.text_0_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_0, text_0_text)

        self.line_0_width = line_width
        self.line_0_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_0,
                (self.REALx / 2 - self.line_0_width / 2 + text_0_pos_x),
                (self.REALy / 2 - self.line_0_height + text_0_pos_y), 0)
        else:
            blf.position(font_id_0, (text_0_pos_x + 20),
                         (self.REALy / 2 - self.line_0_height + text_0_pos_y),
                         0)

        blf.size(font_id_0, text_0_width_title, text_0_height_title + 10)
        blf.draw(font_id_0, text_0_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_0, blf.SHADOW)
            blf.shadow_offset(font_id_0, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_0, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_0, blf.SHADOW)

    # TITLE 1 #
    if panel_prefs.dodraw == "ONE":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_1_pos_x = panel_prefs.text_1_pos_x
            text_1_pos_y = panel_prefs.text_1_pos_y
        else:
            text_1_pos_x = panel_prefs.text_pos_x
            text_1_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_1_width_title = panel_prefs.text_1_width_title
            text_1_height_title = panel_prefs.text_1_height_title
        else:
            text_1_width_title = panel_prefs.text_width_title
            text_1_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_1_color = panel_prefs.text_1_color
            bgl.glColor3f(*text_1_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_1 = font_path
            else:
                font_id_1 = font_path_1
        else:
            font_id_1 = 0

        # FILEPATH FIELD #
        text_1_text = panel_prefs.text_1_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_1, text_1_text)

        self.line_1_width = line_width
        self.line_1_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_1,
                (self.REALx / 2 - self.line_1_width / 2 + text_1_pos_x),
                (self.REALy / 2 - self.line_1_height + text_1_pos_y), 0)
        else:
            blf.position(font_id_1, (text_1_pos_x + 20),
                         (self.REALy / 2 - self.line_1_height + text_1_pos_y),
                         0)

        blf.size(font_id_1, text_1_width_title, text_1_height_title + 10)
        blf.draw(font_id_1, text_1_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_1, blf.SHADOW)
            blf.shadow_offset(font_id_1, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_1, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_1, blf.SHADOW)

    # TITLE 2 #
    if panel_prefs.dodraw == "TWO":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_2_pos_x = panel_prefs.text_2_pos_x
            text_2_pos_y = panel_prefs.text_2_pos_y
        else:
            text_2_pos_x = panel_prefs.text_pos_x
            text_2_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_2_width_title = panel_prefs.text_2_width_title
            text_2_height_title = panel_prefs.text_2_height_title
        else:
            text_2_width_title = panel_prefs.text_width_title
            text_2_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_2_color = panel_prefs.text_2_color
            bgl.glColor3f(*text_2_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_2 = font_path
            else:
                font_id_2 = font_path_2
        else:
            font_id_2 = 0

        # FILEPATH FIELD #
        text_2_text = panel_prefs.text_2_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_2, text_2_text)

        self.line_2_width = line_width
        self.line_2_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_2,
                (self.REALx / 2 - self.line_2_width / 2 + text_2_pos_x),
                (self.REALy / 2 - self.line_2_height + text_2_pos_y), 0)
        else:
            blf.position(font_id_2, (text_2_pos_x + 20),
                         (self.REALy / 2 - self.line_2_height + text_2_pos_y),
                         0)

        blf.size(font_id_2, text_2_width_title, text_2_height_title + 10)
        blf.draw(font_id_2, text_2_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_2, blf.SHADOW)
            blf.shadow_offset(font_id_2, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_2, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_2, blf.SHADOW)

    # TITLE 3 #
    if panel_prefs.dodraw == "THREE":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_3_pos_x = panel_prefs.text_3_pos_x
            text_3_pos_y = panel_prefs.text_3_pos_y
        else:
            text_3_pos_x = panel_prefs.text_pos_x
            text_3_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_3_width_title = panel_prefs.text_3_width_title
            text_3_height_title = panel_prefs.text_3_height_title
        else:
            text_3_width_title = panel_prefs.text_width_title
            text_3_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_3_color = panel_prefs.text_3_color
            bgl.glColor3f(*text_3_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_3 = font_path
            else:
                font_id_3 = font_path_3
        else:
            font_id_3 = 0

        # FILEPATH FIELD #
        text_3_text = panel_prefs.text_3_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_3, text_3_text)

        self.line_3_width = line_width
        self.line_3_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_3,
                (self.REALx / 2 - self.line_3_width / 2 + text_3_pos_x),
                (self.REALy / 2 - self.line_3_height + text_3_pos_y), 0)
        else:
            blf.position(font_id_3, (text_3_pos_x + 20),
                         (self.REALy / 2 - self.line_3_height + text_3_pos_y),
                         0)

        blf.size(font_id_3, text_3_width_title, text_3_height_title + 10)
        blf.draw(font_id_3, text_3_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_3, blf.SHADOW)
            blf.shadow_offset(font_id_3, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_3, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_3, blf.SHADOW)

    # TITLE 4 #
    if panel_prefs.dodraw == "FOUR":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_4_pos_x = panel_prefs.text_4_pos_x
            text_4_pos_y = panel_prefs.text_4_pos_y
        else:
            text_4_pos_x = panel_prefs.text_pos_x
            text_4_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_4_width_title = panel_prefs.text_4_width_title
            text_4_height_title = panel_prefs.text_4_height_title
        else:
            text_4_width_title = panel_prefs.text_width_title
            text_4_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_4_color = panel_prefs.text_4_color
            bgl.glColor3f(*text_4_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_4 = font_path
            else:
                font_id_4 = font_path_4
        else:
            font_id_4 = 0

        # FILEPATH FIELD #
        text_4_text = panel_prefs.text_4_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_4, text_4_text)

        self.line_4_width = line_width
        self.line_4_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_4,
                (self.REALx / 2 - self.line_4_width / 2 + text_4_pos_x),
                (self.REALy / 2 - self.line_4_height + text_4_pos_y), 0)
        else:
            blf.position(font_id_4, (text_4_pos_x + 20),
                         (self.REALy / 2 - self.line_4_height + text_4_pos_y),
                         0)

        blf.size(font_id_4, text_4_width_title, text_4_height_title + 10)
        blf.draw(font_id_4, text_4_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_4, blf.SHADOW)
            blf.shadow_offset(font_id_4, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_4, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_4, blf.SHADOW)

    # TITLE 5 #
    if panel_prefs.dodraw == "FIVE":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_5_pos_x = panel_prefs.text_5_pos_x
            text_5_pos_y = panel_prefs.text_5_pos_y
        else:
            text_5_pos_x = panel_prefs.text_pos_x
            text_5_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_5_width_title = panel_prefs.text_5_width_title
            text_5_height_title = panel_prefs.text_5_height_title
        else:
            text_5_width_title = panel_prefs.text_width_title
            text_5_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_5_color = panel_prefs.text_5_color
            bgl.glColor3f(*text_5_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_5 = font_path
            else:
                font_id_5 = font_path_5
        else:
            font_id_5 = 0

        # FILEPATH FIELD #
        text_5_text = panel_prefs.text_5_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_5, text_5_text)

        self.line_5_width = line_width
        self.line_5_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_5,
                (self.REALx / 2 - self.line_5_width / 2 + text_5_pos_x),
                (self.REALy / 2 - self.line_5_height + text_5_pos_y), 0)
        else:
            blf.position(font_id_5, (text_5_pos_x + 20),
                         (self.REALy / 2 - self.line_5_height + text_5_pos_y),
                         0)

        blf.size(font_id_5, text_5_width_title, text_5_height_title + 10)
        blf.draw(font_id_5, text_5_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_5, blf.SHADOW)
            blf.shadow_offset(font_id_5, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_5, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_5, blf.SHADOW)

    # TITLE 6 #
    if panel_prefs.dodraw == "SIX":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_6_pos_x = panel_prefs.text_6_pos_x
            text_6_pos_y = panel_prefs.text_6_pos_y
        else:
            text_6_pos_x = panel_prefs.text_pos_x
            text_6_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_6_width_title = panel_prefs.text_6_width_title
            text_6_height_title = panel_prefs.text_6_height_title
        else:
            text_6_width_title = panel_prefs.text_width_title
            text_6_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_6_color = panel_prefs.text_6_color
            bgl.glColor3f(*text_6_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_6 = font_path
            else:
                font_id_6 = font_path_6
        else:
            font_id_6 = 0

        # FILEPATH FIELD #
        text_6_text = panel_prefs.text_6_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_6, text_6_text)

        self.line_6_width = line_width
        self.line_6_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_6,
                (self.REALx / 2 - self.line_6_width / 2 + text_6_pos_x),
                (self.REALy / 2 - self.line_6_height + text_6_pos_y), 0)
        else:
            blf.position(font_id_6, (text_6_pos_x + 20),
                         (self.REALy / 2 - self.line_6_height + text_6_pos_y),
                         0)

        blf.size(font_id_6, text_6_width_title, text_6_height_title + 10)
        blf.draw(font_id_6, text_6_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_6, blf.SHADOW)
            blf.shadow_offset(font_id_6, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_6, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_6, blf.SHADOW)

    # TITLE 7 #
    if panel_prefs.dodraw == "SEVEN":

        # POSITION #
        if context.user_preferences.addons[
                __package__].preferences.tab_pos_link == True:
            text_7_pos_x = panel_prefs.text_7_pos_x
            text_7_pos_y = panel_prefs.text_7_pos_y
        else:
            text_7_pos_x = panel_prefs.text_pos_x
            text_7_pos_y = panel_prefs.text_pos_y

        # SCALE #
        if context.user_preferences.addons[
                __package__].preferences.tab_scal_link == True:
            text_7_width_title = panel_prefs.text_7_width_title
            text_7_height_title = panel_prefs.text_7_height_title
        else:
            text_7_width_title = panel_prefs.text_width_title
            text_7_height_title = panel_prefs.text_height_title

        # COLOR #
        if context.user_preferences.addons[
                __package__].preferences.tab_color_link == False:
            text_color = panel_prefs.text_color
            bgl.glColor3f(*text_color)
        else:
            text_7_color = panel_prefs.text_7_color
            bgl.glColor3f(*text_7_color)

        # FONT #
        if context.user_preferences.addons[
                __package__].preferences.tab_font_external == False:
            if context.user_preferences.addons[
                    __package__].preferences.tab_font_unit == False:
                font_id_7 = font_path
            else:
                font_id_7 = font_path_7
        else:
            font_id_7 = 0

        # FILEPATH FIELD #
        text_7_text = panel_prefs.text_7_text

        # length of the text line
        line_width, line_height = blf.dimensions(font_id_7, text_7_text)

        self.line_7_width = line_width
        self.line_7_height = line_height

        # APPLY PREFERENCES #
        if context.user_preferences.addons[
                __package__].preferences.tab_center == 'middle':
            blf.position(
                font_id_7,
                (self.REALx / 2 - self.line_7_width / 2 + text_7_pos_x),
                (self.REALy / 2 - self.line_7_height + text_7_pos_y), 0)
        else:
            blf.position(font_id_7, (text_7_pos_x + 20),
                         (self.REALy / 2 - self.line_7_height + text_7_pos_y),
                         0)

        blf.size(font_id_7, text_7_width_title, text_7_height_title + 10)
        blf.draw(font_id_7, text_7_text)

        # DROPSHADOW #
        if context.user_preferences.addons[
                __package__].preferences.text_shadow == True:
            blf.enable(font_id_7, blf.SHADOW)
            blf.shadow_offset(font_id_7, text_shadow_x, text_shadow_y)
            blf.shadow(font_id_7, 5, text_shadow_color[0],
                       text_shadow_color[1], text_shadow_color[2],
                       text_shadow_alpha)
        else:
            blf.disable(font_id_7, blf.SHADOW)

    # restore opengl defaults
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor3f(0.0, 0.0, 0.0)
Beispiel #51
0
    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)
Beispiel #52
0
def _draw_3dview_report(region):
    """Draws reports in 3d views.

    :param region: region of 3D viewport
    :type region: bpy.types.Region
    """
    if _Show3DViewReportOperator.has_lines():

        blf.size(0, 15, 72)
        pos = region.height - 40

        # draw Close control
        glColor3f(.2, .2, .2)
        glBegin(GL_POLYGON)
        glVertex3f(20, pos + 2, 0)
        glVertex3f(94, pos + 2, 0)
        glVertex3f(94, pos - 22, 0)
        glVertex3f(20, pos - 22, 0)
        glEnd()

        glColor3f(1, 1, 1)
        blf.position(0, 25, pos - 15, 0)
        blf.draw(0, "[X] Close")

        glColor3f(.2, .2, .2)
        glBegin(GL_POLYGON)
        glVertex3f(100, pos + 2, 0)
        glVertex3f(250, pos + 2, 0)
        glVertex3f(250, pos - 22, 0)
        glVertex3f(100, pos - 22, 0)
        glEnd()

        # draw Show/Hide control and actual reports if exists
        glColor3f(1, 1, 1)
        blf.position(0, 105, pos - 15, 0)
        if _Show3DViewReportOperator.is_shown():
            blf.draw(0, "[+] Show | [  ] Hide")

            blf.enable(0, blf.SHADOW)
            blf.size(0, 12, 72)
            glColor3f(1, 1, 1)
            pos -= 40
            for line in _Show3DViewReportOperator.get_lines():

                # finish printing if running out of space
                if pos - 60 < 0:
                    blf.position(0, 20, pos, 0)
                    blf.draw(0, "...")
                    break

                blf.position(0, 20, pos, 0)
                if "ERROR" in line:
                    blf.shadow(0, 5, 0.5, 0., 0, 1)
                elif "WARNING" in line:
                    blf.shadow(0, 5, 0.3, 0.15, 0, 1)

                blf.draw(0, line)
                pos -= 15
            blf.disable(0, blf.SHADOW)
        else:
            blf.draw(0, "[  ] Show | [+] Hide")
Beispiel #53
0
def draw_text_array_mpm(self, text, key_text):
    font_id = 0
    x_offset = 0
    y_offset = 0
    text_size = get_addon_preferences().text_size
    line_height = (blf.dimensions(font_id, "M")[1] * 1.45)
    first_line_width = 0
    overlap = bpy.context.user_preferences.system.use_region_overlap
    t_panel_width = 0
    if overlap:
        for region in bpy.context.area.regions:
            if region.type == 'TOOLS':
                t_panel_width = region.width
    width = bpy.context.region.width
    line_color = get_addon_preferences().text_color
    text_size = get_addon_preferences().text_size
    text_shadow = get_addon_preferences().text_shadow
    shadow_color = get_addon_preferences().shadow_color
    shadow_alpha = get_addon_preferences().shadow_alpha
    shadow_x = get_addon_preferences().offset_shadow_x
    shadow_y = get_addon_preferences().offset_shadow_y
    text_pos_x = get_addon_preferences().text_pos_x
    text_pos_y = get_addon_preferences().text_pos_y

    for command in text[:5]:
        if len(command) == 3:
            Text, Color, Size = command
            blf.size(font_id, Size, 72)
            text_width, text_height = blf.dimensions(font_id, Text)
            first_line_width += text_width

    text_line_count = text.count("Carriage return") + 1
    x = min(text_pos_x + t_panel_width + 20, width - first_line_width - 20)
    y = min((line_height + text_size) * text_line_count + text_pos_y,
            bpy.context.region.height - 15)
    for command in text:
        if len(command) == 3:
            Text, Color, Size = command
            bgl.glColor3f(*Color)
            blf.size(font_id, Size, 72)
            text_width, text_height = blf.dimensions(font_id, Text)
            if text_shadow:
                blf.enable(0, blf.SHADOW)
                blf.shadow_offset(0, shadow_x, shadow_y)
                blf.shadow(0, 3, shadow_color[0], shadow_color[1],
                           shadow_color[2], shadow_alpha)
            blf.position(font_id, (x + x_offset), (y + y_offset), 0)
            blf.draw(font_id, Text)
            x_offset += text_width

        else:
            x_offset = 0
            if command == "line":
                y_offset -= 20
                bgl.glLineWidth(text_size * 0.075)
                bgl.glColor3f(*line_color)
                bgl.glEnable(bgl.GL_BLEND)
                bgl.glBegin(bgl.GL_LINES)
                bgl.glVertex2f(int(x + x_offset), int(y + y_offset))
                bgl.glVertex2f(int(x + x_offset + first_line_width),
                               int(y + y_offset))
                bgl.glEnd()
                bgl.glLineWidth(1)
                bgl.glDisable(bgl.GL_BLEND)
                bgl.glColor3f(0, 0, 0)

            else:
                y_offset -= line_height + text_size

    keys_size = get_addon_preferences().keys_size
    line_count = key_text.count("Carriage return")
    x_offset = 0
    y_offset = 0
    blf.size(font_id, keys_size, 72)
    line_height = (blf.dimensions(font_id, "M")[1] * 2)
    pos_x = 80 + t_panel_width
    pos_y = line_height * line_count + 70

    for command in key_text:
        if len(command) == 2:
            Text, Color = command
            bgl.glColor3f(*Color)
            text_width, text_height = blf.dimensions(font_id, Text)
            if text_shadow:
                blf.enable(0, blf.SHADOW)
                blf.shadow_offset(0, shadow_x, shadow_y)
                blf.shadow(0, 3, shadow_color[0], shadow_color[1],
                           shadow_color[2], shadow_alpha)
            blf.position(font_id, (pos_x + x_offset), (pos_y + y_offset), 0)
            blf.draw(font_id, Text)
            x_offset += text_width

        else:
            x_offset = 0
            y_offset -= line_height

    if text_shadow:
        blf.disable(0, blf.SHADOW)
Beispiel #54
0
def draw_callback_px(self, context):
    """Draws Code Editors Minimap and indentation marks"""
    def draw_line(origin, length, thickness, vertical=False):
        """Drawing lines with polys, its faster"""
        x = (origin[0] + thickness) if vertical else (origin[0] + length)
        y = (origin[1] + length) if vertical else (origin[1] + thickness)
        bgl.glBegin(bgl.GL_QUADS)
        for v1, v2 in [origin, (x, origin[1]), (x, y), (origin[0], y)]:
            bgl.glVertex2i(v1, v2)
        bgl.glEnd()
        return

    # abort if another text editor
    try:
        if self.window == context.window and self.area == context.area:
            bgl.glEnable(bgl.GL_BLEND)
        else:
            return
    except:
        return

    start = time.clock()

    # init params
    font_id = 0
    self.width = next(region.width for region in context.area.regions
                      if region.type == 'WINDOW')
    self.height = next(region.height for region in context.area.regions
                       if region.type == 'WINDOW')
    dpi_r = context.user_preferences.system.dpi / 72.0
    self.left_edge = self.width - round(
        dpi_r * (self.width + 5 * self.minimap_width) / 10.0)
    self.right_edge = self.width - round(dpi_r * 15)
    self.opacity = min(max(0, (self.width - self.min_width) / 100.0), 1)

    # compute character dimensions
    mcw = dpi_r * self.minimap_symbol_width  # minimap char width
    mlh = round(dpi_r * self.minimap_line_height)  # minimap line height
    fs = context.space_data.font_size
    cw = round(dpi_r * round(2 + 0.6 * (fs - 4)))  # char width
    ch = round(dpi_r * round(2 + 1.3 * (fs - 2) +
                             ((fs % 10) == 0)))  # char height
    #chfx = round(dpi_r * (2 + 1.3 * (fs - 2) + ((fs % 10) == 0))) # char height fixed
    # panel background box
    #self.tab_width = round(dpi_r * 25) if (self.tabs and len(bpy.data.texts) > 1) else 0
    bgl.glColor4f(self.background.r, self.background.g, self.background.b,
                  (1 - self.bg_opacity) * self.opacity)
    bgl.glBegin(bgl.GL_QUADS)
    #bgl.glVertex2i(self.left_edge-self.tab_width, self.height)
    bgl.glVertex2i(self.left_edge, self.height)
    bgl.glVertex2i(self.right_edge, self.height)
    bgl.glVertex2i(self.right_edge, 0)
    #bgl.glVertex2i(self.left_edge-self.tab_width, 0)
    bgl.glVertex2i(self.left_edge, 0)
    bgl.glEnd()

    # space = context.space_data
    # if space.text:
    #     lines = len(space.text.lines)
    #     lines_digits = len(str(lines)) if space.show_line_numbers else 0

    #### AQUI Y AHORA
    #line numbers background
    space = context.space_data
    if space.text:
        lines = len(space.text.lines)
        lines_digits = len(str(lines)) if space.show_line_numbers else 0
        self.line_bar_width = int(dpi_r * 5) + cw * (lines_digits)
#        bgl.glColor4f(1, 0, 0, 0.3)
#        for id in range(space.top, min(space.top+space.visible_lines+1, lines+1)):
#            if id in [2, 1, 4, 8, 24, 55]:
#                bgl.glBegin(bgl.GL_QUADS)
#                bgl.glVertex2i(0, self.height-chfx*(id-space.top))
#                bgl.glVertex2i(self.line_bar_width, self.height-chfx*(id-space.top))
#                bgl.glVertex2i(self.line_bar_width, self.height-chfx*(id-1-space.top))
#                bgl.glVertex2i(0, self.height-chfx*(id-1-space.top))
#                bgl.glEnd()
#                #bgl.glColor4f(1, 0, 0, 0.5)
#blf.size(font_id, fs, int(dpi_r)*72)
#blf.position(font_id, 2+int(0.5*cw*(len(str(lines))-len(str(id)))), self.height-ch*(id-space.top)+3, 0)
#blf.draw(font_id, '*')
# blf.position(font_id,
#              2+int(0.5*cw*(len(str(lines))-len(str(id)))),
#              self.height-ch*(id-space.top)+3, 0)
# blf.draw(font_id, u'▓▓')

# minimap shadow
    for id, intensity in enumerate([0.2, 0.1, 0.07, 0.05, 0.03, 0.02, 0.01]):
        bgl.glColor4f(0.0, 0.0, 0.0, intensity * self.opacity)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        #bgl.glVertex2i(self.left_edge-id-self.tab_width, 0)
        #bgl.glVertex2i(self.left_edge-id-self.tab_width, self.height)
        bgl.glVertex2i(self.left_edge - id, 0)
        bgl.glVertex2i(self.left_edge - id, self.height)
        bgl.glEnd()

    # divider
    # if self.tab_width:
    #     bgl.glColor4f(0.0, 0.0, 0.0, 0.2*self.opacity)
    #     bgl.glBegin(bgl.GL_LINE_STRIP)
    #     bgl.glVertex2i(self.left_edge, 0)
    #     bgl.glVertex2i(self.left_edge, self.height)
    #     bgl.glEnd()

    # if there is text in window
    if space.text and self.opacity:

        # minimap horizontal sliding based on text block length
        max_slide = max(0, mlh * (lines + self.height / ch) - self.height)
        self.slide = int(max_slide * space.top / lines)
        minimap_top_line = int(self.slide / mlh)
        minimap_bot_line = int((self.height + self.slide) / mlh)

        # draw minimap visible box
        if self.in_minimap:
            bgl.glColor4f(1.0, 1.0, 1.0, 0.1 * self.opacity)
        else:
            bgl.glColor4f(1.0, 1.0, 1.0, 0.07 * self.opacity)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glVertex2i(self.left_edge,
                       self.height - mlh * space.top + self.slide)
        bgl.glVertex2i(self.right_edge,
                       self.height - mlh * space.top + self.slide)
        bgl.glVertex2i(
            self.right_edge,
            self.height - mlh * (space.top + space.visible_lines) + self.slide)
        bgl.glVertex2i(
            self.left_edge,
            self.height - mlh * (space.top + space.visible_lines) + self.slide)
        bgl.glEnd()

        # draw minimap code
        for segment in self.segments[:-1]:
            bgl.glColor4f(segment['col'][0], segment['col'][1],
                          segment['col'][2], 0.4 * self.opacity)
            for id, element in enumerate(
                    segment['elements'][minimap_top_line:minimap_bot_line]):
                loc_y = mlh * (id + minimap_top_line + 3) - self.slide
                for sub_element in element:
                    draw_line(
                        (self.left_edge + int(mcw * (sub_element[0] + 4)),
                         self.height - loc_y),
                        int(mcw * (sub_element[1] - sub_element[0])),
                        int(0.5 * mlh))

        # minimap code marks
        bgl.glColor4f(self.segments[-2]['col'][0], self.segments[-2]['col'][1],
                      self.segments[-2]['col'][2],
                      0.3 * self.block_trans * self.opacity)
        for id, element in enumerate(self.segments[-2]['elements']):
            for sub_element in element:
                if sub_element[
                        2] >= space.top or id < space.top + space.visible_lines:
                    draw_line(
                        (self.left_edge + int(mcw * (sub_element[0] + 4)),
                         self.height - mlh * (id + 3) + self.slide),
                        -int(mlh * (sub_element[2] - id - 1)), int(0.5 * mlh),
                        True)

    # draw dotted indentation marks
    bgl.glLineWidth(1.0 * dpi_r)
    if space.text:
        bgl.glColor4f(self.segments[0]['col'][0], self.segments[0]['col'][1],
                      self.segments[0]['col'][2], self.indent_trans)
        for id, element in enumerate(
                self.segments[-1]['elements'][space.top:space.top +
                                              space.visible_lines]):
            loc_y = id
            for sub_element in element:
                draw_line(
                    (int(dpi_r * 10) + cw *
                     (lines_digits + sub_element[0] + 4), self.height - ch *
                     (loc_y)), -ch, int(1 * dpi_r), True)

        # draw code block marks
        bgl.glColor4f(self.segments[-2]['col'][0], self.segments[-2]['col'][1],
                      self.segments[-2]['col'][2], self.block_trans)
        for id, element in enumerate(self.segments[-2]['elements']):
            for sub_element in element:
                if sub_element[
                        2] >= space.top or id < space.top + space.visible_lines:
                    bgl.glBegin(bgl.GL_LINE_STRIP)
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0])),
                        self.height - ch * (id + 1 - space.top))
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw * (lines_digits + sub_element[0])),
                        self.height - int(ch * (sub_element[2] - space.top)))
                    bgl.glVertex2i(
                        int(dpi_r * 10 + cw *
                            (lines_digits + sub_element[0] + 1)),
                        self.height - int(ch * (sub_element[2] - space.top)))
                    bgl.glEnd()

    # tab dividers
    # if self.tab_width and self.opacity:
    #     self.tab_height = min(200, int(self.height/len(bpy.data.texts)))
    #     y_loc = self.height-5
    #     for text in bpy.data.texts:
    #         # tab selection
    #         if text.name == self.in_tab:
    #             bgl.glColor4f(1.0, 1.0, 1.0, 0.05*self.opacity)
    #             bgl.glBegin(bgl.GL_QUADS)
    #             bgl.glVertex2i(self.left_edge-self.tab_width, y_loc)
    #             bgl.glVertex2i(self.left_edge, y_loc)
    #             bgl.glVertex2i(self.left_edge, y_loc-self.tab_height)
    #             bgl.glVertex2i(self.left_edge-self.tab_width, y_loc-self.tab_height)
    #             bgl.glEnd()
    #         # tab active
    #         if context.space_data.text and text.name == context.space_data.text.name:
    #             bgl.glColor4f(1.0, 1.0, 1.0, 0.05*self.opacity)
    #             bgl.glBegin(bgl.GL_QUADS)
    #             bgl.glVertex2i(self.left_edge-self.tab_width, y_loc)
    #             bgl.glVertex2i(self.left_edge, y_loc)
    #             bgl.glVertex2i(self.left_edge, y_loc-self.tab_height)
    #             bgl.glVertex2i(self.left_edge-self.tab_width, y_loc-self.tab_height)
    #             bgl.glEnd()
    #         bgl.glColor4f(0.0, 0.0, 0.0, 0.2*self.opacity)
    #         y_loc -= self.tab_height
    #         bgl.glBegin(bgl.GL_LINE_STRIP)
    #         bgl.glVertex2i(self.left_edge-self.tab_width, y_loc)
    #         bgl.glVertex2i(self.left_edge, y_loc)
    #         bgl.glEnd()

    # draw fps
#    bgl.glColor4f(1, 1, 1, 0.2)
#    blf.size(font_id, fs, int(dpi_r*72))
#    blf.position(font_id, self.left_edge-50, 5, 0)
#    blf.draw(font_id, str(round(1/(time.clock() - start),3)))

# draw line numbers
#    if space.text:
#        bgl.glColor4f(1, 0, 0, 0.5)
#        for id in range(space.top, min(space.top+space.visible_lines+1, lines+1)):
#            blf.size(font_id, fs, int(dpi_r*72))
#            blf.position(font_id, 2+int(0.5*cw*(len(str(lines))-len(str(id)))), self.height-ch*(id-space.top)+3, 0)
#            blf.draw(font_id, '*')
#    #     # bgl.glColor4f(self.segments[0]['col'][0],
#     #               self.segments[0]['col'][1],
#     #               self.segments[0]['col'][2],
#     #               0.5)
#     for id in range(space.top, min(space.top+space.visible_lines+1, lines+1)):
#         blf.position(font_id, 2+int(0.5*cw*(len(str(lines))-len(str(id)))), self.height-ch*(id-space.top)+3, 0)
#         blf.draw(font_id, u'▓▓')

# draw file names
# if self.tab_width:
#     blf.enable(font_id, blf.ROTATION)
#     blf.rotation(font_id, 1.570796)
#     y_loc = self.height
#     for text in bpy.data.texts:
#         text_max_length = max(2,int((self.tab_height - 40)/cw))
#         name = text.name[:text_max_length]
#         if text_max_length < len(text.name):
#             name += '...'
#         bgl.glColor4f(self.segments[0]['col'][0],
#                       self.segments[0]['col'][1],
#                       self.segments[0]['col'][2],
#                       (0.7 if text.name == self.in_tab else 0.4)*self.opacity)
#         blf.position(font_id,
#                      self.left_edge-round((self.tab_width-ch)/2.0)-5,
#                      round(y_loc-(self.tab_height/2)-cw*len(name)/2),
#                      0)
#         blf.draw(font_id, name)
#         y_loc -= self.tab_height

# restore opengl defaults
    bgl.glColor4f(0, 0, 0, 1)
    bgl.glLineWidth(1.0)
    bgl.glDisable(bgl.GL_BLEND)
    blf.disable(font_id, blf.ROTATION)
    return
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)
Beispiel #56
0
 def disable_word_wrap(fontid=None):
     return blf.disable(FontManager.load(fontid), blf.WORD_WRAP)
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):
    # 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)