Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MouseEvent.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, The Cinder Project, All rights reserved.
3 
4  This code is intended for use with the Cinder C++ library: http://libcinder.org
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7  the following conditions are met:
8 
9  * Redistributions of source code must retain the above copyright notice, this list of conditions and
10  the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12  the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 #pragma once
25 
26 #include "cinder/Cinder.h"
27 #include "cinder/app/Event.h"
28 #include "cinder/Vector.h"
29 
30 
31 namespace cinder { namespace app {
32 
34 class MouseEvent : public Event {
35  public:
36  MouseEvent() : Event() {}
37  MouseEvent( WindowRef win, int aInitiator, int aX, int aY, unsigned int aModifiers, float aWheelIncrement, uint32_t aNativeModifiers )
38  : Event( win ), mInitiator( aInitiator ), mX( aX ), mY( aY ), mModifiers( aModifiers ), mWheelIncrement( aWheelIncrement ), mNativeModifiers( aNativeModifiers )
39  {}
40 
42  int getX() const { return mX; }
44  int getY() const { return mY; }
46  Vec2i getPos() const { return Vec2i( mX, mY ); }
48  bool isLeft() const { return ( mInitiator & LEFT_DOWN ) ? true : false; }
50  bool isRight() const { return ( mInitiator & RIGHT_DOWN ) ? true : false; }
52  bool isMiddle() const { return ( mInitiator & MIDDLE_DOWN ) ? true : false; }
54  bool isLeftDown() const { return (mModifiers & LEFT_DOWN) ? true : false; }
56  bool isRightDown() const { return (mModifiers & RIGHT_DOWN) ? true : false; }
58  bool isMiddleDown() const { return (mModifiers & MIDDLE_DOWN) ? true : false; }
60  bool isShiftDown() const { return (mModifiers & SHIFT_DOWN) ? true : false; }
62  bool isAltDown() const { return (mModifiers & ALT_DOWN) ? true : false; }
64  bool isControlDown() const { return (mModifiers & CTRL_DOWN) ? true : false; }
66  bool isMetaDown() const { return (mModifiers & META_DOWN) ? true : false; }
68  bool isAccelDown() const { return (mModifiers & ACCEL_DOWN) ? true : false; }
70  float getWheelIncrement() const { return mWheelIncrement; }
71 
73  uint32_t getNativeModifiers() const { return mNativeModifiers; }
74 
75  enum { LEFT_DOWN = 0x0001,
76  RIGHT_DOWN = 0x0002,
77  MIDDLE_DOWN = 0x0004,
78  SHIFT_DOWN = 0x0008,
79  ALT_DOWN = 0x0010,
80  CTRL_DOWN = 0x0020,
81  META_DOWN = 0x0040,
82 #if (defined( CINDER_MSW ) || defined( CINDER_WINRT ))
84 #else
86 #endif
87  };
88 
89  private:
90  int mInitiator;
91  int mX, mY;
92  unsigned int mModifiers;
93  float mWheelIncrement;
94  uint32_t mNativeModifiers;
95 };
96 
97 } } // namespace cinder::app
bool isRightDown() const
Returns whether the right mouse button was pressed during the event.
Definition: MouseEvent.h:56
Represents a mouse event.
Definition: MouseEvent.h:34
bool isLeft() const
Returns whether the initiator for the event was the left mouse button.
Definition: MouseEvent.h:48
Definition: MouseEvent.h:75
bool isAltDown() const
Returns whether the Alt (or Option) key was pressed during the event.
Definition: MouseEvent.h:62
Definition: MouseEvent.h:76
bool isMiddle() const
Returns whether the initiator for the event was the middle mouse button.
Definition: MouseEvent.h:52
int getY() const
Returns the Y coordinate of the mouse event measured in points.
Definition: MouseEvent.h:44
GLXFBConfig Window win
Definition: GLee.h:16730
bool isMetaDown() const
Returns whether the meta key was pressed during the event. Maps to the Windows key on Windows and the...
Definition: MouseEvent.h:66
Definition: MouseEvent.h:85
bool isLeftDown() const
Returns whether the left mouse button was pressed during the event.
Definition: MouseEvent.h:54
bool isRight() const
Returns whether the initiator for the event was the right mouse button.
Definition: MouseEvent.h:50
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
Definition: MouseEvent.h:81
Base class for all Events.
Definition: Event.h:53
bool isControlDown() const
Returns whether the Control key was pressed during the event.
Definition: MouseEvent.h:64
uint32_t getNativeModifiers() const
Returns the platform-native modifier mask.
Definition: MouseEvent.h:73
bool isMiddleDown() const
Returns whether the middle mouse button was pressed during the event.
Definition: MouseEvent.h:58
Definition: MouseEvent.h:80
MouseEvent(WindowRef win, int aInitiator, int aX, int aY, unsigned int aModifiers, float aWheelIncrement, uint32_t aNativeModifiers)
Definition: MouseEvent.h:37
bool isAccelDown() const
Returns whether the accelerator key was pressed during the event. Maps to the Control key on Windows ...
Definition: MouseEvent.h:68
float getWheelIncrement() const
Returns the number of detents the user has wheeled through. Positive values correspond to wheel-up an...
Definition: MouseEvent.h:70
Definition: MouseEvent.h:77
Definition: MouseEvent.h:78
int getX() const
Returns the X coordinate of the mouse event measured in points.
Definition: MouseEvent.h:42
Vec2i getPos() const
Returns the coordinates of the mouse event measured in points.
Definition: MouseEvent.h:46
Definition: MouseEvent.h:79
bool isShiftDown() const
Returns whether the Shift key was pressed during the event.
Definition: MouseEvent.h:60
Vec2< int > Vec2i
Definition: Vector.h:1313
MouseEvent()
Definition: MouseEvent.h:36