Пример #1
0
	bool selector_widget::handle_event(const SDL_Event& event, bool claimed)
	{
		SDL_Event ev = event;
		normalize_event(&ev);

		if(claimed) {
			return claimed;
		}
		if(event.type == SDL_MOUSEMOTION) {
			return handle_mousemotion(event.motion, claimed);
		} else if(event.type == SDL_MOUSEBUTTONDOWN) {
			return handle_mousedown(event.button, claimed);
		} else if(event.type == SDL_MOUSEBUTTONUP) {
			return handle_mouseup(event.button, claimed);
		} else if(event.type == SDL_KEYDOWN) {
			const SDL_Keycode key = event.key.keysym.sym;
			if(key == SDLK_LEFT || key == SDLK_PAGEUP) {
				select_left();
			} else if(key == SDLK_RIGHT || key == SDLK_PAGEDOWN) {
				select_right();
			} else if(key == SDLK_HOME) {
				if(!list_.empty()) {
					set_selection(0);
				}
			} else if(key == SDLK_END) {
				if(!list_.empty()) {
					set_selection(list_.size()-1);
				}
			} else if(key == SDLK_RETURN && on_select_) {
				on_select_(list_[current_selection_].first);
			}
		}
		return claimed;
	}
Пример #2
0
void OptionsScreen::process_cursor() {
	if(input->is_pressed(A_RUN) || input->is_pressed(A_JUMP) ||
			input->is_pressed(A_SHOOT) || input->is_pressed(A_BOMB)) {
		if(!(input->is_pressed(A_JUMP) && input->is_pressed(A_UP))) // It's likely that up and jump are the same keybind
			select();
	}

	if(input->is_pressed(A_LEFT))
		select_left();
	if(input->is_pressed(A_RIGHT))
		select_right();
	if(input->is_pressed(A_UP))
		select_up();
	if(input->is_pressed(A_DOWN))
		select_down();
}