Introduce Widget and Screen classes

This commit is contained in:
2021-01-10 00:32:11 +01:00
parent 6ecf2011bc
commit d173eb0913
14 changed files with 153 additions and 42 deletions

46
src/Widget.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include "Widget.h"
#include "VertexArray.h"
Widget::Widget(Texture *texture, float x, float y, float w, float h) :
x(x), y(y), w(w), h(h)
{
widgetTextures.push_back(texture);
const double ofst = 0.005;
double widgetVerticesData[12] = {
x + w + ofst, -1.0f + 2*y - ofst, 0.0f, // Bottom right
-1.0f + 2*x - ofst, y + h + ofst, 0.0f, // Top left
-1.0f + 2*x-ofst, -1.0f + 2*y - ofst, 0.0f, // Bottom left
x + w + ofst, y + h + ofst, 0.0f // Top right
};
unsigned int widgetIndicesData[6] = {
0, 1, 2,
0, 3, 1
};
float widgetTextureCoordinates[8] = {
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 1.0f
};
widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates);
widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6);
widgetMesh = new Mesh(widgetVertices, widgetIndices, widgetTextures);
}
Widget::~Widget()
{
delete widgetMesh;
}
void Widget::draw(ShaderProgram *shaderProgram)
{
shaderProgram->bind();
widgetMesh->draw(shaderProgram);
shaderProgram->unbind();
}