-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIGui.cpp
More file actions
64 lines (50 loc) · 1.58 KB
/
IGui.cpp
File metadata and controls
64 lines (50 loc) · 1.58 KB
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
//Incomplete
#include "stdafx.h"
#include "IGui.h"
#include "ServiceLocator.h"
IGui::IGui(sf::Image* img, sf::Vector2f loc): location(loc)
{
image = img;
sprite.SetImage(*image);
sprite.SetCenter(image->GetWidth() / 2.0f, image->GetHeight() / 2.0f);
sprite.SetPosition(location);
boundingBox = sf::Rect<int>(location.x - image->GetWidth() / 2.0f, location.y - image->GetHeight() / 2.0f, location.x + image->GetWidth() / 2.0f, location.y + image->GetHeight() / 2.0f);
id = s_id;
s_id++;
}
IGui::~IGui()
{}
//TODO figure out if this works - Make this make more sense
void IGui::ChangeImage(sf::Image* newImage)
{
image = newImage;
sprite.SetImage(*(this->image));
sprite.SetCenter(this->image->GetWidth() / 2.0f, this->image->GetHeight() / 2.0f);
//redundant with below
sf::Vector2f location = sprite.GetPosition();
location.x -= image->GetWidth() / 2.0f;
location.y -= image->GetHeight() / 2.0f;
boundingBox = sf::Rect<int>(static_cast<int>(location.x),
static_cast<int>(location.y),
static_cast<int>(location.x + image->GetWidth()),
static_cast<int>(location.y + image->GetHeight()));
//redudant with above
location.x += image->GetWidth() / 2.0f;
location.y += image->GetHeight() / 2.0f;
}
void IGui::Draw(sf::RenderWindow& window)
{
window.Draw(sprite);
}
bool IGui::IsClicked(sf::Vector2f mouse)
{
if (boundingBox.Contains(static_cast<int>(location.x), static_cast<int>(location.y)))
return true;
else
return false;
}
int IGui::GetId()
{
return id;
}
int IGui::s_id = 0;