Fixed Buttons, Added Button events, Added Toggle Buttons, Added Sliders(WIP no graphics), Rework backend #308

Merged
maverickdgg merged 13 commits from SP3-20-UI-System into main 2023-01-16 14:11:51 +08:00
4 changed files with 41 additions and 19 deletions
Showing only changes of commit b293b28a56 - Show all commits

View File

@ -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

View File

@ -1,3 +1,3 @@
Name: UI Test
ID: 87707373
ID: 92351881
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 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<SHEditorViewport>()->windowSize;
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->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<SHRenderable>(comp.GetEID()))
{
//auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
auto texture = SHResourceManager::Get<SHTexture>(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<SHCameraSystem>();
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) };
result.y *= -1.0f;
result += camSize * 0.5f;
return result;
}
}//end namespace

View File

@ -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;
};