-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
hotkey_preferences_display.cpp
84 lines (65 loc) · 2.27 KB
/
hotkey_preferences_display.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Copyright (C) 2012 - 2016 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
/**
* @file
* Manages the hotkey bindings.
*/
#include "hotkey/hotkey_item.hpp"
#include "construct_dialog.hpp"
#include "display.hpp"
#include "gettext.hpp"
#include "marked-up_text.hpp"
namespace hotkey {
hotkey::hotkey_ptr show_binding_dialog(CVideo& video, const std::string& id)
{
// Lets bind a hotkey...
const std::string text = _("Press desired hotkey (Esc cancels)");
SDL_Rect clip_rect = sdl::create_rect(0, 0, video.getx(), video.gety());
SDL_Rect text_size = font::draw_text(NULL, clip_rect, font::SIZE_LARGE,
font::NORMAL_COLOR, text, 0, 0);
const int centerx = video.getx() / 2;
const int centery = video.gety() / 2;
SDL_Rect dlgr = sdl::create_rect(centerx - text_size.w / 2 - 30,
centery - text_size.h / 2 - 16, text_size.w + 60,
text_size.h + 32);
surface_restorer restorer(&video, dlgr);
gui::dialog_frame mini_frame(video);
mini_frame.layout(centerx - text_size.w / 2 - 20,
centery - text_size.h / 2 - 6, text_size.w + 40,
text_size.h + 12);
mini_frame.draw_background();
mini_frame.draw_border();
font::draw_text(&video, clip_rect, font::SIZE_LARGE,
font::NORMAL_COLOR, text,
centerx - text_size.w / 2, centery - text_size.h / 2);
video.flip();
SDL_Event event;
event.type = 0;
int keycode = -1;
do {
switch (event.type) {
case SDL_KEYDOWN:
keycode = event.key.keysym.sym;
break;
}
SDL_PollEvent(&event);
#if SDL_VERSION_ATLEAST(2,0,0)
events::peek_for_resize();
#endif
} while (event.type != SDL_KEYUP && event.type != SDL_JOYBUTTONUP
&& event.type != SDL_JOYHATMOTION
&& event.type != SDL_MOUSEBUTTONUP);
restorer.restore();
return keycode == SDLK_ESCAPE ? hotkey::hotkey_ptr() : hotkey::create_hotkey(id, event);
}
} //end namespace hotkey