UI.hx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (C)2005-2017 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package hl;
  23. typedef SentinelHandle = hl.Abstract<"ui_sentinel">;
  24. abstract Sentinel(SentinelHandle) {
  25. public function new( timeout, callback ) {
  26. this = create_sentinel(timeout,callback);
  27. }
  28. public function setPause( p : Bool ) {
  29. _pause(this, p);
  30. }
  31. public function tick() {
  32. _tick(this);
  33. }
  34. @:hlNative("ui", "ui_start_sentinel") static function create_sentinel( timeout : Float, callb : Void -> Void ) : SentinelHandle {
  35. return null;
  36. }
  37. @:hlNative("ui","ui_sentinel_tick") static function _tick( h : SentinelHandle ) : Void {}
  38. @:hlNative("ui","ui_sentinel_pause") static function _pause( h : SentinelHandle, b : Bool ) : Void {}
  39. }
  40. typedef WinHandle = hl.Abstract<"ui_window">;
  41. class Window {
  42. var h : WinHandle;
  43. public function setText( text : String ) {
  44. win_set_text(h, @:privateAccess text.bytes);
  45. }
  46. public function setEnable( b : Bool ) {
  47. win_set_enable(h, b);
  48. }
  49. public function destroy() {
  50. win_destroy(h);
  51. }
  52. @:hlNative("ui","ui_win_destroy")
  53. static function win_destroy( win : WinHandle ) : Void {
  54. }
  55. @:hlNative("ui","ui_win_set_text")
  56. static function win_set_text( win : WinHandle, text : hl.Bytes ) : Void {
  57. }
  58. @:hlNative("ui","ui_win_set_enable")
  59. static function win_set_enable( win : WinHandle, enable : Bool ) : Void {
  60. }
  61. }
  62. class Button extends Window {
  63. public function new( parent : Window, text : String ) {
  64. h = button_new(parent.h, @:privateAccess text.bytes, function() this.onClick());
  65. }
  66. public dynamic function onClick() {
  67. }
  68. @:hlNative("ui", "ui_button_new")
  69. static function button_new( parent : WinHandle, text : hl.Bytes, onClick : Void -> Void ) : WinHandle {
  70. return null;
  71. }
  72. }
  73. class WinLog extends Window {
  74. public function new( title : String, width, height ) {
  75. h = winlog_new(@:privateAccess title.bytes,width, height);
  76. }
  77. public function setTextContent( text : String, autoScroll = false ) {
  78. winlog_set_text(h, @:privateAccess text.bytes,autoScroll);
  79. }
  80. @:hlNative("ui","ui_winlog_new")
  81. static function winlog_new( text : hl.Bytes, width : Int, height : Int ) : WinHandle {
  82. return null;
  83. }
  84. @:hlNative("ui","ui_winlog_set_text")
  85. static function winlog_set_text( win : WinHandle, text : hl.Bytes, autoScroll : Bool ) : Void {
  86. }
  87. }
  88. enum DialogFlags {
  89. YesNo;
  90. IsError;
  91. }
  92. @:enum abstract LoopResult(Int) {
  93. var NoMessage = 0;
  94. var HandledMessage = 1;
  95. var Quit = 2;
  96. }
  97. /**
  98. These are the bindings for the HL `ui.hdll` library, which contains some low level system access.
  99. **/
  100. class UI {
  101. @:hlNative("ui","ui_init") static function init() {}
  102. static function __init__() {
  103. init();
  104. }
  105. @:hlNative("ui","ui_dialog")
  106. static function _dialog( title : hl.Bytes, text : hl.Bytes, flags : Int ) : Int {
  107. return 0;
  108. }
  109. public static function dialog( title : String, text : String, flags : haxe.EnumFlags<DialogFlags> ) {
  110. @:privateAccess _dialog(title.bytes,text.bytes,flags.toInt());
  111. }
  112. @:hlNative("ui","ui_loop")
  113. public static function loop( blocking : Bool ) : LoopResult {
  114. return Quit;
  115. }
  116. @:hlNative("ui","ui_stop_loop")
  117. public static function stopLoop() : Void {
  118. }
  119. @:hlNative("ui","ui_close_console")
  120. public static function closeConsole() : Void {
  121. }
  122. }