Created
June 2, 2011 22:33
-
-
Save holmesmr/1005486 to your computer and use it in GitHub Desktop.
A simple, horrible test of Clutter and Vala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code is under public domain, or the CC0 "license" in legal | |
// jurisdictions where the concept of public domain does not exist. | |
// See http://creativecommons.org/publicdomain/zero/1.0/legalcode | |
// for more info. | |
// to compile, try | |
// `valac --pkg clutter-1.0 cluttertest.vala` | |
// You will need to have the Clutter headers installed on your system. | |
namespace ClutterTest { | |
class Core : GLib.Object { | |
// three texts wise | |
private static Clutter.Text hello1 = null; | |
private static Clutter.Text hello2 = null; | |
private static Clutter.Text hello3 = null; | |
// init my floatin' brothers | |
private static double rotation = 0; | |
private static float startpos; | |
private static float endpos; | |
private static float range; | |
private static float pos; | |
static void on_new_frame(Clutter.Timeline sender, int frame) { | |
if (pos > endpos) // THE END(?) | |
pos = startpos; // start again! | |
rotation += 360.0/1200.0; // turn 0.3deg per frame | |
pos += range/1200.0F; | |
hello1.rotation_angle_z = rotation; // rotate this | |
hello2.rotation_angle_z = -rotation; // rotate that | |
hello3.y = pos; // move thineself | |
} | |
public static int main(string[] args) { | |
Clutter.init(ref args); | |
// static position for specific font face size and text | |
startpos = 25.0F; | |
endpos = 1940.0F; | |
pos = 25.0F; | |
// wuts dat my range is calculated | |
range = endpos-startpos; | |
// some bog-standard colours | |
Clutter.Color white = {255, 255, 255, 255}; | |
Clutter.Color black = {0, 0, 0, 255}; | |
Clutter.Stage stage = Clutter.Stage.get_default(); // run of the mill stage | |
stage.set_size(512.0F, 512.0F); // 512x512px stage area | |
stage.color = black; // background color! | |
stage.title = "Super awesome Clutter demo!"; // window title! | |
Clutter.Timeline line = new Clutter.Timeline(60); | |
line.new_frame.connect(on_new_frame); | |
line.loop = true; | |
// yeah i know, MS font. forgive me! | |
hello1 = new Clutter.Text.full("Segoe UI 24", "Hello, world!", white); | |
hello1.set_position(200.0F, 200.0F); | |
stage.add(hello1); | |
hello2 = new Clutter.Text.full("Segoe UI 48", "Hello, world!", {255, 0, 0, 128}); // 50% transparent red | |
hello2.set_position(200.0F, 200.0F); | |
stage.add(hello2); | |
hello3 = new Clutter.Text.full("Segoe UI 196", "Hello, world!", {255, 255, 255, 192}); // 75% transparent white | |
hello3.set_position(-90.0F, startpos); | |
hello3.rotation_angle_z = -90; // (90 deg acw) | |
stage.add(hello3); | |
stage.show_all(); // SUPRISE COCKFAGS HERE'S A FRESH STAGE | |
line.start(); // roll the reel | |
Clutter.main(); // get the show on the road | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment