~chasedouglas/frame/ubuntu-upstream-xi

« back to all changes in this revision

Viewing changes to src/v2/touch.cpp

  • Committer: Chase Douglas
  • Date: 2011-12-09 01:36:45 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: chase.douglas@ubuntu.com-20111209013645-n24l4myiumblzsfu
* New upstream release.
  - Version 2 adds a new API built on top of XInput multitouch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *
 
3
 * utouch-frame - Touch Frame Library
 
4
 *
 
5
 * Copyright (C) 2011 Canonical Ltd.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the
 
9
 * Free Software Foundation, either version 3 of the License, or (at your
 
10
 * option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along
 
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 ****************************************************************************/
 
21
 
 
22
#include "v2/touch.h"
 
23
 
 
24
#include <assert.h>
 
25
 
 
26
#include "v2/frame.h"
 
27
 
 
28
namespace utouch {
 
29
namespace frame {
 
30
 
 
31
UFTouch::UFTouch(UFTouchState state, UFTouchId id, float x, float y,
 
32
                 uint64_t time)
 
33
    : id_(id),
 
34
      state_(state) {
 
35
  const Value* value;
 
36
 
 
37
  value = new Value(state);
 
38
  InsertProperty(UFTouchPropertyState, value);
 
39
 
 
40
  value = new Value(id);
 
41
  InsertProperty(UFTouchPropertyId, value);
 
42
 
 
43
  value = new Value(x);
 
44
  InsertProperty(UFTouchPropertyWindowX, value);
 
45
 
 
46
  value = new Value(y);
 
47
  InsertProperty(UFTouchPropertyWindowY, value);
 
48
 
 
49
  value = new Value(time);
 
50
  InsertProperty(UFTouchPropertyTime, value);
 
51
 
 
52
  if (state == UFTouchStateBegin) {
 
53
    value = new Value(time);
 
54
    InsertProperty(UFTouchPropertyStartTime, value);
 
55
  }
 
56
}
 
57
 
 
58
UFTouch::UFTouch(const UFTouch& touch, UFTouchState new_state)
 
59
    : Property(touch),
 
60
      id_(touch.id_),
 
61
      state_(new_state),
 
62
      values_(touch.values_) {
 
63
  const Value* value = new Value(new_state);
 
64
  InsertProperty(UFTouchPropertyState, value);
 
65
}
 
66
 
 
67
void UFTouch::SetValue(UFAxisType type, float value) {
 
68
  values_[type] = value;
 
69
}
 
70
 
 
71
UFStatus UFTouch::GetValue(UFAxisType type, float* value) const {
 
72
  auto it = values_.find(type);
 
73
  if (it == values_.end())
 
74
    return UFStatusErrorInvalidAxis;
 
75
 
 
76
  *value = it->second;
 
77
 
 
78
  return UFStatusSuccess;
 
79
}
 
80
 
 
81
} // namespace frame
 
82
} // namespace utouch
 
83
 
 
84
extern "C" {
 
85
 
 
86
UFStatus frame_touch_get_property(UFTouch touch, UFTouchProperty property,
 
87
                                  void* data) {
 
88
  const utouch::frame::UFTouch* uftouch =
 
89
      static_cast<const utouch::frame::UFTouch*>(touch);
 
90
  return uftouch->GetProperty(property, data);
 
91
}
 
92
 
 
93
UFStatus frame_touch_get_value(UFTouch touch, UFAxisType type, float* value) {
 
94
  const utouch::frame::UFTouch* uftouch =
 
95
      static_cast<const utouch::frame::UFTouch*>(touch);
 
96
  return uftouch->GetValue(type, value);
 
97
}
 
98
 
 
99
UFTouchId frame_touch_get_id(UFTouch touch) {
 
100
  UFTouchId touch_id;
 
101
  const utouch::frame::UFTouch* uftouch =
 
102
      static_cast<const utouch::frame::UFTouch*>(touch);
 
103
  UFStatus status = uftouch->GetProperty(UFTouchPropertyId, &touch_id);
 
104
  assert(status == UFStatusSuccess);
 
105
  return touch_id;
 
106
}
 
107
 
 
108
UFTouchState frame_touch_get_state(UFTouch touch) {
 
109
  UFTouchState state;
 
110
  const utouch::frame::UFTouch* uftouch =
 
111
      static_cast<const utouch::frame::UFTouch*>(touch);
 
112
  UFStatus status = uftouch->GetProperty(UFTouchPropertyState, &state);
 
113
  assert(status == UFStatusSuccess);
 
114
  return state;
 
115
}
 
116
 
 
117
float frame_touch_get_window_x(UFTouch touch) {
 
118
  float x;
 
119
  const utouch::frame::UFTouch* uftouch =
 
120
      static_cast<const utouch::frame::UFTouch*>(touch);
 
121
  UFStatus status = uftouch->GetProperty(UFTouchPropertyWindowX, &x);
 
122
  assert(status == UFStatusSuccess);
 
123
  return x;
 
124
}
 
125
 
 
126
float frame_touch_get_window_y(UFTouch touch) {
 
127
  float y;
 
128
  const utouch::frame::UFTouch* uftouch =
 
129
      static_cast<const utouch::frame::UFTouch*>(touch);
 
130
  UFStatus status = uftouch->GetProperty(UFTouchPropertyWindowY, &y);
 
131
  assert(status == UFStatusSuccess);
 
132
  return y;
 
133
}
 
134
 
 
135
float frame_touch_get_device_x(UFTouch touch) {
 
136
  float x;
 
137
  const utouch::frame::UFTouch* uftouch =
 
138
      static_cast<const utouch::frame::UFTouch*>(touch);
 
139
  UFStatus status = uftouch->GetValue(UFAxisTypeX, &x);
 
140
  assert(status == UFStatusSuccess);
 
141
  return x;
 
142
}
 
143
 
 
144
float frame_touch_get_device_y(UFTouch touch) {
 
145
  float y;
 
146
  const utouch::frame::UFTouch* uftouch =
 
147
      static_cast<const utouch::frame::UFTouch*>(touch);
 
148
  UFStatus status = uftouch->GetValue(UFAxisTypeY, &y);
 
149
  assert(status == UFStatusSuccess);
 
150
  return y;
 
151
}
 
152
 
 
153
uint64_t frame_touch_get_time(UFTouch touch) {
 
154
  uint64_t time;
 
155
  const utouch::frame::UFTouch* uftouch =
 
156
      static_cast<const utouch::frame::UFTouch*>(touch);
 
157
  UFStatus status = uftouch->GetProperty(UFTouchPropertyTime, &time);
 
158
  assert(status == UFStatusSuccess);
 
159
  return time;
 
160
}
 
161
 
 
162
uint64_t frame_touch_get_start_time(UFTouch touch) {
 
163
  uint64_t start_time;
 
164
  const utouch::frame::UFTouch* uftouch =
 
165
      static_cast<const utouch::frame::UFTouch*>(touch);
 
166
  UFStatus status = uftouch->GetProperty(UFTouchPropertyStartTime, &start_time);
 
167
  assert(status == UFStatusSuccess);
 
168
  return start_time;
 
169
}
 
170
 
 
171
} // extern "C"