void DropDownList::draw(Renderer *renderer, const FontID defaultFont, const SamplerStateID linearClamp, const BlendStateID blendSrcAlpha, const DepthStateID depthState){
	vec4 col = enabled? color : vec4(color.xyz() * 0.5f, 1);
	vec4 black(0, 0, 0, 1);

	vec2 quad[] = { MAKEQUAD(xPos, yPos, xPos + width, yPos + height, 2) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, quad, elementsOf(quad), blendSrcAlpha, depthState, &col);

	vec2 rect[] = { MAKERECT(xPos, yPos, xPos + width, yPos + height, 2) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, rect, elementsOf(rect), BS_NONE, depthState, &black);

	vec2 line0[] = { MAKEQUAD(xPos + width - height, yPos + 2, xPos + width - height + 2, yPos + height - 2, 0) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, line0, elementsOf(line0), BS_NONE, depthState, &black);
	vec2 line1[] = { MAKEQUAD(xPos + width - height + 1, yPos + 0.5f * height - 1, xPos + width - 2, yPos + 0.5f * height + 1, 0) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, line1, elementsOf(line1), BS_NONE, depthState, &black);

	vec2 triangles[] = {
		vec2(xPos + width - 0.5f * height, yPos + 0.1f * height),
		vec2(xPos + width - 0.2f * height, yPos + 0.4f * height),
		vec2(xPos + width - 0.8f * height, yPos + 0.4f * height),
		vec2(xPos + width - 0.5f * height, yPos + 0.9f * height),
		vec2(xPos + width - 0.8f * height, yPos + 0.6f * height),
		vec2(xPos + width - 0.2f * height, yPos + 0.6f * height),
	};
	renderer->drawPlain(PRIM_TRIANGLES, triangles, elementsOf(triangles), BS_NONE, depthState, &black);

	float textWidth = 0.75f * height;
	float w = width - 1.3f * height;
	if (selectedItem >= 0){
		float tw = renderer->getTextWidth(defaultFont, items[selectedItem]);
		float maxW = w / tw;
		if (textWidth > maxW) textWidth = maxW;

		renderer->drawText(items[selectedItem], xPos + 0.15f * height, yPos, textWidth, height, defaultFont, linearClamp, blendSrcAlpha, depthState);
	}

	if (isDroppedDown){
		vec2 quad[] = { MAKEQUAD(xPos, yPos - selectedItem * height, xPos + width - height + 2, yPos + (items.getCount() - selectedItem) * height, 2) };
		renderer->drawPlain(PRIM_TRIANGLE_STRIP, quad, elementsOf(quad), blendSrcAlpha, depthState, &col);

		vec2 rect[] = { MAKERECT(xPos, yPos - selectedItem * height, xPos + width - height + 2, yPos + (items.getCount() - selectedItem) * height, 2) };
		renderer->drawPlain(PRIM_TRIANGLE_STRIP, rect, elementsOf(rect), BS_NONE, depthState, &black);

		for (uint i = 0; i < items.getCount(); i++){
			float tw = renderer->getTextWidth(defaultFont, items[i]);
			float maxW = w / tw;
			if (textWidth > maxW) textWidth = maxW;

			renderer->drawText(items[i], xPos + 0.15f * height, yPos + (int(i) - selectedItem) * height, textWidth, height, defaultFont, linearClamp, blendSrcAlpha, depthState);
		}		
	}

}
Esempio n. 2
0
void Dialog::draw(GraphicsDevice *gfxDevice, const FontID defaultFont, const SamplerStateID linearClamp, const BlendStateID blendSrcAlpha, const DepthStateID depthState){
	drawSoftBorderQuad(gfxDevice, linearClamp, blendSrcAlpha, depthState, xPos, yPos, xPos + width, yPos + height, borderWidth, 1, 1);

	vec4 black(0, 0, 0, 1);
	vec4 blue(0.3f, 0.4f, 1.0f, 0.65f);

	float x = xPos + 2 * borderWidth;
	float y = yPos + 2 * borderWidth;
	for (uint i = 0; i < tabs.getCount(); i++){
		float tabWidth = 0.75f * tabHeight;
		float cw = gfxDevice->getTextWidth(defaultFont, tabs[i]->caption);
		float newX = x + tabWidth * cw + 6;

		if (i == currTab){
			vec2 quad[] = { MAKEQUAD(x, y, newX, y + tabHeight, 2) };
			gfxDevice->drawPlain(PRIM_TRIANGLE_STRIP, quad, elementsOf(quad), blendSrcAlpha, depthState, &blue);
		}

		vec2 rect[] = { MAKERECT(x, y, newX, y + tabHeight, 2) };
		gfxDevice->drawPlain(PRIM_TRIANGLE_STRIP, rect, elementsOf(rect), BS_NONE, depthState, &black);

		gfxDevice->drawText(tabs[i]->caption, x + 3, y, tabWidth, tabHeight, defaultFont, linearClamp, blendSrcAlpha, depthState);

		tabs[i]->rightX = x = newX;
	}

	vec2 line[] = { MAKEQUAD(xPos + 2 * borderWidth, y + tabHeight - 1, xPos + width - 2 * borderWidth, y + tabHeight + 1, 0) };
	gfxDevice->drawPlain(PRIM_TRIANGLE_STRIP, line, elementsOf(line), BS_NONE, depthState, &black);

	closeButton->draw(gfxDevice, defaultFont, linearClamp, blendSrcAlpha, depthState);

	if (currTab < tabs.getCount()){
		DialogTab *tab = tabs[currTab];

		if (tab->widgets.goToLast()){
			do {
				Widget *widget = tab->widgets.getCurrent().widget;
				if (widget->isVisible()) widget->draw(gfxDevice, defaultFont, linearClamp, blendSrcAlpha, depthState);
			} while (tab->widgets.goToPrev());
		}
		if (showSelection){
			if (tab->widgets.goToFirst()){
				Widget *w = tab->widgets.getCurrent().widget;

				float x = w->getX();
				float y = w->getY();
				vec2 rect[] = { MAKERECT(x - 5, y - 5, x + w->getWidth() + 5, y + w->getHeight() + 5, 1) };
				gfxDevice->drawPlain(PRIM_TRIANGLE_STRIP, rect, elementsOf(rect), BS_NONE, depthState, &black);
			}
		}
	}
}
Esempio n. 3
0
void Slider::draw(Renderer *renderer, const FontID defaultFont, const SamplerStateID linearClamp, const BlendStateID blendSrcAlpha, const DepthStateID depthState){
	vec4 black(0, 0, 0, 1);

	vec2 quad[] = { MAKEQUAD(xPos, yPos, xPos + width, yPos + height, 2) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, quad, elementsOf(quad), blendSrcAlpha, depthState, &color);

	vec2 rect[] = { MAKERECT(xPos, yPos, xPos + width, yPos + height, 2) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, rect, elementsOf(rect), BS_NONE, depthState, &black);

	vec2 line[] = { MAKEQUAD(xPos + 0.5f * height, yPos + 0.5f * height - 1, xPos + width - 0.5f * height, yPos + 0.5f * height + 1, 0) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, line, elementsOf(line), BS_NONE, depthState, &black);

	float x = lerp(xPos + 0.5f * height, xPos + width - 0.5f * height, (value - minValue) / (maxValue - minValue));
	vec2 marker[] = { MAKEQUAD(x - 0.2f * height, yPos + 0.2f * height, x + 0.2f * height, yPos + 0.8f * height, 0) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, marker, elementsOf(marker), BS_NONE, depthState, &black);
}
void CheckBox::draw(Renderer *renderer, const FontID defaultFont, const SamplerStateID linearClamp, const BlendStateID blendSrcAlpha, const DepthStateID depthState){
	if (check == TEXTURE_NONE){
		uint32 checkPic[] = {
			0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xf5ffffff,0x9744619d,0xffffffff,0xffffffff,
			0x25d8ffff,0xce1a0000,0xffffffff,0xffffffff,0x001adeff,0xffd81a00,0xffffffff,0xffffffff,0x00002aef,0xffffd81a,
			0xffffffff,0xfcffffff,0x1000004a,0xffffffd5,0xffffffff,0x7cffffff,0xc9090000,0xffffffff,0xffffffff,0x01b3ffff,
			0xffb30400,0xffffffff,0xf6d6f5ff,0x0011deff,0xffff9300,0xffffffff,0x6b000fa8,0x000035f6,0xffffff67,0xffffffff,
			0x0c00004b,0x39000055,0xfffffff9,0xffffffff,0x00000075,0xe0130000,0xffffffff,0xffffffff,0x000000c9,0xffaf0000,
			0xffffffff,0xffffffff,0x000034ff,0xffff5c00,0xffffffff,0xffffffff,0x4b5bdaff,0xfffff575,0xffffffff,0xffffffff,
			0xffffffff,0xffffffff,0xffffffff,0xffffffff,
		};
		Image img;
		img.loadFromMemory(checkPic, FORMAT_I8, 16, 16, 1, 1, false);
		img.convert(FORMAT_RGBA8); // For DX10
		check = renderer->addTexture(img, false, linearClamp);
	}

	if (checked){
		TexVertex quad[] = { MAKETEXQUAD(xPos, yPos + 0.2f * height, xPos + 0.6f * height, yPos + 0.8f * height, 3) };
		renderer->drawTextured(PRIM_TRIANGLE_STRIP, quad, elementsOf(quad), check, linearClamp, BS_NONE, depthState);
	} else {
		vec2 quad[] = { MAKEQUAD(xPos, yPos + 0.2f * height, xPos + 0.6f * height, yPos + 0.8f * height, 3) };
		renderer->drawPlain(PRIM_TRIANGLE_STRIP, quad, elementsOf(quad), BS_NONE, depthState);
	}

	vec2 rect[] = { MAKERECT(xPos, yPos + 0.2f * height, xPos + 0.6f * height, yPos + 0.8f * height, 3) };
	vec4 black(0, 0, 0, 1);
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, rect, elementsOf(rect), BS_NONE, depthState, &black);


	float textWidth = 0.75f * height;

	float w = width - 0.7f * height;
	float tw = renderer->getTextWidth(defaultFont, text);
	float maxW = w / tw;
	if (textWidth > maxW) textWidth = maxW;

	float x = 0.7f * height;

	renderer->drawText(text, xPos + x, yPos, textWidth, height, defaultFont, linearClamp, blendSrcAlpha, depthState);
}
Esempio n. 5
0
void PushButton::drawButton(Renderer *renderer, const char *text, const FontID defaultFont, const SamplerStateID linearClamp, const BlendStateID blendSrcAlpha, const DepthStateID depthState){
	vec4 black(0, 0, 0, 1);
	vec4 col = color;
	if (pushed) col *= vec4(0.5f, 0.5f, 0.5f, 1);

	vec2 quad[] = { MAKEQUAD(xPos, yPos, xPos + width, yPos + height, 2) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, quad, elementsOf(quad), blendSrcAlpha, depthState, &col);

	vec2 rect[] = { MAKERECT(xPos, yPos, xPos + width, yPos + height, 2) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, rect, elementsOf(rect), BS_NONE, depthState, &black);


	float textWidth = 0.75f * height;

	float tw = renderer->getTextWidth(defaultFont, text);
	float maxW = width / tw;
	if (textWidth > maxW) textWidth = maxW;

	float x = 0.5f * (width - textWidth * tw);

	renderer->drawText(text, xPos + x, yPos, textWidth, height, defaultFont, linearClamp, blendSrcAlpha, depthState);
}