1/* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "config.h"
19
20#include <math.h>
21
22#include "gdkdevicetoolprivate.h"
23#include "gdkinternals.h"
24#include "gdkintl.h"
25
26
27G_DEFINE_TYPE (GdkDeviceTool, gdk_device_tool, G_TYPE_OBJECT)
28
29enum {
30 TOOL_PROP_0,
31 TOOL_PROP_SERIAL,
32 TOOL_PROP_TOOL_TYPE,
33 TOOL_PROP_AXES,
34 N_TOOL_PROPS
35};
36
37GParamSpec *tool_props[N_TOOL_PROPS] = { 0 };
38
39static void
40gdk_device_tool_set_property (GObject *object,
41 guint prop_id,
42 const GValue *value,
43 GParamSpec *pspec)
44{
45 GdkDeviceTool *tool = GDK_DEVICE_TOOL (object);
46
47 switch (prop_id)
48 {
49 case TOOL_PROP_SERIAL:
50 tool->serial = g_value_get_uint64 (value);
51 break;
52 case TOOL_PROP_TOOL_TYPE:
53 tool->type = g_value_get_enum (value);
54 break;
55 case TOOL_PROP_AXES:
56 tool->tool_axes = g_value_get_flags (value);
57 break;
58 default:
59 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
60 break;
61 }
62}
63
64static void
65gdk_device_tool_get_property (GObject *object,
66 guint prop_id,
67 GValue *value,
68 GParamSpec *pspec)
69{
70 GdkDeviceTool *tool = GDK_DEVICE_TOOL (object);
71
72 switch (prop_id)
73 {
74 case TOOL_PROP_SERIAL:
75 g_value_set_uint64 (value, tool->serial);
76 break;
77 case TOOL_PROP_TOOL_TYPE:
78 g_value_set_enum (value, tool->type);
79 break;
80 case TOOL_PROP_AXES:
81 g_value_set_flags (value, tool->tool_axes);
82 break;
83 default:
84 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
85 break;
86 }
87}
88
89static void
90gdk_device_tool_class_init (GdkDeviceToolClass *klass)
91{
92 GObjectClass *object_class = G_OBJECT_CLASS (klass);
93
94 object_class->set_property = gdk_device_tool_set_property;
95 object_class->get_property = gdk_device_tool_get_property;
96
97 tool_props[TOOL_PROP_SERIAL] = g_param_spec_uint64 ("serial",
98 "Serial",
99 "Serial number",
100 0, G_MAXUINT64, 0,
101 G_PARAM_READWRITE |
102 G_PARAM_CONSTRUCT_ONLY);
103 tool_props[TOOL_PROP_TOOL_TYPE] = g_param_spec_enum ("tool-type",
104 "Tool type",
105 "Tool type",
106 GDK_TYPE_DEVICE_TOOL_TYPE,
107 GDK_DEVICE_TOOL_TYPE_UNKNOWN,
108 G_PARAM_READWRITE |
109 G_PARAM_CONSTRUCT_ONLY);
110 tool_props[TOOL_PROP_AXES] = g_param_spec_flags ("axes",
111 "Axes",
112 "Tool axes",
113 GDK_TYPE_AXIS_FLAGS, 0,
114 G_PARAM_READWRITE |
115 G_PARAM_CONSTRUCT_ONLY);
116
117 g_object_class_install_properties (object_class, N_TOOL_PROPS, tool_props);
118}
119
120static void
121gdk_device_tool_init (GdkDeviceTool *tool)
122{
123}
124
125GdkDeviceTool *
126gdk_device_tool_new (guint64 serial,
127 GdkDeviceToolType type,
128 GdkAxisFlags tool_axes)
129{
130 return g_object_new (GDK_TYPE_DEVICE_TOOL,
131 "serial", serial,
132 "tool-type", type,
133 "axes", tool_axes,
134 NULL);
135}
136
137/**
138 * gdk_device_tool_get_serial:
139 * @tool: a #GdkDeviceTool
140 *
141 * Gets the serial of this tool, this value can be used to identify a
142 * physical tool (eg. a tablet pen) across program executions.
143 *
144 * Returns: The serial ID for this tool
145 *
146 * Since: 3.22
147 **/
148guint
149gdk_device_tool_get_serial (GdkDeviceTool *tool)
150{
151 g_return_val_if_fail (tool != NULL, 0);
152
153 return tool->serial;
154}
155
156/**
157 * gdk_device_tool_get_tool_type:
158 * @tool: a #GdkDeviceTool
159 *
160 * Gets the #GdkDeviceToolType of the tool.
161 *
162 * Returns: The physical type for this tool. This can be used to figure out what
163 * sort of pen is being used, such as an airbrush or a pencil.
164 *
165 * Since: 3.22
166 **/
167GdkDeviceToolType
168gdk_device_tool_get_tool_type (GdkDeviceTool *tool)
169{
170 g_return_val_if_fail (tool != NULL, GDK_DEVICE_TOOL_TYPE_UNKNOWN);
171
172 return tool->type;
173}
174