]> Dogcows Code - chaz/yoink/blobdiff - src/event.hh
new classes; yajl library
[chaz/yoink] / src / event.hh
diff --git a/src/event.hh b/src/event.hh
new file mode 100644 (file)
index 0000000..84a073e
--- /dev/null
@@ -0,0 +1,152 @@
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+ Redistribution   and   use  in  source  and  binary  forms,  with  or  without
+ modification, are permitted provided that the following conditions are met:
+   * Redistributions  of  source  code  must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+   * Redistributions  in binary form must reproduce the above copyright notice,
+     this  list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+ THIS  SOFTWARE  IS  PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES  (INCLUDING,  BUT  NOT  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES;  LOSS  OF  USE,  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _EVENT_HH_
+#define _EVENT_HH_
+
+#include "bz/date.h"
+#include "bz/object.h"
+
+
+namespace bz {
+       
+
+class event
+{
+public:
+       typedef enum
+       {
+               left_click_down         = 1<<1,
+               left_click_up           = 1<<2,
+               right_click_down        = 1<<3,
+               right_click_up          = 1<<4,
+               other_click_down        = 1<<5,
+               other_click_up          = 1<<6,
+               mouse_moved                     = 1<<7,
+               mouse_entered           = 1<<8,
+               mouse_exited            = 1<<9,
+               key_down                        = 1<<10,
+               key_up                          = 1<<11,
+               activated                       = 1<<12,
+               iconified                       = 1<<13,
+               deactivated                     = 1<<14,
+
+               file_new                        = 1<<20,
+               file_open                       = 1<<21,
+               file_revert                     = 1<<22,
+               file_save                       = 1<<23,
+               file_save_as            = 1<<24,
+               edit_undo                       = 1<<25,
+               edit_redo                       = 1<<26,
+               edit_copy                       = 1<<27,
+               edit_cut                        = 1<<28,
+               edit_paste                      = 1<<29,
+               edit_select_all         = 1<<30,
+               app_quit                        = 1<<31,
+               any                                     = 0xffffffffU
+       } type;
+
+       // This constructor is for keyboard events:
+       event( type theType,                                            // What happened?
+                  unsigned char keycode,                               // The ASCII value.
+                  int modifiers,                                               // Ctrl, Shift, Opt, etc...
+                  bool isRepeat ) :                                    // Is the key held down?
+               type_(theType), keycode_(keycode), modifiers_(modifiers),
+               isRepeat_(isRepeat)
+       {
+               timestamp_ = date();
+               id_ = getIdentifier();
+       }
+       
+       // This constructor is for mouse events:
+       event( type theType,                                            // What happened?
+                  vec2d location,                                              // Where? (window coordinates)
+                  vec2d delta,                                                 // How far has it moved?
+                  int nClick,                                                  // How many consecutive clicks?
+                  float pressure ) :                                   // How hard was it pushed?
+               type_(theType), location_(location), delta_(delta), nClick_(nClick),
+               pressure_(pressure)
+       {
+               timestamp_ = date();
+               id_ = getIdentifier();
+       }
+
+       // This constructor is for other event types:
+       event( type theType ) : type_(theType)          // What happened?
+       {
+               timestamp_ = date();
+               id_ = getIdentifier();
+       }
+
+       // Accessors for all event types:
+       type kind() const { return type_; }
+       const date& timestamp() const { return timestamp_; }
+       unsigned int identifier() const { return id_; }
+
+       void *userInfo() const { return userInfo_; }
+       void setUserInfo( void* userInfo ) { userInfo_ = userInfo; }
+       unsigned int tag() const { return tag_; }
+       void setTag( unsigned int tag ) { tag_ = tag; }
+
+       // Accessors for keyboard events:
+       unsigned char keycode() const { return keycode_; }
+       int modifiers() const { return modifiers_; }
+       bool isRepeat() const { return isRepeat_; }
+
+       // Accessors for mouse events:
+       const vec2d& location() const { return location_; }
+       const vec2d& delta() const { return delta_; }
+       int clicks() const { return nClick_; }
+       float pressure() const { return pressure_; }
+
+private:
+       unsigned int getIdentifier() {
+               static unsigned int identifier = 1;
+               return identifier++;
+       }
+
+       type type_;
+       date timestamp_;
+       unsigned int id_;
+       void *userInfo_;
+       unsigned int tag_;
+
+       unsigned char keycode_;
+       unsigned char modifiers_;
+       bool isRepeat_;
+
+       vec2d location_;
+       vec2d delta_;
+       int nClick_;
+       float pressure_;
+};
+       
+} // namespace dc
+
+#endif // _EVENT_HH_
+
This page took 0.023335 seconds and 4 git commands to generate.