Ejemplo n.º 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;
	}
Ejemplo n.º 2
0
void dropdown_widget::text_enter()
{
	dropdown_list::iterator it = std::find(list_.begin(), list_.end(), editor_->text());
	if(it == list_.end()) {
		current_selection_ = -1;
	} else {
		current_selection_ = it - list_.begin();
	}
	if(on_select_) {
		on_select_(current_selection_, editor_->text());
	}
}
Ejemplo n.º 3
0
void dropdown_widget::execute_selection(int selection)
{
	if(dropdown_menu_) {
		dropdown_menu_->set_visible(false);
	}
	if(selection < 0 || size_t(selection) >= list_.size()) {
		return;
	}
	//std::cerr << "execute_selection: " << selection << std::endl;
	current_selection_ = selection;
	if(type_ == DROPDOWN_LIST) {
		label_->set_text(list_[current_selection_]);
	} else if(type_ == DROPDOWN_COMBOBOX) {
		editor_->set_text(list_[current_selection_]);
	}
	if(on_select_) {
		if(type_ == DROPDOWN_LIST) {
			on_select_(current_selection_, list_[current_selection_]);
		} else if(type_ == DROPDOWN_COMBOBOX) {
			on_select_(current_selection_, editor_->text());
		}
	}
}