// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "UIImage.hpp" #include "game/DawnGame.hpp" using namespace Dawn; UIImage::UIImage(std::weak_ptr item) : texture(nullptr), UIComponentRenderable(item), uvs(glm::vec4(0, 1, 1, 0)) { } float_t UIImage::getContentWidth() { if(this->texture != nullptr) return this->texture->getWidth(); return this->width; } float_t UIImage::getContentHeight() { if(this->texture != nullptr) return this->texture->getHeight(); return this->height; } std::vector UIImage::getUIRenderPasses() { struct ShaderPassItem item; auto shader = getGame()->renderManager->uiShader; item.shader = shader; item.colorValues[shader->paramColor] = this->color; item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer; item.matrixValues[shader->paramModel] = this->item.lock()->getWorldTransform(); if(this->texture == nullptr) { item.boolValues[shader->paramHasTexture] = false; } else { item.boolValues[shader->paramHasTexture] = true; item.textureSlots[0] = this->texture; item.textureValues[shader->paramTexture] = 0; } item.w = this->item.lock()->getWorldPosition().z; item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; item.mesh = &mesh; return { item }; } void UIImage::onStart() { UIComponent::onStart(); useEvent([&]{ QuadMesh::bufferPositions(mesh, glm::vec2(0, 0), glm::vec2(width, height), 0 ); }, this->eventAlignmentUpdated); useEffect([&]{ QuadMesh::bufferCoordinates(mesh, glm::vec2(this->uvs._realValue[0], this->uvs._realValue[1]), glm::vec2(this->uvs._realValue[2], this->uvs._realValue[3]), 0 ); }, this->uvs); QuadMesh::initQuadMesh(mesh, glm::vec2(0, 0), glm::vec2(this->uvs._realValue[0], this->uvs._realValue[1]), glm::vec2(width, height), glm::vec2(this->uvs._realValue[2], this->uvs._realValue[3]), 0.0f ); }