code_uisection.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // UISection application source code
  2. using System;
  3. using AtomicEngine;
  4. public class code_uisection : CSComponent {
  5. public void Setup( UIWidget layout )
  6. {
  7. var dest = new AtomicEngine.Vector<AtomicEngine.UIWidget>();
  8. layout.SearchWidgetClass( "TBButton", dest );
  9. for (var ii = 0; ii < dest.Size; ii++) {
  10. dest[ii].SubscribeToEvent<WidgetEvent> (dest [ii], HandleUisectionEvent );
  11. }
  12. UIWidget sec1 = layout.GetWidget("UISectionDemo");
  13. if ( !sec1.Equals(null))
  14. sec1.SubscribeToEvent<WidgetEvent> (sec1, HandleUisectionEvent );
  15. UIWidget sec2 = layout.GetWidget("UISection2Demo");
  16. if ( !sec2.Equals(null))
  17. sec2.SubscribeToEvent<WidgetEvent> (sec2, HandleUisectionEvent );
  18. }
  19. private static void HandleUisectionEvent ( WidgetEvent ev )
  20. {
  21. UIWidget widget = (UIWidget)ev.Target;
  22. if ( widget.Equals(null)) return;
  23. if ( ev.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) {
  24. if (widget.GetId() == "uisectioncode" ) {
  25. AtomicMain.AppLog( "UISection support : " + widget.GetId() + " was pressed " );
  26. AtomicMain.ViewCode ( "Components/code_uisection.cs", widget.GetParent() );
  27. }
  28. if (widget.GetId() == "uisectionlayout" ) {
  29. AtomicMain.AppLog( "UISection support : " + widget.GetId() + " was pressed ");
  30. AtomicMain.ViewCode ( "Scenes/layout_uisection.ui.txt", widget.GetParent() );
  31. }
  32. }
  33. if ( ev.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CHANGED ) {
  34. UIWidget demo1 = widget.FindWidget("UISectionDemo"); // event comes in on child widget!
  35. if ( demo1.IsAncestorOf(widget) )
  36. AtomicMain.AppLog( "UISection event : " + demo1.GetId() + " changed to value = " + demo1.GetValue().ToString());
  37. UIWidget demo2 = widget.FindWidget("UISection2Demo");
  38. if ( demo2.IsAncestorOf(widget) )
  39. AtomicMain.AppLog( "UISection event : " + demo2.GetId() + " changed to value = " + demo2.GetValue().ToString());
  40. }
  41. }
  42. }