25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

183 satır
3.6 KiB

  1. /**
  2. * libcaca Java bindings for libcaca
  3. * Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org>
  4. *
  5. * This library is free software. It comes without any warranty, to
  6. * the extent permitted by applicable law. You can redistribute it
  7. * and/or modify it under the terms of the Do What The Fuck You Want
  8. * To Public License, Version 2, as published by Sam Hocevar. See
  9. * http://sam.zoy.org/wtfpl/COPYING for more details.
  10. */
  11. package org.zoy.caca;
  12. public class Event extends NativeObject {
  13. static {
  14. Caca.load();
  15. }
  16. public static enum Type {
  17. NONE(0x0000),
  18. KEY_PRESS(0x0001),
  19. KEY_RELEASE(0x0002),
  20. MOUSE_PRESS(0x0004),
  21. MOUSE_RELEASE(0x0008),
  22. MOUSE_MOTION(0x0010),
  23. RESIZE(0x0020),
  24. QUIT(0x0040),
  25. ANY(0xffff);
  26. protected final int code;
  27. private Type(int code) {
  28. this.code = code;
  29. }
  30. public static Type forCode(int code) {
  31. Type[] types = Type.values();
  32. for (Type type : types) {
  33. if (type.code == code) {
  34. return type;
  35. }
  36. }
  37. return null;
  38. }
  39. }
  40. public static enum Key {
  41. CTRL_A(0x01),
  42. CTRL_B(0x02),
  43. CTRL_C(0x03),
  44. CTRL_D(0x04),
  45. CTRL_E(0x05),
  46. CTRL_F(0x06),
  47. CTRL_G(0x07),
  48. BACKSPACE(0x08),
  49. TAB(0x09),
  50. CTRL_J(0x0a),
  51. CTRL_K(0x0b),
  52. CTRL_L(0x0c),
  53. RETURN(0x0d),
  54. CTRL_N(0x0e),
  55. CTRL_O(0x0f),
  56. CTRL_P(0x10),
  57. CTRL_Q(0x11),
  58. CTRL_R(0x12),
  59. PAUSE(0x13),
  60. CTRL_T(0x14),
  61. CTRL_U(0x15),
  62. CTRL_V(0x16),
  63. CTRL_W(0x17),
  64. CTRL_X(0x18),
  65. CTRL_Y(0x19),
  66. CTRL_Z(0x20),
  67. UP(0x111),
  68. DOWN(0x112),
  69. LEFT(0x113),
  70. RIGHT(0x114),
  71. INSERT(0x115),
  72. HOME(0x116),
  73. END(0x117),
  74. PAGE_HOME(0x118),
  75. PAGE_DOWN(0x119),
  76. F1(0x11a),
  77. F2(0x11b),
  78. F3(0x11c),
  79. F4(0x11d),
  80. F5(0x11e),
  81. F6(0x11f),
  82. F7(0x120),
  83. F8(0x121),
  84. F9(0x122),
  85. F10(0x123),
  86. F11(0x124),
  87. F12(0x125),
  88. F13(0x126),
  89. F14(0x127),
  90. F15(0x128);
  91. protected final int code;
  92. private Key(int code) {
  93. this.code = code;
  94. }
  95. public static Key forCode(int code) {
  96. Key[] keys = Key.values();
  97. for (Key key : keys) {
  98. if (key.code == code) {
  99. return key;
  100. }
  101. }
  102. return null;
  103. }
  104. }
  105. protected Event(long ptr) {
  106. this.ptr = ptr;
  107. }
  108. private static native int getEventType(long eventPtr);
  109. public Type getType() {
  110. return Type.forCode(getEventType(ptr));
  111. }
  112. private static native int getEventKeyCh(long eventPtr);
  113. public int getKeyCh() {
  114. return getEventKeyCh(ptr);
  115. }
  116. private static native int getEventKeyUtf32(long eventPtr);
  117. public int getKeyUtf32() {
  118. return getEventKeyUtf32(ptr);
  119. }
  120. private static native String getEventKeyUtf8(long eventPtr);
  121. public String getKeyUtf8() {
  122. return getEventKeyUtf8(ptr);
  123. }
  124. private static native int getEventMouseButton(long eventPtr);
  125. public int getMouseButton() {
  126. return getEventMouseButton(ptr);
  127. }
  128. private static native int getEventMouseX(long eventPtr);
  129. public int getMouseX() {
  130. return getEventMouseX(ptr);
  131. }
  132. private static native int getEventMouseY(long eventPtr);
  133. public int getMouseY() {
  134. return getEventMouseY(ptr);
  135. }
  136. private static native int getEventResizeWidth(long eventPtr);
  137. public int getResizeWidth() {
  138. return getEventResizeWidth(ptr);
  139. }
  140. private static native int getEventResizeHeight(long eventPtr);
  141. public int getResizeHeight() {
  142. return getEventResizeHeight(ptr);
  143. }
  144. private static native void freeEvent(long eventPtr);
  145. @Override
  146. public void finalize() throws Throwable {
  147. freeEvent(ptr);
  148. super.finalize();
  149. }
  150. }