Blender V2.61 - r43446
|
00001 00028 #include <stdlib.h> 00029 00030 #include <stdio.h> 00031 00032 #include "MEM_guardedalloc.h" 00033 00034 #include "GHOST_C-api.h" 00035 #include "EventToBuf.h" 00036 00037 char *eventtype_to_string(GHOST_TEventType type) { 00038 switch(type) { 00039 case GHOST_kEventCursorMove: return "CursorMove"; 00040 case GHOST_kEventButtonDown: return "ButtonDown"; 00041 case GHOST_kEventButtonUp: return "ButtonUp"; 00042 00043 case GHOST_kEventKeyDown: return "KeyDown"; 00044 case GHOST_kEventKeyUp: return "KeyUp"; 00045 00046 case GHOST_kEventQuit: return "Quit"; 00047 00048 case GHOST_kEventWindowClose: return "WindowClose"; 00049 case GHOST_kEventWindowActivate: return "WindowActivate"; 00050 case GHOST_kEventWindowDeactivate: return "WindowDeactivate"; 00051 case GHOST_kEventWindowUpdate: return "WindowUpdate"; 00052 case GHOST_kEventWindowSize: return "WindowSize"; 00053 default: 00054 return "<invalid>"; 00055 } 00056 } 00057 00058 static char *keytype_to_string(GHOST_TKey key) { 00059 #define K(key) case GHOST_k##key: return #key; 00060 switch (key) { 00061 K(KeyBackSpace); 00062 K(KeyTab); 00063 K(KeyLinefeed); 00064 K(KeyClear); 00065 K(KeyEnter); 00066 00067 K(KeyEsc); 00068 K(KeySpace); 00069 K(KeyQuote); 00070 K(KeyComma); 00071 K(KeyMinus); 00072 K(KeyPeriod); 00073 K(KeySlash); 00074 00075 K(Key0); 00076 K(Key1); 00077 K(Key2); 00078 K(Key3); 00079 K(Key4); 00080 K(Key5); 00081 K(Key6); 00082 K(Key7); 00083 K(Key8); 00084 K(Key9); 00085 00086 K(KeySemicolon); 00087 K(KeyEqual); 00088 00089 K(KeyA); 00090 K(KeyB); 00091 K(KeyC); 00092 K(KeyD); 00093 K(KeyE); 00094 K(KeyF); 00095 K(KeyG); 00096 K(KeyH); 00097 K(KeyI); 00098 K(KeyJ); 00099 K(KeyK); 00100 K(KeyL); 00101 K(KeyM); 00102 K(KeyN); 00103 K(KeyO); 00104 K(KeyP); 00105 K(KeyQ); 00106 K(KeyR); 00107 K(KeyS); 00108 K(KeyT); 00109 K(KeyU); 00110 K(KeyV); 00111 K(KeyW); 00112 K(KeyX); 00113 K(KeyY); 00114 K(KeyZ); 00115 00116 K(KeyLeftBracket); 00117 K(KeyRightBracket); 00118 K(KeyBackslash); 00119 K(KeyAccentGrave); 00120 00121 K(KeyLeftShift); 00122 K(KeyRightShift); 00123 K(KeyLeftControl); 00124 K(KeyRightControl); 00125 K(KeyLeftAlt); 00126 K(KeyRightAlt); 00127 K(KeyOS); 00128 00129 K(KeyCapsLock); 00130 K(KeyNumLock); 00131 K(KeyScrollLock); 00132 00133 K(KeyLeftArrow); 00134 K(KeyRightArrow); 00135 K(KeyUpArrow); 00136 K(KeyDownArrow); 00137 00138 K(KeyPrintScreen); 00139 K(KeyPause); 00140 00141 K(KeyInsert); 00142 K(KeyDelete); 00143 K(KeyHome); 00144 K(KeyEnd); 00145 K(KeyUpPage); 00146 K(KeyDownPage); 00147 00148 K(KeyNumpad0); 00149 K(KeyNumpad1); 00150 K(KeyNumpad2); 00151 K(KeyNumpad3); 00152 K(KeyNumpad4); 00153 K(KeyNumpad5); 00154 K(KeyNumpad6); 00155 K(KeyNumpad7); 00156 K(KeyNumpad8); 00157 K(KeyNumpad9); 00158 K(KeyNumpadPeriod); 00159 K(KeyNumpadEnter); 00160 K(KeyNumpadPlus); 00161 K(KeyNumpadMinus); 00162 K(KeyNumpadAsterisk); 00163 K(KeyNumpadSlash); 00164 00165 K(KeyF1); 00166 K(KeyF2); 00167 K(KeyF3); 00168 K(KeyF4); 00169 K(KeyF5); 00170 K(KeyF6); 00171 K(KeyF7); 00172 K(KeyF8); 00173 K(KeyF9); 00174 K(KeyF10); 00175 K(KeyF11); 00176 K(KeyF12); 00177 K(KeyF13); 00178 K(KeyF14); 00179 K(KeyF15); 00180 K(KeyF16); 00181 K(KeyF17); 00182 K(KeyF18); 00183 K(KeyF19); 00184 K(KeyF20); 00185 K(KeyF21); 00186 K(KeyF22); 00187 K(KeyF23); 00188 K(KeyF24); 00189 00190 default: 00191 return "KeyUnknown"; 00192 } 00193 #undef K 00194 } 00195 00196 void event_to_buf(GHOST_EventHandle evt, char buf[128]) { 00197 GHOST_TEventType type= GHOST_GetEventType(evt); 00198 double time= (double) ((GHOST_TInt64) GHOST_GetEventTime(evt))/1000; 00199 GHOST_WindowHandle win= GHOST_GetEventWindow(evt); 00200 void *data= GHOST_GetEventData(evt); 00201 char *pos= buf; 00202 00203 pos+= sprintf(pos, "event: %6.2f, %16s", time, eventtype_to_string(type)); 00204 if (win) { 00205 char *s= GHOST_GetTitle(win); 00206 pos+= sprintf(pos, " - win: %s", s); 00207 free(s); 00208 } else { 00209 pos+= sprintf(pos, " - sys evt"); 00210 } 00211 switch (type) { 00212 case GHOST_kEventCursorMove: { 00213 GHOST_TEventCursorData *cd= data; 00214 pos+= sprintf(pos, " - pos: (%d, %d)", cd->x, cd->y); 00215 break; 00216 } 00217 case GHOST_kEventButtonDown: 00218 case GHOST_kEventButtonUp: { 00219 GHOST_TEventButtonData *bd= data; 00220 pos+= sprintf(pos, " - but: %d", bd->button); 00221 break; 00222 } 00223 00224 case GHOST_kEventKeyDown: 00225 case GHOST_kEventKeyUp: { 00226 GHOST_TEventKeyData *kd= data; 00227 pos+= sprintf(pos, " - key: %s (%d)", keytype_to_string(kd->key), kd->key); 00228 if (kd->ascii) pos+= sprintf(pos, " ascii: '%c' (%d)", kd->ascii, kd->ascii); 00229 break; 00230 } 00231 } 00232 }