ui/gtk/image.c

Wed, 02 Sep 2026 16:57:28 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 02 Sep 2026 16:57:28 +0200
changeset 1240
3e2516e7a957
parent 1238
a40c1ec7883d
permissions
-rw-r--r--

add support for actions in imageviewer events (GTK)

339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "image.h"
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "container.h"
389
d15eca5fd8b3 implement image viewer context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
32 #include "menu.h"
962
7016bcb8d38b add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 961
diff changeset
33 #include "widget.h"
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/context.h"
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/object.h"
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
36 #include "../common/action.h"
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
38 static void imageviewer_destroy(UiImageViewer *iv) {
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
39 if(iv->pixbuf) {
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
40 g_object_unref(iv->pixbuf);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
41 }
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
42 free(iv->onbuttonpress_action);
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
43 free(iv->onbuttonrelease_action);
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
44 free(iv);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
45 }
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
46
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
47 #if GTK_MAJOR_VERSION >= 4
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
48
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
49 static void imageviewer_draw(
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
50 GtkDrawingArea *drawingarea,
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
51 cairo_t *cr,
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
52 int width,
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
53 int height,
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
54 gpointer userdata)
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
55 {
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
56 ui_cairo_draw_image(userdata, cr, width, height);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
57 }
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
58
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
59 #else
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
60
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
61 static gboolean imageviewer_draw(GtkWidget *widget, cairo_t *cr, gpointer userdata) {
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
62 int width = gtk_widget_get_allocated_width(widget);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
63 int height = gtk_widget_get_allocated_height(widget);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
64 ui_cairo_draw_image(userdata, cr, width, height);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
65 return FALSE;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
66 }
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
67
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
68 #endif
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
70 UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs *args) {
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
71 GtkWidget *drawingarea = gtk_drawing_area_new();
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
72 GtkWidget *toplevel;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
73 GtkWidget *widget = drawingarea;
961
687f43736aef add width/height to UiImageViewerArgs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 801
diff changeset
74
962
7016bcb8d38b add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 961
diff changeset
75 int width = args->width;
7016bcb8d38b add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 961
diff changeset
76 int height = args->height;
7016bcb8d38b add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 961
diff changeset
77 if(width == 0 && height == 0) {
7016bcb8d38b add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 961
diff changeset
78 width = 100;
7016bcb8d38b add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 961
diff changeset
79 height = 100;
961
687f43736aef add width/height to UiImageViewerArgs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 801
diff changeset
80 }
962
7016bcb8d38b add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 961
diff changeset
81 ui_widget_size_request(drawingarea, width, height);
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 #if GTK_MAJOR_VERSION < 4
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 GtkWidget *eventbox = gtk_event_box_new();
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
85 gtk_container_add(GTK_CONTAINER(eventbox), drawingarea);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
86 widget = eventbox;
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 #endif
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
89 if(args->scrollarea) {
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
90 toplevel = SCROLLEDWINDOW_NEW();
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
91 SCROLLEDWINDOW_SET_CHILD(toplevel, widget);
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
92 args->adjustwidgetsize = TRUE;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
93 } else {
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
94 toplevel = widget;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
95 }
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
96
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
97 UiImageViewer *imgviewer = malloc(sizeof(UiImageViewer));
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
98 memset(imgviewer, 0, sizeof(UiImageViewer));
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
99 imgviewer->obj = obj;
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
100 imgviewer->onbuttonpress = args->onbuttonpress;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
101 imgviewer->onbuttonpressdata = args->onbuttonpressdata;
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
102 imgviewer->onbuttonpress_action = args->onbuttonpress_action ? strdup(args->onbuttonpress_action) : NULL;
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
103 imgviewer->onbuttonrelease = args->onbuttonrelease;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
104 imgviewer->onbuttonreleasedata = args->onbuttonreleasedata;
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
105 imgviewer->onbuttonrelease_action = args->onbuttonrelease_action ? strdup(args->onbuttonrelease_action) : NULL;
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
106 if(args->image_padding > 0) {
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
107 imgviewer->padding_left = args->image_padding;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
108 imgviewer->padding_right = args->image_padding;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
109 imgviewer->padding_top = args->image_padding;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
110 imgviewer->padding_bottom = args->image_padding;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
111 } else {
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
112 imgviewer->padding_left = args->image_padding_left;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
113 imgviewer->padding_right = args->image_padding_right;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
114 imgviewer->padding_top = args->image_padding_top;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
115 imgviewer->padding_bottom = args->image_padding_bottom;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
116 }
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
117 imgviewer->adjustwidgetsize = args->adjustwidgetsize;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
118 imgviewer->autoscale = args->autoscale;
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
119 imgviewer->useradjustable = args->useradjustable;
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
120 imgviewer->zoom_scale = 20;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
121
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
122 g_object_set_data_full(G_OBJECT(drawingarea), "uiimageviewer", imgviewer, (GDestroyNotify)imageviewer_destroy);
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
801
e096c441e874 refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 669
diff changeset
124 UiVar *var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_GENERIC);
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
125 imgviewer->var = var;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
126 imgviewer->widget = drawingarea;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
127
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 if(var) {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 UiGeneric *value = var->value;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 value->get = ui_imageviewer_get;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 value->get_type = ui_imageviewer_get_type;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 value->set = ui_imageviewer_set;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
133 value->obj = imgviewer;
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 if(value->value && value->type && !strcmp(value->type, UI_IMAGE_OBJECT_TYPE)) {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 GdkPixbuf *pixbuf = value->value;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 value->value = NULL;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 ui_imageviewer_set(value, pixbuf, UI_IMAGE_OBJECT_TYPE);
548
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
138 g_object_unref(pixbuf);
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
142 #if GTK_MAJOR_VERSION >= 4
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
143 gtk_drawing_area_set_draw_func(
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
144 GTK_DRAWING_AREA(drawingarea),
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
145 imageviewer_draw,
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
146 imgviewer,
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
147 NULL);
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
148
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
149 if(args->useradjustable) {
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
150 gtk_widget_set_focusable(drawingarea, TRUE);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
151 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
152
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
153 GtkEventController *scrollcontroller = gtk_event_controller_scroll_new(GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
154 g_signal_connect(scrollcontroller, "scroll", G_CALLBACK(ui_imageviewer_scroll), imgviewer);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
155 gtk_widget_add_controller(GTK_WIDGET(drawingarea), GTK_EVENT_CONTROLLER(scrollcontroller));
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
156
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
157 GtkGesture *drag = gtk_gesture_drag_new();
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
158 g_signal_connect(drag, "drag-begin", G_CALLBACK(ui_imageviewer_drag_begin_cb), imgviewer);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
159 g_signal_connect(drag, "drag-end", G_CALLBACK(ui_imageviewer_drag_end_cb), imgviewer);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
160 g_signal_connect(drag, "drag-update", G_CALLBACK(ui_imageviewer_drag_update_cb), imgviewer);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
161 gtk_widget_add_controller(GTK_WIDGET(drawingarea), GTK_EVENT_CONTROLLER(drag));
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
162
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
163 GtkGesture *click = gtk_gesture_click_new();
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
164 g_signal_connect(click, "pressed", G_CALLBACK(ui_imageviewer_pressed_cb), imgviewer);
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
165 g_signal_connect(click, "released", G_CALLBACK(ui_imageviewer_released_cb), imgviewer);
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
166 gtk_widget_add_controller(GTK_WIDGET(drawingarea), GTK_EVENT_CONTROLLER(click));
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
167
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
168 #elif GTK_MAJOR_VERSION == 3
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
169 g_signal_connect(
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
170 drawingarea,
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
171 "draw",
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
172 G_CALLBACK(imageviewer_draw),
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
173 imgviewer);
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
174
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
175 gtk_widget_add_events(eventbox, GDK_SCROLL_MASK);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
176
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
177 g_signal_connect(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
178 eventbox,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
179 "scroll-event",
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
180 G_CALLBACK(ui_imageviewer_scroll_event),
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
181 imgviewer);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
182 g_signal_connect(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
183 eventbox,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
184 "button-press-event",
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
185 G_CALLBACK(ui_imageviewer_button_press_event),
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
186 imgviewer);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
187 g_signal_connect(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
188 eventbox,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
189 "button-release-event",
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
190 G_CALLBACK(ui_imageviewer_button_release_event),
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
191 imgviewer);
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
192
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
193 #endif
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
194
594
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
195 if(args->contextmenu) {
fc854e0ab924 pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
196 UIMENU menu = ui_contextmenu_create(args->contextmenu, obj, widget);
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
197 ui_widget_set_contextmenu(widget, menu);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
198 }
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
199
801
e096c441e874 refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 669
diff changeset
200 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end;
e096c441e874 refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 669
diff changeset
201 UiLayout layout = UI_ARGS2LAYOUT(args);
e096c441e874 refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 669
diff changeset
202 ct->add(ct, toplevel, &layout);
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
203
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
204 return toplevel;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
205 }
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
206
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
207 static void imageviewer_reset(UiImageViewer *imgviewer) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
208 imgviewer->isautoscaled = FALSE;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
209 imgviewer->transx = 0;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
210 imgviewer->transy;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
211 imgviewer->begin_transx = 0;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
212 imgviewer->begin_transy = 0;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
213 imgviewer->scale = 1;
533
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
214 imgviewer->user_scale = 1;
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
215 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
216
1222
163146220e94 fix return type of imageviewer functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 962
diff changeset
217 void ui_imageviewer_reset(UIWIDGET w) {
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
218 UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer");
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
219 if(imgviewer) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
220 imageviewer_reset(imgviewer);
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
221 gtk_widget_queue_draw(w);
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
222 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
223 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
224
1222
163146220e94 fix return type of imageviewer functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 962
diff changeset
225 void ui_imageviewer_set_autoscale(UIWIDGET w, UiBool set) {
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
226 UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer");
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
227 if(imgviewer) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
228 imgviewer->autoscale = set;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
229 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
230 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
231
1222
163146220e94 fix return type of imageviewer functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 962
diff changeset
232 void ui_imageviewer_set_adjustwidgetsize(UIWIDGET w, UiBool set) {
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
233 UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer");
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
234 if(imgviewer) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
235 imgviewer->adjustwidgetsize = set;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
236 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
237 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
238
1222
163146220e94 fix return type of imageviewer functions (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 962
diff changeset
239 void ui_imageviewer_set_useradjustable(UIWIDGET w, UiBool set) {
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
240 UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer");
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
241 if(imgviewer) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
242 imgviewer->useradjustable = set;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
243 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
244 }
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
245
1238
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
246 static void imageviewer_set(UiImageViewer *imgviewer, GdkPixbuf *pixbuf) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
247 if(imgviewer->pixbuf) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
248 g_object_unref(imgviewer->pixbuf);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
249 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
250
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
251 g_object_ref(pixbuf);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
252 imgviewer->pixbuf = pixbuf;
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
253
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
254 imageviewer_reset(imgviewer);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
255 if(imgviewer->adjustwidgetsize && !imgviewer->autoscale) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
256 int width = gdk_pixbuf_get_width(pixbuf);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
257 int height = gdk_pixbuf_get_height(pixbuf);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
258 gtk_widget_set_size_request(imgviewer->widget, width, height);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
259 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
260 gtk_widget_queue_draw(imgviewer->widget);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
261 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
262
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
263 void ui_imageviewer_load_file(UIWIDGET w, const char *path) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
264 UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer");
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
265 if(imgviewer) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
266 GError *error = NULL;
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
267 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &error);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
268 if(pixbuf) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
269 imageviewer_set(imgviewer, pixbuf);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
270 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
271 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
272 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
273
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
274 void ui_imageviewer_load_data(UIWIDGET w, const void *imgdata, size_t size) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
275 UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer");
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
276 if(imgviewer) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
277 GBytes *bytes = g_bytes_new_static(imgdata, size);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
278 GInputStream *in = g_memory_input_stream_new_from_bytes(bytes);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
279 GError *error = NULL;
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
280 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream(in, NULL, &error);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
281 g_object_unref(in);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
282 if(pixbuf) {
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
283 imageviewer_set(imgviewer, pixbuf);
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
284 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
285 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
286 }
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
287
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
288 void ui_cairo_draw_image(UiImageViewer *imgviewer, cairo_t *cr, int width, int height) {
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
289 if(!imgviewer->pixbuf) {
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
290 return;
389
d15eca5fd8b3 implement image viewer context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
291 }
d15eca5fd8b3 implement image viewer context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
292
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
293 GdkPixbuf *pixbuf = imgviewer->pixbuf;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
294 double dpixwidth = (double)gdk_pixbuf_get_width(pixbuf);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
295 double dpixheight = (double)gdk_pixbuf_get_height(pixbuf);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
296
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
297 double dwidth = width;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
298 double dheight = height;
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
299 double scale = 1;
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
300 // if autoscale is enabled, scale the image to fill available space
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
301 // if useradjustable is also enabled, the autoscaling is only done once
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
302 if(imgviewer->autoscale && imgviewer->scale != 0) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
303 if(!imgviewer->isautoscaled) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
304 scale = dwidth / dpixwidth;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
305 if(dpixheight * scale > dheight) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
306 scale = dheight / dpixheight;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
307 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
308
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
309 if(imgviewer->useradjustable) {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
310 imgviewer->isautoscaled = TRUE;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
311 }
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
312
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
313 imgviewer->scale = scale;
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
314 } else {
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
315 scale = imgviewer->scale;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
316 }
533
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
317
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
318 imgviewer->user_scale = scale;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
319 } else {
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
320 // user-adjusted scaling
533
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
321 //scale = 1 + ((double)imgviewer->zoom / (double)imgviewer->zoom_scale);
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
322 scale = imgviewer->user_scale;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
323 }
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
324
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
325 dpixwidth *= scale;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
326 dpixheight *= scale;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
327 double x = (dwidth - dpixwidth) / 2;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
328 double y = (dheight - dpixheight) / 2;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
329
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
330 x += imgviewer->transx;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
331 y += imgviewer->transy;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
332
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
333 cairo_translate(cr, x, y);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
334 cairo_scale(cr, scale, scale);
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
335
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
336 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
337 cairo_paint(cr);
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 void* ui_imageviewer_get(UiGeneric *g) {
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
341 UiImageViewer *imgviewer = g->obj;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
342 g->value = imgviewer->pixbuf;
340
2dd42bd4fe5d add imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
343 return g->value;
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 const char* ui_imageviewer_get_type(UiGeneric *g) {
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
347 return UI_IMAGE_OBJECT_TYPE;
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 int ui_imageviewer_set(UiGeneric *g, void *value, const char *type) {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 if(!type || strcmp(type, UI_IMAGE_OBJECT_TYPE)) {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 return 1;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 GdkPixbuf *pixbuf = value;
529
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
356 UiImageViewer *imgviewer = g->obj;
0a4a6b0d1c82 add new imageviewer implementation (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
357 g->value = pixbuf;
1238
a40c1ec7883d add ui_imageviewer_load_file/ui_imageviewer_load_data
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1222
diff changeset
358 imageviewer_set(imgviewer, pixbuf);
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 return 0;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 int ui_image_load_file(UiGeneric *obj, const char *path) {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 GError *error = NULL;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &error);
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 if(!pixbuf) {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 return 1;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 }
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 if(obj->set) {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 obj->set(obj, pixbuf, UI_IMAGE_OBJECT_TYPE);
548
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
374 g_object_unref(pixbuf);
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 } else {
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 obj->value = pixbuf;
578
950d2e38957b fix ui_image_load_* functions would not set the type to UI_IMAGE_OBJECT_TYPE in case UiGeneric is not bound to an widget
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 565
diff changeset
377 obj->type = UI_IMAGE_OBJECT_TYPE;
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 }
548
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
379
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 return 0;
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 }
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
382
563
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
383 UIEXPORT int ui_image_load_data(UiGeneric *obj, const void *imgdata, size_t size) {
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
384 GBytes *bytes = g_bytes_new_static(imgdata, size);
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
385 GInputStream *in = g_memory_input_stream_new_from_bytes(bytes);
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
386 GError *error = NULL;
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
387 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream(in, NULL, &error);
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
388 g_object_unref(in);
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
389 if(!pixbuf) {
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
390 return 1;
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
391 }
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
392
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
393 if(obj->set) {
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
394 obj->set(obj, pixbuf, UI_IMAGE_OBJECT_TYPE);
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
395 g_object_unref(pixbuf);
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
396 } else {
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
397 obj->value = pixbuf;
578
950d2e38957b fix ui_image_load_* functions would not set the type to UI_IMAGE_OBJECT_TYPE in case UiGeneric is not bound to an widget
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 565
diff changeset
398 obj->type = UI_IMAGE_OBJECT_TYPE;
563
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
399 }
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
400
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
401 return 0;
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
402 }
6fc93c3b91c9 add ui_image_load_data (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
403
548
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
404 void ui_image_ref(UIIMAGE img) {
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
405 g_object_ref(img);
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
406 }
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
407
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
408 void ui_image_unref(UIIMAGE img) {
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
409 g_object_unref(img);
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
410 }
198756ab2845 add UIIMAGE type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
411
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
412 #if GTK_MAJOR_VERSION >= 4
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
413
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
414 gboolean ui_imageviewer_scroll(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
415 GtkEventControllerScroll *widget,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
416 gdouble dx,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
417 gdouble dy,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
418 gpointer userdata)
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
419 {
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
420 UiImageViewer *imgviewer = userdata;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
421 if(imgviewer->useradjustable) {
533
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
422 double step = dy / imgviewer->zoom_scale;
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
423 if(imgviewer->user_scale - step > 0) {
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
424 imgviewer->user_scale -= step;
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
425 }
533
951b92ce3708 replace imageviewer integer zoom with fp userscale setting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
426
532
80a6d8923d75 allow autoscale + useradjustable in imageviewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
427 imgviewer->scale = 0; // disable autoscale
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
428 gtk_widget_queue_draw(imgviewer->widget);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
429 return TRUE;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
430 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
431 return FALSE;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
432 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
433
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
434 void ui_imageviewer_drag_begin_cb(
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
435 GtkGestureDrag *self,
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
436 gdouble start_x,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
437 gdouble start_y,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
438 gpointer userdata)
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
439 {
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
440 UiImageViewer *imgviewer = userdata;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
441 imgviewer->begin_transx = imgviewer->transx;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
442 imgviewer->begin_transy = imgviewer->transy;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
443 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
444
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
445 void ui_imageviewer_drag_end_cb(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
446 GtkGestureDrag* self,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
447 gdouble x,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
448 gdouble y,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
449 gpointer userdata)
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
450 {
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
451
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
452 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
453
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
454 void ui_imageviewer_drag_update_cb(
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
455 GtkGestureDrag *self,
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
456 gdouble x,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
457 gdouble y,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
458 gpointer userdata)
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
459 {
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
460 UiImageViewer *imgviewer = userdata;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
461 if(imgviewer->useradjustable) {
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
462 imgviewer->transx = imgviewer->begin_transx + x;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
463 imgviewer->transy = imgviewer->begin_transy + y;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
464 gtk_widget_queue_draw(imgviewer->widget);
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
465 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
466 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
467
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
468 static void imgviewer_button_event(
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
469 GtkGestureClick *gesture,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
470 UiImageViewer *imgviewer,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
471 ui_callback callback,
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
472 void *userdata,
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
473 const char *action)
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
474 {
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
475 UiEvent event;
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
476 event.obj = imgviewer->obj;
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
477 event.window = event.obj->window;
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
478 event.document = event.obj->ctx->document;
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
479 event.eventdata = NULL;
659
d6baaa93f7be add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 594
diff changeset
480 event.eventdatatype = 0;
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
481 event.intval = gtk_gesture_single_get_current_button(GTK_GESTURE_SINGLE(gesture));
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
482 event.set = 0;
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
483
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
484 if(callback) {
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
485 callback(&event, userdata);
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
486 }
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
487 if(action) {
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
488 uic_action_callback(&event, action);
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
489 }
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
490 }
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
491
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
492 void ui_imageviewer_pressed_cb(
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
493 GtkGestureClick *self,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
494 gint n_press,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
495 gdouble x,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
496 gdouble y,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
497 gpointer userdata)
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
498 {
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
499 UiImageViewer *imgviewer = userdata;
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
500 imgviewer_button_event(self, imgviewer, imgviewer->onbuttonpress, imgviewer->onbuttonpressdata, imgviewer->onbuttonpress_action);
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
501 }
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
502
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
503 void ui_imageviewer_released_cb(
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
504 GtkGestureClick *self,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
505 gint n_press,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
506 gdouble x,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
507 gdouble y,
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
508 gpointer userdata)
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
509 {
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
510 UiImageViewer *imgviewer = userdata;
1240
3e2516e7a957 add support for actions in imageviewer events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1238
diff changeset
511 imgviewer_button_event(self, imgviewer, imgviewer->onbuttonrelease, imgviewer->onbuttonreleasedata, imgviewer->onbuttonrelease_action);
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
512 }
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
513
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
514 #else
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
515
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
516 gboolean ui_imageviewer_scroll_event(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
517 GtkWidget *widget,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
518 GdkEventScroll event,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
519 gpointer userdata)
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
520 {
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
521 // TODO
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
522 return FALSE;
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
523 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
524
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
525 gboolean ui_imageviewer_button_press_event(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
526 GtkWidget *widget,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
527 GdkEventButton event,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
528 gpointer userdata)
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
529 {
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
530 // TODO
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
531 return FALSE;
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
532 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
533
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
534 gboolean ui_imageviewer_button_release_event(
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
535 GtkWidget *widget,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
536 GdkEventButton event,
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
537 gpointer userdata)
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
538 {
547
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
539 // TODO
631162b266d1 add imgviewer button press/release callbacks (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
540 return FALSE;
530
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
541 }
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
542
7992a44fe719 implement imageviewer useradjustable setting in gtk4 implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
543 #endif

mercurial