Loop.hx 631 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package dx;
  2. class Loop {
  3. static function eventLoop( e : Event ) {
  4. for( w in @:privateAccess Window.windows )
  5. if( w.getNextEvent(e) ) {
  6. e.windowId = w.id;
  7. return true;
  8. }
  9. return false;
  10. }
  11. static var event = new Event();
  12. public static function processEvents( onEvent : Event -> Bool ) {
  13. while( true ) {
  14. switch( hl.UI.loop(false) ) {
  15. case NoMessage:
  16. break;
  17. case HandledMessage:
  18. continue;
  19. case Quit:
  20. return false;
  21. }
  22. }
  23. while( true ) {
  24. if( !eventLoop(event) )
  25. break;
  26. var ret = onEvent(event);
  27. if( event.type == Quit && ret )
  28. return false;
  29. }
  30. return true;
  31. }
  32. }