fix bug #1546
[blender.git] / intern / ghost / intern / GHOST_EventPrinter.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  */
31 /**
32  * @file        GHOST_EventPrinter.h
33  * Declaration of GHOST_EventPrinter class.
34  */
35
36 #include "GHOST_EventPrinter.h"
37 #include <iostream>
38 #include "GHOST_EventKey.h"
39 #include "GHOST_Debug.h"
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45
46 bool GHOST_EventPrinter::processEvent(GHOST_IEvent* event)
47 {
48         bool handled = true;
49         
50         GHOST_ASSERT(event, "event==0");
51
52         if (event->getType() == GHOST_kEventWindowUpdate) return false;
53
54         std::cout << "GHOST_EventPrinter::processEvent, time: " << (GHOST_TInt32)event->getTime() << ", type: ";
55         switch (event->getType()) {
56         case GHOST_kEventUnknown:
57                 std::cout << "GHOST_kEventUnknown"; handled = false;    break;
58
59         case GHOST_kEventButtonUp:
60                 {
61                 GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData();
62                 std::cout << "GHOST_kEventCursorButtonUp, button: " << buttonData->button;
63                 }
64                 break;
65         case GHOST_kEventButtonDown:
66                 {
67                 GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData();
68                 std::cout << "GHOST_kEventButtonDown, button: " << buttonData->button;
69                 }
70                 break;
71
72         case GHOST_kEventWheel:
73                 {
74                 GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*)((GHOST_IEvent*)event)->getData();
75                 std::cout << "GHOST_kEventWheel, z: " << wheelData->z;
76                 }
77                 break;
78
79         case GHOST_kEventCursorMove:
80                 {
81                 GHOST_TEventCursorData* cursorData = (GHOST_TEventCursorData*)((GHOST_IEvent*)event)->getData();
82                 std::cout << "GHOST_kEventCursorMove, (x,y): (" << cursorData->x << "," << cursorData->y << ")";
83                 }
84                 break;
85
86         case GHOST_kEventKeyUp:
87                 {
88                 GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData();
89                 STR_String str;
90                 getKeyString(keyData->key, str);
91                 std::cout << "GHOST_kEventKeyUp, key: " << str.Ptr();
92                 }
93                 break;
94         case GHOST_kEventKeyDown:
95                 {
96                 GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData();
97                 STR_String str;
98                 getKeyString(keyData->key, str);
99                 std::cout << "GHOST_kEventKeyDown, key: " << str.Ptr();
100                 }
101                 break;
102
103         case GHOST_kEventQuit:
104                 std::cout << "GHOST_kEventQuit"; break;
105         case GHOST_kEventWindowClose:
106                 std::cout << "GHOST_kEventWindowClose"; break;
107         case GHOST_kEventWindowActivate:
108                 std::cout << "GHOST_kEventWindowActivate"; break;
109         case GHOST_kEventWindowDeactivate:
110                 std::cout << "GHOST_kEventWindowDeactivate"; break;
111         case GHOST_kEventWindowUpdate:
112                 std::cout << "GHOST_kEventWindowUpdate"; break;
113         case GHOST_kEventWindowSize:
114                 std::cout << "GHOST_kEventWindowSize"; break;
115
116         default:
117                 std::cout << "not found"; handled = false; break;
118         }
119         std::cout << "\n";
120         return handled;
121 }
122
123
124 void GHOST_EventPrinter::getKeyString(GHOST_TKey key, STR_String& str) const
125 {
126         if ((key >= GHOST_kKeyComma) && (key <= GHOST_kKeyRightBracket)) {
127                 str = ((char)key);
128         }
129         else if ((key >= GHOST_kKeyNumpad0) && (key <= GHOST_kKeyNumpad9)) {
130                 int number = key - GHOST_kKeyNumpad0;
131                 STR_String numberStr (number);
132                 str = "Numpad";
133                 str += numberStr;
134         }
135         else if ((key >= GHOST_kKeyF1) && (key <= GHOST_kKeyF24)) {
136                 int number = key - GHOST_kKeyF1 + 1;
137                 STR_String numberStr (number);
138                 str = "F";
139                 str += numberStr;
140         }
141         else {
142                 switch (key)
143                 {
144                 case GHOST_kKeyBackSpace:
145                         str = "BackSpace";
146                         break;
147                 case GHOST_kKeyTab:
148                         str = "Tab";
149                         break;
150                 case GHOST_kKeyLinefeed:
151                         str = "Linefeed";
152                         break;
153                 case GHOST_kKeyClear:
154                         str = "Clear";
155                         break;
156                 case GHOST_kKeyEnter:
157                         str = "Enter";
158                         break;
159                 case GHOST_kKeyEsc:
160                         str = "Esc";
161                         break;
162                 case GHOST_kKeySpace:
163                         str = "Space";
164                         break;
165                 case GHOST_kKeyQuote:
166                         str = "Quote";
167                         break;
168                 case GHOST_kKeyBackslash:
169                         str = "\\";
170                         break;
171                 case GHOST_kKeyAccentGrave:
172                         str = "`";
173                         break;
174                 case GHOST_kKeyLeftShift:
175                         str = "LeftShift";
176                         break;
177                 case GHOST_kKeyRightShift:
178                         str = "RightShift";
179                         break;
180                 case GHOST_kKeyLeftControl:
181                         str = "LeftControl";
182                         break;
183                 case GHOST_kKeyRightControl:
184                         str = "RightControl";
185                         break;
186                 case GHOST_kKeyLeftAlt:
187                         str = "LeftAlt";
188                         break;
189                 case GHOST_kKeyRightAlt:
190                         str = "RightAlt";
191                         break;
192                 case GHOST_kKeyCommand:
193             // APPLE only!
194                         str = "Command";
195                         break;
196                 case GHOST_kKeyGrLess:
197             // PC german!
198                         str = "GrLess";
199                         break;
200                 case GHOST_kKeyCapsLock:
201                         str = "CapsLock";
202                         break;
203                 case GHOST_kKeyNumLock:
204                         str = "NumLock";
205                         break;
206                 case GHOST_kKeyScrollLock:
207                         str = "ScrollLock";
208                         break;
209                 case GHOST_kKeyLeftArrow:
210                         str = "LeftArrow";
211                         break;
212                 case GHOST_kKeyRightArrow:
213                         str = "RightArrow";
214                         break;
215                 case GHOST_kKeyUpArrow:
216                         str = "UpArrow";
217                         break;
218                 case GHOST_kKeyDownArrow:
219                         str = "DownArrow";
220                         break;
221                 case GHOST_kKeyPrintScreen:
222                         str = "PrintScreen";
223                         break;
224                 case GHOST_kKeyPause:
225                         str = "Pause";
226                         break;
227                 case GHOST_kKeyInsert:
228                         str = "Insert";
229                         break;
230                 case GHOST_kKeyDelete:
231                         str = "Delete";
232                         break;
233                 case GHOST_kKeyHome:
234                         str = "Home";
235                         break;
236                 case GHOST_kKeyEnd:
237                         str = "End";
238                         break;
239                 case GHOST_kKeyUpPage:
240                         str = "UpPage";
241                         break;
242                 case GHOST_kKeyDownPage:
243                         str = "DownPage";
244                         break;
245                 case GHOST_kKeyNumpadPeriod:
246                         str = "NumpadPeriod";
247                         break;
248                 case GHOST_kKeyNumpadEnter:
249                         str = "NumpadEnter";
250                         break;
251                 case GHOST_kKeyNumpadPlus:
252                         str = "NumpadPlus";
253                         break;
254                 case GHOST_kKeyNumpadMinus:
255                         str = "NumpadMinus";
256                         break;
257                 case GHOST_kKeyNumpadAsterisk:
258                         str = "NumpadAsterisk";
259                         break;
260                 case GHOST_kKeyNumpadSlash:
261                         str = "NumpadSlash";
262                         break;
263                 default:
264                         str = "unknown";
265                         break;
266                 }
267         }
268 }
269