summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/point.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 15:38:48 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 15:38:48 +0000
commit493d1421853518d3b16a7b103311ea4fa1988341 (patch)
treeabc9bd73da85786a933666c8c6042a62aabd7c4b /ppapi/cpp/point.h
parentb18d98d7de474db2a2057d0e3aaaac9bd87a2f41 (diff)
downloadchromium_src-493d1421853518d3b16a7b103311ea4fa1988341.zip
chromium_src-493d1421853518d3b16a7b103311ea4fa1988341.tar.gz
chromium_src-493d1421853518d3b16a7b103311ea4fa1988341.tar.bz2
Add interfaces for requesting and receiving input event resources.
This converts the input event from a C struct to a resource to give us more ability to change over time. This patch includes a proxy and a C++ wrapper for this resource. You now have to register for classes of input events. No events are sent by default. This also allows us to specify whether the events support bubbling or not, which allows us to better-optimize IPC. TEST=none BUG=none Review URL: http://codereview.chromium.org/7285010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp/point.h')
-rw-r--r--ppapi/cpp/point.h141
1 files changed, 141 insertions, 0 deletions
diff --git a/ppapi/cpp/point.h b/ppapi/cpp/point.h
index fb92c06..94ad519 100644
--- a/ppapi/cpp/point.h
+++ b/ppapi/cpp/point.h
@@ -39,6 +39,7 @@ class Point {
point_.x = point.x;
point_.y = point.y;
}
+
/// Destructor.
~Point() {
}
@@ -132,6 +133,129 @@ class Point {
PP_Point point_;
};
+/// A 2 dimensional floating-point point with 0,0 being the upper-left starting
+/// coordinate.
+class FloatPoint {
+ public:
+ /// A constructor for a point at 0,0.
+ FloatPoint() {
+ float_point_.x = 0.0f;
+ float_point_.y = 0.0f;
+ }
+
+ /// A constructor accepting two values for x and y and converting them to a
+ /// FloatPoint.
+ ///
+ /// @param[in] in_x An value representing a horizontal coordinate of a
+ /// point, starting with 0 as the left-most coordinate.
+ ///
+ /// @param[in] in_y An value representing a vertical coordinate of a point,
+ /// starting with 0 as the top-most coordinate.
+ FloatPoint(float in_x, float in_y) {
+ float_point_.x = in_x;
+ float_point_.y = in_y;
+ }
+
+ /// A constructor accepting a pointer to a PP_FloatPoint and converting the
+ /// PP_Point to a Point. This is an implicit conversion constructor.
+ /// @param[in] point A PP_FloatPoint.
+ FloatPoint(const PP_FloatPoint& point) { // Implicit.
+ float_point_.x = point.x;
+ float_point_.y = point.y;
+ }
+ /// Destructor.
+ ~FloatPoint() {
+ }
+
+ /// A function allowing implicit conversion of a FloatPoint to a
+ /// PP_FloatPoint.
+ operator PP_FloatPoint() const {
+ return float_point_;
+ }
+
+ /// Getter function for returning the internal PP_FloatPoint struct.
+ /// @return A const reference to the internal PP_FloatPoint struct.
+ const PP_FloatPoint& pp_float_point() const {
+ return float_point_;
+ }
+
+ /// Getter function for returning the internal PP_Point struct.
+ /// @return A mutable reference to the PP_Point struct.
+ PP_FloatPoint& pp_float_point() {
+ return float_point_;
+ }
+
+ /// Getter function for returning the value of x.
+ /// @return The value of x for this Point.
+ float x() const { return float_point_.x; }
+
+ /// Setter function for setting the value of x.
+ /// @param[in] in_x A new x value.
+ void set_x(float in_x) {
+ float_point_.x = in_x;
+ }
+
+ /// Getter function for returning the value of y.
+ /// @return The value of y for this Point.
+ float y() const { return float_point_.y; }
+
+ /// Setter function for setting the value of y.
+ /// @param[in] in_y A new y value.
+ void set_y(float in_y) {
+ float_point_.y = in_y;
+ }
+
+ /// Adds two Points (this and other) together by adding their x values and
+ /// y values.
+ /// @param[in] other A Point.
+ /// @return A new Point containing the result.
+ FloatPoint operator+(const FloatPoint& other) const {
+ return FloatPoint(x() + other.x(), y() + other.y());
+ }
+
+ /// Subtracts one Point from another Point by subtracting their x values
+ /// and y values. Returnes a new point with the result.
+ /// @param[in] other A FloatPoint.
+ /// @return A new Point containing the result.
+ FloatPoint operator-(const FloatPoint& other) const {
+ return FloatPoint(x() - other.x(), y() - other.y());
+ }
+
+ /// Adds two Points (this and other) together by adding their x and y
+ /// values. Returns this point as the result.
+ /// @param[in] other A Point.
+ /// @return This Point containing the result.
+ FloatPoint& operator+=(const FloatPoint& other) {
+ float_point_.x += other.x();
+ float_point_.y += other.y();
+ return *this;
+ }
+
+ /// Subtracts one Point from another Point by subtracting their x values
+ /// and y values. Returns this point as the result.
+ /// @param[in] other A Point.
+ /// @return This Point containing the result.
+ FloatPoint& operator-=(const FloatPoint& other) {
+ float_point_.x -= other.x();
+ float_point_.y -= other.y();
+ return *this;
+ }
+
+ /// Swaps the coordinates of two Points.
+ /// @param[in] other A Point.
+ void swap(FloatPoint& other) {
+ float x = float_point_.x;
+ float y = float_point_.y;
+ float_point_.x = other.float_point_.x;
+ float_point_.y = other.float_point_.y;
+ other.float_point_.x = x;
+ other.float_point_.y = y;
+ }
+
+ private:
+ PP_FloatPoint float_point_;
+};
+
} // namespace pp
/// Determines whether the x and y values of two Points are equal.
@@ -151,4 +275,21 @@ inline bool operator!=(const pp::Point& lhs, const pp::Point& rhs) {
return !(lhs == rhs);
}
+/// Determines whether the x and y values of two FloatPoints are equal.
+/// @param[in] lhs The Point on the left-hand side of the equation.
+/// @param[in] rhs The Point on the right-hand side of the equation.
+/// @return true if they are equal, false if unequal.
+inline bool operator==(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
+ return lhs.x() == rhs.x() && lhs.y() == rhs.y();
+}
+
+/// Determines whether two Points have different coordinates.
+/// @param[in] lhs The Point on the left-hand side of the equation.
+/// @param[in] rhs The Point on the right-hand side of the equation.
+/// @return true if the coordinates of lhs are equal to the coordinates
+/// of rhs, otherwise false.
+inline bool operator!=(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
+ return !(lhs == rhs);
+}
+
#endif // PPAPI_CPP_POINT_H_