123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- /* nuklear - 1.32.0 - public domain */
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <limits.h>
- #define WINDOW_WIDTH 800
- #define WINDOW_HEIGHT 600
- #define NK_INCLUDE_FIXED_TYPES
- #define NK_INCLUDE_STANDARD_IO
- #define NK_INCLUDE_STANDARD_VARARGS
- #define NK_INCLUDE_DEFAULT_ALLOCATOR
- #define NK_IMPLEMENTATION
- #define NK_GDI_IMPLEMENTATION
- #include "../../nuklear.h"
- #include "nuklear_gdi.h"
- /* ===============================================================
- *
- * EXAMPLE
- *
- * ===============================================================*/
- /* This are some code examples to provide a small overview of what can be
- * done with this library. To try out an example uncomment the defines */
- /*#define INCLUDE_ALL */
- /*#define INCLUDE_STYLE */
- /*#define INCLUDE_CALCULATOR */
- /*#define INCLUDE_CANVAS */
- #define INCLUDE_OVERVIEW
- /*#define INCLUDE_CONFIGURATOR */
- /*#define INCLUDE_NODE_EDITOR */
- #ifdef INCLUDE_ALL
- #define INCLUDE_STYLE
- #define INCLUDE_CALCULATOR
- #define INCLUDE_CANVAS
- #define INCLUDE_OVERVIEW
- #define INCLUDE_CONFIGURATOR
- #define INCLUDE_NODE_EDITOR
- #endif
- #ifdef INCLUDE_STYLE
- #include "../../demo/common/style.c"
- #endif
- #ifdef INCLUDE_CALCULATOR
- #include "../../demo/common/calculator.c"
- #endif
- #ifdef INCLUDE_CANVAS
- #include "../../demo/common/canvas.c"
- #endif
- #ifdef INCLUDE_OVERVIEW
- #include "../../demo/common/overview.c"
- #endif
- #ifdef INCLUDE_CONFIGURATOR
- #include "../../demo/common/style_configurator.c"
- #endif
- #ifdef INCLUDE_NODE_EDITOR
- #include "../../demo/common/node_editor.c"
- #endif
- /* ===============================================================
- *
- * DEMO
- *
- * ===============================================================*/
- static LRESULT CALLBACK
- WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
- {
- switch (msg)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- if (nk_gdi_handle_event(wnd, msg, wparam, lparam))
- return 0;
- return DefWindowProcW(wnd, msg, wparam, lparam);
- }
- int main(void)
- {
- GdiFont* font;
- struct nk_context *ctx;
- WNDCLASSW wc;
- ATOM atom;
- RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
- DWORD style = WS_OVERLAPPEDWINDOW;
- DWORD exstyle = WS_EX_APPWINDOW;
- HWND wnd;
- HDC dc;
- int running = 1;
- int needs_refresh = 1;
- #ifdef INCLUDE_CONFIGURATOR
- static struct nk_color color_table[NK_COLOR_COUNT];
- memcpy(color_table, nk_default_color_style, sizeof(color_table));
- #endif
- /* Win32 */
- memset(&wc, 0, sizeof(wc));
- wc.style = CS_DBLCLKS;
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = GetModuleHandleW(0);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.lpszClassName = L"NuklearWindowClass";
- atom = RegisterClassW(&wc);
- AdjustWindowRectEx(&rect, style, FALSE, exstyle);
- wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear GDI Demo",
- style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
- rect.right - rect.left, rect.bottom - rect.top,
- NULL, NULL, wc.hInstance, NULL);
- dc = GetDC(wnd);
- /* GUI */
- font = nk_gdifont_create("Arial", 14);
- ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT);
- while (running)
- {
- /* Input */
- MSG msg;
- nk_input_begin(ctx);
- if (needs_refresh == 0) {
- if (GetMessageW(&msg, NULL, 0, 0) <= 0)
- running = 0;
- else {
- TranslateMessage(&msg);
- DispatchMessageW(&msg);
- }
- needs_refresh = 1;
- } else needs_refresh = 0;
- while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
- if (msg.message == WM_QUIT)
- running = 0;
- TranslateMessage(&msg);
- DispatchMessageW(&msg);
- needs_refresh = 1;
- }
- nk_input_end(ctx);
- /* GUI */
- if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
- NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
- NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
- {
- enum {EASY, HARD};
- static int op = EASY;
- static int property = 20;
- nk_layout_row_static(ctx, 30, 80, 1);
- if (nk_button_label(ctx, "button"))
- fprintf(stdout, "button pressed\n");
- nk_layout_row_dynamic(ctx, 30, 2);
- if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
- if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
- nk_layout_row_dynamic(ctx, 22, 1);
- nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- }
- nk_end(ctx);
- /* -------------- EXAMPLES ---------------- */
- #ifdef INCLUDE_CALCULATOR
- calculator(ctx);
- #endif
- #ifdef INCLUDE_CANVAS
- canvas(ctx);
- #endif
- #ifdef INCLUDE_OVERVIEW
- overview(ctx);
- #endif
- #ifdef INCLUDE_CONFIGURATOR
- style_configurator(ctx, color_table);
- #endif
- #ifdef INCLUDE_NODE_EDITOR
- node_editor(ctx);
- #endif
- /* ----------------------------------------- */
- /* Draw */
- nk_gdi_render(nk_rgb(30,30,30));
- }
- nk_gdifont_del(font);
- ReleaseDC(wnd, dc);
- UnregisterClassW(wc.lpszClassName, wc.hInstance);
- return 0;
- }
|