Class: Oekaki::Tool
- Inherits:
-
Object
- Object
- Oekaki::Tool
- Defined in:
- lib/oekaki.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #arc(fill, x, y, width, height, d1, d2, color = nil) ⇒ Object
- #circle(fill, x, y, r, color = nil) ⇒ Object
- #clear(color = nil) ⇒ Object
- #color(r, g, b) ⇒ Object
- #get_pic(x, y, width, height) ⇒ Object
- #get_window_size ⇒ Object
-
#initialize ⇒ Tool
constructor
A new instance of Tool.
- #line(x1, y1, x2, y2, color = nil) ⇒ Object
- #lines(array, color = nil) ⇒ Object
- #load_pic(filename) ⇒ Object
- #point(x, y, color = nil) ⇒ Object
- #polygon(fill, array, color = nil) ⇒ Object
- #rectangle(fill, x, y, width, height, color = nil) ⇒ Object
- #save_pic(img, filename, type = "png") ⇒ Object
- #show_pic(img, x, y) ⇒ Object
- #star(fill, x1, y1, x2, y2, color = nil) ⇒ Object
- #text(str, x, y, size, color = nil) ⇒ Object
- #timer_stop(id) ⇒ Object
Constructor Details
#initialize ⇒ Tool
Returns a new instance of Tool.
8 9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
18 19 20 |
# File 'lib/oekaki.rb', line 18 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
18 19 20 |
# File 'lib/oekaki.rb', line 18 def width @width end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
17 18 19 |
# File 'lib/oekaki.rb', line 17 def window @window end |
Instance Method Details
#arc(fill, x, y, width, height, d1, d2, color = nil) ⇒ Object
31 32 33 34 |
# 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) ⇒ Object
36 37 38 |
# 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) ⇒ Object
100 101 102 103 |
# File 'lib/oekaki.rb', line 100 def clear(color = nil) set_color(color) rectangle(true, 0, 0, @width, @height) end |
#color(r, g, b) ⇒ Object
20 21 22 23 24 |
# 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) ⇒ Object
87 88 89 |
# 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 ⇒ Object
105 106 107 |
# File 'lib/oekaki.rb', line 105 def get_window_size W.size end |
#line(x1, y1, x2, y2, color = nil) ⇒ Object
45 46 47 48 |
# 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) ⇒ Object
50 51 52 53 |
# File 'lib/oekaki.rb', line 50 def lines(array, color = nil) set_color(color) @drawable.draw_lines(@gc, array) end |
#load_pic(filename) ⇒ Object
75 76 77 |
# File 'lib/oekaki.rb', line 75 def load_pic(filename) GdkPixbuf::Pixbuf.new(file: filename) end |
#point(x, y, color = nil) ⇒ Object
40 41 42 43 |
# 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) ⇒ Object
55 56 57 58 |
# 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) ⇒ Object
26 27 28 29 |
# 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") ⇒ Object
79 80 81 |
# File 'lib/oekaki.rb', line 79 def save_pic(img, filename, type = "png") img.save(filename, type) end |
#show_pic(img, x, y) ⇒ Object
83 84 85 |
# 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) ⇒ Object
95 96 97 98 |
# 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) ⇒ Object
60 61 62 63 64 65 66 67 |
# 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) ⇒ Object
91 92 93 |
# File 'lib/oekaki.rb', line 91 def timer_stop(id) Gtk.timeout_remove(id) end |