Added 3 button event. Changed hovered and clicked boolean to be stored in UIComponent instead. Fixed Canvas Scaling matrix. #356

Merged
maverickdgg merged 3 commits from SP3-20-UI-System into main 2023-02-21 15:49:28 +08:00
4 changed files with 31 additions and 6 deletions
Showing only changes of commit a3112f9c60 - Show all commits

View File

@ -6,6 +6,7 @@
Canvas Component:
Canvas Width: 1920
Canvas Height: 1080
Scale by canvas width: false
IsActive: true
Scripts: ~
- EID: 1
@ -24,6 +25,8 @@
IsActive: true
UI Component:
Canvas ID: 0
Hovered: false
Clicked: false
IsActive: true
Scripts: ~
- EID: 5
@ -47,6 +50,8 @@
IsActive: true
UI Component:
Canvas ID: 0
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: ChangeSceneButton
@ -73,6 +78,8 @@
IsActive: true
UI Component:
Canvas ID: 0
Hovered: false
Clicked: false
IsActive: true
Scripts:
- Type: QuitButton
@ -106,11 +113,12 @@
Pitch: 0
Yaw: 0
Roll: 0
Width: 1920
Height: 1080
Width: 1319
Height: 622
Near: 0.00999999978
Far: 10000
Perspective: true
FOV: 90
IsActive: true
Scripts: ~
- EID: 4

View File

@ -6,7 +6,7 @@ namespace SHADE
{
SHCanvasComponent::SHCanvasComponent()
:width(1),height(1), dirtyMatrix(false), canvasMatrix()
:width(1), height(1), dirtyMatrix(false), canvasMatrix(), scaleByCanvasWidth(false)
{
}
@ -27,6 +27,8 @@ namespace SHADE
height = val;
}
SHCanvasComponent::CanvasSizeType SHCanvasComponent::GetCanvasWidth() const noexcept
{
@ -43,6 +45,8 @@ namespace SHADE
return canvasMatrix;
}
}
@ -54,6 +58,7 @@ RTTR_REGISTRATION
registration::class_<SHCanvasComponent>("Canvas Component")
.property("Canvas Width", &SHCanvasComponent::GetCanvasWidth, &SHCanvasComponent::SetCanvasWidth)
.property("Canvas Height", &SHCanvasComponent::GetCanvasHeight, &SHCanvasComponent::SetCanvasHeight)
.property("Scale by canvas width", &SHCanvasComponent::scaleByCanvasWidth)
;

View File

@ -21,21 +21,24 @@ namespace SHADE
SHCanvasComponent();
~SHCanvasComponent() = default;
bool scaleByCanvasWidth;
void SetCanvasSize(CanvasSizeType width, CanvasSizeType height) noexcept;
void SetCanvasWidth(CanvasSizeType width) noexcept;
void SetCanvasHeight(CanvasSizeType height) noexcept;
CanvasSizeType GetCanvasWidth() const noexcept;
CanvasSizeType GetCanvasHeight() const noexcept;
SHMatrix const& GetMatrix() const noexcept;
private:
CanvasSizeType width;
CanvasSizeType height;
bool dirtyMatrix;
SHMatrix canvasMatrix;
RTTR_ENABLE()
};

View File

@ -131,8 +131,17 @@ namespace SHADE
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
SHVec2 camSize = cameraSystem->GetCameraWidthHeight(0);
comp.canvasMatrix = SHMatrix::Identity;
comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f);
comp.canvasMatrix(1, 1) = camSize.y * 0.5f / (comp.GetCanvasHeight() * 0.5f);
float scale = camSize.y / comp.GetCanvasHeight();
if (comp.scaleByCanvasWidth)
{
scale = camSize.x / comp.GetCanvasWidth();
}
comp.canvasMatrix(0, 0) = scale;
comp.canvasMatrix(1, 1) = scale;
//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