Window.hx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package hxd;
  2. import hxd.impl.MouseMode;
  3. enum DisplayMode {
  4. Windowed;
  5. Borderless;
  6. Fullscreen;
  7. }
  8. class Window {
  9. var resizeEvents : List<Void -> Void>;
  10. var eventTargets : List<Event -> Void>;
  11. public var width(get, never) : Int;
  12. public var height(get, never) : Int;
  13. public var mouseX(get, never) : Int;
  14. public var mouseY(get, never) : Int;
  15. @:deprecated("Use mouseMode = AbsoluteUnbound(true)")
  16. public var mouseLock(get, set) : Bool;
  17. /**
  18. If set, will restrain the mouse cursor within the window boundaries.
  19. **/
  20. public var mouseClip(get, set) : Bool;
  21. /**
  22. Set the mouse movement input handling mode.
  23. @see `hxd.impl.MouseMode` for more details on each mode.
  24. **/
  25. public var mouseMode(default, set) : MouseMode = Absolute;
  26. public var vsync(get, set) : Bool;
  27. public var isFocused(get, never) : Bool;
  28. public var title(get, set) : String;
  29. public var displayMode(get, set) : DisplayMode;
  30. function new() : Void {
  31. eventTargets = new List();
  32. resizeEvents = new List();
  33. }
  34. public dynamic function onClose() : Bool {
  35. return true;
  36. }
  37. /**
  38. An event called when `mouseMode` is changed.
  39. Note that changing from `Relative(callbackA)` to `Relative(callbackB)` would also cause this event as any other parameter changes.
  40. @returns Force-override of the mouse mode that will be used as an active mode or null.
  41. **/
  42. public dynamic function onMouseModeChange( from : MouseMode, to : MouseMode ) : Null<MouseMode> {
  43. return null;
  44. }
  45. public function event( e : hxd.Event ) : Void {
  46. for( et in eventTargets )
  47. et(e);
  48. }
  49. public function addEventTarget( et : Event->Void ) : Void {
  50. eventTargets.add(et);
  51. }
  52. public function removeEventTarget( et : Event->Void ) : Void {
  53. for( e in eventTargets )
  54. if( Reflect.compareMethods(e,et) ) {
  55. eventTargets.remove(e);
  56. break;
  57. }
  58. }
  59. public function addResizeEvent( f : Void -> Void ) : Void {
  60. resizeEvents.push(f);
  61. }
  62. public function removeResizeEvent( f : Void -> Void ) : Void {
  63. for( e in resizeEvents )
  64. if( Reflect.compareMethods(e,f) ) {
  65. resizeEvents.remove(f);
  66. break;
  67. }
  68. }
  69. function onResize(e:Dynamic) : Void {
  70. for( r in resizeEvents )
  71. r();
  72. }
  73. public function resize( width : Int, height : Int ) : Void {
  74. }
  75. /**
  76. Add a drag&drop events callback.
  77. **/
  78. public function addDragAndDropTarget( f : ( event : DropFileEvent ) -> Void ) : Void {
  79. }
  80. /**
  81. Remove a drag&drop events callback.
  82. **/
  83. public function removeDragAndDropTarget( f : ( event : DropFileEvent ) -> Void ) : Void {
  84. }
  85. @:deprecated("Use the displayMode property instead")
  86. public function setFullScreen( v : Bool ) : Void {
  87. }
  88. /**
  89. Set the hardware mouse cursor position relative to window boundaries.
  90. **/
  91. public function setCursorPos( x : Int, y : Int, emitEvent : Bool = false ) : Void {
  92. throw "Not implemented";
  93. }
  94. public function setCurrent() {
  95. }
  96. static var inst : Window = null;
  97. public static function getInstance() : Window {
  98. if( inst == null ) inst = new Window();
  99. return inst;
  100. }
  101. function get_mouseX() : Int {
  102. return 0;
  103. }
  104. function get_mouseY() : Int {
  105. return 0;
  106. }
  107. function get_width() : Int {
  108. return 0;
  109. }
  110. function get_height() : Int {
  111. return 0;
  112. }
  113. function get_mouseLock() : Bool {
  114. return switch (mouseMode) { case AbsoluteUnbound(_): true; default: false; };
  115. }
  116. function set_mouseLock(v:Bool) : Bool {
  117. return set_mouseMode(v ? AbsoluteUnbound(true) : Absolute).equals(AbsoluteUnbound(true));
  118. }
  119. function get_mouseClip() : Bool {
  120. return false;
  121. }
  122. function set_mouseClip( v : Bool ) : Bool {
  123. if ( v ) throw "Not implemented";
  124. return false;
  125. }
  126. function set_mouseMode( v : MouseMode ) : MouseMode {
  127. if ( v != Absolute ) throw "Not implemented";
  128. return Absolute;
  129. }
  130. function get_vsync() : Bool return true;
  131. function set_vsync( b : Bool ) : Bool {
  132. if( !b ) throw "Can't disable vsync on this platform";
  133. return true;
  134. }
  135. function get_isFocused() : Bool return true;
  136. function get_displayMode() : DisplayMode {
  137. return Windowed;
  138. }
  139. function set_displayMode( m : DisplayMode ) : DisplayMode {
  140. return m;
  141. }
  142. function get_title() : String {
  143. return "";
  144. }
  145. function set_title( t : String ) : String {
  146. return t;
  147. }
  148. }