remove: Function class
This commit is contained in:
parent
e4e6b47d3b
commit
7608996dda
|
|
@ -20,26 +20,26 @@
|
||||||
|
|
||||||
#include "..\e2daction.h"
|
#include "..\e2daction.h"
|
||||||
|
|
||||||
easy2d::Callback::Callback(const Function& func) :
|
easy2d::CallFunc::CallFunc(const Callback& func) :
|
||||||
callback_(func)
|
callback_(func)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Callback * easy2d::Callback::Clone() const
|
easy2d::CallFunc * easy2d::CallFunc::Clone() const
|
||||||
{
|
{
|
||||||
return new Callback(callback_);
|
return new CallFunc(callback_);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Callback * easy2d::Callback::Reverse() const
|
easy2d::CallFunc * easy2d::CallFunc::Reverse() const
|
||||||
{
|
{
|
||||||
return new Callback(callback_);
|
return new CallFunc(callback_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Callback::Init()
|
void easy2d::CallFunc::Init()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Callback::Update()
|
void easy2d::CallFunc::Update()
|
||||||
{
|
{
|
||||||
callback_();
|
callback_();
|
||||||
this->Stop();
|
this->Stop();
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ easy2d::Button::Button()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Button::Button(Node * normal, const Function& func)
|
easy2d::Button::Button(Node * normal, const Callback& func)
|
||||||
: callback_(nullptr)
|
: callback_(nullptr)
|
||||||
, status_(Status::Normal)
|
, status_(Status::Normal)
|
||||||
, enabled_(true)
|
, enabled_(true)
|
||||||
|
|
@ -63,7 +63,7 @@ easy2d::Button::Button(Node * normal, const Function& func)
|
||||||
this->SetCallbackOnClick(func);
|
this->SetCallbackOnClick(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Button::Button(Node * normal, Node * selected, const Function& func)
|
easy2d::Button::Button(Node * normal, Node * selected, const Callback& func)
|
||||||
: callback_(nullptr)
|
: callback_(nullptr)
|
||||||
, status_(Status::Normal)
|
, status_(Status::Normal)
|
||||||
, enabled_(true)
|
, enabled_(true)
|
||||||
|
|
@ -78,7 +78,7 @@ easy2d::Button::Button(Node * normal, Node * selected, const Function& func)
|
||||||
this->SetCallbackOnClick(func);
|
this->SetCallbackOnClick(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func)
|
easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Callback& func)
|
||||||
: callback_(nullptr)
|
: callback_(nullptr)
|
||||||
, status_(Status::Normal)
|
, status_(Status::Normal)
|
||||||
, enabled_(true)
|
, enabled_(true)
|
||||||
|
|
@ -94,7 +94,7 @@ easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const F
|
||||||
this->SetCallbackOnClick(func);
|
this->SetCallbackOnClick(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func)
|
easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Callback& func)
|
||||||
: callback_(nullptr)
|
: callback_(nullptr)
|
||||||
, status_(Status::Normal)
|
, status_(Status::Normal)
|
||||||
, enabled_(true)
|
, enabled_(true)
|
||||||
|
|
@ -149,7 +149,7 @@ void easy2d::Button::SetEnabled(bool enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Button::SetCallbackOnClick(const Function& func)
|
void easy2d::Button::SetCallbackOnClick(const Callback& func)
|
||||||
{
|
{
|
||||||
callback_ = func;
|
callback_ = func;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -580,22 +580,24 @@ namespace easy2d
|
||||||
|
|
||||||
|
|
||||||
// 回调动作
|
// 回调动作
|
||||||
class Callback
|
class CallFunc
|
||||||
: public Action
|
: public Action
|
||||||
{
|
{
|
||||||
|
typedef std::function<void()> Callback;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Callback(
|
explicit CallFunc(
|
||||||
const Function& func /* 函数对象 */
|
const Callback& func /* 函数对象 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual Callback * Clone() const override;
|
virtual CallFunc * Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual Callback * Reverse() const override;
|
virtual CallFunc * Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
E2D_DISABLE_COPY(Callback);
|
E2D_DISABLE_COPY(CallFunc);
|
||||||
|
|
||||||
// 初始化动作
|
// 初始化动作
|
||||||
virtual void Init() override;
|
virtual void Init() override;
|
||||||
|
|
@ -604,7 +606,7 @@ namespace easy2d
|
||||||
virtual void Update() override;
|
virtual void Update() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Function callback_;
|
Callback callback_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,25 +30,27 @@ namespace easy2d
|
||||||
class Button
|
class Button
|
||||||
: public Node
|
: public Node
|
||||||
{
|
{
|
||||||
|
typedef std::function<void()> Callback;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Button();
|
Button();
|
||||||
|
|
||||||
explicit Button(
|
explicit Button(
|
||||||
Node * normal, /* 普通状态 */
|
Node * normal, /* 普通状态 */
|
||||||
const Function& func = nullptr /* 按钮点击后的回调函数 */
|
const Callback& func = nullptr /* 按钮点击后的回调函数 */
|
||||||
);
|
);
|
||||||
|
|
||||||
explicit Button(
|
explicit Button(
|
||||||
Node * normal, /* 普通状态 */
|
Node * normal, /* 普通状态 */
|
||||||
Node * selected, /* 鼠标按下状态 */
|
Node * selected, /* 鼠标按下状态 */
|
||||||
const Function& func = nullptr /* 按钮点击后的回调函数 */
|
const Callback& func = nullptr /* 按钮点击后的回调函数 */
|
||||||
);
|
);
|
||||||
|
|
||||||
explicit Button(
|
explicit Button(
|
||||||
Node * normal, /* 普通状态 */
|
Node * normal, /* 普通状态 */
|
||||||
Node * mouseover, /* 鼠标移入状态 */
|
Node * mouseover, /* 鼠标移入状态 */
|
||||||
Node * selected, /* 鼠标按下状态 */
|
Node * selected, /* 鼠标按下状态 */
|
||||||
const Function& func = nullptr /* 按钮点击后的回调函数 */
|
const Callback& func = nullptr /* 按钮点击后的回调函数 */
|
||||||
);
|
);
|
||||||
|
|
||||||
explicit Button(
|
explicit Button(
|
||||||
|
|
@ -56,7 +58,7 @@ namespace easy2d
|
||||||
Node * mouseover, /* 鼠标移入状态 */
|
Node * mouseover, /* 鼠标移入状态 */
|
||||||
Node * selected, /* 鼠标移入状态 */
|
Node * selected, /* 鼠标移入状态 */
|
||||||
Node * disabled, /* 按钮禁用状态 */
|
Node * disabled, /* 按钮禁用状态 */
|
||||||
const Function& func = nullptr /* 按钮点击后的回调函数 */
|
const Callback& func = nullptr /* 按钮点击后的回调函数 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取按钮状态是启用还是禁用
|
// 获取按钮状态是启用还是禁用
|
||||||
|
|
@ -89,7 +91,7 @@ namespace easy2d
|
||||||
|
|
||||||
// 设置按钮点击后的回调函数
|
// 设置按钮点击后的回调函数
|
||||||
void SetCallbackOnClick(
|
void SetCallbackOnClick(
|
||||||
const Function& func
|
const Callback& func
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置支点位置
|
// 设置支点位置
|
||||||
|
|
@ -130,7 +132,7 @@ namespace easy2d
|
||||||
bool enabled_;
|
bool enabled_;
|
||||||
bool is_selected_;
|
bool is_selected_;
|
||||||
Status status_;
|
Status status_;
|
||||||
Function callback_;
|
Callback callback_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,14 +201,16 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
friend class Node;
|
friend class Node;
|
||||||
|
|
||||||
|
typedef std::function<void()> Callback;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Task(
|
explicit Task(
|
||||||
const Function& func, /* 执行函数 */
|
const Callback& func, /* 执行函数 */
|
||||||
const std::wstring& name = L"" /* 任务名称 */
|
const std::wstring& name = L"" /* 任务名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
explicit Task(
|
explicit Task(
|
||||||
const Function& func, /* 执行函数 */
|
const Callback& func, /* 执行函数 */
|
||||||
float delay, /* 时间间隔(秒) */
|
float delay, /* 时间间隔(秒) */
|
||||||
int times = -1, /* 执行次数(设 -1 为永久执行) */
|
int times = -1, /* 执行次数(设 -1 为永久执行) */
|
||||||
const std::wstring& name = L"" /* 任务名称 */
|
const std::wstring& name = L"" /* 任务名称 */
|
||||||
|
|
@ -243,7 +245,7 @@ namespace easy2d
|
||||||
std::wstring name_;
|
std::wstring name_;
|
||||||
Duration delay_;
|
Duration delay_;
|
||||||
Time last_time_;
|
Time last_time_;
|
||||||
Function callback_;
|
Callback callback_;
|
||||||
Node * target_;
|
Node * target_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -336,41 +336,6 @@ namespace easy2d
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// º¯Êý¶ÔÏó
|
|
||||||
class Function
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Function();
|
|
||||||
|
|
||||||
Function(
|
|
||||||
std::nullptr_t
|
|
||||||
);
|
|
||||||
|
|
||||||
Function(
|
|
||||||
std::function<void()> func
|
|
||||||
);
|
|
||||||
|
|
||||||
template<typename Func>
|
|
||||||
Function(Func func)
|
|
||||||
: func_(func)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Func, typename Object>
|
|
||||||
Function(Func&& func, Object&& obj)
|
|
||||||
: func_(std::bind(func, obj))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator() (void) const;
|
|
||||||
|
|
||||||
E2D_OP_EXPLICIT operator bool() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::function<void()> func_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// 时间段
|
// 时间段
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
#include "..\e2dobject.h"
|
#include "..\e2dobject.h"
|
||||||
|
|
||||||
|
|
||||||
easy2d::Task::Task(const Function & func, const std::wstring & name)
|
easy2d::Task::Task(const Callback & func, const std::wstring & name)
|
||||||
: running_(true)
|
: running_(true)
|
||||||
, stopped_(false)
|
, stopped_(false)
|
||||||
, run_times_(0)
|
, run_times_(0)
|
||||||
|
|
@ -32,7 +32,7 @@ easy2d::Task::Task(const Function & func, const std::wstring & name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Task::Task(const Function & func, float delay, int times, const std::wstring & name)
|
easy2d::Task::Task(const Callback & func, float delay, int times, const std::wstring & name)
|
||||||
: running_(true)
|
: running_(true)
|
||||||
, stopped_(false)
|
, stopped_(false)
|
||||||
, run_times_(0)
|
, run_times_(0)
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
#include "..\e2dutil.h"
|
|
||||||
|
|
||||||
easy2d::Function::Function()
|
|
||||||
: func_(nullptr)
|
|
||||||
{}
|
|
||||||
|
|
||||||
easy2d::Function::Function(std::nullptr_t)
|
|
||||||
: func_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
easy2d::Function::Function(std::function<void()> func)
|
|
||||||
: func_(func)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void easy2d::Function::operator()(void) const
|
|
||||||
{
|
|
||||||
if (func_)
|
|
||||||
{
|
|
||||||
func_();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
easy2d::Function::operator bool() const
|
|
||||||
{
|
|
||||||
return static_cast<bool>(func_);
|
|
||||||
}
|
|
||||||
|
|
@ -70,7 +70,6 @@
|
||||||
<ClCompile Include="..\..\core\utils\Color.cpp" />
|
<ClCompile Include="..\..\core\utils\Color.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Duration.cpp" />
|
<ClCompile Include="..\..\core\utils\Duration.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Font.cpp" />
|
<ClCompile Include="..\..\core\utils\Font.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Function.cpp" />
|
|
||||||
<ClCompile Include="..\..\core\utils\Point.cpp" />
|
<ClCompile Include="..\..\core\utils\Point.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Random.cpp" />
|
<ClCompile Include="..\..\core\utils\Random.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Rect.cpp" />
|
<ClCompile Include="..\..\core\utils\Rect.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,6 @@
|
||||||
<ClCompile Include="..\..\core\utils\Font.cpp">
|
<ClCompile Include="..\..\core\utils\Font.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\core\utils\Function.cpp">
|
|
||||||
<Filter>utils</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\core\utils\Point.cpp">
|
<ClCompile Include="..\..\core\utils\Point.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,6 @@
|
||||||
<ClCompile Include="..\..\core\utils\Color.cpp" />
|
<ClCompile Include="..\..\core\utils\Color.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Duration.cpp" />
|
<ClCompile Include="..\..\core\utils\Duration.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Font.cpp" />
|
<ClCompile Include="..\..\core\utils\Font.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Function.cpp" />
|
|
||||||
<ClCompile Include="..\..\core\utils\Point.cpp" />
|
<ClCompile Include="..\..\core\utils\Point.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Random.cpp" />
|
<ClCompile Include="..\..\core\utils\Random.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Rect.cpp" />
|
<ClCompile Include="..\..\core\utils\Rect.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,6 @@
|
||||||
<ClCompile Include="..\..\core\utils\Font.cpp">
|
<ClCompile Include="..\..\core\utils\Font.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\core\utils\Function.cpp">
|
|
||||||
<Filter>utils</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\core\utils\Point.cpp">
|
<ClCompile Include="..\..\core\utils\Point.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,6 @@
|
||||||
<ClCompile Include="..\..\core\utils\Color.cpp" />
|
<ClCompile Include="..\..\core\utils\Color.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Duration.cpp" />
|
<ClCompile Include="..\..\core\utils\Duration.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Font.cpp" />
|
<ClCompile Include="..\..\core\utils\Font.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Function.cpp" />
|
|
||||||
<ClCompile Include="..\..\core\utils\Point.cpp" />
|
<ClCompile Include="..\..\core\utils\Point.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Random.cpp" />
|
<ClCompile Include="..\..\core\utils\Random.cpp" />
|
||||||
<ClCompile Include="..\..\core\utils\Rect.cpp" />
|
<ClCompile Include="..\..\core\utils\Rect.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,6 @@
|
||||||
<ClCompile Include="..\..\core\utils\Font.cpp">
|
<ClCompile Include="..\..\core\utils\Font.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\core\utils\Function.cpp">
|
|
||||||
<Filter>utils</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\core\utils\Point.cpp">
|
<ClCompile Include="..\..\core\utils\Point.cpp">
|
||||||
<Filter>utils</Filter>
|
<Filter>utils</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue