Update to 1.10.0-beta2
This commit is contained in:
+65
-36
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -23,6 +21,7 @@
|
||||
#include "../core/math_func.hpp"
|
||||
#include "../fileio_func.h"
|
||||
#include "../framerate_type.h"
|
||||
#include "../window_func.h"
|
||||
#include "sdl2_v.h"
|
||||
#include <SDL.h>
|
||||
#include <mutex>
|
||||
@@ -354,43 +353,70 @@ bool VideoDriver_SDL::ClaimMousePointer()
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called to indicate that an edit box has gained focus, text input mode should be enabled.
|
||||
*/
|
||||
void VideoDriver_SDL::EditBoxGainedFocus()
|
||||
{
|
||||
if (!this->edit_box_focused) {
|
||||
SDL_StartTextInput();
|
||||
this->edit_box_focused = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called to indicate that an edit box has lost focus, text input mode should be disabled.
|
||||
*/
|
||||
void VideoDriver_SDL::EditBoxLostFocus()
|
||||
{
|
||||
if (this->edit_box_focused) {
|
||||
SDL_StopTextInput();
|
||||
this->edit_box_focused = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct VkMapping {
|
||||
SDL_Keycode vk_from;
|
||||
byte vk_count;
|
||||
byte map_to;
|
||||
bool unprintable;
|
||||
};
|
||||
|
||||
#define AS(x, z) {x, 0, z}
|
||||
#define AM(x, y, z, w) {x, (byte)(y - x), z}
|
||||
#define AS(x, z) {x, 0, z, false}
|
||||
#define AM(x, y, z, w) {x, (byte)(y - x), z, false}
|
||||
#define AS_UP(x, z) {x, 0, z, true}
|
||||
#define AM_UP(x, y, z, w) {x, (byte)(y - x), z, true}
|
||||
|
||||
static const VkMapping _vk_mapping[] = {
|
||||
/* Pageup stuff + up/down */
|
||||
AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN),
|
||||
AS(SDLK_UP, WKC_UP),
|
||||
AS(SDLK_DOWN, WKC_DOWN),
|
||||
AS(SDLK_LEFT, WKC_LEFT),
|
||||
AS(SDLK_RIGHT, WKC_RIGHT),
|
||||
AS_UP(SDLK_PAGEUP, WKC_PAGEUP),
|
||||
AS_UP(SDLK_PAGEDOWN, WKC_PAGEDOWN),
|
||||
AS_UP(SDLK_UP, WKC_UP),
|
||||
AS_UP(SDLK_DOWN, WKC_DOWN),
|
||||
AS_UP(SDLK_LEFT, WKC_LEFT),
|
||||
AS_UP(SDLK_RIGHT, WKC_RIGHT),
|
||||
|
||||
AS(SDLK_HOME, WKC_HOME),
|
||||
AS(SDLK_END, WKC_END),
|
||||
AS_UP(SDLK_HOME, WKC_HOME),
|
||||
AS_UP(SDLK_END, WKC_END),
|
||||
|
||||
AS(SDLK_INSERT, WKC_INSERT),
|
||||
AS(SDLK_DELETE, WKC_DELETE),
|
||||
AS_UP(SDLK_INSERT, WKC_INSERT),
|
||||
AS_UP(SDLK_DELETE, WKC_DELETE),
|
||||
|
||||
/* Map letters & digits */
|
||||
AM(SDLK_a, SDLK_z, 'A', 'Z'),
|
||||
AM(SDLK_0, SDLK_9, '0', '9'),
|
||||
|
||||
AS(SDLK_ESCAPE, WKC_ESC),
|
||||
AS(SDLK_PAUSE, WKC_PAUSE),
|
||||
AS(SDLK_BACKSPACE, WKC_BACKSPACE),
|
||||
AS_UP(SDLK_ESCAPE, WKC_ESC),
|
||||
AS_UP(SDLK_PAUSE, WKC_PAUSE),
|
||||
AS_UP(SDLK_BACKSPACE, WKC_BACKSPACE),
|
||||
|
||||
AS(SDLK_SPACE, WKC_SPACE),
|
||||
AS(SDLK_RETURN, WKC_RETURN),
|
||||
AS(SDLK_TAB, WKC_TAB),
|
||||
|
||||
/* Function keys */
|
||||
AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12),
|
||||
AM_UP(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12),
|
||||
|
||||
/* Numeric part. */
|
||||
AM(SDLK_KP_0, SDLK_KP_9, '0', '9'),
|
||||
@@ -419,27 +445,18 @@ static uint ConvertSdlKeyIntoMy(SDL_Keysym *sym, WChar *character)
|
||||
{
|
||||
const VkMapping *map;
|
||||
uint key = 0;
|
||||
bool unprintable = false;
|
||||
|
||||
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) {
|
||||
if ((uint)(sym->sym - map->vk_from) <= map->vk_count) {
|
||||
key = sym->sym - map->vk_from + map->map_to;
|
||||
unprintable = map->unprintable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards) */
|
||||
#if defined(_WIN32) || defined(__OS2__)
|
||||
if (sym->scancode == 41) key = WKC_BACKQUOTE;
|
||||
#elif defined(__APPLE__)
|
||||
if (sym->scancode == 10) key = WKC_BACKQUOTE;
|
||||
#elif defined(__SVR4) && defined(__sun)
|
||||
if (sym->scancode == 60) key = WKC_BACKQUOTE;
|
||||
if (sym->scancode == 49) key = WKC_BACKSPACE;
|
||||
#elif defined(__sgi__)
|
||||
if (sym->scancode == 22) key = WKC_BACKQUOTE;
|
||||
#else
|
||||
if (sym->scancode == 49) key = WKC_BACKQUOTE;
|
||||
#endif
|
||||
if (sym->scancode == SDL_SCANCODE_GRAVE) key = WKC_BACKQUOTE;
|
||||
|
||||
/* META are the command keys on mac */
|
||||
if (sym->mod & KMOD_GUI) key |= WKC_META;
|
||||
@@ -449,9 +466,9 @@ static uint ConvertSdlKeyIntoMy(SDL_Keysym *sym, WChar *character)
|
||||
|
||||
/* The mod keys have no character. Prevent '?' */
|
||||
if (sym->mod & KMOD_GUI ||
|
||||
sym->mod & KMOD_SHIFT ||
|
||||
sym->mod & KMOD_CTRL ||
|
||||
sym->mod & KMOD_ALT) {
|
||||
sym->mod & KMOD_ALT ||
|
||||
unprintable) {
|
||||
*character = WKC_NONE;
|
||||
} else {
|
||||
*character = sym->sym;
|
||||
@@ -554,12 +571,16 @@ int VideoDriver_SDL::PollEvent()
|
||||
uint keycode = ConvertSdlKeyIntoMy(&ev.key.keysym, &character);
|
||||
// Only handle non-text keys here. Text is handled in
|
||||
// SDL_TEXTINPUT below.
|
||||
if (keycode == WKC_DELETE ||
|
||||
if (!this->edit_box_focused ||
|
||||
keycode == WKC_DELETE ||
|
||||
keycode == WKC_NUM_ENTER ||
|
||||
keycode == WKC_LEFT ||
|
||||
keycode == WKC_RIGHT ||
|
||||
keycode == WKC_UP ||
|
||||
keycode == WKC_DOWN ||
|
||||
keycode == WKC_HOME ||
|
||||
keycode == WKC_END ||
|
||||
keycode & WKC_META ||
|
||||
keycode & WKC_SHIFT ||
|
||||
keycode & WKC_CTRL ||
|
||||
keycode & WKC_ALT ||
|
||||
(keycode >= WKC_F1 && keycode <= WKC_F12) ||
|
||||
@@ -570,12 +591,17 @@ int VideoDriver_SDL::PollEvent()
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT: {
|
||||
WChar character;
|
||||
if (!this->edit_box_focused) break;
|
||||
SDL_Keycode kc = SDL_GetKeyFromName(ev.text.text);
|
||||
uint keycode = ConvertSdlKeycodeIntoMy(kc);
|
||||
|
||||
Utf8Decode(&character, ev.text.text);
|
||||
HandleKeypress(keycode, character);
|
||||
if (keycode == WKC_BACKQUOTE && FocusedWindowIsConsole()) {
|
||||
WChar character;
|
||||
Utf8Decode(&character, ev.text.text);
|
||||
HandleKeypress(keycode, character);
|
||||
} else {
|
||||
HandleTextInput(ev.text.text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT: {
|
||||
@@ -628,6 +654,9 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
|
||||
|
||||
_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr;
|
||||
|
||||
SDL_StopTextInput();
|
||||
this->edit_box_focused = false;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user