Button fix

This commit is contained in:
maverickdgg 2023-01-09 07:14:40 +08:00
parent 44733308f1
commit b293b28a56
4 changed files with 41 additions and 19 deletions

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false Start in Fullscreen: false
Starting Scene ID: 94246101 Starting Scene ID: 93618245
Window Size: {x: 1920, y: 1080} Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine Window Title: SHADE Engine

View File

@ -1,3 +1,3 @@
Name: UI Test Name: UI Test
ID: 87707373 ID: 92351881
Type: 5 Type: 5

View File

@ -149,9 +149,9 @@ namespace SHADE
SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f); SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f);
SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f); SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f);
SHVec2 topExtent{ topExtent4.x,-topExtent4.y }; SHVec2 topExtent{ topExtent4.x,topExtent4.y };
SHVec2 btmExtent{ btmExtent4.x,-btmExtent4.y }; SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y };
//SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y);
SHVec2 windowSize; SHVec2 windowSize;
@ -160,23 +160,24 @@ namespace SHADE
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->windowSize; windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->windowSize;
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos; mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
//SHLOG_INFO("MousePos: {}, {}", mousePos.x, mousePos.y);
//mousePos /= windowSize;
#endif #endif
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y }; SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)};
topExtent += camSize * 0.5f; topExtent = CanvasToScreenPoint(topExtent);
btmExtent += camSize * 0.5f; btmExtent = CanvasToScreenPoint(btmExtent);
//SHLOG_INFO("TopExtent Screen Point: {}, {}, Cam size: {}, {}", topExtent.x, topExtent.y, camSize.x, camSize.y);
//Convert everything to using ratios //Convert everything to using ratios
topExtent /= camSize; //topExtent /= camSize;
btmExtent /= camSize; //btmExtent /= camSize;
mousePos /= windowSize;
//SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y); //SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y);
comp.isClicked = false; comp.isClicked = false;
@ -187,6 +188,7 @@ namespace SHADE
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
{ {
comp.isClicked = true; comp.isClicked = true;
//SHLOG_INFO("BUTTON CLICKED");
} }
//SHLOG_INFO("BUTTON HOVERED"); //SHLOG_INFO("BUTTON HOVERED");
@ -202,11 +204,11 @@ namespace SHADE
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID())) if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
{ {
//auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID()); auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture()); auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
//auto material = renderable->GetModifiableMaterial(); auto material = renderable->GetModifiableMaterial();
//material->SetProperty("texture", comp.GetDefaultTexture()); material->SetProperty("texture", comp.GetDefaultTexture());
} }
} }
@ -221,4 +223,22 @@ namespace SHADE
} }
} }
SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept
{
SHVec2 result{canvasPoint};
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) };
result.y *= -1.0f;
result += camSize * 0.5f;
return result;
}
}//end namespace }//end namespace

View File

@ -65,6 +65,8 @@ namespace SHADE
void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateUIComponent(SHUIComponent& comp) noexcept;
void UpdateButtonComponent(SHButtonComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept;
void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept;
SHVec2 CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept;
}; };