class Oekaki::Tool
Attributes
height[RW]
width[RW]
window[R]
Public Class Methods
new()
click to toggle source
# File lib/oekaki.rb, line 8 def initialize @window = W @drawable = W.window @gc = Gdk::GC.new(@drawable) @colormap = Gdk::Colormap.system @color = Gdk::Color.new(0, 0, 0) @fontdesc = Pango::FontDescription.new @width, @height = 0, 0 end
Public Instance Methods
arc(fill, x, y, width, height, d1, d2, color = nil)
click to toggle source
# File lib/oekaki.rb, line 31 def arc(fill, x, y, width, height, d1, d2, color = nil) set_color(color) @drawable.draw_arc(@gc, fill, x, y, width, height, d1, d2) end
circle(fill, x, y, r, color = nil)
click to toggle source
# File lib/oekaki.rb, line 36 def circle(fill, x, y, r, color = nil) arc(fill, x - r, y - r, 2 * r, 2 * r, 0, 64 * 360, color) end
clear(color = nil)
click to toggle source
# File lib/oekaki.rb, line 100 def clear(color = nil) color ||= Gdk::Color.new(0, 0, 0) set_color(color) rectangle(true, 0, 0, @width, @height) end
color(r, g, b)
click to toggle source
# File lib/oekaki.rb, line 20 def color(r, g, b) @color = Gdk::Color.new(r, g, b) @colormap.alloc_color(@color, false, true) @color end
get_pic(x, y, width, height)
click to toggle source
# File lib/oekaki.rb, line 87 def get_pic(x, y, width, height) GdkPixbuf::Pixbuf.from_drawable(nil, @drawable, x, y, width, height) end
get_window_size()
click to toggle source
# File lib/oekaki.rb, line 106 def get_window_size W.size end
line(x1, y1, x2, y2, color = nil)
click to toggle source
# File lib/oekaki.rb, line 45 def line(x1, y1, x2, y2, color = nil) set_color(color) @drawable.draw_lines(@gc, [[x1, y1], [x2, y2]]) end
lines(array, color = nil)
click to toggle source
# File lib/oekaki.rb, line 50 def lines(array, color = nil) set_color(color) @drawable.draw_lines(@gc, array) end
load_pic(filename)
click to toggle source
# File lib/oekaki.rb, line 75 def load_pic(filename) GdkPixbuf::Pixbuf.new(file: filename) end
point(x, y, color = nil)
click to toggle source
# File lib/oekaki.rb, line 40 def point(x, y, color = nil) set_color(color) @drawable.draw_point(@gc, x, y) end
polygon(fill, array, color = nil)
click to toggle source
# File lib/oekaki.rb, line 55 def polygon(fill, array, color = nil) set_color(color) @drawable.draw_polygon(@gc, fill, array) end
rectangle(fill, x, y, width, height, color = nil)
click to toggle source
# File lib/oekaki.rb, line 26 def rectangle(fill, x, y, width, height, color = nil) set_color(color) @drawable.draw_rectangle(@gc, fill, x, y, width, height) end
save_pic(img, filename, type = "png")
click to toggle source
# File lib/oekaki.rb, line 79 def save_pic(img, filename, type = "png") img.save(filename, type) end
show_pic(img, x, y)
click to toggle source
# File lib/oekaki.rb, line 83 def show_pic(img, x, y) @drawable.draw_pixbuf(@gc, img, 0, 0, x, y, img.width, img.height, Gdk::RGB::DITHER_NONE, 0, 0) end
star(fill, x1, y1, x2, y2, color = nil)
click to toggle source
# File lib/oekaki.rb, line 95 def star(fill, x1, y1, x2, y2, color = nil) set_color(color) Star.new(fill, x1, y1, x2, y2, @color).draw end
text(str, x, y, size, color = nil)
click to toggle source
# File lib/oekaki.rb, line 60 def text(str, x, y, size, color = nil) set_color(color) @fontdesc.set_size(size) layout = Pango::Layout.new(W.pango_context) layout.font_description = @fontdesc layout.text = str @drawable.draw_layout(@gc, x, y, layout) end
timer_stop(id)
click to toggle source
# File lib/oekaki.rb, line 91 def timer_stop(id) Gtk.timeout_remove(id) end
Private Instance Methods
set_color(color)
click to toggle source
# File lib/oekaki.rb, line 69 def set_color(color) @color = color if color @gc.set_foreground(@color) end