Beispiel #1
0
void menu::set_items(const std::vector<std::string>& items, bool strip_spaces, bool keep_viewport)
{

	const bool scrolled_to_max = (has_scrollbar() && get_position() == get_max_position());
	items_.clear();
	item_pos_.clear();
	itemRects_.clear();
	column_widths_.clear();
	//undrawn_items_.clear();
	max_items_ = -1; // Force recalculation of the max items.
	item_height_ = -1; // Force recalculation of the item height.

	if (!keep_viewport || selected_ >= items.size()) {
		selected_ = 0;
	}

	fill_items(items, strip_spaces);
	if(!keep_viewport) {
		set_position(0);
	} else if(scrolled_to_max) {
		set_position(get_max_position());
	}

	update_scrollbar_grip_height();

	if(!keep_viewport) {
		adjust_viewport_to_selection();
	}
	set_dirty();
}
Beispiel #2
0
void scrollbar::set_full_size(unsigned h)
{
	if (h == full_height_)
		return;
	bool at_bottom = get_position() == get_max_position() && get_max_position() > 0;
	full_height_ = h;
	if (at_bottom)
		grip_position_ = get_max_position();
	downarrow_.enable(grip_position_ < full_height_ - grip_height_);
	set_shown_size(grip_height_);
	set_position(grip_position_);
	set_dirty(true);
}
Beispiel #3
0
void scrollbar::set_shown_size(unsigned h)
{
	if (h > full_height_)
		h = full_height_;
	if (h == grip_height_)
		return;
	bool at_bottom = get_position() == get_max_position() && get_max_position() > 0;
	grip_height_ = h;
	if (at_bottom)
		grip_position_ = get_max_position();
	set_position(grip_position_);
	set_dirty(true);
}
void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_Color& color)
{
	if(text_image_.get() == NULL) {
		set_text(text, color);
		return;
	}

	//disallow adding multi-line text to a single-line text box
	if(wrap_ == false && std::find_if(text.begin(),text.end(),utils::isnewline) != text.end()) {
		return;
	}
	const bool is_at_bottom = get_position() == get_max_position();
	const wide_string& wtext = utils::string_to_wstring(text);

	const surface new_text = add_text_line(wtext, color);
	const surface new_surface = create_compatible_surface(text_image_,std::max<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h);

	SDL_SetAlpha(new_text.get(),0,0);
	SDL_SetAlpha(text_image_.get(),0,0);

	SDL_BlitSurface(text_image_,NULL,new_surface,NULL);

	SDL_Rect target = {0,text_image_->h,new_text->w,new_text->h};
	SDL_BlitSurface(new_text,NULL,new_surface,&target);
	text_image_.assign(new_surface);

	text_.resize(text_.size() + wtext.size());
	std::copy(wtext.begin(),wtext.end(),text_.end()-wtext.size());

	set_dirty(true);
	update_text_cache(false);
	if(auto_scroll && is_at_bottom) scroll_to_bottom();
	handle_text_changed(text_);
}
void textbox::scroll_to_bottom()
{
	set_position(get_max_position());
}
Beispiel #6
0
bool scrollarea::handle_drag_event(const SDL_Event& event)
{
	// KP: added content dragging for iPhone
	static bool isDragging = false;
	static int startDrag = 0;
	static int startPos = 0;
	static bool didDrag = false;
	SDL_MouseButtonEvent const &e = event.button;
	if (point_in_rect(e.x, e.y, inner_location()))
	{
		switch(event.type)
		{
			case SDL_MOUSEBUTTONUP:
			{
				isDragging = false;
				break;
			}
			case SDL_MOUSEBUTTONDOWN:
			{
				isDragging = true;
				startDrag = e.y;
				startPos = get_position();
				didDrag = false;
				break;
			}
			case SDL_MOUSEMOTION:
			{
				if (isDragging)
				{
					int changeY = startDrag - e.y;
					//SDL_Rect inner_loc = inner_location();
					//float pixelsPerScroll = item_height_ / ((float) (item_height_ * nitems()) / inner_loc.h);
					//int move = changeY / pixelsPerScroll;
					int move = changeY;
					if (move != 0)
					{
						int newPos = startPos + move;
						if (newPos < 0)
							newPos = 0;
						if (newPos > get_max_position())
							newPos = get_max_position();
						set_position(newPos);
						didDrag = true;
						
						// fixes dragging off of control
						startDrag = e.y;
						startPos = newPos;
					}
				}
				break;
			}
			default:
				break;
		}
	}
	else if (event.type == SDL_MOUSEBUTTONUP)
	{
		isDragging = false;
	}
	
	// do not select after dragging
	if (didDrag == true && isDragging == false)
	{
		didDrag = false;
		return true;
	}
	
	return false;
	// END iPhone content dragging
	
}