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.
 
 
 
 
 
 

186 satır
5.4 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. #include "caca_java_common.h"
  12. #include "org_zoy_caca_Display.h"
  13. #include <stdlib.h>
  14. #include "caca.h"
  15. #define DISPLAY_CREATION_ERROR "Cannot create display"
  16. JNIEXPORT jlong JNICALL
  17. Java_org_zoy_caca_Display_createDisplayAndCanvas(JNIEnv *env, jclass cls)
  18. {
  19. caca_display_t *display = caca_create_display(NULL);
  20. if(display == NULL) {
  21. THROW_EX(DISPLAY_CREATION_ERROR);
  22. return 0;
  23. }
  24. return (jlong)display;
  25. }
  26. JNIEXPORT jlong JNICALL
  27. Java_org_zoy_caca_Display_createDisplay(JNIEnv *env, jclass cls, jlong canvas_ptr)
  28. {
  29. caca_display_t *display = caca_create_display((caca_canvas_t *)canvas_ptr);
  30. if(display == NULL) {
  31. THROW_EX(DISPLAY_CREATION_ERROR);
  32. return 0;
  33. }
  34. return (jlong)display;
  35. }
  36. JNIEXPORT jlong JNICALL
  37. Java_org_zoy_caca_Display_createDisplayAndCanvasWithDriver(JNIEnv *env, jclass cls,
  38. jstring driver_name)
  39. {
  40. const char *driver_name_chars = (*env)->GetStringUTFChars(env, driver_name, 0);
  41. caca_display_t *ret = caca_create_display_with_driver(NULL, driver_name_chars);
  42. (*env)->ReleaseStringUTFChars(env, driver_name, driver_name_chars);
  43. if(ret == NULL) {
  44. THROW_EX(DISPLAY_CREATION_ERROR);
  45. return 0;
  46. }
  47. return (jlong)ret;
  48. }
  49. JNIEXPORT jlong JNICALL
  50. Java_org_zoy_caca_Display_createDisplayWithDriver(JNIEnv *env, jclass cls,
  51. jlong canvas_ptr, jstring driver_name)
  52. {
  53. const char *driver_name_chars = (*env)->GetStringUTFChars(env, driver_name, 0);
  54. caca_display_t *ret = caca_create_display_with_driver((caca_canvas_t *)canvas_ptr, driver_name_chars);
  55. (*env)->ReleaseStringUTFChars(env, driver_name, driver_name_chars);
  56. if(ret == NULL) {
  57. THROW_EX(DISPLAY_CREATION_ERROR);
  58. return 0;
  59. }
  60. return (jlong)ret;
  61. }
  62. JNIEXPORT jobjectArray JNICALL
  63. Java_org_zoy_caca_Display_getDisplayDriverList(JNIEnv *env, jclass cls)
  64. {
  65. const char *const *drivers = caca_get_display_driver_list();
  66. return caca_java_to_string_array(env, drivers);
  67. }
  68. JNIEXPORT void JNICALL
  69. Java_org_zoy_caca_Display_setDisplayDriver(JNIEnv *env, jclass cls, jlong ptr, jstring driver_name)
  70. {
  71. const char *driver_name_chars = (*env)->GetStringUTFChars(env, driver_name, 0);
  72. caca_set_display_driver((caca_display_t *)ptr, driver_name_chars);
  73. (*env)->ReleaseStringUTFChars(env, driver_name, driver_name_chars);
  74. }
  75. JNIEXPORT jstring JNICALL
  76. Java_org_zoy_caca_Display_getDisplayDriver(JNIEnv *env, jclass cls, jlong ptr)
  77. {
  78. return (*env)->NewStringUTF(env, caca_get_display_driver((caca_display_t *)ptr));
  79. }
  80. JNIEXPORT jlong JNICALL
  81. Java_org_zoy_caca_Display_getDisplayCanvas(JNIEnv *env, jclass cls, jlong ptr)
  82. {
  83. return (jlong)caca_get_canvas((caca_display_t *)ptr);
  84. }
  85. JNIEXPORT void JNICALL
  86. Java_org_zoy_caca_Display_displayRefresh(JNIEnv *env, jclass cls, jlong ptr)
  87. {
  88. caca_refresh_display((caca_display_t *)ptr);
  89. }
  90. JNIEXPORT void JNICALL
  91. Java_org_zoy_caca_Display_setDisplayTime(JNIEnv *env, jclass cls, jlong ptr, jint time)
  92. {
  93. caca_set_display_time((caca_display_t *)ptr, time);
  94. }
  95. JNIEXPORT jint JNICALL
  96. Java_org_zoy_caca_Display_getDisplayTime(JNIEnv *env, jclass cls, jlong ptr)
  97. {
  98. return caca_get_display_time((caca_display_t *)ptr);
  99. }
  100. JNIEXPORT jint JNICALL
  101. Java_org_zoy_caca_Display_getDisplayWidth(JNIEnv *env, jclass cls, jlong ptr)
  102. {
  103. return caca_get_display_width((caca_display_t *)ptr);
  104. }
  105. JNIEXPORT jint JNICALL
  106. Java_org_zoy_caca_Display_getDisplayHeight(JNIEnv *env, jclass cls, jlong ptr)
  107. {
  108. return caca_get_display_height((caca_display_t *)ptr);
  109. }
  110. JNIEXPORT void JNICALL
  111. Java_org_zoy_caca_Display_setDisplayTitle(JNIEnv *env, jclass cls, jlong ptr, jstring title)
  112. {
  113. const char *title_chars = (*env)->GetStringUTFChars(env, title, 0);
  114. caca_set_display_title((caca_display_t *)ptr, title_chars);
  115. (*env)->ReleaseStringUTFChars(env, title, title_chars);
  116. }
  117. JNIEXPORT void JNICALL
  118. Java_org_zoy_caca_Display_setDisplayMouse(JNIEnv *env, jclass cls, jlong ptr, jboolean st)
  119. {
  120. caca_set_mouse((caca_display_t *)ptr, st);
  121. }
  122. JNIEXPORT void JNICALL
  123. Java_org_zoy_caca_Display_setDisplayCursor(JNIEnv *env, jclass cls, jlong ptr, jboolean st)
  124. {
  125. caca_set_cursor((caca_display_t *)ptr, st);
  126. }
  127. JNIEXPORT jlong JNICALL
  128. Java_org_zoy_caca_Display_getDisplayEvent(JNIEnv *env, jclass cls, jlong ptr, jint mask, jint timeout)
  129. {
  130. caca_event_t *ev = malloc(sizeof(caca_event_t));
  131. if (caca_get_event((caca_display_t *)ptr, mask, ev, timeout))
  132. {
  133. return (jlong) ev;
  134. }
  135. free(ev);
  136. (*env)->ThrowNew(env, (*env)->FindClass(env, "org/zoy/caca/TimeoutException"), "No event received");
  137. return -1;
  138. }
  139. JNIEXPORT jint JNICALL
  140. Java_org_zoy_caca_Display_getDisplayMouseX(JNIEnv *env, jclass cls, jlong ptr)
  141. {
  142. return caca_get_mouse_x((caca_display_t *)ptr);
  143. }
  144. JNIEXPORT jint JNICALL
  145. Java_org_zoy_caca_Display_getDisplayMouseY(JNIEnv *env, jclass cls, jlong ptr)
  146. {
  147. return caca_get_mouse_y((caca_display_t *)ptr);
  148. }
  149. JNIEXPORT void JNICALL
  150. Java_org_zoy_caca_Display_freeDisplay(JNIEnv *env, jclass cls, jlong ptr)
  151. {
  152. caca_free_display((caca_display_t *)ptr);
  153. }