-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileItem.cpp
More file actions
87 lines (56 loc) · 1.9 KB
/
FileItem.cpp
File metadata and controls
87 lines (56 loc) · 1.9 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
//
// Created by Kristal Hong on 11/21/23.
//
#include "FileItem.h"
#include "AppHandler/AppHandler.h"
FileItem::FileItem() : Item() {
//
}
FileItem::FileItem(std::string text, sf::Vector2f size, sf::Vector2f position) : shape(size), labelText(text, sf::Font(), 12) {
shape.setPosition(position);
shape.setFillColor(sf::Color::White);
labelText.setPosition(position.x + 5, position.y + 5);
}
void FileItem::draw(sf::RenderTarget &window, sf::RenderStates states) const {
Item::draw(window, states);
window.draw(icon);
}
void FileItem::addEventHandler(sf::RenderWindow &window, sf::Event event) {
Item::addEventHandler(window, event);
}
void FileItem::setPosition(sf::Vector2f position) {
Item::setPosition(position);
setIconPosition();
}
void FileItem::setIcon(const std::string& filename) {
this->texture.loadFromFile(filename);
icon.setTexture(texture);
resizeIcon();
}
void FileItem::setPNGImage(const std::string& filename) {
this->texturePNG.loadFromFile(filename);
imagePNG.setTexture(texturePNG);
//change the position of the image
imagePNG.setPosition({210, 130});
//change the scale of the image.
imagePNG.setScale({1.6, 1.6});
AppHandler::setSprite(imagePNG);
}
////private
void FileItem::setPNGPosition() {
sf::Vector2f PNGPosition;
PNGPosition = {100, 100};
this->imagePNG.setPosition(PNGPosition);
}
void FileItem::setIconPosition() {
sf::Vector2f borderPosition = getPosition();
sf::Vector2f iconPosition;
iconPosition = {borderPosition.x - padding - icon.getGlobalBounds().width, borderPosition.y + 2 * padding};
this->icon.setPosition(iconPosition);
}
void FileItem::resizeIcon() {
float borderHeight = getSize().y - 5 * padding;
float iconHeight = icon.getGlobalBounds().height;
float resizeFactor = borderHeight / iconHeight;
icon.setScale({resizeFactor, resizeFactor});
}