aboutsummaryrefslogtreecommitdiff
path: root/CruUI/graph
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-04 01:05:25 +0800
committercrupest <crupest@outlook.com>2018-09-04 01:05:25 +0800
commit1a2cf75e94b98a649b2b1e87d62e3a3be9de5ea1 (patch)
tree03f15c6d29add5ee38e4d12b587d3e9659cba786 /CruUI/graph
parent9397b9fb89e389906ec9f6c9ea3ca18073593c8c (diff)
downloadcru-1a2cf75e94b98a649b2b1e87d62e3a3be9de5ea1.tar.gz
cru-1a2cf75e94b98a649b2b1e87d62e3a3be9de5ea1.tar.bz2
cru-1a2cf75e94b98a649b2b1e87d62e3a3be9de5ea1.zip
...
Diffstat (limited to 'CruUI/graph')
-rw-r--r--CruUI/graph/graph.cpp48
-rw-r--r--CruUI/graph/graph.h17
2 files changed, 43 insertions, 22 deletions
diff --git a/CruUI/graph/graph.cpp b/CruUI/graph/graph.cpp
index 4871c5f4..49616a6f 100644
--- a/CruUI/graph/graph.cpp
+++ b/CruUI/graph/graph.cpp
@@ -8,7 +8,7 @@ namespace cru {
using Microsoft::WRL::ComPtr;
WindowRenderTarget::WindowRenderTarget(GraphManager* graph_manager, HWND hwnd)
- {
+ {
this->graph_manager_ = graph_manager;
const auto d3d11_device = graph_manager->GetD3D11Device();
@@ -46,18 +46,18 @@ namespace cru {
}
WindowRenderTarget::~WindowRenderTarget()
- {
+ {
}
void WindowRenderTarget::ResizeBuffer(const int width, const int height)
- {
+ {
const auto graph_manager = graph_manager_;
const auto d2d1_device_context = graph_manager->GetD2D1DeviceContext();
ComPtr<ID2D1Image> old_target;
d2d1_device_context->GetTarget(&old_target);
- const auto target_this = old_target == this->target_bitmap_;
+ const auto target_this = old_target == this->target_bitmap_;
if (target_this)
d2d1_device_context->SetTarget(nullptr);
@@ -75,19 +75,19 @@ namespace cru {
}
void WindowRenderTarget::SetAsTarget()
- {
+ {
GetD2DDeviceContext()->SetTarget(target_bitmap_.Get());
}
void WindowRenderTarget::Present()
- {
+ {
ThrowIfFailed(
dxgi_swap_chain_->Present(1, 0)
);
}
void WindowRenderTarget::CreateTargetBitmap()
- {
+ {
// Direct2D needs the dxgi version of the backbuffer surface pointer.
ComPtr<IDXGISurface> dxgiBackBuffer;
ThrowIfFailed(
@@ -114,8 +114,13 @@ namespace cru {
);
}
+ GraphManager* GraphManager::GetInstance()
+ {
+ return Application::GetInstance()->GetGraphManager();
+ }
+
GraphManager::GraphManager()
- {
+ {
UINT creation_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG
@@ -174,59 +179,66 @@ namespace cru {
ThrowIfFailed(
dxgi_adapter->GetParent(IID_PPV_ARGS(&dxgi_factory_))
);
+
+
+ ThrowIfFailed(DWriteCreateFactory(
+ DWRITE_FACTORY_TYPE_SHARED,
+ __uuidof(IDWriteFactory),
+ reinterpret_cast<IUnknown**>(dwrite_factory_.GetAddressOf())
+ ));
}
GraphManager::~GraphManager()
- {
+ {
}
std::shared_ptr<WindowRenderTarget> GraphManager::CreateWindowRenderTarget(HWND hwnd)
- {
+ {
return std::make_shared<WindowRenderTarget>(this, hwnd);
}
Dpi GraphManager::GetDpi()
- {
+ {
Dpi dpi;
d2d1_factory_->GetDesktopDpi(&dpi.x, &dpi.y);
return dpi;
}
void GraphManager::ReloadSystemMetrics()
- {
+ {
ThrowIfFailed(
d2d1_factory_->ReloadSystemMetrics()
);
}
inline int DipToPixelInternal(float dip, float dpi)
- {
+ {
return static_cast<int>(dip * dpi / 96.0f);
}
int DipToPixelX(float dipX)
- {
+ {
return DipToPixelInternal(dipX, Application::GetInstance()->GetGraphManager()->GetDpi().x);
}
int DipToPixelY(float dipY)
- {
+ {
return DipToPixelInternal(dipY, Application::GetInstance()->GetGraphManager()->GetDpi().y);
}
inline float DipToPixelInternal(int pixel, float dpi)
- {
+ {
return static_cast<float>(pixel) * 96.0f / dpi;
}
float PixelToDipX(int pixelX)
- {
+ {
return DipToPixelInternal(pixelX, Application::GetInstance()->GetGraphManager()->GetDpi().x);
}
float PixelToDipY(int pixelY)
- {
+ {
return DipToPixelInternal(pixelY, Application::GetInstance()->GetGraphManager()->GetDpi().y);
}
}
diff --git a/CruUI/graph/graph.h b/CruUI/graph/graph.h
index 69d11b9c..b221115a 100644
--- a/CruUI/graph/graph.h
+++ b/CruUI/graph/graph.h
@@ -9,12 +9,12 @@
namespace cru
{
namespace graph
- {
+ {
class GraphManager;
//Represents a window render target.
class WindowRenderTarget : public Object
- {
+ {
public:
WindowRenderTarget(GraphManager* graph_manager, HWND hwnd);
WindowRenderTarget(const WindowRenderTarget& other) = delete;
@@ -58,13 +58,16 @@ namespace cru
};
struct Dpi
- {
+ {
float x;
float y;
};
class GraphManager : public Object
- {
+ {
+ public:
+ static GraphManager* GetInstance();
+
public:
GraphManager();
GraphManager(const GraphManager& other) = delete;
@@ -94,6 +97,12 @@ namespace cru
return dxgi_factory_;
}
+ Microsoft::WRL::ComPtr<IDWriteFactory> GetDWriteFactory() const
+ {
+ return dwrite_factory_;
+ }
+
+
//Create a window render target with the HWND.
std::shared_ptr<WindowRenderTarget> CreateWindowRenderTarget(HWND hwnd);