Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "GHOST_EventPrinter.h" 00034 #include <iostream> 00035 #include "GHOST_EventKey.h" 00036 #include "GHOST_EventDragnDrop.h" 00037 #include "GHOST_Debug.h" 00038 00039 #include <stdio.h> 00040 00041 bool GHOST_EventPrinter::processEvent(GHOST_IEvent* event) 00042 { 00043 bool handled = true; 00044 00045 GHOST_ASSERT(event, "event==0"); 00046 00047 if (event->getType() == GHOST_kEventWindowUpdate) return false; 00048 00049 std::cout << "\nGHOST_EventPrinter::processEvent, time: " << (GHOST_TInt32)event->getTime() << ", type: "; 00050 switch (event->getType()) { 00051 case GHOST_kEventUnknown: 00052 std::cout << "GHOST_kEventUnknown"; handled = false; 00053 break; 00054 00055 case GHOST_kEventButtonUp: 00056 { 00057 GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData(); 00058 std::cout << "GHOST_kEventCursorButtonUp, button: " << buttonData->button; 00059 } 00060 break; 00061 case GHOST_kEventButtonDown: 00062 { 00063 GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData(); 00064 std::cout << "GHOST_kEventButtonDown, button: " << buttonData->button; 00065 } 00066 break; 00067 00068 case GHOST_kEventWheel: 00069 { 00070 GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*)((GHOST_IEvent*)event)->getData(); 00071 std::cout << "GHOST_kEventWheel, z: " << wheelData->z; 00072 } 00073 break; 00074 00075 case GHOST_kEventCursorMove: 00076 { 00077 GHOST_TEventCursorData* cursorData = (GHOST_TEventCursorData*)((GHOST_IEvent*)event)->getData(); 00078 std::cout << "GHOST_kEventCursorMove, (x,y): (" << cursorData->x << "," << cursorData->y << ")"; 00079 } 00080 break; 00081 00082 case GHOST_kEventKeyUp: 00083 { 00084 GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData(); 00085 char str[32]= {'\0'}; 00086 getKeyString(keyData->key, str); 00087 std::cout << "GHOST_kEventKeyUp, key: " << str; 00088 } 00089 break; 00090 case GHOST_kEventKeyDown: 00091 { 00092 GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData(); 00093 char str[32]= {'\0'}; 00094 getKeyString(keyData->key, str); 00095 std::cout << "GHOST_kEventKeyDown, key: " << str; 00096 } 00097 break; 00098 00099 case GHOST_kEventDraggingEntered: 00100 { 00101 GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData(); 00102 std::cout << "GHOST_kEventDraggingEntered, dragged object type : " << dragnDropData->dataType; 00103 std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y; 00104 } 00105 break; 00106 00107 case GHOST_kEventDraggingUpdated: 00108 { 00109 GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData(); 00110 std::cout << "GHOST_kEventDraggingUpdated, dragged object type : " << dragnDropData->dataType; 00111 std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y; 00112 } 00113 break; 00114 00115 case GHOST_kEventDraggingExited: 00116 { 00117 GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData(); 00118 std::cout << "GHOST_kEventDraggingExited, dragged object type : " << dragnDropData->dataType; 00119 } 00120 break; 00121 00122 case GHOST_kEventDraggingDropDone: 00123 { 00124 GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData(); 00125 std::cout << "GHOST_kEventDraggingDropDone,"; 00126 std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y; 00127 switch (dragnDropData->dataType) { 00128 case GHOST_kDragnDropTypeString: 00129 std::cout << " type : GHOST_kDragnDropTypeString,"; 00130 std::cout << "\n String received = " << (char*)dragnDropData->data; 00131 break; 00132 case GHOST_kDragnDropTypeFilenames: 00133 { 00134 GHOST_TStringArray *strArray = (GHOST_TStringArray*)dragnDropData->data; 00135 int i; 00136 std::cout << " type : GHOST_kDragnDropTypeFilenames,"; 00137 std::cout << "\n Received " << strArray->count << " filename" << (strArray->count > 1 ? "s:" : ":"); 00138 for (i=0;i<strArray->count;i++) 00139 std::cout << "\n File[" << i << "] : " << strArray->strings[i]; 00140 } 00141 break; 00142 default: 00143 break; 00144 } 00145 } 00146 break; 00147 00148 case GHOST_kEventOpenMainFile: 00149 { 00150 GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData(); 00151 00152 if (eventData) 00153 std::cout << "GHOST_kEventOpenMainFile for path : " << (char*)eventData; 00154 else 00155 std::cout << "GHOST_kEventOpenMainFile with no path specified!!"; 00156 } 00157 break; 00158 00159 case GHOST_kEventQuit: 00160 std::cout << "GHOST_kEventQuit"; 00161 break; 00162 case GHOST_kEventWindowClose: 00163 std::cout << "GHOST_kEventWindowClose"; 00164 break; 00165 case GHOST_kEventWindowActivate: 00166 std::cout << "GHOST_kEventWindowActivate"; 00167 break; 00168 case GHOST_kEventWindowDeactivate: 00169 std::cout << "GHOST_kEventWindowDeactivate"; 00170 break; 00171 case GHOST_kEventWindowUpdate: 00172 std::cout << "GHOST_kEventWindowUpdate"; 00173 break; 00174 case GHOST_kEventWindowSize: 00175 std::cout << "GHOST_kEventWindowSize"; 00176 break; 00177 00178 default: 00179 std::cout << "not found"; handled = false; 00180 break; 00181 } 00182 return handled; 00183 } 00184 00185 00186 void GHOST_EventPrinter::getKeyString(GHOST_TKey key, char str[32]) const 00187 { 00188 if ((key >= GHOST_kKeyComma) && (key <= GHOST_kKeyRightBracket)) { 00189 sprintf(str, "%c", (char)key); 00190 } else if ((key >= GHOST_kKeyNumpad0) && (key <= GHOST_kKeyNumpad9)) { 00191 sprintf(str, "Numpad %d", (key - GHOST_kKeyNumpad0)); 00192 #if defined(__sun__) || defined(__sun) 00193 } else if (key == 268828432) { /* solaris keyboards are messed up */ 00194 /* This should really test XK_F11 but that doesn't work */ 00195 strcpy(str, "F11"); 00196 } else if (key == 268828433) { /* solaris keyboards are messed up */ 00197 /* This should really test XK_F12 but that doesn't work */ 00198 strcpy(str, "F12"); 00199 #endif 00200 } else if ((key >= GHOST_kKeyF1) && (key <= GHOST_kKeyF24)) { 00201 sprintf(str, "F%d", key - GHOST_kKeyF1 + 1); 00202 } else { 00203 const char *tstr= NULL; 00204 switch (key) { 00205 case GHOST_kKeyBackSpace: 00206 tstr = "BackSpace"; 00207 break; 00208 case GHOST_kKeyTab: 00209 tstr = "Tab"; 00210 break; 00211 case GHOST_kKeyLinefeed: 00212 tstr = "Linefeed"; 00213 break; 00214 case GHOST_kKeyClear: 00215 tstr = "Clear"; 00216 break; 00217 case GHOST_kKeyEnter: 00218 tstr = "Enter"; 00219 break; 00220 case GHOST_kKeyEsc: 00221 tstr = "Esc"; 00222 break; 00223 case GHOST_kKeySpace: 00224 tstr = "Space"; 00225 break; 00226 case GHOST_kKeyQuote: 00227 tstr = "Quote"; 00228 break; 00229 case GHOST_kKeyBackslash: 00230 tstr = "\\"; 00231 break; 00232 case GHOST_kKeyAccentGrave: 00233 tstr = "`"; 00234 break; 00235 case GHOST_kKeyLeftShift: 00236 tstr = "LeftShift"; 00237 break; 00238 case GHOST_kKeyRightShift: 00239 tstr = "RightShift"; 00240 break; 00241 case GHOST_kKeyLeftControl: 00242 tstr = "LeftControl"; 00243 break; 00244 case GHOST_kKeyRightControl: 00245 tstr = "RightControl"; 00246 break; 00247 case GHOST_kKeyLeftAlt: 00248 tstr = "LeftAlt"; 00249 break; 00250 case GHOST_kKeyRightAlt: 00251 tstr = "RightAlt"; 00252 break; 00253 case GHOST_kKeyOS: 00254 tstr = "OS"; 00255 break; 00256 case GHOST_kKeyGrLess: 00257 // PC german! 00258 tstr = "GrLess"; 00259 break; 00260 case GHOST_kKeyCapsLock: 00261 tstr = "CapsLock"; 00262 break; 00263 case GHOST_kKeyNumLock: 00264 tstr = "NumLock"; 00265 break; 00266 case GHOST_kKeyScrollLock: 00267 tstr = "ScrollLock"; 00268 break; 00269 case GHOST_kKeyLeftArrow: 00270 tstr = "LeftArrow"; 00271 break; 00272 case GHOST_kKeyRightArrow: 00273 tstr = "RightArrow"; 00274 break; 00275 case GHOST_kKeyUpArrow: 00276 tstr = "UpArrow"; 00277 break; 00278 case GHOST_kKeyDownArrow: 00279 tstr = "DownArrow"; 00280 break; 00281 case GHOST_kKeyPrintScreen: 00282 tstr = "PrintScreen"; 00283 break; 00284 case GHOST_kKeyPause: 00285 tstr = "Pause"; 00286 break; 00287 case GHOST_kKeyInsert: 00288 tstr = "Insert"; 00289 break; 00290 case GHOST_kKeyDelete: 00291 tstr = "Delete"; 00292 break; 00293 case GHOST_kKeyHome: 00294 tstr = "Home"; 00295 break; 00296 case GHOST_kKeyEnd: 00297 tstr = "End"; 00298 break; 00299 case GHOST_kKeyUpPage: 00300 tstr = "UpPage"; 00301 break; 00302 case GHOST_kKeyDownPage: 00303 tstr = "DownPage"; 00304 break; 00305 case GHOST_kKeyNumpadPeriod: 00306 tstr = "NumpadPeriod"; 00307 break; 00308 case GHOST_kKeyNumpadEnter: 00309 tstr = "NumpadEnter"; 00310 break; 00311 case GHOST_kKeyNumpadPlus: 00312 tstr = "NumpadPlus"; 00313 break; 00314 case GHOST_kKeyNumpadMinus: 00315 tstr = "NumpadMinus"; 00316 break; 00317 case GHOST_kKeyNumpadAsterisk: 00318 tstr = "NumpadAsterisk"; 00319 break; 00320 case GHOST_kKeyNumpadSlash: 00321 tstr = "NumpadSlash"; 00322 break; 00323 case GHOST_kKeyMediaPlay: 00324 tstr = "MediaPlayPause"; 00325 break; 00326 case GHOST_kKeyMediaStop: 00327 tstr = "MediaStop"; 00328 break; 00329 case GHOST_kKeyMediaFirst: 00330 tstr = "MediaFirst"; 00331 break; 00332 case GHOST_kKeyMediaLast: 00333 tstr = "MediaLast"; 00334 break; 00335 default: 00336 tstr = "unknown"; 00337 break; 00338 } 00339 00340 sprintf(str, "%s", tstr); 00341 } 00342 } 00343