-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextButton.h
More file actions
80 lines (70 loc) · 1.69 KB
/
Copy pathTextButton.h
File metadata and controls
80 lines (70 loc) · 1.69 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include <wrl.h>
#include <Content\AnimatedTexture.h>
#include <SpriteBatch.h>
#include <DirectXMath.h>
#include <DirectXTK\Inc\SimpleMath.h>
#include "SpriteFont.h"
#include "DrawableObject.h"
class TextButton : public DrawableObject
{
public:
TextButton(ID3D11ShaderResourceView* buttonSpriteSheet, std::shared_ptr<DirectX::SpriteFont> spriteFont,
std::wstring inString, std::wstring inId, XMFLOAT2 inPosition, float scaleX, float scaleY) :
DrawableObject(buttonSpriteSheet, inPosition, scaleX, scaleY)
{
this->id = inId;
this->string = inString;
this->colorNormal = this->color = Colors::Black;
this->colorOver = Colors::Blue;
this->m_font = spriteFont;
centerHorizontally();
updateBoundingRect();
}
bool isOver(Windows::Foundation::Rect rect)
{
if (this->boundingRectangle.IntersectsWith(rect))
{
this->color = this->colorOver;
return true;
}
else
{
this->color = this->colorNormal;
return false;
}
}
void Draw(DirectX::SpriteBatch* batch)
{
DrawableObject::Draw(batch);
m_font->DrawString(batch, string.c_str(), XMFLOAT2(position.x + 16 * scale.x, position.y + 4 * scale.y), color);
}
void setString(std::wstring string)
{
this->string = string;
}
std::wstring getString()
{
return this->string;
}
void setId(std::wstring string)
{
this->id = string;
}
std::wstring getId()
{
return this->id;
}
private:
void centerHorizontally()
{
position.x -= (float) (dimensions.x / 2.);
position.y -= (float) (dimensions.y / 2.);
}
std::wstring id;
std::wstring string;
DirectX::XMVECTOR color;
DirectX::XMVECTOR colorNormal;
DirectX::XMVECTOR colorOver;
std::shared_ptr<DirectX::SpriteFont> m_font;
};