Improves SDL2 support, includes patch by yashi and fabio, refs #2041:
* Adds SDL color cursor implementation * Adds config option for choosing preferred display in multimonitor setup * Uses text input API to better handle CJK input * Fixes various hotkey and input bugs SDL 1.2 is still the default and recommended, to test experimental SDL2 support, pass the --sdl2 flag to update-workspaces This was SVN commit r15767.
This commit is contained in:
parent
801d13aa8b
commit
d62e3729d5
@ -47,6 +47,9 @@ yres = 0
|
||||
; Force a non-standard bit depth (if 0 then use the current desktop bit depth)
|
||||
bpp = 0
|
||||
|
||||
; Preferred display (for multidisplay setups, only works with SDL 2.0)
|
||||
display = 0
|
||||
|
||||
; System settings:
|
||||
|
||||
; if false, actors won't be rendered but anything entity will be.
|
||||
|
@ -569,12 +569,21 @@ extern_lib_defs = {
|
||||
sdl = {
|
||||
compile_settings = function()
|
||||
if os.is("windows") then
|
||||
includedirs { libraries_dir .. "sdl/include/SDL" }
|
||||
if _OPTIONS["sdl2"] then
|
||||
includedirs { libraries_dir .. "sdl2/include/SDL" }
|
||||
defines { "CONFIG2_WSDL=0" }
|
||||
else
|
||||
includedirs { libraries_dir .. "sdl/include/SDL" }
|
||||
end
|
||||
elseif not _OPTIONS["android"] then
|
||||
-- Support SDL_CONFIG for overriding for the default PATH-based sdl-config
|
||||
sdl_config_path = os.getenv("SDL_CONFIG")
|
||||
if not sdl_config_path then
|
||||
sdl_config_path = "sdl-config"
|
||||
if _OPTIONS["sdl2"] then
|
||||
sdl_config_path = "sdl2-config"
|
||||
else
|
||||
sdl_config_path = "sdl-config"
|
||||
end
|
||||
end
|
||||
|
||||
-- "pkg-config sdl --libs" appears to include both static and dynamic libs
|
||||
@ -584,11 +593,19 @@ extern_lib_defs = {
|
||||
end,
|
||||
link_settings = function()
|
||||
if os.is("windows") then
|
||||
add_default_lib_paths("sdl")
|
||||
if _OPTIONS["sdl2"] then
|
||||
add_default_lib_paths("sdl2")
|
||||
else
|
||||
add_default_lib_paths("sdl")
|
||||
end
|
||||
elseif not _OPTIONS["android"] then
|
||||
sdl_config_path = os.getenv("SDL_CONFIG")
|
||||
if not sdl_config_path then
|
||||
sdl_config_path = "sdl-config"
|
||||
if _OPTIONS["sdl2"] then
|
||||
sdl_config_path = "sdl2-config"
|
||||
else
|
||||
sdl_config_path = "sdl-config"
|
||||
end
|
||||
end
|
||||
pkgconfig_libs(nil, sdl_config_path.." --libs")
|
||||
end
|
||||
|
@ -7,6 +7,7 @@ newoption { trigger = "icc", description = "Use Intel C++ Compiler (Linux only;
|
||||
newoption { trigger = "jenkins-tests", description = "Configure CxxTest to use the XmlPrinter runner which produces Jenkins-compatible output" }
|
||||
newoption { trigger = "minimal-flags", description = "Only set compiler/linker flags that are really needed. Has no effect on Windows builds" }
|
||||
newoption { trigger = "outpath", description = "Location for generated project files" }
|
||||
newoption { trigger = "sdl2", description = "Experimental build using SDL 2" }
|
||||
newoption { trigger = "with-c++11", description = "Enable C++11 on GCC" }
|
||||
newoption { trigger = "with-system-miniupnpc", description = "Search standard paths for libminiupnpc, instead of using bundled copy" }
|
||||
newoption { trigger = "with-system-mozjs24", description = "Search standard paths for libmozjs24, instead of using bundled copy" }
|
||||
|
@ -275,6 +275,9 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
!g_keys[SDLK_LCTRL] && !g_keys[SDLK_RCTRL] &&
|
||||
!g_keys[SDLK_LALT] && !g_keys[SDLK_RALT])
|
||||
|| ev->ev.type == SDL_HOTKEYDOWN
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|| ev->ev.type == SDL_TEXTINPUT
|
||||
#endif
|
||||
)
|
||||
{
|
||||
ret = GetFocusedObject()->ManuallyHandleEvent(ev);
|
||||
|
@ -30,6 +30,7 @@ CInput
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/sysdep/clipboard.h"
|
||||
#include "lib/timer.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/ConfigDB.h"
|
||||
#include "ps/Globals.h"
|
||||
@ -84,7 +85,11 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
{
|
||||
return(ManuallyHandleHotkeyEvent(ev));
|
||||
}
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
else if (ev->ev.type == SDL_KEYDOWN)
|
||||
#else // SDL2
|
||||
else if (ev->ev.type == SDL_KEYDOWN || ev->ev.type == SDL_TEXTINPUT)
|
||||
#endif
|
||||
{
|
||||
// Since the GUI framework doesn't handle to set settings
|
||||
// in Unicode (CStrW), we'll simply retrieve the actual
|
||||
@ -92,8 +97,15 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
|
||||
bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
int szChar = ev->ev.key.keysym.sym;
|
||||
wchar_t cooked = (wchar_t)ev->ev.key.keysym.unicode;
|
||||
#else // SDL2
|
||||
int szChar = 0;
|
||||
if (ev->ev.type == SDL_KEYDOWN)
|
||||
szChar = ev->ev.key.keysym.sym;
|
||||
wchar_t cooked = 0;
|
||||
#endif
|
||||
|
||||
switch (szChar)
|
||||
{
|
||||
@ -411,8 +423,21 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
}
|
||||
default: //Insert a character
|
||||
{
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (cooked == 0)
|
||||
return IN_PASS; // Important, because we didn't use any key
|
||||
#else // SDL2
|
||||
// In SDL2, we no longer get Unicode wchars via SDL_Keysym
|
||||
// we use text input events instead and they provide UTF-8 chars
|
||||
if (ev->ev.type == SDL_KEYDOWN && cooked == 0)
|
||||
return IN_HANDLED;
|
||||
else if (ev->ev.type == SDL_TEXTINPUT)
|
||||
{
|
||||
std::wstring wstr = wstring_from_utf8(ev->ev.text.text);
|
||||
for (size_t i = 0; i < wstr.length(); ++i)
|
||||
{
|
||||
cooked = wstr[i];
|
||||
#endif
|
||||
|
||||
// check max length
|
||||
int max_length;
|
||||
@ -437,6 +462,11 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
++m_iBufferPos;
|
||||
|
||||
UpdateAutoScroll();
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -89,12 +89,14 @@ template<> void ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, JS::MutableH
|
||||
// SET(keysym, "scancode", (int)val.ev.key.keysym.scancode); // (not in wsdl.h)
|
||||
SET(keysym, "sym", (int)val.ev.key.keysym.sym);
|
||||
// SET(keysym, "mod", (int)val.ev.key.keysym.mod); // (not in wsdl.h)
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (val.ev.key.keysym.unicode)
|
||||
{
|
||||
std::wstring unicode(1, (wchar_t)val.ev.key.keysym.unicode);
|
||||
SET(keysym, "unicode", unicode);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
SET(keysym, "unicode", CScriptVal(JSVAL_VOID));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2012 Wildfire Games
|
||||
/* Copyright (c) 2014 Wildfire Games
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -44,8 +44,13 @@
|
||||
# include "SDL_endian.h"
|
||||
|
||||
# if MSC_VERSION
|
||||
# pragma comment(lib, "SDL")
|
||||
# pragma comment(lib, "SDLmain")
|
||||
# if SDL_VERSION_ATLEAST(2,0,0)
|
||||
# pragma comment(lib, "SDL2")
|
||||
# pragma comment(lib, "SDL2main")
|
||||
# else
|
||||
# pragma comment(lib, "SDL")
|
||||
# pragma comment(lib, "SDLmain")
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2012 Wildfire Games
|
||||
/* Copyright (c) 2014 Wildfire Games
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -27,14 +27,15 @@
|
||||
#include "precompiled.h"
|
||||
#include "cursor.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
#include "lib/sysdep/cursor.h"
|
||||
#include "ogl_tex.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
|
||||
// On Windows, allow runtime choice between system cursors and OpenGL
|
||||
// cursors (Windows = more responsive, OpenGL = more consistent with what
|
||||
@ -45,10 +46,10 @@
|
||||
# define ALLOW_SYS_CURSOR 0
|
||||
#endif
|
||||
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
static Status load_sys_cursor(const PIVFS& vfs, const VfsPath& pathname, int hx, int hy, sys_cursor* cursor)
|
||||
{
|
||||
#if !ALLOW_SYS_CURSOR
|
||||
# if !ALLOW_SYS_CURSOR
|
||||
UNUSED2(vfs);
|
||||
UNUSED2(pathname);
|
||||
UNUSED2(hx);
|
||||
@ -56,7 +57,7 @@ static Status load_sys_cursor(const PIVFS& vfs, const VfsPath& pathname, int hx,
|
||||
UNUSED2(cursor);
|
||||
|
||||
return ERR::FAIL;
|
||||
#else
|
||||
# else
|
||||
shared_ptr<u8> file; size_t fileSize;
|
||||
RETURN_STATUS_IF_ERR(vfs->LoadFile(pathname, file, fileSize));
|
||||
|
||||
@ -72,9 +73,54 @@ static Status load_sys_cursor(const PIVFS& vfs, const VfsPath& pathname, int hx,
|
||||
|
||||
RETURN_STATUS_IF_ERR(sys_cursor_create((int)t.m_Width, (int)t.m_Height, bgra_img, hx, hy, cursor));
|
||||
return INFO::OK;
|
||||
#endif
|
||||
# endif // ALLOW_SYS_CURSOR
|
||||
}
|
||||
|
||||
#else // SDL_VERSION_ATLEAST(2,0,0)
|
||||
|
||||
class SDLCursor
|
||||
{
|
||||
SDL_Surface* surface;
|
||||
SDL_Cursor* cursor;
|
||||
|
||||
public:
|
||||
Status create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_)
|
||||
{
|
||||
shared_ptr<u8> file; size_t fileSize;
|
||||
RETURN_STATUS_IF_ERR(vfs->LoadFile(pathname, file, fileSize));
|
||||
|
||||
Tex t;
|
||||
RETURN_STATUS_IF_ERR(t.decode(file, fileSize));
|
||||
|
||||
// convert to required BGRA format.
|
||||
const size_t flags = (t.m_Flags | TEX_BGR) & ~TEX_DXT;
|
||||
RETURN_STATUS_IF_ERR(t.transform_to(flags));
|
||||
void* bgra_img = t.get_data();
|
||||
if(!bgra_img)
|
||||
WARN_RETURN(ERR::FAIL);
|
||||
|
||||
surface = SDL_CreateRGBSurfaceFrom(bgra_img, (int)t.m_Width, (int)t.m_Height, 32, (int)t.m_Width*4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
|
||||
if (!surface)
|
||||
return ERR::FAIL;
|
||||
cursor = SDL_CreateColorCursor(surface, hotspotx_, hotspoty_);
|
||||
if (!cursor)
|
||||
return ERR::FAIL;
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
void set()
|
||||
{
|
||||
SDL_SetCursor(cursor);
|
||||
}
|
||||
|
||||
void destroy()
|
||||
{
|
||||
SDL_FreeCursor(cursor);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
};
|
||||
#endif // SDL_VERSION_ATLEAST(2,0,0)
|
||||
|
||||
// no init is necessary because this is stored in struct Cursor, which
|
||||
// is 0-initialized by h_mgr.
|
||||
@ -150,7 +196,11 @@ public:
|
||||
enum CursorKind
|
||||
{
|
||||
CK_Default,
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
CK_System,
|
||||
#else
|
||||
CK_SDL,
|
||||
#endif
|
||||
CK_OpenGL
|
||||
};
|
||||
|
||||
@ -161,12 +211,19 @@ struct Cursor
|
||||
|
||||
CursorKind kind;
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
// valid iff kind == CK_System
|
||||
sys_cursor system_cursor;
|
||||
#else
|
||||
// valid iff kind == CK_SDL
|
||||
SDLCursor sdl_cursor;
|
||||
#endif
|
||||
|
||||
// valid iff kind == CK_OpenGL
|
||||
GLCursor gl_cursor;
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
sys_cursor gl_empty_system_cursor;
|
||||
#endif
|
||||
};
|
||||
|
||||
H_TYPE_DEFINE(Cursor);
|
||||
@ -183,13 +240,21 @@ static void Cursor_dtor(Cursor* c)
|
||||
case CK_Default:
|
||||
break; // nothing to do
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
case CK_System:
|
||||
sys_cursor_free(c->system_cursor);
|
||||
break;
|
||||
#else
|
||||
case CK_SDL:
|
||||
c->sdl_cursor.destroy();
|
||||
break;
|
||||
#endif
|
||||
|
||||
case CK_OpenGL:
|
||||
c->gl_cursor.destroy();
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
sys_cursor_free(c->gl_empty_system_cursor);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -215,15 +280,23 @@ static Status Cursor_reload(Cursor* c, const PIVFS& vfs, const VfsPath& name, Ha
|
||||
|
||||
const VfsPath pathnameImage = pathname.ChangeExtension(L".png");
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// try loading as SDL2 cursor
|
||||
if (!c->forceGL && c->sdl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty) == INFO::OK)
|
||||
c->kind = CK_SDL;
|
||||
#else
|
||||
// try loading as system cursor (2d, hardware accelerated)
|
||||
if(!c->forceGL && load_sys_cursor(vfs, pathnameImage, hotspotx, hotspoty, &c->system_cursor) == INFO::OK)
|
||||
if (!c->forceGL && load_sys_cursor(vfs, pathnameImage, hotspotx, hotspoty, &c->system_cursor) == INFO::OK)
|
||||
c->kind = CK_System;
|
||||
#endif
|
||||
// fall back to GLCursor (system cursor code is disabled or failed)
|
||||
else if(c->gl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty) == INFO::OK)
|
||||
{
|
||||
c->kind = CK_OpenGL;
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// (we need to hide the system cursor when using a OpenGL cursor)
|
||||
sys_cursor_create_empty(&c->gl_empty_system_cursor);
|
||||
#endif
|
||||
}
|
||||
// everything failed, leave cursor unchanged
|
||||
else
|
||||
@ -239,10 +312,15 @@ static Status Cursor_validate(const Cursor* c)
|
||||
case CK_Default:
|
||||
break; // nothing to do
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
case CK_System:
|
||||
if(c->system_cursor == 0)
|
||||
WARN_RETURN(ERR::_1);
|
||||
break;
|
||||
#else
|
||||
case CK_SDL:
|
||||
break; // nothing to do
|
||||
#endif
|
||||
|
||||
case CK_OpenGL:
|
||||
RETURN_STATUS_IF_ERR(c->gl_cursor.validate());
|
||||
@ -265,9 +343,15 @@ static Status Cursor_to_string(const Cursor* c, wchar_t* buf)
|
||||
type = L"default";
|
||||
break;
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
case CK_System:
|
||||
type = L"sys";
|
||||
break;
|
||||
#else
|
||||
case CK_SDL:
|
||||
type = L"sdl";
|
||||
break;
|
||||
#endif
|
||||
|
||||
case CK_OpenGL:
|
||||
type = L"gl";
|
||||
@ -311,7 +395,11 @@ Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, bool for
|
||||
// hide the cursor
|
||||
if(!name)
|
||||
{
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
sys_cursor_set(0);
|
||||
#else
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
#endif
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
@ -328,18 +416,29 @@ Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, bool for
|
||||
case CK_Default:
|
||||
break;
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
case CK_System:
|
||||
sys_cursor_set(c->system_cursor);
|
||||
break;
|
||||
#else
|
||||
case CK_SDL:
|
||||
c->sdl_cursor.set();
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case CK_OpenGL:
|
||||
c->gl_cursor.draw(x, y);
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// note: gl_empty_system_cursor can be 0 if sys_cursor_create_empty
|
||||
// failed; in that case we don't want to sys_cursor_set because that
|
||||
// would restore the default cursor (which is exactly what we're
|
||||
// trying to avoid here)
|
||||
if(c->gl_empty_system_cursor)
|
||||
sys_cursor_set(c->gl_empty_system_cursor);
|
||||
#else
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -153,8 +153,8 @@ static InReaction MainInputHandler(const SDL_Event_* ev)
|
||||
}
|
||||
else if (hotkey == "togglefullscreen")
|
||||
{
|
||||
#if !OS_MACOSX
|
||||
// TODO: Fix fullscreen toggling on OS X, see http://trac.wildfiregames.com/ticket/741
|
||||
#if !OS_MACOSX || SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// Fullscreen toggling is broken on OS X w/ SDL 1.2, see http://trac.wildfiregames.com/ticket/741
|
||||
g_VideoMode.ToggleFullscreen();
|
||||
#else
|
||||
LOGWARNING(L"Toggling fullscreen and resizing are disabled on OS X due to a known bug. Please use the config file to change display settings.");
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -32,6 +32,7 @@
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/sysdep/clipboard.h"
|
||||
#include "lib/timer.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "maths/MathUtil.h"
|
||||
#include "network/NetClient.h"
|
||||
#include "network/NetServer.h"
|
||||
@ -673,9 +674,11 @@ static bool isUnprintableChar(SDL_Keysym key)
|
||||
static bool isUnprintableChar(SDL_keysym key)
|
||||
#endif
|
||||
{
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// U+0000 to U+001F are control characters
|
||||
if (key.unicode < 0x20)
|
||||
{
|
||||
#endif
|
||||
switch (key.sym)
|
||||
{
|
||||
// We want to allow some, which are handled specially
|
||||
@ -691,9 +694,10 @@ static bool isUnprintableChar(SDL_keysym key)
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
InReaction conInputHandler(const SDL_Event_* ev)
|
||||
@ -729,6 +733,19 @@ InReaction conInputHandler(const SDL_Event_* ev)
|
||||
if (!g_Console->IsActive())
|
||||
return IN_PASS;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// In SDL2, we no longer get Unicode wchars via SDL_Keysym
|
||||
// we use text input events instead and they provide UTF-8 chars
|
||||
if (ev->ev.type == SDL_TEXTINPUT && !HotkeyIsPressed("console.toggle"))
|
||||
{
|
||||
// TODO: this could be more efficient with an interface to insert UTF-8 strings directly
|
||||
std::wstring wstr = wstring_from_utf8(ev->ev.text.text);
|
||||
for (size_t i = 0; i < wstr.length(); ++i)
|
||||
g_Console->InsertChar(0, wstr[i]);
|
||||
return IN_HANDLED;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ev->ev.type != SDL_KEYDOWN)
|
||||
return IN_PASS;
|
||||
|
||||
@ -739,7 +756,11 @@ InReaction conInputHandler(const SDL_Event_* ev)
|
||||
if (!isUnprintableChar(ev->ev.key.keysym) &&
|
||||
!HotkeyIsPressed("console.toggle"))
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
g_Console->InsertChar(sym, 0);
|
||||
#else
|
||||
g_Console->InsertChar(sym, (wchar_t)ev->ev.key.keysym.unicode);
|
||||
#endif
|
||||
return IN_HANDLED;
|
||||
}
|
||||
|
||||
|
@ -709,6 +709,12 @@ void Shutdown(int flags)
|
||||
|
||||
g_Profiler2.ShutdownGPU();
|
||||
|
||||
#if OS_WIN
|
||||
TIMER_BEGIN(L"shutdown wmi");
|
||||
wmi_Shutdown();
|
||||
TIMER_END(L"shutdown wmi");
|
||||
#endif
|
||||
|
||||
// Free cursors before shutting down SDL, as they may depend on SDL.
|
||||
cursor_shutdown();
|
||||
|
||||
@ -765,12 +771,6 @@ from_config:
|
||||
delete &g_Profiler;
|
||||
delete &g_ProfileViewer;
|
||||
TIMER_END(L"shutdown misc");
|
||||
|
||||
#if OS_WIN
|
||||
TIMER_BEGIN(L"shutdown wmi");
|
||||
wmi_Shutdown();
|
||||
TIMER_END(L"shutdown wmi");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if OS_UNIX
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -44,7 +44,7 @@
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_X11
|
||||
#include <GL/glx.h>
|
||||
#include <SDL/SDL_syswm.h>
|
||||
#include "SDL_syswm.h"
|
||||
|
||||
// Define the GLX_MESA_query_renderer macros if built with
|
||||
// an old Mesa (<10.0) that doesn't provide them
|
||||
@ -707,9 +707,18 @@ static void ReportGLLimits(ScriptInterface& scriptInterface, JS::HandleValue set
|
||||
|
||||
SDL_SysWMinfo wminfo;
|
||||
SDL_VERSION(&wminfo.version);
|
||||
if (SDL_GetWMInfo(&wminfo) && wminfo.subsystem == SDL_SYSWM_X11)
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
const int ret = SDL_GetWindowWMInfo(g_VideoMode.GetWindow(), &wminfo);
|
||||
#else
|
||||
const int ret = SDL_GetWMInfo(&wminfo);
|
||||
#endif
|
||||
if (ret && wminfo.subsystem == SDL_SYSWM_X11)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
Display* dpy = wminfo.info.x11.display;
|
||||
#else
|
||||
Display* dpy = wminfo.info.x11.gfxdisplay;
|
||||
#endif
|
||||
int scrnum = DefaultScreen(dpy);
|
||||
|
||||
const char* glxexts = glXQueryExtensionsString(dpy, scrnum);
|
||||
|
@ -206,8 +206,16 @@ InReaction HotkeyInputHandler( const SDL_Event_* ev )
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// Mousewheel events are no longer buttons, but we want to maintain the order
|
||||
// expected by g_mouse_buttons for compatibility
|
||||
if (ev->ev.button.button >= SDL_BUTTON_X1)
|
||||
keycode = MOUSE_BASE + (int)ev->ev.button.button + 2;
|
||||
else
|
||||
#endif
|
||||
keycode = MOUSE_BASE + (int)ev->ev.button.button;
|
||||
break;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (ev->ev.wheel.y > 0)
|
||||
@ -220,6 +228,16 @@ InReaction HotkeyInputHandler( const SDL_Event_* ev )
|
||||
keycode = MOUSE_WHEELDOWN;
|
||||
break;
|
||||
}
|
||||
else if (ev->ev.wheel.x > 0)
|
||||
{
|
||||
keycode = MOUSE_X2;
|
||||
break;
|
||||
}
|
||||
else if (ev->ev.wheel.x < 0)
|
||||
{
|
||||
keycode = MOUSE_X1;
|
||||
break;
|
||||
}
|
||||
return IN_PASS;
|
||||
#endif
|
||||
|
||||
@ -235,10 +253,12 @@ InReaction HotkeyInputHandler( const SDL_Event_* ev )
|
||||
return IN_PASS;
|
||||
}
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// Rather ugly hack to make the '"' key work better on a MacBook Pro on Windows so it doesn't
|
||||
// always close the console. (Maybe this would be better handled in wsdl or something?)
|
||||
if (keycode == SDLK_BACKQUOTE && (ev->ev.key.keysym.unicode == '\'' || ev->ev.key.keysym.unicode == '"'))
|
||||
keycode = ev->ev.key.keysym.unicode;
|
||||
#endif
|
||||
|
||||
// Somewhat hackish:
|
||||
// Create phantom 'unified-modifier' events when left- or right- modifier keys are pressed
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -44,21 +44,19 @@ enum {
|
||||
UNIFIED_SUPER,
|
||||
UNIFIED_LAST,
|
||||
// 'Keycodes' for the mouse buttons
|
||||
// SDL2 doesn't count wheels as buttons, so just give them the previous sequential IDs
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
MOUSE_WHEELUP,
|
||||
MOUSE_WHEELDOWN,
|
||||
#endif
|
||||
// Base for mouse buttons.
|
||||
// Everything less than MOUSE_BASE is not reported by an SDL mouse button event.
|
||||
// Everything greater than MOUSE_BASE is reported by an SDL mouse button event.
|
||||
MOUSE_BASE,
|
||||
MOUSE_LEFT = MOUSE_BASE + SDL_BUTTON_LEFT,
|
||||
MOUSE_RIGHT = MOUSE_BASE + SDL_BUTTON_RIGHT,
|
||||
MOUSE_MIDDLE = MOUSE_BASE + SDL_BUTTON_MIDDLE,
|
||||
MOUSE_RIGHT = MOUSE_BASE + SDL_BUTTON_RIGHT,
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
MOUSE_X1 = MOUSE_BASE + SDL_BUTTON_X1,
|
||||
MOUSE_X2 = MOUSE_BASE + SDL_BUTTON_X2,
|
||||
// SDL2 doesn't count wheels as buttons, so just give them the previous sequential IDs
|
||||
MOUSE_WHEELUP = MOUSE_BASE + 4,
|
||||
MOUSE_WHEELDOWN = MOUSE_BASE + 5,
|
||||
MOUSE_X1 = MOUSE_BASE + SDL_BUTTON_X1 + 2,
|
||||
MOUSE_X2 = MOUSE_BASE + SDL_BUTTON_X2 + 2,
|
||||
#elif SDL_VERSION_ATLEAST(1, 2, 13)
|
||||
// SDL 1.2 defines wheel buttons before X1/X2 buttons
|
||||
MOUSE_WHEELUP = MOUSE_BASE + SDL_BUTTON_WHEELUP,
|
||||
|
@ -65,6 +65,7 @@ void CVideoMode::ReadConfig()
|
||||
CFG_GET_VAL("xres", Int, m_ConfigW);
|
||||
CFG_GET_VAL("yres", Int, m_ConfigH);
|
||||
CFG_GET_VAL("bpp", Int, m_ConfigBPP);
|
||||
CFG_GET_VAL("display", Int, m_ConfigDisplay);
|
||||
CFG_GET_VAL("force_s3tc_enable", Bool, m_ConfigForceS3TCEnable);
|
||||
}
|
||||
|
||||
@ -80,7 +81,7 @@ bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
|
||||
|
||||
if (!m_Window)
|
||||
{
|
||||
m_Window = SDL_CreateWindow("0 A.D.", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
|
||||
m_Window = SDL_CreateWindow("0 A.D.", SDL_WINDOWPOS_UNDEFINED_DISPLAY(m_ConfigDisplay), SDL_WINDOWPOS_UNDEFINED_DISPLAY(m_ConfigDisplay), w, h, flags);
|
||||
if (!m_Window)
|
||||
{
|
||||
// If fullscreen fails, try windowed mode
|
||||
@ -327,6 +328,13 @@ void CVideoMode::Shutdown()
|
||||
|
||||
m_IsFullscreen = false;
|
||||
m_IsInitialised = false;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (m_Window)
|
||||
{
|
||||
SDL_DestroyWindow(m_Window);
|
||||
m_Window = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CVideoMode::EnableS3TC()
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -100,6 +100,7 @@ private:
|
||||
int m_ConfigW;
|
||||
int m_ConfigH;
|
||||
int m_ConfigBPP;
|
||||
int m_ConfigDisplay;
|
||||
bool m_ConfigFullscreen;
|
||||
bool m_ConfigForceS3TCEnable;
|
||||
|
||||
|
@ -195,8 +195,8 @@ MESSAGEHANDLER(GuiKeyEvent)
|
||||
ev.ev.key.keysym.sym = (SDL_Keycode)(int)msg->sdlkey;
|
||||
#else
|
||||
ev.ev.key.keysym.sym = (SDLKey)(int)msg->sdlkey;
|
||||
#endif
|
||||
ev.ev.key.keysym.unicode = msg->unichar;
|
||||
#endif
|
||||
in_dispatch_event(&ev);
|
||||
}
|
||||
|
||||
@ -212,8 +212,8 @@ MESSAGEHANDLER(GuiCharEvent)
|
||||
ev.ev.key.keysym.sym = (SDL_Keycode)(int)msg->sdlkey;
|
||||
#else
|
||||
ev.ev.key.keysym.sym = (SDLKey)(int)msg->sdlkey;
|
||||
#endif
|
||||
ev.ev.key.keysym.unicode = msg->unichar;
|
||||
#endif
|
||||
in_dispatch_event(&ev);
|
||||
|
||||
ev.ev.type = SDL_KEYUP;
|
||||
|
Loading…
Reference in New Issue
Block a user