Cleanup: remove redundant, invalid info from headers
[blender.git] / intern / ghost / intern / GHOST_EventPrinter.cpp
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file ghost/intern/GHOST_EventPrinter.cpp
21  *  \ingroup GHOST
22  * Declaration of GHOST_EventPrinter class.
23  */
24
25 #include "GHOST_EventPrinter.h"
26 #include <iostream>
27 #include "GHOST_EventKey.h"
28 #include "GHOST_EventDragnDrop.h"
29 #include "GHOST_Debug.h"
30
31 #include <stdio.h>
32
33 bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event)
34 {
35         bool handled = true;
36
37         GHOST_ASSERT(event, "event==0");
38
39         if (event->getType() == GHOST_kEventWindowUpdate) return false;
40
41         std::cout << "\nGHOST_EventPrinter::processEvent, time: " << (GHOST_TInt32)event->getTime() << ", type: ";
42         switch (event->getType()) {
43                 case GHOST_kEventUnknown:
44                         std::cout << "GHOST_kEventUnknown"; handled = false;
45                         break;
46
47                 case GHOST_kEventButtonUp:
48                 {
49                         GHOST_TEventButtonData *buttonData = (GHOST_TEventButtonData *)((GHOST_IEvent *)event)->getData();
50                         std::cout << "GHOST_kEventCursorButtonUp, button: " << buttonData->button;
51                 }
52                 break;
53                 case GHOST_kEventButtonDown:
54                 {
55                         GHOST_TEventButtonData *buttonData = (GHOST_TEventButtonData *)((GHOST_IEvent *)event)->getData();
56                         std::cout << "GHOST_kEventButtonDown, button: " << buttonData->button;
57                 }
58                 break;
59
60                 case GHOST_kEventWheel:
61                 {
62                         GHOST_TEventWheelData *wheelData = (GHOST_TEventWheelData *)((GHOST_IEvent *)event)->getData();
63                         std::cout << "GHOST_kEventWheel, z: " << wheelData->z;
64                 }
65                 break;
66
67                 case GHOST_kEventCursorMove:
68                 {
69                         GHOST_TEventCursorData *cursorData = (GHOST_TEventCursorData *)((GHOST_IEvent *)event)->getData();
70                         std::cout << "GHOST_kEventCursorMove, (x,y): (" << cursorData->x << "," << cursorData->y << ")";
71                 }
72                 break;
73
74                 case GHOST_kEventKeyUp:
75                 {
76                         GHOST_TEventKeyData *keyData = (GHOST_TEventKeyData *)((GHOST_IEvent *)event)->getData();
77                         char str[32] = {'\0'};
78                         getKeyString(keyData->key, str);
79                         std::cout << "GHOST_kEventKeyUp, key: " << str;
80                 }
81                 break;
82                 case GHOST_kEventKeyDown:
83                 {
84                         GHOST_TEventKeyData *keyData = (GHOST_TEventKeyData *)((GHOST_IEvent *)event)->getData();
85                         char str[32] = {'\0'};
86                         getKeyString(keyData->key, str);
87                         std::cout << "GHOST_kEventKeyDown, key: " << str;
88                 }
89                 break;
90
91                 case GHOST_kEventDraggingEntered:
92                 {
93                         GHOST_TEventDragnDropData *dragnDropData = (GHOST_TEventDragnDropData *)((GHOST_IEvent *)event)->getData();
94                         std::cout << "GHOST_kEventDraggingEntered, dragged object type : " << dragnDropData->dataType;
95                         std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
96                 }
97                 break;
98
99                 case GHOST_kEventDraggingUpdated:
100                 {
101                         GHOST_TEventDragnDropData *dragnDropData = (GHOST_TEventDragnDropData *)((GHOST_IEvent *)event)->getData();
102                         std::cout << "GHOST_kEventDraggingUpdated, dragged object type : " << dragnDropData->dataType;
103                         std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
104                 }
105                 break;
106
107                 case GHOST_kEventDraggingExited:
108                 {
109                         GHOST_TEventDragnDropData *dragnDropData = (GHOST_TEventDragnDropData *)((GHOST_IEvent *)event)->getData();
110                         std::cout << "GHOST_kEventDraggingExited, dragged object type : " << dragnDropData->dataType;
111                 }
112                 break;
113
114                 case GHOST_kEventDraggingDropDone:
115                 {
116                         GHOST_TEventDragnDropData *dragnDropData = (GHOST_TEventDragnDropData *)((GHOST_IEvent *)event)->getData();
117                         std::cout << "GHOST_kEventDraggingDropDone,";
118                         std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
119                         switch (dragnDropData->dataType) {
120                                 case GHOST_kDragnDropTypeString:
121                                         std::cout << " type : GHOST_kDragnDropTypeString,";
122                                         std::cout << "\n  String received = " << (char *)dragnDropData->data;
123                                         break;
124                                 case GHOST_kDragnDropTypeFilenames:
125                                 {
126                                         GHOST_TStringArray *strArray = (GHOST_TStringArray *)dragnDropData->data;
127                                         int i;
128                                         std::cout << " type : GHOST_kDragnDropTypeFilenames,";
129                                         std::cout << "\n  Received " << strArray->count << " filename" << (strArray->count > 1 ? "s:" : ":");
130                                         for (i = 0; i < strArray->count; i++)
131                                                 std::cout << "\n        File["<< i << "] : " << strArray->strings[i];
132                                 }
133                                 break;
134                                 default:
135                                         break;
136                         }
137                 }
138                 break;
139
140                 case GHOST_kEventOpenMainFile:
141                 {
142                         GHOST_TEventDataPtr eventData = ((GHOST_IEvent *)event)->getData();
143
144                         if (eventData)
145                                 std::cout << "GHOST_kEventOpenMainFile for path : " << (char *)eventData;
146                         else
147                                 std::cout << "GHOST_kEventOpenMainFile with no path specified!!";
148                 }
149                 break;
150
151                 case GHOST_kEventQuit:
152                         std::cout << "GHOST_kEventQuit";
153                         break;
154                 case GHOST_kEventWindowClose:
155                         std::cout << "GHOST_kEventWindowClose";
156                         break;
157                 case GHOST_kEventWindowActivate:
158                         std::cout << "GHOST_kEventWindowActivate";
159                         break;
160                 case GHOST_kEventWindowDeactivate:
161                         std::cout << "GHOST_kEventWindowDeactivate";
162                         break;
163                 case GHOST_kEventWindowUpdate:
164                         std::cout << "GHOST_kEventWindowUpdate";
165                         break;
166                 case GHOST_kEventWindowSize:
167                         std::cout << "GHOST_kEventWindowSize";
168                         break;
169
170                 default:
171                         std::cout << "not found"; handled = false;
172                         break;
173         }
174
175         std::cout.flush();
176
177         return handled;
178 }
179
180
181 void GHOST_EventPrinter::getKeyString(GHOST_TKey key, char str[32]) const
182 {
183         if ((key >= GHOST_kKeyComma) && (key <= GHOST_kKeyRightBracket)) {
184                 sprintf(str, "%c", (char)key);
185         }
186         else if ((key >= GHOST_kKeyNumpad0) && (key <= GHOST_kKeyNumpad9)) {
187                 sprintf(str, "Numpad %d", (key - GHOST_kKeyNumpad0));
188         }
189         else if ((key >= GHOST_kKeyF1) && (key <= GHOST_kKeyF24)) {
190                 sprintf(str, "F%d", key - GHOST_kKeyF1 + 1);
191         }
192         else {
193                 const char *tstr = NULL;
194                 switch (key) {
195                         case GHOST_kKeyBackSpace:
196                                 tstr = "BackSpace";
197                                 break;
198                         case GHOST_kKeyTab:
199                                 tstr = "Tab";
200                                 break;
201                         case GHOST_kKeyLinefeed:
202                                 tstr = "Linefeed";
203                                 break;
204                         case GHOST_kKeyClear:
205                                 tstr = "Clear";
206                                 break;
207                         case GHOST_kKeyEnter:
208                                 tstr = "Enter";
209                                 break;
210                         case GHOST_kKeyEsc:
211                                 tstr = "Esc";
212                                 break;
213                         case GHOST_kKeySpace:
214                                 tstr = "Space";
215                                 break;
216                         case GHOST_kKeyQuote:
217                                 tstr = "Quote";
218                                 break;
219                         case GHOST_kKeyBackslash:
220                                 tstr = "\\";
221                                 break;
222                         case GHOST_kKeyAccentGrave:
223                                 tstr = "`";
224                                 break;
225                         case GHOST_kKeyLeftShift:
226                                 tstr = "LeftShift";
227                                 break;
228                         case GHOST_kKeyRightShift:
229                                 tstr = "RightShift";
230                                 break;
231                         case GHOST_kKeyLeftControl:
232                                 tstr = "LeftControl";
233                                 break;
234                         case GHOST_kKeyRightControl:
235                                 tstr = "RightControl";
236                                 break;
237                         case GHOST_kKeyLeftAlt:
238                                 tstr = "LeftAlt";
239                                 break;
240                         case GHOST_kKeyRightAlt:
241                                 tstr = "RightAlt";
242                                 break;
243                         case GHOST_kKeyOS:
244                                 tstr = "OS";
245                                 break;
246                         case GHOST_kKeyGrLess:
247                                 // PC german!
248                                 tstr = "GrLess";
249                                 break;
250                         case GHOST_kKeyCapsLock:
251                                 tstr = "CapsLock";
252                                 break;
253                         case GHOST_kKeyNumLock:
254                                 tstr = "NumLock";
255                                 break;
256                         case GHOST_kKeyScrollLock:
257                                 tstr = "ScrollLock";
258                                 break;
259                         case GHOST_kKeyLeftArrow:
260                                 tstr = "LeftArrow";
261                                 break;
262                         case GHOST_kKeyRightArrow:
263                                 tstr = "RightArrow";
264                                 break;
265                         case GHOST_kKeyUpArrow:
266                                 tstr = "UpArrow";
267                                 break;
268                         case GHOST_kKeyDownArrow:
269                                 tstr = "DownArrow";
270                                 break;
271                         case GHOST_kKeyPrintScreen:
272                                 tstr = "PrintScreen";
273                                 break;
274                         case GHOST_kKeyPause:
275                                 tstr = "Pause";
276                                 break;
277                         case GHOST_kKeyInsert:
278                                 tstr = "Insert";
279                                 break;
280                         case GHOST_kKeyDelete:
281                                 tstr = "Delete";
282                                 break;
283                         case GHOST_kKeyHome:
284                                 tstr = "Home";
285                                 break;
286                         case GHOST_kKeyEnd:
287                                 tstr = "End";
288                                 break;
289                         case GHOST_kKeyUpPage:
290                                 tstr = "UpPage";
291                                 break;
292                         case GHOST_kKeyDownPage:
293                                 tstr = "DownPage";
294                                 break;
295                         case GHOST_kKeyNumpadPeriod:
296                                 tstr = "NumpadPeriod";
297                                 break;
298                         case GHOST_kKeyNumpadEnter:
299                                 tstr = "NumpadEnter";
300                                 break;
301                         case GHOST_kKeyNumpadPlus:
302                                 tstr = "NumpadPlus";
303                                 break;
304                         case GHOST_kKeyNumpadMinus:
305                                 tstr = "NumpadMinus";
306                                 break;
307                         case GHOST_kKeyNumpadAsterisk:
308                                 tstr = "NumpadAsterisk";
309                                 break;
310                         case GHOST_kKeyNumpadSlash:
311                                 tstr = "NumpadSlash";
312                                 break;
313                         case GHOST_kKeyMediaPlay:
314                                 tstr = "MediaPlayPause";
315                                 break;
316                         case GHOST_kKeyMediaStop:
317                                 tstr = "MediaStop";
318                                 break;
319                         case GHOST_kKeyMediaFirst:
320                                 tstr = "MediaFirst";
321                                 break;
322                         case GHOST_kKeyMediaLast:
323                                 tstr = "MediaLast";
324                                 break;
325                         default:
326                                 tstr = "unknown";
327                                 break;
328                 }
329
330                 sprintf(str, "%s", tstr);
331         }
332 }