comparison src/events/SDL_keyboard.c @ 4429:faa9fc8e7f67

General improvements for user custom event registration * Switched event type to enum (int32) * Switched polling by mask to polling by type range * Added SDL_RegisterEvents() to allow dynamic user event registration * Spread events out to allow inserting new related events without breaking binary compatibility * Added padding to event structures so they're the same size regardless of 32-bit compiler structure packing settings * Split SDL_HasEvent() to SDL_HasEvent() for a single event and SDL_HasEvents() for a range of events * Added SDL_GetEventState() as a shortcut for SDL_EventState(X, SDL_QUERY) * Added SDL_FlushEvent() and SDL_FlushEvents() to clear events from the event queue
author Sam Lantinga <slouken@libsdl.org>
date Thu, 25 Mar 2010 01:08:26 -0700
parents f7b03b6838cb
children 5c64052fb476
comparison
equal deleted inserted replaced
4428:68dfd6df47da 4429:faa9fc8e7f67
686 SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode) 686 SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
687 { 687 {
688 SDL_Keyboard *keyboard = SDL_GetKeyboard(index); 688 SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
689 int posted; 689 int posted;
690 Uint16 modstate; 690 Uint16 modstate;
691 Uint8 type; 691 Uint32 type;
692 692
693 if (!keyboard || !scancode) { 693 if (!keyboard || !scancode) {
694 return 0; 694 return 0;
695 } 695 }
696 #if 0 696 #if 0
798 /* Update internal keyboard state */ 798 /* Update internal keyboard state */
799 keyboard->keystate[scancode] = state; 799 keyboard->keystate[scancode] = state;
800 800
801 /* Post the event, if desired */ 801 /* Post the event, if desired */
802 posted = 0; 802 posted = 0;
803 if (SDL_ProcessEvents[type] == SDL_ENABLE) { 803 if (SDL_GetEventState(type) == SDL_ENABLE) {
804 SDL_Event event; 804 SDL_Event event;
805 event.key.type = type; 805 event.key.type = type;
806 event.key.which = (Uint8) index; 806 event.key.which = (Uint8) index;
807 event.key.state = state; 807 event.key.state = state;
808 event.key.keysym.scancode = scancode; 808 event.key.keysym.scancode = scancode;
825 return 0; 825 return 0;
826 } 826 }
827 827
828 /* Post the event, if desired */ 828 /* Post the event, if desired */
829 posted = 0; 829 posted = 0;
830 if (SDL_ProcessEvents[SDL_TEXTINPUT] == SDL_ENABLE) { 830 if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
831 SDL_Event event; 831 SDL_Event event;
832 event.text.type = SDL_TEXTINPUT; 832 event.text.type = SDL_TEXTINPUT;
833 event.text.which = (Uint8) index; 833 event.text.which = (Uint8) index;
834 SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text)); 834 SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
835 event.text.windowID = keyboard->focus->id; 835 event.text.windowID = keyboard->focus->id;
843 { 843 {
844 int posted; 844 int posted;
845 845
846 /* Post the event, if desired */ 846 /* Post the event, if desired */
847 posted = 0; 847 posted = 0;
848 if (SDL_ProcessEvents[SDL_TEXTEDITING] == SDL_ENABLE) { 848 if (SDL_GetEventState(SDL_TEXTEDITING) == SDL_ENABLE) {
849 SDL_Event event; 849 SDL_Event event;
850 event.edit.type = SDL_TEXTEDITING; 850 event.edit.type = SDL_TEXTEDITING;
851 event.edit.start = start; 851 event.edit.start = start;
852 event.edit.length = length; 852 event.edit.length = length;
853 SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.text.text)); 853 SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.text.text));