goocanvas 0.90.6
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/ChangeLog +87 -0
- data/README +37 -0
- data/Rakefile +14 -0
- data/ext/goocanvas/Makefile +162 -0
- data/ext/goocanvas/depend +5 -0
- data/ext/goocanvas/extconf.rb +66 -0
- data/ext/goocanvas/goocanvas.def +2 -0
- data/ext/goocanvas/goocanvas.so +0 -0
- data/ext/goocanvas/rbgoo_canvasversion.h +25 -0
- data/ext/goocanvas/rbgoocairo.c +74 -0
- data/ext/goocanvas/rbgoocairo.o +0 -0
- data/ext/goocanvas/rbgoocanvas.c +236 -0
- data/ext/goocanvas/rbgoocanvas.h +66 -0
- data/ext/goocanvas/rbgoocanvas.o +0 -0
- data/ext/goocanvas/rbgoocanvasellipse.c +50 -0
- data/ext/goocanvas/rbgoocanvasellipse.o +0 -0
- data/ext/goocanvas/rbgoocanvasgroup.c +41 -0
- data/ext/goocanvas/rbgoocanvasgroup.o +0 -0
- data/ext/goocanvas/rbgoocanvasimage.c +45 -0
- data/ext/goocanvas/rbgoocanvasimage.o +0 -0
- data/ext/goocanvas/rbgoocanvasitem.c +358 -0
- data/ext/goocanvas/rbgoocanvasitem.o +0 -0
- data/ext/goocanvas/rbgoocanvaspolyline.c +102 -0
- data/ext/goocanvas/rbgoocanvaspolyline.o +0 -0
- data/ext/goocanvas/rbgoocanvasrect.c +47 -0
- data/ext/goocanvas/rbgoocanvasrect.o +0 -0
- data/ext/goocanvas/rbgoocanvasstyle.c +61 -0
- data/ext/goocanvas/rbgoocanvasstyle.o +0 -0
- data/ext/goocanvas/rbgoocanvastable.c +41 -0
- data/ext/goocanvas/rbgoocanvastable.o +0 -0
- data/ext/goocanvas/rbgoocanvastext.c +58 -0
- data/ext/goocanvas/rbgoocanvastext.o +0 -0
- data/ext/goocanvas/rbgoocanvaswidget.c +48 -0
- data/ext/goocanvas/rbgoocanvaswidget.o +0 -0
- data/ext/goocanvas/rbgooutils.c +44 -0
- data/ext/goocanvas/rbgooutils.o +0 -0
- data/ext/goocanvas/ruby-goocanvas.pc +3 -0
- data/extconf.rb +49 -0
- data/lib/goocanvas.rb +145 -0
- data/sample/demo-arrowhead.rb +315 -0
- data/sample/demo-fifteen.rb +218 -0
- data/sample/demo-primitives.rb +720 -0
- data/sample/demo.rb +84 -0
- data/sample/flower.png +0 -0
- data/sample/scalability-demo.rb +130 -0
- data/sample/simple-demo.rb +35 -0
- data/sample/table-demo.rb +137 -0
- data/sample/toroid.png +0 -0
- data/sample/units-demo.rb +80 -0
- data/sample/widgets-demo.rb +197 -0
- metadata +133 -0
Binary file
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgoocanvasrect.c 3288 2008-09-13 10:07:44Z ktou $ */
|
3
|
+
/* GooCanvasRect
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rb_goo_canvas_rect_new(VALUE self, VALUE parent, VALUE x, VALUE y,
|
25
|
+
VALUE width, VALUE height)
|
26
|
+
{
|
27
|
+
GooCanvasItem *item;
|
28
|
+
item = goo_canvas_rect_new(RVAL2GCI(parent),
|
29
|
+
NUM2DBL(x),
|
30
|
+
NUM2DBL(y),
|
31
|
+
NUM2DBL(width),
|
32
|
+
NUM2DBL(height),
|
33
|
+
NULL);
|
34
|
+
RB_GOO_CANVAS_ITEM_INITIALIZE(self, item);
|
35
|
+
G_CHILD_ADD(parent, self);
|
36
|
+
return Qnil;
|
37
|
+
}
|
38
|
+
|
39
|
+
void
|
40
|
+
Init_goocanvasrect(void)
|
41
|
+
{
|
42
|
+
VALUE GooCanvasRect;
|
43
|
+
|
44
|
+
GooCanvasRect = G_DEF_CLASS(GOO_TYPE_CANVAS_RECT, "CanvasRect", mGoo);
|
45
|
+
|
46
|
+
rb_define_method(GooCanvasRect, "initialize", rb_goo_canvas_rect_new, 5);
|
47
|
+
}
|
Binary file
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgoocanvasstyle.c 3288 2008-09-13 10:07:44Z ktou $ */
|
3
|
+
/* GooCanvasStyle
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rb_goo_canvas_style_new(VALUE self)
|
25
|
+
{
|
26
|
+
G_INITIALIZE(self, goo_canvas_style_new());
|
27
|
+
return Qnil;
|
28
|
+
}
|
29
|
+
|
30
|
+
/* TODO: make it more generic, with maybe some part in Ruby */
|
31
|
+
static VALUE
|
32
|
+
rb_goo_canvas_style_set_fill_pattern(VALUE self, VALUE value)
|
33
|
+
{
|
34
|
+
GValue gval = {0,};
|
35
|
+
cairo_pattern_t *pattern;
|
36
|
+
|
37
|
+
g_value_init(&gval, GOO_TYPE_CAIRO_PATTERN);
|
38
|
+
pattern = RVAL2CRPATTERN(value);
|
39
|
+
g_value_take_boxed(&gval, pattern);
|
40
|
+
goo_canvas_style_set_property(RVAL2GCS(self),
|
41
|
+
goo_canvas_style_fill_pattern_id,
|
42
|
+
&gval);
|
43
|
+
g_value_unset(&gval);
|
44
|
+
|
45
|
+
G_CHILD_SET(self, rb_intern("fill_pattern"), value);
|
46
|
+
return self;
|
47
|
+
}
|
48
|
+
|
49
|
+
void
|
50
|
+
Init_goocanvasstyle(void)
|
51
|
+
{
|
52
|
+
VALUE GooCanvasStyle;
|
53
|
+
|
54
|
+
GooCanvasStyle = G_DEF_CLASS(GOO_TYPE_CANVAS_STYLE, "CanvasStyle", mGoo);
|
55
|
+
|
56
|
+
rb_define_method(GooCanvasStyle, "initialize", rb_goo_canvas_style_new, 0);
|
57
|
+
rb_define_method(GooCanvasStyle, "set_fill_pattern",
|
58
|
+
rb_goo_canvas_style_set_fill_pattern, 1);
|
59
|
+
|
60
|
+
G_DEF_SETTERS(GooCanvasStyle);
|
61
|
+
}
|
Binary file
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgoocanvastable.c 3288 2008-09-13 10:07:44Z ktou $ */
|
3
|
+
/* GooCanvasTable
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rb_goo_canvas_table_new(VALUE self, VALUE parent)
|
25
|
+
{
|
26
|
+
GooCanvasItem *item;
|
27
|
+
item = goo_canvas_table_new(RVAL2GCI(parent), NULL);
|
28
|
+
RB_GOO_CANVAS_ITEM_INITIALIZE(self, item);
|
29
|
+
G_CHILD_ADD(parent, self);
|
30
|
+
return Qnil;
|
31
|
+
}
|
32
|
+
|
33
|
+
void
|
34
|
+
Init_goocanvastable(void)
|
35
|
+
{
|
36
|
+
VALUE GooCanvasTable;
|
37
|
+
|
38
|
+
GooCanvasTable = G_DEF_CLASS(GOO_TYPE_CANVAS_TABLE, "CanvasTable", mGoo);
|
39
|
+
|
40
|
+
rb_define_method(GooCanvasTable, "initialize", rb_goo_canvas_table_new, 1);
|
41
|
+
}
|
Binary file
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgoocanvastext.c 3288 2008-09-13 10:07:44Z ktou $ */
|
3
|
+
/* GooCanvasText
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rb_goo_canvas_text_new(VALUE self, VALUE parent, VALUE string,
|
25
|
+
VALUE x, VALUE y, VALUE width, VALUE anchor)
|
26
|
+
{
|
27
|
+
GooCanvasItem *item;
|
28
|
+
item = goo_canvas_text_new(RVAL2GCI(parent),
|
29
|
+
NIL_P(string) ? NULL : StringValueCStr(string),
|
30
|
+
NUM2DBL(x),
|
31
|
+
NUM2DBL(y),
|
32
|
+
NUM2DBL(width),
|
33
|
+
RVAL2GENUM(anchor, GTK_TYPE_ANCHOR_TYPE),
|
34
|
+
NULL);
|
35
|
+
RB_GOO_CANVAS_ITEM_INITIALIZE(self, item);
|
36
|
+
G_CHILD_ADD(parent, self);
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
void
|
41
|
+
Init_goocanvastext(void)
|
42
|
+
{
|
43
|
+
VALUE GooCanvasText;
|
44
|
+
|
45
|
+
GooCanvasText = G_DEF_CLASS(GOO_TYPE_CANVAS_TEXT, "CanvasText", mGoo);
|
46
|
+
|
47
|
+
rb_define_method(GooCanvasText, "initialize", rb_goo_canvas_text_new, 6);
|
48
|
+
|
49
|
+
#if 0
|
50
|
+
GooCanvasItemModel* goo_canvas_text_model_new (GooCanvasItemModel *parent,
|
51
|
+
const char *string,
|
52
|
+
gdouble x,
|
53
|
+
gdouble y,
|
54
|
+
gdouble width,
|
55
|
+
GtkAnchorType anchor,
|
56
|
+
...);
|
57
|
+
#endif
|
58
|
+
}
|
Binary file
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgoocanvaswidget.c 3288 2008-09-13 10:07:44Z ktou $ */
|
3
|
+
/* GooCanvasWidget
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rb_goo_canvas_widget_new(VALUE self, VALUE parent, VALUE widget,
|
25
|
+
VALUE x, VALUE y, VALUE width, VALUE height)
|
26
|
+
{
|
27
|
+
GooCanvasItem *item;
|
28
|
+
item = goo_canvas_widget_new(RVAL2GCI(parent),
|
29
|
+
RVAL2GTK_WIDGET(widget),
|
30
|
+
NUM2DBL(x),
|
31
|
+
NUM2DBL(y),
|
32
|
+
NUM2DBL(width),
|
33
|
+
NUM2DBL(height),
|
34
|
+
NULL);
|
35
|
+
RB_GOO_CANVAS_ITEM_INITIALIZE(self, item);
|
36
|
+
G_CHILD_ADD(parent, self);
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
void
|
41
|
+
Init_goocanvaswidget(void)
|
42
|
+
{
|
43
|
+
VALUE GooCanvasWidget;
|
44
|
+
|
45
|
+
GooCanvasWidget = G_DEF_CLASS(GOO_TYPE_CANVAS_WIDGET, "CanvasWidget", mGoo);
|
46
|
+
|
47
|
+
rb_define_method(GooCanvasWidget, "initialize", rb_goo_canvas_widget_new, 6);
|
48
|
+
}
|
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgooutils.c 3426 2008-11-01 14:20:52Z ktou $ */
|
3
|
+
/* Utility functions
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
GooCanvasBounds *
|
24
|
+
ruby_to_goo_canvas_bounds(VALUE rb_bounds, GooCanvasBounds *dest_bounds)
|
25
|
+
{
|
26
|
+
if (rb_bounds == Qnil)
|
27
|
+
return NULL;
|
28
|
+
|
29
|
+
if (TYPE(rb_bounds) != T_ARRAY) {
|
30
|
+
VALUE rb_array;
|
31
|
+
rb_array = rb_funcall(rb_bounds, rb_intern("to_a"), 0);
|
32
|
+
return ruby_to_goo_canvas_bounds(rb_array, dest_bounds);
|
33
|
+
}
|
34
|
+
|
35
|
+
if (RARRAY_LEN(rb_bounds) != 4)
|
36
|
+
rb_raise(rb_eRuntimeError, "Bounds must be arrays of length 4");
|
37
|
+
|
38
|
+
dest_bounds->x1 = NUM2DBL(RARRAY_PTR(rb_bounds)[0]);
|
39
|
+
dest_bounds->y1 = NUM2DBL(RARRAY_PTR(rb_bounds)[1]);
|
40
|
+
dest_bounds->x2 = NUM2DBL(RARRAY_PTR(rb_bounds)[2]);
|
41
|
+
dest_bounds->y2 = NUM2DBL(RARRAY_PTR(rb_bounds)[3]);
|
42
|
+
|
43
|
+
return dest_bounds;
|
44
|
+
}
|
Binary file
|
data/extconf.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'mkmf'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
package = "goocanvas"
|
9
|
+
|
10
|
+
base_dir = Pathname(__FILE__).dirname.expand_path
|
11
|
+
ext_dir = base_dir + "ext" + package
|
12
|
+
mkmf_gnome2_dir = base_dir + 'lib'
|
13
|
+
|
14
|
+
ruby = File.join(RbConfig::CONFIG['bindir'],
|
15
|
+
RbConfig::CONFIG['ruby_install_name'] +
|
16
|
+
RbConfig::CONFIG["EXEEXT"])
|
17
|
+
|
18
|
+
build_dir = Pathname("ext") + package
|
19
|
+
FileUtils.mkdir_p(build_dir.to_s) unless build_dir.exist?
|
20
|
+
extconf_rb_path = ext_dir + "extconf.rb"
|
21
|
+
system(ruby, "-C", build_dir.to_s, extconf_rb_path.to_s, *ARGV) || exit(false)
|
22
|
+
|
23
|
+
create_makefile(package)
|
24
|
+
FileUtils.mv("Makefile", "Makefile.lib")
|
25
|
+
|
26
|
+
File.open("Makefile", "w") do |makefile|
|
27
|
+
makefile.puts(<<-EOM)
|
28
|
+
all:
|
29
|
+
(cd ext/#{package} && $(MAKE))
|
30
|
+
$(MAKE) -f Makefile.lib
|
31
|
+
|
32
|
+
install:
|
33
|
+
(cd ext/#{package} && $(MAKE) install)
|
34
|
+
$(MAKE) -f Makefile.lib install
|
35
|
+
|
36
|
+
site-install:
|
37
|
+
(cd ext/#{package} && $(MAKE) site-install)
|
38
|
+
$(MAKE) -f Makefile.lib site-install
|
39
|
+
|
40
|
+
clean:
|
41
|
+
(cd ext/#{package} && $(MAKE) clean)
|
42
|
+
$(MAKE) -f Makefile.lib clean
|
43
|
+
|
44
|
+
distclean:
|
45
|
+
(cd ext/#{package} && $(MAKE) distclean)
|
46
|
+
$(MAKE) -f Makefile.lib distclean
|
47
|
+
@rm -f Makefile.lib
|
48
|
+
EOM
|
49
|
+
end
|
data/lib/goocanvas.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require 'cairo'
|
3
|
+
require 'goocanvas.so'
|
4
|
+
|
5
|
+
module Goo
|
6
|
+
LOG_DOMAIN="Goo"
|
7
|
+
|
8
|
+
def self.args_to_hash(args)
|
9
|
+
hash = args.pop if args.last.respond_to?(:to_hash)
|
10
|
+
hash ||= Hash.new
|
11
|
+
(args.length/2).times do |i|
|
12
|
+
key_index, value_index = i*2, i*2+1
|
13
|
+
hash[args[key_index]] = args[value_index]
|
14
|
+
end
|
15
|
+
hash
|
16
|
+
end
|
17
|
+
|
18
|
+
module PropsInit
|
19
|
+
def init_props(*args)
|
20
|
+
hash = Goo.args_to_hash(args)
|
21
|
+
hash.each_pair { |key, value| set_property(key.to_s.gsub(/-/, '_').to_sym, value) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.append_features(klass)
|
25
|
+
super
|
26
|
+
arity = klass.instance_method(:initialize).arity
|
27
|
+
raise 'the initialize method of a class including PropsInit must have a fixed arity' if arity < 0
|
28
|
+
args_list = (1..arity).collect { |i| "param#{i}" }.join(", ")
|
29
|
+
klass.module_eval <<-END
|
30
|
+
alias :_initialize :initialize
|
31
|
+
def initialize(#{args_list}, *args)
|
32
|
+
_initialize(#{args_list})
|
33
|
+
init_props(*args)
|
34
|
+
end
|
35
|
+
|
36
|
+
alias :_set_property :set_property
|
37
|
+
def set_property(prop_name, value)
|
38
|
+
pspec = self.class.property(prop_name)
|
39
|
+
value = value.to_goo if pspec.value_type.name =~ /^GooCairo/ and value.respond_to?(:to_goo)
|
40
|
+
_set_property(prop_name, value)
|
41
|
+
end
|
42
|
+
END
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module CanvasItem
|
47
|
+
def set_child_properties(child, *args)
|
48
|
+
hash = Goo.args_to_hash(args)
|
49
|
+
hash.each_pair { |key, value| set_child_property(child, key, value) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def bounds
|
53
|
+
[x1, x2, y1, y2]
|
54
|
+
end
|
55
|
+
|
56
|
+
def width
|
57
|
+
x2 - x1
|
58
|
+
end
|
59
|
+
|
60
|
+
def height
|
61
|
+
y2 - y1
|
62
|
+
end
|
63
|
+
|
64
|
+
def x
|
65
|
+
x1
|
66
|
+
end
|
67
|
+
|
68
|
+
def y
|
69
|
+
y1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class CanvasText
|
74
|
+
include PropsInit
|
75
|
+
end
|
76
|
+
|
77
|
+
class CanvasRect
|
78
|
+
include PropsInit
|
79
|
+
end
|
80
|
+
|
81
|
+
class CanvasEllipse
|
82
|
+
include PropsInit
|
83
|
+
end
|
84
|
+
|
85
|
+
class CanvasPolyline
|
86
|
+
include PropsInit
|
87
|
+
def initialize(parent, close_path, points, *args)
|
88
|
+
_initialize(parent, close_path)
|
89
|
+
set_points(points)
|
90
|
+
init_props(*args)
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_points(points)
|
94
|
+
points = CanvasPoints.new(points) unless points.instance_of?(CanvasPoints)
|
95
|
+
set_property(:points, points)
|
96
|
+
end
|
97
|
+
alias :points= :set_points
|
98
|
+
|
99
|
+
def self.new_line(parent, x1, y1, x2, y2, *args)
|
100
|
+
self.new(parent, false, [ x1, y1, x2, y2 ], *args)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class CanvasPoints
|
105
|
+
alias :_initialize :initialize
|
106
|
+
def initialize(arg)
|
107
|
+
if arg.respond_to?(:to_ary)
|
108
|
+
points = arg.flatten
|
109
|
+
num_points = points.length / 2
|
110
|
+
_initialize(num_points)
|
111
|
+
num_points.times { |i| self[i] = [ points[i*2], points[i*2+1] ] }
|
112
|
+
else
|
113
|
+
_initialize(arg)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def each
|
118
|
+
num_points.times { |i| yield self[i] }
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_a
|
122
|
+
a = []
|
123
|
+
each { |e| a.push(e) }
|
124
|
+
a
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class CanvasTable
|
129
|
+
include PropsInit
|
130
|
+
end
|
131
|
+
|
132
|
+
class CanvasGroup
|
133
|
+
include PropsInit
|
134
|
+
end
|
135
|
+
|
136
|
+
class CanvasWidget
|
137
|
+
include PropsInit
|
138
|
+
end
|
139
|
+
|
140
|
+
class CanvasImage
|
141
|
+
include PropsInit
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
GLib::Log.set_log_domain(Goo::LOG_DOMAIN)
|