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 <limits.h>
7 #include <time.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_GDIP_IMPLEMENTATION
18 #include "../../nuklear.h"
19 #include "nuklear_gdip.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 case WM_DESTROY:
64 PostQuitMessage(0);
65 return 0;
66 }
67 if (nk_gdip_handle_event(wnd, msg, wparam, lparam))
68 return 0;
69 return DefWindowProcW(wnd, msg, wparam, lparam);
70 }
71
main(void)72 int main(void)
73 {
74 GdipFont* font;
75 struct nk_context *ctx;
76
77 WNDCLASSW wc;
78 RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
79 DWORD style = WS_OVERLAPPEDWINDOW;
80 DWORD exstyle = WS_EX_APPWINDOW;
81 HWND wnd;
82 int running = 1;
83 int needs_refresh = 1;
84
85 /* Win32 */
86 memset(&wc, 0, sizeof(wc));
87 wc.style = CS_DBLCLKS;
88 wc.lpfnWndProc = WindowProc;
89 wc.hInstance = GetModuleHandleW(0);
90 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
91 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
92 wc.lpszClassName = L"NuklearWindowClass";
93 RegisterClassW(&wc);
94
95 AdjustWindowRectEx(&rect, style, FALSE, exstyle);
96
97 wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo",
98 style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
99 rect.right - rect.left, rect.bottom - rect.top,
100 NULL, NULL, wc.hInstance, NULL);
101
102 /* GUI */
103 ctx = nk_gdip_init(wnd, WINDOW_WIDTH, WINDOW_HEIGHT);
104 font = nk_gdipfont_create("Arial", 12);
105 nk_gdip_set_font(font);
106
107 /* style.c */
108 #ifdef INCLUDE_STYLE
109 /*set_style(ctx, THEME_WHITE);*/
110 /*set_style(ctx, THEME_RED);*/
111 /*set_style(ctx, THEME_BLUE);*/
112 /*set_style(ctx, THEME_DARK);*/
113 #endif
114
115 while (running)
116 {
117 /* Input */
118 MSG msg;
119 nk_input_begin(ctx);
120 if (needs_refresh == 0) {
121 if (GetMessageW(&msg, NULL, 0, 0) <= 0)
122 running = 0;
123 else {
124 TranslateMessage(&msg);
125 DispatchMessageW(&msg);
126 }
127 needs_refresh = 1;
128 } else needs_refresh = 0;
129 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
130 if (msg.message == WM_QUIT)
131 running = 0;
132 TranslateMessage(&msg);
133 DispatchMessageW(&msg);
134 needs_refresh = 1;
135 }
136 nk_input_end(ctx);
137
138 /* GUI */
139 if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
140 NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
141 NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
142 {
143 enum {EASY, HARD};
144 static int op = EASY;
145 static int property = 20;
146
147 nk_layout_row_static(ctx, 30, 80, 1);
148 if (nk_button_label(ctx, "button"))
149 fprintf(stdout, "button pressed\n");
150 nk_layout_row_dynamic(ctx, 30, 2);
151 if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
152 if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
153 nk_layout_row_dynamic(ctx, 22, 1);
154 nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
155 }
156 nk_end(ctx);
157
158 /* -------------- EXAMPLES ---------------- */
159 #ifdef INCLUDE_CALCULATOR
160 calculator(ctx);
161 #endif
162 #ifdef INCLUDE_OVERVIEW
163 overview(ctx);
164 #endif
165 #ifdef INCLUDE_NODE_EDITOR
166 node_editor(ctx);
167 #endif
168 /* ----------------------------------------- */
169
170 /* Draw */
171 nk_gdip_render(NK_ANTI_ALIASING_ON, nk_rgb(30,30,30));
172 }
173
174 nk_gdipfont_del(font);
175 nk_gdip_shutdown();
176 UnregisterClassW(wc.lpszClassName, wc.hInstance);
177 return 0;
178 }
179