-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
158 lines (131 loc) · 5.55 KB
/
main.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "stdafx.h"
#include "Programmer.h"
//Nice icons. This is a Base85 STB-compressed TTF with icons from the free font entypo by Daniel Bruce
//Glyphs are :
// [ = square
// ] = computer screen
// { = file
// } = left arrow
static const char icons[1585 + 1] =
"7])#######N=6T.'/###[),##-`($#Q6>##kZn426?q)C@->>#a?'o/VNV=B7Xot#S*m<-ve6#5(.0%Ju]v;1B@uu#(,>>#0.d<BjM.R9g'l?-E@pV-TT$=(]GFE$+fG<-%e1p.<_[FH"
":eGb%,Nu3L7-CG)o6Q<Bq>]S.tG<`s>Z+q&0iR/G#MFS7B6wV%g2WA-qmnUC?E,ob_-)#P1G/2B@C=GHFheS%pm1/qm]B,3wdd>$$YO&#+ac8.(Jl>#KT*=()r#Z$;k$C#jF<A'/Jss'"
"alVP&L0v�dQ/LdCFgMTL6uu.P(Z#+lQS%WgJe$uIbA#(7HZ$]BWV$xOF&#BN89&-A###SQs-$C$%?$7#juLo'NZ#S<6&Mi@^rMBN(Po_^]S%%/5##nOSq)2Qxd<3P_-#jH`,#;Dj9`"
"':c'A)Th$'IG:;$>[5/$07C#$?GI&,G)(w-]5FGMm8#&#?=;mLDwCHM.6pfLYia,#Q`-0##1RkX7:L#vpd%1vcUVUM7dBHNMn%s$:)mN%QhR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Dtuf$Z2###*J(v#.c_V$##########_VumqHl###";
static void glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}
#ifdef _WIN32
//unicode version
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
SetProcessDPIAware(); //as a safety measure, but it really should be set in the manifest
//we can use GetSystemMetrics() GetDeviceCaps() or GetDpiForMonitor()
float scale = 1.0;
//retrieve DPI info
HDC dc = GetDC(NULL);
if (dc)
{
int dpix = GetDeviceCaps(dc, LOGPIXELSX); //Win7 compatible
ReleaseDC(NULL, dc);
scale = (float)dpix / 96.0f;
}
#else
int main(int, char**)
{
float scale = 1.0;
#endif
// Setup window
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
return 1;
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow((int)(624.0f*scale), (int)(600.0f*scale), "Programmateur HDMI", NULL, NULL);
if (window == NULL)
return 2;
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
// Setup ImGui binding
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//disable .ini
io.IniFilename = NULL;
// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL2_Init();
// Setup style
ImGui::StyleColorsLight();
ImGui::GetStyle().FrameRounding = 3;
ImGui::GetStyle().WindowRounding = 3;
ImGui::GetStyle().ChildRounding = 3;
ImGui::GetStyle().ScrollbarRounding = 2;
ImGui::GetStyle().GrabRounding = 2;
ImGui::GetStyle().FramePadding = ImVec2(8, 3);
io.Fonts->AddFontDefault();
//font 1
//we make holes in the glyph range for icons
static const ImWchar basic_ranges[] = { 0x0020, '[' - 1, '[' + 1, ']' - 1, ']' + 1, '{' - 1, '{' + 1, '}' - 1, '}' + 1, 0x00FF, 0 };
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeui.ttf", 22.0f*scale, NULL, basic_ranges);
//merge with icons
static const ImWchar icons_ranges[] = { '[','[',']',']','{','{','}','}', 0 };
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
//this font is merged to font 1
io.Fonts->AddFontFromMemoryCompressedBase85TTF(icons, 32.0f*scale, &icons_config, icons_ranges);
//font 2
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\consola.ttf", 14.0f*scale);
io.FontDefault = io.Fonts->Fonts[1];
//scale all gui
ImGui::GetStyle().ScaleAllSizes(scale);
ImVec4 clear_color = ImVec4(0.75, 0.75, 0.75, 1.0);
//Creates programmer
Programmer* prog = new Programmer();
bool shouldClose = false;
// Main loop
while (!shouldClose)
{
// Poll and handle messages (inputs, window resize, etc.)
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
//force full size window
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(io.DisplaySize);
//draw Programmer GUI
shouldClose=prog->render(scale, glfwWindowShouldClose(window));
// Rendering
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
glfwMakeContextCurrent(window);
glfwSwapBuffers(window);
}
//cleanup programmer
delete prog;
// Cleanup
ImGui_ImplOpenGL2_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}