goocanvas 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README +1 -1
- data/Rakefile +1 -1
- data/sample/demo-animation.rb +176 -0
- data/sample/demo-arrowhead.rb +354 -315
- data/sample/demo-events.rb +187 -0
- data/sample/demo-features.rb +148 -0
- data/sample/demo-fifteen.rb +30 -22
- data/sample/demo-focus.rb +135 -0
- data/sample/demo-primitives.rb +3 -4
- data/sample/demo.rb +17 -7
- metadata +29 -15
checksums.yaml
ADDED
@@ -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
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 = ["
|
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
|
data/sample/demo-arrowhead.rb
CHANGED
@@ -1,315 +1,354 @@
|
|
1
|
-
class CanvasSampleArrowhead < Gtk::
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
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
|