Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
managerTextFunctions.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"
24#include "getFontType.hpp"
25
27 Chronos::Engine::TextParams params, std::string fontType, int fontSize)
28{
29 if (params.text == "") {
30 throw std::runtime_error("Text cannot be empty");
31 }
33 text->params = params;
35 = Chronos::Engine::getFontType(fontType, fontSize);
36 text->init(&this->engine.device, this->engine.commandPool,
37 &(this->engine.swapChain), this->engine.objectManager.textureSampler,
38 &this->engine.objectManager.renderPass, fontStyle);
39
40 return engine.objectManager.addObject(text);
41}
42
44 int objectNo, Chronos::Engine::TextParams params)
45{
46 if (params.text == "") {
47 throw std::runtime_error("Text cannot be empty");
48 }
49 if (engine.objectManager.objects.count(objectNo) == 0) {
50 throw std::runtime_error("Text does not exist");
51 }
52 if (engine.objectManager.objects[objectNo]->objectType
54 throw std::runtime_error("Object is not a text object");
55 }
56 ((Chronos::Engine::Text*)engine.objectManager.objects[objectNo])->params
57 = params;
58}
59
60std::vector<std::pair<int, Chronos::Engine::TextParams>>
62{
63 std::vector<std::pair<int, Chronos::Engine::TextParams>> textDetails;
64 for (auto& text : engine.objectManager.objects) {
65 if (text.second->objectType != Chronos::Engine::ObjectType::TypeText) {
66 continue;
67 }
68 std::pair<int, Chronos::Engine::TextParams> textDetail;
69 textDetail.first = text.first;
70 textDetail.second = ((Chronos::Engine::Text*)text.second)->params;
71 textDetails.push_back(textDetail);
72 }
73 return textDetails;
74}
Main API for chronos. Any applications should include this file.
Chronos::Engine::Device device
This is the object that manages the device.
Definition engine.hpp:233
Chronos::Engine::ObjectManager objectManager
Definition engine.hpp:99
Class for creating a text object for rendering text.
Definition text.hpp:86
Chronos::Engine::TextParams params
Various parameters of the text that are set by the user.
Definition text.hpp:154
void init(Chronos::Engine::Device *device, VkCommandPool commandPool, Chronos::Engine::SwapChain *swapChain, VkSampler textureSampler, VkRenderPass *renderPass, Chronos::Engine::FontTypes fontStyle)
Initializes the font object and creates the necessary objects.
Definition text.cpp:28
Chronos::Engine::Engine engine
The backend Vulkan engine, used for rendering the desired shapes and text.s.
Definition chronos.hpp:509
int addText(Chronos::Engine::TextParams params, std::string fontType, int fontSize)
Adds text to the window.
std::vector< std::pair< int, Chronos::Engine::TextParams > > getTextDetails()
Returns the details of all text defined.
void updateText(int objectNo, Chronos::Engine::TextParams params)
Updates the text with the new parameters.
Chronos::Engine::FontTypes getFontType(std::string fontType, int fontSize)
The parameters needed for the font style.
Definition text.hpp:58
Parameters for rendering text.