示例#1
0
    def draw_cb(self, widget, cairo_ctx):
        style = widget.get_style_context()
        bg_color = style.get_background_color(0)
        Gdk.cairo_set_source_rgba(cairo_ctx, bg_color)
        cairo_ctx.paint()

        return True
    def do_draw(self, cr):
        a = self.get_allocation()
        #state = self.get_state_flags()
        context = self.get_style_context()

        ds_h = self._dropshadow.get_height()
        y = (a.height - ds_h) / 2
        Gdk.cairo_set_source_pixbuf(cr, self._dropshadow, 0, y)
        cr.paint()

        # layout circle
        x = self._margin
        y = (a.height - ds_h) / 2 + self._margin
        w = a.width - 2 * self._margin
        h = a.width - 2 * self._margin
        cr.new_path()
        r = min(w, h) * 0.5
        x += int((w - 2 * r) / 2)
        y += int((h - 2 * r) / 2)
        from math import pi
        cr.arc(r + x, r + y, r, 0, 2 * pi)
        cr.close_path()

        if self.is_active:
            color = context.get_background_color(Gtk.StateFlags.SELECTED)
        else:
            color = context.get_background_color(Gtk.StateFlags.INSENSITIVE)

        Gdk.cairo_set_source_rgba(cr, color)
        cr.fill()

        for child in self:
            self.propagate_draw(child, cr)
示例#3
0
    def do_draw(self, cr):
        a = self.get_allocation()
        #state = self.get_state_flags()
        context = self.get_style_context()

        ds_h = self._dropshadow.get_height()
        y = (a.height - ds_h) / 2
        Gdk.cairo_set_source_pixbuf(cr, self._dropshadow, 0, y)
        cr.paint()

        # layout circle
        x = self._margin
        y = (a.height - ds_h) / 2 + self._margin
        w = a.width - 2 * self._margin
        h = a.width - 2 * self._margin
        cr.new_path()
        r = min(w, h) * 0.5
        x += int((w - 2 * r) / 2)
        y += int((h - 2 * r) / 2)
        from math import pi
        cr.arc(r + x, r + y, r, 0, 2 * pi)
        cr.close_path()

        if self.is_active:
            color = context.get_background_color(Gtk.StateFlags.SELECTED)
        else:
            color = context.get_background_color(Gtk.StateFlags.INSENSITIVE)

        Gdk.cairo_set_source_rgba(cr, color)
        cr.fill()

        for child in self:
            self.propagate_draw(child, cr)
示例#4
0
    def draw_chunks(
            self, context, background_area, cell_area, start, end, state):

        chunk = self._chunk
        if not chunk:
            return

        line = start.get_line()
        is_first_line = line == chunk[1]
        is_last_line = line == chunk[2] - 1
        if not (is_first_line or is_last_line):
            # Only paint for the first and last lines of a chunk
            return

        x = background_area.x - 1
        y = background_area.y
        width = background_area.width + 2
        height = 1 if chunk[1] == chunk[2] else background_area.height

        context.set_line_width(1.0)
        Gdk.cairo_set_source_rgba(context, self.line_colors[chunk[0]])
        if is_first_line:
            context.move_to(x, y + 0.5)
            context.rel_line_to(width, 0)
        if is_last_line:
            context.move_to(x, y - 0.5 + height)
            context.rel_line_to(width, 0)
        context.stroke()
    def render_grid(self, cr):
        context = self.get_style_context()
        context.save()
        context.add_class("grid-lines")
        bg = context.get_border_color(self.get_state_flags())
        context.restore()

        cr.save()

        Gdk.cairo_set_source_rgba(cr, bg)
        cr.set_line_width(1)

        a = self.get_allocation()
        w = a.width / self.n_columns

        for i in range(self.n_columns):
            cr.move_to(i * w + 0.5, 0)
            cr.rel_line_to(0, a.height - 3)
            cr.stroke()

        w = a.height / self.n_rows

        for i in range(self.n_rows):
            cr.move_to(2, i * w + 0.5)
            cr.rel_line_to(a.width - 4, 0)
            cr.stroke()

        cr.restore()
    def draw_chunks(self, context, background_area, cell_area, start, end,
                    state):

        chunk = self._chunk
        if not chunk:
            return

        line = start.get_line()
        is_first_line = line == chunk[1]
        is_last_line = line == chunk[2] - 1
        if not (is_first_line or is_last_line):
            # Only paint for the first and last lines of a chunk
            return

        x = background_area.x - 1
        y = background_area.y
        width = background_area.width + 2
        height = 1 if chunk[1] == chunk[2] else background_area.height

        context.set_line_width(1.0)
        Gdk.cairo_set_source_rgba(context, self.line_colors[chunk[0]])
        if is_first_line:
            context.move_to(x, y + 0.5)
            context.rel_line_to(width, 0)
        if is_last_line:
            context.move_to(x, y - 0.5 + height)
            context.rel_line_to(width, 0)
        context.stroke()
示例#7
0
    def render_grid(self, cr):
        context = self.get_style_context()
        context.save()
        context.add_class("grid-lines")
        bg = context.get_border_color(self.get_state_flags())
        context.restore()

        cr.save()

        Gdk.cairo_set_source_rgba(cr, bg)
        cr.set_line_width(1)

        a = self.get_allocation()
        w = a.width / self.n_columns

        for i in range(self.n_columns):
            cr.move_to(i * w + 0.5, 0)
            cr.rel_line_to(0, a.height - 3)
            cr.stroke()

        w = a.height / self.n_rows

        for i in range(self.n_rows):
            cr.move_to(2, i * w + 0.5)
            cr.rel_line_to(a.width - 4, 0)
            cr.stroke()

        cr.restore()
示例#8
0
    def draw_cb(self, widget, cairo_ctx):
        style = widget.get_style_context()
        bg_color = style.get_background_color(0)
        Gdk.cairo_set_source_rgba(cairo_ctx, bg_color)
        cairo_ctx.paint()

        return True
示例#9
0
def debug_set_color_rgba(cr, rgba):
    COLORS = ("red","green","blue","yellow","purple","wheat","maroon","gray")

    if DEBUG_COLORS:
        rgba = Gdk.RGBA()
        rgba.parse(COLORS[random.randint(0,len(COLORS)-1)])

    Gdk.cairo_set_source_rgba(cr, rgba)
示例#10
0
def debug_set_color_rgba(cr, rgba):
    COLORS = ("red", "green", "blue", "yellow", "purple", "wheat", "maroon",
              "gray")

    if DEBUG_COLORS:
        rgba = Gdk.RGBA()
        rgba.parse(COLORS[random.randint(0, len(COLORS) - 1)])

    Gdk.cairo_set_source_rgba(cr, rgba)
    def on_draw(self, widget, cr, *args, **kwargs):
        cr.save()
        if self.is_animating():
            # translate to the center, then set the rotation
            a = widget.get_allocation()
            cr.translate(a.width * 0.5, a.height * 0.5)
            cr.rotate(self.rotation)
            # pass on the translation details
            kwargs['xo'] = -(a.width * 0.5)
            kwargs['yo'] = -(a.height * 0.5)

        # do icon drawing
        SymbolicIcon.on_draw(self, widget, cr, *args, **kwargs)
        cr.restore()

        if not self.is_animating() or not self.transaction_count:
            return

        # paint transactions bubble

        # get the layout extents and calc the bubble size
        ex = self.layout.get_pixel_extents()[1]
        x = ((a.width - self.icon.get_width()) / 2 +
            self.icon.get_width() - ex.width + 2)
        y = ((a.height - self.icon.get_height()) / 2 +
            self.icon.get_height() - ex.height + 2)
        w = ex.width + 2 * self.BUBBLE_XPADDING
        h = ex.height + 2 * self.BUBBLE_YPADDING

        border_radius = w / 3
        if border_radius > self.BUBBLE_MAX_BORDER_RADIUS:
            border_radius = self.BUBBLE_MAX_BORDER_RADIUS

        # paint background
        context = widget.get_style_context()
        context.save()
        color = context.get_background_color(Gtk.StateFlags.SELECTED)
        rounded_rect(cr, x + 1, y + 1, w - 2, h - 2, border_radius)
        Gdk.cairo_set_source_rgba(cr, color)
        cr.fill()
        context.restore()

        # paint outline
        rounded_rect(cr, x + 1.5, y + 1.5, w - 3, h - 3, border_radius - 1)
        cr.set_source_rgb(1, 1, 1)
        cr.set_line_width(1)
        cr.stroke()

        # paint layout
        cr.save()
        cr.translate(x + (w - ex.width) * 0.5, y + (h - ex.height) * 0.5)
        cr.move_to(0, 1)
        PangoCairo.layout_path(cr, self.layout)
        cr.set_source_rgba(0, 0, 0, 0.6)
        cr.fill()
        Gtk.render_layout(context, cr, 0, 0, self.layout)
        cr.restore()
示例#12
0
    def on_view_draw_after(self, view, cr):
        window = view.get_window(Gtk.TextWindowType.TOP)

        if window is None or not Gtk.cairo_should_draw_window(cr, window):
            return False

        if not self._in_mode:
            return False

        layout = view.create_pango_layout(_('Multi Edit Mode'))
        extents = layout.get_pixel_extents()

        w = window.get_width()
        h = window.get_height()

        Gtk.cairo_transform_to_window(cr, view, window)

        cr.save()

        cr.translate(0.5, 0.5)
        cr.set_line_width(1)

        col = self.get_border_color()
        Gdk.cairo_set_source_rgba(cr, col)

        cr.move_to(0, h - 1)
        cr.rel_line_to(w, 0)
        cr.stroke()
        cr.restore()

        ctx = self.view.get_style_context()
        ctx.save()
        ctx.add_class('top')

        cr.save()
        Gtk.render_layout(ctx, cr, w - extents[1].width - 3,
                          (h - extents[1].height) / 2, layout)
        cr.restore()

        if not self._status:
            status = ''
        else:
            status = str(self._status)

        if status:
            layout.set_markup(status, -1)

            cr.save()
            Gtk.render_layout(ctx, cr, 3, (h - extents[1].height) / 2, layout)
            cr.restore()

        ctx.restore()

        return False
示例#13
0
文件: rulers.py 项目: Guff/sinister
 def draw_rule(self, cr):
     cr.save()
     
     horizontal = self.orientation == Gtk.Orientation.HORIZONTAL
     
     sc = self.get_style_context()
     alloc = self.get_allocation()
     
     orient, subdivs = self.orientation, self.subdivisions
     
     ruler_fg = sc.get_color(Gtk.StateFlags.NORMAL)
     Gdk.cairo_set_source_rgba(cr, ruler_fg)
     
     cr.set_line_width(1.0)
     
     if horizontal:
         span = alloc.width
     else:
         span = alloc.height
     
     # prevents a bit of code duplication
     flip_if_vertical = lambda x, y: (x, y) if horizontal else (y, x)
     
     for tick in range(0, span + 1, self.major_ticks_spacing):
         tick_start = flip_if_vertical(tick + 0.5, self.size)
         tick_end = flip_if_vertical(0, -(7 * self.size) // 9 - 0.5)
         
         cr.move_to(*tick_start)
         cr.rel_line_to(*tick_end)
         
         for subtick in range(1, subdivs):
             spacing = (subtick * self.major_ticks_spacing) // subdivs
             
             if subdivs % 2 == 0 and subtick == subdivs // 2:
                 subtick_size = self.size // 2
             else:
                 subtick_size = self.size // 4
             
             subtick_start = flip_if_vertical(tick + spacing + 0.5, self.size)
             subtick_end = flip_if_vertical(0, -subtick_size - 0.5)
             
             cr.move_to(*subtick_start)
             cr.rel_line_to(*subtick_end)
         
     cr.stroke()
     
     end = alloc.width if horizontal else alloc.height
     coords_start = flip_if_vertical(0, self.size - 1)
     coords_end = flip_if_vertical(end, self.size - 1)
     
     Gtk.render_line(sc, cr, *(coords_start + coords_end))
     
     cr.restore()
示例#14
0
 def onWindowDraw(self, widget, cr):
     if self.usecustomcolor:
         borderColor = Gdk.RGBA()
         borderColor.parse(self.custombordercolor)
         Gdk.cairo_set_source_rgba(cr, borderColor)
         cr.paint()
     else:
         style = widget.get_style_context()
         req = widget.get_preferred_size()[0]
         Gtk.render_background(style, cr, 0, 0, req.width, req.height)
         Gtk.render_frame(style, cr, 0, 0, req.width, req.height)
     return False
    def on_view_draw_after(self, view, cr):
        window = view.get_window(Gtk.TextWindowType.TOP)

        if window is None or not Gtk.cairo_should_draw_window(cr, window):
            return False

        if not self._in_mode:
            return False

        layout = view.create_pango_layout(_('Multi Edit Mode'))
        extents = layout.get_pixel_extents()

        w = window.get_width()
        h = window.get_height()

        Gtk.cairo_transform_to_window(cr, view, window)

        cr.save()

        cr.translate(0.5, 0.5)
        cr.set_line_width(1)

        col = self.get_border_color()
        Gdk.cairo_set_source_rgba(cr, col)

        cr.move_to(0, h - 1)
        cr.rel_line_to(w, 0)
        cr.stroke()
        cr.restore()

        ctx = self.view.get_style_context()
        ctx.save()
        ctx.add_class('top')

        cr.save()
        Gtk.render_layout(ctx, cr, w - extents[1].width - 3, (h - extents[1].height) / 2, layout)
        cr.restore()

        if not self._status:
            status = ''
        else:
            status = str(self._status)

        if status:
            layout.set_markup(status, -1)

            cr.save()
            Gtk.render_layout(ctx, cr, 3, (h - extents[1].height) / 2, layout)
            cr.restore()

        ctx.restore()

        return False
示例#16
0
    def on_draw(self, widget, cr):
        ctx = widget.get_style_context()
        alloc = self.get_allocation()

        padding = ctx.get_padding(Gtk.StateFlags.NORMAL)
        border = ctx.get_border(Gtk.StateFlags.NORMAL)

        x = padding.left + border.left
        y = padding.top + border.top
        width = alloc.width - padding.left - padding.right - border.left - border.right
        height = alloc.height - padding.top - padding.bottom - border.top - border.bottom
        floor = y + height
        end = x + width
        value = round(self.get_value())
        value_x = x + ((value / 100) * width)
        value_y = floor - ((value / 100) * height)

        if self.muted:
            fill_color = ctx.get_color(Gtk.StateFlags.INSENSITIVE)
            bg_color = ctx.get_background_color(Gtk.StateFlags.INSENSITIVE)
        else:
            fill_color = ctx.get_color(Gtk.StateFlags.NORMAL)
            bg_color = ctx.get_background_color(Gtk.StateFlags.NORMAL)

        cr.save()

        cr.new_sub_path()
        cr.move_to(x, floor)
        cr.line_to(end, floor)
        cr.line_to(end, y)
        cr.close_path()

        Gdk.cairo_set_source_rgba(cr, bg_color)
        cr.fill()

        cr.restore()
        cr.save()

        cr.new_sub_path()
        cr.move_to(x, floor)
        cr.line_to(value_x, floor)
        cr.line_to(value_x, value_y)
        cr.close_path()

        Gdk.cairo_set_source_rgba(cr, fill_color)
        cr.fill()

        cr.restore()

        return True
示例#17
0
    def draw_cb(self, widget, cr):
        rect = widget.get_allocation()

        cr.set_operator(cairo.OPERATOR_SOURCE)
        #cr.set_source_rgba(1.0, 1.0, 1.0, 0.0)
        context = self.get_toplevel().get_style_context()
        bg_colour = context.get_background_color(Gtk.StateFlags.NORMAL)
        Gdk.cairo_set_source_rgba(cr, bg_colour)
        cr.rectangle(0, 0, rect.width, rect.height)
        cr.fill()

        cr.set_operator(cairo.OPERATOR_OVER)
        self.draw_spectrum(cr)
        return True
    def do_draw(self, cr, bg_area, cell_area, start, end, state):
        GtkSource.GutterRenderer.do_draw(self, cr, bg_area, cell_area,
                                         start, end, state)

        line_context = self.file_context.get(start.get_line() + 1, None)
        if line_context is None or line_context.line_type == DiffType.NONE:
            return

        background = self.backgrounds[line_context.line_type]

        Gdk.cairo_set_source_rgba(cr, background)
        cr.rectangle(cell_area.x, cell_area.y,
                     cell_area.width, cell_area.height)
        cr.fill()
示例#19
0
    def do_draw(self, cr, bg_area, cell_area, start, end, state):
        GtkSource.GutterRenderer.do_draw(self, cr, bg_area, cell_area, start,
                                         end, state)

        line_context = self.file_context.get(start.get_line() + 1, None)
        if line_context is None or line_context.line_type == DiffType.NONE:
            return

        background = self.backgrounds[line_context.line_type]

        Gdk.cairo_set_source_rgba(cr, background)
        cr.rectangle(cell_area.x, cell_area.y, cell_area.width,
                     cell_area.height)
        cr.fill()
    def on_draw(self, widget, cr):
        ctx = widget.get_style_context()
        alloc = self.get_allocation()

        padding = ctx.get_padding(Gtk.StateFlags.NORMAL)
        border = ctx.get_border(Gtk.StateFlags.NORMAL)

        x = padding.left + border.left
        y = padding.top + border.top
        width = alloc.width - padding.left - padding.right - border.left - border.right
        height = alloc.height - padding.top - padding.bottom - border.top - border.bottom
        floor = y + height
        end = x + width
        value = round(self.get_value())
        value_x = x + ((value / 100) * width)
        value_y = floor - ((value / 100) * height)

        if self.muted:
            fill_color = ctx.get_color(Gtk.StateFlags.INSENSITIVE)
            bg_color = ctx.get_background_color(Gtk.StateFlags.INSENSITIVE)
        else:
            fill_color = ctx.get_color(Gtk.StateFlags.NORMAL)
            bg_color = ctx.get_background_color(Gtk.StateFlags.NORMAL)

        cr.save()

        cr.new_sub_path()
        cr.move_to(x, floor)
        cr.line_to(end, floor)
        cr.line_to(end, y)
        cr.close_path()

        Gdk.cairo_set_source_rgba(cr, bg_color)
        cr.fill()

        cr.restore()
        cr.save()

        cr.new_sub_path()
        cr.move_to(x, floor)
        cr.line_to(value_x, floor)
        cr.line_to(value_x, value_y)
        cr.close_path()

        Gdk.cairo_set_source_rgba(cr, fill_color)
        cr.fill()

        cr.restore()

        return True
示例#21
0
    def draw_cb(self, widget, cr):
        rect = widget.get_allocation()

        cr.set_operator(cairo.OPERATOR_SOURCE)
        #cr.set_source_rgba(1.0, 1.0, 1.0, 0.0)
        context = self.get_toplevel().get_style_context()
        bg_colour = context.get_background_color(Gtk.StateFlags.NORMAL)
        Gdk.cairo_set_source_rgba(cr, bg_colour)
        cr.rectangle(0, 0, rect.width, rect.height)
        cr.fill()

        cr.set_operator(cairo.OPERATOR_OVER)
        self.draw_spectrum(cr)
        return True
示例#22
0
    def _draw_column_mode(self, cr):
        if not self._column_mode:
            return False

        start = self._column_mode[0]
        end = self._column_mode[1]
        buf = self._buffer

        layout = self.view.create_pango_layout('W')
        width = layout.get_pixel_extents()[1].width

        context = self.view.get_style_context()
        context.save()
        context.add_class('view')
        col = context.get_background_color(Gtk.StateFlags.SELECTED)
        context.restore()

        Gdk.cairo_set_source_rgba(cr, col)

        cstart = self._column_mode[2]
        cend = self._column_mode[3]

        while start <= end:
            # Get the line range, convert to window coords, and see if it needs
            # rendering
            piter = buf.get_iter_at_line(start)
            y, height = self.view.get_line_yrange(piter)

            x_, y = self.view.buffer_to_window_coords(Gtk.TextWindowType.TEXT,
                                                      0, y)
            start += 1

            # Check where to possible draw fake selection
            start_iter, soff = self.get_visible_iter(start - 1, cstart)
            end_iter, eoff = self.get_visible_iter(start - 1, cend)

            if soff == 0 and eoff == 0 and not start_iter.equal(end_iter):
                continue

            rx = cstart * width + self.view.get_left_margin()
            rw = (cend - cstart) * width

            if rw == 0:
                rw = 1

            cr.rectangle(rx, y, rw, height)
            cr.fill()

        return False
示例#23
0
    def on_view_draw(self, view, cr):
        window = view.get_window(Gtk.TextWindowType.TEXT)

        if Gtk.cairo_should_draw_window (cr, window):
            return self._draw_column_mode(cr)

        window = view.get_window(Gtk.TextWindowType.TOP)

        if window is None or not Gtk.cairo_should_draw_window (cr, window):
            return False

        if not self._in_mode:
            return False

        layout = view.create_pango_layout(_('Multi Edit Mode'))
        extents = layout.get_pixel_extents()

        w = window.get_width()
        h = window.get_height()

        Gtk.cairo_transform_to_window(cr, view, window)

        cr.translate(0.5, 0.5)
        cr.set_line_width(1)

        col = self.get_border_color()
        Gdk.cairo_set_source_rgba(cr, col)

        cr.move_to(0, h - 1)
        cr.rel_line_to(w, 0)
        cr.stroke()

        context = self._view.get_style_context()
        Gdk.cairo_set_source_rgba(cr, context.get_color(Gtk.StateFlags.NORMAL))
        cr.move_to(w - extents[1].width - 3, (h - extents[1].height) / 2)
        PangoCairo.show_layout(cr, layout)

        if not self._status:
            status = ''
        else:
            status = str(self._status)

        if status:
            layout.set_markup(status, -1)

            cr.move_to(3, (h - extents[1].height) / 2)
            PangoCairo.show_layout(cr, layout)

        return False
示例#24
0
    def on_view_draw(self, view, cr):
        window = view.get_window(Gtk.TextWindowType.TEXT)

        if Gtk.cairo_should_draw_window(cr, window):
            return self._draw_column_mode(cr)

        window = view.get_window(Gtk.TextWindowType.TOP)

        if window is None or not Gtk.cairo_should_draw_window(cr, window):
            return False

        if not self._in_mode:
            return False

        layout = view.create_pango_layout(_('Multi Edit Mode'))
        extents = layout.get_pixel_extents()

        w = window.get_width()
        h = window.get_height()

        Gtk.cairo_transform_to_window(cr, view, window)

        cr.translate(0.5, 0.5)
        cr.set_line_width(1)

        col = self.get_border_color()
        Gdk.cairo_set_source_rgba(cr, col)

        cr.move_to(0, h - 1)
        cr.rel_line_to(w, 0)
        cr.stroke()

        context = self._view.get_style_context()
        Gdk.cairo_set_source_rgba(cr, context.get_color(Gtk.StateFlags.NORMAL))
        cr.move_to(w - extents[1].width - 3, (h - extents[1].height) / 2)
        PangoCairo.show_layout(cr, layout)

        if not self._status:
            status = ''
        else:
            status = str(self._status)

        if status:
            layout.set_markup(status, -1)

            cr.move_to(3, (h - extents[1].height) / 2)
            PangoCairo.show_layout(cr, layout)

        return False
示例#25
0
 def _draw_bg_cb(self, view, cr, drawstate):
     """ Renders a background in a ImageView """
     use_custom_color, color, checkered, = self.get_properties(
         "use-custom-color", "color", "checkered"
     )
     if use_custom_color:
         Gdk.cairo_set_source_rgba(cr, color)
         cr.paint()
         
     if checkered:
         if self._obsolete_checkered_pattern:
             self._create_checkered_pattern()
         
         cr.set_source(self._checkered_pattern)
         cr.paint()
    def _draw_column_mode(self, cr):
        if not self._column_mode:
            return False

        start = self._column_mode[0]
        end = self._column_mode[1]
        buf = self._buffer

        layout = self.view.create_pango_layout('W')
        width = layout.get_pixel_extents()[1].width

        context = self.view.get_style_context()
        context.save()
        context.add_class('view')
        col = context.get_background_color(Gtk.StateFlags.SELECTED)
        context.restore()

        Gdk.cairo_set_source_rgba(cr, col)

        cstart = self._column_mode[2]
        cend = self._column_mode[3]

        while start <= end:
            # Get the line range, convert to window coords, and see if it needs
            # rendering
            piter = buf.get_iter_at_line(start)
            y, height = self.view.get_line_yrange(piter)

            x_, y = self.view.buffer_to_window_coords(Gtk.TextWindowType.TEXT, 0, y)
            start += 1

            # Check where to possible draw fake selection
            start_iter, soff = self.get_visible_iter(start - 1, cstart)
            end_iter, eoff = self.get_visible_iter(start - 1, cend)

            if soff == 0 and eoff == 0 and not start_iter.equal(end_iter):
                continue

            rx = cstart * width + self.view.get_left_margin()
            rw = (cend - cstart) * width

            if rw == 0:
                rw = 1

            cr.rectangle(rx, y, rw, height)
            cr.fill()

        return False
    def do_draw(self, cr):
        context = self.get_style_context()
        bc = context.get_border_color(self.get_state_flags())

        cr.save()
        Gdk.cairo_set_source_rgba(cr, bc)

        width = self.get_property("height-request")

        a = self.get_allocation()
        cr.move_to(0, 0)
        cr.rel_line_to(a.width, 0)
        cr.set_dash((width, 2 * width), 0)
        cr.set_line_width(2 * width)
        cr.stroke()
        cr.restore()
示例#28
0
    def __draw(self, cr):
        """Draws the widget"""
        alloc = self.get_allocation()
        #FIXME - why to use a special variables?
        alloc_w, alloc_h = alloc.width, alloc.height
        # Drawing context
        #cr_ctxt    = self.window.cairo_create() # pylint: disable-msg=E1101
        #gdkcontext = Gdk.CairoContext(cr_ctxt)
        #FIXME
        gdkcontext = cr

        # Draw rectangle
        if self.color is not None:
            my_color = Gdk.color_parse(self.color)
            Gdk.cairo_set_source_color(gdkcontext, my_color)
        else:
            Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0))
        gdkcontext.rectangle(0, 0, alloc_w, alloc_h)
        gdkcontext.fill()

        # Outer line
        Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.30))
        gdkcontext.set_line_width(2.0)
        gdkcontext.rectangle(0, 0, alloc_w, alloc_h)
        gdkcontext.stroke()

          # If selected draw a symbol
        if(self.selected):
            size = alloc_h * 0.50 - 3
            pos_x = math.floor((alloc_w - size) / 2)
            pos_y = math.floor((alloc_h - size) / 2)
            Gdk.cairo_set_source_rgba(gdkcontext,
                                      Gdk.RGBA(255, 255, 255, 0.80))
            gdkcontext.arc(
                alloc_w / 2, alloc_h / 2, size / 2 + 3, 0, 2 * math.pi)
            gdkcontext.fill()
            gdkcontext.set_line_width(1.0)
            Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.20))
            gdkcontext.arc(
                alloc_w / 2, alloc_h / 2, size / 2 + 3, 0, 2 * math.pi)
            gdkcontext.stroke()
            Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.50))
            gdkcontext.set_line_width(3.0)
            gdkcontext.move_to(pos_x, pos_y + size / 2)
            gdkcontext.line_to(pos_x + size / 2, pos_y + size)
            gdkcontext.line_to(pos_x + size, pos_y)
            gdkcontext.stroke()
示例#29
0
    def __draw(self, cr):
        """Draws the widget"""
        alloc = self.get_allocation()
        # FIXME - why to use a special variables?
        alloc_w, alloc_h = alloc.width, alloc.height
        # Drawing context
        # cr_ctxt    = Gdk.cairo_create(self.window)
        # gdkcontext = Gdk.CairoContext(cr_ctxt)
        # FIXME
        gdkcontext = cr

        # Draw rectangle
        if self.color is not None:
            my_color = Gdk.color_parse(self.color)
            Gdk.cairo_set_source_color(gdkcontext, my_color)
        else:
            Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0))
        gdkcontext.rectangle(0, 0, alloc_w, alloc_h)
        gdkcontext.fill()

        # Outer line
        Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.30))
        gdkcontext.set_line_width(2.0)
        gdkcontext.rectangle(0, 0, alloc_w, alloc_h)
        gdkcontext.stroke()

        # If selected draw a symbol
        if (self.selected):
            size = alloc_h * 0.50 - 3
            pos_x = math.floor((alloc_w - size) / 2)
            pos_y = math.floor((alloc_h - size) / 2)
            Gdk.cairo_set_source_rgba(gdkcontext,
                                      Gdk.RGBA(255, 255, 255, 0.80))
            gdkcontext.arc(alloc_w / 2, alloc_h / 2, size / 2 + 3, 0,
                           2 * math.pi)
            gdkcontext.fill()
            gdkcontext.set_line_width(1.0)
            Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.20))
            gdkcontext.arc(alloc_w / 2, alloc_h / 2, size / 2 + 3, 0,
                           2 * math.pi)
            gdkcontext.stroke()
            Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.50))
            gdkcontext.set_line_width(3.0)
            gdkcontext.move_to(pos_x, pos_y + size / 2)
            gdkcontext.line_to(pos_x + size / 2, pos_y + size)
            gdkcontext.line_to(pos_x + size, pos_y)
            gdkcontext.stroke()
    def on_draw(self, widget, cr, drop_shadow, icon, ds_xo, ds_yo, xo=0, yo=0):
        a = widget.get_allocation()

        # dropshadow
        x = (a.width - drop_shadow.get_width()) * 0.5 + ds_xo + xo
        y = (a.height - drop_shadow.get_height()) * 0.5 + ds_yo + yo
        cr.set_source_surface(drop_shadow, int(x), int(y))
        cr.paint_with_alpha(0.4)

        # colorised icon
        state = widget.get_state_flags()
        context = widget.get_style_context()
        color = context.get_color(state)
        Gdk.cairo_set_source_rgba(cr, color)
        x = (a.width - icon.get_width()) * 0.5 + xo
        y = (a.height - icon.get_height()) * 0.5 + yo
        cr.mask_surface(icon, int(x), int(y))
    def do_render(self, cr, treeview, background_area, cell_area, flags):
        context = Gtk.Widget.get_style_context(treeview)
        Gtk.render_background(context, cr, cell_area.x, cell_area.y,
                              cell_area.x + cell_area.width,
                              cell_area.y + cell_area.height)

        scaled = self.icon.scale_simple(self.size, self.size,
                                        GdkPixbuf.InterpType.BILINEAR)
        surf = Gdk.cairo_surface_create_from_pixbuf(scaled, 1)
        if self.has_colors:
            cr.set_source_surface(surf, cell_area.x, cell_area.y)
            cr.rectangle(cell_area.x, cell_area.y, self.size, self.size)
        else:
            color_flags = Gtk.StateFlags.NORMAL
            if (flags & Gtk.CellRendererState.SELECTED) != 0:
                color_flags = Gtk.StateFlags.SELECTED
            Gdk.cairo_set_source_rgba(cr, context.get_color(color_flags))
            cr.mask_surface(surf, cell_area.x, cell_area.y)
        cr.fill()
示例#32
0
    def render_grid(self, cr):
        context = self.get_style_context()
        context.save()
        context.add_class("grid-lines")
        bg = context.get_border_color(self.get_state_flags())
        context.restore()

        cr.save()
        a = self.get_allocation()
        rounded_rect(cr, 0, 0, a.width, a.height-1, Frame.BORDER_RADIUS)
        cr.clip()

        Gdk.cairo_set_source_rgba(cr, bg)
        cr.set_line_width(1)

        cell_w = a.width / self.n_columns
        cell_h = self.get_cell_size()[1]

        for i in range(self.n_columns):
            for j in range(self.n_rows):
                # paint checker if need be
                #~ if not (i + j%2)%2:
                    #~ cr.save()
                    #~ cr.set_source_rgba(0.976470588, 0.956862745, 0.960784314, 0.85) #F9F4F5
                    #~ cr.rectangle(i*cell_w, j*cell_h, cell_w, cell_h)
                    #~ cr.fill()
                    #~ cr.restore()

                # paint rows
                if not j: continue
                cr.move_to(0, j*cell_h + 0.5)
                cr.rel_line_to(a.width-1, 0)
                cr.stroke()

            # paint columns
            if not i: continue
            cr.move_to(i*cell_w + 0.5, 0)
            cr.rel_line_to(0, a.height-1)
            cr.stroke()

        cr.restore()
        return
示例#33
0
文件: document.py 项目: lucabi/gedit
        def draw_placeholder(self, ctx, placeholder):
                if isinstance(placeholder, PlaceholderEnd):
                        return

                col = self.view.get_style_context().get_color(Gtk.StateFlags.INSENSITIVE)
                col.alpha = 0.5
                Gdk.cairo_set_source_rgba(ctx, col)

                if placeholder.tabstop > 0:
                        ctx.set_dash([], 0)
                else:
                        ctx.set_dash([2], 0)

                start = placeholder.begin_iter()
                end = placeholder.end_iter()

                if start.equal(end):
                        self.draw_placeholder_bar(ctx, placeholder)
                else:
                        self.draw_placeholder_rect(ctx, placeholder)
示例#34
0
    def draw_placeholder(self, ctx, placeholder):
        if isinstance(placeholder, PlaceholderEnd):
            return

        col = self.view.get_style_context().get_color(Gtk.StateFlags.INSENSITIVE)
        col.alpha = 0.5
        Gdk.cairo_set_source_rgba(ctx, col)

        if placeholder.tabstop > 0:
            ctx.set_dash([], 0)
        else:
            ctx.set_dash([2], 0)

        start = placeholder.begin_iter()
        end = placeholder.end_iter()

        if start.equal(end):
            self.draw_placeholder_bar(ctx, placeholder)
        else:
            self.draw_placeholder_rect(ctx, placeholder)
示例#35
0
 def _create_checkered_pattern(self):
     """ Creates the checkered background pattern """
     checks_size = self.checks_size
     checkered_surface = cairo.ImageSurface(
         cairo.FORMAT_RGB24, checks_size * 2, checks_size * 2
     )
     cr = cairo.Context(checkered_surface)
     
     Gdk.cairo_set_source_rgba(cr, self.checks_primary_color)
     cr.rectangle(0, 0, checks_size, checks_size)
     cr.rectangle(checks_size, checks_size, checks_size, checks_size)
     cr.fill()
     
     Gdk.cairo_set_source_rgba(cr, self.checks_secondary_color)
     cr.rectangle(checks_size, 0, checks_size, checks_size)
     cr.rectangle(0, checks_size, checks_size, checks_size)
     cr.fill()
     
     self._checkered_pattern = cairo.SurfacePattern(checkered_surface)
     self._checkered_pattern.set_extend(cairo.EXTEND_REPEAT)
     self._checkered_pattern.set_filter(cairo.FILTER_NEAREST)
示例#36
0
 def do_draw(self, cr):
     allocation = self.get_allocation()
     if allocation.width >= allocation.height:
         context = Gtk.Widget.get_style_context(self)
         Gtk.render_background(context, cr, 0, 0, allocation.width,
                               allocation.height)
         if self.pb is None:
             # No icon set
             return
         scaled = self.pb.scale_simple(allocation.height, allocation.height,
                                       GdkPixbuf.InterpType.BILINEAR)
         surf = Gdk.cairo_surface_create_from_pixbuf(scaled, 1)
         if self.has_colors:
             cr.set_source_surface(surf, 1.0, 1.0)
             #allocation.height, allocation.height)
             cr.rectangle(0, 0, allocation.height, allocation.height)
         else:
             Gdk.cairo_set_source_rgba(
                 cr, context.get_color(Gtk.StateFlags.NORMAL))
             cr.mask_surface(surf, 0, 0)
         cr.fill()
示例#37
0
    def render_labels(self, cr):
        if len(self.segments) == 0:
            return
        box_stroke_color = Gdk.RGBA(0, 0, 0, 0.6)
        x = 0
        layout = self.create_pango_layout('')

        for segment in self.segments:
            cr.set_line_width(1)
            cr.rectangle(x + 0.5, 2 + 0.5, self.segment_box_size - 1,
                         self.segment_box_size - 1)
            grad = self.make_segment_gradient(self.segment_box_size,
                                              segment.color)
            cr.set_source(grad)
            cr.fill_preserve()
            Gdk.cairo_set_source_rgba(cr, box_stroke_color)
            cr.stroke()

            x = x + self.segment_box_size + self.segment_box_spacing

            layout.set_markup('<b>%s</b>' % segment.title, -1)
            (lw, lh) = layout.get_pixel_size()

            cr.move_to(x, 0)
            Gdk.cairo_set_source_rgba(cr, self.text_color)
            PangoCairo.show_layout(cr, layout)
            cr.fill()

            layout.set_markup('<small>%s</small>' % segment.subtitle, -1)

            cr.move_to(x, lh)
            Gdk.cairo_set_source_rgba(cr, self.subtext_color)
            PangoCairo.show_layout(cr, layout)
            cr.fill()
            x = x + segment.layout_width + self.segment_label_spacing
示例#38
0
    def do_draw(self, cr):
        a = self.get_allocation()
        #state = self.get_state_flags()
        context = self.get_style_context()

        ds_h = self._dropshadow.get_height()
        y = (a.height - ds_h) / 2
        Gdk.cairo_set_source_pixbuf(cr, self._dropshadow, 0, y)
        cr.paint()
        Circle.layout(cr, self._margin, (a.height - ds_h) / 2 + self._margin,
                      a.width - 2 * self._margin,
                      a.width - 2 * self._margin)
        if self.is_active:
            color = context.get_background_color(Gtk.StateFlags.SELECTED)
        else:
            color = context.get_background_color(Gtk.StateFlags.INSENSITIVE)

        Gdk.cairo_set_source_rgba(cr, color)
        cr.fill()

        for child in self:
            self.propagate_draw(child, cr)
    def get_text_pixbuf(self, text, widget):
        v, w, h = Gtk.icon_size_lookup(Gtk.IconSize.MENU)

        surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
        cr = cairo.Context(surf)

        cr.set_source_rgba(0, 0, 0, 0)
        cr.fill()

        font_size = 10.0

        cr.move_to(0, h - ((h - font_size) / 2))

        rgba = widget.get_style_context().get_color(Gtk.StateFlags.NORMAL)
        Gdk.cairo_set_source_rgba(cr, rgba)

        cr.show_text(text.upper()[:2])

        final_surf = cr.get_target()
        pixbuf = Gdk.pixbuf_get_from_surface(final_surf, 0, 0, w, h)

        return pixbuf
示例#40
0
    def draw(self, another_self, cr):
        resolution = self._detector.get_resolution()
        # hilights = [ [0] * resolution for x in xrange(0, resolution) ]

        # Background
        Gdk.cairo_set_source_rgba(cr, self.colors['background'])
        cr.rectangle(0, 0, self._size, self._size)
        cr.fill()

        # Hilighted boxes
        # Iterates over gesture in progress hilighting apripriate boxes,
        # so user can see what's he doing.
        box_width = float(self._size) / float(resolution)
        col = self.colors['hilight']
        alpha = col.alpha
        alpha_fallout = alpha * 0.5 / self.MAX_STEPS
        step = 0
        for x, y in reversed(self._detector.get_positions()):
            if step > self.MAX_STEPS:
                break
            col.alpha = alpha - alpha_fallout * step
            Gdk.cairo_set_source_rgba(cr, col)
            cr.rectangle(box_width * x, box_width * y, box_width, box_width)
            cr.fill()
            step += 1
        col.alpha = alpha

        # Grid
        Gdk.cairo_set_source_rgba(cr, self.colors['grid'])
        for i in xrange(1, resolution):
            cr.move_to(i * box_width, self.GRID_PAD)
            cr.line_to(i * box_width, self._size - self.GRID_PAD)
            cr.stroke()
            cr.move_to(self.GRID_PAD, i * box_width)
            cr.line_to(self._size - self.GRID_PAD, i * box_width)
            cr.stroke()

        # Line
        Gdk.cairo_set_source_rgba(cr, self.colors['line'])
        drawing = False
        for x, y in self._points:
            if drawing:
                cr.line_to(x, y)
            else:
                cr.move_to(x, y)
                drawing = True
        if drawing:
            cr.stroke()
示例#41
0
	def draw(self, another_self, cr):
		resolution = self._detector.get_resolution()
		# hilights = [ [0] * resolution for x in xrange(0, resolution) ]

		# Background
		Gdk.cairo_set_source_rgba(cr, self.colors['background'])
		cr.rectangle(0, 0, self._size, self._size)
		cr.fill()
		
		# Hilighted boxes
		# Iterates over gesture in progress hilighting apripriate boxes,
		# so user can see what's he doing.
		box_width = float(self._size) / float(resolution)
		col = self.colors['hilight']
		alpha = col.alpha
		alpha_fallout = alpha * 0.5 / self.MAX_STEPS
		step = 0
		for x, y in reversed(self._detector.get_positions()):
			if step > self.MAX_STEPS:
				break
			col.alpha = alpha - alpha_fallout * step
			Gdk.cairo_set_source_rgba(cr, col)
			cr.rectangle(box_width * x, box_width * y, box_width, box_width)
			cr.fill()
			step += 1
		col.alpha = alpha
		
		# Grid
		Gdk.cairo_set_source_rgba(cr, self.colors['grid'])
		for i in xrange(1, resolution):
			cr.move_to(i * box_width, self.GRID_PAD)
			cr.line_to(i * box_width, self._size - self.GRID_PAD)
			cr.stroke()
			cr.move_to(self.GRID_PAD, i * box_width)
			cr.line_to(self._size - self.GRID_PAD, i * box_width)
			cr.stroke()
		
		# Line
		Gdk.cairo_set_source_rgba(cr, self.colors['line'])
		drawing = False
		for x, y in self._points:
			if drawing:
				cr.line_to(x, y)
			else:
				cr.move_to(x, y)
				drawing = True
		if drawing:
			cr.stroke()
示例#42
0
	def do_render(self, cr, treeview, background_area, cell_area, flags):
		context = Gtk.Widget.get_style_context(treeview)
		Gtk.render_background(context, cr,
				cell_area.x, cell_area.y,
				cell_area.x + cell_area.width,
				cell_area.y + cell_area.height
		)
		
		scaled = self.icon.scale_simple(
				self.size, self.size,
				GdkPixbuf.InterpType.BILINEAR
		)
		surf = Gdk.cairo_surface_create_from_pixbuf(scaled, 1)
		if self.has_colors:
			cr.set_source_surface(surf, cell_area.x, cell_area.y)
			cr.rectangle(cell_area.x, cell_area.y, self.size, self.size)
		else:
			color_flags = Gtk.StateFlags.NORMAL
			if (flags & Gtk.CellRendererState.SELECTED) != 0:
				color_flags = Gtk.StateFlags.SELECTED
			Gdk.cairo_set_source_rgba(cr, context.get_color(color_flags))
			cr.mask_surface(surf, cell_area.x, cell_area.y)
		cr.fill()
示例#43
0
文件: plotters.py 项目: Guff/sinister
 def plot(self, cr):
     width, height = self.dimensions
     
     x0, y0, x1, y1 = cr.clip_extents()
     
     cr.save()
     cr.set_operator(cairo.OPERATOR_OVER)
     
     for window_x in range(int(x0), int(x1) + 2):
         window_y = self(window_x)
         if window_y is None:
             continue
         
         if window_y < -2 * height or window_y > 2 * height:
             cr.new_sub_path()
         else:
             cr.line_to(window_x, window_y)
     
     cr.set_line_width(1.0)
     Gdk.cairo_set_source_rgba(cr, self.rgba)
     cr.stroke()
     
     cr.restore()
示例#44
0
    def do_draw(self, cr):
        a = self.get_allocation()
        #state = self.get_state_flags()
        context = self.get_style_context()

        ds_h = self._dropshadow.get_height()
        y = (a.height - ds_h) / 2
        Gdk.cairo_set_source_pixbuf(cr, self._dropshadow, 0, y)
        cr.paint()
        Circle.layout(cr, self._margin, (a.height-ds_h)/2 + self._margin,
                      a.width-2*self._margin,
                      a.width-2*self._margin)
        if self.is_active:
            color = context.get_background_color(Gtk.StateFlags.SELECTED)
        else:
            color = context.get_background_color(Gtk.StateFlags.INSENSITIVE)

        Gdk.cairo_set_source_rgba(cr, color)
        cr.fill()

        for child in self: 
            self.propagate_draw(child, cr)
        return
示例#45
0
	def do_draw(self, cr):
		allocation = self.get_allocation()
		if allocation.width >= allocation.height:
			context = Gtk.Widget.get_style_context(self)
			Gtk.render_background(context, cr, 0, 0,
					allocation.width, allocation.height)
			if self.pb is None:
				# No icon set
				return
			scaled = self.pb.scale_simple(
				allocation.height, allocation.height,
				GdkPixbuf.InterpType.BILINEAR
			)
			surf = Gdk.cairo_surface_create_from_pixbuf(scaled, 1)
			if self.has_colors:
				cr.set_source_surface(surf, 1.0, 1.0)
						#allocation.height, allocation.height)
				cr.rectangle(0, 0, allocation.height, allocation.height)
			else:
				Gdk.cairo_set_source_rgba(cr,
						context.get_color(Gtk.StateFlags.NORMAL))
				cr.mask_surface(surf, 0, 0)
			cr.fill()
示例#46
0
    def snapshot(self,
                 snapshot: Gtk.Snapshot,
                 bounds: Graphene.Rect,
                 fgcolor: Gdk.RGBA, scale: float):
        if (self._cached_texture_scale < scale
                or not self._fgcolor.equal(fgcolor)):
            PangoCairo.context_set_resolution(
                _text_texture_pango_ctx, 96 * scale)
            layout = Pango.Layout.new(_text_texture_pango_ctx)
            layout.set_text(self._text)
            layout.set_font_description(FONT_NORMAL)
            layout_width, layout_height = layout.get_pixel_size()

            scaled_w = int(WIDTH * scale)
            scaled_h = int(HEIGHT * scale)

            cr = cairo.ImageSurface(
                cairo.Format.ARGB32,
                scaled_w, scaled_h)
            ctx = cairo.Context(cr)
            Gdk.cairo_set_source_rgba(ctx, fgcolor)

            x = int(scaled_w / 2 - layout_width / 2)
            y = int(scaled_h / 2 - layout_height / 2)
            ctx.move_to(x, y)

            PangoCairo.show_layout(ctx, layout)

            pixbuf = Gdk.pixbuf_get_from_surface(
                cr, 0, 0, scaled_w, scaled_h)

            del self._cached_texture
            self._cached_texture = Gdk.Texture.new_for_pixbuf(pixbuf)
            self._cached_texture_scale = scale
            self._fgcolor = fgcolor

        snapshot.append_texture(self._cached_texture, bounds)
示例#47
0
    def on_draw(self, widget, cr):
        ctx = widget.get_style_context()
        alloc = self.get_allocation()

        padding = ctx.get_padding(Gtk.StateFlags.NORMAL)
        border = ctx.get_border(Gtk.StateFlags.NORMAL)

        x = padding.left + border.left
        y = padding.top + border.top
        width = alloc.width - padding.left - padding.right - border.left - border.right
        height = alloc.height - padding.top - padding.bottom - border.top - border.bottom
        floor = y + height
        end = x + width
        value = self.get_fraction()
        value_width = value * width

        fill_color = ctx.get_color(Gtk.StateFlags.NORMAL)
        bg_color = ctx.get_background_color(Gtk.StateFlags.NORMAL)

        cr.save()

        cr.new_sub_path()
        cr.rectangle(x, y, end, floor)
        Gdk.cairo_set_source_rgba(cr, bg_color)
        cr.fill()

        cr.restore()
        cr.save()

        cr.new_sub_path()
        cr.rectangle(x, y, value_width, floor)
        Gdk.cairo_set_source_rgba(cr, fill_color)
        cr.fill()

        cr.restore()

        return True
示例#48
0
    def on_draw(self, widget, cr):
        ctx = widget.get_style_context()
        alloc = self.get_allocation()

        padding = ctx.get_padding(Gtk.StateFlags.NORMAL)
        border = ctx.get_border(Gtk.StateFlags.NORMAL)

        x = padding.left + border.left
        y = padding.top + border.top
        width = alloc.width - padding.left - padding.right - border.left - border.right
        height = alloc.height - padding.top - padding.bottom - border.top - border.bottom
        floor = y + height
        end = x + width
        value = self.get_fraction()
        value_width = value * width

        fill_color = ctx.get_color(Gtk.StateFlags.NORMAL)
        bg_color = ctx.get_background_color(Gtk.StateFlags.NORMAL)

        cr.save()

        cr.new_sub_path()
        cr.rectangle(x, y, end, floor)
        Gdk.cairo_set_source_rgba(cr, bg_color)
        cr.fill()

        cr.restore()
        cr.save()

        cr.new_sub_path()
        cr.rectangle(x, y, value_width, floor)
        Gdk.cairo_set_source_rgba(cr, fill_color)
        cr.fill()

        cr.restore()

        return True
示例#49
0
文件: editor.py 项目: chergert/editor
    def draw_rect(self, cr, begin, end, dashed=False):
        rect = self.view.get_iter_location(begin)
        rect.x, rect.y = self.view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect.x, rect.y)

        rect_end = self.view.get_iter_location(end)
        rect_end.x, rect_end.y = self.view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect_end.x, rect_end.y)
        rect.width = rect_end.x - rect.x

        rect.width -= 1
        rect.height -= 1
        col = self.view.get_style_context().get_color(Gtk.StateFlags.INSENSITIVE)
        col.alpha = 0.7
        Gdk.cairo_set_source_rgba(cr, col)
        cr.set_line_width(1.0)
        if dashed:
            cr.set_dash([2], 0)
        Gdk.cairo_rectangle(cr, rect)
        if dashed:
            cr.stroke()
        else:
            cr.stroke_preserve()
            col.alpha = 0.1
            Gdk.cairo_set_source_rgba(cr, col)
            cr.fill()
示例#50
0
    def render_header(self, cr, a, border_radius, assets):
        context = self.get_style_context()
        Gtk.render_background(context, cr,
                              0, 0, a.width, a.height)

        cr.save()
        lin = cairo.LinearGradient(0, 0, 0, a.height)
        lin.add_color_stop_rgba(0, 1,1,1, 0.5)
        lin.add_color_stop_rgba(1, 1,1,1, 0.0)
        cr.set_source(lin)
        cr.rectangle(0, 0, a.width, a.height)
        cr.fill()

        # gridline color
        context.save()
        context.add_class("grid-lines")
        bc = context.get_border_color(self.get_state_flags())
        Gdk.cairo_set_source_rgba(cr, bc)
        context.restore()

        cr.move_to(0, a.height-0.5)
        cr.rel_line_to(a.width, 0)
        cr.set_line_width(1)
        cr.stroke()
        cr.restore()

        if hasattr(self, "more"):
            # set the arrow fill color
            context = self.more.get_style_context()
            cr.save()

            bg = context.get_background_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bg)

            # the arrow shape stuff
            ta = self.more.get_allocation()
            cr.move_to(ta.x-a.x-StockEms.MEDIUM, 0)
            cr.rel_line_to(ta.width+StockEms.MEDIUM, 0)
            cr.rel_line_to(0, a.height)
            cr.rel_line_to(-(ta.width+StockEms.MEDIUM), 0)
            cr.rel_line_to(StockEms.MEDIUM, -(a.height)*0.5)
            cr.close_path()
            cr.clip_preserve()
            cr.fill_preserve()

            bc = context.get_border_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bc)
            cr.stroke()

            cr.restore()

        # paint the containers children
        for child in self: self.propagate_draw(child, cr)
        return
示例#51
0
    def _on_goal_draw(self, widget, cr):
        context = widget.get_style_context()

        width = widget.get_allocated_width()
        height = widget.get_allocated_height()

        Gtk.render_background(context, cr, 0, 0, width, height)

        xc, yc = width / 2.0, height / 2.0
        radius = min(height, width) / 2.0
        angle1 = angle2 = -(math.pi / 2.0)
        ratio = self._word_goal_ratio_accomplished
        fg_color = context.get_color(context.get_state())
        bg_color = Gdk.RGBA()
        has_color, bg_color = context.lookup_color('theme_bg_color')
        has_color, completion_color = context.lookup_color(
            'theme_selected_bg_color')

        # Add a faded circle first
        cr.move_to(xc, yc)
        fg_color.alpha = 0.1
        Gdk.cairo_set_source_rgba(cr, fg_color)
        cr.arc(xc, yc, radius, 0, 2 * math.pi)
        cr.fill()

        # Add the goal completion circle
        if ratio > 0:
            if ratio >= 1:
                ratio = 1
                has_color, completion_color = context.lookup_color(
                    'success_color')
                completion_color.alpha = 0.7
            angle2 = (ratio * math.pi * 2.0) - (math.pi / 2.0)
            cr.move_to(xc, yc)
            Gdk.cairo_set_source_rgba(cr, completion_color)
            cr.arc(xc, yc, radius, angle1, angle2)
            cr.fill()

        # Add an inner circle of bg color
        cr.move_to(xc, yc)
        bg_color.alpha = 1.0
        if ratio >= 1:
            bg_color.alpha = 0.8
        Gdk.cairo_set_source_rgba(cr, bg_color)
        cr.arc(xc, yc, radius - 16, 0, 2 * math.pi)
        cr.fill()

        return False
示例#52
0
    def render_labels(self, cr):
        if len(self.segments) == 0:
            return
        box_stroke_color = Gdk.RGBA(0, 0, 0, 0.6)
        x = 0
        layout = self.create_pango_layout('')

        for segment in self.segments:
            cr.set_line_width(1)
            cr.rectangle(
                x + 0.5, 2 + 0.5, self.segment_box_size - 1,
                self.segment_box_size - 1)
            grad = self.make_segment_gradient(
                self.segment_box_size, segment.color)
            cr.set_source(grad)
            cr.fill_preserve()
            Gdk.cairo_set_source_rgba(cr, box_stroke_color)
            cr.stroke()

            x = x + self.segment_box_size + self.segment_box_spacing

            layout.set_markup('<b>%s</b>' % segment.title, -1)
            (lw, lh) = layout.get_pixel_size()

            cr.move_to(x, 0)
            Gdk.cairo_set_source_rgba(cr, self.text_color)
            PangoCairo.show_layout(cr, layout)
            cr.fill()

            layout.set_markup('<small>%s</small>' % segment.subtitle, -1)

            cr.move_to(x, lh)
            Gdk.cairo_set_source_rgba(cr, self.subtext_color)
            PangoCairo.show_layout(cr, layout)
            cr.fill()
            x = x + segment.layout_width + self.segment_label_spacing
示例#53
0
文件: linkmap.py 项目: levif/meld
    def do_draw(self, context):
        if not self.views:
            return

        pix_start = [t.get_visible_rect().y for t in self.views]
        y_offset = [
            t.translate_coordinates(self, 0, 0)[1] + 1 for t in self.views]

        clip_y = min(y_offset) - 1
        clip_height = max(t.get_visible_rect().height for t in self.views) + 2
        allocation = self.get_allocation()

        stylecontext = self.get_style_context()
        Gtk.render_background(
            stylecontext, context, 0, clip_y, allocation.width, clip_height)
        context.set_line_width(1.0)

        height = allocation.height
        visible = [
            self.views[0].get_line_num_for_y(pix_start[0]),
            self.views[0].get_line_num_for_y(pix_start[0] + height),
            self.views[1].get_line_num_for_y(pix_start[1]),
            self.views[1].get_line_num_for_y(pix_start[1] + height),
        ]

        # For bezier control points
        x_steps = [-0.5, allocation.width / 2, allocation.width + 0.5]
        q_rad = math.pi / 2

        left, right = self.view_indices

        def view_offset_line(view_idx, line_num):
            line_start = self.views[view_idx].get_y_for_line_num(line_num)
            return line_start - pix_start[view_idx] + y_offset[view_idx]

        for c in self.filediff.linediffer.pair_changes(left, right, visible):
            # f and t are short for "from" and "to"
            f0, f1 = [view_offset_line(0, l) for l in c[1:3]]
            t0, t1 = [view_offset_line(1, l) for l in c[3:5]]
            # We want the last pixel of the previous line
            f1 = f1 if f1 == f0 else f1 - 1
            t1 = t1 if t1 == t0 else t1 - 1

            # If either endpoint is completely off-screen, we cull for clarity
            if (t0 < 0 and t1 < 0) or (t0 > height and t1 > height):
                if f0 == f1:
                    continue
                context.arc(
                    x_steps[0], f0 - 0.5 + RADIUS, RADIUS, q_rad * 3, 0)
                context.arc(x_steps[0], f1 - 0.5 - RADIUS, RADIUS, 0, q_rad)
                context.close_path()
            elif (f0 < 0 and f1 < 0) or (f0 > height and f1 > height):
                if t0 == t1:
                    continue
                context.arc_negative(x_steps[2], t0 - 0.5 + RADIUS, RADIUS,
                                     q_rad * 3, q_rad * 2)
                context.arc_negative(x_steps[2], t1 - 0.5 - RADIUS, RADIUS,
                                     q_rad * 2, q_rad)
                context.close_path()
            else:
                context.move_to(x_steps[0], f0 - 0.5)
                context.curve_to(x_steps[1], f0 - 0.5,
                                 x_steps[1], t0 - 0.5,
                                 x_steps[2], t0 - 0.5)
                context.line_to(x_steps[2], t1 - 0.5)
                context.curve_to(x_steps[1], t1 - 0.5,
                                 x_steps[1], f1 - 0.5,
                                 x_steps[0], f1 - 0.5)
                context.close_path()

            Gdk.cairo_set_source_rgba(context, self.fill_colors[c[0]])
            context.fill_preserve()

            chunk_idx = self.filediff.linediffer.locate_chunk(left, c[1])[0]
            if chunk_idx == self.filediff.cursor.chunk:
                highlight = self.fill_colors['current-chunk-highlight']
                Gdk.cairo_set_source_rgba(context, highlight)
                context.fill_preserve()

            Gdk.cairo_set_source_rgba(context, self.line_colors[c[0]])
            context.stroke()
示例#54
0
 def cb_draw(self, widget, cr):
     Gdk.cairo_set_source_rgba(
         cr,
         Gdk.RGBA(self.channels[0].value, self.channels[1].value,
                  self.channels[2].value))
     cr.paint()
示例#55
0
    def on_draw(self, widget, cr, data=None):
        """
        GtkEntry always makes its icons menu-sized, no matter how much actual
        space is available for the image.  So, we use a transparent icon in
        update_layout_icon(), just so GtkEntry thinks there's an icon there,
        that way it allocates space for it, and responds to clicks in the area.
        """
        if not self.keyboard_controller.get_enabled():
            return False

        icon_rect = widget.get_icon_area(Gtk.EntryIconPosition.PRIMARY)
        x = icon_rect.x
        y = icon_rect.y + 2
        width = (icon_rect.width // 2) * 2
        height = icon_rect.height - 4

        handled = False

        if settings.get_show_flags():
            name = self.keyboard_controller.get_current_icon_name()

            if name:
                filename = "/usr/share/iso-flag-png/%s.png" % name

                try:
                    pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                        filename, -1, height)

                    render_x = (x + (width / 2) - (pixbuf.get_width() / 2))
                    render_y = (y + (height / 2) - (pixbuf.get_height() / 2))

                    Gdk.cairo_set_source_pixbuf(cr, pixbuf, render_x, render_y)

                    cr.paint()

                    self.keyboard_controller.render_cairo_subscript(
                        cr, render_x + (pixbuf.get_width() / 2),
                        render_y + (pixbuf.get_height() / 2),
                        pixbuf.get_width() / 2,
                        pixbuf.get_height() / 2,
                        self.keyboard_controller.get_current_flag_id())

                    handled = True
                except GLib.Error:
                    pass

        if not handled:
            if settings.get_use_layout_variant_names():
                name = self.keyboard_controller.get_current_variant_label()
            else:
                name = self.keyboard_controller.get_current_short_group_label()

            if settings.get_show_upper_case_layout():
                name = name.upper()

            ctx = widget.get_style_context()
            ctx.save()

            ctx.set_state(Gtk.StateFlags.BACKDROP)
            font_size = ctx.get_property("font-size", Gtk.StateFlags.BACKDROP)
            family = ctx.get_property("font-family", Gtk.StateFlags.BACKDROP)
            cr.select_font_face(family[0], cairo.FONT_WEIGHT_NORMAL,
                                cairo.FONT_SLANT_NORMAL)
            cr.set_font_size(font_size)

            (xb, yb, w, h, xa, ya) = cr.text_extents(name)

            # Drop shadow for visibility - 1px, 1px
            cr.set_source_rgba(0, 0, 0, 0.8)
            cr.move_to((x + (width / 2) - (w / 2)) + 1,
                       (y + (height / 2) + (h / 2) + 1))

            cr.show_text(name)

            # Text

            text_color = widget.get_style_context().get_color(
                Gtk.StateFlags.BACKDROP)

            Gdk.cairo_set_source_rgba(cr, text_color)
            cr.move_to((x + (width / 2) - (w / 2)),
                       (y + (height / 2) + (h / 2)))

            cr.show_text(name)

            ctx.restore()

        return False
    def render_frame(self, cr, a, border_radius, assets):
        # we cache as much of the drawing as possible
        # store a copy of the rendered frame surface, so we only have to
        # do a full redraw if the widget dimensions change
        if self._frame_surface_cache is None:
            surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height)
            _cr = cairo.Context(surf)

            at = self.ASSET_TAG

            width = a.width
            height = a.height
            cnr_slice = assets["corner-slice"]

            # paint north-west corner
            _cr.set_source_surface(assets["%s-nw" % at], 0, 0)
            _cr.paint()

            # paint north length
            _cr.save()
            _cr.set_source(assets["%s-n" % at])
            _cr.rectangle(cnr_slice, 0, width - 2 * cnr_slice, cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint north-east corner
            _cr.set_source_surface(assets["%s-ne" % at], width - cnr_slice, 0)
            _cr.paint()

            # paint east length
            _cr.save()
            _cr.translate(width - cnr_slice, cnr_slice)
            _cr.set_source(assets["%s-e" % at])
            _cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint south-east corner
            _cr.set_source_surface(assets["%s-se" % at], width - cnr_slice,
                                   height - cnr_slice)
            _cr.paint()

            # paint south length
            _cr.save()
            _cr.translate(cnr_slice, height - cnr_slice)
            _cr.set_source(assets["%s-s" % at])
            _cr.rectangle(0, 0, width - 2 * cnr_slice, cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # paint south-west corner
            _cr.set_source_surface(assets["%s-sw" % at], 0, height - cnr_slice)
            _cr.paint()

            # paint west length
            _cr.save()
            _cr.translate(0, cnr_slice)
            _cr.set_source(assets["%s-w" % at])
            _cr.rectangle(0, 0, cnr_slice, height - 2 * cnr_slice)
            _cr.clip()
            _cr.paint()
            _cr.restore()

            # fill interior
            rounded_rect(_cr, 3, 2, a.width - 6, a.height - 6, border_radius)
            context = self.get_style_context()
            bg = context.get_background_color(self.get_state_flags())

            Gdk.cairo_set_source_rgba(_cr, bg)
            _cr.fill_preserve()

            lin = cairo.LinearGradient(0, 0, 0, max(300, a.height))
            lin.add_color_stop_rgba(0, 1, 1, 1, 0.02)
            lin.add_color_stop_rgba(1, 0, 0, 0, 0.06)
            _cr.set_source(lin)
            _cr.fill()

            self._frame_surface_cache = surf
            del _cr

        # paint the cached surface and apply a rounded rect clip to
        # child draw ops
        A = self.get_allocation()
        xo, yo = a.x - A.x, a.y - A.y

        cr.set_source_surface(self._frame_surface_cache, xo, yo)
        cr.paint()
    def render_header(self, cr, a, border_radius, assets):

        if hasattr(self, "more"):
            context = self.get_style_context()

            # set the arrow fill color
            context = self.more.get_style_context()
            cr.save()

            bg = context.get_background_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bg)

            # the arrow shape stuff
            r = Frame.BORDER_RADIUS - 1
            ta = self.more.get_allocation()

            y = ta.y - a.y + 2
            h = ta.height - 2

            if self.get_direction() == Gtk.TextDirection.RTL:
                x = ta.x - a.x + 3
                w = ta.width + StockEms.MEDIUM

                cr.new_sub_path()
                cr.arc(r + x, r + y, r, PI, 270 * PI_OVER_180)
                cr.line_to(x + w, y)
                cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
                cr.line_to(x + w, y + h)
                cr.line_to(x, y + h)
                cr.close_path()

                cr.fill()

                cr.move_to(x + w, y)
                cr.line_to(x + w - StockEms.MEDIUM, y + h / 2)
                cr.line_to(x + w, y + h)

            else:
                x = ta.x - a.x - StockEms.MEDIUM
                w = ta.width + StockEms.MEDIUM - 1

                cr.move_to(x, y)
                cr.arc(x + w - r, y + r, r, 270 * PI_OVER_180, 0)
                cr.line_to(x + w, y + h)
                cr.line_to(x, y + h)
                cr.line_to(x + StockEms.MEDIUM, y + h / 2)
                cr.close_path()

                cr.fill()

                cr.move_to(x, y)
                cr.line_to(x + StockEms.MEDIUM, y + h / 2)
                cr.line_to(x, y + h)

            bc = context.get_border_color(self.get_state_flags())
            Gdk.cairo_set_source_rgba(cr, bc)
            cr.set_line_width(1)
            cr.stroke()

            cr.restore()

        # paint the containers children
        for child in self:
            self.propagate_draw(child, cr)