-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathEditor.cpp
63 lines (49 loc) · 1.93 KB
/
Editor.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
#include <SFML/Graphics.hpp>
#include "EditorView.h"
#include "TextDocument.h"
#include "InputController.h"
#include "ImplementationUtils.h"
int main(int argc, char* argv[]) {
std::string workingDirectory = ImplementationUtils::getWorkingDirectory(argv[0]);
std::string saveFileName;
std::string loadFileName;
if (argc == 2) {
saveFileName = workingDirectory + argv[1];
loadFileName = workingDirectory + argv[1];
} else {
saveFileName = workingDirectory + "txt/textoDePruebaGuardado.txt";
loadFileName = workingDirectory + "txt/textoDePruebaGuardado.txt";
}
sf::RenderWindow window(sf::VideoMode(720, 405), "Jonno-text");
window.setVerticalSyncEnabled(true);
sf::Color backgroundColor = sf::Color(21, 29, 45);
TextDocument document;
document.init(loadFileName);
EditorContent editorContent(document);
EditorView editorView(window, workingDirectory, editorContent);
InputController inputController(editorContent);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::Resized) {
editorView.setCameraBounds(event.size.width, event.size.height);
}
if (event.key.code == sf::Keyboard::S && sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) {
if (document.hasChanged()){
document.saveFile(saveFileName);
std::cout << "SAVED TO: " << saveFileName << "\n";
}
}
inputController.handleEvents(editorView, window, event);
}
inputController.handleConstantInput(editorView, window);
window.clear(backgroundColor);
window.setView(editorView.getCameraView());
editorView.draw(window);
window.display();
}
return 0;
}