def render_round_floating_color_chip(cr, x, y, color, radius): """Draw a round color chip with a slight drop shadow Currently used for dismiss/delete buttons and control points. The button's style is similar to that used for the paint chips in the dockable palette panel. """ x = round(float(x)) y = round(float(y)) cr.save() cr.set_dash([], 0) cr.set_line_width(0) base_col = RGBColor(color=color) hi_col = _get_paint_chip_highlight(base_col) xoffs = gui.style.DROP_SHADOW_X_OFFSET yoffs = gui.style.DROP_SHADOW_Y_OFFSET blur = gui.style.DROP_SHADOW_BLUR alpha = gui.style.DROP_SHADOW_ALPHA drop_shadow = cairo.RadialGradient( x + xoffs, y + yoffs, radius, x + xoffs, y + yoffs, radius + blur, ) drop_shadow.add_color_stop_rgba(0, 0, 0, 0, alpha) drop_shadow.add_color_stop_rgba(1, 0, 0, 0, 0.0) cr.arc(x + xoffs, y + yoffs, radius + blur + 1, 0, 2 * math.pi) cr.set_source(drop_shadow) cr.fill() cr.arc(x, y, radius, 0, 2 * math.pi) cr.set_source_rgb(*base_col.get_rgb()) cr.fill_preserve() cr.clip_preserve() cr.set_source_rgb(*hi_col.get_rgb()) cr.set_line_width(2) cr.stroke() cr.restore()
def render_round_floating_color_chip(cr, x, y, color, radius, z=2): """Draw a round color chip with a slight drop shadow :param cairo.Context cr: Context in which to draw. :param float x: X coordinate of the center pixel. :param float y: Y coordinate of the center pixel. :param lib.color.UIColor color: Color for the chip. :param float radius: Circle radius, in pixels. :param int z: Simulated height of the object above the canvas. Currently used for accept/dismiss/delete buttons and control points on the painting canvas, in certain modes. The button's style is similar to that used for the paint chips in the dockable palette panel. As used here with drop shadows to indicate that the blob can be interacted with, the style is similar to Google's Material Design approach. This style adds a subtle edge highlight in a brighter variant of "color", which seems to help address adjacent color interactions. """ x = round(float(x)) y = round(float(y)) radius = round(radius) cr.save() cr.set_dash([], 0) cr.set_line_width(0) base_col = RGBColor(color=color) hi_col = _get_paint_chip_highlight(base_col) cr.arc(x, y, radius + 0, 0, 2 * math.pi) cr.set_line_width(2) render_drop_shadow(cr, z=z) cr.set_source_rgb(*base_col.get_rgb()) cr.fill_preserve() cr.clip_preserve() cr.set_source_rgb(*hi_col.get_rgb()) cr.stroke() cr.restore()
def render_round_floating_color_chip(cr, x, y, color, radius, z=2): """Draw a round color chip with a slight drop shadow :param cairo.Context cr: Context in which to draw. :param float x: X coordinate of the center pixel. :param float y: Y coordinate of the center pixel. :param lib.color.UIColor color: Color for the chip. :param float radius: Circle radius, in pixels. :param int z: Simulated height of the object above the canvas. Currently used for accept/dismiss/delete buttons and control points on the painting canvas, in certain modes. The button's style is similar to that used for the paint chips in the dockable palette panel. As used here with drop shadows to indicate that the blob can be interacted with, the style is similar to Google's Material Design approach. This style adds a subtle edge highlight in a brighter variant of "color", which seems to help address adjacent color interactions. """ x = round(float(x)) y = round(float(y)) radius = round(radius) cr.save() cr.set_dash([], 0) cr.set_line_width(0) base_col = RGBColor(color=color) hi_col = _get_paint_chip_highlight(base_col) cr.arc(x, y, radius+0, 0, 2*math.pi) cr.set_line_width(2) render_drop_shadow(cr, z=z) cr.set_source_rgb(*base_col.get_rgb()) cr.fill_preserve() cr.clip_preserve() cr.set_source_rgb(*hi_col.get_rgb()) cr.stroke() cr.restore()
def render_round_floating_color_chip(cr, x, y, color, radius): """Draw a round color chip with a slight drop shadow Currently used for dismiss/delete buttons and control points. The button's style is similar to that used for the paint chips in the dockable palette panel. """ x = round(float(x)) y = round(float(y)) cr.save() cr.set_dash([], 0) cr.set_line_width(0) base_col = RGBColor(color=color) hi_col = _get_paint_chip_highlight(base_col) xoffs = gui.style.DROP_SHADOW_X_OFFSET yoffs = gui.style.DROP_SHADOW_Y_OFFSET blur = gui.style.DROP_SHADOW_BLUR alpha = gui.style.DROP_SHADOW_ALPHA drop_shadow = cairo.RadialGradient( x+xoffs, y+yoffs, radius, x+xoffs, y+yoffs, radius + blur, ) drop_shadow.add_color_stop_rgba(0, 0, 0, 0, alpha) drop_shadow.add_color_stop_rgba(1, 0, 0, 0, 0.0) cr.arc(x+xoffs, y+yoffs, radius + blur + 1, 0, 2*math.pi) cr.set_source(drop_shadow) cr.fill() cr.arc(x, y, radius, 0, 2*math.pi) cr.set_source_rgb(*base_col.get_rgb()) cr.fill_preserve() cr.clip_preserve() cr.set_source_rgb(*hi_col.get_rgb()) cr.set_line_width(2) cr.stroke() cr.restore()