Debian Codegraph @

java/org/zoy/caca/Canvas.java

raw
1 /**
2 * libcaca Java bindings for libcaca
3 * Copyright (c) 2009 Adrien Grand <[email protected]>
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
12 package org.zoy.caca;
13
14 public class Canvas extends NativeObject {
15
16 static {
17 Caca.load();
18 }
19
20 private static native int getCursorX(long canvasPtr);
21 private static native int getCursorY(long canvasPtr);
22 private static native void setCursorXY(long canvasPtr, int x, int y);
23
24 public class Cursor {
25
26 protected Cursor() {}
27
28 public int getX() {
29 return getCursorX(ptr);
30 }
31
32 public int getY() {
33 return getCursorY(ptr);
34 }
35
36 public void setXY(int x, int y) {
37 setCursorXY(ptr, x, y);
38 }
39
40 }
41
42 private static native int getHandleX(long canvasPtr);
43 private static native int getHandleY(long canvasPtr);
44 private static native void setHandleXY(long canvasPtr, int x, int y);
45
46 public class Handle {
47
48 protected Handle() {}
49
50 public int getX() {
51 return getHandleX(ptr);
52 }
53
54 public int getY() {
55 return getHandleY(ptr);
56 }
57
58 public void setXY(int x, int y) {
59 setHandleXY(ptr, x, y);
60 }
61
62 }
63
64 // Is this canvas managed by a display?
65 private final boolean managed;
66 private final Cursor cursor;
67 private final Handle handle;
68
69 private static native long createCanvas(int width, int height);
70
71 public Canvas(int width, int height) {
72 this(createCanvas(width, height), false);
73 }
74
75 protected Canvas(long ptr) {
76 this(ptr, true);
77 }
78
79 private Canvas(long ptr, boolean managed) {
80 this.cursor = new Cursor();
81 this.handle = new Handle();
82 this.ptr = ptr;
83 this.managed = managed;
84 }
85
86 public Cursor getCursor() {
87 return cursor;
88 }
89
90 public Handle getHandle() {
91 return handle;
92 }
93
94 private static native int getCanvasWidth(long canvasPtr);
95
96 public int getWidth() {
97 return getCanvasWidth(ptr);
98 }
99
100 private static native int getCanvasHeight(long canvasPtr);
101
102 public int getHeight() {
103 return getCanvasHeight(ptr);
104 }
105
106 private static native void setCanvasSize(long canvasPtr, int width, int height);
107
108 public void setSize(int width, int height) {
109 setCanvasSize(ptr, width, height);
110 }
111
112 private static native void clearCanvas(long canvasPtr);
113
114 public void clear() {
115 clearCanvas(ptr);
116 }
117
118 private static native int getCanvasChar(long canvasPtr, int x, int y);
119
120 public int getChar(int x, int y) {
121 return getCanvasChar(ptr, x, y);
122 }
123
124 private static native void putCanvasChar(long canvasPtr, int x, int y, int ch);
125
126 public void put(int x, int y, int ch) {
127 putCanvasChar(ptr, x, y, ch);
128 }
129
130 private static native void putCanvasString(long canvasPtr, int x, int y, String s);
131
132 public void put(int x, int y, String s) {
133 putCanvasString(ptr, x, y, s);
134 }
135
136 private static native void blitCanvas(long canvasPtr, int x, int y, long otherCanvasPtr, long maskCanvasPtr);
137
138 public void blit(int x, int y, Canvas other, Canvas mask) {
139 blitCanvas(ptr, x, y, other.ptr, mask.ptr);
140 }
141
142 private static native void setCanvasBoundaries(long canvasPtr, int x, int y, int width, int height);
143
144 public void setBoundaries(int x, int y, int width, int height) {
145 setCanvasBoundaries(ptr, x, y, width, height);
146 }
147
148 private static native void invertCanvas(long canvasPtr);
149
150 public void invert() {
151 invertCanvas(ptr);
152 }
153
154 private static native void flipCanvas(long canvasPtr);
155
156 public void flip() {
157 flipCanvas(ptr);
158 }
159
160 private static native void flopCanvas(long canvasPtr);
161
162 public void flop() {
163 flopCanvas(ptr);
164 }
165
166 private static native void rotateCanvas180(long canvasPtr);
167
168 public void rotate180() {
169 rotateCanvas180(ptr);
170 }
171
172 private static native void rotateCanvasLeft(long canvasPtr);
173
174 public void rotateLeft() {
175 rotateCanvasLeft(ptr);
176 }
177
178 private static native void rotateCanvasRight(long canvasPtr);
179
180 public void rotateRight() {
181 rotateCanvasRight(ptr);
182 }
183
184 private static native void stretchCanvasLeft(long canvasPtr);
185
186 public void stretchLeft() {
187 stretchCanvasLeft(ptr);
188 }
189
190 private static native void stretchCanvasRight(long canvasPtr);
191
192 public void stretchRight() {
193 stretchCanvasRight(ptr);
194 }
195
196 private static native int getCanvasAttribute(long canvasPtr, int x, int y);
197
198 public int getAttribute(int x, int y) {
199 return getCanvasAttribute(ptr, x, y);
200 }
201
202 private static native void setCanvasAttribute(long canvasPtr, int attr);
203
204 public void setDefaultAttribute(int attribute) {
205 setCanvasAttribute(ptr, attribute);
206 }
207
208 private static native void putCanvasAttribute(long canvasPtr, int x, int y, int attr);
209
210 public void putAttribute(int x, int y, int attribute) {
211 putCanvasAttribute(ptr, x, y, attribute);
212 }
213
214 private static native void setCanvasColorAnsi(long canvasPtr, byte colorAnsiFg, byte colorAnsiBg);
215
216 public void setColor(Color.Ansi foreground, Color.Ansi background) {
217 setCanvasColorAnsi(ptr, foreground.code, background.code);
218 }
219
220 private static native void setCanvasColorArgb(long canvasPtr, short colorArgbFg, short colorArbgBg);
221
222 public void setColor(Color.Argb foreground, Color.Argb background) {
223 setCanvasColorArgb(ptr, foreground.code, background.code);
224 }
225
226 private static native void canvasDrawLine(long canvasPtr, int x1, int y1, int x2, int y2, int ch);
227
228 public void drawLine(int x1, int y1, int x2, int y2, int ch) {
229 canvasDrawLine(ptr, x1, y1, x2, y2, ch);
230 }
231
232 private static native void canvasDrawPolyline(long canvasPtr, int[] x, int[] y, int ch);
233
234 public void drawPolyline(int[] x, int[] y, int ch) {
235 canvasDrawPolyline(ptr, x, y, ch);
236 }
237
238 private static native void canvasDrawThinLine(long canvasPtr, int x1, int y1, int x2, int y2);
239
240 public void drawThinLine(int x1, int y1, int x2, int y2) {
241 canvasDrawThinLine(ptr, x1, y1, x2, y2);
242 }
243
244 private static native void canvasDrawThinPolyline(long canvasPtr, int[] x, int[] y);
245
246 public void drawThinPolyline(int[] x, int[] y, int ch) {
247 canvasDrawThinPolyline(ptr, x, y);
248 }
249
250 private static native void canvasDrawCircle(long canvasPtr, int x, int y, int r, int ch);
251
252 public void drawCircle(int x, int y, int r, int ch) {
253 canvasDrawCircle(ptr, x, y, r, ch);
254 }
255
256 private static native void canvasDrawEllipse(long canvasPtr, int x, int y, int a, int b, int ch);
257
258 public void drawEllipse(int x, int y, int a, int b, int ch) {
259 canvasDrawEllipse(ptr, x, y, a, b, ch);
260 }
261
262 private static native void canvasDrawThinEllipse(long canvasPtr, int x, int y, int a, int b);
263
264 public void drawThinEllipse(int x, int y, int a, int b) {
265 canvasDrawThinEllipse(ptr, x, y, a, b);
266 }
267
268 private static native void canvasFillEllipse(long canvasPtr, int x, int y, int a, int b, int ch);
269
270 public void fillEllipse(int x, int y, int a, int b, int ch) {
271 canvasFillEllipse(ptr, x, y, a, b, ch);
272 }
273
274 private static native void canvasDrawBox(long canvasPtr, int x, int y, int width, int height, int ch);
275
276 public void drawBox(int x, int y, int width, int height, int ch) {
277 canvasDrawBox(ptr, x, y, width, height, ch);
278 }
279
280 private static native void canvasDrawThinBox(long canvasPtr, int x, int y, int width, int height);
281
282 public void drawThinBox(int x, int y, int width, int height) {
283 canvasDrawThinBox(ptr, x, y, width, height);
284 }
285
286 private static native void canvasDrawCp437Box(long canvasPtr, int x, int y, int width, int height);
287
288 public void drawCp437Box(int x, int y, int width, int height) {
289 canvasDrawCp437Box(ptr, x, y, width, height);
290 }
291
292 private static native void canvasFillBox(long canvasPtr, int x, int y, int width, int height, int ch);
293
294 public void fillBox(int x, int y, int width, int height, int ch) {
295 canvasFillBox(ptr, x, y, width, height, ch);
296 }
297
298 private static native void canvasDrawTriangle(long canvasPtr, int x1, int y1, int x2, int y2, int x3, int y3, int ch);
299
300 public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int ch) {
301 canvasDrawTriangle(ptr, x1, y1, x2, y2, x3, y3, ch);
302 }
303
304 private static native void canvasDrawThinTriangle(long canvasPtr, int x1, int y1, int x2, int y2, int x3, int y3);
305
306 public void drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
307 canvasDrawThinTriangle(ptr, x1, y1, x2, y2, x3, y3);
308 }
309
310 private static native void canvasFillTriangle(long canvasPtr, int x1, int y1, int x2, int y2, int x3, int y3, int ch);
311
312 public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int ch) {
313 canvasFillTriangle(ptr, x1, y1, x2, y2, x3, y3, ch);
314 }
315
316 private static native int getCanvasFrameCount(long canvasPtr);
317
318 public int getFrameCount() {
319 return getCanvasFrameCount(ptr);
320 }
321
322 private static native void setCanvasFrame(long canvasPtr, int id);
323
324 public void setFrame(int id) {
325 setCanvasFrame(ptr, id);
326 }
327
328 private static native String getCanvasFrameName(long canvasPtr);
329
330 public String getFrameName() {
331 return getCanvasFrameName(ptr);
332 }
333
334 private static native void setCanvasFrameName(long canvasPtr, String name);
335
336 public void setFrameName(String name) {
337 setCanvasFrameName(ptr, name);
338 }
339
340 private static native void createCanvasFrame(long canvasPtr, int id);
341
342 public void createFrame(int id) {
343 createCanvasFrame(ptr, id);
344 }
345
346 private static native void freeCanvasFrame(long canvasPtr, int id);
347
348 public void removeFrame(int id) {
349 freeCanvasFrame(ptr, id);
350 }
351
352 private static native void canvasRender(long canvasPtr, long fontPtr, byte[] buf,
353 int width, int height, int pitch);
354
355 public void render(Font font, byte[] buf, int width, int height, int pitch) {
356 canvasRender(ptr, font.ptr, buf, width, height, pitch);
357 }
358
359 private static native void canvasDitherBitmap(long canvasPtr, int x, int y, int width,
360 int height, long ditherPtr, byte[] pixels);
361
362 public void ditherBitmap(int x, int y, int width, int height, Dither dither, byte[] pixels) {
363 canvasDitherBitmap(ptr, x, y, width, height, dither.ptr, pixels);
364 }
365
366 private static native void freeCanvas(long canvasPtr);
367
368 @Override
369 public void finalize() throws Throwable {
370 if (!managed)
371 freeCanvas(ptr);
372 super.finalize();
373 }
374
375 }