Merge lp:~widelands-dev/widelands/bug-1459529 into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7470
Proposed branch: lp:~widelands-dev/widelands/bug-1459529
Merge into: lp:widelands
Diff against target: 114 lines (+44/-42)
2 files modified
src/wlapplication.cc (+43/-41)
src/wlapplication.h (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1459529
Reviewer Review Type Date Requested Status
Tino Approve
Review via email: mp+260632@code.launchpad.net

Description of the change

WLApplication::handle_key can now distinguish between key_down and key_up events. This fixed problems with hotkeys for fullscreen mode and screenshots etc.

To post a comment you must log in.
Revision history for this message
Tino (tino79) wrote :

Works fine here!

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wlapplication.cc'
2--- src/wlapplication.cc 2015-05-11 20:43:27 +0000
3+++ src/wlapplication.cc 2015-05-29 21:26:17 +0000
4@@ -501,46 +501,48 @@
5 return true;
6 }
7
8-bool WLApplication::handle_key(const SDL_Keycode& keycode, int modifiers) {
9- const bool ctrl = (modifiers & KMOD_LCTRL) || (modifiers & KMOD_RCTRL);
10- switch (keycode) {
11- case SDLK_F10:
12- // exits the game.
13- if (ctrl) {
14- m_should_die = true;
15- }
16- return true;
17-
18- case SDLK_F11:
19- // Takes a screenshot.
20- if (ctrl) {
21- if (g_fs->disk_space() < MINIMUM_DISK_SPACE) {
22- log("Omitting screenshot because diskspace is lower than %luMB\n",
23- MINIMUM_DISK_SPACE / (1000 * 1000));
24- break;
25- }
26- g_fs->ensure_directory_exists(SCREENSHOT_DIR);
27- for (uint32_t nr = 0; nr < 10000; ++nr) {
28- const std::string filename = (boost::format(SCREENSHOT_DIR "/shot%04u.png") % nr).str();
29- if (g_fs->file_exists(filename)) {
30- continue;
31- }
32- g_gr->screenshot(filename);
33- break;
34- }
35- }
36- return true;
37-
38- case SDLK_f: {
39- // toggle fullscreen
40- bool value = !g_gr->fullscreen();
41- g_gr->set_fullscreen(value);
42- g_options.pull_section("global").set_bool("fullscreen", value);
43- return true;
44- }
45-
46- default:
47- break;
48+bool WLApplication::handle_key(bool down, const SDL_Keycode& keycode, int modifiers) {
49+ if (down) {
50+ const bool ctrl = (modifiers & KMOD_LCTRL) || (modifiers & KMOD_RCTRL);
51+ switch (keycode) {
52+ case SDLK_F10:
53+ // exits the game.
54+ if (ctrl) {
55+ m_should_die = true;
56+ }
57+ return true;
58+
59+ case SDLK_F11:
60+ // Takes a screenshot.
61+ if (ctrl) {
62+ if (g_fs->disk_space() < MINIMUM_DISK_SPACE) {
63+ log("Omitting screenshot because diskspace is lower than %luMB\n",
64+ MINIMUM_DISK_SPACE / (1000 * 1000));
65+ break;
66+ }
67+ g_fs->ensure_directory_exists(SCREENSHOT_DIR);
68+ for (uint32_t nr = 0; nr < 10000; ++nr) {
69+ const std::string filename = (boost::format(SCREENSHOT_DIR "/shot%04u.png") % nr).str();
70+ if (g_fs->file_exists(filename)) {
71+ continue;
72+ }
73+ g_gr->screenshot(filename);
74+ break;
75+ }
76+ }
77+ return true;
78+
79+ case SDLK_f: {
80+ // toggle fullscreen
81+ bool value = !g_gr->fullscreen();
82+ g_gr->set_fullscreen(value);
83+ g_options.pull_section("global").set_bool("fullscreen", value);
84+ return true;
85+ }
86+
87+ default:
88+ break;
89+ }
90 }
91 return false;
92 }
93@@ -557,7 +559,7 @@
94 handled = cb->key(ev.type == SDL_KEYDOWN, ev.key.keysym);
95 }
96 if (!handled) {
97- handle_key(ev.key.keysym.sym, ev.key.keysym.mod);
98+ handle_key(ev.type == SDL_KEYDOWN, ev.key.keysym.sym, ev.key.keysym.mod);
99 }
100 } break;
101
102
103=== modified file 'src/wlapplication.h'
104--- src/wlapplication.h 2014-12-06 12:22:35 +0000
105+++ src/wlapplication.h 2015-05-29 21:26:17 +0000
106@@ -207,7 +207,7 @@
107
108 // Handle the given pressed key. Returns true when key was
109 // handled.
110- bool handle_key(const SDL_Keycode& keycode, int modifiers);
111+ bool handle_key(bool down, const SDL_Keycode& keycode, int modifiers);
112
113 /**
114 * The commandline, conveniently repackaged.

Subscribers

People subscribed via source and target branches

to status/vote changes: