コード例 #1
0
bool ButtonControl::Render(const Canvas& canvas, GuiGeometryBuilder* builder, const Rect& rect, const playstate::string& text)
{
	// Status used 
	GuiMouseState::Enum state = canvas.GetMouseState(rect);

	const Color& buttonColorTop = mButtonColors[2 * (uint32)state];
	const Color& buttonColorBotton = mButtonColors[2 * (uint32)state + 1];
	const Color& fontColor = mFontColors[(uint32)state];

	// Add body
	builder->AddGradientQuad(rect, buttonColorTop, buttonColorBotton);

	if(mFont.IsNotNull() && !text.empty()) {
		builder->AddText(mFont.Get(), rect, fontColor, text, FontAlign::CENTER);
	}

	if(state == GuiMouseState::HOVER && canvas.GetMouseClick() == MouseButtons::LEFT) {
		return true;
	}
	return false;
}
コード例 #2
0
bool CheckboxControl::Render(const Canvas& canvas, GuiGeometryBuilder* builder, const Rect& rect, bool toggled, const playstate::string& text)
{
	// Status used 
	GuiMouseState::Enum state = canvas.GetMouseState(rect);

	const uint32 checkboxBorderOffset = 1U;
	const uint32 checkboxToggleOffset = checkboxBorderOffset + 3U;
	
	// Add border around checkbox button
	const Rect checkboxButtonBorder(rect.Position, Size(mCheckboxSize, mCheckboxSize));
	builder->AddQuad(checkboxButtonBorder, Color::Black);

	// Add checkbox button
	const Color& boxColorTop = mCheckboxColors[2 * (uint32)state];
	const Color& boxColorBottom = mCheckboxColors[2 * (uint32)state + 1];
	const Rect checkboxButton(rect.Position + Point(checkboxBorderOffset, checkboxBorderOffset), 
		Size(mCheckboxSize - (checkboxBorderOffset * 2), mCheckboxSize - (checkboxBorderOffset * 2)));
	builder->AddGradientQuad(checkboxButton, boxColorTop, boxColorBottom);

	// Add geometry if checkbox is toggled (enabled)
	if(toggled) {
		const Rect toggledCoords(rect.Position + Point(checkboxToggleOffset, checkboxToggleOffset), 
			Size(mCheckboxSize - (checkboxToggleOffset * 2), mCheckboxSize - (checkboxToggleOffset * 2)));
		builder->AddQuad(toggledCoords, Color::White);
	}

	// Add checkbox text if one is present.
	if(text.length() > 0 && !mFont.IsNull()) {
		const Color& fontColor = mFontColors[toggled ? 1 : 0];
		builder->AddText(mFont.Get(), rect + Rect(mCheckboxSize + 10, 0, 0, 0), fontColor, text, FontAlign::LEFT);
	}

	if(state == GuiMouseState::HOVER && canvas.GetMouseClick() == MouseButtons::LEFT) {
		toggled = !toggled;
	}

	return toggled;
}