Added blending operators to png and svg
Also refactored to start using save/restore more often
This commit is contained in:
@@ -4,9 +4,10 @@ module Squib
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def background(color)
|
||||
cc = cairo_context
|
||||
cc.set_source_color(color)
|
||||
cc.paint
|
||||
use_cairo do |cc|
|
||||
cc.set_source_color(color)
|
||||
cc.paint
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -14,17 +14,19 @@ module Squib
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def png(file, x, y, alpha)
|
||||
def png(file, x, y, alpha, blend)
|
||||
return if file.nil? or file.eql? ''
|
||||
cc = cairo_context
|
||||
png = Squib.cache_load_image(file)
|
||||
cc.set_source(png, x, y)
|
||||
cc.paint(alpha)
|
||||
use_cairo do |cc|
|
||||
cc.set_source(png, x, y)
|
||||
cc.operator = blend unless blend == :none
|
||||
cc.paint(alpha)
|
||||
end
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def svg(file, id, x, y, width, height)
|
||||
def svg(file, id, x, y, width, height, alpha, blend)
|
||||
return if file.nil? or file.eql? ''
|
||||
svg = RSVG::Handle.new_from_file(file)
|
||||
width = svg.width if width == :native
|
||||
@@ -33,8 +35,11 @@ module Squib
|
||||
tmp_cc = Cairo::Context.new(tmp)
|
||||
tmp_cc.scale(width.to_f / svg.width.to_f, height.to_f / svg.height.to_f)
|
||||
tmp_cc.render_rsvg_handle(svg, id)
|
||||
cairo_context.set_source(tmp, x, y)
|
||||
cairo_context.paint
|
||||
use_cairo do |cc|
|
||||
cc.set_source(tmp, x, y)
|
||||
cc.operator = blend unless blend == :none
|
||||
cc.paint(alpha)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5,51 +5,55 @@ module Squib
|
||||
# @api private
|
||||
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
|
||||
width=@width if width==:native; height=@height if height==:native
|
||||
cc = cairo_context
|
||||
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
|
||||
cc.set_source_color(fill_color)
|
||||
cc.fill
|
||||
use_cairo do |cc|
|
||||
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
|
||||
cc.set_source_color(fill_color)
|
||||
cc.fill
|
||||
end
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def circle(x, y, radius, fill_color, stroke_color, stroke_width)
|
||||
cc = cairo_context
|
||||
cc.circle(x, y, radius)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
cc.circle(x, y, radius)
|
||||
cc.set_source_color(fill_color)
|
||||
cc.fill
|
||||
use_cairo do |cc|
|
||||
cc.circle(x, y, radius)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
cc.circle(x, y, radius)
|
||||
cc.set_source_color(fill_color)
|
||||
cc.fill
|
||||
end
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width)
|
||||
cc = cairo_context
|
||||
cc.triangle(x1, y1, x2, y2, x3, y3)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
cc.triangle(x1, y1, x2, y2, x3, y3)
|
||||
cc.set_source_color(fill_color)
|
||||
cc.fill
|
||||
use_cairo do |cc|
|
||||
cc.triangle(x1, y1, x2, y2, x3, y3)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
cc.triangle(x1, y1, x2, y2, x3, y3)
|
||||
cc.set_source_color(fill_color)
|
||||
cc.fill
|
||||
end
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def line(x1, y1, x2, y2, stroke_color, stroke_width)
|
||||
cc = cairo_context
|
||||
cc.move_to(x1, y1)
|
||||
cc.line_to(x2, y2)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
use_cairo do |cc|
|
||||
cc.move_to(x1, y1)
|
||||
cc.line_to(x2, y2)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
+19
-18
@@ -89,24 +89,25 @@ module Squib
|
||||
x, y, width, height,
|
||||
markup, justify, wrap, ellipsize,
|
||||
spacing, align, valign, hint)
|
||||
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, etc. (TODO FILL THIS IN WITH METAPROGRAMMING)"}
|
||||
cc = cairo_context
|
||||
cc.set_source_color(color)
|
||||
cc.move_to(x,y)
|
||||
layout = cc.create_pango_layout
|
||||
layout.font_description = Pango::FontDescription.new(font)
|
||||
layout.text = str.to_s
|
||||
layout.markup = str.to_s if markup
|
||||
layout = setwh(layout, width, height)
|
||||
layout = wrap(layout, wrap)
|
||||
layout = ellipsize(layout, ellipsize)
|
||||
layout = align(layout, align)
|
||||
layout.justify = justify unless justify.nil?
|
||||
layout.spacing = spacing * Pango::SCALE unless spacing.nil?
|
||||
cc.update_pango_layout(layout)
|
||||
valign(cc, layout, x,y, valign)
|
||||
cc.update_pango_layout(layout) ; cc.show_pango_layout(layout)
|
||||
draw_text_hint(x,y,layout,hint)
|
||||
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, etc."}
|
||||
use_cairo do |cc|
|
||||
cc.set_source_color(color)
|
||||
cc.move_to(x,y)
|
||||
layout = cc.create_pango_layout
|
||||
layout.font_description = Pango::FontDescription.new(font)
|
||||
layout.text = str.to_s
|
||||
layout.markup = str.to_s if markup
|
||||
layout = setwh(layout, width, height)
|
||||
layout = wrap(layout, wrap)
|
||||
layout = ellipsize(layout, ellipsize)
|
||||
layout = align(layout, align)
|
||||
layout.justify = justify unless justify.nil?
|
||||
layout.spacing = spacing * Pango::SCALE unless spacing.nil?
|
||||
cc.update_pango_layout(layout)
|
||||
valign(cc, layout, x,y, valign)
|
||||
cc.update_pango_layout(layout) ; cc.show_pango_layout(layout)
|
||||
draw_text_hint(x,y,layout,hint)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user