You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

185 rivejä
3.6 KiB

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