Example #1
0
void slider::mouse_down(const SDL_MouseButtonEvent& event)
{
	bool prev_change = value_change_;

	if (!sdl::point_in_rect(event.x, event.y, location()))
		return;


	if (event.button != SDL_BUTTON_LEFT)
		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_slider_position(event.x);
		if(value_change_) {
			sound::play_UI_sound(game_config::sounds::slider_adjust);
		} else {
			value_change_ = prev_change;
		}
	}
}
Example #2
0
void slider::mouse_motion(const SDL_MouseMotionEvent& event)
{
	if (state_ == NORMAL || state_ == ACTIVE) {
		bool on = point_in_rect(event.x, event.y, slider_area());
		state_ = on ? ACTIVE : NORMAL;
	} else if (state_ == CLICKED || state_ == DRAGGED) {
		state_ = DRAGGED;
		bool prev_change = value_change_;
		value_change_ = false;
		set_slider_position(event.x);
		if(value_change_) {
			sound::play_UI_sound(game_config::sounds::slider_adjust);
		} else {
			value_change_ = prev_change;
		}
	}
}