diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index c9b34a7a..bc619d3b 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 94246101 +Starting Scene ID: 93618245 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index cf38916e..f64d5657 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 87707373 +ID: 92351881 Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 1387bc6b..00aa0cda 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -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 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 btmExtent{ btmExtent4.x,-btmExtent4.y }; - + SHVec2 topExtent{ topExtent4.x,topExtent4.y }; + SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; + //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y); SHVec2 windowSize; @@ -160,23 +160,24 @@ namespace SHADE windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; - - - + //SHLOG_INFO("MousePos: {}, {}", mousePos.x, mousePos.y); + //mousePos /= windowSize; #endif - SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y }; + SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)}; - topExtent += camSize * 0.5f; - btmExtent += camSize * 0.5f; + topExtent = CanvasToScreenPoint(topExtent); + btmExtent = CanvasToScreenPoint(btmExtent); - //Convert everything to using ratios - topExtent /= camSize; - btmExtent /= camSize; + //SHLOG_INFO("TopExtent Screen Point: {}, {}, Cam size: {}, {}", topExtent.x, topExtent.y, camSize.x, camSize.y); - mousePos /= windowSize; + //Convert everything to using ratios + //topExtent /= camSize; + //btmExtent /= camSize; + + //SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y); comp.isClicked = false; @@ -187,6 +188,7 @@ namespace SHADE if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { comp.isClicked = true; + //SHLOG_INFO("BUTTON CLICKED"); } //SHLOG_INFO("BUTTON HOVERED"); @@ -202,11 +204,11 @@ namespace SHADE if (SHComponentManager::HasComponent(comp.GetEID())) { - //auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); - //auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); + auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); - //auto material = renderable->GetModifiableMaterial(); - //material->SetProperty("texture", comp.GetDefaultTexture()); + auto material = renderable->GetModifiableMaterial(); + 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(); + + SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) }; + + + result.y *= -1.0f; + result += camSize * 0.5f; + + return result; + } + + + + }//end namespace diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 04e057ad..21518f16 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -65,6 +65,8 @@ namespace SHADE void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept; void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; + SHVec2 CanvasToScreenPoint(SHVec2& const canvasPoint) noexcept; + };