Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Display.java 4.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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://www.wtfpl.net/ for more details.
  10. */
  11. package org.zoy.caca;
  12. public class Display extends NativeObject {
  13. static {
  14. Caca.load();
  15. }
  16. private static native long createDisplayAndCanvas();
  17. private static native long createDisplay(long canvasPtr);
  18. private static native long createDisplayAndCanvasWithDriver(String driver);
  19. private static native long createDisplayWithDriver(long canvasPtr, String driver);
  20. // Keep a reference to the canvas so that it does not get collected before this.
  21. private Canvas canvas;
  22. public Display() {
  23. ptr = createDisplayAndCanvas();
  24. long canvasPtr = getDisplayCanvas(ptr);
  25. // Create a managed canvas
  26. canvas = new Canvas(canvasPtr);
  27. }
  28. public Display(Canvas canvas) {
  29. this.canvas = canvas;
  30. ptr = createDisplay(canvas.ptr);
  31. }
  32. public Display(String driver) {
  33. ptr = createDisplayAndCanvasWithDriver(driver);
  34. long canvasPtr = getDisplayCanvas(ptr);
  35. // Create a managed canvas
  36. canvas = new Canvas(canvasPtr);
  37. }
  38. public Display(Canvas canvas, Driver driver) {
  39. ptr = createDisplayWithDriver(canvas.ptr, driver.code);
  40. }
  41. public static class Driver extends CacaObject {
  42. public Driver(String code, String desc) {
  43. super(code, desc);
  44. }
  45. public static Driver forCode(String code) {
  46. for (Driver driver : getDriverList()) {
  47. if (driver.code.equals(code)) {
  48. return driver;
  49. }
  50. }
  51. return null;
  52. }
  53. }
  54. private static native String[] getDisplayDriverList();
  55. public static Driver[] getDriverList() {
  56. String[] tmp = getDisplayDriverList();
  57. Driver[] drivers = new Driver[tmp.length / 2];
  58. for (int i = 0; 2*i < tmp.length; i++) {
  59. drivers[i] = new Driver(tmp[2*i], tmp[2*i+1]);
  60. }
  61. return drivers;
  62. }
  63. private static native void setDisplayDriver(long displayPtr, String driver);
  64. public void setDriver(Driver driver) {
  65. setDisplayDriver(ptr, driver.code);
  66. }
  67. private static native String getDisplayDriver(long displayPtr);
  68. public Driver getDriver() {
  69. return Driver.forCode(getDisplayDriver(ptr));
  70. }
  71. private static native long getDisplayCanvas(long displayPtr);
  72. public Canvas getCanvas() {
  73. return canvas;
  74. }
  75. private static native void displayRefresh(long displayPtr);
  76. public void refresh() {
  77. displayRefresh(ptr);
  78. }
  79. private static native void setDisplayTime(long displayPtr, int time);
  80. public void setTime(int time) {
  81. setDisplayTime(ptr, time);
  82. }
  83. private static native int getDisplayTime(long displayPtr);
  84. public int getTime() {
  85. return getDisplayTime(ptr);
  86. }
  87. private static native int getDisplayWidth(long displayPtr);
  88. public int getWidth() {
  89. return getDisplayWidth(ptr);
  90. }
  91. private static native int getDisplayHeight(long displayPtr);
  92. public int getHeight() {
  93. return getDisplayHeight(ptr);
  94. }
  95. private static native void setDisplayTitle(long displayPtr, String title);
  96. public void setTitle(String title) {
  97. setDisplayTitle(ptr, title);
  98. }
  99. private static native void setDisplayMouse(long displayPtr, boolean status);
  100. public void setMouse(boolean status) {
  101. setDisplayMouse(ptr, status);
  102. }
  103. private static native void setDisplayCursor(long displayPtr, boolean status);
  104. public void setCursor(boolean status) {
  105. setDisplayCursor(ptr, status);
  106. }
  107. private static native long getDisplayEvent(long displayPtr, int eventMask, int timeout);
  108. public Event getEvent(Event.Type type, int timeout) {
  109. return new Event(getDisplayEvent(ptr, type.code, timeout));
  110. }
  111. private static native int getDisplayMouseX(long eventPtr);
  112. public int getMouseX() {
  113. return getDisplayMouseX(ptr);
  114. }
  115. private static native int getDisplayMouseY(long eventPtr);
  116. public int getMouseY() {
  117. return getDisplayMouseY(ptr);
  118. }
  119. private static native void freeDisplay(long displayPtr);
  120. @Override
  121. public void finalize() throws Throwable {
  122. freeDisplay(ptr);
  123. super.finalize();
  124. }
  125. }