1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PPAPI_CPP_TOUCH_POINT_H_
6 #define PPAPI_CPP_TOUCH_POINT_H_
7 
8 #include <stdint.h>
9 
10 #include "ppapi/c/ppb_input_event.h"
11 #include "ppapi/cpp/input_event.h"
12 #include "ppapi/cpp/point.h"
13 
14 namespace pp {
15 
16 /// Wrapper class for PP_TouchPoint.
17 class TouchPoint {
18  public:
TouchPoint()19   TouchPoint() : touch_point_(PP_MakeTouchPoint()) {}
20 
TouchPoint(const PP_TouchPoint & point)21   TouchPoint(const PP_TouchPoint& point)
22       : touch_point_(point), tilt_(PP_MakeFloatPoint(0, 0)) {}
23 
TouchPoint(const PP_TouchPoint & point,const PP_FloatPoint & tilt)24   TouchPoint(const PP_TouchPoint& point, const PP_FloatPoint& tilt)
25       : touch_point_(point), tilt_(tilt) {}
26 
27   /// @return The identifier for this TouchPoint. This corresponds to the order
28   /// in which the points were pressed. For example, the first point to be
29   /// pressed has an id of 0, the second has an id of 1, and so on. An id can be
30   /// reused when a touch point is released.  For example, if two fingers are
31   /// down, with id 0 and 1, and finger 0 releases, the next finger to be
32   /// pressed can be assigned to id 0.
id()33   uint32_t id() const { return touch_point_.id; }
34 
35   /// @return The x-y coordinates of this TouchPoint, in DOM coordinate space.
position()36   FloatPoint position() const {
37     return pp::FloatPoint(touch_point_.position);
38   }
39 
40   /// @return The elliptical radii, in screen pixels, in the x and y direction
41   /// of this TouchPoint.
radii()42   FloatPoint radii() const { return pp::FloatPoint(touch_point_.radius); }
43 
44   /// @return The angle of rotation of the elliptical model of this TouchPoint
45   /// from the y-axis.
rotation_angle()46   float rotation_angle() const { return touch_point_.rotation_angle; }
47 
48   /// @return The pressure applied to this TouchPoint.  This is typically a
49   /// value between 0 and 1, with 0 indicating no pressure and 1 indicating
50   /// some maximum pressure, but scaling differs depending on the hardware and
51   /// the value is not guaranteed to stay within that range.
pressure()52   float pressure() const { return touch_point_.pressure; }
53 
54   /// @return The tilt of this touchpoint. This is a float point. Values of x
55   /// and y are between 0 and 90, with 0 indicating 0 degrees and 90 indicating
56   //  90 degrees.
tilt()57   PP_FloatPoint tilt() const { return tilt_; }
58 
59  private:
60   PP_TouchPoint touch_point_;
61   PP_FloatPoint tilt_;
62 };
63 
64 }  // namespace pp
65 
66 #endif  /* PPAPI_CPP_TOUCH_POINT_H_ */
67