-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_project.cpp
More file actions
107 lines (90 loc) · 2.7 KB
/
base_project.cpp
File metadata and controls
107 lines (90 loc) · 2.7 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
// base_project.cpp : Defines the entry point for the application.
//
#include "base_project.h" // includes header
#include <iostream> // import input/output stream library
#include "CustomConsole.h"
#include <limits>
#include "SFML/Graphics.hpp"
#include "Services/WindowManagementService.h"
using namespace std; // allows usage of std functions like std::cout without the prefixed std
int main()
{
cout << "Hello CMake." << endl;
std::cout << "WindowName" << std::endl;
sf::RenderWindow window(sf::VideoMode({500,500}),"WindowName");
while (window.isOpen()) {
while (const std::optional event = window.pollEvent())
{
// "close requested" event: we close the window
if (event->is<sf::Event::Closed>())
window.close();
}
// Clear the window
window.clear(sf::Color::Black);
// Display the contents
window.display();
}
int choice;
CustomConsole console;
console.printColoured();
console.log("hello");
CustomConsole::log("Hello 2");
do {
cout << std::endl;
cout << "1. Test create window\n"; // console output
cout << "2. Test list windows\n";
cout << "3. Test remove window\n";
cout << "9. Exit\n";
cout << "Enter your choice: ";
cin >> choice; // console input
cout << std::endl;
if (cin.fail()) { // cin.fail() checks the cin for error states, and returns true or false
cout << "Input error";
cin.clear(); // remove error state
cin.ignore((numeric_limits<streamsize>::max)(), '\n'); // discard errored input (wrapped in brackets because something was overriding max somewhere)
cout << "Invalid input. Please enter an integer.\n";
continue; // restart loop
}
//windowParams params;
//Window newWindow;
switch (choice) {
case 1: {
cout << "Creating test window.\n";
cout << "Choose a title.\n";
std::string newTitle;
cin >> newTitle;
windowParams params;
params.width = 800;
params.height = 600;
params.title = newTitle;
params.type = windowParams::WindowType::programWindow;
Window newWindow(WindowManagementService::createWindow(params));
break;
}
case 2: {
cout << "Listing all windows...\n";
cout << "There are currently [" << WindowManagementService::getWindowCount() << "] windows open.\n";
auto windows = WindowManagementService::getAllWindows();
for (const auto& pair : windows) {
int id = pair.first;
const Window& win = pair.second;
std::cout << "Window ID: " << id << ", Title: " << win.getTitle() << std::endl;
}
break;
}
case 3: {
int id;
cout << "Choose a window ID.\n";
cin >> id;
WindowManagementService::closeWindow(id);
break;
}
case 9:
cout << "Exiting.\n";
break;
default:
cout << "Invalid. Try again.\n";
}
} while (choice != 9);
return 0;
}