Exemple #1
0
/**
 *
 *  rct2: 0x006E3B43
 */
void title_handle_keyboard_input()
{
	rct_window *w;
	int key;

	if (gOpenRCT2Headless) {
		return;
	}

	if (!gConsoleOpen) {
		// Handle modifier keys and key scrolling
		gInputPlaceObjectModifier = PLACE_OBJECT_MODIFIER_NONE;
		if (RCT2_GLOBAL(0x009E2B64, uint32) != 1) {
			if (gKeysState[SDL_SCANCODE_LSHIFT] || gKeysState[SDL_SCANCODE_RSHIFT])
				gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_SHIFT_Z;
			if (gKeysState[SDL_SCANCODE_LCTRL] || gKeysState[SDL_SCANCODE_RCTRL])
				gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_COPY_Z;
			if (gKeysState[SDL_SCANCODE_LALT] || gKeysState[SDL_SCANCODE_RALT])
				gInputPlaceObjectModifier |= 4;
#ifdef __MACOSX__
			if (gKeysState[SDL_SCANCODE_LGUI] || gKeysState[SDL_SCANCODE_RGUI]) {
				gInputPlaceObjectModifier |= 8;
			}
#endif
		}
	}

	while ((key = get_next_key()) != 0) {
		if (key == 255)
			continue;

		// Reserve backtick for console
		if (key == SDL_SCANCODE_GRAVE) {
			if (gConfigGeneral.debugging_tools || gConsoleOpen) {
				window_cancel_textbox();
				console_toggle();
			}
			continue;
		} else if (gConsoleOpen) {
			console_input(key);
			continue;
		}

		key |= gInputPlaceObjectModifier << 8;

		w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
		if (w != NULL) {
			keyboard_shortcut_set(key);
		} else {
			w = window_find_by_class(WC_TEXTINPUT);
			if (w != NULL) {
				window_text_input_key(w, key);
			}
			
			if (key == gShortcutKeys[SHORTCUT_SCREENSHOT]) {
				keyboard_shortcut_handle_command(SHORTCUT_SCREENSHOT);
			}
		}
	}
}
/**
 * 
 *  rct2: 0x006E3E68
 */
void keyboard_shortcut_handle(int key)
{
	int i;
	for (i = 0; i < SHORTCUT_COUNT; i++) {
		if (key == gShortcutKeys[i]) {
			keyboard_shortcut_handle_command(i);
			break;
		}
	}
}
Exemple #3
0
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);
}