Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

378 rindas
10 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 Canvas extends NativeObject {
  15. static {
  16. Caca.load();
  17. }
  18. private static native int getCursorX(long canvasPtr);
  19. private static native int getCursorY(long canvasPtr);
  20. private static native void setCursorXY(long canvasPtr, int x, int y);
  21. public class Cursor {
  22. protected Cursor() {}
  23. public int getX() {
  24. return getCursorX(ptr);
  25. }
  26. public int getY() {
  27. return getCursorY(ptr);
  28. }
  29. public void setXY(int x, int y) {
  30. setCursorXY(ptr, x, y);
  31. }
  32. }
  33. private static native int getHandleX(long canvasPtr);
  34. private static native int getHandleY(long canvasPtr);
  35. private static native void setHandleXY(long canvasPtr, int x, int y);
  36. public class Handle {
  37. protected Handle() {}
  38. public int getX() {
  39. return getHandleX(ptr);
  40. }
  41. public int getY() {
  42. return getHandleY(ptr);
  43. }
  44. public void setXY(int x, int y) {
  45. setHandleXY(ptr, x, y);
  46. }
  47. }
  48. // Is this canvas managed by a display?
  49. private final boolean managed;
  50. private final Cursor cursor;
  51. private final Handle handle;
  52. private static native long createCanvas(int width, int height);
  53. public Canvas(int width, int height) {
  54. this(createCanvas(width, height), false);
  55. }
  56. protected Canvas(long ptr) {
  57. this(ptr, true);
  58. }
  59. private Canvas(long ptr, boolean managed) {
  60. this.cursor = new Cursor();
  61. this.handle = new Handle();
  62. this.ptr = ptr;
  63. this.managed = managed;
  64. }
  65. public Cursor getCursor() {
  66. return cursor;
  67. }
  68. public Handle getHandle() {
  69. return handle;
  70. }
  71. private static native int getCanvasWidth(long canvasPtr);
  72. public int getWidth() {
  73. return getCanvasWidth(ptr);
  74. }
  75. private static native int getCanvasHeight(long canvasPtr);
  76. public int getHeight() {
  77. return getCanvasHeight(ptr);
  78. }
  79. private static native void setCanvasSize(long canvasPtr, int width, int height);
  80. public void setSize(int width, int height) {
  81. setCanvasSize(ptr, width, height);
  82. }
  83. private static native void clearCanvas(long canvasPtr);
  84. public void clear() {
  85. clearCanvas(ptr);
  86. }
  87. private static native int getCanvasChar(long canvasPtr, int x, int y);
  88. public int getChar(int x, int y) {
  89. return getCanvasChar(ptr, x, y);
  90. }
  91. private static native void putCanvasChar(long canvasPtr, int x, int y, int ch);
  92. public void put(int x, int y, int ch) {
  93. putCanvasChar(ptr, x, y, ch);
  94. }
  95. private static native void putCanvasString(long canvasPtr, int x, int y, String s);
  96. public void put(int x, int y, String s) {
  97. putCanvasString(ptr, x, y, s);
  98. }
  99. private static native void blitCanvas(long canvasPtr, int x, int y, long otherCanvasPtr, long maskCanvasPtr);
  100. public void blit(int x, int y, Canvas other, Canvas mask) {
  101. blitCanvas(ptr, x, y, other.ptr, mask.ptr);
  102. }
  103. private static native void setCanvasBoundaries(long canvasPtr, int x, int y, int width, int height);
  104. public void setBoundaries(int x, int y, int width, int height) {
  105. setCanvasBoundaries(ptr, x, y, width, height);
  106. }
  107. private static native void invertCanvas(long canvasPtr);
  108. public void invert() {
  109. invertCanvas(ptr);
  110. }
  111. private static native void flipCanvas(long canvasPtr);
  112. public void flip() {
  113. flipCanvas(ptr);
  114. }
  115. private static native void flopCanvas(long canvasPtr);
  116. public void flop() {
  117. flopCanvas(ptr);
  118. }
  119. private static native void rotateCanvas180(long canvasPtr);
  120. public void rotate180() {
  121. rotateCanvas180(ptr);
  122. }
  123. private static native void rotateCanvasLeft(long canvasPtr);
  124. public void rotateLeft() {
  125. rotateCanvasLeft(ptr);
  126. }
  127. private static native void rotateCanvasRight(long canvasPtr);
  128. public void rotateRight() {
  129. rotateCanvasRight(ptr);
  130. }
  131. private static native void stretchCanvasLeft(long canvasPtr);
  132. public void stretchLeft() {
  133. stretchCanvasLeft(ptr);
  134. }
  135. private static native void stretchCanvasRight(long canvasPtr);
  136. public void stretchRight() {
  137. stretchCanvasRight(ptr);
  138. }
  139. private static native int getCanvasAttribute(long canvasPtr, int x, int y);
  140. public int getAttribute(int x, int y) {
  141. return getCanvasAttribute(ptr, x, y);
  142. }
  143. private static native void setCanvasAttribute(long canvasPtr, int attr);
  144. public void setDefaultAttribute(int attribute) {
  145. setCanvasAttribute(ptr, attribute);
  146. }
  147. private static native void putCanvasAttribute(long canvasPtr, int x, int y, int attr);
  148. public void putAttribute(int x, int y, int attribute) {
  149. putCanvasAttribute(ptr, x, y, attribute);
  150. }
  151. private static native void setCanvasColorAnsi(long canvasPtr, byte colorAnsiFg, byte colorAnsiBg);
  152. public void setColor(Color.Ansi foreground, Color.Ansi background) {
  153. setCanvasColorAnsi(ptr, foreground.code, background.code);
  154. }
  155. private static native void setCanvasColorArgb(long canvasPtr, short colorArgbFg, short colorArbgBg);
  156. public void setColor(Color.Argb foreground, Color.Argb background) {
  157. setCanvasColorArgb(ptr, foreground.code, background.code);
  158. }
  159. private static native void canvasDrawLine(long canvasPtr, int x1, int y1, int x2, int y2, int ch);
  160. public void drawLine(int x1, int y1, int x2, int y2, int ch) {
  161. canvasDrawLine(ptr, x1, y1, x2, y2, ch);
  162. }
  163. private static native void canvasDrawPolyline(long canvasPtr, int[] x, int[] y, int ch);
  164. public void drawPolyline(int[] x, int[] y, int ch) {
  165. canvasDrawPolyline(ptr, x, y, ch);
  166. }
  167. private static native void canvasDrawThinLine(long canvasPtr, int x1, int y1, int x2, int y2);
  168. public void drawThinLine(int x1, int y1, int x2, int y2) {
  169. canvasDrawThinLine(ptr, x1, y1, x2, y2);
  170. }
  171. private static native void canvasDrawThinPolyline(long canvasPtr, int[] x, int[] y);
  172. public void drawThinPolyline(int[] x, int[] y, int ch) {
  173. canvasDrawThinPolyline(ptr, x, y);
  174. }
  175. private static native void canvasDrawCircle(long canvasPtr, int x, int y, int r, int ch);
  176. public void drawCircle(int x, int y, int r, int ch) {
  177. canvasDrawCircle(ptr, x, y, r, ch);
  178. }
  179. private static native void canvasDrawEllipse(long canvasPtr, int x, int y, int a, int b, int ch);
  180. public void drawEllipse(int x, int y, int a, int b, int ch) {
  181. canvasDrawEllipse(ptr, x, y, a, b, ch);
  182. }
  183. private static native void canvasDrawThinEllipse(long canvasPtr, int x, int y, int a, int b);
  184. public void drawThinEllipse(int x, int y, int a, int b) {
  185. canvasDrawThinEllipse(ptr, x, y, a, b);
  186. }
  187. private static native void canvasFillEllipse(long canvasPtr, int x, int y, int a, int b, int ch);
  188. public void fillEllipse(int x, int y, int a, int b, int ch) {
  189. canvasFillEllipse(ptr, x, y, a, b, ch);
  190. }
  191. private static native void canvasDrawBox(long canvasPtr, int x, int y, int width, int height, int ch);
  192. public void drawBox(int x, int y, int width, int height, int ch) {
  193. canvasDrawBox(ptr, x, y, width, height, ch);
  194. }
  195. private static native void canvasDrawThinBox(long canvasPtr, int x, int y, int width, int height);
  196. public void drawThinBox(int x, int y, int width, int height) {
  197. canvasDrawThinBox(ptr, x, y, width, height);
  198. }
  199. private static native void canvasDrawCp437Box(long canvasPtr, int x, int y, int width, int height);
  200. public void drawCp437Box(int x, int y, int width, int height) {
  201. canvasDrawCp437Box(ptr, x, y, width, height);
  202. }
  203. private static native void canvasFillBox(long canvasPtr, int x, int y, int width, int height, int ch);
  204. public void fillBox(int x, int y, int width, int height, int ch) {
  205. canvasFillBox(ptr, x, y, width, height, ch);
  206. }
  207. private static native void canvasDrawTriangle(long canvasPtr, int x1, int y1, int x2, int y2, int x3, int y3, int ch);
  208. public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int ch) {
  209. canvasDrawTriangle(ptr, x1, y1, x2, y2, x3, y3, ch);
  210. }
  211. private static native void canvasDrawThinTriangle(long canvasPtr, int x1, int y1, int x2, int y2, int x3, int y3);
  212. public void drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
  213. canvasDrawThinTriangle(ptr, x1, y1, x2, y2, x3, y3);
  214. }
  215. private static native void canvasFillTriangle(long canvasPtr, int x1, int y1, int x2, int y2, int x3, int y3, int ch);
  216. public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int ch) {
  217. canvasFillTriangle(ptr, x1, y1, x2, y2, x3, y3, ch);
  218. }
  219. private static native int getCanvasFrameCount(long canvasPtr);
  220. public int getFrameCount() {
  221. return getCanvasFrameCount(ptr);
  222. }
  223. private static native void setCanvasFrame(long canvasPtr, int id);
  224. public void setFrame(int id) {
  225. setCanvasFrame(ptr, id);
  226. }
  227. private static native String getCanvasFrameName(long canvasPtr);
  228. public String getFrameName() {
  229. return getCanvasFrameName(ptr);
  230. }
  231. private static native void setCanvasFrameName(long canvasPtr, String name);
  232. public void setFrameName(String name) {
  233. setCanvasFrameName(ptr, name);
  234. }
  235. private static native void createCanvasFrame(long canvasPtr, int id);
  236. public void createFrame(int id) {
  237. createCanvasFrame(ptr, id);
  238. }
  239. private static native void freeCanvasFrame(long canvasPtr, int id);
  240. public void removeFrame(int id) {
  241. freeCanvasFrame(ptr, id);
  242. }
  243. private static native void canvasRender(long canvasPtr, long fontPtr, byte[] buf,
  244. int width, int height, int pitch);
  245. public void render(Font font, byte[] buf, int width, int height, int pitch) {
  246. canvasRender(ptr, font.ptr, buf, width, height, pitch);
  247. }
  248. private static native void canvasDitherBitmap(long canvasPtr, int x, int y, int width,
  249. int height, long ditherPtr, byte[] pixels);
  250. public void ditherBitmap(int x, int y, int width, int height, Dither dither, byte[] pixels) {
  251. canvasDitherBitmap(ptr, x, y, width, height, dither.ptr, pixels);
  252. }
  253. private static native void freeCanvas(long canvasPtr);
  254. @Override
  255. public void finalize() throws Throwable {
  256. if (!managed)
  257. freeCanvas(ptr);
  258. super.finalize();
  259. }
  260. }