コード例 #1
0
ファイル: UIButton.cpp プロジェクト: BitYorkie/KlayGE
	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);
	}
コード例 #2
0
ファイル: UIComboBox.cpp プロジェクト: BobLChen/KlayGE
	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;
		}
	}
コード例 #3
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_);
	}
コード例 #4
0
ファイル: UIListBox.cpp プロジェクト: BitYorkie/KlayGE
	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();
	}
コード例 #5
0
ファイル: UIComboBox.cpp プロジェクト: BobLChen/KlayGE
	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);
			}
		}
	}