code_uimenuwindow.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // UIMenuWindow application source code
  2. 'use strict';
  3. var utils = require("Scripts/utils");
  4. exports.init = function(mylayout,mylogger) {
  5. //
  6. // action functions
  7. //
  8. var button1 = mylayout.getWidget("uimenuwindowpush");
  9. button1.onClick = function () {
  10. mylogger.setText( "UIMenuWindow action : " + button1.id + " was pressed ");
  11. var mymenuwindow = new Atomic.UIMenuWindow( mylayout, "MenuWindowDemo");
  12. var mis = new Atomic.UIMenuItemSource();
  13. mis.addItem( new Atomic.UIMenuItem( "UISelectItem1", "item1" ) );
  14. mis.addItem( new Atomic.UIMenuItem( "UISelectItem2", "item2", "Ctrl+C" ) );
  15. mis.addItem( new Atomic.UIMenuItem( "UISelectItem3", "item3", "Ctrl+A", "DuckButton" ) );
  16. mis.addItem( new Atomic.UIMenuItem( "UISelectItem4", "item4", "Ctrl+O", "LogoAtomic" ) );
  17. var xx = button1.x + (button1.width/2);
  18. var yy = button1.y + (button1.height/2);
  19. mymenuwindow.show(mis, xx, yy);
  20. //
  21. // widget event functions
  22. //
  23. mymenuwindow.subscribeToEvent( "WidgetEvent", function (ev) {
  24. if ( ev.type == Atomic.UI_EVENT_TYPE_CLICK && ev.target == mymenuwindow )
  25. mylogger.setText( "UIMenuWindow event : " + mymenuwindow.id + " selected entry id = " + ev.refID + " event type = " + utils.eventReport(ev.type));
  26. if ( ev.type == Atomic.UI_EVENT_TYPE_SHORTCUT )
  27. mylogger.setText( "UIMenuWindow event : " + mymenuwindow.id + " Shortcut id = " + ev.refID + " event type = " + utils.eventReport(ev.type));
  28. });
  29. mymenuwindow.subscribeToEvent( "UIShortcut", function (ev) {
  30. mylogger.setText( "UIMenuWindow event : " + mymenuwindow.id + " Shortcut key = " + ev.key + " qualifiers = " + ev.qualifiers );
  31. });
  32. mymenuwindow.subscribeToEvent( "UIUnhandledShortcut", function (ev) {
  33. mylogger.setText( "UIMenuWindow event : " + mymenuwindow.id + " UIUnhandledShortcut id = " + ev.refid );
  34. });
  35. };
  36. var topw = mylayout.getWidget("uimenuwindowtop");
  37. topw.subscribeToEvent( "WidgetEvent", function (ev) {
  38. if ( ev.type == Atomic.UI_EVENT_TYPE_RIGHT_POINTER_UP && ev.target == topw ) {
  39. mylogger.setText( "UIMenuWindow event : " + topw.id + " target id = " + ev.target.id + " event type = " + utils.eventReport(ev.type));
  40. var mypoppup = new Atomic.UIMenuWindow( mylayout, "MenuPopupDemo");
  41. var mix = new Atomic.UIMenuItemSource();
  42. mix.addItem( new Atomic.UIMenuItem( "UISelectItem1", "popup1", "Ctrl+A", "DuckButton" ) );
  43. mix.addItem( new Atomic.UIMenuItem( "UISelectItem2", "popup2", "Ctrl+C" ) );
  44. mix.addItem( new Atomic.UIMenuItem( "UISelectItem3", "popup3" ) );
  45. mix.addItem( new Atomic.UIMenuItem( "UISelectItem4", "popup4", "Ctrl+O", "LogoAtomic" ) );
  46. var xx = ev.x;
  47. var yy = ev.y;
  48. mypoppup.show(mix, xx, yy);
  49. mypoppup.subscribeToEvent( "WidgetEvent", function (ev) {
  50. if ( ev.type == Atomic.UI_EVENT_TYPE_CLICK && ev.target == mypoppup )
  51. mylogger.setText( "UIMenuWindow event : " + mypoppup.id + " popup entry id = " + ev.refID + " event type = " + utils.eventReport(ev.type));
  52. });
  53. }
  54. });
  55. //
  56. // support functions
  57. //
  58. var button2 = mylayout.getWidget("uimenuwindowcode");
  59. button2.onClick = function () {
  60. mylogger.setText( "UIMenuWindow support : " + button2.id + " was pressed ");
  61. utils.viewCode ( "Components/code_uimenuwindow.js", mylayout );
  62. };
  63. var button3 = mylayout.getWidget("uimenuwindowlayout");
  64. button3.onClick = function () {
  65. mylogger.setText( "UIMenuWindow support : " + button3.id + " was pressed ");
  66. utils.viewCode ( "Scenes/layout_uimenuwindow.ui.txt", mylayout );
  67. };
  68. };