-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageInfo.cpp
More file actions
138 lines (114 loc) · 4.44 KB
/
ImageInfo.cpp
File metadata and controls
138 lines (114 loc) · 4.44 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
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
135
136
137
138
#include "stdafx.h"
#include "ImageInfo.h"
ImageInfo::ImageInfo(){
ii_type = INTERFACE_ITEM_TYPE::IMAGE_INFO;
shape.setFillColor(Color(0, 0, 0, 0));
}
ImageInfo::ImageInfo(float x, float y, string text_, int text_size, Font* font,
TextureManager* t_manager, int index, string name){
ii_type = INTERFACE_ITEM_TYPE::IMAGE_INFO;
shape.setFillColor(Color(0, 0, 0, 0));
position.x = x;
position.y = y;
src_img.setTexture(t_manager->getTexture(index, name));
shape.setPosition(position);
text.setFont(*font);
text.setString(text_);
text.setFillColor(Color::White);
text.setCharacterSize(text_size);
src_img.setScale(
(text.getGlobalBounds().height * 2) / src_img.getGlobalBounds().height,
(text.getGlobalBounds().height * 2) / src_img.getGlobalBounds().height
);
shape.setSize(Vector2f(
src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 + text.getGlobalBounds().width,
text.getGlobalBounds().height * 2)
);
src_img.setPosition(shape.getPosition());
text.setPosition(
position.x + src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 - text.getLocalBounds().left,
position.y + text.getLocalBounds().height / 2 - text.getLocalBounds().top
);
}
ImageInfo::ImageInfo(float x, float y, int text_, int text_size, Font* font, TextureManager* t_manager, int index, string name){
ii_type = INTERFACE_ITEM_TYPE::IMAGE_INFO;
shape.setFillColor(Color(0, 0, 0, 0));
position.x = x;
position.y = y;
src_img.setTexture(t_manager->getTexture(index, name));
shape.setPosition(position);
text.setFont(*font);
text.setString(std::to_string(text_));
text.setFillColor(Color::White);
text.setCharacterSize(text_size);
src_img.setScale(
(text.getGlobalBounds().height * 2) / src_img.getGlobalBounds().height,
(text.getGlobalBounds().height * 2) / src_img.getGlobalBounds().height
);
shape.setSize(Vector2f(
src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 + text.getGlobalBounds().width,
text.getGlobalBounds().height * 2)
);
src_img.setPosition(shape.getPosition());
text.setPosition(
position.x + src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 - text.getLocalBounds().left,
position.y + text.getLocalBounds().height / 2 - text.getLocalBounds().top
);
}
FloatRect ImageInfo::getLocalBounds(){
return shape.getLocalBounds();
}
FloatRect ImageInfo::getGlobalBounds(){
return shape.getGlobalBounds();
}
void ImageInfo::setPosition(Vector2f new_position){
position = new_position;
shape.setPosition(position);
src_img.setPosition(position);
text.setPosition(
position.x + src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 - text.getLocalBounds().left,
position.y + text.getLocalBounds().height / 2 - text.getLocalBounds().top
);
}
void ImageInfo::setPositionX(float x){
setPosition(Vector2f(x + shape.getOutlineThickness(), position.y));
}
void ImageInfo::setPositionY(float y){
setPosition(Vector2f(position.x, y + shape.getOutlineThickness()));
}
void ImageInfo::setText(float text_){
text.setString(std::to_string(static_cast<int>(text_)));
shape.setSize(Vector2f(
src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 + text.getGlobalBounds().width,
text.getGlobalBounds().height * 2)
);
src_img.setPosition(shape.getPosition());
text.setPosition(
position.x + src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 - text.getLocalBounds().left,
position.y + text.getLocalBounds().height / 2 - text.getLocalBounds().top
);
}
void ImageInfo::setBackgroundColor(Color color){
shape.setFillColor(color);
}
void ImageInfo::changePosition(float offset_x, float offset_y){
setPosition(Vector2f(position.x + offset_x, position.y + offset_y));
}
void ImageInfo::update(Vector2f mouse_pos, FloatRect view_cords){
shape.setPosition(Vector2f(
position.x + view_cords.left - view_cords.width / 2,
position.y + view_cords.top - view_cords.height / 2)
);
src_img.setPosition(Vector2f(
position.x + view_cords.left - view_cords.width / 2,
position.y + view_cords.top - view_cords.height / 2)
);
text.setPosition(
position.x + src_img.getGlobalBounds().width + src_img.getGlobalBounds().height / 2 - text.getLocalBounds().left,
position.y + text.getLocalBounds().height / 2 - text.getLocalBounds().top
);
}
void ImageInfo::render(sf::RenderTarget* target){
target->draw(src_img);
target->draw(text);
}