Fix for Canvas Scaler #253

Merged
maverickdgg merged 2 commits from SP3-20-UI-System into main 2022-11-22 21:06:25 +08:00
5 changed files with 33 additions and 21 deletions
Showing only changes of commit 7c36886669 - Show all commits

View File

@ -22,6 +22,11 @@
Mesh: 141771688
Material: 129340704
IsActive: true
Button Component:
Default Texture: 0
Hovered Texture: 0
Clicked Texture: 0
IsActive: true
Scripts: ~
- EID: 1
Name: Camera

View File

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

View File

@ -8,6 +8,8 @@
#include "Math/Transform/SHTransformComponent.h"
#include <math.h>
#include "Scene/SHSceneManager.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Editor/SHEditor.h"
namespace SHADE
{
@ -440,4 +442,22 @@ namespace SHADE
SetCameraViewMatrix(camera, viewMtx);
}
SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept
{
#ifdef SHEDITOR
auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor->editorState != SHEditor::State::PLAY)
{
return SHVec2{ GetEditorCamera()->GetWidth(), GetEditorCamera()->GetHeight() };
}
else
{
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
}
#else
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
#endif
}
}

View File

@ -29,6 +29,7 @@ namespace SHADE
void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept;
public:
SHCameraSystem(void) = default;
virtual ~SHCameraSystem(void) = default;
@ -57,6 +58,8 @@ namespace SHADE
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept;
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;
SHVec2 GetCameraWidthHeight(size_t index) noexcept;
};

View File

@ -119,26 +119,10 @@ namespace SHADE
void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept
{
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
#ifdef SHEDITOR
auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor->editorState != SHEditor::State::PLAY)
{
SHVec2 camSize = cameraSystem->GetCameraWidthHeight(0);
comp.canvasMatrix = SHMatrix::Identity;
comp.canvasMatrix(0, 0) = cameraSystem->GetEditorCamera()->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f);
comp.canvasMatrix(1, 1) = cameraSystem->GetEditorCamera()->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f);
}
else
{
comp.canvasMatrix = SHMatrix::Identity;
comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f);
comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f);
}
#else
comp.canvasMatrix = SHMatrix::Identity;
comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f );
comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f );
#endif
comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f);
comp.canvasMatrix(1, 1) = camSize.y * 0.5f / (comp.GetCanvasHeight() * 0.5f);
}
void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept
@ -183,7 +167,7 @@ namespace SHADE
SHVec2 camSize{ cameraSystem->GetDirector(0)->GetWidth() , cameraSystem->GetDirector(0)->GetHeight() };
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y };
topExtent += camSize * 0.5f;
btmExtent += camSize * 0.5f;