diff --git a/Source/UI/Window/UIWindow.h b/Source/UI/Window/UIWindow.h index b31eb19d3..31f25cd5d 100644 --- a/Source/UI/Window/UIWindow.h +++ b/Source/UI/Window/UIWindow.h @@ -196,6 +196,7 @@ public: int x, int y, int, int, const SpriteRleImage* image, const SpriteFrameCell* cell, float scale, float angle, std::uint32_t color, const std::uint32_t* palette, float extentScale ); + void AddRotatedSpriteCellOverlay(int x, int y, int width, int height, const SpriteRleImage* image, const SpriteFrameCell* cell, const std::uint32_t* palette); int DrawTitleBar(FontCache& fonts, const TextLocale& locale, bool closeButton, const char* title, int width); int DrawTitleBarAt(FontCache& fonts, const TextLocale& locale, int x, int width, bool closeButton, const char* title); void DrawPanelBackground(int y, int width, const char* bitmapName); diff --git a/Source/UI/WindowSprite.cpp b/Source/UI/WindowSprite.cpp index c3b273428..9d5a3411f 100644 --- a/Source/UI/WindowSprite.cpp +++ b/Source/UI/WindowSprite.cpp @@ -100,3 +100,81 @@ void UIWindow::AddSpriteCellOverlay( this->m_overlayPrimitives.push_back(primitive); } + +// OFFSET: 0x00A7A5C0 +// FUNCTION: fn_16923 +void UIWindow::AddRotatedSpriteCellOverlay( + int x, int y, int width, int height, const SpriteRleImage* image, const SpriteFrameCell* cell, const std::uint32_t* palette +) { + if (!width || !height || !image || !cell || !palette) { + return; + } + + for (UIWindow* window = this; window; window = window->parent) { + x += window->geometry.x; + y += window->geometry.y; + } + + RenderPrimitive* primitive = g_renderer->primitives.Acquire(); + SpriteAtlasRecord record{}; + + CTexture* texture = static_cast(const_cast(image->unknown_0008)); + if (!texture) { + texture = g_renderer->atlas.Find(image, palette, record); + if (!texture) { + texture = g_renderer->atlas.Insert(*GetRenderSystemHolder()->system, image, palette, record, g_serviceType, g_resourceReuseDelay); + } + } else { + record.u0 = 0.0f; + record.v0 = 0.0f; + record.u1 = static_cast(texture->ImageWidth()) / static_cast(texture->TextureWidth()); + record.v1 = static_cast(texture->ImageHeight()) / static_cast(texture->TextureHeight()); + } + primitive->texture = texture; + + const int left = static_cast(cell->x * static_cast(cell->scaleX) + 1.0); + const int right = static_cast(((static_cast(image->unknown_0004) + 1) * image->width + cell->x) * static_cast(cell->scaleX)); + const int top = static_cast(cell->y * static_cast(cell->scaleY)); + const int startX = (cell->mirrored & 1) ? right : left; + const int endX = (cell->mirrored & 1) ? left : right; + const float halfWidth = static_cast(endX - startX) * 0.5f; + const int bottom = + static_cast(((static_cast(image->unknown_0006) + 1) * image->height + cell->y) * static_cast(cell->scaleY) + 1.0); + const float halfHeight = static_cast(bottom - top) * 0.5f; + + const float corners[4][2] = { + {-halfWidth, -halfHeight}, + {halfWidth, -halfHeight}, + {-halfWidth, halfHeight}, + {halfWidth, halfHeight}, + }; + const float centerX = static_cast(x + startX) + halfWidth; + const float centerY = static_cast(y + top) + halfHeight; + const float angle = static_cast(cell->unknown_001C) / 180.0f * 3.141592f; + + const unsigned char* rgba = reinterpret_cast(&cell->color); + RenderVertex* vertices = primitive->quad; + for (unsigned int i = 0; i < 4; ++i) { + const float cornerX = corners[i][0]; + const float cornerY = corners[i][1]; + vertices[i].x = ClientCos(angle) * cornerX - ClientSin(angle) * cornerY + centerX + 0.5f; + vertices[i].y = ClientCos(angle) * cornerY + ClientSin(angle) * cornerX + centerY + 0.5f; + vertices[i].z = 0.000001f; + vertices[i].rhw = 0.999999f; + vertices[i].diffuse = (((((rgba[3] << 8) | rgba[0]) << 8) | rgba[1]) << 8) | rgba[2]; + } + vertices[0].u = record.u0; + vertices[0].v = record.v0; + vertices[1].u = record.u1; + vertices[1].v = record.v0; + vertices[2].u = record.u0; + vertices[2].v = record.v1; + vertices[3].u = record.u1; + vertices[3].v = record.v1; + + for (UIWindow* window = this->parent; window; window = window->parent) { + if (!window->parent) { + window->m_overlayPrimitives.push_back(primitive); + } + } +}