Want more features on Pastebin? Sign Up, it's FREE!
Guest

Clutter in D test 1

By: a guest on Jun 2nd, 2011  |  syntax: D  |  size: 2.06 KB  |  views: 85  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. module test2;
  2.  
  3. import std.stdio;
  4. import std.string,
  5.         std.conv;
  6. import gtkc.gobject,
  7.         gtkc.gobjecttypes;
  8. import ccb.SharedLibrary;
  9.  
  10. enum ClutterInitError {
  11.   SUCCESS  =  1,
  12.   UNKNOWN  =  0,
  13.   THREADS  = -1,
  14.   BACKEND  = -2,
  15.   INTERNAL = -3
  16. }
  17.  
  18. struct ClutterActor { uint flags; }
  19. struct ClutterStage {}
  20. struct ClutterContainer {}
  21. struct ClutterColor { ubyte red, green, blue, alpha; }
  22.  
  23. char* cstring(string s) { return cast(char*)toStringz(s); }
  24.  
  25. void main(string[] args)
  26. {
  27.  
  28.         auto clutter = new SharedLibrary("libclutter-glx-1.0.so", RTLD_NOW | RTLD_GLOBAL);
  29.        
  30.         auto clutter_init = clutter.getSymbol!(ClutterInitError function(int*, char***))("clutter_init");
  31.         auto clutter_main = clutter.getSymbol!(void function())("clutter_main");
  32.         auto clutter_main_quit = clutter.getSymbol!(void function())("clutter_main_quit");
  33.  
  34.         auto clutter_stage_get_default = clutter.getSymbol!(ClutterActor* function())("clutter_stage_get_default");
  35.         auto clutter_actor_set_size = clutter.getSymbol!(void function(ClutterActor*, float, float))("clutter_actor_set_size");
  36.         auto clutter_actor_show_all = clutter.getSymbol!(void function(ClutterActor*))("clutter_actor_show_all");
  37.  
  38.         auto clutter_text_new_full = clutter.getSymbol!(ClutterActor* function(char*, char*, ClutterColor*))("clutter_text_new_full");
  39.         auto clutter_container_add_actor = clutter.getSymbol!(void function(ClutterContainer*, ClutterActor*))("clutter_container_add_actor");
  40.  
  41.  
  42.         auto err = clutter_init(null, null);
  43.  
  44.         writeln(to!string(err));
  45.         if (err != ClutterInitError.SUCCESS)
  46.                 return;
  47.  
  48.         ClutterActor*   stage;
  49.         ClutterActor*   textbox;
  50.         ClutterColor    txtColor = { 0, 0, 100, 255};
  51.  
  52.         stage = clutter_stage_get_default();
  53.         clutter_actor_set_size(stage, 400, 400);
  54.  
  55.         textbox = clutter_text_new_full(cstring("Sans 24"), cstring("Hello, world"), &txtColor);
  56.         clutter_container_add_actor(cast(ClutterContainer*)stage, textbox);
  57.  
  58.         clutter_actor_show_all(stage);
  59.  
  60.         g_signal_connect_object(stage, cstring("key-press-event"),
  61.                     cast(GCallback)clutter_main_quit, null, cast(GConnectFlags)0);
  62.  
  63.         clutter_main();
  64. }
clone this paste RAW Paste Data