Window.hx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package dx;
  2. import haxe.EntryPoint;
  3. private typedef WinPtr = hl.Abstract<"dx_window">;
  4. @:enum abstract DisplayMode(Int) {
  5. var Windowed = 0;
  6. var Fullscreen = 1;
  7. /**
  8. Fullscreen not exclusive.
  9. **/
  10. var Borderless = 2;
  11. var FullscreenResize = 3;
  12. }
  13. @:hlNative("directx")
  14. class Window {
  15. static var windows : Array<Window> = [];
  16. var win : WinPtr;
  17. var savedSize : { x : Int, y : Int, width : Int, height : Int };
  18. public var title(default, set) : String;
  19. public var width(get, never) : Int;
  20. public var height(get, never) : Int;
  21. public var x(get, never) : Int;
  22. public var y(get, never) : Int;
  23. public var displayMode(default, set) : DisplayMode;
  24. public var visible(default, set) : Bool = true;
  25. public var vsync : Bool;
  26. public function new( title : String, width : Int, height : Int ) {
  27. win = winCreate(width, height);
  28. this.title = title;
  29. windows.push(this);
  30. vsync = true;
  31. }
  32. function set_title(name:String) {
  33. winSetTitle(win, @:privateAccess name.bytes);
  34. return title = name;
  35. }
  36. function set_displayMode(mode) {
  37. if( mode == displayMode )
  38. return mode;
  39. displayMode = mode;
  40. var fs = mode != Windowed;
  41. if( savedSize == null ) {
  42. if( !fs ) return mode;
  43. savedSize = { x : x, y : y, width : width, height : height };
  44. winSetFullscreen(win,true);
  45. Driver.fullScreen = mode == Fullscreen;
  46. } else {
  47. Driver.fullScreen = mode == Fullscreen;
  48. if( fs )
  49. return mode;
  50. winSetFullscreen(win, false);
  51. resize(savedSize.width, savedSize.height);
  52. setPosition(savedSize.x, savedSize.y);
  53. savedSize = null;
  54. }
  55. return mode;
  56. }
  57. function set_visible(b) {
  58. if( visible == b )
  59. return b;
  60. winResize(win, b ? 4 : 3);
  61. return visible = b;
  62. }
  63. public function resize( width : Int, height : Int ) {
  64. winSetSize(win, width, height);
  65. }
  66. public function setPosition( x : Int, y : Int ) {
  67. winSetPosition(win, x, y);
  68. }
  69. function get_width() {
  70. var w = 0;
  71. winGetSize(win, w, null);
  72. return w;
  73. }
  74. function get_height() {
  75. var h = 0;
  76. winGetSize(win, null, h);
  77. return h;
  78. }
  79. function get_x() {
  80. var x = 0;
  81. winGetPosition(win, x, null);
  82. return x;
  83. }
  84. function get_y() {
  85. var y = 0;
  86. winGetPosition(win, null, y);
  87. return y;
  88. }
  89. public function destroy() {
  90. winDestroy(win);
  91. win = null;
  92. windows.remove(this);
  93. }
  94. public function maximize() {
  95. winResize(win, 0);
  96. }
  97. public function minimize() {
  98. winResize(win, 1);
  99. }
  100. public function restore() {
  101. winResize(win, 2);
  102. }
  103. public function getNextEvent( e : Event ) : Bool {
  104. return winGetNextEvent(win, e);
  105. }
  106. public function clipCursor( enable : Bool ) : Void {
  107. winClipCursor(enable ? win : null);
  108. }
  109. static function winCreate( width : Int, height : Int ) : WinPtr {
  110. return null;
  111. }
  112. static function winSetTitle( win : WinPtr, title : hl.Bytes ) {
  113. }
  114. static function winSetFullscreen( win : WinPtr, fs : Bool ) {
  115. }
  116. static function winSetSize( win : WinPtr, width : Int, height : Int ) {
  117. }
  118. static function winSetPosition( win : WinPtr, x : Int, y : Int ) {
  119. }
  120. static function winResize( win : WinPtr, mode : Int ) {
  121. }
  122. static function winGetSize( win : WinPtr, width : hl.Ref<Int>, height : hl.Ref<Int> ) {
  123. }
  124. static function winGetPosition( win : WinPtr, x : hl.Ref<Int>, y : hl.Ref<Int> ) {
  125. }
  126. static function winDestroy( win : WinPtr ) {
  127. }
  128. public static function getScreenWidth() {
  129. return 0;
  130. }
  131. public static function getScreenHeight() {
  132. return 0;
  133. }
  134. static function winGetNextEvent( win : WinPtr, event : Dynamic ) : Bool {
  135. return false;
  136. }
  137. static function winClipCursor( win : WinPtr ) : Void {
  138. }
  139. }