Sha256: 3693c81017f2f2ad07168c45060ba6ec7264900fd317562de48203510d5ec6b6

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

class ImageVoodoo
  module Shapes
    ##
    # *AWT* Draw a square
    #
    def square(x, y, dim, rgb, fill=true)
      square_rounded(x, y, dim, rgb, 0, fill)
    end
    
    ##
    # *AWT* Draw a rectangle
    #
    def rect(x, y, width, height, rgb, fill=true)
      rect_rounded(x, y, width, height, rgb, 0, 0, fill)
    end

    ##
    # *AWT* Draw a rounded square
    #
    def square_rounded(x, y, dim, rgb, arc_width=0, fill=true)
      rect_rounded(x,y, dim, dim, rgb, arc_width, arc_width, fill)
    end

    ##
    # *AWT* Draw a rounded rectangle
    #
    def rect_rounded(x, y, width, height, rgb, arc_width=0, arc_height=0, fill=true)
      as_color(ImageVoodoo.hex_to_color(rgb)) do |g|
        if fill
          g.fill_round_rect x, y, width, height, arc_width, arc_height
        else
          g.draw_round_rect x, y, width, height, arc_width, arc_height
        end
      end
    end

    def as_color(color)
      paint do |g| 
        old_color = g.color
        g.color = color
        yield g
        g.color = old_color
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
image_voodoo-0.8.4 lib/image_voodoo/awt/shapes.rb
image_voodoo-0.8.3 lib/image_voodoo/awt/shapes.rb