Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
manager.cpp
Go to the documentation of this file.
1/*
2Copyright (c) 2024 Rahul Satish Vadhyar
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
23#include "chronos.hpp"
24namespace Chronos {
25GLFWwindow* Manager::Manager::getWindow() { return engine.window; }
27{
28
29 // check whether the bg color is between 0 and 1
30 if (initializer.BackgroundColor[0] < 0 || initializer.BackgroundColor[0] > 1
31 || initializer.BackgroundColor[1] < 0
32 || initializer.BackgroundColor[1] > 1
33 || initializer.BackgroundColor[2] < 0
34 || initializer.BackgroundColor[2] > 1) {
35 throw std::runtime_error("Invalid background color");
36 }
37 engine.bgColor[0] = initializer.BackgroundColor[0];
38 engine.bgColor[1] = initializer.BackgroundColor[1];
39 engine.bgColor[2] = initializer.BackgroundColor[2];
40
41 if (initializer.WindowWidth <= 0 || initializer.WindowHeight <= 0) {
42 throw std::runtime_error("Invalid window size");
43 }
44 engine.width = initializer.WindowWidth;
45 engine.height = initializer.WindowHeight;
46
47#ifdef ENABLE_EDITOR
48 engine.setEditorAddElementsCallback(initializer.editorAddElements);
49#endif
50}
51
53{
54 animManager.update();
55 engine.drawFrame();
56}
57int Manager::Manager::changeBackgroundColor(float r, float g, float b)
58{
59 if (r < 0 || r > 1 || g < 0 || g > 1 || b < 0 || b > 1) {
60 throw std::runtime_error("Invalid background color");
61 }
62 engine.bgColor[0] = r;
63 engine.bgColor[1] = g;
64 engine.bgColor[2] = b;
65 return 0;
66}
67};
69{
70
71 engine.objectManager.remove(objectNo);
72}
Main API for chronos. Any applications should include this file.
GLFWwindow * window
This is the GLFW window reference that is used by the engine.
Definition engine.hpp:124
Chronos::Engine::Engine engine
The backend Vulkan engine, used for rendering the desired shapes and text.s.
Definition chronos.hpp:509
Manager(Initializer initializer)
Constructor for chronos. The initalizer struct with the necessary options to be passed.
Definition manager.cpp:26
void removeObject(int objectNo)
Definition manager.cpp:68
int changeBackgroundColor(float r, float g, float b)
Changes the background color of the window.
Definition manager.cpp:57
GLFWwindow * getWindow()
Gets a reference to the GLFWWindow.
Definition manager.cpp:25
void drawFrame()
Draws the current frame to the window.
Definition manager.cpp:52
This struct contains the details for initialing the manager.
Definition chronos.hpp:46