clutter 1.2.0

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,125 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/basic-actor.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) 2012 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 "clutter"
24
+
25
+ Clutter.init
26
+
27
+ stage = Clutter::Stage.new
28
+ stage.signal_connect("destroy") do |*args|
29
+ Clutter.main_quit
30
+ end
31
+
32
+ vase = Clutter::Actor.new
33
+ vase.name = "vase"
34
+ vase.layout_manager = Clutter::BoxLayout.new
35
+ vase.background_color = Clutter::Color.get_static(:sky_blue_light)
36
+ vase.add_constraint(Clutter::AlignConstraint.new(stage, :both, 0.5))
37
+ stage.add_child(vase)
38
+
39
+ SIZE = 128
40
+
41
+ flower = Clutter::Actor.new
42
+ flower.name = "flower.1"
43
+ flower.set_size(SIZE, SIZE)
44
+ flower.margin_left = 12
45
+ flower.background_color = Clutter::Color.get_static(:red)
46
+ flower.reactive = true
47
+ vase.add_child(flower)
48
+
49
+ toggled = true
50
+ flower.signal_connect("button-press-event") do |actor, event|
51
+ if toggled
52
+ end_color = Clutter::Color.get_static(:blue)
53
+ else
54
+ end_color = Clutter::Color.get_static(:red)
55
+ end
56
+
57
+ actor.save_easing_state do
58
+ actor.easing_duration = 500
59
+ actor.easing_mode = :linear
60
+ actor.background_color = end_color
61
+ end
62
+
63
+ toggled = !toggled
64
+
65
+ Clutter::Event::STOP
66
+ end
67
+
68
+ flower = Clutter::Actor.new
69
+ flower.name = "flower.2"
70
+ flower.set_size(SIZE, SIZE)
71
+ flower.margin_top = 12
72
+ flower.margin_left = 6
73
+ flower.margin_right = 6
74
+ flower.margin_bottom = 12
75
+ flower.background_color = Clutter::Color.get_static(:yellow)
76
+ flower.reactive = true
77
+ vase.add_child(flower)
78
+
79
+ on_crossing = lambda do |actor, event|
80
+ if event.type == Clutter::EventType::ENTER
81
+ zpos = -250.0
82
+ else
83
+ zpos = 0.0
84
+ end
85
+
86
+ actor.save_easing_state do
87
+ actor.easing_duration = 500
88
+ actor.easing_mode = :ease_out_bounce
89
+ actor.z_position = zpos
90
+ end
91
+
92
+ Clutter::Event::STOP
93
+ end
94
+ flower.signal_connect("enter-event", &on_crossing)
95
+ flower.signal_connect("leave-event", &on_crossing)
96
+
97
+ flower = Clutter::Actor.new
98
+ flower.name = "flower.3"
99
+ flower.set_size(SIZE, SIZE)
100
+ flower.margin_right = 12
101
+ flower.background_color = Clutter::Color::get_static(:green)
102
+ flower.set_pivot_point(0.5, 0.0)
103
+ flower.reactive = true
104
+ vase.add_child(flower);
105
+
106
+ flower.signal_connect("button-press-event") do |actor, event|
107
+ actor.save_easing_state do
108
+ actor.easing_duration = 1000
109
+ actor.set_rotation_angle(:y_axis, 360.0)
110
+ end
111
+
112
+ id = actor.signal_connect("transition-stopped::rotation-angle-y") do
113
+ actor.save_easing_state do
114
+ actor.set_rotation_angle(:y_axis, 0.0)
115
+ end
116
+
117
+ actor.signal_handler_disconnect(id)
118
+ end
119
+
120
+ Clutter::Event::STOP
121
+ end
122
+
123
+ stage.show
124
+
125
+ Clutter.main
@@ -0,0 +1,215 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/basic-actor.c. The
4
+ # image file used in this sample code is copied from
5
+ # clutter/tests/data/redhand.png. They are licensed under the terms
6
+ # of the GNU Lesser General Public License, version 2.1 or (at your
7
+ # option) later.
8
+ #
9
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
10
+ #
11
+ # This library is free software; you can redistribute it and/or
12
+ # modify it under the terms of the GNU Lesser General Public
13
+ # License as published by the Free Software Foundation; either
14
+ # version 2.1 of the License, or (at your option) any later version.
15
+ #
16
+ # This library is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
+ # Lesser General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU Lesser General Public
22
+ # License along with this library; if not, write to the Free Software
23
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
+
25
+ require "clutter"
26
+ require "gdk_pixbuf2"
27
+
28
+ Clutter.init
29
+
30
+ stage = Clutter::Stage.new
31
+ stage.title = "BinLayout"
32
+ stage.background_color = Clutter::Color.get_static(:aluminium_2)
33
+ stage.set_size(640, 480)
34
+ stage.show
35
+
36
+ stage.signal_connect("destroy") do
37
+ Clutter.main_quit
38
+ end
39
+
40
+ layout = Clutter::BinLayout.new(:center, :center)
41
+
42
+ box = Clutter::Actor.new
43
+ box.layout_manager = layout
44
+ box.add_constraint(Clutter::AlignConstraint.new(stage, :both, 0.5))
45
+ box.set_position(320, 240)
46
+ box.reactive = true
47
+ box.name = "box"
48
+ stage.add_child(box)
49
+
50
+ canvas = Clutter::Canvas.new
51
+ canvas.signal_connect("draw") do |_canvas, cairo_context, width, height|
52
+ puts("Painting at #{width}x#{height}")
53
+
54
+ cairo_context.save do
55
+ cairo_context.operator = :clear
56
+ cairo_context.paint
57
+ end
58
+
59
+ bg_round_radius = 12
60
+ x = y = 0
61
+
62
+ cairo_context.move_to(bg_round_radius, y)
63
+ cairo_context.line_to(width - bg_round_radius, y)
64
+ cairo_context.curve_to(width, y, width, y, width, bg_round_radius)
65
+ cairo_context.line_to(width, height - bg_round_radius)
66
+ cairo_context.curve_to(width, height, width, height,
67
+ width - bg_round_radius, height)
68
+ cairo_context.line_to(bg_round_radius, height)
69
+ cairo_context.curve_to(x, height, x, height, x, height - bg_round_radius)
70
+ cairo_context.line_to(x, bg_round_radius)
71
+ cairo_context.curve_to(x, y, x, y, bg_round_radius, y)
72
+
73
+ cairo_context.close_path
74
+
75
+ bg_color = Clutter::Color.new(0xcc, 0xcc, 0xcc, 0x99)
76
+ cairo_context.set_source_clutter_color(bg_color)
77
+ cairo_context.stroke
78
+
79
+ x += 4
80
+ y += 4
81
+ width -= 4
82
+ height -= 4
83
+
84
+ cairo_context.move_to(bg_round_radius, y)
85
+ cairo_context.line_to(width - bg_round_radius, y)
86
+ cairo_context.curve_to(width, y, width, y, width, bg_round_radius)
87
+ cairo_context.line_to(width, height - bg_round_radius)
88
+ cairo_context.curve_to(width, height, width, height,
89
+ width - bg_round_radius, height)
90
+ cairo_context.line_to(bg_round_radius, height)
91
+ cairo_context.curve_to(x, height, x, height, x, height - bg_round_radius)
92
+ cairo_context.line_to(x, bg_round_radius)
93
+ cairo_context.curve_to(x, y, x, y, bg_round_radius, y)
94
+
95
+ cairo_context.close_path
96
+
97
+ pattern = Cairo::LinearPattern.new(0, 0, 0, height)
98
+ pattern.add_color_stop_rgba(1, 0.85, 0.85, 0.85, 1)
99
+ pattern.add_color_stop_rgba(0.95, 1, 1, 1, 1)
100
+ pattern.add_color_stop_rgba(0.05, 1, 1, 1, 1)
101
+ pattern.add_color_stop_rgba(0, 0.85, 0.85, 0.85, 1)
102
+
103
+ cairo_context.set_source(pattern)
104
+ cairo_context.fill
105
+
106
+ true
107
+ end
108
+ canvas.set_size(200, 200)
109
+
110
+ bg = Clutter::Actor.new
111
+ bg.name = "background"
112
+ bg.set_size(200, 200)
113
+ bg.content = canvas
114
+ bg.x_expand = true
115
+ bg.y_expand = true
116
+ bg.x_align = :fill
117
+ bg.y_align = :fill
118
+ box.add_child(bg)
119
+ box.signal_connect("transitions-completed") do |actor|
120
+ canvas.set_size(actor.width, actor.height)
121
+ end
122
+
123
+ pixbuf = Gdk::Pixbuf.new(File.expand_path("redhand.png", File.dirname(__FILE__)))
124
+ image = Clutter::Image.new
125
+ image.set_data(pixbuf.pixels,
126
+ pixbuf.has_alpha? ? :rgba_8888 : :rgb_888,
127
+ pixbuf.width,
128
+ pixbuf.height,
129
+ pixbuf.rowstride)
130
+
131
+ icon = Clutter::Actor.new
132
+ icon.name = "icon"
133
+ icon.set_size(196, 196)
134
+ icon.x_expand = true
135
+ icon.y_expand = true
136
+ icon.x_align = :center
137
+ icon.y_align = :center
138
+ icon.content_gravity = :resize_aspect
139
+ icon.set_content_scaling_filters(:trilinear, :linear)
140
+ icon.content = image
141
+ box.add_child(icon)
142
+
143
+ color = Clutter::Color.new(rand(255), rand(255), rand(255), 224)
144
+ emblem = Clutter::Actor.new
145
+ emblem.name = "emblem"
146
+ emblem.set_size(48, 48)
147
+ emblem.background_color = color
148
+ emblem.x_expand = true
149
+ emblem.y_expand = true
150
+ emblem.x_align = :end
151
+ emblem.y_align = :end
152
+ emblem.reactive = true
153
+ emblem.opacity = 0
154
+ box.add_child(emblem)
155
+
156
+ action = Clutter::ClickAction.new
157
+ emblem.add_action(action)
158
+
159
+ expanded_p = false
160
+ action.signal_connect("clicked") do |_action, _emblem|
161
+ box.save_easing_state do
162
+ box.easing_mode = :ease_out_bounce
163
+ box.easing_duration = 500
164
+ if expanded_p
165
+ box.set_size(200, 200)
166
+ else
167
+ box.set_size(400, 400)
168
+ end
169
+ end
170
+ expanded_p = !expanded_p
171
+ end
172
+ action.signal_connect("long-press") do |_action, _emblem, state|
173
+ case state
174
+ when Clutter::LongPressState::QUERY
175
+ puts("*** long press: query ***")
176
+ expanded_p
177
+ when Clutter::LongPressState::CANCEL
178
+ puts("*** long press: cancel ***")
179
+ true
180
+ when Clutter::LongPressState::ACTIVATE
181
+ puts("*** long press: activate ***")
182
+ true
183
+ else
184
+ true
185
+ end
186
+ end
187
+
188
+
189
+ box.signal_connect("enter-event") do |_box, event|
190
+ emblem.save_easing_state do
191
+ emblem.easing_mode = :linear
192
+ emblem.opacity = 255
193
+ end
194
+
195
+ Clutter::Event::STOP
196
+ end
197
+ box.signal_connect("leave-event") do |_box, event|
198
+ emblem.save_easing_state do
199
+ emblem.easing_mode = :linear
200
+ emblem.opacity = 0
201
+ end
202
+
203
+ Clutter::Event::STOP
204
+ end
205
+
206
+ label = Clutter::Text.new
207
+ label.name = "text"
208
+ label.text = "A simple test"
209
+ label.x_expand = true
210
+ label.x_align = :center
211
+ label.y_expand = true
212
+ label.y_align = :start
213
+ box.add_child(label)
214
+
215
+ Clutter.main
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/box-layout.c.
4
+ # The original header:
5
+ # Copyright 2009 Intel Corporation.
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
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
22
+ #
23
+ # This library is free software; you can redistribute it and/or
24
+ # modify it under the terms of the GNU Lesser General Public
25
+ # License, version 2.1, as published by the Free Software Foundation.
26
+ #
27
+ # This library is distributed in the hope that it will be useful,
28
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30
+ # Lesser General Public License for more details.
31
+ #
32
+ # You should have received a copy of the GNU Lesser General Public
33
+ # License along with this library; if not, write to the Free Software
34
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35
+
36
+ require "clutter"
37
+
38
+ Clutter.init
39
+
40
+ stage = Clutter::Stage.new
41
+ stage.title = "Box Layout"
42
+ stage.user_resizable = true
43
+
44
+ layout = Clutter::BoxLayout.new
45
+ layout.orientation = :vertical
46
+ stage.layout_manager = layout
47
+
48
+ box = Clutter::Actor.new
49
+ box.background_color = Clutter::Color.get_static(:light_gray)
50
+ box.x_expand = true
51
+ box.y_expand = true
52
+ layout = Clutter::BoxLayout.new
53
+ box.layout_manager = layout
54
+ stage.add_child(box)
55
+
56
+ instructions_label = [
57
+ "Press v\t\342\236\236\tSwitch horizontal/vertical",
58
+ "Press h\t\342\236\236\tToggle homogeneous",
59
+ "Press p\t\342\236\236\tToggle pack start/end",
60
+ "Press s\t\342\236\236\tIncrement spacing (up to 12px)",
61
+ "Press +\t\342\236\236\tAdd a new actor",
62
+ "Press a\t\342\236\236\tToggle animations",
63
+ "Press q\t\342\236\236\tQuit"
64
+ ].join("\n")
65
+ instructions = Clutter::Text.new("Sans 12px", instructions_label)
66
+ instructions.x_expand = true
67
+ instructions.y_expand = false
68
+ instructions.x_align = :start
69
+ instructions.margin_top = 4
70
+ instructions.margin_left = 4
71
+ instructions.margin_bottom = 4
72
+ stage.add_child(instructions)
73
+
74
+ add_actor = lambda do |_box, position|
75
+ color = Clutter::Color.hls(rand * 360, 0.5, 0.5)
76
+
77
+ layout = Clutter::BinLayout.new(:center, :center)
78
+ rect = Clutter::Actor.new
79
+ rect.layout_manager = layout
80
+ rect.background_color = color
81
+ rect.reactive = true
82
+ rect.set_size(32, 64)
83
+ rect.x_expand = true
84
+ rect.y_expand = true
85
+ rect.x_align = :center
86
+ rect.y_align = :center
87
+
88
+ text = Clutter::Text.new("Sans 8px", "")
89
+ text.line_alignment = :center
90
+ rect.add_child(text)
91
+
92
+ rect.signal_connect("button-release-event") do |_rect, event|
93
+ x_align = _rect.x_align
94
+ y_align = _rect.y_align
95
+ x_expand = _rect.x_expand?
96
+ y_expand = _rect.y_expand?
97
+
98
+ case event.button
99
+ when Clutter::BUTTON_PRIMARY
100
+ aligns = Clutter::ActorAlign.values
101
+ if event.has_shift_modifier?
102
+ y_align = aligns[(aligns.index(y_align) + 1) % aligns.size]
103
+ else
104
+ x_align = aligns[(aligns.index(x_align) + 1) % aligns.size]
105
+ end
106
+ when Clutter::BUTTON_SECONDARY
107
+ if event.has_shift_modifier?
108
+ y_expand = !y_expand
109
+ else
110
+ x_expand = !x_expand
111
+ end
112
+ end
113
+
114
+ _rect.x_align = x_align
115
+ _rect.y_align = y_align
116
+ _rect.x_expand = x_expand
117
+ _rect.y_expand = y_expand
118
+
119
+ true
120
+ end
121
+
122
+ changed = lambda do |actor, pspec|
123
+ x_align = actor.x_align
124
+ y_align = actor.y_align
125
+ x_expand = actor.x_expand?
126
+ y_expand = actor.y_expand?
127
+
128
+ label = ["#{x_expand},#{y_expand}", x_align.nick, y_align.nick].join("\n")
129
+ end
130
+ rect.signal_connect("notify::x-align", &changed)
131
+ rect.signal_connect("notify::y-align", &changed)
132
+ rect.signal_connect("notify::x-expand", &changed)
133
+ rect.signal_connect("notify::y-expand", &changed)
134
+ changed.call(rect, nil)
135
+
136
+ _box.insert_child_at_index(rect, position)
137
+ end
138
+
139
+ 5.times do |i|
140
+ add_actor.call(box, i)
141
+ end
142
+
143
+ stage.signal_connect("destroy") do
144
+ Clutter.main_quit
145
+ end
146
+
147
+ stage.signal_connect("key-release-event") do |_stage, event|
148
+ layout = box.layout_manager
149
+
150
+ handled = true
151
+ case event.key_symbol
152
+ when Clutter::Keys::KEY_a
153
+ iter = Clutter::ActorIter.new(box)
154
+ iter.each do |child|
155
+ duration = child.easing_duration
156
+ if duration.zero?
157
+ duration = 250
158
+ else
159
+ duration = 0
160
+ end
161
+ child.easing_duration = duration
162
+ end
163
+ when Clutter::Keys::KEY_v
164
+ orientation = layout.orientation
165
+ if orientation == Clutter::Orientation::HORIZONTAL
166
+ orientation = :vertical
167
+ else
168
+ orientation = :horizontal
169
+ end
170
+ layout.orientation = orientation
171
+ when Clutter::Keys::KEY_h
172
+ layout.homogeneous = !layout.homogeneous?
173
+ when Clutter::Keys::KEY_p
174
+ layout.pack_start = !layout.pack_start?
175
+ when Clutter::Keys::KEY_s
176
+ spacing = layout.spacing
177
+ if spacing > 12
178
+ spacing = 0
179
+ else
180
+ spacing += 1
181
+ end
182
+ layout.spacing = spacing
183
+ when Clutter::Keys::KEY_plus
184
+ add_actor.call(box, rand(box.n_children))
185
+ when Clutter::Keys::KEY_q
186
+ Clutter.main_quit
187
+ else
188
+ handled = false
189
+ end
190
+
191
+ handled
192
+ end
193
+
194
+ stage.show
195
+
196
+ Clutter.main