]> Dogcows Code - chaz/yoink/blob - src/event.hh
new classes; yajl library
[chaz/yoink] / src / event.hh
1
2 /*******************************************************************************
3
4 Copyright (c) 2009, Charles McGarvey
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 *******************************************************************************/
28
29 #ifndef _EVENT_HH_
30 #define _EVENT_HH_
31
32 #include "bz/date.h"
33 #include "bz/object.h"
34
35
36 namespace bz {
37
38
39 class event
40 {
41 public:
42 typedef enum
43 {
44 left_click_down = 1<<1,
45 left_click_up = 1<<2,
46 right_click_down = 1<<3,
47 right_click_up = 1<<4,
48 other_click_down = 1<<5,
49 other_click_up = 1<<6,
50 mouse_moved = 1<<7,
51 mouse_entered = 1<<8,
52 mouse_exited = 1<<9,
53 key_down = 1<<10,
54 key_up = 1<<11,
55 activated = 1<<12,
56 iconified = 1<<13,
57 deactivated = 1<<14,
58
59 file_new = 1<<20,
60 file_open = 1<<21,
61 file_revert = 1<<22,
62 file_save = 1<<23,
63 file_save_as = 1<<24,
64 edit_undo = 1<<25,
65 edit_redo = 1<<26,
66 edit_copy = 1<<27,
67 edit_cut = 1<<28,
68 edit_paste = 1<<29,
69 edit_select_all = 1<<30,
70 app_quit = 1<<31,
71 any = 0xffffffffU
72 } type;
73
74 // This constructor is for keyboard events:
75 event( type theType, // What happened?
76 unsigned char keycode, // The ASCII value.
77 int modifiers, // Ctrl, Shift, Opt, etc...
78 bool isRepeat ) : // Is the key held down?
79 type_(theType), keycode_(keycode), modifiers_(modifiers),
80 isRepeat_(isRepeat)
81 {
82 timestamp_ = date();
83 id_ = getIdentifier();
84 }
85
86 // This constructor is for mouse events:
87 event( type theType, // What happened?
88 vec2d location, // Where? (window coordinates)
89 vec2d delta, // How far has it moved?
90 int nClick, // How many consecutive clicks?
91 float pressure ) : // How hard was it pushed?
92 type_(theType), location_(location), delta_(delta), nClick_(nClick),
93 pressure_(pressure)
94 {
95 timestamp_ = date();
96 id_ = getIdentifier();
97 }
98
99 // This constructor is for other event types:
100 event( type theType ) : type_(theType) // What happened?
101 {
102 timestamp_ = date();
103 id_ = getIdentifier();
104 }
105
106 // Accessors for all event types:
107 type kind() const { return type_; }
108 const date& timestamp() const { return timestamp_; }
109 unsigned int identifier() const { return id_; }
110
111 void *userInfo() const { return userInfo_; }
112 void setUserInfo( void* userInfo ) { userInfo_ = userInfo; }
113 unsigned int tag() const { return tag_; }
114 void setTag( unsigned int tag ) { tag_ = tag; }
115
116 // Accessors for keyboard events:
117 unsigned char keycode() const { return keycode_; }
118 int modifiers() const { return modifiers_; }
119 bool isRepeat() const { return isRepeat_; }
120
121 // Accessors for mouse events:
122 const vec2d& location() const { return location_; }
123 const vec2d& delta() const { return delta_; }
124 int clicks() const { return nClick_; }
125 float pressure() const { return pressure_; }
126
127 private:
128 unsigned int getIdentifier() {
129 static unsigned int identifier = 1;
130 return identifier++;
131 }
132
133 type type_;
134 date timestamp_;
135 unsigned int id_;
136 void *userInfo_;
137 unsigned int tag_;
138
139 unsigned char keycode_;
140 unsigned char modifiers_;
141 bool isRepeat_;
142
143 vec2d location_;
144 vec2d delta_;
145 int nClick_;
146 float pressure_;
147 };
148
149 } // namespace dc
150
151 #endif // _EVENT_HH_
152
This page took 0.035525 seconds and 4 git commands to generate.