Exemple #1
0
void menu::update_size()
{
	unsigned int h = heading_height();
	for(size_t i = get_position(),
	    i_end = std::min(items_.size(), i + max_items_onscreen());
	    i < i_end; ++i)
		h += get_item_rect(i).h;
	h = std::max(h, height());
	if (max_height_ > 0 && h > static_cast<unsigned>(max_height_)) {
		h = max_height_;
	}

	use_ellipsis_ = false;
	std::vector<int> const &widths = column_widths();
	unsigned w = std::accumulate(widths.begin(), widths.end(), 0);
	if (items_.size() > max_items_onscreen())
		w += scrollbar_width();
	w = std::max(w, width());
	if (max_width_ > 0 && w > static_cast<unsigned>(max_width_)) {
		use_ellipsis_ = true;
		w = max_width_;
	}

	//update_scrollbar_grip_height();
	//set_measurements(w, h);
	size_t max_height = (max_height_ == -1 ? (video().gety()*88)/100 : max_height_) - heading_height();
	h = heading_height();
	for(int i = 0; i < items_.size(); i++)
		h += get_item_height(i);	

	if (max_height > h)
		max_height = h;
	set_measurements(w, max_height);
	update_scrollbar_grip_height();
}
Exemple #2
0
void menu::update_scrollbar_grip_height()
{
	//set_full_size(items_.size());
	int h = heading_height();
	for(int i = 0; i < items_.size(); i++)
		h += get_item_height(i);	
	set_full_size(h);
	size_t max_height = (max_height_ == -1 ? (video().gety()*88)/100 : max_height_) - heading_height();
	if (max_height > h)
		max_height = h;
	set_shown_size(max_height);
}
Exemple #3
0
void menu::draw_contents()
{
	
	// KP: now draw a nice frame!
	SDL_Rect frame_rect = inner_location();
	gui::dialog_frame f(video(), "", gui::dialog_frame::preview_style, false);
	f.layout(frame_rect);
//	f.draw_background();
	f.draw_border();
	
	
	SDL_Rect heading_rect = inner_location();
	heading_rect.h = heading_height();
	style_->draw_row(*this,0,heading_rect,HEADING_ROW);
	
	// KP: make sure to clip
	SDL_Rect content_rect = inner_location();
	content_rect.y += heading_rect.h;
	content_rect.h -= heading_rect.h;
	clip_rect_setter clippy(content_rect);
	

	for(size_t i = 0; i != item_pos_.size(); ++i) {
		style_->draw_row(*this,item_pos_[i],get_item_rect(i),
			 (!out_ && item_pos_[i] == selected_) ? SELECTED_ROW : NORMAL_ROW);
	}
}
Exemple #4
0
void menu::update_size()
{
	int h = heading_height();
	for(size_t i = get_position(),
	    i_end = std::min(items_.size(), i + max_items_onscreen());
	    i < i_end; ++i)
		h += get_item_rect(i).h;
	h = std::max(h, height());
	if (max_height_ > 0 && h > (max_height_)) {
		h = max_height_;
	}

	use_ellipsis_ = false;
	std::vector<int> const &widths = column_widths();
	int w = std::accumulate(widths.begin(), widths.end(), 0);
	if (items_.size() > max_items_onscreen())
		w += scrollbar_width();
	w = std::max(w, width());
	if (max_width_ > 0 && w > (max_width_)) {
		use_ellipsis_ = true;
		w = max_width_;
	}

	update_scrollbar_grip_height();
	set_measurements(w, h);
}
Exemple #5
0
int menu::hit_heading(int x, int y) const
{
	const size_t height = heading_height();
	const SDL_Rect& loc = inner_location();
	if(y >= loc.y && static_cast<size_t>(y) < loc.y + height) {
		return hit_column(x);
	} else {
		return -1;
	}
}
Exemple #6
0
void menu::draw_contents()
{
	SDL_Rect heading_rect = inner_location();
	heading_rect.h = heading_height();
	style_->draw_row(*this,0,heading_rect,HEADING_ROW);

	for(size_t i = 0; i != item_pos_.size(); ++i) {
		style_->draw_row(*this,item_pos_[i],get_item_rect(i),
			 (!out_ && item_pos_[i] == selected_) ? SELECTED_ROW : NORMAL_ROW);
	}
}
Exemple #7
0
SDL_Rect menu::get_item_rect_internal(size_t item) const
{
	//unsigned int first_item_on_screen = get_position();
	unsigned int first_item_on_screen = get_position() / item_height_;
	unsigned int leftovers = get_position() - (first_item_on_screen * item_height_);
	if (item < first_item_on_screen ||
	    size_t(item) >= first_item_on_screen + max_items_onscreen() + 2) {
		return empty_rect;
	}

	const std::map<int,SDL_Rect>::const_iterator i = itemRects_.find(item);
	if(i != itemRects_.end())
		return i->second;

	SDL_Rect const &loc = inner_location();

	int y = loc.y + heading_height();
	if (item != first_item_on_screen) {
		const SDL_Rect& prev = get_item_rect_internal(item-1);
		y = prev.y + prev.h;
	}
	else
	{
		// KP: sub-item scrolling
		y -= leftovers;
	}

	SDL_Rect res = { loc.x, y, loc.w, get_item_height(item) };

	SDL_Rect const &screen_area = ::screen_area();

	if(res.x > screen_area.w) {
		return empty_rect;
	} else if(res.x + res.w > screen_area.w) {
		res.w = screen_area.w - res.x;
	}

	if(res.y > screen_area.h) {
		return empty_rect;
	} else if(res.y + res.h > screen_area.h) {
		res.h = screen_area.h - res.y;
	}

	//only insert into the cache if the menu's co-ordinates have
	//been initialized
	if (loc.x > 0 && loc.y > 0)
		itemRects_.insert(std::pair<int,SDL_Rect>(item,res));

	return res;
}
//*************************************************************************************
//
//*************************************************************************************
void	ICheatOptionsScreen::Render()
{
	mpContext->ClearBackground();

	//u32		font_height( mpContext->GetFontHeight() );
	//u32		line_height( font_height + 2 );
	s32		y;

	const char * const title_text = "Cheat Options";
	mpContext->SetFontStyle( CUIContext::FS_HEADING );
	u32		heading_height( mpContext->GetFontHeight() );
	y = TITLE_AREA_TOP + heading_height;
	mpContext->DrawTextAlign( TEXT_AREA_LEFT, TEXT_AREA_RIGHT, AT_CENTRE, y, title_text, mpContext->GetDefaultTextColour() ); y += heading_height;
	mpContext->SetFontStyle( CUIContext::FS_REGULAR );

	y += 2;

	//mpContext->DrawTextAlign( TEXT_AREA_LEFT, TEXT_AREA_RIGHT, AT_CENTRE, y, mRomName.c_str(), mpContext->GetDefaultTextColour() ); y += line_height;

	y += 4;

	// Very basic scroller for cheats, note ROM tittle is disabled since it overlaps when scrolling - FIX ME
	//
	if( mElements.GetSelectedIndex() > 1 )
		mElements.Draw( mpContext, TEXT_AREA_LEFT, TEXT_AREA_RIGHT, AT_CENTRE, TEXT_AREA_TOP - mElements.GetSelectedIndex()*11 );
	else
		mElements.Draw( mpContext, TEXT_AREA_LEFT, TEXT_AREA_RIGHT, AT_CENTRE, TEXT_AREA_TOP - mElements.GetSelectedIndex());

	//mElements.Draw( mpContext, TEXT_AREA_LEFT, TEXT_AREA_RIGHT, AT_CENTRE, y );

	CUIElement *	element( mElements.GetSelectedElement() );
	if( element != NULL )
	{
		const char *		p_description( element->GetDescription() );

		mpContext->DrawTextArea( DESCRIPTION_AREA_LEFT,
								 DESCRIPTION_AREA_TOP,
								 DESCRIPTION_AREA_RIGHT - DESCRIPTION_AREA_LEFT,
								 DESCRIPTION_AREA_BOTTOM - DESCRIPTION_AREA_TOP,
								 p_description,
								 DrawTextUtilities::TextWhite,
								 VA_BOTTOM );
	}
}
Exemple #9
0
void menu::draw()
{
	if(hidden()) {
		return;
	}

	if(!dirty()) {

		for(std::set<int>::const_iterator i = invalid_.begin(); i != invalid_.end(); ++i) {
			if(*i == -1) {
				SDL_Rect heading_rect = inner_location();
				heading_rect.h = heading_height();
				bg_restore(heading_rect);
				style_->draw_row(*this,0,heading_rect,HEADING_ROW);
				update_rect(heading_rect);
			} else if(*i >= 0 && *i < int(item_pos_.size())) {
				const unsigned int pos = item_pos_[*i];
				const SDL_Rect& rect = get_item_rect(*i);
				bg_restore(rect);
				style_->draw_row(*this,pos,rect,
					(!out_ && pos == selected_) ? SELECTED_ROW : NORMAL_ROW);
				update_rect(rect);
			}
		}

		invalid_.clear();
		return;
	}

	invalid_.clear();

	bg_restore();

	util::scoped_ptr<clip_rect_setter> clipper(NULL);
	if(clip_rect())
		clipper.assign(new clip_rect_setter(video().getSurface(), *clip_rect()));

	draw_contents();

	update_rect(location());
	set_dirty(false);
}
Exemple #10
0
size_t menu::max_items_onscreen() const
{
	if(max_items_ != -1) {
		return size_t(max_items_);
	}

#ifdef USE_TINY_GUI
	const size_t max_height = (max_height_ == -1 ? (video().gety()*55)/100 : max_height_) - heading_height();
#else
	const size_t max_height = (max_height_ == -1 ? (video().gety()*66)/100 : max_height_) - heading_height();
#endif

	std::vector<int> heights;
	size_t n;
	for(n = 0; n != items_.size(); ++n) {
		heights.push_back(get_item_height(n));
	}

	std::sort(heights.begin(),heights.end(),std::greater<int>());
	size_t sum = 0;
	for(n = 0; n != items_.size() && sum < max_height; ++n) {
		sum += heights[n];
	}

	if(sum > max_height && n > 1)
		--n;

	return max_items_ = n;
}