Пример #1
0
void UIText(int font, const LayoutManager &layout, const char *text, uint32_t color, float scale, int align)
{
	ui_draw2d.SetFontScale(scale, scale);
	float w, h;
	ui_draw2d.MeasureText(font, text, &w, &h);
	float x, y;
	layout.GetPos(&w, &h, &x, &y);
	UIText(font, x, y, text, color, scale, 0);
	ui_draw2d.SetFontScale(1.0f, 1.0f);
}
Пример #2
0
int UICheckBox(int id, int x, int y, const char *text, int align, bool *value) {
#ifdef _WIN32
	const int h = 32;
#else
	const int h = 48;
#endif
	float tw, th;
	ui_draw2d.MeasureText(theme.uiFont, text, &tw, &th);
	int w = themeAtlas->images[theme.checkOn].w + UI_SPACE + tw;
	if (align & ALIGN_HCENTER) x -= w / 2;
	if (align & ALIGN_VCENTER) y -= h / 2;
	if (align & ALIGN_RIGHT) x -= w;
	if (align & ALIGN_BOTTOMRIGHT) y -= h;

	int txOffset = 0;
	int clicked = 0;
	for (int i = 0; i < MAX_POINTERS; i++) {

		// Check whether the button should be hot
		if (UIRegionHit(i, x, y, w, h, 8)) {
			uistate.hotitem[i] = id;
			if (uistate.activeitem[i] == 0 && uistate.mousedown[i])
				uistate.activeitem[i] = id;
		}

		// Render button

		if (uistate.hotitem[i] == id) {
			if (uistate.activeitem[i] == id) {
				// Button is both 'hot' and 'active'
				txOffset = 2;
			} else {
				// Button is merely 'hot'
			}
		} else {
			// button is not hot, but it may be active
		}
		// If button is hot and active, but mouse button is not
		// down, the user must have clicked the button.
		if (uistate.mousedown[i] == 0 &&
			uistate.hotitem[i] == id &&
			uistate.activeitem[i] == id) {
				*value = !(*value);
				clicked = 1;
		}
	}

	ui_draw2d.DrawImage((*value) ? theme.checkOn : theme.checkOff, x, y+h/2, 1.0f, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER);
	ui_draw2d.DrawTextShadow(theme.uiFont, text, x + themeAtlas->images[theme.checkOn].w + UI_SPACE, y + txOffset + h/2, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER);


	uistate.lastwidget = id;
	return clicked;
}