Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Event.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/Function.h"
28 
29 namespace cinder { namespace app {
30 
31 template<typename T>
32 struct EventCombiner {
33  typedef void result_type;
34 
35  EventCombiner() : mEvent( 0 ) {}
36  EventCombiner( const T *event ) : mEvent( event ) {}
37 
38  template<typename InputIterator>
39  void operator()( InputIterator first, InputIterator last ) const
40  {
41  while( ( first != last ) && ( ! mEvent->isHandled() ) ) {
42  *first++;
43  }
44  }
45 
46  const T *mEvent;
47 };
48 
49 class Window;
50 typedef std::shared_ptr<Window> WindowRef;
51 
53 class Event {
54  public:
56  bool isHandled() const { return mHandled; }
58  void setHandled( bool handled = true ) { mHandled = handled; }
59 
61  WindowRef getWindow() const { return mWindow; }
62  void setWindow( const WindowRef &window ) { mWindow = window; }
63 
64  protected:
65  Event() : mHandled( false ) {}
66  Event( WindowRef window ) : mWindow( window ), mHandled( false ) {}
67 
68  public:
69  virtual ~Event() {}
70 
71  bool mHandled;
73 };
74 
75 } } // namespace cinder::app
WindowRef getWindow() const
Returns the Window in which the MouseEvent occurred.
Definition: Event.h:61
bool mHandled
Definition: Event.h:71
void operator()(InputIterator first, InputIterator last) const
Definition: Event.h:39
EventCombiner(const T *event)
Definition: Event.h:36
Definition: Window.h:137
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
EventCombiner()
Definition: Event.h:35
GLint * first
Definition: GLee.h:1725
WindowRef mWindow
Definition: Event.h:72
Event()
Definition: Event.h:65
Base class for all Events.
Definition: Event.h:53
const T * mEvent
Definition: Event.h:46
void setWindow(const WindowRef &window)
Definition: Event.h:62
Window window
Definition: GLee.h:17134
Event(WindowRef window)
Definition: Event.h:66
Definition: Event.h:32
virtual ~Event()
Definition: Event.h:69
void result_type
Definition: Event.h:33
void setHandled(bool handled=true)
Marks the event as handled, terminating the normal iteration of the event's slots.
Definition: Event.h:58
bool isHandled() const
Returns whether this event has been marked as handled by one of its slots, terminating the normal ite...
Definition: Event.h:56