2017-01-15 23:04:51 +03:00
|
|
|
/* nuklear - 1.32.0 - public domain */
|
2016-04-22 07:02:17 +03:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-04-30 21:24:59 +03:00
|
|
|
#include <time.h>
|
|
|
|
#include <limits.h>
|
2016-04-22 07:02:17 +03:00
|
|
|
|
|
|
|
#define WINDOW_WIDTH 800
|
|
|
|
#define WINDOW_HEIGHT 600
|
|
|
|
|
|
|
|
#define NK_INCLUDE_FIXED_TYPES
|
2016-04-30 21:24:59 +03:00
|
|
|
#define NK_INCLUDE_STANDARD_IO
|
2016-08-06 18:44:00 +03:00
|
|
|
#define NK_INCLUDE_STANDARD_VARARGS
|
2016-04-22 07:02:17 +03:00
|
|
|
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
2016-05-01 20:14:48 +03:00
|
|
|
#define NK_IMPLEMENTATION
|
|
|
|
#define NK_GDI_IMPLEMENTATION
|
|
|
|
#include "../../nuklear.h"
|
2016-04-22 07:02:17 +03:00
|
|
|
#include "nuklear_gdi.h"
|
|
|
|
|
2016-04-28 15:38:44 +03:00
|
|
|
/* ===============================================================
|
|
|
|
*
|
|
|
|
* EXAMPLE
|
|
|
|
*
|
|
|
|
* ===============================================================*/
|
|
|
|
/* This are some code examples to provide a small overview of what can be
|
2018-01-01 19:20:55 +03:00
|
|
|
* done with this library. To try out an example uncomment the defines */
|
|
|
|
/*#define INCLUDE_ALL */
|
|
|
|
/*#define INCLUDE_STYLE */
|
|
|
|
/*#define INCLUDE_CALCULATOR */
|
2021-12-16 18:16:33 +03:00
|
|
|
/*#define INCLUDE_CANVAS */
|
2018-01-01 19:20:55 +03:00
|
|
|
/*#define INCLUDE_OVERVIEW */
|
|
|
|
/*#define INCLUDE_NODE_EDITOR */
|
|
|
|
|
|
|
|
#ifdef INCLUDE_ALL
|
|
|
|
#define INCLUDE_STYLE
|
|
|
|
#define INCLUDE_CALCULATOR
|
2021-12-16 18:16:33 +03:00
|
|
|
#define INCLUDE_CANVAS
|
2018-01-01 19:20:55 +03:00
|
|
|
#define INCLUDE_OVERVIEW
|
|
|
|
#define INCLUDE_NODE_EDITOR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INCLUDE_STYLE
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/style.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
|
|
|
#ifdef INCLUDE_CALCULATOR
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/calculator.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
2021-12-16 18:16:33 +03:00
|
|
|
#ifdef INCLUDE_CANVAS
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/canvas.c"
|
2021-12-16 18:16:33 +03:00
|
|
|
#endif
|
2018-01-01 19:20:55 +03:00
|
|
|
#ifdef INCLUDE_OVERVIEW
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/overview.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
|
|
|
#ifdef INCLUDE_NODE_EDITOR
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/node_editor.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
2016-04-28 15:38:44 +03:00
|
|
|
|
|
|
|
/* ===============================================================
|
|
|
|
*
|
|
|
|
* DEMO
|
|
|
|
*
|
|
|
|
* ===============================================================*/
|
2016-04-22 07:02:17 +03:00
|
|
|
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;
|
|
|
|
|
|
|
|
/* Win32 */
|
|
|
|
memset(&wc, 0, sizeof(wc));
|
2017-05-17 08:29:43 +03:00
|
|
|
wc.style = CS_DBLCLKS;
|
2016-04-22 07:02:17 +03:00
|
|
|
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);
|
2022-12-02 02:18:30 +03:00
|
|
|
wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear GDI Demo",
|
2016-04-22 07:02:17 +03:00
|
|
|
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);
|
2016-04-28 15:38:44 +03:00
|
|
|
|
2016-04-22 07:02:17 +03:00
|
|
|
while (running)
|
|
|
|
{
|
|
|
|
/* Input */
|
2016-04-28 15:38:44 +03:00
|
|
|
MSG msg;
|
2016-04-22 07:02:17 +03:00
|
|
|
nk_input_begin(ctx);
|
2016-04-28 15:38:44 +03:00
|
|
|
if (needs_refresh == 0) {
|
2016-04-22 07:02:17 +03:00
|
|
|
if (GetMessageW(&msg, NULL, 0, 0) <= 0)
|
|
|
|
running = 0;
|
2016-04-28 15:38:44 +03:00
|
|
|
else {
|
2016-04-22 07:02:17 +03:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
needs_refresh = 1;
|
2016-04-28 15:38:44 +03:00
|
|
|
} else needs_refresh = 0;
|
|
|
|
|
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
|
2016-04-22 07:02:17 +03:00
|
|
|
if (msg.message == WM_QUIT)
|
|
|
|
running = 0;
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
needs_refresh = 1;
|
|
|
|
}
|
|
|
|
nk_input_end(ctx);
|
|
|
|
|
|
|
|
/* GUI */
|
2016-10-30 00:23:46 +03:00
|
|
|
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
|
2016-04-22 07:02:17 +03:00
|
|
|
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);
|
2016-07-15 19:04:50 +03:00
|
|
|
if (nk_button_label(ctx, "button"))
|
2016-04-22 07:02:17 +03:00
|
|
|
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);
|
|
|
|
}
|
2016-10-30 00:23:46 +03:00
|
|
|
nk_end(ctx);
|
2016-04-22 07:02:17 +03:00
|
|
|
|
2016-04-28 15:38:44 +03:00
|
|
|
/* -------------- EXAMPLES ---------------- */
|
2018-01-01 19:20:55 +03:00
|
|
|
#ifdef INCLUDE_CALCULATOR
|
|
|
|
calculator(ctx);
|
|
|
|
#endif
|
2021-12-16 18:16:33 +03:00
|
|
|
#ifdef INCLUDE_CANVAS
|
|
|
|
canvas(ctx);
|
|
|
|
#endif
|
2018-01-01 19:20:55 +03:00
|
|
|
#ifdef INCLUDE_OVERVIEW
|
|
|
|
overview(ctx);
|
|
|
|
#endif
|
|
|
|
#ifdef INCLUDE_NODE_EDITOR
|
|
|
|
node_editor(ctx);
|
|
|
|
#endif
|
2016-04-28 15:38:44 +03:00
|
|
|
/* ----------------------------------------- */
|
|
|
|
|
2016-04-22 07:02:17 +03:00
|
|
|
/* Draw */
|
|
|
|
nk_gdi_render(nk_rgb(30,30,30));
|
|
|
|
}
|
|
|
|
|
|
|
|
nk_gdifont_del(font);
|
|
|
|
ReleaseDC(wnd, dc);
|
|
|
|
UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|