Update gtk118

This commit is contained in:
daleclack 2021-11-27 13:39:37 +08:00
parent 7a306a6306
commit cb1910125e
5 changed files with 40 additions and 3 deletions

View File

@ -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){

View File

@ -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);

BIN
Gtk4/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

1
Gtk4/icon.rc Normal file
View File

@ -0,0 +1 @@
MAINICON ICON "Icon.ico"

3
rust_test/test.rs Normal file
View File

@ -0,0 +1,3 @@
fn main(){
println!("Hello World");
}