Python blf.color() Examples

The following are 30 code examples of blf.color(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module blf , or try the search function .
Example #1
Source File: draw_imageeditor.py    From BlendLuxCore with GNU General Public License v3.0 6 votes vote down vote up
def _draw_tiles(coords, passcounts, color, view_to_region):
    if not coords or TileStats.film_width == 0 or TileStats.film_height == 0:
        return

    for i in range(len(coords) // 2):
        # Pixel coords
        x = coords[i * 2]
        y = coords[i * 2 + 1]
        width = min(TileStats.width, TileStats.film_width - x)
        height = min(TileStats.height, TileStats.film_height - y)

        # Relative coords in range 0..1
        rel_x = x / TileStats.film_width
        rel_y = y / TileStats.film_height
        rel_width = width / TileStats.film_width
        rel_height = height / TileStats.film_height

        _draw_rect(rel_x, rel_y, rel_width, rel_height, color, view_to_region)

        if passcounts:
            _draw_text(str(passcounts[i]), rel_x, rel_y, color, view_to_region) 
Example #2
Source File: bl_ui_checkbox.py    From bl_ui_widgets with GNU General Public License v3.0 6 votes vote down vote up
def draw(self):

        area_height = self.get_area_height()
        self.shader_chb.bind()

        if self.is_checked:
            bgl.glLineWidth(3)
            self.shader_chb.uniform_float("color", self._cross_color)

            self.batch_cross.draw(self.shader_chb) 

        bgl.glLineWidth(2)
        self.shader_chb.uniform_float("color", self._box_color)

        self.batch_box.draw(self.shader_chb) 

        # Draw text
        self.draw_text(area_height) 
Example #3
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 6 votes vote down vote up
def draw_rect(x, y, width, height, color):
    xmax = x + width
    ymax = y + height
    points = [[x, y],  # [x, y]
              [x, ymax],  # [x, y]
              [xmax, ymax],  # [x, y]
              [xmax, y],  # [x, y]
              ]
    indices = ((0, 1, 2), (2, 3, 0))

    shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'TRIS', {"pos": points}, indices=indices)

    shader.bind()
    shader.uniform_float("color", color)
    bgl.glEnable(bgl.GL_BLEND)
    batch.draw(shader) 
Example #4
Source File: modal_utils.py    From leomoon-lightstudio with GNU General Public License v3.0 6 votes vote down vote up
def _draw(self, context, event):
        # first draw to reset buffer
        shader2Dcolor.uniform_float("color", (.5, .5, .5, .5))
        batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((0,0), (0,0))}).draw(shader2Dcolor)
        
        if self.draw_guide:
            shader2Dcolor.uniform_float("color", (.5, .5, .5, .5))
            batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((self._start_position[:]), (self._end_position[:]))}).draw(shader2Dcolor)

        if self.allow_xy_keys:
            if self.x_key:
                shader2Dcolor.uniform_float("color", (1, 0, 0, .5))
                batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((0, self._start_position.y), (context.area.width, self._start_position.y))}).draw(shader2Dcolor)
            elif self.y_key:
                shader2Dcolor.uniform_float("color", (0, 1, 0, .5))
                batch_for_shader(shader2Dcolor, 'LINES', {"pos": ((self._start_position.x, 0), (self._start_position.x, context.area.height))}).draw(shader2Dcolor) 
Example #5
Source File: onscreen_text.py    From jewelcraft with GNU General Public License v3.0 6 votes vote down vote up
def onscreen_warning(self, x, y):
        gamma = self.gamma_correction

        fontid = 1
        blf.size(fontid, self.prefs.view_font_size_report, 72)
        blf.color(fontid, *gamma((1.0, 0.3, 0.3, 1.0)))

        _, font_h = blf.dimensions(fontid, "Row Height")
        font_row_height = font_h * 2
        y += font_h

        for row in self.warn:
            y -= font_row_height

            blf.position(fontid, x, y, 0.0)
            blf.draw(fontid, row)

        return y 
Example #6
Source File: mi_curve_stretch.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def draw_text_2d(self, context):

    cur_stretch_settings = context.scene.mi_cur_stretch_settings
    rh = context.region.height
    rw = context.region.width

    font_id = 0
    font_size = 30

    #Set font color
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glColor(1, 0.75, 0.1, 1)
    blf.color(0, 1, 0.75, 0.1, 1)
    bgl.glLineWidth(2)

    #Draw text
    blf.position(font_id, rw - 400, 210 - font_size, 0)
    blf.size(font_id, font_size, 72)
    blf.draw(font_id, str(cur_stretch_settings.points_number))

    # restore opengl defaults
    bgl.glLineWidth(1)
    blf.color(0, 0.0, 0.0, 0.0, 1.0)
    bgl.glDisable(bgl.GL_BLEND)
    #bgl.glColor(0, 0.0, 0.0, 0.0, 1.0) 
Example #7
Source File: fsc_add_object_op.py    From fast-sculpt with GNU General Public License v3.0 6 votes vote down vote up
def draw_callback_2d(self, op, context):

        # Draw text for add object mode
        header = "- Add Object Mode (Type: " + context.scene.add_object_type + ") -"
        text = "Ctrl + Left Click = Add | Esc = Exit"

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

        region = context.region
        xt = int(region.width / 2.0)

        blf.position(0, xt - blf.dimensions(0, header)[0] / 2, 50 , 0)
        blf.draw(0, header)

        blf.position(1, xt - blf.dimensions(1, text)[0] / 2, 20 , 0)
        blf.draw(1, text) 
Example #8
Source File: scv_op.py    From shortcut_VUr with GNU General Public License v3.0 5 votes vote down vote up
def create_font(id, size, color):
    blf.color(id, color.r, color.g, color.b, 1.0 )
    blf.size(id, size, 72) 
Example #9
Source File: bl_ui_textbox.py    From bl_ui_widgets with GNU General Public License v3.0 5 votes vote down vote up
def draw_text(self, area_height):
        blf.size(0, self._text_size, 72)
        size = blf.dimensions(0, self._text)

        textpos_y = area_height - \
            self._textpos[1] - (self.height + size[1]) / 2.0
        blf.position(
            0, self._textpos[0] + (self.width - size[0]) / 2.0, textpos_y + 1, 0)

        r, g, b, a = self._text_color
        blf.color(0, r, g, b, a)

        blf.draw(0, self._text) 
Example #10
Source File: draw.py    From blender-power-sequencer with GNU General Public License v3.0 5 votes vote down vote up
def get_color_gizmo_primary(context):
    color = context.preferences.themes[0].user_interface.gizmo_primary
    return _color_to_list(color) 
Example #11
Source File: bl_ui_up_down.py    From bl_ui_widgets with GNU General Public License v3.0 5 votes vote down vote up
def color(self, value):
        self._color = value 
Example #12
Source File: bl_ui_checkbox.py    From bl_ui_widgets with GNU General Public License v3.0 5 votes vote down vote up
def draw_text(self, area_height):
        blf.size(0, self._text_size, 72)
        size = blf.dimensions(0, self._text)

        textpos_y = area_height - self._textpos[1] - (self.height + size[1]) / 2.0
        blf.position(0, self._textpos[0], textpos_y, 0)

        r, g, b, a = self._text_color
        blf.color(0, r, g, b, a)

        blf.draw(0, self._text) 
Example #13
Source File: textRenderExample.py    From FlowState with GNU General Public License v3.0 5 votes vote down vote up
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.glColor(1,1,1,1)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    # BLF drawing routine
    font_id = logic.font_id
    RED = (1, 0, 0, 1)
    pcol = ("Blue ", RED)
    #blf.color(font_id, 1, 1, 0, 0.5)
    blf.blur(font_id,500)
    blf.rotation(font_id, 90)
    blf.position(font_id, (width * 0.5), (height * 0.5), 0.5)
    blf.size(font_id, 20, 100)
    blf.draw(font_id, "Hello World1")
    blf.size(font_id, 50, 72)
    blf.position(font_id, (width * 0.0), (height * 0.5), 0.5)
    blf.draw(font_id, "Hello World2") 
Example #14
Source File: onscreen_text.py    From jewelcraft with GNU General Public License v3.0 5 votes vote down vote up
def onscreen_gem_table(self, x, y, color=(0.95, 0.95, 0.95, 1.0), is_viewport=True):
        gamma = self.gamma_correction if is_viewport else lambda x: x
        color = gamma(color)

        fontid = 1
        blf.size(fontid, self.prefs.view_font_size_report, 72)
        blf.color(fontid, *color)

        _, font_h = blf.dimensions(fontid, "Row Height")
        font_baseline = font_h * 0.4
        font_row_height = font_h * 2
        box_size = font_h * 1.5
        y += font_baseline

        for row, color in self.gems_fmt:
            y -= font_row_height

            shader.bind()
            shader.uniform_float("color", color)
            batch_font = batch_for_shader(shader, "TRI_FAN", {"pos": self.rect_coords(x, y, box_size, box_size)})
            batch_font.draw(shader)

            blf.position(fontid, x + font_row_height, y + font_baseline, 0.0)
            blf.draw(fontid, row)

        return y 
Example #15
Source File: bl_ui_up_down.py    From bl_ui_widgets with GNU General Public License v3.0 5 votes vote down vote up
def color(self):
        return self._color 
Example #16
Source File: scv_op.py    From shortcut_VUr with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_px(self, op, context):

        if context.region.width != self.width_region:
            self.width_region = context.region.width
            self.draw_util.create_batches(context, self.mouse_input)
            
        refresh_after_sec = 3.0
        font_color = context.scene.font_color
        font_size = 28

        if context.scene.show_buttons:

            # set color for buttons
            self.draw_util.set_color_buttons(context)

            # Draw the mouse buttons
            self.draw_util.draw_buttons(
            self.mouse_input.is_left,
            self.mouse_input.is_middle, 
            self.mouse_input.is_right)
        
        # draw the text for events
        current_time = time.time()
        
        time_diff_keys = current_time - self.key_input.timestamp
                            
        if(time_diff_keys < refresh_after_sec):
                                                 
            self.draw_text(font_size, font_color, context)

        else:
            self.key_input.clear()
            self.mouse_input.clear() 
Example #17
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def draw_progress(x, y, text='', percent=None, color=(0, 1, 0, 1)):
    draw_rect(x, y, percent, 5, color)
    draw_text(text, x, y + 8, 16, color) 
Example #18
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def draw_line2d(x1, y1, x2, y2, width, color):
    coords = (
        (x1, y1), (x2, y2))

    indices = (
        (0, 1),)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_SMOOTH)

    shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'LINES', {"pos": coords}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
Example #19
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def draw_lines(vertices, indices, color):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_SMOOTH)
    bgl.glLineWidth(2)

    shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'LINES', {"pos": vertices}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
Example #20
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def draw_rect_3d(coords, color):
    indices = [(0, 1, 2), (2, 3, 0)]
    shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'TRIS', {"pos": coords}, indices=indices)
    shader.uniform_float("color", color)
    batch.draw(shader) 
Example #21
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def draw_progress(x, y, text='', percent=None, color=(.2, 1, .2, .7)):
    draw_rect(x, y, percent, 5, color)
    draw_text(text, x, y + 8, 16, color) 
Example #22
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def draw_text(text, x, y, size, color=(1, 1, 1, 0.5)):
    font_id = 0
    # bgl.glColor4f(*color)
    blf.color(font_id, color[0], color[1], color[2], color[3])
    blf.position(font_id, x, y, 0)
    blf.size(font_id, size, 72)
    blf.draw(font_id, text) 
Example #23
Source File: draw_imageeditor.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def _draw_rect(x, y, width, height, color, view_to_region):
    x1, y1 = view_to_region(x, y, clip=False)
    x2, y2 = view_to_region(x + width, y, clip=False)
    x3, y3 = view_to_region(x + width, y + height, clip=False)
    x4, y4 = view_to_region(x, y + height, clip=False)

    co = ((x1, y1), (x2, y2), (x3, y3), (x4, y4))
    indices = ((0, 1), (1, 2), (2, 3), (3, 0))

    shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'LINES', {"pos": co}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
Example #24
Source File: draw_imageeditor.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def _draw_text(text, x, y, color, view_to_region):
    font_id = 0
    dpi = 72
    text_size = 12
    offset = 5
    pixelpos_x, pixelpos_y = view_to_region(x, y, clip=False)

    r, g, b, a = color
    blf.position(font_id, pixelpos_x + offset, pixelpos_y + offset, 0)
    blf.color(font_id, r,g,b,a)
    blf.size(font_id, text_size, dpi)
    blf.draw(font_id, text) 
Example #25
Source File: modal_utils.py    From leomoon-lightstudio with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, loc, text, size=15):
        self.font_size = size
        self.font_color = (.25, .25, .25, 1)
        self.bg_color = (.5, .5, .5, 1)
        self.bg_color_selected = (.7, .7, .7, 1)
        self.font_id = len(Button.buttons)
        self.text = text
        blf.color(self.font_id, *self.font_color)
        blf.position(self.font_id, *loc, 0)
        blf.size(self.font_id, self.font_size, 72)
        self.dimensions = blf.dimensions(self.font_id, text)
        self.function = lambda args : None

        super().__init__(loc, self.dimensions[0]+5, self.dimensions[1]+5)
        Button.buttons.append(self) 
Example #26
Source File: draw.py    From blender-power-sequencer with GNU General Public License v3.0 5 votes vote down vote up
def get_color_gizmo_secondary(context):
    color = context.preferences.themes[0].user_interface.gizmo_secondary
    return _color_to_list(color) 
Example #27
Source File: draw.py    From blender-power-sequencer with GNU General Public License v3.0 5 votes vote down vote up
def get_color_axis_x(context):
    color = context.preferences.themes[0].user_interface.axis_x
    return _color_to_list(color) 
Example #28
Source File: draw.py    From blender-power-sequencer with GNU General Public License v3.0 5 votes vote down vote up
def get_color_axis_y(context):
    color = context.preferences.themes[0].user_interface.axis_y
    return _color_to_list(color) 
Example #29
Source File: draw.py    From blender-power-sequencer with GNU General Public License v3.0 5 votes vote down vote up
def get_color_axis_z(context):
    color = context.preferences.themes[0].user_interface.axis_z
    return _color_to_list(color) 
Example #30
Source File: draw.py    From blender-power-sequencer with GNU General Public License v3.0 5 votes vote down vote up
def draw_rectangle(shader, origin, size, color=(1.0, 1.0, 1.0, 1.0)):
    vertices = (
        (origin.x, origin.y),
        (origin.x + size.x, origin.y),
        (origin.x, origin.y + size.y),
        (origin.x + size.x, origin.y + size.y),
    )
    indices = ((0, 1, 2), (2, 1, 3))
    batch = batch_for_shader(shader, "TRIS", {"pos": vertices}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader)