Advertisement
Guest User

Untitled

a guest
Aug 21st, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.76 KB | None | 0 0
  1. module main;
  2.  
  3. import std.stdio;
  4.  
  5. import orange.serialization._;
  6. import orange.serialization.archives._;
  7.  
  8. alias writeln println;
  9.  
  10. void main ()
  11. {
  12.     auto archive = new XmlArchive!(char);
  13.     auto serializer = new Serializer(archive);
  14.    
  15.     image({
  16.        id = "image2";
  17.        source = "images/Alpha-blue-trans.png";
  18.  
  19.        mouseArea({
  20.           id = "mArea2";
  21.           width = 3;// _ => image2.width;
  22.           height = 4;//_ => image2.height;
  23.  
  24.           onPressedChanged = {
  25.               writeln("onPressedChanged");
  26.               writeln(3/*mArea2.mouseX*/);
  27.           };
  28.        });
  29.     });
  30.  
  31.     serializer.serialize(root);
  32.     println(archive.data);
  33. }
  34.  
  35. class Item
  36. {
  37.     string id;
  38.     string source;
  39.  
  40.     int width;
  41.     int height;
  42.  
  43.     Item[] childern;
  44.     @nonSerialized void delegate () onPressedChanged;
  45. }
  46.  
  47. Item root;
  48. Item currentItem;
  49.  
  50. void image (void delegate () block)
  51. {
  52.     restore!(currentItem, {
  53.         newItem();
  54.         block();
  55.     });
  56. }
  57.  
  58. void id (string id)
  59. {
  60.     currentItem.id = id;
  61. }
  62.  
  63. void source (string source)
  64. {
  65.     currentItem.source = source;
  66. }
  67.  
  68. void mouseArea (void delegate () block)
  69. {
  70.     restore!(currentItem, {
  71.         newItem();
  72.         block();
  73.     });
  74. }
  75.  
  76. void onPressedChanged (void delegate () block)
  77. {
  78.     currentItem.onPressedChanged = block;
  79. }
  80.  
  81. void newItem ()
  82. {
  83.     auto item = new Item;
  84.  
  85.     if (!root)
  86.         root = item;
  87.  
  88.     if (currentItem)
  89.         currentItem.childern ~= item;
  90.  
  91.     currentItem = item;
  92. }
  93.  
  94. void restore (alias var, alias block) ()
  95. {
  96.     auto tmp = var;
  97.  
  98.     scope (exit)
  99.         var = tmp;
  100.  
  101.     block();    
  102. }
  103.  
  104. void width (int width)
  105. {
  106.     currentItem.width = width;
  107. }
  108.  
  109. void height (int height)
  110. {
  111.     currentItem.height = height;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement