goocanvas 2.0.2 → 2.0.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb18174e2d2b2fd2c12dd97283ad960ed329de63
4
+ data.tar.gz: f0bbfbc296334905928a5951febbc33293919896
5
+ SHA512:
6
+ metadata.gz: 2390a713563922a9cad24dc7e6408e2f48cab7e0902f184b777b03ff71ca2320b6384fb7e187439433fbfa9e8673170fe7f6655c3b146a43f37c96c6b6112033
7
+ data.tar.gz: 48a557c770a1e3224c53388cc22a0573845216916ec505939799f8b187a9f4004598aa3e14464b5df29079702a5bc57c026564263fc7b4c91118f302c6d03f86
data/README CHANGED
@@ -9,7 +9,7 @@ Requirements
9
9
 
10
10
  Install
11
11
  -------
12
- 0. install ruby-1.8.x or later and GooCanvas.
12
+ 0. install ruby-1.9.x or later and GooCanvas.
13
13
  1. ruby extconf.rb
14
14
  2. make
15
15
  3. su
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'gnome2-raketask'
6
6
  package = GNOME2Package.new do |_package|
7
7
  _package.summary = "Ruby/GooCanvas is a Ruby binding of GooCanvas."
8
8
  _package.description = "Ruby/GooCanvas is a Ruby binding of GooCanvas."
9
- _package.dependency.gem.runtime = ["gtk2"]
9
+ _package.dependency.gem.runtime = ["gtk3", "gobject-introspection"]
10
10
  _package.win32.packages = ["goocanvas"]
11
11
  _package.win32.dependencies = []
12
12
  end
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of
4
+ # goocanvas/demo/demo-animation.c. It is licensed
5
+ # under the terms of the GNU Library General Public License, version
6
+ # 2 or (at your option) later.
7
+ #
8
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
9
+ #
10
+ # This library is free software; you can redistribute it and/or
11
+ # modify it under the terms of the GNU Lesser General Public
12
+ # License as published by the Free Software Foundation; either
13
+ # version 2.1 of the License, or (at your option) any later version.
14
+ #
15
+ # This library is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ # Lesser General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU Lesser General Public
21
+ # License along with this library; if not, write to the Free Software
22
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
+
24
+ class CanvasSampleAnimation < Gtk::Box
25
+ def initialize
26
+ super(:vertical, 4)
27
+ set_border_width(4)
28
+ show
29
+ create_animation_page(self)
30
+ end
31
+
32
+ private
33
+ def create_animation_page(vbox)
34
+ hbox = Gtk::Box.new(:horizontal, 4)
35
+ vbox.pack_start(hbox, :expand => false,
36
+ :fill => false,
37
+ :padding => 0)
38
+ hbox.show
39
+
40
+ start_button = Gtk::Button.new(:label => "Start Animation")
41
+ hbox.pack_start(start_button, :expand => false,
42
+ :fill => false,
43
+ :padding => 0)
44
+ start_button.show
45
+
46
+ stop_button = Gtk::Button.new(:label => "Stop Animation")
47
+ hbox.pack_start(stop_button, :expand => false,
48
+ :fill => false,
49
+ :padding => 0)
50
+ stop_button.show
51
+
52
+ scrolled_win = Gtk::ScrolledWindow.new
53
+ scrolled_win.shadow_type = :in
54
+ vbox.pack_start(scrolled_win, :expand => true,
55
+ :fill => true,
56
+ :padding => 0)
57
+ scrolled_win.show
58
+
59
+ canvas = Goo::Canvas.new
60
+ canvas.set_size_request(600, 450)
61
+ canvas.set_bounds(0, 0, 1000, 1000)
62
+ canvas.show
63
+ scrolled_win.add(canvas)
64
+
65
+ items = setup_canvas(canvas)
66
+
67
+ start_button.signal_connect("clicked") do
68
+ start_animation_clicked(*items)
69
+ end
70
+
71
+ stop_button.signal_connect("clicked") do
72
+ stop_animation_clicked(*items)
73
+ end
74
+ end
75
+
76
+ def setup_canvas(canvas)
77
+ root = canvas.root_item
78
+
79
+ # Absolute.
80
+ ellipse1 = Goo::CanvasEllipse.new(:parent => root,
81
+ :center_x => 0,
82
+ :center_y => 0,
83
+ :radius_x => 25,
84
+ :radius_y => 15,
85
+ :fill_color => "blue")
86
+ ellipse1.translate(100, 100)
87
+ ellipse1.signal_connect("animation_finished") do |_, event|
88
+ on_animation_finished(event, ellipse1)
89
+ end
90
+
91
+ rect1 = Goo::CanvasRect.new(:parent => root,
92
+ :x => -10,
93
+ :y => -10,
94
+ :width => 20,
95
+ :height => 20,
96
+ :fill_color => "blue")
97
+ rect1.translate(100, 200)
98
+
99
+ rect3 = Goo::CanvasRect.new(:parent => root,
100
+ :x => -10,
101
+ :y => -10,
102
+ :width => 20,
103
+ :height => 20,
104
+ :fill_color => "blue")
105
+ rect3.translate(200, 200)
106
+
107
+ # Relative.
108
+ ellipse2 = Goo::CanvasEllipse.new(:parent => root,
109
+ :center_x => 0,
110
+ :center_y => 0,
111
+ :radius_x => 25,
112
+ :radius_y => 15,
113
+ :fill_color => "red")
114
+ ellipse2.translate(100, 400)
115
+
116
+ rect2 = Goo::CanvasRect.new(:parent => root,
117
+ :x => -10,
118
+ :y => -10,
119
+ :width => 20,
120
+ :height => 20,
121
+ :fill_color => "red")
122
+ rect2.translate(100, 500)
123
+
124
+ rect4 = Goo::CanvasRect.new(:parent => root,
125
+ :x => -10,
126
+ :y => -10,
127
+ :width => 20,
128
+ :height => 20,
129
+ :fill_color => "red")
130
+ rect4.translate(200, 500)
131
+
132
+ [ellipse1, rect1, rect3, ellipse2, rect2, rect4]
133
+ end
134
+
135
+ def start_animation_clicked(ellipse1, rect1, rect3,
136
+ ellipse2, rect2, rect4)
137
+ # Absolute.
138
+ ellipse1.set_simple_transform(100, 100, 1, 0)
139
+ ellipse1.animate(500, 100, 2, 720, true, 2000, 40,
140
+ Goo::CanvasAnimateType::BOUNCE)
141
+
142
+ rect1.set_simple_transform(100, 200, 1, 0)
143
+ rect1.animate(100, 200, 1, 350, true, 40 * 36, 40,
144
+ Goo::CanvasAnimateType::RESTART)
145
+
146
+ rect3.set_simple_transform(200, 200, 1, 0)
147
+ rect3.animate(200, 200, 3, 0, true, 400, 40,
148
+ Goo::CanvasAnimateType::BOUNCE)
149
+
150
+ # Relative.
151
+ ellipse2.set_simple_transform(100, 400, 1, 0)
152
+ ellipse2.animate(400, 0, 2, 720, false, 2000, 40,
153
+ Goo::CanvasAnimateType::BOUNCE)
154
+
155
+ rect2.set_simple_transform(100, 500, 1, 0)
156
+ rect2.animate(0, 0, 1, 350, false, 40 * 36, 40,
157
+ Goo::CanvasAnimateType::RESTART)
158
+
159
+ rect4.set_simple_transform(200, 500, 1, 0)
160
+ rect4.animate(0, 0, 3, 0, false, 400, 40,
161
+ Goo::CanvasAnimateType::BOUNCE)
162
+ end
163
+
164
+ def stop_animation_clicked(*items)
165
+ items.each do |item|
166
+ item.stop_animation
167
+ end
168
+ end
169
+
170
+ def on_animation_finished(event, ellipse1)
171
+ puts "Animation finished stopped: #{event}"
172
+ # Test starting another animation. */
173
+ #ellipse1.animate(500, 100, 2, 720, true, 2000, 40,
174
+ # Goo::CanvasAnimateType::BOUNCE)
175
+ end
176
+ end
@@ -1,315 +1,354 @@
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
1
+ class CanvasSampleArrowhead < Gtk::Box
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(:vertical, 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, :expand => false, :fill => false, :padding => 0)
21
+ w.show
22
+
23
+ w = Gtk::Alignment.new(0.5, 0.5, 0.0, 0.0)
24
+ pack_start(w, :expand => true, :fill => true, :padding => 0)
25
+ w.show
26
+
27
+ frame = Gtk::Frame.new
28
+ frame.shadow_type = :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
+ points = Goo::CanvasPoints.new(2)
48
+ points.set_point(0, LEFT, MIDDLE)
49
+ points.set_point(1, RIGHT, MIDDLE)
50
+ item = Goo::CanvasPolyline.new(:parent => root,
51
+ :points => points,
52
+ :stroke_color => "mediumseagreen",
53
+ :end_arrow => true)
54
+ canvas.instance_variable_set(:@big_arrow, item)
55
+
56
+ # Arrow outline
57
+
58
+ item = Goo::CanvasPolyline.new(:parent => root,
59
+ :close_path => true,
60
+ :points => Goo::CanvasPoints.new(0),
61
+ :stroke_color => "black",
62
+ :line_width => 2.0,
63
+ :line_cap => Cairo::LINE_CAP_ROUND,
64
+ :line_join => Cairo::LINE_JOIN_ROUND)
65
+ canvas.instance_variable_set(:@outline, item)
66
+
67
+ # Drag boxes
68
+
69
+ create_drag_box(canvas, root, "width_drag_box")
70
+ create_drag_box(canvas, root, "shape_a_drag_box")
71
+ create_drag_box(canvas, root, "shape_b_c_drag_box")
72
+
73
+ # Dimensions
74
+
75
+ create_dimension(canvas, root, "width_arrow", "width_text", :e)
76
+ create_dimension(canvas, root, "shape_a_arrow", "shape_a_text", :n)
77
+ create_dimension(canvas, root, "shape_b_arrow", "shape_b_text", :n)
78
+ create_dimension(canvas, root, "shape_c_arrow", "shape_c_text", :w)
79
+
80
+ # Info
81
+
82
+ create_info(canvas, root, "width_info", LEFT, 260)
83
+ create_info(canvas, root, "shape_a_info", LEFT, 280)
84
+ create_info(canvas, root, "shape_b_info", LEFT, 300)
85
+ create_info(canvas, root, "shape_c_info", LEFT, 320)
86
+
87
+ # Division line
88
+
89
+ points = Goo::CanvasPoints.new(2)
90
+ points.set_point(0, RIGHT + 50, 0)
91
+ points.set_point(1, RIGHT + 50, 1000)
92
+ Goo::CanvasPolyline.new(:parent => root,
93
+ :points => points,
94
+ :fill_color => "black", :line_width => 2.0)
95
+
96
+ # Sample arrows
97
+
98
+ create_sample_arrow(canvas, root, "sample_1",
99
+ RIGHT + 100, 30, RIGHT + 100, MIDDLE - 30)
100
+ create_sample_arrow(canvas, root, "sample_2",
101
+ RIGHT + 70, MIDDLE, RIGHT + 130, MIDDLE)
102
+ create_sample_arrow(canvas, root, "sample_3",
103
+ RIGHT + 70, MIDDLE + 30, RIGHT + 130, MIDDLE + 120)
104
+
105
+ # Done!
106
+ set_arrow_shape(canvas)
107
+ end
108
+
109
+ def set_dimension(canvas, arrow_name, text_name, x1, y1, x2, y2, tx, ty, dim)
110
+ points = Goo::CanvasPoints.new(2)
111
+ points.set_point(0, x1, y1)
112
+ points.set_point(1, x2, y2)
113
+
114
+ arrow = canvas.instance_variable_get("@#{arrow_name}")
115
+ arrow.points = points
116
+
117
+ text = canvas.instance_variable_get("@#{text_name}")
118
+ text.text = dim.to_s
119
+ text.x = tx
120
+ text.y = ty
121
+ end
122
+
123
+ def move_drag_box(item, x, y)
124
+ item.x = x - 5.0
125
+ item.y = y - 5.0
126
+ end
127
+
128
+ def set_arrow_shape(canvas)
129
+ width = canvas.instance_variable_get(:@width)
130
+ shape_a = canvas.instance_variable_get(:@shape_a)
131
+ shape_b = canvas.instance_variable_get(:@shape_b)
132
+ shape_c = canvas.instance_variable_get(:@shape_c)
133
+
134
+ # Big arrow
135
+
136
+ big_arrow = canvas.instance_variable_get(:@big_arrow)
137
+ big_arrow.line_width = 10.0 * width
138
+ big_arrow.arrow_tip_length = shape_a
139
+ big_arrow.arrow_length = shape_b
140
+ big_arrow.arrow_width = shape_c
141
+
142
+ # Outline
143
+
144
+ points0 = RIGHT - 10 * shape_a * width
145
+ points1 = MIDDLE - 10 * width / 2
146
+ points2 = RIGHT - 10 * shape_b * width
147
+ points3 = MIDDLE - 10 * (shape_c * width / 2.0)
148
+ points4 = RIGHT
149
+ points5 = MIDDLE
150
+ points6 = points2
151
+ points7 = MIDDLE + 10 * (shape_c * width / 2.0)
152
+ points8 = points0
153
+ points9 = MIDDLE + 10 * width / 2
154
+
155
+ points = Goo::CanvasPoints.new(5)
156
+ points.set_point(0, points0, points1)
157
+ points.set_point(1, points2, points3)
158
+ points.set_point(2, points4, points5)
159
+ points.set_point(3, points6, points7)
160
+ points.set_point(4, points8, points9)
161
+
162
+ outline = canvas.instance_variable_get(:@outline)
163
+ outline.points = points
164
+
165
+ # Drag boxes
166
+ move_drag_box(canvas.instance_variable_get(:@width_drag_box), LEFT, MIDDLE - 10 * width / 2.0)
167
+ move_drag_box(canvas.instance_variable_get(:@shape_a_drag_box), RIGHT - 10 * shape_a * width, MIDDLE)
168
+ move_drag_box(canvas.instance_variable_get(:@shape_b_c_drag_box), RIGHT - 10 * shape_b * width, MIDDLE - 10 * (shape_c * width / 2.0))
169
+
170
+ # Dimensions
171
+
172
+ set_dimension(canvas, "width_arrow", "width_text",
173
+ LEFT - 10,
174
+ MIDDLE - 10 * width / 2.0,
175
+ LEFT - 10,
176
+ MIDDLE + 10 * width / 2.0,
177
+ LEFT - 15,
178
+ MIDDLE,
179
+ width)
180
+
181
+ set_dimension(canvas, "shape_a_arrow", "shape_a_text",
182
+ RIGHT - 10 * shape_a * width,
183
+ MIDDLE + 10 * (shape_c * width / 2.0) + 10,
184
+ RIGHT,
185
+ MIDDLE + 10 * (shape_c * width / 2.0) + 10,
186
+ RIGHT - 10 * shape_a * width / 2.0,
187
+ MIDDLE + 10 * (shape_c * width / 2.0) + 15,
188
+ shape_a)
189
+
190
+ set_dimension(canvas, "shape_b_arrow", "shape_b_text",
191
+ RIGHT - 10 * shape_b * width,
192
+ MIDDLE + 10 * (shape_c * width / 2.0) + 35,
193
+ RIGHT,
194
+ MIDDLE + 10 * (shape_c * width / 2.0) + 35,
195
+ RIGHT - 10 * shape_b * width / 2.0,
196
+ MIDDLE + 10 * (shape_c * width / 2.0) + 40,
197
+ shape_b)
198
+
199
+ set_dimension(canvas, "shape_c_arrow", "shape_c_text",
200
+ RIGHT + 10,
201
+ MIDDLE - 10 * shape_c * width / 2.0,
202
+ RIGHT + 10,
203
+ MIDDLE + 10 * shape_c * width / 2.0,
204
+ RIGHT + 15,
205
+ MIDDLE,
206
+ shape_c)
207
+
208
+ # Info
209
+
210
+ width_info = canvas.instance_variable_get(:@width_info)
211
+ width_info.text = "line-width: #{width}"
212
+
213
+ shape_a_info = canvas.instance_variable_get(:@shape_a_info)
214
+ shape_a_info.text = "arrow-tip-length: #{shape_a} (* line-width)"
215
+
216
+ shape_b_info = canvas.instance_variable_get(:@shape_b_info)
217
+ shape_b_info.text = "arrow-length: #{shape_b} (* line-width)"
218
+
219
+ shape_c_info = canvas.instance_variable_get(:@shape_c_info)
220
+ shape_c_info.text = "arrow-length: #{shape_c} (* line-width)"
221
+
222
+ # Sample arrows
223
+
224
+ sample_1 = canvas.instance_variable_get(:@sample_1)
225
+ sample_1.line_width = width
226
+ sample_1.arrow_tip_length = shape_a
227
+ sample_1.arrow_length = shape_b
228
+ sample_1.arrow_width = shape_c
229
+ sample_2 = canvas.instance_variable_get(:@sample_2)
230
+ sample_2.line_width = width
231
+ sample_2.arrow_tip_length = shape_a
232
+ sample_2.arrow_length = shape_b
233
+ sample_2.arrow_width = shape_c
234
+ sample_3 = canvas.instance_variable_get(:@sample_3)
235
+ sample_3.line_width = width
236
+ sample_3.arrow_tip_length = shape_a
237
+ sample_3.arrow_length = shape_b
238
+ sample_3.arrow_width = shape_c
239
+ end
240
+
241
+ def create_dimension(canvas, root, arrow_name, text_name, anchor)
242
+ item = Goo::CanvasPolyline.new(:parent => root,
243
+ :close_path => false,
244
+ :points => Goo::CanvasPoints.new(0),
245
+ :fill_color => "black",
246
+ :start_arrow => true,
247
+ :end_arrow => true)
248
+ canvas.instance_variable_set("@#{arrow_name}", item)
249
+
250
+ item = Goo::CanvasText.new(:parent => root,
251
+ :text => nil,
252
+ :x => 0,
253
+ :y => 0,
254
+ :width => -1,
255
+ :anchor => anchor,
256
+ :fill_color => "black",
257
+ :font => "Sans 12")
258
+ canvas.instance_variable_set("@#{text_name}", item)
259
+ end
260
+
261
+ def create_info(canvas, root, info_name, x, y)
262
+ item = Goo::CanvasText.new(:parent => root,
263
+ :text => nil,
264
+ :x => x,
265
+ :y => y,
266
+ :width => -1,
267
+ :anchor => :nw,
268
+ :fill_color => "black",
269
+ :font => "Sans 14")
270
+ canvas.instance_variable_set("@#{info_name}", item)
271
+ end
272
+
273
+ def create_sample_arrow(canvas, root, sample_name, x1, y1, x2, y2)
274
+ points = Goo::CanvasPoints.new(2)
275
+ points.set_point(0, x1, y1)
276
+ points.set_point(1, x2, y2)
277
+ item = Goo::CanvasPolyline.new(:parent => root,
278
+ :points => points,
279
+ :start_arrow => true,
280
+ :end_arrow => true)
281
+ canvas.instance_variable_set("@#{sample_name}", item)
282
+ end
283
+
284
+ def create_drag_box(canvas, root, box_name)
285
+ item = Goo::CanvasRect.new(:parent => root,
286
+ :x => 0,
287
+ :y => 0,
288
+ :width => 10,
289
+ :height => 10,
290
+ :fill_color => 'black',
291
+ :stroke_color => 'black',
292
+ :line_width => 1.0)
293
+ canvas.instance_variable_set("@#{box_name}", item)
294
+
295
+ item.signal_connect('enter_notify_event') do
296
+ item.fill_color = 'red'
297
+ true
298
+ end
299
+ item.signal_connect('leave_notify_event') do
300
+ item.fill_color = 'black'
301
+ true
302
+ end
303
+ item.signal_connect('button_press_event') do |item, target, event|
304
+ # fixed "`initialize': ruby wrapper for this GObject* already exists."
305
+ fleur = @fleur ||= Gdk::Cursor.new(:fleur)
306
+ # Symbol is not allowed. Because "undefined method `|' for :pointer_motion_mask:Symbol"
307
+ canvas.pointer_grab(item, Gdk::Event::Mask::POINTER_MOTION_MASK | Gdk::Event::Mask::BUTTON_RELEASE_MASK, fleur, event.time)
308
+ true
309
+ end
310
+ item.signal_connect('button_release_event') do |item, target, event|
311
+ canvas.pointer_ungrab(item, event.time)
312
+ true
313
+ end
314
+ item.signal_connect('motion_notify_event') do |item, target, event|
315
+ catch :done do
316
+ throw :done, false unless event.state & :button1_mask == :button1_mask
317
+
318
+ if item == canvas.instance_variable_get(:@width_drag_box)
319
+ y = event.y
320
+ width = ((MIDDLE - y) / 5).round
321
+ throw :done, false if width < 0
322
+ canvas.instance_variable_set(:@width, width)
323
+ set_arrow_shape(canvas)
324
+ elsif item == canvas.instance_variable_get(:@shape_a_drag_box)
325
+ x = event.x
326
+ width = canvas.instance_variable_get(:@width)
327
+ shape_a = ((RIGHT - x) / 10 / width).round
328
+ throw :done, false if (shape_a < 0) || (shape_a > 30)
329
+ width = canvas.instance_variable_set(:@shape_a, shape_a)
330
+ set_arrow_shape(canvas)
331
+ elsif item == canvas.instance_variable_get(:@shape_b_c_drag_box)
332
+ change = false
333
+ width = canvas.instance_variable_get(:@width)
334
+ x = event.x
335
+ shape_b = ((RIGHT - x) / 10 / width).round
336
+ if (shape_b >= 0) && (shape_b <= 30)
337
+ canvas.instance_variable_set(:@shape_b, shape_b)
338
+ change = true
339
+ end
340
+
341
+ y = event.y
342
+ shape_c = ((MIDDLE - y) * 2 / 10 / width).round
343
+ if shape_c >= 0
344
+ canvas.instance_variable_set(:@shape_c, shape_c)
345
+ change = true
346
+ end
347
+
348
+ set_arrow_shape(canvas) if change
349
+ end
350
+ true
351
+ end
352
+ end
353
+ end
354
+ end