From e88d101855785f72fcdff777822a1d3352402173 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Sat, 9 Feb 2019 00:03:24 +0800 Subject: [PATCH] add definition of all API symbols declarations for DLL --- src/core/Action.hpp | 2 +- src/core/ActionGroup.h | 6 +- src/core/ActionHelper.h | 4 +- src/core/ActionManager.h | 2 +- src/core/ActionTween.cpp | 1 - src/core/ActionTween.h | 91 +++++++++++------------ src/core/Animation.h | 2 +- src/core/Application.cpp | 40 ++++++++-- src/core/Application.h | 14 +--- src/core/Canvas.h | 2 +- src/core/Color.h | 2 +- src/core/DebugNode.h | 2 +- src/core/Delay.h | 4 +- src/core/Event.hpp | 2 +- src/core/EventDispatcher.h | 2 +- src/core/EventListener.h | 2 +- src/core/Factory.cpp | 13 +++- src/core/Factory.h | 28 +++---- src/core/Frames.h | 2 +- src/core/Geometry.h | 14 ++-- src/core/GeometryNode.h | 2 +- src/core/Image.cpp | 2 +- src/core/Image.h | 4 +- src/core/Input.cpp | 3 - src/core/Input.h | 2 +- src/core/IntrusiveList.hpp | 17 ++--- src/core/Music.cpp | 2 +- src/core/Music.h | 2 +- src/core/Node.h | 2 +- src/core/Object.h | 2 +- src/core/RefCounter.hpp | 2 +- src/core/Resource.h | 2 +- src/core/Scene.h | 2 +- src/core/Sprite.h | 2 +- src/core/Task.h | 2 +- src/core/TaskManager.h | 2 +- src/core/Text.h | 2 +- src/core/TextRenderer.cpp | 147 ++++++++++++++++++++++++++++++------- src/core/TextRenderer.h | 95 ++---------------------- src/core/TextStyle.hpp | 2 +- src/core/Transform.hpp | 2 +- src/core/Transition.h | 2 +- src/core/audio.cpp | 32 ++++---- src/core/audio.h | 6 +- src/core/config.h | 4 + src/core/logs.h | 20 ++--- src/core/macros.h | 12 +++ src/core/modules.h | 8 +- src/core/noncopyable.hpp | 3 +- src/core/render.cpp | 18 ++++- src/core/render.h | 4 +- src/core/time.h | 16 ++-- src/core/window.cpp | 39 +++++----- src/core/window.h | 6 +- src/math/Matrix.cpp | 8 +- src/math/Matrix.h | 3 +- src/math/Rect.hpp | 2 +- src/math/rand.h | 3 +- src/math/scalar.hpp | 1 + src/math/vector.hpp | 2 +- src/ui/Button.h | 2 +- src/ui/Menu.h | 2 +- src/utils/Data.h | 2 +- src/utils/File.h | 2 +- src/utils/Path.h | 2 +- src/utils/Player.h | 2 +- src/utils/ResLoader.h | 2 +- src/utils/Transcoder.h | 2 +- src/utils/string.h | 5 +- 69 files changed, 412 insertions(+), 331 deletions(-) diff --git a/src/core/Action.hpp b/src/core/Action.hpp index bba02328..cc66e7a8 100644 --- a/src/core/Action.hpp +++ b/src/core/Action.hpp @@ -28,7 +28,7 @@ namespace easy2d { class ActionManager; - class Action + class E2D_API Action : public virtual Object , protected IntrusiveListItem { diff --git a/src/core/ActionGroup.h b/src/core/ActionGroup.h index afcdd712..f3891681 100644 --- a/src/core/ActionGroup.h +++ b/src/core/ActionGroup.h @@ -24,7 +24,7 @@ namespace easy2d { // 循环动作 - class Loop + class E2D_API Loop : public Action { public: @@ -61,7 +61,7 @@ namespace easy2d // 顺序动作 - class Sequence + class E2D_API Sequence : public Action { public: @@ -106,7 +106,7 @@ namespace easy2d // 同步动作 - class Spawn + class E2D_API Spawn : public Action { public: diff --git a/src/core/ActionHelper.h b/src/core/ActionHelper.h index 8b187215..9db79a77 100644 --- a/src/core/ActionHelper.h +++ b/src/core/ActionHelper.h @@ -26,7 +26,7 @@ namespace easy2d { - struct ActionHelper + struct E2D_API ActionHelper { ActionHelper& SetLoopCount(int loop) { this->loop = loop; return (*this); } @@ -44,7 +44,7 @@ namespace easy2d int loop; }; - struct TweenActionHelper + struct E2D_API TweenActionHelper { TweenActionHelper& SetDuration(Duration dur) { this->dur = dur; return (*this); } diff --git a/src/core/ActionManager.h b/src/core/ActionManager.h index b2fdbc15..a6e60f05 100644 --- a/src/core/ActionManager.h +++ b/src/core/ActionManager.h @@ -23,7 +23,7 @@ namespace easy2d { - class ActionManager + class E2D_API ActionManager { using Actions = IntrusiveList; diff --git a/src/core/ActionTween.cpp b/src/core/ActionTween.cpp index 78425d7c..8cd0d90e 100644 --- a/src/core/ActionTween.cpp +++ b/src/core/ActionTween.cpp @@ -19,7 +19,6 @@ // THE SOFTWARE. #include "ActionTween.h" -#include "Geometry.h" #include "include-forwards.h" #include "Node.h" #include diff --git a/src/core/ActionTween.h b/src/core/ActionTween.h index 5a543534..0ef790b2 100644 --- a/src/core/ActionTween.h +++ b/src/core/ActionTween.h @@ -21,6 +21,7 @@ #pragma once #include "Action.hpp" #include "logs.h" +#include "Geometry.h" // PathAction #include "../math/ease.hpp" namespace easy2d @@ -32,37 +33,37 @@ namespace easy2d // See https://easings.net for more information struct Ease { - static EaseFunc Linear; // 线性 - static EaseFunc EaseIn; // 由慢变快 - static EaseFunc EaseOut; // 由快变慢 - static EaseFunc EaseInOut; // 由慢变快, 再由快变慢 - static EaseFunc ExpoIn; // 由慢变极快 - static EaseFunc ExpoOut; // 由极快变慢 - static EaseFunc ExpoInOut; // 由慢至极快, 再由极快边慢 - static EaseFunc ElasticIn; // 自起点赋予弹性 - static EaseFunc ElasticOut; // 自终点赋予弹性 - static EaseFunc ElasticInOut; // 再起点和终点赋予弹性 - static EaseFunc BounceIn; // 自起点赋予反弹力 - static EaseFunc BounceOut; // 自终点赋予反弹力 - static EaseFunc BounceInOut; // 在起点和终点赋予反弹力 - static EaseFunc BackIn; - static EaseFunc BackOut; - static EaseFunc BackInOut; - static EaseFunc QuadIn; - static EaseFunc QuadOut; - static EaseFunc QuadInOut; - static EaseFunc CubicIn; - static EaseFunc CubicOut; - static EaseFunc CubicInOut; - static EaseFunc QuartIn; - static EaseFunc QuartOut; - static EaseFunc QuartInOut; - static EaseFunc QuintIn; - static EaseFunc QuintOut; - static EaseFunc QuintInOut; - static EaseFunc SineIn; - static EaseFunc SineOut; - static EaseFunc SineInOut; + static E2D_API EaseFunc Linear; // 线性 + static E2D_API EaseFunc EaseIn; // 由慢变快 + static E2D_API EaseFunc EaseOut; // 由快变慢 + static E2D_API EaseFunc EaseInOut; // 由慢变快, 再由快变慢 + static E2D_API EaseFunc ExpoIn; // 由慢变极快 + static E2D_API EaseFunc ExpoOut; // 由极快变慢 + static E2D_API EaseFunc ExpoInOut; // 由慢至极快, 再由极快边慢 + static E2D_API EaseFunc ElasticIn; // 自起点赋予弹性 + static E2D_API EaseFunc ElasticOut; // 自终点赋予弹性 + static E2D_API EaseFunc ElasticInOut; // 再起点和终点赋予弹性 + static E2D_API EaseFunc BounceIn; // 自起点赋予反弹力 + static E2D_API EaseFunc BounceOut; // 自终点赋予反弹力 + static E2D_API EaseFunc BounceInOut; // 在起点和终点赋予反弹力 + static E2D_API EaseFunc BackIn; + static E2D_API EaseFunc BackOut; + static E2D_API EaseFunc BackInOut; + static E2D_API EaseFunc QuadIn; + static E2D_API EaseFunc QuadOut; + static E2D_API EaseFunc QuadInOut; + static E2D_API EaseFunc CubicIn; + static E2D_API EaseFunc CubicOut; + static E2D_API EaseFunc CubicInOut; + static E2D_API EaseFunc QuartIn; + static E2D_API EaseFunc QuartOut; + static E2D_API EaseFunc QuartInOut; + static E2D_API EaseFunc QuintIn; + static E2D_API EaseFunc QuintOut; + static E2D_API EaseFunc QuintInOut; + static E2D_API EaseFunc SineIn; + static E2D_API EaseFunc SineOut; + static E2D_API EaseFunc SineInOut; }; inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); } @@ -74,7 +75,7 @@ namespace easy2d // 补间动画 - class ActionTween + class E2D_API ActionTween : public Action { public: @@ -113,7 +114,7 @@ namespace easy2d // 相对位移动作 - class MoveBy + class E2D_API MoveBy : public ActionTween { public: @@ -142,7 +143,7 @@ namespace easy2d // 位移动作 - class MoveTo + class E2D_API MoveTo : public MoveBy { public: @@ -171,7 +172,7 @@ namespace easy2d // 相对跳跃动作 - class JumpBy + class E2D_API JumpBy : public ActionTween { public: @@ -204,7 +205,7 @@ namespace easy2d // 跳跃动作 - class JumpTo + class E2D_API JumpTo : public JumpBy { public: @@ -235,7 +236,7 @@ namespace easy2d // 相对缩放动作 - class ScaleBy + class E2D_API ScaleBy : public ActionTween { public: @@ -272,7 +273,7 @@ namespace easy2d // 缩放动作 - class ScaleTo + class E2D_API ScaleTo : public ScaleBy { public: @@ -309,7 +310,7 @@ namespace easy2d // 透明度相对渐变动作 - class OpacityBy + class E2D_API OpacityBy : public ActionTween { public: @@ -337,7 +338,7 @@ namespace easy2d // 透明度渐变动作 - class OpacityTo + class E2D_API OpacityTo : public OpacityBy { public: @@ -366,7 +367,7 @@ namespace easy2d // 淡入动作 - class FadeIn + class E2D_API FadeIn : public OpacityTo { public: @@ -379,7 +380,7 @@ namespace easy2d // 淡出动作 - class FadeOut + class E2D_API FadeOut : public OpacityTo { public: @@ -392,7 +393,7 @@ namespace easy2d // 相对旋转动作 - class RotateBy + class E2D_API RotateBy : public ActionTween { public: @@ -420,7 +421,7 @@ namespace easy2d // 旋转动作 - class RotateTo + class E2D_API RotateTo : public RotateBy { public: @@ -449,7 +450,7 @@ namespace easy2d // 路径动作 - class PathAction + class E2D_API PathAction : public ActionTween { public: diff --git a/src/core/Animation.h b/src/core/Animation.h index 8345218d..1a944c76 100644 --- a/src/core/Animation.h +++ b/src/core/Animation.h @@ -24,7 +24,7 @@ namespace easy2d { // 帧动画 - class Animation + class E2D_API Animation : public ActionTween { public: diff --git a/src/core/Application.cpp b/src/core/Application.cpp index 725aaacc..38093906 100644 --- a/src/core/Application.cpp +++ b/src/core/Application.cpp @@ -34,8 +34,20 @@ namespace easy2d { + Options::Options() + : title(L"Easy2D Game") + , width(640) + , height(480) + , icon(nullptr) + , vsync(true) + , fullscreen(false) + , debug(false) + {} + Application::Application(String const& app_name) - : debug_(false) + : end_(true) + , inited_(false) + , debug_(false) , curr_scene_(nullptr) , next_scene_(nullptr) , transition_(nullptr) @@ -47,6 +59,8 @@ namespace easy2d Application::~Application() { + Destroy(); + ::CoUninitialize(); } @@ -130,6 +144,8 @@ namespace easy2d // use Application instance in message loop ::SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(this)); + + inited_ = true; } void Application::Run() @@ -138,10 +154,12 @@ namespace easy2d if (hwnd) { + end_ = false; + Window::Instance()->Prepare(); MSG msg = {}; - while (::GetMessageW(&msg, nullptr, 0, 0)) + while (::GetMessageW(&msg, nullptr, 0, 0) && !end_) { ::TranslateMessage(&msg); ::DispatchMessageW(&msg); @@ -151,14 +169,24 @@ namespace easy2d void Application::Quit() { - Window::Instance()->Destroy(); + end_ = true; } void Application::Destroy() { - transition_ = nullptr; - next_scene_ = nullptr; - curr_scene_ = nullptr; + if (inited_) + { + inited_ = false; + + transition_.Reset(); + next_scene_.Reset(); + curr_scene_.Reset(); + + Audio::Instance()->Destroy(); + RenderSystem::Instance()->Destroy(); + Window::Instance()->Destroy(); + Factory::Instance()->Destroy(); + } } void Application::EnterScene(ScenePtr const & scene) diff --git a/src/core/Application.h b/src/core/Application.h index 8c84ba28..20ad57c7 100644 --- a/src/core/Application.h +++ b/src/core/Application.h @@ -38,19 +38,11 @@ namespace easy2d bool fullscreen; // 全屏模式 bool debug; // 调试模式 - Options() - : title(L"Easy2D Game") - , width(640) - , height(480) - , icon(nullptr) - , vsync(true) - , fullscreen(false) - , debug(false) - {} + E2D_API Options(); }; - class Application + class E2D_API Application : protected Noncopyable { public: @@ -111,6 +103,8 @@ namespace easy2d static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); private: + bool end_; + bool inited_; bool debug_; float time_scale_; String app_name_; diff --git a/src/core/Canvas.h b/src/core/Canvas.h index 2a73799e..8ada5b0e 100644 --- a/src/core/Canvas.h +++ b/src/core/Canvas.h @@ -29,7 +29,7 @@ namespace easy2d { // 画布 - class Canvas + class E2D_API Canvas : public Node { public: diff --git a/src/core/Color.h b/src/core/Color.h index bff84bb6..8185f1fa 100644 --- a/src/core/Color.h +++ b/src/core/Color.h @@ -30,7 +30,7 @@ namespace easy2d // 使用 RGBA 表示一个带透明度的颜色: Color not_black(1.0f, 1.0f, 1.0f, 0.5f); // 使用一个 unsigned int 类型的值表示 RGB: Color black(0x000000); // - class Color + class E2D_API Color { public: Color(); diff --git a/src/core/DebugNode.h b/src/core/DebugNode.h index 34e92a14..fcf2652a 100644 --- a/src/core/DebugNode.h +++ b/src/core/DebugNode.h @@ -25,7 +25,7 @@ namespace easy2d { - class DebugNode + class E2D_API DebugNode : public Node , public ISingleton { diff --git a/src/core/Delay.h b/src/core/Delay.h index fe8f453a..9a15a557 100644 --- a/src/core/Delay.h +++ b/src/core/Delay.h @@ -23,8 +23,8 @@ namespace easy2d { - // 延时 - class Delay + // 延时动作 + class E2D_API Delay : public Action { public: diff --git a/src/core/Event.hpp b/src/core/Event.hpp index b57f4e74..1fd33fa8 100644 --- a/src/core/Event.hpp +++ b/src/core/Event.hpp @@ -137,7 +137,7 @@ namespace easy2d }; // 事件 - struct Event + struct E2D_API Event { EventType type; Node* target; diff --git a/src/core/EventDispatcher.h b/src/core/EventDispatcher.h index 90bc7411..332a03c9 100644 --- a/src/core/EventDispatcher.h +++ b/src/core/EventDispatcher.h @@ -23,7 +23,7 @@ namespace easy2d { - class EventDispatcher + class E2D_API EventDispatcher { using Listeners = IntrusiveList; diff --git a/src/core/EventListener.h b/src/core/EventListener.h index 576ba65d..820cc310 100644 --- a/src/core/EventListener.h +++ b/src/core/EventListener.h @@ -29,7 +29,7 @@ namespace easy2d class EventDispatcher; - class EventListener + class E2D_API EventListener : public virtual Object , protected IntrusiveListItem { diff --git a/src/core/Factory.cpp b/src/core/Factory.cpp index 13cff748..848b2288 100644 --- a/src/core/Factory.cpp +++ b/src/core/Factory.cpp @@ -31,7 +31,6 @@ namespace easy2d Factory::~Factory() { - E2D_LOG(L"Destroying device-independent resources"); } HRESULT Factory::Init(bool debug) @@ -111,6 +110,18 @@ namespace easy2d return hr; } + void Factory::Destroy() + { + E2D_LOG(L"Destroying device-independent resources"); + + factory_.Reset(); + imaging_factory_.Reset(); + write_factory_.Reset(); + miter_stroke_style_.Reset(); + bevel_stroke_style_.Reset(); + round_stroke_style_.Reset(); + } + HRESULT Factory::CreateHwndRenderTarget(D2DHwndRenderTargetPtr & hwnd_render_target, D2D1_RENDER_TARGET_PROPERTIES const & properties, D2D1_HWND_RENDER_TARGET_PROPERTIES const & hwnd_rt_properties) const { if (!factory_) diff --git a/src/core/Factory.h b/src/core/Factory.h index e0c17eec..dce7e937 100644 --- a/src/core/Factory.h +++ b/src/core/Factory.h @@ -28,7 +28,7 @@ namespace easy2d { - class Factory + class E2D_API Factory : public ISingleton { E2D_DECLARE_SINGLETON(Factory); @@ -36,68 +36,70 @@ namespace easy2d public: HRESULT Init(bool debug); + void Destroy(); + HRESULT CreateHwndRenderTarget( - D2DHwndRenderTargetPtr& hwnd_render_target, + _Out_ D2DHwndRenderTargetPtr& hwnd_render_target, D2D1_RENDER_TARGET_PROPERTIES const& properties, D2D1_HWND_RENDER_TARGET_PROPERTIES const& hwnd_rt_properties ) const; HRESULT CreateTextRenderer( - D2DTextRendererPtr& text_renderer, + _Out_ D2DTextRendererPtr& text_renderer, D2DRenderTargetPtr const& render_target, D2DSolidColorBrushPtr const& brush ); HRESULT CreateBitmapFromFile( - D2DBitmapPtr& bitmap, + _Out_ D2DBitmapPtr& bitmap, D2DRenderTargetPtr const& rt, String const& file_path ); HRESULT CreateBitmapFromResource( - D2DBitmapPtr& bitmap, + _Out_ D2DBitmapPtr& bitmap, D2DRenderTargetPtr const& rt, Resource const& res ); HRESULT CreateRectangleGeometry( - D2DRectangleGeometryPtr& geo, + _Out_ D2DRectangleGeometryPtr& geo, Rect const& rect ) const; HRESULT CreateRoundedRectangleGeometry( - D2DRoundedRectangleGeometryPtr& geo, + _Out_ D2DRoundedRectangleGeometryPtr& geo, Rect const& rect, float radius_x, float radius_y ) const; HRESULT CreateEllipseGeometry( - D2DEllipseGeometryPtr& geo, + _Out_ D2DEllipseGeometryPtr& geo, Point const& center, float radius_x, float radius_y ) const; HRESULT CreateTransformedGeometry( - D2DTransformedGeometryPtr& transformed, + _Out_ D2DTransformedGeometryPtr& transformed, Matrix const& matrix, D2DGeometryPtr const& geo ) const; HRESULT CreatePathGeometry( - D2DPathGeometryPtr& geometry + _Out_ D2DPathGeometryPtr& geometry ) const; HRESULT CreateTextFormat( - D2DTextFormatPtr& text_format, + _Out_ D2DTextFormatPtr& text_format, Font const& font, TextStyle const& text_style ) const; HRESULT CreateTextLayout( - D2DTextLayoutPtr& text_layout, - Size& layout_size, + _Out_ D2DTextLayoutPtr& text_layout, + _Out_ Size& layout_size, String const& text, D2DTextFormatPtr const& text_format, TextStyle const& text_style diff --git a/src/core/Frames.h b/src/core/Frames.h index 05a835db..c6ba9675 100644 --- a/src/core/Frames.h +++ b/src/core/Frames.h @@ -25,7 +25,7 @@ namespace easy2d { // 帧集合 - class Frames + class E2D_API Frames : public virtual Object { public: diff --git a/src/core/Geometry.h b/src/core/Geometry.h index 219e4623..917113d9 100644 --- a/src/core/Geometry.h +++ b/src/core/Geometry.h @@ -24,7 +24,7 @@ namespace easy2d { // 几何抽象 - class Geometry + class E2D_API Geometry : public virtual Object { friend class Canvas; @@ -62,7 +62,7 @@ namespace easy2d // 直线 - class LineGeometry + class E2D_API LineGeometry : public Geometry { public: @@ -99,7 +99,7 @@ namespace easy2d // 几何矩形 - class RectangleGeometry + class E2D_API RectangleGeometry : public Geometry { public: @@ -126,7 +126,7 @@ namespace easy2d // 几何圆形 - class CircleGeometry + class E2D_API CircleGeometry : public Geometry { public: @@ -163,7 +163,7 @@ namespace easy2d // 几何椭圆 - class EllipseGeometry + class E2D_API EllipseGeometry : public Geometry { public: @@ -206,7 +206,7 @@ namespace easy2d // 几何路径 - class PathGeometry + class E2D_API PathGeometry : public Geometry { public: @@ -260,7 +260,7 @@ namespace easy2d // 几何圆角矩形 - class RoundedRectGeometry + class E2D_API RoundedRectGeometry : public Geometry { public: diff --git a/src/core/GeometryNode.h b/src/core/GeometryNode.h index 7ab3c6ff..00a1b9f1 100644 --- a/src/core/GeometryNode.h +++ b/src/core/GeometryNode.h @@ -25,7 +25,7 @@ namespace easy2d { // 几何图形 - class GeometryNode + class E2D_API GeometryNode : public Node { public: diff --git a/src/core/Image.cpp b/src/core/Image.cpp index 5a505e40..f15d7afa 100644 --- a/src/core/Image.cpp +++ b/src/core/Image.cpp @@ -64,7 +64,7 @@ namespace easy2d { if (!File(res.GetFileName()).Exists()) { - E2D_WARNING_LOG(L"Image file '%s' not found!", res.GetFileName()); + E2D_WARNING_LOG(L"Image file '%s' not found!", res.GetFileName().c_str()); return false; } hr = RenderSystem::Instance()->CreateBitmapFromFile(bitmap, res.GetFileName()); diff --git a/src/core/Image.h b/src/core/Image.h index b2ba8440..ed525586 100644 --- a/src/core/Image.h +++ b/src/core/Image.h @@ -25,7 +25,7 @@ namespace easy2d { // 图片 - class Image + class E2D_API Image : public virtual Object { public: @@ -97,7 +97,7 @@ namespace easy2d ); protected: - Rect crop_rect_; + Rect crop_rect_; D2DBitmapPtr bitmap_; }; } diff --git a/src/core/Input.cpp b/src/core/Input.cpp index 2ba5ccb7..e1d2b4ca 100644 --- a/src/core/Input.cpp +++ b/src/core/Input.cpp @@ -35,15 +35,12 @@ namespace easy2d Input::~Input() { - E2D_LOG(L"Destroying input device"); } HRESULT Input::Init(HWND hwnd, bool debug) { E2D_NOT_USED(debug); - E2D_LOG(L"Initing input device"); - hwnd_ = hwnd; return S_OK; diff --git a/src/core/Input.h b/src/core/Input.h index 7a91e101..371e82b2 100644 --- a/src/core/Input.h +++ b/src/core/Input.h @@ -25,7 +25,7 @@ namespace easy2d { - class Input + class E2D_API Input : public ISingleton { E2D_DECLARE_SINGLETON(Input); diff --git a/src/core/IntrusiveList.hpp b/src/core/IntrusiveList.hpp index 543f581a..729f9193 100644 --- a/src/core/IntrusiveList.hpp +++ b/src/core/IntrusiveList.hpp @@ -22,11 +22,10 @@ #include "macros.h" #include -#undef DEBUG_CHECK_LIST #ifdef E2D_DEBUG -# define DEBUG_CHECK_LIST(list_ptr) list_ptr->Check() +# define E2D_DEBUG_CHECK_LIST(list_ptr) list_ptr->Check() #else -# define DEBUG_CHECK_LIST __noop +# define E2D_DEBUG_CHECK_LIST __noop #endif namespace easy2d @@ -101,7 +100,7 @@ namespace easy2d last_ = child; - DEBUG_CHECK_LIST(this); + E2D_DEBUG_CHECK_LIST(this); } void PushFront(T const& child) @@ -125,7 +124,7 @@ namespace easy2d first_ = child; - DEBUG_CHECK_LIST(this); + E2D_DEBUG_CHECK_LIST(this); } void InsertBefore(T const& child, T const& before) @@ -144,7 +143,7 @@ namespace easy2d child->next_ = before; before->prev_ = child; - DEBUG_CHECK_LIST(this); + E2D_DEBUG_CHECK_LIST(this); } void InsertAfter(T const& child, T const& after) @@ -163,7 +162,7 @@ namespace easy2d child->prev_ = after; after->next_ = child; - DEBUG_CHECK_LIST(this); + E2D_DEBUG_CHECK_LIST(this); } void Remove(T const& child) @@ -198,7 +197,7 @@ namespace easy2d child->prev_ = nullptr; child->next_ = nullptr; - DEBUG_CHECK_LIST(this); + E2D_DEBUG_CHECK_LIST(this); } void Clear() @@ -250,4 +249,4 @@ namespace easy2d }; } -#undef DEBUG_CHECK_LIST +#undef E2D_DEBUG_CHECK_LIST diff --git a/src/core/Music.cpp b/src/core/Music.cpp index 8f447a3a..c54b24e9 100644 --- a/src/core/Music.cpp +++ b/src/core/Music.cpp @@ -62,7 +62,7 @@ namespace easy2d { if (!File(res.GetFileName()).Exists()) { - E2D_WARNING_LOG(L"Media file '%s' not found", res.GetFileName()); + E2D_WARNING_LOG(L"Media file '%s' not found", res.GetFileName().c_str()); return false; } hr = transcoder.LoadMediaFile(res.GetFileName(), &wave_data_, &size_); diff --git a/src/core/Music.h b/src/core/Music.h index 1fcaedef..298a044d 100644 --- a/src/core/Music.h +++ b/src/core/Music.h @@ -26,7 +26,7 @@ namespace easy2d { // 音乐 - class Music + class E2D_API Music : public virtual Object { public: diff --git a/src/core/Node.h b/src/core/Node.h index de59649a..300c7edc 100644 --- a/src/core/Node.h +++ b/src/core/Node.h @@ -32,7 +32,7 @@ namespace easy2d class Application; // 节点 - class Node + class E2D_API Node : public virtual Object , public TaskManager , public ActionManager diff --git a/src/core/Object.h b/src/core/Object.h index 24d8d16e..53d6e0c6 100644 --- a/src/core/Object.h +++ b/src/core/Object.h @@ -24,7 +24,7 @@ namespace easy2d { - class Object + class E2D_API Object : public RefCounter { public: diff --git a/src/core/RefCounter.hpp b/src/core/RefCounter.hpp index 6c3681e2..7c08c578 100644 --- a/src/core/RefCounter.hpp +++ b/src/core/RefCounter.hpp @@ -24,7 +24,7 @@ namespace easy2d { - class RefCounter + class E2D_API RefCounter : protected Noncopyable { public: diff --git a/src/core/Resource.h b/src/core/Resource.h index 47570c15..ecf39447 100644 --- a/src/core/Resource.h +++ b/src/core/Resource.h @@ -31,7 +31,7 @@ namespace easy2d // // 了解资源的更多信息: https://docs.microsoft.com/en-us/windows/desktop/menurc/resources // - class Resource + class E2D_API Resource { enum class Type { File, Binary }; diff --git a/src/core/Scene.h b/src/core/Scene.h index 7416bfb8..3e40a66d 100644 --- a/src/core/Scene.h +++ b/src/core/Scene.h @@ -24,7 +24,7 @@ namespace easy2d { // 场景 - class Scene + class E2D_API Scene : public Node { public: diff --git a/src/core/Sprite.h b/src/core/Sprite.h index bc3beb06..ed03aea6 100644 --- a/src/core/Sprite.h +++ b/src/core/Sprite.h @@ -25,7 +25,7 @@ namespace easy2d { // 精灵 - class Sprite + class E2D_API Sprite : public Node { public: diff --git a/src/core/Task.h b/src/core/Task.h index a5c49d85..0ca3036f 100644 --- a/src/core/Task.h +++ b/src/core/Task.h @@ -29,7 +29,7 @@ namespace easy2d class TaskManager; // 定时任务 - class Task + class E2D_API Task : public virtual Object , protected IntrusiveListItem { diff --git a/src/core/TaskManager.h b/src/core/TaskManager.h index c5ad7b16..00e5360c 100644 --- a/src/core/TaskManager.h +++ b/src/core/TaskManager.h @@ -23,7 +23,7 @@ namespace easy2d { - class TaskManager + class E2D_API TaskManager { using Tasks = IntrusiveList; diff --git a/src/core/Text.h b/src/core/Text.h index e09798f7..d33c0bf1 100644 --- a/src/core/Text.h +++ b/src/core/Text.h @@ -26,7 +26,7 @@ namespace easy2d { // 文本 - class Text + class E2D_API Text : public Node { public: diff --git a/src/core/TextRenderer.cpp b/src/core/TextRenderer.cpp index f4a43f00..028bb4b7 100644 --- a/src/core/TextRenderer.cpp +++ b/src/core/TextRenderer.cpp @@ -24,7 +24,113 @@ namespace easy2d { - ITextRenderer::ITextRenderer(ID2D1Factory* pD2DFactory, ID2D1RenderTarget* pRT, ID2D1SolidColorBrush* pBrush) + class TextRendererImpl + : public ITextRenderer + { + public: + TextRendererImpl( + ID2D1Factory* pD2DFactory, + ID2D1RenderTarget* pRT, + ID2D1SolidColorBrush* pBrush + ); + + ~TextRendererImpl(); + + STDMETHOD_(void, SetTextStyle)( + CONST D2D1_COLOR_F &fillColor, + BOOL outline, + CONST D2D1_COLOR_F &outlineColor, + FLOAT outlineWidth, + ID2D1StrokeStyle* outlineJoin + ); + + STDMETHOD(DrawGlyphRun)( + __maybenull void* clientDrawingContext, + FLOAT baselineOriginX, + FLOAT baselineOriginY, + DWRITE_MEASURING_MODE measuringMode, + __in DWRITE_GLYPH_RUN const* glyphRun, + __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, + IUnknown* clientDrawingEffect + ); + + STDMETHOD(DrawUnderline)( + __maybenull void* clientDrawingContext, + FLOAT baselineOriginX, + FLOAT baselineOriginY, + __in DWRITE_UNDERLINE const* underline, + IUnknown* clientDrawingEffect + ); + + STDMETHOD(DrawStrikethrough)( + __maybenull void* clientDrawingContext, + FLOAT baselineOriginX, + FLOAT baselineOriginY, + __in DWRITE_STRIKETHROUGH const* strikethrough, + IUnknown* clientDrawingEffect + ); + + STDMETHOD(DrawInlineObject)( + __maybenull void* clientDrawingContext, + FLOAT originX, + FLOAT originY, + IDWriteInlineObject* inlineObject, + BOOL IsSideways, + BOOL IsRightToLeft, + IUnknown* clientDrawingEffect + ); + + 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(); + unsigned long STDMETHODCALLTYPE Release(); + HRESULT STDMETHODCALLTYPE QueryInterface( + IID const& riid, + void** ppvObject + ); + + private: + unsigned long cRefCount_; + D2D1_COLOR_F sFillColor_; + D2D1_COLOR_F sOutlineColor_; + FLOAT fOutlineWidth; + BOOL bShowOutline_; + ID2D1Factory* pD2DFactory_; + ID2D1RenderTarget* pRT_; + ID2D1SolidColorBrush* pBrush_; + ID2D1StrokeStyle* pCurrStrokeStyle_; + }; + + HRESULT ITextRenderer::Create( + ITextRenderer** ppTextRenderer, + ID2D1Factory* pD2DFactory, + ID2D1RenderTarget* pRT, + ID2D1SolidColorBrush* pBrush) + { + *ppTextRenderer = new (std::nothrow) TextRendererImpl(pD2DFactory, pRT, pBrush); + if (*ppTextRenderer) + { + (*ppTextRenderer)->AddRef(); + return S_OK; + } + return E_FAIL; + } + + TextRendererImpl::TextRendererImpl(ID2D1Factory* pD2DFactory, ID2D1RenderTarget* pRT, ID2D1SolidColorBrush* pBrush) : cRefCount_(0) , pD2DFactory_(pD2DFactory) , pRT_(pRT) @@ -40,29 +146,14 @@ namespace easy2d pBrush->AddRef(); } - ITextRenderer::~ITextRenderer() + TextRendererImpl::~TextRendererImpl() { SafeRelease(pD2DFactory_); SafeRelease(pRT_); SafeRelease(pBrush_); } - HRESULT ITextRenderer::Create( - ITextRenderer** ppTextRenderer, - ID2D1Factory* pD2DFactory, - ID2D1RenderTarget* pRT, - ID2D1SolidColorBrush* pBrush) - { - *ppTextRenderer = new (std::nothrow) ITextRenderer(pD2DFactory, pRT, pBrush); - if (*ppTextRenderer) - { - (*ppTextRenderer)->AddRef(); - return S_OK; - } - return E_FAIL; - } - - STDMETHODIMP_(void) ITextRenderer::SetTextStyle( + STDMETHODIMP_(void) TextRendererImpl::SetTextStyle( CONST D2D1_COLOR_F &fillColor, BOOL outline, CONST D2D1_COLOR_F &outlineColor, @@ -76,7 +167,7 @@ namespace easy2d pCurrStrokeStyle_ = outlineJoin; } - STDMETHODIMP ITextRenderer::DrawGlyphRun( + STDMETHODIMP TextRendererImpl::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -169,7 +260,7 @@ namespace easy2d return hr; } - STDMETHODIMP ITextRenderer::DrawUnderline( + STDMETHODIMP TextRendererImpl::DrawUnderline( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -238,7 +329,7 @@ namespace easy2d return S_OK; } - STDMETHODIMP ITextRenderer::DrawStrikethrough( + STDMETHODIMP TextRendererImpl::DrawStrikethrough( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -307,7 +398,7 @@ namespace easy2d return S_OK; } - STDMETHODIMP ITextRenderer::DrawInlineObject( + STDMETHODIMP TextRendererImpl::DrawInlineObject( __maybenull void* clientDrawingContext, FLOAT originX, FLOAT originY, @@ -326,12 +417,12 @@ namespace easy2d return E_NOTIMPL; } - STDMETHODIMP_(unsigned long) ITextRenderer::AddRef() + STDMETHODIMP_(unsigned long) TextRendererImpl::AddRef() { return InterlockedIncrement(&cRefCount_); } - STDMETHODIMP_(unsigned long) ITextRenderer::Release() + STDMETHODIMP_(unsigned long) TextRendererImpl::Release() { unsigned long newCount = InterlockedDecrement(&cRefCount_); @@ -344,7 +435,7 @@ namespace easy2d return newCount; } - STDMETHODIMP ITextRenderer::IsPixelSnappingDisabled( + STDMETHODIMP TextRendererImpl::IsPixelSnappingDisabled( __maybenull void* clientDrawingContext, __out BOOL* isDisabled) { @@ -354,7 +445,7 @@ namespace easy2d return S_OK; } - STDMETHODIMP ITextRenderer::GetCurrentTransform( + STDMETHODIMP TextRendererImpl::GetCurrentTransform( __maybenull void* clientDrawingContext, __out DWRITE_MATRIX* transform) { @@ -364,7 +455,7 @@ namespace easy2d return S_OK; } - STDMETHODIMP ITextRenderer::GetPixelsPerDip( + STDMETHODIMP TextRendererImpl::GetPixelsPerDip( __maybenull void* clientDrawingContext, __out FLOAT* pixelsPerDip) { @@ -378,7 +469,7 @@ namespace easy2d return S_OK; } - STDMETHODIMP ITextRenderer::QueryInterface( + STDMETHODIMP TextRendererImpl::QueryInterface( IID const& riid, void** ppvObject) { diff --git a/src/core/TextRenderer.h b/src/core/TextRenderer.h index e9b7cf86..d70a56dc 100644 --- a/src/core/TextRenderer.h +++ b/src/core/TextRenderer.h @@ -23,15 +23,15 @@ namespace easy2d { - class ITextRenderer + interface ITextRenderer : public IDWriteTextRenderer { public: - static HRESULT Create( - ITextRenderer** ppTextRenderer, - ID2D1Factory* pD2DFactory, - ID2D1RenderTarget* pRT, - ID2D1SolidColorBrush* pBrush + static E2D_API HRESULT Create( + _Out_ ITextRenderer** ppTextRenderer, + _In_ ID2D1Factory* pD2DFactory, + _In_ ID2D1RenderTarget* pRT, + _In_ ID2D1SolidColorBrush* pBrush ); STDMETHOD_(void, SetTextStyle)( @@ -39,87 +39,8 @@ namespace easy2d BOOL outline, CONST D2D1_COLOR_F &outlineColor, FLOAT outlineWidth, - ID2D1StrokeStyle* outlineJoin - ); - - STDMETHOD(DrawGlyphRun)( - __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, - DWRITE_MEASURING_MODE measuringMode, - __in DWRITE_GLYPH_RUN const* glyphRun, - __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, - IUnknown* clientDrawingEffect - ); - - STDMETHOD(DrawUnderline)( - __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, - __in DWRITE_UNDERLINE const* underline, - IUnknown* clientDrawingEffect - ); - - STDMETHOD(DrawStrikethrough)( - __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, - __in DWRITE_STRIKETHROUGH const* strikethrough, - IUnknown* clientDrawingEffect - ); - - STDMETHOD(DrawInlineObject)( - __maybenull void* clientDrawingContext, - FLOAT originX, - FLOAT originY, - IDWriteInlineObject* inlineObject, - BOOL IsSideways, - BOOL IsRightToLeft, - IUnknown* clientDrawingEffect - ); - - 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(); - unsigned long STDMETHODCALLTYPE Release(); - HRESULT STDMETHODCALLTYPE QueryInterface( - IID const& riid, - void** ppvObject - ); - - private: - ITextRenderer( - ID2D1Factory* pD2DFactory, - ID2D1RenderTarget* pRT, - ID2D1SolidColorBrush* pBrush - ); - - ~ITextRenderer(); - - private: - unsigned long cRefCount_; - D2D1_COLOR_F sFillColor_; - D2D1_COLOR_F sOutlineColor_; - FLOAT fOutlineWidth; - BOOL bShowOutline_; - ID2D1Factory* pD2DFactory_; - ID2D1RenderTarget* pRT_; - ID2D1SolidColorBrush* pBrush_; - ID2D1StrokeStyle* pCurrStrokeStyle_; + _In_ ID2D1StrokeStyle* outlineJoin + ) PURE; }; } diff --git a/src/core/TextStyle.hpp b/src/core/TextStyle.hpp index f154d523..c9143d12 100644 --- a/src/core/TextStyle.hpp +++ b/src/core/TextStyle.hpp @@ -32,7 +32,7 @@ namespace easy2d }; // 文本样式 - class TextStyle + class E2D_API TextStyle { public: Color color; // 颜色 diff --git a/src/core/Transform.hpp b/src/core/Transform.hpp index 34c46a94..72cfea85 100644 --- a/src/core/Transform.hpp +++ b/src/core/Transform.hpp @@ -23,7 +23,7 @@ namespace easy2d { - class Transform + class E2D_API Transform { public: float rotation; // 旋转 diff --git a/src/core/Transition.h b/src/core/Transition.h index a4dfca8b..6e9143bb 100644 --- a/src/core/Transition.h +++ b/src/core/Transition.h @@ -27,7 +27,7 @@ namespace easy2d class Scene; // 场景过渡 - class Transition + class E2D_API Transition : public virtual Object { friend class Application; diff --git a/src/core/audio.cpp b/src/core/audio.cpp index 8893d180..6c2519fd 100644 --- a/src/core/audio.cpp +++ b/src/core/audio.cpp @@ -167,26 +167,13 @@ namespace easy2d Audio::~Audio() { - E2D_LOG(L"Destroying audio device"); - - ClearVoiceCache(); - - if (mastering_voice_) - { - mastering_voice_->DestroyVoice(); - mastering_voice_ = nullptr; - } - - SafeRelease(x_audio2_); - - modules::MediaFoundation::Get().MFShutdown(); } HRESULT Audio::Init(bool debug) { E2D_NOT_USED(debug); - E2D_LOG(L"Initing audio device"); + E2D_LOG(L"Initing audio resources"); HRESULT hr = modules::MediaFoundation::Get().MFStartup(MF_VERSION, MFSTARTUP_FULL); @@ -203,6 +190,23 @@ namespace easy2d return hr; } + void Audio::Destroy() + { + E2D_LOG(L"Destroying audio resources"); + + ClearVoiceCache(); + + if (mastering_voice_) + { + mastering_voice_->DestroyVoice(); + mastering_voice_ = nullptr; + } + + SafeRelease(x_audio2_); + + modules::MediaFoundation::Get().MFShutdown(); + } + HRESULT Audio::CreateVoice(Voice& voice, const WAVEFORMATEX* wfx) { HRESULT hr; diff --git a/src/core/audio.h b/src/core/audio.h index 6b6651f3..584ff465 100644 --- a/src/core/audio.h +++ b/src/core/audio.h @@ -27,7 +27,7 @@ namespace easy2d { - class Voice + class E2D_API Voice : protected Noncopyable { public: @@ -74,7 +74,7 @@ namespace easy2d }; - class Audio + class E2D_API Audio : public ISingleton