diff --git a/core/Action/Action.cpp b/core/Action/Action.cpp index 68aac364..8e311992 100644 --- a/core/Action/Action.cpp +++ b/core/Action/Action.cpp @@ -58,7 +58,7 @@ e2d::String e2d::Action::getName() const return m_sName; } -void e2d::Action::setName(String& name) +void e2d::Action::setName(String name) { m_sName = name; } diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index f7bb623a..e7fa57e2 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -12,7 +12,7 @@ static bool s_bInitialized = false; static e2d::String s_sAppName; -bool e2d::Game::init(String& sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID, String sAppname) +bool e2d::Game::init(String sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID, String sAppname) { if (s_bInitialized) { diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp index bc33e2ce..674a28df 100644 --- a/core/Base/Input.cpp +++ b/core/Base/Input.cpp @@ -191,7 +191,7 @@ void e2d::Input::add(Function func, String name) (new Listener(func, name))->start(); } -void e2d::Input::start(String& name) +void e2d::Input::start(String name) { for (const auto & pListener : s_vListeners) { @@ -202,7 +202,7 @@ void e2d::Input::start(String& name) } } -void e2d::Input::stop(String& name) +void e2d::Input::stop(String name) { for (const auto & pListener : s_vListeners) { @@ -213,7 +213,7 @@ void e2d::Input::stop(String& name) } } -void e2d::Input::clear(String& name) +void e2d::Input::clear(String name) { for (const auto & pListener : s_vListeners) { @@ -248,7 +248,7 @@ void e2d::Input::clearAll() } } -std::vector e2d::Input::get(String& name) +std::vector e2d::Input::get(String name) { std::vector vListeners; for (auto pListener : s_vListeners) diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp index 18ce644f..9c76b253 100644 --- a/core/Base/Window.cpp +++ b/core/Base/Window.cpp @@ -9,7 +9,7 @@ static HWND s_HWnd = nullptr; static bool s_bShowConsole = false; -bool e2d::Window::__init(String& sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID /*= nullptr*/) +bool e2d::Window::__init(const String& sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID /*= nullptr*/) { if (!Window::__initMutex(sTitle)) { @@ -106,7 +106,7 @@ bool e2d::Window::__init(String& sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR return SUCCEEDED(hr); } -bool e2d::Window::__initMutex(String& sTitle) +bool e2d::Window::__initMutex(const String& sTitle) { // 创建进程互斥体 HANDLE m_hMutex = ::CreateMutex(NULL, TRUE, L"Easy2DApp-" + sTitle); @@ -204,7 +204,7 @@ void e2d::Window::setSize(UINT32 width, UINT32 height) ::MoveWindow(s_HWnd, (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE); } -void e2d::Window::setTitle(String&title) +void e2d::Window::setTitle(String title) { // 设置窗口标题 ::SetWindowText(s_HWnd, title); diff --git a/core/Common/Font.cpp b/core/Common/Font.cpp index 9b4d9b17..c7186482 100644 --- a/core/Common/Font.cpp +++ b/core/Common/Font.cpp @@ -50,7 +50,7 @@ bool e2d::Font::isItalic() const return m_bItalic; } -void e2d::Font::setFamily(String& fontFamily) +void e2d::Font::setFamily(String fontFamily) { m_sFontFamily = fontFamily; m_bRecreateNeeded = true; @@ -90,14 +90,14 @@ void e2d::Font::_initTextFormat() m_bItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, m_fFontSize, - L"en-us", + L"zh-cn", &m_pTextFormat ); ASSERT(SUCCEEDED(hr), "Create IDWriteTextFormat Failed!"); } -IDWriteTextFormat * e2d::Font::_getTextFormat() +IDWriteTextFormat * e2d::Font::getDWriteTextFormat() { if (m_bRecreateNeeded) { diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index ace6088e..b77c06fd 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -13,12 +13,12 @@ e2d::Image::Image() { } -e2d::Image::Image(String& strFileName) +e2d::Image::Image(String strFileName) { this->open(strFileName); } -e2d::Image::Image(String& strFileName, double nClipX, double nClipY, double nClipWidth, double nClipHeight) +e2d::Image::Image(String strFileName, double nClipX, double nClipY, double nClipWidth, double nClipHeight) { this->open(strFileName); this->clip(nClipX, nClipY, nClipWidth, nClipHeight); @@ -28,7 +28,7 @@ e2d::Image::~Image() { } -void e2d::Image::open(String& strFilePath) +void e2d::Image::open(String strFilePath) { WARN_IF(strFilePath.isEmpty(), "Image cannot load bitmap from NULL file name."); @@ -124,7 +124,7 @@ e2d::Point e2d::Image::getClipPos() const return Point(m_fSourceClipX, m_fSourceClipY); } -bool e2d::Image::preload(String& fileName) +bool e2d::Image::preload(String fileName) { if (s_mBitmapsFromFile.find(fileName.getHashCode()) != s_mBitmapsFromFile.end()) { diff --git a/core/Common/Listener.cpp b/core/Common/Listener.cpp index 01c01cd4..0535c540 100644 --- a/core/Common/Listener.cpp +++ b/core/Common/Listener.cpp @@ -17,7 +17,7 @@ e2d::Listener::Listener(Function func) Input::__add(this); } -e2d::Listener::Listener(Function func, String& name) +e2d::Listener::Listener(Function func, String name) : m_bRunning(false) , m_sName(name) , m_callback(func) @@ -52,7 +52,7 @@ e2d::String e2d::Listener::getName() return m_sName; } -void e2d::Listener::setName(String& name) +void e2d::Listener::setName(String name) { m_sName = name; } diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index 88e18e01..b9904ceb 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -114,7 +114,7 @@ void e2d::ActionManager::__stopAllBindedWith(Node * pTargetNode) } } -void e2d::ActionManager::resume(String& strActionName) +void e2d::ActionManager::resume(String strActionName) { for (auto action : s_vRunningActions) { @@ -125,7 +125,7 @@ void e2d::ActionManager::resume(String& strActionName) } } -void e2d::ActionManager::pause(String& strActionName) +void e2d::ActionManager::pause(String strActionName) { for (auto action : s_vRunningActions) { @@ -136,7 +136,7 @@ void e2d::ActionManager::pause(String& strActionName) } } -void e2d::ActionManager::stop(String& strActionName) +void e2d::ActionManager::stop(String strActionName) { for (auto action : s_vRunningActions) { @@ -191,7 +191,7 @@ void e2d::ActionManager::stopAll() } } -std::vector e2d::ActionManager::get(String& strActionName) +std::vector e2d::ActionManager::get(String strActionName) { std::vector vActions; for (const auto action : s_vActions) diff --git a/core/Manager/MusicManager.cpp b/core/Manager/MusicManager.cpp index 21eb51ab..85006d24 100644 --- a/core/Manager/MusicManager.cpp +++ b/core/Manager/MusicManager.cpp @@ -15,7 +15,7 @@ static MusicList& getMusicList() } -bool e2d::MusicManager::preload(String& strFilePath) +bool e2d::MusicManager::preload(String strFilePath) { UINT nRet = strFilePath.getHashCode(); @@ -42,7 +42,7 @@ bool e2d::MusicManager::preload(String& strFilePath) return false; } -bool e2d::MusicManager::play(String& strFilePath, int nLoopCount) +bool e2d::MusicManager::play(String strFilePath, int nLoopCount) { if (MusicManager::preload(strFilePath)) { @@ -56,7 +56,7 @@ bool e2d::MusicManager::play(String& strFilePath, int nLoopCount) return false; } -void e2d::MusicManager::pause(String& strFilePath) +void e2d::MusicManager::pause(String strFilePath) { auto music = MusicManager::get(strFilePath); if (music) @@ -65,7 +65,7 @@ void e2d::MusicManager::pause(String& strFilePath) } } -void e2d::MusicManager::resume(String& strFilePath) +void e2d::MusicManager::resume(String strFilePath) { auto music = MusicManager::get(strFilePath); if (music) @@ -74,7 +74,7 @@ void e2d::MusicManager::resume(String& strFilePath) } } -void e2d::MusicManager::stop(String& strFilePath) +void e2d::MusicManager::stop(String strFilePath) { auto music = MusicManager::get(strFilePath); if (music) @@ -83,7 +83,7 @@ void e2d::MusicManager::stop(String& strFilePath) } } -e2d::Music * e2d::MusicManager::get(String& strFilePath) +e2d::Music * e2d::MusicManager::get(String strFilePath) { if (strFilePath.isEmpty()) return nullptr; diff --git a/core/Manager/TimerManager.cpp b/core/Manager/TimerManager.cpp index bb5c5e3b..e48a1657 100644 --- a/core/Manager/TimerManager.cpp +++ b/core/Manager/TimerManager.cpp @@ -62,7 +62,7 @@ void e2d::TimerManager::__add(Timer * pTimer) } } -void e2d::TimerManager::start(String& name) +void e2d::TimerManager::start(String name) { for (auto timer : s_vTimers) { @@ -73,7 +73,7 @@ void e2d::TimerManager::start(String& name) } } -void e2d::TimerManager::stop(String& name) +void e2d::TimerManager::stop(String name) { for (auto timer : s_vTimers) { @@ -84,7 +84,7 @@ void e2d::TimerManager::stop(String& name) } } -void e2d::TimerManager::clear(String& name) +void e2d::TimerManager::clear(String name) { for (auto timer : s_vTimers) { @@ -95,7 +95,7 @@ void e2d::TimerManager::clear(String& name) } } -std::vector e2d::TimerManager::get(String& name) +std::vector e2d::TimerManager::get(String name) { std::vector vTimers; for (auto timer : s_vTimers) diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 8cf9f0de..9b7faedb 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -211,10 +211,7 @@ void e2d::Node::_onExit() void e2d::Node::_updateTransform() { // 计算中心点坐标 - D2D1_POINT_2F pivot = D2D1::Point2F( - m_fWidth * m_fPivotX, - m_fHeight * m_fPivotY - ); + D2D1_POINT_2F pivot = { m_fWidth * m_fPivotX, m_fHeight * m_fPivotY }; // 变换 Initial 矩阵,子节点将根据这个矩阵进行变换 m_MatriInitial = D2D1::Matrix3x2F::Scale( m_fScaleX, @@ -614,7 +611,7 @@ e2d::Scene * e2d::Node::getParentScene() const return m_pParentScene; } -std::vector e2d::Node::getChildren(String& name) +std::vector e2d::Node::getChildren(String name) { std::vector vChildren; unsigned int hash = name.getHashCode(); @@ -684,7 +681,7 @@ bool e2d::Node::removeChild(Node * child) return false; } -void e2d::Node::removeChildren(String& childName) +void e2d::Node::removeChildren(String childName) { WARN_IF(childName.isEmpty(), "Invalid Node name."); @@ -753,7 +750,7 @@ void e2d::Node::runAction(Action * action) } } -void e2d::Node::resumeAction(String& strActionName) +void e2d::Node::resumeAction(String strActionName) { auto actions = ActionManager::get(strActionName); for (auto action : actions) @@ -765,7 +762,7 @@ void e2d::Node::resumeAction(String& strActionName) } } -void e2d::Node::pauseAction(String& strActionName) +void e2d::Node::pauseAction(String strActionName) { auto actions = ActionManager::get(strActionName); for (auto action : actions) @@ -777,7 +774,7 @@ void e2d::Node::pauseAction(String& strActionName) } } -void e2d::Node::stopAction(String& strActionName) +void e2d::Node::stopAction(String strActionName) { auto actions = ActionManager::get(strActionName); for (auto action : actions) @@ -789,7 +786,7 @@ void e2d::Node::stopAction(String& strActionName) } } -e2d::Action * e2d::Node::getAction(String& strActionName) +e2d::Action * e2d::Node::getAction(String strActionName) { auto actions = ActionManager::get(strActionName); for (auto action : actions) @@ -802,7 +799,7 @@ e2d::Action * e2d::Node::getAction(String& strActionName) return nullptr; } -std::vector e2d::Node::getActions(String& strActionName) +std::vector e2d::Node::getActions(String strActionName) { std::vector::iterator iter; auto actions = ActionManager::get(strActionName); @@ -826,7 +823,7 @@ bool e2d::Node::isPointIn(Point point) const // 如果存在形状,用形状判断 if (m_pShape) { - m_pShape->_getD2dGeometry()->FillContainsPoint( + m_pShape->getD2dGeometry()->FillContainsPoint( D2D1::Point2F( static_cast(point.x), static_cast(point.y)), @@ -970,7 +967,7 @@ void e2d::Node::setVisiable(bool value) m_bVisiable = value; } -void e2d::Node::setName(String& name) +void e2d::Node::setName(String name) { WARN_IF(name.isEmpty(), "Invalid Node name."); diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index baaf32f9..b5a88bd8 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -12,13 +12,13 @@ e2d::Sprite::Sprite(Image * image) open(image); } -e2d::Sprite::Sprite(String& imageFileName) +e2d::Sprite::Sprite(String imageFileName) : m_pImage(nullptr) { open(imageFileName); } -e2d::Sprite::Sprite(String& imageFileName, double x, double y, double width, double height) +e2d::Sprite::Sprite(String imageFileName, double x, double y, double width, double height) : m_pImage(nullptr) { open(imageFileName); @@ -42,7 +42,7 @@ void e2d::Sprite::open(Image * image) } } -void e2d::Sprite::open(String& imageFileName) +void e2d::Sprite::open(String imageFileName) { open(new Image(imageFileName)); } @@ -65,6 +65,7 @@ void e2d::Sprite::onRender() { if (m_pImage && m_pImage->getBitmap()) { + // 获取图片裁剪位置 float fClipX = static_cast(m_pImage->getClipX()); float fClipY = static_cast(m_pImage->getClipY()); // 渲染图片 diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index a823021b..62bbbb2b 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -1,43 +1,58 @@ #include "..\enodes.h" e2d::Text::Text() - : m_bWordWrapping(false) + : m_bWrappingEnable(false) , m_pFont(nullptr) - , m_fWordWrappingWidth(0) + , m_fWrappingWidth(0) + , m_bHasUnderline(false) + , m_bHasStrikethrough(false) + , m_pDWriteTextLayout(nullptr) { this->setFont(new Font()); } -e2d::Text::Text(String& text) - : m_bWordWrapping(false) +e2d::Text::Text(String text) + : m_bWrappingEnable(false) , m_pFont(nullptr) - , m_fWordWrappingWidth(0) + , m_fWrappingWidth(0) + , m_bHasUnderline(false) + , m_bHasStrikethrough(false) + , m_pDWriteTextLayout(nullptr) { this->setText(text); this->setFont(new Font()); } e2d::Text::Text(Font * font) - : m_bWordWrapping(false) + : m_bWrappingEnable(false) , m_pFont(nullptr) - , m_fWordWrappingWidth(0) + , m_fWrappingWidth(0) + , m_bHasUnderline(false) + , m_bHasStrikethrough(false) + , m_pDWriteTextLayout(nullptr) { this->setFont(font); } -e2d::Text::Text(String& text, Font * font) - : m_bWordWrapping(false) +e2d::Text::Text(String text, Font * font) + : m_bWrappingEnable(false) , m_pFont(nullptr) - , m_fWordWrappingWidth(0) + , m_fWrappingWidth(0) + , m_bHasUnderline(false) + , m_bHasStrikethrough(false) + , m_pDWriteTextLayout(nullptr) { this->setText(text); this->setFont(font); } -e2d::Text::Text(String& text, String fontFamily, double fontSize, UINT32 color, UINT32 fontWeight, bool italic) - : m_bWordWrapping(false) +e2d::Text::Text(String text, String fontFamily, double fontSize, UINT32 color, UINT32 fontWeight, bool italic) + : m_bWrappingEnable(false) , m_pFont(nullptr) - , m_fWordWrappingWidth(0) + , m_fWrappingWidth(0) + , m_bHasUnderline(false) + , m_bHasStrikethrough(false) + , m_pDWriteTextLayout(nullptr) { this->setText(text); this->setFont(new Font(fontFamily, fontSize, color, fontWeight, italic)); @@ -53,22 +68,12 @@ e2d::String e2d::Text::getText() const return m_sText; } -double e2d::Text::getWidth() const -{ - return m_fWordWrappingWidth * m_fScaleX; -} - -double e2d::Text::getRealWidth() const -{ - return m_fWordWrappingWidth; -} - e2d::Font * e2d::Text::getFont() const { return m_pFont; } -void e2d::Text::setText(String& text) +void e2d::Text::setText(String text) { m_sText = text; _initTextLayout(); @@ -86,29 +91,76 @@ void e2d::Text::setFont(Font * font) } } -void e2d::Text::setWordWrappingEnable(bool value) +void e2d::Text::setWrappingWidth(double wordWrapWidth) { - m_bWordWrapping = value; + m_fWrappingWidth = max(static_cast(wordWrapWidth), 0); + m_bWrappingEnable = (abs(m_fWrappingWidth) >= 1e-7); _initTextLayout(); } -void e2d::Text::setWordWrappingWidth(double wordWrapWidth) +void e2d::Text::setLineSpacing(double fLineSpacing) { - m_fWordWrappingWidth = max(static_cast(wordWrapWidth), 0); - _initTextLayout(); + if (m_pFont) + { + if (fLineSpacing == 0.0f) + { + m_pFont->getDWriteTextFormat()->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0); + } + else + { + m_pFont->getDWriteTextFormat()->SetLineSpacing( + DWRITE_LINE_SPACING_METHOD_UNIFORM, + static_cast(fLineSpacing), + static_cast(fLineSpacing) * 0.8f + ); + } + + _initTextLayout(); + } +} + +void e2d::Text::setAlignment(UINT32 nAlign) +{ + if (m_pFont) + { + m_pFont->getDWriteTextFormat()->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(nAlign)); + _initTextLayout(); + } +} + +void e2d::Text::setUnderline(bool hasUnderline) +{ + if (m_bHasUnderline != hasUnderline) + { + m_bHasUnderline = hasUnderline; + _initTextLayout(); + } +} + +void e2d::Text::setStrikethrough(bool hasStrikethrough) +{ + if (m_bHasStrikethrough != hasStrikethrough) + { + m_bHasStrikethrough = hasStrikethrough; + _initTextLayout(); + } } void e2d::Text::onRender() { - D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, m_bWordWrapping ? m_fWordWrappingWidth : m_fWidth, m_fHeight); + // 创建文本区域 + D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, m_bWrappingEnable ? m_fWrappingWidth : m_fWidth, m_fHeight); + // 设置画刷颜色和透明度 Renderer::getSolidColorBrush()->SetColor(D2D1::ColorF(m_pFont->m_Color, m_fDisplayOpacity)); - Renderer::getRenderTarget()->DrawTextW( - m_sText, - static_cast(m_sText.getLength()), - m_pFont->_getTextFormat(), - textLayoutRect, - Renderer::getSolidColorBrush() - ); + // 渲染文字内容 + if (m_pDWriteTextLayout) + { + Renderer::getRenderTarget()->DrawTextLayout( + { 0, 0 }, + m_pDWriteTextLayout, + Renderer::getSolidColorBrush() + ); + } } void e2d::Text::_initTextLayout() @@ -117,41 +169,48 @@ void e2d::Text::_initTextLayout() if (!m_pFont || m_sText.isEmpty()) { this->setSize(0, 0); - m_fWordWrappingWidth = 0; return; } // 未打开文本自动换行时,设置 TextFormat 属性为不换行 - if (!m_bWordWrapping) + if (!m_bWrappingEnable) { - m_pFont->_getTextFormat()->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); + m_pFont->getDWriteTextFormat()->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); } else { - m_pFont->_getTextFormat()->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP); + m_pFont->getDWriteTextFormat()->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP); } // 获取 TextLayout - IDWriteTextLayout * pDWriteTextLayout = nullptr; + SafeReleaseInterface(&m_pDWriteTextLayout); + UINT32 length = static_cast(m_sText.getLength()); HRESULT hr = Renderer::getIDWriteFactory()->CreateTextLayout( m_sText, - static_cast(m_sText.getLength()), - m_pFont->_getTextFormat(), - m_bWordWrapping ? m_fWordWrappingWidth : 0, + length, + m_pFont->getDWriteTextFormat(), + m_bWrappingEnable ? m_fWrappingWidth : 0, 0, - &pDWriteTextLayout + &m_pDWriteTextLayout ); ASSERT(SUCCEEDED(hr), "Create IDWriteTextFormat Failed!"); + // 添加下划线和删除线 + if (m_bHasUnderline) + { + m_pDWriteTextLayout->SetUnderline(true, { 0, length }); + } + if (m_bHasStrikethrough) + { + m_pDWriteTextLayout->SetStrikethrough(true, { 0, length }); + } + // 获取文本布局的宽度和高度 DWRITE_TEXT_METRICS metrics; - pDWriteTextLayout->GetMetrics(&metrics); + m_pDWriteTextLayout->GetMetrics(&metrics); this->setSize(metrics.widthIncludingTrailingWhitespace, metrics.height); - m_fWordWrappingWidth = metrics.widthIncludingTrailingWhitespace; - - // 删除相关资源 - SafeReleaseInterface(&pDWriteTextLayout); + m_fWrappingWidth = metrics.widthIncludingTrailingWhitespace; } diff --git a/core/Shape/Circle.cpp b/core/Shape/Circle.cpp index 56138179..82f61348 100644 --- a/core/Shape/Circle.cpp +++ b/core/Shape/Circle.cpp @@ -60,7 +60,7 @@ void e2d::Circle::_resize() } } -ID2D1EllipseGeometry * e2d::Circle::_getD2dGeometry() const +ID2D1EllipseGeometry * e2d::Circle::getD2dGeometry() const { return m_pD2dCircle; } diff --git a/core/Shape/Ellipse.cpp b/core/Shape/Ellipse.cpp index 6bf14fd2..bc389750 100644 --- a/core/Shape/Ellipse.cpp +++ b/core/Shape/Ellipse.cpp @@ -60,7 +60,7 @@ void e2d::Ellipse::_resize() } } -ID2D1EllipseGeometry * e2d::Ellipse::_getD2dGeometry() const +ID2D1EllipseGeometry * e2d::Ellipse::getD2dGeometry() const { return m_pD2dEllipse; } diff --git a/core/Shape/Rect.cpp b/core/Shape/Rect.cpp index 7cfebafa..b90144bf 100644 --- a/core/Shape/Rect.cpp +++ b/core/Shape/Rect.cpp @@ -55,7 +55,7 @@ void e2d::Rect::_resize() } } -ID2D1RectangleGeometry * e2d::Rect::_getD2dGeometry() const +ID2D1RectangleGeometry * e2d::Rect::getD2dGeometry() const { return m_pD2dRectangle; } diff --git a/core/Shape/Shape.cpp b/core/Shape/Shape.cpp index beaf915c..4843514f 100644 --- a/core/Shape/Shape.cpp +++ b/core/Shape/Shape.cpp @@ -121,7 +121,7 @@ void e2d::Shape::_transform() // 根据父节点转换几何图形 Renderer::getID2D1Factory()->CreateTransformedGeometry( - _getD2dGeometry(), + getD2dGeometry(), m_pParentNode->m_MatriFinal, &m_pTransformedShape ); diff --git a/core/Tool/Data.cpp b/core/Tool/Data.cpp index 3e9cc481..26896b95 100644 --- a/core/Tool/Data.cpp +++ b/core/Tool/Data.cpp @@ -2,54 +2,54 @@ static e2d::String s_sDefaultFileName = L"DefaultData.ini"; -void e2d::Data::saveInt(String& key, int value, String field) +void e2d::Data::saveInt(String key, int value, String field) { ::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath()); } -void e2d::Data::saveDouble(String& key, double value, String field) +void e2d::Data::saveDouble(String key, double value, String field) { ::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath()); } -void e2d::Data::saveBool(String& key, bool value, String field) +void e2d::Data::saveBool(String key, bool value, String field) { const wchar_t* sValue = value ? L"1" : L"0"; ::WritePrivateProfileString(field, key, sValue, Data::getDataFilePath()); } -void e2d::Data::saveString(String& key, String& value, String field) +void e2d::Data::saveString(String key, String value, String field) { ::WritePrivateProfileString(field, key, value, Data::getDataFilePath()); } -int e2d::Data::getInt(String& key, int defaultValue, String field) +int e2d::Data::getInt(String key, int defaultValue, String field) { return ::GetPrivateProfileInt(field, key, defaultValue, Data::getDataFilePath()); } -double e2d::Data::getDouble(String& key, double defaultValue, String field) +double e2d::Data::getDouble(String key, double defaultValue, String field) { wchar_t temp[32] = { 0 }; ::GetPrivateProfileString(field, key, String::toString(defaultValue), temp, 31, Data::getDataFilePath()); return std::stof(temp); } -bool e2d::Data::getBool(String& key, bool defaultValue, String field) +bool e2d::Data::getBool(String key, bool defaultValue, String field) { int nDefaultValue = defaultValue ? 1 : 0; int nValue = ::GetPrivateProfileInt(field, key, nDefaultValue, Data::getDataFilePath()); return nValue != 0; } -e2d::String e2d::Data::getString(String& key, String& defaultValue, String field) +e2d::String e2d::Data::getString(String key, String defaultValue, String field) { wchar_t temp[256] = { 0 }; ::GetPrivateProfileString(field, key, defaultValue, temp, 255, Data::getDataFilePath()); return temp; } -void e2d::Data::setDataFileName(String& fileName) +void e2d::Data::setDataFileName(String fileName) { if (!fileName.isEmpty()) { diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 1e65b1aa..b66cc39a 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -35,7 +35,7 @@ Music::Music() { } -e2d::Music::Music(String& strFileName) +e2d::Music::Music(String strFileName) : m_bOpened(false) , m_bPlaying(false) , m_pwfx(nullptr) @@ -53,7 +53,7 @@ Music::~Music() close(); } -bool Music::open(String& strFileName) +bool Music::open(String strFileName) { if (m_bOpened) { diff --git a/core/Tool/Path.cpp b/core/Tool/Path.cpp index 97e26929..796f912f 100644 --- a/core/Tool/Path.cpp +++ b/core/Tool/Path.cpp @@ -94,7 +94,7 @@ e2d::String e2d::Path::getDefaultSavePath() return std::move(path); } -e2d::String e2d::Path::getFileExtension(String& filePath) +e2d::String e2d::Path::getFileExtension(String filePath) { String fileExtension; // 找到文件名中的最后一个 '.' 的位置 @@ -111,7 +111,7 @@ e2d::String e2d::Path::getFileExtension(String& filePath) return fileExtension; } -e2d::String e2d::Path::getSaveFilePath(const String& title, const String& defExt) +e2d::String e2d::Path::getSaveFilePath(const String title, const String defExt) { // 弹出保存对话框 OPENFILENAME ofn = { 0 }; @@ -134,7 +134,7 @@ e2d::String e2d::Path::getSaveFilePath(const String& title, const String& defExt return L""; } -bool e2d::Path::createFolder(String& strDirPath) +bool e2d::Path::createFolder(String strDirPath) { if (strDirPath.isEmpty()) { diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index 06b10b16..82bad345 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -49,7 +49,7 @@ e2d::String e2d::Timer::getName() const return m_sName; } -void e2d::Timer::setName(String& name) +void e2d::Timer::setName(String name) { m_sName = name; } diff --git a/core/eactions.h b/core/eactions.h index 2b8622bd..5528403c 100644 --- a/core/eactions.h +++ b/core/eactions.h @@ -48,7 +48,7 @@ public: // 设置动作名称 virtual void setName( - String&name + String name ); // 获取一个新的逆向动作 diff --git a/core/ebase.h b/core/ebase.h index 325cad7b..27e3fea8 100644 --- a/core/ebase.h +++ b/core/ebase.h @@ -14,7 +14,7 @@ class Game public: // 初始化游戏 static bool init( - String& sTitle, /* 窗口标题 */ + String sTitle, /* 窗口标题 */ UINT32 nWidth = 640U, /* 窗口宽度 */ UINT32 nHeight = 480U, /* 窗口高度 */ LPCTSTR pIconID = nullptr, /* 窗口图标 */ @@ -73,7 +73,7 @@ public: // 设置窗口标题 static void setTitle( - String& sTitle + String sTitle ); // 打开/隐藏控制台 @@ -89,7 +89,7 @@ public: private: // 初始化窗口 static bool __init( - String& sTitle, + const String& sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID @@ -97,7 +97,7 @@ private: // 创建进程互斥体 static bool __initMutex( - String& sTitle + const String& sTitle ); // 重置窗口属性 @@ -159,17 +159,17 @@ public: // 启动输入监听 static void start( - String& name + String name ); // 停止输入监听 static void stop( - String& name + String name ); // 清除输入监听 static void clear( - String& name + String name ); // 启动所有监听器 @@ -183,7 +183,7 @@ public: // 获取监听器 static std::vector get( - String& name + String name ); // 获取全部监听器 diff --git a/core/ecommon.h b/core/ecommon.h index a156b3cd..071e0f41 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -297,6 +297,19 @@ public: }; +// 文本对齐方式 +class TextAlign +{ +public: + enum COMMON_VALUE + { + LEFT, /* 左对齐 */ + RIGHT, /* 右对齐 */ + CENTER /* 居中对齐 */ + }; +}; + + // 键值集合 class KeyCode { @@ -358,17 +371,7 @@ public: NUMPAD1 = 0x4F, NUMPAD2 = 0x50, NUMPAD3 = 0x51, - NUMPAD0 = 0x52, - F1 = 0x3B, - F2 = 0x3C, - F3 = 0x3D, - F4 = 0x3E, - F5 = 0x3F, - F6 = 0x40, - F7 = 0x41, - F8 = 0x42, - F9 = 0x43, - F10 = 0x44 + NUMPAD0 = 0x52 }; }; @@ -449,7 +452,7 @@ public: // 设置字体 void setFamily( - String& fontFamily + String fontFamily ); // 设置字号 @@ -477,7 +480,7 @@ protected: void _initTextFormat(); // 获取文字格式 - IDWriteTextFormat * _getTextFormat(); + IDWriteTextFormat * getDWriteTextFormat(); protected: String m_sFontFamily; @@ -500,12 +503,12 @@ public: // 从本地文件中读取资源 Image( - String& strFilePath /* 图片文件路径 */ + String strFilePath /* 图片文件路径 */ ); // 从本地文件中读取资源 Image( - String& strFilePath,/* 图片文件路径 */ + String strFilePath,/* 图片文件路径 */ double nClipX, /* 裁剪位置 X 坐标 */ double nClipY, /* 裁剪位置 Y 坐标 */ double nClipWidth, /* 裁剪宽度 */ @@ -516,7 +519,7 @@ public: // 从本地文件中读取图片 void open( - String& strFilePath + String strFilePath ); // 裁剪图片 @@ -559,7 +562,7 @@ public: // 预加载资源 static bool preload( - String& strFileName /* 图片文件路径 */ + String strFileName /* 图片文件路径 */ ); // 清空缓存 @@ -664,7 +667,7 @@ public: Listener( Function func, /* 监听到消息时的执行函数 */ - String& name /* 监听器名称 */ + String name /* 监听器名称 */ ); // 启动 @@ -684,7 +687,7 @@ public: // 修改名称 void setName( - String& name + String name ); // 设置监听到消息时的执行函数 diff --git a/core/emanagers.h b/core/emanagers.h index c2273240..fd5e7884 100644 --- a/core/emanagers.h +++ b/core/emanagers.h @@ -101,22 +101,22 @@ public: // 启动具有相同名称的定时器 static void start( - String&name + String name ); // 停止具有相同名称的定时器 static void stop( - String&name + String name ); // 删除具有相同名称的定时器 static void clear( - String&name + String name ); // 获取名称相同的定时器 static std::vector get( - String& name + String name ); // 启动所有定时器 @@ -158,17 +158,17 @@ class ActionManager public: // 继续名称相同的所有动作 static void resume( - String& strActionName + String strActionName ); // 暂停名称相同的所有动作 static void pause( - String& strActionName + String strActionName ); // 停止名称相同的所有动作 static void stop( - String& strActionName + String strActionName ); // 继续所有动作 @@ -182,7 +182,7 @@ public: // 获取所有名称相同的动作 static std::vector get( - String& strActionName + String strActionName ); // 获取所有动作 @@ -241,33 +241,33 @@ class MusicManager public: // 预加载音乐资源 static bool preload( - String& strFilePath /* 音乐文件路径 */ + String strFilePath /* 音乐文件路径 */ ); // 播放音乐 static bool play( - String& strFilePath, /* 音乐文件路径 */ - int nLoopCount = 0 /* 重复播放次数,设置 -1 为循环播放 */ + String strFilePath, /* 音乐文件路径 */ + int nLoopCount = 0 /* 重复播放次数,设置 -1 为循环播放 */ ); // 暂停音乐 static void pause( - String& strFilePath /* 音乐文件路径 */ + String strFilePath /* 音乐文件路径 */ ); // 继续播放音乐 static void resume( - String& strFilePath /* 音乐文件路径 */ + String strFilePath /* 音乐文件路径 */ ); // 停止音乐 static void stop( - String& strFilePath /* 音乐文件路径 */ + String strFilePath /* 音乐文件路径 */ ); // 获取指定音乐的 Music 对象 static Music * get( - String& strFilePath /* 音乐文件路径 */ + String strFilePath /* 音乐文件路径 */ ); // 暂停所有音乐 diff --git a/core/enodes.h b/core/enodes.h index 7c1169ed..2ecf2a8b 100644 --- a/core/enodes.h +++ b/core/enodes.h @@ -123,7 +123,7 @@ public: // 获取所有名称相同的子节点 virtual std::vector getChildren( - String& name + String name ); // 获取所有子节点 @@ -139,7 +139,7 @@ public: // 移除所有名称相同的子节点 virtual void removeChildren( - String& childName + String childName ); // 从父节点移除 @@ -160,7 +160,7 @@ public: // 设置节点名称 virtual void setName( - String& name + String name ); // 设置节点横坐标 @@ -325,27 +325,27 @@ public: // 继续动画 virtual void resumeAction( - String& strActionName + String strActionName ); // 暂停动画 virtual void pauseAction( - String& strActionName + String strActionName ); // 停止动画 virtual void stopAction( - String& strActionName + String strActionName ); // 获取名称相同的动画 virtual Action * getAction( - String& strActionName + String strActionName ); // 获取所有名称相同的动画 virtual std::vector getActions( - String& strActionName + String strActionName ); // 继续所有暂停动画 @@ -449,12 +449,12 @@ public: // 从文件图片创建精灵 Sprite( - String& imageFileName + String imageFileName ); // 从文件图片创建精灵并裁剪 Sprite( - String& imageFileName, + String imageFileName, double x, double y, double width, @@ -465,7 +465,7 @@ public: // 从本地文件加载图片 virtual void open( - String& imageFileName + String imageFileName ); // 加载图片 @@ -499,24 +499,24 @@ public: Text(); Text( - String& text /* 文字内容 */ + String text /* 文字内容 */ ); Text( - Font * font /* 字体样式 */ + Font * font /* 字体样式 */ ); Text( - String& text,/* 文字内容 */ - Font * font /* 字体样式 */ + String text, /* 文字内容 */ + Font * font /* 字体样式 */ ); Text( - String& text, /* 文字内容*/ + String text, /* 文字内容*/ String fontFamily, /* 字体 */ double fontSize = 22, /* 字号 */ UINT32 color = Color::WHITE, /* 颜色 */ - UINT32 fontWeight = FontWeight::REGULAR,/* 粗细值 */ + UINT32 fontWeight = FontWeight::NORMAL, /* 粗细值 */ bool italic = false /* 斜体 */ ); @@ -525,18 +525,12 @@ public: // 获取文本 String getText() const; - // 获取文本宽度 - virtual double getWidth() const override; - - // 获取文本宽度(不考虑缩放) - virtual double getRealWidth() const override; - // 获取字体 Font * getFont() const; // 设置文本 void setText( - String& text + String text ); // 设置字体 @@ -544,14 +538,29 @@ public: Font * pFont ); - // 设置文字自动换行 - void setWordWrappingEnable( - bool bEnable + // 设置文本自动换行宽度(默认为 0) + void setWrappingWidth( + double fWrappingWidth ); - // 设置文字换行宽度(WordWrapping 打开时生效) - void setWordWrappingWidth( - double fWordWrapWidth + // 设置行间距(默认为 0) + void setLineSpacing( + double fLineSpacing + ); + + // 设置对齐方式(默认为 TextAlign::LEFT) + void setAlignment( + UINT32 nAlign + ); + + // 设置下划线 + void setUnderline( + bool hasUnderline + ); + + // 设置删除线 + void setStrikethrough( + bool hasStrikethrough ); // 渲染文字 @@ -563,9 +572,12 @@ protected: protected: String m_sText; - bool m_bWordWrapping; - float m_fWordWrappingWidth; - Font * m_pFont; + bool m_bWrappingEnable; + bool m_bHasUnderline; + bool m_bHasStrikethrough; + float m_fWrappingWidth; + Font * m_pFont; + IDWriteTextLayout * m_pDWriteTextLayout; }; diff --git a/core/eshape.h b/core/eshape.h index 10dfcd56..42a0d4ff 100644 --- a/core/eshape.h +++ b/core/eshape.h @@ -69,6 +69,9 @@ public: bool bEnable ); + // 获取 ID2D1Geometry 对象 + virtual ID2D1Geometry * getD2dGeometry() const = 0; + protected: // 转换形状 virtual void _transform(); @@ -79,9 +82,6 @@ protected: // 渲染形状 virtual void _render(); - // 获取 ID2D1Geometry 对象 - virtual ID2D1Geometry * _getD2dGeometry() const = 0; - protected: bool m_bEnable; bool m_bIsVisiable; @@ -117,6 +117,9 @@ public: virtual ~Rect(); + // 获取 ID2D1Geometry 对象 + virtual ID2D1RectangleGeometry * getD2dGeometry() const override; + protected: void _setRect( double left, @@ -128,8 +131,6 @@ protected: // 重设大小 virtual void _resize(); - virtual ID2D1RectangleGeometry * _getD2dGeometry() const override; - protected: ID2D1RectangleGeometry * m_pD2dRectangle; }; @@ -155,6 +156,9 @@ public: virtual ~Circle(); + // 获取 ID2D1Geometry 对象 + virtual ID2D1EllipseGeometry * getD2dGeometry() const override; + protected: void _setCircle( Point center, @@ -164,8 +168,6 @@ protected: // 重设大小 virtual void _resize(); - virtual ID2D1EllipseGeometry * _getD2dGeometry() const override; - protected: ID2D1EllipseGeometry * m_pD2dCircle; }; @@ -192,6 +194,9 @@ public: virtual ~Ellipse(); + // 获取 ID2D1Geometry 对象 + virtual ID2D1EllipseGeometry * getD2dGeometry() const override; + protected: void _setEllipse( Point center, @@ -202,8 +207,6 @@ protected: // 重设大小 virtual void _resize(); - virtual ID2D1EllipseGeometry * _getD2dGeometry() const override; - protected: ID2D1EllipseGeometry * m_pD2dEllipse; }; diff --git a/core/etools.h b/core/etools.h index 7cc5128d..c6c3b21c 100644 --- a/core/etools.h +++ b/core/etools.h @@ -79,7 +79,7 @@ public: // 设置定时器名称 void setName( - String&name + String name ); // 设置定时器执行间隔 @@ -122,36 +122,36 @@ class Data public: // 保存 int 类型的值 static void saveInt( - String& key, /* 键值 */ + String key, /* 键值 */ int value, /* 数据 */ String field = L"Defalut" /* 字段名称 */ ); // 保存 double 类型的值 static void saveDouble( - String& key, /* 键值 */ + String key, /* 键值 */ double value, /* 数据 */ String field = L"Defalut" /* 字段名称 */ ); // 保存 bool 类型的值 static void saveBool( - String& key, /* 键值 */ + String key, /* 键值 */ bool value, /* 数据 */ String field = L"Defalut" /* 字段名称 */ ); // 保存 字符串 类型的值 static void saveString( - String& key, /* 键值 */ - String& value, /* 数据 */ + String key, /* 键值 */ + String value, /* 数据 */ String field = L"Defalut" /* 字段名称 */ ); // 获取 int 类型的值 // (若不存在则返回 defaultValue 参数的值) static int getInt( - String& key, /* 键值 */ + String key, /* 键值 */ int defaultValue, /* 默认值 */ String field = L"Defalut" /* 字段名称 */ ); @@ -159,7 +159,7 @@ public: // 获取 double 类型的值 // (若不存在则返回 defaultValue 参数的值) static double getDouble( - String& key, /* 键值 */ + String key, /* 键值 */ double defaultValue, /* 默认值 */ String field = L"Defalut" /* 字段名称 */ ); @@ -167,7 +167,7 @@ public: // 获取 bool 类型的值 // (若不存在则返回 defaultValue 参数的值) static bool getBool( - String& key, /* 键值 */ + String key, /* 键值 */ bool defaultValue, /* 默认值 */ String field = L"Defalut" /* 字段名称 */ ); @@ -175,14 +175,14 @@ public: // 获取 字符串 类型的值 // (若不存在则返回 defaultValue 参数的值) static String getString( - String& key, /* 键值 */ - String& defaultValue, /* 默认值 */ + String key, /* 键值 */ + String defaultValue, /* 默认值 */ String field = L"Defalut" /* 字段名称 */ ); // 修改数据文件的名称 static void setDataFileName( - String& strFileName /* 文件名称 */ + String strFileName /* 文件名称 */ ); // 获取数据文件的完整路径 @@ -205,18 +205,18 @@ public: // 获取文件扩展名 static String getFileExtension( - String& filePath + String filePath ); // 打开保存文件对话框 static String getSaveFilePath( - const String& title = L"保存到", /* 对话框标题 */ - const String& defExt = L"" /* 默认扩展名 */ + const String title = L"保存到", /* 对话框标题 */ + const String defExt = L"" /* 默认扩展名 */ ); // 创建文件夹 static bool createFolder( - String& strDirPath /* 文件夹路径 */ + String strDirPath /* 文件夹路径 */ ); }; @@ -231,14 +231,14 @@ public: Music(); Music( - String& strFileName /* 音乐文件路径 */ + String strFileName /* 音乐文件路径 */ ); virtual ~Music(); // 打开音乐文件 bool open( - String& strFileName /* 音乐文件路径 */ + String strFileName /* 音乐文件路径 */ ); // 播放