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,720 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -*- indent-tabs-mode: nil -*-
3
+ =begin header
4
+
5
+ Rewritten by Emmanuel Pinault <seatmanu@yahoo.com>
6
+
7
+ Original Copyright:
8
+
9
+ Author : Richard Hestilow <hestgray@ionet.net>
10
+
11
+ Copyright (C) 1998 Free Software Foundation
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 2, or (at your option)
16
+ any later version.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26
+ 02111-1307, USA.
27
+
28
+ =end
29
+ class CanvasSamplePrimitives < Gtk::VBox
30
+ VERTICES = 10
31
+ RADIUS = 60.0
32
+
33
+ def initialize(aa)
34
+ super(false, 4)
35
+ @dragging = false
36
+ self.border_width = 4
37
+ show
38
+
39
+ label = Gtk::Label.new("Drag an item with button 1. " +
40
+ "Click button 2 on an item to lower it, " +
41
+ "or button 3 to raise it.")
42
+ pack_start(label, false, false, 0)
43
+ label.show
44
+
45
+ hbox = Gtk::HBox.new(false, 4)
46
+ pack_start(hbox, false, false, 0)
47
+ hbox.show
48
+
49
+ # Create the canvas
50
+ canvas = Goo::Canvas.new
51
+ canvas.automatic_bounds = true
52
+ canvas.bounds_from_origin = false
53
+ canvas.bounds_padding = 4.0
54
+ canvas.background_color_rgb = 0xc3c3ff
55
+ canvas.set_bounds(0, 0, 604, 454)
56
+
57
+ # Scale
58
+ label = Gtk::Label.new("Scale:")
59
+ hbox.pack_start(label, false, false, 0)
60
+ label.show
61
+
62
+ adjustment = Gtk::Adjustment.new(1.00, 0.05, 50.00, 0.05, 0.50, 0.50)
63
+ button = Gtk::SpinButton.new(adjustment, 0.0, 2)
64
+ adjustment.signal_connect('value_changed') do |adj,|
65
+ canvas.scale = adj.value
66
+ end
67
+ button.set_size_request(50, -1)
68
+ hbox.pack_start(button, false, false, 0)
69
+ button.show
70
+
71
+ label = Gtk::Label.new("Scale X:")
72
+ hbox.pack_start(label, false, false, 0)
73
+ label.show
74
+
75
+ adjustment = Gtk::Adjustment.new(1.00, 0.05, 50.00, 0.05, 0.50, 0.50)
76
+ button = Gtk::SpinButton.new(adjustment, 0.0, 2)
77
+ adjustment.signal_connect('value_changed') do |adj,|
78
+ canvas.scale_x = adj.value
79
+ end
80
+ button.set_size_request(50, -1)
81
+ hbox.pack_start(button, false, false, 0)
82
+ button.show
83
+
84
+ label = Gtk::Label.new("Scale Y:")
85
+ hbox.pack_start(label, false, false, 0)
86
+ label.show
87
+
88
+ adjustment = Gtk::Adjustment.new(1.00, 0.05, 50.00, 0.05, 0.50, 0.50)
89
+ button = Gtk::SpinButton.new(adjustment, 0.0, 2)
90
+ adjustment.signal_connect('value_changed') do |adj,|
91
+ canvas.scale_y = adj.value
92
+ end
93
+ button.set_size_request(50, -1)
94
+ hbox.pack_start(button, false, false, 0)
95
+ button.show
96
+
97
+ hbox = Gtk::HBox.new(false, 4)
98
+ pack_start(hbox, false, false, 0)
99
+ hbox.show
100
+
101
+ # Center
102
+ button = Gtk::CheckButton.new('Center scroll region')
103
+ hbox.pack_start(button, false, false, 0)
104
+ button.signal_connect("toggled") do |_button,|
105
+ canvas.center_scroll_region = _button.active
106
+ end
107
+ # button.show
108
+
109
+ # Move Ellipse
110
+ button = Gtk::Button.new("Move Ellipse")
111
+ hbox.pack_start(button, false, false, 0)
112
+ button.show
113
+ last_state = 0
114
+ button.signal_connect("clicked") do |_button,|
115
+ $ellipse2.transform = nil
116
+
117
+ case last_state
118
+ when 0
119
+ $ellipse2.center_x = 300.0
120
+ $ellipse2.center_y = 70.0
121
+ $ellipse2.radius_x = 45.0
122
+ $ellipse2.radius_y = 30.0
123
+ $ellipse2.fill_color = 'red'
124
+ $ellipse2.stroke_color = 'midnightblue'
125
+ $ellipse2.line_width = 4.0
126
+ $ellipse2.title = 'A red ellipse'
127
+ when 1
128
+ $ellipse2.center_x = 390.0
129
+ $ellipse2.center_y = 150.0
130
+ $ellipse2.radius_x = 45.0
131
+ $ellipse2.radius_y = 40.0
132
+ $ellipse2.fill_color = 'brown'
133
+ $ellipse2.stroke_color = 'midnightblue'
134
+ $ellipse2.line_width = 4.0
135
+ $ellipse2.title = 'A brown ellipse'
136
+ when 2
137
+ $ellipse2.center_x = 0.0
138
+ $ellipse2.center_y = 0.0
139
+ $ellipse2.radius_y = 30.0
140
+ $ellipse2.set_simple_transform(100, 100, 1, 0)
141
+ when 3
142
+ $ellipse2.set_simple_transform(200, 100, 2, 0)
143
+ when 4
144
+ $ellipse2.set_simple_transform(200, 200, 1, 45)
145
+ when 5
146
+ $ellipse2.set_simple_transform(50, 50, 0.2, 225)
147
+ else
148
+ $ellipse2.center_x = 335.0
149
+ $ellipse2.center_y = 70.0
150
+ $ellipse2.radius_x = 45.0
151
+ $ellipse2.radius_y = 30.0
152
+ $ellipse2.fill_color = 'purple'
153
+ $ellipse2.stroke_color = 'midnightblue'
154
+ $ellipse2.line_width = 4.0
155
+ $ellipse2.title = 'A purple ellipse'
156
+ end
157
+ last_state = (last_state + 1) % 7
158
+ end
159
+
160
+ # Animate Ellipse
161
+ button = Gtk::Button.new("Animate Ellipse")
162
+ hbox.pack_start(button, false, false, 0)
163
+ button.show
164
+ button.signal_connect('clicked') do
165
+ $ellipse2.animate(100, 100, 1, 90, true,
166
+ 1000, 40, Goo::CanvasItem::ANIMATE_BOUNCE)
167
+ end
168
+
169
+ # Stop Animation
170
+ button = Gtk::Button.new("Stop Animation")
171
+ hbox.pack_start(button, false, false, 0)
172
+ button.show
173
+ button.signal_connect('clicked') do
174
+ $ellipse2.stop_animation
175
+ end
176
+
177
+ # Create PDF
178
+ button = Gtk::Button.new("Write PDF")
179
+ hbox.pack_start(button, false, false, 0)
180
+ button.show
181
+ button.signal_connect('clicked') do
182
+ puts "In write_pdf_clicked"
183
+
184
+ Cairo::PDFSurface.new("demo.pdf", 9 * 72, 10 * 72) do |surface|
185
+ Cairo::Context.new(surface) do |context|
186
+
187
+ # Place it in the middle of our 9x10 page.
188
+ context.translate(20, 130)
189
+
190
+ canvas.render(context, nil, 1.0)
191
+
192
+ context.show_page
193
+ end
194
+ end
195
+ end
196
+
197
+ button = Gtk::Button.new("Change Bounds")
198
+ hbox.pack_start(button, false, false, 0)
199
+ button.show
200
+ bounds = [
201
+ [-100, -100, 200, 200],
202
+ [100, 100, 200, 200],
203
+ [0, 0, 300, 300],
204
+ [0, 0, 604, 454],
205
+ ]
206
+ bounds_n = 0
207
+ button.signal_connect("clicked") do |_button,|
208
+ if bounds_n < 4
209
+ automatic_bounds = false
210
+ bounds_from_origin = false
211
+ canvas.set_bounds(*bounds[bounds_n])
212
+ elsif bounds_n == 4
213
+ automatic_bounds = true
214
+ bounds_from_origin = true
215
+ end
216
+
217
+ canvas.automatic_bounds = automatic_bounds
218
+ canvas.bounds_from_origin = bounds_from_origin
219
+ canvas.bounds_padding = 50
220
+ bounds_n = (bounds_n + 1) % 6
221
+ end
222
+
223
+ hbox = Gtk::HBox.new(false, 4)
224
+ pack_start(hbox, false, false, 0)
225
+ hbox.show
226
+
227
+ # Scroll to
228
+ label = Gtk::Label.new("Scroll To:")
229
+ hbox.pack_start(label, false, false, 0)
230
+ label.show
231
+
232
+ button = Gtk::Button.new("50,50")
233
+ hbox.pack_start(button, false, false, 0)
234
+ button.show
235
+ button.signal_connect('clicked') {canvas.scroll_to(50, 50)}
236
+
237
+ button = Gtk::Button.new("250,250")
238
+ hbox.pack_start(button, false, false, 0)
239
+ button.show
240
+ button.signal_connect('clicked') {canvas.scroll_to(250, 250)}
241
+
242
+ button = Gtk::Button.new("500,500")
243
+ hbox.pack_start(button, false, false, 0)
244
+ button.show
245
+ button.signal_connect('clicked') {canvas.scroll_to(500, 500)}
246
+
247
+ # Scroll anchor
248
+ label = Gtk::Label.new("Anchor:")
249
+ hbox.pack_start(label, false, false, 0)
250
+ label.show
251
+
252
+ group = nil
253
+ [
254
+ ['NW', Gtk::ANCHOR_NW],
255
+ ['NE', Gtk::ANCHOR_NE],
256
+ ['W', Gtk::ANCHOR_W],
257
+ ['C', Gtk::ANCHOR_CENTER],
258
+ ['E', Gtk::ANCHOR_E],
259
+ ['SW', Gtk::ANCHOR_SW],
260
+ ['S', Gtk::ANCHOR_S],
261
+ ['SE', Gtk::ANCHOR_SE],
262
+ ].each do |name, anchor|
263
+ if group
264
+ button = Gtk::RadioButton.new(group, name)
265
+ else
266
+ button = Gtk::RadioButton.new(name)
267
+ end
268
+ group, = button.group
269
+ hbox.pack_start(button, false, false, 0)
270
+ button.show
271
+ button.signal_connect('toggled') do |_button|
272
+ canvas.anchor = anchor if _button.active?
273
+ end
274
+ end
275
+
276
+ # Layout the stuff
277
+ scrolled_window = Gtk::ScrolledWindow.new
278
+ scrolled_window.show
279
+ pack_start(scrolled_window, true, true, 0)
280
+
281
+ canvas.show
282
+ scrolled_window.add(canvas)
283
+
284
+ # Add all the canvas items.
285
+ setup_canvas(canvas)
286
+ end
287
+
288
+ def image_path(name)
289
+ File.join(File.dirname(__FILE__), name)
290
+ end
291
+
292
+ def setup_item_signals(item)
293
+ dragging = false
294
+ drag_x = nil
295
+ drag_y = nil
296
+
297
+ item.signal_connect('motion_notify_event') do |item, target, event|
298
+ if dragging && (event.state & Gdk::Window::BUTTON1_MASK == Gdk::Window::BUTTON1_MASK)
299
+ item.translate(event.x - drag_x, event.y - drag_y)
300
+ end
301
+ true
302
+ end
303
+
304
+ item.signal_connect('button_press_event') do |item, target, event|
305
+ case event.button
306
+ when 1
307
+ if event.state & Gdk::Window::SHIFT_MASK == Gdk::Window::SHIFT_MASK
308
+ item.parent.remove_child(item)
309
+ else
310
+ drag_x = event.x
311
+ drag_y = event.y
312
+
313
+ fleur = Gdk::Cursor.new(Gdk::Cursor::FLEUR)
314
+ canvas = item.canvas
315
+ canvas.pointer_grab(item, Gdk::Event::POINTER_MOTION_MASK | Gdk::Event::BUTTON_RELEASE_MASK, fleur, event.time)
316
+ dragging = true
317
+ end
318
+ when 2
319
+ item.lower(nil)
320
+ when 3
321
+ item.raise(nil)
322
+ end
323
+ true
324
+ end
325
+
326
+ item.signal_connect('button_release_event') do |item, target, event|
327
+ canvas = item.canvas
328
+ canvas.pointer_ungrab(item, event.time) if canvas
329
+ dragging = false
330
+ true
331
+ end
332
+ end
333
+
334
+ def setup_heading(root, text, pos)
335
+ x = (pos % 3) * 200 + 100
336
+ y = (pos / 3) * 150 + 5
337
+
338
+ item = Goo::CanvasText.new(root, text, x, y, -1, Gtk::ANCHOR_N, :font => "Sans 12")
339
+ item.skew_y(30, x, y)
340
+ end
341
+
342
+ def setup_divisions(root)
343
+ group = Goo::CanvasGroup.new(root, nil)
344
+ group.translate(2, 2)
345
+
346
+ item = Goo::CanvasRect.new(group, 0, 0, 600, 450, :line_width => 4.0)
347
+ item = Goo::CanvasPolyline.new_line(group, 0, 150, 600, 150, :line_width => 4.0)
348
+ item = Goo::CanvasPolyline.new_line(group, 0, 300, 600, 300, :line_width => 4.0)
349
+ item = Goo::CanvasPolyline.new_line(group, 200, 0, 200, 450, :line_width => 4.0)
350
+ item = Goo::CanvasPolyline.new_line(group, 400, 0, 400, 450, :line_width => 4.0)
351
+
352
+ setup_heading(group, 'Rectangles', 0)
353
+ setup_heading(group, 'Ellipses', 1)
354
+ setup_heading(group, 'Texts', 2)
355
+ setup_heading(group, 'Images', 3)
356
+ setup_heading(group, 'Lines', 4)
357
+ setup_heading(group, 'Polygons', 7)
358
+ end
359
+
360
+ # FIXME: I think we may need to check byte order.
361
+ def create_stipple(color_name, stipple_data)
362
+ color = Gdk::Color.parse(color_name)
363
+ stipple_data[2] = stipple_data[14] = (color.red >> 8)
364
+ stipple_data[1] = stipple_data[13] = (color.green >> 8)
365
+ stipple_data[0] = stipple_data[12] = (color.blue >> 8)
366
+ surface = Cairo::ImageSurface.new(stipple_data.pack('C*'), Cairo::FORMAT_ARGB32, 2, 2, 8)
367
+ pattern = Cairo::SurfacePattern.new(surface)
368
+ pattern.extend = Cairo::EXTEND_REPEAT
369
+
370
+ return pattern
371
+ end
372
+
373
+ def setup_rectangles(root)
374
+ stipple_data = [ 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255 ]
375
+
376
+ item = Goo::CanvasRect.new(root, 20, 30, 50, 30,
377
+ :stroke_color => "red",
378
+ :line_width => 8.0)
379
+ setup_item_signals(item)
380
+
381
+ pattern = create_stipple("mediumseagreen", stipple_data)
382
+ item = Goo::CanvasRect.new(root, 90, 40, 90, 60,
383
+ :fill_pattern => pattern,
384
+ :stroke_color => 'black',
385
+ :line_width => 4.0)
386
+ setup_item_signals(item)
387
+
388
+ item = Goo::CanvasRect.new(root, 10, 80, 70, 60, :fill_color => "steelblue")
389
+ setup_item_signals(item)
390
+
391
+ item = Goo::CanvasRect.new(root, 20, 90, 70, 60,
392
+ :fill_color_rgba => 0x3cb37180,
393
+ :stroke_color => "blue",
394
+ :line_width => 2.0)
395
+ setup_item_signals(item)
396
+
397
+ item = Goo::CanvasRect.new(root, 110, 80, 50, 30,
398
+ :radius_x => 20.0,
399
+ :radius_y => 10.0,
400
+ :stroke_color => "yellow",
401
+ :fill_color_rgba => 0x3cb3f180)
402
+ setup_item_signals(item)
403
+
404
+ #TODO
405
+ # item = goo_demo_item_new(root, 30, 20, 50, 30,
406
+ # :fill_color => "yellow")
407
+ # setup_item_signals(item)
408
+ end
409
+
410
+ def setup_ellipses(root)
411
+ stipple_data = [ 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255 ]
412
+
413
+ ellipse1 = Goo::CanvasEllipse.new(root, 245, 45, 25, 15,
414
+ :stroke_color => 'goldenrod',
415
+ :line_width => 8.0)
416
+ setup_item_signals(ellipse1)
417
+
418
+ $ellipse2 = Goo::CanvasEllipse.new(root, 335, 70, 45, 30,
419
+ :fill_color => 'wheat',
420
+ :stroke_color => 'midnightblue',
421
+ :line_width => 4.0,
422
+ :title => 'An ellipse')
423
+ setup_item_signals($ellipse2)
424
+
425
+ pattern = create_stipple('cadetblue', stipple_data)
426
+ ellipse3 = Goo::CanvasEllipse.new(root, 245, 110, 35, 30,
427
+ :fill_pattern => pattern,
428
+ :stroke_color => 'black',
429
+ :line_width => 1.0)
430
+ setup_item_signals(ellipse3)
431
+ end
432
+
433
+
434
+
435
+ def polish_diamond(root)
436
+ group = Goo::CanvasGroup.new(root,
437
+ :line_width => 1.0,
438
+ :line_cap => Cairo::LINE_CAP_ROUND)
439
+ group.translate(270, 230)
440
+ setup_item_signals(group)
441
+
442
+ VERTICES.times do |i|
443
+ a = 2.0 * Math::PI * i / VERTICES
444
+ x1 = RADIUS * Math.cos(a)
445
+ y1 = RADIUS * Math.sin(a)
446
+
447
+ ((i + 1)...VERTICES).each do |j|
448
+ a = 2.0 * Math::PI * j / VERTICES
449
+ x2 = RADIUS * Math.cos(a)
450
+ y2 = RADIUS * Math.sin(a)
451
+ item = Goo::CanvasPolyline.new_line(group, x1, y1, x2, y2)
452
+ end
453
+ end
454
+ end
455
+
456
+ SCALE = 7.0
457
+
458
+ def make_hilbert(root)
459
+ hilbert = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd".split(//)
460
+ stipple_data = [ 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255 ]
461
+
462
+ points = [ 340.0, 290.0 ]
463
+
464
+ i = 0
465
+ hilbert.each do |c|
466
+ case c
467
+ when 'u'
468
+ points[i+2] = points[i+0]
469
+ points[i+3] = points[i+1] - SCALE
470
+ when 'd'
471
+ points[i+2] = points[i+0]
472
+ points[i+3] = points[i+1] + SCALE
473
+ when 'l'
474
+ points[i+2] = points[i+0] - SCALE
475
+ points[i+3] = points[i+1]
476
+ when 'r'
477
+ points[i+2] = points[i+0] + SCALE
478
+ points[i+3] = points[i+1]
479
+ end
480
+ i += 2
481
+ end
482
+
483
+ pattern = create_stipple("red", stipple_data)
484
+ item = Goo::CanvasPolyline.new(root, false, points,
485
+ :line_width => 4.0,
486
+ :stroke_pattern => pattern,
487
+ :line_cap => Cairo::LINE_CAP_SQUARE,
488
+ :line_join => Cairo::LINE_JOIN_MITER)
489
+ setup_item_signals(item)
490
+ end
491
+
492
+ def setup_lines(root)
493
+ polish_diamond(root)
494
+ make_hilbert(root)
495
+
496
+ # Arrow tests
497
+
498
+ polyline1 = Goo::CanvasPolyline.new(root, false,
499
+ [ 340.0, 170.0,
500
+ 340.0, 230.0,
501
+ 390.0, 230.0,
502
+ 390.0, 170.0,
503
+ ],
504
+ :stroke_color => 'midnightblue',
505
+ :line_width => 3.0,
506
+ :start_arrow => true,
507
+ :end_arrow => true,
508
+ :arrow_tip_length => 3.0,
509
+ :arrow_length => 4.0,
510
+ :arrow_width => 3.5)
511
+ setup_item_signals(polyline1)
512
+
513
+ polyline2 = Goo::CanvasPolyline.new(root, false,
514
+ [ 356.0, 180.0,
515
+ 374.0, 220.0,
516
+ ] ,
517
+ :stroke_color => "blue",
518
+ :line_width => 1.0,
519
+ :start_arrow => true,
520
+ :end_arrow => true,
521
+ :arrow_tip_length => 5.0,
522
+ :arrow_length => 6.0,
523
+ :arrow_width => 6.0)
524
+ setup_item_signals(polyline2)
525
+
526
+ polyline3 = Goo::CanvasPolyline.new(root, false,
527
+ [ 356.0, 220.0,
528
+ 374.0, 180.0,
529
+ ],
530
+ :stroke_color => "blue",
531
+ :line_width => 1.0,
532
+ :start_arrow => true,
533
+ :end_arrow => true,
534
+ :arrow_tip_length => 5.0,
535
+ :arrow_length => 6.0,
536
+ :arrow_width => 6.0)
537
+ setup_item_signals(polyline3)
538
+
539
+ # Test polyline without any coords.
540
+ polyline4 = Goo::CanvasPolyline.new(root, false, [])
541
+ setup_item_signals(polyline4)
542
+
543
+ # Test polyline with 1 coord and arrows.
544
+ polyline5 = Goo::CanvasPolyline.new(root, false,
545
+ [ 356.0, 220.0 ],
546
+ :start_arrow => true,
547
+ :end_arrow => true)
548
+ setup_item_signals(polyline5)
549
+ end
550
+
551
+ def setup_polygons(root)
552
+ stipple_data = [ 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255 ]
553
+
554
+ points =
555
+ [ 210.0, 320.0,
556
+ 210.0, 380.0,
557
+ 260.0, 350.0,
558
+ ]
559
+ pattern = create_stipple("blue", stipple_data)
560
+ polyline1 = Goo::CanvasPolyline.new(root, true, points,
561
+ :line_width => 1.0,
562
+ :fill_pattern => pattern,
563
+ :stroke_color => "black")
564
+ setup_item_signals(polyline1)
565
+
566
+ points =
567
+ [ 270.0, 330.0,
568
+ 270.0, 430.0,
569
+ 390.0, 430.0,
570
+ 390.0, 330.0,
571
+ 310.0, 330.0,
572
+ 310.0, 390.0,
573
+ 350.0, 390.0,
574
+ 350.0, 370.0,
575
+ 330.0, 370.0,
576
+ 330.0, 350.0,
577
+ 370.0, 350.0,
578
+ 370.0, 410.0,
579
+ 290.0, 410.0,
580
+ 290.0, 330.0,
581
+ ]
582
+ polyline2 = Goo::CanvasPolyline.new(root, true, points,
583
+ :fill_color => 'tan',
584
+ :stroke_color => 'black',
585
+ :line_width => 3.0)
586
+ setup_item_signals(polyline2)
587
+ end
588
+
589
+ def make_anchor(root, x, y)
590
+ transform = Cairo::Matrix.new(0.8, 0.2, -0.3, 0.5, x, y)
591
+
592
+ group = Goo::CanvasGroup.new(root)
593
+ group.translate(x, y)
594
+ group.transform = transform
595
+ $transforms ||= []
596
+ $transforms << transform
597
+
598
+ item = Goo::CanvasRect.new(group, -2.5, -2.5, 4, 4, :line_width => 1.0)
599
+ setup_item_signals(item)
600
+
601
+ group
602
+ end
603
+
604
+ def setup_texts(root)
605
+ stipple_data = [ 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255 ]
606
+
607
+ pattern = create_stipple('blue', stipple_data)
608
+ item = Goo::CanvasText.new(make_anchor(root, 420, 20),
609
+ 'Anchor NW', 0, 0, -1, Gtk::ANCHOR_NW,
610
+ :font => 'Sans Bold 24',
611
+ :fill_pattern => pattern)
612
+ setup_item_signals(item)
613
+
614
+ item = Goo::CanvasText.new(make_anchor(root, 470, 75),
615
+ "Anchor center\nJustify center\nMultiline text\nb8bit text ÅÄÖåäö",
616
+ 0, 0, -1, Gtk::ANCHOR_CENTER,
617
+ :font => "monospace bold 14",
618
+ :alignment => Pango::ALIGN_CENTER,
619
+ :fill_color => 'firebrick')
620
+ setup_item_signals(item)
621
+
622
+ textitem = Goo::CanvasText.new(make_anchor(root, 420, 240),
623
+ "This is a very long paragraph that will need to be wrapped over several lines so we can see what happens to line-breaking as the view is zoomed in and out.",
624
+ 0, 0, 180, Gtk::ANCHOR_W,
625
+ :font => 'Sans 12',
626
+ :fill_color => 'goldenrod')
627
+ setup_item_signals(textitem)
628
+
629
+ textitem = Goo::CanvasText.new(root,
630
+ "Ellipsized text.",
631
+ 20, 420, 115, Gtk::ANCHOR_W,
632
+ :font => 'Sans 12',
633
+ :fill_color => "blue",
634
+ :ellipsize => Pango::ELLIPSIZE_END)
635
+ setup_item_signals(textitem)
636
+ end
637
+
638
+ def setup_invisible_texts(root)
639
+ Goo::CanvasText.new(root, "Visible above 0.8x", 500, 330, -1,
640
+ Gtk::ANCHOR_CENTER,
641
+ :visibility => Goo::CanvasItem::VISIBLE_ABOVE_THRESHOLD,
642
+ :visibility_threshold => 0.8)
643
+ Goo::CanvasRect.new(root, 410.5, 322.5, 180, 15,
644
+ :line_width => 1.0,
645
+ :visibility => Goo::CanvasItem::VISIBLE_ABOVE_THRESHOLD,
646
+ :visibility_threshold => 0.8)
647
+
648
+ Goo::CanvasText.new(root, "Visible above 1.5x", 500, 350, -1,
649
+ Gtk::ANCHOR_CENTER,
650
+ :visibility => Goo::CanvasItem::VISIBLE_ABOVE_THRESHOLD,
651
+ :visibility_threshold => 1.5)
652
+ Goo::CanvasRect.new(root, 410.5, 342.5, 180, 15,
653
+ :line_width => 1.0,
654
+ :visibility => Goo::CanvasItem::VISIBLE_ABOVE_THRESHOLD,
655
+ :visibility_threshold => 1.5)
656
+
657
+ Goo::CanvasText.new(root, "Visible above 3.0x", 500, 370, -1,
658
+ Gtk::ANCHOR_CENTER,
659
+ :visibility => Goo::CanvasItem::VISIBLE_ABOVE_THRESHOLD,
660
+ :visibility_threshold => 3.0)
661
+ Goo::CanvasRect.new(root, 410.5, 362.5, 180, 15,
662
+ :line_width => 1.0,
663
+ :visibility => Goo::CanvasItem::VISIBLE_ABOVE_THRESHOLD,
664
+ :visibility_threshold => 3.0)
665
+
666
+ # This should never be seen.
667
+ Goo::CanvasText.new(root, "Always Invisible", 500, 390, -1,
668
+ Gtk::ANCHOR_CENTER,
669
+ :visibility => Goo::CanvasItem::INVISIBLE)
670
+ Goo::CanvasRect.new(root, 410.5, 350.5, 180, 15,
671
+ :line_width => 1.0,
672
+ :visibility => Goo::CanvasItem::INVISIBLE)
673
+ end
674
+
675
+ def plant_flower(root, x, y, anchor)
676
+ surface = Cairo::ImageSurface.from_png(image_path('flower.png'))
677
+ w = surface.width
678
+ h = surface.height
679
+
680
+ pattern = Cairo::SurfacePattern.new(surface)
681
+
682
+ image = Goo::CanvasImage.new(root, nil, x, y,
683
+ :pattern => pattern,
684
+ :width => w,
685
+ :height => h)
686
+ setup_item_signals(image)
687
+ end
688
+
689
+ def setup_images(root)
690
+ im = Gdk::Pixbuf.new(image_path('toroid.png'))
691
+
692
+ w = im.width
693
+ h = im.height
694
+ image = Goo::CanvasImage.new(root, im, 100.0 - w / 2, 225.0 - h / 2,
695
+ :width => w, :height => h)
696
+ setup_item_signals(image)
697
+
698
+ plant_flower(root, 20.0, 170.0, Gtk::ANCHOR_NW)
699
+ plant_flower(root, 180.0, 170.0, Gtk::ANCHOR_NE)
700
+ plant_flower(root, 20.0, 280.0, Gtk::ANCHOR_SW)
701
+ plant_flower(root, 180.0, 280.0, Gtk::ANCHOR_SE)
702
+ end
703
+
704
+ def setup_canvas(canvas)
705
+ root = canvas.root_item
706
+ root.signal_connect("button_press_event") {
707
+ puts "background received 'button-press' signal"
708
+ }
709
+
710
+ # Setup canvas items
711
+ setup_divisions(root)
712
+ setup_rectangles(root)
713
+ setup_ellipses(root)
714
+ setup_lines(root)
715
+ setup_polygons(root)
716
+ setup_texts(root)
717
+ setup_images(root)
718
+ setup_invisible_texts(root)
719
+ end
720
+ end