ImageView/ImageButton: don't use deprecated gtk_picture_set_from_pixbuf, reduce code duplication

This commit is contained in:
Mis012
2024-04-20 00:08:09 +02:00
parent 98d17ac25e
commit b52e08fd7a
6 changed files with 15 additions and 18 deletions

View File

@@ -210,10 +210,10 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageButton_native_1constructor
/* /*
* Class: android_widget_ImageButton * Class: android_widget_ImageButton
* Method: native_setPixbuf * Method: native_setPixbuf
* Signature: (J)V * Signature: (JJ)V
*/ */
JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf
(JNIEnv *, jobject, jlong); (JNIEnv *, jobject, jlong, jlong);
/* /*
* Class: android_widget_ImageButton * Class: android_widget_ImageButton

View File

@@ -210,10 +210,10 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageView_native_1constructor
/* /*
* Class: android_widget_ImageView * Class: android_widget_ImageView
* Method: native_setPixbuf * Method: native_setPixbuf
* Signature: (J)V * Signature: (JJ)V
*/ */
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf
(JNIEnv *, jobject, jlong); (JNIEnv *, jobject, jlong, jlong);
/* /*
* Class: android_widget_ImageView * Class: android_widget_ImageView

View File

@@ -19,12 +19,10 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageButton_native_1constructor(JNIE
return _INTPTR(button); return _INTPTR(button);
} }
JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf(JNIEnv *env, jobject this, jlong pixbuf_ptr) JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf(JNIEnv *env, jobject this, jlong widget_ptr, jlong pixbuf_ptr)
{ {
GtkButton *button = _PTR(_GET_LONG_FIELD(this, "widget")); GdkPaintable *paintable = GDK_PAINTABLE(gdk_texture_new_for_pixbuf(_PTR(pixbuf_ptr)));
GtkWidget *image = gtk_button_get_child(GTK_BUTTON(button)); Java_android_widget_ImageButton_native_1setDrawable(env, this, widget_ptr, _INTPTR(paintable));
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr);
gtk_picture_set_pixbuf(GTK_PICTURE(image), pixbuf);
} }
struct touch_callback_data { struct touch_callback_data {
@@ -65,7 +63,7 @@ JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setOnClickListene
JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr) JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr)
{ {
GtkButton *button = _PTR(_GET_LONG_FIELD(this, "widget")); GtkButton *button = _PTR(widget_ptr);
GtkPicture *picture = GTK_PICTURE(gtk_button_get_child(GTK_BUTTON(button))); GtkPicture *picture = GTK_PICTURE(gtk_button_get_child(GTK_BUTTON(button)));
GdkPaintable *paintable = _PTR(paintable_ptr); GdkPaintable *paintable = _PTR(paintable_ptr);
gtk_picture_set_paintable(picture, paintable); gtk_picture_set_paintable(picture, paintable);

View File

@@ -25,11 +25,10 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageView_native_1constructor(JNIEnv
return _INTPTR(image); return _INTPTR(image);
} }
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf(JNIEnv *env, jobject this, jlong pixbuf_ptr) JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf(JNIEnv *env, jobject this, jlong widget_ptr, jlong pixbuf_ptr)
{ {
GtkWidget *image = _PTR(_GET_LONG_FIELD(this, "widget")); GdkPaintable *paintable = GDK_PAINTABLE(gdk_texture_new_for_pixbuf(_PTR(pixbuf_ptr)));
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr); Java_android_widget_ImageView_native_1setDrawable(env, this, widget_ptr, _INTPTR(paintable));
gtk_picture_set_pixbuf(GTK_PICTURE(image), pixbuf);
} }
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr) JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr)

View File

@@ -20,7 +20,7 @@ public class ImageButton extends ImageView {
@Override @Override
protected native long native_constructor(Context context, AttributeSet attrs); protected native long native_constructor(Context context, AttributeSet attrs);
@Override @Override
protected native void native_setPixbuf(long pixbuf); protected native void native_setPixbuf(long widget, long pixbuf);
@Override @Override
protected native void native_setDrawable(long widget, long paintable); protected native void native_setDrawable(long widget, long paintable);
protected native void native_setOnClickListener(long widget, OnClickListener l); protected native void native_setOnClickListener(long widget, OnClickListener l);

View File

@@ -42,7 +42,7 @@ public class ImageView extends View {
return; return;
} }
bitmap = BitmapFactory.decodeResource(Context.this_application.getResources(), resid); bitmap = BitmapFactory.decodeResource(Context.this_application.getResources(), resid);
native_setPixbuf(bitmap.pixbuf); native_setPixbuf(widget, bitmap.pixbuf);
} }
public void setAdjustViewBounds(boolean adjustViewBounds) {} public void setAdjustViewBounds(boolean adjustViewBounds) {}
@@ -82,7 +82,7 @@ public class ImageView extends View {
public void setImageBitmap(Bitmap bitmap) { public void setImageBitmap(Bitmap bitmap) {
if (bitmap != null) if (bitmap != null)
native_setPixbuf(bitmap.pixbuf); native_setPixbuf(widget, bitmap.pixbuf);
} }
/** /**
@@ -168,7 +168,7 @@ public class ImageView extends View {
@Override @Override
protected native long native_constructor(Context context, AttributeSet attrs); protected native long native_constructor(Context context, AttributeSet attrs);
protected native void native_setPixbuf(long pixbuf); protected native void native_setPixbuf(long widget, long pixbuf);
protected native void native_setDrawable(long widget, long paintable); protected native void native_setDrawable(long widget, long paintable);
protected native void native_setScaleType(long widget, int scale_type); protected native void native_setScaleType(long widget, int scale_type);
} }