1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 3 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "widgets-types.h"
24
#include "gimpdeviceinfo.h"
25
#include "gimpdeviceinfo-coords.h"
28
static const GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;
31
/* public functions */
34
gimp_device_info_get_event_coords (GimpDeviceInfo *info,
36
const GdkEvent *event,
41
if (gdk_event_get_axis (event, GDK_AXIS_X, &x))
43
*coords = default_coords;
46
gdk_event_get_axis (event, GDK_AXIS_Y, &coords->y);
48
/* translate event coordinates to window coordinates, only
49
* happens if we drag a guide from a ruler
51
if (event->any.window &&
52
event->any.window != window)
54
GtkWidget *src_widget;
55
GtkWidget *dest_widget;
57
src_widget = gtk_get_event_widget ((GdkEvent *) event);
58
gdk_window_get_user_data (window, (gpointer) &dest_widget);
60
if (src_widget && dest_widget)
65
gtk_widget_translate_coordinates (src_widget, dest_widget,
66
0, 0, &offset_x, &offset_y);
68
coords->x += offset_x;
69
coords->y += offset_y;
73
if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &coords->pressure))
75
coords->pressure = gimp_device_info_map_axis (info,
80
if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &coords->xtilt))
82
coords->xtilt = gimp_device_info_map_axis (info,
87
if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &coords->ytilt))
89
coords->ytilt = gimp_device_info_map_axis (info,
94
if (gdk_event_get_axis (event, GDK_AXIS_WHEEL, &coords->wheel))
96
coords->wheel = gimp_device_info_map_axis (info,
104
gimp_device_info_get_device_coords (info, window, coords);
110
gimp_device_info_get_device_coords (GimpDeviceInfo *info,
114
gdouble axes[GDK_AXIS_LAST];
116
*coords = default_coords;
118
gdk_device_get_state (info->device, window, axes, NULL);
120
gdk_device_get_axis (info->device, axes, GDK_AXIS_X, &coords->x);
121
gdk_device_get_axis (info->device, axes, GDK_AXIS_Y, &coords->y);
123
if (gdk_device_get_axis (info->device,
124
axes, GDK_AXIS_PRESSURE, &coords->pressure))
126
coords->pressure = gimp_device_info_map_axis (info,
131
if (gdk_device_get_axis (info->device,
132
axes, GDK_AXIS_XTILT, &coords->xtilt))
134
coords->xtilt = gimp_device_info_map_axis (info,
139
if (gdk_device_get_axis (info->device,
140
axes, GDK_AXIS_YTILT, &coords->ytilt))
142
coords->ytilt = gimp_device_info_map_axis (info,
147
if (gdk_device_get_axis (info->device,
148
axes, GDK_AXIS_WHEEL, &coords->wheel))
150
coords->wheel = gimp_device_info_map_axis (info,
157
gimp_device_info_get_time_coords (GimpDeviceInfo *info,
161
*coords = default_coords;
163
gdk_device_get_axis (info->device, event->axes, GDK_AXIS_X, &coords->x);
164
gdk_device_get_axis (info->device, event->axes, GDK_AXIS_Y, &coords->y);
166
/* CLAMP() the return value of each *_get_axis() call to be safe
167
* against buggy XInput drivers.
170
if (gdk_device_get_axis (info->device,
171
event->axes, GDK_AXIS_PRESSURE, &coords->pressure))
173
coords->pressure = gimp_device_info_map_axis (info,
178
if (gdk_device_get_axis (info->device,
179
event->axes, GDK_AXIS_XTILT, &coords->xtilt))
181
coords->xtilt = gimp_device_info_map_axis (info,
186
if (gdk_device_get_axis (info->device,
187
event->axes, GDK_AXIS_YTILT, &coords->ytilt))
189
coords->ytilt = gimp_device_info_map_axis (info,
194
if (gdk_device_get_axis (info->device,
195
event->axes, GDK_AXIS_WHEEL, &coords->wheel))
197
coords->wheel = gimp_device_info_map_axis (info,
204
gimp_device_info_get_event_state (GimpDeviceInfo *info,
206
const GdkEvent *event,
207
GdkModifierType *state)
209
if (gdk_event_get_state (event, state))
212
gimp_device_info_get_device_state (info, window, state);
218
gimp_device_info_get_device_state (GimpDeviceInfo *info,
220
GdkModifierType *state)
222
gdk_device_get_state (info->device, window, NULL, state);