-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (88 loc) · 3.06 KB
/
Copy pathmain.cpp
File metadata and controls
112 lines (88 loc) · 3.06 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
108
109
110
111
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#include <iostream>
#include "ui/render.hpp"
#include "ui/fa_icons.hpp"
#include "app.hpp"
int main() {
// Initialize GLFW
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW\n";
return -1;
}
// Configure GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create window
GLFWwindow *window = glfwCreateWindow(1200, 760, "Turing Machine GUI", nullptr, nullptr);
if (!window) {
std::cerr << "Failed to create GLFW window\n";
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
// Initialize ImGui
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable keyboard controls
io.Fonts->AddFontFromFileTTF("../ui/fonts/rubik-regular.ttf", 16.0f);
static const ImWchar icons_ranges[] = { FA_ICON_MIN, FA_ICON_MAX, 0 }; // For FontAwesome
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
io.Fonts->AddFontFromFileTTF("../ui/fonts/fa-light-300.ttf", 16.0f, &icons_config, icons_ranges);
// Setup ImGui style
ImGui::StyleColorsLight(); // or ImGui::StyleColorsLight()
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 330 core");
AppState state;
//auto &tape = state.tm().tape();
//char a[4] = {'A', 'B', 'C', 'D'};
//for (int j = 0; j < 20; j ++) {
// tape.write(a[(j % (j % 4 + 1) + 1) % 4]);
// tape.moveRight();
//}
//tape.moveToLeftMost();
// Test positions
//state.setStatePosition(core::State("q0", core::State::Type::START), ImVec2(200, 200));
//state.setStatePosition(core::State("q1"), ImVec2(400, 200));
//state.setStatePosition(core::State("qAccept", core::State::Type::ACCEPT), ImVec2(600, 200));
//state.setStatePosition(core::State("qReject", core::State::Type::REJECT), ImVec2(800, 200));
// Main loop
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
std::string title{"Turing Machine GUI"};
if (!state.windowTitle().empty()) {
title += " - " + state.windowTitle();
}
glfwSetWindowTitle(window, title.c_str());
state.updateExecution();
ui::render(state);
// Rendering
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.61, 0.61f, 0.61f, 1.00f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}