1 /* nuklear - 1.32.0 - public domain */
2 #define WIN32_LEAN_AND_MEAN
3 #include <windows.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <time.h>
7 #include <limits.h>
8
9 #define WINDOW_WIDTH 800
10 #define WINDOW_HEIGHT 600
11
12 #define NK_INCLUDE_FIXED_TYPES
13 #define NK_INCLUDE_STANDARD_IO
14 #define NK_INCLUDE_STANDARD_VARARGS
15 #define NK_INCLUDE_DEFAULT_ALLOCATOR
16 #define NK_IMPLEMENTATION
17 #define NK_GDI_IMPLEMENTATION
18 #include "../../nuklear.h"
19 #include "nuklear_gdi.h"
20
21 /* ===============================================================
22 *
23 * EXAMPLE
24 *
25 * ===============================================================*/
26 /* This are some code examples to provide a small overview of what can be
27 * done with this library. To try out an example uncomment the defines */
28 /*#define INCLUDE_ALL */
29 /*#define INCLUDE_STYLE */
30 /*#define INCLUDE_CALCULATOR */
31 /*#define INCLUDE_OVERVIEW */
32 /*#define INCLUDE_NODE_EDITOR */
33
34 #ifdef INCLUDE_ALL
35 #define INCLUDE_STYLE
36 #define INCLUDE_CALCULATOR
37 #define INCLUDE_OVERVIEW
38 #define INCLUDE_NODE_EDITOR
39 #endif
40
41 #ifdef INCLUDE_STYLE
42 #include "../style.c"
43 #endif
44 #ifdef INCLUDE_CALCULATOR
45 #include "../calculator.c"
46 #endif
47 #ifdef INCLUDE_OVERVIEW
48 #include "../overview.c"
49 #endif
50 #ifdef INCLUDE_NODE_EDITOR
51 #include "../node_editor.c"
52 #endif
53
54 /* ===============================================================
55 *
56 * DEMO
57 *
58 * ===============================================================*/
59 static LRESULT CALLBACK
WindowProc(HWND wnd,UINT msg,WPARAM wparam,LPARAM lparam)60 WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
61 {
62 switch (msg)
63 {
64 case WM_DESTROY:
65 PostQuitMessage(0);
66 return 0;
67 }
68
69 if (nk_gdi_handle_event(wnd, msg, wparam, lparam))
70 return 0;
71
72 return DefWindowProcW(wnd, msg, wparam, lparam);
73 }
74
main(void)75 int main(void)
76 {
77 GdiFont* font;
78 struct nk_context *ctx;
79
80 WNDCLASSW wc;
81 ATOM atom;
82 RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
83 DWORD style = WS_OVERLAPPEDWINDOW;
84 DWORD exstyle = WS_EX_APPWINDOW;
85 HWND wnd;
86 HDC dc;
87 int running = 1;
88 int needs_refresh = 1;
89
90 /* Win32 */
91 memset(&wc, 0, sizeof(wc));
92 wc.style = CS_DBLCLKS;
93 wc.lpfnWndProc = WindowProc;
94 wc.hInstance = GetModuleHandleW(0);
95 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
96 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
97 wc.lpszClassName = L"NuklearWindowClass";
98 atom = RegisterClassW(&wc);
99
100 AdjustWindowRectEx(&rect, style, FALSE, exstyle);
101 wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo",
102 style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
103 rect.right - rect.left, rect.bottom - rect.top,
104 NULL, NULL, wc.hInstance, NULL);
105 dc = GetDC(wnd);
106
107 /* GUI */
108 font = nk_gdifont_create("Arial", 14);
109 ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT);
110
111 /* style.c */
112 #ifdef INCLUDE_STYLE
113 /*set_style(ctx, THEME_WHITE);*/
114 /*set_style(ctx, THEME_RED);*/
115 /*set_style(ctx, THEME_BLUE);*/
116 /*set_style(ctx, THEME_DARK);*/
117 #endif
118
119 while (running)
120 {
121 /* Input */
122 MSG msg;
123 nk_input_begin(ctx);
124 if (needs_refresh == 0) {
125 if (GetMessageW(&msg, NULL, 0, 0) <= 0)
126 running = 0;
127 else {
128 TranslateMessage(&msg);
129 DispatchMessageW(&msg);
130 }
131 needs_refresh = 1;
132 } else needs_refresh = 0;
133
134 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
135 if (msg.message == WM_QUIT)
136 running = 0;
137 TranslateMessage(&msg);
138 DispatchMessageW(&msg);
139 needs_refresh = 1;
140 }
141 nk_input_end(ctx);
142
143 /* GUI */
144 if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
145 NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
146 NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
147 {
148 enum {EASY, HARD};
149 static int op = EASY;
150 static int property = 20;
151
152 nk_layout_row_static(ctx, 30, 80, 1);
153 if (nk_button_label(ctx, "button"))
154 fprintf(stdout, "button pressed\n");
155 nk_layout_row_dynamic(ctx, 30, 2);
156 if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
157 if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
158 nk_layout_row_dynamic(ctx, 22, 1);
159 nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
160 }
161 nk_end(ctx);
162
163 /* -------------- EXAMPLES ---------------- */
164 #ifdef INCLUDE_CALCULATOR
165 calculator(ctx);
166 #endif
167 #ifdef INCLUDE_OVERVIEW
168 overview(ctx);
169 #endif
170 #ifdef INCLUDE_NODE_EDITOR
171 node_editor(ctx);
172 #endif
173 /* ----------------------------------------- */
174
175 /* Draw */
176 nk_gdi_render(nk_rgb(30,30,30));
177 }
178
179 nk_gdifont_del(font);
180 ReleaseDC(wnd, dc);
181 UnregisterClassW(wc.lpszClassName, wc.hInstance);
182 return 0;
183 }
184
185