app.d 760 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import std.stdio;
  2. import three;
  3. import std.typecons;
  4. class Tester {
  5. Window _window;
  6. bool _keepRunning = true;
  7. this() {
  8. this._window = initThree();
  9. this._window.onKey.connect!"_onKey"(this);
  10. this._window.onClose.connect!"_onClose"(this);
  11. }
  12. ~this() {
  13. _window.destroy();
  14. deinitThree();
  15. }
  16. void run() {
  17. while(this._keepRunning) {
  18. updateWindows();
  19. }
  20. }
  21. void stop() {
  22. this._keepRunning = false;
  23. }
  24. void _onKey(Window window, Key key, ScanCode scanCode, KeyAction action, KeyMod keyMod) {
  25. if(window is _window && action == KeyAction.Pressed) {
  26. if(key == Key.Escape) {
  27. this.stop();
  28. }
  29. }
  30. }
  31. void _onClose(Window window) {
  32. this.stop();
  33. }
  34. }
  35. void main() {
  36. Unique!(Tester) tester = new Tester();
  37. tester.run();
  38. }