* Waits for a button input and returns the information as to which * button was pressed. Used in button configuration. */
| 2106 | * button was pressed. Used in button configuration. |
| 2107 | */ |
| 2108 | int DWaitButton(const uint8_t *text, ButtConfig *bc, int *buttonConfigStatus) |
| 2109 | { |
| 2110 | SDL_Event event; |
| 2111 | static int32 LastAx[64][64]; |
| 2112 | int x, y; |
| 2113 | int timeout_ms = 10000; |
| 2114 | |
| 2115 | if (text) |
| 2116 | { |
| 2117 | std::string title = "Press a key for "; |
| 2118 | title += (const char *)text; |
| 2119 | // TODO - SDL2 |
| 2120 | //SDL_WM_SetCaption (title.c_str (), 0); |
| 2121 | puts((const char *)text); |
| 2122 | } |
| 2123 | |
| 2124 | for (x = 0; x < 64; x++) |
| 2125 | { |
| 2126 | for (y = 0; y < 64; y++) |
| 2127 | { |
| 2128 | LastAx[x][y] = 0x100000; |
| 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | // Purge all pending events, so that this next button press |
| 2133 | // will be the one we want. |
| 2134 | while (SDL_PollEvent(&event)) |
| 2135 | { |
| 2136 | } |
| 2137 | |
| 2138 | while (1) |
| 2139 | { |
| 2140 | int done = 0; |
| 2141 | |
| 2142 | SDL_Delay(10); |
| 2143 | timeout_ms -= 10; |
| 2144 | |
| 2145 | if (timeout_ms <= 0) |
| 2146 | { |
| 2147 | break; |
| 2148 | } |
| 2149 | |
| 2150 | QCoreApplication::processEvents(); |
| 2151 | |
| 2152 | while (SDL_PollEvent(&event)) |
| 2153 | { |
| 2154 | done++; |
| 2155 | switch (event.type) |
| 2156 | { |
| 2157 | case SDL_KEYDOWN: |
| 2158 | //printf("SDL KeyDown:%i \n", event.key.keysym.sym ); |
| 2159 | bc->ButtType = BUTTC_KEYBOARD; |
| 2160 | bc->DeviceNum = 0; |
| 2161 | bc->ButtonNum = event.key.keysym.sym; |
| 2162 | return (1); |
| 2163 | case SDL_JOYBUTTONDOWN: |
| 2164 | bc->ButtType = BUTTC_JOYSTICK; |
| 2165 | bc->DeviceNum = FindJoystickByInstanceID(event.jbutton.which); |
no test coverage detected