Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TouchEvent.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Cinder Project: http://libcinder.org
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Cinder.h"
26 #include "cinder/app/Event.h"
27 #include "cinder/Vector.h"
28 
29 #include <vector>
30 
31 namespace cinder { namespace app {
32 
34 class TouchEvent : public Event {
35  public:
36  class Touch {
37  public:
38  Touch() {}
39  Touch( const Vec2f &pos, const Vec2f &prevPos, uint32_t id, double time, void *native )
40  : mPos( pos ), mPrevPos( prevPos ), mId( id ), mTime( time ), mNative( native )
41  {}
42 
44  float getX() const { return mPos.x; }
46  float getY() const { return mPos.y; }
48  Vec2f getPos() const { return mPos; }
50  float getPrevX() const { return mPrevPos.x; }
52  float getPrevY() const { return mPrevPos.y; }
54  Vec2f getPrevPos() const { return mPrevPos; }
56  uint32_t getId() const { return mId; }
58  double getTime() const { return mTime; }
60  const void* getNative() const { return mNative; }
61 
62  private:
63  Vec2f mPos, mPrevPos;
64  uint32_t mId;
65  double mTime;
66  void *mNative;
67  };
68 
70  : Event()
71  {}
72  TouchEvent( WindowRef win, const std::vector<Touch> &touches )
73  : Event( win ), mTouches( touches )
74  {}
75 
77  const std::vector<Touch>& getTouches() const { return mTouches; }
79  std::vector<Touch>& getTouches() { return mTouches; }
80 
81  private:
82  std::vector<Touch> mTouches;
83  bool mHandled;
84 };
85 
86 inline std::ostream& operator<<( std::ostream &out, const TouchEvent::Touch &touch )
87 {
88  out << touch.getId() << ": " << touch.getPos() << " @ " << touch.getTime() << "s";
89  return out;
90 }
91 
92 inline std::ostream& operator<<( std::ostream &out, const TouchEvent &event )
93 {
94  out << "{" << std::endl;
95  for( std::vector<TouchEvent::Touch>::const_iterator tIt = event.getTouches().begin(); tIt != event.getTouches().end(); ++tIt )
96  out << " " << *tIt << std::endl;
97  out << "}";
98  return out;
99 }
100 
101 } } // namespace cinder::app
TouchEvent()
Definition: TouchEvent.h:69
std::ostream & operator<<(std::ostream &lhs, const InterfaceOrientation &rhs)
Stream InterfacefaceOrientation enum to std::ostream.
Definition: AppCocoaTouch.mm:666
TouchEvent(WindowRef win, const std::vector< Touch > &touches)
Definition: TouchEvent.h:72
float getX() const
Returns the x position of the touch measured in points.
Definition: TouchEvent.h:44
T x
Definition: Vector.h:71
GLXFBConfig Window win
Definition: GLee.h:16730
Definition: TouchEvent.h:36
std::vector< Touch > & getTouches()
Returns a std::vector of Touch descriptors associated with this event.
Definition: TouchEvent.h:79
const std::vector< Touch > & getTouches() const
Returns a std::vector of Touch descriptors associated with this event.
Definition: TouchEvent.h:77
double getTime() const
Returns the timestamp associated with the touch, measured in seconds.
Definition: TouchEvent.h:58
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
Vec2f getPrevPos() const
Returns the previous position of the touch measured in points.
Definition: TouchEvent.h:54
float getPrevX() const
Returns the previous x position of the touch measured in points.
Definition: TouchEvent.h:50
Base class for all Events.
Definition: Event.h:53
Touch(const Vec2f &pos, const Vec2f &prevPos, uint32_t id, double time, void *native)
Definition: TouchEvent.h:39
float getY() const
Returns the y position of the touch measured in points.
Definition: TouchEvent.h:46
T y
Definition: Vector.h:71
Touch()
Definition: TouchEvent.h:38
Vec2f getPos() const
Returns the position of the touch measured in points.
Definition: TouchEvent.h:48
uint32_t getId() const
Returns an ID unique for the lifetime of the touch.
Definition: TouchEvent.h:56
Represents a touch event.
Definition: TouchEvent.h:34
float getPrevY() const
Returns the previous y position of the touch measured in points.
Definition: TouchEvent.h:52
const void * getNative() const
Returns a pointer to the OS-native object. This is a UITouch* on Cocoa Touch and a TOUCHPOINT* on MSW...
Definition: TouchEvent.h:60