forked from pawelplodzpl/PG2D_2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.h
134 lines (107 loc) · 3.08 KB
/
Button.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#pragma once
#include <wrl.h>
//#include "..\Common\DirectXHelper.h" // For ThrowIfaFailed and ReadDataAsync
#include <Content\AnimatedTexture.h>
#include <SpriteBatch.h>
#include <DirectXMath.h>
#include <DirectXTK\Inc\SimpleMath.h>
#include "SpriteFont.h"
class Button
{
public:
Button(ID3D11ShaderResourceView* playerSpriteSheet, SpriteFont *spriteFont, std::wstring inString, XMFLOAT2 inPosition) : framesOfAnimation(4), framesToBeShownPerSecond(4)
{
string = inString;
position = inPosition;
//Instantiate animation here
texture = playerSpriteSheet;
float rotation = 0.f;
float scale = 3.f;
animation.reset(new AnimatedTexture(DirectX::XMFLOAT2(0.f, 0.f), rotation, scale, 0.5f));
animation->Load(texture.Get(), framesOfAnimation, framesToBeShownPerSecond);
m_font.reset(spriteFont);
width = textureWidth = animation->getFrameWidth();
height = textureHeight = animation->getFrameHeight();
rectangle.X = position.x;
rectangle.Y = position.y;
rectangle.Height = height;
rectangle.Width = width;
}
Button(ID3D11ShaderResourceView* playerSpriteSheet, SpriteFont *spriteFont) : framesOfAnimation(4), framesToBeShownPerSecond(4)
{
//Instantiate animation here
texture = playerSpriteSheet;
float rotation = 0.f;
float scale = 3.f;
animation.reset(new AnimatedTexture(DirectX::XMFLOAT2(0.f, 0.f), rotation, scale, 0.5f));
animation->Load(texture.Get(), framesOfAnimation, framesToBeShownPerSecond);
m_font.reset(spriteFont);
width = textureWidth = animation->getFrameWidth();
height = textureHeight = animation->getFrameHeight();
rectangle.X = position.x;
rectangle.Y = position.y;
rectangle.Height = height;
rectangle.Width = width;
}
void setPosition(DirectX::XMFLOAT2 newPosition)
{
//set the position
position = newPosition;
updateBoundingRect();
}
void setPosition(float posX, float posY)
{
position.x = posX;
position.y = posY;
updateBoundingRect();
}
DirectX::XMFLOAT2 getPosition()
{
return position;
}
void Update(float elapsed)
{
//update the animation of the player
animation->Update(elapsed);
}
void Draw(DirectX::SpriteBatch* batch)
{
animation->Draw(batch, position);
m_font->DrawString(batch, string.c_str(), position, Colors::Black);
}
void setString(std::wstring in)
{
string = in;
}
std::wstring getString()
{
return string;
}
public:
Windows::Foundation::Rect rectangle;
private:
void updateBoundingRect()
{
//TODO: proper updating when rotating player object
rectangle.X = position.x;
rectangle.Y = position.y;
rectangle.Height = height;
rectangle.Width = width;
}
Windows::Foundation::Rect getBoundingRect()
{
return rectangle;
}
DirectX::XMFLOAT2 position;
int width;
int height;
int textureWidth;
int textureHeight;
int framesOfAnimation;
int framesToBeShownPerSecond;
//Texture and animation
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> texture;
std::unique_ptr<AnimatedTexture> animation;
std::wstring string;
std::unique_ptr<DirectX::SpriteFont> m_font;
};