// Platform skeleton for EterLib/GrpExpandedImageInstance.h (40250 EterLib/GrpExpandedImageInstance.cpp), generated by platform_stub.py. // Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation. #include "EterLib/StdAfx.h" #include "EterLib/GrpExpandedImageInstance.h" #include "../PlatformStub.h" #include "EterBase/CRC32.h" #include "UIRenderCommands.h" #include auto CGraphicExpandedImageInstance::Type() -> DWORD { static DWORD type = GetCRC32("CGraphicExpandedImageInstance", sizeof("CGraphicExpandedImageInstance") - 1); return type; } CGraphicExpandedImageInstance::CGraphicExpandedImageInstance() { Initialize(); } CGraphicExpandedImageInstance::~CGraphicExpandedImageInstance() { Destroy(); } auto CGraphicExpandedImageInstance::Destroy() -> void { CGraphicImageInstance::Destroy(); Initialize(); } auto CGraphicExpandedImageInstance::SetDepth(float depth) -> void { m_fDepth = depth; } auto CGraphicExpandedImageInstance::SetOrigin() -> void { m_v2Origin = D3DXVECTOR2(GetWidth() * 0.5f, GetHeight() * 0.5f); } auto CGraphicExpandedImageInstance::SetOrigin(float x, float y) -> void { m_v2Origin = D3DXVECTOR2(x, y); } auto CGraphicExpandedImageInstance::SetRotation(float rotation) -> void { m_fRotation = rotation; } auto CGraphicExpandedImageInstance::SetScale(float x, float y) -> void { m_v2Scale = D3DXVECTOR2(x, y); } // In 40250, the arguments are fractions of the image size (uiToolTip gauges, SetPercentage). auto CGraphicExpandedImageInstance::SetRenderingRect(float fLeft, float fTop, float fRight, float fBottom) -> void { if (IsEmpty()) return; float fWidth = float(GetWidth()); float fHeight = float(GetHeight()); m_RenderingRect.left = fWidth * fLeft; m_RenderingRect.top = fHeight * fTop; m_RenderingRect.right = fWidth * fRight; m_RenderingRect.bottom = fHeight * fBottom; } auto CGraphicExpandedImageInstance::SetRenderingMode(int mode) -> void { m_iRenderingMode = mode; } auto CGraphicExpandedImageInstance::Initialize() -> void { m_fDepth = 0; m_v2Origin = D3DXVECTOR2(0, 0); m_v2Scale = D3DXVECTOR2(1, 1); m_fRotation = 0; m_RenderingRect = {0, 0, 0, 0}; m_iRenderingMode = RENDERING_MODE_NORMAL; } // 40250 GrpExpandedImageInstance.cpp:29-142. The vertex and texture-coordinate arithmetic is // verbatim; the D3D stream/blend-state calls become one UIRenderCommand with the four vertices. auto CGraphicExpandedImageInstance::OnRender() -> void { CGraphicImage * pImage = m_roImage.GetPointer(); CGraphicTexture * pTexture = pImage->GetTexturePointer(); if (pTexture->GetWidth() <= 0 || pTexture->GetHeight() <= 0) return; const RECT& c_rRect = pImage->GetRectReference(); float texReverseWidth = 1.0f / float(pTexture->GetWidth()); float texReverseHeight = 1.0f / float(pTexture->GetHeight()); float su = (c_rRect.left - m_RenderingRect.left) * texReverseWidth; float sv = (c_rRect.top - m_RenderingRect.top) * texReverseHeight; float eu = (c_rRect.left + m_RenderingRect.right + (c_rRect.right-c_rRect.left)) * texReverseWidth; float ev = (c_rRect.top + m_RenderingRect.bottom + (c_rRect.bottom-c_rRect.top)) * texReverseHeight; float x[4], y[4]; for (int i = 0; i < 4; ++i) { x[i] = m_v2Position.x-0.5f; y[i] = m_v2Position.y-0.5f; } if (0.0f == m_fRotation) { float fimgWidth = float(pImage->GetWidth()) * m_v2Scale.x; float fimgHeight = float(pImage->GetHeight()) * m_v2Scale.y; x[0] -= m_RenderingRect.left; y[0] -= m_RenderingRect.top; x[1] += fimgWidth + m_RenderingRect.right; y[1] -= m_RenderingRect.top; x[2] -= m_RenderingRect.left; y[2] += fimgHeight + m_RenderingRect.bottom; x[3] += fimgWidth + m_RenderingRect.right; y[3] += fimgHeight + m_RenderingRect.bottom; // PORT: 40250 flips D3DRS_CULLMODE for a mirrored scale; the Godot canvas has no culling. } else { float fimgHalfWidth = float(pImage->GetWidth())/2.0f * m_v2Scale.x; float fimgHalfHeight = float(pImage->GetHeight())/2.0f * m_v2Scale.y; for (int i = 0; i < 4; ++i) { x[i] += m_v2Origin.x; y[i] += m_v2Origin.y; } float fRadian = D3DXToRadian(m_fRotation); x[0] += (-fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian)); y[0] += (-fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian)); x[1] += (+fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian)); y[1] += (+fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian)); x[2] += (-fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian)); y[2] += (-fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian)); x[3] += (+fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian)); y[3] += (+fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian)); } UIRenderAddImage(pTexture, x, y, su, sv, eu, ev, UIRenderColor(m_DiffuseColor), m_iRenderingMode); } auto CGraphicExpandedImageInstance::OnSetImagePointer() -> void { if (!IsEmpty()) SetOrigin(); } auto CGraphicExpandedImageInstance::OnIsType(DWORD type) -> BOOL { return type == Type() || CGraphicImageInstance::OnIsType(type); } auto CGraphicExpandedImageInstance::CreateSystem(UINT) -> void { MT_PLATFORM_STUB(); } auto CGraphicExpandedImageInstance::DestroySystem() -> void { MT_PLATFORM_STUB(); } auto CGraphicExpandedImageInstance::New() -> CGraphicExpandedImageInstance * { return new CGraphicExpandedImageInstance(); } auto CGraphicExpandedImageInstance::Delete(CGraphicExpandedImageInstance *instance) -> void { if (!instance) return; instance->Destroy(); delete instance; } decltype(CGraphicExpandedImageInstance::ms_kPool) CGraphicExpandedImageInstance::ms_kPool{};