Introduce Widget and Screen classes
This commit is contained in:
46
src/Widget.cpp
Normal file
46
src/Widget.cpp
Normal 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user