diff --git a/src/display.cpp b/src/display.cpp index b4f284174eb5..8be1933f5c3a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -840,7 +840,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) { @@ -854,12 +854,12 @@ void display::create_buttons() { std::vector menu_work; std::vector action_work; - std::vector slider_work; + std::vector slider_work; DBG_DP << "creating sliders...\n"; const std::vector& sliders = theme_.sliders(); for(std::vector::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()); @@ -875,7 +875,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()); diff --git a/src/display.hpp b/src/display.hpp index 87aeb020bd93..b51a88972ac2 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -399,7 +399,7 @@ class display : public filter_context */ 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(); @@ -807,7 +807,7 @@ class display : public filter_context #endif std::map reports_; std::vector menu_buttons_, action_buttons_; - std::vector sliders_; + std::vector sliders_; std::set invalidated_; std::set previous_invalidated_; #ifdef SDL_GPU diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp index ddc3b72bde00..406126d1546e 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -242,11 +242,11 @@ void slider::mouse_down(const SDL_MouseButtonEvent& event) return; state_ = CLICKED; + set_focus(true); if (sdl::point_in_rect(event.x, event.y, slider_area())) { sound::play_UI_sound(game_config::sounds::button_press); } else { value_change_ = false; - set_focus(true); set_slider_position(event.x); if(value_change_) { sound::play_UI_sound(game_config::sounds::slider_adjust); @@ -334,20 +334,19 @@ void slider::handle_event(const SDL_Event& event) if (!mouse_locked()) mouse_motion(event.motion); break; - //TODO enable if you know how to fix the zoom slider bug -// case SDL_KEYDOWN: -// if(focus(&event)) { -// const SDL_keysym& key = reinterpret_cast(event).keysym; -// const int c = key.sym; -// if(c == SDLK_LEFT) { -// sound::play_UI_sound(game_config::sounds::slider_adjust); -// set_value(value_ - increment_); -// } else if(c == SDLK_RIGHT) { -// sound::play_UI_sound(game_config::sounds::slider_adjust); -// set_value(value_ + increment_); -// } -// } -// break; + case SDL_KEYDOWN: + 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(event).keysym; + const int c = key.sym; + if(c == SDLK_LEFT) { + sound::play_UI_sound(game_config::sounds::slider_adjust); + set_value(value_ - increment_); + } else if(c == SDLK_RIGHT) { + sound::play_UI_sound(game_config::sounds::slider_adjust); + set_value(value_ + increment_); + } + } + break; #if SDL_VERSION_ATLEAST(2,0,0) case SDL_MOUSEWHEEL: if (!mouse_locked()) @@ -420,4 +419,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 diff --git a/src/widgets/slider.hpp b/src/widgets/slider.hpp index a3241c35b4e3..dc37dcef2bad 100644 --- a/src/widgets/slider.hpp +++ b/src/widgets/slider.hpp @@ -51,6 +51,7 @@ class slider : public widget 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); @@ -88,6 +89,14 @@ class list_slider : public slider std::vector 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