Merge pull request #555 from wesnoth/sdl2
Merge Sdl2 branch with Master. This adds SDL2 support to master and makes it the default build option.
This commit is contained in:
commit
3f9d9ca339
91 changed files with 2537 additions and 1097 deletions
|
@ -53,7 +53,7 @@ before_install:
|
|||
|
||||
install:
|
||||
- travis_wait sudo apt-get update -qq
|
||||
- travis_wait sudo apt-get install -qq libboost-filesystem-dev libboost-iostreams-dev libboost-random-dev libboost-program-options-dev libboost-regex-dev libboost-system-dev libboost-test-dev libboost-locale-dev libcairo2-dev libfribidi-dev libpango1.0-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-net1.2-dev libsdl-ttf2.0-dev gdb moreutils scons xvfb
|
||||
- travis_wait sudo apt-get install -qq libboost-filesystem-dev libboost-iostreams-dev libboost-random-dev libboost-program-options-dev libboost-regex-dev libboost-system-dev libboost-test-dev libboost-locale-dev libcairo2-dev libfribidi-dev libpango1.0-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-net1.2-dev libsdl-ttf2.0-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-net-dev libsdl2-ttf-dev gdb moreutils scons xvfb
|
||||
|
||||
script:
|
||||
- ./utils/travis/check_utf8.sh
|
||||
|
|
|
@ -49,7 +49,7 @@ option(ENABLE_CAMPAIGN_SERVER "Enable compilation of campaign server")
|
|||
option(ENABLE_SERVER "Enable compilation of server" ON)
|
||||
option(ENABLE_TOOLS "Enable building and installation of tools for artists and WML maintainers")
|
||||
option(ENABLE_SDL2_TOOLS "Enable building and installation of tools for testing with SDL2" OFF)
|
||||
option(ENABLE_SDL2 "Enable building the game with SDL2" OFF)
|
||||
option(ENABLE_SDL2 "Enable building the game with SDL2" ON)
|
||||
option(ENABLE_TESTS "Build unit tests")
|
||||
option(ENABLE_NLS "Enable building of translations" ON)
|
||||
option(ENABLE_LOW_MEM "Reduce memory usage by removing extra functionality" OFF)
|
||||
|
|
|
@ -109,7 +109,7 @@ opts.AddVariables(
|
|||
BoolVariable("lockfile", "Create a lockfile to prevent multiple instances of scons from being run at the same time on this working copy.", False),
|
||||
BoolVariable("OS_ENV", "Forward the entire OS environment to scons", False),
|
||||
BoolVariable("history", "Clear to disable GNU history support in lua console", True),
|
||||
BoolVariable("sdl2", "Build with SDL2 support (experimental!)", False)
|
||||
BoolVariable("sdl2", "Build with SDL2 support (experimental!)", True)
|
||||
)
|
||||
|
||||
#
|
||||
|
|
|
@ -197,15 +197,13 @@
|
|||
step=1
|
||||
[/advanced_preference]
|
||||
|
||||
#ifndef APPLE
|
||||
[advanced_preference]
|
||||
field=color_cursors
|
||||
name= _ "Show color cursors"
|
||||
description= _ "Use colored mouse cursors, which may be slower or break the game (use at your own risk)"
|
||||
description= _ "Use colored mouse cursors"
|
||||
type=boolean
|
||||
default=no
|
||||
[/advanced_preference]
|
||||
#endif
|
||||
|
||||
#ifdef __UNUSED__
|
||||
[advanced_preference]
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
[/hotkey]
|
||||
[hotkey]
|
||||
command=command
|
||||
key=:
|
||||
key=;
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=continue
|
||||
|
@ -92,11 +92,11 @@
|
|||
[/hotkey]
|
||||
[hotkey]
|
||||
command=endunitturn
|
||||
key=" "
|
||||
key="space"
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=endturn
|
||||
key=" "
|
||||
key="space"
|
||||
#ifdef APPLE
|
||||
alt=yes
|
||||
#else
|
||||
|
@ -114,7 +114,7 @@
|
|||
[/hotkey]
|
||||
[hotkey]
|
||||
command=holdposition
|
||||
key=" "
|
||||
key="space"
|
||||
shift=yes
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
|
@ -262,7 +262,7 @@
|
|||
[/hotkey]
|
||||
[hotkey]
|
||||
command=zoomin
|
||||
key="+"
|
||||
key="="
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=zoomout
|
||||
|
@ -293,11 +293,11 @@
|
|||
[/hotkey]
|
||||
[hotkey]
|
||||
command=wbbumpupaction
|
||||
key="page up"
|
||||
key="PageUp"
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=wbbumpdownaction
|
||||
key="page down"
|
||||
key="PageDown"
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=wbsupposedead
|
||||
|
@ -347,12 +347,14 @@
|
|||
key=5
|
||||
[/hotkey]
|
||||
|
||||
#ifndef APPLE
|
||||
[hotkey]
|
||||
command="editor-quit-to-desktop"
|
||||
command="quit-to-desktop"
|
||||
key="q"
|
||||
shift=yes
|
||||
{IF_APPLE_CMD_ELSE_CTRL}
|
||||
ctrl=yes
|
||||
[/hotkey]
|
||||
#endif
|
||||
|
||||
[hotkey]
|
||||
command="editor-partial-undo"
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
id=menu-main
|
||||
title= _ "Menu"
|
||||
image=classic/lite
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,quit
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,quit,quit-to-desktop
|
||||
ref=top-panel
|
||||
rect="=+3,=+1,+100,=-4"
|
||||
xanchor=fixed
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
id=menu-main
|
||||
title= _ "Menu"
|
||||
image=button_menu/menu_button_copper_H20
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,menu-autosaves,help,stopnetwork,startnetwork,quit
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,menu-autosaves,help,stopnetwork,startnetwork,quit,quit-to-desktop
|
||||
ref=top-panel
|
||||
rect="=+3,=+1,+100,=-4"
|
||||
xanchor=fixed
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
title= _ "File"
|
||||
type=turbo
|
||||
font_size=9
|
||||
items=editor-scenario-edit,statustable,unitlist,editor-map-new,editor-scenario-new,editor-map-load,menu-editor-recent,editor-map-revert,editor-map-save,editor-map-save-as,editor-scenario-save-as,editor-map-save-all,preferences,help,editor-close-map,quit,editor-quit-to-desktop
|
||||
items=editor-scenario-edit,statustable,unitlist,editor-map-new,editor-scenario-new,editor-map-load,menu-editor-recent,editor-map-revert,editor-map-save,editor-map-save-as,editor-scenario-save-as,editor-map-save-all,preferences,help,editor-close-map,quit,quit-to-desktop
|
||||
ref=top-panel
|
||||
rect="=+1,=+1,+100,+20"
|
||||
xanchor=fixed
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
id=menu-main
|
||||
title= _ "Menu"
|
||||
image=button_menu/menu_button_copper_H20
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,quit
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,quit,quit-to-desktop
|
||||
ref=top-panel
|
||||
rect="=+3,=+1,+100,=-4"
|
||||
xanchor=fixed
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
id=menu-main
|
||||
title= _ "Menu"
|
||||
image=button_menu/menu_button_copper_H20
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,quit
|
||||
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,quit,quit-to-desktop
|
||||
ref=top-panel
|
||||
rect="=+3,=+1,+100,=-4"
|
||||
xanchor=fixed
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
BasicRuntimeChecks="2"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
|
@ -53,11 +53,13 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/SAFESEH:NO"
|
||||
OutputFile="$(OutDir)\WindowsTimeout.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(IntDir)\$(TargetName).pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
LinkIncremental="2"
|
||||
OutputFile="$(OutDir)\WindowsTimeout.exe"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
AdditionalIncludeDirectories="..\..\..\external\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
BasicRuntimeChecks="2"
|
||||
RuntimeLibrary="3"
|
||||
OpenMP="true"
|
||||
UsePrecompiledHeader="0"
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\src;..\..\..\external\include"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
BasicRuntimeChecks="2"
|
||||
RuntimeLibrary="3"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="4"
|
||||
|
@ -53,7 +53,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
|
@ -119,7 +119,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
|
@ -187,7 +187,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
|
@ -253,7 +253,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
AdditionalIncludeDirectories="..\..\src;..\..\..\external\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;DEBUG_LUA"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
BasicRuntimeChecks="2"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="false"
|
||||
EnableEnhancedInstructionSet="2"
|
||||
|
@ -61,7 +61,8 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
AdditionalOptions="/SAFESEH:NO"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
IgnoreDefaultLibraryNames="MSVCR90;MSVCRT"
|
||||
|
@ -88,6 +89,9 @@
|
|||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
|
@ -138,7 +142,7 @@
|
|||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="false"
|
||||
LinkLibraryDependencies="true"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="false"
|
||||
|
@ -220,7 +224,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -246,6 +250,9 @@
|
|||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Test_Debug|Win32"
|
||||
|
@ -292,7 +299,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib Debug\liblua.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib Debug\liblua.lib"
|
||||
OutputFile="$(OutDir)\test.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
|
@ -319,6 +326,9 @@
|
|||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Test_Release|Win32"
|
||||
|
@ -369,7 +379,7 @@
|
|||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="false"
|
||||
LinkLibraryDependencies="true"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib Release\liblua.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib Release\liblua.lib"
|
||||
OutputFile="$(OutDir)\test.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
|
@ -456,7 +466,7 @@
|
|||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="false"
|
||||
LinkLibraryDependencies="true"
|
||||
AdditionalDependencies="SDL.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib SDL_net.lib cairo.lib winmm.lib ws2_32.lib SDLmain.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib SDL2_net.lib cairo.lib winmm.lib ws2_32.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib libpng.lib $(IntDir)\liblua.lib"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -21720,6 +21730,14 @@
|
|||
RelativePath="..\..\src\sdl\image.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\sdl\keyboard.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\sdl\keyboard.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\sdl\rect.cpp"
|
||||
>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
AdditionalIncludeDirectories="..\..\src;..\..\..\external\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;HAVE_PYTHON;USE_GZIP;NOMINMAX;_SCL_SECURE_NO_WARNINGS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
BasicRuntimeChecks="2"
|
||||
RuntimeLibrary="3"
|
||||
OpenMP="true"
|
||||
UsePrecompiledHeader="0"
|
||||
|
@ -58,7 +58,8 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_net.lib winmm.lib ws2_32.lib SDLmain.lib"
|
||||
AdditionalOptions="/SAFESEH:NO"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_net.lib winmm.lib ws2_32.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -129,7 +130,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_net.lib winmm.lib ws2_32.lib SDLmain.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_net.lib winmm.lib ws2_32.lib"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="false"
|
||||
|
@ -203,7 +204,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_net.lib winmm.lib ws2_32.lib SDLmain.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_net.lib winmm.lib ws2_32.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -274,7 +275,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDL_net.lib winmm.lib ws2_32.lib SDLmain.lib"
|
||||
AdditionalDependencies="SDL2main.lib SDL2.lib SDL2_net.lib winmm.lib ws2_32.lib"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\external\lib"
|
||||
GenerateDebugInformation="true"
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
AdditionalIncludeDirectories="..\..\src;..\..\..\external\include"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;NOMINMAX;_DEBUG;_SCL_SECURE_NO_WARNINGS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
BasicRuntimeChecks="2"
|
||||
RuntimeLibrary="3"
|
||||
OpenMP="true"
|
||||
WarningLevel="4"
|
||||
|
|
|
@ -7,12 +7,16 @@
|
|||
#import "SDL.h"
|
||||
#import "SDLMain.h"
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
extern int wesnoth_main(int argc, char **argv);
|
||||
#endif
|
||||
static int gArgc;
|
||||
static char **gArgv;
|
||||
|
||||
@interface SDLApplication : NSApplication
|
||||
@end
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
@implementation SDLApplication
|
||||
/* Invoked from the Quit menu item */
|
||||
- (void)terminate:(id)sender
|
||||
|
@ -42,7 +46,7 @@ static char **gArgv;
|
|||
}
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
/* The main class of the application, the application's delegate */
|
||||
@implementation SDLMain
|
||||
|
@ -73,7 +77,11 @@ static char **gArgv;
|
|||
//setenv("PYTHONHOME", ".", 1); //not needed because we don't use Python anymore
|
||||
|
||||
/* Hand off to main application code */
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
status = wesnoth_main (gArgc, gArgv);
|
||||
#else
|
||||
status = SDL_main (gArgc, gArgv);
|
||||
#endif
|
||||
|
||||
/* We're done, thank you for playing */
|
||||
exit(status);
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
#ifdef main
|
||||
# undef main
|
||||
#endif
|
||||
|
||||
int SDL_main (int argc, char **argv);
|
||||
extern int SDL_main (int argc, char **argv);
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
return SDL_main(argc, argv);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -75,6 +75,8 @@
|
|||
62D24F351519995200350848 /* palette_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F341519995200350848 /* palette_manager.cpp */; };
|
||||
62E48250154D865E001DD4FC /* pane.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62E4824E154D865E001DD4FC /* pane.cpp */; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
911F2DAD1BA086A400E3102E /* window.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911F2DAB1BA086A400E3102E /* window.cpp */; };
|
||||
911F2DB01BA086FA00E3102E /* alpha.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911F2DAE1BA086F900E3102E /* alpha.cpp */; };
|
||||
919B37F81BAF789E00E0094C /* synced_user_choice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B37F71BAF789D00E0094C /* synced_user_choice.cpp */; };
|
||||
919B37FC1BAF7A9D00E0094C /* synced_choice_wait.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */; };
|
||||
91B6217C1B74E6D200B00E0F /* label_settings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B6217A1B74E6D100B00E0F /* label_settings.cpp */; };
|
||||
|
@ -151,7 +153,7 @@
|
|||
B513B1E70ED345EB0006E551 /* pango.modules in Resources */ = {isa = PBXBuildFile; fileRef = B513B1C80ED345EA0006E551 /* pango.modules */; };
|
||||
B513B21E0ED346090006E551 /* pango in Resources */ = {isa = PBXBuildFile; fileRef = B513B2000ED346090006E551 /* pango */; };
|
||||
B513B2290ED36BFB0006E551 /* libcairo.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B513B2270ED36BFB0006E551 /* libcairo.2.dylib */; };
|
||||
B513B2790ED372210006E551 /* SDL_ttf.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B5599E9B0EC68BF2008DD061 /* SDL_ttf.framework */; };
|
||||
B513B2790ED372210006E551 /* SDL2_ttf.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B5599E9B0EC68BF2008DD061 /* SDL2_ttf.framework */; };
|
||||
B514C70B0F5450CC00E273F0 /* addon_list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B514C7090F5450CC00E273F0 /* addon_list.cpp */; };
|
||||
B52EE8841213585300CFBDAB /* tod_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B52EE8821213585300CFBDAB /* tod_manager.cpp */; };
|
||||
B52EE8851213585300CFBDAB /* tod_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B52EE8821213585300CFBDAB /* tod_manager.cpp */; };
|
||||
|
@ -292,10 +294,10 @@
|
|||
B553B6BA12189C5900CC8C58 /* utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B553B6B812189C5900CC8C58 /* utility.cpp */; };
|
||||
B553B6BB12189C5900CC8C58 /* utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B553B6B812189C5900CC8C58 /* utility.cpp */; };
|
||||
B559986C0EC616B3008DD061 /* SDLMain.m in Sources */ = {isa = PBXBuildFile; fileRef = B559986B0EC616B3008DD061 /* SDLMain.m */; settings = {COMPILER_FLAGS = "-w"; }; };
|
||||
B55998F80EC61EA5008DD061 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL.framework */; };
|
||||
B55999250EC61F59008DD061 /* SDL_image.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999220EC61F59008DD061 /* SDL_image.framework */; };
|
||||
B55999260EC61F59008DD061 /* SDL_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL_net.framework */; };
|
||||
B55999270EC61F59008DD061 /* SDL_mixer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999240EC61F59008DD061 /* SDL_mixer.framework */; };
|
||||
B55998F80EC61EA5008DD061 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL2.framework */; };
|
||||
B55999250EC61F59008DD061 /* SDL2_image.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999220EC61F59008DD061 /* SDL2_image.framework */; };
|
||||
B55999260EC61F59008DD061 /* SDL2_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL2_net.framework */; };
|
||||
B55999270EC61F59008DD061 /* SDL2_mixer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999240EC61F59008DD061 /* SDL2_mixer.framework */; };
|
||||
B5599AD30EC62181008DD061 /* wml_exception.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999430EC62181008DD061 /* wml_exception.cpp */; };
|
||||
B5599AD40EC62181008DD061 /* button.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999450EC62181008DD061 /* button.cpp */; };
|
||||
B5599AD50EC62181008DD061 /* combo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999470EC62181008DD061 /* combo.cpp */; };
|
||||
|
@ -399,11 +401,11 @@
|
|||
B5599B8B0EC62181008DD061 /* about.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599AC60EC62181008DD061 /* about.cpp */; };
|
||||
B5599B8E0EC62181008DD061 /* attack_prediction_display.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599ACA0EC62181008DD061 /* attack_prediction_display.cpp */; };
|
||||
B5599B910EC62181008DD061 /* attack_prediction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599AD00EC62181008DD061 /* attack_prediction.cpp */; };
|
||||
B5599E8B0EC64CF2008DD061 /* SDL.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL.framework */; };
|
||||
B5599E8C0EC64CF2008DD061 /* SDL_image.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55999220EC61F59008DD061 /* SDL_image.framework */; };
|
||||
B5599E8D0EC64CF2008DD061 /* SDL_net.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL_net.framework */; };
|
||||
B5599E8E0EC64CF2008DD061 /* SDL_mixer.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55999240EC61F59008DD061 /* SDL_mixer.framework */; };
|
||||
B5599E9C0EC68BF2008DD061 /* SDL_ttf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5599E9B0EC68BF2008DD061 /* SDL_ttf.framework */; };
|
||||
B5599E8B0EC64CF2008DD061 /* SDL2.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL2.framework */; };
|
||||
B5599E8C0EC64CF2008DD061 /* SDL2_image.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55999220EC61F59008DD061 /* SDL2_image.framework */; };
|
||||
B5599E8D0EC64CF2008DD061 /* SDL2_net.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL2_net.framework */; };
|
||||
B5599E8E0EC64CF2008DD061 /* SDL2_mixer.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B55999240EC61F59008DD061 /* SDL2_mixer.framework */; };
|
||||
B5599E9C0EC68BF2008DD061 /* SDL2_ttf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5599E9B0EC68BF2008DD061 /* SDL2_ttf.framework */; };
|
||||
B5599FCB0EC8FBCB008DD061 /* libfreetype.6.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B5599FC90EC8FBCB008DD061 /* libfreetype.6.dylib */; };
|
||||
B559A0140EC8FE2E008DD061 /* editor_display.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599FFF0EC8FE2E008DD061 /* editor_display.cpp */; };
|
||||
B559A0160EC8FE2E008DD061 /* editor_main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B559A0030EC8FE2E008DD061 /* editor_main.cpp */; };
|
||||
|
@ -471,11 +473,11 @@
|
|||
B597C51D0FACD56200CE81F5 /* libcairo.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B513B2270ED36BFB0006E551 /* libcairo.2.dylib */; };
|
||||
B597C51E0FACD56600CE81F5 /* libpixman-1.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B513B2280ED36BFB0006E551 /* libpixman-1.0.dylib */; };
|
||||
B597C51F0FACD56A00CE81F5 /* libfreetype.6.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B5599FC90EC8FBCB008DD061 /* libfreetype.6.dylib */; };
|
||||
B597C5260FACD58400CE81F5 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL.framework */; };
|
||||
B597C5270FACD58400CE81F5 /* SDL_ttf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5599E9B0EC68BF2008DD061 /* SDL_ttf.framework */; };
|
||||
B597C5280FACD58400CE81F5 /* SDL_image.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999220EC61F59008DD061 /* SDL_image.framework */; };
|
||||
B597C5290FACD58400CE81F5 /* SDL_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL_net.framework */; };
|
||||
B597C52A0FACD58400CE81F5 /* SDL_mixer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999240EC61F59008DD061 /* SDL_mixer.framework */; };
|
||||
B597C5260FACD58400CE81F5 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL2.framework */; };
|
||||
B597C5270FACD58400CE81F5 /* SDL2_ttf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5599E9B0EC68BF2008DD061 /* SDL2_ttf.framework */; };
|
||||
B597C5280FACD58400CE81F5 /* SDL2_image.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999220EC61F59008DD061 /* SDL2_image.framework */; };
|
||||
B597C5290FACD58400CE81F5 /* SDL2_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL2_net.framework */; };
|
||||
B597C52A0FACD58400CE81F5 /* SDL2_mixer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999240EC61F59008DD061 /* SDL2_mixer.framework */; };
|
||||
B597C5310FACD6CA00CE81F5 /* callable_objects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599AB00EC62181008DD061 /* callable_objects.cpp */; };
|
||||
B597C5330FACD6CA00CE81F5 /* generator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5795A670F05858100EB190E /* generator.cpp */; };
|
||||
B597C5340FACD6CA00CE81F5 /* cursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599A9D0EC62181008DD061 /* cursor.cpp */; };
|
||||
|
@ -724,8 +726,8 @@
|
|||
B5BB6B8B0F893E7500444FBF /* ban.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5BB6B7C0F893E7500444FBF /* ban.cpp */; };
|
||||
B5BB6B8D0F893F2300444FBF /* config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599AA80EC62181008DD061 /* config.cpp */; };
|
||||
B5BB6BC60F89406100444FBF /* network.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999DA0EC62181008DD061 /* network.cpp */; };
|
||||
B5BB6BC80F89407D00444FBF /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL.framework */; };
|
||||
B5BB6BCB0F89408500444FBF /* SDL_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL_net.framework */; };
|
||||
B5BB6BC80F89407D00444FBF /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL2.framework */; };
|
||||
B5BB6BCB0F89408500444FBF /* SDL2_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL2_net.framework */; };
|
||||
B5BB6BCD0F8940A000444FBF /* network_worker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999D60EC62181008DD061 /* network_worker.cpp */; };
|
||||
B5BB6C670F8940FF00444FBF /* thread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B559998B0EC62181008DD061 /* thread.cpp */; };
|
||||
B5BB6C6F0F8941CD00444FBF /* game_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599A800EC62181008DD061 /* game_config.cpp */; };
|
||||
|
@ -1089,11 +1091,11 @@
|
|||
91B6221A1B76C0A600B00E0F /* libpixman-1.0.dylib in CopyFiles */,
|
||||
91B6221B1B76C0A600B00E0F /* libpng16.16.dylib in CopyFiles */,
|
||||
91B6221C1B76C0A600B00E0F /* libz.1.dylib in CopyFiles */,
|
||||
B5599E8C0EC64CF2008DD061 /* SDL_image.framework in CopyFiles */,
|
||||
B5599E8E0EC64CF2008DD061 /* SDL_mixer.framework in CopyFiles */,
|
||||
B5599E8D0EC64CF2008DD061 /* SDL_net.framework in CopyFiles */,
|
||||
B513B2790ED372210006E551 /* SDL_ttf.framework in CopyFiles */,
|
||||
B5599E8B0EC64CF2008DD061 /* SDL.framework in CopyFiles */,
|
||||
B5599E8C0EC64CF2008DD061 /* SDL2_image.framework in CopyFiles */,
|
||||
B5599E8E0EC64CF2008DD061 /* SDL2_mixer.framework in CopyFiles */,
|
||||
B5599E8D0EC64CF2008DD061 /* SDL2_net.framework in CopyFiles */,
|
||||
B513B2790ED372210006E551 /* SDL2_ttf.framework in CopyFiles */,
|
||||
B5599E8B0EC64CF2008DD061 /* SDL2.framework in CopyFiles */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1247,6 +1249,11 @@
|
|||
62E4824F154D865E001DD4FC /* pane.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = pane.hpp; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
8D1107320486CEB800E47090 /* Wesnoth.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Wesnoth.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
911F2DAB1BA086A400E3102E /* window.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = window.cpp; sourceTree = "<group>"; };
|
||||
911F2DAC1BA086A400E3102E /* window.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = window.hpp; sourceTree = "<group>"; };
|
||||
911F2DAE1BA086F900E3102E /* alpha.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = alpha.cpp; sourceTree = "<group>"; };
|
||||
911F2DAF1BA086FA00E3102E /* alpha.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alpha.hpp; sourceTree = "<group>"; };
|
||||
911F2DB11BA0870E00E3102E /* compat.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = compat.hpp; sourceTree = "<group>"; };
|
||||
919B37F71BAF789D00E0094C /* synced_user_choice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = synced_user_choice.cpp; sourceTree = "<group>"; };
|
||||
919B37F91BAF78AB00E0094C /* synced_user_choice.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = synced_user_choice.hpp; sourceTree = "<group>"; };
|
||||
919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = synced_choice_wait.cpp; sourceTree = "<group>"; };
|
||||
|
@ -1552,10 +1559,10 @@
|
|||
B553B6B912189C5900CC8C58 /* utility.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utility.hpp; sourceTree = "<group>"; };
|
||||
B559986A0EC616B3008DD061 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDLMain.h; path = "Mac Sources/SDLMain.h"; sourceTree = "<group>"; };
|
||||
B559986B0EC616B3008DD061 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLMain.m; path = "Mac Sources/SDLMain.m"; sourceTree = "<group>"; };
|
||||
B55998F70EC61EA5008DD061 /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = lib/SDL.framework; sourceTree = "<group>"; };
|
||||
B55999220EC61F59008DD061 /* SDL_image.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL_image.framework; path = lib/SDL_image.framework; sourceTree = "<group>"; };
|
||||
B55999230EC61F59008DD061 /* SDL_net.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL_net.framework; path = lib/SDL_net.framework; sourceTree = "<group>"; };
|
||||
B55999240EC61F59008DD061 /* SDL_mixer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL_mixer.framework; path = lib/SDL_mixer.framework; sourceTree = "<group>"; };
|
||||
B55998F70EC61EA5008DD061 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = lib/SDL2.framework; sourceTree = "<group>"; };
|
||||
B55999220EC61F59008DD061 /* SDL2_image.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_image.framework; path = lib/SDL2_image.framework; sourceTree = "<group>"; };
|
||||
B55999230EC61F59008DD061 /* SDL2_net.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_net.framework; path = lib/SDL2_net.framework; sourceTree = "<group>"; };
|
||||
B55999240EC61F59008DD061 /* SDL2_mixer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_mixer.framework; path = lib/SDL2_mixer.framework; sourceTree = "<group>"; };
|
||||
B55999410EC62181008DD061 /* wml_separators.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = wml_separators.hpp; path = ../src/wml_separators.hpp; sourceTree = "<group>"; };
|
||||
B55999420EC62181008DD061 /* wml_exception.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = wml_exception.hpp; path = ../src/wml_exception.hpp; sourceTree = "<group>"; };
|
||||
B55999430EC62181008DD061 /* wml_exception.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = wml_exception.cpp; path = ../src/wml_exception.cpp; sourceTree = "<group>"; };
|
||||
|
@ -1777,7 +1784,7 @@
|
|||
B5599ACA0EC62181008DD061 /* attack_prediction_display.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = attack_prediction_display.cpp; path = ../src/attack_prediction_display.cpp; sourceTree = "<group>"; };
|
||||
B5599ACB0EC62181008DD061 /* attack_prediction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = attack_prediction.hpp; path = ../src/attack_prediction.hpp; sourceTree = "<group>"; };
|
||||
B5599AD00EC62181008DD061 /* attack_prediction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = attack_prediction.cpp; path = ../src/attack_prediction.cpp; sourceTree = "<group>"; };
|
||||
B5599E9B0EC68BF2008DD061 /* SDL_ttf.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL_ttf.framework; path = lib/SDL_ttf.framework; sourceTree = "<group>"; };
|
||||
B5599E9B0EC68BF2008DD061 /* SDL2_ttf.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_ttf.framework; path = lib/SDL2_ttf.framework; sourceTree = "<group>"; };
|
||||
B5599FC90EC8FBCB008DD061 /* libfreetype.6.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libfreetype.6.dylib; path = lib/libfreetype.6.dylib; sourceTree = "<group>"; };
|
||||
B5599FFC0EC8FE2E008DD061 /* editor_common.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = editor_common.hpp; sourceTree = "<group>"; };
|
||||
B5599FFF0EC8FE2E008DD061 /* editor_display.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = editor_display.cpp; sourceTree = "<group>"; };
|
||||
|
@ -2463,11 +2470,11 @@
|
|||
EC1D88DB18EF413100E66AC1 /* libpixman-1.0.dylib in Frameworks */,
|
||||
EC5C244A18EF07B4001FA499 /* libpng16.16.dylib in Frameworks */,
|
||||
EC5C245318EF07B4001FA499 /* libz.1.dylib in Frameworks */,
|
||||
B55999250EC61F59008DD061 /* SDL_image.framework in Frameworks */,
|
||||
B55999270EC61F59008DD061 /* SDL_mixer.framework in Frameworks */,
|
||||
B55999260EC61F59008DD061 /* SDL_net.framework in Frameworks */,
|
||||
B5599E9C0EC68BF2008DD061 /* SDL_ttf.framework in Frameworks */,
|
||||
B55998F80EC61EA5008DD061 /* SDL.framework in Frameworks */,
|
||||
B55999250EC61F59008DD061 /* SDL2_image.framework in Frameworks */,
|
||||
B55999270EC61F59008DD061 /* SDL2_mixer.framework in Frameworks */,
|
||||
B55999260EC61F59008DD061 /* SDL2_net.framework in Frameworks */,
|
||||
B5599E9C0EC68BF2008DD061 /* SDL2_ttf.framework in Frameworks */,
|
||||
B55998F80EC61EA5008DD061 /* SDL2.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2479,11 +2486,11 @@
|
|||
B597C51D0FACD56200CE81F5 /* libcairo.2.dylib in Frameworks */,
|
||||
B597C51F0FACD56A00CE81F5 /* libfreetype.6.dylib in Frameworks */,
|
||||
B597C51E0FACD56600CE81F5 /* libpixman-1.0.dylib in Frameworks */,
|
||||
B597C5280FACD58400CE81F5 /* SDL_image.framework in Frameworks */,
|
||||
B597C52A0FACD58400CE81F5 /* SDL_mixer.framework in Frameworks */,
|
||||
B597C5290FACD58400CE81F5 /* SDL_net.framework in Frameworks */,
|
||||
B597C5270FACD58400CE81F5 /* SDL_ttf.framework in Frameworks */,
|
||||
B597C5260FACD58400CE81F5 /* SDL.framework in Frameworks */,
|
||||
B597C5280FACD58400CE81F5 /* SDL2_image.framework in Frameworks */,
|
||||
B597C52A0FACD58400CE81F5 /* SDL2_mixer.framework in Frameworks */,
|
||||
B597C5290FACD58400CE81F5 /* SDL2_net.framework in Frameworks */,
|
||||
B597C5270FACD58400CE81F5 /* SDL2_ttf.framework in Frameworks */,
|
||||
B597C5260FACD58400CE81F5 /* SDL2.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2498,8 +2505,8 @@
|
|||
EC64D7681A085F4A0092EF75 /* libboost_randomw.dylib in Frameworks */,
|
||||
ECF9D44219F4050E00E6C9D9 /* libboost_systemw.dylib in Frameworks */,
|
||||
EC225C9718EF0ABC00025EC4 /* libintl.8.dylib in Frameworks */,
|
||||
B5BB6BCB0F89408500444FBF /* SDL_net.framework in Frameworks */,
|
||||
B5BB6BC80F89407D00444FBF /* SDL.framework in Frameworks */,
|
||||
B5BB6BCB0F89408500444FBF /* SDL2_net.framework in Frameworks */,
|
||||
B5BB6BC80F89407D00444FBF /* SDL2.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2532,11 +2539,11 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
B508D13E10013BF900B12852 /* Growl.framework */,
|
||||
B55999220EC61F59008DD061 /* SDL_image.framework */,
|
||||
B55999240EC61F59008DD061 /* SDL_mixer.framework */,
|
||||
B55999230EC61F59008DD061 /* SDL_net.framework */,
|
||||
B5599E9B0EC68BF2008DD061 /* SDL_ttf.framework */,
|
||||
B55998F70EC61EA5008DD061 /* SDL.framework */,
|
||||
B55999220EC61F59008DD061 /* SDL2_image.framework */,
|
||||
B55999240EC61F59008DD061 /* SDL2_mixer.framework */,
|
||||
B55999230EC61F59008DD061 /* SDL2_net.framework */,
|
||||
B5599E9B0EC68BF2008DD061 /* SDL2_ttf.framework */,
|
||||
B55998F70EC61EA5008DD061 /* SDL2.framework */,
|
||||
);
|
||||
name = "Included Frameworks";
|
||||
sourceTree = "<group>";
|
||||
|
@ -3260,6 +3267,9 @@
|
|||
91B621A61B76A7CD00B00E0F /* sdl */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
911F2DAE1BA086F900E3102E /* alpha.cpp */,
|
||||
911F2DAF1BA086FA00E3102E /* alpha.hpp */,
|
||||
911F2DB11BA0870E00E3102E /* compat.hpp */,
|
||||
EC84246F18F30DB700FC1EEF /* exception.cpp */,
|
||||
EC84247018F30DB700FC1EEF /* exception.hpp */,
|
||||
ECFB9FAB193BFB6E00146ED0 /* rect.cpp */,
|
||||
|
@ -3268,6 +3278,8 @@
|
|||
EC2F60231A04985A0018C9D6 /* savepng.h */,
|
||||
EC28C58D19423426003B0F5E /* utils.cpp */,
|
||||
EC28C58E19423426003B0F5E /* utils.hpp */,
|
||||
911F2DAB1BA086A400E3102E /* window.cpp */,
|
||||
911F2DAC1BA086A400E3102E /* window.hpp */,
|
||||
);
|
||||
path = sdl;
|
||||
sourceTree = "<group>";
|
||||
|
@ -5010,6 +5022,8 @@
|
|||
91B621BA1B76B2C900B00E0F /* version.cpp in Sources */,
|
||||
91ECD5D21BA11A5200B25CF1 /* unit_creator.cpp in Sources */,
|
||||
91ECD5D51BA11A6400B25CF1 /* mp_replay_controller.cpp in Sources */,
|
||||
911F2DAD1BA086A400E3102E /* window.cpp in Sources */,
|
||||
911F2DB01BA086FA00E3102E /* alpha.cpp in Sources */,
|
||||
919B37F81BAF789E00E0094C /* synced_user_choice.cpp in Sources */,
|
||||
919B37FC1BAF7A9D00E0094C /* synced_choice_wait.cpp in Sources */,
|
||||
);
|
||||
|
@ -5636,11 +5650,11 @@
|
|||
./Headers/lua_5.1.4,
|
||||
"./Headers/glib-2.0",
|
||||
./Headers/cairo,
|
||||
./lib/SDL.framework/Headers,
|
||||
./lib/SDL_ttf.framework/Headers,
|
||||
./lib/SDL_image.framework/Headers,
|
||||
./lib/SDL_mixer.framework/Headers,
|
||||
./lib/SDL_net.framework/Headers,
|
||||
./lib/SDL2.framework/Headers,
|
||||
./lib/SDL2_ttf.framework/Headers,
|
||||
./lib/SDL2_image.framework/Headers,
|
||||
./lib/SDL2_mixer.framework/Headers,
|
||||
./lib/SDL2_net.framework/Headers,
|
||||
);
|
||||
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
|
||||
LIBRARY_SEARCH_PATHS = ./lib;
|
||||
|
@ -5682,11 +5696,11 @@
|
|||
./Headers/lua_5.1.4,
|
||||
"./Headers/glib-2.0",
|
||||
./Headers/cairo,
|
||||
./lib/SDL.framework/Headers,
|
||||
./lib/SDL_ttf.framework/Headers,
|
||||
./lib/SDL_image.framework/Headers,
|
||||
./lib/SDL_mixer.framework/Headers,
|
||||
./lib/SDL_net.framework/Headers,
|
||||
./lib/SDL2.framework/Headers,
|
||||
./lib/SDL2_ttf.framework/Headers,
|
||||
./lib/SDL2_image.framework/Headers,
|
||||
./lib/SDL2_mixer.framework/Headers,
|
||||
./lib/SDL2_net.framework/Headers,
|
||||
);
|
||||
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
|
||||
LIBRARY_SEARCH_PATHS = ./lib;
|
||||
|
|
|
@ -450,6 +450,7 @@ set(wesnoth-sdl_SRC
|
|||
sdl/window.cpp
|
||||
sdl/utils.cpp
|
||||
sdl/shader.cpp
|
||||
sdl/keyboard.cpp
|
||||
xBRZ/xbrz.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -172,6 +172,7 @@ libwesnoth_sdl_sources = Split("""
|
|||
sdl/exception.cpp
|
||||
sdl/rect.cpp
|
||||
sdl/image.cpp
|
||||
sdl/keyboard.cpp
|
||||
sdl/window.cpp
|
||||
tracer.cpp
|
||||
xBRZ/xbrz.cpp
|
||||
|
|
|
@ -217,7 +217,7 @@ void show_about(display &disp, const std::string &campaign)
|
|||
{
|
||||
boost::scoped_ptr<cursor::setter> cur(new cursor::setter(cursor::WAIT));
|
||||
CVideo &video = disp.video();
|
||||
surface screen = video.getSurface();
|
||||
surface& screen = video.getSurface();
|
||||
if (screen == NULL) return;
|
||||
|
||||
// If the title is multi-line, we need to split it accordingly or we
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
#include "formula_callable.hpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER < 1600
|
||||
// SDL2 uses [dfi]vec.h which used to define EXPLICIT
|
||||
#undef EXPLICIT
|
||||
#endif
|
||||
#pragma warning(push)
|
||||
//silence "inherits via dominance" warnings
|
||||
#pragma warning(disable:4250)
|
||||
|
|
|
@ -344,7 +344,7 @@ void battle_prediction_pane::draw_unit(int x_off, int damage_line_skip, int left
|
|||
const std::string& label, int label_width,
|
||||
surface& hp_distrib, int hp_distrib_width)
|
||||
{
|
||||
surface screen = resources::screen->get_screen_surface();
|
||||
surface& screen = resources::screen->get_screen_surface();
|
||||
int i;
|
||||
|
||||
// NOTE. A preview pane is not made to be used alone and it is not
|
||||
|
@ -435,9 +435,9 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
|
|||
SDL_SetAlpha(surf, 0, SDL_ALPHA_OPAQUE);
|
||||
|
||||
SDL_Rect clip_rect = sdl::create_rect(0, 0, width, height);
|
||||
Uint32 grey_color = SDL_MapRGBA(surf->format, 0xb7, 0xc1, 0xc1, 255);
|
||||
Uint32 grey_color = SDL_MapRGBA(surf->format, 0xb7, 0xc1, 0xc1, SDL_ALPHA_OPAQUE);
|
||||
|
||||
Uint32 background_color = SDL_MapRGBA(surf->format, 25, 25, 25, 255);
|
||||
Uint32 background_color = SDL_MapRGBA(surf->format, 25, 25, 25, SDL_ALPHA_OPAQUE);
|
||||
sdl::fill_rect(surf, &clip_rect, background_color);
|
||||
|
||||
// Draw the surrounding borders and separators.
|
||||
|
@ -471,7 +471,7 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
|
|||
|
||||
// Death line is red.
|
||||
if(hp == 0) {
|
||||
SDL_Color color = {0xe5, 0, 0, 0};
|
||||
SDL_Color color = {0xe5, 0, 0, SDL_ALPHA_OPAQUE};
|
||||
row_color = color;
|
||||
}
|
||||
|
||||
|
@ -479,17 +479,17 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
|
|||
else if(hp < static_cast<int>(stats.hp)) {
|
||||
// Stone is grey.
|
||||
if(opp_stats.petrifies) {
|
||||
SDL_Color color = {0x9a, 0x9a, 0x9a, 0};
|
||||
SDL_Color color = {0x9a, 0x9a, 0x9a, SDL_ALPHA_OPAQUE};
|
||||
row_color = color;
|
||||
} else {
|
||||
SDL_Color color = {0xf4, 0xc9, 0, 0};
|
||||
SDL_Color color = {0xf4, 0xc9, 0, SDL_ALPHA_OPAQUE};
|
||||
row_color = color;
|
||||
}
|
||||
}
|
||||
|
||||
// Current hitpoints value and above is green.
|
||||
else {
|
||||
SDL_Color color = {0x08, 0xca, 0, 0};
|
||||
SDL_Color color = {0x08, 0xca, 0, SDL_ALPHA_OPAQUE};
|
||||
row_color = color;
|
||||
}
|
||||
|
||||
|
@ -518,16 +518,16 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
|
|||
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 0));
|
||||
#else
|
||||
SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8);
|
||||
sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 100));
|
||||
sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 100));
|
||||
|
||||
SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6);
|
||||
sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 66));
|
||||
SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6);
|
||||
sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 66));
|
||||
|
||||
SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4);
|
||||
sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 33));
|
||||
SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4);
|
||||
sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 33));
|
||||
|
||||
SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2);
|
||||
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 0));
|
||||
SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2);
|
||||
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 0));
|
||||
#endif
|
||||
|
||||
// Draw probability percentage, aligned right.
|
||||
|
@ -553,5 +553,3 @@ attack_prediction_displayer::RESULT attack_prediction_displayer::button_pressed(
|
|||
|
||||
return gui::CONTINUE_DIALOG;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -49,14 +49,20 @@ void controller_base::handle_event(const SDL_Event& event)
|
|||
if(gui::in_dialog()) {
|
||||
return;
|
||||
}
|
||||
static const hotkey::hotkey_command& quit_hotkey = hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_QUIT_GAME);
|
||||
|
||||
switch(event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
// Detect key press events, unless there something that has keyboard focus
|
||||
// in which case the key press events should go only to it.
|
||||
if(have_keyboard_focus()) {
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
hotkey::execute_command(get_display(), quit_hotkey, get_hotkey_command_executor());
|
||||
break;
|
||||
}
|
||||
|
||||
process_keydown_event(event);
|
||||
hotkey::key_event(get_display(), event.key, get_hotkey_command_executor());
|
||||
hotkey::key_event(get_display(), event, get_hotkey_command_executor());
|
||||
} else {
|
||||
process_focus_keydown_event(event);
|
||||
break;
|
||||
|
@ -67,11 +73,11 @@ void controller_base::handle_event(const SDL_Event& event)
|
|||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
process_keydown_event(event);
|
||||
hotkey::jbutton_event(get_display(), event.jbutton, get_hotkey_command_executor());
|
||||
hotkey::jbutton_event(get_display(), event, get_hotkey_command_executor());
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
process_keydown_event(event);
|
||||
hotkey::jhat_event(get_display(), event.jhat, get_hotkey_command_executor());
|
||||
hotkey::jhat_event(get_display(), event, get_hotkey_command_executor());
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
// Ignore old mouse motion events in the event queue
|
||||
|
@ -91,7 +97,7 @@ void controller_base::handle_event(const SDL_Event& event)
|
|||
if (get_mouse_handler_base().get_show_menu()){
|
||||
show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display());
|
||||
}
|
||||
hotkey::mbutton_event(get_display(), event.button, get_hotkey_command_executor());
|
||||
hotkey::mbutton_event(get_display(), event, get_hotkey_command_executor());
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
get_mouse_handler_base().mouse_press(event.button, is_browsing());
|
||||
|
|
|
@ -108,7 +108,7 @@ protected:
|
|||
|
||||
/**
|
||||
* Process mouse- and keypress-events from SDL.
|
||||
* Not virtual but calls various virtual function to allow specialized
|
||||
* Calls various virtual function to allow specialized
|
||||
* behavior of derived classes.
|
||||
*/
|
||||
void handle_event(const SDL_Event& event);
|
||||
|
|
|
@ -26,10 +26,15 @@
|
|||
#include "video.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
#include <boost/logic/tribool.hpp>
|
||||
using boost::logic::tribool;
|
||||
using boost::logic::indeterminate;
|
||||
#endif
|
||||
|
||||
static bool use_color_cursors()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
#if defined(__APPLE__) && !SDL_VERSION_ATLEAST(2,0,0)
|
||||
// Color cursors on OS X are known to be unusable, so don't use them ever.
|
||||
// See bug #18112.
|
||||
return false;
|
||||
|
@ -87,6 +92,12 @@ static SDL_Cursor* create_cursor(surface surf)
|
|||
namespace {
|
||||
|
||||
SDL_Cursor* cache[cursor::NUM_CURSORS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
tribool cache_color[cursor::NUM_CURSORS] = {
|
||||
indeterminate, indeterminate, indeterminate, indeterminate,
|
||||
indeterminate, indeterminate, indeterminate, indeterminate,
|
||||
};
|
||||
#endif
|
||||
|
||||
// This array must have members corresponding to cursor::CURSOR_TYPE enum members
|
||||
// Apple need 16x16 b&w cursors
|
||||
|
@ -99,25 +110,42 @@ const std::string bw_images[cursor::NUM_CURSORS] = { "normal.png", "wait.png", "
|
|||
const std::string color_images[cursor::NUM_CURSORS] = { "normal.png", "wait.png", "move.png", "attack.png", "select.png", "move_drag.png", "attack_drag.png", ""};
|
||||
|
||||
// Position of the hotspot of the cursor, from the normal topleft
|
||||
// These are only for the color cursors
|
||||
const int shift_x[cursor::NUM_CURSORS] = {0, 0, 0, 0, 0, 2, 3, 0};
|
||||
const int shift_y[cursor::NUM_CURSORS] = {0, 0, 0, 0, 0, 20, 22, 0};
|
||||
|
||||
cursor::CURSOR_TYPE current_cursor = cursor::NORMAL;
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
int cursor_x = -1, cursor_y = -1;
|
||||
surface cursor_buf = NULL;
|
||||
bool have_focus = true;
|
||||
bool color_ready = false;
|
||||
#endif
|
||||
bool have_focus = true;
|
||||
|
||||
}
|
||||
|
||||
static SDL_Cursor* get_cursor(cursor::CURSOR_TYPE type)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
bool is_color = use_color_cursors();
|
||||
if(cache[type] == NULL || indeterminate(cache_color[type]) || cache_color[type] != is_color) {
|
||||
const std::string prefix = is_color ? "cursors/" : "cursors-bw/";
|
||||
const surface surf(image::get_image(prefix + (is_color ? color_images : bw_images)[type]));
|
||||
if (is_color) {
|
||||
cache[type] = SDL_CreateColorCursor(surf.get(), shift_x[type], shift_y[type]);
|
||||
} else {
|
||||
cache[type] = create_cursor(surf);
|
||||
}
|
||||
cache_color[type] = is_color;
|
||||
}
|
||||
#else
|
||||
if(cache[type] == NULL) {
|
||||
static const std::string prefix = "cursors-bw/";
|
||||
const surface surf(image::get_image(prefix + bw_images[type]));
|
||||
cache[type] = create_cursor(surf);
|
||||
}
|
||||
#endif
|
||||
|
||||
return cache[type];
|
||||
}
|
||||
|
@ -130,10 +158,11 @@ static void clear_cache()
|
|||
cache[n] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
if(cursor_buf != NULL) {
|
||||
cursor_buf = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace cursor
|
||||
|
@ -162,9 +191,13 @@ void set(CURSOR_TYPE type)
|
|||
current_cursor = NORMAL;
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
SDL_Cursor * cursor_image = get_cursor(current_cursor);
|
||||
#else
|
||||
const CURSOR_TYPE new_cursor = use_color_cursors() && color_ready ? cursor::NO_CURSOR : current_cursor;
|
||||
|
||||
SDL_Cursor * cursor_image = get_cursor(new_cursor);
|
||||
#endif
|
||||
|
||||
// Causes problem on Mac:
|
||||
//if (cursor_image != NULL && cursor_image != SDL_GetCursor())
|
||||
|
@ -202,7 +235,9 @@ void set_focus(bool focus)
|
|||
{
|
||||
have_focus = focus;
|
||||
if (focus==false) {
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
color_ready = false;
|
||||
#endif
|
||||
set();
|
||||
}
|
||||
}
|
||||
|
@ -217,6 +252,7 @@ setter::~setter()
|
|||
set(old_);
|
||||
}
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
void draw(surface screen)
|
||||
{
|
||||
if(use_color_cursors() == false) {
|
||||
|
@ -240,7 +276,8 @@ void draw(surface screen)
|
|||
set();
|
||||
}
|
||||
|
||||
/** @todo FIXME: don't parse the file path every time */
|
||||
/** @todo FIXME: don't parse the file path every time
|
||||
*/
|
||||
const surface surf(image::get_image("cursors/" + color_images[current_cursor]));
|
||||
if(surf == NULL) {
|
||||
// Fall back to b&w cursors
|
||||
|
@ -272,7 +309,7 @@ void draw(surface screen)
|
|||
, cursor_y - shift_y[current_cursor]
|
||||
, surf->w
|
||||
, surf->h);
|
||||
sdl_blit(screen,&area,cursor_buf,NULL);
|
||||
sdl_copy_portion(screen,&area,cursor_buf,NULL);
|
||||
|
||||
// Blit the surface
|
||||
sdl_blit(surf,NULL,screen,&area);
|
||||
|
@ -299,6 +336,7 @@ void undraw(surface screen)
|
|||
sdl_blit(cursor_buf,NULL,screen,&area);
|
||||
update_rect(area);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace cursor
|
||||
|
||||
|
|
|
@ -38,8 +38,11 @@ void set(CURSOR_TYPE type = NUM_CURSORS);
|
|||
void set_dragging(bool drag);
|
||||
CURSOR_TYPE get();
|
||||
|
||||
// These aren't used, but leaving the prototypes doesn't hurt and allows avoiding an SDL include
|
||||
//#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
void draw(surface screen);
|
||||
void undraw(surface screen);
|
||||
//#endif
|
||||
|
||||
void set_focus(bool focus);
|
||||
|
||||
|
|
|
@ -715,7 +715,7 @@ void save_preview_pane::draw_contents()
|
|||
return;
|
||||
}
|
||||
|
||||
surface screen = video().getSurface();
|
||||
surface& screen = video().getSurface();
|
||||
|
||||
SDL_Rect const &loc = location();
|
||||
const SDL_Rect area = sdl::create_rect(loc.x + save_preview_border
|
||||
|
@ -1130,7 +1130,7 @@ void unit_preview_pane::draw_contents()
|
|||
|
||||
GPU_UnsetClip(get_render_target());
|
||||
#else
|
||||
surface screen(video().getSurface());
|
||||
surface& screen(video().getSurface());
|
||||
const clip_rect_setter clipper(screen, &area);
|
||||
|
||||
surface unit_image = det.image;
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
#include <cmath>
|
||||
|
||||
// Includes for bug #17573
|
||||
#if defined(__GLIBC__)
|
||||
#if defined(__GLIBC__) && !SDL_VERSION_ATLEAST(2,0,0)
|
||||
#include <gnu/libc-version.h>
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
@ -225,7 +225,7 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
|
|||
, update_panel_image_(true),
|
||||
panel_image_()
|
||||
#endif
|
||||
#if defined(__GLIBC__)
|
||||
#if defined(__GLIBC__) && !SDL_VERSION_ATLEAST(2,0,0)
|
||||
, do_reverse_memcpy_workaround_(false)
|
||||
#endif
|
||||
{
|
||||
|
@ -769,7 +769,7 @@ bool display::screenshot(const std::string& filename, bool map_screenshot)
|
|||
bool res = false;
|
||||
|
||||
if (!map_screenshot) {
|
||||
surface screenshot_surf = screen_.getSurface();
|
||||
surface& screenshot_surf = screen_.getSurface();
|
||||
|
||||
res = image::save_image(screenshot_surf, filename);
|
||||
#if 0
|
||||
|
@ -1336,7 +1336,7 @@ void display::drawing_buffer_commit()
|
|||
GPU_UnsetClip(get_render_target());
|
||||
#else
|
||||
SDL_Rect clip_rect = map_area();
|
||||
surface screen = get_screen_surface();
|
||||
surface& screen = get_screen_surface();
|
||||
clip_rect_setter set_clip_rect(screen, &clip_rect);
|
||||
|
||||
/*
|
||||
|
@ -1396,14 +1396,14 @@ void display::flip()
|
|||
return;
|
||||
}
|
||||
|
||||
surface frameBuffer = get_video_surface();
|
||||
surface& frameBuffer = get_video_surface();
|
||||
|
||||
// This is just the debug function "sunset" to progressively darken the map area
|
||||
static size_t sunset_timer = 0;
|
||||
if (sunset_delay && ++sunset_timer > sunset_delay) {
|
||||
sunset_timer = 0;
|
||||
SDL_Rect r = map_outside_area(); // Use frameBuffer to also test the UI
|
||||
const Uint32 color = SDL_MapRGBA(video().getSurface()->format,0,0,0,255);
|
||||
const Uint32 color = SDL_MapRGBA(video().getSurface()->format,0,0,0,SDL_ALPHA_OPAQUE);
|
||||
// Adjust the alpha if you want to balance cpu-cost / smooth sunset
|
||||
sdl::fill_rect_alpha(r, color, 1, frameBuffer);
|
||||
update_rect(r);
|
||||
|
@ -1414,11 +1414,15 @@ void display::flip()
|
|||
font::draw_floating_labels(frameBuffer);
|
||||
#endif
|
||||
events::raise_volatile_draw_event();
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
cursor::draw(frameBuffer);
|
||||
#endif
|
||||
|
||||
video().flip();
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
cursor::undraw(frameBuffer);
|
||||
#endif
|
||||
events::raise_volatile_undraw_event();
|
||||
#ifdef SDL_GPU
|
||||
font::undraw_floating_labels(screen_);
|
||||
|
@ -1829,7 +1833,7 @@ void display::draw_init()
|
|||
#ifdef SDL_GPU
|
||||
draw_background(screen_, clip_rect, theme_.border().background_image);
|
||||
#else
|
||||
const surface screen = get_screen_surface();
|
||||
const surface& screen = get_screen_surface();
|
||||
clip_rect_setter set_clip_rect(screen, &clip_rect);
|
||||
draw_background(screen, clip_rect, theme_.border().background_image);
|
||||
#endif
|
||||
|
@ -2100,7 +2104,7 @@ void display::draw_minimap()
|
|||
const surface& screen(screen_.getSurface());
|
||||
clip_rect_setter clip_setter(screen, &area);
|
||||
|
||||
SDL_Color back_color = {31,31,23,255};
|
||||
SDL_Color back_color = {31,31,23,SDL_ALPHA_OPAQUE};
|
||||
draw_centered_on_background(minimap_, area, back_color, screen);
|
||||
|
||||
//update the minimap location for mouse and units functions
|
||||
|
@ -2216,7 +2220,7 @@ bool display::scroll(int xmove, int ymove, bool force)
|
|||
font::scroll_floating_labels(dx, dy);
|
||||
labels().recalculate_shroud();
|
||||
|
||||
surface screen(screen_.getSurface());
|
||||
surface& screen(screen_.getSurface());
|
||||
|
||||
SDL_Rect dstrect = map_area();
|
||||
dstrect.x += dx;
|
||||
|
@ -2774,7 +2778,7 @@ const map_labels& display::labels() const
|
|||
|
||||
void display::clear_screen()
|
||||
{
|
||||
surface disp(screen_.getSurface());
|
||||
surface& disp(screen_.getSurface());
|
||||
SDL_Rect area = screen_area();
|
||||
sdl::fill_rect(disp, &area, SDL_MapRGB(disp->format, 0, 0, 0));
|
||||
}
|
||||
|
@ -2787,7 +2791,7 @@ const SDL_Rect& display::get_clip_rect()
|
|||
void display::draw_invalidated() {
|
||||
// log_scope("display::draw_invalidated");
|
||||
SDL_Rect clip_rect = get_clip_rect();
|
||||
surface screen = get_screen_surface();
|
||||
surface& screen = get_screen_surface();
|
||||
clip_rect_setter set_clip_rect(screen, &clip_rect);
|
||||
BOOST_FOREACH(const map_location& loc, invalidated_) {
|
||||
int xpos = get_location_x(loc);
|
||||
|
|
|
@ -205,7 +205,7 @@ public:
|
|||
CVideo& video() { return screen_; }
|
||||
|
||||
/** return the screen surface or the surface used for map_screenshot. */
|
||||
surface get_screen_surface() { return map_screenshot_ ? map_screenshot_surf_ : screen_.getSurface();}
|
||||
surface& get_screen_surface() { return map_screenshot_ ? map_screenshot_surf_ : screen_.getSurface();}
|
||||
|
||||
virtual bool in_game() const { return false; }
|
||||
virtual bool in_editor() const { return false; }
|
||||
|
@ -1164,7 +1164,7 @@ private:
|
|||
sdl::timage panel_image_;
|
||||
#endif
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
#if defined(__GLIBC__) && !SDL_VERSION_ATLEAST(2,0,0)
|
||||
/** Flag for bug #17573 - this is set in the constructor **/
|
||||
bool do_reverse_memcpy_workaround_;
|
||||
#endif
|
||||
|
|
|
@ -38,7 +38,7 @@ using boost::uint32_t;
|
|||
namespace {
|
||||
const int chat_message_border = 5;
|
||||
const int chat_message_x = 10;
|
||||
const SDL_Color chat_message_color = {255,255,255,255};
|
||||
const SDL_Color chat_message_color = {255,255,255,SDL_ALPHA_OPAQUE};
|
||||
const SDL_Color chat_message_bg = {0,0,0,140};
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ void display_chat_manager::add_chat_message(const time_t& time, const std::strin
|
|||
ypos += std::max(font::get_floating_label_rect(m->handle).h,
|
||||
font::get_floating_label_rect(m->speaker_handle).h);
|
||||
}
|
||||
SDL_Color speaker_color = {255,255,255,255};
|
||||
SDL_Color speaker_color = {255,255,255,SDL_ALPHA_OPAQUE};
|
||||
if(side >= 1) {
|
||||
speaker_color = int_to_color(team::get_side_color_range(side).mid());
|
||||
}
|
||||
|
|
|
@ -324,7 +324,7 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
|
|||
case HOTKEY_EDITOR_PARTIAL_UNDO:
|
||||
return context_manager_->get_map_context().can_undo();
|
||||
case TITLE_SCREEN__RELOAD_WML:
|
||||
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
|
||||
case HOTKEY_QUIT_TO_DESKTOP:
|
||||
case HOTKEY_EDITOR_CUSTOM_TODS:
|
||||
case HOTKEY_EDITOR_MAP_NEW:
|
||||
case HOTKEY_EDITOR_SCENARIO_NEW:
|
||||
|
@ -722,7 +722,7 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
|
|||
case HOTKEY_QUIT_GAME:
|
||||
quit_confirm(EXIT_NORMAL);
|
||||
return true;
|
||||
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
|
||||
case HOTKEY_QUIT_TO_DESKTOP:
|
||||
quit_confirm(EXIT_QUIT_TO_DESKTOP);
|
||||
return true;
|
||||
case TITLE_SCREEN__RELOAD_WML:
|
||||
|
|
|
@ -166,6 +166,8 @@ context_manager::~context_manager()
|
|||
// Restore default window title
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_WM_SetCaption(default_window_title_.c_str(), NULL);
|
||||
#else
|
||||
CVideo::set_window_title(default_window_title_);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1028,6 +1030,8 @@ void context_manager::set_window_title()
|
|||
const std::string& wm_title_string = map_name + " - " + default_window_title_;
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
|
||||
#else
|
||||
CVideo::set_window_title(wm_title_string);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
namespace editor {
|
||||
|
||||
std::string item_palette::get_help_string() {
|
||||
std::string item_palette::get_help_string()
|
||||
{
|
||||
return selected_fg_item().name;
|
||||
}
|
||||
|
||||
|
@ -58,9 +59,8 @@ void item_palette::setup(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text) {
|
||||
|
||||
surface screen = gui_.video().getSurface();
|
||||
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text)
|
||||
{
|
||||
|
||||
std::stringstream filename;
|
||||
filename << item.image;
|
||||
|
|
|
@ -81,8 +81,6 @@ void unit_palette::setup(const config& /*cfg*/)
|
|||
|
||||
void unit_palette::draw_item(const unit_type& u, surface& image, std::stringstream& tooltip_text) {
|
||||
|
||||
surface screen = gui_.video().getSurface();
|
||||
|
||||
std::stringstream filename;
|
||||
filename << u.image() << "~RC(" << u.flag_rgb() << '>'
|
||||
<< team::get_side_color_index(gui_.viewing_side()) << ')';
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "sound.hpp"
|
||||
#include "quit_confirmation.hpp"
|
||||
#include "video.hpp"
|
||||
#include "display.hpp"
|
||||
#if defined _WIN32
|
||||
#include "desktop/windows_tray_notification.hpp"
|
||||
#endif
|
||||
|
@ -164,13 +165,11 @@ event_context::~event_context()
|
|||
event_contexts.pop_back();
|
||||
}
|
||||
|
||||
sdl_handler::sdl_handler(const bool auto_join)
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
: unicode_(1)
|
||||
#else
|
||||
: unicode_(SDL_EnableUNICODE(1))
|
||||
sdl_handler::sdl_handler(const bool auto_join) :
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
unicode_(SDL_EnableUNICODE(1)),
|
||||
#endif
|
||||
, has_joined_(false)
|
||||
has_joined_(false)
|
||||
{
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
@ -280,7 +279,9 @@ bool has_focus(const sdl_handler* hand, const SDL_Event* event)
|
|||
void pump()
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
peek_for_resize();
|
||||
#endif
|
||||
pump_info info;
|
||||
|
||||
//used to keep track of double click events
|
||||
|
@ -294,6 +295,8 @@ void pump()
|
|||
while(SDL_PollEvent(&temp_event)) {
|
||||
++poll_count;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
peek_for_resize();
|
||||
|
||||
if(!begin_ignoring && temp_event.type == SDL_WINDOWEVENT
|
||||
&& (temp_event.window.event == SDL_WINDOWEVENT_ENTER
|
||||
|| temp_event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED))
|
||||
|
@ -399,6 +402,16 @@ void pump()
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
case SDL_KEYDOWN: {
|
||||
if(event.key.keysym.sym == SDLK_F4 && (event.key.keysym.mod == KMOD_RALT || event.key.keysym.mod == KMOD_LALT)) {
|
||||
quit_confirmation::quit();
|
||||
continue; // this event is already handled
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_X11) && !defined(__APPLE__)
|
||||
case SDL_SYSWMEVENT: {
|
||||
|
@ -518,7 +531,7 @@ int pump_info::ticks(unsigned *refresh_counter, unsigned refresh_rate) {
|
|||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
|
||||
/* The constants for the minimum and maximum are picked from the headers. */
|
||||
#define INPUT_MIN 0x200
|
||||
#define INPUT_MIN 0x300
|
||||
#define INPUT_MAX 0x8FF
|
||||
|
||||
bool is_input(const SDL_Event& event)
|
||||
|
@ -531,6 +544,19 @@ void discard_input()
|
|||
SDL_FlushEvents(INPUT_MIN, INPUT_MAX);
|
||||
}
|
||||
|
||||
void peek_for_resize()
|
||||
{
|
||||
SDL_Event events[100];
|
||||
int num = SDL_PeepEvents(events, 100, SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT);
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (events[i].type == SDL_WINDOWEVENT &&
|
||||
events[i].window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
update_framebuffer();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define INPUT_MASK (SDL_EVENTMASK(SDL_KEYDOWN)|\
|
||||
|
|
|
@ -64,7 +64,9 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
int unicode_;
|
||||
#endif
|
||||
bool has_joined_;
|
||||
};
|
||||
|
||||
|
@ -91,6 +93,11 @@ struct event_context
|
|||
//causes events to be dispatched to all handler objects.
|
||||
void pump();
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
//look for resize events and update references to the screen area
|
||||
void peek_for_resize();
|
||||
#endif
|
||||
|
||||
struct pump_info {
|
||||
pump_info() : resize_dimensions(), ticks_(0) {}
|
||||
std::pair<int,int> resize_dimensions;
|
||||
|
|
|
@ -260,6 +260,10 @@ void floating_label::draw(surface screen)
|
|||
return;
|
||||
}
|
||||
|
||||
if(screen == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
create_surface();
|
||||
if(surf_ == NULL) {
|
||||
return;
|
||||
|
@ -272,13 +276,9 @@ void floating_label::draw(surface screen)
|
|||
}
|
||||
}
|
||||
|
||||
if(screen == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Rect rect = sdl::create_rect(xpos(surf_->w), ypos_, surf_->w, surf_->h);
|
||||
const clip_rect_setter clip_setter(screen, &clip_rect_);
|
||||
sdl_blit(screen,&rect,buf_,NULL);
|
||||
sdl_copy_portion(screen,&rect,buf_,NULL);
|
||||
sdl_blit(surf_,NULL,screen,&rect);
|
||||
|
||||
update_rect(rect);
|
||||
|
|
|
@ -885,7 +885,7 @@ surface get_rendered_text(const std::string& str, int size, const SDL_Color& col
|
|||
return render_text(str, size, color, style, false);
|
||||
}
|
||||
|
||||
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size,
|
||||
SDL_Rect draw_text_line(surface& gui_surface, const SDL_Rect& area, int size,
|
||||
const SDL_Color& color, const std::string& text,
|
||||
int x, int y, bool use_tooltips, int style)
|
||||
{
|
||||
|
|
|
@ -76,7 +76,7 @@ inline int relative_size(int size)
|
|||
// Returns a SDL surface containing the text rendered in a given color.
|
||||
surface get_rendered_text(const std::string& text, int size, const SDL_Color& color, int style=0);
|
||||
|
||||
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size,
|
||||
SDL_Rect draw_text_line(surface& gui_surface, const SDL_Rect& area, int size,
|
||||
const SDL_Color& color, const std::string& text,
|
||||
int x, int y, bool use_tooltips, int style);
|
||||
|
||||
|
|
|
@ -682,7 +682,7 @@ static void enter_lobby_mode(game_display& disp, const config& game_config,
|
|||
, 0
|
||||
, 0
|
||||
, 0
|
||||
, 255);
|
||||
, SDL_ALPHA_OPAQUE);
|
||||
|
||||
sdl::fill_rect(disp.video().getSurface(), NULL, color);
|
||||
|
||||
|
|
|
@ -567,8 +567,8 @@ void configure::layout_children(const SDL_Rect& rect)
|
|||
|
||||
int slider_width = options_pane_left_.width() - 40;
|
||||
|
||||
unsigned int xpos_left = 0;
|
||||
unsigned int ypos_left = 0;
|
||||
int xpos_left = 0;
|
||||
int ypos_left = 0;
|
||||
|
||||
ypos_left += 2 * border_size;
|
||||
options_pane_left_.add_widget(&shuffle_sides_, xpos_left, ypos_left);
|
||||
|
|
|
@ -556,11 +556,11 @@ void create::draw_level_image()
|
|||
engine_.current_level().create_image_surface(image_rect_));
|
||||
|
||||
if (!image.null()) {
|
||||
SDL_Color back_color = {0,0,0,255};
|
||||
SDL_Color back_color = {0,0,0,SDL_ALPHA_OPAQUE};
|
||||
draw_centered_on_background(image, image_rect_, back_color,
|
||||
video().getSurface());
|
||||
} else {
|
||||
surface display(disp_.get_screen_surface());
|
||||
surface& display(disp_.get_screen_surface());
|
||||
sdl::fill_rect(display, &image_rect_,
|
||||
SDL_MapRGB(display->format, 0, 0, 0));
|
||||
update_rect(image_rect_);
|
||||
|
|
|
@ -93,7 +93,7 @@ void wait::leader_preview_pane::draw_contents()
|
|||
{
|
||||
bg_restore();
|
||||
|
||||
surface screen = video().getSurface();
|
||||
surface& screen = video().getSurface();
|
||||
|
||||
SDL_Rect const &loc = location();
|
||||
const SDL_Rect area = sdl::create_rect(loc.x + leader_pane_border,
|
||||
|
@ -362,6 +362,7 @@ void wait::join_game(bool observe)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<gui::preview_pane* > preview_panes;
|
||||
leader_preview_pane leader_selector(disp(), flg, color);
|
||||
preview_panes.push_back(&leader_selector);
|
||||
|
|
|
@ -220,7 +220,7 @@ private:
|
|||
*
|
||||
* @param event The SDL joystick hat event triggered.
|
||||
*/
|
||||
void hat_motion(const SDL_JoyHatEvent& event);
|
||||
void hat_motion(const SDL_Event& event);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -228,7 +228,7 @@ private:
|
|||
*
|
||||
* @param event The SDL joystick button event triggered.
|
||||
*/
|
||||
void button_down(const SDL_JoyButtonEvent& event);
|
||||
void button_down(const SDL_Event& event);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -236,7 +236,7 @@ private:
|
|||
*
|
||||
* @param event The SDL keyboard event triggered.
|
||||
*/
|
||||
void key_down(const SDL_KeyboardEvent& event);
|
||||
void key_down(const SDL_Event& event);
|
||||
|
||||
/**
|
||||
* Handles the pressing of a hotkey.
|
||||
|
@ -245,7 +245,7 @@ private:
|
|||
*
|
||||
* @returns True if the hotkey is handled false otherwise.
|
||||
*/
|
||||
bool hotkey_pressed(const hotkey::hotkey_item& key);
|
||||
bool hotkey_pressed(const hotkey::hotkey_ptr key);
|
||||
|
||||
/**
|
||||
* Fires a key down event.
|
||||
|
@ -372,7 +372,7 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
} break;
|
||||
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
button_down(event.jbutton);
|
||||
button_down(event);
|
||||
break;
|
||||
|
||||
case SDL_JOYBUTTONUP:
|
||||
|
@ -382,11 +382,11 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
break;
|
||||
|
||||
case SDL_JOYHATMOTION:
|
||||
hat_motion(event.jhat);
|
||||
hat_motion(event);
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
key_down(event.key);
|
||||
key_down(event);
|
||||
break;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
@ -539,11 +539,14 @@ void thandler::draw(const bool force)
|
|||
if(!dispatchers_.empty()) {
|
||||
CVideo& video = dynamic_cast<twindow&>(*dispatchers_.back()).video();
|
||||
|
||||
surface frame_buffer = video.getSurface();
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
surface& frame_buffer = video.getSurface();
|
||||
cursor::draw(frame_buffer);
|
||||
#endif
|
||||
video.flip();
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
cursor::undraw(frame_buffer);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -689,11 +692,11 @@ tdispatcher* thandler::keyboard_dispatcher()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void thandler::hat_motion(const SDL_JoyHatEvent& event)
|
||||
void thandler::hat_motion(const SDL_Event& event)
|
||||
{
|
||||
const hotkey::hotkey_item& hk = hotkey::get_hotkey(event);
|
||||
const hotkey::hotkey_ptr& hk = hotkey::get_hotkey(event);
|
||||
bool done = false;
|
||||
if(!hk.null()) {
|
||||
if(!hk->null()) {
|
||||
done = hotkey_pressed(hk);
|
||||
}
|
||||
if(!done) {
|
||||
|
@ -702,11 +705,11 @@ void thandler::hat_motion(const SDL_JoyHatEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void thandler::button_down(const SDL_JoyButtonEvent& event)
|
||||
void thandler::button_down(const SDL_Event& event)
|
||||
{
|
||||
const hotkey::hotkey_item& hk = hotkey::get_hotkey(event);
|
||||
const hotkey::hotkey_ptr hk = hotkey::get_hotkey(event);
|
||||
bool done = false;
|
||||
if(!hk.null()) {
|
||||
if(!hk->null()) {
|
||||
done = hotkey_pressed(hk);
|
||||
}
|
||||
if(!done) {
|
||||
|
@ -715,22 +718,22 @@ void thandler::button_down(const SDL_JoyButtonEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void thandler::key_down(const SDL_KeyboardEvent& event)
|
||||
void thandler::key_down(const SDL_Event& event)
|
||||
{
|
||||
const hotkey::hotkey_item& hk = hotkey::get_hotkey(event);
|
||||
const hotkey::hotkey_ptr hk = hotkey::get_hotkey(event);
|
||||
bool done = false;
|
||||
if(!hk.null()) {
|
||||
if(!hk->null()) {
|
||||
done = hotkey_pressed(hk);
|
||||
}
|
||||
if(!done) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
key_down(event.keysym.sym,
|
||||
static_cast<const SDL_Keymod>(event.keysym.mod),
|
||||
key_down(event.key.keysym.sym,
|
||||
static_cast<const SDL_Keymod>(event.key.keysym.mod),
|
||||
"");
|
||||
#else
|
||||
key_down(event.keysym.sym,
|
||||
event.keysym.mod,
|
||||
unicode_cast<std::string>(static_cast<ucs4::char_t>(event.keysym.unicode)));
|
||||
key_down(event.key.keysym.sym,
|
||||
event.key.keysym.mod,
|
||||
unicode_cast<std::string>(static_cast<ucs4::char_t>(event.key.keysym.unicode)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -740,7 +743,7 @@ void thandler::text_input(const std::string& unicode)
|
|||
key_down(static_cast<SDLKey>(0), static_cast<SDLMod>(0), unicode);
|
||||
}
|
||||
|
||||
bool thandler::hotkey_pressed(const hotkey::hotkey_item& key)
|
||||
bool thandler::hotkey_pressed(const hotkey::hotkey_ptr key)
|
||||
{
|
||||
tdispatcher* dispatcher = keyboard_dispatcher();
|
||||
|
||||
|
@ -748,7 +751,7 @@ bool thandler::hotkey_pressed(const hotkey::hotkey_item& key)
|
|||
return false;
|
||||
}
|
||||
|
||||
return dispatcher->execute_hotkey(hotkey::get_id(key.get_command()));
|
||||
return dispatcher->execute_hotkey(hotkey::get_id(key->get_command()));
|
||||
}
|
||||
|
||||
void thandler::key_down(const SDLKey key,
|
||||
|
|
|
@ -267,7 +267,7 @@ void ttitle_screen::post_build(CVideo& video, twindow& window)
|
|||
hotkey::TITLE_SCREEN__CREDITS,
|
||||
boost::bind(&hotkey, boost::ref(window), SHOW_ABOUT));
|
||||
|
||||
window.register_hotkey(hotkey::HOTKEY_QUIT_GAME,
|
||||
window.register_hotkey(hotkey::HOTKEY_QUIT_TO_DESKTOP,
|
||||
boost::bind(&hotkey, boost::ref(window), QUIT_GAME));
|
||||
|
||||
window.register_hotkey(
|
||||
|
|
|
@ -917,7 +917,10 @@ void tgrid::impl_draw_children(surface& frame_buffer)
|
|||
* Without the call when resizing larger a black area of remains, this is
|
||||
* the area not used for resizing the screen, this call `fixes' that.
|
||||
*/
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
SDL_PumpEvents();
|
||||
#endif
|
||||
|
||||
|
||||
assert(get_visible() == twidget::tvisible::visible);
|
||||
set_is_dirty(false);
|
||||
|
@ -955,7 +958,9 @@ tgrid::impl_draw_children(surface& frame_buffer, int x_offset, int y_offset)
|
|||
* Without the call when resizing larger a black area of remains, this is
|
||||
* the area not used for resizing the screen, this call `fixes' that.
|
||||
*/
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
SDL_PumpEvents();
|
||||
#endif
|
||||
|
||||
assert(get_visible() == twidget::tvisible::visible);
|
||||
set_is_dirty(false);
|
||||
|
|
|
@ -740,7 +740,7 @@ void twindow::draw()
|
|||
return;
|
||||
}
|
||||
|
||||
surface frame_buffer = video_.getSurface();
|
||||
surface& frame_buffer = video_.getSurface();
|
||||
|
||||
/***** ***** Layout and get dirty list ***** *****/
|
||||
if(need_layout_) {
|
||||
|
@ -789,7 +789,7 @@ void twindow::draw()
|
|||
|
||||
if(dirty_list_.empty()) {
|
||||
if(preferences::use_color_cursors() || sunset_) {
|
||||
surface frame_buffer = get_video_surface();
|
||||
surface& frame_buffer = get_video_surface();
|
||||
|
||||
if(sunset_) {
|
||||
/** @todo should probably be moved to event::thandler::draw. */
|
||||
|
@ -798,7 +798,7 @@ void twindow::draw()
|
|||
SDL_Rect r = sdl::create_rect(
|
||||
0, 0, frame_buffer->w, frame_buffer->h);
|
||||
const Uint32 color
|
||||
= SDL_MapRGBA(frame_buffer->format, 0, 0, 0, 255);
|
||||
= SDL_MapRGBA(frame_buffer->format, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||
|
||||
sdl::fill_rect_alpha(r, color, 1, frame_buffer);
|
||||
update_rect(r);
|
||||
|
@ -1446,7 +1446,7 @@ void twindow::signal_handler_sdl_video_resize(const event::tevent event,
|
|||
const tpoint& new_size)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if(new_size.x < preferences::min_allowed_width()
|
||||
|| new_size.y < preferences::min_allowed_height()) {
|
||||
|
||||
|
@ -1461,6 +1461,7 @@ void twindow::signal_handler_sdl_video_resize(const event::tevent event,
|
|||
handled = true;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!preferences::set_resolution(video_, new_size.x, new_size.y)) {
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ bool halo_impl::effect::render()
|
|||
return false;
|
||||
}
|
||||
|
||||
surface screen = disp->get_screen_surface();
|
||||
surface& screen = disp->get_screen_surface();
|
||||
|
||||
const clip_rect_setter clip_setter(screen, &clip_rect);
|
||||
if(buffer_ == NULL || buffer_->w != rect.w || buffer_->h != rect.h) {
|
||||
|
@ -240,7 +240,7 @@ bool halo_impl::effect::render()
|
|||
buffer_.assign(get_surface_portion(screen,rect));
|
||||
} else {
|
||||
SDL_Rect rect = rect_;
|
||||
sdl_blit(screen,&rect,buffer_,NULL);
|
||||
sdl_copy_portion(screen,&rect,buffer_,NULL);
|
||||
}
|
||||
|
||||
sdl_blit(surf_,NULL,screen,&rect);
|
||||
|
@ -265,7 +265,7 @@ void halo_impl::effect::unrender()
|
|||
return;
|
||||
}
|
||||
|
||||
surface screen = disp->get_screen_surface();
|
||||
surface& screen = disp->get_screen_surface();
|
||||
|
||||
SDL_Rect clip_rect = disp->map_outside_area();
|
||||
const clip_rect_setter clip_setter(screen, &clip_rect);
|
||||
|
|
|
@ -521,7 +521,7 @@ void help_text_area::draw_contents()
|
|||
{
|
||||
SDL_Rect const &loc = inner_location();
|
||||
bg_restore();
|
||||
surface screen = video().getSurface();
|
||||
surface& screen = video().getSurface();
|
||||
clip_rect_setter clip_rect_set(screen, &loc);
|
||||
for(std::list<item>::const_iterator it = items_.begin(), end = items_.end(); it != end; ++it) {
|
||||
SDL_Rect dst = it->rect;
|
||||
|
|
|
@ -43,10 +43,7 @@ static lg::log_domain log_config("config");
|
|||
|
||||
namespace hotkey {
|
||||
|
||||
static void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor);
|
||||
static void jbutton_event_execute(display& disp, const SDL_JoyButtonEvent& event, command_executor* executor);
|
||||
static void jhat_event_execute(display& disp, const SDL_JoyHatEvent& event, command_executor* executor);
|
||||
static void mbutton_event_execute(display& disp, const SDL_MouseButtonEvent& event, command_executor* executor);
|
||||
static void event_execute(display& disp, const SDL_Event& event, command_executor* executor);
|
||||
|
||||
bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/)
|
||||
{
|
||||
|
@ -484,64 +481,53 @@ void basic_handler::handle_event(const SDL_Event& event)
|
|||
// handled by the executor.
|
||||
// If we're not in a dialog we can call the regular key event handler.
|
||||
if (!gui::in_dialog()) {
|
||||
key_event(*disp_, event.key,exec_);
|
||||
key_event(*disp_, event,exec_);
|
||||
} else if (exec_ != NULL) {
|
||||
key_event_execute(*disp_, event.key,exec_);
|
||||
event_execute(*disp_, event,exec_);
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
if (!gui::in_dialog()) {
|
||||
jbutton_event(*disp_, event.jbutton,exec_);
|
||||
jbutton_event(*disp_, event,exec_);
|
||||
} else if (exec_ != NULL) {
|
||||
jbutton_event_execute(*disp_, event.jbutton,exec_);
|
||||
event_execute(*disp_, event,exec_);
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (!gui::in_dialog()) {
|
||||
mbutton_event(*disp_, event.button,exec_);
|
||||
mbutton_event(*disp_, event,exec_);
|
||||
} else if (exec_ != NULL) {
|
||||
mbutton_event_execute(*disp_, event.button,exec_);
|
||||
event_execute(*disp_, event,exec_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void mbutton_event(display& disp, const SDL_MouseButtonEvent& event, command_executor* executor)
|
||||
void mbutton_event(display& disp, const SDL_Event& event, command_executor* executor)
|
||||
{
|
||||
mbutton_event_execute(disp, event, executor);
|
||||
event_execute(disp, event, executor);
|
||||
}
|
||||
|
||||
void jbutton_event(display& disp, const SDL_JoyButtonEvent& event, command_executor* executor)
|
||||
void jbutton_event(display& disp, const SDL_Event& event, command_executor* executor)
|
||||
{
|
||||
jbutton_event_execute(disp, event, executor);
|
||||
event_execute(disp, event, executor);
|
||||
}
|
||||
|
||||
void jhat_event(display& disp, const SDL_JoyHatEvent& event, command_executor* executor)
|
||||
void jhat_event(display& disp, const SDL_Event& event, command_executor* executor)
|
||||
{
|
||||
jhat_event_execute(disp, event, executor);
|
||||
event_execute(disp, event, executor);
|
||||
}
|
||||
|
||||
void key_event(display& disp, const SDL_KeyboardEvent& event, command_executor* executor)
|
||||
void key_event(display& disp, const SDL_Event& event, command_executor* executor)
|
||||
{
|
||||
if (!executor) return;
|
||||
if(event.keysym.sym == SDLK_ESCAPE && disp.in_game()) {
|
||||
LOG_G << "escape pressed..showing quit\n";
|
||||
const int res = gui2::show_message(disp.video(), _("Quit"),
|
||||
_("Do you really want to quit?"), gui2::tmessage::yes_no_buttons);
|
||||
if(res != gui2::twindow::CANCEL) {
|
||||
throw_quit_game_exception();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
key_event_execute(disp, event,executor);
|
||||
event_execute(disp, event,executor);
|
||||
}
|
||||
|
||||
void mbutton_event_execute(display& disp, const SDL_MouseButtonEvent& event, command_executor* executor)
|
||||
static void event_execute(display& disp, const SDL_Event& event, command_executor* executor)
|
||||
{
|
||||
if (!executor) return;
|
||||
const hotkey_item* hk = &get_hotkey(event);
|
||||
const hotkey_ptr hk = get_hotkey(event);
|
||||
if (!hk->active()) {
|
||||
return;
|
||||
}
|
||||
|
@ -550,52 +536,6 @@ void mbutton_event_execute(display& disp, const SDL_MouseButtonEvent& event, com
|
|||
executor->set_button_state(disp);
|
||||
}
|
||||
|
||||
void jbutton_event_execute(display& disp, const SDL_JoyButtonEvent& event, command_executor* executor)
|
||||
{
|
||||
if (!executor) return;
|
||||
const hotkey_item* hk = &get_hotkey(event);
|
||||
if (!hk->active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
execute_command(disp, get_hotkey_command(hk->get_command()), executor);
|
||||
executor->set_button_state(disp);
|
||||
}
|
||||
|
||||
void jhat_event_execute(display& disp, const SDL_JoyHatEvent& event, command_executor* executor)
|
||||
{
|
||||
if (!executor) return;
|
||||
const hotkey_item* hk = &get_hotkey(event);
|
||||
if (!hk->active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
execute_command(disp, get_hotkey_command(hk->get_command()), executor);
|
||||
executor->set_button_state(disp);
|
||||
}
|
||||
|
||||
void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor)
|
||||
{
|
||||
if (!executor) return;
|
||||
const hotkey_item* hk = &get_hotkey(event);
|
||||
|
||||
#if 0
|
||||
// This is not generally possible without knowing keyboard layout.
|
||||
if (hk->null()) {
|
||||
//no matching hotkey was found, but try an in-exact match.
|
||||
hk = &get_hotkey(event, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!hk->active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
execute_command(disp, get_hotkey_command(hk->get_command()), executor);
|
||||
executor->set_button_state(disp);
|
||||
}
|
||||
|
||||
|
||||
void execute_command(display& disp, const hotkey_command& command, command_executor* executor, int index)
|
||||
{
|
||||
const int zoom_amount = 4;
|
||||
|
@ -696,13 +636,18 @@ void execute_command(display& disp, const hotkey_command& command, command_execu
|
|||
}
|
||||
}
|
||||
break;
|
||||
case HOTKEY_QUIT_TO_DESKTOP:
|
||||
case HOTKEY_QUIT_GAME: {
|
||||
if (disp.in_game()) {
|
||||
DBG_G << "is in game -- showing quit message\n";
|
||||
const int res = gui2::show_message(disp.video(), _("Quit"),
|
||||
_("Do you really want to quit?"), gui2::tmessage::yes_no_buttons);
|
||||
if (res != gui2::twindow::CANCEL) {
|
||||
throw_quit_game_exception();
|
||||
if (command.id == HOTKEY_QUIT_TO_DESKTOP) {
|
||||
throw CVideo::quit();
|
||||
} else {
|
||||
throw_quit_game_exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -134,10 +134,11 @@ public:
|
|||
* Also handles some events in the function itself,
|
||||
* and so is still meaningful to call with executor=NULL
|
||||
*/
|
||||
void jbutton_event(display& disp, const SDL_JoyButtonEvent& event, command_executor* executor);
|
||||
void jhat_event(display& disp, const SDL_JoyHatEvent& event, command_executor* executor);
|
||||
void key_event(display& disp, const SDL_KeyboardEvent& event, command_executor* executor);
|
||||
void mbutton_event(display& disp, const SDL_MouseButtonEvent& event, command_executor* executor);
|
||||
void jbutton_event(display& disp, const SDL_Event& event, command_executor* executor);
|
||||
void jhat_event(display& disp, const SDL_Event& event, command_executor* executor);
|
||||
void key_event(display& disp, const SDL_Event& event, command_executor* executor);
|
||||
void mbutton_event(display& disp, const SDL_Event& event, command_executor* executor);
|
||||
|
||||
|
||||
//TODO
|
||||
void execute_command(display& disp, const hotkey_command& command, command_executor* executor, int index=-1);
|
||||
|
|
|
@ -88,7 +88,7 @@ hotkey::hotkey_command_temp hotkey_list_[] = {
|
|||
{ hotkey::HOTKEY_STATISTICS, "statistics", N_("Statistics"), false, scope_game, "" },
|
||||
{ hotkey::HOTKEY_STOP_NETWORK, "stopnetwork", N_("Pause Network Game"), false, scope_game, "" },
|
||||
{ hotkey::HOTKEY_START_NETWORK, "startnetwork", N_("Continue Network Game"), false, scope_game, "" },
|
||||
{ hotkey::HOTKEY_QUIT_GAME, "quit", N_("Quit to Titlescreen"), false, scope_game | scope_editor | scope_main, "" },
|
||||
{ hotkey::HOTKEY_QUIT_GAME, "quit", N_("Quit to Titlescreen"), false, scope_game | scope_editor, "" },
|
||||
{ hotkey::HOTKEY_LABEL_TEAM_TERRAIN, "labelteamterrain", N_("Set Team Label"), false, scope_game, "" },
|
||||
{ hotkey::HOTKEY_LABEL_TERRAIN, "labelterrain", N_("Set Label"), false, scope_game, "" },
|
||||
{ hotkey::HOTKEY_CLEAR_LABELS, "clearlabels", N_("Clear Labels"), false, scope_game, "" },
|
||||
|
@ -122,7 +122,7 @@ hotkey::hotkey_command_temp hotkey_list_[] = {
|
|||
// TRANSLATORS: whiteboard menu entry: plan as though the chosen unit were dead
|
||||
{ hotkey::HOTKEY_WB_SUPPOSE_DEAD, "wbsupposedead", N_("whiteboard^Suppose Dead"), false, scope_game, "" },
|
||||
|
||||
{ hotkey::HOTKEY_EDITOR_QUIT_TO_DESKTOP, "editor-quit-to-desktop", N_("Quit to Desktop"), false, scope_editor, "" },
|
||||
{ hotkey::HOTKEY_QUIT_TO_DESKTOP, "quit-to-desktop", N_("Quit to Desktop"), false, scope_game | scope_editor | scope_main, "" },
|
||||
{ hotkey::HOTKEY_EDITOR_MAP_CLOSE, "editor-close-map", N_("Close Map"), false, scope_editor, "" },
|
||||
|
||||
// These are not really hotkey items but menu entries to get expanded.
|
||||
|
@ -389,9 +389,9 @@ void add_wml_hotkey(const std::string& id, const t_string& description, const co
|
|||
|
||||
if(!default_hotkey.empty() && !has_hotkey_item(id))
|
||||
{
|
||||
hotkey_item new_item(default_hotkey, true);
|
||||
new_item.set_command(id);
|
||||
if(new_item.valid())
|
||||
hotkey::hotkey_ptr new_item = hotkey::load_from_config(default_hotkey);
|
||||
new_item->set_command(id);
|
||||
if(new_item->valid())
|
||||
{
|
||||
DBG_G << "added default description for the wml hotkey with id=" + id;
|
||||
add_hotkey(new_item);
|
||||
|
|
|
@ -48,7 +48,7 @@ enum HOTKEY_COMMAND {
|
|||
HOTKEY_RECRUIT, HOTKEY_REPEAT_RECRUIT, HOTKEY_RECALL, HOTKEY_ENDTURN,
|
||||
HOTKEY_TOGGLE_ELLIPSES, HOTKEY_TOGGLE_GRID, HOTKEY_STATUS_TABLE, HOTKEY_MUTE, HOTKEY_MOUSE_SCROLL,
|
||||
HOTKEY_SPEAK, HOTKEY_CREATE_UNIT, HOTKEY_CHANGE_SIDE, HOTKEY_KILL_UNIT, HOTKEY_PREFERENCES,
|
||||
HOTKEY_OBJECTIVES, HOTKEY_UNIT_LIST, HOTKEY_STATISTICS, HOTKEY_STOP_NETWORK, HOTKEY_START_NETWORK, HOTKEY_QUIT_GAME,
|
||||
HOTKEY_OBJECTIVES, HOTKEY_UNIT_LIST, HOTKEY_STATISTICS, HOTKEY_STOP_NETWORK, HOTKEY_START_NETWORK, HOTKEY_QUIT_GAME, HOTKEY_QUIT_TO_DESKTOP,
|
||||
HOTKEY_LABEL_TEAM_TERRAIN, HOTKEY_LABEL_TERRAIN, HOTKEY_CLEAR_LABELS,HOTKEY_SHOW_ENEMY_MOVES, HOTKEY_BEST_ENEMY_MOVES,
|
||||
HOTKEY_DELAY_SHROUD, HOTKEY_UPDATE_SHROUD, HOTKEY_CONTINUE_MOVE,
|
||||
HOTKEY_SEARCH, HOTKEY_SPEAK_ALLY, HOTKEY_SPEAK_ALL, HOTKEY_HELP,
|
||||
|
@ -103,7 +103,6 @@ enum HOTKEY_COMMAND {
|
|||
HOTKEY_WML,
|
||||
|
||||
/* Editor commands */
|
||||
HOTKEY_EDITOR_QUIT_TO_DESKTOP,
|
||||
HOTKEY_EDITOR_CUSTOM_TODS,
|
||||
HOTKEY_EDITOR_PARTIAL_UNDO,
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "log.hpp"
|
||||
#include "hotkey_item.hpp"
|
||||
#include "hotkey_command.hpp"
|
||||
|
@ -24,243 +25,384 @@
|
|||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "key.hpp"
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
#include "sdl/keyboard.hpp"
|
||||
#endif
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_G LOG_STREAM(err, lg::general)
|
||||
#define LOG_G LOG_STREAM(info, lg::general)
|
||||
#define DBG_G LOG_STREAM(debug, lg::general)
|
||||
#define ERR_CF LOG_STREAM(err, log_config)
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<hotkey::hotkey_item> hotkeys_;
|
||||
config default_hotkey_cfg_;
|
||||
|
||||
hotkey::hotkey_item null_hotkey_("null");
|
||||
|
||||
hotkey::hotkey_item& get_hotkey(int mouse, int joystick, int button, int hat, int value,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
{
|
||||
std::vector<hotkey::hotkey_item>::iterator itor;
|
||||
|
||||
for (itor = hotkeys_.begin(); itor != hotkeys_.end(); ++itor) {
|
||||
|
||||
if ( !( hotkey::is_scope_active(hotkey::get_hotkey_command(itor->get_command()).scope) && itor->active() ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( itor->get_shift() != shift || itor->get_ctrl() != ctrl
|
||||
|| itor->get_cmd() != cmd || itor->get_alt() != alt ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( itor->get_joystick() == joystick && itor->get_button() == button
|
||||
&& itor->get_hat() == hat && itor->get_value() == value
|
||||
&& itor->get_mouse() == mouse ) {
|
||||
return *itor;
|
||||
}
|
||||
}
|
||||
|
||||
return null_hotkey_;
|
||||
}
|
||||
|
||||
hotkey::hotkey_item& get_hotkey(int character, int keycode,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
{
|
||||
std::vector<hotkey::hotkey_item>::iterator itor;
|
||||
|
||||
DBG_G << "getting hotkey: char=" << lexical_cast<std::string>(character)
|
||||
<< " keycode=" << lexical_cast<std::string>(keycode) << " "
|
||||
<< (shift ? "shift," : "")
|
||||
<< (ctrl ? "ctrl," : "")
|
||||
<< (cmd ? "cmd," : "")
|
||||
<< (alt ? "alt," : "")
|
||||
<< "\n";
|
||||
|
||||
// Sometimes control modifies by -64, ie ^A == 1.
|
||||
if (0 < character && character < 64 && ctrl) {
|
||||
if (shift) {
|
||||
character += 64;
|
||||
} else {
|
||||
character += 96;
|
||||
}
|
||||
/// @todo
|
||||
DBG_G << "Mapped to character " << lexical_cast<std::string>(character) << "\n";
|
||||
}
|
||||
|
||||
// For some reason on Mac OS, if cmd and shift are down, the character doesn't get upper-cased
|
||||
if (cmd && character > 96 && character < 123 && shift) {
|
||||
character -= 32; }
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (itor = hotkeys_.begin(); itor != hotkeys_.end(); ++itor) {
|
||||
// Special case for Ctrl+Return/Enter keys, which gets resolved to Ctrl-j and Ctrl-m characters (LF and CR respectively).
|
||||
// In such cases, do not match by character but go straight to key code.
|
||||
if (itor->get_character() != -1 &&
|
||||
!(tolower(character) == 'j' && keycode != SDLK_j) &&
|
||||
!(tolower(character) == 'm' && keycode != SDLK_m)) {
|
||||
if (character == itor->get_character()) {
|
||||
if (ctrl == itor->get_ctrl()
|
||||
&& cmd == itor->get_cmd()
|
||||
&& alt == itor->get_alt()) {
|
||||
if (hotkey::is_scope_active(hotkey::get_hotkey_command(itor->get_command()).scope) && itor->active()) {
|
||||
DBG_G << "Could match by character..." << "yes\n";
|
||||
found = true;
|
||||
break;
|
||||
} else {
|
||||
DBG_G << "Could match by character..." << "yes, but scope is inactive\n";
|
||||
}
|
||||
}
|
||||
DBG_G << "Could match by character..." << "but modifiers different\n";
|
||||
}
|
||||
} else if (itor->get_keycode() != -1) {
|
||||
if (keycode == itor->get_keycode()) {
|
||||
if (shift == itor->get_shift()
|
||||
&& ctrl == itor->get_ctrl()
|
||||
&& cmd == itor->get_cmd()
|
||||
&& alt == itor->get_alt()) {
|
||||
if (hotkey::is_scope_active(hotkey::get_hotkey_command(itor->get_command()).scope) && itor->active()) {
|
||||
DBG_G << "Could match by keycode..." << "yes\n";
|
||||
found = true;
|
||||
break;
|
||||
} else {
|
||||
DBG_G << "Could match by keycode..." << "yes, but scope is inactive\n";
|
||||
}
|
||||
}
|
||||
DBG_G << "Could match by keycode..." << "but modifiers different\n";
|
||||
}
|
||||
}
|
||||
if (found) { break; }
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return null_hotkey_; }
|
||||
|
||||
return *itor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace hotkey {
|
||||
|
||||
hotkey_list hotkeys_;
|
||||
config default_hotkey_cfg_;
|
||||
|
||||
const hotkey_item& get_hotkey(const SDL_JoyButtonEvent& event)
|
||||
static unsigned int sdl_get_mods()
|
||||
{
|
||||
CKey keystate;
|
||||
bool shift = keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT];
|
||||
bool ctrl = keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL];
|
||||
bool cmd = keystate[SDLK_RMETA] || keystate[SDLK_LMETA];
|
||||
bool alt = keystate[SDLK_RALT] || keystate[SDLK_LALT];
|
||||
unsigned int mods;
|
||||
mods = SDL_GetModState();
|
||||
|
||||
return get_hotkey(-1, event.which, event.button, -1, -1, shift, ctrl, cmd, alt);
|
||||
}
|
||||
mods &= ~KMOD_NUM;
|
||||
mods &= ~KMOD_CAPS;
|
||||
mods &= ~KMOD_MODE;
|
||||
|
||||
const hotkey_item& get_hotkey(const SDL_JoyHatEvent& event)
|
||||
{
|
||||
CKey keystate;
|
||||
bool shift = keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT];
|
||||
bool ctrl = keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL];
|
||||
bool cmd = keystate[SDLK_RMETA] || keystate[SDLK_LMETA];
|
||||
bool alt = keystate[SDLK_RALT] || keystate[SDLK_LALT];
|
||||
// save the matching for checking right vs left keys
|
||||
if (mods & KMOD_SHIFT)
|
||||
mods |= KMOD_SHIFT;
|
||||
|
||||
return get_hotkey(-1, event.which, -1, event.hat, event.value, shift, ctrl, cmd, alt);
|
||||
}
|
||||
if (mods & KMOD_CTRL)
|
||||
mods |= KMOD_CTRL;
|
||||
|
||||
if (mods & KMOD_ALT)
|
||||
mods |= KMOD_ALT;
|
||||
|
||||
const hotkey_item& get_hotkey(const SDL_MouseButtonEvent& event)
|
||||
{
|
||||
CKey keystate;
|
||||
bool shift = keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT];
|
||||
bool ctrl = keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL];
|
||||
bool cmd = keystate[SDLK_RMETA] || keystate[SDLK_LMETA];
|
||||
bool alt = keystate[SDLK_RALT] || keystate[SDLK_LALT];
|
||||
|
||||
return get_hotkey(event.which, -1, event.button, -1, -1, shift, ctrl, cmd, alt);
|
||||
}
|
||||
|
||||
|
||||
const hotkey_item& get_hotkey(const SDL_KeyboardEvent& event)
|
||||
{
|
||||
return get_hotkey(
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
event.keysym.scancode,
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
if (mods & KMOD_GUI)
|
||||
mods |= KMOD_GUI;
|
||||
#else
|
||||
event.keysym.unicode,
|
||||
if (mods & KMOD_META)
|
||||
mods |= KMOD_META;
|
||||
#endif
|
||||
event.keysym.sym,
|
||||
(event.keysym.mod & KMOD_SHIFT) != 0,
|
||||
(event.keysym.mod & KMOD_CTRL) != 0,
|
||||
(event.keysym.mod & KMOD_META) != 0,
|
||||
(event.keysym.mod & KMOD_ALT) != 0
|
||||
);
|
||||
|
||||
return mods;
|
||||
}
|
||||
|
||||
const std::string hotkey_base::get_name() const
|
||||
{
|
||||
std::string ret = "";
|
||||
|
||||
if (mod_ & KMOD_CTRL)
|
||||
ret += "ctrl";
|
||||
|
||||
std::string get_names(std::string id) {
|
||||
ret +=
|
||||
(!ret.empty() && !boost::algorithm::ends_with(ret, "+") ?
|
||||
"+" : "");
|
||||
if (mod_ & KMOD_ALT)
|
||||
ret += "alt";
|
||||
|
||||
std::vector<std::string> names;
|
||||
BOOST_FOREACH(const hotkey::hotkey_item& item, hotkeys_) {
|
||||
if (item.get_command() == id && (!item.null()) ) {
|
||||
names.push_back(item.get_name());
|
||||
}
|
||||
ret +=
|
||||
(!ret.empty() && !boost::algorithm::ends_with(ret, "+") ?
|
||||
"+" : "");
|
||||
if (mod_ & KMOD_SHIFT)
|
||||
ret += "shift";
|
||||
|
||||
ret +=
|
||||
(!ret.empty() && !boost::algorithm::ends_with(ret, "+") ?
|
||||
"+" : "");
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (mod_ & KMOD_GUI)
|
||||
#else
|
||||
if (mod_ & KMOD_META)
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
ret += "cmd";
|
||||
#else
|
||||
ret += "win";
|
||||
#endif
|
||||
|
||||
ret +=
|
||||
(!ret.empty() && !boost::algorithm::ends_with(ret, "+") ?
|
||||
"+" : "");
|
||||
return ret += get_name_helper();
|
||||
}
|
||||
|
||||
bool hotkey_base::bindings_equal(hotkey_ptr other)
|
||||
{
|
||||
|
||||
bool ret;
|
||||
|
||||
if (other == hotkey_ptr()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return boost::algorithm::join(names, ", ");
|
||||
hk_scopes scopematch = hotkey::get_hotkey_command(get_command()).scope
|
||||
& hotkey::get_hotkey_command(other->get_command()).scope;
|
||||
|
||||
if (scopematch.none()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = mod_ == other->mod_ && bindings_equal_helper(other);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const hotkey_item& get_hotkey(int mouse, int joystick, int button, int hat, int value,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
bool hotkey_base::matches(const SDL_Event &event) const
|
||||
{
|
||||
return ::get_hotkey(mouse, joystick, button, hat, value,
|
||||
shift, ctrl, cmd, alt);
|
||||
unsigned int mods = sdl_get_mods();
|
||||
|
||||
if (!hotkey::is_scope_active(hotkey::get_hotkey_command(get_command()).scope) ||
|
||||
!active()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((mods != mod_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return matches_helper(event);
|
||||
}
|
||||
|
||||
const hotkey::hotkey_item& get_hotkey(int character, int keycode,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
void hotkey_base::save(config& item) const
|
||||
{
|
||||
return ::get_hotkey(character, keycode,
|
||||
shift, ctrl, cmd, alt);
|
||||
item["command"] = get_command();
|
||||
|
||||
item["shift"] = !!(mod_ & KMOD_SHIFT);
|
||||
item["ctrl"] = !!(mod_ & KMOD_CTRL);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
item["cmd"] = !!(mod_ & KMOD_GUI);
|
||||
#else
|
||||
item["cmd"] = !!(mod_ & KMOD_META);
|
||||
#endif
|
||||
item["alt"] = !!(mod_ & KMOD_ALT);
|
||||
|
||||
save_helper(item);
|
||||
}
|
||||
|
||||
hotkey_ptr create_hotkey(const std::string &id, SDL_Event &event)
|
||||
{
|
||||
hotkey_ptr base = hotkey_ptr(new hotkey_void);
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
hotkey_keyboard_ptr keyboard(new hotkey_keyboard());
|
||||
base = boost::dynamic_pointer_cast<hotkey_base>(keyboard);
|
||||
SDL_Scancode code;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
code = event.key.keysym.scancode;
|
||||
#else
|
||||
code = SDL_GetScancodeFromKey(event.key.keysym.sym);
|
||||
#endif
|
||||
keyboard->set_scancode(code);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
hotkey_mouse_ptr mouse(new hotkey_mouse());
|
||||
base = boost::dynamic_pointer_cast<hotkey_base>(mouse);
|
||||
mouse->set_button(event.button.button);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ERR_G<< "Trying to bind an unknown event type:" << event.type << "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
base->set_mods(sdl_get_mods());
|
||||
base->set_command(id);
|
||||
base->unset_default();
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
hotkey_ptr load_from_config(const config& cfg)
|
||||
{
|
||||
hotkey_ptr base = hotkey_ptr(new hotkey_void());
|
||||
|
||||
const std::string& mouse_cfg = cfg["mouse"];
|
||||
if (!mouse_cfg.empty()) {
|
||||
hotkey_mouse_ptr mouse(new hotkey_mouse());
|
||||
base = boost::dynamic_pointer_cast<hotkey_base>(mouse);
|
||||
mouse->set_button(cfg["button"].to_int());
|
||||
}
|
||||
// TODO: add joystick support back
|
||||
#if 0
|
||||
const std::string& joystick_cfg = cfg["joystick"];
|
||||
if (!joystick_cfg.empty()) {
|
||||
joystick_ = cfg["joystick"].to_int();
|
||||
}
|
||||
const std::string& hat = cfg["hat"];
|
||||
if (!hat.empty()) {
|
||||
hat_ = cfg["hat"].to_int();
|
||||
value_ = cfg["value"].to_int();
|
||||
}
|
||||
|
||||
const std::string& button = cfg["button"];
|
||||
if (!button.empty()) {
|
||||
button_ = cfg["button"].to_int();
|
||||
}
|
||||
#endif
|
||||
|
||||
const std::string& key_cfg = cfg["key"];
|
||||
if (!key_cfg.empty()) {
|
||||
hotkey_keyboard_ptr keyboard(new hotkey_keyboard());
|
||||
base = boost::dynamic_pointer_cast<hotkey_base>(keyboard);
|
||||
|
||||
SDL_Scancode scancode = SDL_GetScancodeFromName(key_cfg.c_str());
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
ERR_G<< "Unknown key: " << key_cfg << "\n";
|
||||
}
|
||||
keyboard->set_scancode(scancode);
|
||||
}
|
||||
|
||||
if (base == hotkey_ptr()) {
|
||||
return base;
|
||||
}
|
||||
|
||||
unsigned int mods = 0;
|
||||
|
||||
if (cfg["shift"].to_bool())
|
||||
mods |= KMOD_SHIFT;
|
||||
if (cfg["ctrl"].to_bool())
|
||||
mods |= KMOD_CTRL;
|
||||
if (cfg["cmd"].to_bool())
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
mods |= KMOD_GUI;
|
||||
#else
|
||||
mods |= KMOD_META;
|
||||
#endif
|
||||
if (cfg["alt"].to_bool())
|
||||
mods |= KMOD_ALT;
|
||||
|
||||
base->set_mods(mods);
|
||||
base->set_command(cfg["command"].str());
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
bool hotkey_mouse::matches_helper(const SDL_Event &event) const
|
||||
{
|
||||
if (event.type != SDL_MOUSEBUTTONUP && event.type != SDL_MOUSEBUTTONDOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (event.button.button != button_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string hotkey_mouse::get_name_helper() const
|
||||
{
|
||||
return "mouse " + lexical_cast<std::string>(button_);
|
||||
}
|
||||
|
||||
void hotkey_mouse::save_helper(config &item) const
|
||||
{
|
||||
item["mouse"] = 0;
|
||||
if (button_ != 0) {
|
||||
item["button"] = button_;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string hotkey_keyboard::get_name_helper() const
|
||||
{
|
||||
std::string ret = std::string(SDL_GetKeyName(SDL_GetKeyFromScancode(scancode_)));
|
||||
|
||||
if (ret.size() == 1) {
|
||||
boost::algorithm::to_lower(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool hotkey_keyboard::matches_helper(const SDL_Event &event) const
|
||||
{
|
||||
if (event.type != SDL_KEYDOWN && event.type != SDL_KEYUP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_Scancode code;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
code = event.key.keysym.scancode;
|
||||
#else
|
||||
code = SDL_GetScancodeFromKey(event.key.keysym.sym);
|
||||
#endif
|
||||
|
||||
if (code != scancode_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hotkey_mouse::bindings_equal_helper(hotkey_ptr other) const
|
||||
{
|
||||
hotkey_mouse_ptr other_m = boost::dynamic_pointer_cast<hotkey_mouse>(other);
|
||||
|
||||
if (other_m == hotkey_mouse_ptr()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return button_ == other_m->button_;
|
||||
}
|
||||
|
||||
void hotkey_keyboard::save_helper(config &item) const
|
||||
{
|
||||
if (scancode_ != SDL_SCANCODE_UNKNOWN) {
|
||||
item["key"] = SDL_GetScancodeName(scancode_);
|
||||
}
|
||||
}
|
||||
|
||||
bool has_hotkey_item(const std::string& command)
|
||||
{
|
||||
BOOST_FOREACH(hotkey_item& item, hotkeys_)
|
||||
{
|
||||
if(item.get_command() == command)
|
||||
BOOST_FOREACH(hotkey_ptr item, hotkeys_) {
|
||||
if (item->get_command() == command) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void add_hotkey(const hotkey_item& item) {
|
||||
bool hotkey_keyboard::bindings_equal_helper(hotkey_ptr other) const
|
||||
{
|
||||
hotkey_keyboard_ptr other_k = boost::dynamic_pointer_cast<hotkey_keyboard>(
|
||||
other);
|
||||
if (other_k == hotkey_keyboard_ptr()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return scancode_ == other_k->scancode_;
|
||||
}
|
||||
|
||||
void del_hotkey(hotkey_ptr item)
|
||||
{
|
||||
if (!hotkeys_.empty()) {
|
||||
hotkeys_.erase(std::remove(hotkeys_.begin(), hotkeys_.end(), item));
|
||||
}
|
||||
}
|
||||
|
||||
void add_hotkey(const hotkey_ptr item)
|
||||
{
|
||||
|
||||
if (item == hotkey_ptr()) {
|
||||
return;
|
||||
}
|
||||
|
||||
scope_changer scope_ch;
|
||||
set_active_scopes(hotkey::get_hotkey_command(item.get_command()).scope);
|
||||
set_active_scopes(hotkey::get_hotkey_command(item->get_command()).scope);
|
||||
|
||||
hotkey_item& old_hk = (item.get_mouse() != -1 || item.get_joystick() != -1) ?
|
||||
::get_hotkey(item.get_mouse(), item.get_joystick(), item.get_button(), item.get_hat()
|
||||
, item.get_value(), item.get_shift(), item.get_ctrl(), item.get_cmd(), item.get_alt()) :
|
||||
::get_hotkey(item.get_character(), item.get_keycode(),
|
||||
item.get_shift(), item.get_ctrl(), item.get_cmd(), item.get_alt());
|
||||
|
||||
if (old_hk.active()) {
|
||||
old_hk.set_command(item.get_command());
|
||||
old_hk.unset_default();
|
||||
if (!hotkeys_.empty()) {
|
||||
hotkeys_.erase(
|
||||
std::remove_if(hotkeys_.begin(), hotkeys_.end(),
|
||||
boost::bind(&hotkey_base::bindings_equal, _1, (item))),
|
||||
hotkeys_.end());
|
||||
}
|
||||
else
|
||||
hotkeys_.push_back(item);
|
||||
|
||||
hotkeys_.push_back(item);
|
||||
|
||||
}
|
||||
|
||||
void clear_hotkeys(const std::string& command)
|
||||
{
|
||||
BOOST_FOREACH(hotkey::hotkey_item& item, hotkeys_) {
|
||||
if (item.get_command() == command) {
|
||||
item.clear(); }
|
||||
BOOST_FOREACH(hotkey::hotkey_ptr item, hotkeys_) {
|
||||
if (item->get_command() == command) {
|
||||
item->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,11 +411,26 @@ void clear_hotkeys()
|
|||
hotkeys_.clear();
|
||||
}
|
||||
|
||||
const hotkey_ptr get_hotkey(const SDL_Event &event)
|
||||
{
|
||||
BOOST_FOREACH(hotkey_ptr item, hotkeys_) {
|
||||
if (item->matches(event)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return hotkey_ptr(new hotkey_void());
|
||||
}
|
||||
|
||||
void load_hotkeys(const config& cfg, bool set_as_default)
|
||||
{
|
||||
BOOST_FOREACH(const config &hk, cfg.child_range("hotkey")) {
|
||||
hotkey_item item = hotkey_item(hk, set_as_default);
|
||||
if(!item.null()){
|
||||
|
||||
hotkey_ptr item = load_from_config(hk);
|
||||
if (!set_as_default) {
|
||||
item->unset_default();
|
||||
}
|
||||
|
||||
if (!item->null()) {
|
||||
add_hotkey(item);
|
||||
}
|
||||
}
|
||||
|
@ -287,14 +444,14 @@ void reset_default_hotkeys()
|
|||
{
|
||||
hotkeys_.clear();
|
||||
|
||||
if(!default_hotkey_cfg_.empty()) {
|
||||
if (!default_hotkey_cfg_.empty()) {
|
||||
load_hotkeys(default_hotkey_cfg_, true);
|
||||
} else {
|
||||
ERR_G << "no default hotkeys set yet; all hotkeys are now unassigned!" << std::endl;
|
||||
ERR_G<< "no default hotkeys set yet; all hotkeys are now unassigned!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<hotkey_item>& get_hotkeys()
|
||||
const hotkey_list& get_hotkeys()
|
||||
{
|
||||
return hotkeys_;
|
||||
}
|
||||
|
@ -303,258 +460,36 @@ void save_hotkeys(config& cfg)
|
|||
{
|
||||
cfg.clear_children("hotkey");
|
||||
|
||||
for(std::vector<hotkey_item>::iterator i = hotkeys_.begin();
|
||||
i != hotkeys_.end(); ++i)
|
||||
{
|
||||
if (!i->is_default())
|
||||
i->save(cfg.add_child("hotkey"));
|
||||
}
|
||||
}
|
||||
|
||||
bool hotkey_item::active() const
|
||||
{
|
||||
return !(command_ == "null");
|
||||
}
|
||||
|
||||
bool hotkey_item::valid() const
|
||||
{
|
||||
return (character_ | keycode_ | joystick_ | mouse_ | button_ | hat_ | value_) != 0;
|
||||
}
|
||||
|
||||
// There are two kinds of "key" values.
|
||||
// One refers to actual keys, like F1 or SPACE.
|
||||
// The other refers to characters produced, eg 'M' or ':'.
|
||||
// For the latter, specifying shift+; doesn't make sense,
|
||||
// because ; is already shifted on French keyboards, for example.
|
||||
// You really want to say ':', however that is typed.
|
||||
// However, when you say shift+SPACE,
|
||||
// you're really referring to the space bar,
|
||||
// as shift+SPACE usually just produces a SPACE character.
|
||||
void hotkey_item::load_from_config(const config& cfg)
|
||||
{
|
||||
command_ = cfg["command"].str();
|
||||
|
||||
const std::string& mouse = cfg["mouse"];
|
||||
if (!mouse.empty()) {
|
||||
mouse_ = cfg["mouse"].to_int();
|
||||
button_ = cfg["button"].to_int();
|
||||
}
|
||||
const std::string& joystick = cfg["joystick"];
|
||||
if (!joystick.empty()) {
|
||||
joystick_ = cfg["joystick"].to_int();
|
||||
}
|
||||
const std::string& hat = cfg["hat"];
|
||||
if (!hat.empty()) {
|
||||
hat_ = cfg["hat"].to_int();
|
||||
value_ = cfg["value"].to_int();
|
||||
}
|
||||
|
||||
const std::string& button = cfg["button"];
|
||||
if (!button.empty()) {
|
||||
button_ = cfg["button"].to_int();
|
||||
}
|
||||
|
||||
shift_ = cfg["shift"].to_bool();
|
||||
ctrl_ = cfg["ctrl"].to_bool();
|
||||
cmd_ = cfg["cmd"].to_bool();
|
||||
alt_ = cfg["alt"].to_bool();
|
||||
|
||||
const std::string& key = cfg["key"];
|
||||
if (key.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ucs4::string wkey = unicode_cast<ucs4::string>(key);
|
||||
|
||||
// They may really want a specific key on the keyboard:
|
||||
// we assume that any single character keyname is a character.
|
||||
if (wkey.size() > 1) {
|
||||
|
||||
keycode_ = sdl_keysym_from_name(key);
|
||||
if (keycode_ == SDLK_UNKNOWN) {
|
||||
if (tolower(key[0]) != 'f') {
|
||||
ERR_CF << "hotkey key '" << key << "' invalid" << std::endl;
|
||||
} else {
|
||||
int num = lexical_cast_default<int>(key.c_str() + 1);
|
||||
keycode_ = num + SDLK_F1 - 1;
|
||||
}
|
||||
BOOST_FOREACH(hotkey_ptr item, hotkeys_) {
|
||||
if (!item->is_default()) {
|
||||
item->save(cfg.add_child("hotkey"));
|
||||
}
|
||||
} else if (key == " " || shift_
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_names(std::string id)
|
||||
{
|
||||
|
||||
std::vector<std::string> names;
|
||||
BOOST_FOREACH(const hotkey::hotkey_ptr item, hotkeys_) {
|
||||
if (item->get_command() == id && (!item->null())) {
|
||||
names.push_back(item->get_name());
|
||||
}
|
||||
}
|
||||
|
||||
// These are hard-coded, non-rebindable hotkeys
|
||||
if (id == "quit") {
|
||||
names.push_back("escape");
|
||||
}
|
||||
else if (id == "quit-to-desktop") {
|
||||
#ifdef __APPLE__
|
||||
|| alt_
|
||||
names.push_back("cmd+q");
|
||||
#else
|
||||
names.push_back("alt+F4");
|
||||
#endif
|
||||
) {
|
||||
// Space must be treated as a key because shift-space
|
||||
// isn't a different character from space,
|
||||
// and control key makes it go weird.
|
||||
// shift=yes should never be specified on single characters
|
||||
// (eg. key=m, shift=yes would be key=M),
|
||||
// but we don't want to break old preferences files.
|
||||
keycode_ = wkey[0];
|
||||
} else {
|
||||
character_ = wkey[0];
|
||||
}
|
||||
}
|
||||
|
||||
void hotkey_item::set_command(const std::string& command) {
|
||||
command_ = command;
|
||||
}
|
||||
|
||||
std::string hotkey_item::get_name() const
|
||||
{
|
||||
std::stringstream str;
|
||||
|
||||
if (shift_) { str << "shift+"; }
|
||||
if (ctrl_) { str << "ctrl+"; }
|
||||
if (cmd_) { str << "cmd+"; }
|
||||
if (alt_) { str << "alt+"; }
|
||||
|
||||
if (mouse_ >= 0) { str << _("Mouse") << mouse_ << _("Button") << button_; }
|
||||
if (character_ != -1) { str << static_cast<char>(character_); }
|
||||
if (keycode_ != -1) { str << SDL_GetKeyName(SDLKey(keycode_)); }
|
||||
if (joystick_ >= 0) { str << _("Joystick") << joystick_ << _("Button") << button_; }
|
||||
|
||||
if (value_ >= 0) {
|
||||
std::string direction;
|
||||
switch (value_) {
|
||||
case SDL_HAT_CENTERED:
|
||||
direction = _("Centered");
|
||||
break;
|
||||
case SDL_HAT_UP:
|
||||
direction = _("Up");
|
||||
break;
|
||||
case SDL_HAT_RIGHT:
|
||||
direction = _("Right");
|
||||
break;
|
||||
case SDL_HAT_DOWN:
|
||||
direction = _("Down");
|
||||
break;
|
||||
case SDL_HAT_LEFT:
|
||||
direction = _("Left");
|
||||
break;
|
||||
case SDL_HAT_RIGHTUP:
|
||||
direction = _("RightUp");
|
||||
break;
|
||||
case SDL_HAT_RIGHTDOWN:
|
||||
direction = _("RightDown");
|
||||
break;
|
||||
case SDL_HAT_LEFTUP:
|
||||
direction = _("LeftUp");
|
||||
break;
|
||||
case SDL_HAT_LEFTDOWN:
|
||||
direction = _("LeftDown");
|
||||
break;
|
||||
default:
|
||||
direction = _("Unknown");
|
||||
break;
|
||||
}
|
||||
str << _("Joystick") << joystick_ << _("Hat") << button_ << direction;
|
||||
}
|
||||
|
||||
return str.str();
|
||||
}
|
||||
|
||||
void hotkey_item::clear()
|
||||
{
|
||||
command_ = "null";
|
||||
}
|
||||
|
||||
void hotkey_item::save(config& item) const
|
||||
{
|
||||
if (get_button() >= 0) item["button"] = get_button();
|
||||
if (get_joystick() >= 0) item["joystick"] = get_joystick();
|
||||
if (get_hat() >= 0) item["hat"] = get_hat();
|
||||
if (get_value() >= 0) item["value"] = get_value();
|
||||
if (get_keycode() >= 0) item["key"] = SDL_GetKeyName(SDLKey(get_keycode()));
|
||||
if (get_character() >= 0) item["key"] = unicode_cast<utf8::string>(static_cast<ucs4::char_t>(get_character()));
|
||||
if (get_mouse() >= 0) item["mouse"] = get_mouse();
|
||||
if (get_button() >= 0) item["button"] = get_button();
|
||||
|
||||
item["command"] = get_command();
|
||||
if (get_shift()) item["shift"] = get_shift();
|
||||
if (get_ctrl() ) item["ctrl"] = get_ctrl();
|
||||
if (get_cmd() ) item["cmd"] = get_cmd();
|
||||
if (get_alt() ) item["alt"] = get_alt();
|
||||
}
|
||||
|
||||
void hotkey_item::set_jbutton(int joystick, int button,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
{
|
||||
joystick_ = joystick;
|
||||
button_ = button;
|
||||
shift_ = shift;
|
||||
ctrl_ = ctrl;
|
||||
cmd_ = cmd;
|
||||
alt_ = alt;
|
||||
}
|
||||
|
||||
void hotkey_item::set_jhat(int joystick, int hat, int value,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
{
|
||||
joystick_ = joystick;
|
||||
hat_ = hat;
|
||||
value_ = value;
|
||||
shift_ = shift;
|
||||
ctrl_ = ctrl;
|
||||
cmd_ = cmd;
|
||||
alt_ = alt;
|
||||
}
|
||||
|
||||
void hotkey_item::set_mbutton(int mouse, int button,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
{
|
||||
mouse_ = mouse;
|
||||
button_ = button;
|
||||
shift_ = shift;
|
||||
ctrl_ = ctrl;
|
||||
cmd_ = cmd;
|
||||
alt_ = alt;
|
||||
}
|
||||
|
||||
void hotkey_item::set_key(int character, int keycode,
|
||||
bool shift, bool ctrl, bool cmd, bool alt)
|
||||
{
|
||||
LOG_G << "setting hotkey: char=" << lexical_cast<std::string>(character)
|
||||
<< " keycode=" << lexical_cast<std::string>(keycode) << " "
|
||||
<< (shift ? "shift," : "")
|
||||
<< (ctrl ? "ctrl," : "")
|
||||
<< (cmd ? "cmd," : "")
|
||||
<< (alt ? "alt," : "")
|
||||
<< "\n";
|
||||
|
||||
// Sometimes control modifies by -64, ie ^A == 1.
|
||||
if (character < 64 && ctrl) {
|
||||
if (shift) {
|
||||
character += 64; }
|
||||
else {
|
||||
character += 96; }
|
||||
LOG_G << "Mapped to character " << lexical_cast<std::string>(character) << "\n";
|
||||
}
|
||||
|
||||
// For some reason on Mac OS, if cmd and shift are down, the character doesn't get upper-cased
|
||||
if (cmd && character > 96 && character < 123 && shift) {
|
||||
character -= 32; }
|
||||
|
||||
// We handle simple cases by character, others by the actual key.
|
||||
// @ and ` are exceptions related to the space character. Without these, combinations involving Ctrl or Ctrl+Shift often resolve the character value to null (or @ and `).
|
||||
// j and m exceptions are to catch Ctrl+Return/Enter, which is interpreted as Ctrl+j and Ctrl+m characters (LF and CR respectively).
|
||||
if (isprint(character) && !isspace(character) &&
|
||||
character != '@' && character != '`' &&
|
||||
!(tolower(character) == 'j' && keycode != SDLK_j) &&
|
||||
!(tolower(character) == 'm' && keycode != SDLK_m)) {
|
||||
character_ = character;
|
||||
ctrl_ = ctrl;
|
||||
cmd_ = cmd;
|
||||
alt_ = alt;
|
||||
LOG_G << "type = BY_CHARACTER\n";
|
||||
} else {
|
||||
keycode_ = keycode;
|
||||
shift_ = shift;
|
||||
ctrl_ = ctrl;
|
||||
cmd_ = cmd;
|
||||
alt_ = alt;
|
||||
LOG_G << "type = BY_KEYCODE\n";
|
||||
}
|
||||
return boost::algorithm::join(names, ", ");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,154 +12,403 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HOTKEY_ITEM_HPP_INCLUDED
|
||||
#define HOTKEY_ITEM_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL.h"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <vector>
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
#include "sdl/keyboard.hpp"
|
||||
#endif
|
||||
|
||||
namespace hotkey {
|
||||
|
||||
/* forward declarations */
|
||||
class hotkey_base;
|
||||
class hotkey_mouse;
|
||||
class hotkey_keyboard;
|
||||
typedef boost::shared_ptr<hotkey_base> hotkey_ptr;
|
||||
typedef boost::shared_ptr<hotkey_mouse> hotkey_mouse_ptr;
|
||||
typedef boost::shared_ptr<hotkey_keyboard> hotkey_keyboard_ptr;
|
||||
|
||||
class hotkey_item {
|
||||
typedef std::vector<hotkey::hotkey_ptr> hotkey_list;
|
||||
typedef std::vector<hotkey::hotkey_ptr>::iterator hotkey_list_iter;
|
||||
|
||||
/**
|
||||
* This is the base class for hotkey event matching.
|
||||
*/
|
||||
class hotkey_base
|
||||
{
|
||||
public:
|
||||
|
||||
explicit hotkey_item(const std::string& command) :
|
||||
command_(command),
|
||||
shift_(false), ctrl_(false), cmd_(false), alt_(false),
|
||||
character_(-1), keycode_(-1),
|
||||
joystick_(-1), mouse_(-1),
|
||||
button_(-1), hat_(-1), value_(-1),
|
||||
is_default_(false)
|
||||
/**
|
||||
* Initialises a new empty hotkey that will be disabled
|
||||
*/
|
||||
hotkey_base() : command_("null"), is_default_(true), mod_(0)
|
||||
{}
|
||||
|
||||
explicit hotkey_item(const config& cfg, bool is_default):
|
||||
command_("null"),
|
||||
shift_(false), ctrl_(false), cmd_(false), alt_(false),
|
||||
character_(-1), keycode_(-1),
|
||||
joystick_(-1), mouse_(-1),
|
||||
button_(-1), hat_(-1), value_(-1),
|
||||
is_default_(is_default)
|
||||
void set_command(const std::string& command)
|
||||
{
|
||||
load_from_config(cfg);
|
||||
command_ = command;
|
||||
}
|
||||
|
||||
void load_from_config(const config& cfg);
|
||||
/**
|
||||
* Set keyboard modifiers.
|
||||
* @param mods Bitmask of SDLMod.
|
||||
*/
|
||||
void set_mods(unsigned int mods)
|
||||
{
|
||||
mod_ = mods;
|
||||
}
|
||||
|
||||
void set_command(const std::string& command);
|
||||
/**
|
||||
* Returns the string name of the HOTKEY_COMMAND
|
||||
* @return The unique string for a hotkey command.
|
||||
**/
|
||||
const std::string& get_command() const
|
||||
{
|
||||
return command_;
|
||||
}
|
||||
|
||||
/** get the string name of the HOTKEY_COMMAND */
|
||||
const std::string get_command() const { return command_; }
|
||||
/** The translated description */
|
||||
/**
|
||||
* Returns the translated description
|
||||
* @todo unused
|
||||
* @return internationalised description of the command.
|
||||
**/
|
||||
const std::string get_description() const;
|
||||
/** @return if the item should appear in the hotkey preferences */
|
||||
bool hidden() const;
|
||||
|
||||
bool is_default() const { return is_default_; }
|
||||
|
||||
void unset_default(bool is_not_default = true) {
|
||||
is_default_ = !is_not_default;
|
||||
/**
|
||||
* This controls whether the item should appear in the hotkey preferences.
|
||||
* @return true if the item should be hidden
|
||||
**/
|
||||
virtual bool hidden() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Return "name" of hotkey. Example :"ctrl+alt+g"
|
||||
std::string get_name() const;
|
||||
/**
|
||||
* This indicates whether a hotkey is from the default config or if it's
|
||||
* from the user preferences.
|
||||
* @return true if from the default configurations, false otherwise
|
||||
*/
|
||||
bool is_default() const
|
||||
{
|
||||
return is_default_;
|
||||
}
|
||||
|
||||
void clear();
|
||||
/**
|
||||
* Used to indicate that a hotkey is overriden and should be treated as
|
||||
* a user-set hotkey.
|
||||
*/
|
||||
void unset_default()
|
||||
{
|
||||
is_default_ = false;
|
||||
}
|
||||
|
||||
bool null() const { return command_ == "null"; }
|
||||
/**
|
||||
* Unbind this hotkey by linking it to the null-command
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
command_ = "null";
|
||||
}
|
||||
|
||||
/// returns weather there is a associated hotkey_command.
|
||||
// if the none of the hotkey_commands fits this hotkey_item then get_hotkey_command will return the hotkey_command::null_command().
|
||||
bool active() const;
|
||||
/**
|
||||
* Returns whether this hotkey points to the null-command
|
||||
* @return true if it points to the null-command, false otherwise.
|
||||
*/
|
||||
bool null() const
|
||||
{
|
||||
return command_ == "null";
|
||||
}
|
||||
|
||||
/// checks weather that hotkey "makes sense" meaning weather one of character, keycode, joystick, mouse, button, hat, value is set.
|
||||
/// i don't know what the axis_.. values are so i ignore them.
|
||||
bool valid() const;
|
||||
/*
|
||||
* Returns whether there is a associated hotkey_command.
|
||||
* If the none of the hotkey_commands fits this hotkey_item then
|
||||
* @param get_hotkey_command will return the hotkey_command::null_command().
|
||||
* @return true if the hotkey is not bound to the null-command.
|
||||
*/
|
||||
bool active() const
|
||||
{
|
||||
return command_ != "null";
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates whether the hotkey bindings are valid.
|
||||
* @return true if they are valid, false otherwise.
|
||||
*/
|
||||
virtual bool valid() const = 0;
|
||||
|
||||
/**
|
||||
* Save the hotkey into the configuration object.
|
||||
* @param cfg The configuration object to save into.
|
||||
*/
|
||||
void save(config& cfg) const;
|
||||
|
||||
/// Return the actual key code.
|
||||
int get_keycode() const { return keycode_; }
|
||||
/// Returns unicode value of the pressed key.
|
||||
int get_character() const { return character_; }
|
||||
/**
|
||||
* Return "name" of hotkey. Example :"ctrl+alt+g"
|
||||
* @return The string representation of the keybindings
|
||||
*/
|
||||
const std::string get_name() const;
|
||||
|
||||
/** for buttons on devices */
|
||||
int get_button() const { return button_; }
|
||||
int get_joystick() const { return joystick_; }
|
||||
int get_hat() const { return hat_; }
|
||||
int get_mouse() const { return mouse_; }
|
||||
int get_value() const { return value_; }
|
||||
/**
|
||||
* Used to evaluate whether:
|
||||
* 1. The hotkey is valid in the current scope.
|
||||
* 2. The Keyboard modifiers and SDL_Event mathes this hotkey.
|
||||
*
|
||||
* @param event The @SDL_Event that has triggered and is being evaluated.
|
||||
*/
|
||||
bool matches(const SDL_Event &event) const;
|
||||
|
||||
/** modifiers */
|
||||
bool get_shift() const { return shift_; }
|
||||
bool get_ctrl() const { return ctrl_; }
|
||||
bool get_cmd() const { return cmd_; }
|
||||
bool get_alt() const { return alt_; }
|
||||
/**
|
||||
* Checks whether the hotkey bindings and scope are equal.
|
||||
* @param other the hokey bindings to compare against.
|
||||
* @return true if %other has same scope and bindings.
|
||||
*/
|
||||
virtual bool bindings_equal(hotkey_ptr other);
|
||||
|
||||
void set_jbutton(int button, int joystick, bool shift, bool ctrl, bool cmd, bool alt);
|
||||
void set_jhat(int joystick, int hat, int value, bool shift, bool ctrl, bool cmd, bool alt);
|
||||
void set_key(int character, int keycode, bool shift, bool ctrl, bool cmd, bool alt);
|
||||
void set_mbutton(int device, int button, bool shift, bool ctrl, bool cmd, bool alt);
|
||||
virtual ~hotkey_base()
|
||||
{}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This is invoked by hotkey_base::get_name and must be implemented by subclasses.
|
||||
* Keyboard modifiers are handled in this class, other hotkeys in the respective classes
|
||||
*/
|
||||
virtual const std::string get_name_helper() const = 0;
|
||||
/**
|
||||
* This is invoked by hotkey_base::matches as a helper for the concrete classes.
|
||||
* Implementing classes should only check their parts of the hotkey.
|
||||
* @param event The SDL_Event being generated.
|
||||
* @returns true if they match, false otherwise.
|
||||
*/
|
||||
virtual bool matches_helper(const SDL_Event &event) const = 0;
|
||||
virtual void save_helper(config& cfg) const = 0;
|
||||
/**
|
||||
* This is invoked by hotkey_base::bindings_equal as a helper for the concrete classes.
|
||||
* Implementing classes should only check their parts of the hotkey.
|
||||
* @param other The other hotkey the check against. Not guaranteed to be the same subclass.
|
||||
* @returns true if they match, false otherwise.
|
||||
*/
|
||||
virtual bool bindings_equal_helper(hotkey_ptr other) const = 0;
|
||||
|
||||
// The unique command associated with this item.
|
||||
// Used to bind to a hotkey_command struct.
|
||||
/**
|
||||
* The command that should be executed, or "null".
|
||||
*/
|
||||
std::string command_;
|
||||
|
||||
// modifier keys
|
||||
bool shift_, ctrl_, cmd_, alt_;
|
||||
|
||||
// Actual unicode character
|
||||
int character_;
|
||||
|
||||
// These used for function keys (which don't have a unicode value) or
|
||||
// space (which doesn't have a distinct unicode value when shifted).
|
||||
int keycode_;
|
||||
|
||||
int joystick_, mouse_;
|
||||
int button_;
|
||||
int hat_, value_;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
bool is_default_;
|
||||
|
||||
/*
|
||||
* Keyboard modifiers. Treat as opaque, only do comparisons.
|
||||
*
|
||||
*/
|
||||
unsigned int mod_;
|
||||
};
|
||||
|
||||
/// Initiated weather there is at least one hotkey_item with the given command
|
||||
/**
|
||||
* This class is responsible for handling keys, not modifiers.
|
||||
*/
|
||||
class hotkey_keyboard: public hotkey_base
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initialise new instance of this class that has no key associated with is.
|
||||
*/
|
||||
hotkey_keyboard() : hotkey_base(), scancode_(SDL_SCANCODE_UNKNOWN)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Set the scancode associated with this class.
|
||||
* @param scancode The SDL_Scancode that this hotkey should be associated with
|
||||
*/
|
||||
void set_scancode(SDL_Scancode scancode)
|
||||
{
|
||||
scancode_ = scancode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this hotkey has been set to a sensible value.
|
||||
* @ return true if it is a known key
|
||||
*/
|
||||
virtual bool valid() const
|
||||
{
|
||||
return scancode_ != SDL_SCANCODE_UNKNOWN;
|
||||
}
|
||||
|
||||
protected:
|
||||
SDL_Scancode scancode_;
|
||||
|
||||
virtual void save_helper(config& cfg) const;
|
||||
virtual const std::string get_name_helper() const;
|
||||
virtual bool matches_helper(const SDL_Event &event) const;
|
||||
virtual bool bindings_equal_helper (hotkey_ptr other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is used to return non-valid results in order to save
|
||||
* other people from null checks.
|
||||
*/
|
||||
class hotkey_void: public hotkey_base
|
||||
{
|
||||
public:
|
||||
hotkey_void() : hotkey_base()
|
||||
{}
|
||||
virtual bool valid() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
protected:
|
||||
virtual void save_helper(config&) const
|
||||
{}
|
||||
virtual const std::string get_name_helper() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual bool matches_helper(const SDL_Event&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool bindings_equal_helper(hotkey_ptr) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is responsible for handling mouse button presses.
|
||||
*/
|
||||
class hotkey_mouse: public hotkey_base
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initialise new instance of this class that has no button associated with is.
|
||||
*/
|
||||
hotkey_mouse() : hotkey_base(), button_ (0)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Returns true if the hotkey has a valid mouse button associated with it.
|
||||
* @return true if a mouse button is set, false otherwise.
|
||||
*/
|
||||
virtual bool valid() const
|
||||
{
|
||||
return button_ != 0;
|
||||
}
|
||||
|
||||
/* new functionality for this class */
|
||||
void set_button(int button)
|
||||
{
|
||||
button_ = button;
|
||||
}
|
||||
protected:
|
||||
int button_;
|
||||
|
||||
virtual void save_helper(config& cfg) const;
|
||||
virtual const std::string get_name_helper() const;
|
||||
virtual bool matches_helper(const SDL_Event &event) const;
|
||||
virtual bool bindings_equal_helper (hotkey_ptr other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @todo not implemented
|
||||
*/
|
||||
class hotkey_joystick: public hotkey_base
|
||||
{
|
||||
protected:
|
||||
int button_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create and instantiate a hotkey from a config element.
|
||||
* @param cfg The config element to read for data.
|
||||
* @return The new instance of the hotkey item.
|
||||
*/
|
||||
hotkey_ptr load_from_config(const config& cfg);
|
||||
|
||||
/*
|
||||
* Scans the list of hotkeys to see if one has been bound to the command.
|
||||
* @param command The command that is searched for
|
||||
* @return true if there is a hotkey item that has the command bound.
|
||||
*/
|
||||
bool has_hotkey_item(const std::string& command);
|
||||
|
||||
void add_hotkey(const hotkey_item& item);
|
||||
/**
|
||||
* Add a hotkey to the list of hotkeys.
|
||||
* @param item The item to add.
|
||||
*/
|
||||
void add_hotkey(const hotkey_ptr item);
|
||||
|
||||
const hotkey_item& get_hotkey(int mouse, int joystick,
|
||||
int button, int hat, int value,
|
||||
bool shift, bool ctrl, bool cmd, bool alt);
|
||||
const hotkey_item& get_hotkey(int character, int keycode,
|
||||
bool shift, bool ctrl, bool cmd, bool alt);
|
||||
/**
|
||||
* Remove a hotkey from the list of hotkeys
|
||||
* @todo unusued?
|
||||
*/
|
||||
void del_hotkey(const hotkey_ptr item);
|
||||
|
||||
const hotkey_item& get_hotkey(const SDL_JoyButtonEvent& event);
|
||||
const hotkey_item& get_hotkey(const SDL_JoyHatEvent& event);
|
||||
const hotkey_item& get_hotkey(const SDL_KeyboardEvent& event);
|
||||
const hotkey_item& get_hotkey(const SDL_MouseButtonEvent& event);
|
||||
/**
|
||||
* Create a new hotkey item for a command from an SDL_Event.
|
||||
* @param id The command to bind to.
|
||||
* @param event The SDL_Event to base the creation on.
|
||||
*/
|
||||
hotkey_ptr create_hotkey(const std::string &id, SDL_Event &event);
|
||||
|
||||
/**
|
||||
* Iterate through the list of hotkeys and return a hotkey that matches
|
||||
* the SDL_Event and the current keyboard modifier state.
|
||||
* @param event The SDL_Event to use as a template.
|
||||
* @return The newly created hotkey item.
|
||||
*/
|
||||
const hotkey_ptr get_hotkey(const SDL_Event &event);
|
||||
|
||||
/**
|
||||
* Iterates through all hotkeys present in the config struct and creates and adds
|
||||
* them to the hotkey list.
|
||||
* @param cfg The config struct to load from.
|
||||
* @param set_as_default Indicates whether the config struct should be treated as the
|
||||
* default game settings.
|
||||
*/
|
||||
void load_hotkeys(const config& cfg, bool set_as_default = false);
|
||||
|
||||
/**
|
||||
* Reset all hotkeys to the defaults.
|
||||
*/
|
||||
void reset_default_hotkeys();
|
||||
|
||||
const std::vector<hotkey_item>& get_hotkeys();
|
||||
/**
|
||||
* Returns the list of hotkeys.
|
||||
*/
|
||||
const hotkey_list& get_hotkeys();
|
||||
|
||||
/**
|
||||
* Unset the command bindings for all hotkeys matching the command.
|
||||
* @command The binding to be unset
|
||||
*/
|
||||
void clear_hotkeys(const std::string& command);
|
||||
|
||||
/**
|
||||
* Unset the bindings for all hotkeys.
|
||||
*/
|
||||
void clear_hotkeys();
|
||||
|
||||
/// returns all hotkey_item s that point to this, command in the form "A,Strg+M,F4"
|
||||
/// used in the preferences menu
|
||||
/**
|
||||
* Returns a comma-separated string of hotkey names. A hotkey name is in the form of
|
||||
* "ctrl+l" or "n" or "mouse 1". The comman separated string is of the form "ctrl+l,n,mouse 1".
|
||||
* @return The comma separated string of hotkey names.
|
||||
*/
|
||||
std::string get_names(std::string id);
|
||||
|
||||
/**
|
||||
* Save the non-default hotkeys to the config.
|
||||
* @param cfg The config to save to.
|
||||
*/
|
||||
void save_hotkeys(config& cfg);
|
||||
|
||||
/// Append a single hotkey item to @a cfg.
|
||||
//void save_hotkey(config& cfg, const hotkey_item & item);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -590,8 +590,7 @@ void hotkey_preferences_dialog::show_binding_dialog(
|
|||
disp_.update_display();
|
||||
SDL_Event event;
|
||||
event.type = 0;
|
||||
int character = -1, keycode = -1, mod = -1;
|
||||
int mouse = -1, joystick = -1, button = -1, hat = -1, value = -1;
|
||||
int keycode = -1, mod = -1;
|
||||
const int any_mod = KMOD_CTRL | KMOD_META | KMOD_ALT;
|
||||
|
||||
while ( event.type != SDL_KEYDOWN && event.type != SDL_JOYBUTTONDOWN
|
||||
|
@ -599,35 +598,24 @@ void hotkey_preferences_dialog::show_binding_dialog(
|
|||
&& (event.type != SDL_MOUSEBUTTONDOWN )
|
||||
)
|
||||
SDL_PollEvent(&event);
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
events::peek_for_resize();
|
||||
#endif
|
||||
|
||||
do {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
keycode = event.key.keysym.sym;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
character = event.key.keysym.scancode,
|
||||
#else
|
||||
character = event.key.keysym.unicode;
|
||||
#endif
|
||||
mod = event.key.keysym.mod;
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
joystick = event.jbutton.which;
|
||||
button = event.jbutton.button;
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
joystick = event.jhat.which;
|
||||
hat = event.jhat.hat;
|
||||
value = event.jhat.value;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mouse = event.button.which;
|
||||
button = event.button.button;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
SDL_PollEvent(&event);
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
events::peek_for_resize();
|
||||
#endif
|
||||
disp_.flip();
|
||||
disp_.delay(10);
|
||||
} while (event.type != SDL_KEYUP && event.type != SDL_JOYBUTTONUP
|
||||
|
@ -637,46 +625,18 @@ void hotkey_preferences_dialog::show_binding_dialog(
|
|||
restorer.restore();
|
||||
disp_.update_display();
|
||||
|
||||
// only if not canceled.
|
||||
// only if not cancelled.
|
||||
if (!(keycode == SDLK_ESCAPE && (mod & any_mod) == 0)) {
|
||||
hotkey::scope_changer scope_restorer;
|
||||
hotkey::set_active_scopes(hotkey::get_hotkey_command(id).scope);
|
||||
|
||||
hotkey::hotkey_item newhk(id);
|
||||
const hotkey::hotkey_item* oldhk = NULL;
|
||||
hotkey::hotkey_ptr newhk;
|
||||
hotkey::hotkey_ptr oldhk;
|
||||
|
||||
CKey keystate;
|
||||
bool shift = keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT];
|
||||
bool ctrl = keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL];
|
||||
bool cmd = keystate[SDLK_RMETA] || keystate[SDLK_LMETA];
|
||||
bool alt = keystate[SDLK_RALT] || keystate[SDLK_LALT];
|
||||
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_JOYHATMOTION:
|
||||
oldhk = &hotkey::get_hotkey(mouse, joystick, button, hat, value,
|
||||
shift, ctrl, cmd, alt);
|
||||
newhk.set_jhat(joystick, hat, value, shift, ctrl, cmd, alt);
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
oldhk = &hotkey::get_hotkey(-1, joystick, button, -1, -1,
|
||||
shift, ctrl, cmd, alt);
|
||||
newhk.set_jbutton(joystick, button, shift, ctrl, cmd, alt);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
oldhk = &hotkey::get_hotkey(mouse, -1, button, -1, -1,
|
||||
shift, ctrl, cmd, alt);
|
||||
newhk.set_mbutton(mouse, button, shift, ctrl, cmd, alt);
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
oldhk =
|
||||
&hotkey::get_hotkey( character, keycode,
|
||||
(mod & KMOD_SHIFT) != 0, (mod & KMOD_CTRL) != 0,
|
||||
(mod & KMOD_LMETA) != 0, (mod & KMOD_ALT) != 0 );
|
||||
newhk.set_key(character, keycode, (mod & KMOD_SHIFT) != 0,
|
||||
(mod & KMOD_CTRL) != 0, (mod & KMOD_LMETA) != 0,
|
||||
(mod & KMOD_ALT) != 0);
|
||||
oldhk = hotkey::get_hotkey(event);
|
||||
newhk = hotkey::create_hotkey(id, event);
|
||||
|
||||
#if 0
|
||||
//TODO
|
||||
// if ( (hotkey::get_id(newhk.get_command()) == hotkey::HOTKEY_SCREENSHOT
|
||||
// || hotkey::get_id(newhk.get_command()) == hotkey::HOTKEY_MAP_SCREENSHOT)
|
||||
|
@ -687,6 +647,7 @@ Control, Alt or Meta modifiers to avoid problems.")); */
|
|||
// }
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (oldhk && oldhk->active()) {
|
||||
if (oldhk->get_command() != id) {
|
||||
|
@ -694,7 +655,7 @@ Control, Alt or Meta modifiers to avoid problems.")); */
|
|||
utils::string_map symbols;
|
||||
symbols["hotkey_sequence"] = oldhk->get_name();
|
||||
symbols["old_hotkey_action"] = hotkey::get_description(oldhk->get_command());
|
||||
symbols["new_hotkey_action"] = hotkey::get_description(newhk.get_command());
|
||||
symbols["new_hotkey_action"] = hotkey::get_description(newhk->get_command());
|
||||
|
||||
std::string text =
|
||||
vgettext("\"$hotkey_sequence|\" is in use by \
|
||||
|
|
|
@ -281,6 +281,7 @@ bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_c
|
|||
case hotkey::HOTKEY_UNIT_LIST:
|
||||
case hotkey::HOTKEY_STATISTICS:
|
||||
case hotkey::HOTKEY_QUIT_GAME:
|
||||
case hotkey::HOTKEY_QUIT_TO_DESKTOP:
|
||||
case hotkey::HOTKEY_SEARCH:
|
||||
case hotkey::HOTKEY_HELP:
|
||||
case hotkey::HOTKEY_USER_CMD:
|
||||
|
|
|
@ -1179,7 +1179,7 @@ REGISTER_MOD_PARSER(DARKEN, )
|
|||
// Add a background color.
|
||||
REGISTER_MOD_PARSER(BG, args)
|
||||
{
|
||||
int c[4] = { 0, 0, 0, 255 };
|
||||
int c[4] = { 0, 0, 0, SDL_ALPHA_OPAQUE };
|
||||
std::vector<std::string> factors = utils::split(args, ',');
|
||||
|
||||
for (int i = 0; i < std::min<int>(factors.size(), 4); ++i) {
|
||||
|
|
|
@ -41,7 +41,7 @@ static bool attached(
|
|||
const std::vector<SDL_Joystick*>& joysticks
|
||||
, const size_t index)
|
||||
{
|
||||
return SDL_JoystickGetAttached(joysticks[index]);
|
||||
return SDL_JoystickGetAttached(joysticks[index]) == SDL_TRUE;
|
||||
}
|
||||
|
||||
static const char* name(
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include "video.hpp"
|
||||
#include "image.hpp"
|
||||
#include "text.hpp"
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
#include "display.hpp"
|
||||
#endif
|
||||
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_image.h>
|
||||
|
@ -199,7 +202,7 @@ void loadscreen::draw_screen(const std::string &text)
|
|||
}
|
||||
screen_.flip();
|
||||
#else
|
||||
surface gdis = screen_.getSurface();
|
||||
surface& gdis = screen_.getSurface();
|
||||
SDL_Rect area;
|
||||
|
||||
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
|
||||
|
@ -207,8 +210,12 @@ void loadscreen::draw_screen(const std::string &text)
|
|||
while(SDL_PollEvent(&ev)) {
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
if (ev.type == SDL_WINDOWEVENT &&
|
||||
(ev.window.type == SDL_WINDOWEVENT_RESIZED ||
|
||||
ev.window.type == SDL_WINDOWEVENT_EXPOSED))
|
||||
ev.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
update_framebuffer();
|
||||
}
|
||||
if (ev.type == SDL_WINDOWEVENT &&
|
||||
(ev.window.event == SDL_WINDOWEVENT_RESIZED ||
|
||||
ev.window.event == SDL_WINDOWEVENT_EXPOSED))
|
||||
#else
|
||||
if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE)
|
||||
#endif
|
||||
|
@ -298,7 +305,7 @@ void loadscreen::clear_screen()
|
|||
int scrx = screen_.getx(); // Screen width.
|
||||
int scry = screen_.gety(); // Screen height.
|
||||
SDL_Rect area = sdl::create_rect(0, 0, scrx, scry); // Screen area.
|
||||
surface disp(screen_.getSurface()); // Screen surface.
|
||||
surface& disp(screen_.getSurface()); // Screen surface.
|
||||
// Make everything black.
|
||||
sdl::fill_rect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
|
||||
update_whole_screen();
|
||||
|
|
|
@ -50,14 +50,14 @@ const std::string weapon = "<245,230,193>",
|
|||
race = "<166,146,117>";
|
||||
|
||||
const SDL_Color
|
||||
weapon_color = { 245, 230, 193, 255 },
|
||||
good_dmg_color = { 130, 240, 50, 255 },
|
||||
bad_dmg_color = { 250, 140, 80, 255 },
|
||||
weapon_details_color = { 166, 146, 117, 255 },
|
||||
inactive_details_color = { 146, 146, 146, 255 },
|
||||
inactive_ability_color = { 146, 146, 146, 255 },
|
||||
unit_type_color = { 245, 230, 193, 255 },
|
||||
race_color = { 166, 146, 117, 255 };
|
||||
weapon_color = { 245, 230, 193, SDL_ALPHA_OPAQUE },
|
||||
good_dmg_color = { 130, 240, 50, SDL_ALPHA_OPAQUE },
|
||||
bad_dmg_color = { 250, 140, 80, SDL_ALPHA_OPAQUE },
|
||||
weapon_details_color = { 166, 146, 117, SDL_ALPHA_OPAQUE },
|
||||
inactive_details_color = { 146, 146, 146, SDL_ALPHA_OPAQUE },
|
||||
inactive_ability_color = { 146, 146, 146, SDL_ALPHA_OPAQUE },
|
||||
unit_type_color = { 245, 230, 193, SDL_ALPHA_OPAQUE },
|
||||
race_color = { 166, 146, 117, SDL_ALPHA_OPAQUE };
|
||||
|
||||
const std::string weapon_numbers_sep = "–", weapon_details_sep = "–";
|
||||
|
||||
|
@ -190,7 +190,7 @@ SDL_Rect text_area(const std::string& text, int size, int style)
|
|||
return draw_text(NULL, area, size, font::NORMAL_COLOR, text, 0, 0, false, style);
|
||||
}
|
||||
|
||||
SDL_Rect draw_text(surface dst, const SDL_Rect& area, int size,
|
||||
SDL_Rect draw_text(surface& dst, const SDL_Rect& area, int size,
|
||||
const SDL_Color& color, const std::string& txt,
|
||||
int x, int y, bool use_tooltips, int style)
|
||||
{
|
||||
|
@ -241,7 +241,9 @@ SDL_Rect draw_text(CVideo* gui, const SDL_Rect& area, int size,
|
|||
const SDL_Color& color, const std::string& txt,
|
||||
int x, int y, bool use_tooltips, int style)
|
||||
{
|
||||
return draw_text(gui != NULL ? gui->getSurface() : NULL, area, size, color, txt, x, y, use_tooltips, style);
|
||||
surface null_surf = surface(NULL);
|
||||
|
||||
return draw_text(gui != NULL ? gui->getSurface() : null_surf, area, size, color, txt, x, y, use_tooltips, style);
|
||||
}
|
||||
|
||||
bool is_format_char(char c)
|
||||
|
|
|
@ -76,7 +76,7 @@ std::string::const_iterator parse_markup(std::string::const_iterator i1,
|
|||
* A bounding rectangle of the text is returned. If dst is NULL, then the
|
||||
* text will not be drawn, and a bounding rectangle only will be returned.
|
||||
*/
|
||||
SDL_Rect draw_text(surface dst, const SDL_Rect& area, int size,
|
||||
SDL_Rect draw_text(surface& dst, const SDL_Rect& area, int size,
|
||||
const SDL_Color& color, const std::string& text,
|
||||
int x, int y, bool use_tooltips = false, int style = 0);
|
||||
|
||||
|
|
|
@ -349,7 +349,7 @@ SDL_Rect draw_minimap(CVideo &video, const SDL_Rect &area, const gamemap &map, c
|
|||
SDL_Color col;
|
||||
std::map<std::string, color_range>::const_iterator it = game_config::team_rgb_range.find(terrain_info.id());
|
||||
if (it == game_config::team_rgb_range.end()) {
|
||||
col = create_color(0,0,0,255);
|
||||
col = create_color(0,0,0,SDL_ALPHA_OPAQUE);
|
||||
} else
|
||||
col = int_to_color(it->second.rep());
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ void playmp_controller::play_human_turn()
|
|||
{
|
||||
font::floating_label flabel(_("Undoing moves not yet transmitted to the server."));
|
||||
|
||||
SDL_Color color = {255,255,255,255};
|
||||
SDL_Color color = {255,255,255,SDL_ALPHA_OPAQUE};
|
||||
flabel.set_color(color);
|
||||
SDL_Rect rect = gui_->map_area();
|
||||
flabel.set_position(rect.w/2, rect.h/2);
|
||||
|
|
|
@ -176,11 +176,13 @@ bool set_resolution(CVideo& video
|
|||
int bpp = video.bppForMode(width, height, flags);
|
||||
|
||||
if(bpp != 0) {
|
||||
video.setMode(width, height, bpp, flags);
|
||||
//video.setMode(width, height, bpp, flags);
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if(disp) {
|
||||
disp->redraw_everything();
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
// grzywacz: is this even true?
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
int SDL_SetAlpha(SDL_Surface* surface, Uint32 flag, Uint8 alpha)
|
||||
{
|
||||
if(flag & SDL_SRCALPHA) {
|
||||
// Need to specify the alpha blend mode if not setting alpha as opaque
|
||||
int blendModeResult = SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_BLEND);
|
||||
if (blendModeResult != 0)
|
||||
return blendModeResult;
|
||||
|
||||
return SDL_SetSurfaceAlphaMod(surface, alpha);
|
||||
} else {
|
||||
return SDL_SetSurfaceAlphaMod(surface, SDL_ALPHA_OPAQUE);
|
||||
|
|
641
src/sdl/keyboard.cpp
Normal file
641
src/sdl/keyboard.cpp
Normal file
|
@ -0,0 +1,641 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
#include "sdl/keyboard.hpp"
|
||||
|
||||
#define SDLK_SCANCODE_MASK (1<<30)
|
||||
#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
|
||||
|
||||
|
||||
static const int SDL_default_keymap[SDL_NUM_SCANCODES] = {
|
||||
0, 0, 0, 0,
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
'g',
|
||||
'h',
|
||||
'i',
|
||||
'j',
|
||||
'k',
|
||||
'l',
|
||||
'm',
|
||||
'n',
|
||||
'o',
|
||||
'p',
|
||||
'q',
|
||||
'r',
|
||||
's',
|
||||
't',
|
||||
'u',
|
||||
'v',
|
||||
'w',
|
||||
'x',
|
||||
'y',
|
||||
'z',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'0',
|
||||
SDLK_RETURN,
|
||||
SDLK_ESCAPE,
|
||||
SDLK_BACKSPACE,
|
||||
SDLK_TAB,
|
||||
SDLK_SPACE,
|
||||
'-',
|
||||
'=',
|
||||
'[',
|
||||
']',
|
||||
'\\',
|
||||
'#',
|
||||
';',
|
||||
'\'',
|
||||
'`',
|
||||
',',
|
||||
'.',
|
||||
'/',
|
||||
SDLK_CAPSLOCK,
|
||||
SDLK_F1,
|
||||
SDLK_F2,
|
||||
SDLK_F3,
|
||||
SDLK_F4,
|
||||
SDLK_F5,
|
||||
SDLK_F6,
|
||||
SDLK_F7,
|
||||
SDLK_F8,
|
||||
SDLK_F9,
|
||||
SDLK_F10,
|
||||
SDLK_F11,
|
||||
SDLK_F12,
|
||||
SDLK_PRINT,
|
||||
SDLK_SCROLLOCK,
|
||||
SDLK_PAUSE,
|
||||
SDLK_INSERT,
|
||||
SDLK_HOME,
|
||||
SDLK_PAGEUP,
|
||||
SDLK_DELETE,
|
||||
SDLK_END,
|
||||
SDLK_PAGEDOWN,
|
||||
SDLK_RIGHT,
|
||||
SDLK_LEFT,
|
||||
SDLK_DOWN,
|
||||
SDLK_UP,
|
||||
0,
|
||||
SDLK_KP_DIVIDE,
|
||||
SDLK_KP_MULTIPLY,
|
||||
SDLK_KP_MINUS,
|
||||
SDLK_KP_PLUS,
|
||||
SDLK_KP_ENTER,
|
||||
SDLK_KP1,
|
||||
SDLK_KP2,
|
||||
SDLK_KP3,
|
||||
SDLK_KP4,
|
||||
SDLK_KP5,
|
||||
SDLK_KP6,
|
||||
SDLK_KP7,
|
||||
SDLK_KP8,
|
||||
SDLK_KP9,
|
||||
SDLK_KP0,
|
||||
SDLK_KP_PERIOD,
|
||||
0,
|
||||
0,
|
||||
SDLK_POWER,
|
||||
SDLK_KP_EQUALS,
|
||||
SDLK_F13,
|
||||
SDLK_F14,
|
||||
SDLK_F15,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
SDLK_HELP,
|
||||
SDLK_MENU,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
SDLK_SYSREQ,
|
||||
0,
|
||||
SDLK_CLEAR,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, 0,
|
||||
SDLK_LCTRL,
|
||||
SDLK_LSHIFT,
|
||||
SDLK_LALT,
|
||||
SDLK_LMETA,
|
||||
SDLK_RCTRL,
|
||||
SDLK_RSHIFT,
|
||||
SDLK_RALT,
|
||||
SDLK_RMETA,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
SDLK_MODE,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
|
||||
NULL, NULL, NULL, NULL,
|
||||
"A",
|
||||
"B",
|
||||
"C",
|
||||
"D",
|
||||
"E",
|
||||
"F",
|
||||
"G",
|
||||
"H",
|
||||
"I",
|
||||
"J",
|
||||
"K",
|
||||
"L",
|
||||
"M",
|
||||
"N",
|
||||
"O",
|
||||
"P",
|
||||
"Q",
|
||||
"R",
|
||||
"S",
|
||||
"T",
|
||||
"U",
|
||||
"V",
|
||||
"W",
|
||||
"X",
|
||||
"Y",
|
||||
"Z",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"0",
|
||||
"Return",
|
||||
"Escape",
|
||||
"Backspace",
|
||||
"Tab",
|
||||
"Space",
|
||||
"-",
|
||||
"=",
|
||||
"[",
|
||||
"]",
|
||||
"\\",
|
||||
"#",
|
||||
";",
|
||||
"'",
|
||||
"`",
|
||||
",",
|
||||
".",
|
||||
"/",
|
||||
"CapsLock",
|
||||
"F1",
|
||||
"F2",
|
||||
"F3",
|
||||
"F4",
|
||||
"F5",
|
||||
"F6",
|
||||
"F7",
|
||||
"F8",
|
||||
"F9",
|
||||
"F10",
|
||||
"F11",
|
||||
"F12",
|
||||
"PrintScreen",
|
||||
"ScrollLock",
|
||||
"Pause",
|
||||
"Insert",
|
||||
"Home",
|
||||
"PageUp",
|
||||
"Delete",
|
||||
"End",
|
||||
"PageDown",
|
||||
"Right",
|
||||
"Left",
|
||||
"Down",
|
||||
"Up",
|
||||
"Numlock",
|
||||
"Keypad /",
|
||||
"Keypad *",
|
||||
"Keypad -",
|
||||
"Keypad +",
|
||||
"Keypad Enter",
|
||||
"Keypad 1",
|
||||
"Keypad 2",
|
||||
"Keypad 3",
|
||||
"Keypad 4",
|
||||
"Keypad 5",
|
||||
"Keypad 6",
|
||||
"Keypad 7",
|
||||
"Keypad 8",
|
||||
"Keypad 9",
|
||||
"Keypad 0",
|
||||
"Keypad .",
|
||||
NULL,
|
||||
"Application",
|
||||
"Power",
|
||||
"Keypad =",
|
||||
"F13",
|
||||
"F14",
|
||||
"F15",
|
||||
"F16",
|
||||
"F17",
|
||||
"F18",
|
||||
"F19",
|
||||
"F20",
|
||||
"F21",
|
||||
"F22",
|
||||
"F23",
|
||||
"F24",
|
||||
"Execute",
|
||||
"Help",
|
||||
"Menu",
|
||||
"Select",
|
||||
"Stop",
|
||||
"Again",
|
||||
"Undo",
|
||||
"Cut",
|
||||
"Copy",
|
||||
"Paste",
|
||||
"Find",
|
||||
"Mute",
|
||||
"VolumeUp",
|
||||
"VolumeDown",
|
||||
NULL, NULL, NULL,
|
||||
"Keypad ,",
|
||||
"Keypad = (AS400)",
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
"AltErase",
|
||||
"SysReq",
|
||||
"Cancel",
|
||||
"Clear",
|
||||
"Prior",
|
||||
"Return",
|
||||
"Separator",
|
||||
"Out",
|
||||
"Oper",
|
||||
"Clear / Again",
|
||||
"CrSel",
|
||||
"ExSel",
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
"Keypad 00",
|
||||
"Keypad 000",
|
||||
"ThousandsSeparator",
|
||||
"DecimalSeparator",
|
||||
"CurrencyUnit",
|
||||
"CurrencySubUnit",
|
||||
"Keypad (",
|
||||
"Keypad )",
|
||||
"Keypad {",
|
||||
"Keypad }",
|
||||
"Keypad Tab",
|
||||
"Keypad Backspace",
|
||||
"Keypad A",
|
||||
"Keypad B",
|
||||
"Keypad C",
|
||||
"Keypad D",
|
||||
"Keypad E",
|
||||
"Keypad F",
|
||||
"Keypad XOR",
|
||||
"Keypad ^",
|
||||
"Keypad %",
|
||||
"Keypad <",
|
||||
"Keypad >",
|
||||
"Keypad &",
|
||||
"Keypad &&",
|
||||
"Keypad |",
|
||||
"Keypad ||",
|
||||
"Keypad :",
|
||||
"Keypad #",
|
||||
"Keypad Space",
|
||||
"Keypad @",
|
||||
"Keypad !",
|
||||
"Keypad MemStore",
|
||||
"Keypad MemRecall",
|
||||
"Keypad MemClear",
|
||||
"Keypad MemAdd",
|
||||
"Keypad MemSubtract",
|
||||
"Keypad MemMultiply",
|
||||
"Keypad MemDivide",
|
||||
"Keypad +/-",
|
||||
"Keypad Clear",
|
||||
"Keypad ClearEntry",
|
||||
"Keypad Binary",
|
||||
"Keypad Octal",
|
||||
"Keypad Decimal",
|
||||
"Keypad Hexadecimal",
|
||||
NULL, NULL,
|
||||
"Left Ctrl",
|
||||
"Left Shift",
|
||||
"Left Alt",
|
||||
"Left GUI",
|
||||
"Right Ctrl",
|
||||
"Right Shift",
|
||||
"Right Alt",
|
||||
"Right GUI",
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL,
|
||||
"ModeSwitch",
|
||||
"AudioNext",
|
||||
"AudioPrev",
|
||||
"AudioStop",
|
||||
"AudioPlay",
|
||||
"AudioMute",
|
||||
"MediaSelect",
|
||||
"WWW",
|
||||
"Mail",
|
||||
"Calculator",
|
||||
"Computer",
|
||||
"AC Search",
|
||||
"AC Home",
|
||||
"AC Back",
|
||||
"AC Forward",
|
||||
"AC Stop",
|
||||
"AC Refresh",
|
||||
"AC Bookmarks",
|
||||
"BrightnessDown",
|
||||
"BrightnessUp",
|
||||
"DisplaySwitch",
|
||||
"KBDIllumToggle",
|
||||
"KBDIllumDown",
|
||||
"KBDIllumUp",
|
||||
"Eject",
|
||||
"Sleep",
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Get the key code corresponding to the given scancode according
|
||||
* to the current keyboard layout.
|
||||
*
|
||||
* See ::SDL_Keycode for details.
|
||||
*
|
||||
* \sa SDL_GetKeyName()
|
||||
*/
|
||||
SDLKey SDL_GetKeyFromScancode(SDL_Scancode scancode);
|
||||
|
||||
/**
|
||||
* \brief Get the scancode corresponding to the given key code according to the
|
||||
* current keyboard layout.
|
||||
*
|
||||
* See ::SDL_Scancode for details.
|
||||
*
|
||||
* \sa SDL_GetScancodeName()
|
||||
*/
|
||||
SDL_Scancode SDL_GetScancodeFromKey(SDLKey key);
|
||||
|
||||
/**
|
||||
* \brief Get a human-readable name for a scancode.
|
||||
*
|
||||
* \return A pointer to the name for the scancode.
|
||||
* If the scancode doesn't have a name, this function returns
|
||||
* an empty string ("").
|
||||
*
|
||||
* \sa SDL_Scancode
|
||||
*/
|
||||
const char * SDL_GetScancodeName(SDL_Scancode scancode);
|
||||
|
||||
/**
|
||||
* \brief Get a scancode from a human-readable name
|
||||
*
|
||||
* \return scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
|
||||
*
|
||||
* \sa SDL_Scancode
|
||||
*/
|
||||
SDL_Scancode SDL_GetScancodeFromName(const char *name);
|
||||
|
||||
SDLKey
|
||||
SDL_GetKeyFromScancode(SDL_Scancode scancode)
|
||||
{
|
||||
if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
|
||||
return SDLK_UNKNOWN;
|
||||
}
|
||||
|
||||
return static_cast<SDLKey>(SDL_default_keymap[scancode]);
|
||||
}
|
||||
|
||||
SDL_Scancode
|
||||
SDL_GetScancodeFromKey(SDLKey key)
|
||||
{
|
||||
for (int scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
|
||||
++scancode) {
|
||||
if (SDL_default_keymap[scancode] == key) {
|
||||
return static_cast<SDL_Scancode>(scancode);
|
||||
}
|
||||
}
|
||||
return SDL_SCANCODE_UNKNOWN;
|
||||
}
|
||||
|
||||
const char *
|
||||
SDL_GetScancodeName(SDL_Scancode scancode)
|
||||
{
|
||||
const char *name;
|
||||
if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
|
||||
return "";
|
||||
}
|
||||
|
||||
name = SDL_scancode_names[scancode];
|
||||
if (name)
|
||||
return name;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
SDL_Scancode SDL_GetScancodeFromName(const char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (!name || !*name) {
|
||||
return SDL_SCANCODE_UNKNOWN;
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
|
||||
if (!SDL_scancode_names[i]) {
|
||||
continue;
|
||||
}
|
||||
if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
|
||||
return static_cast<SDL_Scancode>(i);
|
||||
}
|
||||
}
|
||||
|
||||
return SDL_SCANCODE_UNKNOWN;
|
||||
}
|
||||
|
||||
SDLKey
|
||||
SDL_GetKeyFromName(const char *name)
|
||||
{
|
||||
int key;
|
||||
|
||||
/* Check input */
|
||||
if (name == NULL) return SDLK_UNKNOWN;
|
||||
|
||||
/* If it's a single UTF-8 character, then that's the keycode itself */
|
||||
key = *reinterpret_cast<const unsigned char *>(name);
|
||||
if (key >= 0xF0) {
|
||||
if (SDL_strlen(name) == 4) {
|
||||
int i = 0;
|
||||
key = static_cast<Uint16>((name[i]&0x07) << 18);
|
||||
key |= static_cast<Uint16>((name[++i]&0x3F) << 12);
|
||||
key |= static_cast<Uint16>((name[++i]&0x3F) << 6);
|
||||
key |= static_cast<Uint16>((name[++i]&0x3F));
|
||||
return static_cast<SDLKey>(key);
|
||||
}
|
||||
return SDLK_UNKNOWN;
|
||||
} else if (key >= 0xE0) {
|
||||
if (SDL_strlen(name) == 3) {
|
||||
int i = 0;
|
||||
key = static_cast<Uint16>((name[i]&0x0F) << 12);
|
||||
key |= static_cast<Uint16>((name[++i]&0x3F) << 6);
|
||||
key |= static_cast<Uint16>((name[++i]&0x3F));
|
||||
return static_cast<SDLKey>(key);
|
||||
}
|
||||
return SDLK_UNKNOWN;
|
||||
} else if (key >= 0xC0) {
|
||||
if (SDL_strlen(name) == 2) {
|
||||
int i = 0;
|
||||
key = static_cast<Uint16>((name[i]&0x1F) << 6);
|
||||
key |= static_cast<Uint16>((name[++i]&0x3F));
|
||||
return static_cast<SDLKey>(key);
|
||||
}
|
||||
return SDLK_UNKNOWN;
|
||||
} else {
|
||||
if (SDL_strlen(name) == 1) {
|
||||
if (key >= 'A' && key <= 'Z') {
|
||||
key += 32;
|
||||
}
|
||||
return static_cast<SDLKey>(key);
|
||||
}
|
||||
|
||||
/* Get the scancode for this name, and the associated keycode */
|
||||
return static_cast<SDLKey>(SDL_default_keymap[SDL_GetScancodeFromName(name)]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
422
src/sdl/keyboard.hpp
Normal file
422
src/sdl/keyboard.hpp
Normal file
|
@ -0,0 +1,422 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_KEYBOARD_HPP_INCLUDED
|
||||
#define SDL_KEYBOARD_HPP_INCLUDED
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/**
|
||||
* \brief The SDL keyboard scancode representation.
|
||||
*
|
||||
* Values of this type are used to represent keyboard keys, among other places
|
||||
* in the \link SDL_Keysym::scancode key.keysym.scancode \endlink field of the
|
||||
* SDL_Event structure.
|
||||
*
|
||||
* The values in this enumeration are based on the USB usage page standard:
|
||||
* http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SDL_SCANCODE_UNKNOWN = 0,
|
||||
|
||||
/**
|
||||
* \name Usage page 0x07
|
||||
*
|
||||
* These values are from usage page 0x07 (USB keyboard page).
|
||||
*/
|
||||
/* @{ */
|
||||
|
||||
SDL_SCANCODE_A = 4,
|
||||
SDL_SCANCODE_B = 5,
|
||||
SDL_SCANCODE_C = 6,
|
||||
SDL_SCANCODE_D = 7,
|
||||
SDL_SCANCODE_E = 8,
|
||||
SDL_SCANCODE_F = 9,
|
||||
SDL_SCANCODE_G = 10,
|
||||
SDL_SCANCODE_H = 11,
|
||||
SDL_SCANCODE_I = 12,
|
||||
SDL_SCANCODE_J = 13,
|
||||
SDL_SCANCODE_K = 14,
|
||||
SDL_SCANCODE_L = 15,
|
||||
SDL_SCANCODE_M = 16,
|
||||
SDL_SCANCODE_N = 17,
|
||||
SDL_SCANCODE_O = 18,
|
||||
SDL_SCANCODE_P = 19,
|
||||
SDL_SCANCODE_Q = 20,
|
||||
SDL_SCANCODE_R = 21,
|
||||
SDL_SCANCODE_S = 22,
|
||||
SDL_SCANCODE_T = 23,
|
||||
SDL_SCANCODE_U = 24,
|
||||
SDL_SCANCODE_V = 25,
|
||||
SDL_SCANCODE_W = 26,
|
||||
SDL_SCANCODE_X = 27,
|
||||
SDL_SCANCODE_Y = 28,
|
||||
SDL_SCANCODE_Z = 29,
|
||||
|
||||
SDL_SCANCODE_1 = 30,
|
||||
SDL_SCANCODE_2 = 31,
|
||||
SDL_SCANCODE_3 = 32,
|
||||
SDL_SCANCODE_4 = 33,
|
||||
SDL_SCANCODE_5 = 34,
|
||||
SDL_SCANCODE_6 = 35,
|
||||
SDL_SCANCODE_7 = 36,
|
||||
SDL_SCANCODE_8 = 37,
|
||||
SDL_SCANCODE_9 = 38,
|
||||
SDL_SCANCODE_0 = 39,
|
||||
|
||||
SDL_SCANCODE_RETURN = 40,
|
||||
SDL_SCANCODE_ESCAPE = 41,
|
||||
SDL_SCANCODE_BACKSPACE = 42,
|
||||
SDL_SCANCODE_TAB = 43,
|
||||
SDL_SCANCODE_SPACE = 44,
|
||||
|
||||
SDL_SCANCODE_MINUS = 45,
|
||||
SDL_SCANCODE_EQUALS = 46,
|
||||
SDL_SCANCODE_LEFTBRACKET = 47,
|
||||
SDL_SCANCODE_RIGHTBRACKET = 48,
|
||||
SDL_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return
|
||||
* key on ISO keyboards and at the right end
|
||||
* of the QWERTY row on ANSI keyboards.
|
||||
* Produces REVERSE SOLIDUS (backslash) and
|
||||
* VERTICAL LINE in a US layout, REVERSE
|
||||
* SOLIDUS and VERTICAL LINE in a UK Mac
|
||||
* layout, NUMBER SIGN and TILDE in a UK
|
||||
* Windows layout, DOLLAR SIGN and POUND SIGN
|
||||
* in a Swiss German layout, NUMBER SIGN and
|
||||
* APOSTROPHE in a German layout, GRAVE
|
||||
* ACCENT and POUND SIGN in a French Mac
|
||||
* layout, and ASTERISK and MICRO SIGN in a
|
||||
* French Windows layout.
|
||||
*/
|
||||
SDL_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
|
||||
* instead of 49 for the same key, but all
|
||||
* OSes I've seen treat the two codes
|
||||
* identically. So, as an implementor, unless
|
||||
* your keyboard generates both of those
|
||||
* codes and your OS treats them differently,
|
||||
* you should generate SDL_SCANCODE_BACKSLASH
|
||||
* instead of this code. As a user, you
|
||||
* should not rely on this code because SDL
|
||||
* will never generate it with most (all?)
|
||||
* keyboards.
|
||||
*/
|
||||
SDL_SCANCODE_SEMICOLON = 51,
|
||||
SDL_SCANCODE_APOSTROPHE = 52,
|
||||
SDL_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI
|
||||
* and ISO keyboards). Produces GRAVE ACCENT and
|
||||
* TILDE in a US Windows layout and in US and UK
|
||||
* Mac layouts on ANSI keyboards, GRAVE ACCENT
|
||||
* and NOT SIGN in a UK Windows layout, SECTION
|
||||
* SIGN and PLUS-MINUS SIGN in US and UK Mac
|
||||
* layouts on ISO keyboards, SECTION SIGN and
|
||||
* DEGREE SIGN in a Swiss German layout (Mac:
|
||||
* only on ISO keyboards), CIRCUMFLEX ACCENT and
|
||||
* DEGREE SIGN in a German layout (Mac: only on
|
||||
* ISO keyboards), SUPERSCRIPT TWO and TILDE in a
|
||||
* French Windows layout, COMMERCIAL AT and
|
||||
* NUMBER SIGN in a French Mac layout on ISO
|
||||
* keyboards, and LESS-THAN SIGN and GREATER-THAN
|
||||
* SIGN in a Swiss German, German, or French Mac
|
||||
* layout on ANSI keyboards.
|
||||
*/
|
||||
SDL_SCANCODE_COMMA = 54,
|
||||
SDL_SCANCODE_PERIOD = 55,
|
||||
SDL_SCANCODE_SLASH = 56,
|
||||
|
||||
SDL_SCANCODE_CAPSLOCK = 57,
|
||||
|
||||
SDL_SCANCODE_F1 = 58,
|
||||
SDL_SCANCODE_F2 = 59,
|
||||
SDL_SCANCODE_F3 = 60,
|
||||
SDL_SCANCODE_F4 = 61,
|
||||
SDL_SCANCODE_F5 = 62,
|
||||
SDL_SCANCODE_F6 = 63,
|
||||
SDL_SCANCODE_F7 = 64,
|
||||
SDL_SCANCODE_F8 = 65,
|
||||
SDL_SCANCODE_F9 = 66,
|
||||
SDL_SCANCODE_F10 = 67,
|
||||
SDL_SCANCODE_F11 = 68,
|
||||
SDL_SCANCODE_F12 = 69,
|
||||
|
||||
SDL_SCANCODE_PRINTSCREEN = 70,
|
||||
SDL_SCANCODE_SCROLLLOCK = 71,
|
||||
SDL_SCANCODE_PAUSE = 72,
|
||||
SDL_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
|
||||
does send code 73, not 117) */
|
||||
SDL_SCANCODE_HOME = 74,
|
||||
SDL_SCANCODE_PAGEUP = 75,
|
||||
SDL_SCANCODE_DELETE = 76,
|
||||
SDL_SCANCODE_END = 77,
|
||||
SDL_SCANCODE_PAGEDOWN = 78,
|
||||
SDL_SCANCODE_RIGHT = 79,
|
||||
SDL_SCANCODE_LEFT = 80,
|
||||
SDL_SCANCODE_DOWN = 81,
|
||||
SDL_SCANCODE_UP = 82,
|
||||
|
||||
SDL_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
|
||||
*/
|
||||
SDL_SCANCODE_KP_DIVIDE = 84,
|
||||
SDL_SCANCODE_KP_MULTIPLY = 85,
|
||||
SDL_SCANCODE_KP_MINUS = 86,
|
||||
SDL_SCANCODE_KP_PLUS = 87,
|
||||
SDL_SCANCODE_KP_ENTER = 88,
|
||||
SDL_SCANCODE_KP_1 = 89,
|
||||
SDL_SCANCODE_KP_2 = 90,
|
||||
SDL_SCANCODE_KP_3 = 91,
|
||||
SDL_SCANCODE_KP_4 = 92,
|
||||
SDL_SCANCODE_KP_5 = 93,
|
||||
SDL_SCANCODE_KP_6 = 94,
|
||||
SDL_SCANCODE_KP_7 = 95,
|
||||
SDL_SCANCODE_KP_8 = 96,
|
||||
SDL_SCANCODE_KP_9 = 97,
|
||||
SDL_SCANCODE_KP_0 = 98,
|
||||
SDL_SCANCODE_KP_PERIOD = 99,
|
||||
|
||||
SDL_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
|
||||
* keyboards have over ANSI ones,
|
||||
* located between left shift and Y.
|
||||
* Produces GRAVE ACCENT and TILDE in a
|
||||
* US or UK Mac layout, REVERSE SOLIDUS
|
||||
* (backslash) and VERTICAL LINE in a
|
||||
* US or UK Windows layout, and
|
||||
* LESS-THAN SIGN and GREATER-THAN SIGN
|
||||
* in a Swiss German, German, or French
|
||||
* layout. */
|
||||
SDL_SCANCODE_APPLICATION = 101, /**< windows contextual menu, compose */
|
||||
SDL_SCANCODE_POWER = 102, /**< The USB document says this is a status flag,
|
||||
* not a physical key - but some Mac keyboards
|
||||
* do have a power key. */
|
||||
SDL_SCANCODE_KP_EQUALS = 103,
|
||||
SDL_SCANCODE_F13 = 104,
|
||||
SDL_SCANCODE_F14 = 105,
|
||||
SDL_SCANCODE_F15 = 106,
|
||||
SDL_SCANCODE_F16 = 107,
|
||||
SDL_SCANCODE_F17 = 108,
|
||||
SDL_SCANCODE_F18 = 109,
|
||||
SDL_SCANCODE_F19 = 110,
|
||||
SDL_SCANCODE_F20 = 111,
|
||||
SDL_SCANCODE_F21 = 112,
|
||||
SDL_SCANCODE_F22 = 113,
|
||||
SDL_SCANCODE_F23 = 114,
|
||||
SDL_SCANCODE_F24 = 115,
|
||||
SDL_SCANCODE_EXECUTE = 116,
|
||||
SDL_SCANCODE_HELP = 117,
|
||||
SDL_SCANCODE_MENU = 118,
|
||||
SDL_SCANCODE_SELECT = 119,
|
||||
SDL_SCANCODE_STOP = 120,
|
||||
SDL_SCANCODE_AGAIN = 121, /**< redo */
|
||||
SDL_SCANCODE_UNDO = 122,
|
||||
SDL_SCANCODE_CUT = 123,
|
||||
SDL_SCANCODE_COPY = 124,
|
||||
SDL_SCANCODE_PASTE = 125,
|
||||
SDL_SCANCODE_FIND = 126,
|
||||
SDL_SCANCODE_MUTE = 127,
|
||||
SDL_SCANCODE_VOLUMEUP = 128,
|
||||
SDL_SCANCODE_VOLUMEDOWN = 129,
|
||||
/* not sure whether there's a reason to enable these */
|
||||
/* SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */
|
||||
/* SDL_SCANCODE_LOCKINGNUMLOCK = 131, */
|
||||
/* SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */
|
||||
SDL_SCANCODE_KP_COMMA = 133,
|
||||
SDL_SCANCODE_KP_EQUALSAS400 = 134,
|
||||
|
||||
SDL_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
|
||||
footnotes in USB doc */
|
||||
SDL_SCANCODE_INTERNATIONAL2 = 136,
|
||||
SDL_SCANCODE_INTERNATIONAL3 = 137, /**< Yen */
|
||||
SDL_SCANCODE_INTERNATIONAL4 = 138,
|
||||
SDL_SCANCODE_INTERNATIONAL5 = 139,
|
||||
SDL_SCANCODE_INTERNATIONAL6 = 140,
|
||||
SDL_SCANCODE_INTERNATIONAL7 = 141,
|
||||
SDL_SCANCODE_INTERNATIONAL8 = 142,
|
||||
SDL_SCANCODE_INTERNATIONAL9 = 143,
|
||||
SDL_SCANCODE_LANG1 = 144, /**< Hangul/English toggle */
|
||||
SDL_SCANCODE_LANG2 = 145, /**< Hanja conversion */
|
||||
SDL_SCANCODE_LANG3 = 146, /**< Katakana */
|
||||
SDL_SCANCODE_LANG4 = 147, /**< Hiragana */
|
||||
SDL_SCANCODE_LANG5 = 148, /**< Zenkaku/Hankaku */
|
||||
SDL_SCANCODE_LANG6 = 149, /**< reserved */
|
||||
SDL_SCANCODE_LANG7 = 150, /**< reserved */
|
||||
SDL_SCANCODE_LANG8 = 151, /**< reserved */
|
||||
SDL_SCANCODE_LANG9 = 152, /**< reserved */
|
||||
|
||||
SDL_SCANCODE_ALTERASE = 153, /**< Erase-Eaze */
|
||||
SDL_SCANCODE_SYSREQ = 154,
|
||||
SDL_SCANCODE_CANCEL = 155,
|
||||
SDL_SCANCODE_CLEAR = 156,
|
||||
SDL_SCANCODE_PRIOR = 157,
|
||||
SDL_SCANCODE_RETURN2 = 158,
|
||||
SDL_SCANCODE_SEPARATOR = 159,
|
||||
SDL_SCANCODE_OUT = 160,
|
||||
SDL_SCANCODE_OPER = 161,
|
||||
SDL_SCANCODE_CLEARAGAIN = 162,
|
||||
SDL_SCANCODE_CRSEL = 163,
|
||||
SDL_SCANCODE_EXSEL = 164,
|
||||
|
||||
SDL_SCANCODE_KP_00 = 176,
|
||||
SDL_SCANCODE_KP_000 = 177,
|
||||
SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
|
||||
SDL_SCANCODE_DECIMALSEPARATOR = 179,
|
||||
SDL_SCANCODE_CURRENCYUNIT = 180,
|
||||
SDL_SCANCODE_CURRENCYSUBUNIT = 181,
|
||||
SDL_SCANCODE_KP_LEFTPAREN = 182,
|
||||
SDL_SCANCODE_KP_RIGHTPAREN = 183,
|
||||
SDL_SCANCODE_KP_LEFTBRACE = 184,
|
||||
SDL_SCANCODE_KP_RIGHTBRACE = 185,
|
||||
SDL_SCANCODE_KP_TAB = 186,
|
||||
SDL_SCANCODE_KP_BACKSPACE = 187,
|
||||
SDL_SCANCODE_KP_A = 188,
|
||||
SDL_SCANCODE_KP_B = 189,
|
||||
SDL_SCANCODE_KP_C = 190,
|
||||
SDL_SCANCODE_KP_D = 191,
|
||||
SDL_SCANCODE_KP_E = 192,
|
||||
SDL_SCANCODE_KP_F = 193,
|
||||
SDL_SCANCODE_KP_XOR = 194,
|
||||
SDL_SCANCODE_KP_POWER = 195,
|
||||
SDL_SCANCODE_KP_PERCENT = 196,
|
||||
SDL_SCANCODE_KP_LESS = 197,
|
||||
SDL_SCANCODE_KP_GREATER = 198,
|
||||
SDL_SCANCODE_KP_AMPERSAND = 199,
|
||||
SDL_SCANCODE_KP_DBLAMPERSAND = 200,
|
||||
SDL_SCANCODE_KP_VERTICALBAR = 201,
|
||||
SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
|
||||
SDL_SCANCODE_KP_COLON = 203,
|
||||
SDL_SCANCODE_KP_HASH = 204,
|
||||
SDL_SCANCODE_KP_SPACE = 205,
|
||||
SDL_SCANCODE_KP_AT = 206,
|
||||
SDL_SCANCODE_KP_EXCLAM = 207,
|
||||
SDL_SCANCODE_KP_MEMSTORE = 208,
|
||||
SDL_SCANCODE_KP_MEMRECALL = 209,
|
||||
SDL_SCANCODE_KP_MEMCLEAR = 210,
|
||||
SDL_SCANCODE_KP_MEMADD = 211,
|
||||
SDL_SCANCODE_KP_MEMSUBTRACT = 212,
|
||||
SDL_SCANCODE_KP_MEMMULTIPLY = 213,
|
||||
SDL_SCANCODE_KP_MEMDIVIDE = 214,
|
||||
SDL_SCANCODE_KP_PLUSMINUS = 215,
|
||||
SDL_SCANCODE_KP_CLEAR = 216,
|
||||
SDL_SCANCODE_KP_CLEARENTRY = 217,
|
||||
SDL_SCANCODE_KP_BINARY = 218,
|
||||
SDL_SCANCODE_KP_OCTAL = 219,
|
||||
SDL_SCANCODE_KP_DECIMAL = 220,
|
||||
SDL_SCANCODE_KP_HEXADECIMAL = 221,
|
||||
|
||||
SDL_SCANCODE_LCTRL = 224,
|
||||
SDL_SCANCODE_LSHIFT = 225,
|
||||
SDL_SCANCODE_LALT = 226, /**< alt, option */
|
||||
SDL_SCANCODE_LGUI = 227, /**< windows, command (apple), meta */
|
||||
SDL_SCANCODE_RCTRL = 228,
|
||||
SDL_SCANCODE_RSHIFT = 229,
|
||||
SDL_SCANCODE_RALT = 230, /**< alt gr, option */
|
||||
SDL_SCANCODE_RGUI = 231, /**< windows, command (apple), meta */
|
||||
|
||||
SDL_SCANCODE_MODE = 257, /**< I'm not sure if this is really not covered
|
||||
* by any of the above, but since there's a
|
||||
* special KMOD_MODE for it I'm adding it here
|
||||
*/
|
||||
|
||||
/* @} *//* Usage page 0x07 */
|
||||
|
||||
/**
|
||||
* \name Usage page 0x0C
|
||||
*
|
||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||
*/
|
||||
/* @{ */
|
||||
|
||||
SDL_SCANCODE_AUDIONEXT = 258,
|
||||
SDL_SCANCODE_AUDIOPREV = 259,
|
||||
SDL_SCANCODE_AUDIOSTOP = 260,
|
||||
SDL_SCANCODE_AUDIOPLAY = 261,
|
||||
SDL_SCANCODE_AUDIOMUTE = 262,
|
||||
SDL_SCANCODE_MEDIASELECT = 263,
|
||||
SDL_SCANCODE_WWW = 264,
|
||||
SDL_SCANCODE_MAIL = 265,
|
||||
SDL_SCANCODE_CALCULATOR = 266,
|
||||
SDL_SCANCODE_COMPUTER = 267,
|
||||
SDL_SCANCODE_AC_SEARCH = 268,
|
||||
SDL_SCANCODE_AC_HOME = 269,
|
||||
SDL_SCANCODE_AC_BACK = 270,
|
||||
SDL_SCANCODE_AC_FORWARD = 271,
|
||||
SDL_SCANCODE_AC_STOP = 272,
|
||||
SDL_SCANCODE_AC_REFRESH = 273,
|
||||
SDL_SCANCODE_AC_BOOKMARKS = 274,
|
||||
|
||||
/* @} *//* Usage page 0x0C */
|
||||
|
||||
/**
|
||||
* \name Walther keys
|
||||
*
|
||||
* These are values that Christian Walther added (for mac keyboard?).
|
||||
*/
|
||||
/* @{ */
|
||||
|
||||
SDL_SCANCODE_BRIGHTNESSDOWN = 275,
|
||||
SDL_SCANCODE_BRIGHTNESSUP = 276,
|
||||
SDL_SCANCODE_DISPLAYSWITCH = 277, /**< display mirroring/dual display
|
||||
switch, video mode switch */
|
||||
SDL_SCANCODE_KBDILLUMTOGGLE = 278,
|
||||
SDL_SCANCODE_KBDILLUMDOWN = 279,
|
||||
SDL_SCANCODE_KBDILLUMUP = 280,
|
||||
SDL_SCANCODE_EJECT = 281,
|
||||
SDL_SCANCODE_SLEEP = 282,
|
||||
|
||||
SDL_SCANCODE_APP1 = 283,
|
||||
SDL_SCANCODE_APP2 = 284,
|
||||
|
||||
/* @} *//* Walther keys */
|
||||
|
||||
/* Add any other keys here. */
|
||||
|
||||
SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
|
||||
for array bounds */
|
||||
} SDL_Scancode;
|
||||
|
||||
extern SDL_Scancode SDL_GetScancodeFromKey(SDLKey key);
|
||||
|
||||
extern SDL_Scancode SDL_GetScancodeFromName(const char *name);
|
||||
|
||||
extern const char *
|
||||
SDL_GetScancodeName(SDL_Scancode scancode);
|
||||
|
||||
/**
|
||||
* \brief Get a key code from a human-readable name
|
||||
*
|
||||
* \return key code, or SDLK_UNKNOWN if the name wasn't recognized
|
||||
*
|
||||
* \sa SDL_Keycode
|
||||
*/
|
||||
extern SDLKey SDL_GetKeyFromName(const char *name);
|
||||
|
||||
|
||||
extern SDLKey SDL_GetKeyFromScancode(SDL_Scancode scancode);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SDL_KEYBOARD_HPP_INCLUDED */
|
|
@ -153,12 +153,12 @@ inline void fill_rect(surface& dst, SDL_Rect* dst_rect, const Uint32 color)
|
|||
void fill_rect(CVideo &video, const SDL_Rect &rect, SDL_Color color);
|
||||
|
||||
void fill_rect(CVideo &video, const SDL_Rect &rect, Uint8 r, Uint8 g,
|
||||
Uint8 b, Uint8 a = 255);
|
||||
Uint8 b, Uint8 a = SDL_ALPHA_OPAQUE);
|
||||
|
||||
void draw_rect(CVideo &video, const SDL_Rect &rect, SDL_Color color);
|
||||
|
||||
void draw_rect(CVideo &video, const SDL_Rect &rect, Uint8 r, Uint8 g,
|
||||
Uint8 b, Uint8 a = 255);
|
||||
Uint8 b, Uint8 a = SDL_ALPHA_OPAQUE);
|
||||
#endif
|
||||
} // namespace sdl
|
||||
|
||||
|
|
|
@ -67,11 +67,11 @@ SDL_Color int_to_color(const Uint32 rgb)
|
|||
result.g = (0x0000FF00 & rgb) >> 8;
|
||||
result.b = (0x000000FF & rgb);
|
||||
#ifdef SDL_GPU
|
||||
result.unused = 255;
|
||||
result.unused = SDL_ALPHA_OPAQUE;
|
||||
#elif SDL_VERSION_ATLEAST(2,0,0)
|
||||
result.a = 0;
|
||||
result.a = SDL_ALPHA_OPAQUE;
|
||||
#else
|
||||
result.unused = 0;
|
||||
result.unused = SDL_ALPHA_OPAQUE;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
@ -2561,7 +2561,7 @@ surface get_surface_portion(const surface &src, SDL_Rect &area, bool optimize_fo
|
|||
return NULL;
|
||||
}
|
||||
|
||||
sdl_blit(src, &area, dst, NULL);
|
||||
sdl_copy_portion(src, &area, dst, NULL);
|
||||
|
||||
return optimize_format ? display_format_alpha(dst) : dst;
|
||||
}
|
||||
|
@ -2748,4 +2748,3 @@ std::ostream& operator<<(std::ostream& s, const SDL_Rect& rect)
|
|||
s << rect.x << ',' << rect.y << " x " << rect.w << ',' << rect.h;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,17 @@ inline void sdl_blit(const surface& src, SDL_Rect* src_rect, surface& dst, SDL_R
|
|||
SDL_BlitSurface(src, src_rect, dst, dst_rect);
|
||||
}
|
||||
|
||||
inline void sdl_copy_portion(const surface& screen, SDL_Rect* screen_rect, surface& dst, SDL_Rect* dst_rect){
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_NONE);
|
||||
SDL_SetSurfaceBlendMode(dst, SDL_BLENDMODE_NONE);
|
||||
#endif
|
||||
SDL_BlitSurface(screen, screen_rect, dst, dst_rect);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_BLEND);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* This method blends a RGBA color. The method takes as input a surface,
|
||||
* the RGB color to blend and a value specifying how much blending to apply.
|
||||
|
@ -440,7 +451,7 @@ SDL_Color string_to_color(const std::string& color_string);
|
|||
SDL_Color create_color(const unsigned char red
|
||||
, unsigned char green
|
||||
, unsigned char blue
|
||||
, unsigned char alpha = 255);
|
||||
, unsigned char alpha = SDL_ALPHA_OPAQUE);
|
||||
|
||||
/**
|
||||
* Helper class for pinning SDL surfaces into memory.
|
||||
|
|
|
@ -67,12 +67,13 @@ twindow::~twindow()
|
|||
|
||||
void twindow::set_size(const int w, const int h)
|
||||
{
|
||||
SDL_SetWindowFullscreen(window_, 0);
|
||||
SDL_SetWindowSize(window_, w, h);
|
||||
}
|
||||
|
||||
void twindow::full_screen()
|
||||
{
|
||||
/** @todo Implement. */
|
||||
SDL_SetWindowFullscreen(window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
}
|
||||
|
||||
void twindow::fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
|
|
|
@ -124,7 +124,9 @@ static lg::log_domain log_config("config");
|
|||
#ifndef SIGHUP
|
||||
#define SIGHUP 20
|
||||
#endif
|
||||
/** @todo FIXME: should define SIGINT here too, but to what? */
|
||||
/**
|
||||
@todo FIXME: should define SIGINT here too, but to what?
|
||||
*/
|
||||
|
||||
static sig_atomic_t config_reload = 0;
|
||||
|
||||
|
|
|
@ -741,7 +741,7 @@ void part_ui::render_story_box()
|
|||
}
|
||||
|
||||
const SDL_Rect rect = sdl::create_rect(0, 0, video_.getx(), video_.gety());
|
||||
sdl::fill_rect(video_, rect, 0, 0, 0, 255);
|
||||
sdl::fill_rect(video_, rect, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||
#else
|
||||
LOG_NG << "ENTER part_ui()::render_story_box()\n";
|
||||
|
||||
|
|
|
@ -899,9 +899,9 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_no_args)
|
|||
BOOST_CHECK_EQUAL(mod->get_color().g, 0);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
|
||||
#else
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
|
||||
#endif
|
||||
|
||||
delete mod;
|
||||
|
@ -925,9 +925,9 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_1_arg)
|
|||
BOOST_CHECK_EQUAL(mod->get_color().g, 0);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
|
||||
#else
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
|
||||
#endif
|
||||
|
||||
delete mod;
|
||||
|
@ -951,9 +951,9 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_2_args)
|
|||
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
|
||||
#else
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
|
||||
#endif
|
||||
|
||||
delete mod;
|
||||
|
@ -977,9 +977,9 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_3_args)
|
|||
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().b, 3);
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
|
||||
#else
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
|
||||
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
|
||||
#endif
|
||||
|
||||
delete mod;
|
||||
|
|
|
@ -33,8 +33,8 @@ surface display_format_alpha(surface)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
surface get_video_surface()
|
||||
surface& get_video_surface()
|
||||
{
|
||||
return NULL;
|
||||
return dummy_screen_surface;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "sdl/window.hpp"
|
||||
#include "video.hpp"
|
||||
#include "sdl/gpu.hpp"
|
||||
#include "display.hpp"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
|
@ -47,11 +48,18 @@ namespace {
|
|||
GPU_Target *render_target_;
|
||||
}
|
||||
void resize_monitor::process(events::pump_info &info) {
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if(info.resize_dimensions.first >= preferences::min_allowed_width()
|
||||
&& info.resize_dimensions.second >= preferences::min_allowed_height()
|
||||
&& disallow_resize == 0) {
|
||||
preferences::set_resolution(info.resize_dimensions);
|
||||
}
|
||||
#else
|
||||
if(info.resize_dimensions.first > 0 &&
|
||||
info.resize_dimensions.second > 0
|
||||
&& display::get_singleton())
|
||||
display::get_singleton()->redraw_everything();
|
||||
#endif
|
||||
}
|
||||
|
||||
resize_lock::resize_lock()
|
||||
|
@ -241,7 +249,7 @@ bool non_interactive()
|
|||
if (fake_interactive)
|
||||
return false;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
return false;
|
||||
return window == NULL;
|
||||
#else
|
||||
return SDL_GetVideoSurface() == NULL;
|
||||
#endif
|
||||
|
@ -268,7 +276,7 @@ surface display_format_alpha(surface surf)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
surface get_video_surface()
|
||||
surface& get_video_surface()
|
||||
{
|
||||
return frameBuffer;
|
||||
}
|
||||
|
@ -412,7 +420,7 @@ CVideo::~CVideo()
|
|||
|
||||
void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rect* clip_rect)
|
||||
{
|
||||
surface target(getSurface());
|
||||
surface& target(getSurface());
|
||||
SDL_Rect dst = sdl::create_rect(x, y, 0, 0);
|
||||
|
||||
const clip_rect_setter clip_setter(target, clip_rect, clip_rect != NULL);
|
||||
|
@ -532,6 +540,19 @@ int CVideo::modePossible( int x, int y, int bits_per_pixel, int flags, bool curr
|
|||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
||||
void update_framebuffer()
|
||||
{
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
surface fb = SDL_GetWindowSurface(*window);
|
||||
if (!frameBuffer)
|
||||
frameBuffer = fb;
|
||||
else
|
||||
frameBuffer.assign(fb);
|
||||
}
|
||||
|
||||
int CVideo::setMode( int x, int y, int bits_per_pixel, int flags )
|
||||
{
|
||||
update_rects.clear();
|
||||
|
@ -554,7 +575,7 @@ int CVideo::setMode( int x, int y, int bits_per_pixel, int flags )
|
|||
}
|
||||
}
|
||||
|
||||
frameBuffer = SDL_GetWindowSurface(*window);
|
||||
update_framebuffer();
|
||||
|
||||
if(frameBuffer != NULL) {
|
||||
image::set_pixel_format(frameBuffer->format);
|
||||
|
@ -652,8 +673,8 @@ void CVideo::flip()
|
|||
|
||||
clear_updates();
|
||||
#else
|
||||
assert(window);
|
||||
window->render();
|
||||
if (window)
|
||||
window->render();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -48,7 +48,13 @@ struct GPU_Target;
|
|||
GPU_Target *get_render_target();
|
||||
|
||||
surface display_format_alpha(surface surf);
|
||||
surface get_video_surface();
|
||||
surface& get_video_surface();
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
//this needs to be invoked immediately after a resize event or the game will crash.
|
||||
void update_framebuffer();
|
||||
#endif
|
||||
|
||||
|
||||
SDL_Rect screen_area();
|
||||
|
||||
|
||||
|
|
|
@ -65,8 +65,7 @@
|
|||
#include "log_windows.hpp"
|
||||
#endif // _WIN32
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <SDL.h> // for SDL_Init, SDL_INIT_TIMER
|
||||
#include <boost/foreach.hpp> // for auto_any_base, etc
|
||||
#include <boost/iostreams/categories.hpp> // for input, output
|
||||
#include <boost/iostreams/copy.hpp> // for copy
|
||||
|
@ -864,8 +863,14 @@ static std::vector<std::string> parse_commandline_arguments(std::string input)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
static void wesnoth_terminate_handler(int) {
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __native_client__
|
||||
#if defined(__native_client__) || (defined(__APPLE__) && SDL_VERSION_ATLEAST(2, 0, 0))
|
||||
extern "C" int wesnoth_main(int argc, char** argv);
|
||||
int wesnoth_main(int argc, char** argv)
|
||||
#else
|
||||
int main(int argc, char** argv)
|
||||
|
@ -932,6 +937,15 @@ int main(int argc, char** argv)
|
|||
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return(1);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
struct sigaction terminate_handler;
|
||||
terminate_handler.sa_handler = wesnoth_terminate_handler;
|
||||
terminate_handler.sa_flags = 0;
|
||||
sigemptyset(&terminate_handler.sa_mask);
|
||||
sigaction(SIGTERM, &terminate_handler, NULL);
|
||||
sigaction(SIGINT, &terminate_handler, NULL);
|
||||
#endif
|
||||
|
||||
try {
|
||||
std::cerr << "Battle for Wesnoth v" << game_config::revision << '\n';
|
||||
|
|
|
@ -90,8 +90,7 @@ void file_menu::display_current_files() {
|
|||
// Make sure that all lines fit.
|
||||
// Guess the width of the scrollbar to be 30 since it is not accessible from here.
|
||||
// -25 to compensate for the picture column.
|
||||
while(static_cast<unsigned int>(
|
||||
font::line_width(*it, menu_font_size)) > width() - 30 - 25) {
|
||||
while(font::line_width(*it, menu_font_size) > width() - 30 - 25) {
|
||||
|
||||
(*it).resize((*it).size() - 1);
|
||||
}
|
||||
|
|
|
@ -341,23 +341,23 @@ void menu::update_scrollbar_grip_height()
|
|||
|
||||
void menu::update_size()
|
||||
{
|
||||
unsigned int h = heading_height();
|
||||
int h = heading_height();
|
||||
for(size_t i = get_position(),
|
||||
i_end = std::min(items_.size(), i + max_items_onscreen());
|
||||
i < i_end; ++i)
|
||||
h += get_item_rect(i).h;
|
||||
h = std::max(h, height());
|
||||
if (max_height_ > 0 && h > static_cast<unsigned>(max_height_)) {
|
||||
if (max_height_ > 0 && h > (max_height_)) {
|
||||
h = max_height_;
|
||||
}
|
||||
|
||||
use_ellipsis_ = false;
|
||||
std::vector<int> const &widths = column_widths();
|
||||
unsigned w = std::accumulate(widths.begin(), widths.end(), 0);
|
||||
int w = std::accumulate(widths.begin(), widths.end(), 0);
|
||||
if (items_.size() > max_items_onscreen())
|
||||
w += scrollbar_width();
|
||||
w = std::max(w, width());
|
||||
if (max_width_ > 0 && w > static_cast<unsigned>(max_width_)) {
|
||||
if (max_width_ > 0 && w > (max_width_)) {
|
||||
use_ellipsis_ = true;
|
||||
w = max_width_;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ void progress_bar::set_text(const std::string& text)
|
|||
|
||||
void progress_bar::draw_contents()
|
||||
{
|
||||
surface surf = video().getSurface();
|
||||
surface& surf = video().getSurface();
|
||||
SDL_Rect area = location();
|
||||
|
||||
if(area.w >= 2 && area.h >= 2) {
|
||||
|
|
|
@ -306,8 +306,6 @@ void scrollbar::draw_contents()
|
|||
return;
|
||||
}
|
||||
|
||||
surface const screen = video().getSurface();
|
||||
|
||||
// Draw scrollbar "groove"
|
||||
video().blit_surface(groove.x, groove.y, top_grv);
|
||||
video().blit_surface(groove.x, groove.y + top_grv->h, groove_scaled_);
|
||||
|
|
|
@ -162,8 +162,8 @@ SDL_Rect scrollpane::client_area() const
|
|||
|
||||
void scrollpane::update_content_size()
|
||||
{
|
||||
unsigned int maxx = 0;
|
||||
unsigned int maxy = 0;
|
||||
int maxx = 0;
|
||||
int maxy = 0;
|
||||
|
||||
for(widget_map::iterator itor = content_.begin(); itor != content_.end(); ++itor) {
|
||||
if(itor->second.x + itor->second.w->width() > maxx) {
|
||||
|
|
|
@ -164,7 +164,7 @@ void slider::draw_contents()
|
|||
if (image->w >= loc.w)
|
||||
return;
|
||||
|
||||
surface screen = video().getSurface();
|
||||
surface& screen = video().getSurface();
|
||||
|
||||
SDL_Rect line_rect = sdl::create_rect(loc.x + image->w / 2
|
||||
, loc.y + loc.h / 2
|
||||
|
|
|
@ -38,6 +38,9 @@ textbox::textbox(CVideo &video, int width, const std::string& text, bool editabl
|
|||
wrap_(false), line_height_(0), yscroll_(0), alpha_(alpha),
|
||||
alpha_focus_(alpha_focus),
|
||||
edit_target_(NULL)
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
,listening_(false)
|
||||
#endif
|
||||
{
|
||||
// static const SDL_Rect area = d.screen_area();
|
||||
// const int height = font::draw_text(NULL,area,font_size,font::NORMAL_COLOR,"ABCD",0,0).h;
|
||||
|
@ -103,14 +106,21 @@ void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_C
|
|||
|
||||
SDL_SetAlpha(new_text.get(),0,0);
|
||||
SDL_SetAlpha(text_image_.get(),0,0);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
SDL_SetSurfaceBlendMode(text_image_, SDL_BLENDMODE_NONE);
|
||||
#endif
|
||||
sdl_blit(text_image_,NULL,new_surface,NULL);
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
SDL_SetSurfaceBlendMode(text_image_, SDL_BLENDMODE_BLEND);
|
||||
#endif
|
||||
|
||||
SDL_Rect target = sdl::create_rect(0
|
||||
, text_image_->h
|
||||
, new_text->w
|
||||
, new_text->h);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
SDL_SetSurfaceBlendMode(new_text, SDL_BLENDMODE_NONE);
|
||||
#endif
|
||||
sdl_blit(new_text,NULL,new_surface,&target);
|
||||
text_image_.assign(new_surface);
|
||||
|
||||
|
@ -182,7 +192,7 @@ void textbox::draw_contents()
|
|||
{
|
||||
SDL_Rect const &loc = inner_location();
|
||||
|
||||
surface surf = video().getSurface();
|
||||
surface& surf = video().getSurface();
|
||||
sdl::draw_solid_tinted_rectangle(loc.x,loc.y,loc.w,loc.h,0,0,0,
|
||||
focus(NULL) ? alpha_focus_ : alpha_, surf);
|
||||
|
||||
|
@ -440,6 +450,187 @@ void textbox::handle_event(const SDL_Event& event)
|
|||
handle_event(event, false);
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
bool textbox::handle_text_input(const SDL_Event& event)
|
||||
{
|
||||
bool changed = false;
|
||||
utf8::string str = event.text.text;
|
||||
ucs4::string s = unicode_cast<ucs4::string>(str);
|
||||
|
||||
DBG_G << "Char: " << str << "\n";
|
||||
|
||||
if (editable_) {
|
||||
changed = true;
|
||||
if (is_selection())
|
||||
erase_selection();
|
||||
|
||||
if (text_.size() + 1 <= max_size_) {
|
||||
|
||||
text_.insert(text_.begin() + cursor_, s.begin(), s.end());
|
||||
cursor_ += s.size();
|
||||
}
|
||||
} else {
|
||||
pass_event_to_target(event);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool textbox::handle_key_down(const SDL_Event &event)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
const SDL_keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym;
|
||||
const SDLMod modifiers = SDL_GetModState();
|
||||
|
||||
const int c = key.sym;
|
||||
const int old_cursor = cursor_;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
listening_ = true;
|
||||
#endif
|
||||
|
||||
if(editable_) {
|
||||
if(c == SDLK_LEFT && cursor_ > 0)
|
||||
--cursor_;
|
||||
|
||||
if(c == SDLK_RIGHT && cursor_ < static_cast<int>(text_.size()))
|
||||
++cursor_;
|
||||
|
||||
// ctrl-a, ctrl-e and ctrl-u are readline style shortcuts, even on Macs
|
||||
if(c == SDLK_END || (c == SDLK_e && (modifiers & KMOD_CTRL)))
|
||||
cursor_ = text_.size();
|
||||
|
||||
if(c == SDLK_HOME || (c == SDLK_a && (modifiers & KMOD_CTRL)))
|
||||
cursor_ = 0;
|
||||
|
||||
if((old_cursor != cursor_) && (modifiers & KMOD_SHIFT)) {
|
||||
if(selstart_ == -1)
|
||||
selstart_ = old_cursor;
|
||||
selend_ = cursor_;
|
||||
}
|
||||
} else if(c == SDLK_LEFT || c == SDLK_RIGHT || c == SDLK_END || c == SDLK_HOME) {
|
||||
pass_event_to_target(event);
|
||||
}
|
||||
|
||||
if(editable_) {
|
||||
if(c == SDLK_BACKSPACE) {
|
||||
changed = true;
|
||||
if(is_selection()) {
|
||||
erase_selection();
|
||||
} else if(cursor_ > 0) {
|
||||
--cursor_;
|
||||
text_.erase(text_.begin()+cursor_);
|
||||
}
|
||||
}
|
||||
|
||||
if(c == SDLK_u && (modifiers & KMOD_CTRL)) { // clear line
|
||||
changed = true;
|
||||
cursor_ = 0;
|
||||
text_.resize(0);
|
||||
}
|
||||
|
||||
if(c == SDLK_DELETE && !text_.empty()) {
|
||||
changed = true;
|
||||
if(is_selection()) {
|
||||
erase_selection();
|
||||
} else {
|
||||
if(cursor_ < static_cast<int>(text_.size())) {
|
||||
text_.erase(text_.begin()+cursor_);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(c == SDLK_BACKSPACE || c == SDLK_DELETE || (c == SDLK_u && (modifiers & KMOD_CTRL))) {
|
||||
pass_event_to_target(event);
|
||||
}
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
ucs4::char_t character = key.unicode;
|
||||
#endif
|
||||
|
||||
//movement characters may have a "Unicode" field on some platforms, so ignore it.
|
||||
if(!(c == SDLK_UP || c == SDLK_DOWN || c == SDLK_LEFT || c == SDLK_RIGHT ||
|
||||
c == SDLK_DELETE || c == SDLK_BACKSPACE || c == SDLK_END || c == SDLK_HOME ||
|
||||
c == SDLK_PAGEUP || c == SDLK_PAGEDOWN)) {
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if(character != 0) {
|
||||
DBG_G << "Char: " << character << ", c = " << c << "\n";
|
||||
}
|
||||
#endif
|
||||
if((event.key.keysym.mod & copypaste_modifier)
|
||||
//on windows SDL fires for AltGr lctrl+ralt (needed to access @ etc on certain keyboards)
|
||||
#ifdef _WIN32
|
||||
&& !(event.key.keysym.mod & KMOD_ALT)
|
||||
#endif
|
||||
) {
|
||||
switch(c) {
|
||||
case SDLK_v: // paste
|
||||
{
|
||||
if(!editable()) {
|
||||
pass_event_to_target(event);
|
||||
break;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
if(is_selection())
|
||||
erase_selection();
|
||||
|
||||
std::string str = desktop::clipboard::copy_from_clipboard(false);
|
||||
|
||||
//cut off anything after the first newline
|
||||
str.erase(std::find_if(str.begin(),str.end(),utils::isnewline),str.end());
|
||||
|
||||
ucs4::string s = unicode_cast<ucs4::string>(str);
|
||||
|
||||
if(text_.size() < max_size_) {
|
||||
if(s.size() + text_.size() > max_size_) {
|
||||
s.resize(max_size_ - text_.size());
|
||||
}
|
||||
text_.insert(text_.begin()+cursor_, s.begin(), s.end());
|
||||
cursor_ += s.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDLK_c: // copy
|
||||
{
|
||||
if(is_selection())
|
||||
{
|
||||
const size_t beg = std::min<size_t>(size_t(selstart_),size_t(selend_));
|
||||
const size_t end = std::max<size_t>(size_t(selstart_),size_t(selend_));
|
||||
|
||||
ucs4::string ws(text_.begin() + beg, text_.begin() + end);
|
||||
std::string s = unicode_cast<utf8::string>(ws);
|
||||
desktop::clipboard::copy_to_clipboard(s, false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
else if(editable_) {
|
||||
if(character >= 32 && character != 127) {
|
||||
changed = true;
|
||||
if(is_selection())
|
||||
erase_selection();
|
||||
|
||||
if(text_.size() + 1 <= max_size_) {
|
||||
text_.insert(text_.begin()+cursor_,character);
|
||||
++cursor_;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
pass_event_to_target(event);
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
||||
{
|
||||
if(!enabled())
|
||||
|
@ -500,7 +691,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
|||
|
||||
update_text_cache(false);
|
||||
|
||||
if(!grabmouse_ && mousebuttons & SDL_BUTTON(1)) {
|
||||
if(!grabmouse_ && (mousebuttons & SDL_BUTTON(1))) {
|
||||
grabmouse_ = true;
|
||||
selstart_ = selend_ = cursor_;
|
||||
} else if (! (mousebuttons & SDL_BUTTON(1))) {
|
||||
|
@ -519,151 +710,24 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
|||
return;
|
||||
}
|
||||
|
||||
if(event.type != SDL_KEYDOWN || (!was_forwarded && focus(&event) != true)) {
|
||||
draw();
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym;
|
||||
const SDLMod modifiers = SDL_GetModState();
|
||||
|
||||
const int c = key.sym;
|
||||
const int old_cursor = cursor_;
|
||||
|
||||
if(editable_) {
|
||||
if(c == SDLK_LEFT && cursor_ > 0)
|
||||
--cursor_;
|
||||
|
||||
if(c == SDLK_RIGHT && cursor_ < static_cast<int>(text_.size()))
|
||||
++cursor_;
|
||||
|
||||
// ctrl-a, ctrl-e and ctrl-u are readline style shortcuts, even on Macs
|
||||
if(c == SDLK_END || (c == SDLK_e && (modifiers & KMOD_CTRL)))
|
||||
cursor_ = text_.size();
|
||||
|
||||
if(c == SDLK_HOME || (c == SDLK_a && (modifiers & KMOD_CTRL)))
|
||||
cursor_ = 0;
|
||||
|
||||
if((old_cursor != cursor_) && (modifiers & KMOD_SHIFT)) {
|
||||
if(selstart_ == -1)
|
||||
selstart_ = old_cursor;
|
||||
selend_ = cursor_;
|
||||
}
|
||||
} else if(c == SDLK_LEFT || c == SDLK_RIGHT || c == SDLK_END || c == SDLK_HOME) {
|
||||
pass_event_to_target(event);
|
||||
}
|
||||
|
||||
if(editable_) {
|
||||
if(c == SDLK_BACKSPACE) {
|
||||
changed = true;
|
||||
if(is_selection()) {
|
||||
erase_selection();
|
||||
} else if(cursor_ > 0) {
|
||||
--cursor_;
|
||||
text_.erase(text_.begin()+cursor_);
|
||||
}
|
||||
}
|
||||
|
||||
if(c == SDLK_u && (modifiers & KMOD_CTRL)) { // clear line
|
||||
changed = true;
|
||||
cursor_ = 0;
|
||||
text_.resize(0);
|
||||
}
|
||||
|
||||
if(c == SDLK_DELETE && !text_.empty()) {
|
||||
changed = true;
|
||||
if(is_selection()) {
|
||||
erase_selection();
|
||||
} else {
|
||||
if(cursor_ < static_cast<int>(text_.size())) {
|
||||
text_.erase(text_.begin()+cursor_);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(c == SDLK_BACKSPACE || c == SDLK_DELETE || (c == SDLK_u && (modifiers & KMOD_CTRL))) {
|
||||
pass_event_to_target(event);
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
ucs4::char_t character = key.sym;
|
||||
#else
|
||||
ucs4::char_t character = key.unicode;
|
||||
if (event.type == SDL_TEXTINPUT && listening_) {
|
||||
changed = handle_text_input(event);
|
||||
} else
|
||||
#endif
|
||||
|
||||
//movement characters may have a "Unicode" field on some platforms, so ignore it.
|
||||
if(!(c == SDLK_UP || c == SDLK_DOWN || c == SDLK_LEFT || c == SDLK_RIGHT ||
|
||||
c == SDLK_DELETE || c == SDLK_BACKSPACE || c == SDLK_END || c == SDLK_HOME ||
|
||||
c == SDLK_PAGEUP || c == SDLK_PAGEDOWN)) {
|
||||
if(character != 0) {
|
||||
DBG_G << "Char: " << character << ", c = " << c << "\n";
|
||||
}
|
||||
if((event.key.keysym.mod & copypaste_modifier)
|
||||
//on windows SDL fires for AltGr lctrl+ralt (needed to access @ etc on certain keyboards)
|
||||
#ifdef _WIN32
|
||||
&& !(event.key.keysym.mod & KMOD_ALT)
|
||||
#endif
|
||||
) {
|
||||
switch(c) {
|
||||
case SDLK_v: // paste
|
||||
{
|
||||
if(!editable()) {
|
||||
pass_event_to_target(event);
|
||||
break;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
if(is_selection())
|
||||
erase_selection();
|
||||
|
||||
std::string str = desktop::clipboard::copy_from_clipboard(false);
|
||||
|
||||
//cut off anything after the first newline
|
||||
str.erase(std::find_if(str.begin(),str.end(),utils::isnewline),str.end());
|
||||
|
||||
ucs4::string s = unicode_cast<ucs4::string>(str);
|
||||
|
||||
if(text_.size() < max_size_) {
|
||||
if(s.size() + text_.size() > max_size_) {
|
||||
s.resize(max_size_ - text_.size());
|
||||
}
|
||||
text_.insert(text_.begin()+cursor_, s.begin(), s.end());
|
||||
cursor_ += s.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDLK_c: // copy
|
||||
{
|
||||
if(is_selection())
|
||||
{
|
||||
const size_t beg = std::min<size_t>(size_t(selstart_),size_t(selend_));
|
||||
const size_t end = std::max<size_t>(size_t(selstart_),size_t(selend_));
|
||||
|
||||
ucs4::string ws(text_.begin() + beg, text_.begin() + end);
|
||||
std::string s = unicode_cast<utf8::string>(ws);
|
||||
desktop::clipboard::copy_to_clipboard(s, false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if(editable_) {
|
||||
if(character >= 32 && character != 127) {
|
||||
changed = true;
|
||||
if(is_selection())
|
||||
erase_selection();
|
||||
|
||||
if(text_.size() + 1 <= max_size_) {
|
||||
text_.insert(text_.begin()+cursor_,character);
|
||||
++cursor_;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pass_event_to_target(event);
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
changed = handle_key_down(event);
|
||||
}
|
||||
else {
|
||||
if(event.type != SDL_KEYDOWN || (!was_forwarded && focus(&event) != true)) {
|
||||
draw();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(is_selection() && (selend_ != cursor_))
|
||||
selstart_ = selend_ = -1;
|
||||
|
||||
|
|
|
@ -92,6 +92,14 @@ private:
|
|||
|
||||
textbox* edit_target_;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/* This boolean is used to filter out any TextInput events that are received without
|
||||
* the corresponding KeyPress events. This is needed to avoid a bug when creating a
|
||||
* textbox using a hotkey.
|
||||
* */
|
||||
bool listening_;
|
||||
#endif
|
||||
|
||||
void handle_event(const SDL_Event& event, bool was_forwarded);
|
||||
|
||||
void handle_event(const SDL_Event& event);
|
||||
|
@ -109,6 +117,10 @@ private:
|
|||
bool requires_event_focus(const SDL_Event *event=NULL) const;
|
||||
|
||||
bool show_scrollbar() const;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
bool handle_text_input(const SDL_Event& event);
|
||||
#endif
|
||||
bool handle_key_down(const SDL_Event &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -116,27 +116,27 @@ void widget::set_location(int x, int y)
|
|||
set_location(sdl::create_rect(x, y, rect_.w, rect_.h));
|
||||
}
|
||||
|
||||
void widget::set_width(unsigned w)
|
||||
void widget::set_width(int w)
|
||||
{
|
||||
set_location(sdl::create_rect(rect_.x, rect_.y, w, rect_.h));
|
||||
}
|
||||
|
||||
void widget::set_height(unsigned h)
|
||||
void widget::set_height(int h)
|
||||
{
|
||||
set_location(sdl::create_rect(rect_.x, rect_.y, rect_.w, h));
|
||||
}
|
||||
|
||||
void widget::set_measurements(unsigned w, unsigned h)
|
||||
void widget::set_measurements(int w, int h)
|
||||
{
|
||||
set_location(sdl::create_rect(rect_.x, rect_.y, w, h));
|
||||
}
|
||||
|
||||
unsigned widget::width() const
|
||||
int widget::width() const
|
||||
{
|
||||
return rect_.w;
|
||||
}
|
||||
|
||||
unsigned widget::height() const
|
||||
int widget::height() const
|
||||
{
|
||||
return rect_.h;
|
||||
}
|
||||
|
|
|
@ -28,12 +28,12 @@ public:
|
|||
SDL_Rect const &location() const;
|
||||
virtual void set_location(SDL_Rect const &rect);
|
||||
void set_location(int x, int y);
|
||||
void set_width(unsigned w);
|
||||
void set_height(unsigned h);
|
||||
void set_measurements(unsigned w, unsigned h);
|
||||
void set_width(int w);
|
||||
void set_height(int h);
|
||||
void set_measurements(int w, int h);
|
||||
|
||||
unsigned width() const;
|
||||
unsigned height() const;
|
||||
int width() const;
|
||||
int height() const;
|
||||
|
||||
//focus() may gain the focus if the currently focused handler doesn't require this event
|
||||
bool focus(const SDL_Event* event);
|
||||
|
|
Loading…
Add table
Reference in a new issue