minor fixes
This commit is contained in:
parent
47be1dc413
commit
90bfda923d
|
|
@ -65,16 +65,12 @@ namespace kiwano
|
||||||
|
|
||||||
if (in_scene_)
|
if (in_scene_)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(
|
Renderer::GetInstance()->CreateLayer(in_layer_);
|
||||||
Renderer::GetInstance()->CreateLayer(in_layer_)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_scene_)
|
if (out_scene_)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(
|
Renderer::GetInstance()->CreateLayer(out_layer_);
|
||||||
Renderer::GetInstance()->CreateLayer(out_layer_)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window_size_ = Renderer::GetInstance()->GetOutputSize();
|
window_size_ = Renderer::GetInstance()->GetOutputSize();
|
||||||
|
|
|
||||||
|
|
@ -211,115 +211,172 @@ namespace kiwano
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::CreateLayer(ComPtr<ID2D1Layer>& layer)
|
void Renderer::IncreasePrimitivesCount()
|
||||||
{
|
{
|
||||||
if (!device_context_)
|
if (collecting_status_)
|
||||||
return E_UNEXPECTED;
|
{
|
||||||
|
++status_.primitives;
|
||||||
layer = nullptr;
|
}
|
||||||
return device_context_->CreateLayer(&layer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::DrawGeometry(
|
void Renderer::CreateLayer(ComPtr<ID2D1Layer>& layer)
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
ComPtr<ID2D1Layer> new_layer;
|
||||||
|
|
||||||
|
if (!device_context_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
hr = device_context_->CreateLayer(&new_layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
layer = new_layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::DrawGeometry(
|
||||||
ComPtr<ID2D1Geometry> const& geometry,
|
ComPtr<ID2D1Geometry> const& geometry,
|
||||||
Color const& stroke_color,
|
Color const& stroke_color,
|
||||||
float stroke_width,
|
float stroke_width,
|
||||||
StrokeStyle stroke
|
StrokeStyle stroke
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!solid_color_brush_ || !device_context_)
|
if (!solid_color_brush_ || !device_context_)
|
||||||
return E_UNEXPECTED;
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color));
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color));
|
||||||
|
|
||||||
device_context_->DrawGeometry(
|
device_context_->DrawGeometry(
|
||||||
geometry.get(),
|
geometry.get(),
|
||||||
solid_color_brush_.get(),
|
solid_color_brush_.get(),
|
||||||
stroke_width,
|
stroke_width,
|
||||||
d2d_res_->GetStrokeStyle(stroke)
|
d2d_res_->GetStrokeStyle(stroke)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (collecting_status_)
|
IncreasePrimitivesCount();
|
||||||
++status_.primitives;
|
}
|
||||||
return S_OK;
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::FillGeometry(ComPtr<ID2D1Geometry> const & geometry, Color const& fill_color)
|
void Renderer::FillGeometry(ComPtr<ID2D1Geometry> const & geometry, Color const& fill_color)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!solid_color_brush_ || !device_context_)
|
if (!solid_color_brush_ || !device_context_)
|
||||||
return E_UNEXPECTED;
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
|
if (SUCCEEDED(hr))
|
||||||
device_context_->FillGeometry(
|
{
|
||||||
geometry.get(),
|
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
|
||||||
solid_color_brush_.get()
|
device_context_->FillGeometry(
|
||||||
);
|
geometry.get(),
|
||||||
|
solid_color_brush_.get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return S_OK;
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::DrawRectangle(Rect const& rect, const Color& stroke_color, float stroke_width, StrokeStyle stroke)
|
void Renderer::DrawRectangle(Rect const& rect, const Color& stroke_color, float stroke_width, StrokeStyle stroke)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!solid_color_brush_ || !device_context_)
|
if (!solid_color_brush_ || !device_context_)
|
||||||
return E_UNEXPECTED;
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color));
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color));
|
||||||
|
|
||||||
device_context_->DrawRectangle(
|
device_context_->DrawRectangle(
|
||||||
DX::ConvertToRectF(rect),
|
DX::ConvertToRectF(rect),
|
||||||
solid_color_brush_.get(),
|
solid_color_brush_.get(),
|
||||||
stroke_width,
|
stroke_width,
|
||||||
d2d_res_->GetStrokeStyle(stroke)
|
d2d_res_->GetStrokeStyle(stroke)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (collecting_status_)
|
IncreasePrimitivesCount();
|
||||||
++status_.primitives;
|
}
|
||||||
return S_OK;
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::FillRectangle(Rect const& rect, Color const& fill_color)
|
void Renderer::FillRectangle(Rect const& rect, Color const& fill_color)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!solid_color_brush_ || !device_context_)
|
if (!solid_color_brush_ || !device_context_)
|
||||||
return E_UNEXPECTED;
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
|
if (SUCCEEDED(hr))
|
||||||
device_context_->FillRectangle(
|
{
|
||||||
DX::ConvertToRectF(rect),
|
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
|
||||||
solid_color_brush_.get()
|
device_context_->FillRectangle(
|
||||||
);
|
DX::ConvertToRectF(rect),
|
||||||
|
solid_color_brush_.get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return S_OK;
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::DrawBitmap(ComPtr<ID2D1Bitmap> const & bitmap, Rect const& src_rect, Rect const& dest_rect)
|
void Renderer::DrawBitmap(ComPtr<ID2D1Bitmap> const & bitmap, Rect const& src_rect, Rect const& dest_rect)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!device_context_)
|
if (!device_context_)
|
||||||
return E_UNEXPECTED;
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
if (!bitmap)
|
if (SUCCEEDED(hr) && bitmap)
|
||||||
return S_OK;
|
{
|
||||||
|
device_context_->DrawBitmap(
|
||||||
|
bitmap.get(),
|
||||||
|
DX::ConvertToRectF(dest_rect),
|
||||||
|
opacity_,
|
||||||
|
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
|
||||||
|
DX::ConvertToRectF(src_rect)
|
||||||
|
);
|
||||||
|
|
||||||
device_context_->DrawBitmap(
|
IncreasePrimitivesCount();
|
||||||
bitmap.get(),
|
}
|
||||||
DX::ConvertToRectF(dest_rect),
|
|
||||||
opacity_,
|
|
||||||
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
|
|
||||||
DX::ConvertToRectF(src_rect)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (collecting_status_)
|
ThrowIfFailed(hr);
|
||||||
++status_.primitives;
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::DrawTextLayout(ComPtr<IDWriteTextLayout> const& text_layout)
|
void Renderer::DrawTextLayout(ComPtr<IDWriteTextLayout> const& text_layout)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!text_renderer_)
|
if (!text_renderer_)
|
||||||
return E_UNEXPECTED;
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
if (collecting_status_)
|
if (SUCCEEDED(hr))
|
||||||
++status_.primitives;
|
{
|
||||||
return text_layout->Draw(nullptr, text_renderer_.get(), 0, 0);
|
hr = text_layout->Draw(nullptr, text_renderer_.get(), 0, 0);
|
||||||
|
|
||||||
|
IncreasePrimitivesCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetVSyncEnabled(bool enabled)
|
void Renderer::SetVSyncEnabled(bool enabled)
|
||||||
|
|
@ -327,66 +384,101 @@ namespace kiwano
|
||||||
vsync_ = enabled;
|
vsync_ = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::PushClip(const Matrix & clip_matrix, const Size & clip_size)
|
void Renderer::PushClip(const Matrix & clip_matrix, const Size & clip_size)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!device_context_)
|
if (!device_context_)
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
device_context_->SetTransform(DX::ConvertToMatrix3x2F(clip_matrix));
|
|
||||||
device_context_->PushAxisAlignedClip(
|
|
||||||
D2D1::RectF(0, 0, clip_size.x, clip_size.y),
|
|
||||||
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
|
|
||||||
);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT Renderer::PopClip()
|
|
||||||
{
|
|
||||||
if (!device_context_)
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
device_context_->PopAxisAlignedClip();
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT Renderer::PushLayer(ComPtr<ID2D1Layer> const& layer, LayerProperties const& properties)
|
|
||||||
{
|
|
||||||
if (!device_context_ || !solid_color_brush_)
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
device_context_->PushLayer(
|
|
||||||
D2D1::LayerParameters(
|
|
||||||
DX::ConvertToRectF(properties.area),
|
|
||||||
nullptr,
|
|
||||||
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
|
|
||||||
D2D1::Matrix3x2F::Identity(),
|
|
||||||
properties.opacity,
|
|
||||||
solid_color_brush_.get(),
|
|
||||||
D2D1_LAYER_OPTIONS_NONE
|
|
||||||
),
|
|
||||||
layer.get()
|
|
||||||
);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT Renderer::PopLayer()
|
|
||||||
{
|
|
||||||
if (!device_context_)
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
device_context_->PopLayer();
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT Renderer::Resize(UINT width, UINT height)
|
|
||||||
{
|
|
||||||
output_size_.x = static_cast<float>(width);
|
|
||||||
output_size_.y = static_cast<float>(height);
|
|
||||||
if (d3d_res_)
|
|
||||||
{
|
{
|
||||||
return d3d_res_->SetLogicalSize(output_size_);
|
hr = E_UNEXPECTED;
|
||||||
}
|
}
|
||||||
return S_OK;
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
device_context_->SetTransform(DX::ConvertToMatrix3x2F(clip_matrix));
|
||||||
|
device_context_->PushAxisAlignedClip(
|
||||||
|
D2D1::RectF(0, 0, clip_size.x, clip_size.y),
|
||||||
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::PopClip()
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
if (!device_context_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
device_context_->PopAxisAlignedClip();
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::PushLayer(ComPtr<ID2D1Layer> const& layer, LayerProperties const& properties)
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
if (!device_context_ || !solid_color_brush_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
device_context_->PushLayer(
|
||||||
|
D2D1::LayerParameters(
|
||||||
|
DX::ConvertToRectF(properties.area),
|
||||||
|
nullptr,
|
||||||
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
|
||||||
|
D2D1::Matrix3x2F::Identity(),
|
||||||
|
properties.opacity,
|
||||||
|
solid_color_brush_.get(),
|
||||||
|
D2D1_LAYER_OPTIONS_NONE
|
||||||
|
),
|
||||||
|
layer.get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::PopLayer()
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
if (!device_context_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
device_context_->PopLayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::Resize(UINT width, UINT height)
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
if (!d3d_res_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
output_size_.x = static_cast<float>(width);
|
||||||
|
output_size_.y = static_cast<float>(height);
|
||||||
|
hr = d3d_res_->SetLogicalSize(output_size_);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCollectingStatus(bool collecting)
|
void Renderer::SetCollectingStatus(bool collecting)
|
||||||
|
|
@ -399,29 +491,43 @@ namespace kiwano
|
||||||
clear_color_ = color;
|
clear_color_ = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::SetTransform(const Matrix & matrix)
|
void Renderer::SetTransform(const Matrix & matrix)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!device_context_)
|
if (!device_context_)
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
device_context_->SetTransform(DX::ConvertToMatrix3x2F(&matrix));
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT Renderer::SetOpacity(float opacity)
|
|
||||||
{
|
|
||||||
if (!solid_color_brush_)
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
if (opacity_ != opacity)
|
|
||||||
{
|
{
|
||||||
opacity_ = opacity;
|
hr = E_UNEXPECTED;
|
||||||
solid_color_brush_->SetOpacity(opacity);
|
|
||||||
}
|
}
|
||||||
return S_OK;
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
device_context_->SetTransform(DX::ConvertToMatrix3x2F(&matrix));
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::SetTextStyle(
|
void Renderer::SetOpacity(float opacity)
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
if (!solid_color_brush_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
if (opacity_ != opacity)
|
||||||
|
{
|
||||||
|
opacity_ = opacity;
|
||||||
|
solid_color_brush_->SetOpacity(opacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetTextStyle(
|
||||||
float opacity,
|
float opacity,
|
||||||
Color const& color,
|
Color const& color,
|
||||||
bool has_outline,
|
bool has_outline,
|
||||||
|
|
@ -430,58 +536,79 @@ namespace kiwano
|
||||||
StrokeStyle outline_stroke
|
StrokeStyle outline_stroke
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
if (!text_renderer_ || !d3d_res_)
|
if (!text_renderer_ || !d3d_res_)
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
text_renderer_->SetTextStyle(
|
|
||||||
opacity,
|
|
||||||
DX::ConvertToColorF(color),
|
|
||||||
has_outline,
|
|
||||||
DX::ConvertToColorF(outline_color),
|
|
||||||
outline_width,
|
|
||||||
d2d_res_->GetStrokeStyle(outline_stroke)
|
|
||||||
);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT Renderer::SetAntialiasMode(bool enabled)
|
|
||||||
{
|
|
||||||
if (!device_context_)
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
device_context_->SetAntialiasMode(
|
|
||||||
enabled ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED
|
|
||||||
);
|
|
||||||
antialias_ = enabled;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT Renderer::SetTextAntialiasMode(TextAntialias mode)
|
|
||||||
{
|
|
||||||
if (!device_context_)
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
text_antialias_ = mode;
|
|
||||||
D2D1_TEXT_ANTIALIAS_MODE antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
|
||||||
switch (text_antialias_)
|
|
||||||
{
|
{
|
||||||
case TextAntialias::Default:
|
hr = E_UNEXPECTED;
|
||||||
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
|
||||||
break;
|
|
||||||
case TextAntialias::ClearType:
|
|
||||||
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
|
||||||
break;
|
|
||||||
case TextAntialias::GrayScale:
|
|
||||||
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
|
||||||
break;
|
|
||||||
case TextAntialias::None:
|
|
||||||
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
device_context_->SetTextAntialiasMode(antialias_mode);
|
|
||||||
return S_OK;
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
text_renderer_->SetTextStyle(
|
||||||
|
opacity,
|
||||||
|
DX::ConvertToColorF(color),
|
||||||
|
has_outline,
|
||||||
|
DX::ConvertToColorF(outline_color),
|
||||||
|
outline_width,
|
||||||
|
d2d_res_->GetStrokeStyle(outline_stroke)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetAntialiasMode(bool enabled)
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
if (!device_context_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
device_context_->SetAntialiasMode(
|
||||||
|
enabled ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED
|
||||||
|
);
|
||||||
|
antialias_ = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetTextAntialiasMode(TextAntialias mode)
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
if (!device_context_)
|
||||||
|
{
|
||||||
|
hr = E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
text_antialias_ = mode;
|
||||||
|
D2D1_TEXT_ANTIALIAS_MODE antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
||||||
|
switch (text_antialias_)
|
||||||
|
{
|
||||||
|
case TextAntialias::Default:
|
||||||
|
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
||||||
|
break;
|
||||||
|
case TextAntialias::ClearType:
|
||||||
|
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
||||||
|
break;
|
||||||
|
case TextAntialias::GrayScale:
|
||||||
|
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
||||||
|
break;
|
||||||
|
case TextAntialias::None:
|
||||||
|
antialias_mode = D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
device_context_->SetTextAntialiasMode(antialias_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowIfFailed(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::CheckVisibility(Size const& content_size, Matrix const& transform)
|
bool Renderer::CheckVisibility(Size const& content_size, Matrix const& transform)
|
||||||
|
|
|
||||||
|
|
@ -52,41 +52,41 @@ namespace kiwano
|
||||||
KGE_DECLARE_SINGLETON(Renderer);
|
KGE_DECLARE_SINGLETON(Renderer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HRESULT CreateLayer(
|
void CreateLayer(
|
||||||
ComPtr<ID2D1Layer>& layer
|
ComPtr<ID2D1Layer>& layer
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawGeometry(
|
void DrawGeometry(
|
||||||
ComPtr<ID2D1Geometry> const& geometry,
|
ComPtr<ID2D1Geometry> const& geometry,
|
||||||
const Color& stroke_color,
|
const Color& stroke_color,
|
||||||
float stroke_width,
|
float stroke_width,
|
||||||
StrokeStyle stroke = StrokeStyle::Miter
|
StrokeStyle stroke = StrokeStyle::Miter
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT FillGeometry(
|
void FillGeometry(
|
||||||
ComPtr<ID2D1Geometry> const& geometry,
|
ComPtr<ID2D1Geometry> const& geometry,
|
||||||
Color const& fill_color
|
Color const& fill_color
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawRectangle(
|
void DrawRectangle(
|
||||||
Rect const& rect,
|
Rect const& rect,
|
||||||
const Color& stroke_color,
|
const Color& stroke_color,
|
||||||
float stroke_width,
|
float stroke_width,
|
||||||
StrokeStyle stroke = StrokeStyle::Miter
|
StrokeStyle stroke = StrokeStyle::Miter
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT FillRectangle(
|
void FillRectangle(
|
||||||
Rect const& rect,
|
Rect const& rect,
|
||||||
Color const& fill_color
|
Color const& fill_color
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawBitmap(
|
void DrawBitmap(
|
||||||
ComPtr<ID2D1Bitmap> const& bitmap,
|
ComPtr<ID2D1Bitmap> const& bitmap,
|
||||||
Rect const& src_rect,
|
Rect const& src_rect,
|
||||||
Rect const& dest_rect
|
Rect const& dest_rect
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawTextLayout(
|
void DrawTextLayout(
|
||||||
ComPtr<IDWriteTextLayout> const& text_layout
|
ComPtr<IDWriteTextLayout> const& text_layout
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -96,12 +96,12 @@ namespace kiwano
|
||||||
);
|
);
|
||||||
|
|
||||||
// ÉèÖÿ¹¾â³Ýģʽ
|
// ÉèÖÿ¹¾â³Ýģʽ
|
||||||
HRESULT SetAntialiasMode(
|
void SetAntialiasMode(
|
||||||
bool enabled
|
bool enabled
|
||||||
);
|
);
|
||||||
|
|
||||||
// ÉèÖÃÎÄ×Ö¿¹¾â³Ýģʽ
|
// ÉèÖÃÎÄ×Ö¿¹¾â³Ýģʽ
|
||||||
HRESULT SetTextAntialiasMode(
|
void SetTextAntialiasMode(
|
||||||
TextAntialias mode
|
TextAntialias mode
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -111,15 +111,15 @@ namespace kiwano
|
||||||
);
|
);
|
||||||
|
|
||||||
// ÉèÖû±Ê͸Ã÷¶È
|
// ÉèÖû±Ê͸Ã÷¶È
|
||||||
HRESULT SetOpacity(
|
void SetOpacity(
|
||||||
float opacity
|
float opacity
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT SetTransform(
|
void SetTransform(
|
||||||
const Matrix& matrix
|
const Matrix& matrix
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT SetTextStyle(
|
void SetTextStyle(
|
||||||
float opacity,
|
float opacity,
|
||||||
const Color& color,
|
const Color& color,
|
||||||
bool has_outline,
|
bool has_outline,
|
||||||
|
|
@ -128,21 +128,21 @@ namespace kiwano
|
||||||
StrokeStyle outline_stroke
|
StrokeStyle outline_stroke
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT PushClip(
|
void PushClip(
|
||||||
const Matrix& clip_matrix,
|
const Matrix& clip_matrix,
|
||||||
const Size& clip_size
|
const Size& clip_size
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT PopClip();
|
void PopClip();
|
||||||
|
|
||||||
HRESULT PushLayer(
|
void PushLayer(
|
||||||
ComPtr<ID2D1Layer> const& layer,
|
ComPtr<ID2D1Layer> const& layer,
|
||||||
LayerProperties const& properties
|
LayerProperties const& properties
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT PopLayer();
|
void PopLayer();
|
||||||
|
|
||||||
HRESULT Resize(
|
void Resize(
|
||||||
UINT width,
|
UINT width,
|
||||||
UINT height
|
UINT height
|
||||||
);
|
);
|
||||||
|
|
@ -200,13 +200,14 @@ namespace kiwano
|
||||||
|
|
||||||
HRESULT EndDraw();
|
HRESULT EndDraw();
|
||||||
|
|
||||||
private:
|
void IncreasePrimitivesCount();
|
||||||
HWND hwnd_;
|
|
||||||
float opacity_;
|
|
||||||
bool antialias_;
|
|
||||||
bool vsync_;
|
|
||||||
bool collecting_status_;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool vsync_;
|
||||||
|
bool antialias_;
|
||||||
|
bool collecting_status_;
|
||||||
|
float opacity_;
|
||||||
|
HWND hwnd_;
|
||||||
Size output_size_;
|
Size output_size_;
|
||||||
Color clear_color_;
|
Color clear_color_;
|
||||||
TextAntialias text_antialias_;
|
TextAntialias text_antialias_;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue