|
|
|
@ -146,25 +146,10 @@ namespace SHADE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SHUISystem::CheckButtonHoveredOrClicked(EntityID eid, SHVec2 topExtent, SHVec2 btmExtent, bool& isHovered, bool& isClicked) noexcept
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept
|
|
|
|
|
{
|
|
|
|
|
if (!SHComponentManager::HasComponent<SHUIComponent>(comp.GetEID()))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
|
|
|
|
auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID());
|
|
|
|
|
//auto canvasComp = SHComponentManager::GetComponent_s<SHCanvasComponent>(uiComp->canvasID);
|
|
|
|
|
|
|
|
|
|
SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SHVec2 topExtent{ topExtent4.x,topExtent4.y };
|
|
|
|
|
SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SHVec2 mousePos;
|
|
|
|
|
SHVec2 windowSize;
|
|
|
|
|
#ifdef SHEDITOR
|
|
|
|
@ -200,19 +185,34 @@ namespace SHADE
|
|
|
|
|
if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x
|
|
|
|
|
&& mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y)
|
|
|
|
|
{
|
|
|
|
|
comp.isHovered = true;
|
|
|
|
|
if (isHovered == false)
|
|
|
|
|
{
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = eid;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_ENTER_EVENT);
|
|
|
|
|
}
|
|
|
|
|
isHovered = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SHEDITOR
|
|
|
|
|
//if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY)
|
|
|
|
|
{
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
isClicked = true;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = eid;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = eid;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -220,17 +220,51 @@ namespace SHADE
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
comp.isHovered = false;
|
|
|
|
|
if (isHovered == true)
|
|
|
|
|
{
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = eid;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_EXIT_EVENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isHovered = false;
|
|
|
|
|
//SHLOG_INFO("NOT HOVERED")
|
|
|
|
|
}
|
|
|
|
|
if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
if (isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = false;
|
|
|
|
|
isClicked = false;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
clickEvent.EID = eid;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_RELEASE_EVENT);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept
|
|
|
|
|
{
|
|
|
|
|
if (!SHComponentManager::HasComponent<SHUIComponent>(comp.GetEID()))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
|
|
|
|
auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID());
|
|
|
|
|
//auto canvasComp = SHComponentManager::GetComponent_s<SHCanvasComponent>(uiComp->canvasID);
|
|
|
|
|
|
|
|
|
|
SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SHVec2 topExtent{ topExtent4.x,topExtent4.y };
|
|
|
|
|
SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y };
|
|
|
|
|
|
|
|
|
|
CheckButtonHoveredOrClicked(comp.GetEID(), topExtent, btmExtent, comp.isHovered, comp.isClicked);
|
|
|
|
|
|
|
|
|
|
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
|
|
|
|
|
{
|
|
|
|
|
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
|
|
|
@ -295,73 +329,8 @@ namespace SHADE
|
|
|
|
|
SHVec2 topExtent{ topExtent4.x,topExtent4.y };
|
|
|
|
|
SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SHVec2 mousePos;
|
|
|
|
|
SHVec2 windowSize;
|
|
|
|
|
#ifdef SHEDITOR
|
|
|
|
|
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
|
|
|
|
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
|
|
|
|
//mousePos.y = windowSize.y - mousePos.y;
|
|
|
|
|
//SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
mousePos /= windowSize;
|
|
|
|
|
//SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
|
SHInputManager::GetMouseScreenPosition(&x, &y);
|
|
|
|
|
mousePos.x = x;
|
|
|
|
|
mousePos.y = y;
|
|
|
|
|
auto ws = SHSystemManager::GetSystem<SHGraphicsSystem>()->GetWindow()->GetWindowSize();
|
|
|
|
|
windowSize = { static_cast<float>(ws.first), static_cast<float>(ws.second) };
|
|
|
|
|
mousePos /= windowSize;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) };
|
|
|
|
|
//SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y)
|
|
|
|
|
|
|
|
|
|
topExtent = CanvasToScreenPoint(topExtent, true);
|
|
|
|
|
btmExtent = CanvasToScreenPoint(btmExtent, true);
|
|
|
|
|
//SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//comp.isClicked = false;
|
|
|
|
|
if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x
|
|
|
|
|
&& mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y)
|
|
|
|
|
{
|
|
|
|
|
comp.isHovered = true;
|
|
|
|
|
#ifdef SHEDITOR
|
|
|
|
|
//if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY)
|
|
|
|
|
{
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//SHLOG_INFO("HOVERED")
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
comp.isHovered = false;
|
|
|
|
|
//SHLOG_INFO("NOT HOVERED")
|
|
|
|
|
}
|
|
|
|
|
if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = false;
|
|
|
|
|
if (CheckButtonHoveredOrClicked(comp.GetEID(), topExtent, btmExtent, comp.isHovered, comp.isClicked))
|
|
|
|
|
comp.value = !comp.value;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
|
|
|
|
|
{
|
|
|
|
|