allows sliders to be adjusted with keyboard left and right
This commit is contained in:
parent
9977836579
commit
ee9a32f024
5 changed files with 21 additions and 6 deletions
|
@ -10,6 +10,7 @@ Version 1.3-svn:
|
|||
* decreased cost of the Mudcrawler from 9 to 5
|
||||
* user interface
|
||||
* disable inactive sliders instead of hiding them
|
||||
* sliders can be adjusted with keyboard left and right
|
||||
|
||||
Version 1.1.7:
|
||||
* campaigns
|
||||
|
|
|
@ -258,7 +258,6 @@ void gamebrowser::handle_event(const SDL_Event& event)
|
|||
|
||||
if(point_in_rect(x, y, item_rect)) {
|
||||
set_focus(true);
|
||||
set_dirty();
|
||||
selected_ = i;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -524,6 +524,9 @@ void menu::key_press(SDLKey key)
|
|||
void menu::handle_event(const SDL_Event& event)
|
||||
{
|
||||
scrollarea::handle_event(event);
|
||||
if (hidden())
|
||||
return;
|
||||
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
// Only pass key events if we have the focus
|
||||
if (focus())
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
const std::string slider_image = "buttons/slider.png";
|
||||
|
@ -173,6 +174,7 @@ void slider::mouse_down(const SDL_MouseButtonEvent& event)
|
|||
return;
|
||||
|
||||
state_ = CLICKED;
|
||||
set_focus(true);
|
||||
set_slider_position(event.x);
|
||||
}
|
||||
|
||||
|
@ -180,9 +182,9 @@ void slider::handle_event(const SDL_Event& event)
|
|||
{
|
||||
if (hidden() || !enabled())
|
||||
return;
|
||||
|
||||
|
||||
STATE start_state = state_;
|
||||
|
||||
|
||||
switch(event.type) {
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
state_ = NORMAL;
|
||||
|
@ -193,12 +195,21 @@ void slider::handle_event(const SDL_Event& event)
|
|||
case SDL_MOUSEMOTION:
|
||||
mouse_motion(event.motion);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if(focus()) {
|
||||
const SDL_keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym;
|
||||
const int c = key.sym;
|
||||
if(c == SDLK_LEFT) {
|
||||
set_value(value_ - increment_);
|
||||
} else if(c == SDLK_RIGHT) {
|
||||
set_value(value_ + increment_);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (start_state != state_)
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
}
|
||||
} //end namespace gui
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
virtual void set_location(SDL_Rect const &rect);
|
||||
|
||||
protected:
|
||||
bool requires_event_focus() const { return enabled(); }
|
||||
virtual void handle_event(const SDL_Event& event);
|
||||
virtual void draw_contents();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue