@@ -26,4 +26,7 @@ Daniele "Eriol" Tricoli <eriol@mornie.org> | |||
Nicolas Vion <nico@picapo.net> | |||
- PHP bindings | |||
Adrien Grand <jpountz@dinauz.org> | |||
- Java bindings | |||
*/ |
@@ -1,6 +1,8 @@ | |||
# $Id$ | |||
SUBDIRS = kernel caca src examples tools caca-sharp cxx python ruby doc test | |||
SUBDIRS = kernel caca src examples tools \ | |||
cxx caca-sharp python ruby java \ | |||
doc test | |||
DIST_SUBDIRS = $(SUBDIRS) win32 | |||
EXTRA_DIST = NOTES COPYING.GPL COPYING.ISC COPYING.LGPL bootstrap build-dos build-kernel build-win32 caca-config.in libcaca.spec libcaca.sln | |||
@@ -78,6 +78,8 @@ AC_ARG_ENABLE(vga, | |||
dnl language bindings | |||
AC_ARG_ENABLE(csharp, | |||
[ --enable-csharp C# bindings (autodetected)]) | |||
AC_ARG_ENABLE(java, | |||
[ --enable-java Java bindings (autodetected)]) | |||
AC_ARG_ENABLE(cxx, | |||
[ --enable-cxx C++ bindings (autodetected)]) | |||
AC_ARG_ENABLE(ruby, | |||
@@ -408,6 +410,48 @@ if test "${enable_csharp}" != "no"; then | |||
fi | |||
AM_CONDITIONAL(USE_CSHARP, test "${ac_cv_my_have_csharp}" = "yes") | |||
# Build the Java bindings? | |||
ac_cv_my_have_java="no" | |||
if test "${enable_java}" != "no"; then | |||
AC_PATH_PROG(JAVAC, javac, no) | |||
AC_PATH_PROG(JAVAH, javah, no) | |||
AC_PATH_PROG(JAR, jar, no) | |||
if test "${JAVAC}" != "no" -a "${JAVAH}" != "no" -a "${JAR}" != "no"; then | |||
if test "$JAVA_HOME" = ""; then | |||
# Try to resolve JAVA_HOME | |||
JAVAC_EXE="$JAVAC" | |||
# Follow symlinks | |||
while test -h "$JAVAC_EXE"; do | |||
ls=`ls -ld "$JAVAC_EXE"` | |||
link=`expr "$ls" : '.*-> \(.*\)$'` | |||
if expr "$link" : '/.*' > /dev/null; then | |||
JAVAC_EXE="$link" | |||
else | |||
JAVAC_EXE="`dirname "$JAVAC_EXE"`/$link" | |||
fi | |||
done | |||
JAVA_HOME="`dirname $JAVAC_EXE`/.." | |||
fi | |||
# Include path to jni.h | |||
JAVA_CFLAGS="${JAVA_CFLAGS} -I$JAVA_HOME/include" | |||
# Add the OS specific include path | |||
for dir in $JAVA_HOME/include/*; do | |||
if test -f "$dir/jni_md.h"; then | |||
JAVA_CFLAGS="${JAVA_CFLAGS} -I$dir" | |||
fi | |||
done | |||
AC_SUBST(JAVA_CFLAGS) | |||
AC_SUBST(JAVA_LIBS) | |||
AC_LANG_PUSH(C) | |||
CPPFLAGS="${CPPFLAGS} ${JAVA_CFLAGS}" | |||
AC_CHECK_HEADERS([jni.h], | |||
[ac_cv_my_have_java="yes" | |||
CACA_BINDINGS="${CACA_BINDINGS} Java"]) | |||
AC_LANG_POP(C) | |||
fi | |||
fi | |||
AM_CONDITIONAL(USE_JAVA, test "${ac_cv_my_have_java}" = "yes") | |||
# Build the Ruby bindings? | |||
ac_cv_my_have_ruby="no" | |||
if test "${enable_ruby}" != "no"; then | |||
@@ -506,6 +550,7 @@ AC_CONFIG_FILES([ | |||
examples/Makefile | |||
test/Makefile | |||
tools/Makefile | |||
java/Makefile | |||
caca-sharp/Makefile | |||
cxx/Makefile | |||
python/Makefile | |||
@@ -0,0 +1,3 @@ | |||
libjava.jar | |||
org_zoy_caca_*.h | |||
org/zoy/caca/*.class |
@@ -0,0 +1,94 @@ | |||
# $Id$ | |||
jnidir = $(libdir)/jni | |||
if USE_JAVA | |||
jni_LTLIBRARIES = libcaca-java.la | |||
endif | |||
java_src = $(wildcard $(srcdir)/org/zoy/caca/*.java) | |||
java_jar = libjava.jar | |||
java_jni_headers = \ | |||
org_zoy_caca_Attribute.h \ | |||
org_zoy_caca_Caca.h \ | |||
org_zoy_caca_Canvas.h \ | |||
org_zoy_caca_Display.h \ | |||
org_zoy_caca_Dither.h \ | |||
org_zoy_caca_Event.h \ | |||
org_zoy_caca_Font.h | |||
java_jni_src = \ | |||
org_zoy_caca_Attribute.c \ | |||
org_zoy_caca_Caca.c \ | |||
org_zoy_caca_Canvas.c \ | |||
org_zoy_caca_Display.c \ | |||
org_zoy_caca_Dither.c \ | |||
org_zoy_caca_Event.c \ | |||
org_zoy_caca_Font.c | |||
java_jni_classes = \ | |||
org/zoy/caca/Attribute.class \ | |||
org/zoy/caca/Caca.class \ | |||
org/zoy/caca/Canvas.class \ | |||
org/zoy/caca/Display.class \ | |||
org/zoy/caca/Dither.class \ | |||
org/zoy/caca/Event.class \ | |||
org/zoy/caca/Font.class | |||
JAVAH_FLAGS = -d . -classpath . | |||
$(java_jni_classes): $(java_src) | |||
$(JAVAC) -d . $(java_src) | |||
$(JAR) -cf $(java_jar) org | |||
# Javah does not update the file if it detects that there is nothing to do, | |||
# hence the `touch` so that javah is not run at every `make`. | |||
org_zoy_caca_Attribute.h: org/zoy/caca/Attribute.class | |||
$(JAVAH) $(JAVAH_FLAGS) org.zoy.caca.Attribute | |||
@touch org_zoy_caca_Attribute.h | |||
org_zoy_caca_Caca.h: org/zoy/caca/Caca.class | |||
$(JAVAH) $(JAVAH_FLAGS) org.zoy.caca.Caca | |||
@touch org_zoy_caca_Caca.h | |||
org_zoy_caca_Canvas.h: org/zoy/caca/Canvas.class | |||
$(JAVAH) $(JAVAH_FLAGS) org.zoy.caca.Canvas | |||
@touch org_zoy_caca_Canvas.h | |||
org_zoy_caca_Display.h: org/zoy/caca/Display.class | |||
$(JAVAH) $(JAVAH_FLAGS) org.zoy.caca.Display | |||
@touch org_zoy_caca_Display.h | |||
org_zoy_caca_Dither.h: org/zoy/caca/Dither.class | |||
$(JAVAH) $(JAVAH_FLAGS) org.zoy.caca.Dither | |||
@touch org_zoy_caca_Dither.h | |||
org_zoy_caca_Event.h: org/zoy/caca/Event.class | |||
$(JAVAH) $(JAVAH_FLAGS) org.zoy.caca.Event | |||
@touch org_zoy_caca_Event.h | |||
org_zoy_caca_Font.h: org/zoy/caca/Font.class | |||
$(JAVAH) $(JAVAH_FLAGS) org.zoy.caca.Font | |||
@touch org_zoy_caca_Font.h | |||
CLEANFILES = org/zoy/caca/*.class org_zoy_caca_[A-Z]*.h $(java_jar) | |||
EXTRA_DIST = README | |||
if USE_JAVA | |||
BUILT_SOURCES = $(java_jni_headers) $(java_jni_classes) | |||
libcaca_java_la_CPPFLAGS = $(JAVA_CFLAGS) | |||
libcaca_java_la_SOURCES = \ | |||
caca_java_common.h \ | |||
caca_java_common.c \ | |||
$(java_jni_src) | |||
#nodist_libcaca_java_la_SOURCES = \ | |||
# $(java_jni_headers) | |||
libcaca_java_la_LDFLAGS = -shared $(JAVA_LIBS) | |||
libcaca_java_la_LIBADD = ../caca/libcaca.la | |||
libcaca_java_ladir = $(datadir)/java | |||
libcaca_java_la_DATA = $(java_jar) | |||
endif |
@@ -0,0 +1,20 @@ | |||
$Id$ | |||
Building the libcaca Java bindings | |||
o In the configure step, ensure the --enable-java flag is turned on. | |||
o `make install` will install: | |||
- libjava.so in ${libdir}/jni, | |||
- libjava.jar in ${datadir}/java. | |||
Using the libcaca Java bindings | |||
o Look into examples/ for source code examples. | |||
o Running an application which uses the libcaca Java bindings: | |||
java -Djava.library.path=${libdir}/jni \ | |||
-cp ${datadir}/java/libjava.jar:<classpath> <class name> | |||
@@ -0,0 +1,31 @@ | |||
/* | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "caca_java_common.h" | |||
jobjectArray caca_java_to_string_array(JNIEnv *env, const char *const *v) | |||
{ | |||
jclass java_lang_string = (*env)->FindClass(env, "java/lang/String"); | |||
jsize size; | |||
jsize i; | |||
for (size = 0; v[size]; ++size); | |||
jobjectArray ret = (*env)->NewObjectArray(env, size, java_lang_string, NULL); | |||
for (i = 0; i < size; ++i) | |||
{ | |||
(*env)->SetObjectArrayElement(env, ret, i, (*env)->NewStringUTF(env, v[i])); | |||
} | |||
return ret; | |||
} | |||
@@ -0,0 +1,23 @@ | |||
/* | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#ifndef __CACA_JAVA_COMMON_H__ | |||
#define __CACA_JAVA_COMMON_H__ | |||
#include <jni.h> | |||
#define THROW_EX(msg) (*env)->ThrowNew(env, (*env)->FindClass(env, "org/zoy/caca/CacaException"), msg) | |||
jobjectArray caca_java_to_string_array(JNIEnv *env, const char *const *v); | |||
#endif |
@@ -0,0 +1,54 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
import org.zoy.caca.Canvas; | |||
import org.zoy.caca.Color; | |||
import org.zoy.caca.Display; | |||
import org.zoy.caca.Event; | |||
import org.zoy.caca.TimeoutException; | |||
public class Driver { | |||
public static void main(String[] args) { | |||
Canvas cv = new Canvas(32, 16); | |||
Display dp = new Display(cv); | |||
cv.setColor(Color.Ansi.WHITE, Color.Ansi.BLACK); | |||
Display.Driver driver; | |||
int i, cur = 0; | |||
while(true) { | |||
cv.put(1, 0, "Availabl driver"); | |||
driver = dp.getDriver(); | |||
Display.Driver[] list = Display.getDriverList(); | |||
for (i = 0; i < list.length; i++) { | |||
if (driver.equals(list[i])) { | |||
cur = i; | |||
} | |||
cv.drawLine(0, 2*i+2, 9999, 2*i+2, ' '); | |||
cv.put(2, 2*i+2, (cur == i ? "* " : " ") + list[i].getCode() + " " + list[i].getDescription()); | |||
} | |||
cv.put(1, 2*i + 2, "Switching driver in 5 seconds"); | |||
dp.refresh(); | |||
try { | |||
dp.getEvent(Event.Type.KEY_PRESS, 5000000); | |||
break; | |||
} catch(TimeoutException e) { | |||
// Let's continue | |||
} | |||
cur++; | |||
if (list[cur].getCode().equals("raw")) cur++; | |||
if (cur >= list.length) cur = 0; | |||
dp.setDriver(list[cur]); | |||
} | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
import org.zoy.caca.Canvas; | |||
import org.zoy.caca.Color; | |||
import org.zoy.caca.Display; | |||
import org.zoy.caca.Event; | |||
public class TrueColor { | |||
public static void main(String[] args) { | |||
Canvas cv = new Canvas(32, 16); | |||
Display dp = new Display(cv); | |||
for (int y = 0; y < 16; y++) { | |||
for (int x = 0; x < 16; x++) { | |||
int bgcolor = 0xff00 | (y << 4) | x; | |||
int fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8); | |||
cv.setColor(new Color.Argb(bgcolor), new Color.Argb(fgcolor)); | |||
cv.put(x*2, y, "CA"); | |||
} | |||
} | |||
cv.setColor(Color.Ansi.WHITE, Color.Ansi.LIGHTBLUE); | |||
cv.put(2, 1, "truecolor libcaca"); | |||
dp.refresh(); | |||
dp.getEvent(Event.Type.KEY_PRESS, -1); | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class Attribute { | |||
static { | |||
Caca.load(); | |||
} | |||
private Attribute() {} | |||
private static final native byte attributeToAnsi(int attr); | |||
public static byte toAnsi(int attr) { | |||
return attributeToAnsi(attr); | |||
} | |||
private static native byte attributeToAnsiForeground(int attr); | |||
public byte toAnsiForeground(int attr) { | |||
return attributeToAnsiForeground(attr); | |||
} | |||
private static native byte attributeToAnsiBackground(int attr); | |||
public byte toAnsiBackground(int attr) { | |||
return attributeToAnsiBackground(attr); | |||
} | |||
private static native short attributeToRgb12Foreground(int attr); | |||
public static short toRgb12Foreground(int attr) { | |||
return attributeToRgb12Foreground(attr); | |||
} | |||
private static native short attributeToRgb12Background(int attr); | |||
public static short toRgb12Background(int attr) { | |||
return attributeToRgb12Background(attr); | |||
} | |||
private static native byte[] attributeToArgb64(int attr); | |||
public static byte[] toArgb64(int attr) { | |||
return attributeToArgb64(attr); | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class Caca { | |||
static { | |||
load(); | |||
} | |||
private static boolean alreadyLoaded = false; | |||
synchronized public static void load() { | |||
if (!alreadyLoaded) { | |||
System.loadLibrary("java"); | |||
alreadyLoaded = true; | |||
} | |||
} | |||
public static native String getVersion(); | |||
} |
@@ -0,0 +1,24 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class CacaException extends RuntimeException { | |||
private static final long serialVersionUID = 0L; | |||
public CacaException(String msg) { | |||
super(msg); | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public abstract class CacaObject { | |||
protected String code; | |||
protected String description; | |||
public CacaObject(String code, String desc) { | |||
this.code = code; | |||
this.description = desc; | |||
} | |||
public String getCode() { | |||
return code; | |||
} | |||
public String getDescription() { | |||
return description; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (o == null) return false; | |||
if (this.getClass().equals(o.getClass())) { | |||
CacaObject other = (CacaObject)o; | |||
return this.code.equals(other.code); | |||
} | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,377 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING 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(); | |||
} | |||
} |
@@ -0,0 +1,84 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public abstract class Color { | |||
public static enum Ansi { | |||
BLACK((byte)0x00), | |||
BLUE((byte)0x01), | |||
GREEN((byte)0x02), | |||
CYAN((byte)0x03), | |||
RED((byte)0x04), | |||
MAGENTA((byte)0x05), | |||
BROWN((byte)0x06), | |||
LIGHTGREY((byte)0x07), | |||
DARKGREY((byte)0x08), | |||
LIGHTBLUE((byte)0x09), | |||
LIGHTGREEN((byte)0x0a), | |||
LIGHTCYAN((byte)0x0b), | |||
LIGHTRED((byte)0x0c), | |||
LIGHTMAGENTA((byte)0x0d), | |||
YELLOW((byte)0x0e), | |||
WHITE((byte)0x0f), | |||
DEFAULT((byte)0x10), | |||
TRANSPARENT((byte)0x20); | |||
private Ansi(byte code) { | |||
this.code = code; | |||
} | |||
protected byte code; | |||
public static Ansi forCode(byte code) { | |||
Ansi[] values = Ansi.values(); | |||
for (Ansi color : values) { | |||
if (color.code == code) { | |||
return color; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
// Use ints mostly because it is more convenient (no need to cast) | |||
public static class Argb { | |||
public Argb(int code) { | |||
if (code < 0 || code > Short.MAX_VALUE - Short.MIN_VALUE) { | |||
throw new IllegalArgumentException("Code should be a 16-bit unsigned integer"); | |||
} | |||
this.code = (short)code; | |||
} | |||
public Argb(int alpha, int red, int green, int blue) { | |||
if (alpha < 0 || alpha >15) { | |||
throw new IllegalArgumentException("alpha should be a 4-bit unsigned integer"); | |||
} | |||
if (red < 0 || red >15) { | |||
throw new IllegalArgumentException("red should be a 4-bit unsigned integer"); | |||
} | |||
if (green < 0 || green >15) { | |||
throw new IllegalArgumentException("green should be a 4-bit unsigned integer"); | |||
} | |||
if (blue < 0 || blue >15) { | |||
throw new IllegalArgumentException("blue should be a 4-bit unsigned integer"); | |||
} | |||
this.code = (short)((alpha << 16) + (red << 8) + (green << 4) + blue); | |||
} | |||
public short getCode() { | |||
return code; | |||
} | |||
protected short code; | |||
} | |||
} |
@@ -0,0 +1,170 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class Display extends NativeObject { | |||
static { | |||
Caca.load(); | |||
} | |||
private static native long createDisplayAndCanvas(); | |||
private static native long createDisplay(long canvasPtr); | |||
private static native long createDisplayAndCanvasWithDriver(String driver); | |||
private static native long createDisplayWithDriver(long canvasPtr, String driver); | |||
// Keep a reference to the canvas so that it does not get collected before this. | |||
private Canvas canvas; | |||
public Display() { | |||
ptr = createDisplayAndCanvas(); | |||
long canvasPtr = getDisplayCanvas(ptr); | |||
// Create a managed canvas | |||
canvas = new Canvas(canvasPtr); | |||
} | |||
public Display(Canvas canvas) { | |||
this.canvas = canvas; | |||
ptr = createDisplay(canvas.ptr); | |||
} | |||
public Display(String driver) { | |||
ptr = createDisplayAndCanvasWithDriver(driver); | |||
long canvasPtr = getDisplayCanvas(ptr); | |||
// Create a managed canvas | |||
canvas = new Canvas(canvasPtr); | |||
} | |||
public Display(Canvas canvas, Driver driver) { | |||
ptr = createDisplayWithDriver(canvas.ptr, driver.code); | |||
} | |||
public static class Driver extends CacaObject { | |||
public Driver(String code, String desc) { | |||
super(code, desc); | |||
} | |||
public static Driver forCode(String code) { | |||
for (Driver driver : getDriverList()) { | |||
if (driver.code.equals(code)) { | |||
return driver; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
private static native String[] getDisplayDriverList(); | |||
public static Driver[] getDriverList() { | |||
String[] tmp = getDisplayDriverList(); | |||
Driver[] drivers = new Driver[tmp.length / 2]; | |||
for (int i = 0; 2*i < tmp.length; i++) { | |||
drivers[i] = new Driver(tmp[2*i], tmp[2*i+1]); | |||
} | |||
return drivers; | |||
} | |||
private static native void setDisplayDriver(long displayPtr, String driver); | |||
public void setDriver(Driver driver) { | |||
setDisplayDriver(ptr, driver.code); | |||
} | |||
private static native String getDisplayDriver(long displayPtr); | |||
public Driver getDriver() { | |||
return Driver.forCode(getDisplayDriver(ptr)); | |||
} | |||
private static native long getDisplayCanvas(long displayPtr); | |||
public Canvas getCanvas() { | |||
return canvas; | |||
} | |||
private static native void displayRefresh(long displayPtr); | |||
public void refresh() { | |||
displayRefresh(ptr); | |||
} | |||
private static native void setDisplayTime(long displayPtr, int time); | |||
public void setTime(int time) { | |||
setDisplayTime(ptr, time); | |||
} | |||
private static native int getDisplayTime(long displayPtr); | |||
public int getTime() { | |||
return getDisplayTime(ptr); | |||
} | |||
private static native int getDisplayWidth(long displayPtr); | |||
public int getWidth() { | |||
return getDisplayWidth(ptr); | |||
} | |||
private static native int getDisplayHeight(long displayPtr); | |||
public int getHeight() { | |||
return getDisplayHeight(ptr); | |||
} | |||
private static native void setDisplayTitle(long displayPtr, String title); | |||
public void setTitle(String title) { | |||
setDisplayTitle(ptr, title); | |||
} | |||
private static native void setDisplayMouse(long displayPtr, boolean status); | |||
public void setMouse(boolean status) { | |||
setDisplayMouse(ptr, status); | |||
} | |||
private static native void setDisplayCursor(long displayPtr, boolean status); | |||
public void setCursor(boolean status) { | |||
setDisplayCursor(ptr, status); | |||
} | |||
private static native long getDisplayEvent(long displayPtr, int eventMask, int timeout); | |||
public Event getEvent(Event.Type type, int timeout) { | |||
return new Event(getDisplayEvent(ptr, type.code, timeout)); | |||
} | |||
private static native int getDisplayMouseX(long eventPtr); | |||
public int getMouseX() { | |||
return getDisplayMouseX(ptr); | |||
} | |||
private static native int getDisplayMouseY(long eventPtr); | |||
public int getMouseY() { | |||
return getDisplayMouseY(ptr); | |||
} | |||
private static native void freeDisplay(long displayPtr); | |||
@Override | |||
public void finalize() throws Throwable { | |||
freeDisplay(ptr); | |||
super.finalize(); | |||
} | |||
} |
@@ -0,0 +1,238 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class Dither extends NativeObject { | |||
static { | |||
Caca.load(); | |||
} | |||
private native static long createDither(int bitmapDepth, int weight, int height, | |||
int pitch, int redMask, int greenMask, int blueMask, int alphaMask); | |||
public Dither(int bitmapDepth, int weight, int height, int pitch, int redMask, | |||
int greenMask, int blueMask, int alphaMask) { | |||
this.ptr = createDither(bitmapDepth, weight, height, pitch, redMask, greenMask, | |||
blueMask, alphaMask); | |||
} | |||
private static native void setDitherPalette(long ditherPtr, int[] red, int[] green, | |||
int[] blue, int[] alpha); | |||
public void setPalette(int[] red, int[] green, int[] blue, int[] alpha) { | |||
if (red.length != 256 || | |||
green.length != 256 || | |||
blue.length != 256 || | |||
alpha.length !=256) { | |||
throw new IllegalArgumentException("Palette components must have 256 elements"); | |||
} | |||
setDitherPalette(ptr, red, green, blue, alpha); | |||
} | |||
private static native void setDitherBrightness(long ditherPtr, float brightness); | |||
public void setBrightness(float brightness) { | |||
setDitherBrightness(ptr, brightness); | |||
} | |||
private static native float getDitherBrightness(long ditherPtr); | |||
public float getBrightness() { | |||
return getDitherBrightness(ptr); | |||
} | |||
private static native void setDitherGamma(long ditherPtr, float gama); | |||
public void setGamma(float gama) { | |||
setDitherGamma(ptr, gama); | |||
} | |||
private static native float getDitherGamma(long ditherPtr); | |||
public float getGamma() { | |||
return getDitherGamma(ptr); | |||
} | |||
private static native void setDitherContrast(long ditherPtr, float contrast); | |||
public void setContrast(float contrast) { | |||
setDitherContrast(ptr, contrast); | |||
} | |||
private static native float getDitherContrast(long ditherPtr); | |||
public float getContrast() { | |||
return getDitherContrast(ptr); | |||
} | |||
public static class AntiAliasing extends CacaObject { | |||
public AntiAliasing(String code, String desc) { | |||
super(code, desc); | |||
} | |||
public static AntiAliasing forCode(Dither dither, String code) { | |||
for (AntiAliasing aa : dither.getAntiAliasingList()) { | |||
if (aa.code.equals(code)) { | |||
return aa; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
private static native String[] getDitherAntiAliasingList(long ditherPtr); | |||
public AntiAliasing[] getAntiAliasingList() { | |||
String[] tmp = getDitherAntiAliasingList(ptr); | |||
AntiAliasing[] aas; | |||
aas = new AntiAliasing[tmp.length / 2]; | |||
for (int i = 0; 2*i < tmp.length; i++) { | |||
aas[i] = new AntiAliasing(tmp[2*i], tmp[2*i+1]); | |||
} | |||
return aas; | |||
} | |||
private static native void setDitherAntiAliasing(long ditherPtr, String antiAliasing); | |||
public void setAntiAliasing(AntiAliasing antiAliasing) { | |||
setDitherAntiAliasing(ptr, antiAliasing.code); | |||
} | |||
private static native String getDitherAntiAliasing(long ditherPtr); | |||
public AntiAliasing getAntiAliasing() { | |||
return AntiAliasing.forCode(this, getDitherAntiAliasing(ptr)); | |||
} | |||
public static class Color extends CacaObject { | |||
public Color(String code, String desc) { | |||
super(code, desc); | |||
} | |||
public static Color forCode(Dither dither, String code) { | |||
for (Color color : dither.getColorList()) { | |||
if (color.code.equals(code)) { | |||
return color; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
private static native String[] getDitherColorList(long ditherPtr); | |||
public Color[] getColorList() { | |||
String[] tmp = getDitherColorList(ptr); | |||
Color[] colors = new Color[tmp.length / 2]; | |||
for (int i = 0; 2*i < tmp.length; i++) { | |||
colors[i] = new Color(tmp[2*i], tmp[2*i+1]); | |||
} | |||
return colors; | |||
} | |||
private static native void setDitherColor(long ditherPtr, String color); | |||
public void setColor(Color color) { | |||
setDitherColor(ptr, color.code); | |||
} | |||
private static native String getDitherColor(long ditherPtr); | |||
public Color getColor() { | |||
return Color.forCode(this, getDitherColor(ptr)); | |||
} | |||
public static class Charset extends CacaObject { | |||
public Charset(String code, String desc) { | |||
super(code, desc); | |||
} | |||
public static Charset forCode(Dither dither, String code) { | |||
for (Charset charset : dither.getCharsetList()) { | |||
if (charset.code.equals(code)) { | |||
return charset; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
private static native String[] getDitherCharsetList(long charsetPtr); | |||
public Charset[] getCharsetList() { | |||
String[] tmp = getDitherCharsetList(ptr); | |||
Charset[] charsets = new Charset[tmp.length / 2]; | |||
for (int i = 0; 2*i < tmp.length; i++) { | |||
charsets[i] = new Charset(tmp[2*i], tmp[2*i+1]); | |||
} | |||
return charsets; | |||
} | |||
private static native void setDitherCharset(long ditherPtr, String charset); | |||
public void setCharset(Charset charset) { | |||
setDitherCharset(ptr, charset.code); | |||
} | |||
private static native String getDitherCharset(long ditherPtr); | |||
public Charset getCharset() { | |||
return Charset.forCode(this, getDitherCharset(ptr)); | |||
} | |||
public static class Algorithm extends CacaObject { | |||
public Algorithm(String code, String desc) { | |||
super(code, desc); | |||
} | |||
public static Algorithm forCode(Dither dither, String code) { | |||
for (Algorithm algorithm : dither.getAlgorithmList()) { | |||
if (algorithm.code.equals(code)) { | |||
return algorithm; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
private static native String[] getDitherAlgorithmList(long ditherPtr); | |||
public Algorithm[] getAlgorithmList() { | |||
String[] tmp = getDitherAlgorithmList(ptr); | |||
Algorithm[] result = new Algorithm[tmp.length / 2]; | |||
for (int i = 0; 2*i < tmp.length; i++) { | |||
result[i] = new Algorithm(tmp[2*i], tmp[2*i+1]); | |||
} | |||
return result; | |||
} | |||
private static native void setDitherAlgorithm(long ditherPtr, String algorithm); | |||
public void setAlgorithm(Algorithm algorithm) { | |||
setDitherAlgorithm(ptr, algorithm.code); | |||
} | |||
private static native String getDitherAlgorithm(long ditherPtr); | |||
public Algorithm getAlgorithm() { | |||
return Algorithm.forCode(this, getDitherAlgorithm(ptr)); | |||
} | |||
private static native void freeDither(long ditherPtr); | |||
@Override | |||
public void finalize() throws Throwable { | |||
freeDither(ptr); | |||
super.finalize(); | |||
} | |||
} |
@@ -0,0 +1,184 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class Event extends NativeObject { | |||
static { | |||
Caca.load(); | |||
} | |||
public static enum Type { | |||
NONE(0x0000), | |||
KEY_PRESS(0x0001), | |||
KEY_RELEASE(0x0002), | |||
MOUSE_PRESS(0x0004), | |||
MOUSE_RELEASE(0x0008), | |||
MOUSE_MOTION(0x0010), | |||
RESIZE(0x0020), | |||
QUIT(0x0040), | |||
ANY(0xffff); | |||
protected final int code; | |||
private Type(int code) { | |||
this.code = code; | |||
} | |||
public static Type forCode(int code) { | |||
Type[] types = Type.values(); | |||
for (Type type : types) { | |||
if (type.code == code) { | |||
return type; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
public static enum Key { | |||
CTRL_A(0x01), | |||
CTRL_B(0x02), | |||
CTRL_C(0x03), | |||
CTRL_D(0x04), | |||
CTRL_E(0x05), | |||
CTRL_F(0x06), | |||
CTRL_G(0x07), | |||
BACKSPACE(0x08), | |||
TAB(0x09), | |||
CTRL_J(0x0a), | |||
CTRL_K(0x0b), | |||
CTRL_L(0x0c), | |||
RETURN(0x0d), | |||
CTRL_N(0x0e), | |||
CTRL_O(0x0f), | |||
CTRL_P(0x10), | |||
CTRL_Q(0x11), | |||
CTRL_R(0x12), | |||
PAUSE(0x13), | |||
CTRL_T(0x14), | |||
CTRL_U(0x15), | |||
CTRL_V(0x16), | |||
CTRL_W(0x17), | |||
CTRL_X(0x18), | |||
CTRL_Y(0x19), | |||
CTRL_Z(0x20), | |||
UP(0x111), | |||
DOWN(0x112), | |||
LEFT(0x113), | |||
RIGHT(0x114), | |||
INSERT(0x115), | |||
HOME(0x116), | |||
END(0x117), | |||
PAGE_HOME(0x118), | |||
PAGE_DOWN(0x119), | |||
F1(0x11a), | |||
F2(0x11b), | |||
F3(0x11c), | |||
F4(0x11d), | |||
F5(0x11e), | |||
F6(0x11f), | |||
F7(0x120), | |||
F8(0x121), | |||
F9(0x122), | |||
F10(0x123), | |||
F11(0x124), | |||
F12(0x125), | |||
F13(0x126), | |||
F14(0x127), | |||
F15(0x128); | |||
protected final int code; | |||
private Key(int code) { | |||
this.code = code; | |||
} | |||
public static Key forCode(int code) { | |||
Key[] keys = Key.values(); | |||
for (Key key : keys) { | |||
if (key.code == code) { | |||
return key; | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
protected Event(long ptr) { | |||
this.ptr = ptr; | |||
} | |||
private static native int getEventType(long eventPtr); | |||
public Type getType() { | |||
return Type.forCode(getEventType(ptr)); | |||
} | |||
private static native int getEventKeyCh(long eventPtr); | |||
public int getKeyCh() { | |||
return getEventKeyCh(ptr); | |||
} | |||
private static native int getEventKeyUtf32(long eventPtr); | |||
public int getKeyUtf32() { | |||
return getEventKeyUtf32(ptr); | |||
} | |||
private static native String getEventKeyUtf8(long eventPtr); | |||
public String getKeyUtf8() { | |||
return getEventKeyUtf8(ptr); | |||
} | |||
private static native int getEventMouseButton(long eventPtr); | |||
public int getMouseButton() { | |||
return getEventMouseButton(ptr); | |||
} | |||
private static native int getEventMouseX(long eventPtr); | |||
public int getMouseX() { | |||
return getEventMouseX(ptr); | |||
} | |||
private static native int getEventMouseY(long eventPtr); | |||
public int getMouseY() { | |||
return getEventMouseY(ptr); | |||
} | |||
private static native int getEventResizeWidth(long eventPtr); | |||
public int getResizeWidth() { | |||
return getEventResizeWidth(ptr); | |||
} | |||
private static native int getEventResizeHeight(long eventPtr); | |||
public int getResizeHeight() { | |||
return getEventResizeHeight(ptr); | |||
} | |||
private static native void freeEvent(long eventPtr); | |||
@Override | |||
public void finalize() throws Throwable { | |||
freeEvent(ptr); | |||
super.finalize(); | |||
} | |||
} |
@@ -0,0 +1,61 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class Font extends NativeObject { | |||
static { | |||
Caca.load(); | |||
} | |||
private static native long loadFont(String fontName); | |||
private static native long loadFont(byte[] fontBytes); | |||
public Font(String fontName) { | |||
ptr = loadFont(fontName); | |||
} | |||
public Font(byte[] fontBytes) { | |||
ptr = loadFont(fontBytes); | |||
} | |||
public static native String[] getFontNames(); | |||
private static native int getFontWidth(long fontPtr); | |||
public int getWidth() { | |||
return getFontWidth(ptr); | |||
} | |||
private static native int getFontHeight(long fontPtr); | |||
public int getHeight() { | |||
return getFontHeight(ptr); | |||
} | |||
private static native int[][] getFontBlocks(long fontPtr); | |||
public int[][] getBlocks() { | |||
return getFontBlocks(ptr); | |||
} | |||
private static native void freeFont(long fontPtr); | |||
@Override | |||
public void finalize() throws Throwable { | |||
freeFont(ptr); | |||
super.finalize(); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public abstract class NativeObject { | |||
protected long ptr; | |||
} |
@@ -0,0 +1,24 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
package org.zoy.caca; | |||
public class TimeoutException extends RuntimeException { | |||
private static final long serialVersionUID = 1L; | |||
public TimeoutException(String msg) { | |||
super(msg); | |||
} | |||
} |
@@ -0,0 +1,62 @@ | |||
/* | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "org_zoy_caca_Attribute.h" | |||
#include "caca.h" | |||
JNIEXPORT jbyte JNICALL | |||
Java_org_zoy_caca_Attribute_attributeToAnsi(JNIEnv *env, jclass cls, jint attr) | |||
{ | |||
return caca_attr_to_ansi(attr); | |||
} | |||
JNIEXPORT jbyte JNICALL | |||
Java_org_zoy_caca_Attribute_attributeToAnsiForeground(JNIEnv *env, jclass cls, jint attr) | |||
{ | |||
return caca_attr_to_ansi_fg(attr); | |||
} | |||
JNIEXPORT jbyte JNICALL | |||
Java_org_zoy_caca_Attribute_attributeToAnsiBackground(JNIEnv *env, jclass cls, jint attr) | |||
{ | |||
return caca_attr_to_ansi_bg(attr); | |||
} | |||
JNIEXPORT jshort JNICALL | |||
Java_org_zoy_caca_Attribute_attributeToRgb12Foreground(JNIEnv *env, jclass cls, jint attr) | |||
{ | |||
return caca_attr_to_rgb12_fg(attr); | |||
} | |||
JNIEXPORT jshort JNICALL | |||
Java_org_zoy_caca_Attribute_attributeToRgb12Background(JNIEnv *env, jclass cls, jint attr) | |||
{ | |||
return caca_attr_to_rgb12_bg(attr); | |||
} | |||
JNIEXPORT jbyteArray JNICALL | |||
Java_org_zoy_caca_Attribute_attributeToArgb64(JNIEnv *env, jclass cls, jint attr) | |||
{ | |||
jbyteArray ret; | |||
jbyte *elems; | |||
ret = (*env)->NewByteArray(env, 8); | |||
elems = (*env)->GetByteArrayElements(env, ret, 0); | |||
caca_attr_to_argb64(attr, elems); | |||
(*env)->ReleaseByteArrayElements(env, ret, elems, 0); | |||
return ret; | |||
} | |||
@@ -0,0 +1,24 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "org_zoy_caca_Caca.h" | |||
#include "caca.h" | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Caca_getVersion(JNIEnv *env, jclass cls) | |||
{ | |||
const char *version = caca_get_version(); | |||
return (*env)->NewStringUTF(env, version); | |||
} |
@@ -0,0 +1,389 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "org_zoy_caca_Canvas.h" | |||
#include "caca.h" | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getCursorX(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_cursor_x((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getCursorY (JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_cursor_y((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCursorXY(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y) | |||
{ | |||
caca_gotoxy((caca_canvas_t *)ptr, x, y); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getHandleX(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_canvas_handle_x((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getHandleY(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_canvas_handle_x((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setHandleXY(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y) | |||
{ | |||
caca_set_canvas_handle((caca_canvas_t *)ptr, x, y); | |||
} | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Canvas_createCanvas(JNIEnv *env, jclass cls, jint w, jint h) | |||
{ | |||
return (jlong)caca_create_canvas(w, h); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getCanvasWidth(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_canvas_width((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getCanvasHeight(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_canvas_height((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCanvasSize(JNIEnv *env, jclass cls, jlong ptr, jint w, jint h) | |||
{ | |||
caca_set_canvas_size((caca_canvas_t *)ptr, w, h); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_clearCanvas(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_clear_canvas((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getCanvasChar(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y) | |||
{ | |||
return caca_get_char((caca_canvas_t *)ptr, x, y); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_putCanvasChar(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, jint ch) | |||
{ | |||
caca_put_char((caca_canvas_t *)ptr, x, y, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_putCanvasString(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, jstring s) | |||
{ | |||
const char *chars; | |||
chars = (*env)->GetStringUTFChars(env, s, 0); | |||
caca_put_str((caca_canvas_t *)ptr, x, y, chars); | |||
(*env)->ReleaseStringUTFChars(env, s, chars); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_blitCanvas(JNIEnv *env, jclass cls, jlong ptr, jint x, | |||
jint y, jlong cv, jlong mask) | |||
{ | |||
caca_blit((caca_canvas_t *)ptr, x, y, (caca_canvas_t *)cv, (caca_canvas_t *)mask); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCanvasBoundaries(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x, jint y, jint w, jint h) | |||
{ | |||
caca_set_canvas_boundaries((caca_canvas_t *)ptr, x, y, w, h); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_invertCanvas(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_invert((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_flipCanvas(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_flip((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_flopCanvas(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_flop((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_rotateCanvas180(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_rotate_180((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_rotateCanvasLeft(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_rotate_left((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_rotateCanvasRight(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_rotate_right((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_stretchCanvasLeft(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_stretch_left((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_stretchCanvasRight(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_stretch_right((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getCanvasAttribute(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y) | |||
{ | |||
return caca_get_attr((caca_canvas_t *)ptr, x, y); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCanvasAttribute(JNIEnv *env, jclass cls, jlong ptr, jint attr) | |||
{ | |||
caca_set_attr((caca_canvas_t *)ptr, attr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_putCanvasAttribute(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x, jint y, jint attr) | |||
{ | |||
caca_put_attr((caca_canvas_t *)ptr, x, y, attr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCanvasColorAnsi(JNIEnv *env, jclass cls, jlong ptr, jbyte fg, jbyte bg) | |||
{ | |||
caca_set_color_ansi((caca_canvas_t *)ptr, fg, bg); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCanvasColorArgb(JNIEnv *env, jclass cls, jlong ptr, jshort fg, jshort bg) | |||
{ | |||
caca_set_color_argb((caca_canvas_t *)ptr, fg, bg); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawLine(JNIEnv *env, jclass cls, jlong ptr, jint x1, jint y1, | |||
jint x2, jint y2, jint ch) | |||
{ | |||
caca_draw_line((caca_canvas_t *)ptr, x1, y1, x2, y2, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawPolyline(JNIEnv *env, jclass cls, jlong ptr, | |||
jintArray xs, jintArray ys, jint ch) | |||
{ | |||
jsize size; | |||
jint *x_elems; | |||
jint *y_elems; | |||
size = (*env)->GetArrayLength(env, xs); | |||
x_elems = (*env)->GetIntArrayElements(env, xs, 0); | |||
y_elems = (*env)->GetIntArrayElements(env, ys, 0); | |||
caca_draw_polyline((caca_canvas_t *)ptr, x_elems, y_elems, size, ch); | |||
(*env)->ReleaseIntArrayElements(env, xs, x_elems, 0); | |||
(*env)->ReleaseIntArrayElements(env, ys, y_elems, 0); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawThinLine(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x1, jint y1, jint x2, jint y2) | |||
{ | |||
caca_draw_thin_line((caca_canvas_t *)ptr, x1, y1, x2, y2); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawThinPolyline(JNIEnv *env, jclass cls, jlong ptr, | |||
jintArray xs, jintArray ys) | |||
{ | |||
jsize size; | |||
jint *x_elems; | |||
jint *y_elems; | |||
size = (*env)->GetArrayLength(env, xs); | |||
x_elems = (*env)->GetIntArrayElements(env, xs, 0); | |||
y_elems = (*env)->GetIntArrayElements(env, ys, 0); | |||
caca_draw_thin_polyline((caca_canvas_t *)ptr, x_elems, y_elems, size); | |||
(*env)->ReleaseIntArrayElements(env, xs, x_elems, 0); | |||
(*env)->ReleaseIntArrayElements(env, ys, y_elems, 0); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawCircle(JNIEnv * env, jclass cls, jlong ptr, | |||
jint x, jint y, jint r, jint ch) | |||
{ | |||
caca_draw_circle((caca_canvas_t *)ptr, x, y, r, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawEllipse(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x, jint y, jint a, jint b, jint ch) | |||
{ | |||
caca_draw_ellipse((caca_canvas_t *)ptr, x, y, a, b, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawThinEllipse(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x, jint y, jint a, jint b) | |||
{ | |||
caca_draw_thin_ellipse((caca_canvas_t *)ptr, x, y, a, b); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasFillEllipse(JNIEnv *env, jclass cls, jlong ptr, jint x, | |||
jint y, jint a, jint b, jint ch) | |||
{ | |||
caca_fill_ellipse((caca_canvas_t *)ptr, x, y, a, b, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawBox(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, | |||
jint w, jint h, jint ch) | |||
{ | |||
caca_draw_box((caca_canvas_t *)ptr, x, y, w, h, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawThinBox(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x, jint y, jint w, jint h) | |||
{ | |||
caca_draw_thin_box((caca_canvas_t *)ptr, x, y, w, h); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawCp437Box(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x, jint y, jint w, jint h) | |||
{ | |||
caca_draw_cp437_box((caca_canvas_t *)ptr, x, y, w, h); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasFillBox(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x, jint y, jint w, jint h, jint ch) | |||
{ | |||
caca_fill_box((caca_canvas_t *)ptr, x, y, w, h, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawTriangle(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x1, jint y1, jint x2, jint y2, | |||
jint x3, jint y3, jint ch) | |||
{ | |||
caca_draw_triangle((caca_canvas_t *)ptr, x1, y1, x2, y2, x3, y3, ch); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDrawThinTriangle(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x1, jint y1, jint x2, jint y2, | |||
jint x3, jint y3) | |||
{ | |||
caca_draw_thin_triangle((caca_canvas_t *)ptr, x1, y1, x2, y2, x3, y3); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasFillTriangle(JNIEnv *env, jclass cls, jlong ptr, | |||
jint x1, jint y1, jint x2, jint y2, | |||
jint x3, jint y3, jint ch) | |||
{ | |||
caca_fill_triangle((caca_canvas_t *)ptr, x1, y1, x2, y2, x3, y3, ch); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Canvas_getCanvasFrameCount(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_frame_count((caca_canvas_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCanvasFrame(JNIEnv *env, jclass cls, jlong ptr, jint id) | |||
{ | |||
caca_set_frame((caca_canvas_t *)ptr, id); | |||
} | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Canvas_getCanvasFrameName(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
const char *frame_name = caca_get_frame_name((caca_canvas_t *)ptr); | |||
return (*env)->NewStringUTF(env, frame_name); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_setCanvasFrameName(JNIEnv *env, jclass cls, jlong ptr, jstring frame_name) | |||
{ | |||
const char *frame_name_chars = (*env)->GetStringUTFChars(env, frame_name, 0); | |||
caca_set_frame_name((caca_canvas_t *)ptr, frame_name_chars); | |||
(*env)->ReleaseStringUTFChars(env, frame_name, frame_name_chars); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_createCanvasFrame(JNIEnv *env, jclass cls, jlong ptr, jint id) | |||
{ | |||
caca_create_frame((caca_canvas_t *)ptr, id); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_freeCanvasFrame(JNIEnv *env, jclass cls, jlong ptr, jint id) | |||
{ | |||
caca_free_frame((caca_canvas_t *)ptr, id); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasRender(JNIEnv *env, jclass cls, jlong ptr, jlong font_ptr, | |||
jbyteArray buf, jint width, jint height, jint pitch) | |||
{ | |||
jbyte *elems = (*env)->GetByteArrayElements(env, buf, 0); | |||
caca_render_canvas((caca_canvas_t *)ptr, (caca_font_t *)font_ptr, elems, width, height, pitch); | |||
(*env)->ReleaseByteArrayElements(env, buf, elems, 0); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_canvasDitherBitmap(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, | |||
jint w, jint h, jlong dither_ptr, jbyteArray pixels) | |||
{ | |||
jbyte *elems = (*env)->GetByteArrayElements(env, pixels, 0); | |||
jsize size = (*env)->GetArrayLength(env, pixels); | |||
caca_dither_bitmap((caca_canvas_t *)ptr, x, y, w, h, (caca_dither_t *)dither_ptr, elems); | |||
(*env)->ReleaseByteArrayElements(env, pixels, elems, 0); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Canvas_freeCanvas(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_free_canvas((caca_canvas_t *)ptr); | |||
} | |||
@@ -0,0 +1,187 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "caca_java_common.h" | |||
#include "org_zoy_caca_Display.h" | |||
#include <stdlib.h> | |||
#include "caca.h" | |||
#define DISPLAY_CREATION_ERROR "Cannot create display" | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Display_createDisplayAndCanvas(JNIEnv *env, jclass cls) | |||
{ | |||
caca_display_t *display = caca_create_display(NULL); | |||
if(display == NULL) { | |||
THROW_EX(DISPLAY_CREATION_ERROR); | |||
return 0; | |||
} | |||
return (jlong)display; | |||
} | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Display_createDisplay(JNIEnv *env, jclass cls, jlong canvas_ptr) | |||
{ | |||
caca_display_t *display = caca_create_display((caca_canvas_t *)canvas_ptr); | |||
if(display == NULL) { | |||
THROW_EX(DISPLAY_CREATION_ERROR); | |||
return 0; | |||
} | |||
return (jlong)display; | |||
} | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Display_createDisplayAndCanvasWithDriver(JNIEnv *env, jclass cls, | |||
jstring driver_name) | |||
{ | |||
const char *driver_name_chars = (*env)->GetStringUTFChars(env, driver_name, 0); | |||
caca_display_t *ret = caca_create_display_with_driver(NULL, driver_name_chars); | |||
(*env)->ReleaseStringUTFChars(env, driver_name, driver_name_chars); | |||
if(ret == NULL) { | |||
THROW_EX(DISPLAY_CREATION_ERROR); | |||
return 0; | |||
} | |||
return (jlong)ret; | |||
} | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Display_createDisplayWithDriver(JNIEnv *env, jclass cls, | |||
jlong canvas_ptr, jstring driver_name) | |||
{ | |||
const char *driver_name_chars = (*env)->GetStringUTFChars(env, driver_name, 0); | |||
caca_display_t *ret = caca_create_display_with_driver((caca_canvas_t *)canvas_ptr, driver_name_chars); | |||
(*env)->ReleaseStringUTFChars(env, driver_name, driver_name_chars); | |||
if(ret == NULL) { | |||
THROW_EX(DISPLAY_CREATION_ERROR); | |||
return 0; | |||
} | |||
return (jlong)ret; | |||
} | |||
JNIEXPORT jobjectArray JNICALL | |||
Java_org_zoy_caca_Display_getDisplayDriverList(JNIEnv *env, jclass cls) | |||
{ | |||
const char *const *drivers = caca_get_display_driver_list(); | |||
return caca_java_to_string_array(env, drivers); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Display_setDisplayDriver(JNIEnv *env, jclass cls, jlong ptr, jstring driver_name) | |||
{ | |||
const char *driver_name_chars = (*env)->GetStringUTFChars(env, driver_name, 0); | |||
caca_set_display_driver((caca_display_t *)ptr, driver_name_chars); | |||
(*env)->ReleaseStringUTFChars(env, driver_name, driver_name_chars); | |||
} | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Display_getDisplayDriver(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return (*env)->NewStringUTF(env, caca_get_display_driver((caca_display_t *)ptr)); | |||
} | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Display_getDisplayCanvas(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return (jlong)caca_get_canvas((caca_display_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Display_displayRefresh(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_refresh_display((caca_display_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Display_setDisplayTime(JNIEnv *env, jclass cls, jlong ptr, jint time) | |||
{ | |||
caca_set_display_time((caca_display_t *)ptr, time); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Display_getDisplayTime(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_display_time((caca_display_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Display_getDisplayWidth(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_display_width((caca_display_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Display_getDisplayHeight(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_display_height((caca_display_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Display_setDisplayTitle(JNIEnv *env, jclass cls, jlong ptr, jstring title) | |||
{ | |||
const char *title_chars = (*env)->GetStringUTFChars(env, title, 0); | |||
caca_set_display_title((caca_display_t *)ptr, title_chars); | |||
(*env)->ReleaseStringUTFChars(env, title, title_chars); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Display_setDisplayMouse(JNIEnv *env, jclass cls, jlong ptr, jboolean st) | |||
{ | |||
caca_set_mouse((caca_display_t *)ptr, st); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Display_setDisplayCursor(JNIEnv *env, jclass cls, jlong ptr, jboolean st) | |||
{ | |||
caca_set_cursor((caca_display_t *)ptr, st); | |||
} | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Display_getDisplayEvent(JNIEnv *env, jclass cls, jlong ptr, jint mask, jint timeout) | |||
{ | |||
caca_event_t *ev = malloc(sizeof(caca_event_t)); | |||
if (caca_get_event((caca_display_t *)ptr, mask, ev, timeout)) | |||
{ | |||
return (jlong) ev; | |||
} | |||
free(ev); | |||
(*env)->ThrowNew(env, (*env)->FindClass(env, "org/zoy/caca/TimeoutException"), "No event received"); | |||
return -1; | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Display_getDisplayMouseX(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_mouse_x((caca_display_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Display_getDisplayMouseY(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_mouse_y((caca_display_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Display_freeDisplay(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_free_display((caca_display_t *)ptr); | |||
} | |||
@@ -0,0 +1,175 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "org_zoy_caca_Dither.h" | |||
#include "caca_java_common.h" | |||
#include "caca.h" | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Dither_createDither(JNIEnv *env, jclass cls, jint bpp, jint w, jint h, | |||
jint pitch, jint rmask, jint gmask, jint bmask, jint amask) | |||
{ | |||
caca_dither_t *dither = caca_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask); | |||
if(dither == NULL) { | |||
THROW_EX("Cannot create a new Dither"); | |||
return 0; | |||
} | |||
return (jlong)dither; | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherPalette(JNIEnv *env, jclass vls, jlong ptr, jintArray red, | |||
jintArray green, jintArray blue, jintArray alpha) | |||
{ | |||
jint *relems, *gelems, *belems, *aelems; | |||
relems = (*env)->GetIntArrayElements(env, red, 0); | |||
gelems = (*env)->GetIntArrayElements(env, green, 0); | |||
belems = (*env)->GetIntArrayElements(env, blue, 0); | |||
aelems = (*env)->GetIntArrayElements(env, alpha, 0); | |||
caca_set_dither_palette((caca_dither_t *)ptr, relems, gelems, belems, aelems); | |||
(*env)->ReleaseIntArrayElements(env, red, relems, 0); | |||
(*env)->ReleaseIntArrayElements(env, green, gelems, 0); | |||
(*env)->ReleaseIntArrayElements(env, blue, belems, 0); | |||
(*env)->ReleaseIntArrayElements(env, alpha, aelems, 0); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherBrightness(JNIEnv *env, jclass cls, jlong ptr, jfloat v) | |||
{ | |||
caca_set_dither_brightness((caca_dither_t *)ptr, v); | |||
} | |||
JNIEXPORT jfloat JNICALL | |||
Java_org_zoy_caca_Dither_getDitherBrightness(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_dither_brightness((caca_dither_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherGamma(JNIEnv *env, jclass cls, jlong ptr, jfloat v) | |||
{ | |||
caca_set_dither_gamma((caca_dither_t *)ptr, v); | |||
} | |||
JNIEXPORT jfloat JNICALL | |||
Java_org_zoy_caca_Dither_getDitherGamma(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_dither_gamma((caca_dither_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherContrast(JNIEnv *env, jclass cls, jlong ptr, jfloat v) | |||
{ | |||
caca_set_dither_contrast((caca_dither_t *)ptr, v); | |||
} | |||
JNIEXPORT jfloat JNICALL | |||
Java_org_zoy_caca_Dither_getDitherContrast(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_dither_contrast((caca_dither_t *)ptr); | |||
} | |||
JNIEXPORT jobjectArray JNICALL | |||
Java_org_zoy_caca_Dither_getDitherAntiAliasingList(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
const char *const *antialias_list = caca_get_dither_antialias_list((caca_dither_t *)ptr); | |||
return caca_java_to_string_array(env, antialias_list); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherAntiAliasing(JNIEnv *env, jclass cls, jlong ptr, jstring aa) | |||
{ | |||
const char *aa_chars = (*env)->GetStringUTFChars(env, aa, 0); | |||
caca_set_dither_antialias((caca_dither_t *)ptr, aa_chars); | |||
(*env)->ReleaseStringUTFChars(env, aa, aa_chars); | |||
} | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Dither_getDitherAntiAliasing(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return (*env)->NewStringUTF(env, caca_get_dither_antialias((caca_dither_t *)ptr)); | |||
} | |||
JNIEXPORT jobjectArray | |||
JNICALL Java_org_zoy_caca_Dither_getDitherColorList(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
const char *const *color_list = caca_get_dither_color_list((caca_dither_t *)ptr); | |||
return caca_java_to_string_array(env, color_list); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherColor(JNIEnv *env, jclass cls, jlong ptr, jstring color) | |||
{ | |||
const char *color_chars = (*env)->GetStringUTFChars(env, color, 0); | |||
caca_set_dither_color((caca_dither_t *)ptr, color_chars); | |||
(*env)->ReleaseStringUTFChars(env, color, color_chars); | |||
} | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Dither_getDitherColor(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return (*env)->NewStringUTF(env, caca_get_dither_color((caca_dither_t *)ptr)); | |||
} | |||
JNIEXPORT jobjectArray JNICALL | |||
Java_org_zoy_caca_Dither_getDitherCharsetList(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
const char *const *color_list = caca_get_dither_color_list((caca_dither_t *)ptr); | |||
return caca_java_to_string_array(env, color_list); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherCharset(JNIEnv *env, jclass cls, jlong ptr, jstring charset) | |||
{ | |||
const char *charset_chars = (*env)->GetStringUTFChars(env, charset, 0); | |||
caca_set_dither_charset((caca_dither_t *)ptr, charset_chars); | |||
(*env)->ReleaseStringUTFChars(env, charset, charset_chars); | |||
} | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Dither_getDitherCharset(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return (*env)->NewStringUTF(env, caca_get_dither_charset((caca_dither_t *)ptr)); | |||
} | |||
JNIEXPORT jobjectArray JNICALL | |||
Java_org_zoy_caca_Dither_getDitherAlgorithmList(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
const char *const *algorithm_list = caca_get_dither_algorithm_list((caca_dither_t *)ptr); | |||
return caca_java_to_string_array(env, algorithm_list); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_setDitherAlgorithm(JNIEnv *env, jclass cls, jlong ptr, jstring algorithm) | |||
{ | |||
const char *algorithm_chars = (*env)->GetStringUTFChars(env, algorithm, 0); | |||
caca_set_dither_algorithm((caca_dither_t *)ptr, algorithm_chars); | |||
(*env)->ReleaseStringUTFChars(env, algorithm, algorithm_chars); | |||
} | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Dither_getDitherAlgorithm(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return (*env)->NewStringUTF(env, caca_get_dither_algorithm((caca_dither_t *)ptr)); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Dither_freeDither(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_free_dither((caca_dither_t *)ptr); | |||
} | |||
@@ -0,0 +1,80 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "org_zoy_caca_Event.h" | |||
#include <stdlib.h> | |||
#include "caca.h" | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventType(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return (jint)caca_get_event_type((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventKeyCh(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_event_key_ch((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventKeyUtf32(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_event_key_utf32((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT jstring JNICALL | |||
Java_org_zoy_caca_Event_getEventKeyUtf8(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
char *str = malloc(8 * sizeof(char)); | |||
caca_get_event_key_utf8((caca_event_t *)ptr, str); | |||
return (*env)->NewStringUTF(env, str); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventMouseButton(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_event_mouse_button((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventMouseX(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_event_mouse_x((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventMouseY(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_event_mouse_y((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventResizeWidth(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_event_resize_width((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Event_getEventResizeHeight(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_event_resize_height((caca_event_t *)ptr); | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Event_freeEvent(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_event_t *ev = (caca_event_t *)ptr; | |||
free(ev); | |||
} |
@@ -0,0 +1,117 @@ | |||
/** | |||
* libcaca Java bindings for libcaca | |||
* Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> | |||
* | |||
* $Id$ | |||
* | |||
* 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://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "caca_java_common.h" | |||
#include "org_zoy_caca_Font.h" | |||
#include "caca.h" | |||
#define FONT_CREATION_ERROR "Cannot load font" | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Font_loadFont__Ljava_lang_String_2(JNIEnv *env, jclass cls, jstring font_name) | |||
{ | |||
const char *font_name_chars; | |||
caca_font_t *font; | |||
font_name_chars = (*env)->GetStringUTFChars(env, font_name, 0); | |||
font = caca_load_font(font_name_chars, 0); | |||
(*env)->ReleaseStringUTFChars(env, font_name, font_name_chars); | |||
if (!font) | |||
{ | |||
THROW_EX(FONT_CREATION_ERROR); | |||
return 0; | |||
} | |||
return (jlong)font; | |||
} | |||
JNIEXPORT jlong JNICALL | |||
Java_org_zoy_caca_Font_loadFont___3B(JNIEnv *env, jclass cls, jbyteArray font_bytes) | |||
{ | |||
jbyte *elems; | |||
jsize size; | |||
caca_font_t *font; | |||
elems = (*env)->GetByteArrayElements(env, font_bytes, 0); | |||
size = (*env)->GetArrayLength(env, font_bytes); | |||
font = caca_load_font(elems, size); | |||
(*env)->ReleaseByteArrayElements(env, font_bytes, elems, 0); | |||
if (!font) | |||
{ | |||
THROW_EX(FONT_CREATION_ERROR); | |||
return 0; | |||
} | |||
return (jlong)font; | |||
} | |||
JNIEXPORT jobjectArray JNICALL | |||
Java_org_zoy_caca_Font_getFontNames(JNIEnv *env, jclass cls) | |||
{ | |||
const char *const *fonts = caca_get_font_list(); | |||
return caca_java_to_string_array(env, fonts); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Font_getFontWidth(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_font_width(ptr); | |||
} | |||
JNIEXPORT jint JNICALL | |||
Java_org_zoy_caca_Font_getFontHeight(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
return caca_get_font_height(ptr); | |||
} | |||
JNIEXPORT jobjectArray JNICALL | |||
Java_org_zoy_caca_Font_getFontBlocks(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
const uint32_t *blocks; | |||
jclass int_array; | |||
jobjectArray ret; | |||
jsize size; | |||
jsize i; | |||
blocks = caca_get_font_blocks(ptr); | |||
for (size = 0; blocks[2*size] || blocks[2*size+1]; ++size); | |||
int_array = (*env)->FindClass(env, "[I"); | |||
ret = (*env)->NewObjectArray(env, size, int_array, NULL); | |||
for (i = 0; i < size; ++i) | |||
{ | |||
jintArray nth = (*env)->NewIntArray(env, 2); /* Size is 2 */ | |||
jint nth_elems[] = { blocks[2*i], blocks[2*i+1] }; | |||
(*env)->SetIntArrayRegion(env, nth, 0, 2, nth_elems); | |||
(*env)->SetObjectArrayElement(env, ret, i, nth); | |||
(*env)->DeleteLocalRef(env, nth); | |||
} | |||
return ret; | |||
} | |||
JNIEXPORT void JNICALL | |||
Java_org_zoy_caca_Font_freeFont(JNIEnv *env, jclass cls, jlong ptr) | |||
{ | |||
caca_free_font((caca_font_t *)ptr); | |||
} | |||