2024-03-24 21:01:47 +01:00
|
|
|
package android.graphics;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GskCanvas:
|
|
|
|
|
* - implements Canvas for onscreen rendering inside GTKs snapshot function
|
|
|
|
|
*/
|
|
|
|
|
public class GskCanvas extends Canvas {
|
2024-05-25 19:58:55 +02:00
|
|
|
public long snapshot;
|
2024-04-08 23:15:05 +02:00
|
|
|
private int save_count = 0;
|
2024-03-24 21:01:47 +01:00
|
|
|
|
2024-12-21 14:24:33 +01:00
|
|
|
private static Paint default_paint = new Paint();
|
|
|
|
|
|
2024-03-24 21:01:47 +01:00
|
|
|
public GskCanvas(long snapshot) {
|
|
|
|
|
this.snapshot = snapshot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int save() {
|
2024-04-08 23:15:05 +02:00
|
|
|
native_save(snapshot);
|
|
|
|
|
return save_count++;
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void restore() {
|
2024-04-08 23:15:05 +02:00
|
|
|
save_count--;
|
|
|
|
|
native_restore(snapshot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void restoreToCount(int count) {
|
|
|
|
|
while (save_count > count) {
|
|
|
|
|
restore();
|
|
|
|
|
}
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void translate(float dx, float dy) {
|
2024-04-08 23:15:05 +02:00
|
|
|
native_translate(snapshot, dx, dy);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void rotate(float degrees) {
|
2024-04-08 23:15:05 +02:00
|
|
|
native_rotate(snapshot, degrees);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
|
2024-12-21 14:24:33 +01:00
|
|
|
native_drawBitmap(snapshot, bitmap.getTexture(), dst.left, dst.top, dst.width(), dst.height(), paint != null ? paint.paint : default_paint.paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawPath(Path path, Paint paint) {
|
2024-12-21 14:24:33 +01:00
|
|
|
native_drawPath(snapshot, path.getGskPath(), paint != null ? paint.paint : default_paint.paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawRect(float left, float top, float right, float bottom, Paint paint) {
|
2024-12-21 14:24:33 +01:00
|
|
|
native_drawRect(snapshot, left, top, right, bottom, paint != null ? paint.paint : default_paint.paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void rotate(float degrees, float px, float py) {
|
2024-05-25 16:32:01 +02:00
|
|
|
native_translate(snapshot, px, py);
|
|
|
|
|
native_rotate(snapshot, degrees);
|
|
|
|
|
native_translate(snapshot, -px, -py);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawText(String text, float x, float y, Paint paint) {
|
2024-12-21 14:24:33 +01:00
|
|
|
native_drawText(snapshot, text, x, y, paint != null ? paint.paint : default_paint.paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
|
2024-12-21 14:24:33 +01:00
|
|
|
native_drawLine(snapshot, startX, startY, stopX, stopY, paint != null ? paint.paint : default_paint.paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
|
|
|
|
|
Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
|
|
|
|
Rect dst = new Rect((int)left, (int)top, (int)left + bitmap.getWidth(), (int)top + bitmap.getHeight());
|
|
|
|
|
drawBitmap(bitmap, src, dst, paint);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 16:32:01 +02:00
|
|
|
@Override
|
|
|
|
|
public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
|
|
|
|
|
drawBitmap(bitmap, src, new Rect((int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom), paint);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-30 17:58:31 +01:00
|
|
|
@Override
|
|
|
|
|
public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) {
|
2024-12-21 14:24:33 +01:00
|
|
|
native_drawRoundRect(snapshot, left, top, right, bottom, rx, ry, paint != null ? paint.paint : default_paint.paint);
|
2024-11-30 17:58:31 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-13 23:10:28 +01:00
|
|
|
@Override
|
|
|
|
|
public void scale(float sx, float sy) {
|
|
|
|
|
native_scale(snapshot, sx, sy);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-21 14:24:33 +01:00
|
|
|
protected native void native_drawBitmap(long snapshot, long texture, int x, int y, int width, int height, long paint);
|
|
|
|
|
protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, long paint);
|
|
|
|
|
protected native void native_drawPath(long snapshot, long path, long paint);
|
2024-04-08 23:15:05 +02:00
|
|
|
protected native void native_translate(long snapshot, float dx, float dy);
|
|
|
|
|
protected native void native_rotate(long snapshot, float degrees);
|
|
|
|
|
protected native void native_save(long snapshot);
|
|
|
|
|
protected native void native_restore(long snapshot);
|
2024-12-21 14:24:33 +01:00
|
|
|
protected native void native_drawLine(long snapshot, float startX, float startY, float stopX, float stopY, long paint);
|
|
|
|
|
protected native void native_drawText(long snapshot, String text, float x, float y, long paint);
|
|
|
|
|
protected native void native_drawRoundRect(long snapshot, float left, float top, float right, float bottom, float rx, float ry, long paint);
|
2024-12-13 23:10:28 +01:00
|
|
|
protected native void native_scale(long snapshot, float sx, float sy);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|