Hotkey Bind: enable dialog and remove old GUI1 code
This commit is contained in:
parent
585ce88d64
commit
581aba7e9d
6 changed files with 2 additions and 131 deletions
|
@ -813,7 +813,6 @@
|
|||
<Unit filename="../../src/hotkey/hotkey_item.hpp" />
|
||||
<Unit filename="../../src/hotkey/hotkey_manager.cpp" />
|
||||
<Unit filename="../../src/hotkey/hotkey_manager.hpp" />
|
||||
<Unit filename="../../src/hotkey/hotkey_preferences_display.cpp" />
|
||||
<Unit filename="../../src/image.cpp" />
|
||||
<Unit filename="../../src/image.hpp" />
|
||||
<Unit filename="../../src/image_modifications.cpp" />
|
||||
|
|
|
@ -301,7 +301,6 @@ help/help_topic_generators.cpp
|
|||
hotkey/hotkey_handler.cpp
|
||||
hotkey/hotkey_handler_mp.cpp
|
||||
hotkey/hotkey_handler_sp.cpp
|
||||
hotkey/hotkey_preferences_display.cpp
|
||||
intro.cpp
|
||||
lobby_preferences.cpp
|
||||
menu_events.cpp
|
||||
|
|
|
@ -820,15 +820,10 @@ void preferences_dialog::add_hotkey_callback(listbox& hotkeys)
|
|||
int row_number = hotkeys.get_selected_row();
|
||||
const hotkey::hotkey_command& hotkey_item = *visible_hotkeys_[row_number];
|
||||
|
||||
// TODO
|
||||
#if 0
|
||||
gui2::dialogs::hotkey_bind bind_dlg(hotkey_item.command);
|
||||
bind_dlg.show(video);
|
||||
|
||||
hotkey::hotkey_ptr newhk = bind_dlg.get_new_binding();
|
||||
#endif
|
||||
|
||||
hotkey::hotkey_ptr newhk = hotkey::show_binding_dialog(video, hotkey_item.command);
|
||||
hotkey::hotkey_ptr oldhk;
|
||||
|
||||
// only if not cancelled.
|
||||
|
|
|
@ -155,40 +155,6 @@ void hotkey_base::save(config& item) const
|
|||
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 = std::dynamic_pointer_cast<hotkey_base>(keyboard);
|
||||
SDL_Scancode code;
|
||||
code = event.key.keysym.scancode;
|
||||
std::cerr << "code is " << code << std::endl;
|
||||
keyboard->set_scancode(code);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
hotkey_mouse_ptr mouse(new hotkey_mouse());
|
||||
base = std::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 create_hotkey(const std::string& id, SDL_Scancode new_val)
|
||||
{
|
||||
hotkey_ptr base = hotkey_ptr(new hotkey_void);
|
||||
|
|
|
@ -371,15 +371,10 @@ void add_hotkey(const hotkey_ptr item);
|
|||
*/
|
||||
void del_hotkey(const hotkey_ptr item);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/** Create a new hotkey item bound to a keyboard key. */
|
||||
hotkey_ptr create_hotkey(const std::string& id, SDL_Scancode new_val);
|
||||
|
||||
/** Create a new hotkey item bound to a mouse button. */
|
||||
hotkey_ptr create_hotkey(const std::string& id, Uint8 new_val);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
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 "gettext.hpp"
|
||||
#include "font/marked-up_text.hpp"
|
||||
#include "font/standard_colors.hpp"
|
||||
#include "sdl/rect.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(nullptr, 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 = {0};
|
||||
event.type = 0;
|
||||
int keycode = -1;
|
||||
|
||||
do {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
keycode = event.key.keysym.sym;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_PollEvent(&event);
|
||||
events::peek_for_resize();
|
||||
|
||||
} 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
|
Loading…
Add table
Reference in a new issue