~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to app/widgets/gimpdeviceinfo-coords.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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/>.
 
16
 */
 
17
 
 
18
#include "config.h"
 
19
 
 
20
#include <gtk/gtk.h>
 
21
 
 
22
#include "widgets-types.h"
 
23
 
 
24
#include "gimpdeviceinfo.h"
 
25
#include "gimpdeviceinfo-coords.h"
 
26
 
 
27
 
 
28
static const GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;
 
29
 
 
30
 
 
31
/*  public functions  */
 
32
 
 
33
gboolean
 
34
gimp_device_info_get_event_coords (GimpDeviceInfo *info,
 
35
                                   GdkWindow      *window,
 
36
                                   const GdkEvent *event,
 
37
                                   GimpCoords     *coords)
 
38
{
 
39
  gdouble x;
 
40
 
 
41
  if (gdk_event_get_axis (event, GDK_AXIS_X, &x))
 
42
    {
 
43
      *coords = default_coords;
 
44
 
 
45
      coords->x = x;
 
46
      gdk_event_get_axis (event, GDK_AXIS_Y, &coords->y);
 
47
 
 
48
      /* translate event coordinates to window coordinates, only
 
49
       * happens if we drag a guide from a ruler
 
50
       */
 
51
      if (event->any.window &&
 
52
          event->any.window != window)
 
53
        {
 
54
          GtkWidget *src_widget;
 
55
          GtkWidget *dest_widget;
 
56
 
 
57
          src_widget = gtk_get_event_widget ((GdkEvent *) event);
 
58
          gdk_window_get_user_data (window, (gpointer) &dest_widget);
 
59
 
 
60
          if (src_widget && dest_widget)
 
61
            {
 
62
              gint offset_x;
 
63
              gint offset_y;
 
64
 
 
65
              gtk_widget_translate_coordinates (src_widget, dest_widget,
 
66
                                                0, 0, &offset_x, &offset_y);
 
67
 
 
68
              coords->x += offset_x;
 
69
              coords->y += offset_y;
 
70
            }
 
71
        }
 
72
 
 
73
      if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &coords->pressure))
 
74
        {
 
75
          coords->pressure = gimp_device_info_map_axis (info,
 
76
                                                        GDK_AXIS_PRESSURE,
 
77
                                                        coords->pressure);
 
78
        }
 
79
 
 
80
      if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &coords->xtilt))
 
81
        {
 
82
          coords->xtilt = gimp_device_info_map_axis (info,
 
83
                                                     GDK_AXIS_XTILT,
 
84
                                                     coords->xtilt);
 
85
        }
 
86
 
 
87
      if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &coords->ytilt))
 
88
        {
 
89
          coords->ytilt = gimp_device_info_map_axis (info,
 
90
                                                     GDK_AXIS_YTILT,
 
91
                                                     coords->ytilt);
 
92
        }
 
93
 
 
94
      if (gdk_event_get_axis (event, GDK_AXIS_WHEEL, &coords->wheel))
 
95
        {
 
96
          coords->wheel = gimp_device_info_map_axis (info,
 
97
                                                     GDK_AXIS_WHEEL,
 
98
                                                     coords->wheel);
 
99
        }
 
100
 
 
101
      return TRUE;
 
102
    }
 
103
 
 
104
  gimp_device_info_get_device_coords (info, window, coords);
 
105
 
 
106
  return FALSE;
 
107
}
 
108
 
 
109
void
 
110
gimp_device_info_get_device_coords (GimpDeviceInfo *info,
 
111
                                    GdkWindow      *window,
 
112
                                    GimpCoords     *coords)
 
113
{
 
114
  gdouble axes[GDK_AXIS_LAST];
 
115
 
 
116
  *coords = default_coords;
 
117
 
 
118
  gdk_device_get_state (info->device, window, axes, NULL);
 
119
 
 
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);
 
122
 
 
123
  if (gdk_device_get_axis (info->device,
 
124
                           axes, GDK_AXIS_PRESSURE, &coords->pressure))
 
125
    {
 
126
      coords->pressure = gimp_device_info_map_axis (info,
 
127
                                                    GDK_AXIS_PRESSURE,
 
128
                                                    coords->pressure);
 
129
    }
 
130
 
 
131
  if (gdk_device_get_axis (info->device,
 
132
                           axes, GDK_AXIS_XTILT, &coords->xtilt))
 
133
    {
 
134
      coords->xtilt = gimp_device_info_map_axis (info,
 
135
                                                 GDK_AXIS_XTILT,
 
136
                                                 coords->xtilt);
 
137
    }
 
138
 
 
139
  if (gdk_device_get_axis (info->device,
 
140
                           axes, GDK_AXIS_YTILT, &coords->ytilt))
 
141
    {
 
142
      coords->ytilt = gimp_device_info_map_axis (info,
 
143
                                                 GDK_AXIS_YTILT,
 
144
                                                 coords->ytilt);
 
145
    }
 
146
 
 
147
  if (gdk_device_get_axis (info->device,
 
148
                           axes, GDK_AXIS_WHEEL, &coords->wheel))
 
149
    {
 
150
      coords->wheel = gimp_device_info_map_axis (info,
 
151
                                                 GDK_AXIS_WHEEL,
 
152
                                                 coords->wheel);
 
153
    }
 
154
}
 
155
 
 
156
void
 
157
gimp_device_info_get_time_coords (GimpDeviceInfo *info,
 
158
                                  GdkTimeCoord   *event,
 
159
                                  GimpCoords     *coords)
 
160
{
 
161
  *coords = default_coords;
 
162
 
 
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);
 
165
 
 
166
  /*  CLAMP() the return value of each *_get_axis() call to be safe
 
167
   *  against buggy XInput drivers.
 
168
   */
 
169
 
 
170
  if (gdk_device_get_axis (info->device,
 
171
                           event->axes, GDK_AXIS_PRESSURE, &coords->pressure))
 
172
    {
 
173
      coords->pressure = gimp_device_info_map_axis (info,
 
174
                                                    GDK_AXIS_PRESSURE,
 
175
                                                    coords->pressure);
 
176
    }
 
177
 
 
178
  if (gdk_device_get_axis (info->device,
 
179
                           event->axes, GDK_AXIS_XTILT, &coords->xtilt))
 
180
    {
 
181
      coords->xtilt = gimp_device_info_map_axis (info,
 
182
                                                 GDK_AXIS_XTILT,
 
183
                                                 coords->xtilt);
 
184
    }
 
185
 
 
186
  if (gdk_device_get_axis (info->device,
 
187
                           event->axes, GDK_AXIS_YTILT, &coords->ytilt))
 
188
    {
 
189
      coords->ytilt = gimp_device_info_map_axis (info,
 
190
                                                 GDK_AXIS_YTILT,
 
191
                                                 coords->ytilt);
 
192
    }
 
193
 
 
194
  if (gdk_device_get_axis (info->device,
 
195
                           event->axes, GDK_AXIS_WHEEL, &coords->wheel))
 
196
    {
 
197
      coords->wheel = gimp_device_info_map_axis (info,
 
198
                                                 GDK_AXIS_WHEEL,
 
199
                                                 coords->wheel);
 
200
    }
 
201
}
 
202
 
 
203
gboolean
 
204
gimp_device_info_get_event_state (GimpDeviceInfo  *info,
 
205
                                  GdkWindow       *window,
 
206
                                  const GdkEvent  *event,
 
207
                                  GdkModifierType *state)
 
208
{
 
209
  if (gdk_event_get_state (event, state))
 
210
    return TRUE;
 
211
 
 
212
  gimp_device_info_get_device_state (info, window, state);
 
213
 
 
214
  return FALSE;
 
215
}
 
216
 
 
217
void
 
218
gimp_device_info_get_device_state (GimpDeviceInfo  *info,
 
219
                                   GdkWindow       *window,
 
220
                                   GdkModifierType *state)
 
221
{
 
222
  gdk_device_get_state (info->device, window, NULL, state);
 
223
}