NinePatchPaintable: new GdkPaintable class to render .9.png files

This commit is contained in:
Julian Winkler
2023-12-30 13:47:04 +01:00
parent ca3c17d773
commit 176405ed45
4 changed files with 183 additions and 1 deletions

View File

@@ -1,12 +1,21 @@
#include <gdk/gdk.h>
#include <string.h>
#include "../defines.h"
#include "NinePatchPaintable.h"
#include "../generated_headers/android_graphics_drawable_Drawable.h"
JNIEXPORT jlong JNICALL Java_android_graphics_drawable_Drawable_native_1paintable_1from_1path(JNIEnv *env, jclass class, jstring pathStr) {
const char *path = (*env)->GetStringUTFChars(env, pathStr, NULL);
GdkPaintable *paintable = NULL;
GdkPaintable *paintable = GDK_PAINTABLE(gdk_texture_new_from_filename(path, NULL));
// check if path ends with .9.png
int len = strlen(path);
if (len >= 6 && !strcmp(path + len - 6, ".9.png")) {
paintable = ninepatch_paintable_new(path);
}
if (!paintable)
paintable = GDK_PAINTABLE(gdk_texture_new_from_filename(path, NULL));
(*env)->ReleaseStringUTFChars(env, pathStr, path);
return _INTPTR(paintable);