File: gtk-test.cs

package info (click to toggle)
clutter-sharp 1.0.0~alpha3~git20090817.r1.349dba6-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 4,104 kB
  • ctags: 2,193
  • sloc: xml: 23,456; cs: 9,946; sh: 3,393; perl: 1,213; makefile: 270; awk: 50; sed: 13
file content (154 lines) | stat: -rw-r--r-- 3,520 bytes parent folder | download
1
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
using System;

using Clutter;
using Gtk;

public class SuperOH
{
	public Actor[] Hands;
	public Group Group;
	public Timeline FadeTimeline;
}

public class Test
{
 	#region Constants
	public const int n_hands = 2;
	#endregion

	#region Fields
	public static Gtk.Window Toplevel;
	public static SuperOH CurrentOH;
	public static Timeline timeline;
	public static bool fade = false;
	#endregion

	static void HandleNewFrame (object o, NewFrameArgs args) 
	{
	 	CurrentOH.Group.SetRotation (RotateAxis.ZAxis,
					     args.FrameNum, 
 					     (int)Stage.Default.Width / 2, 
 					     (int)Stage.Default.Height / 2,
					     0);


		foreach (Actor hand in CurrentOH.Hands) {
		 	hand.SetRotation (RotateAxis.ZAxis,
					  -6.0F * args.FrameNum,
				      	  (int)hand.Width / 2,
				          (int)hand.Height / 2,
					  0);
		}
	}

	static void HandleButtonPress (object o, Clutter.ButtonPressEventArgs args)
	{
	 	Actor c = (Stage.Default as Stage).GetActorAtPos (args.Event.X, args.Event.Y);

	 	if (c != null)
	 	 	c.Hide ();

	}

	static void HandleKeyPress (object o, Clutter.KeyPressEventArgs args)
	{
		 Clutter.Main.Quit ();
	}

	public static void HandleDelete (object o, System.EventArgs args)
	{
		Gtk.Application.Quit (); 
	}

	public static void HandleClickity (object o, System.EventArgs args)
	{
		if (!CurrentOH.FadeTimeline.IsPlaying)
		 	CurrentOH.FadeTimeline.Start ();
		else
		 	CurrentOH.FadeTimeline.Pause ();
	}

	public static void Main ()
	{
		ClutterRun.Init ();
	 	Gtk.Application.Init ();

		Gtk.Window window = new Gtk.Window (WindowType.Toplevel);
		window.DeleteEvent += HandleDelete;
		Toplevel = window;

		Gtk.VBox vbox = new Gtk.VBox (false, 6);
		window.Add (vbox);

		Embed clutter = new Embed ();
		vbox.Add (clutter);

		Stage stage = clutter.Stage as Stage;
		Gtk.Label label = new Gtk.Label ("This is a label");
		vbox.PackStart (label, false, false, 0);

		Gtk.Button button = Gtk.Button.NewWithLabel ("This is a button...clicky");
		button.Clicked += HandleClickity;
		vbox.PackStart (button, false, false, 0);

		button = new Gtk.Button (Gtk.Stock.Quit);
		button.Clicked += delegate { Gtk.Application.Quit (); };

		vbox.PackEnd (button, false, false, 0);

		stage.Color = new Clutter.Color (0x61, 0x64, 0x8c, 0xff);

		uint radius = stage.Width / n_hands / 2;

		SuperOH oh = new SuperOH();
		CurrentOH = oh;
		oh.Group = new Group ();
		oh.Hands = new Actor[n_hands];

		for (int i = 0; i < n_hands; i++) {
			Texture hand_text = new Texture ("redhand.png");
			uint w = hand_text.Width;
			uint h = hand_text.Height;

		 	oh.Hands[i] = hand_text;

			int x = (int) (stage.Width / 2
				 + radius
				 * Math.Cos (i * Math.PI / ( n_hands / 2 ))
				 - w / 2);
			int y = (int)(stage.Height / 2
				 + radius
				 * Math.Sin (i * Math.PI / ( n_hands / 2))
				 - h / 2);

			oh.Hands[i].SetPosition (x, y);

			oh.Group.AddActor (oh.Hands[i]);
		}

		oh.Group.ShowAll ();

		oh.FadeTimeline = new Timeline (2000);
		oh.FadeTimeline.Loop = true;
		BehaviourOpacity behaviour = new BehaviourOpacity (new Alpha (oh.FadeTimeline, Sine.Func), 0xff, 0x00);
		behaviour.Apply (oh.Group);

		stage.AddActor (oh.Group);
		stage.ButtonPressEvent += HandleButtonPress;
		stage.KeyPressEvent += HandleKeyPress;

		stage.ShowAll ();

		timeline = new Timeline (360, 90);
		timeline.Loop = true;

		timeline.NewFrame += HandleNewFrame;

		window.ExposeEvent += delegate { timeline.Start (); };

		window.SetDefaultSize (400, 600);
		window.ShowAll ();

		Gtk.Application.Run ();
	}
}