ui/gtk/image.c

branch
newapi
changeset 340
2dd42bd4fe5d
parent 339
b68b5f984074
equal deleted inserted replaced
339:b68b5f984074 340:2dd42bd4fe5d
35 35
36 UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args) { 36 UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args) {
37 UiObject *current = uic_current_obj(obj); 37 UiObject *current = uic_current_obj(obj);
38 38
39 GtkWidget *scrolledwindow = SCROLLEDWINDOW_NEW(); 39 GtkWidget *scrolledwindow = SCROLLEDWINDOW_NEW();
40 #if GTK_CHECK_VERSION(4, 0, 0)
41 GtkWidget *image = gtk_picture_new();
42 #else
40 GtkWidget *image = gtk_image_new(); 43 GtkWidget *image = gtk_image_new();
44 #endif
45
46 ui_set_name_and_style(image, args.name, args.style_class);
41 47
42 #if GTK_MAJOR_VERSION < 4 48 #if GTK_MAJOR_VERSION < 4
43 GtkWidget *eventbox = gtk_event_box_new(); 49 GtkWidget *eventbox = gtk_event_box_new();
44 SCROLLEDWINDOW_SET_CHILD(scrolledwindow, event_box); 50 SCROLLEDWINDOW_SET_CHILD(scrolledwindow, eventbox);
45 gtk_container_add(GTK_CONTAINER(eventbox), image); 51 gtk_container_add(GTK_CONTAINER(eventbox), image);
46 #else 52 #else
47 SCROLLEDWINDOW_SET_CHILD(scrolledwindow, image); 53 SCROLLEDWINDOW_SET_CHILD(scrolledwindow, image);
48 #endif 54 #endif
49 55
66 72
67 return scrolledwindow; 73 return scrolledwindow;
68 } 74 }
69 75
70 void* ui_imageviewer_get(UiGeneric *g) { 76 void* ui_imageviewer_get(UiGeneric *g) {
71 77 return g->value;
72 } 78 }
73 79
74 const char* ui_imageviewer_get_type(UiGeneric *g) { 80 const char* ui_imageviewer_get_type(UiGeneric *g) {
75 81
76 } 82 }
85 g->value = value; 91 g->value = value;
86 g->type = type; 92 g->type = type;
87 GdkPixbuf *pixbuf = value; 93 GdkPixbuf *pixbuf = value;
88 94
89 if(pixbuf) { 95 if(pixbuf) {
96 int width, height;
90 #if GTK_CHECK_VERSION(4, 12, 0) 97 #if GTK_CHECK_VERSION(4, 12, 0)
91 GdkTexture *texture = gdk_texture_new_for_pixbuf(pixbuf); 98 GdkTexture *texture = gdk_texture_new_for_pixbuf(pixbuf);
92 gtk_image_set_from_paintable(GTK_IMAGE(g->obj), GDK_PAINTABLE(texture)); 99 gtk_picture_set_paintable(GTK_PICTURE(g->obj), GDK_PAINTABLE(texture));
100 width = gdk_texture_get_width(texture);
101 height = gdk_texture_get_height(texture);
93 #else 102 #else
94 gtk_image_set_from_pixbuf(GTK_IMAGE(g->obj), pixbuf); 103 gtk_image_set_from_pixbuf(GTK_IMAGE(g->obj), pixbuf);
95 #endif 104 #endif
105 gtk_widget_set_size_request(g->obj, width, height);
96 } 106 }
97 107
98 108
99 return 0; 109 return 0;
100 } 110 }

mercurial