Update gtk4-test v3

This commit is contained in:
daleclack 2021-02-27 13:47:48 +08:00
parent 24870f6749
commit eca595aa3c
2 changed files with 21 additions and 6 deletions

Binary file not shown.

View File

@ -10,10 +10,12 @@ void dialog_response(GtkWidget *widget,int response){
//g_print("%s\n",filename);
if(response==GTK_RESPONSE_OK){
file=gtk_file_chooser_get_file(GTK_FILE_CHOOSER(widget));
gtk_picture_set_file(GTK_PICTURE(background),file);
/*
filename=g_file_get_path(file);
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,640,360,GDK_INTERP_BILINEAR);
gtk_picture_set_pixbuf(GTK_PICTURE(background),sized);
gtk_picture_set_pixbuf(GTK_PICTURE(background),sized);*/
}
gtk_window_destroy(GTK_WINDOW(widget));
}
@ -36,6 +38,21 @@ void change_background(GtkWidget *widget,GtkWindow *parent){
g_signal_connect(dialog,"response",G_CALLBACK(dialog_response),NULL);
}
void default_background(int width,int height){
//Image as background
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_xpm_data(winpe);
GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,width,height,GDK_INTERP_BILINEAR);
background=gtk_picture_new_for_pixbuf(sized);
}
void image_resize(GtkWidget *widget,gpointer data){
//Get resized width and height
int width,height;
width=gtk_widget_get_allocated_width(widget);
height=gtk_widget_get_allocated_height(widget);
default_background(width,height);
}
static void gtkmain(GtkApplication *app,gpointer user_data){
GtkWidget *window,*overlay,*button,*header;
//Window initalize
@ -49,14 +66,12 @@ static void gtkmain(GtkApplication *app,gpointer user_data){
gtk_header_bar_set_show_title_buttons(GTK_HEADER_BAR(header),TRUE);
gtk_header_bar_set_decoration_layout(GTK_HEADER_BAR(header),"close,minimize,maximize:icon");
gtk_window_set_titlebar(GTK_WINDOW(window),header);
//GtkFixed
//GtkOverlay:Lay widget on the top of background
overlay=gtk_overlay_new();
//Image as background
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_xpm_data(winpe);
GdkPixbuf *sized=gdk_pixbuf_scale_simple(pixbuf,640,360,GDK_INTERP_BILINEAR);
background=gtk_picture_new_for_pixbuf(sized);
default_background(640,360);
gtk_widget_set_size_request(background,640,360);
gtk_overlay_set_child(GTK_OVERLAY(overlay),background);
//g_signal_connect_after(background,"resized",G_CALLBACK(image_resize),NULL);
//GtkButton
button=gtk_button_new_with_label("Change Background");
//gtk_widget_set_size_request(button,200,50);