[cairo-commit] rcairo/gtk extconf.rb,NONE,1.1 rbgtkcairo.c,NONE,1.1 test.rb,NONE,1.1

Evan Martin commit at pdx.freedesktop.org
Mon Nov 24 20:35:44 PST 2003


Committed by: martine

Update of /cvs/cairo/rcairo/gtk
In directory pdx:/tmp/cvs-serv11993/gtk

Added Files:
	extconf.rb rbgtkcairo.c test.rb 
Log Message:
Fix build, add GtkCairo bindings.


--- NEW FILE: extconf.rb ---
=begin
extconf.rb for Ruby/GtkCairo extention library
=end

#$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../glib/src/lib')require 'mkmf-gnome2'
$LOAD_PATH.unshift File.expand_path('/home/martine/projects/cvs/ruby-gnome2/glib/src/lib')

require 'mkmf-gnome2'

PKGConfig.have_package('gtkcairo') or exit 1

# pull in rbcairo.h path.
$CFLAGS += " -I ../src"

create_makefile('gtkcairo')


--- NEW FILE: rbgtkcairo.c ---
/* ruby-cairo - Ruby bindings for Cairo.
 * Copyright (C) 2003 Evan Martin <martine at danga.com>
 *
 * vim: tabstop=4 shiftwidth=4 noexpandtab :
 */

#include "ruby.h"
#include "rbgtk.h"

#include "rbcairo.h"

#include <gtkcairo.h>

static VALUE cGtkCairo;

static VALUE
get_cairo(VALUE self) {
	GtkCairo *gtkcairo = RVAL2GOBJ(self);
	cairo_t *cairo = gtk_cairo_get_cairo(gtkcairo);
	VALUE rbcairo = rcairo_new_from(cairo);

	return rbcairo;
}

void Init_gtkcairo() {
	/* define a "Gtk" class under module "Cairo".
	 * cGtkCairo = G_DEF_CLASS(gtk_cairo_get_type(), "Gtk", mCairo); */

	/* define a "CairoWidget" class under module "Gtk". */
	cGtkCairo = G_DEF_CLASS(gtk_cairo_get_type(), "CairoWidget", mGtk);
	rb_define_method(cGtkCairo, "cairo", get_cairo, 0);
}


--- NEW FILE: test.rb ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

$LOAD_PATH << "../src"

require 'gtk2'
require 'cairo'
require 'gtkcairo'

class DemoWindow < Gtk::Window
	def initialize
    super

    @gc = Gtk::CairoWidget.new

    set_default_size(200, 200)
    signal_connect('destroy') { Gtk.main_quit }
    @gc.signal_connect('redraw') { redraw }

    #b = Gtk::Button.new("redraw")
    #b.signal_connect('clicked') { redraw }

    vb = Gtk::VBox.new(FALSE, 5)
    vb.border_width = 10
    vb.pack_start(@gc, TRUE, TRUE, 0)
    #vb.pack_start(b, FALSE, FALSE, 0)
    vb.show_all
    add(vb)
  end
  def redraw
    cr = @gc.cairo
    cr.set_rgb_color(0, 0, 0)
    cr.rectangle(0, 0, 100, 100)
    cr.fill

    cr.set_rgb_color(1, 0, 0)
    cr.rectangle(10, 10, 50, 50)
    cr.fill
  end
end

Gtk.init
win = DemoWindow.new
win.show
Gtk.main





More information about the cairo-commit mailing list