goocanvas 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -9,7 +9,6 @@ package = GNOME2Package.new do |_package|
9
9
  _package.dependency.gem.runtime = ["gtk2"]
10
10
  _package.win32.packages = ["goocanvas"]
11
11
  _package.win32.dependencies = []
12
- _package.post_install_message = "This library is experimental."
13
12
  end
14
13
  package.define_tasks
15
14
 
@@ -20,7 +20,7 @@ end
20
20
  $LOAD_PATH.unshift(mkmf_gnome2_dir.to_s)
21
21
 
22
22
  module_name = "goocanvas"
23
- package_id = "goocanvas"
23
+ package_id = "goocanvas-2.0"
24
24
 
25
25
  begin
26
26
  require 'mkmf-gnome2'
@@ -30,9 +30,19 @@ rescue LoadError
30
30
  require 'mkmf-gnome2'
31
31
  end
32
32
 
33
- ["glib2", "atk", "pango", "gdk_pixbuf2", "gtk2"].each do |package|
33
+ [
34
+ "glib2",
35
+ "atk",
36
+ "pango",
37
+ "gdk_pixbuf2",
38
+ "gdk3",
39
+ "gtk3",
40
+ "gobject-introspection",
41
+ ].each do |package|
34
42
  directory = "#{package}#{version_suffix}"
35
- build_dir = "#{directory}/tmp/#{RUBY_PLATFORM}/#{package}/#{RUBY_VERSION}"
43
+ build_base_path = "#{directory}/tmp/#{RUBY_PLATFORM}"
44
+ package_library_name = package.gsub(/-/, "_")
45
+ build_dir = "#{build_base_path}/#{package_library_name}/#{RUBY_VERSION}"
36
46
  add_depend_package(package, "#{directory}/ext/#{package}",
37
47
  top_dir.to_s,
38
48
  :top_build_dir => top_build_dir.to_s,
@@ -55,15 +65,10 @@ check_cairo(rcairo_options) or exit(false)
55
65
 
56
66
  setup_win32(module_name, base_dir)
57
67
 
58
- unless required_pkg_config_package(package_id,
59
- :debian => "libgoocanvas-dev",
60
- :fedora => "goocanvas-devel",
61
- :macports => "goocanvas")
68
+ unless required_pkg_config_package(package_id)
62
69
  exit(false)
63
70
  end
64
71
 
65
- make_version_header("GOO_CANVAS", package_id, ".")
66
-
67
72
  create_pkg_config_file("Ruby/GooCanvas", package_id)
68
73
  $defs << "-DRUBY_GOO_CANVAS_COMPILATION"
69
74
  create_makefile(module_name)
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2011-2013 Ruby-GNOME2 Project Team
4
4
  * Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
@@ -19,197 +19,40 @@
19
19
  * MA 02110-1301 USA
20
20
  */
21
21
 
22
- #include "rbgoocanvasprivate.h"
22
+ #include "rbgoocanvas.h"
23
23
 
24
- #define RG_TARGET_NAMESPACE cCanvas
25
- #define SELF(self) RVAL2GOOCANVAS(self)
26
-
27
- void
28
- rb_goo_canvas_initialize_item_object(VALUE obj, GooCanvasItem *item)
29
- {
30
- g_object_ref_sink(item);
31
- G_INITIALIZE(obj, item);
32
- }
33
-
34
- static VALUE
35
- rg_initialize(VALUE self)
36
- {
37
- RBGTK_INITIALIZE(self, goo_canvas_new());
38
- return Qnil;
39
- }
40
-
41
- static VALUE
42
- rg_set_bounds(VALUE self, VALUE left, VALUE top,
43
- VALUE right, VALUE bottom)
44
- {
45
- goo_canvas_set_bounds(SELF(self), NUM2DBL(left), NUM2DBL(top),
46
- NUM2DBL(right), NUM2DBL(bottom));
47
- return self;
48
- }
49
-
50
- static VALUE
51
- rg_root_item(VALUE self)
52
- {
53
- VALUE root;
54
-
55
- root = GOBJ2RVAL(goo_canvas_get_root_item(SELF(self)));
56
- G_CHILD_ADD(self, root);
57
-
58
- return root;
59
- }
60
-
61
- static VALUE
62
- rg_grab_focus(int argc, VALUE *argv, VALUE self)
24
+ static void
25
+ rgoo_canvas_mark(gpointer object)
63
26
  {
64
- VALUE item;
27
+ GooCanvas *canvas = object;
28
+ GooCanvasItem *root_item;
65
29
 
66
- if (rb_scan_args(argc, argv, "01", &item) == 1) {
67
- goo_canvas_grab_focus(SELF(self), RVAL2GOOCANVASITEM(item));
68
- } else {
69
- rb_call_super(0, 0);
30
+ rbgobj_gc_mark_instance(object);
31
+ root_item = goo_canvas_get_root_item(canvas);
32
+ if (root_item) {
33
+ rbgobj_gc_mark_instance(root_item);
70
34
  }
71
-
72
- return self;
73
35
  }
74
36
 
75
- static VALUE
76
- rg_pointer_grab(VALUE self, VALUE item, VALUE event_mask, VALUE cursor, VALUE etime)
37
+ static void
38
+ rgoo_canvas_item_mark(gpointer object)
77
39
  {
78
- return GENUM2RVAL(
79
- goo_canvas_pointer_grab(SELF(self), RVAL2GOOCANVASITEM(item),
80
- NUM2INT(event_mask),
81
- (GdkCursor *)RVAL2BOXED(cursor, GDK_TYPE_CURSOR),
82
- NIL_P(etime) ? 0 : NUM2UINT(etime)),
83
- GDK_TYPE_GRAB_STATUS);
84
- }
40
+ GooCanvasItem *item = object;
41
+ gint i, n_children;
85
42
 
86
- static VALUE
87
- rg_pointer_ungrab(VALUE self, VALUE item, VALUE etime)
88
- {
89
- goo_canvas_pointer_ungrab(SELF(self), RVAL2GOOCANVASITEM(item),
90
- NIL_P(etime) ? 0 : NUM2UINT(etime));
91
- return self;
92
- }
43
+ rbgobj_gc_mark_instance(object);
93
44
 
94
- static VALUE
95
- rg_render(VALUE self, VALUE cr, VALUE rb_bounds, VALUE scale)
96
- {
97
- GooCanvasBounds bounds;
98
-
99
- goo_canvas_render(SELF(self), RVAL2CRCONTEXT(cr),
100
- RVAL2GCBOUNDS(rb_bounds, &bounds),
101
- NUM2DBL(scale));
102
- return self;
103
- }
104
-
105
- static VALUE
106
- rg_scroll_to(VALUE self, VALUE left, VALUE top)
107
- {
108
- goo_canvas_scroll_to(SELF(self), NUM2DBL(left), NUM2DBL(top));
109
- return self;
110
- }
111
-
112
- static VALUE
113
- rg_update(VALUE self)
114
- {
115
- goo_canvas_update(SELF(self));
116
- return self;
117
- }
118
-
119
- static VALUE
120
- rg_request_update(VALUE self)
121
- {
122
- goo_canvas_request_update(SELF(self));
123
- return self;
124
- }
125
-
126
- static VALUE
127
- rg_convert_from_pixels(VALUE self, VALUE rb_x, VALUE rb_y)
128
- {
129
- double x = NUM2DBL(rb_x);
130
- double y = NUM2DBL(rb_y);
131
- goo_canvas_convert_from_pixels(SELF(self), &x, &y);
132
- return rb_ary_new3(2, INT2NUM(x), INT2NUM(y));
133
- }
134
-
135
- static VALUE
136
- rg_convert_to_pixels(VALUE self, VALUE rb_x, VALUE rb_y)
137
- {
138
- double x = NUM2DBL(rb_x);
139
- double y = NUM2DBL(rb_y);
140
- goo_canvas_convert_to_pixels(SELF(self), &x, &y);
141
- return rb_ary_new3(2, INT2NUM(x), INT2NUM(y));
142
- }
143
-
144
- static VALUE
145
- rg_get_item_at(VALUE self, VALUE x, VALUE y, VALUE b)
146
- {
147
- GooCanvasItem *item;
148
- item = goo_canvas_get_item_at(SELF(self),
149
- NUM2DBL(x),
150
- NUM2DBL(y),
151
- RVAL2CBOOL(b));
152
- return GOBJ2RVAL(item);
153
- }
154
-
155
- static VALUE
156
- rg_get_items_at(VALUE self, VALUE x, VALUE y, VALUE b)
157
- {
158
- return GLIST2ARYF(goo_canvas_get_items_at(SELF(self),
159
- NUM2DBL(x),
160
- NUM2DBL(y),
161
- RVAL2CBOOL(b)));
162
- }
163
-
164
- static VALUE
165
- rg_bounds(VALUE self)
166
- {
167
- double left, top, right, bottom;
168
- goo_canvas_get_bounds(SELF(self),
169
- &left,
170
- &top,
171
- &right,
172
- &bottom);
173
- return rb_ary_new3(4, INT2NUM(left), INT2NUM(top), INT2NUM(right), INT2NUM(bottom));
45
+ n_children = goo_canvas_item_get_n_children(item);
46
+ for (i = 0; i < n_children; i++) {
47
+ GooCanvasItem *child;
48
+ child = goo_canvas_item_get_child(item, i);
49
+ rbgobj_gc_mark_instance(child);
50
+ }
174
51
  }
175
52
 
176
53
  void
177
54
  Init_goocanvas(void)
178
55
  {
179
- Init_goo();
180
-
181
- VALUE RG_TARGET_NAMESPACE;
182
-
183
- RG_TARGET_NAMESPACE = G_DEF_CLASS(GOO_TYPE_CANVAS, "Canvas", mGoo);
184
- VALUE mCairo = rb_const_get(rb_mKernel, rb_intern("Cairo"));
185
-
186
- RG_DEF_METHOD(initialize, 0);
187
- RG_DEF_METHOD(set_bounds, 4);
188
- RG_DEF_METHOD(bounds, 0);
189
- RG_DEF_METHOD(root_item, 0);
190
- RG_DEF_METHOD(grab_focus, -1);
191
- RG_DEF_METHOD(pointer_grab, 4);
192
- RG_DEF_METHOD(pointer_ungrab, 2);
193
- RG_DEF_METHOD(render, 3);
194
- RG_DEF_METHOD(scroll_to, 2);
195
- RG_DEF_METHOD(update, 0);
196
- RG_DEF_METHOD(request_update, 0);
197
- RG_DEF_METHOD(convert_from_pixels, 2);
198
- RG_DEF_METHOD(convert_to_pixels, 2);
199
- RG_DEF_METHOD(get_item_at, 3);
200
- RG_DEF_METHOD(get_items_at, 3);
201
-
202
- Init_goocanvasitem(mGoo); /* Goo::CanvasItem */
203
- Init_goocanvastext(mGoo); /* Goo::CanvasText */
204
- Init_goocanvasrect(mGoo); /* Goo::CanvasRect */
205
- Init_goocanvasellipse(mGoo); /* Goo::CanvasEllipse */
206
- Init_goocanvaspolyline(mGoo); /* Goo::CanvasPolyline */
207
- Init_goocanvaspoints(mGoo); /* Goo::CanvasPoints */
208
- Init_goocanvasimage(mGoo); /* Goo::CanvasImage */
209
- Init_goocanvastable(mGoo); /* Goo::CanvasTable */
210
- Init_goocanvaswidget(mGoo); /* Goo::CanvasWidget */
211
- Init_goocanvasstyle(mGoo); /* Goo::CanvasStyle */
212
- Init_goocanvasgroup(mGoo); /* Goo::CanvasGroup */
213
- Init_goocairopattern(mCairo);
214
- Init_goocairomatrix(mCairo);
56
+ rbgobj_register_mark_func(GOO_TYPE_CANVAS, rgoo_canvas_mark);
57
+ rbgobj_register_mark_func(GOO_TYPE_CANVAS_ITEM, rgoo_canvas_item_mark);
215
58
  }
@@ -1,7 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
3
+ * Copyright (C) 2011-2013 Ruby-GNOME2 Project Team
5
4
  *
6
5
  * This library is free software; you can redistribute it and/or
7
6
  * modify it under the terms of the GNU Lesser General Public
@@ -22,24 +21,9 @@
22
21
  #ifndef __RBGOOCANVAS_H__
23
22
  #define __RBGOOCANVAS_H__
24
23
 
25
- #include <rb_cairo.h>
26
- #include <rbgtk.h>
24
+ #include <rbgobject.h>
27
25
  #include <goocanvas.h>
28
26
 
29
- #include "rbgoo_canvasversion.h"
30
- #include "rbgoocanvasconversions.h"
31
-
32
- #define RVAL2GCBOUNDS(obj, bounds) \
33
- (ruby_to_goo_canvas_bounds(obj, bounds))
34
-
35
- #define RVAL2GTKWIDGET(obj) GTK_WIDGET(RVAL2GOBJ(obj))
36
-
37
- #define RB_GOO_CANVAS_ITEM_INITIALIZE(obj, item) \
38
- (rb_goo_canvas_initialize_item_object(obj, GOO_CANVAS_ITEM(item)))
39
-
40
- void rb_goo_canvas_initialize_item_object(VALUE obj, GooCanvasItem *item);
41
- GooCanvasBounds *ruby_to_goo_canvas_bounds(VALUE rb_bounds, GooCanvasBounds *dest_bounds);
42
-
43
- extern VALUE mGoo;
27
+ extern void Init_goocanvas(void);
44
28
 
45
29
  #endif /* __RBGOOCANVAS_H__ */
@@ -14,28 +14,19 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
- require "gtk3"
18
- require "gobject-introspection"
19
-
20
- base_dir = Pathname.new(__FILE__).dirname.dirname.dirname.expand_path
21
- vendor_dir = base_dir + "vendor" + "local"
22
- vendor_bin_dir = vendor_dir + "bin"
23
- GLib.prepend_environment_path(vendor_bin_dir)
24
-
25
17
  module Goo
26
- LOG_DOMAIN = "GooCanvas"
27
- GLib::Log.set_log_domain(LOG_DOMAIN)
28
-
29
- @initialized = false
30
- class << self
31
- def init
32
- return if @initialized
33
- @initialized = true
34
- loader = Loader.new(self)
35
- loader.load("GooCanvas")
18
+ module CanvasItem
19
+ alias_method :remove_child_raw, :remove_child
20
+ private :remove_child_raw
21
+ def remove_child(child_or_position)
22
+ if child_or_position.is_a?(CanvasItem)
23
+ child = child_or_position
24
+ position = find_child(child)
25
+ else
26
+ position = child_or_position
27
+ child = get_child(position)
28
+ end
29
+ remove_child_raw(position)
36
30
  end
37
31
  end
38
-
39
- class Loader < GObjectIntrospection::Loader
40
- end
41
32
  end
@@ -1,155 +1,72 @@
1
- require 'gtk2'
2
- require 'cairo'
1
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3
16
 
4
- base_dir = Pathname.new(__FILE__).dirname.dirname.expand_path
17
+ require "gtk3"
18
+ require "gobject-introspection"
19
+
20
+ base_dir = Pathname.new(__FILE__).dirname.dirname.dirname.expand_path
5
21
  vendor_dir = base_dir + "vendor" + "local"
6
22
  vendor_bin_dir = vendor_dir + "bin"
7
23
  GLib.prepend_dll_path(vendor_bin_dir)
8
- begin
9
- major, minor, micro, = RUBY_VERSION.split(/\./)
10
- require "#{major}.#{minor}/goocanvas.so"
11
- rescue LoadError
12
- require 'goocanvas.so'
13
- end
14
-
15
- module Goo
16
- LOG_DOMAIN="Goo"
17
-
18
- def self.args_to_hash(args)
19
- hash = args.pop if args.last.respond_to?(:to_hash)
20
- hash ||= Hash.new
21
- (args.length/2).times do |i|
22
- key_index, value_index = i*2, i*2+1
23
- hash[args[key_index]] = args[value_index]
24
- end
25
- hash
26
- end
27
-
28
- module PropsInit
29
- def init_props(*args)
30
- hash = Goo.args_to_hash(args)
31
- hash.each_pair { |key, value| set_property(key.to_s.gsub(/-/, '_').to_sym, value) }
32
- end
33
-
34
- def self.append_features(klass)
35
- super
36
- arity = klass.instance_method(:initialize).arity
37
- raise 'the initialize method of a class including PropsInit must have a fixed arity' if arity < 0
38
- args_list = (1..arity).collect { |i| "param#{i}" }.join(", ")
39
- klass.module_eval <<-END
40
- alias :_initialize :initialize
41
- def initialize(#{args_list}, *args)
42
- _initialize(#{args_list})
43
- init_props(*args)
44
- end
45
-
46
- alias :_set_property :set_property
47
- def set_property(prop_name, value)
48
- pspec = self.class.property(prop_name)
49
- value = value.to_goo if pspec.value_type.name =~ /^GooCairo/ and value.respond_to?(:to_goo)
50
- _set_property(prop_name, value)
51
- end
52
- END
53
- end
54
- end
55
-
56
- module CanvasItem
57
- def set_child_properties(child, *args)
58
- hash = Goo.args_to_hash(args)
59
- hash.each_pair { |key, value| set_child_property(child, key, value) }
60
- end
61
-
62
- def bounds
63
- [x1, x2, y1, y2]
64
- end
65
-
66
- def width
67
- x2 - x1
68
- end
69
-
70
- def height
71
- y2 - y1
72
- end
73
-
74
- def x
75
- x1
76
- end
77
-
78
- def y
79
- y1
80
- end
81
- end
82
-
83
- class CanvasText
84
- include PropsInit
85
- end
86
24
 
87
- class CanvasRect
88
- include PropsInit
25
+ if vendor_dir.exist?
26
+ begin
27
+ require "gobject-introspection"
28
+ vendor_girepository_dir = vendor_dir + "lib" + "girepository-1.0"
29
+ GObjectIntrospection.prepend_typelib_path(vendor_girepository_dir)
30
+ rescue LoadError
89
31
  end
32
+ end
90
33
 
91
- class CanvasEllipse
92
- include PropsInit
93
- end
34
+ module Goo
35
+ LOG_DOMAIN = "GooCanvas"
36
+ GLib::Log.set_log_domain(LOG_DOMAIN)
94
37
 
95
- class CanvasPolyline
96
- include PropsInit
97
- def initialize(parent, close_path, points, *args)
98
- _initialize(parent, close_path)
99
- set_points(points)
100
- init_props(*args)
101
- end
102
-
103
- def set_points(points)
104
- points = CanvasPoints.new(points) unless points.instance_of?(CanvasPoints)
105
- set_property(:points, points)
106
- end
107
- alias :points= :set_points
108
-
109
- def self.new_line(parent, x1, y1, x2, y2, *args)
110
- self.new(parent, false, [ x1, y1, x2, y2 ], *args)
111
- end
112
- end
113
-
114
- class CanvasPoints
115
- alias :_initialize :initialize
116
- def initialize(arg)
117
- if arg.respond_to?(:to_ary)
118
- points = arg.flatten
119
- num_points = points.length / 2
120
- _initialize(num_points)
121
- num_points.times { |i| self[i] = [ points[i*2], points[i*2+1] ] }
38
+ class << self
39
+ def const_missing(name)
40
+ init
41
+ if const_defined?(name)
42
+ const_get(name)
122
43
  else
123
- _initialize(arg)
44
+ super
124
45
  end
125
46
  end
126
-
127
- def each
128
- num_points.times { |i| yield self[i] }
129
- end
130
47
 
131
- def to_a
132
- a = []
133
- each { |e| a.push(e) }
134
- a
48
+ def init
49
+ loader = Loader.new(self)
50
+ loader.load("GooCanvas")
51
+ begin
52
+ major, minor, _ = RUBY_VERSION.split(/\./)
53
+ require "#{major}.#{minor}/goocanvas.so"
54
+ rescue LoadError
55
+ require "goocanvas.so"
56
+ end
57
+ require "goo/canvas-item"
58
+ class << self
59
+ remove_method(:init)
60
+ remove_method(:const_missing)
61
+ end
135
62
  end
136
63
  end
137
64
 
138
- class CanvasTable
139
- include PropsInit
140
- end
141
-
142
- class CanvasGroup
143
- include PropsInit
144
- end
145
-
146
- class CanvasWidget
147
- include PropsInit
148
- end
149
-
150
- class CanvasImage
151
- include PropsInit
65
+ class Loader < GObjectIntrospection::Loader
66
+ private
67
+ def load_field(info, i, field_info, klass)
68
+ return if field_info.name == "parent"
69
+ super
70
+ end
152
71
  end
153
72
  end
154
-
155
- GLib::Log.set_log_domain(Goo::LOG_DOMAIN)