// 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(SceneItem *item) : texture(nullptr), UIComponent(item) { } 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::getRenderPasses() { glm::mat4 view, proj; auto canvas = this->getCanvas(); assertNotNull(canvas); canvas->getProjectionAndView(&proj, &view); struct ShaderPassItem item; auto shader = getGame()->renderManager.uiShader; item.shader = shader; item.colorValues[shader->paramColor] = this->color; item.matrixValues[shader->paramProjection] = proj; item.matrixValues[shader->paramView] = view; item.matrixValues[shader->paramModel] = this->transform->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->transform->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); QuadMesh::initQuadMesh(&mesh, glm::vec2(0, 0), glm::vec2(0, 1), glm::vec2(width, height), glm::vec2(1, 0), 0.0f ); }