void osinterface_process_messages() { SDL_Event e; gLastKeyPressed = 0; // gCursorState.wheel = 0; gCursorState.left &= ~CURSOR_CHANGED; gCursorState.middle &= ~CURSOR_CHANGED; gCursorState.right &= ~CURSOR_CHANGED; gCursorState.old = 0; while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_QUIT: // rct2_finish(); rct2_quit(); break; case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) osinterface_resize(e.window.data1, e.window.data2); break; case SDL_MOUSEMOTION: RCT2_GLOBAL(0x0142406C, int) = e.motion.x; RCT2_GLOBAL(0x01424070, int) = e.motion.y; gCursorState.x = e.motion.x; gCursorState.y = e.motion.y; break; case SDL_MOUSEWHEEL: gCursorState.wheel += e.wheel.y * 128; break; case SDL_MOUSEBUTTONDOWN: RCT2_GLOBAL(0x01424318, int) = e.button.x; RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: store_mouse_input(1); gCursorState.left = CURSOR_PRESSED; gCursorState.old = 1; break; case SDL_BUTTON_MIDDLE: gCursorState.middle = CURSOR_PRESSED; break; case SDL_BUTTON_RIGHT: store_mouse_input(3); gCursorState.right = CURSOR_PRESSED; gCursorState.old = 2; break; } break; case SDL_MOUSEBUTTONUP: RCT2_GLOBAL(0x01424318, int) = e.button.x; RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: store_mouse_input(2); gCursorState.left = CURSOR_RELEASED; gCursorState.old = 3; break; case SDL_BUTTON_MIDDLE: gCursorState.middle = CURSOR_RELEASED; break; case SDL_BUTTON_RIGHT: store_mouse_input(4); gCursorState.right = CURSOR_RELEASED; gCursorState.old = 4; break; } break; case SDL_KEYDOWN: if (e.key.keysym.sym == SDLK_KP_ENTER){ // Map Keypad enter to regular enter. e.key.keysym.scancode = SDL_SCANCODE_RETURN; } gLastKeyPressed = e.key.keysym.sym; gKeysPressed[e.key.keysym.scancode] = 1; if (e.key.keysym.sym == SDLK_RETURN && e.key.keysym.mod & KMOD_ALT) osinterface_set_fullscreen_mode(!gGeneral_config.fullscreen_mode); // Text input // If backspace and we have input text with a cursor position none zero if (e.key.keysym.sym == SDLK_BACKSPACE && gTextInputLength > 0 && gTextInput && gTextInputCursorPosition){ // When at max length don't shift the data left // as it would buffer overflow. if (gTextInputCursorPosition != gTextInputMaxLength) memmove(gTextInput + gTextInputCursorPosition - 1, gTextInput + gTextInputCursorPosition, gTextInputMaxLength - gTextInputCursorPosition - 1); gTextInput[gTextInputLength - 1] = '\0'; gTextInputCursorPosition--; gTextInputLength--; } if (e.key.keysym.sym == SDLK_END){ gTextInputCursorPosition = gTextInputLength; } if (e.key.keysym.sym == SDLK_HOME){ gTextInputCursorPosition = 0; } if (e.key.keysym.sym == SDLK_DELETE && gTextInputLength > 0 && gTextInput && gTextInputCursorPosition != gTextInputLength){ memmove(gTextInput + gTextInputCursorPosition, gTextInput + gTextInputCursorPosition + 1, gTextInputMaxLength - gTextInputCursorPosition - 1); gTextInput[gTextInputMaxLength - 1] = '\0'; gTextInputLength--; } if (e.key.keysym.sym == SDLK_LEFT && gTextInput){ if (gTextInputCursorPosition) gTextInputCursorPosition--; } else if (e.key.keysym.sym == SDLK_RIGHT && gTextInput){ if (gTextInputCursorPosition < gTextInputLength) gTextInputCursorPosition++; } break; case SDL_MULTIGESTURE: if (e.mgesture.numFingers == 2) { if (e.mgesture.timestamp > _lastGestureTimestamp + 1000) _gestureRadius = 0; _lastGestureTimestamp = e.mgesture.timestamp; _gestureRadius += e.mgesture.dDist; // Zoom gesture const int tolerance = 128; int gesturePixels = (int)(_gestureRadius * RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16)); if (gesturePixels > tolerance) { _gestureRadius = 0; keyboard_shortcut_handle_command(SHORTCUT_ZOOM_VIEW_IN); } else if (gesturePixels < -tolerance) { _gestureRadius = 0; keyboard_shortcut_handle_command(SHORTCUT_ZOOM_VIEW_OUT); } } break; case SDL_TEXTINPUT: if (gTextInputLength < gTextInputMaxLength && gTextInput){ // Convert the utf-8 code into rct ascii char new_char; if (!(e.text.text[0] & 0x80)) new_char = *e.text.text; else if (!(e.text.text[0] & 0x20)) new_char = ((e.text.text[0] & 0x1F) << 6) | (e.text.text[1] & 0x3F); // If inserting in center of string make space for new letter if (gTextInputLength > gTextInputCursorPosition){ memmove(gTextInput + gTextInputCursorPosition + 1, gTextInput + gTextInputCursorPosition, gTextInputMaxLength - gTextInputCursorPosition - 1); gTextInput[gTextInputCursorPosition] = new_char; gTextInputLength++; } else gTextInput[gTextInputLength++] = new_char; gTextInputCursorPosition++; } break; default: break; } } gCursorState.any = gCursorState.left | gCursorState.middle | gCursorState.right; // Updates the state of the keys int numKeys = 256; gKeysState = SDL_GetKeyboardState(&numKeys); }
void osinterface_process_messages() { SDL_Event e; gLastKeyPressed = 0; // gCursorState.wheel = 0; gCursorState.left &= ~CURSOR_CHANGED; gCursorState.middle &= ~CURSOR_CHANGED; gCursorState.right &= ~CURSOR_CHANGED; gCursorState.old = 0; while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_QUIT: // rct2_finish(); rct2_quit(); break; case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) osinterface_resize(e.window.data1, e.window.data2); break; case SDL_MOUSEMOTION: RCT2_GLOBAL(0x0142406C, int) = e.motion.x; RCT2_GLOBAL(0x01424070, int) = e.motion.y; gCursorState.x = e.motion.x; gCursorState.y = e.motion.y; break; case SDL_MOUSEWHEEL: gCursorState.wheel += e.wheel.y * 128; break; case SDL_MOUSEBUTTONDOWN: RCT2_GLOBAL(0x01424318, int) = e.button.x; RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: store_mouse_input(1); gCursorState.left = CURSOR_PRESSED; gCursorState.old = 1; break; case SDL_BUTTON_MIDDLE: gCursorState.middle = CURSOR_PRESSED; break; case SDL_BUTTON_RIGHT: store_mouse_input(3); gCursorState.right = CURSOR_PRESSED; gCursorState.old = 2; break; } break; case SDL_MOUSEBUTTONUP: RCT2_GLOBAL(0x01424318, int) = e.button.x; RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: store_mouse_input(2); gCursorState.left = CURSOR_RELEASED; gCursorState.old = 3; break; case SDL_BUTTON_MIDDLE: gCursorState.middle = CURSOR_RELEASED; break; case SDL_BUTTON_RIGHT: store_mouse_input(4); gCursorState.right = CURSOR_RELEASED; gCursorState.old = 4; break; } break; case SDL_KEYDOWN: gLastKeyPressed = e.key.keysym.sym; gKeysPressed[e.key.keysym.scancode] = 1; if (e.key.keysym.sym == SDLK_RETURN && e.key.keysym.mod & KMOD_ALT) osinterface_set_fullscreen_mode(!gGeneral_config.fullscreen_mode); if (e.key.keysym.sym == SDLK_PRINTSCREEN){ RCT2_GLOBAL(RCT2_ADDRESS_SCREENSHOT_COUNTDOWN, sint8) = 1; //this function is normally called only in-game (in game_update) //calling it here will save screenshots even while in main menu screenshot_check(); } break; default: break; } } gCursorState.any = gCursorState.left | gCursorState.middle | gCursorState.right; // Updates the state of the keys int numKeys = 256; gKeysState = SDL_GetKeyboardState(&numKeys); }