Update gtk4-test
This commit is contained in:
parent
332c97d73c
commit
7240f93ad1
Binary file not shown.
|
@ -2,19 +2,21 @@
|
||||||
#include <res/winpe.xpm>
|
#include <res/winpe.xpm>
|
||||||
|
|
||||||
GtkWidget *background;
|
GtkWidget *background;
|
||||||
|
GFile *file;
|
||||||
|
|
||||||
void set_background(GFile *file,int width,int height){
|
void set_background(GFile *file1,int width,int height){
|
||||||
const gchar *filename;
|
const gchar *filename;
|
||||||
filename=g_file_get_path(file);
|
filename=g_file_get_path(file1);
|
||||||
g_print("%s",filename);
|
//g_print("%s",filename);
|
||||||
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
|
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
|
||||||
GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,width,height,GDK_INTERP_BILINEAR);
|
GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,width,height,GDK_INTERP_BILINEAR);
|
||||||
gtk_picture_set_pixbuf(GTK_PICTURE(background),sized);
|
gtk_picture_set_pixbuf(GTK_PICTURE(background),sized);
|
||||||
|
g_object_unref(pixbuf);
|
||||||
|
g_object_unref(sized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dialog_response(GtkWidget *widget,int response){
|
void dialog_response(GtkWidget *widget,int response){
|
||||||
//Handle file chooser response and set background
|
//Handle file chooser response and set background
|
||||||
GFile *file;
|
|
||||||
const gchar *filename;
|
const gchar *filename;
|
||||||
//g_print("%s\n",filename);
|
//g_print("%s\n",filename);
|
||||||
if(response==GTK_RESPONSE_OK){
|
if(response==GTK_RESPONSE_OK){
|
||||||
|
@ -49,23 +51,25 @@ void default_background(int width,int height){
|
||||||
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_xpm_data(winpe);
|
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_xpm_data(winpe);
|
||||||
GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,width,height,GDK_INTERP_BILINEAR);
|
GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,width,height,GDK_INTERP_BILINEAR);
|
||||||
background=gtk_picture_new_for_pixbuf(sized);
|
background=gtk_picture_new_for_pixbuf(sized);
|
||||||
|
g_object_unref(pixbuf);
|
||||||
|
g_object_unref(sized);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void image_resize(GtkWidget *widget,gpointer data){
|
void image_resize(GtkWidget *widget,gpointer data){
|
||||||
//Get resized width and height
|
//Get resized width and height
|
||||||
int width,height;
|
int width,height;
|
||||||
width=gtk_widget_get_allocated_width(widget);
|
width=gtk_widget_get_allocated_width(widget);
|
||||||
height=gtk_widget_get_allocated_height(widget);
|
height=gtk_widget_get_allocated_height(widget);
|
||||||
GFile *file=gtk_picture_get_file(GTK_PICTURE(background));
|
//GFile *file=gtk_picture_get_file(GTK_PICTURE(background));
|
||||||
if(file==NULL){
|
if(file==NULL){
|
||||||
//g_print("No File Selected");
|
g_print("No File Selected\n");
|
||||||
default_background(width,height);
|
default_background(width,height);
|
||||||
}else{
|
}else{
|
||||||
|
g_print("File Selected\n");
|
||||||
set_background(file,width,height);
|
set_background(file,width,height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
static void gtkmain(GtkApplication *app,gpointer user_data){
|
static void gtkmain(GtkApplication *app,gpointer user_data){
|
||||||
GtkWidget *window,*overlay,*button,*header,*draw_area;
|
GtkWidget *window,*overlay,*button,*header,*draw_area;
|
||||||
|
@ -85,6 +89,12 @@ static void gtkmain(GtkApplication *app,gpointer user_data){
|
||||||
default_background(640,360);
|
default_background(640,360);
|
||||||
gtk_widget_set_size_request(background,640,360);
|
gtk_widget_set_size_request(background,640,360);
|
||||||
gtk_overlay_set_child(GTK_OVERLAY(overlay),background);
|
gtk_overlay_set_child(GTK_OVERLAY(overlay),background);
|
||||||
|
//GtkDrawingArea to handle resize event
|
||||||
|
/*
|
||||||
|
draw_area=gtk_drawing_area_new();
|
||||||
|
gtk_overlay_add_overlay(GTK_OVERLAY(overlay),draw_area);*/
|
||||||
|
//g_signal_connect(draw_area,"resize",G_CALLBACK(image_resize),NULL);
|
||||||
|
//g_signal_connect(background,"draw",G_CALLBACK(image_resize),NULL);
|
||||||
//GtkButton
|
//GtkButton
|
||||||
button=gtk_button_new_with_label("Change Background");
|
button=gtk_button_new_with_label("Change Background");
|
||||||
//gtk_widget_set_size_request(button,200,50);
|
//gtk_widget_set_size_request(button,200,50);
|
||||||
|
|
Loading…
Reference in New Issue