code_uimenuwindow.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // UIMenuWindow application source code
  2. using System;
  3. using AtomicEngine;
  4. public class code_uimenuwindow : 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], HandleUimenuwindowEvent );
  11. }
  12. }
  13. private static void HandleUimenuwindowEvent ( WidgetEvent ev )
  14. {
  15. UIWidget widget = (UIWidget)ev.Target;
  16. string refid = (string)ev.RefID;
  17. if ( widget.Equals(null)) return;
  18. if ( ev.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) {
  19. if (widget.GetId() == "uimenuwindowcode" ) {
  20. AtomicMain.AppLog( "UIMenuWindow support : " + widget.GetId() + " was pressed " );
  21. AtomicMain.ViewCode ( "Components/code_uimenuwindow.cs", widget.GetParent() );
  22. }
  23. if (widget.GetId() == "uimenuwindowlayout" ) {
  24. AtomicMain.AppLog( "UIMenuWindow support : " + widget.GetId() + " was pressed ");
  25. AtomicMain.ViewCode ( "Scenes/layout_uimenuwindow.ui.txt", widget.GetParent() );
  26. }
  27. if (widget.GetId() == "uimenuwindowpush" ) {
  28. AtomicMain.AppLog( "UIMenuWindow action : " + widget.GetId() + " was pressed " );
  29. UIMenuWindow mymenuwindow = new UIMenuWindow( widget, "MenuWindowDemo");
  30. UIMenuItemSource mis = new UIMenuItemSource();
  31. mis.AddItem( new UIMenuItem( "UISelectItem1", "item1" ) );
  32. mis.AddItem( new UIMenuItem( "UISelectItem2", "item2", "Ctrl+C" ) );
  33. mis.AddItem( new UIMenuItem( "UISelectItem3", "item3", "Ctrl+A", "DuckButton" ) );
  34. mis.AddItem( new UIMenuItem( "UISelectItem4", "item4", "Ctrl+O", "LogoAtomic" ) );
  35. int xx = widget.GetX() + (widget.GetWidth()/2);
  36. int yy = widget.GetY() + (widget.GetHeight()/2);
  37. mymenuwindow.SubscribeToEvent<WidgetEvent> (mymenuwindow, HandleUimenuwindowEvent );
  38. mymenuwindow.Show(mis, xx, yy);
  39. }
  40. if (widget.GetId() == "MenuWindowDemo" ) {
  41. AtomicMain.AppLog( "UIMenuWindow event : " + widget.GetId() + " and " + refid + " was selected ");
  42. }
  43. } else {
  44. if (widget.GetId() == "MenuWindowDemo" ) {
  45. AtomicMain.AppLog( "UIMenuWindow event : " + widget.GetId() + " refid=" + refid + " event type=" + AtomicMain.EventReport((int)ev.Type));
  46. }
  47. }
  48. }
  49. }