fix zoom slider focus issue (add a separate class for zoom_slider)

When the slider widget was added to ThemeWML, some work was not
done apparently to make it play nicely with regards to focus and
key events with the other theme wml widgets, causing it to retain
focus for keyboard events indefinitely. At the time this was
resolved by disabling these events, but this cripples the many
other sliders in the game. In this commit we introduce a subclass
zoom_slider which has this functionality disabled, and use that
for zoom sliders, so that we can get the desired functionality
back for the other sliders. See parent of this commit for more
info.
This commit is contained in:
Chris Beck 2015-03-05 06:57:46 -05:00
parent e1102b394f
commit 641b001a92
4 changed files with 27 additions and 7 deletions

View file

@ -899,7 +899,7 @@ gui::button* display::find_menu_button(const std::string& id)
return NULL;
}
gui::slider* display::find_slider(const std::string& id)
gui::zoom_slider* display::find_slider(const std::string& id)
{
for (size_t i = 0; i < sliders_.size(); ++i) {
if(sliders_[i].id() == id) {
@ -913,12 +913,12 @@ void display::create_buttons()
{
std::vector<gui::button> menu_work;
std::vector<gui::button> action_work;
std::vector<gui::slider> slider_work;
std::vector<gui::zoom_slider> slider_work;
DBG_DP << "creating sliders...\n";
const std::vector<theme::slider>& sliders = theme_.sliders();
for(std::vector<theme::slider>::const_iterator i = sliders.begin(); i != sliders.end(); ++i) {
gui::slider s(screen_, i->image(), i->black_line());
gui::zoom_slider s(screen_, i->image(), i->black_line());
DBG_DP << "drawing button " << i->get_id() << "\n";
s.set_id(i->get_id());
const SDL_Rect& loc = i->location(screen_area());
@ -934,7 +934,7 @@ void display::create_buttons()
s.set_volatile(true);
}
gui::slider* s_prev = find_slider(s.id());
gui::zoom_slider* s_prev = find_slider(s.id());
if(s_prev) {
s.set_max(s_prev->max_value());
s.set_min(s_prev->min_value());

View file

@ -374,7 +374,7 @@ public:
*/
gui::button* find_action_button(const std::string& id);
gui::button* find_menu_button(const std::string& id);
gui::slider* find_slider(const std::string& id);
gui::zoom_slider* find_slider(const std::string& id);
gui::button::TYPE string_to_button_type(std::string type);
void create_buttons();
@ -765,7 +765,7 @@ protected:
std::map<std::string, surface> reportSurfaces_;
std::map<std::string, config> reports_;
std::vector<gui::button> menu_buttons_, action_buttons_;
std::vector<gui::slider> sliders_;
std::vector<gui::zoom_slider> sliders_;
std::set<map_location> invalidated_;
std::set<map_location> previous_invalidated_;
surface mouseover_hex_overlay_;

View file

@ -300,7 +300,7 @@ void slider::handle_event(const SDL_Event& event)
mouse_motion(event.motion);
break;
case SDL_KEYDOWN:
if(focus(&event)) {
if(focus(&event) && allow_key_events()) { //allow_key_events is used by zoom_sliders to disable left-right key press, which is buggy for them
const SDL_keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym;
const int c = key.sym;
if(c == SDLK_LEFT) {
@ -378,4 +378,15 @@ template class list_slider< double >;
template class list_slider< int >;
template class list_slider< std::string >;
/***
*
* Zoom Slider
*
***/
zoom_slider::zoom_slider(CVideo &video, const std::string& image, bool black)
: slider(video, image, black)
{
}
} //end namespace gui

View file

@ -51,6 +51,7 @@ protected:
bool requires_event_focus(const SDL_Event *event=NULL) const;
virtual void handle_event(const SDL_Event& event);
virtual void draw_contents();
virtual bool allow_key_events() { return true; }
private:
void mouse_motion(const SDL_MouseMotionEvent& event);
@ -85,6 +86,14 @@ class list_slider : public slider
std::vector<T> items_;
};
// This is a different style of slider, which doesn't implement key left/right responses
class zoom_slider : public slider
{
public:
zoom_slider(CVideo &video, const std::string& image = "buttons/sliders/slider", bool black = false);
virtual bool allow_key_events() { return false; }
};
}
#endif