Exemplo n.º 1
0
	void UIListBox::UpdateRects()
	{
		UIControl::UpdateRects();

		selection_rc_ = IRect(x_, y_, x_ + width_, y_ + height_);
		selection_rc_.right() -= sb_width_;
		selection_rc_ += IRect(border_, border_, -border_, -border_);
		text_rc_ = selection_rc_;
		text_rc_ += IRect(margin_, 0, -margin_, 0);

		// Update the scrollbar's rects
		scroll_bar_.SetLocation(x_ + width_ - sb_width_, y_);
		scroll_bar_.SetSize(sb_width_, height_);
		FontPtr font = UIManager::Instance().GetFont(elements_[0]->FontIndex());
		float font_size = UIManager::Instance().GetFontSize(elements_[0]->FontIndex());
		if (font && (font_size != 0))
		{
			scroll_bar_.SetPageSize(static_cast<size_t>(text_rc_.Height() / font_size));

			// The selected item may have been scrolled off the page.
			// Ensure that it is in page again.
			scroll_bar_.ShowItem(selected_);
		}

		bounding_box_ = selection_rc_ | text_rc_ | scroll_bar_.BoundingBoxRect();
	}
Exemplo n.º 2
0
	void UIEditBox::UpdateRects()
	{
		UIControl::UpdateRects();

		// Update the text rectangle
		text_rc_ = bounding_box_;
		// First inflate by border_ to compute render rects
		text_rc_ += IRect(border_, border_, -border_, -border_);

		// Update the render rectangles
		render_rc_[0] = text_rc_;
		render_rc_[1] = IRect(bounding_box_.left(), bounding_box_.top(), text_rc_.left(), text_rc_.top());
		render_rc_[2] = IRect(text_rc_.left(), bounding_box_.top(), text_rc_.right(), text_rc_.top());
		render_rc_[3] = IRect(text_rc_.right(), bounding_box_.top(), bounding_box_.right(), text_rc_.top());
		render_rc_[4] = IRect(bounding_box_.left(), text_rc_.top(), text_rc_.left(), text_rc_.bottom());
		render_rc_[5] = IRect(text_rc_.right(), text_rc_.top(), bounding_box_.right(), text_rc_.bottom());
		render_rc_[6] = IRect(bounding_box_.left(), text_rc_.bottom(), text_rc_.left(), bounding_box_.bottom());
		render_rc_[7] = IRect(text_rc_.left(), text_rc_.bottom(), text_rc_.right(), bounding_box_.bottom());
		render_rc_[8] = IRect(text_rc_.right(), text_rc_.bottom(), bounding_box_.right(), bounding_box_.bottom());

		// Inflate further by spacing_
		text_rc_ += IRect(spacing_, spacing_, -spacing_, -spacing_);

		bounding_box_ = text_rc_;
		for (int i = 0; i < 9; ++ i)
		{
			bounding_box_ |= render_rc_[i];
		}
	}
Exemplo n.º 3
0
void ChipSelecter::Draw()
{
	Render::device.SetTexturing(false);
	Render::BeginColor(Color(100, 100, 100, 180));
	Render::DrawRect(IRect(200, 150, 400, 300));
	Render::EndColor();
	
	Render::device.SetTexturing(true);
	
	//IRect rect = Game::ChipColor::DRAW_RECT;
	//Тут должно быть 44х44!
	IRect rect = IRect(0,0,44,44);

	for (int i = 0; i <= 6; i++)
	{
		int x = _chipXLeft + 50*(i%7);
		int y = _chipYDown + 50*(3 - i/7);
		FRect uv = Game::GetChipRect(i, false, false, false);
		_chipsTex->Draw(rect.MovedBy(IPoint(x - rect.width/2, y - rect.height/2)), uv);
	}

	for (size_t i = 0; i < _chipColors.size(); i++)
	{
		int color = _chipColors[i];
		int x = _chipXLeft + 50*(color%7);
		int y = _chipYDown + 50*(3 - color/7);

		Render::BeginColor(Color(100, 255, 255, 255));
		for (int q = -1; q<=1; q++)
		{
			for (int w = -1; w<=1; w++)
			{
				DrawRamka(x+q, y+w);
			}
		}
		Render::EndColor();

		FRect uv = Game::GetChipRect(color, false, false, false);	

		Render::device.SetAlpha(static_cast<int>(150+80*sinf(_timer*6 + x - y/3)));
		Render::device.SetBlendMode(Render::ADD);
		_chipsTex->Draw(rect.MovedBy(IPoint(x - rect.width/2, y - rect.height/2)), uv);
		Render::device.SetBlendMode(Render::ALPHA);
	}

	if (_underMouseChip >= 0)
	{
		int color = _underMouseChip;
		int x = _chipXLeft + 50*(color%7);
		int y = _chipYDown + 50*(3 - color/7);
		Render::BeginColor(Color(0, 255, 0, 255));
		DrawRamka(x, y);
		Render::EndColor();
	}

	Render::BindFont("debug");
	Render::PrintString(IPoint(370, 170), utils::lexical_cast(static_cast<int>(_chipColors.size())) + " colors", 1.f, CenterAlign);
}
Exemplo n.º 4
0
	ComboBox::ComboBox(const IRect &rect, int drop_size, const char *prefix, CRange<const char*> values)
		:Window(rect), m_drop_size(drop_size), m_prefix(prefix) {
		m_button = make_shared<Button>(IRect(int2(0, 0), rect.size()), "");
		m_dummy = make_shared<ListBox>(IRect(0, 0, 10, 10));
		attach(m_button);

		for(auto value : values)
			addEntry(value, ColorId::white);
		if(!values.empty())
			selectEntry(0);
	}
Exemplo n.º 5
0
	void UITexButton::SetTexture(TexturePtr const & tex)
	{
		tex_index_ = UIManager::Instance().AddTexture(tex);
		if (tex)
		{
			elements_[9]->SetTexture(static_cast<uint32_t>(tex_index_), IRect(0, 0, tex->Width(0), tex->Height(0)));
		}
		else
		{
			elements_[9]->SetTexture(static_cast<uint32_t>(tex_index_), IRect(0, 0, 1, 1));
		}
	}
Exemplo n.º 6
0
	UIScrollBar::UIScrollBar(uint32_t type, UIDialogPtr const & dialog)
					: UIControl(type, dialog),
						show_thumb_(true), drag_(false),
						position_(0), page_size_(1),
						start_(0), end_(1),
						arrow_(CLEAR), arrow_ts_(0)
	{
		up_button_rc_ = IRect(0, 0, 0, 0);
		down_button_rc_ = IRect(0, 0, 0, 0);
		track_rc_ = IRect(0, 0, 0, 0);
		thumb_rc_ = IRect(0, 0, 0, 0);

		this->InitDefaultElements();
	}
Exemplo n.º 7
0
IRect ScaleManager::GetScaledRect() {
	FPoint topRigth(Core::screen.GLWidth(), Core::screen.GLHeight());
	FPoint bottomLeft(0, 0);
	topRigth = GetPointScaled(topRigth);
	bottomLeft = GetPointScaled(bottomLeft);
	return IRect(bottomLeft.x, bottomLeft.y, topRigth.x, topRigth.y);
}
Exemplo n.º 8
0
	EditorPanel::EditorPanel(const std::string& name_, rapidxml::xml_node<>* elem_)
		: GUI::Widget(name_, elem_)
		, _tooltipExist(false)
		, _tooltip(Core::resourceManager.Get<Render::Text>("EditorTooltipText"))
	{
		std::string textureID = Xml::GetStringAttributeOrDef(elem_, "tex", "EditPanel");
		_texture = Core::resourceManager.Get<Render::Texture>(textureID);
		int col_count = Xml::GetIntAttributeOrDef(elem_, "col_count", 19);
		_cellSize = Xml::GetIntAttributeOrDef(elem_, "side", 19);
		_scrollable = Xml::GetBoolAttributeOrDef(elem_, "scrollable", false);

		_buttons.clear();
		rapidxml::xml_node<>* xml_button = elem_->first_node("button");
		int i = 0;
		while(xml_button)
		{
			IRect rect(i % col_count * _cellSize, i / col_count * _cellSize, _cellSize, _cellSize);
			_buttons.push_back( ButtonInfo(rect, xml_button) );
			xml_button = xml_button->next_sibling("button");
			i++;
		}

		IPoint pos(elem_);
		pos.y += MyApplication::GAME_HEIGHT;
		int width = col_count * _cellSize;
		int height = (i - 1) / col_count * _cellSize + _cellSize;

		setClientRect(IRect(pos.x, pos.y, width, height) );
	}
Exemplo n.º 9
0
	int UIComboBox::AddItem(std::wstring const & strText, std::experimental::any const & data)
	{
		BOOST_ASSERT(!strText.empty());

		// Create a new item and set the data
		std::shared_ptr<UIComboBoxItem> pItem = MakeSharedPtr<UIComboBoxItem>();
		pItem->strText = strText;
		pItem->data = data;
		pItem->rcActive = IRect(0, 0, 0, 0);
		pItem->bVisible = false;

		int ret = static_cast<int>(items_.size());

		items_.push_back(pItem);

		// Update the scroll bar with new range
		scroll_bar_.SetTrackRange(0, items_.size());

		// If this is the only item in the list, it's selected
		if (1 == this->GetNumItems())
		{
			selected_ = 0;
			focused_ = 0;
			this->OnSelectionChangedEvent()(*this);
		}

		return ret;
	}
Exemplo n.º 10
0
	GroupPad::GroupPad(const IRect &rect, PGroupEditor editor, TileGroup *group)
		:Window(rect), m_editor(editor), m_group(group) {
		m_filter_box = make_shared<ComboBox>(IRect(0, 0, rect.width(), 22), 200,
				"Filter: ", TileFilter::strings(), TileFilter::count);
		attach(m_filter_box);
		m_filter_box->selectEntry(editor->tileFilter());
	}
Exemplo n.º 11
0
	void LoggerTTF::draw(Surface ecran)
	{
		if(m_buffer.empty() )
			return;
		
		if(SDL_GetTicks() - m_last_message >= 3000)
		{
			m_buffer.erase( m_buffer.begin() );
			
			m_last_message = SDL_GetTicks();
		}
		
		if(m_police)
		{
			SDL_Color noir = {0, 0, 0};
			
			vector<string>::iterator message = m_buffer.begin();
			IRect boite = m_boite_ecriture;
		
			for(; message != m_buffer.end(); message++)
			{
				SDL_Surface *text = TTF_RenderText_Blended(m_police, message->c_str(), noir);
				
				if(text)
				{
					boite.y += text->h;
					boite.h -= text->h;
					
					ApplySurface(text, ecran.getSurface(), IRect(), boite );
				}
			}
		}
	}
int ChangeEnergySpeed::Editor_CaptureGadget(const IPoint& mouse_pos, int x, int y)
{
	// Преобразовываем координаты к координатам на поле
	int mx = mouse_pos.x + GameSettings::FieldCoordMouse().x;
	int my = mouse_pos.y + GameSettings::FieldCoordMouse().y;

	IRect r (mx - (GameSettings::SQUARE_SIDE / 2), my - (GameSettings::SQUARE_SIDE / 2), 0, 0);
	r.Inflate((GameSettings::SQUARE_SIDE / 2));
	
	_sliderRect = IRect(_snapPoint.x * GameSettings::SQUARE_SIDE,_snapPoint.y * GameSettings::SQUARE_SIDE - 30,200,30); 

	if (r.Contains(_snapPoint * GameSettings::SQUARE_SIDE)) 
	{
		return (-2);
	}
	else if (_sliderRect.Contains(IPoint(mx,my))) 
	{

		return (-3);
	}
	else 
	{
		return (-1);
	}
}
Exemplo n.º 13
0
	void UICheckBox::UpdateRects()
	{
		button_rc_ = text_rc_ = IRect(x_, y_, x_ + width_, y_ + height_);
		button_rc_.right() = button_rc_.left() + button_rc_.Height();
		text_rc_.left() += static_cast<int32_t>(1.25f * button_rc_.Width());

		bounding_box_ = button_rc_ | text_rc_;
	}
Exemplo n.º 14
0
	void Window::setRect(const IRect &rect) {
		DASSERT(!m_dragging_mode);
		DASSERT(!rect.empty());

		m_rect = rect;
		setInnerRect(IRect({0, 0}, m_rect.size()));
		updateRects();
	}
Exemplo n.º 15
0
void ChipSelecter::DrawRamka(int x, int y)
{
	//Тут должно быть 44х44!
	IRect rect = IRect(0,0,44,44);

	Render::device.SetTexturing(false);
	Render::DrawFrame(rect.MovedBy(IPoint(x - rect.width/2, y - rect.height/2)));
	Render::device.SetTexturing(true);
}
Exemplo n.º 16
0
	ImageButton::ImageButton(const int2 &pos, const ImageButtonProto &proto, const char *text, Mode mode, int id)
		:Window(IRect(pos, pos + proto.rect.size()), Color::transparent), m_proto(proto), m_id(id), m_mode(mode) {
		setBackground(proto.back);
		setText(text);

		m_is_enabled = true;
		m_is_pressed = false;
		m_mouse_press = false;
	}
Exemplo n.º 17
0
	void ImageButton::drawContents(Renderer2D &out) const {
		bool is_pressed =	m_mode == mode_toggle? m_is_pressed ^ m_mouse_press :
							m_mode == mode_toggle_on? m_is_pressed || m_mouse_press : m_mouse_press;

		if(is_pressed)
			out.addFilledRect(IRect(m_proto.down->size()), m_proto.down);
		else
			out.addFilledRect(IRect(m_proto.up->size()), m_proto.up);

		if(m_proto.font) {
			int2 rect_center = size() / 2;
			int2 pos(m_proto.text_rect.min.x - 1, m_proto.text_rect.center().y - m_text_extents.height() / 2 - 1);

			if(m_mouse_press)
				pos += int2(2, 2);
			m_proto.font->draw(out, pos, {m_is_enabled? Color(255, 200, 0) : Color::gray, Color::black}, m_text);
		}
	}
Exemplo n.º 18
0
	ImageButtonProto::ImageButtonProto(const char *back_tex, const char *up_tex, const char *down_tex, const char *font_name, FRect text_area) {
		DASSERT(up_tex && down_tex);

		if(back_tex)
			back = DTexture::gui_mgr[back_tex];

		up = DTexture::gui_mgr[up_tex];
		down = DTexture::gui_mgr[down_tex];
		if(font_name)
			font = Font::mgr[font_name];

		rect = IRect({0, 0}, back? back->size() : max(up->size(), down->size()));
		text_rect = text_area.isEmpty()? IRect::empty() :
			IRect(	lerp(float(rect.min.x), float(rect.max.x), text_area.min.x),
					lerp(float(rect.min.y), float(rect.max.y), text_area.min.y),
					lerp(float(rect.min.x), float(rect.max.x), text_area.max.x),
					lerp(float(rect.min.y), float(rect.max.y), text_area.max.y));
	}
Exemplo n.º 19
0
	UIScrollBar::UIScrollBar(UIDialogPtr const & dialog, int ID, int4 const & coord_size, int nTrackStart, int nTrackEnd, int nTrackPos, int nPageSize)
					: UIControl(UIScrollBar::Type, dialog),
						show_thumb_(true), drag_(false),
						position_(nTrackPos), page_size_(nPageSize),
						start_(nTrackStart), end_(nTrackEnd),
						arrow_(CLEAR), arrow_ts_(0)
	{
		up_button_rc_ = IRect(0, 0, 0, 0);
		down_button_rc_ = IRect(0, 0, 0, 0);
		track_rc_ = IRect(0, 0, 0, 0);
		thumb_rc_ = IRect(0, 0, 0, 0);

		this->InitDefaultElements();

		// Set the ID and position
		this->SetID(ID);
		this->SetLocation(coord_size.x(), coord_size.y());
		this->SetSize(coord_size.z(), coord_size.w());
	}
Exemplo n.º 20
0
	void Button::drawContents() const {
		drawWindow(IRect(int2(0, 0), size()), isMouseOver() && m_is_enabled? WindowStyle::gui_light : WindowStyle::gui_dark,
					m_mouse_press? -2 : 2);

		int2 rect_center = size() / 2;
		int2 pos = rect_center - m_text_extents.size() / 2 - m_text_extents.min - int2(1, 1);
		if(m_mouse_press)
			pos += int2(2, 2);
		m_font->draw((float2)pos, {m_is_enabled? Color::white : Color::gray, Color::black}, m_text);
	}
Exemplo n.º 21
0
    Image::Image(Vector2 pos, Texture2D texture) : Entity(pos, IRect((int32)pos.x, (int32)pos.y, texture.width(), texture.height()))
    {
        // Initialize Vertex and Index buffer
        vBuffer = 0;
        iBuffer = 0;

        tex = texture;

        initVBO();
    }
Exemplo n.º 22
0
	const TileList::Entry* TileList::find(int2 pos) const {
		for(int n = 0; n < (int)m_entries.size(); n++) {
			const Entry &entry = m_entries[n];

			if(IRect(entry.pos, entry.pos + entry.size).isInside(pos))
				return &m_entries[n];
		}

		return nullptr;
	}
Exemplo n.º 23
0
	void UIListBox::InsertItem(int nIndex, std::wstring const & strText, std::experimental::any const & data)
	{
		std::shared_ptr<UIListBoxItem> pNewItem = MakeSharedPtr<UIListBoxItem>();
		pNewItem->strText = strText;
		pNewItem->data = data;
		pNewItem->rcActive = IRect(0, 0, 0, 0);
		pNewItem->bSelected = false;

		items_.insert(items_.begin() + nIndex, pNewItem);
		scroll_bar_.SetTrackRange(0, items_.size());
	}
Exemplo n.º 24
0
	FileDialog::FileDialog(const IRect &rect, const char *title, Mode mode)
		:Window(rect, ColorId::transparent), m_mode(mode) {
		int w = width(), h = height();

		PTextBox title_box = make_shared<TextBox>(IRect(5, 5, w - 5, 25), title);
		title_box->setFont(WindowStyle::fonts[1]);

		m_list_box = make_shared<ListBox>(IRect(5, 25, w - 25, h - 50));
		m_edit_box = make_shared<EditBox>(IRect(5, h - 49, w - 5, h - 26), 30, "", WindowStyle::gui_light);
		m_ok_button = make_shared<Button>(IRect(w - 110, h - 25, w - 55, h - 5), s_ok_label[mode], 1);
		PButton cancel_button = make_shared<Button>(IRect(w - 55 , h - 25, w - 5, h - 5), "cancel", 0);

		attach(title_box);
		attach(m_ok_button);
		attach(cancel_button);
		attach(m_list_box);
		attach(m_edit_box);
	
		m_dir_path = "./";
		updateList();
	}
Exemplo n.º 25
0
	void SquareNewInfo::DrawEdit()
	{
		if(EditorUtils::activeEditBtn == EditorUtils::SquareNewInfo)
		{
			IRect rect = IRect(10, 100, 50 , 20);
			Render::device.SetTexturing(false);
			Render::BeginColor(Color(50, 50, 50, 255));
			Render::DrawRect(rect);
			Render::EndColor();
			Render::device.SetTexturing(true);

			Render::FreeType::BindFont("debug");
			std::string string_info = _type + " current:" + _PORTAL_IDS[_current_portal];
			Render::PrintString( rect.x + rect.width/2, rect.y + rect.height/2, string_info, 1.f, CenterAlign, CenterAlign); 
		}
		if(texture_NoChain)
		{
			//Отрисовка мест без цепочек
			for(std::map<Game::FieldAddress, InfoSquare>::iterator i = _info.begin(); i != _info.end(); i++)
			{
				if(i->second.isNoChainOnStart)
				{
					FPoint pos = i->first.ToPoint()*GameSettings::SQUARE_SIDE;
					texture_NoChain->Draw(pos);
				}
			}
		}
		for(std::map<Game::FieldAddress, InfoSquare>::iterator i = _info.begin(); i != _info.end();i++)
		{
			// помечаем клетку-иcточник энергии
			if(i->second.en_source > 0)
			{
				Render::BindFont("debug");
				FPoint pos = GameSettings::CellCenter(i->first.ToPoint());
				Render::PrintString(pos, "e(" + utils::lexical_cast(i->second.en_source) + ")", 1.f, CenterAlign, BaseLineAlign);
			}
			if(i->second.treasure > 0)
			{
				Render::BindFont("Score");
				FPoint pos = GameSettings::CellCenter(i->first.ToPoint());
				Render::PrintString(pos, utils::lexical_cast(i->second.treasure), 1.f, CenterAlign, CenterAlign);
			}
			if(i->second.kill_diamonds)
			{
				Render::BindFont("debug");
				FPoint pos = GameSettings::CellCenter(i->first.ToPoint()) - FPoint(0.0f, GameSettings::SQUARE_SIDEF * 0.25f);
				Render::BeginColor(Color::RED);
				Render::PrintString(pos, "D", 1.2f, CenterAlign, CenterAlign);
				Render::EndColor();
			}
		}
	}
Exemplo n.º 26
0
	void GroupEditor::updateSelector() {
		PTileListModel model =
			m_mode == mAddRemove? allTilesModel() :
				m_tile_group? make_shared<TileGroupModel>(*m_tile_group) : nullptr;

		m_current_entry = nullptr;
		m_tile_list.setModel(filteredTilesModel(model, m_tile_filter));

		int2 pos(0, -m_offset[m_mode].y);
		int2 size(rect().width(), m_tile_list.m_height + (m_mode == mAddRemove? 0 : rect().height() / 2));

		setInnerRect(IRect(pos, pos + size));
	}
Exemplo n.º 27
0
	void Window::drawWindow(Renderer2D &out, IRect rect, FColor color, int outline) {
		FColor lighter(color.rgb() * 1.2f, color.a);
		FColor darker(color.rgb() * 0.8f, color.a);
		int aoutline = fwk::abs(outline);

		if(outline) {
			int2 hsize(rect.width(), aoutline);
			int2 vsize(aoutline, rect.height());

			FColor col1 = outline < 0? darker : lighter;
			out.addFilledRect(IRect(rect.min, rect.min + hsize), col1);
			out.addFilledRect(IRect(rect.min, rect.min + vsize), col1);

			int2 p1(rect.min.x, rect.max.y - aoutline);
			int2 p2(rect.max.x - aoutline, rect.min.y);
			FColor col2 = outline < 0? lighter : darker;
			out.addFilledRect(IRect(p1, p1 + hsize), col2);
			out.addFilledRect(IRect(p2, p2 + vsize), col2);
		}

		int2 off(aoutline, aoutline);
		out.addFilledRect(inset(rect, off, off), color);
	}
Exemplo n.º 28
0
	int UIListBox::AddItem(std::wstring const & strText)
	{
		std::shared_ptr<UIListBoxItem> pNewItem = MakeSharedPtr<UIListBoxItem>();
		pNewItem->strText = strText;
		pNewItem->rcActive = IRect(0, 0, 0, 0);
		pNewItem->bSelected = false;

		int ret = static_cast<int>(items_.size());

		items_.push_back(pNewItem);
		scroll_bar_.SetTrackRange(0, items_.size());

		return ret;
	}
Exemplo n.º 29
0
	void UIScrollBar::UpdateRects()
	{
		UIControl::UpdateRects();

		// Make the buttons square

		up_button_rc_ = IRect(bounding_box_.left(), bounding_box_.top(),
			bounding_box_.right(), bounding_box_.top() + bounding_box_.Width());
		down_button_rc_ = IRect(bounding_box_.left(), bounding_box_.bottom() - bounding_box_.Width(),
			bounding_box_.right(), bounding_box_.bottom());
		track_rc_ = IRect(up_button_rc_.left(), up_button_rc_.bottom(),
			down_button_rc_.right(), down_button_rc_.top());
		thumb_rc_.left() = up_button_rc_.left();
		thumb_rc_.right() = up_button_rc_.right();

		this->UpdateThumbRect();

		bounding_box_ = up_button_rc_ | down_button_rc_ | track_rc_;
		if (end_ - start_ > page_size_)
		{
			bounding_box_ |= thumb_rc_;
		}
	}
Exemplo n.º 30
0
	void UISlider::UpdateRects()
	{
		UIControl::UpdateRects();

		slider_rc_ = IRect(x_, y_, x_ + width_, y_ + height_);

		button_rc_ = slider_rc_;
		button_rc_.right() = button_rc_.left() + button_rc_.Height();
		button_rc_ += int2(-button_rc_.Width() / 2, 0);

		button_x_ = static_cast<int>((value_ - min_) * static_cast<float>(slider_rc_.Width()) / (max_ - min_));
		button_rc_ += int2(button_x_, 0);

		bounding_box_ = button_rc_ | slider_rc_;
	}