Skip to content

Commit

Permalink
WIP: start to clean up the hotkey dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
aginor committed Apr 28, 2017
1 parent 3215375 commit 43b85f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
27 changes: 2 additions & 25 deletions src/gui/dialogs/hotkey_bind.cpp
Expand Up @@ -36,37 +36,14 @@ hotkey_bind::hotkey_bind(const std::string& hotkey_id)

void hotkey_bind::pre_show(window& window)
{
connect_signal_pre_key_press(window, std::bind(&hotkey_bind::key_press_callback, this, std::ref(window), _5));

window.connect_signal<event::SDL_LEFT_BUTTON_DOWN>(
std::bind(&hotkey_bind::mouse_button_callback, this, std::ref(window), SDL_BUTTON_LEFT), event::dispatcher::front_child);
window.connect_signal<event::SDL_MIDDLE_BUTTON_DOWN>(
std::bind(&hotkey_bind::mouse_button_callback, this, std::ref(window), SDL_BUTTON_MIDDLE), event::dispatcher::front_child);
window.connect_signal<event::SDL_RIGHT_BUTTON_DOWN>(
std::bind(&hotkey_bind::mouse_button_callback, this, std::ref(window), SDL_BUTTON_RIGHT), event::dispatcher::front_child);
}

void hotkey_bind::key_press_callback(window& window, const SDL_Keycode key)
{
/* HACK: SDL_KEYDOWN and SDL_TEXTINPUT events forward to the same GUI2 event (SDL_KEY_DOWN), meaning
* this even gets fired twice, causing problems since 'key' will be 0 in the latter case. SDLK_UNKNOWN
* is the key value used by SDL_TEXTINPUT handling, so exit here if that's detected.
*/
if(key == SDLK_UNKNOWN) {
return;
}

new_binding_ = hotkey::create_hotkey(hotkey_id_, SDL_GetScancodeFromKey(key));

window.set_retval(window::OK);
}

void hotkey_bind::mouse_button_callback(window& window, Uint8 button)
void hotkey_bind::sdl_event_callback(window& window, const SDL_Event &event)
{
new_binding_ = hotkey::create_hotkey(hotkey_id_, button);

window.set_retval(window::OK);
}


} // namespace dialogs
} // namespace gui2
4 changes: 1 addition & 3 deletions src/gui/dialogs/hotkey_bind.hpp
Expand Up @@ -41,9 +41,7 @@ class hotkey_bind : public modal_dialog

hotkey::hotkey_ptr new_binding_;

void key_press_callback(window& window, const SDL_Keycode key);

void mouse_button_callback(window& window, Uint8 button);
void sdl_event_callback(window& window, const SDL_Event &event);

/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;
Expand Down
11 changes: 6 additions & 5 deletions src/hotkey/hotkey_item.hpp
Expand Up @@ -379,11 +379,12 @@ void add_hotkey(const hotkey_ptr item);
*/
void del_hotkey(const hotkey_ptr item);

/** 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);
/**
* 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
Expand Down

0 comments on commit 43b85f7

Please sign in to comment.