120 lines
2.6 KiB
C++
120 lines
2.6 KiB
C++
|
|
#include "SquirrelButton.h"
|
|||
|
|
#include "SquirrelClassEx.h"
|
|||
|
|
|
|||
|
|
|
|||
|
|
void SquirrelButton::OnClick(Event* evt) {
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>̬<EFBFBD><CCAC><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ж<EFBFBD> ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>̬ͣ
|
|||
|
|
if (this->MyState != 3)return;
|
|||
|
|
auto mouse_evt = dynamic_cast<MouseClickEvent*>(evt);
|
|||
|
|
if (mouse_evt->button == MouseButton::Left)
|
|||
|
|
{
|
|||
|
|
SquirrelClassEx::RunUpdateScript("ButtonUpdateCallBack", this->GetObjectID(), 10);
|
|||
|
|
}
|
|||
|
|
else if (mouse_evt->button == MouseButton::Right)
|
|||
|
|
{
|
|||
|
|
SquirrelClassEx::RunUpdateScript("ButtonUpdateCallBack", this->GetObjectID(), 11);
|
|||
|
|
}
|
|||
|
|
else if (mouse_evt->button == MouseButton::Middle)
|
|||
|
|
{
|
|||
|
|
SquirrelClassEx::RunUpdateScript("ButtonUpdateCallBack", this->GetObjectID(), 12);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelButton::OnHover() {
|
|||
|
|
//<2F><><EFBFBD>봦<EFBFBD><EBB4A6><EFBFBD><EFBFBD>̬ͨʱ<CCAC>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬ͣ<CDA3><CCAC><EFBFBD><EFBFBD>
|
|||
|
|
if (this->MyState == 0) {
|
|||
|
|
SetState(2);
|
|||
|
|
//this->_is_Hover = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelButton::OnOut() {
|
|||
|
|
if (this->MyState == 1)return;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD><DAB0><EFBFBD>̬ <20><>ôҲ<C3B4><D2B2>Ҫ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>һ<EFBFBD><D2BB>OnUp
|
|||
|
|
if (this->MyState == 3) {
|
|||
|
|
SetState(2);
|
|||
|
|
this->SetPositionY(this->GetPositionY() - 1);
|
|||
|
|
}
|
|||
|
|
SetState(0);
|
|||
|
|
//this->_is_Hover = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelButton::OnDown(Event* evt) {
|
|||
|
|
if (this->MyState == 1)return;
|
|||
|
|
if (this->MyState == 2) {
|
|||
|
|
SetState(3);
|
|||
|
|
this->SetPositionY(this->GetPositionY() + 1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelButton::OnUp(Event* evt) {
|
|||
|
|
if (this->MyState == 1)return;
|
|||
|
|
if (this->MyState == 3) {
|
|||
|
|
SetState(2);
|
|||
|
|
this->SetPositionY(this->GetPositionY() - 1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool SquirrelButton::IsPress(const int Type)
|
|||
|
|
{
|
|||
|
|
switch (Type)
|
|||
|
|
{
|
|||
|
|
case 0: {
|
|||
|
|
if (this->_is_Left_Press) {
|
|||
|
|
this->_is_Left_Press = false;
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 1: {
|
|||
|
|
if (this->_is_Right_Press) {
|
|||
|
|
this->_is_Right_Press = false;
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 2: {
|
|||
|
|
if (this->_is_Middle_Press) {
|
|||
|
|
this->_is_Middle_Press = false;
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool SquirrelButton::IsHover()
|
|||
|
|
{
|
|||
|
|
return this->_is_Hover;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelButton::SetState(const int state)
|
|||
|
|
{
|
|||
|
|
this->MyState = state;
|
|||
|
|
SquirrelClassEx::RunUpdateScript("ButtonUpdateCallBack", this->GetObjectID(), state);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelButton::Init()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD>Init <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD><C5BF>Գɹ<D4B3>ע<EFBFBD><D7A2>UI<55><49>
|
|||
|
|
this->UiFrameWork::Init();
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD><EFBFBD>Init<69><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>װ<EFBFBD><D7B0> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>źŵĴ<C5B5><C4B4><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
AddListener<MouseClickEvent>(Closure(this, &SquirrelButton::OnClick));
|
|||
|
|
AddListener<MouseDownEvent>(Closure(this, &SquirrelButton::OnDown));
|
|||
|
|
AddListener<MouseUpEvent>(Closure(this, &SquirrelButton::OnUp));
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelButton::OnUpdate(Duration dt) {
|
|||
|
|
//SquirrelClassEx::RunUpdateScript("ButtonUpdateCallBack", this->GetObjectID(), this->MyState);
|
|||
|
|
}
|