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