Class: Mir::PixelBoard
- Inherits:
-
Gtk::DrawingArea
- Object
- Gtk::DrawingArea
- Mir::PixelBoard
- Defined in:
- lib/mir/02_viewer.rb
Instance Method Summary collapse
- #draw_pixels(cr) ⇒ Object
-
#initialize(image) ⇒ PixelBoard
constructor
A new instance of PixelBoard.
- #on_expose ⇒ Object
Constructor Details
#initialize(image) ⇒ PixelBoard
Returns a new instance of PixelBoard.
5 6 7 8 9 10 11 12 |
# File 'lib/mir/02_viewer.rb', line 5 def initialize image super() @image=image override_background_color(:normal, Gdk::RGBA.new(0, 0, 0, 1)) signal_connect "draw" do on_expose end end |
Instance Method Details
#draw_pixels(cr) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mir/02_viewer.rb', line 19 def draw_pixels cr @image.size.y.times do |y| @image.size.x.times do |x| pix=@image[y,x] r,g,b=pix.to_a.map{|v| v/255.0} xx,yy=x*3,y*3 cr.set_source_rgb r,g,b cr.rectangle(x, y,1,1) cr.stroke end end end |
#on_expose ⇒ Object
14 15 16 17 |
# File 'lib/mir/02_viewer.rb', line 14 def on_expose cr = window.create_cairo_context draw_pixels cr end |