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