diff --git a/Gtk4/gtk118_imageviewer/src/MyImage.cpp b/Gtk4/gtk118_imageviewer/src/MyImage.cpp index 4fe6209..d02719c 100644 --- a/Gtk4/gtk118_imageviewer/src/MyImage.cpp +++ b/Gtk4/gtk118_imageviewer/src/MyImage.cpp @@ -25,8 +25,9 @@ struct _MyImageClass{ G_DEFINE_TYPE(MyImage,my_image,GTK_TYPE_WIDGET) void my_image_set_pixbuf(MyImage * self, GdkPixbuf * pixbuf){ - //g_clear_object(&self->paintable); + g_clear_object(&self->paintable); self->paintable = (GdkPaintable*)gdk_texture_new_for_pixbuf(pixbuf); + gtk_widget_queue_draw(GTK_WIDGET(self)); } static void pressed_cb(GtkGestureClick * gesture,int n_press,double x,double y,MyImage * self){ @@ -39,6 +40,7 @@ static void pressed_cb(GtkGestureClick * gesture,int n_press,double x,double y,M static void drag_start(GtkGestureDrag * self,double x,double y,MyImage * image){ //Get Properties + //sleep(1); image->start_x = x; image->start_y = y; image->hmax_value = gtk_adjustment_get_upper(image->hadjustment); @@ -47,6 +49,7 @@ static void drag_start(GtkGestureDrag * self,double x,double y,MyImage * image){ static void drag_update(GtkGestureDrag * self,double x,double y,MyImage * image){ //Move Image + //sleep(1); int hadj_value = gtk_adjustment_get_value(image->hadjustment); int vadj_value = gtk_adjustment_get_value(image->vadjustment); if(hadj_value - x >= 0 && - x <= image->hmax_value){ @@ -59,6 +62,7 @@ static void drag_update(GtkGestureDrag * self,double x,double y,MyImage * image) static void drag_end(GtkGestureDrag * self,double x,double y,MyImage * image){ //g_print("%f %f\n",x+image->start_x,y+image->start_y); + //sleep(1); int hadj_value = gtk_adjustment_get_value(image->hadjustment); int vadj_value = gtk_adjustment_get_value(image->vadjustment); if(hadj_value - x >= 0 && - x <= image->hmax_value){ diff --git a/Gtk4/gtk118_imageviewer/src/MyWindow.cpp b/Gtk4/gtk118_imageviewer/src/MyWindow.cpp index 24877b5..4a504b9 100644 --- a/Gtk4/gtk118_imageviewer/src/MyWindow.cpp +++ b/Gtk4/gtk118_imageviewer/src/MyWindow.cpp @@ -9,9 +9,37 @@ struct _MyWindow{ G_DEFINE_TYPE(MyWindow,my_window,GTK_TYPE_APPLICATION_WINDOW) -static void dialog_respone(GtkNativeDialog * dialog,int respone,MyWindow * window){} +static void dialog_respone(GtkNativeDialog * dialog,int response,MyWindow * window){ + if(response == GTK_RESPONSE_ACCEPT){ + //Get Filename + GFile * file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog)); + char * filename = g_file_get_path(file); -static void openfile_dialog(GtkWidget * widget,MyWindow * window){} + GError * err = NULL; + GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(filename,&err); + if(err!=NULL){ + fprintf(stderr, "Unable to read file: %s\n", err->message); + g_error_free(err); + }else{ + my_image_set_pixbuf(MY_IMAGE(window->img_view),pixbuf); + } + + g_object_unref(file); + g_free(filename); + } + gtk_native_dialog_destroy(dialog); +} + +static void openfile_dialog(GtkWidget * widget,MyWindow * window){ + //Create a dialog + GtkFileChooserNative * dialog = gtk_file_chooser_native_new("Open Image File",GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_OPEN,"OK","Cancel"); + + //Link the "response" signal of dialog + g_signal_connect(dialog,"response",G_CALLBACK(dialog_respone),window); + + gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog)); +} static void my_window_init(MyWindow * window){ GtkWidget * vbox, * sw, * scale, * btnbox, * btnopen; @@ -42,6 +70,7 @@ static void my_window_init(MyWindow * window){ //Add a button btnopen = gtk_button_new_with_label("Open Image"); + g_signal_connect(btnopen,"clicked",G_CALLBACK(openfile_dialog),window); gtk_box_append(GTK_BOX(btnbox),btnopen); gtk_box_append(GTK_BOX(vbox),btnbox); diff --git a/Gtk4/icon.ico b/Gtk4/icon.ico new file mode 100644 index 0000000..006512f Binary files /dev/null and b/Gtk4/icon.ico differ diff --git a/Gtk4/icon.rc b/Gtk4/icon.rc new file mode 100644 index 0000000..b0c9c68 --- /dev/null +++ b/Gtk4/icon.rc @@ -0,0 +1 @@ +MAINICON ICON "Icon.ico" diff --git a/rust_test/test.rs b/rust_test/test.rs new file mode 100644 index 0000000..f7b4975 --- /dev/null +++ b/rust_test/test.rs @@ -0,0 +1,3 @@ +fn main(){ + println!("Hello World"); +} \ No newline at end of file