diff --git a/core/base/ActionTween.cpp b/core/base/ActionTween.cpp index 90c97c3c..7e402b76 100644 --- a/core/base/ActionTween.cpp +++ b/core/base/ActionTween.cpp @@ -75,6 +75,24 @@ namespace easy2d case EaseFunc::EaseExponentialInOut: ease_func_ = math::EaseExponentialInOut; break; + case EaseFunc::EaseBounceIn: + ease_func_ = math::EaseBounceIn; + break; + case EaseFunc::EaseBounceOut: + ease_func_ = math::EaseBounceOut; + break; + case EaseFunc::EaseBounceInOut: + ease_func_ = math::EaseBounceInOut; + break; + case EaseFunc::EaseElasticIn: + ease_func_ = std::bind(math::EaseElasticIn, std::placeholders::_1, 0.3f); + break; + case EaseFunc::EaseElasticOut: + ease_func_ = std::bind(math::EaseElasticOut, std::placeholders::_1, 0.3f); + break; + case EaseFunc::EaseElasticInOut: + ease_func_ = std::bind(math::EaseElasticInOut, std::placeholders::_1, 0.3f); + break; case EaseFunc::EaseSineIn: ease_func_ = math::EaseSineIn; break; diff --git a/core/base/ActionTween.h b/core/base/ActionTween.h index 92c2a986..6e5c5b6f 100644 --- a/core/base/ActionTween.h +++ b/core/base/ActionTween.h @@ -33,9 +33,15 @@ namespace easy2d EaseExponentialIn, // 由慢变极快 EaseExponentialOut, // 由极快变慢 EaseExponentialInOut, // 由慢至极快, 再由极快边慢 + EaseBounceIn, // 自起点赋予反弹力 + EaseBounceOut, // 自终点赋予反弹力 + EaseBounceInOut, // 在起点和终点赋予反弹力 + EaseElasticIn, // 自起点赋予弹性 + EaseElasticOut, // 自终点赋予弹性 + EaseElasticInOut, // 再起点和终点赋予弹性 EaseSineIn, // 由快变慢, 采用正弦变换速度 EaseSineOut, // 由慢变快, 采用正弦变换速度 - EaseSineInOut // 由慢至快, 再由快至慢, 采用正弦变换速度 + EaseSineInOut, // 由慢至快, 再由快至慢, 采用正弦变换速度 }; class Tween diff --git a/core/base/Game.cpp b/core/base/Game.cpp index fdad9574..c6a8ae58 100644 --- a/core/base/Game.cpp +++ b/core/base/Game.cpp @@ -98,10 +98,6 @@ namespace easy2d freopen_s(&stdoutStream, "conout$", "w+t", stdout); freopen_s(&stdinStream, "conin$", "r+t", stdin); freopen_s(&stderrStream, "conout$", "w+t", stderr); - - // disable the close button of console - HMENU hmenu = ::GetSystemMenu(console, FALSE); - ::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } } @@ -113,6 +109,13 @@ namespace easy2d } } + if (console) + { + // disable the close button of console + HMENU hmenu = ::GetSystemMenu(console, FALSE); + ::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); + } + initialized_ = true; } diff --git a/core/base/MouseEvent.h b/core/base/MouseEvent.h index a77261e9..ddc11f60 100644 --- a/core/base/MouseEvent.h +++ b/core/base/MouseEvent.h @@ -31,7 +31,7 @@ namespace easy2d // 鼠标消息类型 enum class Type : int { - MoveBy = 0x0200, // 鼠标移动 + Move = 0x0200, // 鼠标移动 LeftDown, // 鼠标左键按下 LeftUp, // 鼠标左键抬起 LeftDoubleClick, // 鼠标左键双击 diff --git a/core/base/Unit.cpp b/core/base/Unit.cpp index 6278c6eb..a3779a46 100644 --- a/core/base/Unit.cpp +++ b/core/base/Unit.cpp @@ -67,14 +67,14 @@ namespace easy2d dirty_transform_ = true; } - void Unit::MoveBy(float x, float y) + void Unit::Move(float x, float y) { this->SetPosition(transform_.position.x + x, transform_.position.y + y); } - void Unit::MoveBy(const Point & v) + void Unit::Move(const Point & v) { - this->MoveBy(v.x, v.y); + this->Move(v.x, v.y); } void Unit::SetScaleX(float scale_x) diff --git a/core/base/Unit.h b/core/base/Unit.h index 76207615..bef6f6ec 100644 --- a/core/base/Unit.h +++ b/core/base/Unit.h @@ -74,13 +74,13 @@ namespace easy2d ); // 移动 - void MoveBy( + void Move( float x, float y ); // 移动 - void MoveBy( + void Move( const Point & vector ); diff --git a/core/easy2d.h b/core/easy2d.h index 7f2b3003..0264ed65 100644 --- a/core/easy2d.h +++ b/core/easy2d.h @@ -58,6 +58,7 @@ #include "base/Unit.h" #include "base/Geometry.h" #include "base/Image.h" +#include "base/Frames.h" #include "base/Node.h" #include "base/Scene.h" #include "base/Sprite.h" @@ -70,7 +71,7 @@ #include "base/ActionCombined.h" #include "base/ActionTween.h" #include "base/Animation.h" -#include "base/CallFunc.h" +#include "base/Delay.h" #include "base/Transition.h" #include "base/Debuger.h" @@ -84,7 +85,9 @@ // math // +#include "math/constants.hpp" #include "math/scalar.hpp" +#include "math/ease.hpp" #include "math/vector.hpp" #include "math/rand.h" #include "math/Matrix.hpp" diff --git a/core/math/constants.hpp b/core/math/constants.hpp new file mode 100644 index 00000000..f14761ba --- /dev/null +++ b/core/math/constants.hpp @@ -0,0 +1,44 @@ +// Copyright (c) 2016-2018 Easy2D - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once + +#if _MSC_VER >= 1900 +# define E2D_CONSTEXPR constexpr +#else +# define E2D_CONSTEXPR const +#endif + +namespace easy2d +{ + namespace math + { + namespace constants + { + E2D_CONSTEXPR auto PI_F = 3.141592653589793f; + E2D_CONSTEXPR auto PI_F_2 = 1.570796326794896f; + E2D_CONSTEXPR auto PI_F_X_2 = 6.283185307179586f; + + E2D_CONSTEXPR auto PI_D = 3.14159265358979323846; + E2D_CONSTEXPR auto PI_D_2 = 1.57079632679489661923; + E2D_CONSTEXPR auto PI_D_X_2 = 6.28318530717958647692; + } + } +} diff --git a/core/math/ease.hpp b/core/math/ease.hpp index 276e06b3..ae730517 100644 --- a/core/math/ease.hpp +++ b/core/math/ease.hpp @@ -64,6 +64,74 @@ namespace easy2d return 0.5f * (2 - math::Pow(2, -10 * (step * 2 - 1))); } + inline float EaseBounceOut(float step) + { + if (step < 1 / 2.75f) + { + return 7.5625f * step * step; + } + else if (step < 2 / 2.75f) + { + step -= 1.5f / 2.75f; + return 7.5625f * step * step + 0.75f; + } + else if (step < 2.5f / 2.75f) + { + step -= 2.25f / 2.75f; + return 7.5625f * step * step + 0.9375f; + } + + step -= 2.625f / 2.75f; + return 7.5625f * step * step + 0.984375f; + } + + inline float EaseBounceIn(float step) + { + return 1 - EaseBounceOut(1 - step); + } + + inline float EaseBounceInOut(float step) + { + if (step < 0.5f) + { + return EaseBounceIn(step * 2) * 0.5f; + } + else + { + return EaseBounceOut(step * 2 - 1) * 0.5f + 0.5f; + } + } + + inline float EaseElasticIn(float step, float period) + { + if (step == 0 || step == 1) + return step; + + step = step - 1; + return -math::Pow(2, 10 * step) * math::Sin((step - period / 4) * 360.f / period); + } + + inline float EaseElasticOut(float step, float period) + { + if (step == 0 || step == 1) + return step; + + return math::Pow(2, -10 * step) * math::Sin((step - period / 4) * 360.f / period) + 1; + } + + inline float EaseElasticInOut(float step, float period) + { + if (step == 0 || step == 1) + return step; + + step = step * 2 - 1; + if (step < 0) + { + return -0.5f * math::Pow(2, 10 * step) * math::Sin((step - period / 4) * 360.f / period); + } + return math::Pow(2, -10 * step) * math::Sin((step - period / 4) * 360.f / period) * 0.5f + 1; + } + inline float EaseSineIn(float step) { return 1.f - math::Cos(step * 90); diff --git a/core/math/scalar.hpp b/core/math/scalar.hpp index 3b88313f..d32eb8ba 100644 --- a/core/math/scalar.hpp +++ b/core/math/scalar.hpp @@ -19,6 +19,7 @@ // THE SOFTWARE. #pragma once +#include "constants.hpp" #include #if _MSC_VER >= 1900 @@ -32,14 +33,6 @@ namespace easy2d { namespace math { - namespace constants - { - E2D_CONSTEXPR auto PI_F = 3.141592653589793f; - E2D_CONSTEXPR auto PI_F_2 = 1.570796326794896f; - E2D_CONSTEXPR auto PI_D = 3.14159265358979323846; - E2D_CONSTEXPR auto PI_D_2 = 1.57079632679489661923; - } - inline int Abs(int val) { return ::abs(val); } inline float Abs(float val) { return ::fabsf(val); } diff --git a/core/ui/Button.cpp b/core/ui/Button.cpp index 647de6c4..80356d3c 100644 --- a/core/ui/Button.cpp +++ b/core/ui/Button.cpp @@ -198,7 +198,7 @@ namespace easy2d { is_selected_ = false; } - else if (e.GetType() == MouseEvent::Type::MoveBy && is_selected_ && contains) + else if (e.GetType() == MouseEvent::Type::Move && is_selected_ && contains) { SetStatus(Status::Selected); return true; diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj index 44b1da85..05ce657f 100644 --- a/project/vs2013/Easy2D.vcxproj +++ b/project/vs2013/Easy2D.vcxproj @@ -70,6 +70,7 @@ + diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters index ef9f1e48..4642ce07 100644 --- a/project/vs2013/Easy2D.vcxproj.filters +++ b/project/vs2013/Easy2D.vcxproj.filters @@ -191,6 +191,9 @@ base + + math + diff --git a/project/vs2015/Easy2D.vcxproj b/project/vs2015/Easy2D.vcxproj index dd981319..33e1dca5 100644 --- a/project/vs2015/Easy2D.vcxproj +++ b/project/vs2015/Easy2D.vcxproj @@ -70,6 +70,7 @@ + diff --git a/project/vs2015/Easy2D.vcxproj.filters b/project/vs2015/Easy2D.vcxproj.filters index ef9f1e48..4642ce07 100644 --- a/project/vs2015/Easy2D.vcxproj.filters +++ b/project/vs2015/Easy2D.vcxproj.filters @@ -191,6 +191,9 @@ base + + math + diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 3bbbf2be..6d3a59be 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -70,6 +70,7 @@ + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index ef9f1e48..4642ce07 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -191,6 +191,9 @@ base + + math +