예제 #1
0
파일: font.py 프로젝트: DCubix/Compz
	def draw(self, text, x, y):
		if self.shadowed:
			blf.enable(self.id, blf.SHADOW)
			blf.shadow_offset(self.id, self.shadow_offset[0],
				self.shadow_offset[1])
			blf.shadow(self.id, 3, 0, 0, 0, 0.8)
		else:
			blf.disable(self.id, blf.SHADOW)

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

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

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

		if self.shadowed:
			blf.disable(self.id, blf.SHADOW)
예제 #2
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)
예제 #3
0
def write_interaction_status():
    """
    Write the interaction status on Screen
    The status is stored in a property
    """
    cam = logic.getCurrentScene().active_camera

    # get the suffix of the human to reference the right objects
    suffix = cam.name[-4:] if cam.name[-4] == "." else ""
    
    hand = objects['Hand_Grab.R' + suffix]
    
    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    blf.size(font_id, int(windowHeight*0.04), 72)
    # draw a black shadow around the text
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
    blf.position(font_id, windowWidth*0.4, windowHeight*0.4,0)
    blf.draw(font_id, hand['Status'])
예제 #4
0
    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モード以外では利用できません"
            )
예제 #5
0
    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']
                )
            )
예제 #6
0
파일: putil.py 프로젝트: jdpillon/pgui
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)
예제 #9
0
    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)
예제 #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)
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)
예제 #12
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)
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)
예제 #14
0
def draw_text_custom(text, x, y, font_file_path, shadow_on, align="LEFT", size=12, color=(1.0, 1.0, 1.0, 1.0)):
    font_path = font_file_path
    font_id = blf.load(font_path)
    font = font_id

    blf.size(font, size, int(dpi))
    glColor4f(*color)

    if shadow_on == "ON":
        blf.shadow(font, 5, 0.0, 0.0, 0.0, 1.0)

    if align == "LEFT":
        blf.position(font, x, y, 0)
    else:
        width, height = blf.dimensions(font, text)
        if align == "RIGHT":
            blf.position(font, x - width, y, 0)

    blf.draw(font, text)
예제 #15
0
def write_interaction_status():
    """
    Write the interaction status on Screen
    The status is stored in a property
    """
    hand = objects["Hand_Grab.R"]

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    blf.size(font_id, int(windowHeight * 0.04), 72)
    # draw a black shadow around the text
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
    blf.position(font_id, windowWidth * 0.4, windowHeight * 0.4, 0)
    blf.draw(font_id, hand["Status"])
예제 #16
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"
            )
예제 #17
0
def write():
    """
    Write the name of all active objects on Screen
    """
    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    cam = scene.active_camera

    for obj in passive_objects.active_objects():
        # test if the object is in the view frustum
        if cam.pointInsideFrustum(obj.worldPosition):
            pos = cam.getScreenPosition(obj)
    
            blf.size(font_id, int(windowWidth * 0.02), 72)
            # draw a black shadow to increase contrast with white parts
            blf.enable(font_id, blf.SHADOW)
            blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
            blf.position(font_id, pos[0]*windowWidth, (1 - pos[1])*windowHeight,0)
            blf.draw(font_id, obj.name)
예제 #18
0
def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

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

    # BLF drawing routine
    blf.size(font_id, height//40, 72)
    data = parse_file.read_file()
    data = data.splitlines()
    linePosition = height * 0.8
    for str in data:
        str_len = len(str)
        blf.position(font_id, (width * 0.05), linePosition, 0)
        blf.enable(font_id, blf.SHADOW)
        blf.shadow(font_id, 0, 1.0, 0.2, 0.0, 1.0)
        blf.draw(font_id,str)
        linePosition -= height * 0.05
예제 #19
0
    def draw_callback_px(self, context, pos):
        val = self.radial_count
        hpos, vpos = 64, 110
        # title = "tit"
        if pos: hpos = pos - 120
        if val:
            font_id = 0
            blf.enable(font_id, 4)
            blf.position(font_id, hpos, vpos + 68, 0)
            blf.color(font_id, self.hcol[0], self.hcol[1], self.hcol[2],
                      self.hcol[3])
            blf.size(font_id, 20, 72)
            blf.shadow(font_id, 5, 0, 0, 0, 1)
            blf.shadow_offset(font_id, 1, -1)
            blf.draw(font_id, "Radial Array: " + str(val))

            if self.array_input_mode or self.adj_mode_z or self.adj_mode_rad or self.adj_mode_scl:
                blf.size(font_id, 13, 72)
                blf.color(font_id, self.hcol[0], self.hcol[1], self.hcol[2],
                          self.hcol[3])
                blf.position(font_id, hpos, vpos + 98, 0)
                adjm = ""
                if self.adj_mode_rad:
                    adjm = "[ (X) Circle Radius Adjustment Mode ]"
                elif self.adj_mode_z:
                    adjm = "[ (Z) Depth Adjustment Mode ]"
                elif self.adj_mode_scl:
                    adjm = "[ (S) Scale Object Adjustment Mode ]"
                if self.array_input_mode:
                    blf.draw(font_id, "[ (A) Numerical Input Mode ] " + adjm)
                else:
                    blf.draw(font_id, adjm)
            if self.help:
                blf.size(font_id, 13, 72)
                blf.color(font_id, self.tcol[0], self.tcol[1], self.tcol[2],
                          self.tcol[3])
                blf.position(font_id, hpos, vpos + 45, 0)
                blf.draw(font_id, "Count:       Mouse Wheel Up / Down")
                blf.position(font_id, hpos, vpos + 27, 0)
                blf.draw(font_id, "Radius:      (X) (or C)")
                blf.position(font_id, hpos, vpos + 9, 0)
                blf.draw(font_id, "Z Pos:       (Z)   Reset Z: (R)")
                blf.position(font_id, hpos, vpos - 9, 0)
                blf.draw(font_id, "Scale:       (S)")
                blf.position(font_id, hpos, vpos - 30, 0)
                blf.draw(font_id,
                         "Adjustment Level: (1) Very Fine --> (5) Huge ")
                blf.position(font_id, hpos, vpos - 48, 0)
                blf.draw(font_id,
                         "(A) Toggle Numerical Input Mode for Array Count")

                blf.size(font_id, 10, 72)
                blf.color(font_id, self.scol[0], self.scol[1], self.scol[2],
                          self.scol[3])
                blf.position(font_id, hpos, vpos - 66, 0)
                blf.draw(font_id, "Apply: Enter/Spacebar/LMB  Cancel: Esc/RMB")
                blf.position(font_id, hpos, vpos - 80, 0)
                blf.draw(font_id,
                         "Navigation: Blender (MMB's) + Ind.Std (Alt-MB's)")
                blf.position(font_id, hpos, vpos - 94, 0)
                blf.draw(font_id, "(H) Toggle Help")
            else:
                blf.size(font_id, 12, 72)
                blf.color(font_id, self.scol[0], self.scol[1], self.scol[2],
                          self.scol[3])
                blf.position(font_id, hpos, vpos + 45, 0)
                blf.draw(font_id, "(H) Toggle Help")
        else:
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'CANCELLED'}
예제 #20
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 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]
예제 #22
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)
예제 #23
0
 def shadow(level, rgba, fontid=None):
     return blf.shadow(FontManager.load(fontid), level, *rgba)
예제 #24
0
def linumdisplay(disp_op, context, simnode, connode, geonode):
    scene = context.scene
    if not scene.vi_display:
        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

    if scene.frame_current not in range(scene.fs,
                                        scene.fe + 1) and scene.vi_display:
        disp_op.report({'INFO'}, "Outside result frame range")
        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
    #    cp = geonode.cpoint if geonode else simnode.cpoint
    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 = 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

    if not context.space_data.region_3d.is_perspective:
        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 * 10
    else:
        vw = mathutils.Vector(
            (view_mat.inverted()[0][3], view_mat.inverted()[1][3],
             view_mat.inverted()[2][3])).normalized()
        view_location = vw * bpy.context.region_data.view_distance

    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['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
                    (f.calc_center_median() - view_location) * vw < 0
                ]
                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_median().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 (fpos[fi] - view_location) * vw < 0
                ]
                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 (v.co - view_location) * vw < 0
                ]
                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
                    (omw *
                     (ob.data.shape_keys.key_blocks[str(scene.frame_current)].
                      data[v.index].co) - view_location) * vw < 0
                ]
                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)
예제 #25
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")
예제 #26
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
    
    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)
예제 #27
0
 def _draw_text(self, x, y):
     for i, txt in enumerate([i for i in self._text.split('\n')]):
         blf.position(self.fontid, x, y - (self.size[1] * i), 0)
         blf.shadow(self.fontid, self.shadow_blur, self.shadow_color[0],
                 self.shadow_color[1], self.shadow_color[2], self.shadow_color[3])
         blf.draw(self.fontid, txt.replace('\t', '    '))
예제 #28
0
                region = r
                break

        return region
//! [get_region]

    @staticmethod
    def __render(self, context):
        # リージョン幅を取得するため、描画先のリージョンを得る
        region = RenderText.__get_region(context, 'VIEW_3D', 'WINDOW')

//! [call_render_region]
        # 描画先のリージョンへテキストを描画
        if region is not None:
            # 影の効果を設定
            blf.shadow(0, 3, 0.0, 1.0, 0.0, 0.5)
            # 影の位置を設定
            blf.shadow_offset(0, 2, -2)
            # 影の効果を有効化
            blf.enable(0, blf.SHADOW)
            RenderText.__render_text(
                40, 40, region.height - 120, "Hello Blender world!!"
            )
            # 影の効果を無効化
            blf.disable(0, blf.SHADOW)
            RenderText.__render_text(
                30, 40, region.height - 180, "Suzanne on your lap"
            )
//! [call_render_region]

    def invoke(self, context, event):
예제 #29
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")
예제 #30
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)   
예제 #31
0
    def draw_callback_px(self):
        color = bpy.context.tool_settings.image_paint.brush.cursor_color_add

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(color[0], color[1], color[2], .5)
        bgl.glLineWidth(1)

        bgl.glEnable(bgl.GL_LINE_SMOOTH)

        ### draw curve gradient
        ring_count = 12
        segements = 36

        for j in range(ring_count):
            bgl.glBegin(bgl.GL_QUAD_STRIP)
            for i in range(segements + 1):
                curve = self.brush.curve.curves[0]
                curve_pos = (j * (1 / ring_count))
                curve_pos = min(curve_pos, 1.0)
                curve_pos = max(curve_pos, 0.0)
                curve_pos2 = curve_pos + (1 / ring_count)
                curve_pos2 = min(curve_pos2, 1.0)
                curve_pos2 = max(curve_pos2, 0.0)

                alpha1 = curve.evaluate(curve_pos)
                alpha2 = curve.evaluate(curve_pos2)

                offset = self.mouse_pos_init
                angle = 2 * pi / segements
                size = self.outer_size * (j + 1) * (1 / ring_count)
                size2 = self.outer_size * j * (1 / ring_count)
                point1 = offset + Vector(
                    (size * cos(i * angle), (size * sin(i * angle))))
                point2 = offset + Vector(
                    (size2 * cos(i * angle), (size2 * sin(i * angle))))

                bgl.glColor4f(self.brush_color[0], self.brush_color[1],
                              self.brush_color[2], alpha2)
                bgl.glVertex2f(point1[0], point1[1])
                bgl.glColor4f(self.brush_color[0], self.brush_color[1],
                              self.brush_color[2], alpha1)
                bgl.glVertex2f(point2[0], point2[1])

            bgl.glEnd()

        ### draw brush circles
        bgl.glColor4f(color[0], color[1], color[2], .5)
        bgl.glLineWidth(1)
        bgl.glBegin(bgl.GL_LINE_LOOP)
        segements = 42
        for i in range(segements):
            bgl.glVertex2f(
                self.mouse_pos_init.x +
                self.inner_size * cos(i * (2 * pi / segements)),
                self.mouse_pos_init.y +
                self.inner_size * sin(i * (2 * pi / segements)))
        bgl.glEnd()

        bgl.glBegin(bgl.GL_LINE_LOOP)
        for i in range(segements):
            bgl.glVertex2f(
                self.mouse_pos_init.x +
                self.hardness * cos(i * (2 * pi / segements)),
                self.mouse_pos_init.y +
                self.hardness * sin(i * (2 * pi / segements)))
        bgl.glEnd()

        bgl.glBegin(bgl.GL_LINE_LOOP)
        for i in range(segements):
            bgl.glVertex2f(
                self.mouse_pos_init.x +
                self.outer_size * cos(i * (2 * pi / segements)),
                self.mouse_pos_init.y +
                self.outer_size * sin(i * (2 * pi / segements)))
        bgl.glEnd()

        ### draw brush values
        font_id = 0
        blf.size(font_id, 17, 72)

        blf.enable(font_id, blf.SHADOW)
        blf.shadow(font_id, 5, 0, 0, 0, .8)
        blf.shadow_offset(font_id, 1, -1)
        bgl.glColor4f(color[0], color[1], color[2], .5)
        blf.position(font_id, self.mouse_pos_init.x - 24,
                     self.mouse_pos_init.y - 6, 0)
        blf.draw(font_id, format(self.strength, ".3f"))

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #32
0
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 = 0
    text_height = 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]