goocanvas 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +0 -1
- data/ext/goocanvas/extconf.rb +14 -9
- data/ext/goocanvas/rbgoocanvas.c +23 -180
- data/ext/goocanvas/rbgoocanvas.h +3 -19
- data/{sample/goocanvas-gi.rb → lib/goo/canvas-item.rb} +12 -21
- data/lib/goocanvas.rb +55 -138
- data/sample/scalability-demo.rb +57 -18
- data/sample/simple-demo.rb +1 -3
- data/sample/table-demo.rb +104 -23
- data/sample/units-demo.rb +1 -3
- data/sample/widgets-demo.rb +112 -32
- metadata +8 -25
- data/ext/goocanvas/rbgoo.c +0 -41
- data/ext/goocanvas/rbgoocairomatrix.c +0 -47
- data/ext/goocanvas/rbgoocairopattern.c +0 -47
- data/ext/goocanvas/rbgoocanvasconversions.h +0 -31
- data/ext/goocanvas/rbgoocanvasellipse.c +0 -52
- data/ext/goocanvas/rbgoocanvasgroup.c +0 -44
- data/ext/goocanvas/rbgoocanvasimage.c +0 -48
- data/ext/goocanvas/rbgoocanvasitem.c +0 -265
- data/ext/goocanvas/rbgoocanvaspoints.c +0 -88
- data/ext/goocanvas/rbgoocanvaspolyline.c +0 -45
- data/ext/goocanvas/rbgoocanvasprivate.h +0 -47
- data/ext/goocanvas/rbgoocanvasrect.c +0 -50
- data/ext/goocanvas/rbgoocanvasstyle.c +0 -62
- data/ext/goocanvas/rbgoocanvastable.c +0 -44
- data/ext/goocanvas/rbgoocanvastext.c +0 -51
- data/ext/goocanvas/rbgoocanvaswidget.c +0 -51
- data/ext/goocanvas/rbgooutils.c +0 -45
data/sample/scalability-demo.rb
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
#
|
3
|
+
# This sample code is a port of
|
4
|
+
# goocanvas/demo/scalability-demo.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
|
+
require "goocanvas"
|
3
25
|
|
4
26
|
# the values behind the comments are the ones used in the C version
|
5
27
|
# but as with them it takes more than 20 sec on my computer for the window
|
@@ -19,7 +41,7 @@ def setup_canvas(canvas)
|
|
19
41
|
|
20
42
|
item_width = 400
|
21
43
|
item_height = 19
|
22
|
-
|
44
|
+
|
23
45
|
cell_width = item_width + PADDING * 2
|
24
46
|
cell_height = item_height + PADDING * 2
|
25
47
|
|
@@ -36,12 +58,16 @@ def setup_canvas(canvas)
|
|
36
58
|
style = Goo::CanvasStyle.new
|
37
59
|
color = Gdk::Color.parse("mediumseagreen")
|
38
60
|
pattern = Cairo::SolidPattern.new(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0)
|
39
|
-
|
61
|
+
# NOTE: "Goo::CanvasStyle#fill_pattern=" doesn't work. (undefined method)
|
62
|
+
# Substitution is "Goo::CanvasRect#fill_color=".
|
63
|
+
#style.fill_pattern = pattern
|
40
64
|
|
41
65
|
style2 = Goo::CanvasStyle.new
|
42
66
|
color = Gdk::Color.parse("steelblue")
|
43
67
|
pattern = Cairo::SolidPattern.new(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0)
|
44
|
-
|
68
|
+
# NOTE: "Goo::CanvasStyle#fill_pattern=" doesn't work. (undefined method)
|
69
|
+
# Substitution is "Goo::CanvasRect#fill_color=".
|
70
|
+
#style2.fill_pattern = pattern
|
45
71
|
|
46
72
|
total_items = 0
|
47
73
|
|
@@ -50,10 +76,10 @@ def setup_canvas(canvas)
|
|
50
76
|
group_x = left_offset + (group_i * group_width);
|
51
77
|
group_y = top_offset + (group_j * group_height);
|
52
78
|
|
53
|
-
group = Goo::CanvasGroup.new(root)
|
79
|
+
group = Goo::CanvasGroup.new(:parent => root)
|
54
80
|
total_items += 1
|
55
81
|
group.translate(group_x, group_y)
|
56
|
-
|
82
|
+
|
57
83
|
N_COLS.times do |i|
|
58
84
|
N_ROWS.times do |j|
|
59
85
|
item_x = (i * cell_width) + PADDING
|
@@ -61,21 +87,32 @@ def setup_canvas(canvas)
|
|
61
87
|
rotation = i % 10 * 2
|
62
88
|
rotation_x = item_x + item_width / 2
|
63
89
|
rotation_y = item_y + item_height / 2
|
64
|
-
|
90
|
+
|
65
91
|
current_id = "#{group_x + item_x}, #{group_y + item_y}"
|
66
|
-
|
67
|
-
item = Goo::CanvasRect.new(
|
68
|
-
|
92
|
+
|
93
|
+
item = Goo::CanvasRect.new(:parent => group,
|
94
|
+
:x => item_x,
|
95
|
+
:y => item_y,
|
96
|
+
:width => item_width,
|
97
|
+
:height => item_height)
|
98
|
+
# NOTE: "Goo::CanvasStyle#fill_pattern=" doesn't work. (undefined method)
|
99
|
+
# "Goo::CanvasRect#fill_color=" is substitution.
|
100
|
+
item.fill_color = (j % 2) == 1 ? "mediumseagreen" : "steelblue"
|
101
|
+
#item.style = (j % 2) == 1 ? style : style2
|
69
102
|
item.rotate(rotation, rotation_x, rotation_y)
|
70
|
-
|
103
|
+
|
71
104
|
item.signal_connect('motion_notify_event') do
|
72
105
|
puts "#{current_id} item received 'motion-notify' signal"
|
73
106
|
end
|
74
107
|
|
75
|
-
item = Goo::CanvasText.new(group,
|
76
|
-
|
108
|
+
item = Goo::CanvasText.new(:parent => group,
|
109
|
+
:text => current_id,
|
110
|
+
:x => item_x + item_width / 2,
|
111
|
+
:y => item_y + item_height / 2,
|
112
|
+
:width => -1,
|
113
|
+
:anchor => Goo::CanvasAnchorType::CENTER)
|
77
114
|
item.rotate(rotation, rotation_x, rotation_y)
|
78
|
-
|
115
|
+
|
79
116
|
total_items += 2
|
80
117
|
break if ONLY_ONE
|
81
118
|
end
|
@@ -94,7 +131,7 @@ def create_canvas
|
|
94
131
|
# Create the canvas.
|
95
132
|
canvas = Goo::Canvas.new
|
96
133
|
canvas.set_size_request(600, 450)
|
97
|
-
|
134
|
+
|
98
135
|
start = Time.new
|
99
136
|
total_width, total_height, left_offset, top_offset = setup_canvas(canvas)
|
100
137
|
puts "Create Canvas Time Used: #{Time.new - start}"
|
@@ -104,18 +141,18 @@ def create_canvas
|
|
104
141
|
canvas.show
|
105
142
|
|
106
143
|
first_time = true
|
107
|
-
canvas.signal_connect("
|
144
|
+
canvas.signal_connect("draw") do
|
108
145
|
if first_time
|
109
146
|
puts "Update Canvas Time Used: #{Time.new - start}"
|
110
147
|
first_time = false
|
111
148
|
end
|
112
149
|
false
|
113
150
|
end
|
114
|
-
|
151
|
+
|
115
152
|
canvas
|
116
153
|
end
|
117
154
|
|
118
|
-
window = Gtk::Window.new(
|
155
|
+
window = Gtk::Window.new(:toplevel)
|
119
156
|
window.set_default_size(640, 600)
|
120
157
|
window.show
|
121
158
|
window.signal_connect('delete_event') { Gtk.main_quit }
|
@@ -124,7 +161,9 @@ scrolled_win = Gtk::ScrolledWindow.new
|
|
124
161
|
scrolled_win.show
|
125
162
|
window.add(scrolled_win)
|
126
163
|
|
164
|
+
GC.disable
|
127
165
|
canvas = create_canvas
|
128
166
|
scrolled_win.add(canvas)
|
167
|
+
GC.enable
|
129
168
|
|
130
169
|
Gtk.main
|
data/sample/simple-demo.rb
CHANGED
@@ -21,9 +21,7 @@
|
|
21
21
|
# License along with this library; if not, write to the Free Software
|
22
22
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
23
23
|
|
24
|
-
require 'goocanvas
|
25
|
-
|
26
|
-
Goo.init
|
24
|
+
require 'goocanvas'
|
27
25
|
|
28
26
|
# Create the window and widgets.
|
29
27
|
window = Gtk::Window.new(:toplevel)
|
data/sample/table-demo.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
#
|
3
|
+
# This sample code is a port of
|
4
|
+
# goocanvas/demo/table-demo.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
|
+
require "goocanvas"
|
25
|
+
|
3
26
|
DEMO_RECT_ITEM = 0
|
4
27
|
DEMO_TEXT_ITEM = 1
|
5
28
|
DEMO_WIDGET_ITEM = 2
|
@@ -7,16 +30,37 @@ DEMO_WIDGET_ITEM = 2
|
|
7
30
|
def create_demo_item(table, demo_item_type, row, column, rows, columns, text)
|
8
31
|
case demo_item_type
|
9
32
|
when DEMO_RECT_ITEM
|
10
|
-
item = Goo::CanvasRect.new(
|
33
|
+
item = Goo::CanvasRect.new(:parent => table,
|
34
|
+
:x => 0,
|
35
|
+
:y => 0,
|
36
|
+
:width => 38,
|
37
|
+
:height => 19,
|
38
|
+
:fill_color => "red")
|
11
39
|
when DEMO_TEXT_ITEM
|
12
|
-
item = Goo::CanvasText.new(
|
40
|
+
item = Goo::CanvasText.new(:parent => table,
|
41
|
+
:text => text,
|
42
|
+
:x => 0,
|
43
|
+
:y => 0,
|
44
|
+
:width => -1,
|
45
|
+
:anchor => :nw)
|
13
46
|
when DEMO_WIDGET_ITEM
|
14
|
-
widget = Gtk::Button.new(text)
|
15
|
-
item = Goo::CanvasWidget.new(
|
47
|
+
widget = Gtk::Button.new(:label => text)
|
48
|
+
item = Goo::CanvasWidget.new(:parent => table,
|
49
|
+
:widget => widget,
|
50
|
+
:x => 0,
|
51
|
+
:y => 0,
|
52
|
+
:width => -1,
|
53
|
+
:height => -1)
|
16
54
|
end
|
17
55
|
|
18
|
-
table.
|
19
|
-
|
56
|
+
table.set_child_property(item, "row", row)
|
57
|
+
table.set_child_property(item, "column", column)
|
58
|
+
table.set_child_property(item, "rows", rows)
|
59
|
+
table.set_child_property(item, "columns", columns)
|
60
|
+
table.set_child_property(item, "x-expand", true)
|
61
|
+
table.set_child_property(item, "x-fill", true)
|
62
|
+
table.set_child_property(item, "y-expand", true)
|
63
|
+
table.set_child_property(item, "y-fill", true)
|
20
64
|
|
21
65
|
item.signal_connect('button_press_event') do |item, target, event|
|
22
66
|
puts "#{text} received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
|
@@ -26,13 +70,20 @@ end
|
|
26
70
|
|
27
71
|
def create_table(parent, row, column, embedding_level, x, y, rotation, scale, demo_item_type)
|
28
72
|
# Add a few simple items.
|
29
|
-
table = Goo::CanvasTable.new(parent
|
73
|
+
table = Goo::CanvasTable.new(:parent => parent,
|
74
|
+
:row_spacing => 4.0,
|
75
|
+
:column_spacing => 4.0)
|
30
76
|
|
31
77
|
table.translate(x, y)
|
32
78
|
table.rotate(rotation, 0, 0)
|
33
79
|
table.scale(scale, scale)
|
34
80
|
|
35
|
-
|
81
|
+
if row
|
82
|
+
parent.set_child_property(table, "row", row)
|
83
|
+
parent.set_child_property(table, "column", column)
|
84
|
+
parent.set_child_property(table, "x-expand", true)
|
85
|
+
parent.set_child_property(table, "x_fill", true)
|
86
|
+
end
|
36
87
|
|
37
88
|
if embedding_level > 0
|
38
89
|
level = embedding_level - 1
|
@@ -60,51 +111,81 @@ def create_table(parent, row, column, embedding_level, x, y, rotation, scale, de
|
|
60
111
|
end
|
61
112
|
|
62
113
|
def create_demo_table(root, x, y, width, height)
|
63
|
-
table = Goo::CanvasTable.new(
|
114
|
+
table = Goo::CanvasTable.new(:parent => root,
|
115
|
+
:row_spacing => 4.0,
|
116
|
+
:column_spacing => 4.0,
|
117
|
+
:width => width,
|
118
|
+
:height => height)
|
64
119
|
table.translate(x, y)
|
65
120
|
|
66
|
-
square = Goo::CanvasRect.new(
|
67
|
-
|
121
|
+
square = Goo::CanvasRect.new(:parent => table,
|
122
|
+
:x => 0.0,
|
123
|
+
:y => 0.0,
|
124
|
+
:width => 50.0,
|
125
|
+
:height => 50.0,
|
126
|
+
:fill_color => "red")
|
127
|
+
table.set_child_property(square, "row", 0)
|
128
|
+
table.set_child_property(square, "column", 0)
|
129
|
+
table.set_child_property(square, "x_shrink", true)
|
68
130
|
square.signal_connect('button_press_event') do |item, target, event|
|
69
131
|
puts "Red square received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
|
70
132
|
true
|
71
133
|
end
|
72
134
|
|
73
|
-
circle = Goo::CanvasEllipse.new(
|
74
|
-
|
135
|
+
circle = Goo::CanvasEllipse.new(:parent => table,
|
136
|
+
:x => 0.0,
|
137
|
+
:y => 0.0,
|
138
|
+
:radius_x => 25.0,
|
139
|
+
:radius_y => 25.0,
|
140
|
+
:fill_color => "blue")
|
141
|
+
table.set_child_property(circle, "row", 0)
|
142
|
+
table.set_child_property(circle, "column", 1)
|
143
|
+
table.set_child_property(circle, "x_shrink", true)
|
75
144
|
circle.signal_connect('button_press_event') do |item, target, event|
|
76
145
|
puts "Blue circle received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
|
77
146
|
true
|
78
147
|
end
|
79
148
|
|
80
|
-
|
81
|
-
|
149
|
+
points = Goo::CanvasPoints.new(3)
|
150
|
+
points.set_point(0, 25.0, 0.0)
|
151
|
+
points.set_point(1, 0.0, 50.0)
|
152
|
+
points.set_point(2, 50.0, 50.0)
|
153
|
+
triangle = Goo::CanvasPolyline.new(:parent => table,
|
154
|
+
:close_path => true,
|
155
|
+
:points => points,
|
156
|
+
:fill_color => "yellow")
|
157
|
+
table.set_child_property(triangle, "row", 0)
|
158
|
+
table.set_child_property(triangle, "column", 2)
|
159
|
+
table.set_child_property(triangle, "x_shrink", true)
|
82
160
|
triangle.signal_connect('button_press_event') do |item, target, event|
|
83
161
|
puts "Yellow triangle received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
|
84
162
|
true
|
85
163
|
end
|
86
164
|
end
|
87
165
|
|
88
|
-
window = Gtk::Window.new(
|
166
|
+
window = Gtk::Window.new(:toplevel)
|
89
167
|
window.set_default_size(640, 600)
|
90
168
|
window.signal_connect('delete_event') { Gtk.main_quit }
|
91
169
|
|
92
|
-
vbox = Gtk::
|
170
|
+
vbox = Gtk::Box.new(:vertical, 4)
|
93
171
|
vbox.border_width = 4
|
94
172
|
vbox.show
|
95
173
|
window.add(vbox)
|
96
174
|
|
97
|
-
hbox = Gtk::
|
98
|
-
vbox.pack_start(hbox,
|
175
|
+
hbox = Gtk::Box.new(:horizontal, 4)
|
176
|
+
vbox.pack_start(hbox, :expand => false,
|
177
|
+
:fill => false,
|
178
|
+
:padding => 0)
|
99
179
|
hbox.show
|
100
180
|
|
101
181
|
scrolled_win = Gtk::ScrolledWindow.new
|
102
|
-
scrolled_win.shadow_type =
|
182
|
+
scrolled_win.shadow_type = :in
|
103
183
|
scrolled_win.show
|
104
|
-
vbox.pack_start(scrolled_win,
|
184
|
+
vbox.pack_start(scrolled_win, :expand => true,
|
185
|
+
:fill => true,
|
186
|
+
:padding => 0)
|
105
187
|
|
106
188
|
canvas = Goo::Canvas.new
|
107
|
-
canvas.flags = Gtk::Widget::CAN_FOCUS
|
108
189
|
canvas.set_size_request(600, 450)
|
109
190
|
canvas.set_bounds(0, 0, 1000, 1000)
|
110
191
|
scrolled_win.add(canvas)
|
data/sample/units-demo.rb
CHANGED
@@ -21,9 +21,7 @@
|
|
21
21
|
# License along with this library; if not, write to the Free Software
|
22
22
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
23
23
|
|
24
|
-
require 'goocanvas
|
25
|
-
|
26
|
-
Goo.init
|
24
|
+
require 'goocanvas'
|
27
25
|
|
28
26
|
DATA = {
|
29
27
|
:pixel => [ 100, 100, 200, 20, 10, 200, 310, 24 ],
|
data/sample/widgets-demo.rb
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
#
|
3
|
+
# This sample code is a port of
|
4
|
+
# goocanvas/demo/widgets-demo.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
|
+
require "goocanvas"
|
3
25
|
|
4
26
|
num_added_widgets = 0
|
5
27
|
added_widget_items = []
|
@@ -8,7 +30,15 @@ move_item = nil
|
|
8
30
|
|
9
31
|
def create_focus_box(canvas, x, y, width, height, color)
|
10
32
|
root = canvas.root_item
|
11
|
-
item = Goo::CanvasRect.new(
|
33
|
+
item = Goo::CanvasRect.new(:parent => root,
|
34
|
+
:x => x,
|
35
|
+
:y => y,
|
36
|
+
:width => width,
|
37
|
+
:height => height,
|
38
|
+
:stroke_pattern => nil,
|
39
|
+
:fill_color => color,
|
40
|
+
:line_width => 5.0,
|
41
|
+
:can_focus => true)
|
12
42
|
|
13
43
|
item.signal_connect('focus_in_event') do
|
14
44
|
puts "#{color} received focus-in event"
|
@@ -39,25 +69,29 @@ def create_focus_box(canvas, x, y, width, height, color)
|
|
39
69
|
end
|
40
70
|
|
41
71
|
def add_button(hbox, button_name, &click_action)
|
42
|
-
w = Gtk::Button.new(button_name)
|
43
|
-
hbox.pack_start(w,
|
72
|
+
w = Gtk::Button.new(:label => button_name)
|
73
|
+
hbox.pack_start(w, :expand => false,
|
74
|
+
:fill => false,
|
75
|
+
:padding => 0)
|
44
76
|
w.show
|
45
77
|
w.signal_connect('clicked', &click_action)
|
46
78
|
end
|
47
79
|
|
48
80
|
# Create the window and widgets.
|
49
|
-
window = Gtk::Window.new(
|
81
|
+
window = Gtk::Window.new(:toplevel)
|
50
82
|
window.set_default_size(640, 600)
|
51
83
|
window.show
|
52
84
|
window.signal_connect('delete_event') { Gtk.main_quit }
|
53
85
|
|
54
|
-
vbox = Gtk::
|
86
|
+
vbox = Gtk::Box.new(:vertical, 4)
|
55
87
|
vbox.border_width = 4
|
56
88
|
vbox.show
|
57
89
|
window.add(vbox)
|
58
90
|
|
59
|
-
hbox = Gtk::
|
60
|
-
vbox.pack_start(hbox,
|
91
|
+
hbox = Gtk::Box.new(:horizontal, 4)
|
92
|
+
vbox.pack_start(hbox, :expand => false,
|
93
|
+
:fill => false,
|
94
|
+
:padding => 0)
|
61
95
|
hbox.show
|
62
96
|
|
63
97
|
add_button(hbox, 'Add Widget') do
|
@@ -68,7 +102,12 @@ add_button(hbox, 'Add Widget') do
|
|
68
102
|
end
|
69
103
|
|
70
104
|
root = canvas.root_item
|
71
|
-
witem = Goo::CanvasWidget.new(
|
105
|
+
witem = Goo::CanvasWidget.new(:parent => root,
|
106
|
+
:widget => widget,
|
107
|
+
:x => num_added_widgets * 50,
|
108
|
+
:y => num_added_widgets * 50,
|
109
|
+
:width => 200,
|
110
|
+
:height => 50)
|
72
111
|
|
73
112
|
added_widget_items.push(witem)
|
74
113
|
num_added_widgets += 1
|
@@ -100,12 +139,14 @@ add_button(hbox, 'Move Widget') do
|
|
100
139
|
end
|
101
140
|
|
102
141
|
# here we have to do a little more complicated than in C because Ruby/Gtk+'s enums are not ints and we can't do + 1 on them
|
103
|
-
moving_anchor =
|
142
|
+
moving_anchor = Goo::CanvasAnchorType::CENTER.to_i
|
104
143
|
add_button(hbox, 'Change Anchor') do
|
105
|
-
puts "Setting anchor to: #{
|
144
|
+
puts "Setting anchor to: #{Goo::CanvasAnchorType.new(moving_anchor).name}"
|
106
145
|
move_item.anchor = moving_anchor
|
107
146
|
moving_anchor += 1
|
108
|
-
|
147
|
+
if moving_anchor > Goo::CanvasAnchorType::EAST.to_i
|
148
|
+
moving_anchor = Goo::CanvasAnchorType::CENTER.to_i
|
149
|
+
end
|
109
150
|
end
|
110
151
|
|
111
152
|
add_button(hbox, 'Change Widget') do
|
@@ -119,23 +160,26 @@ add_button(hbox, 'Change Widget') do
|
|
119
160
|
end
|
120
161
|
end
|
121
162
|
|
122
|
-
hbox = Gtk::
|
123
|
-
vbox.pack_start(hbox,
|
163
|
+
hbox = Gtk::Box.new(:horizontal, 4)
|
164
|
+
vbox.pack_start(hbox, :expand => false,
|
165
|
+
:fill => false,
|
166
|
+
:padding => 0)
|
124
167
|
hbox.show
|
125
168
|
|
126
169
|
add_button(hbox, 'Hide Canvas') { canvas.hide }
|
127
170
|
add_button(hbox, 'Show Canvas') { canvas.show }
|
128
|
-
add_button(hbox, 'Hide Item') { move_item.visibility =
|
129
|
-
add_button(hbox, 'Show Item') { move_item.visibility =
|
171
|
+
add_button(hbox, 'Hide Item') { move_item.visibility = :invisible }
|
172
|
+
add_button(hbox, 'Show Item') { move_item.visibility = :visible }
|
130
173
|
add_button(hbox, 'Change Transform') { move_item.translate(25, 25) }
|
131
174
|
|
132
175
|
scrolled_win = Gtk::ScrolledWindow.new
|
133
|
-
scrolled_win.shadow_type =
|
176
|
+
scrolled_win.shadow_type = :in
|
134
177
|
scrolled_win.show
|
135
|
-
vbox.pack_start(scrolled_win,
|
178
|
+
vbox.pack_start(scrolled_win, :expand => true,
|
179
|
+
:fill => true,
|
180
|
+
:padding => 0)
|
136
181
|
|
137
182
|
canvas = Goo::Canvas.new
|
138
|
-
canvas.flags = Gtk::Widget::CAN_FOCUS
|
139
183
|
canvas.set_size_request(600, 450)
|
140
184
|
canvas.set_bounds(0, 0, 1000, 1000)
|
141
185
|
scrolled_win.add(canvas)
|
@@ -144,47 +188,83 @@ root = canvas.root_item
|
|
144
188
|
|
145
189
|
# Add a few simple items.
|
146
190
|
label = Gtk::Label.new("Hello World")
|
147
|
-
witem = Goo::CanvasWidget.new(
|
191
|
+
witem = Goo::CanvasWidget.new(:parent => root,
|
192
|
+
:widget => label,
|
193
|
+
:x => 50,
|
194
|
+
:y => 50,
|
195
|
+
:width => 200,
|
196
|
+
:height => 100)
|
148
197
|
|
149
198
|
entry = Gtk::Entry.new
|
150
|
-
move_item = Goo::CanvasWidget.new(
|
199
|
+
move_item = Goo::CanvasWidget.new(:parent => root,
|
200
|
+
:widget => entry,
|
201
|
+
:x => 50,
|
202
|
+
:y => 250,
|
203
|
+
:width => 200,
|
204
|
+
:height => 50)
|
151
205
|
|
152
206
|
entry = Gtk::Entry.new
|
153
207
|
entry.text = "Size: -1 x -1"
|
154
|
-
witem = Goo::CanvasWidget.new(
|
208
|
+
witem = Goo::CanvasWidget.new(:parent => root,
|
209
|
+
:widget => entry,
|
210
|
+
:x => 50,
|
211
|
+
:y => 300,
|
212
|
+
:width => -1,
|
213
|
+
:height => -1)
|
155
214
|
|
156
215
|
entry = Gtk::Entry.new
|
157
216
|
entry.text = "Size: 100 x -1"
|
158
|
-
witem = Goo::CanvasWidget.new(
|
217
|
+
witem = Goo::CanvasWidget.new(:parent => root,
|
218
|
+
:widget => entry,
|
219
|
+
:x => 50,
|
220
|
+
:y => 350,
|
221
|
+
:width => 100,
|
222
|
+
:height => -1)
|
159
223
|
|
160
224
|
# Use a textview so we can see the width & height of the widget.
|
161
225
|
scrolled_win = Gtk::ScrolledWindow.new
|
162
|
-
scrolled_win.shadow_type =
|
163
|
-
scrolled_win.set_policy(
|
226
|
+
scrolled_win.shadow_type = :in
|
227
|
+
scrolled_win.set_policy(:never, :never)
|
164
228
|
textview = Gtk::TextView.new
|
165
229
|
buffer = textview.buffer
|
166
230
|
buffer.text = "Size: -1 x 100"
|
167
231
|
textview.show
|
168
232
|
scrolled_win.add(textview)
|
169
233
|
scrolled_win.set_size_request(160, 50)
|
170
|
-
witem = Goo::CanvasWidget.new(
|
234
|
+
witem = Goo::CanvasWidget.new(:parent => root,
|
235
|
+
:widget => scrolled_win,
|
236
|
+
:x => 50,
|
237
|
+
:y => 400,
|
238
|
+
:width => -1,
|
239
|
+
:height => 100)
|
171
240
|
|
172
241
|
# Create a vbox item with several child entry widgets to check focus traversal.
|
173
|
-
vbox = Gtk::
|
242
|
+
vbox = Gtk::Box.new(:vertical, 4)
|
174
243
|
|
175
244
|
entry = Gtk::Entry.new
|
176
245
|
entry.show
|
177
|
-
vbox.pack_start(entry,
|
246
|
+
vbox.pack_start(entry, :expand => false,
|
247
|
+
:fill => false,
|
248
|
+
:padding => 0)
|
178
249
|
|
179
250
|
entry = Gtk::Entry.new
|
180
251
|
entry.show
|
181
|
-
vbox.pack_start(entry,
|
252
|
+
vbox.pack_start(entry, :expand => false,
|
253
|
+
:fill => false,
|
254
|
+
:padding => 0)
|
182
255
|
|
183
256
|
entry = Gtk::Entry.new
|
184
257
|
entry.show
|
185
|
-
vbox.pack_start(entry,
|
186
|
-
|
187
|
-
|
258
|
+
vbox.pack_start(entry, :expand => false,
|
259
|
+
:fill => false,
|
260
|
+
:padding => 0)
|
261
|
+
|
262
|
+
witem = Goo::CanvasWidget.new(:parent => root,
|
263
|
+
:widget => vbox,
|
264
|
+
:x => 50,
|
265
|
+
:y => 600,
|
266
|
+
:width => -1,
|
267
|
+
:height => -1)
|
188
268
|
|
189
269
|
# Create a few normal canvas items that take keyboard focus.
|
190
270
|
create_focus_box(canvas, 110, 80, 50, 30, 'red')
|