F
Farrel Lifson
What version of rcairo, and ruby-gnome2 do I need to have
GDK#create_cairo_context? I get the following error
demo.rb:23:in `expose': undefined method `create_cairo_context' for
#<Gdk::Window:0xb724dd28 ptr=3D0x82bb290> (NoMethodError)
from demo.rb:13:in `initialize'
from demo.rb:74
when trying to run the following sample code:
#!/usr/bin/env ruby
require 'cairo'
require 'gtk2'
include Math
class DemiCercle < Gtk:rawingArea
attr_accessor :desp
def initialize
super
add_events(Gdk::Event::BUTTON_PRESS_MASK |
Gdk::Event::BUTTON1_MOTION_MASK)
signal_connect "expose_event" do |widget,event|
expose(widget,event)
end # do
signal_connect "button_press_event" do |widget,event|
pressing(widget,event) end
signal_connect "motion_notify_event" do |widget,event|
moving(widget,event) end
@desp =3D 0.0
end # initialize
def expose(widget,event)
# cr=C3(c)er un contexte graphique
context =3D widget.window.create_cairo_context
context.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
context.clip()
draw(context)
return false
end # expose
def draw(context)
rect =3D allocation()
x =3D rect.x + rect.width / 2.0
y =3D rect.y + rect.height / 2.0
radius =3D [rect.width / 2.0, rect.height / 2.0].min - 5.0
#context.arc(x, y, radius, 0,(1 * PI))
context.arc(x, y, radius, 0 + @desp , (1.0 * PI) + @desp)
context.set_source_rgb(0.7, 0.8, 0.1)
context.fill_preserve()
context.set_source_rgb(0, 0, 0)
context.stroke()
end
def pressing(widget,event)
pressing_x =3D event.x
end
def moving(widget,event)
if (pressing(widget,event) - event.x) > 1
@desp =3D @desp + 0.2
else
@desp =3D @desp - 0.1
end
draw(widget.window.create_cairo_context)
queue_draw()
end
end
Gtk.init
fen =3D Gtk::Window.new
fen.set_title("Cairo exemple 2")
fen.signal_connect("destroy") { Gtk.main_quit }
figure =3D DemiCercle.new
fen.add(figure)
fen.show_all
Gtk.main
I have the following libs installed on my Gentoo box:
nicodemus portage # emerge -p rcairo gtk+ ruby-gnome2
Calculating dependencies... done!
[ebuild R ] dev-ruby/rcairo-1.0.0 USE=3D"-examples*"
[ebuild R ] x11-libs/gtk+-2.8.12 USE=3D"-tiff*"
[ebuild R ] dev-ruby/ruby-gnome2-0.14.1
Thank,
Farrel
GDK#create_cairo_context? I get the following error
demo.rb:23:in `expose': undefined method `create_cairo_context' for
#<Gdk::Window:0xb724dd28 ptr=3D0x82bb290> (NoMethodError)
from demo.rb:13:in `initialize'
from demo.rb:74
when trying to run the following sample code:
#!/usr/bin/env ruby
require 'cairo'
require 'gtk2'
include Math
class DemiCercle < Gtk:rawingArea
attr_accessor :desp
def initialize
super
add_events(Gdk::Event::BUTTON_PRESS_MASK |
Gdk::Event::BUTTON1_MOTION_MASK)
signal_connect "expose_event" do |widget,event|
expose(widget,event)
end # do
signal_connect "button_press_event" do |widget,event|
pressing(widget,event) end
signal_connect "motion_notify_event" do |widget,event|
moving(widget,event) end
@desp =3D 0.0
end # initialize
def expose(widget,event)
# cr=C3(c)er un contexte graphique
context =3D widget.window.create_cairo_context
context.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
context.clip()
draw(context)
return false
end # expose
def draw(context)
rect =3D allocation()
x =3D rect.x + rect.width / 2.0
y =3D rect.y + rect.height / 2.0
radius =3D [rect.width / 2.0, rect.height / 2.0].min - 5.0
#context.arc(x, y, radius, 0,(1 * PI))
context.arc(x, y, radius, 0 + @desp , (1.0 * PI) + @desp)
context.set_source_rgb(0.7, 0.8, 0.1)
context.fill_preserve()
context.set_source_rgb(0, 0, 0)
context.stroke()
end
def pressing(widget,event)
pressing_x =3D event.x
end
def moving(widget,event)
if (pressing(widget,event) - event.x) > 1
@desp =3D @desp + 0.2
else
@desp =3D @desp - 0.1
end
draw(widget.window.create_cairo_context)
queue_draw()
end
end
Gtk.init
fen =3D Gtk::Window.new
fen.set_title("Cairo exemple 2")
fen.signal_connect("destroy") { Gtk.main_quit }
figure =3D DemiCercle.new
fen.add(figure)
fen.show_all
Gtk.main
I have the following libs installed on my Gentoo box:
nicodemus portage # emerge -p rcairo gtk+ ruby-gnome2
Calculating dependencies... done!
[ebuild R ] dev-ruby/rcairo-1.0.0 USE=3D"-examples*"
[ebuild R ] x11-libs/gtk+-2.8.12 USE=3D"-tiff*"
[ebuild R ] dev-ruby/ruby-gnome2-0.14.1
Thank,
Farrel