Example #1
0
	void UIRadioButton::Render()
	{
		UI_Control_State iState = UICS_Normal;

		if (!visible_)
		{
			iState = UICS_Hidden;
		}
		else
		{
			if (!enabled_)
			{
				iState = UICS_Disabled;
			}
			else
			{
				if (pressed_)
				{
					iState = UICS_Pressed;
				}
				else
				{
					if (is_mouse_over_)
					{
						iState = UICS_MouseOver;
					}
					else
					{
						if (has_focus_)
						{
							iState = UICS_Focus;
						}
					}
				}
			}
		}

		UIElementPtr pElement = elements_[0];

		pElement->TextureColor().SetState(iState);
		pElement->FontColor().SetState(iState);

		this->GetDialog()->DrawSprite(*pElement, button_rc_);
		this->GetDialog()->DrawString(text_, *pElement, text_rc_, true);

		if (!checked_)
		{
			iState = UICS_Hidden;
		}

		// Main button
		pElement = elements_[1];

		// Blend current color
		pElement->TextureColor().SetState(iState);
		this->GetDialog()->DrawSprite(*pElement, button_rc_);
	}
Example #2
0
	void UIButton::Render()
	{
		UI_Control_State iState = UICS_Normal;

		if (visible_)
		{
			if (enabled_)
			{
				if (pressed_)
				{
					iState = UICS_Pressed;
				}
				else if (is_mouse_over_)
				{
					iState = UICS_MouseOver;
				}
				else if (has_focus_)
				{
					iState = UICS_Focus;
				}
			}
			else
			{
				iState = UICS_Disabled;
			}
		}
		else
		{
			iState = UICS_Hidden;
		}

		// Background fill layer
		//TODO: remove magic numbers
		UIElementPtr pElement = elements_[0];

		IRect rcWindow = bounding_box_;

		// Blend current color
		pElement->TextureColor().SetState(iState);
		pElement->FontColor().SetState(iState);

		this->GetDialog()->DrawSprite(*pElement, rcWindow);
		this->GetDialog()->DrawString(text_, *pElement, rcWindow);

		// Main button
		pElement = elements_[1];


		// Blend current color
		pElement->TextureColor().SetState(iState);
		pElement->FontColor().SetState(iState);

		this->GetDialog()->DrawSprite(*pElement, rcWindow);
		this->GetDialog()->DrawString(text_, *pElement, rcWindow);
	}
Example #3
0
	void UIComboBox::SetTextColor(Color const & color)
	{
		UIElementPtr pElement = elements_[0];

		if (pElement)
		{
			pElement->FontColor().States[UICS_Normal] = color;
		}

		pElement = elements_[2];

		if (pElement)
		{
			pElement->FontColor().States[UICS_Normal] = color;
		}
	}
Example #4
0
	void UISlider::Render()
	{
		UI_Control_State iState = UICS_Normal;

		if (!visible_)
		{
			iState = UICS_Hidden;
		}
		else
		{
			if (!enabled_)
			{
				iState = UICS_Disabled;
			}
			else
			{
				if (pressed_)
				{
					iState = UICS_Pressed;
				}
				else
				{
					if (is_mouse_over_)
					{
						iState = UICS_MouseOver;
					}
					else
					{
						if (has_focus_)
						{
							iState = UICS_Focus;
						}
					}
				}
			}
		}

		UIElementPtr pElement = elements_[0];

		pElement->TextureColor().SetState(iState);
		this->GetDialog()->DrawSprite(*pElement, slider_rc_);

		pElement = elements_[1];

		pElement->TextureColor().SetState(iState);
		this->GetDialog()->DrawSprite(*pElement, button_rc_);
	}
Example #5
0
	void UIScrollBar::Render()
	{
		// Check if the arrow button has been held for a while.
		// If so, update the thumb position to simulate repeated
		// scroll.
		if (arrow_ != CLEAR)
		{
			double dCurrTime = timer_.current_time();
			if (up_button_rc_.PtInRect(last_mouse_))
			{
				switch (arrow_)
				{
				case CLICKED_UP:
					if (SCROLLBAR_ARROWCLICK_DELAY < dCurrTime - arrow_ts_)
					{
						this->Scroll(-1);
						arrow_ = HELD_UP;
						arrow_ts_ = dCurrTime;
					}
					break;

				case HELD_UP:
					if (SCROLLBAR_ARROWCLICK_REPEAT < dCurrTime - arrow_ts_)
					{
						this->Scroll(-1);
						arrow_ts_ = dCurrTime;
					}
					break;

				default:
					BOOST_ASSERT(false);
					break;
				}
			}
			else
			{
				if (down_button_rc_.PtInRect(last_mouse_))
				{
					switch (arrow_)
					{
					case CLICKED_DOWN:
						if (SCROLLBAR_ARROWCLICK_DELAY < dCurrTime - arrow_ts_)
						{
							this->Scroll(1);
							arrow_ = HELD_DOWN;
							arrow_ts_ = dCurrTime;
						}
						break;

					case HELD_DOWN:
						if (SCROLLBAR_ARROWCLICK_REPEAT < dCurrTime - arrow_ts_)
						{
							this->Scroll(1);
							arrow_ts_ = dCurrTime;
						}
						break;

					default:
						BOOST_ASSERT(false);
						break;
					}
				}
			}
		}

		UI_Control_State iState = UICS_Normal;

		if (visible_)
		{
			if (!enabled_ || !show_thumb_)
			{
				iState = UICS_Disabled;
			}
			else
			{
				if (is_mouse_over_)
				{
					iState = UICS_MouseOver;
				}
				else if (has_focus_)
				{
					iState = UICS_Focus;
				}
			}
		}
		else
		{
			iState = UICS_Hidden;
		}


		// Background track layer
		UIElementPtr pElement = elements_[0];

		// Blend current color
		pElement->TextureColor().SetState(iState);
		this->GetDialog()->DrawSprite(*pElement, track_rc_);

		// Up Arrow
		pElement = elements_[1];

		// Blend current color
		pElement->TextureColor().SetState(iState);
		this->GetDialog()->DrawSprite(*pElement, up_button_rc_);

		// Down Arrow
		pElement = elements_[2];

		// Blend current color
		pElement->TextureColor().SetState(iState);
		this->GetDialog()->DrawSprite(*pElement, down_button_rc_);

		// Thumb button
		pElement = elements_[3];

		// Blend current color
		pElement->TextureColor().SetState(iState);
		this->GetDialog()->DrawSprite(*pElement, thumb_rc_);
	}
Example #6
0
	void UIEditBox::Render()
	{
		UIElementPtr pElement = this->GetElement(0);
		if (pElement)
		{
			buffer_.SetFont(this->GetDialog()->GetFont(pElement->FontIndex()), this->GetDialog()->GetFontSize(pElement->FontIndex()));
			this->PlaceCaret(caret_pos_);  // Call PlaceCaret now that we have the font info (node),
			// so that scrolling can be handled.
		}

		// Render the control graphics
		for (int i = 0; i < 9; ++ i)
		{
			pElement = elements_[i];
			if (this->GetEnabled())
			{
				pElement->TextureColor().SetState(UICS_Normal);
			}
			else
			{
				pElement->TextureColor().SetState(UICS_Disabled);
			}

			this->GetDialog()->DrawSprite(*pElement, render_rc_[i]);
		}

		//
		// Compute the X coordinates of the first visible character.
		//
		int nXFirst = buffer_.CPtoX(first_visible_, false);

		//
		// Compute the X coordinates of the selection rectangle
		//
		int nSelStartX = 0;  // Left and right X cordinates of the selection region
		int nCaretX = buffer_.CPtoX(caret_pos_, false);
		if (caret_pos_ != sel_start_)
		{
			nSelStartX = buffer_.CPtoX(sel_start_, false);
		}
		else
		{
			nSelStartX = nCaretX;
		}

		//
		// Render the selection rectangle
		//
		IRect rcSelection;  // Make this available for rendering selected text
		if (caret_pos_ != sel_start_)
		{
			int nSelLeftX = nCaretX, nSelRightX = nSelStartX;
			// Swap if left is bigger than right
			if (nSelLeftX > nSelRightX)
			{
				std::swap(nSelLeftX, nSelRightX);
			}

			rcSelection = IRect(nSelLeftX, text_rc_.top(), nSelRightX, text_rc_.bottom());
			rcSelection += int2(text_rc_.left() - nXFirst, 0);
			rcSelection &= text_rc_;

			this->GetDialog()->DrawRect(rcSelection, -0.005f, sel_bk_color_);
		}

		//
		// Render the text
		//
		// Element 0 for text
		elements_[0]->FontColor().Current = text_color_;
		this->GetDialog()->DrawString(buffer_.GetBuffer().substr(first_visible_), *elements_[0], text_rc_);

		// Render the selected text
		if (caret_pos_ != sel_start_)
		{
			int nFirstToRender = std::max(first_visible_, std::min(sel_start_, caret_pos_));
			int nNumChatToRender = std::max(sel_start_, caret_pos_) - nFirstToRender;
			elements_[0]->FontColor().Current = sel_text_color_;
			this->GetDialog()->DrawString(buffer_.GetBuffer().substr(nFirstToRender, nNumChatToRender),
				*elements_[0], rcSelection);
		}

		//
		// Blink the caret
		//
		if (timer_.current_time() - last_blink_time_ >= blink_time_)
		{
			caret_on_ = !caret_on_;
			last_blink_time_ = timer_.current_time();
		}

		//
		// Render the caret if this control has the focus
		//
		if (has_focus_ && caret_on_ && !hide_caret_)
		{
			// Start the rectangle with insert mode caret
			IRect rcCaret(text_rc_.left() - nXFirst + nCaretX - 1, text_rc_.top(),
				text_rc_.left() - nXFirst + nCaretX + 1, text_rc_.bottom());

			// If we are in overwrite mode, adjust the caret rectangle
			// to fill the entire character.
			if (!insert_mode_)
			{
				// Obtain the right edge X coord of the current character
				int nRightEdgeX = buffer_.CPtoX(caret_pos_, true);
				rcCaret.right() = text_rc_.left() - nXFirst + nRightEdgeX;
			}

			this->GetDialog()->DrawRect(rcCaret, -0.1f, caret_color_);
		}
	}
Example #7
0
	void UIListBox::Render()
	{
		UIElementPtr pElement = elements_[0];
		UIElementPtr pSelElement = elements_[1];
		if (this->GetEnabled())
		{
			pElement->TextureColor().SetState(UICS_Normal);
			pElement->FontColor().SetState(UICS_Normal);
			pSelElement->TextureColor().SetState(UICS_Normal);
			pSelElement->FontColor().SetState(UICS_Normal);
		}
		else
		{
			pElement->TextureColor().SetState(UICS_Disabled);
			pElement->FontColor().SetState(UICS_Disabled);
			pSelElement->TextureColor().SetState(UICS_Disabled);
			pSelElement->FontColor().SetState(UICS_Disabled);
		}

		this->GetDialog()->DrawSprite(*pElement,
			IRect(x_, y_, x_ + width_, y_ + height_));

		// Render the text
		if (!items_.empty())
		{
			// Find out the height of a single line of text
			IRect rc = text_rc_;
			IRect rcSel = selection_rc_;
			rc.bottom() = static_cast<int32_t>(rc.top() + UIManager::Instance().GetFontSize(pElement->FontIndex()));

			// Update the line height formation
			text_height_ = rc.Height();

			static bool bSBInit;
			if (!bSBInit)
			{
				// Update the page size of the scroll bar
				if (text_height_)
				{
					scroll_bar_.SetPageSize(text_rc_.Height() / text_height_);
				}
				else
				{
					scroll_bar_.SetPageSize(text_rc_.Height());
				}
				bSBInit = true;
			}

			rc.right() = text_rc_.right();
			for (int i = static_cast<int>(scroll_bar_.GetTrackPos()); i < static_cast<int>(items_.size()); ++ i)
			{
				if (rc.bottom() > text_rc_.bottom())
				{
					break;
				}

				std::shared_ptr<UIListBoxItem> const & pItem = items_[i];

				// Determine if we need to render this item with the
				// selected element.
				bool bSelectedStyle = false;

				if (!(MULTI_SELECTION == style_) && (i == selected_))
				{
					bSelectedStyle = true;
				}
				else
				{
					if (MULTI_SELECTION == style_)
					{
						if (drag_
							&& (((i >= selected_) && (i < sel_start_))
								|| ((i <= selected_) && (i > sel_start_))))
						{
							bSelectedStyle = items_[sel_start_]->bSelected;
						}
						else
						{
							if (pItem->bSelected)
							{
								bSelectedStyle = true;
							}
						}
					}
				}

				if (bSelectedStyle)
				{
					rcSel.top() = rc.top();
					rcSel.bottom() = rc.bottom();
					this->GetDialog()->DrawSprite(*pSelElement, rcSel);
					this->GetDialog()->DrawString(pItem->strText, *pSelElement, rc);
				}
				else
				{
					this->GetDialog()->DrawString(pItem->strText, *pElement, rc);
				}

				rc += int2(0, text_height_);
			}
		}

		// Render the scroll bar
		scroll_bar_.Render();
	}
Example #8
0
	void UIComboBox::Render()
	{
		UI_Control_State iState = UICS_Normal;

		if (!opened_)
		{
			iState = UICS_Hidden;
		}

		// Dropdown box
		UIElementPtr pElement = elements_[2];

		// If we have not initialized the scroll bar page size,
		// do that now.
		static bool bSBInit;
		if (!bSBInit)
		{
			// Update the page size of the scroll bar
			if (UIManager::Instance().GetFontSize(pElement->FontIndex()) != 0)
			{
				scroll_bar_.SetPageSize(static_cast<size_t>(dropdown_text_rc_.Height() / UIManager::Instance().GetFontSize(pElement->FontIndex())));
			}
			else
			{
				scroll_bar_.SetPageSize(dropdown_text_rc_.Height());
			}
			bSBInit = true;
		}

		// Scroll bar
		if (opened_)
		{
			scroll_bar_.Render();
		}

		// Blend current color
		pElement->TextureColor().SetState(iState);
		pElement->FontColor().SetState(iState);

		float depth_bias = 0.0f;
		if (opened_)
		{
			depth_bias = -0.1f;
		}

		this->GetDialog()->DrawSprite(*pElement, dropdown_rc_, depth_bias);

		// Selection outline
		UIElementPtr pSelectionElement = elements_[3];
		pSelectionElement->TextureColor().Current = pElement->TextureColor().Current;
		pSelectionElement->FontColor().Current = pSelectionElement->FontColor().States[UICS_Normal];

		FontPtr const & font = this->GetDialog()->GetFont(pElement->FontIndex());
		uint32_t font_size = static_cast<uint32_t>(this->GetDialog()->GetFontSize(pElement->FontIndex()) + 0.5f);
		if (font)
		{
			int curY = dropdown_text_rc_.top();
			int nRemainingHeight = dropdown_text_rc_.Height();

			for (size_t i = scroll_bar_.GetTrackPos(); i < items_.size(); ++ i)
			{
				std::shared_ptr<UIComboBoxItem> const & pItem = items_[i];

				// Make sure there's room left in the dropdown
				nRemainingHeight -= font_size;
				if (nRemainingHeight < 0)
				{
					pItem->bVisible = false;
					continue;
				}

				pItem->rcActive = IRect(dropdown_text_rc_.left(), curY, dropdown_text_rc_.right(), curY + font_size);
				curY += font_size;

				//debug
				//int blue = 50 * i;
				//m_pDialog->DrawRect(&pItem->rcActive, 0xFFFF0000 | blue);

				pItem->bVisible = true;

				if (opened_)
				{
					if (static_cast<int>(i) == focused_)
					{
						IRect rc(dropdown_rc_.left(), pItem->rcActive.top() - 2, dropdown_rc_.right(), pItem->rcActive.bottom() + 2);
						this->GetDialog()->DrawSprite(*pSelectionElement, rc, depth_bias);
						this->GetDialog()->DrawString(pItem->strText, *pSelectionElement, pItem->rcActive, false, depth_bias);
					}
					else
					{
						this->GetDialog()->DrawString(pItem->strText, *pElement, pItem->rcActive, false, depth_bias);
					}
				}
			}
		}

		iState = UICS_Normal;

		if (visible_)
		{
			if (enabled_)
			{
				if (pressed_)
				{
					iState = UICS_Pressed;
				}
				else if (is_mouse_over_)
				{
					iState = UICS_MouseOver;
				}
				else if (has_focus_)
				{
					iState = UICS_Focus;
				}
			}
			else
			{
				iState = UICS_Disabled;
			}
		}
		else
		{
			iState = UICS_Hidden;
		}

		// Button
		pElement = elements_[1];

		// Blend current color
		pElement->TextureColor().SetState(iState);

		IRect rcWindow = button_rc_;
		this->GetDialog()->DrawSprite(*pElement, rcWindow, depth_bias);

		if (opened_)
		{
			iState = UICS_Pressed;
		}

		// Main text box
		pElement = elements_[0];

		// Blend current color
		pElement->TextureColor().SetState(iState);
		pElement->FontColor().SetState(iState);

		this->GetDialog()->DrawSprite(*pElement, text_rc_, depth_bias);

		if ((selected_ >= 0) && (selected_ < static_cast<int>(items_.size())))
		{
			std::shared_ptr<UIComboBoxItem> const & pItem = items_[selected_];
			if (pItem)
			{
				this->GetDialog()->DrawString(pItem->strText, *pElement, text_rc_, false, depth_bias);
			}
		}
	}