-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCursorSystem.cpp
88 lines (69 loc) · 1.74 KB
/
CursorSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "pch.h"
#include "CursorSystem.h"
#include "VisPredComponents.h"
CursorSystem::CursorSystem(std::shared_ptr<SceneManager> scenemanager) :System(scenemanager)
{
}
void CursorSystem::Initialize()
{
COMPLOOP(CursorComponent, comp)
{
Start(comp.GetEntityID());
}
}
void CursorSystem::Start(uint32_t gameObjectId)
{
auto entity = GetSceneManager()->GetEntity(gameObjectId);
if (!entity->HasComponent<CursorComponent>())
return;
auto cursor = entity->GetComponent<CursorComponent>();
cursor->preIsCursor = cursor->ShowCursor;
auto image = entity->GetComponent<ImageComponent>();
if (cursor->ShowCursor)
{
image->TexturePath = cursor->CursorImage;
image->Scale = cursor->CursorScale;
SetImagePos(image);
image->Color.w = 1;
}
else
{
image->TexturePath = cursor->CursorImage;
image->Scale = cursor->CursorScale;
SetImagePos(image);
image->Color.w = 0;
}
}
void CursorSystem::Finish(uint32_t gameObjectId)
{
}
void CursorSystem::Finalize()
{
}
void CursorSystem::SetImagePos(ImageComponent* image)
{
VPMath::Vector2 clientsize = InputManager::GetInstance().GetClientSize();
int x =InputManager::GetInstance().GetMouseX();
int y = InputManager::GetInstance().GetMouseY();
image->PosXPercent = (x / clientsize.x)*100;
image->PosYPercent = (y / clientsize.y) * 100;
}
void CursorSystem::FixedUpdate(float deltaTime)
{
COMPLOOP(CursorComponent, cursor)
{
if (!cursor.HasComponent<ImageComponent>())
continue;
auto cursorimage = cursor.GetComponent<ImageComponent>();
if (cursor.ShowCursor != cursor.preIsCursor)
{
if (cursor.ShowCursor)
cursorimage->Color.w = 1;
else
cursorimage->Color.w = 0;
cursor.preIsCursor = cursor.ShowCursor;
}
if (cursor.ShowCursor)
SetImagePos(cursorimage);
}
}