From cb1910125ed4efa25ef807fed8f75991f2c0fad2 Mon Sep 17 00:00:00 2001 From: daleclack Date: Sat, 27 Nov 2021 13:39:37 +0800 Subject: [PATCH] Update gtk118 --- Gtk4/gtk118_imageviewer/src/MyImage.cpp | 6 ++++- Gtk4/gtk118_imageviewer/src/MyWindow.cpp | 33 +++++++++++++++++++++-- Gtk4/icon.ico | Bin 0 -> 9662 bytes Gtk4/icon.rc | 1 + rust_test/test.rs | 3 +++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 Gtk4/icon.ico create mode 100644 Gtk4/icon.rc create mode 100644 rust_test/test.rs 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 0000000000000000000000000000000000000000..006512f3fd445a0b86e3650dbf20c8c357c75360 GIT binary patch literal 9662 zcmc(k30#$BzQ<47G^rirvWOtalA<6eD2Rd^ zii!)18w!HTqK@K5mS|;}m04M7S~)HAyTAX-ISleKv!>fnU!Qk-p6B=9p7%NDs8mn! zKO-X*{~f9-AE{CeP^naUgqKu4M6PT9TK=R`3BSi*|GopB`aS0PSLYC&8lGnRjD}~~ zYSCVk``Ty!?Y3#Oh_>g*AIX1^Kam$nzb^FUaUUZ05yB#to5#Net(e$6> zFJw5;CkDirm}oH4T+?GajJ!nplU_u|_+9MaJX+l^@L2pQnnjc7v?R7#FpOV|J4qTFS+{%B0l>wQIqkT7rPaH>Nm?N8H-4K#pjYIk|U-q#i2M= z8jdsNQMhM3QjP~X%TxrR{)srjm)~P(Dz1ot?YuRXT%H%T{IJY+jt-GRex-1eW zHiU^SPQ->t3|}TvHxi4df1`Cp@?88PaUOFtCjgDBgCP1_chIL*NqD^`6>l`WM*Yha ztzyF!>TYM--n^XJm*H~b5?5oXn$(O&RyV?fSFY$xuZ&^d%Z;V9i_BdRqOjIriL z$20N9vBh}fXa-)dU&I_s!nw-%v^@r=HbtUkT{w=f3`D~+e~E=VnMw@FAR=qkFSdbw zv^gVwAAB&*1Ba8n(Xf=h&!z7RLveC_1kRMj;9NxlF7985*J~MrV;ST%TspcKuQQ+8 zXw${|G+d}l#rfJ4oTc{GssxX-VXHq{5NmL{p3(~d}e zOUxw>zbKdZyyUy|)2R%1!hu+K)TQ{LA#*N{Q-57-D<*#EHELXsL=v^X?clZI43JmIyR5_Z!zyJI6Y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f!74>b?v#*R`T8>(2mFP<@;IL8_0J%Ph6|rwLb1##wDHkBy*o> zsOv^8&mYg}`oopy9m_E(|pL=)Oh zc7xZ}CeQEGEYGsP{6;6AqeQptC&f3vs!o4S^P}#|T$(w>XA<)ly4uqHn4gcD`Hbve zWK9vx@;*{>obB(X`!TkNJ)%bto5ZJGk!x~K@iW_htL8`9p}i*Bx}&}KTendDRH~nD zf8Z^-pZ2`c{vgNXj!Km(?RAw(SK2g{s<*Th_&opl2is>f?Ne;oO}Y7?Yn!T4aTpGy zX{}YN>vFDbbv5T*+T(Jc=TF*R*F68omh&j{cW+ZwDn%z-t!`<>4zWvG{;$|4c8k3@ cuJHp0w3c%Yp!f-VOwMuLx}z0O%Xvrpf3En%;Q#;t literal 0 HcmV?d00001 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