Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
editorManager.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 "editorHeaders.hpp"
24#include "editorManager.hpp"
25#include "editorTheme.hpp"
26#include "logging.hpp"
28
30{
32 this->MenuBar();
33 this->ShapeWindow();
34 this->TextureWindow();
35 this->TextWindow();
36 this->AnimationWindow();
37 this->SettingsWindow();
39 this->ShapeDetailsWindow();
41 this->TextDetailsWindow();
43 this->DebugMetricsWindow();
44 this->DebugLogWindow();
45#ifdef CHRONOS_PROFILING
46 this->ProfilingWindow();
47#endif
48 this->updateKeyframes();
49
50 LOG(4, "Elements added to the editor.")
51}
52
54{
55 if (this->pinMenuBar) {
56 if (ImGui::BeginMainMenuBar()) {
57 ImGui::MenuItem("Shape", NULL, &this->showShapeWindow);
58 ImGui::MenuItem("Texture", NULL, &this->showTextureWindow);
59 ImGui::MenuItem("Text", NULL, &this->showTextWindow);
60 ImGui::MenuItem("Animation", NULL, &this->showAnimationWindow);
61 ImGui::MenuItem("Settings", NULL, &this->showSettingsWindow);
62 ImGui::MenuItem(
63 "Generated Code", NULL, &this->showGeneratedCodeWindow);
64#ifdef CHRONOS_PROFILING
65 ImGui::MenuItem("Profiling", NULL, &this->showProfilingWindow);
66#endif
67 ImGui::EndMainMenuBar();
68 }
69 } else {
70 ImGui::Begin("Editor", nullptr, ImGuiWindowFlags_MenuBar);
71 if (ImGui::BeginMenuBar()) {
72 ImGui::MenuItem("Shape", NULL, &this->showShapeWindow);
73 ImGui::MenuItem("Texture", NULL, &this->showTextureWindow);
74 ImGui::MenuItem("Text", NULL, &this->showTextWindow);
75 ImGui::MenuItem("Animation", NULL, &this->showAnimationWindow);
76 ImGui::MenuItem("Settings", NULL, &this->showSettingsWindow);
77 ImGui::MenuItem(
78 "Generated Code", NULL, &this->showGeneratedCodeWindow);
79 ImGui::EndMenuBar();
80 }
81 ImGui::End();
82 }
83}
84
86{
87 if (this->showShapeWindow) {
88 ImGui::Begin("Shape", &this->showShapeWindow);
89 bool doesNameExist = false;
90 ImGui::SeparatorText("Shape Name");
91 ImGui::InputText("Shape Name", this->newShapeParams.shapeName, 200);
92 std::vector<std::pair<int, Chronos::Manager::ShapeParams>>
93 nameShapeDetails = this->manager->getShapeDetails();
94 for (std::pair<int, Chronos::Manager::ShapeParams> shapeDetail :
95 nameShapeDetails) {
96 if (!strcmp(this->newShapeParams.shapeName,
97 shapeDetail.second.shapeName)) {
98 ImGui::Text("Name Already Exists");
99 doesNameExist = true;
100 break;
101 }
102 }
103 ImGui::SeparatorText("Fill");
104 ImGui::RadioButton("Color", &this->newShapeFill, 0);
105 ImGui::RadioButton("Texture", &this->newShapeFill, 1);
106 ImGui::SeparatorText("Properties");
107 ImGui::DragFloat(
108 "X(-1 to 1)", &this->newShapeParams.x, 0.01f, -1.0f, 1.0f);
109 ImGui::DragFloat(
110 "Y(-1 to 1)", &this->newShapeParams.y, 0.01f, -1.0f, 1.0f);
111 ImGui::DragFloat(
112 "X Size", &this->newShapeParams.xSize, 0.01f, 0.0f, FLT_MAX);
113 ImGui::DragFloat(
114 "Y Size", &this->newShapeParams.ySize, 0.01f, 0.0f, FLT_MAX);
115 ImGui::DragFloat(
116 "Rotation", &this->newShapeParams.rotation, 0.01f, 0.0f, FLT_MAX);
117 switch (this->newShapeFill) {
118 case 0:
119 ImGui::ColorEdit3("Color", this->newShapeParams.color.data());
120 break;
121 case 1:
122 if (ImGui::BeginCombo("Select Texture", currentShapeTextureName)) {
123 std::vector<Chronos::Manager::TextureDetails> details
124 = this->manager->getTextureDetails();
125 if (details.size() == 0) {
126 ImGui::Selectable("No Textures");
127 } else {
128 for (Chronos::Manager::TextureDetails textureDetail :
129 details) {
130 bool isSelected = currentShapeTextureSelection
131 == textureDetail.textureNo;
132 if (ImGui::Selectable(textureDetail.textureName.c_str(),
133 isSelected)) {
134 currentShapeTextureSelection
135 = textureDetail.textureNo;
136 strcpy(currentShapeTextureName,
137 textureDetail.textureName.c_str());
138 LOG(1,
139 "Texture selected for shapeNo ["
140 + std::to_string(
141 currentShapeTextureSelection)
142 + "], textureName ["
143 + currentShapeTextureName + "]")
144 }
145 if (isSelected) {
146 ImGui::SetItemDefaultFocus();
147 }
148 }
149 }
150 ImGui::EndCombo();
151 }
152 }
153 if (!doesNameExist) {
154 if (ImGui::Button("Add Shape")) {
155 switch (this->newShapeFill) {
156 case 0:
157 this->manager->addShape(this->newShapeParams);
158 LOG(1,
159 "Colored shape added with shapeName ["
160 + std::string(this->newShapeParams.shapeName) + "]")
161 break;
162 case 1:
163 this->manager->addShape(this->newShapeParams,
164 this->currentShapeTextureSelection);
165 LOG(1,
166 "Textured shape added with shapeName ["
167 + std::string(this->newShapeParams.shapeName) + "]")
168 break;
169 }
170 }
171 }
172 ImGui::SeparatorText("Current Shapes");
173 if (ImGui::BeginListBox("Shapes")) {
174 std::vector<std::pair<int, Chronos::Manager::ShapeParams>>
175 shapeDetails = this->manager->getShapeDetails();
176 if (shapeDetails.size() == 0) {
177 ImGui::Selectable("No Shapes");
178 } else {
179 for (int i = 0; i < static_cast<int>(shapeDetails.size());
180 i++) {
181 if (ImGui::Selectable(shapeDetails[i].second.shapeName,
182 this->currentShapeSelection == i)) {
183 this->currentShapeSelection = i;
184 }
185 }
186 }
187 ImGui::EndListBox();
188 if (shapeDetails.size() > 0) {
189 ImGui::Text("Selected Shape: %d",
190 shapeDetails[currentShapeSelection].first);
191 if (ImGui::Button("Edit Shape")) {
192 this->showShapeDetailsWindow = true;
193 this->shapeDetailsShapeNo
194 = shapeDetails[currentShapeSelection].first;
195 this->shapeDetailsShapeParams
196 = shapeDetails[currentShapeSelection].second;
197 }
198 ImGui::SameLine();
199 if (ImGui::Button("Remove Shape")) {
200 this->manager->removeObject(
201 shapeDetails[currentShapeSelection].first);
202 }
203 }
204 }
205
206 ImGui::End();
207 }
208}
209
211{
212 if (this->showTextureWindow) {
213 ImGui::Begin("Texture", &this->showTextureWindow);
214 bool doesTextureExist = false;
215 ImGui::SeparatorText("Add Textures");
216 ImGui::InputText("Texture Path", this->newTexturePath, 200);
217 ImGui::InputText("Texture Name", this->newTextureName, 200);
218 std::vector<Chronos::Manager::TextureDetails> nameTextureDetails
219 = this->manager->getTextureDetails();
220 for (Chronos::Manager::TextureDetails textureDetail :
221 nameTextureDetails) {
222 if (!strcmp(
223 this->newTextureName, textureDetail.textureName.c_str())) {
224 ImGui::Text("Name Already Exists");
225 doesTextureExist = true;
226 break;
227 }
228 if (std::string(this->newTextureName).size() == '\0') {
229 ImGui::Text("Name Cannot be empty");
230 doesTextureExist = true;
231 break;
232 }
233 if (!std::string(this->newTexturePath).ends_with(".jpg")
234 && !std::string(this->newTexturePath).ends_with(".png")) {
235 ImGui::Text("Only jpg and png files are supported");
236 doesTextureExist = true;
237 break;
238 }
239 }
240
241 if (!doesTextureExist) {
242 if (ImGui::Button("Add Texture")) {
243 this->manager->addTexture(
244 this->newTexturePath, this->newTextureName);
245 this->newTexturePath[0] = '\0';
246 LOG(1,
247 "Texture added with textureName ["
248 + std::string(this->newTextureName)
249 + "] and texturePath [" + this->newTexturePath + "]")
250 }
251 }
252 ImGui::SeparatorText("Current Textures");
253 std::vector<Chronos::Manager::TextureDetails> details
254 = this->manager->getTextureDetails();
255 if (ImGui::BeginListBox("Textures")) {
256 if (details.size() == 0) {
257 ImGui::Selectable("No Textures");
258 } else {
259 for (int i = 0; i < static_cast<int>(details.size()); i++) {
260 if (ImGui::Selectable(details[i].textureName.c_str(),
261 currentTextureSelection == i)) {
262 currentTextureSelection = i;
263 }
264 }
265 }
266 ImGui::EndListBox();
267 }
268 if (details.size() > 0) {
269 if (ImGui::Button("Remove Texture")) {
270 this->manager->removeTexture(
271 details[currentTextureSelection].textureNo);
272 LOG(1,
273 "Texture removed with textureNo ["
274 + std::to_string(
275 details[currentTextureSelection].textureNo)
276 + "]")
277 }
278 ImGui::SameLine();
279 if (ImGui::Button("View Texture Details")) {
280 this->showTextureDetailsWindow = true;
281 LOG(1,
282 "Texture selected for editing with textureNo ["
283 + std::to_string(this->textureDetailsCurrentSelection)
284 + "]")
285 }
286 }
287 ImGui::End();
288 }
289}
290
292{
293 if (this->showTextWindow) {
294 ImGui::Begin("Text", &this->showTextWindow);
295 ImGui::SeparatorText("Add Text");
296 char inputText[2048];
297 strcpy(inputText, this->newTextParams.text.c_str());
298 ImGui::InputText("Text", inputText, 2048);
299 this->newTextParams.text = inputText;
300 ImGui::DragFloat(
301 "X(-1 to 1)", &this->newTextParams.x, 0.01f, -1.0f, 1.0f);
302 ImGui::DragFloat(
303 "Y(-1 to 1)", &this->newTextParams.y, 0.01f, -1.0f, 1.0f);
304 ImGui::DragFloat(
305 "Rotation", &this->newTextParams.rotation, 0.01f, 0.0f, FLT_MAX);
306 ImGui::DragFloat(
307 "Scale", &this->newTextParams.scale, 0.01f, 0.0f, FLT_MAX);
308 ImGui::ColorEdit3("Color", this->newTextParams.color.data());
309 if (ImGui::BeginCombo(
310 "Select Font", this->currentFontSelection.c_str())) {
311 if (ImGui::Selectable(
312 "consolas", this->currentFontSelection == "consolas")) {
313 this->currentFontSelection = "consolas";
314 LOG(1, "Font selected [" + this->currentFontSelection + "]")
315 }
316 if (ImGui::Selectable("consolas_bold",
317 this->currentFontSelection == "consolas_bold")) {
318 this->currentFontSelection = "consolas_bold";
319 LOG(1, "Font selected [" + this->currentFontSelection + "]")
320 }
321 if (ImGui::Selectable(
322 "arial", this->currentFontSelection == "arial")) {
323 this->currentFontSelection = "arial";
324 LOG(1, "Font selected [" + this->currentFontSelection + "]")
325 }
326 if (ImGui::Selectable(
327 "arial_bold", this->currentFontSelection == "arial_bold")) {
328 this->currentFontSelection = "arial_bold";
329 LOG(1, "Font selected [" + this->currentFontSelection + "]")
330 }
331 if (ImGui::Selectable(
332 "times", this->currentFontSelection == "times")) {
333 this->currentFontSelection = "times";
334 LOG(1, "Font selected [" + this->currentFontSelection + "]")
335 }
336 if (ImGui::Selectable(
337 "times_bold", this->currentFontSelection == "times_bold")) {
338 this->currentFontSelection = "times_bold";
339 LOG(1, "Font selected [" + this->currentFontSelection + "]")
340 }
341 ImGui::EndCombo();
342 }
343 ImGui::DragInt("Font Size", &this->currentFontSizeSelection, 1, 6, 50);
344 if (this->newTextParams.text.size() == 0) {
345 ImGui::Text("Text Cannot be empty");
346 } else {
347 if (ImGui::Button("Add Text")) {
348 this->manager->addText(this->newTextParams,
349 this->currentFontSelection, this->currentFontSizeSelection);
350 LOG(1,
351 "Text added with text [" + this->newTextParams.text + "]")
352 }
353 }
354 ImGui::SeparatorText("Current Text");
355 if (ImGui::BeginListBox("Text")) {
356 std::vector<std::pair<int, Chronos::Engine::TextParams>> textDetails
357 = this->manager->getTextDetails();
358 if (textDetails.size() == 0) {
359 ImGui::Selectable("No Text");
360 } else {
361 for (int i = 0; i < static_cast<int>(textDetails.size()); i++) {
362 if (ImGui::Selectable(textDetails[i].second.text.c_str(),
363 this->currentTextSelection == i)) {
364 this->currentTextSelection = i;
365 }
366 }
367 }
368 ImGui::EndListBox();
369 if (textDetails.size() > 0) {
370 if (ImGui::Button("Edit Text")) {
371 this->showTextDetailsWindow = true;
372 this->textDetailsTextNo
373 = textDetails[currentTextSelection].first;
374 this->textDetailsTextParams
375 = textDetails[currentTextSelection].second;
376 LOG(1,
377 "Text selected for editing with textNo ["
378 + std::to_string(this->textDetailsTextNo) + "]")
379 }
380 ImGui::SameLine();
381 if (ImGui::Button("Remove Text")) {
382 this->manager->removeObject(
383 textDetails[currentTextSelection].first);
384 LOG(1,
385 "Text removed with textNo ["
386 + std::to_string(
387 textDetails[currentTextSelection].first)
388 + "]")
389 }
390 }
391 }
392 ImGui::End();
393 }
394}
395
397{
398 if (this->showSettingsWindow) {
399 ImGui::Begin("Settings", &this->showSettingsWindow);
400 ImGui::SeparatorText("Build Information");
401 ImGui::Text("Engine name: %s", "Chronos");
402 ImGui::Text("Build Version: %d.%d.%d", CHRONOS_VERSION_MAJOR,
403 CHRONOS_VERSION_MINOR, CHRONOS_VERSION_PATCH);
404 ImGui::Text("Build Date: %s", __DATE__);
405 ImGui::Text("Build Time: %s", __TIME__);
406
407 ImGui::SeparatorText("Window Settings");
408 ImGui::InputText("Window Title", this->windowTitle, 200);
409 if (ImGui::Button("Update Window Title")) {
410 glfwSetWindowTitle(this->manager->getWindow(), this->windowTitle);
411 LOG(1,
412 "Window title updated to [" + std::string(this->windowTitle)
413 + "]")
414 }
415 ImGui::Checkbox("Make Window Fullscreen", &this->fullScreen);
416 if (this->fullScreen && !this->isWindowFullscreen) {
417 GLFWwindow* window = this->manager->getWindow();
418 const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
419 glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0,
420 mode->width, mode->height, mode->refreshRate);
421 this->isWindowFullscreen = true;
422 LOG(1, "Window set to fullscreen")
423 } else if (!this->fullScreen && this->isWindowFullscreen) {
424 GLFWwindow* window = this->manager->getWindow();
425 glfwSetWindowMonitor(window, nullptr, 0, 0, 800, 600, 0);
426 this->isWindowFullscreen = false;
427 LOG(1, "Window set to windowed mode")
428 }
429
430 ImGui::SeparatorText("Present Mode");
431 if (ImGui::BeginCombo("Present Mode", this->presentMode.c_str())) {
432 if (ImGui::Selectable("mailbox", this->presentMode == "mailbox")) {
433 this->presentMode = "mailbox";
434 }
435 if (ImGui::Selectable(
436 "immediate", this->presentMode == "immediate")) {
437 this->presentMode = "immediate";
438 }
439 if (ImGui::Selectable("fifo", this->presentMode == "fifo")) {
440 this->presentMode = "fifo";
441 }
442 if (ImGui::Selectable(
443 "fifo_relaxed", this->presentMode == "fifo_relaxed")) {
444 this->presentMode = "fifo_relaxed";
445 }
446 ImGui::EndCombo();
447 }
448 if (ImGui::Button("Update Present Mode")) {
449 this->manager->changePresentMode(this->presentMode);
450 LOG(1, "Present mode updated to [" + this->presentMode + "]")
451 }
452
453 ImGui::SeparatorText("MSAA Samples");
454 std::vector<std::string> msaaSamples = this->manager->getMSAAModes();
455 for (std::string sample : msaaSamples) {
456 if (ImGui::Selectable(
457 sample.c_str(), this->msaaSamples == sample)) {
458 this->msaaSamples = sample;
459 }
460 }
461 if (ImGui::Button("Update MSAA Samples")) {
462 this->manager->changeMSAA(this->msaaSamples);
463 LOG(1, "MSAA Samples updated to [" + this->msaaSamples + "]")
464 }
465
466 ImGui::SeparatorText("Background Color");
467 ImGui::ColorEdit3("Background Color", this->bgColor);
468 if (ImGui::Button("Update Background Color")) {
469 this->manager->changeBackgroundColor(
470 this->bgColor[0], this->bgColor[1], this->bgColor[2]);
471 LOG(1,
472 "Background color updated to ["
473 + std::to_string(this->bgColor[0]) + ", "
474 + std::to_string(this->bgColor[1]) + ", "
475 + std::to_string(this->bgColor[2]) + "]")
476 }
477
478 ImGui::SeparatorText("ImGui Debug Settings");
479 ImGui::Checkbox("Show Metrics", &this->showDebugMetricsWindow);
480 ImGui::Checkbox("Show Log", &this->showDebugLogWindow);
481 ImGui::Checkbox("Pin Menu Bar", &this->pinMenuBar);
482
483 ImGui::End();
484 }
485}
486
488{
489 if (this->showShapeDetailsWindow) {
490 ImGui::Begin("Shape Details", &this->showShapeDetailsWindow);
491 ImGui::SeparatorText("Shape Details");
492 if (this->manager->getShapeDetails().size() == 0) {
493 ImGui::Text("No Shapes");
494 } else {
495 ImGui::InputText(
496 "Shape Name", this->shapeDetailsShapeParams.shapeName, 200);
497 ImGui::DragFloat("X(-1 to 1)", &this->shapeDetailsShapeParams.x,
498 0.01f, -1.0f, 1.0f);
499 ImGui::SameLine();
500 this->keyframeCheckbox(&this->shapeDetailsShapeParams.x, "X");
501 ImGui::DragFloat("Y(-1 to 1)", &this->shapeDetailsShapeParams.y,
502 0.01f, -1.0f, 1.0f);
503 ImGui::SameLine();
504 this->keyframeCheckbox(&this->shapeDetailsShapeParams.y, "Y");
505 ImGui::DragFloat("X Size", &this->shapeDetailsShapeParams.xSize,
506 0.01f, 0.0f, FLT_MAX);
507 ImGui::SameLine();
508 this->keyframeCheckbox(
509 &this->shapeDetailsShapeParams.xSize, "X size");
510 ImGui::DragFloat("Y Size", &this->shapeDetailsShapeParams.ySize,
511 0.01f, 0.0f, FLT_MAX);
512 ImGui::SameLine();
513 this->keyframeCheckbox(
514 &this->shapeDetailsShapeParams.ySize, "Y size");
515 ImGui::DragFloat("Rotation",
516 &this->shapeDetailsShapeParams.rotation, 0.01f, 0.0f, FLT_MAX);
517 ImGui::SameLine();
518 this->keyframeCheckbox(
519 &this->shapeDetailsShapeParams.rotation, "Rotation(degrees)");
520 ImGui::ColorEdit3(
521 "Color", this->shapeDetailsShapeParams.color.data());
522 this->manager->updateShape(
523 this->shapeDetailsShapeNo, this->shapeDetailsShapeParams);
524 }
525 ImGui::End();
526 }
527}
528
530{
531 if (this->showTextureDetailsWindow) {
532 ImGui::Begin("Texture Details", &this->showTextureDetailsWindow);
533 ImGui::SeparatorText("Texture Details");
534 std::vector<Chronos::Manager::TextureDetails> textureDetails
535 = this->manager->getTextureDetails();
536 if (textureDetails.size() == 0) {
537 ImGui::Text("No Textures");
538 } else {
539 ImGui::Text("Texture Name: %s",
540 textureDetails[this->textureDetailsCurrentSelection]
541 .textureName.data());
542 ImGui::Text("Texture Path: %s",
543 textureDetails[this->textureDetailsCurrentSelection]
544 .texturePath.data());
545 ImGui::Text("Width: %d",
546 textureDetails[this->textureDetailsCurrentSelection].width);
547 ImGui::Text("Height: %d",
548 textureDetails[this->textureDetailsCurrentSelection].height);
549 ImGui::SeparatorText("Texture Preview");
550 ImGui::Image(
551 (ImTextureID)
552 textureDetails[this->textureDetailsCurrentSelection]
553 .descriptorSet,
554 ImVec2(
555 textureDetails[this->textureDetailsCurrentSelection].width,
556 textureDetails[this->textureDetailsCurrentSelection]
557 .height));
558 }
559 ImGui::End();
560 }
561}
562
564{
565 if (this->showTextDetailsWindow) {
566 ImGui::Begin("Text Details", &this->showTextDetailsWindow);
567 ImGui::SeparatorText("Text Details");
568 std::vector<std::pair<int, Chronos::Engine::TextParams>> textDetails
569 = this->manager->getTextDetails();
570 if (textDetails.size() == 0) {
571 ImGui::Text("No Text");
572 } else {
573 char inputText[2048];
574 strcpy(inputText, this->textDetailsTextParams.text.c_str());
575 ImGui::InputText("Text", inputText, 2048);
576 if (inputText[0] != '\0') {
577 this->textDetailsTextParams.text = inputText;
578 ImGui::Text("Text Field cannot be empty");
579 }
580
581 ImGui::DragFloat("X(-1 to 1)", &this->textDetailsTextParams.x,
582 0.01f, -1.0f, 1.0f);
583 ImGui::DragFloat("Y(-1 to 1)", &this->textDetailsTextParams.y,
584 0.01f, -1.0f, 1.0f);
585 ImGui::DragFloat("Rotation", &this->textDetailsTextParams.rotation,
586 0.01f, 0.0f, FLT_MAX);
587 ImGui::DragFloat("Scale", &this->textDetailsTextParams.scale, 0.01f,
588 0.0f, FLT_MAX);
589 ImGui::ColorEdit3(
590 "Color", this->textDetailsTextParams.color.data());
591 this->manager->updateText(
592 this->textDetailsTextNo, this->textDetailsTextParams);
593 }
594 ImGui::End();
595 }
596}
598{
599 if (this->showDebugMetricsWindow) {
600 ImGui::ShowMetricsWindow(&this->showDebugMetricsWindow);
601 }
602}
603
605{
606 if (this->showDebugLogWindow) {
607 ImGui::ShowDebugLogWindow(&this->showDebugLogWindow);
608 }
609}
610
611#ifdef CHRONOS_PROFILING
612void Chronos::Editor::EditorManager::ProfilingWindow()
613{
614 if (this->showProfilingWindow) {
615 ImGui::Begin("Profiling", &this->showProfilingWindow);
616 ImGui::Text("FPS %f ms", 1000 / this->manager->getTotalTime());
617 ImGui::Text("Frame Time %f ms", this->manager->getTotalTime());
618 ImGui::Text("Update Time %f ms", this->manager->getUpdateTime());
619 ImGui::Text("CPU Time %f ms", this->manager->getCpuTime());
620 ImGui::Text("GPU Time %f ms",
621 this->manager->getTotalTime() - this->manager->getCpuTime());
622 ImGui::Text("Present Time %f ms", this->manager->getPresentTime());
623 ImGui::End();
624 }
625}
626#endif
627
629{
630 if (this->showGeneratedCodeWindow) {
631 ImGui::Begin("Generated Code", &this->showGeneratedCodeWindow);
632 ImGui::SeparatorText("Generated Code");
633 std::string code = Chronos::Editor::generateCode(this->manager);
634 ImGui::InputTextMultiline("Code", code.data(), code.size(),
635 ImVec2(800, 600), ImGuiInputTextFlags_ReadOnly);
636 ImGui::End();
637 }
638}
639
641{
642 if (this->showAnimationWindow) {
643 ImGui::Begin("Animation", &this->showAnimationWindow);
644 ImGui::SeparatorText("Animation");
645 ImGui::End();
646 }
647}
648
650{
651 if (this->showKeyframeDetailsWindow) {
652 ImGui::Begin("Keyframe Details", &this->showKeyframeDetailsWindow);
653 ImGui::SeparatorText("Keyframe Details");
654 ImGui::Text("Current Value pointer: %p",
655 (void*)this->currentKeyframeValuePointer);
656 int keyframeNo = this->getKeyframeNo(this->currentKeyframeValuePointer);
657 ImGui::Text("Keyframe Number: %d", keyframeNo);
658 ImGui::End();
659 }
660}
661
663{
664 if (!valuePointer) {
665 throw std::runtime_error("Value Pointer is null");
666 }
667 if (this->floatPointerToKeyframeNo.find(valuePointer)
668 == this->floatPointerToKeyframeNo.end()) {
669 return -1;
670 } else {
671 return this->floatPointerToKeyframeNo[valuePointer];
672 }
673}
674
676{
677 if (this->getKeyframeNo(valuePointer) == -1)
678 return false;
679 return true;
680}
681
683 float* valuePointer, std::string name)
684{
685 bool isAnimated = this->doesKeyframeExist(valuePointer);
686 bool currentChange = isAnimated;
687 ImGui::Checkbox(name.c_str(), &currentChange);
688 if (currentChange != isAnimated) {
689 LOG(3,
690 "Animate checkbox changed for valuePointer ["
691 + std::to_string((long long)valuePointer) + "]");
692 if (currentChange) {
693 int keyframeNo = this->manager->addKeyframeVariable(
694 { { 0, *valuePointer }, { 100, *valuePointer } });
695 this->floatPointerToKeyframeNo[valuePointer] = keyframeNo;
696 LOG(3,
697 "Added keyframe for valuePointer ["
698 + std::to_string((long long)valuePointer)
699 + "] with keyframeNo [" + std::to_string(keyframeNo) + "]")
700 } else {
701 int keyframeNo = this->getKeyframeNo(valuePointer);
702 if (keyframeNo == -1) {
703 throw std::runtime_error("Could not find keyframe number!!!");
704 }
705 this->manager->removeKeyframeVariable(keyframeNo);
706 this->floatPointerToKeyframeNo.erase(valuePointer);
707 LOG(3,
708 "Removed keyframe for valuePointer ["
709 + std::to_string((long long)valuePointer)
710 + "] with keyframeNo [" + std::to_string(keyframeNo) + "]")
711 }
712 }
713 if (currentChange) {
714 ImGui::SameLine();
715 if (ImGui::Button("Keyframe Details")) {
716 this->showKeyframeDetailsWindow = true;
717 this->currentKeyframeValuePointer = valuePointer;
718 }
719 }
720}
721
723{
724 for (auto& [key, value] : this->floatPointerToKeyframeNo) {
725 *key = this->manager->keyframeGetVariable(value);
726 LOG(4,
727 "Updated keyframe value for keyframeNo [" + std::to_string(value)
728 + "] to [" + std::to_string(*key) + "]")
729 }
730}
int getKeyframeNo(float *valuePointer)
void keyframeCheckbox(float *valuePointer, std::string name)
bool doesKeyframeExist(float *valuePointer)
Contains all the editor headers.
#define LOG(LEVEL, MESSAGE)
Definition logging.hpp:60
std::string generateCode(Chronos::Manager::Manager *manager)
Holds some details about the texture.
Definition chronos.hpp:90