-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
129 lines (106 loc) · 3.69 KB
/
main.cpp
File metadata and controls
129 lines (106 loc) · 3.69 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "src/ui/notebook.hpp" // Updated include path
#include "imgui.h"
#include "imgui_impl_sdl2.h"
#include "imgui_impl_opengl3.h"
#include <SDL.h>
#include <glad/glad.h>
#include <iostream>
int main(int, char**) {
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
// Configure OpenGL
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
// Create window
SDL_Window* window = SDL_CreateWindow(
"C++ Notebook",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
1280, 720,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
);
if (!window) {
std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
// Create GL context
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (!glContext) {
std::cerr << "SDL_GL_CreateContext Error: " << SDL_GetError() << std::endl;
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// Initialize GLAD
if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) {
std::cerr << "Failed to initialize GLAD" << std::endl;
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// Setup ImGui
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigMacOSXBehaviors = true; // Enable macOS keyboard shortcuts (Cmd instead of Ctrl)
// Setup Platform/Renderer bindings
ImGui_ImplSDL2_InitForOpenGL(window, glContext);
ImGui_ImplOpenGL3_Init("#version 330");
// Load larger fonts for better visibility
ImFontConfig fontConfig;
fontConfig.SizePixels = 18.0f; // Default font size (18pt)
io.Fonts->AddFontDefault(&fontConfig);
// Create much larger font for code (22pt)
fontConfig.SizePixels = 22.0f;
ImFont* codeFont = io.Fonts->AddFontDefault(&fontConfig);
// Create heading fonts
fontConfig.SizePixels = 28.0f; // H1 - 28pt
ImFont* h1Font = io.Fonts->AddFontDefault(&fontConfig);
fontConfig.SizePixels = 24.0f; // H2 - 24pt
ImFont* h2Font = io.Fonts->AddFontDefault(&fontConfig);
fontConfig.SizePixels = 20.0f; // H3 - 20pt
ImFont* h3Font = io.Fonts->AddFontDefault(&fontConfig);
io.Fonts->Build();
// Style
ImGui::StyleColorsDark();
// Notebook state
std::vector<NotebookUtils::Cell> cells;
bool darkMode = true;
std::string selectedFont = "Default";
// Main loop
bool running = true;
while (running) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT)
running = false;
}
// Start frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
// Draw notebook
NotebookUtils::drawNotebook(cells, darkMode, selectedFont);
// Rendering
ImGui::Render();
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}