66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
|
|
#include <XCEngine/UI/DrawData.h>
|
|
|
|
#include <d2d1.h>
|
|
#include <dwrite.h>
|
|
#include <wincodec.h>
|
|
#include <windows.h>
|
|
#include <wrl/client.h>
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace XCEngine::UI::Editor::Host {
|
|
|
|
class NativeRenderer {
|
|
public:
|
|
bool Initialize(HWND hwnd);
|
|
void Shutdown();
|
|
void Resize(UINT width, UINT height);
|
|
bool Render(const ::XCEngine::UI::UIDrawData& drawData);
|
|
bool CaptureToPng(
|
|
const ::XCEngine::UI::UIDrawData& drawData,
|
|
UINT width,
|
|
UINT height,
|
|
const std::filesystem::path& outputPath,
|
|
std::string& outError);
|
|
|
|
private:
|
|
bool EnsureRenderTarget();
|
|
bool EnsureWicFactory(std::string& outError);
|
|
void DiscardRenderTarget();
|
|
bool CreateDeviceResources();
|
|
bool RenderToTarget(
|
|
ID2D1RenderTarget& renderTarget,
|
|
ID2D1SolidColorBrush& solidBrush,
|
|
const ::XCEngine::UI::UIDrawData& drawData);
|
|
void RenderCommand(
|
|
ID2D1RenderTarget& renderTarget,
|
|
ID2D1SolidColorBrush& solidBrush,
|
|
const ::XCEngine::UI::UIDrawCommand& command,
|
|
std::vector<D2D1_RECT_F>& clipStack);
|
|
|
|
IDWriteTextFormat* GetTextFormat(float fontSize);
|
|
static D2D1_COLOR_F ToD2DColor(const ::XCEngine::UI::UIColor& color);
|
|
static std::wstring Utf8ToWide(std::string_view text);
|
|
|
|
HWND m_hwnd = nullptr;
|
|
Microsoft::WRL::ComPtr<ID2D1Factory> m_d2dFactory;
|
|
Microsoft::WRL::ComPtr<IDWriteFactory> m_dwriteFactory;
|
|
Microsoft::WRL::ComPtr<IWICImagingFactory> m_wicFactory;
|
|
Microsoft::WRL::ComPtr<ID2D1HwndRenderTarget> m_renderTarget;
|
|
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_solidBrush;
|
|
std::unordered_map<int, Microsoft::WRL::ComPtr<IDWriteTextFormat>> m_textFormats;
|
|
bool m_wicComInitialized = false;
|
|
};
|
|
|
|
} // namespace XCEngine::UI::Editor::Host
|