diff --git a/.gitignore b/.gitignore index c0da8165..86bb91a8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ Easy2D/Win32/ Easy2D/x64/ /Win32/ /x64/ +Debug/ +Release/ backup/ *.lnk .vs \ No newline at end of file diff --git a/Demo/Demo.vcxproj b/Demo/Demo.vcxproj new file mode 100644 index 00000000..98bd4630 --- /dev/null +++ b/Demo/Demo.vcxproj @@ -0,0 +1,156 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C} + Win32Proj + Demo + 10.0.15063.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(MSBuildProjectDirectory)\..\Win32;$(LibraryPath) + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + + + Level3 + Disabled + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + + + Level3 + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/Demo/Demo.vcxproj.filters b/Demo/Demo.vcxproj.filters new file mode 100644 index 00000000..203a71c4 --- /dev/null +++ b/Demo/Demo.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/Demo/main.cpp b/Demo/main.cpp new file mode 100644 index 00000000..22db1191 --- /dev/null +++ b/Demo/main.cpp @@ -0,0 +1,24 @@ +#include "..\Easy2D\easy2d.h" +#pragma comment(lib, "d2d1.lib") + + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + EApp app; + + if (app.init(L"Easy2D Demo", 640, 480)) + { + auto scene = new EScene(); + + auto node = new ENode(); + node->setPos(50, 80); + node->setSize(30, 180); + scene->add(node); + + app.enterScene(scene); + + app.run(); + } + + return 0; +} diff --git a/Easy2D.sln b/Easy2D.sln index 6b3b67bc..2c6780c3 100644 --- a/Easy2D.sln +++ b/Easy2D.sln @@ -1,38 +1,38 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.12 +VisualStudioVersion = 15.0.26730.16 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D\Easy2D.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo\Demo.vcxproj", "{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - DebugW|x64 = DebugW|x64 - DebugW|x86 = DebugW|x86 Release|x64 = Release|x64 Release|x86 = Release|x86 - ReleaseW|x64 = ReleaseW|x64 - ReleaseW|x86 = ReleaseW|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x64.ActiveCfg = Debug|x64 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x64.Build.0 = Debug|x64 + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x64.Deploy.0 = Debug|x64 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x86.ActiveCfg = Debug|Win32 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x86.Build.0 = Debug|Win32 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.DebugW|x64.ActiveCfg = DebugW|x64 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.DebugW|x64.Build.0 = DebugW|x64 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.DebugW|x86.ActiveCfg = DebugW|Win32 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.DebugW|x86.Build.0 = DebugW|Win32 + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x86.Deploy.0 = Debug|Win32 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x64.ActiveCfg = Release|x64 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x64.Build.0 = Release|x64 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x86.ActiveCfg = Release|Win32 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x86.Build.0 = Release|Win32 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.ReleaseW|x64.ActiveCfg = ReleaseW|x64 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.ReleaseW|x64.Build.0 = ReleaseW|x64 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.ReleaseW|x86.ActiveCfg = ReleaseW|Win32 - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.ReleaseW|x86.Build.0 = ReleaseW|Win32 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Debug|x64.ActiveCfg = Debug|x64 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Debug|x64.Build.0 = Debug|x64 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Debug|x86.ActiveCfg = Debug|Win32 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Debug|x86.Build.0 = Debug|Win32 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x64.ActiveCfg = Release|x64 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x64.Build.0 = Release|x64 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.ActiveCfg = Release|Win32 + {9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Easy2D/Action/Action.cpp b/Easy2D/Action/Action.cpp deleted file mode 100644 index 1d99e527..00000000 --- a/Easy2D/Action/Action.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "..\easy2d.h" -#include - -Action::Action() : - m_bRunning(true), - m_bWaiting(false), - m_bEnding(false), - m_bInit(false), - m_pTargetSprite(nullptr), - m_pParentScene(nullptr) -{ - // Ĭ϶ 15ms һ - setInterval(15); -} - -Action::~Action() -{ -} - -bool Action::isRunning() -{ - return m_bRunning && !m_bWaiting; -} - -bool Action::isEnding() -{ - return m_bEnding; -} - -void Action::start() -{ - m_bRunning = true; -} - -void Action::resume() -{ - m_bRunning = true; -} - -void Action::pause() -{ - m_bRunning = false; -} - -void Action::stop() -{ - m_bEnding = true; -} -void Action::wait() -{ - m_bWaiting = true; -} - -void Action::notify() -{ - m_bWaiting = false; -} - -void Action::setInterval(LONGLONG milliSeconds) -{ - // öʱ - m_nAnimationInterval = milliSeconds; -} - -Action * Action::reverse() const -{ - assert(0); - return nullptr; -} - -Sprite * Action::getTarget() -{ - return m_pTargetSprite; -} - -void Action::_init() -{ - m_bInit = true; -} - -void Action::_reset() -{ - m_bInit = false; - m_bEnding = false; -} diff --git a/Easy2D/Action/ActionCallback.cpp b/Easy2D/Action/ActionCallback.cpp deleted file mode 100644 index c1cf46e1..00000000 --- a/Easy2D/Action/ActionCallback.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "..\easy2d.h" - -ActionCallback::ActionCallback(const std::function& callback) : - m_Callback(callback) -{ -} - -ActionCallback::~ActionCallback() -{ -} - -ActionCallback * ActionCallback::copy() const -{ - return new ActionCallback(m_Callback); -} - -void ActionCallback::_init() -{ - Action::_init(); -} - -void ActionCallback::_exec(std::chrono::steady_clock::time_point nNow) -{ - m_Callback(); - this->stop(); -} - -void ActionCallback::_reset() -{ - Action::_reset(); -} diff --git a/Easy2D/Action/ActionDelay.cpp b/Easy2D/Action/ActionDelay.cpp deleted file mode 100644 index 4e5c8b6a..00000000 --- a/Easy2D/Action/ActionDelay.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" - -ActionDelay::ActionDelay(float duration) -{ - setInterval(LONGLONG(duration * 1000)); -} - -ActionDelay::~ActionDelay() -{ -} - -ActionDelay * ActionDelay::copy() const -{ - return new ActionDelay(m_nAnimationInterval / 1000.0f); -} - -void ActionDelay::_init() -{ - Action::_init(); - // ¼ǰʱ - m_nLast = steady_clock::now(); -} - -void ActionDelay::_exec(steady_clock::time_point nNow) -{ - // жʱǷ㹻 - if (duration_cast(nNow - m_nLast).count() > m_nAnimationInterval) - { - this->stop(); - } -} - -void ActionDelay::_reset() -{ - Action::_reset(); - // ¼ǰʱ - m_nLast = steady_clock::now(); -} diff --git a/Easy2D/Action/ActionFrames.cpp b/Easy2D/Action/ActionFrames.cpp deleted file mode 100644 index 582bf48b..00000000 --- a/Easy2D/Action/ActionFrames.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" - -ActionFrames::ActionFrames() : - m_nFrameIndex(0) -{ - // ֡Ĭ .5s ˢһ - setInterval(500); -} - -ActionFrames::ActionFrames(LONGLONG frameDelay) : - m_nFrameIndex(0) -{ - setInterval(frameDelay); -} - -ActionFrames::~ActionFrames() -{ - for (auto frame : m_vFrames) - { - frame->autoRelease(); - frame->release(); - } -} - -void ActionFrames::_init() -{ - Action::_init(); - // ¼ǰʱ - m_nLast = steady_clock::now(); -} - -void ActionFrames::_exec(steady_clock::time_point nNow) -{ - // жʱǷ㹻 - while (duration_cast(nNow - m_nLast).count() > m_nAnimationInterval) - { - // ¼¼ʱ - m_nLast += milliseconds(m_nAnimationInterval); - m_pTargetSprite->setImage(m_vFrames[m_nFrameIndex]); - m_nFrameIndex++; - // ж϶Ƿ - if (m_nFrameIndex == m_vFrames.size()) - { - this->stop(); - break; - } - } -} - -void ActionFrames::_reset() -{ - Action::_reset(); - m_nFrameIndex = 0; - // ¼ǰʱ - m_nLast = steady_clock::now(); -} - -void ActionFrames::addFrame(Image * frame) -{ - if (frame) - { - m_vFrames.push_back(frame); - frame->retain(); - } -} - -ActionFrames * ActionFrames::copy() const -{ - auto a = new ActionFrames(this->m_nAnimationInterval); - for (auto f : m_vFrames) - { - a->addFrame(f); - } - return a; -} - -ActionFrames * ActionFrames::reverse() const -{ - auto a = this->copy(); - a->m_vFrames.reserve(m_vFrames.size()); - return a; -} diff --git a/Easy2D/Action/ActionMoveBy.cpp b/Easy2D/Action/ActionMoveBy.cpp deleted file mode 100644 index ebc83a66..00000000 --- a/Easy2D/Action/ActionMoveBy.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" - -ActionMoveBy::ActionMoveBy(float duration, CVector vec) : - Animation(duration) -{ - m_MoveVector = vec; -} - -ActionMoveBy::~ActionMoveBy() -{ -} - -void ActionMoveBy::_init() -{ - Animation::_init(); - m_BeginPos = m_pTargetSprite->getPos(); -} - -void ActionMoveBy::_exec(steady_clock::time_point nNow) -{ - while (Animation::_isDelayEnough(nNow)) - { - // ƶλ - float scale = float(m_nDuration) / m_nTotalDuration; - // ƶ Sprite - m_pTargetSprite->setPos(int(m_BeginPos.x + m_MoveVector.x * scale), - int(m_BeginPos.y + m_MoveVector.y * scale)); - // ж϶Ƿ - if (_isEnd()) - { - this->stop(); - break; - } - } -} - -void ActionMoveBy::_reset() -{ - Animation::_reset(); -} - -ActionMoveBy * ActionMoveBy::copy() const -{ - return new ActionMoveBy(m_nAnimationInterval / 1000.0f, m_MoveVector); -} - -ActionMoveBy * ActionMoveBy::reverse() const -{ - return new ActionMoveBy(m_nTotalDuration / 1000.0f, CVector(-m_MoveVector.x, -m_MoveVector.y)); -} \ No newline at end of file diff --git a/Easy2D/Action/ActionMoveTo.cpp b/Easy2D/Action/ActionMoveTo.cpp deleted file mode 100644 index c4249317..00000000 --- a/Easy2D/Action/ActionMoveTo.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "..\easy2d.h" - -ActionMoveTo::ActionMoveTo(float duration, CPoint pos) : - ActionMoveBy(duration, CVector()) -{ - m_EndPos = pos; -} - -ActionMoveTo::~ActionMoveTo() -{ -} - -ActionMoveTo * ActionMoveTo::copy() const -{ - return new ActionMoveTo(m_nAnimationInterval / 1000.0f, m_EndPos); -} - -void ActionMoveTo::_init() -{ - ActionMoveBy::_init(); - m_MoveVector = m_EndPos - m_BeginPos; -} - -void ActionMoveTo::_reset() -{ - ActionMoveBy::_reset(); -} diff --git a/Easy2D/Action/ActionNeverStop.cpp b/Easy2D/Action/ActionNeverStop.cpp deleted file mode 100644 index ac11b65c..00000000 --- a/Easy2D/Action/ActionNeverStop.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "..\easy2d.h" - -ActionNeverStop::ActionNeverStop(Action * action) : - m_Action(action) -{ - m_Action->retain(); -} - -ActionNeverStop::~ActionNeverStop() -{ - SafeRelease(m_Action); -} - -ActionNeverStop * ActionNeverStop::copy() const -{ - return new ActionNeverStop(m_Action->copy()); -} - -void ActionNeverStop::_init() -{ - Action::_init(); - m_Action->m_pTargetSprite = m_pTargetSprite; - m_Action->_init(); -} - -void ActionNeverStop::_exec(std::chrono::steady_clock::time_point nNow) -{ - m_Action->_exec(nNow); - - if (m_Action->isEnding()) - { - m_Action->_reset(); - } -} - -void ActionNeverStop::_reset() -{ - Action::_reset(); -} diff --git a/Easy2D/Action/ActionOpacityBy.cpp b/Easy2D/Action/ActionOpacityBy.cpp deleted file mode 100644 index 2d9ea7c0..00000000 --- a/Easy2D/Action/ActionOpacityBy.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" - -ActionOpacityBy::ActionOpacityBy(float duration, float opacity) : - Animation(duration) -{ - m_nVariation = opacity; -} - -ActionOpacityBy::~ActionOpacityBy() -{ -} - -void ActionOpacityBy::_init() -{ - Animation::_init(); - m_nBeginVal = m_pTargetSprite->getOpacity(); -} - -void ActionOpacityBy::_exec(steady_clock::time_point nNow) -{ - while (Animation::_isDelayEnough(nNow)) - { - // ƶλ - float scale = float(m_nDuration) / m_nTotalDuration; - // ƶ Sprite - m_pTargetSprite->setOpacity(m_nBeginVal + m_nVariation * scale); - // ж϶Ƿ - if (_isEnd()) - { - this->stop(); - break; - } - } -} - -void ActionOpacityBy::_reset() -{ - Animation::_reset(); -} - -ActionOpacityBy * ActionOpacityBy::copy() const -{ - return new ActionOpacityBy(m_nAnimationInterval / 1000.0f, m_nVariation); -} - -ActionOpacityBy * ActionOpacityBy::reverse() const -{ - return new ActionOpacityBy(m_nTotalDuration / 1000.0f, -m_nVariation); -} \ No newline at end of file diff --git a/Easy2D/Action/ActionOpacityTo.cpp b/Easy2D/Action/ActionOpacityTo.cpp deleted file mode 100644 index 5bd7c001..00000000 --- a/Easy2D/Action/ActionOpacityTo.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "..\easy2d.h" - -ActionOpacityTo::ActionOpacityTo(float duration, float opacity) : - ActionOpacityBy(duration, 0) -{ - m_nEndVal = opacity; -} - -ActionOpacityTo::~ActionOpacityTo() -{ -} - -ActionOpacityTo * ActionOpacityTo::copy() const -{ - return new ActionOpacityTo(m_nAnimationInterval / 1000.0f, m_nEndVal); -} - -void ActionOpacityTo::_init() -{ - ActionOpacityBy::_init(); - m_nVariation = m_nEndVal - m_nBeginVal; -} - -void ActionOpacityTo::_reset() -{ - ActionOpacityBy::_reset(); -} diff --git a/Easy2D/Action/ActionScaleBy.cpp b/Easy2D/Action/ActionScaleBy.cpp deleted file mode 100644 index b86f0f5c..00000000 --- a/Easy2D/Action/ActionScaleBy.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" - -ActionScaleBy::ActionScaleBy(float duration, float scaleX, float scaleY) : - Animation(duration) -{ - m_nVariationX = scaleX; - m_nVariationY = scaleY; -} - -ActionScaleBy::~ActionScaleBy() -{ -} - -void ActionScaleBy::_init() -{ - Animation::_init(); - m_nBeginScaleX = m_pTargetSprite->getScaleX(); - m_nBeginScaleY = m_pTargetSprite->getScaleY(); -} - -void ActionScaleBy::_exec(steady_clock::time_point nNow) -{ - while (Animation::_isDelayEnough(nNow)) - { - // ƶλ - float scale = float(m_nDuration) / m_nTotalDuration; - // ƶ Sprite - m_pTargetSprite->setScale(m_nBeginScaleX + m_nVariationX * scale, m_nBeginScaleX + m_nVariationX * scale); - // ж϶Ƿ - if (_isEnd()) - { - this->stop(); - break; - } - } -} - -void ActionScaleBy::_reset() -{ - Animation::_reset(); -} - -ActionScaleBy * ActionScaleBy::copy() const -{ - return new ActionScaleBy(m_nAnimationInterval / 1000.0f, m_nVariationX, m_nVariationY); -} - -ActionScaleBy * ActionScaleBy::reverse() const -{ - return new ActionScaleBy(m_nTotalDuration / 1000.0f, -m_nVariationX, -m_nVariationY); -} \ No newline at end of file diff --git a/Easy2D/Action/ActionScaleTo.cpp b/Easy2D/Action/ActionScaleTo.cpp deleted file mode 100644 index 76b8fdcc..00000000 --- a/Easy2D/Action/ActionScaleTo.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "..\easy2d.h" - -ActionScaleTo::ActionScaleTo(float duration, float scaleX, float scaleY) : - ActionScaleBy(duration, 0, 0) -{ - m_nEndScaleX = scaleX; - m_nEndScaleY = scaleY; -} - -ActionScaleTo::~ActionScaleTo() -{ -} - -ActionScaleTo * ActionScaleTo::copy() const -{ - return new ActionScaleTo(m_nAnimationInterval / 1000.0f, m_nEndScaleX, m_nEndScaleY); -} - -void ActionScaleTo::_init() -{ - ActionScaleBy::_init(); - m_nVariationX = m_nEndScaleX - m_nBeginScaleX; - m_nVariationY = m_nEndScaleY - m_nBeginScaleY; -} - -void ActionScaleTo::_reset() -{ - ActionScaleBy::_reset(); -} diff --git a/Easy2D/Action/ActionSequence.cpp b/Easy2D/Action/ActionSequence.cpp deleted file mode 100644 index 911dfde9..00000000 --- a/Easy2D/Action/ActionSequence.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "..\easy2d.h" -#include - -ActionSequence::ActionSequence() : - m_nActionIndex(0) -{ -} - -ActionSequence::ActionSequence(int number, Action * action1, ...) : - m_nActionIndex(0) -{ - va_list params; - va_start(params, number); - - while (number > 0) - { - this->addAction(va_arg(params, Action*)); - number--; - } - - va_end(params); -} - -ActionSequence::~ActionSequence() -{ - for (auto action : m_vActions) - { - SafeRelease(action); - } -} - -void ActionSequence::_init() -{ - Action::_init(); - // жĿ - for (auto action : m_vActions) - { - action->m_pTargetSprite = m_pTargetSprite; - } - // ʼһ - m_vActions[0]->_init(); -} - -void ActionSequence::_exec(std::chrono::steady_clock::time_point nNow) -{ - m_vActions[m_nActionIndex]->_exec(nNow); - - if (m_vActions[m_nActionIndex]->isEnding()) - { - m_nActionIndex++; - if (m_nActionIndex == m_vActions.size()) - { - this->stop(); - } - else - { - m_vActions[m_nActionIndex]->_init(); - } - } -} - -void ActionSequence::_reset() -{ - Action::_reset(); - for (auto action : m_vActions) - { - action->_reset(); - } - m_nActionIndex = 0; -} - -void ActionSequence::addAction(Action * action) -{ - m_vActions.push_back(action); - action->retain(); -} - -ActionSequence * ActionSequence::copy() const -{ - auto a = new ActionSequence(); - for (auto action : m_vActions) - { - a->addAction(action->copy()); - } - return a; -} - -ActionSequence * ActionSequence::reverse(bool actionReverse) const -{ - auto a = new ActionSequence(); - for (auto action : a->m_vActions) - { - if (actionReverse) - { - a->addAction(action->reverse()); - } - else - { - a->addAction(action->copy()); - } - } - // ˳ - a->m_vActions.reserve(m_vActions.size()); - return a; -} \ No newline at end of file diff --git a/Easy2D/Action/ActionTwo.cpp b/Easy2D/Action/ActionTwo.cpp deleted file mode 100644 index 669ebcd4..00000000 --- a/Easy2D/Action/ActionTwo.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "..\easy2d.h" - -ActionTwo::ActionTwo(Action * actionFirst, Action * actionSecond) : - m_FirstAction(actionFirst), - m_SecondAction(actionSecond) -{ - m_FirstAction->retain(); - m_SecondAction->retain(); -} - -ActionTwo::~ActionTwo() -{ - SafeRelease(m_FirstAction); - SafeRelease(m_SecondAction); -} - -ActionTwo * ActionTwo::copy() const -{ - return new ActionTwo(m_FirstAction->copy(), m_SecondAction->copy()); -} - -ActionTwo * ActionTwo::reverse(bool actionReverse) const -{ - if (actionReverse) - { - return new ActionTwo(m_SecondAction->reverse(), m_FirstAction->reverse()); - } - else - { - return new ActionTwo(m_SecondAction->copy(), m_FirstAction->copy()); - } -} - -void ActionTwo::_init() -{ - Action::_init(); - m_FirstAction->m_pTargetSprite = m_pTargetSprite; - m_SecondAction->m_pTargetSprite = m_pTargetSprite; - - m_FirstAction->_init(); -} - -void ActionTwo::_exec(std::chrono::steady_clock::time_point nNow) -{ - if (!m_FirstAction->isEnding()) - { - m_FirstAction->_exec(nNow); - if (m_FirstAction->isEnding()) - { - // true ʾһѾ - m_SecondAction->_init(); - } - } - else if (!m_SecondAction->isEnding()) - { - m_SecondAction->_exec(nNow); - } - else - { - this->stop(); - } -} - -void ActionTwo::_reset() -{ - Action::_reset(); - - m_FirstAction->_reset(); - m_SecondAction->_reset(); -} diff --git a/Easy2D/Action/Animation.cpp b/Easy2D/Action/Animation.cpp deleted file mode 100644 index 0ad44d20..00000000 --- a/Easy2D/Action/Animation.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" - -Animation::Animation(float duration) -{ - m_nDuration = 0; - m_nTotalDuration = UINT(duration * 1000); -} - -Animation::~Animation() -{ -} - -bool Animation::_isEnd() const -{ - return m_nDuration >= m_nTotalDuration; -} - -void Animation::_init() -{ - Action::_init(); - // ¼ǰʱ - m_nLast = steady_clock::now(); -} - -bool Animation::_isDelayEnough(steady_clock::time_point nNow) -{ - // жʱǷ㹻 - if (duration_cast(nNow - m_nLast).count() > m_nAnimationInterval) - { - // ¼¼ʱ - m_nLast += milliseconds(m_nAnimationInterval); - m_nDuration += m_nAnimationInterval; - return true; - } - return false; -} - -void Animation::_reset() -{ - Action::_reset(); - m_nDuration = 0; - // ¼ǰʱ - m_nLast = steady_clock::now(); -} diff --git a/Easy2D/Base/EApp.cpp b/Easy2D/Base/EApp.cpp index b19cb5e7..622ae220 100644 --- a/Easy2D/Base/EApp.cpp +++ b/Easy2D/Base/EApp.cpp @@ -1,5 +1,6 @@ #include "..\ebase.h" #include "..\Win\winbase.h" +#include "..\etools.h" #include #include #include @@ -18,7 +19,7 @@ std::stack s_SceneStack; e2d::EApp::EApp() : m_bRunning(false) - , m_ClearColor(EColor::White) + , m_ClearColor(EColor::Black) , m_bSaveScene(true) , m_pCurrentScene(nullptr) , m_pNextScene(nullptr) @@ -46,72 +47,74 @@ bool e2d::EApp::init(e2d::EString title, e2d::ESize size, bool bShowConsole /* = bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShowConsole /* = false */) { - m_sTitle = title; - HRESULT hr; hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { - // رտ̨. - if (bShowConsole) + // رտ̨ + if (!bShowConsole) { - HWND hwnd = FindWindow(L"ConsoleWindowClass", NULL); + HWND consoleHWnd = FindWindow(L"ConsoleWindowClass", NULL); - if (hwnd) + if (consoleHWnd) { - ShowWindow(hwnd, SW_HIDE); + ShowWindow(consoleHWnd, SW_HIDE); } } + + // ʼ device-indpendent Դ + // Direct2D factory. + hr = _createDeviceIndependentResources(); } if (SUCCEEDED(hr)) { - // ʼ device-indpendent Դ - // Direct2D factory. - hr = _createDeviceIndependentResources(); + // עᴰ + WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = EApp::WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = sizeof(LONG_PTR); + wcex.hInstance = HINST_THISCOMPONENT; + wcex.hbrBackground = NULL; + wcex.lpszMenuName = NULL; + wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); + wcex.lpszClassName = L"E2DApp"; - if (SUCCEEDED(hr)) + RegisterClassEx(&wcex); + + + // Because the CreateWindow function takes its size in pixels, + // obtain the system DPI and use it to scale the window size. + FLOAT dpiX, dpiY; + + // The factory returns the current system DPI. This is also the value it will use + // to create its own windows. + GetFactory()->GetDesktopDpi(&dpiX, &dpiY); + + m_sTitle = title; + + // Create the window. + GetHWnd() = CreateWindow( + L"E2DApp", + m_sTitle.c_str(), + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + static_cast(ceil(width * dpiX / 96.f)), + static_cast(ceil(height * dpiY / 96.f)), + NULL, + NULL, + HINST_THISCOMPONENT, + this + ); + + hr = GetHWnd() ? S_OK : E_FAIL; + if (FAILED(hr)) { - // עᴰ - WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = EApp::WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = sizeof(LONG_PTR); - wcex.hInstance = HINST_THISCOMPONENT; - wcex.hbrBackground = NULL; - wcex.lpszMenuName = NULL; - wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); - wcex.lpszClassName = L"E2DApp"; - - RegisterClassEx(&wcex); - - - // Because the CreateWindow function takes its size in pixels, - // obtain the system DPI and use it to scale the window size. - FLOAT dpiX, dpiY; - - // The factory returns the current system DPI. This is also the value it will use - // to create its own windows. - GetFactory()->GetDesktopDpi(&dpiX, &dpiY); - - - // Create the window. - GetHWnd() = CreateWindow( - L"E2DApp", - m_sTitle.c_str(), - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, - CW_USEDEFAULT, - static_cast(ceil(width * dpiX / 96.f)), - static_cast(ceil(height * dpiY / 96.f)), - NULL, - NULL, - HINST_THISCOMPONENT, - this - ); - hr = GetHWnd() ? S_OK : E_FAIL; + UnregisterClass(L"E2DApp", HINST_THISCOMPONENT); + MessageBox(nullptr, L"Create Window Failed!", L"Error", MB_OK); } } @@ -126,6 +129,9 @@ bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShow // Ϸ void e2d::EApp::run() { + ASSERT(m_pNextScene != nullptr); + // һ + _enterNextScene(); // ʾ ShowWindow(GetHWnd(), SW_SHOWNORMAL); UpdateWindow(GetHWnd()); @@ -181,7 +187,7 @@ void e2d::EApp::_mainLoop() { // ¼ǰʱ nLast = nNow; - // + // ִϷ _onControl(); // ˢϷ _onRender(); @@ -213,7 +219,7 @@ void e2d::EApp::_onControl() //KeyMsg::__exec(); // ̰ //Timer::__exec(); // ʱִг //ActionManager::__exec(); // ִг - //EObjectManager::__flush(); // ˢڴ + EObjectManager::__flush(); // ˢڴ } // This method discards device-specific @@ -233,7 +239,7 @@ bool e2d::EApp::_onRender() GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor)); - m_pCurrentScene->_onDraw(); // Ƶǰ + m_pCurrentScene->_onRender(); // Ƶǰ hr = GetRenderTarget()->EndDraw(); } @@ -474,7 +480,7 @@ HRESULT e2d::EApp::_createDeviceIndependentResources() if (FAILED(hr)) { - MessageBox(nullptr, L"Create Device Independent Resources Fail!", L"Error", MB_OK); + MessageBox(nullptr, L"Create Device Independent Resources Failed!", L"Error", MB_OK); } return hr; @@ -506,6 +512,11 @@ HRESULT e2d::EApp::_createDeviceResources() ); } + if (FAILED(hr)) + { + MessageBox(nullptr, L"Create Device Resources Failed!", L"Error", MB_OK); + } + return hr; } @@ -537,10 +548,10 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam if (message == WM_CREATE) { LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; - EApp *pEApp = (EApp *)pcs->lpCreateParams; + e2d::EApp *pEApp = (e2d::EApp *)pcs->lpCreateParams; ::SetWindowLongPtrW( - GetHWnd(), + hWnd, GWLP_USERDATA, PtrToUlong(pEApp) ); @@ -549,9 +560,9 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam } else { - EApp *pEApp = reinterpret_cast(static_cast( + e2d::EApp *pEApp = reinterpret_cast(static_cast( ::GetWindowLongPtrW( - GetHWnd(), + hWnd, GWLP_USERDATA ))); @@ -572,6 +583,23 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam } while (msg.wParam != WA_ACTIVE); } }*/ + case WM_LBUTTONUP: + case WM_LBUTTONDOWN: + case WM_LBUTTONDBLCLK: + case WM_MBUTTONUP: + case WM_MBUTTONDOWN: + case WM_MBUTTONDBLCLK: + case WM_RBUTTONUP: + case WM_RBUTTONDOWN: + case WM_RBUTTONDBLCLK: + case WM_MOUSEMOVE: + case WM_MOUSEWHEEL: + { + EMsgManager::setMouseMsg(message); + } + result = 0; + break; + case WM_SIZE: { UINT width = LOWORD(lParam); @@ -584,7 +612,7 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam case WM_DISPLAYCHANGE: { - InvalidateRect(GetHWnd(), NULL, FALSE); + InvalidateRect(hWnd, NULL, FALSE); } result = 0; wasHandled = true; @@ -593,7 +621,7 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam case WM_PAINT: { pEApp->_onRender(); - ValidateRect(GetHWnd(), NULL); + ValidateRect(hWnd, NULL); } result = 0; wasHandled = true; @@ -611,7 +639,7 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam if (!wasHandled) { - result = DefWindowProc(GetHWnd(), message, wParam, lParam); + result = DefWindowProc(hWnd, message, wParam, lParam); } } diff --git a/Easy2D/Base/EScene.cpp b/Easy2D/Base/EScene.cpp index a33dc05d..2de8ed04 100644 --- a/Easy2D/Base/EScene.cpp +++ b/Easy2D/Base/EScene.cpp @@ -25,12 +25,12 @@ void e2d::EScene::_exec() } } -void e2d::EScene::_onDraw() +void e2d::EScene::_onRender() { // нڵ for (auto child : m_vChildren) { - child->_onDraw(); + child->_onRender(); } } @@ -46,7 +46,7 @@ void e2d::EScene::onExit() { } -void e2d::EScene::add(ENode * child, int zOrder) +void e2d::EScene::add(ENode * child, int zOrder /* = 0 */) { // ӵĽڵǿ ASSERT(child != nullptr); @@ -80,7 +80,7 @@ void e2d::EScene::add(ENode * child, int zOrder) } } -bool e2d::EScene::del(ENode * child) +bool e2d::EScene::del(ENode * child, bool autoRelease /* = true */) { if (child == nullptr) return false; @@ -91,6 +91,7 @@ bool e2d::EScene::del(ENode * child) // ҵͬڵ if (*iter == child) { + if (autoRelease) (*iter)->autoRelease(); // üһ (*iter)->release(); // ȥýڵ diff --git a/Easy2D/Easy2D.vcxproj b/Easy2D/Easy2D.vcxproj index 4315f90b..410a9fdb 100644 --- a/Easy2D/Easy2D.vcxproj +++ b/Easy2D/Easy2D.vcxproj @@ -1,34 +1,18 @@  - - DebugW - Win32 - - - DebugW - x64 - Debug Win32 - - ReleaseW - Win32 - - - ReleaseW - x64 - - - Release - Win32 - Debug x64 + + Release + Win32 + Release x64 @@ -43,25 +27,12 @@ - StaticLibrary - true - v141 - MultiByte - - StaticLibrary true v141 Unicode - StaticLibrary - false - v141 - false - MultiByte - - StaticLibrary false v141 @@ -69,25 +40,12 @@ Unicode - StaticLibrary - true - v141 - MultiByte - - StaticLibrary true v141 Unicode - StaticLibrary - false - v141 - false - MultiByte - - StaticLibrary false v141 @@ -99,74 +57,38 @@ - + - + - + - - - - - - - - - - - - - + - true - Easy2Dd - $(SolutionDir)$(Platform)\ - $(Platform)\$(Configuration)\ - - true Easy2Ddw $(SolutionDir)$(Platform)\ $(Platform)\$(Configuration)\ - true - Easy2Dd - $(SolutionDir)$(Platform)\ - $(Platform)\$(Configuration)\ - - true Easy2Ddw $(SolutionDir)$(Platform)\ $(Platform)\$(Configuration)\ - false - Easy2D - $(SolutionDir)$(Platform)\ - $(Platform)\$(Configuration)\ - - false Easy2Dw $(SolutionDir)$(Platform)\ $(Platform)\$(Configuration)\ - false - Easy2D - $(SolutionDir)$(Platform)\ - $(Platform)\$(Configuration)\ - - false Easy2Dw $(SolutionDir)$(Platform)\ @@ -179,31 +101,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - None - false - - - Console - true - - - false - - - - - - - - - - - NotUsing - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - None + EditAndContinue false @@ -223,27 +121,6 @@ - - NotUsing - Level3 - Disabled - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - None - false - - - Console - true - - - - - - - - - NotUsing Level3 @@ -265,30 +142,6 @@ - - NotUsing - Level3 - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - None - - - Console - true - true - true - - - - - - - - - NotUsing Level3 @@ -315,30 +168,6 @@ - - NotUsing - Level3 - MaxSpeed - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - None - - - Console - true - true - true - - - - - - - - - NotUsing Level3 @@ -367,6 +196,8 @@ + + diff --git a/Easy2D/Easy2D.vcxproj.filters b/Easy2D/Easy2D.vcxproj.filters index a6bbd9f1..cdc50456 100644 --- a/Easy2D/Easy2D.vcxproj.filters +++ b/Easy2D/Easy2D.vcxproj.filters @@ -1,72 +1,57 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {261633d3-3814-40c7-bd6d-201ede6c6ade} - - + {2f0f3d30-bfc2-4aea-a170-258bbaacaa79} - + + {42d46a92-c043-4667-8c20-358319e5c313} + + {51864c81-02ee-4043-bf09-9ce3cbe5b6da} - - {42d46a92-c043-4667-8c20-358319e5c313} + + {261633d3-3814-40c7-bd6d-201ede6c6ade} + + + {bdc55351-669e-4ee5-ba0b-ee0e4b628fea} - 源文件\Win + Win - 源文件\Base + Base - 源文件\Base + Base - 源文件\Node + Node - 源文件\Tool + Tool - 源文件\Base + Base + + + Tool + + + Tool\Listener - - 头文件 - - - 头文件 - - - 头文件 - - 源文件\Win - - - 头文件 - - - 头文件 - - - 头文件 + Win + + + + + + \ No newline at end of file diff --git a/Easy2D/EasyX/easyx.h b/Easy2D/EasyX/easyx.h deleted file mode 100644 index d5a35fac..00000000 --- a/Easy2D/EasyX/easyx.h +++ /dev/null @@ -1,321 +0,0 @@ -/****************************************************** - * EasyX Library for C++ (Ver:20170827(beta)) - * http://www.easyx.cn - * - * EasyX.h - * VC ʵּ򵥵Ļͼ - ******************************************************/ - -#pragma once - -#ifndef WINVER -#define WINVER 0x0400 // Specifies that the minimum required platform is Windows 95 and Windows NT 4.0. -#endif - -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 // Specifies that the minimum required platform is Windows 2000. -#endif - -#ifndef _WIN32_WINDOWS -#define _WIN32_WINDOWS 0x0410 // Specifies that the minimum required platform is Windows 98. -#endif - - -#ifndef __cplusplus -#error EasyX is only for C++ -#endif - - -#include -#include - -// ͼڳʼ -#define SHOWCONSOLE 1 // ͼδʱ̨ʾ -#define NOCLOSE 2 // ûйرչ -#define NOMINIMIZE 4 // ûС - -// ɫ -#define BLACK 0 -#define BLUE 0xAA0000 -#define GREEN 0x00AA00 -#define CYAN 0xAAAA00 -#define RED 0x0000AA -#define MAGENTA 0xAA00AA -#define BROWN 0x0055AA -#define LIGHTGRAY 0xAAAAAA -#define DARKGRAY 0x555555 -#define LIGHTBLUE 0xFF5555 -#define LIGHTGREEN 0x55FF55 -#define LIGHTCYAN 0xFFFF55 -#define LIGHTRED 0x5555FF -#define LIGHTMAGENTA 0xFF55FF -#define YELLOW 0x55FFFF -#define WHITE 0xFFFFFF - -// ɫת -#define BGR(color) ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) ) - - -class IMAGE; - -// ߵʽ -class LINESTYLE -{ -public: - LINESTYLE(); - LINESTYLE(const LINESTYLE &style); - LINESTYLE& operator = (const LINESTYLE &style); // ֵغ - virtual ~LINESTYLE(); - - DWORD style; - DWORD thickness; - DWORD *puserstyle; - DWORD userstylecount; -}; - -class FILLSTYLE -{ -public: - FILLSTYLE(); - FILLSTYLE(const FILLSTYLE &style); - FILLSTYLE& operator = (const FILLSTYLE &style); // ֵغ - virtual ~FILLSTYLE(); - - int style; // ʽ - long hatch; // ͼʽ - IMAGE* ppattern; // ͼ -}; - -// ͼ -class IMAGE -{ -public: - int getwidth() const; // ȡĿ - int getheight() const; // ȡĸ߶ - -private: - int width, height; // Ŀ - HBITMAP m_hBmp; - HDC m_hMemDC; - int m_MemCurX; // ǰX - int m_MemCurY; // ǰY - float m_data[6]; - COLORREF m_LineColor; // ǰɫ - COLORREF m_FillColor; // ǰɫ - COLORREF m_TextColor; // ǰɫ - COLORREF m_BkColor; // ǰɫ - DWORD* m_pBuffer; // ͼڴ - - LINESTYLE m_LineStyle; // ʽ - FILLSTYLE m_FillStyle; // ʽ - - virtual void SetDefault(); // ΪĬ״̬ - -public: - IMAGE(int _width = 0, int _height = 0); // ͼ - IMAGE(const IMAGE &img); // 캯 - IMAGE& operator = (const IMAGE &img); // ֵغ - virtual ~IMAGE(); - virtual void Resize(int _width, int _height); // ߴ -}; - - - -// ͼģʽغ - -HWND initgraph(int width, int height, int flag = NULL); // ʼͼλ -void closegraph(); // رͼλ - -// ͼ - -void cleardevice(); // -void setcliprgn(HRGN hrgn); // õǰͼ豸IJü -void clearcliprgn(); // üĻ - -void getlinestyle(LINESTYLE* pstyle); // ȡǰʽ -void setlinestyle(const LINESTYLE* pstyle); // õǰʽ -void setlinestyle(int style, int thickness = 1, const DWORD *puserstyle = NULL, DWORD userstylecount = 0); // õǰʽ -void getfillstyle(FILLSTYLE* pstyle); // ȡǰʽ -void setfillstyle(const FILLSTYLE* pstyle); // õǰʽ -void setfillstyle(int style, long hatch = NULL, IMAGE* ppattern = NULL); // õǰʽ -void setfillstyle(BYTE* ppattern8x8); // õǰʽ - -void setorigin(int x, int y); // ԭ -void getaspectratio(float *pxasp, float *pyasp); // ȡǰ -void setaspectratio(float xasp, float yasp); // õǰ - -int getrop2(); // ȡǰĶԪդģʽ -void setrop2(int mode); // ǰĶԪդģʽ -int getpolyfillmode(); // ȡģʽ -void setpolyfillmode(int mode); // öģʽ - -void graphdefaults(); // лͼΪĬֵ - -COLORREF getlinecolor(); // ȡǰɫ -void setlinecolor(COLORREF color); // õǰɫ -COLORREF gettextcolor(); // ȡǰɫ -void settextcolor(COLORREF color); // õǰɫ -COLORREF getfillcolor(); // ȡǰɫ -void setfillcolor(COLORREF color); // õǰɫ -COLORREF getbkcolor(); // ȡǰͼɫ -void setbkcolor(COLORREF color); // õǰͼɫ -int getbkmode(); // ȡģʽ -void setbkmode(int mode); // ñģʽ - -// ɫģת -COLORREF RGBtoGRAY(COLORREF rgb); -void RGBtoHSL(COLORREF rgb, float *H, float *S, float *L); -void RGBtoHSV(COLORREF rgb, float *H, float *S, float *V); -COLORREF HSLtoRGB(float H, float S, float L); -COLORREF HSVtoRGB(float H, float S, float V); - - -// ͼ - -COLORREF getpixel(int x, int y); // ȡɫ -void putpixel(int x, int y, COLORREF color); // - -void moveto(int x, int y); // ƶǰ() -void moverel(int dx, int dy); // ƶǰ() - -void line(int x1, int y1, int x2, int y2); // -void linerel(int dx, int dy); // () -void lineto(int x, int y); // () - -void rectangle (int left, int top, int right, int bottom); // -void fillrectangle (int left, int top, int right, int bottom); // (б߿) -void solidrectangle(int left, int top, int right, int bottom); // (ޱ߿) -void clearrectangle(int left, int top, int right, int bottom); // վ - -void circle (int x, int y, int radius); // Բ -void fillcircle (int x, int y, int radius); // Բ(б߿) -void solidcircle(int x, int y, int radius); // Բ(ޱ߿) -void clearcircle(int x, int y, int radius); // Բ - -void ellipse (int left, int top, int right, int bottom); // Բ -void fillellipse (int left, int top, int right, int bottom); // Բ(б߿) -void solidellipse(int left, int top, int right, int bottom); // Բ(ޱ߿) -void clearellipse(int left, int top, int right, int bottom); // Բ - -void roundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // ԲǾ -void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // ԲǾ(б߿) -void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // ԲǾ(ޱ߿) -void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // ԲǾ - -void arc (int left, int top, int right, int bottom, double stangle, double endangle); // Բ(ʼǶȺֹǶΪ) -void pie (int left, int top, int right, int bottom, double stangle, double endangle); // Բ(ʼǶȺֹǶΪ) -void fillpie (int left, int top, int right, int bottom, double stangle, double endangle); // Բ(б߿) -void solidpie(int left, int top, int right, int bottom, double stangle, double endangle); // Բ(ޱ߿) -void clearpie(int left, int top, int right, int bottom, double stangle, double endangle); // Բ - -void polyline (const POINT *points, int num); // -void polygon (const POINT *points, int num); // -void fillpolygon (const POINT *points, int num); // Ķ(б߿) -void solidpolygon(const POINT *points, int num); // Ķ(ޱ߿) -void clearpolygon(const POINT *points, int num); // ն - -void floodfill(int x, int y, int border); // - - - -// غ - -void outtext(LPCTSTR str); // ڵǰλַ -void outtext(TCHAR c); // ڵǰλַ -void outtextxy(int x, int y, LPCTSTR str); // ָλַ -void outtextxy(int x, int y, TCHAR c); // ָλַ -int textwidth(LPCTSTR str); // ȡַռõؿ -int textwidth(TCHAR c); // ȡַռõؿ -int textheight(LPCTSTR str); // ȡַռõظ -int textheight(TCHAR c); // ȡַռõظ -int drawtext(LPCTSTR str, RECT* pRect, UINT uFormat); // ָָʽַ -int drawtext(TCHAR c, RECT* pRect, UINT uFormat); // ָָʽַ - -// õǰʽ() -// nHeight: ַƽ߶ȣ -// nWidth: ַƽ(0 ʾӦ) -// lpszFace: ƣ -// nEscapement: ַдǶ(λ 0.1 ) -// nOrientation: ÿַдǶ(λ 0.1 ) -// nWeight: ַıʻϸ(0 ʾĬϴϸ) -// bItalic: Ƿб壻 -// bUnderline: Ƿ»ߣ -// bStrikeOut: Ƿɾߣ -// fbCharSet: ַָ -// fbOutPrecision: ֵָȣ -// fbClipPrecision: ֵָļȣ -// fbQuality: ֵָ -// fbPitchAndFamily: ָԳ淽ʽϵС -void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace); -void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut); -void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily); -void settextstyle(const LOGFONT *font); // õǰʽ -void gettextstyle(LOGFONT *font); // ȡǰʽ - - - -// ͼ -void loadimage(IMAGE *pDstImg, LPCTSTR pImgFile, int nWidth = 0, int nHeight = 0, bool bResize = false); // ͼƬļȡͼ(bmp/jpg/gif/emf/wmf) -void loadimage(IMAGE *pDstImg, LPCTSTR pResType, LPCTSTR pResName, int nWidth = 0, int nHeight = 0, bool bResize = false); // Դļȡͼ(bmp/jpg/gif/emf/wmf) -void saveimage(LPCTSTR pImgFile, IMAGE* pImg = NULL); // ͼ -void getimage(IMAGE *pDstImg, int srcX, int srcY, int srcWidth, int srcHeight); // ӵǰͼ豸ȡͼ -void putimage(int dstX, int dstY, const IMAGE *pSrcImg, DWORD dwRop = SRCCOPY); // ͼĻ -void putimage(int dstX, int dstY, int dstWidth, int dstHeight, const IMAGE *pSrcImg, int srcX, int srcY, DWORD dwRop = SRCCOPY); // ͼĻ(ָ) -void rotateimage(IMAGE *dstimg, IMAGE *srcimg, double radian, COLORREF bkcolor = BLACK, bool autosize = false, bool highquality = true);// תͼ -void Resize(IMAGE* pImg, int width, int height); // ͼ豸ĴС -DWORD* GetImageBuffer(IMAGE* pImg = NULL); // ȡͼ豸Դָ -IMAGE* GetWorkingImage(); // ȡǰͼ豸 -void SetWorkingImage(IMAGE* pImg = NULL); // õǰͼ豸 -HDC GetImageHDC(IMAGE* pImg = NULL); // ȡͼ豸(HDC) - - -// - -int getwidth(); // ȡͼ -int getheight(); // ȡͼ߶ -int getx(); // ȡǰ x -int gety(); // ȡǰ y - -void BeginBatchDraw(); // ʼ -void FlushBatchDraw(); // ִδɵĻ -void FlushBatchDraw(int left, int top, int right, int bottom); // ִָδɵĻ -void EndBatchDraw(); // ƣִδɵĻ -void EndBatchDraw(int left, int top, int right, int bottom); // ƣִָδɵĻ - -HWND GetHWnd(); // ȡͼھ(HWND) -TCHAR* GetEasyXVer(); // ȡ EasyX ǰ汾 - -// ȡû -bool InputBox(LPTSTR pString, int nMaxCount, LPCTSTR pPrompt = NULL, LPCTSTR pTitle = NULL, LPCTSTR pDefault = NULL, int width = 0, int height = 0, bool bOnlyOK = true); - - - -// Ϣ -// ֧Ϣ -// WM_MOUSEMOVE ƶ -// WM_MOUSEWHEEL ֲ -// WM_LBUTTONDOWN -// WM_LBUTTONUP -// WM_LBUTTONDBLCLK ˫ -// WM_MBUTTONDOWN м -// WM_MBUTTONUP м -// WM_MBUTTONDBLCLK м˫ -// WM_RBUTTONDOWN Ҽ -// WM_RBUTTONUP Ҽ -// WM_RBUTTONDBLCLK Ҽ˫ -struct MOUSEMSG -{ - UINT uMsg; // ǰϢ - bool mkCtrl; // Ctrl Ƿ - bool mkShift; // Shift Ƿ - bool mkLButton; // Ƿ - bool mkMButton; // мǷ - bool mkRButton; // ҼǷ - short x; // ǰ x - short y; // ǰ y - short wheel; // ֵֹ (120 ı) -}; - -bool MouseHit(); // ǷϢ -MOUSEMSG GetMouseMsg(); // ȡһϢûУ͵ȴ -void FlushMouseMsgBuffer(); // Ϣ diff --git a/Easy2D/EasyX/x64/EasyXa.lib b/Easy2D/EasyX/x64/EasyXa.lib deleted file mode 100644 index d1c996b2..00000000 Binary files a/Easy2D/EasyX/x64/EasyXa.lib and /dev/null differ diff --git a/Easy2D/EasyX/x64/EasyXw.lib b/Easy2D/EasyX/x64/EasyXw.lib deleted file mode 100644 index f47b4075..00000000 Binary files a/Easy2D/EasyX/x64/EasyXw.lib and /dev/null differ diff --git a/Easy2D/EasyX/x86/EasyXa.lib b/Easy2D/EasyX/x86/EasyXa.lib deleted file mode 100644 index db14e5bf..00000000 Binary files a/Easy2D/EasyX/x86/EasyXa.lib and /dev/null differ diff --git a/Easy2D/EasyX/x86/EasyXw.lib b/Easy2D/EasyX/x86/EasyXw.lib deleted file mode 100644 index c2f75141..00000000 Binary files a/Easy2D/EasyX/x86/EasyXw.lib and /dev/null differ diff --git a/Easy2D/Msg/KeyMsg.cpp b/Easy2D/Msg/KeyMsg.cpp deleted file mode 100644 index b3a76b14..00000000 --- a/Easy2D/Msg/KeyMsg.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" -#include - -// ص -static std::vector s_vListeners; - -// ֵĶ -const VK_KEY KeyMsg::A = 'A'; -const VK_KEY KeyMsg::B = 'B'; -const VK_KEY KeyMsg::C = 'C'; -const VK_KEY KeyMsg::D = 'D'; -const VK_KEY KeyMsg::E = 'E'; -const VK_KEY KeyMsg::F = 'F'; -const VK_KEY KeyMsg::G = 'G'; -const VK_KEY KeyMsg::H = 'H'; -const VK_KEY KeyMsg::I = 'I'; -const VK_KEY KeyMsg::J = 'J'; -const VK_KEY KeyMsg::K = 'K'; -const VK_KEY KeyMsg::L = 'L'; -const VK_KEY KeyMsg::M = 'M'; -const VK_KEY KeyMsg::N = 'N'; -const VK_KEY KeyMsg::O = 'O'; -const VK_KEY KeyMsg::P = 'P'; -const VK_KEY KeyMsg::Q = 'Q'; -const VK_KEY KeyMsg::R = 'R'; -const VK_KEY KeyMsg::S = 'S'; -const VK_KEY KeyMsg::T = 'T'; -const VK_KEY KeyMsg::U = 'U'; -const VK_KEY KeyMsg::V = 'V'; -const VK_KEY KeyMsg::W = 'W'; -const VK_KEY KeyMsg::X = 'X'; -const VK_KEY KeyMsg::Y = 'Y'; -const VK_KEY KeyMsg::Z = 'Z'; -const VK_KEY KeyMsg::NUM_0 = '0'; -const VK_KEY KeyMsg::NUM_1 = '1'; -const VK_KEY KeyMsg::NUM_2 = '2'; -const VK_KEY KeyMsg::NUM_3 = '3'; -const VK_KEY KeyMsg::NUM_4 = '4'; -const VK_KEY KeyMsg::NUM_5 = '5'; -const VK_KEY KeyMsg::NUM_6 = '6'; -const VK_KEY KeyMsg::NUM_7 = '7'; -const VK_KEY KeyMsg::NUM_8 = '8'; -const VK_KEY KeyMsg::NUM_9 = '9'; -const VK_KEY KeyMsg::NUMPAD_0 = VK_NUMPAD0; -const VK_KEY KeyMsg::NUMPAD_1 = VK_NUMPAD1; -const VK_KEY KeyMsg::NUMPAD_2 = VK_NUMPAD2; -const VK_KEY KeyMsg::NUMPAD_3 = VK_NUMPAD3; -const VK_KEY KeyMsg::NUMPAD_4 = VK_NUMPAD4; -const VK_KEY KeyMsg::NUMPAD_5 = VK_NUMPAD5; -const VK_KEY KeyMsg::NUMPAD_6 = VK_NUMPAD6; -const VK_KEY KeyMsg::NUMPAD_7 = VK_NUMPAD7; -const VK_KEY KeyMsg::NUMPAD_8 = VK_NUMPAD8; -const VK_KEY KeyMsg::NUMPAD_9 = VK_NUMPAD9; -const VK_KEY KeyMsg::Enter = VK_RETURN; -const VK_KEY KeyMsg::Space = VK_SPACE; -const VK_KEY KeyMsg::Ctrl = VK_CONTROL; -const VK_KEY KeyMsg::LCtrl = VK_LCONTROL; -const VK_KEY KeyMsg::RCtrl = VK_RCONTROL; -const VK_KEY KeyMsg::Shift = VK_SHIFT; -const VK_KEY KeyMsg::LShift = VK_LSHIFT; -const VK_KEY KeyMsg::RShift = VK_RSHIFT; -const VK_KEY KeyMsg::Up = VK_UP; -const VK_KEY KeyMsg::Down = VK_DOWN; -const VK_KEY KeyMsg::Left = VK_LEFT; -const VK_KEY KeyMsg::Right = VK_RIGHT; -const VK_KEY KeyMsg::Esc = VK_ESCAPE; -const VK_KEY KeyMsg::F1 = VK_F1; -const VK_KEY KeyMsg::F2 = VK_F2; -const VK_KEY KeyMsg::F3 = VK_F3; -const VK_KEY KeyMsg::F4 = VK_F4; -const VK_KEY KeyMsg::F5 = VK_F5; -const VK_KEY KeyMsg::F6 = VK_F6; -const VK_KEY KeyMsg::F7 = VK_F7; -const VK_KEY KeyMsg::F8 = VK_F8; -const VK_KEY KeyMsg::F9 = VK_F9; -const VK_KEY KeyMsg::F10 = VK_F10; -const VK_KEY KeyMsg::F11 = VK_F11; -const VK_KEY KeyMsg::F12 = VK_F12; - -static VK_KEY convert(int ascii); - -KeyMsg::KeyMsg(TString name, const KEY_CALLBACK & callback) : - m_sName(name), - m_callback(callback), - m_pParentScene(nullptr), - m_bRunning(true), - m_bWaiting(false) -{ -} - -KeyMsg::~KeyMsg() -{ -} - -void KeyMsg::onKbHit(VK_KEY key) -{ - m_callback(key); -} - -void KeyMsg::start() -{ - m_bRunning = true; -} - -void KeyMsg::stop() -{ - m_bRunning = false; -} - -void KeyMsg::wait() -{ - m_bWaiting = true; -} - -void KeyMsg::notify() -{ - m_bWaiting = false; -} - -void KeyMsg::__exec() -{ - if (_kbhit()) // ްϢ - { - VK_KEY key = convert(_getch()); // ȡϢ - - for (auto l : s_vListeners) // ַϢ - { - if (!l->m_bWaiting && l->m_bRunning) - { - l->onKbHit(key); // ִаص - } - } - } -} - -void KeyMsg::addListener(TString name, const KEY_CALLBACK & callback) -{ - // µļ - auto listener = new KeyMsg(name, callback); - // ڳ - listener->m_pParentScene = EApp::getLoadingScene(); - // µİص - s_vListeners.push_back(listener); -} - -void KeyMsg::startListener(TString name) -{ - // ͬļ - for (auto l : s_vListeners) - { - if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene()) - { - l->start(); - } - } -} - -void KeyMsg::stopListener(TString name) -{ - // ͬļ - for (auto l : s_vListeners) - { - if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene()) - { - l->stop(); - } - } -} - -void KeyMsg::delListener(TString name) -{ - // - std::vector::iterator iter; - // ѭм - for (iter = s_vListeners.begin(); iter != s_vListeners.end();) - { - // ͬƵļ - if ((*iter)->m_sName == name && (*iter)->m_pParentScene == EApp::getCurrentScene()) - { - // ɾöʱ - delete (*iter); - iter = s_vListeners.erase(iter); - } - else - { - iter++; - } - } -} - -void KeyMsg::notifyAllSceneListeners(EScene * scene) -{ - for (auto l : s_vListeners) - { - if (l->m_pParentScene == scene) - { - l->notify(); - } - } -} - -void KeyMsg::waitAllSceneListeners(EScene * scene) -{ - for (auto l : s_vListeners) - { - if (l->m_pParentScene == scene) - { - l->wait(); - } - } -} - -void KeyMsg::clearAllSceneListeners(EScene * scene) -{ - // - std::vector::iterator iter; - // ѭм - for (iter = s_vListeners.begin(); iter != s_vListeners.end();) - { - // ͬƵļ - if ((*iter)->m_pParentScene == scene) - { - // ɾöʱ - delete (*iter); - iter = s_vListeners.erase(iter); - } - else - { - iter++; - } - } -} - -void KeyMsg::clearAllListeners() -{ - // ɾм - for (auto l : s_vListeners) - { - delete l; - } - // - s_vListeners.clear(); -} - -bool KeyMsg::isKeyDown(VK_KEY key) -{ - // ȡ key İ - return (GetAsyncKeyState(key) & 0x8000); -} - - -VK_KEY convert(int ascii) -{ - // ĸ - if (ascii >= 'a' && ascii <= 'z') - { - return VK_KEY(ascii - ('a' - 'A')); - } - else if (ascii >= 'A' && ascii <= 'Z') - { - return VK_KEY(ascii); - } - // ּ - else if (ascii >= '0' && ascii <= '9') - { - return VK_KEY(ascii); - } - // سոEsc - else if (ascii == 0x0D || ascii == 0x20 || ascii == 0x1B) - { - return VK_KEY(ascii); - } - // ܼ - else if (ascii == 0 || ascii == 0xE0) - { - switch (_getch()) - { - case 72: - return KeyMsg::Up; - case 75: - return KeyMsg::Left; - case 77: - return KeyMsg::Right; - case 80: - return KeyMsg::Down; - case 59: - return KeyMsg::F1; - case 60: - return KeyMsg::F2; - case 61: - return KeyMsg::F3; - case 62: - return KeyMsg::F4; - case 63: - return KeyMsg::F5; - case 64: - return KeyMsg::F6; - case 65: - return KeyMsg::F7; - case 66: - return KeyMsg::F8; - case 67: - return KeyMsg::F9; - case 133: - return KeyMsg::F10; - case 134: - return KeyMsg::F11; - default: - return 0; - } - } - return 0; -} \ No newline at end of file diff --git a/Easy2D/Msg/MouseMsg.cpp b/Easy2D/Msg/MouseMsg.cpp deleted file mode 100644 index 8234e7ef..00000000 --- a/Easy2D/Msg/MouseMsg.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" - -// ص -static std::vector s_vListeners; - -// Ϣ -static MOUSEMSG s_mouseMsg; - -void MouseMsg::__exec() -{ - // ȡϢ - while (MouseHit()) - { - // ȡϢ - s_mouseMsg = GetMouseMsg(); - // ִг - EApp::get()->getCurrentScene()->_exec(); - // ִص - for (auto l : s_vListeners) // ѭе - { - if (!l->m_bWaiting && l->m_bRunning) - { - l->onMouseMsg(); // ִлص - } - } - } -} - -MouseMsg::MouseMsg() : - m_callback([]() {}), - m_pParentScene(nullptr), - m_bRunning(true), - m_bWaiting(false) -{ -} - -MouseMsg::MouseMsg(TString name, const MOUSE_CALLBACK & callback) : - m_sName(name), - m_callback(callback), - m_pParentScene(nullptr), - m_bRunning(true), - m_bWaiting(false) -{ -} - -MouseMsg::~MouseMsg() -{ -} - -void MouseMsg::onMouseMsg() -{ - m_callback(); -} - -void MouseMsg::addListener(TString name, const MOUSE_CALLBACK & callback) -{ - // µļ - auto listener = new MouseMsg(name, callback); - // ڳ - listener->m_pParentScene = EApp::getLoadingScene(); - // µİص - s_vListeners.push_back(listener); -} - -void MouseMsg::startListener(TString name) -{ - // ͬļ - for (auto l : s_vListeners) - { - if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene()) - { - l->start(); - } - } -} - -void MouseMsg::stopListener(TString name) -{ - // ͬļ - for (auto l : s_vListeners) - { - if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene()) - { - l->stop(); - } - } -} - -void MouseMsg::delListener(TString name) -{ - // - std::vector::iterator iter; - // ѭм - for (iter = s_vListeners.begin(); iter != s_vListeners.end();) - { - // ͬƵļ - if ((*iter)->m_sName == name && (*iter)->m_pParentScene == EApp::getCurrentScene()) - { - // ɾöʱ - delete (*iter); - iter = s_vListeners.erase(iter); - } - else - { - iter++; - } - } -} - -void MouseMsg::start() -{ - m_bRunning = true; -} - -void MouseMsg::stop() -{ - m_bRunning = false; -} - -void MouseMsg::wait() -{ - m_bWaiting = true; -} - -void MouseMsg::notify() -{ - m_bWaiting = false; -} - -void MouseMsg::clearAllListeners() -{ - // ɾм - for (auto l : s_vListeners) - { - delete l; - } - // - s_vListeners.clear(); -} - -void MouseMsg::notifyAllSceneListeners(EScene * scene) -{ - for (auto l : s_vListeners) - { - if (l->m_pParentScene == scene) - { - l->notify(); - } - } -} - -void MouseMsg::waitAllSceneListeners(EScene * scene) -{ - for (auto l : s_vListeners) - { - if (l->m_pParentScene == scene) - { - l->wait(); - } - } -} - -void MouseMsg::clearAllSceneListeners(EScene * scene) -{ - // - std::vector::iterator iter; - // ѭм - for (iter = s_vListeners.begin(); iter != s_vListeners.end();) - { - // ͬƵļ - if ((*iter)->m_pParentScene == scene) - { - // ɾöʱ - delete (*iter); - iter = s_vListeners.erase(iter); - } - else - { - iter++; - } - } -} - -bool MouseMsg::isLButtonDown() -{ - return s_mouseMsg.mkLButton; -} - -bool MouseMsg::isRButtonDown() -{ - return s_mouseMsg.mkRButton; -} - -bool MouseMsg::isMButtonDown() -{ - return s_mouseMsg.mkMButton; -} - -int MouseMsg::getX() -{ - return s_mouseMsg.x; -} - -int MouseMsg::getY() -{ - return s_mouseMsg.y; -} - -CPoint MouseMsg::getPos() -{ - return CPoint(s_mouseMsg.x, s_mouseMsg.y); -} - -int MouseMsg::getWheel() -{ - return s_mouseMsg.wheel; -} - -MouseMsg::MESSAGE MouseMsg::getMsg() -{ - return MESSAGE(s_mouseMsg.uMsg); -} diff --git a/Easy2D/Node/BatchNode.cpp b/Easy2D/Node/BatchNode.cpp deleted file mode 100644 index 63716580..00000000 --- a/Easy2D/Node/BatchNode.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" - -BatchNode::BatchNode() -{ -} - - -BatchNode::~BatchNode() -{ - clearAllChildren(); -} - -bool BatchNode::_exec(bool active) -{ - // ڵǷʾ - if (!m_bDisplay) - { - return false; - } - // ӽڵ - for (int i = int(m_vChildren.size() - 1); i >= 0; i--) - { - if (m_vChildren[i]->_exec(active)) - { - active = false; - } - } - // ӽڵȡ˻潹㣬ýڵҲȡ˽ - return !active; -} - -void BatchNode::_onDraw() -{ - // ڵǷʾ - if (!m_bDisplay) - { - return; - } - - for (auto child : m_vChildren) - { - // ӽڵ - child->_onDraw(); - } -} - -void BatchNode::add(Node * child, int z_Order) -{ - if (child == nullptr) return; - - // ýڵĸ - child->setParentScene(this->getParentScene()); - // ýڵڵе z ˳ - child->setZOrder(z_Order); - // üһ - child->retain(); - // ޸ӽڵλ - child->move(getPos()); - - // z ˳ڵ - size_t size = m_vChildren.size(); - for (unsigned i = 0; i <= size; i++) - { - if (i != size) - { - if (z_Order < m_vChildren.at(i)->getZOrder()) - { - m_vChildren.insert(m_vChildren.begin() + i, child); - break; - } - } - else - { - m_vChildren.push_back(child); - break; - } - } -} - -bool BatchNode::del(Node * child) -{ - if (child == nullptr) return false; - - // ѰǷͬڵ - std::vector::iterator iter; - for (iter = m_vChildren.begin(); iter != m_vChildren.end(); iter++) - { - // ҵͬڵ - if ((*iter) == child) - { - // üһ - (*iter)->release(); - // ȥýڵ - m_vChildren.erase(iter); - return true; - } - } - return false; -} - -int BatchNode::getCount() -{ - return (int)m_vChildren.size(); -} - -std::vector& BatchNode::getChildren() -{ - return m_vChildren; -} - -void BatchNode::clearAllChildren() -{ - // нڵüһ - for (auto child : m_vChildren) - { - child->autoRelease(); - child->release(); - } - // մڵ - m_vChildren.clear(); -} - -void BatchNode::setX(int x) -{ - // ƶλ - int var = x - getX(); - // ƶӽڵλ - for (auto child : m_vChildren) - { - child->move(var, 0); - } - Node::setX(x); -} - -void BatchNode::setY(int y) -{ - // ƶλ - int var = y - getY(); - // ƶӽڵλ - for (auto child : m_vChildren) - { - child->move(0, var); - } - Node::setY(y); -} - -void BatchNode::setPos(int x, int y) -{ - // ƶλ - CPoint var(x - getX(), y - getY()); - // ƶӽڵλ - for (auto child : m_vChildren) - { - child->move(var); - } - Node::setPos(x, y); -} - -void BatchNode::setPos(CPoint p) -{ - // ƶλ - CPoint var(p - getPos()); - // ƶӽڵλ - for (auto child : m_vChildren) - { - child->move(var); - } - Node::setPos(p); -} - -void BatchNode::move(int x, int y) -{ - // ƶӽڵλ - for (auto child : m_vChildren) - { - child->move(x, y); - } - Node::move(x, y); -} - -void BatchNode::move(CVector v) -{ - // ƶӽڵλ - for (auto child : m_vChildren) - { - child->move(v); - } - Node::move(v); -} diff --git a/Easy2D/Node/BatchSprite.cpp b/Easy2D/Node/BatchSprite.cpp deleted file mode 100644 index edbb9e84..00000000 --- a/Easy2D/Node/BatchSprite.cpp +++ /dev/null @@ -1,260 +0,0 @@ -#include "..\easy2d.h" - -BatchSprite::BatchSprite() -{ -} - -BatchSprite::~BatchSprite() -{ -} - -void BatchSprite::addSprite(Sprite * sprite, int z_Order) -{ - if (sprite == nullptr) return; - - // ýڵĸ - sprite->setParentScene(this->getParentScene()); - // ýڵڵе z ˳ - sprite->setZOrder(z_Order); - // üһ - sprite->retain(); - - // z ˳ڵ - size_t size = m_vSprites.size(); - for (unsigned i = 0; i <= size; i++) - { - if (i != size) - { - if (z_Order < m_vSprites.at(i)->getZOrder()) - { - m_vSprites.insert(m_vSprites.begin() + i, sprite); - break; - } - } - else - { - m_vSprites.push_back(sprite); - break; - } - } -} - -bool BatchSprite::delSprite(Sprite * sprite) -{ - if (sprite == nullptr) return false; - - // ѰǷͬڵ - std::vector::iterator iter; - for (iter = m_vSprites.begin(); iter != m_vSprites.end(); iter++) - { - // ҵͬڵ - if ((*iter) == sprite) - { - // üһ - (*iter)->release(); - // ȥýڵ - m_vSprites.erase(iter); - return true; - } - } - return false; -} - -int BatchSprite::getCount() -{ - return (int)m_vSprites.size(); -} - -std::vector& BatchSprite::getChildren() -{ - return m_vSprites; -} - -void BatchSprite::clearAllSprites() -{ - // нڵüһ - for (auto s : m_vSprites) - { - s->release(); - } - // մڵ - m_vSprites.clear(); -} - -bool BatchSprite::_exec(bool active) -{ - // ڵǷʾ - if (!m_bDisplay) - { - return false; - } - // ӽڵ - for (int i = int(m_vSprites.size() - 1); i >= 0; i--) - { - if (m_vSprites[i]->_exec(active)) - { - active = false; - } - } - // ӽڵȡ˻潹㣬ýڵҲȡ˽ - return !active; -} - -void BatchSprite::_onDraw() -{ - // ڵǷʾ - if (!m_bDisplay) - { - return; - } - - // λûӽڵ - for (auto sprite : m_vSprites) - { - // ӽڵƶλ - sprite->move(getX(), getY()); - // ӽڵ - sprite->_onDraw(); - // ӽڵƻԭλ - sprite->move(-getX(), -getY()); - } -} - -Sprite * BatchSprite::isCollisionWith(Sprite * sprite) -{ - for (int i = int(m_vSprites.size() - 1); i >= 0; i--) - { - if (m_vSprites[i]->isCollisionWith(sprite)) - { - return m_vSprites[i]; - } - } - return nullptr; -} - -Sprite * BatchSprite::isPointIn(CPoint point) -{ - for (int i = int(m_vSprites.size() - 1); i >= 0; i--) - { - if (m_vSprites[i]->isPointIn(point)) - { - return m_vSprites[i]; - } - } - return nullptr; -} - -void BatchSprite::addAction(Action * action) -{ - Sprite::addAction(action); -} - -float BatchSprite::getScaleX() const -{ - return m_fScaleX; -} - -float BatchSprite::getScaleY() const -{ - return m_fScaleY; -} - -float BatchSprite::getOpacity() const -{ - return m_nAlpha / 255.0f; -} - -void BatchSprite::setScale(float scaleX, float scaleY) -{ - m_fScaleX = scaleX; - m_fScaleY = scaleY; - for (auto s : m_vSprites) - { - s->setScale(scaleX, scaleY); - } -} - -void BatchSprite::setOpacity(float opacity) -{ - m_nAlpha = BYTE(min(max(opacity, 0), 1) * 255); - for (auto s : m_vSprites) - { - s->setOpacity(opacity); - } -} - -void BatchSprite::setImage(Image * image) -{ - for (auto s : m_vSprites) - { - s->setImage(image); - } -} - -void BatchSprite::setX(int x) -{ - // ƶλ - int var = x - getX(); - // ƶӽڵλ - for (auto s : m_vSprites) - { - s->move(var, 0); - } - RectNode::setX(x); -} - -void BatchSprite::setY(int y) -{ - // ƶλ - int var = y - getY(); - // ƶӽڵλ - for (auto s : m_vSprites) - { - s->move(0, var); - } - RectNode::setY(y); -} - -void BatchSprite::setPos(int x, int y) -{ - // ƶλ - CPoint var(x - getX(), y - getY()); - // ƶӽڵλ - for (auto s : m_vSprites) - { - s->move(var); - } - RectNode::setPos(x, y); -} - -void BatchSprite::setPos(CPoint p) -{ - // ƶλ - CPoint var(p - getPos()); - // ƶӽڵλ - for (auto s : m_vSprites) - { - s->move(var); - } - RectNode::setPos(p); -} - -void BatchSprite::move(int x, int y) -{ - // ƶӽڵλ - for (auto s : m_vSprites) - { - s->move(x, y); - } - RectNode::move(x, y); -} - -void BatchSprite::move(CVector v) -{ - // ƶӽڵλ - for (auto s : m_vSprites) - { - s->move(v); - } - RectNode::move(v); -} \ No newline at end of file diff --git a/Easy2D/Node/Button/Button.cpp b/Easy2D/Node/Button/Button.cpp deleted file mode 100644 index 8044d691..00000000 --- a/Easy2D/Node/Button/Button.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "..\..\easy2d.h" -#include "..\..\EasyX\easyx.h" - - -Button::Button() : - m_bEnable(true) -{ -} - -Button::~Button() -{ -} - -bool Button::_exec(bool active) -{ - // ťǷ - if (!m_bEnable) - { - return false; - } - return MouseNode::_exec(active); -} - -void Button::_onDraw() -{ - // ťǷ - if (!m_bEnable) - { - // δʱ Disable ״̬ - _onDisable(); - return; - } - MouseNode::_onDraw(); -} - -bool Button::isEnable() -{ - return m_bEnable; -} - -void Button::setEnable(bool enable) -{ - m_bEnable = enable; -} - -void Button::setX(int x) -{ - MouseNode::setX(x); - _resetPosition(); -} - -void Button::setY(int y) -{ - MouseNode::setY(y); - _resetPosition(); -} - -void Button::setPos(int x, int y) -{ - MouseNode::setPos(x, y); - _resetPosition(); -} - -void Button::setPos(CPoint p) -{ - MouseNode::setPos(p); - _resetPosition(); -} - -void Button::move(int x, int y) -{ - MouseNode::move(x, y); - _resetPosition(); -} - -void Button::move(CVector v) -{ - MouseNode::move(v); - _resetPosition(); -} diff --git a/Easy2D/Node/Button/ImageButton.cpp b/Easy2D/Node/Button/ImageButton.cpp deleted file mode 100644 index 824b8113..00000000 --- a/Easy2D/Node/Button/ImageButton.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include "..\..\easy2d.h" - - -ImageButton::ImageButton() : - m_pNormalImage(nullptr), - m_pMouseInImage(nullptr), - m_pSelectedImage(nullptr), - m_pUnableImage(nullptr) -{ -} - -ImageButton::ImageButton(LPCTSTR image) : - ImageButton() -{ - setNormal(new Image(image)); // ðť״̬ʱͼƬ -} - -ImageButton::ImageButton(Image * image) : - ImageButton() -{ - setNormal(image); // ðť״̬ʱͼƬ -} - -ImageButton::~ImageButton() -{ - // ͼƬüһ - SafeRelease(m_pNormalImage); - SafeRelease(m_pMouseInImage); - SafeRelease(m_pSelectedImage); - SafeRelease(m_pUnableImage); -} - -void ImageButton::_setStatus(Status status) -{ - if (m_eStatus != status) - { - if (status == MOUSEIN) - { - if (m_pMouseInImage) setRect(m_pMouseInImage->getRect()); - } - else if (status == SELECTED) - { - if (m_pSelectedImage) setRect(m_pSelectedImage->getRect()); - } - else - { - setRect(m_pNormalImage->getRect()); - } - } - MouseNode::_setStatus(status); -} - -void ImageButton::_onNormal() -{ - if (m_pNormalImage) - { - m_pNormalImage->_onDraw(); - } -} - -void ImageButton::_onMouseIn() -{ - if (m_pMouseInImage) - { - m_pMouseInImage->_onDraw(); - } - else - { - _onNormal(); - } -} - -void ImageButton::_onSelected() -{ - if (m_pSelectedImage) - { - m_pSelectedImage->_onDraw(); - } - else - { - _onNormal(); - } -} - -void ImageButton::_onDisable() -{ - if (m_pUnableImage) - { - m_pUnableImage->_onDraw(); - } - else - { - _onNormal(); - } -} - -void ImageButton::setNormal(Image * image) -{ - if (image) - { - // ԭͼƬüһ - SafeRelease(m_pNormalImage); - // ޸ͼƬ - m_pNormalImage = image; - // ͼƬüһ - m_pNormalImage->retain(); - // ͼƬ趨ťС - setSize(m_pNormalImage->getSize()); - // ¼ͼƬλ - _resetPosition(); - } -} - -void ImageButton::setMouseIn(Image * image) -{ - if (image) - { - SafeRelease(m_pMouseInImage); - m_pMouseInImage = image; - m_pMouseInImage->retain(); - _resetPosition(); - } -} - -void ImageButton::setSelected(Image * image) -{ - if (image) - { - SafeRelease(m_pSelectedImage); - m_pSelectedImage = image; - m_pSelectedImage->retain(); - _resetPosition(); - } -} - -void ImageButton::setUnable(Image * image) -{ - if (image) - { - SafeRelease(m_pUnableImage); - m_pUnableImage = image; - m_pUnableImage->retain(); - _resetPosition(); - } -} - -void ImageButton::_resetPosition() -{ - if (m_pNormalImage) - { - // ݰťλúͼƬͼƬλþʾ - m_pNormalImage->setPos(getX(), getY()); - } - if (m_pMouseInImage) - { - m_pMouseInImage->setPos( - getX() + (getWidth() - m_pMouseInImage->getWidth()) / 2, - getY() + (getHeight() - m_pMouseInImage->getHeight()) / 2); - } - if (m_pSelectedImage) - { - m_pSelectedImage->setPos( - getX() + (getWidth() - m_pSelectedImage->getWidth()) / 2, - getY() + (getHeight() - m_pSelectedImage->getHeight()) / 2); - } - if (m_pUnableImage) - { - m_pUnableImage->setPos( - getX() + (getWidth() - m_pUnableImage->getWidth()) / 2, - getY() + (getHeight() - m_pUnableImage->getHeight()) / 2); - } -} diff --git a/Easy2D/Node/Button/TextButton.cpp b/Easy2D/Node/Button/TextButton.cpp deleted file mode 100644 index fcebafad..00000000 --- a/Easy2D/Node/Button/TextButton.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include "..\..\easy2d.h" - - -TextButton::TextButton() : - m_pNormalText(nullptr), - m_pMouseInText(nullptr), - m_pSelectedText(nullptr), - m_pUnableText(nullptr) -{ -} - -TextButton::TextButton(TString text) : - TextButton() -{ - setNormal(new Text(text)); // ðť״̬ʱ -} - -TextButton::TextButton(Text * text) : - TextButton() -{ - setNormal(text); // ðť״̬ʱ -} - -TextButton::~TextButton() -{ - // ıüһ - SafeRelease(m_pNormalText); - SafeRelease(m_pMouseInText); - SafeRelease(m_pSelectedText); - SafeRelease(m_pUnableText); -} - -void TextButton::_setStatus(Status status) -{ - if (m_eStatus != status) - { - if (status == MOUSEIN) - { - if (m_pMouseInText) setRect(m_pMouseInText->getRect()); - } - else if (status == SELECTED) - { - if (m_pSelectedText) setRect(m_pSelectedText->getRect()); - } - else - { - setRect(m_pNormalText->getRect()); - } - } - MouseNode::_setStatus(status); -} - -void TextButton::_onNormal() -{ - if (m_pNormalText) - { - m_pNormalText->_onDraw(); - } -} - -void TextButton::_onMouseIn() -{ - if (m_pMouseInText) - { - m_pMouseInText->_onDraw(); - } - else - { - _onNormal(); - } -} - -void TextButton::_onSelected() -{ - if (m_pSelectedText) - { - m_pSelectedText->_onDraw(); - } - else - { - _onNormal(); - } -} - -void TextButton::_onDisable() -{ - if (m_pUnableText) - { - m_pUnableText->_onDraw(); - } - else - { - _onNormal(); - } -} - -void TextButton::setNormal(Text * text) -{ - if (text) - { - // ԭıüһ - SafeRelease(m_pNormalText); - // ޸ı - m_pNormalText = text; - // ıüһ - m_pNormalText->retain(); - // ֿ趨ťС - setSize(m_pNormalText->getSize()); - // ¼ıλ - _resetPosition(); - } -} - -void TextButton::setMouseIn(Text * text) -{ - if (text) - { - SafeRelease(m_pMouseInText); - m_pMouseInText = text; - m_pMouseInText->retain(); - _resetPosition(); - } -} - -void TextButton::setSelected(Text * text) -{ - if (text) - { - SafeRelease(m_pSelectedText); - m_pSelectedText = text; - m_pSelectedText->retain(); - _resetPosition(); - } -} - -void TextButton::setUnable(Text * text) -{ - if (text) - { - SafeRelease(m_pUnableText); - m_pUnableText = text; - m_pUnableText->retain(); - _resetPosition(); - } -} - -void TextButton::_resetPosition() -{ - if (m_pNormalText) - { - // ݰťλúֿλþʾ - m_pNormalText->setPos(getX() , getY()); - } - if (m_pMouseInText) - { - m_pMouseInText->setPos( - getX() + (getWidth() - m_pMouseInText->getWidth()) / 2, - getY() + (getHeight() - m_pMouseInText->getHeight()) / 2); - } - if (m_pSelectedText) - { - m_pSelectedText->setPos( - getX() + (getWidth() - m_pSelectedText->getWidth()) / 2, - getY() + (getHeight() - m_pSelectedText->getHeight()) / 2); - } - if (m_pUnableText) - { - m_pUnableText->setPos( - getX() + (getWidth() - m_pUnableText->getWidth()) / 2, - getY() + (getHeight() - m_pUnableText->getHeight()) / 2); - } -} diff --git a/Easy2D/Node/ENode.cpp b/Easy2D/Node/ENode.cpp index 8f6eea95..10b7b256 100644 --- a/Easy2D/Node/ENode.cpp +++ b/Easy2D/Node/ENode.cpp @@ -1,4 +1,5 @@ #include "..\enodes.h" +#include "..\Win\winbase.h" e2d::ENode::ENode() : m_nZOrder(0) @@ -27,8 +28,20 @@ bool e2d::ENode::_exec(bool active) return false; } -void e2d::ENode::_onDraw() +void e2d::ENode::_onRender() { + D2D1_RECT_F rectangle = D2D1::RectF( + m_Rect.left, + m_Rect.top, + m_Rect.right, + m_Rect.bottom + ); + ID2D1SolidColorBrush* m_pLightSlateGrayBrush; + GetRenderTarget()->CreateSolidColorBrush( + D2D1::ColorF(D2D1::ColorF::LightSlateGray), + &m_pLightSlateGrayBrush + ); + GetRenderTarget()->FillRectangle(&rectangle, m_pLightSlateGrayBrush); } int e2d::ENode::getX() const diff --git a/Easy2D/Node/Image.cpp b/Easy2D/Node/Image.cpp deleted file mode 100644 index 83b8a0b7..00000000 --- a/Easy2D/Node/Image.cpp +++ /dev/null @@ -1,251 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" -#include -using namespace std; - -// ͼƬ -static map s_mCImages; -// ͼƬжȡͼƬ -static CImage* GetCImage(TString name, bool fromRes = false); -// PNG ͼת -static void CrossImage(CImage &img); - - -Image::Image() : - m_pCImage(nullptr), - m_nAlpha(255), - m_fScaleX(1), - m_fScaleY(1) -{ -} - -Image::Image(LPCTSTR ImageFile) : - Image() -{ - setImage(ImageFile); // ͼƬԴ -} - -Image::Image(LPCTSTR ImageFile, int x, int y, int width, int height) : - Image() -{ - setImage(ImageFile, x, y, width, height); // ͼƬԴͲüС -} - -Image::~Image() -{ -} - -void Image::_onDraw() -{ - // display Ϊ falseδͼƬԴʱƸͼƬ - if (!m_bDisplay || !m_pCImage) - { - return; - } - // ͼƬ - if (m_pCImage->GetBPP() == 32) - { - m_pCImage->AlphaBlend(GetImageHDC(), m_Rect, m_SrcRect, m_nAlpha, AC_SRC_OVER); - } - else - { - m_pCImage->Draw(GetImageHDC(), m_Rect, m_SrcRect); - } -} - -float Image::getScaleX() const -{ - return m_fScaleX; -} - -float Image::getScaleY() const -{ - return m_fScaleY; -} - -float Image::getOpacity() const -{ - return m_nAlpha / 255.0f; -} - -bool Image::setImage(LPCTSTR ImageFile) -{ - m_pCImage = GetCImage(ImageFile); - if (m_pCImage) - { - reset(); - return true; - } - return false; -} - -bool Image::setImage(LPCTSTR ImageFile, int x, int y, int width, int height) -{ - if (!setImage(ImageFile)) - { - return false; - } - // üͼƬС - crop(x, y, width, height); - - return true; -} - -bool Image::setImageFromRes(LPCTSTR pResName) -{ - m_pCImage = GetCImage(pResName, true); - if (m_pCImage) - { - reset(); - return true; - } - return false; -} - -bool Image::setImageFromRes(LPCTSTR pResName, int x, int y, int width, int height) -{ - if (!setImageFromRes(pResName)) - { - return false; - } - // üͼƬС - crop(x, y, width, height); - - return true; -} - -void Image::crop(int x, int y, int width, int height) -{ - width = min(max(width, 0), m_pCImage->GetWidth() - x); - height = min(max(height, 0), m_pCImage->GetHeight() - y); - // ԴελúʹСڲü - m_SrcRect.SetRect(x, y, x + width, y + height); - // ĿΣƵڵλúʹС - setSize(int(width * m_fScaleX), int(height * m_fScaleY)); -} - -void Image::stretch(int width, int height) -{ - // ĿελúʹСƵڵλúʹСͼƬ - setSize(max(width, 0), max(height, 0)); - // ñ - m_fScaleX = 1; - m_fScaleY = 1; -} - -void Image::setScale(float scaleX, float scaleY) -{ - m_fScaleX = max(scaleX, 0); - m_fScaleY = max(scaleY, 0); - setSize(int(m_SrcRect.Width() * scaleX), int(m_SrcRect.Height() * scaleY)); -} - -void Image::setOpacity(float value) -{ - if (m_pCImage->GetBPP() == 32) - { - m_nAlpha = BYTE(min(max(value, 0), 1) * 255); - } -} - -void Image::setTransparentColor(COLORREF value) -{ - // ͸ɫ - m_pCImage->SetTransparentColor(value); -} - -void Image::reset() -{ - // ĿΣƵڵλúʹС - setSize(m_pCImage->GetWidth(), m_pCImage->GetHeight()); - // ԴΣȡͼƬĴС - m_SrcRect.SetRect(0, 0, m_pCImage->GetWidth(), m_pCImage->GetHeight()); - // - m_fScaleX = 1; - m_fScaleY = 1; - // ͸ - m_nAlpha = 255; -} - -bool Image::preload(LPCTSTR fileName, bool fromRes) -{ - // жͼƬǷѾ - if (s_mCImages.find(fileName) != s_mCImages.end()) - { - return true; - } - // ͼƬ - CImage* cImage = nullptr; - if (fromRes) - { - cImage = new CImage(); - // ԴͼƬ֧ PNG - cImage->LoadFromResource(GetModuleHandle(NULL), fileName); - } - else - { - //жͼƬ·Ƿ - if (!PathFileExists(fileName)) - { - return false; - } - cImage = new CImage(); - cImage->Load(fileName); - } - // ʧ - if (!cImage || cImage->IsNull()) - { - return false; - } - // ȷϸͼ Alpha ͨ - if (cImage->GetBPP() == 32) - { - // ͸ͼƬ - CrossImage(*cImage); - } - s_mCImages.insert(map::value_type(fileName, cImage)); - - return true; -} - -void Image::saveScreenshot() -{ - TString savePath; - // ȡλ - if (FileUtils::getSaveFilePath(savePath, _T("ͼ浽"), _T("jpg"))) - { - // 洰ڽͼ - IMAGE image; - getimage(&image, 0, 0, EApp::getWidth(), EApp::getHeight()); - saveimage(savePath.c_str(), &image); - } -} - - -// PNG ͼת -void CrossImage(CImage &img) -{ - // ת - for (int i = 0; i < img.GetWidth(); i++) - { - for (int j = 0; j < img.GetHeight(); j++) - { - UCHAR *cr = (UCHAR*)img.GetPixelAddress(i, j); - cr[0] = cr[0] * cr[3] / 255; - cr[1] = cr[1] * cr[3] / 255; - cr[2] = cr[2] * cr[3] / 255; - } - } -} - -CImage* GetCImage(TString name, bool fromRes) -{ - if (Image::preload(name.c_str())) - { - return s_mCImages.at(name); - } - else - { - return nullptr; - } -} \ No newline at end of file diff --git a/Easy2D/Node/Layer.cpp b/Easy2D/Node/Layer.cpp deleted file mode 100644 index 85c5e2e1..00000000 --- a/Easy2D/Node/Layer.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "..\easy2d.h" - - -Layer::Layer() : - m_bBlock(true) -{ -} - -Layer::~Layer() -{ -} - -int Layer::getBlock() const -{ - return m_bBlock; -} - -void Layer::setBlock(bool block) -{ - m_bBlock = block; -} - -bool Layer::_exec(bool active) -{ - // ͼϢԶȡû潹 - return BatchNode::_exec(active) || m_bBlock; -} diff --git a/Easy2D/Node/MouseNode.cpp b/Easy2D/Node/MouseNode.cpp deleted file mode 100644 index 3ef74b2d..00000000 --- a/Easy2D/Node/MouseNode.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "..\easy2d.h" - - -MouseNode::MouseNode() : - m_bBlock(true), - m_bTarget(false), - m_ClickCallback([]() {}), - m_OnMouseInCallback([]() {}), - m_OnMouseOutCallback([]() {}), - m_OnSelectCallback([]() {}), - m_OnUnselectCallback([]() {}) -{ -} - -MouseNode::~MouseNode() -{ -} - -bool MouseNode::_exec(bool active) -{ - // display Ϊ false˳ - if (!m_bDisplay) - { - return false; - } - // ȡý㣬ðťԲ˳ - if (!active) - { - reset(); - return false; - } - // жϽڵ㵱ǰ״̬ - // ڵδȡý㣬жϽڵ״̬ - if (!m_bTarget) - { - // λڽڵڵľ - if (_isMouseIn()) - { - // ״̬Ϊ MOUSEIN - _setStatus(MOUSEIN); - // ʱ - if (MouseMsg::getMsg() == MouseMsg::LBUTTON_DOWN) - { - m_bTarget = true; // ȡý - _setStatus(SELECTED); // ״̬Ϊ SELECTED - } - // ڵϢȡû潹 - if (m_bBlock) return true; - } - else - { - reset(); // ָĬ״̬ - } - } - else - { - // ڵȡýʱ̧ - if (MouseMsg::getMsg() == MouseMsg::LBUTTON_UP) - { - // ̧ʱڽڵ - if (_isMouseIn()) - { - m_ClickCallback(); // ִлص - } - reset(); // ָĬ״̬ - } - // ڵϢȡû潹 - if (m_bBlock) return true; - } - return false; -} - -void MouseNode::_onDraw() -{ - // ڵǷʾ - if (!m_bDisplay) - { - return; - } - // ڵǷѡ - if (m_eStatus == SELECTED) - { - _onSelected(); - } - else - { - // Ƿڽڵ - if (m_eStatus == MOUSEIN) - { - _onMouseIn(); - } - else - { - _onNormal(); - } - } -} - -bool MouseNode::_isMouseIn() -{ - return isPointIn(MouseMsg::getPos()); -} - -void MouseNode::_setStatus(Status status) -{ - if (m_eStatus != status) - { - // ˳ij״̬Ļص - if (m_eStatus == MOUSEIN) - { - m_OnMouseOutCallback(); - } - else if (m_eStatus == SELECTED) - { - m_OnUnselectCallback(); - } - // ij״̬Ļص - if (status == MOUSEIN) - { - m_OnMouseInCallback(); - } - else if (status == SELECTED) - { - m_OnSelectCallback(); - } - m_eStatus = status; - } -} - -bool MouseNode::isMouseIn() -{ - return m_eStatus == MOUSEIN || m_eStatus == SELECTED; -} - -bool MouseNode::isSelected() -{ - return m_eStatus == SELECTED; -} - -void MouseNode::setClickedCallback(const CLICK_CALLBACK & callback) -{ - m_ClickCallback = callback; -} - -void MouseNode::setMouseInCallback(const CLICK_CALLBACK & callback) -{ - m_OnMouseInCallback = callback; -} - -void MouseNode::setMouseOutCallback(const CLICK_CALLBACK & callback) -{ - m_OnMouseOutCallback = callback; -} - -void MouseNode::setSelectCallback(const CLICK_CALLBACK & callback) -{ - m_OnSelectCallback = callback; -} - -void MouseNode::setUnselectCallback(const CLICK_CALLBACK & callback) -{ - m_OnUnselectCallback = callback; -} - -void MouseNode::reset() -{ - m_bTarget = false; // ʧȥ - _setStatus(NORMAL); // ָĬ״̬ -} - -void MouseNode::setBlock(bool block) -{ - m_bBlock = block; -} diff --git a/Easy2D/Node/RectNode.cpp b/Easy2D/Node/RectNode.cpp deleted file mode 100644 index ba5854da..00000000 --- a/Easy2D/Node/RectNode.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "..\easy2d.h" - -RectNode::RectNode() : - m_Rect(0, 0, 0, 0) -{ - -} - -RectNode::~RectNode() -{ -} - -bool RectNode::isCollisionWith(RectNode * rectNode) const -{ - static CRect rt; - return IntersectRect(&rt, &m_Rect, &rectNode->m_Rect); -} - -bool RectNode::isPointIn(CPoint p) const -{ - return m_Rect.PtInRect(p); -} - -void RectNode::setWindowCenterX() -{ - setX((EApp::getWidth() - getWidth()) / 2); -} - -void RectNode::setWindowCenterY() -{ - setY((EApp::getHeight() - getHeight()) / 2); -} - -void RectNode::setWindowCenter() -{ - setWindowCenterX(); - setWindowCenterY(); -} - -int RectNode::getX() const -{ - return m_Rect.left; -} - -int RectNode::getY() const -{ - return m_Rect.top; -} - -CPoint RectNode::getPos() const -{ - return m_Rect.TopLeft(); -} - -int RectNode::getWidth() const -{ - return m_Rect.Width(); // ο -} - -int RectNode::getHeight() const -{ - return m_Rect.Height(); // θ߶ -} - -CSize RectNode::getSize() const -{ - return m_Rect.Size(); -} - -CRect RectNode::getRect() const -{ - return m_Rect; -} - -void RectNode::setX(int x) -{ - m_Rect.MoveToX(x); -} - -void RectNode::setY(int y) -{ - m_Rect.MoveToY(y); -} - -void RectNode::setPos(int x, int y) -{ - m_Rect.MoveToXY(x, y); // ޸ľλ -} - -void RectNode::setPos(CPoint p) -{ - m_Rect.MoveToXY(p); // ޸ľλ -} - -void RectNode::move(int x, int y) -{ - m_Rect.OffsetRect(x, y); // ƶ -} - -void RectNode::move(CVector v) -{ - m_Rect.OffsetRect(v); // ƶ -} - -void RectNode::setWidth(int width) -{ - m_Rect.right = max(m_Rect.left + width, 0); -} - -void RectNode::setHeight(int height) -{ - m_Rect.bottom = max(m_Rect.top + height, 0); -} - -void RectNode::setSize(int width, int height) -{ - setWidth(width); - setHeight(height); -} - -void RectNode::setSize(CSize size) -{ - setSize(size.cx, size.cy); -} - -void RectNode::setRect(int x1, int y1, int x2, int y2) -{ - m_Rect.SetRect(x1, y1, x2, y2); -} - -void RectNode::setRect(CPoint leftTop, CPoint rightBottom) -{ - m_Rect.SetRect(leftTop, rightBottom); -} - -void RectNode::setRect(CRect rect) -{ - m_Rect.CopyRect(&rect); -} diff --git a/Easy2D/Node/Shape/Circle.cpp b/Easy2D/Node/Shape/Circle.cpp deleted file mode 100644 index a8e1c3e6..00000000 --- a/Easy2D/Node/Shape/Circle.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "..\..\easy2d.h" -#include "..\..\EasyX\easyx.h" - - -Circle::Circle() : - m_nRadius(0) -{ -} - -Circle::Circle(int x, int y, int radius) : - m_nRadius(radius) -{ - setPos(x, y); -} - -Circle::~Circle() -{ -} - -void Circle::solidShape() -{ - solidcircle(getX(), getY(), m_nRadius); -} - -void Circle::fillShape() -{ - fillcircle(getX(), getY(), m_nRadius); -} - -void Circle::roundShape() -{ - circle(getX(), getY(), m_nRadius); -} - -int Circle::getRadius() const -{ - return m_nRadius; -} - -void Circle::setRadius(int r) -{ - m_nRadius = r; -} \ No newline at end of file diff --git a/Easy2D/Node/Shape/Rectangle.cpp b/Easy2D/Node/Shape/Rectangle.cpp deleted file mode 100644 index 854163d2..00000000 --- a/Easy2D/Node/Shape/Rectangle.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "..\..\easy2d.h" -#include "..\..\EasyX\easyx.h" - - -Rect::Rect() -{ -} - -Rect::Rect(int x, int y, int width, int height) : - m_Size(width, height) -{ - setPos(x, y); -} - -Rect::~Rect() -{ -} - -void Rect::solidShape() -{ - solidrectangle(getX(), getY(), getX() + m_Size.cx, getY() + m_Size.cy); -} - -void Rect::fillShape() -{ - fillrectangle(getX(), getY(), getX() + m_Size.cx, getY() + m_Size.cy); -} - -void Rect::roundShape() -{ - rectangle(getX(), getY(), getX() + m_Size.cx, getY() + m_Size.cy); -} - -int Rect::getWidth() const -{ - return m_Size.cx; -} - -int Rect::getHeight() const -{ - return m_Size.cy; -} - -void Rect::setWidth(int width) -{ - m_Size.cx = width; -} - -void Rect::setHeight(int height) -{ - m_Size.cy = height; -} - -void Rect::setSize(int width, int height) -{ - m_Size.cx = width; - m_Size.cy = height; -} \ No newline at end of file diff --git a/Easy2D/Node/Shape/Shape.cpp b/Easy2D/Node/Shape/Shape.cpp deleted file mode 100644 index f0747499..00000000 --- a/Easy2D/Node/Shape/Shape.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "..\..\easy2d.h" -#include "..\..\EasyX\easyx.h" - -Shape::Shape() : - lineColor(Color::black), - fillColor(Color::white), - m_eStyle(SOLID) -{ -} - -Shape::~Shape() -{ -} - -void Shape::_onDraw() -{ - // ״Ƿʾ - if (!m_bDisplay) - { - return; - } - // ɫ - setlinecolor(lineColor); - setfillcolor(fillColor); - - // ״ʽвͬĻ - if (m_eStyle == Shape::STYLE::ROUND) - { - roundShape(); - } - else if (m_eStyle == Shape::STYLE::SOLID) - { - solidShape(); - } - else if (m_eStyle == Shape::STYLE::FILL) - { - fillShape(); - } -} - -inline COLORREF Shape::getFillColor() const -{ - return fillColor; -} - -inline COLORREF Shape::getLineColor() const -{ - return lineColor; -} - -void Shape::setFillColor(COLORREF color) -{ - fillColor = color; -} - -void Shape::setLineColor(COLORREF color) -{ - lineColor = color; -} - -void Shape::setStyle(STYLE style) -{ - m_eStyle = style; -} diff --git a/Easy2D/Node/Sprite.cpp b/Easy2D/Node/Sprite.cpp deleted file mode 100644 index 870dd868..00000000 --- a/Easy2D/Node/Sprite.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" - -Sprite::Sprite() : - m_nAlpha(255), - m_fScaleX(1), - m_fScaleY(1), - m_pImage(nullptr) -{ - -} - -Sprite::Sprite(Image * image) : - Sprite() -{ - setImage(image); -} - -Sprite::Sprite(LPCTSTR imageFileName) : - Sprite() -{ - setImage(new Image(imageFileName)); -} - -Sprite::~Sprite() -{ - SafeRelease(m_pImage); -} - -bool Sprite::_exec(bool active) -{ - return false; -} - -void Sprite::_onDraw() -{ - // display Ϊ falseδͼƬԴʱƸͼƬ - if (!m_bDisplay || !m_pImage || !m_pImage->m_pCImage) - { - return; - } - // ͼƬ - if (m_pImage->m_pCImage->GetBPP() == 32) - { - m_pImage->m_pCImage->AlphaBlend(GetImageHDC(), getRect(), m_pImage->m_SrcRect, m_nAlpha, AC_SRC_OVER); - } - else - { - m_pImage->m_pCImage->Draw(GetImageHDC(), getRect(), m_pImage->m_SrcRect); - } -} - -void Sprite::setImage(Image * image) -{ - SafeRelease(m_pImage); - m_pImage = image; - setSize(int(m_pImage->getWidth() * m_fScaleX), int(m_pImage->getHeight() * m_fScaleY)); - m_pImage->retain(); -} - -bool Sprite::isCollisionWith(Sprite * sprite) -{ - static CRect rt; - return IntersectRect(&rt, &getRect(), &sprite->getRect()); -} - -void Sprite::addAction(Action * action) -{ - if (action) - { - // Sprite - action->m_pTargetSprite = this; - // 붯ᴦ - ActionManager::addAction(action); - } -} - -void Sprite::runAction(Action * action) -{ - addAction(action); -} - -void Sprite::resumeAction(Action * action) -{ - if (action->getTarget() == this) - { - ActionManager::resumeAction(action); - } -} - -void Sprite::pauseAction(Action * action) -{ - if (action->getTarget() == this) - { - ActionManager::pauseAction(action); - } -} - -void Sprite::stopAction(Action * action) -{ - if (action->getTarget() == this) - { - ActionManager::stopAction(action); - } -} - -void Sprite::pauseAllActions() -{ - ActionManager::pauseSpriteAllActions(this); -} - -void Sprite::resumeAllActions() -{ - ActionManager::resumeSpriteAllActions(this); -} - -void Sprite::stopAllActions() -{ - ActionManager::stopSpriteAllActions(this); -} - -float Sprite::getScaleX() const -{ - return m_fScaleX; -} - -float Sprite::getScaleY() const -{ - return m_fScaleY; -} - -float Sprite::getOpacity() const -{ - return m_nAlpha / 255.0f; -} - -void Sprite::setScale(float scaleX, float scaleY) -{ - m_fScaleX = max(scaleX, 0); - m_fScaleY = max(scaleY, 0); - setSize(int(m_pImage->getWidth() * scaleX), int(m_pImage->getHeight() * scaleY)); -} - -void Sprite::setOpacity(float opacity) -{ - m_nAlpha = BYTE(min(max(opacity, 0), 1) * 255); -} diff --git a/Easy2D/Node/Text.cpp b/Easy2D/Node/Text.cpp deleted file mode 100644 index 607eb328..00000000 --- a/Easy2D/Node/Text.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" - - -Text::Text() : - m_sText(_T("")), - m_color(Color::white), - m_pFontStyle(FontStyle::getDefault()) -{ - m_pFontStyle->retain(); // üһ -} - -Text::Text(TString text, COLORREF color, FontStyle * font) : - m_color(color), - m_pFontStyle(font) -{ - setText(text); - m_pFontStyle->retain(); // üһ -} - -Text::Text(int x, int y, TString text, COLORREF color, FontStyle * font) : - m_color(color), - m_pFontStyle(font) -{ - setText(text); - setPos(x, y); - m_pFontStyle->retain(); // üһ -} - -Text::~Text() -{ - SafeRelease(m_pFontStyle); // üһ -} - -void Text::_onDraw() -{ - // display Ϊ falseı - if (!m_bDisplay) - { - return; - } - // - settextstyle(&m_pFontStyle->m_font); - // ıɫ - settextcolor(m_color); - // - outtextxy(getX(), getY(), m_sText.c_str()); -} - -COLORREF Text::getColor() const -{ - return m_color; -} - -TString Text::getText() const -{ - return m_sText; -} - -FontStyle * Text::getFontStyle() -{ - return m_pFontStyle; -} - -bool Text::isEmpty() const -{ - return m_sText.empty(); // ıǷΪ -} - -void Text::setText(TString text) -{ - m_sText = text; - // 壬ȻȡıڸµĿȺ͸߶ - settextstyle(&m_pFontStyle->m_font); - setSize(textwidth(getText().c_str()), textheight(getText().c_str())); -} - -void Text::setColor(COLORREF color) -{ - m_color = color; -} - -void Text::setFontStyle(FontStyle * style) -{ - SafeRelease(m_pFontStyle); // ԭüһ - m_pFontStyle = style; // ޸ - m_pFontStyle->retain(); // üһ - // 壬ȻȡıڸµĿȺ͸߶ - settextstyle(&m_pFontStyle->m_font); - setSize(textwidth(getText().c_str()), textheight(getText().c_str())); -} diff --git a/Easy2D/Style/Color.cpp b/Easy2D/Style/Color.cpp deleted file mode 100644 index c14aa401..00000000 --- a/Easy2D/Style/Color.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" - -// ɫֵĶ -const COLORREF Color::black = BLACK; -const COLORREF Color::blue = BLUE; -const COLORREF Color::green = GREEN; -const COLORREF Color::cyan = CYAN; -const COLORREF Color::red = RED; -const COLORREF Color::magenta = MAGENTA; -const COLORREF Color::brown = BROWN; -const COLORREF Color::lightgray = LIGHTGRAY; -const COLORREF Color::darkgray = DARKGRAY; -const COLORREF Color::lightblue = LIGHTBLUE; -const COLORREF Color::lightgreen = LIGHTGREEN; -const COLORREF Color::lightcyan = LIGHTCYAN; -const COLORREF Color::lightred = LIGHTRED; -const COLORREF Color::lightmagenta = LIGHTMAGENTA; -const COLORREF Color::yellow = YELLOW; -const COLORREF Color::white = WHITE; - - -COLORREF Color::getFromRGB(BYTE r, BYTE g, BYTE b) -{ - return RGB(r, g, b); // (r, g, b) ɫֵתΪɫ -} - -COLORREF Color::getFromHSL(float H, float S, float L) -{ - return HSLtoRGB(H, S, L); -} - -COLORREF Color::getFromHSV(float H, float S, float V) -{ - return HSVtoRGB(H, S, V); -} - -BYTE Color::getRValue(COLORREF color) -{ - return GetRValue(color); // ɫеĺɫֵ -} - -BYTE Color::getGValue(COLORREF color) -{ - return GetGValue(color); // ɫеɫֵ -} - -BYTE Color::getBValue(COLORREF color) -{ - return GetBValue(color); // ɫеɫֵ -} - -COLORREF Color::getGray(COLORREF color) -{ - return RGBtoGRAY(color); // ȡɫеĻҶֵ -} diff --git a/Easy2D/Style/FillStyle.cpp b/Easy2D/Style/FillStyle.cpp deleted file mode 100644 index 498580d5..00000000 --- a/Easy2D/Style/FillStyle.cpp +++ /dev/null @@ -1 +0,0 @@ -/* FillStyle EasyX е࣬Ŀǰδʵ */ \ No newline at end of file diff --git a/Easy2D/Style/FontStyle.cpp b/Easy2D/Style/FontStyle.cpp deleted file mode 100644 index 2c5c69ba..00000000 --- a/Easy2D/Style/FontStyle.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "..\easy2d.h" - -// ϸֵĶ -const LONG FontWeight::dontcare = 0; -const LONG FontWeight::thin = 100; -const LONG FontWeight::extraLight = 200; -const LONG FontWeight::light = 300; -const LONG FontWeight::normal = 400; -const LONG FontWeight::regular = 400; -const LONG FontWeight::medium = 500; -const LONG FontWeight::demiBlod = 600; -const LONG FontWeight::blod = 700; -const LONG FontWeight::extraBold = 800; -const LONG FontWeight::black = 900; -const LONG FontWeight::heavy = 900; - - -FontStyle::FontStyle() -{ - setFontFamily(_T("")); - m_font.lfWeight = 18; - m_font.lfHeight = 0; - m_font.lfWidth = 0; - m_font.lfItalic = 0; - m_font.lfUnderline = 0; - m_font.lfStrikeOut = 0; - m_font.lfEscapement = 0; - m_font.lfOrientation = 0; - setQuality(true); -} - -FontStyle::FontStyle(LPCTSTR fontfamily, LONG height, LONG weight, LONG width, bool italic, bool underline, bool strikeout, LONG escapement, LONG orientation, bool quality) -{ - setFontFamily(fontfamily); - m_font.lfWeight = weight; - m_font.lfHeight = height; - m_font.lfWidth = width; - m_font.lfItalic = italic; - m_font.lfUnderline = underline; - m_font.lfStrikeOut = strikeout; - m_font.lfEscapement = escapement; - m_font.lfOrientation = orientation; - setQuality(quality); -} - -FontStyle::~FontStyle() -{ -} - -FontStyle * FontStyle::getDefault() -{ - return new FontStyle(_T(""), 18, FontWeight::normal); -} - -void FontStyle::setHeight(LONG value) -{ - m_font.lfHeight = value; -} - -void FontStyle::setWidth(LONG value) -{ - m_font.lfWidth = value; -} - -void FontStyle::setFontFamily(LPCTSTR value) -{ - _tcscpy_s(m_font.lfFaceName, 32, value); -} - -void FontStyle::setEscapement(LONG value) -{ - m_font.lfEscapement = value; -} - -void FontStyle::setOrientation(LONG value) -{ - m_font.lfOrientation = value; -} - -void FontStyle::setQuality(bool value) -{ - m_font.lfQuality = value ? ANTIALIASED_QUALITY : DEFAULT_QUALITY; -} - -void FontStyle::setWeight(LONG value) -{ - m_font.lfWeight = value; -} - -void FontStyle::setItalic(bool value) -{ - m_font.lfItalic = value; -} - -void FontStyle::setUnderline(bool value) -{ - m_font.lfUnderline = value; -} - -void FontStyle::setStrikeOut(bool value) -{ - m_font.lfStrikeOut = value; -} \ No newline at end of file diff --git a/Easy2D/Style/LineStyle.cpp b/Easy2D/Style/LineStyle.cpp deleted file mode 100644 index 1b613360..00000000 --- a/Easy2D/Style/LineStyle.cpp +++ /dev/null @@ -1 +0,0 @@ -/* LineStyle EasyX е࣬Ŀǰδʵ */ \ No newline at end of file diff --git a/Easy2D/Tool/ActionManager.cpp b/Easy2D/Tool/ActionManager.cpp deleted file mode 100644 index f9f62b6e..00000000 --- a/Easy2D/Tool/ActionManager.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" -#include - -static std::vector s_vActions; - -void ActionManager::__exec() -{ - // ʱָ - static Action * action; - // ѭеĶ - for (size_t i = 0; i < s_vActions.size(); i++) - { - action = s_vActions[i]; - // ȡ״̬ - if (action->isRunning()) - { - if (action->isEnding()) - { - // Ѿ - action->autoRelease(); - action->release(); - s_vActions.erase(s_vActions.begin() + i); - } - else - { - // ʼ - if (!action->m_bInit) - { - action->_init(); - } - // ִж - action->_exec(GetNow()); - } - } - } -} - -void ActionManager::addAction(Action * action) -{ - if (action) - { -#ifdef _DEBUG - for (auto a : s_vActions) - { - assert(a != action); - } -#endif - action->m_pParentScene = EApp::getLoadingScene(); - s_vActions.push_back(action); - } -} - -void ActionManager::notifyAllSceneActions(EScene * scene) -{ - for (auto action : s_vActions) - { - if (action->m_pParentScene == scene) - { - action->notify(); - } - } -} - -void ActionManager::waitAllSceneActions(EScene * scene) -{ - for (auto action : s_vActions) - { - if (action->m_pParentScene == scene) - { - action->wait(); - } - } -} - -void ActionManager::stopAllSceneActions(EScene * scene) -{ - for (auto action : s_vActions) - { - if (action->m_pParentScene == scene) - { - action->stop(); - } - } -} - -void ActionManager::startAction(Action * action) -{ - resumeAction(action); -} - -void ActionManager::resumeAction(Action * action) -{ - for (auto act : s_vActions) - { - if (act == action) - { - act->resume(); - } - } -} - -void ActionManager::pauseAction(Action * action) -{ - for (auto act : s_vActions) - { - if (act == action) - { - act->pause(); - } - } -} - -void ActionManager::stopAction(Action * action) -{ - for (auto act : s_vActions) - { - if (act == action) - { - act->stop(); - } - } -} - -void ActionManager::startSpriteAllActions(Sprite * sprite) -{ - resumeSpriteAllActions(sprite); -} - -void ActionManager::resumeSpriteAllActions(Sprite * sprite) -{ - for (auto action : s_vActions) - { - if (action->m_pTargetSprite == sprite) - { - action->resume(); - } - } -} - -void ActionManager::pauseSpriteAllActions(Sprite * sprite) -{ - for (auto action : s_vActions) - { - if (action->m_pTargetSprite == sprite) - { - action->pause(); - } - } -} - -void ActionManager::stopSpriteAllActions(Sprite * sprite) -{ - for (auto action : s_vActions) - { - if (action->m_pTargetSprite == sprite) - { - action->stop(); - } - } -} - -void ActionManager::startAllActions() -{ - resumeAllActions(); -} - -void ActionManager::resumeAllActions() -{ - for (auto action : s_vActions) - { - action->resume(); - } -} - -void ActionManager::pauseAllActions() -{ - for (auto action : s_vActions) - { - action->pause(); - } -} - -void ActionManager::stopAllActions() -{ - for (auto action : s_vActions) - { - action->stop(); - } -} - -void ActionManager::clearAllActions() -{ - for (auto action : s_vActions) - { - action->autoRelease(); - action->release(); - } - s_vActions.clear(); -} diff --git a/Easy2D/Tool/EMouseListener.cpp b/Easy2D/Tool/EMouseListener.cpp new file mode 100644 index 00000000..08fb0b33 --- /dev/null +++ b/Easy2D/Tool/EMouseListener.cpp @@ -0,0 +1 @@ +#include "..\etools.h" \ No newline at end of file diff --git a/Easy2D/Tool/EMsgManager.cpp b/Easy2D/Tool/EMsgManager.cpp new file mode 100644 index 00000000..99f0cf95 --- /dev/null +++ b/Easy2D/Tool/EMsgManager.cpp @@ -0,0 +1,86 @@ +#include "..\etools.h" +#include "..\Win\winbase.h" +#include + +static POINT p; +static e2d::EMouseMsg mouseMsg; + +std::vector m_vMouseListeners; + +void e2d::EMsgManager::setMouseMsg(UINT message) +{ + mouseMsg.m_nMsg = message; + + switch (message) + { + case WM_LBUTTONUP: + mouseMsg.m_bLButtonDown = false; + break; + + case WM_LBUTTONDOWN: + mouseMsg.m_bLButtonDown = true; + break; + + case WM_LBUTTONDBLCLK: + mouseMsg.m_bLButtonDown = true; + break; + + case WM_MBUTTONUP: + mouseMsg.m_bMButtonDown = false; + break; + + case WM_MBUTTONDOWN: + mouseMsg.m_bMButtonDown = true; + break; + + case WM_MBUTTONDBLCLK: + mouseMsg.m_bMButtonDown = true; + break; + + case WM_RBUTTONUP: + mouseMsg.m_bRButtonDown = false; + break; + + case WM_RBUTTONDOWN: + mouseMsg.m_bRButtonDown = true; + break; + + case WM_RBUTTONDBLCLK: + mouseMsg.m_bRButtonDown = true; + break; + + case WM_MOUSEMOVE: + { + GetCursorPos(&p); + ScreenToClient(GetHWnd(), &p); + mouseMsg.m_Pos = p; + break; + } + + case WM_MOUSEWHEEL: + break; + } + + for (auto mlistener : m_vMouseListeners) + { + //mlistener-> + } +} + +e2d::EMouseMsg::MESSAGE e2d::EMsgManager::getMouseMsg() +{ + return e2d::EMouseMsg::MESSAGE(mouseMsg.m_nMsg); +} + +void e2d::EMsgManager::addListener(e2d::EMouseListener * listener) +{ + if (listener) + { + listener->retain(); + m_vMouseListeners.push_back(listener); + } +} + +void e2d::EMsgManager::__exec() +{ +} diff --git a/Easy2D/Tool/FileUtils.cpp b/Easy2D/Tool/FileUtils.cpp deleted file mode 100644 index 0c14dec6..00000000 --- a/Easy2D/Tool/FileUtils.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include "..\easy2d.h" -#include "..\EasyX\easyx.h" -#include -#pragma comment(lib, "shell32.lib") -#include -#include - -#ifndef UNICODE - #include - #include -#endif - -TString FileUtils::getLocalAppDataPath() -{ - TCHAR m_lpszDefaultDir[MAX_PATH] = { 0 }; - TCHAR szDocument[MAX_PATH] = { 0 }; - - // ȡ AppData\Local ļе ID - LPITEMIDLIST pidl = NULL; - SHGetSpecialFolderLocation(NULL, CSIDL_LOCAL_APPDATA, &pidl); - if (pidl && SHGetPathFromIDList(pidl, szDocument)) - { - // ȡļ· - GetShortPathName(szDocument, m_lpszDefaultDir, _MAX_PATH); - } - - return m_lpszDefaultDir; -} - -TString FileUtils::getDefaultSavePath() -{ - TCHAR m_lpszDefaultDir[MAX_PATH] = { 0 }; - TCHAR szDocument[MAX_PATH] = { 0 }; - - // ȡ AppData\Local ļе ID - LPITEMIDLIST pidl = NULL; - SHGetSpecialFolderLocation(NULL, CSIDL_LOCAL_APPDATA, &pidl); - if (pidl && SHGetPathFromIDList(pidl, szDocument)) - { - // ȡļ· - GetShortPathName(szDocument, m_lpszDefaultDir, _MAX_PATH); - } - - TString path = m_lpszDefaultDir; - path.append(_T("\\")); - path.append(EApp::getAppName()); - -#ifdef UNICODE - if (_waccess(path.c_str(), 0) == -1) - { - _wmkdir(path.c_str()); - } -#else - if (_access(path.c_str(), 0) == -1) - { - _mkdir(path.c_str()); - } -#endif - - path.append(_T("\\DefaultData.ini")); - - return path; -} - -void FileUtils::saveInt(LPCTSTR key, int value) -{ -#ifdef UNICODE - std::wstringstream ss; -#else - std::stringstream ss; -#endif - ss << value; - ::WritePrivateProfileString(_T("Default"), key, ss.str().c_str(), getDefaultSavePath().c_str()); -} - -void FileUtils::saveDouble(LPCTSTR key, double value) -{ -#ifdef UNICODE - std::wstringstream ss; -#else - std::stringstream ss; -#endif - ss << value; - ::WritePrivateProfileString(_T("Default"), key, ss.str().c_str(), getDefaultSavePath().c_str()); -} - -void FileUtils::saveString(LPCTSTR key, TString value) -{ - ::WritePrivateProfileString(_T("Default"), key, value.c_str(), getDefaultSavePath().c_str()); -} - -int FileUtils::getInt(LPCTSTR key, int default) -{ - return ::GetPrivateProfileInt(_T("Default"), key, default, getDefaultSavePath().c_str()); -} -#include -using namespace std; -double FileUtils::getDouble(LPCTSTR key, double default) -{ - // default תΪַ -#ifdef UNICODE - std::wstringstream ss; -#else - std::stringstream ss; -#endif - ss << default; - // ȡ - TCHAR temp[128] = { 0 }; - ::GetPrivateProfileString(_T("Default"), key, ss.str().c_str(), temp, 128, getDefaultSavePath().c_str()); - // תΪַ - ss.str(_T("")); - ss << temp; - // ַתΪ double -#ifdef UNICODE - double d = _wtof(ss.str().c_str()); -#else - double d = atof(ss.str().c_str()); -#endif - return d; -} - -TString FileUtils::geTString(LPCTSTR key, TString default) -{ - TCHAR temp[128] = { 0 }; - ::GetPrivateProfileString(_T("Default"), key, default.c_str(), temp, 128, getDefaultSavePath().c_str()); - return TString(temp); -} - -TString FileUtils::getFileExtension(const TString & filePath) -{ - TString fileExtension; - // ҵļеһ '.' λ - size_t pos = filePath.find_last_of('.'); - // ж pos ǷǸЧλ - if (pos != TString::npos) - { - // ȡչ - fileExtension = filePath.substr(pos, filePath.length()); - // תΪСдĸ - std::transform(fileExtension.begin(), fileExtension.end(), fileExtension.begin(), ::tolower); - } - - return fileExtension; -} - -bool FileUtils::getSaveFilePath(TString& path, LPCTSTR title, LPCTSTR defExt) -{ - // Ի - OPENFILENAME ofn = { 0 }; - TCHAR strFilename[MAX_PATH] = { 0 }; // ڽļ - ofn.lStructSize = sizeof(OPENFILENAME); // ṹС - ofn.hwndOwner = GetHWnd(); // ӵŴھNULL ʾԻǷģ̬ - ofn.lpstrFilter = _T("ļ\0*.*\0\0"); // ù - ofn.nFilterIndex = 1; // - ofn.lpstrFile = strFilename; // շصļ·ļ - ofn.nMaxFile = sizeof(strFilename); // - ofn.lpstrInitialDir = NULL; // ʼĿ¼ΪĬ - ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;// Ŀ¼ڣļǰ - ofn.lpstrTitle = title; // ʹϵͳĬϱռ - ofn.lpstrDefExt = defExt; // Ĭ׷ӵչ - - if (GetSaveFileName(&ofn)) - { - path = strFilename; - return true; - } - return false; -} diff --git a/Easy2D/Tool/Math.cpp b/Easy2D/Tool/Math.cpp deleted file mode 100644 index 2d0a3821..00000000 --- a/Easy2D/Tool/Math.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "..\easy2d.h" - - -std::default_random_engine &Math::getEngine() -{ - static std::random_device device; - static std::default_random_engine engine(device()); - return engine; -} diff --git a/Easy2D/Tool/MusicUtils.cpp b/Easy2D/Tool/MusicUtils.cpp deleted file mode 100644 index f374b3b1..00000000 --- a/Easy2D/Tool/MusicUtils.cpp +++ /dev/null @@ -1,417 +0,0 @@ -#include "..\easy2d.h" -#include -#pragma comment(lib , "winmm.lib") - -#include -#include - -//////////////////////////////////////////////////////////////////// -// MciPlayer -//////////////////////////////////////////////////////////////////// - -class MciPlayer -{ -public: - MciPlayer(); - ~MciPlayer(); - - void close(); - void open(TString pFileName, UINT uId); - void play(bool bLoop = false); - void pause(); - void resume(); - void stop(); - void rewind(); - void setVolume(float volume); - bool isPlaying(); - UINT getSoundID(); - -private: - void _sendCommand(int nCommand, DWORD_PTR param1 = 0, DWORD_PTR parma2 = 0); - - MCIDEVICEID m_dev; - UINT m_nSoundID; - bool m_bPlaying; - bool m_bLoop; - TString m_sExt; -}; - - -MciPlayer::MciPlayer() : - m_dev(0L), - m_nSoundID(0), - m_bPlaying(false), - m_bLoop(false), - m_sExt(_T("")) -{ -} - -MciPlayer::~MciPlayer() -{ - close(); // رղ -} - -void MciPlayer::open(TString pFileName, UINT uId) -{ - // Բڵļ - if (pFileName.empty() || !PathFileExists(pFileName.c_str())) return; - // ȡļ׺ - m_sExt = FileUtils::getFileExtension(pFileName); - // ֹͣǰ - close(); - - // MCI_OPEN_PARMS - MCI_OPEN_PARMS mciOpen = { 0 }; - mciOpen.lpstrDeviceType = (LPCTSTR)-1; // device ID for "all devices" - mciOpen.lpstrElementName = pFileName.c_str(); - - // ļ - MCIERROR mciError; - mciError = mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT, reinterpret_cast(&mciOpen)); - // ִʱβ - if (mciError) return; - - // 豸Ϣ - m_dev = mciOpen.wDeviceID; - m_nSoundID = uId; - m_bPlaying = false; -} - -void MciPlayer::play(bool bLoop) -{ - // 豸Ϊʱβ - if (!m_dev) - { - return; - } - // òŲ - MCI_PLAY_PARMS mciPlay = { 0 }; - MCIERROR s_mciError; - // - s_mciError = mciSendCommand(m_dev, MCI_PLAY, MCI_FROM | (bLoop ? MCI_DGV_PLAY_REPEAT : 0), reinterpret_cast(&mciPlay)); - // δʱ m_bPlaying Ϊ true - if (!s_mciError) - { - m_bPlaying = true; - m_bLoop = bLoop; - } -} - -void MciPlayer::close() -{ - // ֹͣ - if (m_bPlaying) - { - stop(); - } - // ر豸 - if (m_dev) - { - _sendCommand(MCI_CLOSE); - } - // ָĬ - m_dev = 0; - m_bPlaying = false; -} - -void MciPlayer::pause() -{ - // ͣ - _sendCommand(MCI_PAUSE); - m_bPlaying = false; -} - -void MciPlayer::resume() -{ - // - if (m_sExt == _T(".mid")) - { - // midi ֧ MCI_RESUME Ӧʹ MCI_FROM òʼλ - // ȡ MCI ״̬ - MCI_STATUS_PARMS mciStatusParms; - mciStatusParms.dwItem = MCI_STATUS_POSITION; - _sendCommand(MCI_STATUS, MCI_STATUS_ITEM, reinterpret_cast(&mciStatusParms)); - // òʼλãʼ - MCI_PLAY_PARMS mciPlayParms; - mciPlayParms.dwFrom = (DWORD)mciStatusParms.dwReturn; - _sendCommand(MCI_PLAY, MCI_FROM, reinterpret_cast(&mciPlayParms)); - } - else - { - // - _sendCommand(MCI_RESUME); - m_bPlaying = true; - } -} - -void MciPlayer::stop() -{ - // ֹͣ - _sendCommand(MCI_STOP); - m_bPlaying = false; -} - -void MciPlayer::rewind() -{ - // 豸Ϊʱβ - if (!m_dev) - { - return; - } - // òλ - mciSendCommand(m_dev, MCI_SEEK, MCI_SEEK_TO_START, 0); - // - MCI_PLAY_PARMS mciPlay = { 0 }; - m_bPlaying = mciSendCommand(m_dev, MCI_PLAY, (m_bLoop ? MCI_DGV_PLAY_REPEAT : 0), reinterpret_cast(&mciPlay)) ? false : true; -} - -void MciPlayer::setVolume(float volume) -{ - volume = min(max(volume, 0), 1); - MCI_DGV_SETAUDIO_PARMS mciSetAudioPara = { 0 }; - mciSetAudioPara.dwItem = MCI_DGV_SETAUDIO_VOLUME; - mciSetAudioPara.dwValue = DWORD(1000 * volume); - mciSendCommand(m_dev, MCI_SETAUDIO, MCI_DGV_SETAUDIO_VALUE | MCI_DGV_SETAUDIO_ITEM, (DWORD_PTR)&mciSetAudioPara); -} - -bool MciPlayer::isPlaying() -{ - return m_bPlaying; -} - -UINT MciPlayer::getSoundID() -{ - return m_nSoundID; -} - -void MciPlayer::_sendCommand(int nCommand, DWORD_PTR param1, DWORD_PTR parma2) -{ - // 豸ʱβ - if (!m_dev) - { - return; - } - // ǰ豸Ͳ - mciSendCommand(m_dev, nCommand, param1, parma2); -} - - - - -//////////////////////////////////////////////////////////////////// -// MusicUtils -//////////////////////////////////////////////////////////////////// - - -typedef std::map MusicList; -typedef std::pair Music; - -static unsigned int _Hash(TString key); - - -static MusicList& getMciPlayerList() -{ - static MusicList s_List; - return s_List; -} - -static MciPlayer& getBgMciPlayer() -{ - static MciPlayer s_Music; - return s_Music; -} - -void MusicUtils::end() -{ - // ֹͣ - getBgMciPlayer().close(); - // ֹͣ - for (auto& iter : getMciPlayerList()) - { - SafeDelete(iter.second); - } - // б - getMciPlayerList().clear(); - return; -} - -void MusicUtils::setVolume(float volume) -{ - // ñ - getBgMciPlayer().setVolume(volume); - // - for (auto& iter : getMciPlayerList()) - { - iter.second->setVolume(volume); - } -} - -void MusicUtils::setVolume(TString pszFilePath, float volume) -{ - unsigned int nRet = ::_Hash(pszFilePath); - - MusicList::iterator p = getMciPlayerList().find(nRet); - if (p != getMciPlayerList().end()) - { - p->second->setVolume(volume); - } -} - -void MusicUtils::playBackgroundMusic(TString pszFilePath, bool bLoop) -{ - if (pszFilePath.empty()) - { - return; - } - - getBgMciPlayer().open(pszFilePath, ::_Hash(pszFilePath)); - getBgMciPlayer().play(bLoop); -} - -void MusicUtils::stopBackgroundMusic(bool bReleaseData) -{ - if (bReleaseData) - { - getBgMciPlayer().close(); - } - else - { - getBgMciPlayer().stop(); - } -} - -void MusicUtils::pauseBackgroundMusic() -{ - getBgMciPlayer().pause(); -} - -void MusicUtils::resumeBackgroundMusic() -{ - getBgMciPlayer().resume(); -} - -void MusicUtils::rewindBackgroundMusic() -{ - getBgMciPlayer().rewind(); -} - -bool MusicUtils::isBackgroundMusicPlaying() -{ - return getBgMciPlayer().isPlaying(); -} - -void MusicUtils::setBackgroundMusicVolume(float volume) -{ - getBgMciPlayer().setVolume(volume); -} - -unsigned int MusicUtils::playMusic(TString pszFilePath, bool bLoop) -{ - unsigned int nRet = ::_Hash(pszFilePath); - - preloadMusic(pszFilePath); - - MusicList::iterator p = getMciPlayerList().find(nRet); - if (p != getMciPlayerList().end()) - { - p->second->play(bLoop); - } - return nRet; -} - -void MusicUtils::stopMusic(unsigned int nSoundId) -{ - MusicList::iterator p = getMciPlayerList().find(nSoundId); - if (p != getMciPlayerList().end()) - { - p->second->stop(); - } -} - -void MusicUtils::preloadMusic(TString pszFilePath) -{ - if (pszFilePath.empty()) return; - - int nRet = ::_Hash(pszFilePath); - - if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) return; - - getMciPlayerList().insert(Music(nRet, new MciPlayer())); - MciPlayer * pPlayer = getMciPlayerList()[nRet]; - pPlayer->open(pszFilePath, nRet); - - if (nRet == pPlayer->getSoundID()) return; - - delete pPlayer; - getMciPlayerList().erase(nRet); - nRet = 0; -} - -void MusicUtils::pauseMusic(unsigned int nSoundId) -{ - MusicList::iterator p = getMciPlayerList().find(nSoundId); - if (p != getMciPlayerList().end()) - { - p->second->pause(); - } -} - -void MusicUtils::pauseAllMusics() -{ - for (auto& iter : getMciPlayerList()) - { - iter.second->pause(); - } -} - -void MusicUtils::resumeMusic(unsigned int nSoundId) -{ - MusicList::iterator p = getMciPlayerList().find(nSoundId); - if (p != getMciPlayerList().end()) - { - p->second->resume(); - } -} - -void MusicUtils::resumeAllMusics() -{ - for (auto& iter : getMciPlayerList()) - { - iter.second->resume(); - } -} - -void MusicUtils::stopAllMusics() -{ - for (auto& iter : getMciPlayerList()) - { - iter.second->stop(); - } -} - -void MusicUtils::unloadMusic(LPCTSTR pszFilePath) -{ - unsigned int nID = ::_Hash(pszFilePath); - - MusicList::iterator p = getMciPlayerList().find(nID); - if (p != getMciPlayerList().end()) - { - SafeDelete(p->second); - getMciPlayerList().erase(nID); - } -} - - - -unsigned int _Hash(TString key) -{ - unsigned int len = unsigned(key.size()); - unsigned int hash = 0; - - for (unsigned i = 0; i < len; i++) - { - hash *= 16777619; - hash ^= (unsigned int)(unsigned char)toupper(key[i]); - } - return (hash); -} \ No newline at end of file diff --git a/Easy2D/Tool/Timer.cpp b/Easy2D/Tool/Timer.cpp deleted file mode 100644 index e3c44ce7..00000000 --- a/Easy2D/Tool/Timer.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include "..\easy2d.h" -#include "..\Win\winbase.h" - -// жʱ -static std::vector s_vTimers; - -Timer::Timer(TString name, LONGLONG milliSeconds, const TIMER_CALLBACK & callback) : - m_sName(name), - m_bRunning(false), - m_bWaiting(false), - m_callback(callback), - m_pParentScene(nullptr) -{ - setInterval(milliSeconds); // öʱʱ -} - -Timer::~Timer() -{ -} - -void Timer::start() -{ - // ־öʱ - m_bRunning = true; - // ¼ǰʱ - m_nLast = steady_clock::now(); -} - -void Timer::stop() -{ - m_bRunning = false; // ־öʱֹͣ -} - -void Timer::wait() -{ - m_bWaiting = true; -} - -void Timer::notify() -{ - m_bWaiting = false; -} - -bool Timer::isRunning() -{ - return m_bRunning && !m_bWaiting; // ȡöʱ״̬ -} - -void Timer::setInterval(LONGLONG milliSeconds) -{ - // öʱʱ - m_nAnimationInterval = milliSeconds; -} - -void Timer::setCallback(const TIMER_CALLBACK & callback) -{ - m_callback = callback; // ص -} - -void Timer::setName(TString name) -{ - m_sName = name; // ޸Ķʱ -} - -LONGLONG Timer::getInterval() const -{ - return m_nAnimationInterval;// ȡʱʱ -} - -TString Timer::getName() const -{ - return m_sName; // ȡʱ -} - -void Timer::__exec() -{ - // ʱΪ - if (!s_vTimers.size()) - { - return; - } - // ѭеĶʱ - for (auto timer : s_vTimers) - { - // ʱδУʱ - if (!timer->isRunning()) - { - continue; - } - // жʱǷ㹻 - while (duration_cast(GetNow() - timer->m_nLast).count() > timer->m_nAnimationInterval) - { - // ¼¼ʱ - timer->m_nLast += milliseconds(timer->m_nAnimationInterval); - // лص - timer->m_callback(); - } - } -} - -void Timer::addTimer(Timer * timer) -{ - // ʱ - timer->start(); - // ڳ - timer->m_pParentScene = EApp::getLoadingScene(); - // öʱ - s_vTimers.push_back(timer); -} - -void Timer::addTimer(TString name, const TIMER_CALLBACK & callback) -{ - addTimer(name, 20, callback); -} - -void Timer::addTimer(TString name, LONGLONG milliSeconds, const TIMER_CALLBACK & callback) -{ - // ʱ - auto timer = new Timer(name, milliSeconds, callback); - // Ӷʱ - addTimer(timer); -} - -void Timer::startTimer(TString name) -{ - // ͬĶʱ - for (auto timer : s_vTimers) - { - if (timer->m_sName == name && timer->m_pParentScene == EApp::getCurrentScene()) - { - // ʱ - timer->start(); - } - } -} - -void Timer::stopTimer(TString name) -{ - // ͬĶʱ - for (auto timer : s_vTimers) - { - if (timer->m_sName == name && timer->m_pParentScene == EApp::getCurrentScene()) - { - // ֹͣʱ - timer->stop(); - } - } -} - -void Timer::delTimer(TString name) -{ - // - std::vector::iterator iter; - // ѭжʱ - for (iter = s_vTimers.begin(); iter != s_vTimers.end();) - { - // ͬƵĶʱ - if ((*iter)->m_sName == name && (*iter)->m_pParentScene == EApp::getCurrentScene()) - { - // ɾöʱ - delete (*iter); - iter = s_vTimers.erase(iter); - } - else - { - iter++; - } - } -} - -void Timer::clearAllTimers() -{ - // ɾжʱ - for (auto t : s_vTimers) - { - delete t; - } - // - s_vTimers.clear(); -} - -void Timer::notifyAllSceneTimers(EScene * scene) -{ - for (auto t : s_vTimers) - { - if (t->m_pParentScene == scene) - { - t->notify(); - } - } -} - -void Timer::waitAllSceneTimers(EScene * scene) -{ - for (auto t : s_vTimers) - { - if (t->m_pParentScene == scene) - { - t->wait(); - } - } -} - -void Timer::clearAllSceneTimers(EScene * scene) -{ - // - std::vector::iterator iter; - // ѭжʱ - for (iter = s_vTimers.begin(); iter != s_vTimers.end();) - { - // ͬƵĶʱ - if ((*iter)->m_pParentScene == scene) - { - // ɾöʱ - delete (*iter); - iter = s_vTimers.erase(iter); - } - else - { - iter++; - } - } -} diff --git a/Easy2D/Win/winbase.cpp b/Easy2D/Win/winbase.cpp index 17a13d67..48fbea8f 100644 --- a/Easy2D/Win/winbase.cpp +++ b/Easy2D/Win/winbase.cpp @@ -1,24 +1,24 @@ #include "winbase.h" #include "..\emacros.h" -HWND m_hwnd = nullptr; -ID2D1Factory * m_pDirect2dFactory = nullptr; -ID2D1HwndRenderTarget * m_pRenderTarget = nullptr; +HWND hwnd = nullptr; +ID2D1Factory * pDirect2dFactory = nullptr; +ID2D1HwndRenderTarget * pRenderTarget = nullptr; HWND &GetHWnd() { - return m_hwnd; + return hwnd; } ID2D1Factory * &GetFactory() { - return m_pDirect2dFactory; + return pDirect2dFactory; } ID2D1HwndRenderTarget * &GetRenderTarget() { - return m_pRenderTarget; + return pRenderTarget; } void WindowCenter(HWND hWnd) diff --git a/Easy2D/Win/winbase.h b/Easy2D/Win/winbase.h index cfaf4ba8..aae0f32d 100644 --- a/Easy2D/Win/winbase.h +++ b/Easy2D/Win/winbase.h @@ -1,4 +1,5 @@ #pragma once +#include "..\emacros.h" #include #include #include diff --git a/Easy2D/easy2d.h b/Easy2D/easy2d.h index 199ac9a7..0114b253 100644 --- a/Easy2D/easy2d.h +++ b/Easy2D/easy2d.h @@ -16,45 +16,18 @@ #endif -// Modify the following defines if you have to target a platform prior to the ones specified below. -// Refer to MSDN for the latest info on corresponding values for different platforms. -#ifndef WINVER // Allow use of features specific to Windows 7 or later. -#define WINVER 0x0700 // Change this to the appropriate value to target other versions of Windows. -#endif - -#ifndef _WIN32_WINNT // Allow use of features specific to Windows 7 or later. -#define _WIN32_WINNT 0x0700 // Change this to the appropriate value to target other versions of Windows. -#endif - -#ifndef UNICODE -#define UNICODE -#endif - -// Exclude rarely-used items from Windows headers. -#define WIN32_LEAN_AND_MEAN - -// Windows Header Files: -#include - -// C RunTime Header Files: -#include - #include "emacros.h" #include "ecommon.h" #include "ebase.h" +#include "enodes.h" +#include "etools.h" -#if defined(UNICODE) && (_DEBUG) +#if defined(DEBUG) || defined(_DEBUG) #pragma comment(lib, "Easy2Ddw.lib") -#elif !defined(UNICODE) && (_DEBUG) - #pragma comment(lib, "Easy2Dd.lib") -#elif defined(UNICODE) +#else #pragma comment(lib, "Easy2Dw.lib") -#elif !defined(UNICODE) - #pragma comment(lib, "Easy2D.lib") #endif -// Functions Declare - using namespace e2d; \ No newline at end of file diff --git a/Easy2D/ebase.h b/Easy2D/ebase.h index 176eed1c..33208d5d 100644 --- a/Easy2D/ebase.h +++ b/Easy2D/ebase.h @@ -3,6 +3,7 @@ #include "ecommon.h" #include + // Base Classes namespace e2d @@ -188,7 +189,8 @@ public: // ɾӳԱ bool del( - e2d::ENode * child + e2d::ENode * child, + bool autoRelease = true ); // ȡӽڵ @@ -202,9 +204,10 @@ protected: std::vector m_vChildren; protected: + // void _exec(); - void _onDraw(); + void _onRender(); }; diff --git a/Easy2D/emacros.h b/Easy2D/emacros.h index dedf3f0e..2c2b2337 100644 --- a/Easy2D/emacros.h +++ b/Easy2D/emacros.h @@ -1,6 +1,28 @@ #pragma once +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Allow use of features specific to Windows 7 or later. +#define WINVER 0x0700 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Allow use of features specific to Windows 7 or later. +#define _WIN32_WINNT 0x0700 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef UNICODE +#define UNICODE +#endif + +// Exclude rarely-used items from Windows headers. +#define WIN32_LEAN_AND_MEAN + +// Windows Header Files: +#include + + + #ifndef ASSERT_IF #if defined( DEBUG ) || defined( _DEBUG ) #define ASSERT(b) do {if (!(b)) { OutputDebugStringA("Assert: " #b "\n"); }} while(0) diff --git a/Easy2D/enodes.h b/Easy2D/enodes.h index 2a374487..859266a1 100644 --- a/Easy2D/enodes.h +++ b/Easy2D/enodes.h @@ -158,7 +158,7 @@ protected: virtual bool _exec(bool active); - virtual void _onDraw() = 0; + virtual void _onRender(); }; } \ No newline at end of file diff --git a/Easy2D/etools.h b/Easy2D/etools.h index 8c41cc10..280aa0aa 100644 --- a/Easy2D/etools.h +++ b/Easy2D/etools.h @@ -8,7 +8,9 @@ class EObjectManager { public: // һڵͷų - static void add(e2d::EObject * nptr); + static void add( + e2d::EObject * nptr + ); // ɾнڵ static void clearAllObjects(); @@ -20,4 +22,62 @@ private: static void __flush(); }; + +class EMouseMsg +{ +public: + // Ϣ + enum MESSAGE + { + MOVE = 0x0200, // ƶ + LBUTTON_DOWN, // + LBUTTON_UP, // ̧ + LBUTTON_DBLCLK, // ˫ + RBUTTON_DOWN, // Ҽ + RBUTTON_UP, // Ҽ̧ + RBUTTON_DBLCLK, // Ҽ˫ + MBUTTON_DOWN, // м + MBUTTON_UP, // м̧ + MBUTTON_DBLCLK, // м˫ + WHEEL // + }; + +public: + EPoint m_Pos; + UINT m_nMsg = 0; + bool m_bLButtonDown = false; + bool m_bRButtonDown = false; + bool m_bMButtonDown = false; +}; + + +class EMouseListener : + public EObject +{ +protected: + friend EMsgManager; + e2d::EString name; + +}; + + +class EMsgManager +{ +public: + static void setMouseMsg( + UINT message + ); + + static e2d::EMouseMsg::MESSAGE getMouseMsg(); + + static void addListener( + EMouseListener * listener + ); + +private: + friend EApp; + + static void __exec(); +}; + } \ No newline at end of file