clutter 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/easing-mode.c.
4
+ # It is licensed under the terms of the GNU Lesser General Public
5
+ # License, version 2.1 or (at your option) later.
6
+ #
7
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
8
+ #
9
+ # This library is free software; you can redistribute it and/or
10
+ # modify it under the terms of the GNU Lesser General Public
11
+ # License as published by the Free Software Foundation; either
12
+ # version 2.1 of the License, or (at your option) any later version.
13
+ #
14
+ # This library is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ # Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public
20
+ # License along with this library; if not, write to the Free Software
21
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
+
23
+ require "optparse"
24
+
25
+ require "clutter"
26
+
27
+ Clutter.init
28
+
29
+ duration = 1
30
+
31
+ parser = OptionParser.new
32
+ parser.on("--duration=SECONDS", Integer,
33
+ "Duration of the animation",
34
+ "(#{duration})") do |_duration|
35
+ duration = _duration
36
+ end
37
+ parser.parse!
38
+
39
+ current_mode_index = 0
40
+ easing_modes = Clutter::AnimationMode.values.reject do |mode|
41
+ mode == Clutter::AnimationMode::CUSTOM_MODE
42
+ end
43
+
44
+ help_text = lambda do
45
+ format = <<-EOT.chomp
46
+ <b>Easing mode: %s (%d of %d)</b>
47
+ Left click to tween
48
+ Middle click to jump
49
+ Right click to change the easing mode
50
+ EOT
51
+ current_mode = easing_modes[current_mode_index]
52
+ format % [current_mode.nick, current_mode_index, easing_modes.size]
53
+ end
54
+
55
+ stage = Clutter::Stage.new
56
+ stage.title = "Easing Modes"
57
+ stage.background_color = Clutter::Color.new(:sky_blue_light)
58
+ stage.signal_connect("destroy") do
59
+ Clutter.main_quit
60
+ end
61
+
62
+ main_stage = stage
63
+
64
+ stage_size = stage.size
65
+ stage_width = stage_size.width
66
+ stage_height = stage_size.height
67
+
68
+ bouncer_width = 50
69
+ bouncer_height = 50
70
+
71
+ canvas = Clutter::Canvas.new
72
+ canvas.signal_connect("draw") do |_canvas, cairo_context, width, height|
73
+ cairo_context.operator = :clear
74
+ cairo_context.paint
75
+
76
+ cairo_context.operator = :over
77
+
78
+ radius = [width, height].max
79
+
80
+ cairo_context.arc(radius / 2, radius / 2, radius / 2, 0.0, 2.0 * Math::PI)
81
+
82
+ bouncer_color = Clutter::Color.new(:scarlet_red_dark)
83
+
84
+ pattern = Cairo::RadialPattern.new(radius / 2, radius / 2, 0,
85
+ radius, radius, radius)
86
+ pattern.add_color_stop_rgba(0,
87
+ bouncer_color.red / 255.0,
88
+ bouncer_color.green / 255.0,
89
+ bouncer_color.blue / 255.0,
90
+ bouncer_color.alpha / 255.0)
91
+ pattern.add_color_stop_rgba(0.85,
92
+ bouncer_color.red / 255.0,
93
+ bouncer_color.green / 255.0,
94
+ bouncer_color.blue / 255.0,
95
+ 0.25);
96
+
97
+ cairo_context.set_source(pattern)
98
+ cairo_context.fill
99
+
100
+ Clutter::Event::STOP
101
+ end
102
+ canvas.set_size(bouncer_width, bouncer_height)
103
+
104
+ rectangle = Clutter::Actor.new
105
+ rectangle.name = "bouncer"
106
+ rectangle.set_size(bouncer_width, bouncer_height)
107
+ rectangle.set_pivot_point(0.5, 0.5)
108
+ rectangle.set_translation(bouncer_width / -2.0, bouncer_height / -2.0, 0.0)
109
+ rectangle.reactive = true
110
+ rectangle.content = canvas
111
+
112
+ stage.add_child(rectangle)
113
+ rectangle.set_position(stage_width / 2, stage_height / 2)
114
+
115
+ label = Clutter::Text.new
116
+ stage.add_child(label)
117
+ label.markup = help_text.call
118
+ label.line_alignment = :right
119
+ label.add_constraint(Clutter::AlignConstraint.new(stage, :x_axis, 0.95))
120
+ label.add_constraint(Clutter::AlignConstraint.new(stage, :y_axis, 0.95))
121
+ easing_mode_label = label
122
+
123
+ stage.signal_connect("button-press-event") do |actor, event|
124
+ case event.button
125
+ when Clutter::BUTTON_SECONDARY
126
+ current_mode_index = (current_mode_index + 1) % easing_modes.size
127
+ label.markup = help_text.call
128
+ when Clutter::BUTTON_MIDDLE
129
+ rectangle.set_position(event.x, event.y)
130
+ when Clutter::BUTTON_PRIMARY
131
+ current_mode = easing_modes[current_mode_index]
132
+ rectangle.save_easing_state do
133
+ rectangle.easing_mode = current_mode
134
+ rectangle.easing_duration = duration * 1000
135
+
136
+ rectangle.set_position(event.x, event.y)
137
+ end
138
+ end
139
+
140
+ Clutter::Event::STOP
141
+ end
142
+
143
+ stage.show
144
+
145
+ Clutter.main
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/flow-layout.c.
4
+ # It is licensed under the terms of the GNU Lesser General Public
5
+ # License, version 2.1 or (at your option) later.
6
+ #
7
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
8
+ #
9
+ # This library is free software; you can redistribute it and/or
10
+ # modify it under the terms of the GNU Lesser General Public
11
+ # License as published by the Free Software Foundation; either
12
+ # version 2.1 of the License, or (at your option) any later version.
13
+ #
14
+ # This library is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ # Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public
20
+ # License along with this library; if not, write to the Free Software
21
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
+
23
+ require "optparse"
24
+
25
+ require "clutter"
26
+
27
+ Clutter.init
28
+
29
+ random_size_p = false
30
+ n_rects = 20
31
+ vertical_p = false
32
+ homogeneous_p = false
33
+ x_spacing = 0
34
+ y_spacing = 0
35
+ fixed_size_p = false
36
+
37
+ parser = OptionParser.new
38
+ parser.on("--[no-]random-size",
39
+ "Randomly size the rectangles",
40
+ "(#{random_size_p})") do |boolean|
41
+ random_size_p = boolean
42
+ end
43
+ parser.on("--n-rects=N", Integer,
44
+ "Number of rectangles",
45
+ "(#{n_rects})") do |n|
46
+ n_rects = n
47
+ end
48
+ parser.on("--[no-]vertical",
49
+ "Set vertical orientation",
50
+ "(#{vertical_p})") do |boolean|
51
+ vertical_p = boolean
52
+ end
53
+ parser.on("--[no-]homogeneous",
54
+ "Whether the layout should be homogeneous",
55
+ "(#{homogeneous_p})") do |boolean|
56
+ homogeneous_p = boolean
57
+ end
58
+ parser.on("--x-spacing=PIXEL", Integer,
59
+ "Horizontal spacing between elements",
60
+ "(#{x_spacing})") do |pixel|
61
+ x_spacing = pixel
62
+ end
63
+ parser.on("--y-spacing=PIXEL", Integer,
64
+ "Vertical spacing between elements",
65
+ "(#{y_spacing})") do |pixel|
66
+ y_spacing = pixel
67
+ end
68
+ parser.on("--[no-]fixed-size",
69
+ "Fix the layout size",
70
+ "(#{fixed_size_p})") do |boolean|
71
+ fixed_size_p = boolean
72
+ end
73
+ parser.parse!
74
+
75
+ stage = Clutter::Stage.new
76
+ stage.background_color = Clutter::Color.new(:sky_blue_light)
77
+ stage.title = "Flow Layout"
78
+ stage.user_resizable = true
79
+ stage.signal_connect("destroy") do
80
+ Clutter.main_quit
81
+ end
82
+
83
+ layout = Clutter::FlowLayout.new(vertical_p ? :vertical : :horizontal)
84
+ layout.homogeneous = homogeneous_p
85
+ layout.column_spacing = x_spacing
86
+ layout.row_spacing = y_spacing
87
+
88
+ box = Clutter::Actor.new
89
+ box.layout_manager = layout
90
+ box.background_color = Clutter::Color.new(:aluminium_2)
91
+ stage.add_child(box)
92
+
93
+ unless fixed_size_p
94
+ box.add_constraint(Clutter::BindConstraint.new(stage, :size, 0.0))
95
+ end
96
+
97
+ box.set_position(0, 0)
98
+ box.name = "box"
99
+
100
+ n_rects.times do |i|
101
+ color = Clutter::Color.hls(360.0 / n_rects * i,
102
+ 0.5,
103
+ 0.8)
104
+ rect = Clutter::Actor.new
105
+ rect.background_color = color
106
+ if random_size_p
107
+ width = rand(50..100)
108
+ height = rand(50..100)
109
+ else
110
+ width = height = 50.0
111
+ end
112
+
113
+ rect.set_size(width, height)
114
+ rect.name = "rect%02d" % i
115
+
116
+ box.add_child(rect)
117
+ end
118
+
119
+ stage.show
120
+
121
+ Clutter.main
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/grid-layout.c.
4
+ # The original header:
5
+ # Copyright 2012 Bastian Winkler <buz@netbuz.org>
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify it
8
+ # under the terms and conditions of the GNU Lesser General Public License,
9
+ # version 2.1, as published by the Free Software Foundation.
10
+ #
11
+ # This program is distributed in the hope it will be useful, but WITHOUT ANY
12
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14
+ # more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program; if not, write to the Free Software Foundation,
18
+ # Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19
+ # Boston, MA 02111-1307, USA.
20
+ #
21
+ #
22
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
23
+ #
24
+ # This library is free software; you can redistribute it and/or
25
+ # modify it under the terms of the GNU Lesser General Public
26
+ # License, version 2.1, as published by the Free Software Foundation.
27
+ #
28
+ # This library is distributed in the hope that it will be useful,
29
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
30
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31
+ # Lesser General Public License for more details.
32
+ #
33
+ # You should have received a copy of the GNU Lesser General Public
34
+ # License along with this library; if not, write to the Free Software
35
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36
+
37
+ require "optparse"
38
+
39
+ require "clutter"
40
+
41
+ Clutter.init
42
+
43
+ random_size_p = false
44
+ random_align_p = false
45
+ default_expand_p = true
46
+ use_box_p = false
47
+ vertical_p = false
48
+
49
+ parser = OptionParser.new
50
+ parser.on("--[no-]random-size",
51
+ "Randomly size the rectangles",
52
+ "(#{random_size_p})") do |boolean|
53
+ random_size_p = boolean
54
+ end
55
+ parser.on("--[no-]random-align",
56
+ "Randomly set the align values",
57
+ "(#{random_align_p})") do |boolean|
58
+ random_align_p = boolean
59
+ end
60
+ parser.on("--no-expand",
61
+ "Don't expand all actors by default",
62
+ "(#{default_expand_p})") do |boolean|
63
+ default_expand_p = boolean
64
+ end
65
+ parser.on("--[no-]box",
66
+ "Use the layout in a Clutter::BoxLayout style",
67
+ "(#{use_box_p})") do |boolean|
68
+ use_box_p = boolean
69
+ end
70
+ parser.on("--[no-]vertical",
71
+ "Use a vertical orientation when used with --box",
72
+ "(#{vertical_p})") do |boolean|
73
+ vertical_p = boolean
74
+ end
75
+ parser.parse!
76
+
77
+ stage = Clutter::Stage.new
78
+ stage.user_resizable = true
79
+
80
+ stage_layout = Clutter::BoxLayout.new
81
+ stage_layout.orientation = :vertical
82
+ stage.layout_manager = stage_layout
83
+
84
+ grid_layout = Clutter::GridLayout.new
85
+ if vertical_p
86
+ grid_layout.orientation = :vertical
87
+ end
88
+
89
+ box = Clutter::Actor.new
90
+ box.background_color = Clutter::Color.new(:light_gray)
91
+ box.x_expand = true
92
+ box.y_expand = true
93
+ box.layout_manager = grid_layout
94
+ stage_layout.pack(box, true, true, true, :center, :center)
95
+
96
+ add_actor = lambda do |left, top, width, height|
97
+ color = Clutter::Color.hls(rand(0.0...360.0),
98
+ 0.5,
99
+ 0.5)
100
+ color.alpha = 255
101
+
102
+ layout = Clutter::BinLayout.new(:center, :center)
103
+ rect = Clutter::Actor.new
104
+ rect.layout_manager = layout
105
+ rect.background_color = color
106
+ rect.reactive = true
107
+
108
+ if random_size_p
109
+ rect.set_size(rand(40..80),
110
+ rand(40..80))
111
+ else
112
+ rect.set_size(60, 60)
113
+ end
114
+ rect.x_expand = default_expand_p
115
+ rect.y_expand = default_expand_p
116
+
117
+ unless default_expand_p
118
+ rect.x_align = :center
119
+ rect.y_align = :center
120
+ end
121
+
122
+ if random_align_p
123
+ aligns = Clutter::ActorAlign.values
124
+ rect.x_align = aligns[rand(aligns.size)]
125
+ rect.y_align = aligns[rand(aligns.size)]
126
+ end
127
+
128
+ text = Clutter::Text.new("Sans 8px", "")
129
+ text.line_alignment = :center
130
+ rect.add_child(text)
131
+
132
+ changed = lambda do |actor, pspec|
133
+ layout = box.layout_manager
134
+ meta = layout.get_child_meta(box, actor)
135
+
136
+ label = <<-EOL.chomp
137
+ attach: #{meta.left_attach},#{meta.top_attach}
138
+ span: #{meta.width},#{meta.height}
139
+ expand: #{actor.x_expand?},#{actor.y_expand?}
140
+ align: #{actor.x_align.nick},#{actor.y_align.nick}"
141
+ EOL
142
+ text.text = label
143
+ end
144
+
145
+ rect.signal_connect("button-release-event") do |actor, event|
146
+ x_align = actor.x_align
147
+ y_align = actor.y_align
148
+ x_expand_p = actor.x_expand?
149
+ y_expand_p = actor.y_expand?
150
+
151
+ processed = true
152
+ aligns = Clutter::ActorAlign.values
153
+ case event.button
154
+ when Clutter::BUTTON_PRIMARY
155
+ if event.has_shift_modifier?
156
+ actor.x_expand = !actor.x_expand?
157
+ else
158
+ actor.x_align = aligns[(actor.x_align.to_i + 1) % aligns.size]
159
+ end
160
+ when Clutter::BUTTON_SECONDARY
161
+ if event.has_shift_modifier?
162
+ actor.y_expand = !actor.y_expand?
163
+ else
164
+ actor.y_align = aligns[(actor.y_align.to_i + 1) % aligns.size]
165
+ end
166
+ else
167
+ processed = false
168
+ end
169
+ processed
170
+ end
171
+ rect.signal_connect("notify::x-expand", &changed)
172
+ rect.signal_connect("notify::y-expand", &changed)
173
+ rect.signal_connect("notify::x-align", &changed)
174
+ rect.signal_connect("notify::y-align", &changed)
175
+
176
+ layout = box.layout_manager
177
+ if use_box_p
178
+ box.add_child(rect)
179
+ else
180
+ layout.attach(rect, left, top, width, height)
181
+ end
182
+ changed.call(rect, nil)
183
+ end
184
+
185
+ add_actor.call(0, 0, 1, 1)
186
+ add_actor.call(1, 0, 1, 1)
187
+ add_actor.call(2, 0, 1, 1)
188
+ add_actor.call(0, 1, 1, 1)
189
+ add_actor.call(1, 1, 2, 1)
190
+ add_actor.call(0, 2, 3, 1)
191
+ add_actor.call(0, 3, 2, 2)
192
+ add_actor.call(2, 3, 1, 1)
193
+ add_actor.call(2, 4, 1, 1)
194
+
195
+ instructions = Clutter::Text.new("Sans 12px", <<-EOI.chomp)
196
+ Press r\t\342\236\236\tSwitch row homogeneous
197
+ Press c\t\342\236\236\tSwitch column homogeneous
198
+ Press s\t\342\236\236\tIncrement spacing (up to 12px)
199
+ Press q\t\342\236\236\tQuit
200
+
201
+ Left/right click\t\t\342\236\236\tChange actor align
202
+ Shift left/right click\t\342\236\236\tChange actor expand
203
+ EOI
204
+ instructions.margin_top = 4
205
+ instructions.margin_left = 4
206
+ instructions.margin_bottom = 4
207
+ stage_layout.pack(instructions, false, true, false, :start, :center)
208
+
209
+ stage.signal_connect("destroy") do
210
+ Clutter.main_quit
211
+ end
212
+
213
+ stage.signal_connect("key-release-event") do |actor, event|
214
+ layout = box.layout_manager
215
+
216
+ processed = true
217
+ case event.key_symbol
218
+ when Clutter::Keys::KEY_c
219
+ homogeneous_p = layout.column_homogeneous?
220
+ layout.column_homogeneous = !homogeneous_p
221
+ when Clutter::Keys::KEY_r
222
+ homogeneous_p = layout.row_homogeneous?
223
+ layout.row_homogeneous = !homogeneous_p
224
+ when Clutter::Keys::KEY_s
225
+ spacing = (layout.column_spacing + 1) % 12
226
+ layout.column_spacing = spacing
227
+ layout.row_spacing = spacing
228
+ when Clutter::Keys::KEY_q
229
+ Clutter.main_quit
230
+ else
231
+ processed = false
232
+ end
233
+
234
+ processed
235
+ end
236
+
237
+ stage.show
238
+
239
+ Clutter.main