Class: Zyps::GTK2Canvas
- Inherits:
-
Object
- Object
- Zyps::GTK2Canvas
- Defined in:
- lib/zyps/views/canvas/gtk2.rb
Overview
Called by View objects for use in Ruby-GNOME2 applications. Assign an instance to a View, then add the drawing_area attribute to a GUI container object. The drawing area will be updated whenever the View is.
Instance Attribute Summary collapse
-
#drawing_area ⇒ Object
readonly
A Gtk::DrawingArea that will be painted on.
-
#height ⇒ Object
Dimensions of the drawing area.
-
#width ⇒ Object
Dimensions of the drawing area.
Instance Method Summary collapse
-
#draw_line(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :width => nil :x1 => nil :y1 => nil :x2 => nil :y2 => nil.
-
#draw_rectangle(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :border_width => 1 :filled => true :x => nil :y => nil :width => nil :height => nil.
-
#initialize ⇒ GTK2Canvas
constructor
A new instance of GTK2Canvas.
-
#render ⇒ Object
Draw all objects to the drawing area.
Constructor Details
#initialize ⇒ GTK2Canvas
Returns a new instance of GTK2Canvas.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/zyps/views/canvas/gtk2.rb', line 37 def initialize #Will be resized later. @width = 1 @height = 1 #Create a drawing area. @drawing_area = Gtk::DrawingArea.new #Set to correct size. resize #Whenever the drawing area needs updating... @drawing_area.signal_connect("expose_event") do #Copy buffer bitmap to canvas. @drawing_area.window.draw_drawable( @drawing_area.style.fg_gc(@drawing_area.state), #Gdk::GC (graphics context) to use when drawing. buffer, #Gdk::Drawable source to copy onto canvas. 0, 0, #Pull from upper left of source. 0, 0, #Copy to upper left of canvas. -1, -1 #-1 width and height signals to copy entire source over. ) end end |
Instance Attribute Details
#drawing_area ⇒ Object (readonly)
A Gtk::DrawingArea that will be painted on.
32 33 34 |
# File 'lib/zyps/views/canvas/gtk2.rb', line 32 def drawing_area @drawing_area end |
#height ⇒ Object
Dimensions of the drawing area. Control should normally be left to the owner View object.
35 36 37 |
# File 'lib/zyps/views/canvas/gtk2.rb', line 35 def height @height end |
#width ⇒ Object
Dimensions of the drawing area. Control should normally be left to the owner View object.
35 36 37 |
# File 'lib/zyps/views/canvas/gtk2.rb', line 35 def width @width end |
Instance Method Details
#draw_line(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :width => nil :x1 => nil :y1 => nil :x2 => nil :y2 => nil
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/zyps/views/canvas/gtk2.rb', line 103 def draw_line( = {}) graphics_context = Gdk::GC.new(buffer) graphics_context.rgb_fg_color = convert_color([:color]) graphics_context.set_line_attributes( [:width].ceil, Gdk::GC::LINE_SOLID, Gdk::GC::CAP_ROUND, Gdk::GC::JOIN_MITER #Only used for polygons. ) buffer.draw_line( graphics_context, [:x1], [:y1], [:x2], [:y2] ) end |
#draw_rectangle(options = {}) ⇒ Object
Takes a hash with these keys and defaults: :color => nil :border_width => 1 :filled => true :x => nil :y => nil :width => nil :height => nil
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/zyps/views/canvas/gtk2.rb', line 81 def draw_rectangle( = {}) = { :filled => true }.merge() graphics_context = Gdk::GC.new(buffer) graphics_context.rgb_fg_color = convert_color([:color]) buffer.draw_rectangle( graphics_context, [:filled], [:x], [:y], [:width], [:height] ) end |
#render ⇒ Object
Draw all objects to the drawing area.
121 122 123 |
# File 'lib/zyps/views/canvas/gtk2.rb', line 121 def render @drawing_area.queue_draw_area(0, 0, @width, @height) end |