goocanvas 0.90.6-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/ChangeLog +87 -0
  2. data/README +37 -0
  3. data/Rakefile +14 -0
  4. data/ext/goocanvas/depend +5 -0
  5. data/ext/goocanvas/extconf.rb +66 -0
  6. data/ext/goocanvas/goocanvas.def +2 -0
  7. data/ext/goocanvas/rbgoocairo.c +74 -0
  8. data/ext/goocanvas/rbgoocanvas.c +236 -0
  9. data/ext/goocanvas/rbgoocanvas.h +66 -0
  10. data/ext/goocanvas/rbgoocanvasellipse.c +50 -0
  11. data/ext/goocanvas/rbgoocanvasgroup.c +41 -0
  12. data/ext/goocanvas/rbgoocanvasimage.c +45 -0
  13. data/ext/goocanvas/rbgoocanvasitem.c +358 -0
  14. data/ext/goocanvas/rbgoocanvaspolyline.c +102 -0
  15. data/ext/goocanvas/rbgoocanvasrect.c +47 -0
  16. data/ext/goocanvas/rbgoocanvasstyle.c +61 -0
  17. data/ext/goocanvas/rbgoocanvastable.c +41 -0
  18. data/ext/goocanvas/rbgoocanvastext.c +58 -0
  19. data/ext/goocanvas/rbgoocanvaswidget.c +48 -0
  20. data/ext/goocanvas/rbgooutils.c +44 -0
  21. data/extconf.rb +49 -0
  22. data/lib/1.8/goocanvas.so +0 -0
  23. data/lib/1.9/goocanvas.so +0 -0
  24. data/lib/goocanvas.rb +145 -0
  25. data/sample/demo-arrowhead.rb +315 -0
  26. data/sample/demo-fifteen.rb +218 -0
  27. data/sample/demo-primitives.rb +720 -0
  28. data/sample/demo.rb +84 -0
  29. data/sample/flower.png +0 -0
  30. data/sample/scalability-demo.rb +130 -0
  31. data/sample/simple-demo.rb +35 -0
  32. data/sample/table-demo.rb +137 -0
  33. data/sample/toroid.png +0 -0
  34. data/sample/units-demo.rb +80 -0
  35. data/sample/widgets-demo.rb +197 -0
  36. data/vendor/local/bin/libgoocanvas-3.dll +0 -0
  37. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvas.h +334 -0
  38. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasatk.h +22 -0
  39. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasellipse.h +120 -0
  40. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasenumtypes.h +33 -0
  41. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasgrid.h +153 -0
  42. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasgroup.h +109 -0
  43. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasimage.h +121 -0
  44. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasitem.h +479 -0
  45. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasitemmodel.h +275 -0
  46. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasitemsimple.h +247 -0
  47. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasmarshal.h +61 -0
  48. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvaspath.h +116 -0
  49. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvaspolyline.h +176 -0
  50. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasprivate.h +59 -0
  51. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasrect.h +121 -0
  52. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasstyle.h +110 -0
  53. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvastable.h +139 -0
  54. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvastext.h +133 -0
  55. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvasutils.h +333 -0
  56. data/vendor/local/include/goocanvas-1.0.0/goocanvas/goocanvaswidget.h +66 -0
  57. data/vendor/local/include/goocanvas-1.0.0/goocanvas/stamp-goocanvasmarshal.h +1 -0
  58. data/vendor/local/lib/libgoocanvas.a +0 -0
  59. data/vendor/local/lib/libgoocanvas.dll.a +0 -0
  60. data/vendor/local/lib/pkgconfig/goocanvas.pc +13 -0
  61. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvas.html +1982 -0
  62. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasEllipse.html +269 -0
  63. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasEllipseModel.html +274 -0
  64. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasGrid.html +469 -0
  65. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasGridModel.html +476 -0
  66. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasGroup.html +183 -0
  67. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasGroupModel.html +184 -0
  68. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasImage.html +247 -0
  69. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasImageModel.html +252 -0
  70. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasItem.html +3014 -0
  71. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasItemModel.html +1764 -0
  72. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasItemModelSimple.html +298 -0
  73. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasItemSimple.html +809 -0
  74. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasPath.html +279 -0
  75. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasPathModel.html +280 -0
  76. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasPolyline.html +369 -0
  77. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasPolylineModel.html +375 -0
  78. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasRect.html +247 -0
  79. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasRectModel.html +252 -0
  80. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasStyle.html +489 -0
  81. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasTable.html +452 -0
  82. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasTableModel.html +452 -0
  83. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasText.html +324 -0
  84. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasTextModel.html +287 -0
  85. data/vendor/local/share/gtk-doc/html/goocanvas/GooCanvasWidget.html +266 -0
  86. data/vendor/local/share/gtk-doc/html/goocanvas/ch01.html +53 -0
  87. data/vendor/local/share/gtk-doc/html/goocanvas/ch02.html +50 -0
  88. data/vendor/local/share/gtk-doc/html/goocanvas/ch03.html +62 -0
  89. data/vendor/local/share/gtk-doc/html/goocanvas/ch04.html +60 -0
  90. data/vendor/local/share/gtk-doc/html/goocanvas/ch05.html +33 -0
  91. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-GooCanvas-Types.html +815 -0
  92. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-architecture.html +157 -0
  93. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-coordinates.html +106 -0
  94. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-creating-items.html +420 -0
  95. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-model-view-canvas.html +246 -0
  96. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-overview.html +106 -0
  97. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-simple-canvas.html +238 -0
  98. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas-wysiwyg.html +84 -0
  99. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas.devhelp +608 -0
  100. data/vendor/local/share/gtk-doc/html/goocanvas/goocanvas.devhelp2 +639 -0
  101. data/vendor/local/share/gtk-doc/html/goocanvas/home.png +0 -0
  102. data/vendor/local/share/gtk-doc/html/goocanvas/index.html +138 -0
  103. data/vendor/local/share/gtk-doc/html/goocanvas/index.sgml +814 -0
  104. data/vendor/local/share/gtk-doc/html/goocanvas/left.png +0 -0
  105. data/vendor/local/share/gtk-doc/html/goocanvas/right.png +0 -0
  106. data/vendor/local/share/gtk-doc/html/goocanvas/style.css +257 -0
  107. data/vendor/local/share/gtk-doc/html/goocanvas/up.png +0 -0
  108. data/vendor/local/share/gtk-doc/tmpl/goocanvas/dummy.sgml +0 -0
  109. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvas-unused.sgml +0 -0
  110. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvas.sgml +536 -0
  111. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasellipse.sgml +82 -0
  112. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasellipsemodel.sgml +82 -0
  113. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasgrid.sgml +176 -0
  114. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasgridmodel.sgml +176 -0
  115. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasgroup.sgml +58 -0
  116. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasgroupmodel.sgml +58 -0
  117. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasimage.sgml +81 -0
  118. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasimagemodel.sgml +81 -0
  119. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasitem.sgml +773 -0
  120. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasitemmodel.sgml +490 -0
  121. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasitemmodelsimple.sgml +135 -0
  122. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasitemsimple.sgml +254 -0
  123. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvaspath.sgml +64 -0
  124. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvaspathmodel.sgml +64 -0
  125. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvaspolyline.sgml +109 -0
  126. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvaspolylinemodel.sgml +109 -0
  127. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasrect.sgml +72 -0
  128. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasrectmodel.sgml +72 -0
  129. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasstyle.sgml +186 -0
  130. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvastable.sgml +158 -0
  131. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvastablemodel.sgml +158 -0
  132. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvastext.sgml +103 -0
  133. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvastextmodel.sgml +93 -0
  134. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvasutils.sgml +241 -0
  135. data/vendor/local/share/gtk-doc/tmpl/goocanvas/goocanvaswidget.sgml +73 -0
  136. metadata +218 -0
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }
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
Binary file
Binary file
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)
@@ -0,0 +1,315 @@
1
+ class CanvasSampleArrowhead < Gtk::VBox
2
+ LEFT = 50.0
3
+ RIGHT = 350.0
4
+ MIDDLE = 150.0
5
+ DEFAULT_WIDTH = 2
6
+ DEFAULT_SHAPE_A = 4
7
+ DEFAULT_SHAPE_B = 5
8
+ DEFAULT_SHAPE_C = 4
9
+
10
+ def initialize()
11
+ super(false, 4)
12
+ border_width = 4
13
+ show()
14
+
15
+ w = Gtk::Label.new <<-END
16
+ This demo allows you to edit arrowhead shapes. Drag the little boxes
17
+ to change the shape of the line and its arrowhead. You can see the
18
+ arrows at their normal scale on the right hand side of the window.
19
+ END
20
+ pack_start(w, false, false, 0)
21
+ w.show
22
+
23
+ w = Gtk::Alignment.new(0.5, 0.5, 0.0, 0.0)
24
+ pack_start(w, true, true, 0)
25
+ w.show
26
+
27
+ frame = Gtk::Frame.new
28
+ frame.shadow_type = Gtk::SHADOW_IN
29
+ w.add(frame)
30
+ frame.show
31
+
32
+ canvas = Goo::Canvas.new
33
+ root = canvas.root_item
34
+
35
+ canvas.set_size_request(500, 350)
36
+ canvas.set_bounds(0, 0, 500, 350)
37
+ frame.add(canvas)
38
+ canvas.show
39
+
40
+ canvas.instance_variable_set(:@width, DEFAULT_WIDTH)
41
+ canvas.instance_variable_set(:@shape_a, DEFAULT_SHAPE_A)
42
+ canvas.instance_variable_set(:@shape_b, DEFAULT_SHAPE_B)
43
+ canvas.instance_variable_set(:@shape_c, DEFAULT_SHAPE_C)
44
+
45
+ # Big arrow
46
+
47
+ item = Goo::CanvasPolyline.new_line(root,
48
+ LEFT, MIDDLE, RIGHT, MIDDLE,
49
+ :stroke_color => "mediumseagreen",
50
+ :end_arrow => true)
51
+ canvas.instance_variable_set(:@big_arrow, item)
52
+
53
+ # Arrow outline
54
+
55
+ item = Goo::CanvasPolyline.new(root, true, [],
56
+ :stroke_color, "black",
57
+ :line_width => 2.0,
58
+ :line_cap => Cairo::LINE_CAP_ROUND,
59
+ :line_join => Cairo::LINE_JOIN_ROUND)
60
+ canvas.instance_variable_set(:@outline, item)
61
+
62
+ # Drag boxes
63
+
64
+ create_drag_box(canvas, root, "width_drag_box")
65
+ create_drag_box(canvas, root, "shape_a_drag_box")
66
+ create_drag_box(canvas, root, "shape_b_c_drag_box")
67
+
68
+ # Dimensions
69
+
70
+ create_dimension(canvas, root, "width_arrow", "width_text", Gtk::ANCHOR_E)
71
+ create_dimension(canvas, root, "shape_a_arrow", "shape_a_text", Gtk::ANCHOR_N)
72
+ create_dimension(canvas, root, "shape_b_arrow", "shape_b_text", Gtk::ANCHOR_N)
73
+ create_dimension(canvas, root, "shape_c_arrow", "shape_c_text", Gtk::ANCHOR_W)
74
+
75
+ # Info
76
+
77
+ create_info(canvas, root, "width_info", LEFT, 260)
78
+ create_info(canvas, root, "shape_a_info", LEFT, 280)
79
+ create_info(canvas, root, "shape_b_info", LEFT, 300)
80
+ create_info(canvas, root, "shape_c_info", LEFT, 320)
81
+
82
+ # Division line
83
+
84
+ Goo::CanvasPolyline.new_line(root, RIGHT + 50, 0, RIGHT + 50, 1000,
85
+ :fill_color => "black", :line_width => 2.0)
86
+
87
+ # Sample arrows
88
+
89
+ create_sample_arrow(canvas, root, "sample_1",
90
+ RIGHT + 100, 30, RIGHT + 100, MIDDLE - 30)
91
+ create_sample_arrow(canvas, root, "sample_2",
92
+ RIGHT + 70, MIDDLE, RIGHT + 130, MIDDLE)
93
+ create_sample_arrow(canvas, root, "sample_3",
94
+ RIGHT + 70, MIDDLE + 30, RIGHT + 130, MIDDLE + 120)
95
+
96
+ # Done!
97
+ set_arrow_shape(canvas)
98
+ end
99
+
100
+ def set_dimension(canvas, arrow_name, text_name, x1, y1, x2, y2, tx, ty, dim)
101
+ points = [ x1, y1, x2, y2 ]
102
+
103
+ arrow = canvas.instance_variable_get("@#{arrow_name}")
104
+ arrow.points = points
105
+
106
+ text = canvas.instance_variable_get("@#{text_name}")
107
+ text.text = dim.to_s
108
+ text.x = tx
109
+ text.y = ty
110
+ end
111
+
112
+ def move_drag_box(item, x, y)
113
+ item.x = x - 5.0
114
+ item.y = y - 5.0
115
+ end
116
+
117
+ def set_arrow_shape(canvas)
118
+ width = canvas.instance_variable_get(:@width)
119
+ shape_a = canvas.instance_variable_get(:@shape_a)
120
+ shape_b = canvas.instance_variable_get(:@shape_b)
121
+ shape_c = canvas.instance_variable_get(:@shape_c)
122
+
123
+ # Big arrow
124
+
125
+ big_arrow = canvas.instance_variable_get(:@big_arrow)
126
+ big_arrow.line_width = 10.0 * width
127
+ big_arrow.arrow_tip_length = shape_a
128
+ big_arrow.arrow_length = shape_b
129
+ big_arrow.arrow_width = shape_c
130
+
131
+ # Outline
132
+
133
+ points = []
134
+ points[0] = RIGHT - 10 * shape_a * width
135
+ points[1] = MIDDLE - 10 * width / 2
136
+ points[2] = RIGHT - 10 * shape_b * width
137
+ points[3] = MIDDLE - 10 * (shape_c * width / 2.0)
138
+ points[4] = RIGHT
139
+ points[5] = MIDDLE
140
+ points[6] = points[2]
141
+ points[7] = MIDDLE + 10 * (shape_c * width / 2.0)
142
+ points[8] = points[0]
143
+ points[9] = MIDDLE + 10 * width / 2
144
+
145
+ outline = canvas.instance_variable_get(:@outline)
146
+ outline.points = points
147
+
148
+ # Drag boxes
149
+ move_drag_box(canvas.instance_variable_get(:@width_drag_box), LEFT, MIDDLE - 10 * width / 2.0)
150
+ move_drag_box(canvas.instance_variable_get(:@shape_a_drag_box), RIGHT - 10 * shape_a * width, MIDDLE)
151
+ move_drag_box(canvas.instance_variable_get(:@shape_b_c_drag_box), RIGHT - 10 * shape_b * width, MIDDLE - 10 * (shape_c * width / 2.0))
152
+
153
+ # Dimensions
154
+
155
+ set_dimension(canvas, "width_arrow", "width_text",
156
+ LEFT - 10,
157
+ MIDDLE - 10 * width / 2.0,
158
+ LEFT - 10,
159
+ MIDDLE + 10 * width / 2.0,
160
+ LEFT - 15,
161
+ MIDDLE,
162
+ width)
163
+
164
+ set_dimension(canvas, "shape_a_arrow", "shape_a_text",
165
+ RIGHT - 10 * shape_a * width,
166
+ MIDDLE + 10 * (shape_c * width / 2.0) + 10,
167
+ RIGHT,
168
+ MIDDLE + 10 * (shape_c * width / 2.0) + 10,
169
+ RIGHT - 10 * shape_a * width / 2.0,
170
+ MIDDLE + 10 * (shape_c * width / 2.0) + 15,
171
+ shape_a)
172
+
173
+ set_dimension(canvas, "shape_b_arrow", "shape_b_text",
174
+ RIGHT - 10 * shape_b * width,
175
+ MIDDLE + 10 * (shape_c * width / 2.0) + 35,
176
+ RIGHT,
177
+ MIDDLE + 10 * (shape_c * width / 2.0) + 35,
178
+ RIGHT - 10 * shape_b * width / 2.0,
179
+ MIDDLE + 10 * (shape_c * width / 2.0) + 40,
180
+ shape_b)
181
+
182
+ set_dimension(canvas, "shape_c_arrow", "shape_c_text",
183
+ RIGHT + 10,
184
+ MIDDLE - 10 * shape_c * width / 2.0,
185
+ RIGHT + 10,
186
+ MIDDLE + 10 * shape_c * width / 2.0,
187
+ RIGHT + 15,
188
+ MIDDLE,
189
+ shape_c)
190
+
191
+ # Info
192
+
193
+ width_info = canvas.instance_variable_get(:@width_info)
194
+ width_info.text = "line-width: #{width}"
195
+
196
+ shape_a_info = canvas.instance_variable_get(:@shape_a_info)
197
+ shape_a_info.text = "arrow-tip-length: #{shape_a} (* line-width)"
198
+
199
+ shape_b_info = canvas.instance_variable_get(:@shape_b_info)
200
+ shape_b_info.text = "arrow-length: #{shape_b} (* line-width)"
201
+
202
+ shape_c_info = canvas.instance_variable_get(:@shape_c_info)
203
+ shape_c_info.text = "arrow-length: #{shape_c} (* line-width)"
204
+
205
+ # Sample arrows
206
+
207
+ sample_1 = canvas.instance_variable_get(:@sample_1)
208
+ sample_1.line_width = width
209
+ sample_1.arrow_tip_length = shape_a
210
+ sample_1.arrow_length = shape_b
211
+ sample_1.arrow_width = shape_c
212
+ sample_2 = canvas.instance_variable_get(:@sample_2)
213
+ sample_2.line_width = width
214
+ sample_2.arrow_tip_length = shape_a
215
+ sample_2.arrow_length = shape_b
216
+ sample_2.arrow_width = shape_c
217
+ sample_3 = canvas.instance_variable_get(:@sample_3)
218
+ sample_3.line_width = width
219
+ sample_3.arrow_tip_length = shape_a
220
+ sample_3.arrow_length = shape_b
221
+ sample_3.arrow_width = shape_c
222
+ end
223
+
224
+ def create_dimension(canvas, root, arrow_name, text_name, anchor)
225
+ item = Goo::CanvasPolyline.new(root, false, 0,
226
+ :fill_color => "black",
227
+ :start_arrow => true,
228
+ :end_arrow => true)
229
+ canvas.instance_variable_set("@#{arrow_name}", item)
230
+
231
+ item = Goo::CanvasText.new(root, nil, 0, 0, -1, anchor,
232
+ :fill_color => "black",
233
+ :font => "Sans 12")
234
+ canvas.instance_variable_set("@#{text_name}", item)
235
+ end
236
+
237
+ def create_info(canvas, root, info_name, x, y)
238
+ item = Goo::CanvasText.new(root, nil, x, y, -1, Gtk::ANCHOR_NW,
239
+ :fill_color => "black",
240
+ :font => "Sans 14")
241
+ canvas.instance_variable_set("@#{info_name}", item)
242
+ end
243
+
244
+ def create_sample_arrow(canvas, root, sample_name, x1, y1, x2, y2)
245
+ item = Goo::CanvasPolyline.new_line(root, x1, y1, x2, y2,
246
+ :start_arrow => true,
247
+ :end_arrow => true)
248
+ canvas.instance_variable_set("@#{sample_name}", item)
249
+ end
250
+
251
+ def create_drag_box(canvas, root, box_name)
252
+ item = Goo::CanvasRect.new(root, 0, 0, 10, 10,
253
+ :fill_color => 'black',
254
+ :stroke_color => 'black',
255
+ :line_width => 1.0)
256
+ canvas.instance_variable_set("@#{box_name}", item)
257
+
258
+ item.signal_connect('enter_notify_event') do
259
+ item.fill_color = 'red'
260
+ true
261
+ end
262
+ item.signal_connect('leave_notify_event') do
263
+ item.fill_color = 'black'
264
+ true
265
+ end
266
+ item.signal_connect('button_press_event') do |item, target, event|
267
+ fleur = Gdk::Cursor.new(Gdk::Cursor::FLEUR)
268
+ canvas.pointer_grab(item, Gdk::Event::POINTER_MOTION_MASK | Gdk::Event::BUTTON_RELEASE_MASK, fleur, event.time)
269
+ true
270
+ end
271
+ item.signal_connect('button_release_event') do |item, target, event|
272
+ canvas.pointer_ungrab(item, event.time)
273
+ true
274
+ end
275
+ item.signal_connect('motion_notify_event') do |item, target, event|
276
+ catch :done do
277
+ throw :done, false unless event.state & Gdk::Window::BUTTON1_MASK == Gdk::Window::BUTTON1_MASK
278
+
279
+ if item == canvas.instance_variable_get(:@width_drag_box)
280
+ y = event.y
281
+ width = (MIDDLE - y) / 5
282
+ throw :done, false if width < 0
283
+ canvas.instance_variable_set(:@width, width)
284
+ set_arrow_shape(canvas)
285
+ elsif item == canvas.instance_variable_get(:@shape_a_drag_box)
286
+ x = event.x
287
+ width = canvas.instance_variable_get(:@width)
288
+ shape_a = (RIGHT - x) / 10 / width
289
+ throw :done, false if (shape_a < 0) || (shape_a > 30)
290
+ width = canvas.instance_variable_set(:@shape_a, shape_a)
291
+ set_arrow_shape(canvas)
292
+ elsif item == canvas.instance_variable_get(:@shape_b_c_drag_box)
293
+ change = false
294
+ width = canvas.instance_variable_get(:@width)
295
+ x = event.x
296
+ shape_b = (RIGHT - x) / 10 / width
297
+ if (shape_b >= 0) && (shape_b <= 30)
298
+ canvas.instance_variable_set(:@shape_b, shape_b)
299
+ change = true
300
+ end
301
+
302
+ y = event.y
303
+ shape_c = (MIDDLE - y) * 2 / 10 / width
304
+ if shape_c >= 0
305
+ canvas.instance_variable_set(:@shape_c, shape_c)
306
+ change = true
307
+ end
308
+
309
+ set_arrow_shape(canvas) if change
310
+ end
311
+ true
312
+ end
313
+ end
314
+ end
315
+ end