Skip to content

Commit

Permalink
Created demo using Win32 GDI rendering. Uses VS2015 for compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozeiko committed Apr 22, 2016
1 parent 7536d0d commit d6ada00
Show file tree
Hide file tree
Showing 5 changed files with 870 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
demo/gdi/*.exe
demo/gdi/*.obj
6 changes: 6 additions & 0 deletions demo/gdi/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off

rem This will use VS2015 for compiler
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86

cl /nologo /W3 /WX /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib gdi32.lib /link /incremental:no
130 changes: 130 additions & 0 deletions demo/gdi/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* nuklear - v1.00 - public domain */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <string.h>

#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#include "nuklear_gdi.h"
#include "nuklear_gdi.c"

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));
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 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)
{
MSG msg;

/* Input */
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 */
{struct nk_panel layout;
if (nk_begin(ctx, &layout, "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", NK_BUTTON_DEFAULT))
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);}
if (nk_window_is_closed(ctx, "Demo")) break;

/* Draw */
nk_gdi_render(nk_rgb(30,30,30));
}

nk_gdifont_del(font);
ReleaseDC(wnd, dc);
UnregisterClassW(wc.lpszClassName, wc.hInstance);
return 0;
}

Loading

0 comments on commit d6ada00

Please sign in to comment.