clutter 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/image-content.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) 2013 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
+ gravities = Clutter::ContentGravity.values
31
+ current_gravity_index = gravities.size - 1
32
+
33
+ stage = Clutter::Stage.new
34
+ stage.name = "Stage"
35
+ stage.title = "Content Box"
36
+ stage.user_resizable = true
37
+
38
+ stage.signal_connect("destroy") do
39
+ Clutter.main_quit
40
+ end
41
+
42
+ stage.show
43
+
44
+ box = Clutter::Actor.new
45
+ box.name = "Image"
46
+ box.margin_top = 12
47
+ box.margin_right = 12
48
+ box.margin_bottom = 12
49
+ box.margin_left = 12
50
+ box.add_constraint(Clutter::BindConstraint.new(stage, :size, 0.0))
51
+ stage.add_child(box)
52
+
53
+ pixbuf = Gdk::Pixbuf.new(File.expand_path("redhand.png", File.dirname(__FILE__)))
54
+ image = Clutter::Image.new
55
+ image.set_data(pixbuf.pixels,
56
+ pixbuf.has_alpha? ? :rgba_8888 : :rgb_888,
57
+ pixbuf.width,
58
+ pixbuf.height,
59
+ pixbuf.rowstride)
60
+
61
+ box.set_content_scaling_filters(:trilinear, :linear)
62
+ box.content_gravity = gravities[current_gravity_index]
63
+ box.content = image
64
+
65
+ text = Clutter::Text.new
66
+ text.add_constraint(Clutter::AlignConstraint.new(stage, :both, 0.5))
67
+ stage.add_child(text)
68
+
69
+ update_text = lambda do
70
+ current_gravity = gravities[current_gravity_index]
71
+ text.text = "Content gravity: #{current_gravity.nick}"
72
+ end
73
+ update_text.call
74
+
75
+ action = Clutter::TapAction.new
76
+ action.signal_connect("tap") do |_action, actor|
77
+ current_gravity_index = (current_gravity_index + 1) % gravities.size
78
+ actor.save_easing_state do
79
+ actor.content_gravity = gravities[current_gravity_index]
80
+ end
81
+
82
+ update_text.call
83
+ end
84
+
85
+ box.reactive = true
86
+ box.add_action(action)
87
+
88
+ Clutter.main
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/pan-action.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) 2013 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.name = "Pan Action"
32
+ stage.user_resizable = true
33
+
34
+ scroll = Clutter::Actor.new
35
+ scroll.name = "scroll"
36
+
37
+ scroll.add_constraint(Clutter::AlignConstraint.new(stage, :x_axis, 0))
38
+ scroll.add_constraint(Clutter::BindConstraint.new(stage, :size, 0))
39
+
40
+ content = Clutter::Actor.new
41
+ content.set_size(720, 720)
42
+
43
+ pixbuf = Gdk::Pixbuf.new(File.expand_path("redhand.png", File.dirname(__FILE__)))
44
+ image = Clutter::Image.new
45
+ image.set_data(pixbuf.pixels,
46
+ pixbuf.has_alpha? ? :rgba_8888 : :rgb_888,
47
+ pixbuf.width,
48
+ pixbuf.height,
49
+ pixbuf.rowstride)
50
+
51
+ content.set_content_scaling_filters(:trilinear, :linear)
52
+ content.content_gravity = :resize_aspect
53
+ content.content = image
54
+
55
+ scroll.add_child(content)
56
+
57
+ pan_action = Clutter::PanAction.new
58
+ pan_action.interpolate = true
59
+ pan_action.signal_connect("pan") do |action, actor, interpolated_p|
60
+ if interpolated_p
61
+ delta_x, delta_y = action.interpolated_delta
62
+ event_name = "INTERPOLATED"
63
+ else
64
+ delta_x, delta_y = action.get_motion_delta(0)
65
+ event = action.get_last_event(0)
66
+ event_name = event.class.name
67
+ end
68
+
69
+ puts("[#{event_name}] panning dx:#{delta_x} dy:#{delta_y}");
70
+ Clutter::Event::STOP
71
+ end
72
+
73
+ scroll.add_action(pan_action)
74
+ scroll.reactive = true
75
+
76
+ stage.add_child(scroll)
77
+
78
+ info = Clutter::Text.new(nil, "Press <space> to reset the image position.")
79
+ stage.add_child(info)
80
+ info.set_position(12, 12)
81
+
82
+ stage.signal_connect("destroy") do
83
+ Clutter.main_quit
84
+ end
85
+
86
+ stage.signal_connect("key-press-event") do |actor, event|
87
+ case event.key_symbol
88
+ when Clutter::Keys::KEY_space
89
+ scroll.save_easing_state do
90
+ scroll.easing_duration = 1000
91
+ scroll.child_transform = nil
92
+ end
93
+ end
94
+
95
+ Clutter::Event::STOP
96
+ end
97
+
98
+ stage.show
99
+
100
+ Clutter.main
Binary file
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/rounded-rectangle.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.title = "Rectangle with rounded corners"
29
+ stage.background_color = Clutter::Color.new(:black)
30
+ stage.set_size(500, 500)
31
+ stage.show
32
+
33
+ canvas = Clutter::Canvas.new
34
+ canvas.set_size(300, 300)
35
+
36
+ actor = Clutter::Actor.new
37
+ actor.content = canvas
38
+ actor.content_gravity = :center
39
+ actor.set_content_scaling_filters(:trilinear, :linear)
40
+ actor.set_pivot_point(0.5, 0.5)
41
+ actor.add_constraint(Clutter::BindConstraint.new(stage, :size, 0.0))
42
+ stage.add_child(actor)
43
+
44
+ transition = Clutter::PropertyTransition.new("rotation-angle-y")
45
+ transition.from = 0.0
46
+ transition.to = 360.0
47
+ transition.duration = 2000
48
+ transition.repeat_count = -1
49
+ actor.add_transition("rotateActor", transition)
50
+
51
+ stage.signal_connect("destroy") do
52
+ Clutter.main_quit
53
+ end
54
+
55
+ canvas.signal_connect("draw") do |_canvas, cairo_context, surface_width, surface_height|
56
+ x = 1.0
57
+ y = 1.0
58
+ width = surface_width - 2.0
59
+ height = surface_height - 2.0
60
+ aspect = 1.0
61
+ corner_radius = height / 20.0
62
+
63
+ radius = corner_radius / aspect
64
+ degrees = Math::PI / 180.0
65
+
66
+ cairo_context.save do
67
+ cairo_context.operator = :clear
68
+ cairo_context.paint
69
+ end
70
+
71
+ cairo_context.new_sub_path
72
+ cairo_context.arc(x + width - radius, y + radius, radius,
73
+ -90 * degrees, 0 * degrees)
74
+ cairo_context.arc(x + width - radius, y + height - radius,
75
+ radius, 0 * degrees, 90 * degrees)
76
+ cairo_context.arc(x + radius, y + height - radius, radius,
77
+ 90 * degrees, 180 * degrees)
78
+ cairo_context.arc(x + radius, y + radius, radius,
79
+ 180 * degrees, 270 * degrees)
80
+ cairo_context.close_path
81
+
82
+ cairo_context.set_source_rgb(0.5, 0.5, 1)
83
+ cairo_context.fill
84
+
85
+ Clutter::Event::STOP
86
+ end
87
+
88
+ canvas.invalidate
89
+
90
+ Clutter.main
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This sample code is a port of clutter/examples/scroll-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) 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 "clutter"
24
+
25
+ Clutter.init
26
+
27
+ stage = Clutter::Stage.new
28
+ stage.title = "Scroll Actor"
29
+ stage.user_resizable = true
30
+
31
+ stage.signal_connect("destroy") do
32
+ Clutter.main_quit
33
+ end
34
+
35
+ selected_item_index = nil
36
+ select_item_at_index = lambda do |scroll, index|
37
+ menu = scroll.first_child
38
+ if selected_item_index
39
+ item = menu.get_child_at_index(selected_item_index)
40
+ item.color = Clutter::Color.new(:white)
41
+ end
42
+
43
+ index = index % menu.n_children
44
+
45
+ item = menu.get_child_at_index(index)
46
+ succeeded, x, y = item.position
47
+
48
+ scroll.save_easing_state do
49
+ scroll.scroll_to_point(Clutter::Point.new(x, y))
50
+ end
51
+
52
+ item.color = Clutter::Color.new(:sky_blue_light)
53
+ selected_item_index = index
54
+ end
55
+
56
+ stage.signal_connect("key-press-event") do |actor, event|
57
+ scroll = stage.first_child
58
+
59
+ case event.key_symbol
60
+ when Clutter::Keys::KEY_Up
61
+ select_item_at_index.call(scroll, selected_item_index - 1)
62
+ when Clutter::Keys::KEY_Down
63
+ select_item_at_index.call(scroll, selected_item_index + 1)
64
+ end
65
+
66
+ Clutter::Event::STOP
67
+ end
68
+
69
+ scroll = Clutter::ScrollActor.new
70
+ scroll.name = "scroll"
71
+
72
+ scroll.set_position(0.0, 18.0)
73
+ scroll.add_constraint(Clutter::AlignConstraint.new(stage, :x_axis, 0.5))
74
+ scroll.add_constraint(Clutter::BindConstraint.new(stage, :height, -36.0))
75
+
76
+ scroll.scroll_mode = :vertically
77
+
78
+ layout_manager = Clutter::BoxLayout.new
79
+ layout_manager.orientation = :vertical
80
+ layout_manager.spacing = 12.0
81
+
82
+ menu = Clutter::Actor.new
83
+ menu.layout_manager = layout_manager
84
+ menu.background_color = Clutter::Color.new(:black)
85
+
86
+ n_items = 11
87
+ n_items.times do |i|
88
+ text = Clutter::Text.new
89
+ text.font_name = "Sans Bold 24"
90
+ text.text = "Option #{i + 1}"
91
+ text.color = Clutter::Color.new(:white)
92
+ text.margin_left = 12.0
93
+ text.margin_right = 12.0
94
+ menu.add_child(text)
95
+ end
96
+
97
+ scroll.add_child(menu)
98
+
99
+ select_item_at_index.call(scroll, 0)
100
+
101
+ stage.add_child(scroll)
102
+
103
+ stage.show
104
+
105
+ Clutter.main
@@ -0,0 +1,21 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "test-unit"
18
+ require "test/unit/notify"
19
+
20
+ module ClutterTestUtils
21
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ ruby_gnome2_base = File.join(File.dirname(__FILE__), "..", "..")
20
+ ruby_gnome2_base = File.expand_path(ruby_gnome2_base)
21
+
22
+ glib_base = File.join(ruby_gnome2_base, "glib2")
23
+ gobject_introspection_base = File.join(ruby_gnome2_base, "gobject-introspection")
24
+ clutter_base = File.join(ruby_gnome2_base, "clutter")
25
+
26
+ modules = [
27
+ [glib_base, "glib2"],
28
+ [gobject_introspection_base, "gobject-introspection"],
29
+ [clutter_base, "clutter"],
30
+ ]
31
+ modules.each do |target, module_name|
32
+ if system("which make > /dev/null")
33
+ `make -C #{target.dump} > /dev/null` or exit(false)
34
+ end
35
+ $LOAD_PATH.unshift(File.join(target, "ext", module_name))
36
+ $LOAD_PATH.unshift(File.join(target, "lib"))
37
+ end
38
+
39
+ $LOAD_PATH.unshift(File.join(glib_base, "test"))
40
+ require "glib-test-init"
41
+
42
+ $LOAD_PATH.unshift(File.join(gobject_introspection_base, "test"))
43
+ require "gobject-introspection-test-utils"
44
+
45
+ $LOAD_PATH.unshift(File.join(clutter_base, "test"))
46
+ require "clutter-test-utils"
47
+
48
+ require "clutter"
49
+
50
+ exit Test::Unit::AutoRunner.run(true)