-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
74 lines (67 loc) · 1.92 KB
/
main.cpp
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
#include <iostream>
#include <string>
#include "ArtistTree.h"
#include "AlbumList.h"
#include "MusicData.h"
#include <SFML/Graphics.hpp>
#include "GraphicsHelper.h"
#include "InputBar.h"
#include "DisplayTable.h"
#include "Instructions.h"
int main()
{
float width = 800;
float height = 800;
sf::RenderWindow window(sf::VideoMode(width, height), "Music Library Data", sf::Style::Titlebar | sf::Style::Close);
// Load font file for sf::Text objects
std::string font_file = "SourceSansPro.otf"; // font for Text Objects
sf::Font font;
if (!font.loadFromFile(font_file))
{
std::cerr << "Could not load " << font_file << " font file." << std::endl;
}
// load DisplayTable then use it to initialize InputBar
DisplayTable mytable{ font_file };
InputBar myinput{ font_file, mytable };
// load instructions for the user
Instructions myinstructions{ font_file, sf::Vector2f(width, height) };
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::MouseButtonReleased:
// pass click location to InputBar to take action
if (event.key.code == sf::Mouse::Left)
// left click means information might have been entered
{
myinput.clicked(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
myinstructions.clicked(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
}
else if (event.key.code == sf::Mouse::Right)
// right click means input field might have been cleared
{
myinput.cleared(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
}
break;
case sf::Event::TextEntered:
// handle ASCII characters only
if (event.text.unicode < 128)
{
myinput.input(static_cast<char>(event.text.unicode));
}
break;
}
}
window.clear();
myinput.draw(window);
myinstructions.draw(window);
window.display();
}
return 0;
}