diff --git a/core/e2dimpl.h b/core/e2dimpl.h index 80af4da3..b28c6caa 100644 --- a/core/e2dimpl.h +++ b/core/e2dimpl.h @@ -23,46 +23,13 @@ namespace easy2d { - - - class MediaAsyncCallback : public IMFAsyncCallback - { - public: - MediaAsyncCallback( - HWND hwnd, - IMFMediaSession * pSession, - HANDLE hCloseEvent - ); - - // IUnknown methods - STDMETHODIMP QueryInterface(REFIID iid, void** ppv); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - - // IMFAsyncCallback methods - STDMETHODIMP GetParameters(DWORD*, DWORD*); - STDMETHODIMP Invoke(IMFAsyncResult* pAsyncResult); - - protected: - long m_nRefCount; - IMFMediaSession * m_pSession; - HWND m_hwnd; - HANDLE m_hCloseEvent; - }; - - // 文字渲染器 - class E2DTextRenderer + class TextRenderer : public IDWriteTextRenderer { - private: - E2DTextRenderer(); - - ~E2DTextRenderer(); - public: static HRESULT Create( - E2DTextRenderer** ppTextRenderer, + TextRenderer** ppTextRenderer, ID2D1Factory* pD2DFactory, ID2D1HwndRenderTarget* pRT, ID2D1SolidColorBrush* pBrush @@ -74,7 +41,7 @@ namespace easy2d CONST D2D1_COLOR_F &outline_color, FLOAT outline_width, D2D1_LINE_JOIN outlineJoin - ); + ); STDMETHOD(DrawGlyphRun)( __maybenull void* clientDrawingContext, @@ -84,7 +51,7 @@ namespace easy2d __in DWRITE_GLYPH_RUN const* glyphRun, __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, IUnknown* clientDrawingEffect - ); + ); STDMETHOD(DrawUnderline)( __maybenull void* clientDrawingContext, @@ -92,7 +59,7 @@ namespace easy2d FLOAT baselineOriginY, __in DWRITE_UNDERLINE const* underline, IUnknown* clientDrawingEffect - ); + ); STDMETHOD(DrawStrikethrough)( __maybenull void* clientDrawingContext, @@ -100,7 +67,7 @@ namespace easy2d FLOAT baselineOriginY, __in DWRITE_STRIKETHROUGH const* strikethrough, IUnknown* clientDrawingEffect - ); + ); STDMETHOD(DrawInlineObject)( __maybenull void* clientDrawingContext, @@ -115,17 +82,17 @@ namespace easy2d STDMETHOD(IsPixelSnappingDisabled)( __maybenull void* clientDrawingContext, __out BOOL* isDisabled - ); + ); STDMETHOD(GetCurrentTransform)( __maybenull void* clientDrawingContext, __out DWRITE_MATRIX* transform - ); + ); STDMETHOD(GetPixelsPerDip)( __maybenull void* clientDrawingContext, __out FLOAT* pixelsPerDip - ); + ); public: unsigned long STDMETHODCALLTYPE AddRef(); @@ -136,15 +103,20 @@ namespace easy2d ); private: - unsigned long cRefCount_; - D2D1_COLOR_F sFillColor_; - D2D1_COLOR_F sOutlineColor_; - FLOAT fOutlineWidth; - BOOL bShowOutline_; - ID2D1Factory* pD2DFactory_; - ID2D1HwndRenderTarget* pRT_; - ID2D1SolidColorBrush* pBrush_; - ID2D1StrokeStyle * pCurrStrokeStyle_; + TextRenderer(); + + ~TextRenderer(); + + private: + unsigned long cRefCount_; + D2D1_COLOR_F sFillColor_; + D2D1_COLOR_F sOutlineColor_; + FLOAT fOutlineWidth; + BOOL bShowOutline_; + ID2D1Factory* pD2DFactory_; + ID2D1HwndRenderTarget* pRT_; + ID2D1SolidColorBrush* pBrush_; + ID2D1StrokeStyle* pCurrStrokeStyle_; }; @@ -171,11 +143,11 @@ namespace easy2d { if (FAILED(hr)) { - // 在此处设置断点以捕获 D2D API 异常. + // 在此处设置断点以捕获系统异常. static char s_str[64] = {}; sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast(hr)); throw RuntimeException(s_str); } } -} \ No newline at end of file +} diff --git a/core/e2dmodule.h b/core/e2dmodule.h index 0a3a0087..9ab21539 100644 --- a/core/e2dmodule.h +++ b/core/e2dmodule.h @@ -62,7 +62,7 @@ namespace easy2d ID2D1SolidColorBrush * GetSolidBrush() const; // 获取文字渲染工具 - E2DTextRenderer * GetTextRender() const; + TextRenderer * GetTextRender() const; // 获取 Miter 样式的 ID2D1StrokeStyle ID2D1StrokeStyle * GetMiterStrokeStyle(); @@ -84,7 +84,7 @@ namespace easy2d ID2D1StrokeStyle* miter_stroke_style_; ID2D1StrokeStyle* bevel_stroke_style_; ID2D1StrokeStyle* round_stroke_style_; - E2DTextRenderer* text_renderer_; + TextRenderer* text_renderer_; IDWriteTextFormat* fps_text_format_; IDWriteTextLayout* fps_text_layout_; ID2D1SolidColorBrush* solid_brush_; diff --git a/core/e2dtool.h b/core/e2dtool.h index 318494fa..dcaf2525 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -75,6 +75,14 @@ namespace easy2d public: Music(); + Music( + const easy2d::String& file_path /* 音乐文件路径 */ + ); + + Music( + const Resource& res /* 音乐资源 */ + ); + virtual ~Music(); // 打开音乐文件 @@ -84,7 +92,7 @@ namespace easy2d // 打开音乐资源 bool Load( - const Resource& res + const Resource& res /* 音乐资源 */ ); // 播放 diff --git a/core/impl/TextRenderer.cpp b/core/impl/TextRenderer.cpp index 49907581..8a6f5c2c 100644 --- a/core/impl/TextRenderer.cpp +++ b/core/impl/TextRenderer.cpp @@ -23,7 +23,7 @@ using namespace easy2d; -E2DTextRenderer::E2DTextRenderer() +TextRenderer::TextRenderer() : cRefCount_(0) , pD2DFactory_(nullptr) , pRT_(nullptr) @@ -36,21 +36,21 @@ E2DTextRenderer::E2DTextRenderer() { } -E2DTextRenderer::~E2DTextRenderer() +TextRenderer::~TextRenderer() { SafeRelease(pD2DFactory_); SafeRelease(pRT_); SafeRelease(pBrush_); } -HRESULT E2DTextRenderer::Create( - E2DTextRenderer** ppTextRenderer, +HRESULT TextRenderer::Create( + TextRenderer** ppTextRenderer, ID2D1Factory* pD2DFactory, ID2D1HwndRenderTarget* pRT, ID2D1SolidColorBrush* pBrush ) { - *ppTextRenderer = new (std::nothrow) E2DTextRenderer(); + *ppTextRenderer = new (std::nothrow) TextRenderer(); if (*ppTextRenderer) { pD2DFactory->AddRef(); @@ -66,7 +66,7 @@ HRESULT E2DTextRenderer::Create( return E_FAIL; } -STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle( +STDMETHODIMP_(void) TextRenderer::SetTextStyle( CONST D2D1_COLOR_F &fillColor, BOOL outline, CONST D2D1_COLOR_F &outline_color, @@ -96,7 +96,7 @@ STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle( } } -STDMETHODIMP E2DTextRenderer::DrawGlyphRun( +STDMETHODIMP TextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -185,7 +185,7 @@ STDMETHODIMP E2DTextRenderer::DrawGlyphRun( return hr; } -STDMETHODIMP E2DTextRenderer::DrawUnderline( +STDMETHODIMP TextRenderer::DrawUnderline( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -252,7 +252,7 @@ STDMETHODIMP E2DTextRenderer::DrawUnderline( return S_OK; } -STDMETHODIMP E2DTextRenderer::DrawStrikethrough( +STDMETHODIMP TextRenderer::DrawStrikethrough( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -319,7 +319,7 @@ STDMETHODIMP E2DTextRenderer::DrawStrikethrough( return S_OK; } -STDMETHODIMP E2DTextRenderer::DrawInlineObject( +STDMETHODIMP TextRenderer::DrawInlineObject( __maybenull void* clientDrawingContext, FLOAT originX, FLOAT originY, @@ -332,12 +332,12 @@ STDMETHODIMP E2DTextRenderer::DrawInlineObject( return E_NOTIMPL; } -STDMETHODIMP_(unsigned long) E2DTextRenderer::AddRef() +STDMETHODIMP_(unsigned long) TextRenderer::AddRef() { return InterlockedIncrement(&cRefCount_); } -STDMETHODIMP_(unsigned long) E2DTextRenderer::Release() +STDMETHODIMP_(unsigned long) TextRenderer::Release() { unsigned long newCount = InterlockedDecrement(&cRefCount_); @@ -350,7 +350,7 @@ STDMETHODIMP_(unsigned long) E2DTextRenderer::Release() return newCount; } -STDMETHODIMP E2DTextRenderer::IsPixelSnappingDisabled( +STDMETHODIMP TextRenderer::IsPixelSnappingDisabled( __maybenull void* clientDrawingContext, __out BOOL* isDisabled ) @@ -359,7 +359,7 @@ STDMETHODIMP E2DTextRenderer::IsPixelSnappingDisabled( return S_OK; } -STDMETHODIMP E2DTextRenderer::GetCurrentTransform( +STDMETHODIMP TextRenderer::GetCurrentTransform( __maybenull void* clientDrawingContext, __out DWRITE_MATRIX* transform ) @@ -368,7 +368,7 @@ STDMETHODIMP E2DTextRenderer::GetCurrentTransform( return S_OK; } -STDMETHODIMP E2DTextRenderer::GetPixelsPerDip( +STDMETHODIMP TextRenderer::GetPixelsPerDip( __maybenull void* clientDrawingContext, __out FLOAT* pixelsPerDip ) @@ -381,7 +381,7 @@ STDMETHODIMP E2DTextRenderer::GetPixelsPerDip( return S_OK; } -STDMETHODIMP E2DTextRenderer::QueryInterface( +STDMETHODIMP TextRenderer::QueryInterface( IID const& riid, void** ppvObject ) diff --git a/core/modules/Graphics.cpp b/core/modules/Graphics.cpp index 3d6ab505..a7fd2db5 100644 --- a/core/modules/Graphics.cpp +++ b/core/modules/Graphics.cpp @@ -92,7 +92,7 @@ easy2d::Graphics::Graphics(HWND hwnd) // 创建自定义的文字渲染器 ThrowIfFailed( - E2DTextRenderer::Create( + TextRenderer::Create( &text_renderer_, factory_, render_target_, @@ -223,7 +223,7 @@ ID2D1SolidColorBrush * easy2d::Graphics::GetSolidBrush() const return solid_brush_; } -easy2d::E2DTextRenderer * easy2d::Graphics::GetTextRender() const +easy2d::TextRenderer * easy2d::Graphics::GetTextRender() const { return text_renderer_; } diff --git a/core/tools/Music.cpp b/core/tools/Music.cpp index 229a587e..d8872de1 100644 --- a/core/tools/Music.cpp +++ b/core/tools/Music.cpp @@ -37,7 +37,7 @@ inline bool TraceError(wchar_t* prompt, HRESULT hr) namespace easy2d { - + // 音频解码器 class Transcoder { WAVEFORMATEX* wave_format_; @@ -324,6 +324,26 @@ easy2d::Music::Music() { } +easy2d::Music::Music(const easy2d::String& file_path) + : opened_(false) + , playing_(false) + , wave_data_(nullptr) + , size_(0) + , voice_(nullptr) +{ + Load(file_path); +} + +easy2d::Music::Music(const Resource& res) + : opened_(false) + , playing_(false) + , wave_data_(nullptr) + , size_(0) + , voice_(nullptr) +{ + Load(res); +} + easy2d::Music::~Music() { Close();