engine: sync editor rendering and ui changes
This commit is contained in:
@@ -12,12 +12,57 @@ D2D1_RECT_F ToD2DRect(const ::XCEngine::UI::UIRect& rect) {
|
||||
return D2D1::RectF(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
|
||||
}
|
||||
|
||||
D2D1_COLOR_F ToD2DColorValue(const ::XCEngine::UI::UIColor& color) {
|
||||
return D2D1::ColorF(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
std::string HrToString(const char* operation, HRESULT hr) {
|
||||
char buffer[128] = {};
|
||||
sprintf_s(buffer, "%s failed with hr=0x%08X.", operation, static_cast<unsigned int>(hr));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void FillLinearGradientRect(
|
||||
ID2D1RenderTarget& renderTarget,
|
||||
const ::XCEngine::UI::UIDrawCommand& command) {
|
||||
const D2D1_RECT_F rect = ToD2DRect(command.rect);
|
||||
const D2D1_GRADIENT_STOP stops[2] = {
|
||||
D2D1::GradientStop(0.0f, ToD2DColorValue(command.color)),
|
||||
D2D1::GradientStop(1.0f, ToD2DColorValue(command.secondaryColor))
|
||||
};
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1GradientStopCollection> stopCollection;
|
||||
if (FAILED(renderTarget.CreateGradientStopCollection(
|
||||
stops,
|
||||
2u,
|
||||
stopCollection.ReleaseAndGetAddressOf()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const D2D1_POINT_2F startPoint = D2D1::Point2F(rect.left, rect.top);
|
||||
const D2D1_POINT_2F endPoint =
|
||||
command.gradientDirection == ::XCEngine::UI::UILinearGradientDirection::Vertical
|
||||
? D2D1::Point2F(rect.left, rect.bottom)
|
||||
: D2D1::Point2F(rect.right, rect.top);
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1LinearGradientBrush> gradientBrush;
|
||||
if (FAILED(renderTarget.CreateLinearGradientBrush(
|
||||
D2D1::LinearGradientBrushProperties(startPoint, endPoint),
|
||||
stopCollection.Get(),
|
||||
gradientBrush.ReleaseAndGetAddressOf()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.rounding > 0.0f) {
|
||||
renderTarget.FillRoundedRectangle(
|
||||
D2D1::RoundedRect(rect, command.rounding, command.rounding),
|
||||
gradientBrush.Get());
|
||||
return;
|
||||
}
|
||||
|
||||
renderTarget.FillRectangle(rect, gradientBrush.Get());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool NativeRenderer::Initialize(HWND hwnd) {
|
||||
@@ -345,6 +390,9 @@ void NativeRenderer::RenderCommand(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ::XCEngine::UI::UIDrawCommandType::FilledRectLinearGradient:
|
||||
FillLinearGradientRect(renderTarget, command);
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::RectOutline: {
|
||||
const D2D1_RECT_F rect = ToD2DRect(command.rect);
|
||||
const float thickness = command.thickness > 0.0f ? command.thickness : 1.0f;
|
||||
@@ -358,6 +406,34 @@ void NativeRenderer::RenderCommand(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ::XCEngine::UI::UIDrawCommandType::Line:
|
||||
renderTarget.DrawLine(
|
||||
D2D1::Point2F(command.position.x, command.position.y),
|
||||
D2D1::Point2F(command.uvMin.x, command.uvMin.y),
|
||||
&solidBrush,
|
||||
command.thickness > 0.0f ? command.thickness : 1.0f);
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::FilledCircle:
|
||||
if (command.radius > 0.0f) {
|
||||
renderTarget.FillEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(command.position.x, command.position.y),
|
||||
command.radius,
|
||||
command.radius),
|
||||
&solidBrush);
|
||||
}
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::CircleOutline:
|
||||
if (command.radius > 0.0f) {
|
||||
renderTarget.DrawEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(command.position.x, command.position.y),
|
||||
command.radius,
|
||||
command.radius),
|
||||
&solidBrush,
|
||||
command.thickness > 0.0f ? command.thickness : 1.0f);
|
||||
}
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::Text: {
|
||||
if (command.text.empty()) {
|
||||
break;
|
||||
@@ -452,7 +528,7 @@ IDWriteTextFormat* NativeRenderer::GetTextFormat(float fontSize) {
|
||||
}
|
||||
|
||||
D2D1_COLOR_F NativeRenderer::ToD2DColor(const ::XCEngine::UI::UIColor& color) {
|
||||
return D2D1::ColorF(color.r, color.g, color.b, color.a);
|
||||
return ToD2DColorValue(color);
|
||||
}
|
||||
|
||||
std::wstring NativeRenderer::Utf8ToWide(std::string_view text) {
|
||||
|
||||
Reference in New Issue
Block a user