From d4e695420d1e613e9dd9560a0c0f5c22bcedf614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20F=C3=BCchsl?= Date: Fri, 25 Feb 2022 11:13:01 +0100 Subject: [PATCH 01/61] Added GDI full featured window code --- demo/gdi_native_nuklear/build.bat | 6 + demo/gdi_native_nuklear/main.cpp | 37 + demo/gdi_native_nuklear/nuklear_gdi.h | 932 ++++++++++++++++++++++++++ demo/gdi_native_nuklear/window.h | 377 +++++++++++ 4 files changed, 1352 insertions(+) create mode 100644 demo/gdi_native_nuklear/build.bat create mode 100644 demo/gdi_native_nuklear/main.cpp create mode 100644 demo/gdi_native_nuklear/nuklear_gdi.h create mode 100644 demo/gdi_native_nuklear/window.h diff --git a/demo/gdi_native_nuklear/build.bat b/demo/gdi_native_nuklear/build.bat new file mode 100644 index 0000000..65a8ce6 --- /dev/null +++ b/demo/gdi_native_nuklear/build.bat @@ -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 /O2 /fp:fast /Gm- /D_CRT_SECURE_NO_DEPRECATE /Fedemo.exe main.cpp user32.lib gdi32.lib Msimg32.lib /link /incremental:no diff --git a/demo/gdi_native_nuklear/main.cpp b/demo/gdi_native_nuklear/main.cpp new file mode 100644 index 0000000..000ea2a --- /dev/null +++ b/demo/gdi_native_nuklear/main.cpp @@ -0,0 +1,37 @@ +#include +#include + +#pragma comment(linker,"\"/manifestdependency:type='win32' \ +name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ +processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + +#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" + +#define NKGDI_IMPLEMENT_WINDOW +#include "window.h" + +INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, PWSTR _In_ cmdArgs, INT _In_ cmdShow) +{ + NkGdi::Window w1(500, 500, "F1", 10, 10); + w1.AllowSizing = false; + w1.AllowMaximize = false; + w1.AllowMove = false; + w1.HasTitlebar = false; + + NkGdi::Window w2(500, 500, "F2", 520, 10); + w2.AllowSizing = true; + w2.AllowMaximize = true; + w2.AllowMove = true; + w2.HasTitlebar = true; + + while (w1.Update() && w2.Update()) Sleep(20); + + return 0; +} diff --git a/demo/gdi_native_nuklear/nuklear_gdi.h b/demo/gdi_native_nuklear/nuklear_gdi.h new file mode 100644 index 0000000..aef6452 --- /dev/null +++ b/demo/gdi_native_nuklear/nuklear_gdi.h @@ -0,0 +1,932 @@ +/* + * Nuklear - 1.32.0 - public domain + * no warrenty implied; use at your own risk. + * authored from 2015-2016 by Micha Mettke + */ + /* + * ============================================================== + * + * API + * + * =============================================================== + */ +#ifndef NK_GDI_H_ +#define NK_GDI_H_ + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct GdiFont GdiFont; +struct _nk_gdi_ctx; +typedef struct _nk_gdi_ctx* nk_gdi_ctx; + +NK_API struct nk_context* nk_gdi_init(nk_gdi_ctx* gdi, GdiFont* font, HDC window_dc, unsigned int width, unsigned int height); +NK_API int nk_gdi_handle_event(nk_gdi_ctx gdi, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); +NK_API void nk_gdi_render(nk_gdi_ctx gdi, struct nk_color clear); +NK_API void nk_gdi_shutdown(nk_gdi_ctx gdi); + +/* font */ +NK_API GdiFont* nk_gdifont_create(const char* name, int size); +NK_API void nk_gdifont_del(GdiFont* font); +NK_API void nk_gdi_set_font(nk_gdi_ctx gdi, GdiFont* font); + +#ifdef __cplusplus +} +#endif + +#endif + +/* + * ============================================================== + * + * IMPLEMENTATION + * + * =============================================================== + */ +#ifdef NK_GDI_IMPLEMENTATION + +#include +#include + +struct GdiFont { + struct nk_user_font nk; + int height; + HFONT handle; + HDC dc; +}; + +struct _nk_gdi_ctx { + HBITMAP bitmap; + HDC window_dc; + HDC memory_dc; + unsigned int width; + unsigned int height; + struct nk_context ctx; +}; + +static void +nk_create_image(struct nk_image* image, const char* frame_buffer, const int width, const int height) +{ + if (image && frame_buffer && (width > 0) && (height > 0)) + { + const unsigned char* src = (const unsigned char*)frame_buffer; + INT row = ((width * 3 + 3) & ~3); + LPBYTE lpBuf, pb = NULL; + BITMAPINFO bi = { 0 }; + HBITMAP hbm; + int v, i; + + image->w = width; + image->h = height; + image->region[0] = 0; + image->region[1] = 0; + image->region[2] = width; + image->region[3] = height; + + bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bi.bmiHeader.biWidth = width; + bi.bmiHeader.biHeight = height; + bi.bmiHeader.biPlanes = 1; + bi.bmiHeader.biBitCount = 24; + bi.bmiHeader.biCompression = BI_RGB; + bi.bmiHeader.biSizeImage = row * height; + + hbm = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**)&lpBuf, NULL, 0); + + pb = lpBuf + row * height; + for (v = 0; v < height; v++) + { + pb -= row; + for (i = 0; i < row; i += 3) + { + pb[i + 0] = src[0]; + pb[i + 1] = src[1]; + pb[i + 2] = src[2]; + src += 3; + } + } + SetDIBits(NULL, hbm, 0, height, lpBuf, &bi, DIB_RGB_COLORS); + image->handle.ptr = hbm; + } +} + +static void +nk_delete_image(struct nk_image* image) +{ + if (image && image->handle.id != 0) + { + HBITMAP hbm = (HBITMAP)image->handle.ptr; + DeleteObject(hbm); + memset(image, 0, sizeof(struct nk_image)); + } +} + +static void +nk_gdi_draw_image(nk_gdi_ctx gdi, short x, short y, unsigned short w, unsigned short h, + struct nk_image img, struct nk_color col) +{ + HBITMAP hbm = (HBITMAP)img.handle.ptr; + HDC hDCBits; + BITMAP bitmap; + + if (!gdi->memory_dc || !hbm) + return; + + hDCBits = CreateCompatibleDC(gdi->memory_dc); + GetObject(hbm, sizeof(BITMAP), (LPSTR)&bitmap); + SelectObject(hDCBits, hbm); + StretchBlt(gdi->memory_dc, x, y, w, h, hDCBits, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY); + DeleteDC(hDCBits); +} + +static COLORREF +convert_color(struct nk_color c) +{ + return c.r | (c.g << 8) | (c.b << 16); +} + +static void +nk_gdi_scissor(HDC dc, float x, float y, float w, float h) +{ + SelectClipRgn(dc, NULL); + IntersectClipRect(dc, (int)x, (int)y, (int)(x + w + 1), (int)(y + h + 1)); +} + +static void +nk_gdi_stroke_line(HDC dc, short x0, short y0, short x1, + short y1, unsigned int line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + + HPEN pen = NULL; + if (line_thickness == 1) { + SetDCPenColor(dc, color); + } + else { + pen = CreatePen(PS_SOLID, line_thickness, color); + SelectObject(dc, pen); + } + + MoveToEx(dc, x0, y0, NULL); + LineTo(dc, x1, y1); + + if (pen) { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_stroke_rect(HDC dc, short x, short y, unsigned short w, + unsigned short h, unsigned short r, unsigned short line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + HGDIOBJ br; + HPEN pen = NULL; + + if (line_thickness == 1) { + SetDCPenColor(dc, color); + } + else { + pen = CreatePen(PS_SOLID, line_thickness, color); + SelectObject(dc, pen); + } + + br = SelectObject(dc, GetStockObject(NULL_BRUSH)); + if (r == 0) { + Rectangle(dc, x, y, x + w, y + h); + } + else { + RoundRect(dc, x, y, x + w, y + h, r, r); + } + SelectObject(dc, br); + + if (pen) { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_fill_rect(HDC dc, short x, short y, unsigned short w, + unsigned short h, unsigned short r, struct nk_color col) +{ + COLORREF color = convert_color(col); + + if (r == 0) { + RECT rect; + SetRect(&rect, x, y, x + w, y + h); + SetBkColor(dc, color); + ExtTextOutW(dc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); + } + else { + SetDCPenColor(dc, color); + SetDCBrushColor(dc, color); + RoundRect(dc, x, y, x + w, y + h, r, r); + } +} +static void +nk_gdi_set_vertexColor(PTRIVERTEX tri, struct nk_color col) +{ + tri->Red = col.r << 8; + tri->Green = col.g << 8; + tri->Blue = col.b << 8; + tri->Alpha = 0xff << 8; +} + +static void +nk_gdi_rect_multi_color(nk_gdi_ctx gdi, HDC dc, short x, short y, unsigned short w, + unsigned short h, struct nk_color left, struct nk_color top, + struct nk_color right, struct nk_color bottom) +{ + BLENDFUNCTION alphaFunction; + // GRADIENT_RECT gRect; + GRADIENT_TRIANGLE gTri[2]; + TRIVERTEX vt[4]; + alphaFunction.BlendOp = AC_SRC_OVER; + alphaFunction.BlendFlags = 0; + alphaFunction.SourceConstantAlpha = 0; + alphaFunction.AlphaFormat = AC_SRC_ALPHA; + + /* TODO: This Case Needs Repair.*/ + /* Top Left Corner */ + vt[0].x = x; + vt[0].y = y; + nk_gdi_set_vertexColor(&vt[0], left); + /* Top Right Corner */ + vt[1].x = x + w; + vt[1].y = y; + nk_gdi_set_vertexColor(&vt[1], top); + /* Bottom Left Corner */ + vt[2].x = x; + vt[2].y = y + h; + nk_gdi_set_vertexColor(&vt[2], right); + + /* Bottom Right Corner */ + vt[3].x = x + w; + vt[3].y = y + h; + nk_gdi_set_vertexColor(&vt[3], bottom); + + gTri[0].Vertex1 = 0; + gTri[0].Vertex2 = 1; + gTri[0].Vertex3 = 2; + gTri[1].Vertex1 = 2; + gTri[1].Vertex2 = 1; + gTri[1].Vertex3 = 3; + GdiGradientFill(dc, vt, 4, gTri, 2, GRADIENT_FILL_TRIANGLE); + AlphaBlend(gdi->window_dc, x, y, x + w, y + h, gdi->memory_dc, x, y, x + w, y + h, alphaFunction); + +} + +static BOOL +SetPoint(POINT* p, LONG x, LONG y) +{ + if (!p) + return FALSE; + p->x = x; + p->y = y; + return TRUE; +} + +static void +nk_gdi_fill_triangle(HDC dc, short x0, short y0, short x1, + short y1, short x2, short y2, struct nk_color col) +{ + COLORREF color = convert_color(col); + POINT points[3]; + + SetPoint(&points[0], x0, y0); + SetPoint(&points[1], x1, y1); + SetPoint(&points[2], x2, y2); + + SetDCPenColor(dc, color); + SetDCBrushColor(dc, color); + Polygon(dc, points, 3); +} + +static void +nk_gdi_stroke_triangle(HDC dc, short x0, short y0, short x1, + short y1, short x2, short y2, unsigned short line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + POINT points[4]; + HPEN pen = NULL; + + SetPoint(&points[0], x0, y0); + SetPoint(&points[1], x1, y1); + SetPoint(&points[2], x2, y2); + SetPoint(&points[3], x0, y0); + + if (line_thickness == 1) { + SetDCPenColor(dc, color); + } + else { + pen = CreatePen(PS_SOLID, line_thickness, color); + SelectObject(dc, pen); + } + + Polyline(dc, points, 4); + + if (pen) { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_fill_polygon(HDC dc, const struct nk_vec2i* pnts, int count, struct nk_color col) +{ + int i = 0; +#define MAX_POINTS 64 + POINT points[MAX_POINTS]; + COLORREF color = convert_color(col); + SetDCBrushColor(dc, color); + SetDCPenColor(dc, color); + for (i = 0; i < count && i < MAX_POINTS; ++i) { + points[i].x = pnts[i].x; + points[i].y = pnts[i].y; + } + Polygon(dc, points, i); +#undef MAX_POINTS +} + +static void +nk_gdi_stroke_polygon(HDC dc, const struct nk_vec2i* pnts, int count, + unsigned short line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + HPEN pen = NULL; + if (line_thickness == 1) { + SetDCPenColor(dc, color); + } + else { + pen = CreatePen(PS_SOLID, line_thickness, color); + SelectObject(dc, pen); + } + + if (count > 0) { + int i; + MoveToEx(dc, pnts[0].x, pnts[0].y, NULL); + for (i = 1; i < count; ++i) + LineTo(dc, pnts[i].x, pnts[i].y); + LineTo(dc, pnts[0].x, pnts[0].y); + } + + if (pen) { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_stroke_polyline(HDC dc, const struct nk_vec2i* pnts, + int count, unsigned short line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + HPEN pen = NULL; + if (line_thickness == 1) { + SetDCPenColor(dc, color); + } + else { + pen = CreatePen(PS_SOLID, line_thickness, color); + SelectObject(dc, pen); + } + + if (count > 0) { + int i; + MoveToEx(dc, pnts[0].x, pnts[0].y, NULL); + for (i = 1; i < count; ++i) + LineTo(dc, pnts[i].x, pnts[i].y); + } + + if (pen) { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_fill_circle(HDC dc, short x, short y, unsigned short w, + unsigned short h, struct nk_color col) +{ + COLORREF color = convert_color(col); + SetDCBrushColor(dc, color); + SetDCPenColor(dc, color); + Ellipse(dc, x, y, x + w, y + h); +} + +static void +nk_gdi_stroke_circle(HDC dc, short x, short y, unsigned short w, + unsigned short h, unsigned short line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + HPEN pen = NULL; + if (line_thickness == 1) { + SetDCPenColor(dc, color); + } + else { + pen = CreatePen(PS_SOLID, line_thickness, color); + SelectObject(dc, pen); + } + + SetDCBrushColor(dc, OPAQUE); + Ellipse(dc, x, y, x + w, y + h); + + if (pen) { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_stroke_curve(HDC dc, struct nk_vec2i p1, + struct nk_vec2i p2, struct nk_vec2i p3, struct nk_vec2i p4, + unsigned short line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + POINT p[4]; + HPEN pen = NULL; + + SetPoint(&p[0], p1.x, p1.y); + SetPoint(&p[1], p2.x, p2.y); + SetPoint(&p[2], p3.x, p3.y); + SetPoint(&p[3], p4.x, p4.y); + + if (line_thickness == 1) { + SetDCPenColor(dc, color); + } + else { + pen = CreatePen(PS_SOLID, line_thickness, color); + SelectObject(dc, pen); + } + + SetDCBrushColor(dc, OPAQUE); + PolyBezier(dc, p, 4); + + if (pen) { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_draw_text(HDC dc, short x, short y, unsigned short w, unsigned short h, + const char* text, int len, GdiFont* font, struct nk_color cbg, struct nk_color cfg) +{ + int wsize; + WCHAR* wstr; + + if (!text || !font || !len) return; + + wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); + wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t)); + MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); + + SetBkColor(dc, convert_color(cbg)); + SetTextColor(dc, convert_color(cfg)); + + SelectObject(dc, font->handle); + ExtTextOutW(dc, x, y, ETO_OPAQUE, NULL, wstr, wsize, NULL); +} + +static void +nk_gdi_clear(nk_gdi_ctx gdi, HDC dc, struct nk_color col) +{ + COLORREF color = convert_color(col); + RECT rect; + SetRect(&rect, 0, 0, gdi->width, gdi->height); + SetBkColor(dc, color); + + ExtTextOutW(dc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); +} + +static void +nk_gdi_blit(nk_gdi_ctx gdi, HDC dc) +{ + BitBlt(dc, 0, 0, gdi->width, gdi->height, gdi->memory_dc, 0, 0, SRCCOPY); + +} + +GdiFont* +nk_gdifont_create(const char* name, int size) +{ + TEXTMETRICW metric; + GdiFont* font = (GdiFont*)calloc(1, sizeof(GdiFont)); + if (!font) + return NULL; + font->dc = CreateCompatibleDC(0); + font->handle = CreateFontA(size, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE, name); + SelectObject(font->dc, font->handle); + GetTextMetricsW(font->dc, &metric); + font->height = metric.tmHeight; + return font; +} + +static float +nk_gdifont_get_text_width(nk_handle handle, float height, const char* text, int len) +{ + GdiFont* font = (GdiFont*)handle.ptr; + SIZE size; + int wsize; + WCHAR* wstr; + if (!font || !text) + return 0; + + wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); + wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t)); + MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); + if (GetTextExtentPoint32W(font->dc, wstr, wsize, &size)) + return (float)size.cx; + return -1.0f; +} + +void +nk_gdifont_del(GdiFont* font) +{ + if (!font) return; + DeleteObject(font->handle); + DeleteDC(font->dc); + free(font); +} + +static void +nk_gdi_clipboard_paste(nk_handle usr, struct nk_text_edit* edit) +{ + (void)usr; + if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) + { + HGLOBAL mem = GetClipboardData(CF_UNICODETEXT); + if (mem) + { + SIZE_T size = GlobalSize(mem) - 1; + if (size) + { + LPCWSTR wstr = (LPCWSTR)GlobalLock(mem); + if (wstr) + { + int utf8size = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), NULL, 0, NULL, NULL); + if (utf8size) + { + char* utf8 = (char*)malloc(utf8size); + if (utf8) + { + WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), utf8, utf8size, NULL, NULL); + nk_textedit_paste(edit, utf8, utf8size); + free(utf8); + } + } + GlobalUnlock(mem); + } + } + } + CloseClipboard(); + } +} + +static void +nk_gdi_clipboard_copy(nk_handle usr, const char* text, int len) +{ + if (OpenClipboard(NULL)) + { + int wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); + if (wsize) + { + HGLOBAL mem = (HGLOBAL)GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t)); + if (mem) + { + wchar_t* wstr = (wchar_t*)GlobalLock(mem); + if (wstr) + { + MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); + wstr[wsize] = 0; + GlobalUnlock(mem); + + SetClipboardData(CF_UNICODETEXT, mem); + } + } + } + CloseClipboard(); + } +} + +NK_API struct nk_context* +nk_gdi_init(nk_gdi_ctx* gdi, GdiFont* gdifont, HDC window_dc, unsigned int width, unsigned int height) +{ + *gdi = (nk_gdi_ctx)malloc(sizeof(struct _nk_gdi_ctx)); + + struct nk_user_font* font = &gdifont->nk; + font->userdata = nk_handle_ptr(gdifont); + font->height = (float)gdifont->height; + font->width = nk_gdifont_get_text_width; + + (*gdi)->bitmap = CreateCompatibleBitmap(window_dc, width, height); + (*gdi)->window_dc = window_dc; + (*gdi)->memory_dc = CreateCompatibleDC(window_dc); + (*gdi)->width = width; + (*gdi)->height = height; + SelectObject((*gdi)->memory_dc, (*gdi)->bitmap); + + nk_init_default(&(*gdi)->ctx, font); + (*gdi)->ctx.clip.copy = nk_gdi_clipboard_copy; + (*gdi)->ctx.clip.paste = nk_gdi_clipboard_paste; + return &(*gdi)->ctx; +} + +NK_API void +nk_gdi_set_font(nk_gdi_ctx gdi, GdiFont* gdifont) +{ + struct nk_user_font* font = &gdifont->nk; + font->userdata = nk_handle_ptr(gdifont); + font->height = (float)gdifont->height; + font->width = nk_gdifont_get_text_width; + nk_style_set_font(&gdi->ctx, font); +} + +NK_API int +nk_gdi_handle_event(nk_gdi_ctx gdi, HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + switch (msg) + { + case WM_SIZE: + { + unsigned width = LOWORD(lparam); + unsigned height = HIWORD(lparam); + if (width != gdi->width || height != gdi->height) + { + DeleteObject(gdi->bitmap); + gdi->bitmap = CreateCompatibleBitmap(gdi->window_dc, width, height); + gdi->width = width; + gdi->height = height; + SelectObject(gdi->memory_dc, gdi->bitmap); + } + break; + } + + case WM_PAINT: + { + PAINTSTRUCT paint; + HDC dc = BeginPaint(wnd, &paint); + nk_gdi_blit(gdi, dc); + EndPaint(wnd, &paint); + return 1; + } + + case WM_KEYDOWN: + case WM_KEYUP: + case WM_SYSKEYDOWN: + case WM_SYSKEYUP: + { + int down = !((lparam >> 31) & 1); + int ctrl = GetKeyState(VK_CONTROL) & (1 << 15); + + switch (wparam) + { + case VK_SHIFT: + case VK_LSHIFT: + case VK_RSHIFT: + nk_input_key(&gdi->ctx, NK_KEY_SHIFT, down); + return 1; + + case VK_DELETE: + nk_input_key(&gdi->ctx, NK_KEY_DEL, down); + return 1; + + case VK_RETURN: + nk_input_key(&gdi->ctx, NK_KEY_ENTER, down); + return 1; + + case VK_TAB: + nk_input_key(&gdi->ctx, NK_KEY_TAB, down); + return 1; + + case VK_LEFT: + if (ctrl) + nk_input_key(&gdi->ctx, NK_KEY_TEXT_WORD_LEFT, down); + else + nk_input_key(&gdi->ctx, NK_KEY_LEFT, down); + return 1; + + case VK_RIGHT: + if (ctrl) + nk_input_key(&gdi->ctx, NK_KEY_TEXT_WORD_RIGHT, down); + else + nk_input_key(&gdi->ctx, NK_KEY_RIGHT, down); + return 1; + + case VK_BACK: + nk_input_key(&gdi->ctx, NK_KEY_BACKSPACE, down); + return 1; + + case VK_HOME: + nk_input_key(&gdi->ctx, NK_KEY_TEXT_START, down); + nk_input_key(&gdi->ctx, NK_KEY_SCROLL_START, down); + return 1; + + case VK_END: + nk_input_key(&gdi->ctx, NK_KEY_TEXT_END, down); + nk_input_key(&gdi->ctx, NK_KEY_SCROLL_END, down); + return 1; + + case VK_NEXT: + nk_input_key(&gdi->ctx, NK_KEY_SCROLL_DOWN, down); + return 1; + + case VK_PRIOR: + nk_input_key(&gdi->ctx, NK_KEY_SCROLL_UP, down); + return 1; + + case 'C': + if (ctrl) { + nk_input_key(&gdi->ctx, NK_KEY_COPY, down); + return 1; + } + break; + + case 'V': + if (ctrl) { + nk_input_key(&gdi->ctx, NK_KEY_PASTE, down); + return 1; + } + break; + + case 'X': + if (ctrl) { + nk_input_key(&gdi->ctx, NK_KEY_CUT, down); + return 1; + } + break; + + case 'Z': + if (ctrl) { + nk_input_key(&gdi->ctx, NK_KEY_TEXT_UNDO, down); + return 1; + } + break; + + case 'R': + if (ctrl) { + nk_input_key(&gdi->ctx, NK_KEY_TEXT_REDO, down); + return 1; + } + break; + } + return 0; + } + + case WM_CHAR: + if (wparam >= 32) + { + nk_input_unicode(&gdi->ctx, (nk_rune)wparam); + return 1; + } + break; + + case WM_LBUTTONDOWN: + nk_input_button(&gdi->ctx, NK_BUTTON_LEFT, (short)LOWORD(lparam), (short)HIWORD(lparam), 1); + SetCapture(wnd); + return 1; + + case WM_LBUTTONUP: + nk_input_button(&gdi->ctx, NK_BUTTON_DOUBLE, (short)LOWORD(lparam), (short)HIWORD(lparam), 0); + nk_input_button(&gdi->ctx, NK_BUTTON_LEFT, (short)LOWORD(lparam), (short)HIWORD(lparam), 0); + ReleaseCapture(); + return 1; + + case WM_RBUTTONDOWN: + nk_input_button(&gdi->ctx, NK_BUTTON_RIGHT, (short)LOWORD(lparam), (short)HIWORD(lparam), 1); + SetCapture(wnd); + return 1; + + case WM_RBUTTONUP: + nk_input_button(&gdi->ctx, NK_BUTTON_RIGHT, (short)LOWORD(lparam), (short)HIWORD(lparam), 0); + ReleaseCapture(); + return 1; + + case WM_MBUTTONDOWN: + nk_input_button(&gdi->ctx, NK_BUTTON_MIDDLE, (short)LOWORD(lparam), (short)HIWORD(lparam), 1); + SetCapture(wnd); + return 1; + + case WM_MBUTTONUP: + nk_input_button(&gdi->ctx, NK_BUTTON_MIDDLE, (short)LOWORD(lparam), (short)HIWORD(lparam), 0); + ReleaseCapture(); + return 1; + + case WM_MOUSEWHEEL: + nk_input_scroll(&gdi->ctx, nk_vec2(0, (float)(short)HIWORD(wparam) / WHEEL_DELTA)); + return 1; + + case WM_MOUSEMOVE: + nk_input_motion(&gdi->ctx, (short)LOWORD(lparam), (short)HIWORD(lparam)); + return 1; + + case WM_LBUTTONDBLCLK: + nk_input_button(&gdi->ctx, NK_BUTTON_DOUBLE, (short)LOWORD(lparam), (short)HIWORD(lparam), 1); + return 1; + } + + return 0; +} + +NK_API void +nk_gdi_shutdown(nk_gdi_ctx gdi) +{ + DeleteObject(gdi->memory_dc); + DeleteObject(gdi->bitmap); + nk_free(&gdi->ctx); +} + +NK_API void +nk_gdi_render(nk_gdi_ctx gdi, struct nk_color clear) +{ + const struct nk_command* cmd; + + HDC memory_dc = gdi->memory_dc; + SelectObject(memory_dc, GetStockObject(DC_PEN)); + SelectObject(memory_dc, GetStockObject(DC_BRUSH)); + nk_gdi_clear(gdi, memory_dc, clear); + + nk_foreach(cmd, &gdi->ctx) + { + switch (cmd->type) { + case NK_COMMAND_NOP: break; + case NK_COMMAND_SCISSOR: { + const struct nk_command_scissor* s = (const struct nk_command_scissor*)cmd; + nk_gdi_scissor(memory_dc, s->x, s->y, s->w, s->h); + } break; + case NK_COMMAND_LINE: { + const struct nk_command_line* l = (const struct nk_command_line*)cmd; + nk_gdi_stroke_line(memory_dc, l->begin.x, l->begin.y, l->end.x, + l->end.y, l->line_thickness, l->color); + } break; + case NK_COMMAND_RECT: { + const struct nk_command_rect* r = (const struct nk_command_rect*)cmd; + nk_gdi_stroke_rect(memory_dc, r->x, r->y, r->w, r->h, + (unsigned short)r->rounding, r->line_thickness, r->color); + } break; + case NK_COMMAND_RECT_FILLED: { + const struct nk_command_rect_filled* r = (const struct nk_command_rect_filled*)cmd; + nk_gdi_fill_rect(memory_dc, r->x, r->y, r->w, r->h, + (unsigned short)r->rounding, r->color); + } break; + case NK_COMMAND_CIRCLE: { + const struct nk_command_circle* c = (const struct nk_command_circle*)cmd; + nk_gdi_stroke_circle(memory_dc, c->x, c->y, c->w, c->h, c->line_thickness, c->color); + } break; + case NK_COMMAND_CIRCLE_FILLED: { + const struct nk_command_circle_filled* c = (const struct nk_command_circle_filled*)cmd; + nk_gdi_fill_circle(memory_dc, c->x, c->y, c->w, c->h, c->color); + } break; + case NK_COMMAND_TRIANGLE: { + const struct nk_command_triangle* t = (const struct nk_command_triangle*)cmd; + nk_gdi_stroke_triangle(memory_dc, t->a.x, t->a.y, t->b.x, t->b.y, + t->c.x, t->c.y, t->line_thickness, t->color); + } break; + case NK_COMMAND_TRIANGLE_FILLED: { + const struct nk_command_triangle_filled* t = (const struct nk_command_triangle_filled*)cmd; + nk_gdi_fill_triangle(memory_dc, t->a.x, t->a.y, t->b.x, t->b.y, + t->c.x, t->c.y, t->color); + } break; + case NK_COMMAND_POLYGON: { + const struct nk_command_polygon* p = (const struct nk_command_polygon*)cmd; + nk_gdi_stroke_polygon(memory_dc, p->points, p->point_count, p->line_thickness, p->color); + } break; + case NK_COMMAND_POLYGON_FILLED: { + const struct nk_command_polygon_filled* p = (const struct nk_command_polygon_filled*)cmd; + nk_gdi_fill_polygon(memory_dc, p->points, p->point_count, p->color); + } break; + case NK_COMMAND_POLYLINE: { + const struct nk_command_polyline* p = (const struct nk_command_polyline*)cmd; + nk_gdi_stroke_polyline(memory_dc, p->points, p->point_count, p->line_thickness, p->color); + } break; + case NK_COMMAND_TEXT: { + const struct nk_command_text* t = (const struct nk_command_text*)cmd; + nk_gdi_draw_text(memory_dc, t->x, t->y, t->w, t->h, + (const char*)t->string, t->length, + (GdiFont*)t->font->userdata.ptr, + t->background, t->foreground); + } break; + case NK_COMMAND_CURVE: { + const struct nk_command_curve* q = (const struct nk_command_curve*)cmd; + nk_gdi_stroke_curve(memory_dc, q->begin, q->ctrl[0], q->ctrl[1], + q->end, q->line_thickness, q->color); + } break; + case NK_COMMAND_RECT_MULTI_COLOR: { + const struct nk_command_rect_multi_color* r = (const struct nk_command_rect_multi_color*)cmd; + nk_gdi_rect_multi_color(gdi, memory_dc, r->x, r->y, r->w, r->h, r->left, r->top, r->right, r->bottom); + } break; + case NK_COMMAND_IMAGE: { + const struct nk_command_image* i = (const struct nk_command_image*)cmd; + nk_gdi_draw_image(gdi, i->x, i->y, i->w, i->h, i->img, i->col); + } break; + case NK_COMMAND_ARC: + case NK_COMMAND_ARC_FILLED: + default: break; + } + } + nk_gdi_blit(gdi, gdi->window_dc); + nk_clear(&gdi->ctx); +} + +#endif diff --git a/demo/gdi_native_nuklear/window.h b/demo/gdi_native_nuklear/window.h new file mode 100644 index 0000000..123e4a7 --- /dev/null +++ b/demo/gdi_native_nuklear/window.h @@ -0,0 +1,377 @@ +#pragma once + +namespace NkGdi +{ + // Container for window management + class WindowClass + { + public: + // Public exposed name + static const wchar_t* const ClassName; + + WindowClass(const WindowClass&) = delete; + private: + // Instance + static WindowClass ClassInstance; + + // Sigelton + WindowClass(); + }; + + // Window base class + class Window + { + friend class WindowClass; + + public: + // Default constructs + Window() = default; + Window(const Window&) = delete; + Window(Window&&) = default; + // Constructor + Window(unsigned int width, unsigned int height, const char* name, int posX = 100, int posY = 100); + // Destructor + ~Window(); + + // Processs window events and render the window (returns true as long as window is open) + bool Update(); + + // Properties + bool AllowSizing = true; + bool AllowMaximize = true; + bool AllowMove = true; + bool HasTitlebar = true; + + public: + // Called when the core window gets an event + virtual LRESULT OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); + + // Called when the window is created + inline virtual void OnCreate() {}; + // Called when the window is destroyed + inline virtual void OnDestroy() {}; + // Called when the windows is beein updated (before events are served) + inline virtual void OnUpdate() {}; + // Called when the window is beeing closed by the user (return false to abort) + inline virtual bool OnClose() { return true; }; + // Called when nuklear drawcalls can be issued (return false to close the window) + inline virtual bool OnDraw(nk_context* ctx) { return true; }; + + private: + // Static window procs + static LRESULT wndProcSetup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); + static LRESULT wndProcRun(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); + + private: + // Window handle + HWND m_window = NULL; + + // Nuklear context + nk_gdi_ctx m_nkGdiCtx = nullptr; + nk_context* m_nkCtx = nullptr; + + // Nuklear objects + GdiFont* m_gdiFont = nullptr; + HDC m_windowDc = NULL; + + // Window runtime features + bool m_isOpen = true; + bool m_isDraggin = false; + bool m_wsOverride = false; + bool m_isMaximized = false; + POINT m_dragOffset = {}; + int m_width = 0; + int m_height = 0; + }; +} + +#ifdef NKGDI_IMPLEMENT_WINDOW + +const wchar_t* const NkGdi::WindowClass::ClassName = L"WNDCLS_NkGdi"; +NkGdi::WindowClass NkGdi::WindowClass::ClassInstance; + +NkGdi::WindowClass::WindowClass() +{ + // Describe class + WNDCLASSEXW cls; + cls.cbSize = sizeof(WNDCLASSEXW); + cls.style = CS_OWNDC | CS_DBLCLKS; + cls.lpfnWndProc = &Window::wndProcSetup; + cls.cbClsExtra = 0; + cls.cbWndExtra = 0; + cls.hInstance = GetModuleHandle(NULL); + cls.hIcon = LoadIcon(NULL, IDI_APPLICATION); + cls.hCursor = LoadCursor(NULL, IDC_ARROW); + cls.hbrBackground = NULL; + cls.lpszMenuName = nullptr; + cls.lpszClassName = ClassName; + cls.hIconSm = NULL; + + // Register class + RegisterClassExW(&cls); +} + +NkGdi::Window::Window(unsigned int width, unsigned int height, const char* name, int posX, int posY) +{ + DWORD styleEx = WS_EX_WINDOWEDGE; + DWORD style = WS_POPUP; + + // Compute window size + RECT cr; + cr.left = 0; + cr.top = 0; + cr.right = width; + cr.bottom = height; + AdjustWindowRectEx(&cr, style, FALSE, styleEx); + + // Create the window + m_window = CreateWindowExW( + styleEx, + WindowClass::ClassName, + L"NkGdi", + style | WS_VISIBLE, + posX, posY, + cr.right - cr.left, cr.bottom - cr.top, + NULL, NULL, + GetModuleHandleW(nullptr), + this + ); + + // Rename window to user picked name + SetWindowTextA(m_window, name); + + // Get DC + m_windowDc = GetWindowDC(m_window); + + // Create font + m_gdiFont = nk_gdifont_create("Arial", 16); + m_nkCtx = nk_gdi_init(&m_nkGdiCtx, m_gdiFont, m_windowDc, width, height); +} + +NkGdi::Window::~Window() +{ + // Destroy GDI context + if (m_nkGdiCtx) + { + nk_gdi_shutdown(m_nkGdiCtx); + } + + // Destroy font + if (m_gdiFont) + { + nk_gdifont_del(m_gdiFont); + } + + // Close DC + if (m_windowDc) + { + ReleaseDC(m_window, m_windowDc); + } + + // Destroy window + if (m_window) + { + CloseWindow(m_window); + DestroyWindow(m_window); + } +} + +bool NkGdi::Window::Update() +{ + // Only process events while window is open + if (m_isOpen) + { + // Notify class that event processing has stated + OnUpdate(); + + // Windows event loop + MSG msg = {}; + nk_input_begin(m_nkCtx); + while (PeekMessage(&msg, m_window, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + nk_input_end(m_nkCtx); + + // Get title + char title[1024]; + GetWindowTextA(m_window, title, 1024); + + // Window body + if (m_wsOverride) + nk_window_set_bounds(m_nkCtx, title, nk_rect(0, 0, m_width, m_height)); + if (nk_begin(m_nkCtx, title, nk_rect(0, 0, m_width, m_height), + NK_WINDOW_BORDER | + (HasTitlebar ? NK_WINDOW_CLOSABLE | NK_WINDOW_TITLE : NULL) | + (m_isMaximized || !AllowSizing ? NULL : NK_WINDOW_SCALABLE) + )) + { + if(!OnDraw(m_nkCtx)) + m_isOpen = false; + + // Update window size + struct nk_rect bounds = nk_window_get_bounds(m_nkCtx); + if(bounds.w != m_width || bounds.h != m_height) + SetWindowPos(m_window, NULL, 0, 0, bounds.w, bounds.h, SWP_NOMOVE | SWP_NOOWNERZORDER); + } + else + { + // Handle window closing + if(OnClose()) + m_isOpen = false; + } + nk_end(m_nkCtx); + m_wsOverride = false; + + // Final render pass + nk_gdi_render(m_nkGdiCtx, nk_rgb(30, 30, 30)); + } + + return m_isOpen; +} + +LRESULT NkGdi::Window::OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + // Switch on supplied message code + switch (msg) + { + // Close event + case WM_CLOSE: + if (OnClose()) + m_isOpen = false; + return 0; // Will always be handled internaly + + // While sizing + case WM_SIZING: + { + RECT cr; + GetClientRect(wnd, &cr); + m_width = cr.right - cr.left; + m_height = cr.bottom - cr.top; + } + break; + + // When sized + case WM_SIZE: + { + // Adjust maximize properties + if (wParam == SIZE_MAXIMIZED) + { + HMONITOR monitor = MonitorFromWindow(wnd, MONITOR_DEFAULTTOPRIMARY); + MONITORINFO monitorInfo; + monitorInfo.cbSize = sizeof(MONITORINFO); + if (GetMonitorInfoW(monitor, &monitorInfo)) + { + m_height = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; + m_width = monitorInfo.rcWork.right - monitorInfo.rcWork.left; + m_wsOverride = true; + m_isMaximized = true; + SetWindowPos(wnd, NULL, 0, 0, m_width, m_height, SWP_NOMOVE | SWP_NOZORDER); + } + } + else if (wParam == SIZE_RESTORED) + { + m_isMaximized = false; + } + + // Compute new bounds + RECT cr; + GetClientRect(wnd, &cr); + m_width = cr.right - cr.left; + m_height = cr.bottom - cr.top; + } + break; + + // When mouse start l-press (drag window) + case WM_LBUTTONDOWN: + { + if (HIWORD(lParam) <= 30 && AllowMove) + { + // Start dragging + m_isDraggin = true; + m_dragOffset.x = LOWORD(lParam); + m_dragOffset.y = HIWORD(lParam); + } + } + break; + + // When mouse stops l-press (drag window) + case WM_LBUTTONUP: + m_isDraggin = false; + break; + + // Mouse movement (dragging) + case WM_MOUSEMOVE: + { + if (m_isDraggin && !m_isMaximized) + { + // Get mouse postion and substract offset + POINT cursorPos; + GetCursorPos(&cursorPos); + cursorPos.x -= m_dragOffset.x; + cursorPos.y -= m_dragOffset.y; + // Use as new position + ShowWindow(m_window, SW_RESTORE); + SetWindowPos(wnd, NULL, cursorPos.x, cursorPos.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + } + } + break; + + // On mouse doubble click (maximize) + case WM_LBUTTONDBLCLK: + { + if (HIWORD(lParam) <= 30 && AllowMaximize) + { + if (m_isMaximized) + { + ShowWindow(wnd, SW_RESTORE); + } + else + { + ShowWindow(wnd, SW_MAXIMIZE); + } + m_wsOverride = true; + } + } + break; + } + + // Send to nuklear + if (m_nkGdiCtx && nk_gdi_handle_event(m_nkGdiCtx, wnd, msg, wParam, lParam)) + return 0; + + // In case this is ever reached: Run default behaviour + return DefWindowProc(wnd, msg, wParam, lParam); +} + +LRESULT NkGdi::Window::wndProcSetup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + // Wait for setup message + if (msg == WM_NCCREATE) + { + // Get creation parameters & window pointer + CREATESTRUCT* ptrCr = (CREATESTRUCT*)lParam; + Window* ptrWindow = (Window*)ptrCr->lpCreateParams; + + // Store pointer and new proc in window + SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR)ptrWindow); + SetWindowLongPtr(wnd, GWLP_WNDPROC, (LONG_PTR)&wndProcRun); + + // Handled by window + return ptrWindow->OnWindowMessage(wnd, msg, wParam, lParam); + } + + // Default handler + return DefWindowProc(wnd, msg, wParam, lParam); +} + +LRESULT NkGdi::Window::wndProcRun(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + // Get window pointer + Window* ptrWindow = (Window*)GetWindowLongPtr(wnd, GWLP_USERDATA); + // Call window + return ptrWindow->OnWindowMessage(wnd, msg, wParam, lParam); +} + +#endif From 169470d2e3bfcea4956aeb5ae82a127f29f5afaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20F=C3=BCchsl?= Date: Mon, 28 Feb 2022 14:57:47 +0100 Subject: [PATCH 02/61] Converted from C++ to C WARNING: Is currently not working! Needs more debugging. --- demo/gdi_native_nuklear/build.bat | 2 +- demo/gdi_native_nuklear/{main.cpp => main.c} | 25 +- demo/gdi_native_nuklear/window.h | 356 +++++++++---------- 3 files changed, 183 insertions(+), 200 deletions(-) rename demo/gdi_native_nuklear/{main.cpp => main.c} (61%) diff --git a/demo/gdi_native_nuklear/build.bat b/demo/gdi_native_nuklear/build.bat index 65a8ce6..2f87f8e 100644 --- a/demo/gdi_native_nuklear/build.bat +++ b/demo/gdi_native_nuklear/build.bat @@ -3,4 +3,4 @@ rem This will use VS2015 for compiler call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 -cl /nologo /W3 /O2 /fp:fast /Gm- /D_CRT_SECURE_NO_DEPRECATE /Fedemo.exe main.cpp user32.lib gdi32.lib Msimg32.lib /link /incremental:no +cl /nologo /W3 /O2 /fp:fast /Gm- /D_CRT_SECURE_NO_DEPRECATE /Fedemo.exe main.c user32.lib gdi32.lib Msimg32.lib /link /incremental:no diff --git a/demo/gdi_native_nuklear/main.cpp b/demo/gdi_native_nuklear/main.c similarity index 61% rename from demo/gdi_native_nuklear/main.cpp rename to demo/gdi_native_nuklear/main.c index 000ea2a..70ba268 100644 --- a/demo/gdi_native_nuklear/main.cpp +++ b/demo/gdi_native_nuklear/main.c @@ -1,5 +1,4 @@ #include -#include #pragma comment(linker,"\"/manifestdependency:type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ @@ -19,19 +18,21 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, PWSTR _In_ cmdArgs, INT _In_ cmdShow) { - NkGdi::Window w1(500, 500, "F1", 10, 10); - w1.AllowSizing = false; - w1.AllowMaximize = false; - w1.AllowMove = false; - w1.HasTitlebar = false; + struct nkgdi_window w1, w2; - NkGdi::Window w2(500, 500, "F2", 520, 10); - w2.AllowSizing = true; - w2.AllowMaximize = true; - w2.AllowMove = true; - w2.HasTitlebar = true; + w1.allow_sizing = 0; + w1.allow_maximize = 0; + w1.allow_move = 0; + w1.has_titlebar = 0; + nkgdi_window_create(&w1, 500, 500, "F1", 10, 10); + + w2.allow_sizing = 1; + w2.allow_maximize = 1; + w2.allow_move = 1; + w2.has_titlebar = 1; + nkgdi_window_create(&w2, 500, 500, "F2", 520, 10); - while (w1.Update() && w2.Update()) Sleep(20); + while (nkgdi_window_update(&w1) && nkgdi_window_update(&w2)) Sleep(20); return 0; } diff --git a/demo/gdi_native_nuklear/window.h b/demo/gdi_native_nuklear/window.h index 123e4a7..ce60475 100644 --- a/demo/gdi_native_nuklear/window.h +++ b/demo/gdi_native_nuklear/window.h @@ -1,117 +1,93 @@ -#pragma once +#ifndef NK_GDI_WINDOW +#define NK_GDI_WINDOW -namespace NkGdi +#define NK_GDI_WINDOW_CLS L"WNDCLS_NkGdi" + +#include + +/* Functin pointer types for window callbacks */ +typedef void(*nkgdi_window_func_update)(void); +typedef int(*nkgdi_window_func_close)(void); +typedef int(*nkgdi_window_func_draw)(struct nk_context*); + +/* Window container / context */ +struct nkgdi_window { - // Container for window management - class WindowClass + /* Properties */ + int allow_sizing; + int allow_maximize; + int allow_move; + int has_titlebar; + + /* Callbacks */ + nkgdi_window_func_update cb_on_update; + nkgdi_window_func_close cb_on_close; + nkgdi_window_func_draw cb_on_draw; + + /* Internal Data */ + struct { - public: - // Public exposed name - static const wchar_t* const ClassName; + // Window handle + HWND window_handle; - WindowClass(const WindowClass&) = delete; - private: - // Instance - static WindowClass ClassInstance; + // Nuklear context + nk_gdi_ctx nk_gdi_ctx; + struct nk_context* nk_ctx; - // Sigelton - WindowClass(); - }; + // Nuklear objects + GdiFont* gdi_font; + HDC window_dc; - // Window base class - class Window - { - friend class WindowClass; + // Window runtime features + int is_open; + int is_draggin; + int ws_override; + int is_maximized; + POINT drag_offset; + int width; + int height; + }_internal; +}; - public: - // Default constructs - Window() = default; - Window(const Window&) = delete; - Window(Window&&) = default; - // Constructor - Window(unsigned int width, unsigned int height, const char* name, int posX = 100, int posY = 100); - // Destructor - ~Window(); - - // Processs window events and render the window (returns true as long as window is open) - bool Update(); - - // Properties - bool AllowSizing = true; - bool AllowMaximize = true; - bool AllowMove = true; - bool HasTitlebar = true; - - public: - // Called when the core window gets an event - virtual LRESULT OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); - - // Called when the window is created - inline virtual void OnCreate() {}; - // Called when the window is destroyed - inline virtual void OnDestroy() {}; - // Called when the windows is beein updated (before events are served) - inline virtual void OnUpdate() {}; - // Called when the window is beeing closed by the user (return false to abort) - inline virtual bool OnClose() { return true; }; - // Called when nuklear drawcalls can be issued (return false to close the window) - inline virtual bool OnDraw(nk_context* ctx) { return true; }; - - private: - // Static window procs - static LRESULT wndProcSetup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); - static LRESULT wndProcRun(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); - - private: - // Window handle - HWND m_window = NULL; - - // Nuklear context - nk_gdi_ctx m_nkGdiCtx = nullptr; - nk_context* m_nkCtx = nullptr; - - // Nuklear objects - GdiFont* m_gdiFont = nullptr; - HDC m_windowDc = NULL; - - // Window runtime features - bool m_isOpen = true; - bool m_isDraggin = false; - bool m_wsOverride = false; - bool m_isMaximized = false; - POINT m_dragOffset = {}; - int m_width = 0; - int m_height = 0; - }; -} +/* API */ +void nkgdi_window_init(void); +void nkgdi_window_shutdown(void); +void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned int height, const char* name, int posX, int posY); +int nkgdi_window_update(struct nkgdi_window* wnd); +void nkgdi_window_destroy(struct nkgdi_window* wnd); #ifdef NKGDI_IMPLEMENT_WINDOW -const wchar_t* const NkGdi::WindowClass::ClassName = L"WNDCLS_NkGdi"; -NkGdi::WindowClass NkGdi::WindowClass::ClassInstance; +LRESULT nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); +LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); -NkGdi::WindowClass::WindowClass() +void nkgdi_window_init(void) { // Describe class WNDCLASSEXW cls; cls.cbSize = sizeof(WNDCLASSEXW); cls.style = CS_OWNDC | CS_DBLCLKS; - cls.lpfnWndProc = &Window::wndProcSetup; + cls.lpfnWndProc = &nkgdi_window_proc_setup; cls.cbClsExtra = 0; cls.cbWndExtra = 0; cls.hInstance = GetModuleHandle(NULL); cls.hIcon = LoadIcon(NULL, IDI_APPLICATION); cls.hCursor = LoadCursor(NULL, IDC_ARROW); cls.hbrBackground = NULL; - cls.lpszMenuName = nullptr; - cls.lpszClassName = ClassName; + cls.lpszMenuName = NULL; + cls.lpszClassName = NK_GDI_WINDOW_CLS; cls.hIconSm = NULL; // Register class RegisterClassExW(&cls); } -NkGdi::Window::Window(unsigned int width, unsigned int height, const char* name, int posX, int posY) +void nkgdi_window_shutdown(void) +{ + UnregisterClassW(NK_GDI_WINDOW_CLS, GetModuleHandle(NULL)); +} + +void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned int height, const char* name, int posX, int posY) { DWORD styleEx = WS_EX_WINDOWEDGE; DWORD style = WS_POPUP; @@ -125,121 +101,155 @@ NkGdi::Window::Window(unsigned int width, unsigned int height, const char* name, AdjustWindowRectEx(&cr, style, FALSE, styleEx); // Create the window - m_window = CreateWindowExW( + wnd->_internal.window_handle = CreateWindowExW( styleEx, - WindowClass::ClassName, + NK_GDI_WINDOW_CLS, L"NkGdi", style | WS_VISIBLE, posX, posY, cr.right - cr.left, cr.bottom - cr.top, NULL, NULL, - GetModuleHandleW(nullptr), - this + GetModuleHandleW(NULL), + wnd ); // Rename window to user picked name - SetWindowTextA(m_window, name); + SetWindowTextA(wnd->_internal.window_handle, name); // Get DC - m_windowDc = GetWindowDC(m_window); + wnd->_internal.window_dc = GetWindowDC(wnd->_internal.window_handle); // Create font - m_gdiFont = nk_gdifont_create("Arial", 16); - m_nkCtx = nk_gdi_init(&m_nkGdiCtx, m_gdiFont, m_windowDc, width, height); + wnd->_internal.gdi_font = nk_gdifont_create("Arial", 16); + wnd->_internal.nk_ctx = nk_gdi_init(&wnd->_internal.nk_gdi_ctx, wnd->_internal.gdi_font, wnd->_internal.window_dc, width, height); + + // Setup internal data + wnd->_internal.is_open = 1; + wnd->_internal.is_draggin = 0; + wnd->_internal.ws_override = 0; + wnd->_internal.is_maximized = 0; + wnd->_internal.drag_offset.x = 0; + wnd->_internal.drag_offset.y = 0; + wnd->_internal.width = 0; + wnd->_internal.height = 0; } -NkGdi::Window::~Window() +void nkgdi_window_destroy(struct nkgdi_window* wnd) { // Destroy GDI context - if (m_nkGdiCtx) + if (wnd->_internal.nk_gdi_ctx) { - nk_gdi_shutdown(m_nkGdiCtx); + nk_gdi_shutdown(wnd->_internal.nk_gdi_ctx); } // Destroy font - if (m_gdiFont) + if (wnd->_internal.gdi_font) { - nk_gdifont_del(m_gdiFont); + nk_gdifont_del(wnd->_internal.gdi_font); } // Close DC - if (m_windowDc) + if (wnd->_internal.window_dc) { - ReleaseDC(m_window, m_windowDc); + ReleaseDC(wnd->_internal.window_handle, wnd->_internal.window_dc); } // Destroy window - if (m_window) + if (wnd->_internal.window_handle) { - CloseWindow(m_window); - DestroyWindow(m_window); + CloseWindow(wnd->_internal.window_handle); + DestroyWindow(wnd->_internal.window_handle); } } -bool NkGdi::Window::Update() +int nkgdi_window_update(struct nkgdi_window* wnd) { // Only process events while window is open - if (m_isOpen) + if (wnd->_internal.is_open) { - // Notify class that event processing has stated - OnUpdate(); - // Windows event loop - MSG msg = {}; - nk_input_begin(m_nkCtx); - while (PeekMessage(&msg, m_window, 0, 0, PM_REMOVE)) + MSG msg; + nk_input_begin(wnd->_internal.nk_ctx); + while (PeekMessage(&msg, wnd->_internal.window_handle, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageW(&msg); } - nk_input_end(m_nkCtx); + nk_input_end(wnd->_internal.nk_ctx); // Get title char title[1024]; - GetWindowTextA(m_window, title, 1024); + GetWindowTextA(wnd->_internal.window_handle, title, 1024); + + // Window flags + nk_flags window_flags = NK_WINDOW_BORDER; + if(wnd->has_titlebar) + window_flags |= NK_WINDOW_CLOSABLE | NK_WINDOW_TITLE; + if(!wnd->_internal.is_maximized && wnd->allow_sizing) + window_flags |= NK_WINDOW_SCALABLE; // Window body - if (m_wsOverride) - nk_window_set_bounds(m_nkCtx, title, nk_rect(0, 0, m_width, m_height)); - if (nk_begin(m_nkCtx, title, nk_rect(0, 0, m_width, m_height), - NK_WINDOW_BORDER | - (HasTitlebar ? NK_WINDOW_CLOSABLE | NK_WINDOW_TITLE : NULL) | - (m_isMaximized || !AllowSizing ? NULL : NK_WINDOW_SCALABLE) - )) + if (wnd->_internal.ws_override) + nk_window_set_bounds(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height)); + if (nk_begin(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height), window_flags)) { - if(!OnDraw(m_nkCtx)) - m_isOpen = false; + if(!wnd->cb_on_draw(wnd->_internal.nk_ctx)) + wnd->_internal.is_open = 0; // Update window size - struct nk_rect bounds = nk_window_get_bounds(m_nkCtx); - if(bounds.w != m_width || bounds.h != m_height) - SetWindowPos(m_window, NULL, 0, 0, bounds.w, bounds.h, SWP_NOMOVE | SWP_NOOWNERZORDER); + struct nk_rect bounds = nk_window_get_bounds(wnd->_internal.nk_ctx); + if(bounds.w != wnd->_internal.width || bounds.h != wnd->_internal.height) + SetWindowPos(wnd->_internal.window_handle, NULL, 0, 0, bounds.w, bounds.h, SWP_NOMOVE | SWP_NOOWNERZORDER); } else { // Handle window closing - if(OnClose()) - m_isOpen = false; + if(!wnd->cb_on_close || wnd->cb_on_close()) + wnd->_internal.is_open = 0; } - nk_end(m_nkCtx); - m_wsOverride = false; + nk_end(wnd->_internal.nk_ctx); + wnd->_internal.ws_override = 0; // Final render pass - nk_gdi_render(m_nkGdiCtx, nk_rgb(30, 30, 30)); + nk_gdi_render(wnd->_internal.nk_gdi_ctx, nk_rgb(30, 30, 30)); } - return m_isOpen; + return wnd->_internal.is_open; } -LRESULT NkGdi::Window::OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { + // Wait for setup message + if (msg == WM_NCCREATE) + { + // Get creation parameters & window pointer + CREATESTRUCT* ptrCr = (CREATESTRUCT*)lParam; + struct nkgdi_window* nkgdi_wnd = (struct nkgdi_window*)ptrCr->lpCreateParams; + + // Store pointer and new proc in window + SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR)nkgdi_wnd); + SetWindowLongPtr(wnd, GWLP_WNDPROC, (LONG_PTR)&nkgdi_window_proc_run); + + // Handled by window + return nkgdi_window_proc_run(wnd, msg, wParam, lParam); + } + + // Default handler + return DefWindowProc(wnd, msg, wParam, lParam); +} + +LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + // Get window pointer + struct nkgdi_window* nkwnd = (struct nkgdi_window*)GetWindowLongPtrW(wnd, GWLP_USERDATA); + // Switch on supplied message code switch (msg) { // Close event case WM_CLOSE: - if (OnClose()) - m_isOpen = false; + if(!nkwnd->cb_on_close || nkwnd->cb_on_close()) + nkwnd->_internal.is_open = 0; return 0; // Will always be handled internaly // While sizing @@ -247,8 +257,8 @@ LRESULT NkGdi::Window::OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM { RECT cr; GetClientRect(wnd, &cr); - m_width = cr.right - cr.left; - m_height = cr.bottom - cr.top; + nkwnd->_internal.width = cr.right - cr.left; + nkwnd->_internal.height = cr.bottom - cr.top; } break; @@ -263,56 +273,56 @@ LRESULT NkGdi::Window::OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM monitorInfo.cbSize = sizeof(MONITORINFO); if (GetMonitorInfoW(monitor, &monitorInfo)) { - m_height = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; - m_width = monitorInfo.rcWork.right - monitorInfo.rcWork.left; - m_wsOverride = true; - m_isMaximized = true; - SetWindowPos(wnd, NULL, 0, 0, m_width, m_height, SWP_NOMOVE | SWP_NOZORDER); + nkwnd->_internal.height = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; + nkwnd->_internal.width = monitorInfo.rcWork.right - monitorInfo.rcWork.left; + nkwnd->_internal.ws_override = 1; + nkwnd->_internal.is_maximized = 1; + SetWindowPos(wnd, NULL, 0, 0, nkwnd->_internal.width, nkwnd->_internal.height, SWP_NOMOVE | SWP_NOZORDER); } } else if (wParam == SIZE_RESTORED) { - m_isMaximized = false; + nkwnd->_internal.is_maximized = 0; } // Compute new bounds RECT cr; GetClientRect(wnd, &cr); - m_width = cr.right - cr.left; - m_height = cr.bottom - cr.top; + nkwnd->_internal.width = cr.right - cr.left; + nkwnd->_internal.height = cr.bottom - cr.top; } break; // When mouse start l-press (drag window) case WM_LBUTTONDOWN: { - if (HIWORD(lParam) <= 30 && AllowMove) + if (HIWORD(lParam) <= 30 && nkwnd->allow_move) { // Start dragging - m_isDraggin = true; - m_dragOffset.x = LOWORD(lParam); - m_dragOffset.y = HIWORD(lParam); + nkwnd->_internal.is_draggin = 1; + nkwnd->_internal.drag_offset.x = LOWORD(lParam); + nkwnd->_internal.drag_offset.y = HIWORD(lParam); } } break; // When mouse stops l-press (drag window) case WM_LBUTTONUP: - m_isDraggin = false; + nkwnd->_internal.is_draggin = 0; break; // Mouse movement (dragging) case WM_MOUSEMOVE: { - if (m_isDraggin && !m_isMaximized) + if (nkwnd->_internal.is_draggin && !nkwnd->_internal.is_maximized) { // Get mouse postion and substract offset POINT cursorPos; GetCursorPos(&cursorPos); - cursorPos.x -= m_dragOffset.x; - cursorPos.y -= m_dragOffset.y; + cursorPos.x -= nkwnd->_internal.drag_offset.x; + cursorPos.y -= nkwnd->_internal.drag_offset.y; // Use as new position - ShowWindow(m_window, SW_RESTORE); + ShowWindow(wnd, SW_RESTORE); SetWindowPos(wnd, NULL, cursorPos.x, cursorPos.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); } } @@ -321,9 +331,9 @@ LRESULT NkGdi::Window::OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM // On mouse doubble click (maximize) case WM_LBUTTONDBLCLK: { - if (HIWORD(lParam) <= 30 && AllowMaximize) + if (HIWORD(lParam) <= 30 && nkwnd->allow_maximize) { - if (m_isMaximized) + if (nkwnd->_internal.is_maximized) { ShowWindow(wnd, SW_RESTORE); } @@ -331,47 +341,19 @@ LRESULT NkGdi::Window::OnWindowMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM { ShowWindow(wnd, SW_MAXIMIZE); } - m_wsOverride = true; + nkwnd->_internal.ws_override = 1; } } break; } // Send to nuklear - if (m_nkGdiCtx && nk_gdi_handle_event(m_nkGdiCtx, wnd, msg, wParam, lParam)) + if (nkwnd->_internal.nk_gdi_ctx && nk_gdi_handle_event(nkwnd->_internal.nk_gdi_ctx, wnd, msg, wParam, lParam)) return 0; // In case this is ever reached: Run default behaviour return DefWindowProc(wnd, msg, wParam, lParam); } -LRESULT NkGdi::Window::wndProcSetup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - // Wait for setup message - if (msg == WM_NCCREATE) - { - // Get creation parameters & window pointer - CREATESTRUCT* ptrCr = (CREATESTRUCT*)lParam; - Window* ptrWindow = (Window*)ptrCr->lpCreateParams; - - // Store pointer and new proc in window - SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR)ptrWindow); - SetWindowLongPtr(wnd, GWLP_WNDPROC, (LONG_PTR)&wndProcRun); - - // Handled by window - return ptrWindow->OnWindowMessage(wnd, msg, wParam, lParam); - } - - // Default handler - return DefWindowProc(wnd, msg, wParam, lParam); -} - -LRESULT NkGdi::Window::wndProcRun(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - // Get window pointer - Window* ptrWindow = (Window*)GetWindowLongPtr(wnd, GWLP_USERDATA); - // Call window - return ptrWindow->OnWindowMessage(wnd, msg, wParam, lParam); -} - +#endif #endif From 33395aabdb439ac41998f5c57982d2dfc8fc09a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20F=C3=BCchsl?= Date: Mon, 28 Feb 2022 15:53:54 +0100 Subject: [PATCH 03/61] Fixed non displayed windows. WARNING: Drawing is not done correctly --- demo/gdi_native_nuklear/main.c | 16 ++++++++++++++++ demo/gdi_native_nuklear/window.h | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/demo/gdi_native_nuklear/main.c b/demo/gdi_native_nuklear/main.c index 70ba268..05ed83b 100644 --- a/demo/gdi_native_nuklear/main.c +++ b/demo/gdi_native_nuklear/main.c @@ -16,23 +16,39 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #define NKGDI_IMPLEMENT_WINDOW #include "window.h" +int drawCallback(struct nk_context* ctx) +{ + nk_label(ctx, "Label", NK_TEXT_ALIGN_CENTERED); + nk_button_label(ctx, "Test 1234"); + return 1; +} + INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, PWSTR _In_ cmdArgs, INT _In_ cmdShow) { + nkgdi_window_init(); struct nkgdi_window w1, w2; + memset(&w1, 0x0, sizeof(struct nkgdi_window)); + memset(&w2, 0x0, sizeof(struct nkgdi_window)); w1.allow_sizing = 0; w1.allow_maximize = 0; w1.allow_move = 0; w1.has_titlebar = 0; + w1.cb_on_draw = &drawCallback; nkgdi_window_create(&w1, 500, 500, "F1", 10, 10); w2.allow_sizing = 1; w2.allow_maximize = 1; w2.allow_move = 1; w2.has_titlebar = 1; + w2.cb_on_draw = &drawCallback; nkgdi_window_create(&w2, 500, 500, "F2", 520, 10); while (nkgdi_window_update(&w1) && nkgdi_window_update(&w2)) Sleep(20); + nkgdi_window_destroy(&w1); + nkgdi_window_destroy(&w2); + + nkgdi_window_shutdown(); return 0; } diff --git a/demo/gdi_native_nuklear/window.h b/demo/gdi_native_nuklear/window.h index ce60475..ee1b5de 100644 --- a/demo/gdi_native_nuklear/window.h +++ b/demo/gdi_native_nuklear/window.h @@ -130,8 +130,8 @@ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned wnd->_internal.is_maximized = 0; wnd->_internal.drag_offset.x = 0; wnd->_internal.drag_offset.y = 0; - wnd->_internal.width = 0; - wnd->_internal.height = 0; + wnd->_internal.width = width; + wnd->_internal.height = height; } void nkgdi_window_destroy(struct nkgdi_window* wnd) @@ -193,7 +193,7 @@ int nkgdi_window_update(struct nkgdi_window* wnd) nk_window_set_bounds(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height)); if (nk_begin(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height), window_flags)) { - if(!wnd->cb_on_draw(wnd->_internal.nk_ctx)) + if(wnd->cb_on_draw && !wnd->cb_on_draw(wnd->_internal.nk_ctx)) wnd->_internal.is_open = 0; // Update window size From a31c6c0089a2e13ad6dbfc8cc29cc975cf3afcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20F=C3=BCchsl?= Date: Fri, 4 Mar 2022 13:16:47 +0100 Subject: [PATCH 04/61] Bug fix & Added comments --- demo/gdi_native_nuklear/main.c | 76 +++++++++++++- demo/gdi_native_nuklear/nuklear_gdi.h | 5 + demo/gdi_native_nuklear/window.h | 142 +++++++++++++++----------- 3 files changed, 164 insertions(+), 59 deletions(-) diff --git a/demo/gdi_native_nuklear/main.c b/demo/gdi_native_nuklear/main.c index 05ed83b..b6cb6a9 100644 --- a/demo/gdi_native_nuklear/main.c +++ b/demo/gdi_native_nuklear/main.c @@ -4,6 +4,9 @@ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +/* Includes the default nuklear implementation + * Includes the modified GDI backend (No more global state to allow multiple hwnd's) + */ #define NK_INCLUDE_FIXED_TYPES #define NK_INCLUDE_STANDARD_IO #define NK_INCLUDE_STANDARD_VARARGS @@ -13,23 +16,88 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include "../../nuklear.h" #include "nuklear_gdi.h" +/* Include the window framework (the new fancy code of this demo) */ #define NKGDI_IMPLEMENT_WINDOW #include "window.h" +/* This callback will be called when the window is draw + * You will NOT need to call nk_begin(...) and nk_end(...) + * begin and end are handled by the parent code calling this + * callback + */ int drawCallback(struct nk_context* ctx) { - nk_label(ctx, "Label", NK_TEXT_ALIGN_CENTERED); - nk_button_label(ctx, "Test 1234"); + /* Code is from ../calculator.c */ + static int set = 0, prev = 0, op = 0; + static const char numbers[] = "789456123"; + static const char ops[] = "+-*/"; + static double a = 0, b = 0; + static double *current = &a; + + size_t i = 0; + int solve = 0; + {int len; char buffer[256]; + nk_layout_row_dynamic(ctx, 35, 1); + len = snprintf(buffer, 256, "%.2f", *current); + nk_edit_string(ctx, NK_EDIT_SIMPLE, buffer, &len, 255, nk_filter_float); + buffer[len] = 0; + *current = atof(buffer);} + + nk_layout_row_dynamic(ctx, 35, 4); + for (i = 0; i < 16; ++i) { + if (i >= 12 && i < 15) { + if (i > 12) continue; + if (nk_button_label(ctx, "C")) { + a = b = op = 0; current = &a; set = 0; + } if (nk_button_label(ctx, "0")) { + *current = *current*10.0f; set = 0; + } if (nk_button_label(ctx, "=")) { + solve = 1; prev = op; op = 0; + } + } else if (((i+1) % 4)) { + if (nk_button_text(ctx, &numbers[(i/4)*3+i%4], 1)) { + *current = *current * 10.0f + numbers[(i/4)*3+i%4] - '0'; + set = 0; + } + } else if (nk_button_text(ctx, &ops[i/4], 1)) { + if (!set) { + if (current != &b) { + current = &b; + } else { + prev = op; + solve = 1; + } + } + op = ops[i/4]; + set = 1; + } + } + if (solve) { + if (prev == '+') a = a + b; + if (prev == '-') a = a - b; + if (prev == '*') a = a * b; + if (prev == '/') a = a / b; + current = &a; + if (set) current = &b; + b = 0; set = 0; + } return 1; } +/* Main entry point (Windows wchar_t) */ INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, PWSTR _In_ cmdArgs, INT _In_ cmdShow) { + /* Call this first to setup all required prerequisites */ nkgdi_window_init(); + + /* Preparing two window contexts */ struct nkgdi_window w1, w2; memset(&w1, 0x0, sizeof(struct nkgdi_window)); memset(&w2, 0x0, sizeof(struct nkgdi_window)); + /* Configure and create window 1. + * Note: You can allways change the direct accesible parameters later as well! + */ w1.allow_sizing = 0; w1.allow_maximize = 0; w1.allow_move = 0; @@ -37,6 +105,7 @@ INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, w1.cb_on_draw = &drawCallback; nkgdi_window_create(&w1, 500, 500, "F1", 10, 10); + /* Configure and create window 2 */ w2.allow_sizing = 1; w2.allow_maximize = 1; w2.allow_move = 1; @@ -44,11 +113,14 @@ INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, w2.cb_on_draw = &drawCallback; nkgdi_window_create(&w2, 500, 500, "F2", 520, 10); + /* As long as both windows are valid (nkgdi_window_update returning 1) */ while (nkgdi_window_update(&w1) && nkgdi_window_update(&w2)) Sleep(20); + /* Destroy both windows context */ nkgdi_window_destroy(&w1); nkgdi_window_destroy(&w2); + /* Call nkgdi_window_shutdown to properly shutdown the gdi window framework */ nkgdi_window_shutdown(); return 0; } diff --git a/demo/gdi_native_nuklear/nuklear_gdi.h b/demo/gdi_native_nuklear/nuklear_gdi.h index aef6452..5c2f1f8 100644 --- a/demo/gdi_native_nuklear/nuklear_gdi.h +++ b/demo/gdi_native_nuklear/nuklear_gdi.h @@ -2,6 +2,11 @@ * Nuklear - 1.32.0 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke + * + * Modified GDI backend 2022 + * Now based on a context that is required for each API function call. + * Removes the global state --> you can have multiple windows :-) + * */ /* * ============================================================== diff --git a/demo/gdi_native_nuklear/window.h b/demo/gdi_native_nuklear/window.h index ee1b5de..0db572f 100644 --- a/demo/gdi_native_nuklear/window.h +++ b/demo/gdi_native_nuklear/window.h @@ -6,40 +6,45 @@ #include /* Functin pointer types for window callbacks */ -typedef void(*nkgdi_window_func_update)(void); typedef int(*nkgdi_window_func_close)(void); typedef int(*nkgdi_window_func_draw)(struct nk_context*); /* Window container / context */ struct nkgdi_window { - /* Properties */ + /* The window can be sized */ int allow_sizing; + /* The window can be maximized by double clicking the titlebar */ int allow_maximize; + /* The window is allowed to be moved by the user */ int allow_move; + /* The window will render it's title bar */ int has_titlebar; /* Callbacks */ - nkgdi_window_func_update cb_on_update; + /* Called when the user or os requests a window close (return 1 to accept the reqest)*/ nkgdi_window_func_close cb_on_close; + /* Called each time the window content should be drawn. Here you will do your nuklear drawing code + * but WITHOUT nk_begin and nk_end. Return 1 to keep the window open. + */ nkgdi_window_func_draw cb_on_draw; /* Internal Data */ struct { - // Window handle + /* Window handle */ HWND window_handle; - // Nuklear context + /* Nuklear & GDI context */ nk_gdi_ctx nk_gdi_ctx; struct nk_context* nk_ctx; - // Nuklear objects + /* GDI required objects */ GdiFont* gdi_font; HDC window_dc; - // Window runtime features - int is_open; + /* Internally used state variables */ + int is_open; int is_draggin; int ws_override; int is_maximized; @@ -50,20 +55,28 @@ struct nkgdi_window }; /* API */ +/* This function will init all resources used by the implementation */ void nkgdi_window_init(void); +/* This function will free all globally used resources */ void nkgdi_window_shutdown(void); +/* Creates a new window (for the wnd context) */ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned int height, const char* name, int posX, int posY); +/* Updates the window (Windows message loop, nuklear loop and drawing). Returns one as long as the window is valid and open */ int nkgdi_window_update(struct nkgdi_window* wnd); +/* Destroys the window context wnd */ void nkgdi_window_destroy(struct nkgdi_window* wnd); #ifdef NKGDI_IMPLEMENT_WINDOW +/* Predeclare the windows window message procs */ +/* This proc will setup the pointer to the window context */ LRESULT nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); +/* This proc will take the window context pointer and performs operations on it*/ LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); void nkgdi_window_init(void) { - // Describe class + /* Describe the window class */ WNDCLASSEXW cls; cls.cbSize = sizeof(WNDCLASSEXW); cls.style = CS_OWNDC | CS_DBLCLKS; @@ -78,12 +91,13 @@ void nkgdi_window_init(void) cls.lpszClassName = NK_GDI_WINDOW_CLS; cls.hIconSm = NULL; - // Register class + /* Register the window class */ RegisterClassExW(&cls); } void nkgdi_window_shutdown(void) { + /* Windows class no longer required, unregister it */ UnregisterClassW(NK_GDI_WINDOW_CLS, GetModuleHandle(NULL)); } @@ -92,7 +106,7 @@ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned DWORD styleEx = WS_EX_WINDOWEDGE; DWORD style = WS_POPUP; - // Compute window size + /* Adjust window size to fit selected window styles */ RECT cr; cr.left = 0; cr.top = 0; @@ -100,7 +114,7 @@ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned cr.bottom = height; AdjustWindowRectEx(&cr, style, FALSE, styleEx); - // Create the window + /* Create the new window */ wnd->_internal.window_handle = CreateWindowExW( styleEx, NK_GDI_WINDOW_CLS, @@ -113,17 +127,19 @@ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned wnd ); - // Rename window to user picked name + /* Give the window the ascii char name */ SetWindowTextA(wnd->_internal.window_handle, name); - // Get DC + /* Extract the window dc for gdi drawing */ wnd->_internal.window_dc = GetWindowDC(wnd->_internal.window_handle); - // Create font + /* Create the gdi font required to draw text */ wnd->_internal.gdi_font = nk_gdifont_create("Arial", 16); + + /* Init the gdi backend */ wnd->_internal.nk_ctx = nk_gdi_init(&wnd->_internal.nk_gdi_ctx, wnd->_internal.gdi_font, wnd->_internal.window_dc, width, height); - // Setup internal data + /* Bring all internal variables to a defined and valid initial state */ wnd->_internal.is_open = 1; wnd->_internal.is_draggin = 0; wnd->_internal.ws_override = 0; @@ -136,25 +152,19 @@ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned void nkgdi_window_destroy(struct nkgdi_window* wnd) { - // Destroy GDI context + /* Destroy all objects in reverse order */ if (wnd->_internal.nk_gdi_ctx) { nk_gdi_shutdown(wnd->_internal.nk_gdi_ctx); } - - // Destroy font if (wnd->_internal.gdi_font) { nk_gdifont_del(wnd->_internal.gdi_font); } - - // Close DC if (wnd->_internal.window_dc) { ReleaseDC(wnd->_internal.window_handle, wnd->_internal.window_dc); } - - // Destroy window if (wnd->_internal.window_handle) { CloseWindow(wnd->_internal.window_handle); @@ -164,10 +174,10 @@ void nkgdi_window_destroy(struct nkgdi_window* wnd) int nkgdi_window_update(struct nkgdi_window* wnd) { - // Only process events while window is open + /* The window will only be updated when it is open / valid */ if (wnd->_internal.is_open) { - // Windows event loop + /* First all pending window events will be processed */ MSG msg; nk_input_begin(wnd->_internal.nk_ctx); while (PeekMessage(&msg, wnd->_internal.window_handle, 0, 0, PM_REMOVE)) @@ -177,41 +187,46 @@ int nkgdi_window_update(struct nkgdi_window* wnd) } nk_input_end(wnd->_internal.nk_ctx); - // Get title + /* To setup the nuklear window we need the windows title */ char title[1024]; GetWindowTextA(wnd->_internal.window_handle, title, 1024); - // Window flags + /* The nk window flags are beeing create based on the context setup */ nk_flags window_flags = NK_WINDOW_BORDER; if(wnd->has_titlebar) window_flags |= NK_WINDOW_CLOSABLE | NK_WINDOW_TITLE; if(!wnd->_internal.is_maximized && wnd->allow_sizing) window_flags |= NK_WINDOW_SCALABLE; - // Window body + /* Override the nuklear windows size when required */ if (wnd->_internal.ws_override) nk_window_set_bounds(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height)); + + /* Start the nuklear window */ if (nk_begin(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height), window_flags)) { + /* Call user drawing callback */ if(wnd->cb_on_draw && !wnd->cb_on_draw(wnd->_internal.nk_ctx)) wnd->_internal.is_open = 0; - // Update window size + /* Update the windows window to reflect the nuklear windows size */ struct nk_rect bounds = nk_window_get_bounds(wnd->_internal.nk_ctx); if(bounds.w != wnd->_internal.width || bounds.h != wnd->_internal.height) SetWindowPos(wnd->_internal.window_handle, NULL, 0, 0, bounds.w, bounds.h, SWP_NOMOVE | SWP_NOOWNERZORDER); } else { - // Handle window closing + /* Nuklear window was closed. Handle close internally */ if(!wnd->cb_on_close || wnd->cb_on_close()) wnd->_internal.is_open = 0; } nk_end(wnd->_internal.nk_ctx); + + /* We no longer need the window size override flag to be set */ wnd->_internal.ws_override = 0; - // Final render pass - nk_gdi_render(wnd->_internal.nk_gdi_ctx, nk_rgb(30, 30, 30)); + /* Pass context to the nuklear gdi renderer */ + nk_gdi_render(wnd->_internal.nk_gdi_ctx, nk_rgb(0, 0, 0)); } return wnd->_internal.is_open; @@ -219,42 +234,44 @@ int nkgdi_window_update(struct nkgdi_window* wnd) LRESULT nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { - // Wait for setup message + /* Waiting to receive the NCCREATE message with the custom window data */ if (msg == WM_NCCREATE) { - // Get creation parameters & window pointer + /* Extracting the window context from message parameters */ CREATESTRUCT* ptrCr = (CREATESTRUCT*)lParam; struct nkgdi_window* nkgdi_wnd = (struct nkgdi_window*)ptrCr->lpCreateParams; - // Store pointer and new proc in window + /* Store the context in the window and redirect any further message to the run window proc*/ SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR)nkgdi_wnd); SetWindowLongPtr(wnd, GWLP_WNDPROC, (LONG_PTR)&nkgdi_window_proc_run); - // Handled by window + /* Already call the run proc so that it gets the chance to handle NCCREATE as well */ return nkgdi_window_proc_run(wnd, msg, wParam, lParam); } - // Default handler + /* Until we get WM_NCCREATE windows is going to handle the messages */ return DefWindowProc(wnd, msg, wParam, lParam); } LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { - // Get window pointer + /* The window context is extracted from the window data */ struct nkgdi_window* nkwnd = (struct nkgdi_window*)GetWindowLongPtrW(wnd, GWLP_USERDATA); - // Switch on supplied message code + /* Switch on the message code to handle all required messages */ switch (msg) { - // Close event + /* Window close event */ case WM_CLOSE: + /* Call custom close callback */ if(!nkwnd->cb_on_close || nkwnd->cb_on_close()) nkwnd->_internal.is_open = 0; - return 0; // Will always be handled internaly + return 0; /* No default behaviour. We do it our own way */ - // While sizing + /* Window sizing event (is currently beeing sized) */ case WM_SIZING: { + /* Size of the client / active are is extracted and stored */ RECT cr; GetClientRect(wnd, &cr); nkwnd->_internal.width = cr.right - cr.left; @@ -262,30 +279,33 @@ LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) } break; - // When sized + /* Window size event (done sizing, maximize, minimize, ...) */ case WM_SIZE: { - // Adjust maximize properties + /* Window was maximized */ if (wParam == SIZE_MAXIMIZED) { + /* Get the nearest monitor and retrive its details */ HMONITOR monitor = MonitorFromWindow(wnd, MONITOR_DEFAULTTOPRIMARY); MONITORINFO monitorInfo; monitorInfo.cbSize = sizeof(MONITORINFO); if (GetMonitorInfoW(monitor, &monitorInfo)) { + /* Adjust the window size and position by the monitor working area (without taskbar) */ nkwnd->_internal.height = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; nkwnd->_internal.width = monitorInfo.rcWork.right - monitorInfo.rcWork.left; - nkwnd->_internal.ws_override = 1; + nkwnd->_internal.ws_override = 1; /* Sizing was done without nuklear beeing aware. So we need to override it */ nkwnd->_internal.is_maximized = 1; SetWindowPos(wnd, NULL, 0, 0, nkwnd->_internal.width, nkwnd->_internal.height, SWP_NOMOVE | SWP_NOZORDER); } } + /* Window was restored (no longer maximized) */ else if (wParam == SIZE_RESTORED) { nkwnd->_internal.is_maximized = 0; } - // Compute new bounds + /* Always get the new bounds of the window */ RECT cr; GetClientRect(wnd, &cr); nkwnd->_internal.width = cr.right - cr.left; @@ -293,12 +313,13 @@ LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) } break; - // When mouse start l-press (drag window) + /* Mouse started left click */ case WM_LBUTTONDOWN: { - if (HIWORD(lParam) <= 30 && nkwnd->allow_move) + /* Handle dragging when allowed, has titlebar and mouse is in titlebar (Y <= 30) */ + if (HIWORD(lParam) <= 30 && nkwnd->allow_move && nkwnd->has_titlebar) { - // Start dragging + /* Mark dragging internally and store mouse click offset */ nkwnd->_internal.is_draggin = 1; nkwnd->_internal.drag_offset.x = LOWORD(lParam); nkwnd->_internal.drag_offset.y = HIWORD(lParam); @@ -306,52 +327,59 @@ LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) } break; - // When mouse stops l-press (drag window) + /* Mouse stoped left click */ case WM_LBUTTONUP: + /* No longer dragging the window */ nkwnd->_internal.is_draggin = 0; break; - // Mouse movement (dragging) + /* Mouse is moving on the window */ case WM_MOUSEMOVE: { + /* When we are dragging and are not maximized process dragging */ if (nkwnd->_internal.is_draggin && !nkwnd->_internal.is_maximized) { - // Get mouse postion and substract offset + /* Get the current global position of the mouse */ POINT cursorPos; GetCursorPos(&cursorPos); + /* Substract the internal offset */ cursorPos.x -= nkwnd->_internal.drag_offset.x; cursorPos.y -= nkwnd->_internal.drag_offset.y; - // Use as new position + /* Update position of out window and make sure window is in a movable state (= Restored) */ ShowWindow(wnd, SW_RESTORE); SetWindowPos(wnd, NULL, cursorPos.x, cursorPos.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); } } break; - // On mouse doubble click (maximize) + /* Mouse double clicked */ case WM_LBUTTONDBLCLK: { - if (HIWORD(lParam) <= 30 && nkwnd->allow_maximize) + /* Will only affect window when on the titlebar */ + if (HIWORD(lParam) <= 30 && nkwnd->allow_maximize && nkwnd->has_titlebar) { + /* When the window is already maximized restore it */ if (nkwnd->_internal.is_maximized) { ShowWindow(wnd, SW_RESTORE); } + /* Else we gonna do maximize it*/ else { ShowWindow(wnd, SW_MAXIMIZE); } + /* We overrideed the window size, make sure to affect the nk window as well */ nkwnd->_internal.ws_override = 1; } } break; } - // Send to nuklear + /* Allow nuklear to handle the message as well */ if (nkwnd->_internal.nk_gdi_ctx && nk_gdi_handle_event(nkwnd->_internal.nk_gdi_ctx, wnd, msg, wParam, lParam)) return 0; - // In case this is ever reached: Run default behaviour + /* In case we reach this line our code and nuklear did not respond to the message. Allow windows to handle it s*/ return DefWindowProc(wnd, msg, wParam, lParam); } From ec4aa9992f8bd13dce8197ee8795071baa512c49 Mon Sep 17 00:00:00 2001 From: Kristian Bolino Date: Mon, 14 Mar 2022 12:26:25 -0400 Subject: [PATCH 05/61] Fix high-DPI scaling in sdl_renderer This commit resolves two issues with high-DPI display rendering: 1. The coordinates were not scaled properly, resulting in tiny output and misalignment of actual cursor position with apparent position; this is fixed by calling SDL_SetRenderScale with appropriate scaling factors determined by comparing the window size to the renderer's output size 2. The fonts were not oversampled, resulting in excessively blurry text; this is fixed by setting oversample_h and oversample_v on the font_config according to the scaling factors --- demo/sdl_renderer/main.c | 56 +++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/demo/sdl_renderer/main.c b/demo/sdl_renderer/main.c index 0208d33..a65a44e 100644 --- a/demo/sdl_renderer/main.c +++ b/demo/sdl_renderer/main.c @@ -76,6 +76,8 @@ main(int argc, char *argv[]) SDL_Renderer *renderer; int running = 1; int flags = 0; + unsigned char oversample_h = 1; + unsigned char oversample_v = 1; /* GUI */ struct nk_context *ctx; @@ -112,22 +114,53 @@ main(int argc, char *argv[]) exit(-1); } + /* scale the renderer output for High-DPI displays */ + { + int render_w, render_h; + int window_w, window_h; + float scale_x, scale_y; + SDL_GetRendererOutputSize(renderer, &render_w, &render_h); + SDL_GetWindowSize(win, &window_w, &window_h); + scale_x = (float)(render_w) / (float)(window_w); + scale_y = (float)(render_h) / (float)(window_h); + SDL_RenderSetScale(renderer, scale_x, scale_y); + if (scale_x > 1) { + oversample_h = nk_iceilf(scale_x); + } + if (scale_y > 1) { + oversample_v = nk_iceilf(scale_y); + } + } /* GUI */ ctx = nk_sdl_init(win, renderer); /* Load Fonts: if none of these are loaded a default font will be used */ /* Load Cursor: if you uncomment cursor loading please hide the cursor */ - {struct nk_font_atlas *atlas; - nk_sdl_font_stash_begin(&atlas); - /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ - /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/ - /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ - /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ - /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ - /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ - nk_sdl_font_stash_end(); - /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ - /*nk_style_set_font(ctx, &roboto->handle)*/;} + { + struct nk_font_atlas *atlas; + struct nk_font_config config = nk_font_config(0); + + /* oversample the fonts for high-DPI displays */ + if (oversample_h > 1) { + config.oversample_h = oversample_h; + } + if (oversample_v > 1) { + config.oversample_v = oversample_v; + } + + /* set up the font atlas and add desired fonts */ + nk_sdl_font_stash_begin(&atlas); + struct nk_font *default_font = nk_font_atlas_add_default(atlas, 12, &config); + /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, &config);*/ + /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, &config);*/ + /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, &config);*/ + /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, &config);*/ + /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, &config);*/ + /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, &config);*/ + nk_sdl_font_stash_end(); + /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ + nk_style_set_font(ctx, &default_font->handle); + } #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ @@ -212,4 +245,3 @@ cleanup: SDL_Quit(); return 0; } - From 779c420d066caa584395c6a6218736e1f6f245d9 Mon Sep 17 00:00:00 2001 From: Kristian Bolino Date: Tue, 15 Mar 2022 11:44:59 -0400 Subject: [PATCH 06/61] Fix C89 warnings and oversample at 3x scale --- demo/sdl_renderer/main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/demo/sdl_renderer/main.c b/demo/sdl_renderer/main.c index a65a44e..63625f8 100644 --- a/demo/sdl_renderer/main.c +++ b/demo/sdl_renderer/main.c @@ -76,6 +76,8 @@ main(int argc, char *argv[]) SDL_Renderer *renderer; int running = 1; int flags = 0; + + /* Nuklear settings */ unsigned char oversample_h = 1; unsigned char oversample_v = 1; @@ -125,7 +127,7 @@ main(int argc, char *argv[]) scale_y = (float)(render_h) / (float)(window_h); SDL_RenderSetScale(renderer, scale_x, scale_y); if (scale_x > 1) { - oversample_h = nk_iceilf(scale_x); + oversample_h = 3 * nk_iceilf(scale_x); } if (scale_y > 1) { oversample_v = nk_iceilf(scale_y); @@ -139,24 +141,25 @@ main(int argc, char *argv[]) { struct nk_font_atlas *atlas; struct nk_font_config config = nk_font_config(0); + struct nk_font *default_font, *droid, *roboto, *future, *clean, *tiny, *cousine; /* oversample the fonts for high-DPI displays */ - if (oversample_h > 1) { + if (oversample_h > config.oversample_h) { config.oversample_h = oversample_h; } - if (oversample_v > 1) { + if (oversample_v > config.oversample_v) { config.oversample_v = oversample_v; } /* set up the font atlas and add desired fonts */ nk_sdl_font_stash_begin(&atlas); - struct nk_font *default_font = nk_font_atlas_add_default(atlas, 12, &config); - /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, &config);*/ - /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, &config);*/ - /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, &config);*/ - /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, &config);*/ - /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, &config);*/ - /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, &config);*/ + default_font = nk_font_atlas_add_default(atlas, 13, &config); + /*droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, &config);*/ + /*roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, &config);*/ + /*future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, &config);*/ + /*clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, &config);*/ + /*tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, &config);*/ + /*cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, &config);*/ nk_sdl_font_stash_end(); /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ nk_style_set_font(ctx, &default_font->handle); From 04eac1db2a9c4b3d36d16e83e48ec399fcecdefb Mon Sep 17 00:00:00 2001 From: Kristian Bolino Date: Wed, 16 Mar 2022 16:47:36 -0400 Subject: [PATCH 07/61] Scale font height rather than oversampling --- demo/sdl_renderer/main.c | 45 +++++++++++++++------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/demo/sdl_renderer/main.c b/demo/sdl_renderer/main.c index 63625f8..d50f16c 100644 --- a/demo/sdl_renderer/main.c +++ b/demo/sdl_renderer/main.c @@ -76,10 +76,7 @@ main(int argc, char *argv[]) SDL_Renderer *renderer; int running = 1; int flags = 0; - - /* Nuklear settings */ - unsigned char oversample_h = 1; - unsigned char oversample_v = 1; + float font_scale = 1; /* GUI */ struct nk_context *ctx; @@ -126,12 +123,7 @@ main(int argc, char *argv[]) scale_x = (float)(render_w) / (float)(window_w); scale_y = (float)(render_h) / (float)(window_h); SDL_RenderSetScale(renderer, scale_x, scale_y); - if (scale_x > 1) { - oversample_h = 3 * nk_iceilf(scale_x); - } - if (scale_y > 1) { - oversample_v = nk_iceilf(scale_y); - } + font_scale = scale_y; } /* GUI */ @@ -141,28 +133,25 @@ main(int argc, char *argv[]) { struct nk_font_atlas *atlas; struct nk_font_config config = nk_font_config(0); - struct nk_font *default_font, *droid, *roboto, *future, *clean, *tiny, *cousine; + struct nk_font *font; - /* oversample the fonts for high-DPI displays */ - if (oversample_h > config.oversample_h) { - config.oversample_h = oversample_h; - } - if (oversample_v > config.oversample_v) { - config.oversample_v = oversample_v; - } - - /* set up the font atlas and add desired fonts */ + /* set up the font atlas and add desired font; note that font sizes are + * multiplied by font_scale to produce better results at higher DPIs */ nk_sdl_font_stash_begin(&atlas); - default_font = nk_font_atlas_add_default(atlas, 13, &config); - /*droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, &config);*/ - /*roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, &config);*/ - /*future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, &config);*/ - /*clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, &config);*/ - /*tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, &config);*/ - /*cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, &config);*/ + font = nk_font_atlas_add_default(atlas, 13 * font_scale, &config); + /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14 * font_scale, &config);*/ + /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16 * font_scale, &config);*/ + /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13 * font_scale, &config);*/ + /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12 * font_scale, &config);*/ + /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10 * font_scale, &config);*/ + /*font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13 * font_scale, &config);*/ nk_sdl_font_stash_end(); + + /* this hack makes the font appear to be scaled down to the desired + * size and is only necessary when font_scale > 1 */ + font->handle.height /= font_scale; /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ - nk_style_set_font(ctx, &default_font->handle); + nk_style_set_font(ctx, &font->handle); } #ifdef INCLUDE_STYLE From f58114e45e3992f8cb2634f20d4f8cd110ec384f Mon Sep 17 00:00:00 2001 From: crazyBaboon Date: Wed, 13 Apr 2022 22:44:14 +0100 Subject: [PATCH 08/61] file_browser.c - remove #include It is no longer necessary, since string comparison is now carried out by Nuklear API. --- demo/common/file_browser.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/demo/common/file_browser.c b/demo/common/file_browser.c index 3204629..74f11e9 100644 --- a/demo/common/file_browser.c +++ b/demo/common/file_browser.c @@ -1,3 +1,12 @@ +#ifdef __unix__ +#include +#include +#endif + +#ifndef _WIN32 +# include +#endif + struct icons { struct nk_image desktop; struct nk_image home; @@ -78,17 +87,6 @@ struct file_browser { struct media *media; }; -#ifdef __unix__ -#include -#include -#endif - -#ifndef _WIN32 -# include -#endif - -#include - static void die(const char *fmt, ...) { From c9d3a3fd20bedafd50db1426122ae25920bcd5f6 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 15 Apr 2022 17:20:20 -0400 Subject: [PATCH 09/61] file_browser: Bring string.h to the top --- demo/common/file_browser.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demo/common/file_browser.c b/demo/common/file_browser.c index 74f11e9..9095aa3 100644 --- a/demo/common/file_browser.c +++ b/demo/common/file_browser.c @@ -1,3 +1,5 @@ +#include // strcpy, strlen + #ifdef __unix__ #include #include @@ -454,7 +456,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx) /* draw and execute directory buttons */ if (nk_button_image(ctx,media->icons.directory)) index = (int)j; - + qsort(browser->directories, browser->dir_count, sizeof(char *), cmp_fn); nk_label(ctx, browser->directories[j], NK_TEXT_LEFT); } else { @@ -499,7 +501,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx) { fprintf(stdout, "File dialog has been closed!\n"); file_browser_is_open = nk_false; - } + } if(nk_button_label(ctx, "Open")) fprintf(stdout, "Insert routine to open/save the file!\n"); } From cacdf6baa46d5f28ecb573d4e02cb69b6f47830e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCssig?= Date: Thu, 12 May 2022 12:52:05 +0200 Subject: [PATCH 10/61] Added the arc methods to the GDI binding --- demo/gdi/nuklear_gdi.h | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index aef8425..70380ca 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -391,6 +391,60 @@ nk_gdi_stroke_polyline(HDC dc, const struct nk_vec2i *pnts, } } +static void +nk_gdi_stroke_arc(HDC dc, short cx, short cy, unsigned short r, float amin, float adelta, unsigned short line_thickness, struct nk_color col) +{ + COLORREF color = convert_color(col); + + /* setup pen */ + HPEN pen = NULL; + if (line_thickness == 1) + SetDCPenColor(dc, color); + else + { + /* the flat endcap makes thick arcs look better */ + DWORD pen_style = PS_SOLID | PS_ENDCAP_FLAT | PS_GEOMETRIC; + + LOGBRUSH brush; + brush.lbStyle = BS_SOLID; + brush.lbColor = color; + brush.lbHatch = 0; + + pen = ExtCreatePen(pen_style, line_thickness, &brush, 0, NULL); + SelectObject(dc, pen); + } + + /* calculate arc and draw */ + int start_x = cx + (int) ((float)r*nk_cos(amin+adelta)), + start_y = cy + (int) ((float)r*nk_sin(amin+adelta)), + end_x = cx + (int) ((float)r*nk_cos(amin)), + end_y = cy + (int) ((float)r*nk_sin(amin)); + + SetArcDirection(dc, AD_COUNTERCLOCKWISE); + Pie(dc, cx-r, cy-r, cx+r, cy+r, start_x, start_y, end_x, end_y); + + if (pen) + { + SelectObject(dc, GetStockObject(DC_PEN)); + DeleteObject(pen); + } +} + +static void +nk_gdi_fill_arc(HDC dc, short cx, short cy, unsigned short r, float amin, float adelta, struct nk_color col) +{ + COLORREF color = convert_color(col); + SetDCBrushColor(dc, color); + SetDCPenColor(dc, color); + + int start_x = cx + (int) ((float)r*nk_cos(amin+adelta)), + start_y = cy + (int) ((float)r*nk_sin(amin+adelta)), + end_x = cx + (int) ((float)r*nk_cos(amin)), + end_y = cy + (int) ((float)r*nk_sin(amin)); + + Pie(dc, cx-r, cy-r, cx+r, cy+r, start_x, start_y, end_x, end_y); +} + static void nk_gdi_fill_circle(HDC dc, short x, short y, unsigned short w, unsigned short h, struct nk_color col) @@ -414,6 +468,7 @@ nk_gdi_stroke_circle(HDC dc, short x, short y, unsigned short w, SelectObject(dc, pen); } + SelectObject(dc, GetStockObject(NULL_BRUSH)); SetDCBrushColor(dc, OPAQUE); Ellipse(dc, x, y, x + w, y + h); From 321badb389c96cb08c6f6a4217656cec26ebe3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCssig?= Date: Thu, 12 May 2022 12:52:44 +0200 Subject: [PATCH 11/61] Implemented select all for GDI --- demo/gdi/nuklear_gdi.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index 70380ca..e6c6878 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -771,6 +771,13 @@ nk_gdi_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) case VK_PRIOR: nk_input_key(&gdi.ctx, NK_KEY_SCROLL_UP, down); return 1; + + case 'A': + if (ctrl) { + nk_input_key(&gdi.ctx, NK_KEY_TEXT_SELECT_ALL, down); + return 1; + } + break; case 'C': if (ctrl) { From e698bb15315e3750ad0b8aa8a7b7c015e8d9cb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCssig?= Date: Thu, 12 May 2022 12:54:03 +0200 Subject: [PATCH 12/61] Added the GDI arc drawing commands to the dispatch switch-case --- demo/gdi/nuklear_gdi.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index e6c6878..3a01dd5 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -921,6 +921,14 @@ nk_gdi_render(struct nk_color clear) const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd; nk_gdi_fill_circle(memory_dc, c->x, c->y, c->w, c->h, c->color); } break; + case NK_COMMAND_ARC: { + const struct nk_command_arc *q = (const struct nk_command_arc *)cmd; + nk_gdi_stroke_arc(memory_dc, q->cx, q->cy, q->r, q->a[0], q->a[1], q->line_thickness, q->color); + } break; + case NK_COMMAND_ARC_FILLED: { + const struct nk_command_arc_filled *q = (const struct nk_command_arc_filled *)cmd; + nk_gdi_fill_arc(memory_dc, q->cx, q->cy, q->r, q->a[0], q->a[1], q->color); + } break; case NK_COMMAND_TRIANGLE: { const struct nk_command_triangle*t = (const struct nk_command_triangle*)cmd; nk_gdi_stroke_triangle(memory_dc, t->a.x, t->a.y, t->b.x, t->b.y, @@ -963,8 +971,7 @@ nk_gdi_render(struct nk_color clear) const struct nk_command_image *i = (const struct nk_command_image *)cmd; nk_gdi_draw_image(i->x, i->y, i->w, i->h, i->img, i->col); } break; - case NK_COMMAND_ARC: - case NK_COMMAND_ARC_FILLED: + case NK_COMMAND_CUSTOM: default: break; } } From 628cc61263c5ff2734e5ccd5ba730f0923ceafd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCssig?= Date: Thu, 12 May 2022 13:04:42 +0200 Subject: [PATCH 13/61] Added the wingdi header to the GDI binding --- demo/gdi/nuklear_gdi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index 3a01dd5..f60a087 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -15,6 +15,7 @@ #define WIN32_LEAN_AND_MEAN #include +#include typedef struct GdiFont GdiFont; NK_API struct nk_context* nk_gdi_init(GdiFont *font, HDC window_dc, unsigned int width, unsigned int height); From dca0f6fcfcfe9e3d9e4289b6530d789f01b08cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20M=C3=BCssig?= Date: Thu, 12 May 2022 13:30:18 +0200 Subject: [PATCH 14/61] Corrected the fill bugs in the GDI binding --- demo/gdi/nuklear_gdi.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index f60a087..8efc8da 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -421,8 +421,10 @@ nk_gdi_stroke_arc(HDC dc, short cx, short cy, unsigned short r, float amin, floa end_x = cx + (int) ((float)r*nk_cos(amin)), end_y = cy + (int) ((float)r*nk_sin(amin)); + HGDIOBJ br = SelectObject(dc, GetStockObject(NULL_BRUSH)); SetArcDirection(dc, AD_COUNTERCLOCKWISE); Pie(dc, cx-r, cy-r, cx+r, cy+r, start_x, start_y, end_x, end_y); + SelectObject(dc, br); if (pen) { @@ -468,10 +470,11 @@ nk_gdi_stroke_circle(HDC dc, short x, short y, unsigned short w, pen = CreatePen(PS_SOLID, line_thickness, color); SelectObject(dc, pen); } - - SelectObject(dc, GetStockObject(NULL_BRUSH)); + + HGDIOBJ br = SelectObject(dc, GetStockObject(NULL_BRUSH)); SetDCBrushColor(dc, OPAQUE); Ellipse(dc, x, y, x + w, y + h); + SelectObject(dc, br); if (pen) { SelectObject(dc, GetStockObject(DC_PEN)); From a931a8d499ecb59334bcda5f21c6b15e414c07a2 Mon Sep 17 00:00:00 2001 From: tcdude Date: Fri, 27 May 2022 04:12:11 +0200 Subject: [PATCH 15/61] Fix regression introduced in #448 This adds a new `nk_input_has_mouse_click_in_rect_button` function that is being used only by buttons. This allows `nk_input_has_mouse_click_in_rect` to act as its name suggests while still allowing for the behavior introduced in #448 --- nuklear.h | 15 ++++++++++++++- src/CHANGELOG | 1 + src/nuklear.h | 1 + src/nuklear_button.c | 2 +- src/nuklear_input.c | 11 +++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/nuklear.h b/nuklear.h index 38d72c8..121cf91 100644 --- a/nuklear.h +++ b/nuklear.h @@ -4682,6 +4682,7 @@ struct nk_input { NK_API nk_bool nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); NK_API nk_bool nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_has_mouse_click_in_rect_button(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, nk_bool down); NK_API nk_bool nk_input_is_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b, nk_bool down); @@ -17947,6 +17948,17 @@ nk_input_has_mouse_click(const struct nk_input *i, enum nk_buttons id) NK_API nk_bool nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; + if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) + return nk_false; + return nk_true; +} +NK_API nk_bool +nk_input_has_mouse_click_in_rect_button(const struct nk_input *i, enum nk_buttons id, + struct nk_rect b) { const struct nk_mouse_button *btn; if (!i) return nk_false; @@ -23770,7 +23782,7 @@ nk_button_behavior(nk_flags *state, struct nk_rect r, *state = NK_WIDGET_STATE_HOVERED; if (nk_input_is_mouse_down(i, NK_BUTTON_LEFT)) *state = NK_WIDGET_STATE_ACTIVE; - if (nk_input_has_mouse_click_in_rect(i, NK_BUTTON_LEFT, r)) { + if (nk_input_has_mouse_click_in_rect_button(i, NK_BUTTON_LEFT, r)) { ret = (behavior != NK_BUTTON_DEFAULT) ? nk_input_is_mouse_down(i, NK_BUTTON_LEFT): #ifdef NK_BUTTON_TRIGGER_ON_RELEASE @@ -29644,6 +29656,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_rect_button() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down /// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS diff --git a/src/CHANGELOG b/src/CHANGELOG index 869c890..7f05782 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_rect_button() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down /// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS diff --git a/src/nuklear.h b/src/nuklear.h index 7979958..6d06be9 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -4461,6 +4461,7 @@ struct nk_input { NK_API nk_bool nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); NK_API nk_bool nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_has_mouse_click_in_rect_button(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, nk_bool down); NK_API nk_bool nk_input_is_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b, nk_bool down); diff --git a/src/nuklear_button.c b/src/nuklear_button.c index 54f02f7..5ca736c 100644 --- a/src/nuklear_button.c +++ b/src/nuklear_button.c @@ -70,7 +70,7 @@ nk_button_behavior(nk_flags *state, struct nk_rect r, *state = NK_WIDGET_STATE_HOVERED; if (nk_input_is_mouse_down(i, NK_BUTTON_LEFT)) *state = NK_WIDGET_STATE_ACTIVE; - if (nk_input_has_mouse_click_in_rect(i, NK_BUTTON_LEFT, r)) { + if (nk_input_has_mouse_click_in_rect_button(i, NK_BUTTON_LEFT, r)) { ret = (behavior != NK_BUTTON_DEFAULT) ? nk_input_is_mouse_down(i, NK_BUTTON_LEFT): #ifdef NK_BUTTON_TRIGGER_ON_RELEASE diff --git a/src/nuklear_input.c b/src/nuklear_input.c index b22afa6..c959a32 100644 --- a/src/nuklear_input.c +++ b/src/nuklear_input.c @@ -146,6 +146,17 @@ nk_input_has_mouse_click(const struct nk_input *i, enum nk_buttons id) NK_API nk_bool nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; + if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) + return nk_false; + return nk_true; +} +NK_API nk_bool +nk_input_has_mouse_click_in_rect_button(const struct nk_input *i, enum nk_buttons id, + struct nk_rect b) { const struct nk_mouse_button *btn; if (!i) return nk_false; From 5bb591b0fbb880cda5b71be780e2c7442e161633 Mon Sep 17 00:00:00 2001 From: tcdude Date: Fri, 27 May 2022 21:28:34 +0200 Subject: [PATCH 16/61] Rename function --- nuklear.h | 8 ++++---- src/CHANGELOG | 2 +- src/nuklear.h | 2 +- src/nuklear_button.c | 2 +- src/nuklear_input.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nuklear.h b/nuklear.h index 121cf91..aef8f7f 100644 --- a/nuklear.h +++ b/nuklear.h @@ -4682,7 +4682,7 @@ struct nk_input { NK_API nk_bool nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); NK_API nk_bool nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); -NK_API nk_bool nk_input_has_mouse_click_in_rect_button(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_has_mouse_click_in_button_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, nk_bool down); NK_API nk_bool nk_input_is_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b, nk_bool down); @@ -17957,7 +17957,7 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, return nk_true; } NK_API nk_bool -nk_input_has_mouse_click_in_rect_button(const struct nk_input *i, enum nk_buttons id, +nk_input_has_mouse_click_in_button_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b) { const struct nk_mouse_button *btn; @@ -23782,7 +23782,7 @@ nk_button_behavior(nk_flags *state, struct nk_rect r, *state = NK_WIDGET_STATE_HOVERED; if (nk_input_is_mouse_down(i, NK_BUTTON_LEFT)) *state = NK_WIDGET_STATE_ACTIVE; - if (nk_input_has_mouse_click_in_rect_button(i, NK_BUTTON_LEFT, r)) { + if (nk_input_has_mouse_click_in_button_rect(i, NK_BUTTON_LEFT, r)) { ret = (behavior != NK_BUTTON_DEFAULT) ? nk_input_is_mouse_down(i, NK_BUTTON_LEFT): #ifdef NK_BUTTON_TRIGGER_ON_RELEASE @@ -29656,7 +29656,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_rect_button() to fix window move bug +/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down /// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS diff --git a/src/CHANGELOG b/src/CHANGELOG index 7f05782..44223af 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,7 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_rect_button() to fix window move bug +/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down /// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS diff --git a/src/nuklear.h b/src/nuklear.h index 6d06be9..67b2aa9 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -4461,7 +4461,7 @@ struct nk_input { NK_API nk_bool nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); NK_API nk_bool nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); -NK_API nk_bool nk_input_has_mouse_click_in_rect_button(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_has_mouse_click_in_button_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, nk_bool down); NK_API nk_bool nk_input_is_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b, nk_bool down); diff --git a/src/nuklear_button.c b/src/nuklear_button.c index 5ca736c..2636b60 100644 --- a/src/nuklear_button.c +++ b/src/nuklear_button.c @@ -70,7 +70,7 @@ nk_button_behavior(nk_flags *state, struct nk_rect r, *state = NK_WIDGET_STATE_HOVERED; if (nk_input_is_mouse_down(i, NK_BUTTON_LEFT)) *state = NK_WIDGET_STATE_ACTIVE; - if (nk_input_has_mouse_click_in_rect_button(i, NK_BUTTON_LEFT, r)) { + if (nk_input_has_mouse_click_in_button_rect(i, NK_BUTTON_LEFT, r)) { ret = (behavior != NK_BUTTON_DEFAULT) ? nk_input_is_mouse_down(i, NK_BUTTON_LEFT): #ifdef NK_BUTTON_TRIGGER_ON_RELEASE diff --git a/src/nuklear_input.c b/src/nuklear_input.c index c959a32..e438581 100644 --- a/src/nuklear_input.c +++ b/src/nuklear_input.c @@ -155,7 +155,7 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, return nk_true; } NK_API nk_bool -nk_input_has_mouse_click_in_rect_button(const struct nk_input *i, enum nk_buttons id, +nk_input_has_mouse_click_in_button_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b) { const struct nk_mouse_button *btn; From 50277a1c39e3077aaf42bf814f5d5363a7dbc1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20F=C3=BCchsl?= Date: Sun, 29 May 2022 01:47:00 +0200 Subject: [PATCH 17/61] Changed windows include to lowercase --- demo/gdi_native_nuklear/main.c | 2 +- demo/gdi_native_nuklear/window.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/gdi_native_nuklear/main.c b/demo/gdi_native_nuklear/main.c index b6cb6a9..349adea 100644 --- a/demo/gdi_native_nuklear/main.c +++ b/demo/gdi_native_nuklear/main.c @@ -1,4 +1,4 @@ -#include +#include #pragma comment(linker,"\"/manifestdependency:type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ diff --git a/demo/gdi_native_nuklear/window.h b/demo/gdi_native_nuklear/window.h index 0db572f..f78d574 100644 --- a/demo/gdi_native_nuklear/window.h +++ b/demo/gdi_native_nuklear/window.h @@ -3,7 +3,7 @@ #define NK_GDI_WINDOW_CLS L"WNDCLS_NkGdi" -#include +#include /* Functin pointer types for window callbacks */ typedef int(*nkgdi_window_func_close)(void); From adeb2a720fd4836b5e69e075e277866f3c3e80c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20F=C3=BCchsl?= Date: Mon, 30 May 2022 22:49:12 +0200 Subject: [PATCH 18/61] Added wWinMain comment --- demo/gdi_native_nuklear/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/demo/gdi_native_nuklear/main.c b/demo/gdi_native_nuklear/main.c index 349adea..d12f972 100644 --- a/demo/gdi_native_nuklear/main.c +++ b/demo/gdi_native_nuklear/main.c @@ -84,17 +84,19 @@ int drawCallback(struct nk_context* ctx) return 1; } -/* Main entry point (Windows wchar_t) */ +/* Main entry point - wWinMain used for UNICODE + * (You can also use _tWinMain(...) to automaticaly use the ASCII or WIDE char entry point base on your build) + */ INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, PWSTR _In_ cmdArgs, INT _In_ cmdShow) { /* Call this first to setup all required prerequisites */ nkgdi_window_init(); - + /* Preparing two window contexts */ struct nkgdi_window w1, w2; memset(&w1, 0x0, sizeof(struct nkgdi_window)); memset(&w2, 0x0, sizeof(struct nkgdi_window)); - + /* Configure and create window 1. * Note: You can allways change the direct accesible parameters later as well! */ From ed3ff76d0eb8c2db2e9127075ad666c829f14bdf Mon Sep 17 00:00:00 2001 From: ryuukk Date: Mon, 27 Jun 2022 00:15:14 +0200 Subject: [PATCH 19/61] rename null texture field to tex_null --- src/nuklear.h | 4 ++-- src/nuklear_vertex.c | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/nuklear.h b/src/nuklear.h index 67b2aa9..4ced6b9 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -906,7 +906,7 @@ NK_API void nk_input_end(struct nk_context*); /// cfg.curve_segment_count = 22; /// cfg.arc_segment_count = 22; /// cfg.global_alpha = 1.0f; -/// cfg.null = dev->null; +/// cfg.tex_null = dev->tex_null; /// // /// // setup buffers and convert /// struct nk_buffer cmds, verts, idx; @@ -956,7 +956,7 @@ struct nk_convert_config { unsigned circle_segment_count; /* number of segments used for circles: default to 22 */ unsigned arc_segment_count; /* number of segments used for arcs: default to 22 */ unsigned curve_segment_count; /* number of segments used for curves: default to 22 */ - struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */ + struct nk_draw_null_texture tex_null; /* handle to texture with a white pixel for shape drawing */ const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */ nk_size vertex_size; /* sizeof one vertex for vertex packing */ nk_size vertex_alignment; /* vertex alignment: Can be obtained by NK_ALIGNOF */ diff --git a/src/nuklear_vertex.c b/src/nuklear_vertex.c index b98eb1e..ce1f94e 100644 --- a/src/nuklear_vertex.c +++ b/src/nuklear_vertex.c @@ -177,7 +177,7 @@ nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect) NK_ASSERT(list); if (!list) return; if (!list->cmd_count) { - nk_draw_list_push_command(list, rect, list->config.null.texture); + nk_draw_list_push_command(list, rect, list->config.tex_null.texture); } else { struct nk_draw_command *prev = nk_draw_list_command_last(list); if (prev->elem_count == 0) @@ -532,7 +532,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p /* fill vertices */ for (i = 0; i < points_count; ++i) { - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col); vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans); vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans); @@ -597,7 +597,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p /* add vertices */ for (i = 0; i < points_count; ++i) { - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans); vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col); vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col); @@ -618,7 +618,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p for (i1 = 0; i1 < count; ++i1) { float dx, dy; - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1; const struct nk_vec2 p1 = points[i1]; const struct nk_vec2 p2 = points[i2]; @@ -728,7 +728,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list, /* add vertices + indexes */ for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) { - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; struct nk_vec2 n0 = normals[i0]; struct nk_vec2 n1 = normals[i1]; struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f); @@ -765,7 +765,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list, if (!vtx || !ids) return; for (i = 0; i < vtx_count; ++i) - vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.null.uv, col); + vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.tex_null.uv, col); for (i = 2; i < points_count; ++i) { ids[0] = (nk_draw_index)index; ids[1] = (nk_draw_index)(index+ i - 1); @@ -794,8 +794,8 @@ nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos) nk_draw_list_add_clip(list, nk_null_rect); cmd = nk_draw_list_command_last(list); - if (cmd && cmd->texture.ptr != list->config.null.texture.ptr) - nk_draw_list_push_image(list, list->config.null.texture); + if (cmd && cmd->texture.ptr != list->config.tex_null.texture.ptr) + nk_draw_list_push_image(list, list->config.tex_null.texture); points = nk_draw_list_alloc_path(list, 1); if (!points) return; @@ -997,7 +997,7 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec NK_ASSERT(list); if (!list) return; - nk_draw_list_push_image(list, list->config.null.texture); + nk_draw_list_push_image(list, list->config.tex_null.texture); index = (nk_draw_index)list->vertex_count; vtx = nk_draw_list_alloc_vertices(list, 4); idx = nk_draw_list_alloc_elements(list, 6); @@ -1007,10 +1007,10 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0); idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.null.uv, col_left); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.null.uv, col_top); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.null.uv, col_right); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.null.uv, col_bottom); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.tex_null.uv, col_left); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.tex_null.uv, col_top); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.tex_null.uv, col_right); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.tex_null.uv, col_bottom); } NK_API void nk_draw_list_fill_triangle(struct nk_draw_list *list, struct nk_vec2 a, From 7597cc7a09eed867a9afe520a9ad74a5bed0f3b7 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 9 Jul 2022 17:18:15 -0400 Subject: [PATCH 20/61] x11: Free XVisualInfo after use Fixes #473 --- demo/x11_opengl2/main.c | 1 + demo/x11_opengl3/main.c | 1 + 2 files changed, 2 insertions(+) diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index e751eef..5145c3b 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -172,6 +172,7 @@ int main(void) glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) fb_best = i, best_num_samples = samples; + XFree(vi); } } win.fbc = fbc[fb_best]; diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index 7e415b5..faaad12 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -170,6 +170,7 @@ int main(void) glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) fb_best = i, best_num_samples = samples; + XFree(vi); } } win.fbc = fbc[fb_best]; From 3b5009255e8fdcf13d0e4b7895812f0acd561c0e Mon Sep 17 00:00:00 2001 From: opsJson <54485405+opsJson@users.noreply.github.com> Date: Mon, 25 Jul 2022 20:07:20 -0300 Subject: [PATCH 21/61] Fix Shift + End in nk_edit --- nuklear.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuklear.h b/nuklear.h index aef8f7f..fde970a 100644 --- a/nuklear.h +++ b/nuklear.h @@ -26423,6 +26423,7 @@ retry: if (shift_mod) { nk_textedit_prep_selection_at_cursor(state); state->cursor = state->select_end = state->string.len; + if (state->select_start >= state->select_end) state->select_start = 0; state->has_preferred_x = 0; } else { state->cursor = state->string.len; @@ -30006,4 +30007,3 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// in libraries and brought me to create some of my own. Finally Apoorva Joshi /// for his single header file packer. */ - From ec4acc7cf4e6e53d604d17e6cab5019233a221cc Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 30 Jul 2022 17:38:10 -0400 Subject: [PATCH 22/61] Rename the null variable to tex_null --- demo/d3d11/nuklear_d3d11.h | 8 +++--- demo/d3d12/nuklear_d3d12.h | 24 ++++++++-------- demo/d3d9/nuklear_d3d9.h | 6 ++-- demo/glfw_opengl2/nuklear_glfw_gl2.h | 2 +- demo/glfw_opengl3/nuklear_glfw_gl3.h | 2 +- demo/glfw_opengl4/nuklear_glfw_gl4.h | 2 +- demo/sdl_opengl2/nuklear_sdl_gl2.h | 2 +- demo/sdl_opengl3/nuklear_sdl_gl3.h | 2 +- demo/sdl_opengles2/nuklear_sdl_gles2.h | 8 +++--- demo/sdl_renderer/nuklear_sdl_renderer.h | 2 +- demo/sfml_opengl2/nuklear_sfml_gl2.h | 4 +-- demo/sfml_opengl3/nuklear_sfml_gl3.h | 4 +-- demo/x11_opengl2/nuklear_xlib_gl2.h | 2 +- demo/x11_opengl3/nuklear_xlib_gl3.h | 2 +- example/canvas.c | 36 ++++++++++++------------ example/extended.c | 2 +- example/file_browser.c | 2 +- example/skinning.c | 2 +- nuklear.h | 31 ++++++++++---------- src/CHANGELOG | 1 + 20 files changed, 73 insertions(+), 71 deletions(-) diff --git a/demo/d3d11/nuklear_d3d11.h b/demo/d3d11/nuklear_d3d11.h index b716632..46c615d 100644 --- a/demo/d3d11/nuklear_d3d11.h +++ b/demo/d3d11/nuklear_d3d11.h @@ -137,7 +137,7 @@ nk_d3d11_render(ID3D11DeviceContext *context, enum nk_anti_aliasing AA) config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; - config.null = d3d11.null; + config.tex_null = d3d11.null; {/* setup buffers to load vertices and elements */ struct nk_buffer vbuf, ibuf; @@ -373,7 +373,7 @@ nk_d3d11_clipboard_paste(nk_handle usr, struct nk_text_edit *edit) (void)usr; if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) { - HGLOBAL mem = GetClipboardData(CF_UNICODETEXT); + HGLOBAL mem = GetClipboardData(CF_UNICODETEXT); if (mem) { SIZE_T size = GlobalSize(mem) - 1; @@ -393,7 +393,7 @@ nk_d3d11_clipboard_paste(nk_handle usr, struct nk_text_edit *edit) free(utf8); } } - GlobalUnlock(mem); + GlobalUnlock(mem); } } } @@ -419,7 +419,7 @@ nk_d3d11_clipboard_copy(nk_handle usr, const char *text, int len) MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); wstr[wsize] = 0; GlobalUnlock(mem); - SetClipboardData(CF_UNICODETEXT, mem); + SetClipboardData(CF_UNICODETEXT, mem); } } } diff --git a/demo/d3d12/nuklear_d3d12.h b/demo/d3d12/nuklear_d3d12.h index a235d69..1660d7b 100644 --- a/demo/d3d12/nuklear_d3d12.h +++ b/demo/d3d12/nuklear_d3d12.h @@ -2,7 +2,7 @@ * Nuklear - 1.32.0 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke - * + * * D3D12 backend created by Ludwig Fuechsl (2022) */ /* @@ -30,7 +30,7 @@ NK_API struct nk_context *nk_d3d12_init(ID3D12Device *device, int width, int hei NK_API void nk_d3d12_font_stash_begin(struct nk_font_atlas **atlas); /* * USAGE: - * - Call this function after a call to nk_d3d12_font_stash_begin(...) when all fonts have been loaded and configured. + * - Call this function after a call to nk_d3d12_font_stash_begin(...) when all fonts have been loaded and configured. * - This function will place commands on the supplied ID3D12GraphicsCommandList. * - This function will allocate temporary data that is required until the command list has finish executing. The temporary data can be free by calling nk_d3d12_font_stash_cleanup(...) */ @@ -96,7 +96,7 @@ NK_API void nk_d3d12_shutdown(void); #include "nuklear_d3d12_vertex_shader.h" #include "nuklear_d3d12_pixel_shader.h" -struct nk_d3d12_vertex +struct nk_d3d12_vertex { float position[2]; float uv[2]; @@ -198,7 +198,7 @@ nk_d3d12_render(ID3D12GraphicsCommandList *command_list, enum nk_anti_aliasing A config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; - config.null = d3d12.null; + config.tex_null = d3d12.null; struct nk_buffer vbuf, ibuf; nk_buffer_init_fixed(&vbuf, &ptr_data[sizeof(float) * 4 * 4], (size_t)d3d12.max_vertex_buffer); @@ -505,7 +505,7 @@ nk_d3d12_clipboard_paste(nk_handle usr, struct nk_text_edit *edit) (void)usr; if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) { - HGLOBAL mem = GetClipboardData(CF_UNICODETEXT); + HGLOBAL mem = GetClipboardData(CF_UNICODETEXT); if (mem) { SIZE_T size = GlobalSize(mem) - 1; @@ -525,7 +525,7 @@ nk_d3d12_clipboard_paste(nk_handle usr, struct nk_text_edit *edit) free(utf8); } } - GlobalUnlock(mem); + GlobalUnlock(mem); } } } @@ -551,7 +551,7 @@ nk_d3d12_clipboard_copy(nk_handle usr, const char *text, int len) MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); wstr[wsize] = 0; GlobalUnlock(mem); - SetClipboardData(CF_UNICODETEXT, mem); + SetClipboardData(CF_UNICODETEXT, mem); } } } @@ -566,7 +566,7 @@ nk_d3d12_init(ID3D12Device *device, int width, int height, unsigned int max_vert D3D12_CONSTANT_BUFFER_VIEW_DESC cbv; D3D12_CPU_DESCRIPTOR_HANDLE cbv_handle; - /* Do plain object / ref copys */ + /* Do plain object / ref copys */ d3d12.max_vertex_buffer = max_vertex_buffer; d3d12.max_index_buffer = max_index_buffer; d3d12.max_user_textures = max_user_textures; @@ -679,7 +679,7 @@ nk_d3d12_init(ID3D12Device *device, int width, int height, unsigned int max_vert /* Get address of first handle (CPU and GPU) */ ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(d3d12.desc_heap, &d3d12.cpu_descriptor_handle); ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(d3d12.desc_heap, &d3d12.gpu_descriptor_handle); - + /* Get addresses of vertex & index buffers */ d3d12.gpu_vertex_buffer_address = ID3D12Resource_GetGPUVirtualAddress(d3d12.vertex_buffer); d3d12.gpu_index_buffer_address = ID3D12Resource_GetGPUVirtualAddress(d3d12.index_buffer); @@ -870,7 +870,7 @@ nk_d3d12_font_stash_end(ID3D12GraphicsCommandList *command_list) nk_style_set_font(&d3d12.ctx, &d3d12.atlas.default_font->handle); } -NK_API +NK_API void nk_d3d12_font_stash_cleanup() { if(d3d12.font_upload_buffer) @@ -880,7 +880,7 @@ void nk_d3d12_font_stash_cleanup() } } -NK_API +NK_API nk_bool nk_d3d12_set_user_texture(unsigned int index, ID3D12Resource* texture, const D3D12_SHADER_RESOURCE_VIEW_DESC* description, nk_handle* handle_out) { nk_bool result = nk_false; @@ -919,7 +919,7 @@ void nk_d3d12_shutdown(void) ID3D12Resource_Release(d3d12.const_buffer); ID3D12Resource_Release(d3d12.index_buffer); ID3D12Resource_Release(d3d12.vertex_buffer); - if(d3d12.font_texture) + if(d3d12.font_texture) ID3D12Resource_Release(d3d12.font_texture); if(d3d12.font_upload_buffer) ID3D12Resource_Release(d3d12.font_upload_buffer); diff --git a/demo/d3d9/nuklear_d3d9.h b/demo/d3d9/nuklear_d3d9.h index 9a6fe4c..1aee6ba 100644 --- a/demo/d3d9/nuklear_d3d9.h +++ b/demo/d3d9/nuklear_d3d9.h @@ -150,7 +150,7 @@ nk_d3d9_render(enum nk_anti_aliasing AA) config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; - config.null = d3d9.null; + config.tex_null = d3d9.null; /* convert shapes into vertexes */ nk_buffer_init_default(&vbuf); @@ -468,7 +468,7 @@ nk_d3d9_clipboard_paste(nk_handle usr, struct nk_text_edit *edit) } } - GlobalUnlock(mem); + GlobalUnlock(mem); CloseClipboard(); } @@ -491,7 +491,7 @@ nk_d3d9_clipboard_copy(nk_handle usr, const char *text, int len) MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); wstr[wsize] = 0; GlobalUnlock(mem); - SetClipboardData(CF_UNICODETEXT, mem); + SetClipboardData(CF_UNICODETEXT, mem); } } } diff --git a/demo/glfw_opengl2/nuklear_glfw_gl2.h b/demo/glfw_opengl2/nuklear_glfw_gl2.h index 6eb43cb..97e3b6e 100644 --- a/demo/glfw_opengl2/nuklear_glfw_gl2.h +++ b/demo/glfw_opengl2/nuklear_glfw_gl2.h @@ -140,7 +140,7 @@ nk_glfw3_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/glfw_opengl3/nuklear_glfw_gl3.h b/demo/glfw_opengl3/nuklear_glfw_gl3.h index fcc8335..573b76d 100644 --- a/demo/glfw_opengl3/nuklear_glfw_gl3.h +++ b/demo/glfw_opengl3/nuklear_glfw_gl3.h @@ -266,7 +266,7 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/glfw_opengl4/nuklear_glfw_gl4.h b/demo/glfw_opengl4/nuklear_glfw_gl4.h index 6e77627..6f1e259 100644 --- a/demo/glfw_opengl4/nuklear_glfw_gl4.h +++ b/demo/glfw_opengl4/nuklear_glfw_gl4.h @@ -407,7 +407,7 @@ nk_glfw3_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_opengl2/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h index 93ca705..7850d65 100644 --- a/demo/sdl_opengl2/nuklear_sdl_gl2.h +++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h @@ -120,7 +120,7 @@ nk_sdl_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_opengl3/nuklear_sdl_gl3.h b/demo/sdl_opengl3/nuklear_sdl_gl3.h index 5a89869..26036f1 100644 --- a/demo/sdl_opengl3/nuklear_sdl_gl3.h +++ b/demo/sdl_opengl3/nuklear_sdl_gl3.h @@ -247,7 +247,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_opengles2/nuklear_sdl_gles2.h b/demo/sdl_opengles2/nuklear_sdl_gles2.h index e2f297f..592e0db 100644 --- a/demo/sdl_opengles2/nuklear_sdl_gles2.h +++ b/demo/sdl_opengles2/nuklear_sdl_gles2.h @@ -103,7 +103,7 @@ nk_sdl_device_create(void) "}\n"; struct nk_sdl_device *dev = &sdl.ogl; - + nk_buffer_init_default(&dev->cmds); dev->prog = glCreateProgram(); dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER); @@ -133,7 +133,7 @@ nk_sdl_device_create(void) dev->vp = offsetof(struct nk_sdl_vertex, position); dev->vt = offsetof(struct nk_sdl_vertex, uv); dev->vc = offsetof(struct nk_sdl_vertex, col); - + /* Allocate buffers */ glGenBuffers(1, &dev->vbo); glGenBuffers(1, &dev->ebo); @@ -214,7 +214,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b /* Bind buffers */ glBindBuffer(GL_ARRAY_BUFFER, dev->vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo); - + { /* buffer setup */ glEnableVertexAttribArray((GLuint)dev->attrib_pos); @@ -245,7 +245,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_renderer/nuklear_sdl_renderer.h b/demo/sdl_renderer/nuklear_sdl_renderer.h index bd85044..702d56c 100644 --- a/demo/sdl_renderer/nuklear_sdl_renderer.h +++ b/demo/sdl_renderer/nuklear_sdl_renderer.h @@ -113,7 +113,7 @@ nk_sdl_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sfml_opengl2/nuklear_sfml_gl2.h b/demo/sfml_opengl2/nuklear_sfml_gl2.h index 728d899..1f9fcd1 100644 --- a/demo/sfml_opengl2/nuklear_sfml_gl2.h +++ b/demo/sfml_opengl2/nuklear_sfml_gl2.h @@ -59,7 +59,7 @@ nk_sfml_device_upload_atlas(const void* image, int width, int height) glBindTexture(GL_TEXTURE_2D, dev->font_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); } @@ -118,7 +118,7 @@ nk_sfml_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sfml_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sfml_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sfml_opengl3/nuklear_sfml_gl3.h b/demo/sfml_opengl3/nuklear_sfml_gl3.h index 27d7511..0038b34 100644 --- a/demo/sfml_opengl3/nuklear_sfml_gl3.h +++ b/demo/sfml_opengl3/nuklear_sfml_gl3.h @@ -248,7 +248,7 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_ config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sfml_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sfml_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; @@ -451,7 +451,7 @@ nk_sfml_handle_event(sf::Event* evt) return 1; } else if(evt->type == sf::Event::TextEntered) { /* 8 ~ backspace */ - if (evt->text.unicode != 8) { + if (evt->text.unicode != 8) { nk_input_unicode(ctx, evt->text.unicode); } return 1; diff --git a/demo/x11_opengl2/nuklear_xlib_gl2.h b/demo/x11_opengl2/nuklear_xlib_gl2.h index de720f4..9e1382e 100644 --- a/demo/x11_opengl2/nuklear_xlib_gl2.h +++ b/demo/x11_opengl2/nuklear_xlib_gl2.h @@ -153,7 +153,7 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_x11_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_x11_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/x11_opengl3/nuklear_xlib_gl3.h b/demo/x11_opengl3/nuklear_xlib_gl3.h index bc25109..85ff2ae 100644 --- a/demo/x11_opengl3/nuklear_xlib_gl3.h +++ b/demo/x11_opengl3/nuklear_xlib_gl3.h @@ -536,7 +536,7 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_x11_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_x11_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/example/canvas.c b/example/canvas.c index 5f651cc..d8a1534 100644 --- a/example/canvas.c +++ b/example/canvas.c @@ -78,24 +78,24 @@ die(const char *fmt, ...) exit(EXIT_FAILURE); } -static struct nk_image -icon_load(const char *filename) -{ - int x,y,n; - GLuint tex; - unsigned char *data = stbi_load(filename, &x, &y, &n, 0); - if (!data) die("[SDL]: failed to load image: %s", filename); +static struct nk_image +icon_load(const char *filename) +{ + int x,y,n; + GLuint tex; + unsigned char *data = stbi_load(filename, &x, &y, &n, 0); + if (!data) die("[SDL]: failed to load image: %s", filename); - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - glGenerateMipmap(GL_TEXTURE_2D); - stbi_image_free(data); - return nk_image_id((int)tex); + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glGenerateMipmap(GL_TEXTURE_2D); + stbi_image_free(data); + return nk_image_id((int)tex); } */ @@ -262,7 +262,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/example/extended.c b/example/extended.c index f1ae3c1..41f2fa2 100644 --- a/example/extended.c +++ b/example/extended.c @@ -685,7 +685,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/example/file_browser.c b/example/file_browser.c index 7286d5f..60e6ac2 100644 --- a/example/file_browser.c +++ b/example/file_browser.c @@ -722,7 +722,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/example/skinning.c b/example/skinning.c index 54f71e4..b54b03d 100644 --- a/example/skinning.c +++ b/example/skinning.c @@ -286,7 +286,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.null = dev->null; + config.tex_null = dev->null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/nuklear.h b/nuklear.h index aef8f7f..90d8b2d 100644 --- a/nuklear.h +++ b/nuklear.h @@ -1127,7 +1127,7 @@ NK_API void nk_input_end(struct nk_context*); /// cfg.curve_segment_count = 22; /// cfg.arc_segment_count = 22; /// cfg.global_alpha = 1.0f; -/// cfg.null = dev->null; +/// cfg.tex_null = dev->tex_null; /// // /// // setup buffers and convert /// struct nk_buffer cmds, verts, idx; @@ -1177,7 +1177,7 @@ struct nk_convert_config { unsigned circle_segment_count; /* number of segments used for circles: default to 22 */ unsigned arc_segment_count; /* number of segments used for arcs: default to 22 */ unsigned curve_segment_count; /* number of segments used for curves: default to 22 */ - struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */ + struct nk_draw_null_texture tex_null; /* handle to texture with a white pixel for shape drawing */ const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */ nk_size vertex_size; /* sizeof one vertex for vertex packing */ nk_size vertex_alignment; /* vertex alignment: Can be obtained by NK_ALIGNOF */ @@ -9563,7 +9563,7 @@ nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect) NK_ASSERT(list); if (!list) return; if (!list->cmd_count) { - nk_draw_list_push_command(list, rect, list->config.null.texture); + nk_draw_list_push_command(list, rect, list->config.tex_null.texture); } else { struct nk_draw_command *prev = nk_draw_list_command_last(list); if (prev->elem_count == 0) @@ -9918,7 +9918,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p /* fill vertices */ for (i = 0; i < points_count; ++i) { - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col); vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans); vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans); @@ -9983,7 +9983,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p /* add vertices */ for (i = 0; i < points_count; ++i) { - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans); vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col); vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col); @@ -10004,7 +10004,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p for (i1 = 0; i1 < count; ++i1) { float dx, dy; - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1; const struct nk_vec2 p1 = points[i1]; const struct nk_vec2 p2 = points[i2]; @@ -10114,7 +10114,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list, /* add vertices + indexes */ for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) { - const struct nk_vec2 uv = list->config.null.uv; + const struct nk_vec2 uv = list->config.tex_null.uv; struct nk_vec2 n0 = normals[i0]; struct nk_vec2 n1 = normals[i1]; struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f); @@ -10151,7 +10151,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list, if (!vtx || !ids) return; for (i = 0; i < vtx_count; ++i) - vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.null.uv, col); + vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.tex_null.uv, col); for (i = 2; i < points_count; ++i) { ids[0] = (nk_draw_index)index; ids[1] = (nk_draw_index)(index+ i - 1); @@ -10180,8 +10180,8 @@ nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos) nk_draw_list_add_clip(list, nk_null_rect); cmd = nk_draw_list_command_last(list); - if (cmd && cmd->texture.ptr != list->config.null.texture.ptr) - nk_draw_list_push_image(list, list->config.null.texture); + if (cmd && cmd->texture.ptr != list->config.tex_null.texture.ptr) + nk_draw_list_push_image(list, list->config.tex_null.texture); points = nk_draw_list_alloc_path(list, 1); if (!points) return; @@ -10383,7 +10383,7 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec NK_ASSERT(list); if (!list) return; - nk_draw_list_push_image(list, list->config.null.texture); + nk_draw_list_push_image(list, list->config.tex_null.texture); index = (nk_draw_index)list->vertex_count; vtx = nk_draw_list_alloc_vertices(list, 4); idx = nk_draw_list_alloc_elements(list, 6); @@ -10393,10 +10393,10 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0); idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.null.uv, col_left); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.null.uv, col_top); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.null.uv, col_right); - vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.null.uv, col_bottom); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.tex_null.uv, col_left); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.tex_null.uv, col_top); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.tex_null.uv, col_right); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.tex_null.uv, col_bottom); } NK_API void nk_draw_list_fill_triangle(struct nk_draw_list *list, struct nk_vec2 a, @@ -29656,6 +29656,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/07/30 (4.10.1) - Renamed the `null` texture variable to `tex_null` /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down diff --git a/src/CHANGELOG b/src/CHANGELOG index 44223af..619468c 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/07/30 (4.10.1) - Renamed the `null` texture variable to `tex_null` /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down From 54fd67bddd8aa82beed67cf29667ae403e319508 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 30 Jul 2022 17:43:46 -0400 Subject: [PATCH 23/61] Rename additional .null variables --- demo/d3d11/nuklear_d3d11.h | 6 +++--- demo/d3d12/nuklear_d3d12.h | 6 +++--- demo/d3d9/nuklear_d3d9.h | 6 +++--- demo/glfw_opengl2/nuklear_glfw_gl2.h | 4 ++-- demo/glfw_opengl3/nuklear_glfw_gl3.h | 4 ++-- demo/glfw_opengl4/nuklear_glfw_gl4.h | 4 ++-- demo/sdl_opengl2/nuklear_sdl_gl2.h | 4 ++-- demo/sdl_opengl3/nuklear_sdl_gl3.h | 4 ++-- demo/sdl_opengles2/nuklear_sdl_gles2.h | 4 ++-- demo/sdl_renderer/nuklear_sdl_renderer.h | 4 ++-- demo/sfml_opengl2/nuklear_sfml_gl2.h | 4 ++-- demo/sfml_opengl3/nuklear_sfml_gl3.h | 4 ++-- demo/x11_opengl2/nuklear_xlib_gl2.h | 4 ++-- demo/x11_opengl3/nuklear_xlib_gl3.h | 4 ++-- doc/index.html | 2 +- example/canvas.c | 4 ++-- example/extended.c | 4 ++-- example/file_browser.c | 4 ++-- example/skinning.c | 4 ++-- nuklear.h | 16 ++++++++-------- src/nuklear_font.c | 16 ++++++++-------- 21 files changed, 56 insertions(+), 56 deletions(-) diff --git a/demo/d3d11/nuklear_d3d11.h b/demo/d3d11/nuklear_d3d11.h index 46c615d..27fa2c1 100644 --- a/demo/d3d11/nuklear_d3d11.h +++ b/demo/d3d11/nuklear_d3d11.h @@ -61,7 +61,7 @@ static struct struct nk_font_atlas atlas; struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; unsigned int max_vertex_buffer; unsigned int max_index_buffer; @@ -137,7 +137,7 @@ nk_d3d11_render(ID3D11DeviceContext *context, enum nk_anti_aliasing AA) config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; - config.tex_null = d3d11.null; + config.tex_null = d3d11.tex_null; {/* setup buffers to load vertices and elements */ struct nk_buffer vbuf, ibuf; @@ -603,7 +603,7 @@ nk_d3d11_font_stash_end(void) assert(SUCCEEDED(hr));} ID3D11Texture2D_Release(font_texture);} - nk_font_atlas_end(&d3d11.atlas, nk_handle_ptr(d3d11.font_texture_view), &d3d11.null); + nk_font_atlas_end(&d3d11.atlas, nk_handle_ptr(d3d11.font_texture_view), &d3d11.tex_null); if (d3d11.atlas.default_font) nk_style_set_font(&d3d11.ctx, &d3d11.atlas.default_font->handle); } diff --git a/demo/d3d12/nuklear_d3d12.h b/demo/d3d12/nuklear_d3d12.h index 1660d7b..5b86ea1 100644 --- a/demo/d3d12/nuklear_d3d12.h +++ b/demo/d3d12/nuklear_d3d12.h @@ -109,7 +109,7 @@ static struct struct nk_font_atlas atlas; struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; unsigned int max_vertex_buffer; unsigned int max_index_buffer; unsigned int max_user_textures; @@ -198,7 +198,7 @@ nk_d3d12_render(ID3D12GraphicsCommandList *command_list, enum nk_anti_aliasing A config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; - config.tex_null = d3d12.null; + config.tex_null = d3d12.tex_null; struct nk_buffer vbuf, ibuf; nk_buffer_init_fixed(&vbuf, &ptr_data[sizeof(float) * 4 * 4], (size_t)d3d12.max_vertex_buffer); @@ -863,7 +863,7 @@ nk_d3d12_font_stash_end(ID3D12GraphicsCommandList *command_list) ID3D12Device_CreateShaderResourceView(d3d12.device, d3d12.font_texture, &srv_desc, srv_handle); /* Done with nk atlas data. Atlas will be served with texture id 0 */ - nk_font_atlas_end(&d3d12.atlas, nk_handle_id(0), &d3d12.null); + nk_font_atlas_end(&d3d12.atlas, nk_handle_id(0), &d3d12.tex_null); /* Setup default font */ if (d3d12.atlas.default_font) diff --git a/demo/d3d9/nuklear_d3d9.h b/demo/d3d9/nuklear_d3d9.h index 1aee6ba..f967678 100644 --- a/demo/d3d9/nuklear_d3d9.h +++ b/demo/d3d9/nuklear_d3d9.h @@ -58,7 +58,7 @@ static struct { struct nk_font_atlas atlas; struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; D3DVIEWPORT9 viewport; D3DMATRIX projection; @@ -150,7 +150,7 @@ nk_d3d9_render(enum nk_anti_aliasing AA) config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; - config.tex_null = d3d9.null; + config.tex_null = d3d9.tex_null; /* convert shapes into vertexes */ nk_buffer_init_default(&vbuf); @@ -248,7 +248,7 @@ nk_d3d9_create_font_texture() hr = IDirect3DTexture9_UnlockRect(d3d9.texture, 0); NK_ASSERT(SUCCEEDED(hr)); - nk_font_atlas_end(&d3d9.atlas, nk_handle_ptr(d3d9.texture), &d3d9.null); + nk_font_atlas_end(&d3d9.atlas, nk_handle_ptr(d3d9.texture), &d3d9.tex_null); } NK_API void diff --git a/demo/glfw_opengl2/nuklear_glfw_gl2.h b/demo/glfw_opengl2/nuklear_glfw_gl2.h index 97e3b6e..2706f11 100644 --- a/demo/glfw_opengl2/nuklear_glfw_gl2.h +++ b/demo/glfw_opengl2/nuklear_glfw_gl2.h @@ -53,7 +53,7 @@ NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xof struct nk_glfw_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint font_tex; }; @@ -288,7 +288,7 @@ nk_glfw3_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&glfw.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_glfw3_device_upload_atlas(image, w, h); - nk_font_atlas_end(&glfw.atlas, nk_handle_id((int)glfw.ogl.font_tex), &glfw.ogl.null); + nk_font_atlas_end(&glfw.atlas, nk_handle_id((int)glfw.ogl.font_tex), &glfw.ogl.tex_null); if (glfw.atlas.default_font) nk_style_set_font(&glfw.ctx, &glfw.atlas.default_font->handle); } diff --git a/demo/glfw_opengl3/nuklear_glfw_gl3.h b/demo/glfw_opengl3/nuklear_glfw_gl3.h index 573b76d..a1e5d6c 100644 --- a/demo/glfw_opengl3/nuklear_glfw_gl3.h +++ b/demo/glfw_opengl3/nuklear_glfw_gl3.h @@ -26,7 +26,7 @@ enum nk_glfw_init_state{ struct nk_glfw_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -403,7 +403,7 @@ nk_glfw3_font_stash_end(struct nk_glfw* glfw) const void *image; int w, h; image = nk_font_atlas_bake(&glfw->atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_glfw3_device_upload_atlas(glfw, image, w, h); - nk_font_atlas_end(&glfw->atlas, nk_handle_id((int)glfw->ogl.font_tex), &glfw->ogl.null); + nk_font_atlas_end(&glfw->atlas, nk_handle_id((int)glfw->ogl.font_tex), &glfw->ogl.tex_null); if (glfw->atlas.default_font) nk_style_set_font(&glfw->ctx, &glfw->atlas.default_font->handle); } diff --git a/demo/glfw_opengl4/nuklear_glfw_gl4.h b/demo/glfw_opengl4/nuklear_glfw_gl4.h index 6f1e259..683da8c 100644 --- a/demo/glfw_opengl4/nuklear_glfw_gl4.h +++ b/demo/glfw_opengl4/nuklear_glfw_gl4.h @@ -72,7 +72,7 @@ struct nk_glfw_vertex { struct nk_glfw_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -553,7 +553,7 @@ nk_glfw3_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&glfw.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_glfw3_device_upload_atlas(image, w, h); - nk_font_atlas_end(&glfw.atlas, nk_handle_id((int)glfw.ogl.font_tex_index), &glfw.ogl.null); + nk_font_atlas_end(&glfw.atlas, nk_handle_id((int)glfw.ogl.font_tex_index), &glfw.ogl.tex_null); if (glfw.atlas.default_font) nk_style_set_font(&glfw.ctx, &glfw.atlas.default_font->handle); } diff --git a/demo/sdl_opengl2/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h index 7850d65..eaa00e5 100644 --- a/demo/sdl_opengl2/nuklear_sdl_gl2.h +++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h @@ -33,7 +33,7 @@ NK_API void nk_sdl_shutdown(void); struct nk_sdl_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint font_tex; }; @@ -226,7 +226,7 @@ nk_sdl_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&sdl.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_sdl_device_upload_atlas(image, w, h); - nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.null); + nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.tex_null); if (sdl.atlas.default_font) nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle); } diff --git a/demo/sdl_opengl3/nuklear_sdl_gl3.h b/demo/sdl_opengl3/nuklear_sdl_gl3.h index 26036f1..560ef69 100644 --- a/demo/sdl_opengl3/nuklear_sdl_gl3.h +++ b/demo/sdl_opengl3/nuklear_sdl_gl3.h @@ -40,7 +40,7 @@ NK_API void nk_sdl_device_create(void); struct nk_sdl_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -334,7 +334,7 @@ nk_sdl_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&sdl.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_sdl_device_upload_atlas(image, w, h); - nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.null); + nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.tex_null); if (sdl.atlas.default_font) nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle); diff --git a/demo/sdl_opengles2/nuklear_sdl_gles2.h b/demo/sdl_opengles2/nuklear_sdl_gles2.h index 592e0db..854c582 100644 --- a/demo/sdl_opengles2/nuklear_sdl_gles2.h +++ b/demo/sdl_opengles2/nuklear_sdl_gles2.h @@ -43,7 +43,7 @@ NK_API void nk_sdl_device_create(void); struct nk_sdl_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, ebo; GLuint prog; GLuint vert_shdr; @@ -335,7 +335,7 @@ nk_sdl_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&sdl.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_sdl_device_upload_atlas(image, w, h); - nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.null); + nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.tex_null); if (sdl.atlas.default_font) nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle); diff --git a/demo/sdl_renderer/nuklear_sdl_renderer.h b/demo/sdl_renderer/nuklear_sdl_renderer.h index 702d56c..be6f0aa 100644 --- a/demo/sdl_renderer/nuklear_sdl_renderer.h +++ b/demo/sdl_renderer/nuklear_sdl_renderer.h @@ -44,7 +44,7 @@ NK_API void nk_sdl_shutdown(void); struct nk_sdl_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; SDL_Texture *font_tex; }; @@ -259,7 +259,7 @@ nk_sdl_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&sdl.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_sdl_device_upload_atlas(image, w, h); - nk_font_atlas_end(&sdl.atlas, nk_handle_ptr(sdl.ogl.font_tex), &sdl.ogl.null); + nk_font_atlas_end(&sdl.atlas, nk_handle_ptr(sdl.ogl.font_tex), &sdl.ogl.tex_null); if (sdl.atlas.default_font) nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle); } diff --git a/demo/sfml_opengl2/nuklear_sfml_gl2.h b/demo/sfml_opengl2/nuklear_sfml_gl2.h index 1f9fcd1..a848d27 100644 --- a/demo/sfml_opengl2/nuklear_sfml_gl2.h +++ b/demo/sfml_opengl2/nuklear_sfml_gl2.h @@ -34,7 +34,7 @@ NK_API void nk_sfml_shutdown(void); struct nk_sfml_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint font_tex; }; @@ -245,7 +245,7 @@ nk_sfml_font_stash_end() const void* img; img = nk_font_atlas_bake(&sfml.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_sfml_device_upload_atlas(img, w, h); - nk_font_atlas_end(&sfml.atlas, nk_handle_id((int)sfml.ogl.font_tex), &sfml.ogl.null); + nk_font_atlas_end(&sfml.atlas, nk_handle_id((int)sfml.ogl.font_tex), &sfml.ogl.tex_null); if(sfml.atlas.default_font) nk_style_set_font(&sfml.ctx, &sfml.atlas.default_font->handle); } diff --git a/demo/sfml_opengl3/nuklear_sfml_gl3.h b/demo/sfml_opengl3/nuklear_sfml_gl3.h index 0038b34..a601ce8 100644 --- a/demo/sfml_opengl3/nuklear_sfml_gl3.h +++ b/demo/sfml_opengl3/nuklear_sfml_gl3.h @@ -43,7 +43,7 @@ NK_API void nk_sfml_device_destroy(void); struct nk_sfml_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -353,7 +353,7 @@ nk_sfml_font_stash_end() int w, h; image = nk_font_atlas_bake(&sfml.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_sfml_device_upload_atlas(image, w, h); - nk_font_atlas_end(&sfml.atlas, nk_handle_id((int)sfml.ogl.font_tex), &sfml.ogl.null); + nk_font_atlas_end(&sfml.atlas, nk_handle_id((int)sfml.ogl.font_tex), &sfml.ogl.tex_null); if(sfml.atlas.default_font) nk_style_set_font(&sfml.ctx, &sfml.atlas.default_font->handle); } diff --git a/demo/x11_opengl2/nuklear_xlib_gl2.h b/demo/x11_opengl2/nuklear_xlib_gl2.h index 9e1382e..209fa79 100644 --- a/demo/x11_opengl2/nuklear_xlib_gl2.h +++ b/demo/x11_opengl2/nuklear_xlib_gl2.h @@ -60,7 +60,7 @@ struct nk_x11_vertex { struct nk_x11_device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint font_tex; }; @@ -226,7 +226,7 @@ nk_x11_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&x11.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_x11_device_upload_atlas(image, w, h); - nk_font_atlas_end(&x11.atlas, nk_handle_id((int)x11.ogl.font_tex), &x11.ogl.null); + nk_font_atlas_end(&x11.atlas, nk_handle_id((int)x11.ogl.font_tex), &x11.ogl.tex_null); if (x11.atlas.default_font) nk_style_set_font(&x11.ctx, &x11.atlas.default_font->handle); } diff --git a/demo/x11_opengl3/nuklear_xlib_gl3.h b/demo/x11_opengl3/nuklear_xlib_gl3.h index 85ff2ae..e9d1fcc 100644 --- a/demo/x11_opengl3/nuklear_xlib_gl3.h +++ b/demo/x11_opengl3/nuklear_xlib_gl3.h @@ -173,7 +173,7 @@ struct nk_x11_device { struct opengl_info info; #endif struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -592,7 +592,7 @@ nk_x11_font_stash_end(void) const void *image; int w, h; image = nk_font_atlas_bake(&x11.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); nk_x11_device_upload_atlas(image, w, h); - nk_font_atlas_end(&x11.atlas, nk_handle_id((int)x11.ogl.font_tex), &x11.ogl.null); + nk_font_atlas_end(&x11.atlas, nk_handle_id((int)x11.ogl.font_tex), &x11.ogl.tex_null); if (x11.atlas.default_font) nk_style_set_font(&x11.ctx, &x11.atlas.default_font->handle); } diff --git a/doc/index.html b/doc/index.html index bed7855..b967ac2 100644 --- a/doc/index.html +++ b/doc/index.html @@ -637,7 +637,7 @@ cfg.circle_segment_count = 22; cfg.curve_segment_count = 22; cfg.arc_segment_count = 22; cfg.global_alpha = 1.0f; -cfg.null = dev->null; +cfg.tex_null = dev->null; // // setup buffers and convert struct nk_buffer cmds, verts, idx; diff --git a/example/canvas.c b/example/canvas.c index d8a1534..d48e15c 100644 --- a/example/canvas.c +++ b/example/canvas.c @@ -52,7 +52,7 @@ struct nk_glfw_vertex { struct device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -441,7 +441,7 @@ int main(int argc, char *argv[]) font = nk_font_atlas_add_default(&atlas, 13, 0); image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32); device_upload_atlas(&device, image, w, h); - nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.null); + nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.tex_null); nk_init_default(&ctx, &font->handle); glEnable(GL_TEXTURE_2D); diff --git a/example/extended.c b/example/extended.c index 41f2fa2..e12eef6 100644 --- a/example/extended.c +++ b/example/extended.c @@ -478,7 +478,7 @@ struct nk_glfw_vertex { struct device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -795,7 +795,7 @@ int main(int argc, char *argv[]) media.font_22 = nk_font_atlas_add_from_file(&atlas, "../../extra_font/Roboto-Regular.ttf", 22.0f, &cfg); image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32); device_upload_atlas(&device, image, w, h); - nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.null);} + nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.tex_null);} nk_init_default(&ctx, &media.font_14->handle);} /* icons */ diff --git a/example/file_browser.c b/example/file_browser.c index 60e6ac2..cd21f09 100644 --- a/example/file_browser.c +++ b/example/file_browser.c @@ -527,7 +527,7 @@ struct nk_glfw_vertex { struct device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -823,7 +823,7 @@ int main(int argc, char *argv[]) else font = nk_font_atlas_add_default(&atlas, 13.0f, NULL); image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32); device_upload_atlas(&device, image, w, h); - nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.null);} + nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.tex_null);} nk_init_default(&ctx, &font->handle);} /* icons */ diff --git a/example/skinning.c b/example/skinning.c index b54b03d..db365dc 100644 --- a/example/skinning.c +++ b/example/skinning.c @@ -79,7 +79,7 @@ struct nk_glfw_vertex { struct device { struct nk_buffer cmds; - struct nk_draw_null_texture null; + struct nk_draw_null_texture tex_null; GLuint vbo, vao, ebo; GLuint prog; GLuint vert_shdr; @@ -388,7 +388,7 @@ int main(int argc, char *argv[]) else font = nk_font_atlas_add_default(&atlas, 13.0f, NULL); image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32); device_upload_atlas(&device, image, w, h); - nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.null);} + nk_font_atlas_end(&atlas, nk_handle_id((int)device.font_tex), &device.tex_null);} nk_init_default(&ctx, &font->handle);} { /* skin */ diff --git a/nuklear.h b/nuklear.h index 90d8b2d..901d3e5 100644 --- a/nuklear.h +++ b/nuklear.h @@ -17703,20 +17703,20 @@ failed: } NK_API void nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture, - struct nk_draw_null_texture *null) + struct nk_draw_null_texture *tex_null) { int i = 0; struct nk_font *font_iter; NK_ASSERT(atlas); if (!atlas) { - if (!null) return; - null->texture = texture; - null->uv = nk_vec2(0.5f,0.5f); + if (!tex_null) return; + tex_null->texture = texture; + tex_null->uv = nk_vec2(0.5f,0.5f); } - if (null) { - null->texture = texture; - null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width; - null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height; + if (tex_null) { + tex_null->texture = texture; + tex_null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width; + tex_null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height; } for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) { font_iter->texture = texture; diff --git a/src/nuklear_font.c b/src/nuklear_font.c index 541bf48..e1ada96 100644 --- a/src/nuklear_font.c +++ b/src/nuklear_font.c @@ -1276,20 +1276,20 @@ failed: } NK_API void nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture, - struct nk_draw_null_texture *null) + struct nk_draw_null_texture *tex_null) { int i = 0; struct nk_font *font_iter; NK_ASSERT(atlas); if (!atlas) { - if (!null) return; - null->texture = texture; - null->uv = nk_vec2(0.5f,0.5f); + if (!tex_null) return; + tex_null->texture = texture; + tex_null->uv = nk_vec2(0.5f,0.5f); } - if (null) { - null->texture = texture; - null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width; - null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height; + if (tex_null) { + tex_null->texture = texture; + tex_null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width; + tex_null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height; } for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) { font_iter->texture = texture; From ca49016428aace2b19c30b87f8d2418bdfc755ca Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 30 Jul 2022 17:45:12 -0400 Subject: [PATCH 24/61] Rename more null variables to tex_null --- demo/glfw_opengl2/nuklear_glfw_gl2.h | 2 +- demo/glfw_opengl3/nuklear_glfw_gl3.h | 2 +- demo/glfw_opengl4/nuklear_glfw_gl4.h | 2 +- demo/sdl_opengl2/nuklear_sdl_gl2.h | 2 +- demo/sdl_opengl3/nuklear_sdl_gl3.h | 2 +- demo/sdl_opengles2/nuklear_sdl_gles2.h | 2 +- demo/sdl_renderer/nuklear_sdl_renderer.h | 2 +- demo/sfml_opengl2/nuklear_sfml_gl2.h | 2 +- demo/sfml_opengl3/nuklear_sfml_gl3.h | 2 +- demo/x11_opengl2/nuklear_xlib_gl2.h | 2 +- demo/x11_opengl3/nuklear_xlib_gl3.h | 2 +- doc/index.html | 2 +- example/canvas.c | 2 +- example/extended.c | 2 +- example/file_browser.c | 2 +- example/skinning.c | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/demo/glfw_opengl2/nuklear_glfw_gl2.h b/demo/glfw_opengl2/nuklear_glfw_gl2.h index 2706f11..fb8b31e 100644 --- a/demo/glfw_opengl2/nuklear_glfw_gl2.h +++ b/demo/glfw_opengl2/nuklear_glfw_gl2.h @@ -140,7 +140,7 @@ nk_glfw3_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/glfw_opengl3/nuklear_glfw_gl3.h b/demo/glfw_opengl3/nuklear_glfw_gl3.h index a1e5d6c..663fa0b 100644 --- a/demo/glfw_opengl3/nuklear_glfw_gl3.h +++ b/demo/glfw_opengl3/nuklear_glfw_gl3.h @@ -266,7 +266,7 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/glfw_opengl4/nuklear_glfw_gl4.h b/demo/glfw_opengl4/nuklear_glfw_gl4.h index 683da8c..781bfc3 100644 --- a/demo/glfw_opengl4/nuklear_glfw_gl4.h +++ b/demo/glfw_opengl4/nuklear_glfw_gl4.h @@ -407,7 +407,7 @@ nk_glfw3_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_opengl2/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h index eaa00e5..0c6a2fb 100644 --- a/demo/sdl_opengl2/nuklear_sdl_gl2.h +++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h @@ -120,7 +120,7 @@ nk_sdl_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_opengl3/nuklear_sdl_gl3.h b/demo/sdl_opengl3/nuklear_sdl_gl3.h index 560ef69..cac8629 100644 --- a/demo/sdl_opengl3/nuklear_sdl_gl3.h +++ b/demo/sdl_opengl3/nuklear_sdl_gl3.h @@ -247,7 +247,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_opengles2/nuklear_sdl_gles2.h b/demo/sdl_opengles2/nuklear_sdl_gles2.h index 854c582..595d7a7 100644 --- a/demo/sdl_opengles2/nuklear_sdl_gles2.h +++ b/demo/sdl_opengles2/nuklear_sdl_gles2.h @@ -245,7 +245,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sdl_renderer/nuklear_sdl_renderer.h b/demo/sdl_renderer/nuklear_sdl_renderer.h index be6f0aa..672b81b 100644 --- a/demo/sdl_renderer/nuklear_sdl_renderer.h +++ b/demo/sdl_renderer/nuklear_sdl_renderer.h @@ -113,7 +113,7 @@ nk_sdl_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sfml_opengl2/nuklear_sfml_gl2.h b/demo/sfml_opengl2/nuklear_sfml_gl2.h index a848d27..f168bab 100644 --- a/demo/sfml_opengl2/nuklear_sfml_gl2.h +++ b/demo/sfml_opengl2/nuklear_sfml_gl2.h @@ -118,7 +118,7 @@ nk_sfml_render(enum nk_anti_aliasing AA) config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sfml_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sfml_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/sfml_opengl3/nuklear_sfml_gl3.h b/demo/sfml_opengl3/nuklear_sfml_gl3.h index a601ce8..286cfc1 100644 --- a/demo/sfml_opengl3/nuklear_sfml_gl3.h +++ b/demo/sfml_opengl3/nuklear_sfml_gl3.h @@ -248,7 +248,7 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_ config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sfml_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_sfml_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/x11_opengl2/nuklear_xlib_gl2.h b/demo/x11_opengl2/nuklear_xlib_gl2.h index 209fa79..2ad2648 100644 --- a/demo/x11_opengl2/nuklear_xlib_gl2.h +++ b/demo/x11_opengl2/nuklear_xlib_gl2.h @@ -153,7 +153,7 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_x11_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_x11_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/demo/x11_opengl3/nuklear_xlib_gl3.h b/demo/x11_opengl3/nuklear_xlib_gl3.h index e9d1fcc..9dd0181 100644 --- a/demo/x11_opengl3/nuklear_xlib_gl3.h +++ b/demo/x11_opengl3/nuklear_xlib_gl3.h @@ -536,7 +536,7 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_x11_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_x11_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/doc/index.html b/doc/index.html index b967ac2..0312be3 100644 --- a/doc/index.html +++ b/doc/index.html @@ -637,7 +637,7 @@ cfg.circle_segment_count = 22; cfg.curve_segment_count = 22; cfg.arc_segment_count = 22; cfg.global_alpha = 1.0f; -cfg.tex_null = dev->null; +cfg.tex_null = dev->tex_null; // // setup buffers and convert struct nk_buffer cmds, verts, idx; diff --git a/example/canvas.c b/example/canvas.c index d48e15c..2456927 100644 --- a/example/canvas.c +++ b/example/canvas.c @@ -262,7 +262,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/example/extended.c b/example/extended.c index e12eef6..4e1211b 100644 --- a/example/extended.c +++ b/example/extended.c @@ -685,7 +685,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/example/file_browser.c b/example/file_browser.c index cd21f09..6bf23c2 100644 --- a/example/file_browser.c +++ b/example/file_browser.c @@ -722,7 +722,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; diff --git a/example/skinning.c b/example/skinning.c index db365dc..fab9ce3 100644 --- a/example/skinning.c +++ b/example/skinning.c @@ -286,7 +286,7 @@ device_draw(struct device *dev, struct nk_context *ctx, int width, int height, config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_glfw_vertex); config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex); - config.tex_null = dev->null; + config.tex_null = dev->tex_null; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; From d28d145732a8b9e17a16348a1d86d2174b5b9d96 Mon Sep 17 00:00:00 2001 From: opsJson <54485405+opsJson@users.noreply.github.com> Date: Sat, 30 Jul 2022 21:33:46 -0300 Subject: [PATCH 25/61] Fixed cursor position overflow --- nuklear.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nuklear.h b/nuklear.h index fde970a..377fa6b 100644 --- a/nuklear.h +++ b/nuklear.h @@ -26163,6 +26163,7 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) { nk_textedit_makeundo_insert(state, state->cursor, 1); ++state->cursor; + state->cursor = NK_MIN(state->cursor, state->string.len); state->has_preferred_x = 0; } } @@ -26423,7 +26424,6 @@ retry: if (shift_mod) { nk_textedit_prep_selection_at_cursor(state); state->cursor = state->select_end = state->string.len; - if (state->select_start >= state->select_end) state->select_start = 0; state->has_preferred_x = 0; } else { state->cursor = state->string.len; @@ -30007,3 +30007,4 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// in libraries and brought me to create some of my own. Finally Apoorva Joshi /// for his single header file packer. */ + From 9f0a6013954d6fa0ac44307245450f65b22cfb11 Mon Sep 17 00:00:00 2001 From: opsJson <54485405+opsJson@users.noreply.github.com> Date: Sat, 30 Jul 2022 21:36:01 -0300 Subject: [PATCH 26/61] Update nuklear_text_editor.c --- src/nuklear_text_editor.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nuklear_text_editor.c b/src/nuklear_text_editor.c index 5b0c03a..bd93250 100644 --- a/src/nuklear_text_editor.c +++ b/src/nuklear_text_editor.c @@ -395,6 +395,7 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) { nk_textedit_makeundo_insert(state, state->cursor, 1); ++state->cursor; + state->cursor = NK_MIN(state->cursor, state->string.len); state->has_preferred_x = 0; } } From c7c3069dc2e6c070dcbb9c99f3292076dc5a69a0 Mon Sep 17 00:00:00 2001 From: opsJson Date: Mon, 1 Aug 2022 15:33:42 -0300 Subject: [PATCH 27/61] following the read me --- clib.json | 2 +- src/CHANGELOG | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clib.json b/clib.json index 27c495f..3fe7d63 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.9.6", + "version": "4.10.1", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/src/CHANGELOG b/src/CHANGELOG index 44223af..bb0aad8 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than nk_edit_xxx limit /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down From df86105c695b4dbb5e3974b12a23377e170e031b Mon Sep 17 00:00:00 2001 From: opsJson Date: Mon, 1 Aug 2022 16:19:45 -0300 Subject: [PATCH 28/61] Fix tabs --- src/CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CHANGELOG b/src/CHANGELOG index bb0aad8..00ee208 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,7 +7,8 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than nk_edit_xxx limit +/// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than +/// nk_edit_xxx limit /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down From e57ee582ab087af05ff61f767d977bb9aba3ca6c Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 3 Aug 2022 13:00:54 -0400 Subject: [PATCH 29/61] Update NK_MIN() call to save a line of code --- nuklear.h | 5 +++-- src/nuklear_text_editor.c | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nuklear.h b/nuklear.h index 377fa6b..7af8bb1 100644 --- a/nuklear.h +++ b/nuklear.h @@ -26162,8 +26162,7 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) text+text_len, 1)) { nk_textedit_makeundo_insert(state, state->cursor, 1); - ++state->cursor; - state->cursor = NK_MIN(state->cursor, state->string.len); + state->cursor = NK_MIN(state->cursor + 1, state->string.len); state->has_preferred_x = 0; } } @@ -29657,6 +29656,8 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than +/// nk_edit_xxx limit /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to /// only trigger when the mouse position was inside the same button on down diff --git a/src/nuklear_text_editor.c b/src/nuklear_text_editor.c index bd93250..e381857 100644 --- a/src/nuklear_text_editor.c +++ b/src/nuklear_text_editor.c @@ -394,8 +394,7 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) text+text_len, 1)) { nk_textedit_makeundo_insert(state, state->cursor, 1); - ++state->cursor; - state->cursor = NK_MIN(state->cursor, state->string.len); + state->cursor = NK_MIN(state->cursor + 1, state->string.len); state->has_preferred_x = 0; } } From ce1c94d84bdf0e5de68ec8a06c8372ad56c3b16c Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 11 Sep 2022 13:53:59 -0400 Subject: [PATCH 30/61] Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE --- nuklear.h | 5 +++-- src/CHANGELOG | 1 + src/nuklear.h | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nuklear.h b/nuklear.h index 7af8bb1..bb5917c 100644 --- a/nuklear.h +++ b/nuklear.h @@ -372,7 +372,7 @@ extern "C" { #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) #define NK_SIZE_TYPE unsigned __int32 #elif defined(__GNUC__) || defined(__clang__) - #if defined(__x86_64__) || defined(__ppc64__) + #if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) #define NK_SIZE_TYPE unsigned long #else #define NK_SIZE_TYPE unsigned int @@ -387,7 +387,7 @@ extern "C" { #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) #define NK_POINTER_TYPE unsigned __int32 #elif defined(__GNUC__) || defined(__clang__) - #if defined(__x86_64__) || defined(__ppc64__) + #if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) #define NK_POINTER_TYPE unsigned long #else #define NK_POINTER_TYPE unsigned int @@ -29656,6 +29656,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE /// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than /// nk_edit_xxx limit /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug diff --git a/src/CHANGELOG b/src/CHANGELOG index 00ee208..2ddafe1 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE /// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than /// nk_edit_xxx limit /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug diff --git a/src/nuklear.h b/src/nuklear.h index 67b2aa9..03f7514 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -151,7 +151,7 @@ extern "C" { #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) #define NK_SIZE_TYPE unsigned __int32 #elif defined(__GNUC__) || defined(__clang__) - #if defined(__x86_64__) || defined(__ppc64__) + #if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) #define NK_SIZE_TYPE unsigned long #else #define NK_SIZE_TYPE unsigned int @@ -166,7 +166,7 @@ extern "C" { #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) #define NK_POINTER_TYPE unsigned __int32 #elif defined(__GNUC__) || defined(__clang__) - #if defined(__x86_64__) || defined(__ppc64__) + #if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) #define NK_POINTER_TYPE unsigned long #else #define NK_POINTER_TYPE unsigned int From a74061af6d5d697c1262cd26d88b8458b761d139 Mon Sep 17 00:00:00 2001 From: dczheng Date: Fri, 23 Sep 2022 00:27:48 +0800 Subject: [PATCH 31/61] Fix typo --- nuklear.h | 2 +- src/nuklear_font.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nuklear.h b/nuklear.h index bb5917c..72a423d 100644 --- a/nuklear.h +++ b/nuklear.h @@ -16512,7 +16512,7 @@ nk_font_chinese_glyph_ranges(void) 0x3000, 0x30FF, 0x31F0, 0x31FF, 0xFF00, 0xFFEF, - 0x4e00, 0x9FAF, + 0x4E00, 0x9FAF, 0 }; return ranges; diff --git a/src/nuklear_font.c b/src/nuklear_font.c index 541bf48..073971c 100644 --- a/src/nuklear_font.c +++ b/src/nuklear_font.c @@ -85,7 +85,7 @@ nk_font_chinese_glyph_ranges(void) 0x3000, 0x30FF, 0x31F0, 0x31FF, 0xFF00, 0xFFEF, - 0x4e00, 0x9FAF, + 0x4E00, 0x9FAF, 0 }; return ranges; From 6a429eca62ceec9009b3df9f45d08ba67d05476d Mon Sep 17 00:00:00 2001 From: Richard Gill Date: Mon, 3 Oct 2022 21:11:12 +0200 Subject: [PATCH 32/61] cleanup xlib text drawing fixes #502 --- demo/x11/nuklear_xlib.h | 39 ++++++++++++++++--------------------- demo/x11_xft/nuklear_xlib.h | 13 ++++--------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/demo/x11/nuklear_xlib.h b/demo/x11/nuklear_xlib.h index 772ac56..0d71dee 100644 --- a/demo/x11/nuklear_xlib.h +++ b/demo/x11/nuklear_xlib.h @@ -385,15 +385,12 @@ nk_xsurf_stroke_curve(XSurface *surf, struct nk_vec2i p1, } NK_INTERN void -nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned short h, - const char *text, int len, XFont *font, struct nk_color cbg, struct nk_color cfg) +nk_xsurf_draw_text(XSurface *surf, short x, short y, const char *text, int len, + XFont *font, struct nk_color cfg) { int tx, ty; - unsigned long bg = nk_color_from_byte(&cbg.r); unsigned long fg = nk_color_from_byte(&cfg.r); - XSetForeground(surf->dpy, surf->gc, bg); - XFillRectangle(surf->dpy, surf->drawable, surf->gc, (int)x, (int)y, (unsigned)w, (unsigned)h); if(!text || !font || !len) return; tx = (int)x; @@ -413,10 +410,10 @@ nk_stbi_image_to_xsurf(unsigned char *data, int width, int height, int channels) int bpl = channels; long i, isize = width*height*channels; XImageWithAlpha *aimage = (XImageWithAlpha*)calloc( 1, sizeof(XImageWithAlpha) ); - int depth = DefaultDepth(surf->dpy, surf->screen); + int depth = DefaultDepth(surf->dpy, surf->screen); if (data == NULL) return nk_image_id(0); if (aimage == NULL) return nk_image_id(0); - + switch (depth){ case 24: bpl = 4; @@ -429,7 +426,7 @@ nk_stbi_image_to_xsurf(unsigned char *data, int width, int height, int channels) bpl = 1; break; } - + /* rgba to bgra */ if (channels >= 3){ for (i=0; i < isize; i += channels) { @@ -441,9 +438,9 @@ nk_stbi_image_to_xsurf(unsigned char *data, int width, int height, int channels) } if (channels == 4){ - const unsigned alpha_treshold = 127; + const unsigned alpha_treshold = 127; aimage->clipMask = XCreatePixmap(surf->dpy, surf->drawable, width, height, 1); - + if( aimage->clipMask ){ aimage->clipMaskGC = XCreateGC(surf->dpy, aimage->clipMask, 0, 0); XSetForeground(surf->dpy, aimage->clipMaskGC, BlackPixel(surf->dpy, surf->screen)); @@ -460,13 +457,13 @@ nk_stbi_image_to_xsurf(unsigned char *data, int width, int height, int channels) } } } - - aimage->ximage = XCreateImage(surf->dpy, - CopyFromParent, depth, - ZPixmap, 0, - (char*)data, - width, height, - bpl*8, bpl * width); + + aimage->ximage = XCreateImage(surf->dpy, + CopyFromParent, depth, + ZPixmap, 0, + (char*)data, + width, height, + bpl*8, bpl * width); img = nk_image_ptr( (void*)aimage); img.h = height; img.w = width; @@ -503,7 +500,7 @@ nk_xsurf_draw_image(XSurface *surf, short x, short y, unsigned short w, unsigned if (aimage){ if (aimage->clipMask){ XSetClipMask(surf->dpy, surf->gc, aimage->clipMask); - XSetClipOrigin(surf->dpy, surf->gc, x, y); + XSetClipOrigin(surf->dpy, surf->gc, x, y); } XPutImage(surf->dpy, surf->drawable, surf->gc, aimage->ximage, 0, 0, x, y, w, h); XSetClipMask(surf->dpy, surf->gc, None); @@ -939,10 +936,8 @@ nk_xlib_render(Drawable screen, struct nk_color clear) } break; case NK_COMMAND_TEXT: { const struct nk_command_text *t = (const struct nk_command_text*)cmd; - nk_xsurf_draw_text(surf, t->x, t->y, t->w, t->h, - (const char*)t->string, t->length, - (XFont*)t->font->userdata.ptr, - t->background, t->foreground); + nk_xsurf_draw_text(surf, t->x, t->y, (const char*)t->string, t->length, + (XFont*)t->font->userdata.ptr, t->foreground); } break; case NK_COMMAND_CURVE: { const struct nk_command_curve *q = (const struct nk_command_curve *)cmd; diff --git a/demo/x11_xft/nuklear_xlib.h b/demo/x11_xft/nuklear_xlib.h index 7fbcd47..5728e8f 100644 --- a/demo/x11_xft/nuklear_xlib.h +++ b/demo/x11_xft/nuklear_xlib.h @@ -417,8 +417,8 @@ nk_xsurf_stroke_curve(XSurface *surf, struct nk_vec2i p1, } NK_INTERN void -nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned short h, - const char *text, int len, XFont *font, struct nk_color cbg, struct nk_color cfg) +nk_xsurf_draw_text(XSurface *surf, short x, short y, const char *text, int len, + XFont *font, struct nk_color cfg) { #ifdef NK_XLIB_USE_XFT XRenderColor xrc; @@ -426,11 +426,8 @@ nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned #else unsigned long fg = nk_color_from_byte(&cfg.r); #endif - unsigned long bg = nk_color_from_byte(&cbg.r); int tx, ty; - XSetForeground(surf->dpy, surf->gc, bg); - XFillRectangle(surf->dpy, surf->drawable, surf->gc, (int)x, (int)y, (unsigned)w, (unsigned)h); if(!text || !font || !len) return; tx = (int)x; @@ -1024,10 +1021,8 @@ nk_xlib_render(Drawable screen, struct nk_color clear) } break; case NK_COMMAND_TEXT: { const struct nk_command_text *t = (const struct nk_command_text*)cmd; - nk_xsurf_draw_text(surf, t->x, t->y, t->w, t->h, - (const char*)t->string, t->length, - (XFont*)t->font->userdata.ptr, - t->background, t->foreground); + nk_xsurf_draw_text(surf, t->x, t->y, (const char*)t->string, t->length, + (XFont*)t->font->userdata.ptr, t->foreground); } break; case NK_COMMAND_CURVE: { const struct nk_command_curve *q = (const struct nk_command_curve *)cmd; From fc5ce1c495d88a920c0c475dc48f5370aed71138 Mon Sep 17 00:00:00 2001 From: Richard Gill Date: Wed, 12 Oct 2022 21:19:45 +0200 Subject: [PATCH 33/61] demos: set style with defines To avoid having to modify the demo code, conditionnally include a predefined style --- demo/allegro5/main.c | 15 +++++++++++---- demo/d3d11/main.c | 13 +++++++++---- demo/d3d12/main.c | 17 +++++++++++------ demo/d3d9/main.c | 13 +++++++++---- demo/gdi/main.c | 13 +++++++++---- demo/gdip/main.c | 13 +++++++++---- demo/glfw_opengl2/main.c | 23 ++++++++++++++--------- demo/glfw_opengl3/main.c | 13 +++++++++---- demo/glfw_opengl4/main.c | 13 +++++++++---- demo/sdl_opengl2/main.c | 13 +++++++++---- demo/sdl_opengl3/main.c | 13 +++++++++---- demo/sdl_opengles2/main.c | 13 +++++++++---- demo/sdl_renderer/main.c | 13 +++++++++---- demo/sfml_opengl2/main.cpp | 13 +++++++++---- demo/sfml_opengl3/main.cpp | 13 +++++++++---- demo/x11/main.c | 13 +++++++++---- demo/x11_opengl2/main.c | 13 +++++++++---- demo/x11_opengl3/main.c | 13 +++++++++---- demo/x11_rawfb/main.c | 13 +++++++++---- demo/x11_xft/main.c | 13 +++++++++---- 20 files changed, 189 insertions(+), 87 deletions(-) diff --git a/demo/allegro5/main.c b/demo/allegro5/main.c index 24a27ba..0c0f88c 100644 --- a/demo/allegro5/main.c +++ b/demo/allegro5/main.c @@ -115,10 +115,17 @@ int main(void) ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT); /* style.c */ - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef INCLUDE_STYLE + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif + #endif while(1) { diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index e890150..f059ea0 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -210,10 +210,15 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/d3d12/main.c b/demo/d3d12/main.c index d8bb406..005ce10 100644 --- a/demo/d3d12/main.c +++ b/demo/d3d12/main.c @@ -191,7 +191,7 @@ WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) } int main(void) -{ +{ struct nk_context *ctx; struct nk_colorf bg; @@ -278,7 +278,7 @@ int main(void) /* GUI */ ctx = nk_d3d12_init(device, WINDOW_WIDTH, WINDOW_HEIGHT, MAX_VERTEX_BUFFER, MAX_INDEX_BUFFER, USER_TEXTURES); - + /* Load Fonts: if none of these are loaded a default font will be used */ /* Load Cursor: if you uncomment cursor loading please hide the cursor */ { @@ -302,10 +302,15 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/d3d9/main.c b/demo/d3d9/main.c index de85e92..762ee02 100644 --- a/demo/d3d9/main.c +++ b/demo/d3d9/main.c @@ -216,10 +216,15 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/gdi/main.c b/demo/gdi/main.c index 1451323..0c08c39 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -115,10 +115,15 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif while (running) diff --git a/demo/gdip/main.c b/demo/gdip/main.c index 69bd83a..11f5aa3 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -111,10 +111,15 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif while (running) diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c index 6a89e4b..0401626 100644 --- a/demo/glfw_opengl2/main.c +++ b/demo/glfw_opengl2/main.c @@ -85,7 +85,7 @@ int main(void) /* Platform */ static GLFWwindow *win; int width = 0, height = 0; - + /* GUI */ struct nk_context *ctx; struct nk_colorf bg; @@ -121,14 +121,19 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; - + #ifdef INCLUDE_FILE_BROWSER /* icons */ glEnable(GL_TEXTURE_2D); @@ -219,7 +224,7 @@ int main(void) glfwSwapBuffers(win); } - #ifdef INCLUDE_FILE_BROWSER + #ifdef INCLUDE_FILE_BROWSER glDeleteTextures(1,(const GLuint*)&media.icons.home.handle.id); glDeleteTextures(1,(const GLuint*)&media.icons.directory.handle.id); glDeleteTextures(1,(const GLuint*)&media.icons.computer.handle.id); @@ -232,8 +237,8 @@ int main(void) glDeleteTextures(1,(const GLuint*)&media.icons.movie_file.handle.id); file_browser_free(&browser); - #endif - + #endif + nk_glfw3_shutdown(); glfwTerminate(); return 0; diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c index d8eda87..a4346d9 100644 --- a/demo/glfw_opengl3/main.c +++ b/demo/glfw_opengl3/main.c @@ -126,10 +126,15 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/glfw_opengl4/main.c b/demo/glfw_opengl4/main.c index 75783bd..7b7c093 100644 --- a/demo/glfw_opengl4/main.c +++ b/demo/glfw_opengl4/main.c @@ -126,10 +126,15 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif /* Create bindless texture. diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c index cd1071e..eb09427c 100644 --- a/demo/sdl_opengl2/main.c +++ b/demo/sdl_opengl2/main.c @@ -117,10 +117,15 @@ main(int argc, char *argv[]) /*nk_style_set_font(ctx, &roboto->handle)*/;} #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c index 97351f5..cc9388b 100644 --- a/demo/sdl_opengl3/main.c +++ b/demo/sdl_opengl3/main.c @@ -128,10 +128,15 @@ int main(int argc, char *argv[]) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/sdl_opengles2/main.c b/demo/sdl_opengles2/main.c index 80a4285..4048381 100644 --- a/demo/sdl_opengles2/main.c +++ b/demo/sdl_opengles2/main.c @@ -209,10 +209,15 @@ int main(int argc, char* argv[]) /*nk_style_set_font(ctx, &roboto->handle)*/;} /* style.c */ - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #if defined(__EMSCRIPTEN__) #include diff --git a/demo/sdl_renderer/main.c b/demo/sdl_renderer/main.c index d50f16c..09cc83b 100644 --- a/demo/sdl_renderer/main.c +++ b/demo/sdl_renderer/main.c @@ -155,10 +155,15 @@ main(int argc, char *argv[]) } #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/sfml_opengl2/main.cpp b/demo/sfml_opengl2/main.cpp index e8ebaba..ca5ecd2 100644 --- a/demo/sfml_opengl2/main.cpp +++ b/demo/sfml_opengl2/main.cpp @@ -98,10 +98,15 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif struct nk_colorf bg; diff --git a/demo/sfml_opengl3/main.cpp b/demo/sfml_opengl3/main.cpp index b2568e7..f772057 100644 --- a/demo/sfml_opengl3/main.cpp +++ b/demo/sfml_opengl3/main.cpp @@ -104,10 +104,15 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif struct nk_colorf bg; diff --git a/demo/x11/main.c b/demo/x11/main.c index 16bf043..c93ae78 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -153,10 +153,15 @@ main(void) ctx = nk_xlib_init(xw.font, xw.dpy, xw.screen, xw.win, xw.width, xw.height); #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif while (running) diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index 5145c3b..06c2ee0 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -257,10 +257,15 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index faaad12..5609d24 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -254,10 +254,15 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; diff --git a/demo/x11_rawfb/main.c b/demo/x11_rawfb/main.c index ea51c1e..1e72c1e 100644 --- a/demo/x11_rawfb/main.c +++ b/demo/x11_rawfb/main.c @@ -194,10 +194,15 @@ main(void) if (!rawfb) running = 0; #ifdef INCLUDE_STYLE - /*set_style(&rawfb->ctx, THEME_WHITE);*/ - /*set_style(&rawfb->ctx, THEME_RED);*/ - /*set_style(&rawfb->ctx, THEME_BLUE);*/ - /*set_style(&rawfb->ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(&rawfb->ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(&rawfb->ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(&rawfb->ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(&rawfb->ctx, THEME_DARK); + #endif #endif while (running) { diff --git a/demo/x11_xft/main.c b/demo/x11_xft/main.c index 8b2a146..e069622 100644 --- a/demo/x11_xft/main.c +++ b/demo/x11_xft/main.c @@ -157,10 +157,15 @@ main(void) xw.width, xw.height); #ifdef INCLUDE_STYLE - /*set_style(ctx, THEME_WHITE);*/ - /*set_style(ctx, THEME_RED);*/ - /*set_style(ctx, THEME_BLUE);*/ - /*set_style(ctx, THEME_DARK);*/ + #ifdef STYLE_WHITE + set_style(ctx, THEME_WHITE); + #elif defined(STYLE_RED) + set_style(ctx, THEME_RED); + #elif defined(STYLE_BLUE) + set_style(ctx, THEME_BLUE); + #elif defined(STYLE_DARK) + set_style(ctx, THEME_DARK); + #endif #endif while (running) From d63f106334f3b3a23445464cf768165bbe8709c9 Mon Sep 17 00:00:00 2001 From: Richard Gill Date: Wed, 12 Oct 2022 22:08:08 +0200 Subject: [PATCH 34/61] xlib backend: implemented arc commands --- demo/x11/nuklear_xlib.h | 33 +++++++++++++++++++++++++++++++-- demo/x11_xft/nuklear_xlib.h | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/demo/x11/nuklear_xlib.h b/demo/x11/nuklear_xlib.h index 0d71dee..9b3a861 100644 --- a/demo/x11/nuklear_xlib.h +++ b/demo/x11/nuklear_xlib.h @@ -357,6 +357,29 @@ nk_xsurf_stroke_circle(XSurface *surf, short x, short y, unsigned short w, XSetLineAttributes(surf->dpy, surf->gc, 1, LineSolid, CapButt, JoinMiter); } +NK_INTERN void +nk_xsurf_stroke_arc(XSurface *surf, short cx, short cy, unsigned short radius, + float a_min, float a_max, unsigned short line_thickness, struct nk_color col) +{ + unsigned long c = nk_color_from_byte(&col.r); + XSetLineAttributes(surf->dpy, surf->gc, line_thickness, LineSolid, CapButt, JoinMiter); + XSetForeground(surf->dpy, surf->gc, c); + XDrawArc(surf->dpy, surf->drawable, surf->gc, (int)(cx - radius), (int)(cy - radius), + (unsigned)(radius * 2), (unsigned)(radius * 2), + (int)(a_min * 180 * 64 / NK_PI), (int)(a_max * 180 * 64 / NK_PI)); +} + +NK_INTERN void +nk_xsurf_fill_arc(XSurface *surf, short cx, short cy, unsigned short radius, + float a_min, float a_max, struct nk_color col) +{ + unsigned long c = nk_color_from_byte(&col.r); + XSetForeground(surf->dpy, surf->gc, c); + XFillArc(surf->dpy, surf->drawable, surf->gc, (int)(cx - radius), (int)(cy - radius), + (unsigned)(radius * 2), (unsigned)(radius * 2), + (int)(a_min * 180 * 64 / NK_PI), (int)(a_max * 180 * 64 / NK_PI)); +} + NK_INTERN void nk_xsurf_stroke_curve(XSurface *surf, struct nk_vec2i p1, struct nk_vec2i p2, struct nk_vec2i p3, struct nk_vec2i p4, @@ -912,6 +935,14 @@ nk_xlib_render(Drawable screen, struct nk_color clear) const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd; nk_xsurf_fill_circle(surf, c->x, c->y, c->w, c->h, c->color); } break; + case NK_COMMAND_ARC: { + const struct nk_command_arc *a = (const struct nk_command_arc *)cmd; + nk_xsurf_stroke_arc(surf, a->cx, a->cy, a->r, a->a[0], a->a[1], a->line_thickness, a->color); + } break; + case NK_COMMAND_ARC_FILLED: { + const struct nk_command_arc_filled *a = (const struct nk_command_arc_filled *)cmd; + nk_xsurf_fill_arc(surf, a->cx, a->cy, a->r, a->a[0], a->a[1], a->color); + } break; case NK_COMMAND_TRIANGLE: { const struct nk_command_triangle*t = (const struct nk_command_triangle*)cmd; nk_xsurf_stroke_triangle(surf, t->a.x, t->a.y, t->b.x, t->b.y, @@ -949,8 +980,6 @@ nk_xlib_render(Drawable screen, struct nk_color clear) nk_xsurf_draw_image(surf, i->x, i->y, i->w, i->h, i->img, i->col); } break; case NK_COMMAND_RECT_MULTI_COLOR: - case NK_COMMAND_ARC: - case NK_COMMAND_ARC_FILLED: case NK_COMMAND_CUSTOM: default: break; } diff --git a/demo/x11_xft/nuklear_xlib.h b/demo/x11_xft/nuklear_xlib.h index 5728e8f..9526e3e 100644 --- a/demo/x11_xft/nuklear_xlib.h +++ b/demo/x11_xft/nuklear_xlib.h @@ -389,6 +389,29 @@ nk_xsurf_stroke_circle(XSurface *surf, short x, short y, unsigned short w, XSetLineAttributes(surf->dpy, surf->gc, 1, LineSolid, CapButt, JoinMiter); } +NK_INTERN void +nk_xsurf_stroke_arc(XSurface *surf, short cx, short cy, unsigned short radius, + float a_min, float a_max, unsigned short line_thickness, struct nk_color col) +{ + unsigned long c = nk_color_from_byte(&col.r); + XSetLineAttributes(surf->dpy, surf->gc, line_thickness, LineSolid, CapButt, JoinMiter); + XSetForeground(surf->dpy, surf->gc, c); + XDrawArc(surf->dpy, surf->drawable, surf->gc, (int)(cx - radius), (int)(cy - radius), + (unsigned)(radius * 2), (unsigned)(radius * 2), + (int)(a_min * 180 * 64 / NK_PI), (int)(a_max * 180 * 64 / NK_PI)); +} + +NK_INTERN void +nk_xsurf_fill_arc(XSurface *surf, short cx, short cy, unsigned short radius, + float a_min, float a_max, struct nk_color col) +{ + unsigned long c = nk_color_from_byte(&col.r); + XSetForeground(surf->dpy, surf->gc, c); + XFillArc(surf->dpy, surf->drawable, surf->gc, (int)(cx - radius), (int)(cy - radius), + (unsigned)(radius * 2), (unsigned)(radius * 2), + (int)(a_min * 180 * 64 / NK_PI), (int)(a_max * 180 * 64 / NK_PI)); +} + NK_INTERN void nk_xsurf_stroke_curve(XSurface *surf, struct nk_vec2i p1, struct nk_vec2i p2, struct nk_vec2i p3, struct nk_vec2i p4, @@ -997,6 +1020,14 @@ nk_xlib_render(Drawable screen, struct nk_color clear) const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd; nk_xsurf_fill_circle(surf, c->x, c->y, c->w, c->h, c->color); } break; + case NK_COMMAND_ARC: { + const struct nk_command_arc *a = (const struct nk_command_arc *)cmd; + nk_xsurf_stroke_arc(surf, a->cx, a->cy, a->r, a->a[0], a->a[1], a->line_thickness, a->color); + } break; + case NK_COMMAND_ARC_FILLED: { + const struct nk_command_arc_filled *a = (const struct nk_command_arc_filled *)cmd; + nk_xsurf_fill_arc(surf, a->cx, a->cy, a->r, a->a[0], a->a[1], a->color); + } break; case NK_COMMAND_TRIANGLE: { const struct nk_command_triangle*t = (const struct nk_command_triangle*)cmd; nk_xsurf_stroke_triangle(surf, t->a.x, t->a.y, t->b.x, t->b.y, @@ -1034,8 +1065,6 @@ nk_xlib_render(Drawable screen, struct nk_color clear) nk_xsurf_draw_image(surf, i->x, i->y, i->w, i->h, i->img, i->col); } break; case NK_COMMAND_RECT_MULTI_COLOR: - case NK_COMMAND_ARC: - case NK_COMMAND_ARC_FILLED: case NK_COMMAND_CUSTOM: default: break; } From 54cd692d17d1cf22e452c31c18b8f5921fdf1610 Mon Sep 17 00:00:00 2001 From: Richard Gill Date: Thu, 13 Oct 2022 11:51:50 +0200 Subject: [PATCH 35/61] added comment on ifdefs to use styles in demos --- demo/allegro5/main.c | 1 + demo/d3d11/main.c | 1 + demo/d3d12/main.c | 1 + demo/d3d9/main.c | 1 + demo/gdi/main.c | 1 + demo/gdip/main.c | 1 + demo/glfw_opengl2/main.c | 1 + demo/glfw_opengl3/main.c | 1 + demo/glfw_opengl4/main.c | 1 + demo/sdl_opengl2/main.c | 1 + demo/sdl_opengl3/main.c | 1 + demo/sdl_opengles2/main.c | 3 +++ demo/sdl_renderer/main.c | 1 + demo/sfml_opengl2/main.cpp | 1 + demo/sfml_opengl3/main.cpp | 1 + demo/x11/main.c | 1 + demo/x11_opengl2/main.c | 1 + demo/x11_opengl3/main.c | 1 + demo/x11_rawfb/main.c | 1 + demo/x11_xft/main.c | 1 + 20 files changed, 22 insertions(+) diff --git a/demo/allegro5/main.c b/demo/allegro5/main.c index 0c0f88c..ee01de7 100644 --- a/demo/allegro5/main.c +++ b/demo/allegro5/main.c @@ -116,6 +116,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index f059ea0..ff2ac95 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -210,6 +210,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/d3d12/main.c b/demo/d3d12/main.c index 005ce10..f6891e5 100644 --- a/demo/d3d12/main.c +++ b/demo/d3d12/main.c @@ -302,6 +302,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/d3d9/main.c b/demo/d3d9/main.c index 762ee02..c6b8a5d 100644 --- a/demo/d3d9/main.c +++ b/demo/d3d9/main.c @@ -216,6 +216,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/gdi/main.c b/demo/gdi/main.c index 0c08c39..f588c07 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -115,6 +115,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/gdip/main.c b/demo/gdip/main.c index 11f5aa3..8f132f5 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -111,6 +111,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c index 0401626..8d97773 100644 --- a/demo/glfw_opengl2/main.c +++ b/demo/glfw_opengl2/main.c @@ -121,6 +121,7 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c index a4346d9..8eb749d 100644 --- a/demo/glfw_opengl3/main.c +++ b/demo/glfw_opengl3/main.c @@ -126,6 +126,7 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/glfw_opengl4/main.c b/demo/glfw_opengl4/main.c index 7b7c093..176a1ef 100644 --- a/demo/glfw_opengl4/main.c +++ b/demo/glfw_opengl4/main.c @@ -126,6 +126,7 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c index eb09427c..45c51d2 100644 --- a/demo/sdl_opengl2/main.c +++ b/demo/sdl_opengl2/main.c @@ -117,6 +117,7 @@ main(int argc, char *argv[]) /*nk_style_set_font(ctx, &roboto->handle)*/;} #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c index cc9388b..e039a2f 100644 --- a/demo/sdl_opengl3/main.c +++ b/demo/sdl_opengl3/main.c @@ -128,6 +128,7 @@ int main(int argc, char *argv[]) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/sdl_opengles2/main.c b/demo/sdl_opengles2/main.c index 4048381..b114159 100644 --- a/demo/sdl_opengles2/main.c +++ b/demo/sdl_opengles2/main.c @@ -209,6 +209,8 @@ int main(int argc, char* argv[]) /*nk_style_set_font(ctx, &roboto->handle)*/;} /* style.c */ + #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) @@ -218,6 +220,7 @@ int main(int argc, char* argv[]) #elif defined(STYLE_DARK) set_style(ctx, THEME_DARK); #endif + #endif #if defined(__EMSCRIPTEN__) #include diff --git a/demo/sdl_renderer/main.c b/demo/sdl_renderer/main.c index 09cc83b..940ea84 100644 --- a/demo/sdl_renderer/main.c +++ b/demo/sdl_renderer/main.c @@ -155,6 +155,7 @@ main(int argc, char *argv[]) } #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/sfml_opengl2/main.cpp b/demo/sfml_opengl2/main.cpp index ca5ecd2..82f8e0f 100644 --- a/demo/sfml_opengl2/main.cpp +++ b/demo/sfml_opengl2/main.cpp @@ -98,6 +98,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/sfml_opengl3/main.cpp b/demo/sfml_opengl3/main.cpp index f772057..22aafcc 100644 --- a/demo/sfml_opengl3/main.cpp +++ b/demo/sfml_opengl3/main.cpp @@ -104,6 +104,7 @@ int main(void) /* style.c */ #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/x11/main.c b/demo/x11/main.c index c93ae78..0d02ad7 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -153,6 +153,7 @@ main(void) ctx = nk_xlib_init(xw.font, xw.dpy, xw.screen, xw.win, xw.width, xw.height); #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index 06c2ee0..2dc845e 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -257,6 +257,7 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index 5609d24..a4a3008 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -254,6 +254,7 @@ int main(void) /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/x11_rawfb/main.c b/demo/x11_rawfb/main.c index 1e72c1e..52a1c93 100644 --- a/demo/x11_rawfb/main.c +++ b/demo/x11_rawfb/main.c @@ -194,6 +194,7 @@ main(void) if (!rawfb) running = 0; #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(&rawfb->ctx, THEME_WHITE); #elif defined(STYLE_RED) diff --git a/demo/x11_xft/main.c b/demo/x11_xft/main.c index e069622..263f43b 100644 --- a/demo/x11_xft/main.c +++ b/demo/x11_xft/main.c @@ -157,6 +157,7 @@ main(void) xw.width, xw.height); #ifdef INCLUDE_STYLE + /* ease regression testing during Nuklear release process; not needed for anything else */ #ifdef STYLE_WHITE set_style(ctx, THEME_WHITE); #elif defined(STYLE_RED) From da5198ccdcae3b49cab99cfd0b1195de4369d505 Mon Sep 17 00:00:00 2001 From: loli Date: Mon, 24 Oct 2022 10:40:48 +0200 Subject: [PATCH 36/61] Fix nk_str_{append,insert}_str_utf8 always returning 0 --- nuklear.h | 9 ++++----- src/CHANGELOG | 1 + src/nuklear_string.c | 6 ++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/nuklear.h b/nuklear.h index 5e645db..d115913 100644 --- a/nuklear.h +++ b/nuklear.h @@ -8439,7 +8439,6 @@ nk_str_append_text_utf8(struct nk_str *str, const char *text, int len) NK_API int nk_str_append_str_utf8(struct nk_str *str, const char *text) { - int runes = 0; int byte_len = 0; int num_runes = 0; int glyph_len = 0; @@ -8453,7 +8452,7 @@ nk_str_append_str_utf8(struct nk_str *str, const char *text) num_runes++; } nk_str_append_text_char(str, text, byte_len); - return runes; + return num_runes; } NK_API int nk_str_append_text_runes(struct nk_str *str, const nk_rune *text, int len) @@ -8568,7 +8567,6 @@ nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len) NK_API int nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text) { - int runes = 0; int byte_len = 0; int num_runes = 0; int glyph_len = 0; @@ -8582,7 +8580,7 @@ nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text) num_runes++; } nk_str_insert_at_rune(str, pos, text, byte_len); - return runes; + return num_runes; } NK_API int nk_str_insert_text_runes(struct nk_str *str, int pos, const nk_rune *runes, int len) @@ -29656,7 +29654,8 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2022/08/28 (4.10.3) - Renamed the `null` texture variable to `tex_null` +/// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 +/// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` /// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE /// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than /// nk_edit_xxx limit diff --git a/src/CHANGELOG b/src/CHANGELOG index da6fd2d..62db3f1 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 /// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` /// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE /// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than diff --git a/src/nuklear_string.c b/src/nuklear_string.c index 6ba249f..01a8de5 100644 --- a/src/nuklear_string.c +++ b/src/nuklear_string.c @@ -64,7 +64,6 @@ nk_str_append_text_utf8(struct nk_str *str, const char *text, int len) NK_API int nk_str_append_str_utf8(struct nk_str *str, const char *text) { - int runes = 0; int byte_len = 0; int num_runes = 0; int glyph_len = 0; @@ -78,7 +77,7 @@ nk_str_append_str_utf8(struct nk_str *str, const char *text) num_runes++; } nk_str_append_text_char(str, text, byte_len); - return runes; + return num_runes; } NK_API int nk_str_append_text_runes(struct nk_str *str, const nk_rune *text, int len) @@ -193,7 +192,6 @@ nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len) NK_API int nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text) { - int runes = 0; int byte_len = 0; int num_runes = 0; int glyph_len = 0; @@ -207,7 +205,7 @@ nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text) num_runes++; } nk_str_insert_at_rune(str, pos, text, byte_len); - return runes; + return num_runes; } NK_API int nk_str_insert_text_runes(struct nk_str *str, int pos, const nk_rune *runes, int len) From 637b5e198dbc8ca407cb6e9e260e7a89d8e31638 Mon Sep 17 00:00:00 2001 From: Th3T3chn0G1t Date: Thu, 24 Nov 2022 10:21:37 +0000 Subject: [PATCH 37/61] Fixed UBSan trip in GLFW OpenGL3 demo backend This resolves a false UBSan trip caused by treating the element offset in `glDrawElements` as a pointer This parameter is effectively an offset but is taken as a `void*` By not storing the offset as a pointer, UBSan no longer tools the offset to check for null pointer overflow --- demo/glfw_opengl3/nuklear_glfw_gl3.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demo/glfw_opengl3/nuklear_glfw_gl3.h b/demo/glfw_opengl3/nuklear_glfw_gl3.h index 663fa0b..cef59e5 100644 --- a/demo/glfw_opengl3/nuklear_glfw_gl3.h +++ b/demo/glfw_opengl3/nuklear_glfw_gl3.h @@ -240,7 +240,7 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b /* convert from command queue into draw list and draw to screen */ const struct nk_draw_command *cmd; void *vertices, *elements; - const nk_draw_index *offset = NULL; + nk_size offset = 0; /* allocate vertex and element buffer */ glBindVertexArray(dev->vao); @@ -292,8 +292,8 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b (GLint)((glfw->height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * glfw->fb_scale.y), (GLint)(cmd->clip_rect.w * glfw->fb_scale.x), (GLint)(cmd->clip_rect.h * glfw->fb_scale.y)); - glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset); - offset += cmd->elem_count; + glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, (const void*) offset); + offset += cmd->elem_count * sizeof(nk_draw_index); } nk_clear(&glfw->ctx); nk_buffer_clear(&dev->cmds); From b98732fbc8247b0a1af734179724b7f2e04cef95 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Wed, 30 Nov 2022 18:46:56 +0100 Subject: [PATCH 38/61] gdi_native: Fix calling convention problem The calling convention of a WNDPROC is specified as being 'CALLBACK'. --- demo/gdi_native_nuklear/window.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/demo/gdi_native_nuklear/window.h b/demo/gdi_native_nuklear/window.h index f78d574..0e8eba2 100644 --- a/demo/gdi_native_nuklear/window.h +++ b/demo/gdi_native_nuklear/window.h @@ -44,7 +44,7 @@ struct nkgdi_window HDC window_dc; /* Internally used state variables */ - int is_open; + int is_open; int is_draggin; int ws_override; int is_maximized; @@ -70,9 +70,9 @@ void nkgdi_window_destroy(struct nkgdi_window* wnd); /* Predeclare the windows window message procs */ /* This proc will setup the pointer to the window context */ -LRESULT nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); -/* This proc will take the window context pointer and performs operations on it*/ -LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); +/* This proc will take the window context pointer and performs operations on it*/ +LRESULT CALLBACK nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); void nkgdi_window_init(void) { @@ -126,7 +126,7 @@ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned GetModuleHandleW(NULL), wnd ); - + /* Give the window the ascii char name */ SetWindowTextA(wnd->_internal.window_handle, name); @@ -232,7 +232,7 @@ int nkgdi_window_update(struct nkgdi_window* wnd) return wnd->_internal.is_open; } -LRESULT nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { /* Waiting to receive the NCCREATE message with the custom window data */ if (msg == WM_NCCREATE) @@ -253,11 +253,11 @@ LRESULT nkgdi_window_proc_setup(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam return DefWindowProc(wnd, msg, wParam, lParam); } -LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { /* The window context is extracted from the window data */ struct nkgdi_window* nkwnd = (struct nkgdi_window*)GetWindowLongPtrW(wnd, GWLP_USERDATA); - + /* Switch on the message code to handle all required messages */ switch (msg) { @@ -267,7 +267,7 @@ LRESULT nkgdi_window_proc_run(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) if(!nkwnd->cb_on_close || nkwnd->cb_on_close()) nkwnd->_internal.is_open = 0; return 0; /* No default behaviour. We do it our own way */ - + /* Window sizing event (is currently beeing sized) */ case WM_SIZING: { From 0b7547b710d7574901ef4a957f830cc2a6a81172 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Fri, 2 Dec 2022 00:18:30 +0100 Subject: [PATCH 39/61] demo/win32: Add the renderer name to the window title --- demo/d3d11/main.c | 2 +- demo/d3d12/main.c | 2 +- demo/d3d9/main.c | 2 +- demo/gdi/main.c | 2 +- demo/gdip/main.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index ff2ac95..338dde2 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -161,7 +161,7 @@ int main(void) AdjustWindowRectEx(&rect, style, FALSE, exstyle); - wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", + wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Direct3D 11 Demo", style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, wc.hInstance, NULL); diff --git a/demo/d3d12/main.c b/demo/d3d12/main.c index f6891e5..57e7bc3 100644 --- a/demo/d3d12/main.c +++ b/demo/d3d12/main.c @@ -219,7 +219,7 @@ int main(void) AdjustWindowRectEx(&rect, style, FALSE, exstyle); - wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", + wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Direct3D 12 Demo", style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, wc.hInstance, NULL); diff --git a/demo/d3d9/main.c b/demo/d3d9/main.c index c6b8a5d..638c584 100644 --- a/demo/d3d9/main.c +++ b/demo/d3d9/main.c @@ -191,7 +191,7 @@ int main(void) AdjustWindowRectEx(&rect, style, FALSE, exstyle); - wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", + wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Direct3D 9 Demo", style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, wc.hInstance, NULL); diff --git a/demo/gdi/main.c b/demo/gdi/main.c index f588c07..281f82b 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -103,7 +103,7 @@ int main(void) atom = RegisterClassW(&wc); AdjustWindowRectEx(&rect, style, FALSE, exstyle); - wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", + 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); diff --git a/demo/gdip/main.c b/demo/gdip/main.c index 8f132f5..7151964 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -99,7 +99,7 @@ int main(void) AdjustWindowRectEx(&rect, style, FALSE, exstyle); - wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", + 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); From da9d3866e24c40d4246b4b0b8f0c48523c236652 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Fri, 2 Dec 2022 00:19:04 +0100 Subject: [PATCH 40/61] utils: Add .yml indent_size to .editorconfig --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 4ce28c3..25319b3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [clib.json] indent_size = 2 + +[*.yml] +indent_size = 2 From 607e4716cc851d8aaa7fb51db4b5d5bd2b41b201 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sat, 3 Dec 2022 21:57:14 +0100 Subject: [PATCH 41/61] Add link from the documentation to the code Fixes #515 --- src/HEADER | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HEADER b/src/HEADER index 3a5bffe..477d244 100644 --- a/src/HEADER +++ b/src/HEADER @@ -47,6 +47,7 @@ /// - No global or hidden state /// - Customizable library modules (you can compile and use only what you need) /// - Optional font baker and vertex buffer output +/// - [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/) /// /// ## Features /// - Absolutely no platform dependent code From 1dad328fe9839d57f8282129b3cb9c6a9b75f9c2 Mon Sep 17 00:00:00 2001 From: Jai <814683@qq.com> Date: Fri, 16 Dec 2022 12:20:03 +0800 Subject: [PATCH 42/61] Fix the problem that nk_font_bake_pack uses ttc font offset incorrectly (#456) --- nuklear.h | 2 +- src/nuklear_font.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nuklear.h b/nuklear.h index d115913..c76926a 100644 --- a/nuklear.h +++ b/nuklear.h @@ -16619,7 +16619,7 @@ nk_font_bake_pack(struct nk_font_baker *baker, struct stbtt_fontinfo *font_info = &baker->build[i++].info; font_info->userdata = alloc; - if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, 0)) + if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0))) return nk_false; } while ((it = it->n) != config_iter); } diff --git a/src/nuklear_font.c b/src/nuklear_font.c index 49df38e..431ed80 100644 --- a/src/nuklear_font.c +++ b/src/nuklear_font.c @@ -194,7 +194,7 @@ nk_font_bake_pack(struct nk_font_baker *baker, struct stbtt_fontinfo *font_info = &baker->build[i++].info; font_info->userdata = alloc; - if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, 0)) + if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0))) return nk_false; } while ((it = it->n) != config_iter); } From f78acb43335aa451c60ee24dc7a8b6ce24a00fa1 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 17 Dec 2022 14:00:26 -0500 Subject: [PATCH 43/61] Remove .gitmodules as it's not used anymore --- .gitmodules | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 From 743dd0105feda03ed39415c4877d087bd1651de8 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 17 Dec 2022 14:01:12 -0500 Subject: [PATCH 44/61] Update version for 4.10.5 --- clib.json | 2 +- nuklear.h | 1 + src/CHANGELOG | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clib.json b/clib.json index 3fe7d63..6ae79d6 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.10.1", + "version": "4.10.5", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/nuklear.h b/nuklear.h index c76926a..febee39 100644 --- a/nuklear.h +++ b/nuklear.h @@ -29654,6 +29654,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly /// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 /// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` /// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE diff --git a/src/CHANGELOG b/src/CHANGELOG index 62db3f1..be54e55 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly /// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 /// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` /// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE From 8d9f46a6a5d0f8278ae220187fac7671e08e5660 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 17 Dec 2022 14:10:43 -0500 Subject: [PATCH 45/61] utils: Apply indent_size 2 to all JSON and YAML files --- .editorconfig | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 25319b3..5012ad1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,8 +10,5 @@ indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true -[clib.json] -indent_size = 2 - -[*.yml] +[**.{json,yml}] indent_size = 2 From 23cb43f5ebc820bf62ded25b5843c8395fee4f83 Mon Sep 17 00:00:00 2001 From: Jai <814683@qq.com> Date: Fri, 23 Dec 2022 01:58:40 +0800 Subject: [PATCH 46/61] Fix incorrect glyph index in nk_font_bake --- clib.json | 2 +- nuklear.h | 2 +- src/CHANGELOG | 1 + src/nuklear_font.c | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clib.json b/clib.json index 6ae79d6..cf690c7 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.10.5", + "version": "4.10.6", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/nuklear.h b/nuklear.h index febee39..115317b 100644 --- a/nuklear.h +++ b/nuklear.h @@ -16779,7 +16779,6 @@ nk_font_bake(struct nk_font_baker *baker, void *image_memory, int width, int hei /* query glyph bounds from stb_truetype */ const stbtt_packedchar *pc = &range->chardata_for_range[char_idx]; - if (!pc->x0 && !pc->x1 && !pc->y0 && !pc->y1) continue; codepoint = (nk_rune)(range->first_unicode_codepoint_in_range + char_idx); stbtt_GetPackedQuad(range->chardata_for_range, (int)width, (int)height, char_idx, &dummy_x, &dummy_y, &q, 0); @@ -29654,6 +29653,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly /// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 /// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` diff --git a/src/CHANGELOG b/src/CHANGELOG index be54e55..4bcdfdb 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly /// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 /// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` diff --git a/src/nuklear_font.c b/src/nuklear_font.c index 431ed80..836584f 100644 --- a/src/nuklear_font.c +++ b/src/nuklear_font.c @@ -354,7 +354,6 @@ nk_font_bake(struct nk_font_baker *baker, void *image_memory, int width, int hei /* query glyph bounds from stb_truetype */ const stbtt_packedchar *pc = &range->chardata_for_range[char_idx]; - if (!pc->x0 && !pc->x1 && !pc->y0 && !pc->y1) continue; codepoint = (nk_rune)(range->first_unicode_codepoint_in_range + char_idx); stbtt_GetPackedQuad(range->chardata_for_range, (int)width, (int)height, char_idx, &dummy_x, &dummy_y, &q, 0); From 7c84c3cc1830baaf4f12ebf9d9494bb887f4faa3 Mon Sep 17 00:00:00 2001 From: LonerDan Date: Fri, 13 Jan 2023 12:33:12 +0100 Subject: [PATCH 47/61] Remove link to no longer existing tool The link to the online single header packer (https://apoorvaj.io/single-header-packer.html) no longer works (returns 404), so remove it. --- src/Readme.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Readme.md b/src/Readme.md index eb4de92..e4d9ad3 100644 --- a/src/Readme.md +++ b/src/Readme.md @@ -1,5 +1,4 @@ File Packer: ------------ -- [Click to generate nuklear.h](http://apoorvaj.io/single-header-packer.html?macro=NK&pre=https://raw.githubusercontent.com/vurtun/nuklear/master/src/HEADER&pub=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear.h&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_internal.h&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_math.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_util.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_color.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_utf8.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_buffer.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_string.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_draw.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_vertex.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_font.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_input.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_style.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_context.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_pool.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_page_element.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_table.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_panel.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_window.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_popup.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_contextual.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_menu.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_layout.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_tree.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_group.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_list_view.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_widget.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_text.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_image.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_button.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_toggle.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_selectable.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_slider.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_progress.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_scrollbar.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_text_editor.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_edit.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_property.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_chart.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_color_picker.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_combo.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_tooltip.c&post=https://raw.githubusercontent.com/vurtun/nuklear/master/src/LICENSE&post=https://raw.githubusercontent.com/vurtun/nuklear/master/src/CHANGELOG&post=https://raw.githubusercontent.com/vurtun/nuklear/master/src/CREDITS) - On Linux/Mac just run ./paq.sh > ../nuklear.h - On Windows just run paq.bat From cb6132f1714ca54bca26e647028cbaf65391c59e Mon Sep 17 00:00:00 2001 From: Rongcui Dong Date: Tue, 17 Jan 2023 15:19:05 -0500 Subject: [PATCH 48/61] Update docs --- doc/doc | Bin 0 -> 33632 bytes doc/index.html | 416 ++++++++++++++++++++++++++++--- index.html | 0 nuklear.h | 603 +++++++++++++++++++++++---------------------- src/nuklear.h | 549 +++++++++++++++++++++-------------------- src/nuklear_math.c | 53 ++-- 6 files changed, 999 insertions(+), 622 deletions(-) create mode 100755 doc/doc create mode 100644 index.html diff --git a/doc/doc b/doc/doc new file mode 100755 index 0000000000000000000000000000000000000000..906b2cc19faa9e40ab935b2e401968269fa40f9e GIT binary patch literal 33632 zcmeI5eQZ-z6u{4GhrocXz#IcLJdCV}v=#Xjw$ZUIFcCJ#j8%+}(!Q?G^=o~vj(zBg z2IB`1j3kiw1tvsCkO&$i0kyv`%h>1~{CJ_8%i3uofGU_?+y>49*3DG~#Nlx!M z=bn4sxxd%`d2hcN=({!^KmZgA>O@pA4`4HhXaP(`U5P45^_44Xo~UW4qv%M{7mo~G z=TV)PFj0~kYdno3r}g#jkufm+Q5Yu0mUNLMP2Q-P4i35XQf0vfhzpMt}5X)YW2ID8w`Q&JHr(cy07qSN zMk@wMscjpoBsE2|Uc(LRWw?RcSdU9}xeY%v@00?=-?N8n*Q~0kuFZT$k~w{$PqLnx zL7{$3l)673AW8kvTc&-^GyPrYQ!m7(1obrfV{qKK37{Uwai}zA3+0khuQ!rw}t%ZliYzyeFR@9u@y~U`1+B1Vx?NT;q3=7CZY(H;Qo_%jlQd%=FzwyByNb}n~fU&;nO z2}*IG`X`eHpLNfC(@GCcp%k025#WOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XB zzyz286JP>NfC(^xAp!$UN4x)&gzi5cvvgmsvvv=5?YQv%H2ZG(D>KSjBdjNEl(L$YD8qZ;d0Vg2R!oXYNjrW5a{tkRjO zI5!2g7?sxEUJRa+ykx^@fFg>~+=HWGB0UF>52hO_e;>|weFiP5e0O^CTG{T#~MW~`@YQXcJ%@~&Xs zDa<=(ffkBUt@RcU_Ept>Wy;QJlye;C@vP{FwtRO#Sf-!R?Sd?OQkGq8*kxf^^NPNp zH?GQBxjmr;9E!gRn6s%DgLO>=~LBZ zR8{rGm6%qM$*PNKN;IODcW6=HT6)Y9dsy}>iLm|IrDZNN8Omlj9O7!~4+}359gYgK zj;O|cx71DMxz4Z>aXw8g4L`*=AABbml0DK{Upfnn=b&}Or!&Ok@eHs{KT!<$ zvjFo5wk;{(9G>h=8fS%VN#l66Eomg!l5_?iC8>Y%2NPfdOn?b60Vco%m;e)C0!)Aj zFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#WOn?b60Vco%m;e)C0!)Aj zFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCh)%#5V2xCY7mwF>)f~t01XuLf&ks7 z{}RuLZo4ttorxIh1iU~%C`O%wikDaj)u>clk|b60E0LIKMH3pD0XZ4~sY%v+AjJ~q zr%ELS3C8M|5m=;fP?9&wzJw-ALD}n<<1i}hRU$Cc3aK{p@fm}b6bg9L1Pbi~TS4Er z6M=lXD*;C`b)o+|&-Ul$_=|G<@*KY^$0uHNR|0XwyFm2+UZ=Yha^oUmxPD)fzOP$F zh2@82;OzJm?r1v(GJ7n-7`>HFuwWM!y`?8{-eWEr3$W?5Xwm cD(caGJlWe?d+q9$FFv`jZTDB7Tb9=T4GB_2tpET3 literal 0 HcmV?d00001 diff --git a/doc/index.html b/doc/index.html index 0312be3..919cd95 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,6 +1,5 @@ -Nuklear # Nuklear ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif) ## Contents @@ -47,6 +46,7 @@ render backends it only focuses on the actual UI. - No global or hidden state - Customizable library modules (you can compile and use only what you need) - Optional font baker and vertex buffer output +- [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/) ## Features - Absolutely no platform dependent code - Memory management control ranging from/to @@ -90,7 +90,8 @@ NK_PRIVATE | If defined declares all functions as static, s NK_INCLUDE_FIXED_TYPES | If defined it will include header `` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself. NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management. NK_INCLUDE_STANDARD_IO | If defined it will include header `` and provide additional functions depending on file loading. -NK_INCLUDE_STANDARD_VARARGS | If defined it will include header and provide additional functions depending on file loading. +NK_INCLUDE_STANDARD_VARARGS | If defined it will include header and provide additional functions depending on file loading. +NK_INCLUDE_STANDARD_BOOL | If defined it will include header `` for nk_bool otherwise nuklear defines nk_bool as int. NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,... NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it. NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font @@ -109,6 +110,7 @@ NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for - NK_INCLUDE_FIXED_TYPES - NK_INCLUDE_DEFAULT_ALLOCATOR - NK_INCLUDE_STANDARD_VARARGS + - NK_INCLUDE_STANDARD_BOOL - NK_INCLUDE_VERTEX_BUFFER_OUTPUT - NK_INCLUDE_FONT_BAKING - NK_INCLUDE_DEFAULT_FONT @@ -132,7 +134,7 @@ Function | Description NK_ASSERT | If you don't define this, nuklear will use with assert(). NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version. NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version. -NK_SQRT | You can define this to 'sqrt' or your own sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version. +NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version. NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation. NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation. NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). @@ -221,7 +223,7 @@ __nk_set_user_data__| Utility function to pass user data to draw command Initializes a `nk_context` struct with a default standard library allocator. Should be used if you don't want to be bothered with memory management in nuklear. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_init_default(struct nk_context *ctx, const struct nk_user_font *font); +nk_bool nk_init_default(struct nk_context *ctx, const struct nk_user_font *font); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|--------------------------------------------------------------- @@ -235,7 +237,7 @@ Especially recommended for system with little memory or systems with virtual mem For the later case you can just allocate for example 16MB of virtual memory and only the required amount of memory will actually be committed. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font); +nk_bool nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! Warning make sure the passed memory block is aligned correctly for `nk_draw_commands`. @@ -251,7 +253,7 @@ Initializes a `nk_context` struct with memory allocation callbacks for nuklear t memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation interface to nuklear. Can be useful for cases like monitoring memory consumption. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font); +nk_bool nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|--------------------------------------------------------------- @@ -264,7 +266,7 @@ Initializes a `nk_context` struct from two different either fixed or growing buffers. The first buffer is for allocating draw commands while the second buffer is used for allocating windows, panels and state tables. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font); +nk_bool nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|--------------------------------------------------------------- @@ -379,7 +381,7 @@ __y__ | Must hold an integer describing the current mouse cursor y-positio #### nk_input_key Mirrors the state of a specific key to nuklear ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -void nk_input_key(struct nk_context*, enum nk_keys key, int down); +void nk_input_key(struct nk_context*, enum nk_keys key, nk_bool down); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -389,7 +391,7 @@ __down__ | Must be 0 for key is up and 1 for key is down #### nk_input_button Mirrors the state of a specific mouse button to nuklear ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, int down); +void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, nk_bool down); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -891,7 +893,7 @@ __NK_MAXIMIZED__| UI section is extended and visible until minimized Starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); +nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -905,7 +907,7 @@ until `nk_end` or `false(0)` otherwise for example if minimized Extended window start with separated title and identifier to allow multiple windows with same title but not name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); +nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1086,7 +1088,7 @@ Returns if the currently processed window is currently active !!! WARNING Only call this function between calls `nk_begin_xxx` and `nk_end` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_window_has_focus(const struct nk_context *ctx); +nk_bool nk_window_has_focus(const struct nk_context *ctx); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1097,7 +1099,7 @@ Return if the current window is being hovered !!! WARNING Only call this function between calls `nk_begin_xxx` and `nk_end` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_window_is_hovered(struct nk_context *ctx); +nk_bool nk_window_is_hovered(struct nk_context *ctx); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1106,7 +1108,7 @@ Returns `true(1)` if current window is hovered or `false(0)` otherwise #### nk_window_is_collapsed Returns if the window with given name is currently minimized/collapsed ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_window_is_collapsed(struct nk_context *ctx, const char *name); +nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1117,7 +1119,7 @@ found or is not minimized #### nk_window_is_closed Returns if the window with given name was closed by calling `nk_close` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_window_is_closed(struct nk_context *ctx, const char *name); +nk_bool nk_window_is_closed(struct nk_context *ctx, const char *name); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1127,7 +1129,7 @@ Returns `true(1)` if current window was closed or `false(0)` window not found or #### nk_window_is_hidden Returns if the window with given name is hidden ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_window_is_hidden(struct nk_context *ctx, const char *name); +nk_bool nk_window_is_hidden(struct nk_context *ctx, const char *name); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1137,7 +1139,7 @@ Returns `true(1)` if current window is hidden or `false(0)` window not found or #### nk_window_is_active Same as nk_window_has_focus for some reason ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_window_is_active(struct nk_context *ctx, const char *name); +nk_bool nk_window_is_active(struct nk_context *ctx, const char *name); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1147,7 +1149,7 @@ Returns `true(1)` if current window is active or `false(0)` window not found or #### nk_window_is_any_hovered Returns if the any window is being hovered ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_window_is_any_hovered(struct nk_context*); +nk_bool nk_window_is_any_hovered(struct nk_context*); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1158,7 +1160,7 @@ Returns if the any window is being hovered or any widget is currently active. Can be used to decide if input should be processed by UI or your specific input handling. Example could be UI and 3D camera to move inside a 3D space. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_item_is_any_active(struct nk_context*); +nk_bool nk_item_is_any_active(struct nk_context*); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1731,6 +1733,14 @@ Parameter | Description __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` __bounds__ | Rectangle to convert from layout space into screen space Returns transformed `nk_rect` in layout space coordinates +#### nk_spacer +Spacer is a dummy widget that consumes space as usual but doesn't draw anything +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +void nk_spacer(struct nk_context* ); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Parameter | Description +------------|----------------------------------------------------------- +__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` ### Groups Groups are basically windows inside windows. They allow to subdivide space in a window to layout widgets as a group. Almost all more complex widget @@ -1812,7 +1822,7 @@ nk_group_set_scroll | Sets the scroll offset for the given group #### nk_group_begin Starts a new widget group. Requires a previous layouting function to specify a pos/size. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_group_begin(struct nk_context*, const char *title, nk_flags); +nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1823,7 +1833,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise #### nk_group_begin_titled Starts a new widget group. Requires a previous layouting function to specify a pos/size. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); +nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1844,7 +1854,7 @@ __ctx__ | Must point to an previously initialized `nk_context` struct starts a new widget group. requires a previous layouting function to specify a size. Does not keep track of scrollbar. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); +nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1858,7 +1868,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise Starts a new widget group. requires a previous layouting function to specify a size. Does not keep track of scrollbar. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); +nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -1986,7 +1996,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise Start a collapsible UI section with internal state management with full control over internal unique ID used to store state ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -2035,7 +2045,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise Start a collapsible UI section with internal state management with full control over internal unique ID used to store state ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -2059,7 +2069,7 @@ __ctx__ | Must point to an previously initialized `nk_context` struct after #### nk_tree_state_push Start a collapsible UI section with external state management ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); +nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -2071,7 +2081,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise #### nk_tree_state_image_push Start a collapsible UI section with image and label header and external state management ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -int nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); +nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter | Description ------------|----------------------------------------------------------- @@ -2260,6 +2270,302 @@ __max__ | Maximum value not allowed to be overflown __step__ | Increment added and subtracted on increment and decrement button __inc_per_pixel__ | Value per pixel added or subtracted on dragging Returns the new modified double value +### Font +Font handling in this library was designed to be quite customizable and lets +you decide what you want to use and what you want to provide. There are three +different ways to use the font atlas. The first two will use your font +handling scheme and only requires essential data to run nuklear. The next +slightly more advanced features is font handling with vertex buffer output. +Finally the most complex API wise is using nuklear's font baking API. +#### Using your own implementation without vertex buffer output + +So first up the easiest way to do font handling is by just providing a +`nk_user_font` struct which only requires the height in pixel of the used +font and a callback to calculate the width of a string. This way of handling +fonts is best fitted for using the normal draw shape command API where you +do all the text drawing yourself and the library does not require any kind +of deeper knowledge about which font handling mechanism you use. +IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist +over the complete life time! I know this sucks but it is currently the only +way to switch between fonts. +```c + float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) + { + your_font_type *type = handle.ptr; + float text_width = ...; + return text_width; + } + struct nk_user_font font; + font.userdata.ptr = &your_font_class_or_struct; + font.height = your_font_height; + font.width = your_text_width_calculation; + + struct nk_context ctx; + nk_init_default(&ctx, &font); +``` +#### Using your own implementation with vertex buffer output + +While the first approach works fine if you don't want to use the optional +vertex buffer output it is not enough if you do. To get font handling working +for these cases you have to provide two additional parameters inside the +`nk_user_font`. First a texture atlas handle used to draw text as subimages +of a bigger font atlas texture and a callback to query a character's glyph +information (offset, size, ...). So it is still possible to provide your own +font and use the vertex buffer output. +```c + float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) + { + your_font_type *type = handle.ptr; + float text_width = ...; + return text_width; + } + void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) + { + your_font_type *type = handle.ptr; + glyph.width = ...; + glyph.height = ...; + glyph.xadvance = ...; + glyph.uv[0].x = ...; + glyph.uv[0].y = ...; + glyph.uv[1].x = ...; + glyph.uv[1].y = ...; + glyph.offset.x = ...; + glyph.offset.y = ...; + } + + struct nk_user_font font; + font.userdata.ptr = &your_font_class_or_struct; + font.height = your_font_height; + font.width = your_text_width_calculation; + font.query = query_your_font_glyph; + font.texture.id = your_font_texture; + + struct nk_context ctx; + nk_init_default(&ctx, &font); +``` +#### Nuklear font baker + +The final approach if you do not have a font handling functionality or don't +want to use it in this library is by using the optional font baker. +The font baker APIs can be used to create a font plus font atlas texture +and can be used with or without the vertex buffer output. + +It still uses the `nk_user_font` struct and the two different approaches +previously stated still work. The font baker is not located inside +`nk_context` like all other systems since it can be understood as more of +an extension to nuklear and does not really depend on any `nk_context` state. + +Font baker need to be initialized first by one of the nk_font_atlas_init_xxx +functions. If you don't care about memory just call the default version +`nk_font_atlas_init_default` which will allocate all memory from the standard library. +If you want to control memory allocation but you don't care if the allocated +memory is temporary and therefore can be freed directly after the baking process +is over or permanent you can call `nk_font_atlas_init`. + +After successfully initializing the font baker you can add Truetype(.ttf) fonts from +different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. +functions. Adding font will permanently store each font, font config and ttf memory block(!) +inside the font atlas and allows to reuse the font atlas. If you don't want to reuse +the font baker by for example adding additional fonts you can call +`nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). + +As soon as you added all fonts you wanted you can now start the baking process +for every selected glyph to image by calling `nk_font_atlas_bake`. +The baking process returns image memory, width and height which can be used to +either create your own image object or upload it to any graphics library. +No matter which case you finally have to call `nk_font_atlas_end` which +will free all temporary memory including the font atlas image so make sure +you created our texture beforehand. `nk_font_atlas_end` requires a handle +to your font texture or object and optionally fills a `struct nk_draw_null_texture` +which can be used for the optional vertex output. If you don't want it just +set the argument to `NULL`. + +At this point you are done and if you don't want to reuse the font atlas you +can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration +memory. Finally if you don't use the font atlas and any of it's fonts anymore +you need to call `nk_font_atlas_clear` to free all memory still being used. + +```c + struct nk_font_atlas atlas; + nk_font_atlas_init_default(&atlas); + nk_font_atlas_begin(&atlas); + nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); + nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); + const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); + nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); + + struct nk_context ctx; + nk_init_default(&ctx, &font->handle); + while (1) { + + } + nk_font_atlas_clear(&atlas); +``` +The font baker API is probably the most complex API inside this library and +I would suggest reading some of my examples `example/` to get a grip on how +to use the font atlas. There are a number of details I left out. For example +how to merge fonts, configure a font with `nk_font_config` to use other languages, +use another texture coordinate format and a lot more: +```c + struct nk_font_config cfg = nk_font_config(font_pixel_height); + cfg.merge_mode = nk_false or nk_true; + cfg.range = nk_font_korean_glyph_ranges(); + cfg.coord_type = NK_COORD_PIXEL; + nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); +``` +### Memory Buffer +A basic (double)-buffer with linear allocation and resetting as only +freeing policy. The buffer's main purpose is to control all memory management +inside the GUI toolkit and still leave memory control as much as possible in +the hand of the user while also making sure the library is easy to use if +not as much control is needed. +In general all memory inside this library can be provided from the user in +three different ways. + +The first way and the one providing most control is by just passing a fixed +size memory block. In this case all control lies in the hand of the user +since he can exactly control where the memory comes from and how much memory +the library should consume. Of course using the fixed size API removes the +ability to automatically resize a buffer if not enough memory is provided so +you have to take over the resizing. While being a fixed sized buffer sounds +quite limiting, it is very effective in this library since the actual memory +consumption is quite stable and has a fixed upper bound for a lot of cases. + +If you don't want to think about how much memory the library should allocate +at all time or have a very dynamic UI with unpredictable memory consumption +habits but still want control over memory allocation you can use the dynamic +allocator based API. The allocator consists of two callbacks for allocating +and freeing memory and optional userdata so you can plugin your own allocator. + +The final and easiest way can be used by defining +NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory +allocation functions malloc and free and takes over complete control over +memory in this library. +### Text Editor +Editing text in this library is handled by either `nk_edit_string` or +`nk_edit_buffer`. But like almost everything in this library there are multiple +ways of doing it and a balance between control and ease of use with memory +as well as functionality controlled by flags. +This library generally allows three different levels of memory control: +First of is the most basic way of just providing a simple char array with +string length. This method is probably the easiest way of handling simple +user text input. Main upside is complete control over memory while the biggest +downside in comparison with the other two approaches is missing undo/redo. +For UIs that require undo/redo the second way was created. It is based on +a fixed size nk_text_edit struct, which has an internal undo/redo stack. +This is mainly useful if you want something more like a text editor but don't want +to have a dynamically growing buffer. +The final way is using a dynamically growing nk_text_edit struct, which +has both a default version if you don't care where memory comes from and an +allocator version if you do. While the text editor is quite powerful for its +complexity I would not recommend editing gigabytes of data with it. +It is rather designed for uses cases which make sense for a GUI library not for +an full blown text editor. +### Drawing +This library was designed to be render backend agnostic so it does +not draw anything to screen. Instead all drawn shapes, widgets +are made of, are buffered into memory and make up a command queue. +Each frame therefore fills the command buffer with draw commands +that then need to be executed by the user and his own render backend. +After that the command buffer needs to be cleared and a new frame can be +started. It is probably important to note that the command buffer is the main +drawing API and the optional vertex buffer API only takes this format and +converts it into a hardware accessible format. + +To use the command queue to draw your own widgets you can access the +command buffer of each window by calling `nk_window_get_canvas` after +previously having called `nk_begin`: + +```c + void draw_red_rectangle_widget(struct nk_context *ctx) + { + struct nk_command_buffer *canvas; + struct nk_input *input = &ctx->input; + canvas = nk_window_get_canvas(ctx); + + struct nk_rect space; + enum nk_widget_layout_states state; + state = nk_widget(&space, ctx); + if (!state) return; + + if (state != NK_WIDGET_ROM) + update_your_widget_by_user_input(...); + nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); + } + + if (nk_begin(...)) { + nk_layout_row_dynamic(ctx, 25, 1); + draw_red_rectangle_widget(ctx); + } + nk_end(..) + +``` +Important to know if you want to create your own widgets is the `nk_widget` +call. It allocates space on the panel reserved for this widget to be used, +but also returns the state of the widget space. If your widget is not seen and does +not have to be updated it is '0' and you can just return. If it only has +to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both +update and draw your widget. The reason for separating is to only draw and +update what is actually necessary which is crucial for performance. +Draw List +The optional vertex buffer draw list provides a 2D drawing context +with antialiasing functionality which takes basic filled or outlined shapes +or a path and outputs vertexes, elements and draw commands. +The actual draw list API is not required to be used directly while using this +library since converting the default library draw command output is done by +just calling `nk_convert` but I decided to still make this library accessible +since it can be useful. + +The draw list is based on a path buffering and polygon and polyline +rendering API which allows a lot of ways to draw 2D content to screen. +In fact it is probably more powerful than needed but allows even more crazy +things than this library provides by default. +### Stack +The style modifier stack can be used to temporarily change a +property inside `nk_style`. For example if you want a special +red button you can temporarily push the old button color onto a stack +draw the button with a red color and then you just pop the old color +back from the stack: + + nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); + nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); + nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); + nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); + + nk_button(...); + + nk_style_pop_style_item(ctx); + nk_style_pop_style_item(ctx); + nk_style_pop_style_item(ctx); + nk_style_pop_vec2(ctx); + +Nuklear has a stack for style_items, float properties, vector properties, +flags, colors, fonts and for button_behavior. Each has it's own fixed size stack +which can be changed at compile time. +### Math + Since nuklear is supposed to work on all systems providing floating point + math without any dependencies I also had to implement my own math functions + for sqrt, sin and cos. Since the actual highly accurate implementations for + the standard library functions are quite complex and I do not need high + precision for my use cases I use approximations. + Sqrt + ---- + For square root nuklear uses the famous fast inverse square root: + https://en.wikipedia.org/wiki/Fast_inverse_square_root with + slightly tweaked magic constant. While on today's hardware it is + probably not faster it is still fast and accurate enough for + nuklear's use cases. IMPORTANT: this requires float format IEEE 754 + Sine/Cosine + ----------- + All constants inside both function are generated Remez's minimax + approximations for value range 0...2*PI. The reason why I decided to + approximate exactly that range is that nuklear only needs sine and + cosine to generate circles which only requires that exact range. + In addition I used Remez instead of Taylor for additional precision: + www.lolengine.net/blog/2011/12/21/better-function-approximations. + The tool I used to generate constants for both sine and cosine + (it can actually approximate a lot more functions) can be + found here: www.lolengine.net/wiki/oss/lolremez -XXX.XXX- X...X - X...X -X....X - X....X" X...XXXXXXXXXXXXX...X - " ## License @@ -2306,13 +2612,55 @@ X...XXXXXXXXXXXXX...X - " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## Changelog ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none -[date][x.yy.zz]-[description] --[date]: date on which the change has been pushed --[x.yy.zz]: Numerical version string representation. Each version number on the right - resets back to zero if version on the left is incremented. - - [x]: Major version with API and library breaking changes - - [yy]: Minor version with non-breaking API and library changes - - [zz]: Bug fix version with no direct changes to API +[date] ([x.y.z]) - [description] +- [date]: date on which the change has been pushed +- [x.y.z]: Version string, represented in Semantic Versioning format + - [x]: Major version with API and library breaking changes + - [y]: Minor version with non-breaking API and library changes + - [z]: Patch version with no direct changes to the API +- 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly +- 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 +- 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` +- 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE +- 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than + nk_edit_xxx limit +- 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug +- 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to + only trigger when the mouse position was inside the same button on down +- 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS +- 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions +- 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized +- 2021/12/22 (4.09.3) - Fix layout bounds not accounting for padding +- 2021/12/19 (4.09.2) - Update to stb_rect_pack.h v1.01 and stb_truetype.h v1.26 +- 2021/12/16 (4.09.1) - Fix the majority of GCC warnings +- 2021/10/16 (4.09.0) - Added nk_spacer() widget +- 2021/09/22 (4.08.6) - Fix "may be used uninitialized" warnings in nk_widget +- 2021/09/22 (4.08.5) - GCC __builtin_offsetof only exists in version 4 and later +- 2021/09/15 (4.08.4) - Fix "'num_len' may be used uninitialized" in nk_do_property +- 2021/09/15 (4.08.3) - Fix "Templates cannot be declared to have 'C' Linkage" +- 2021/09/08 (4.08.2) - Fix warnings in C89 builds +- 2021/09/08 (4.08.1) - Use compiler builtins for NK_OFFSETOF when possible +- 2021/08/17 (4.08.0) - Implemented 9-slice scaling support for widget styles +- 2021/08/16 (4.07.5) - Replace usage of memset in nk_font_atlas_bake with NK_MEMSET +- 2021/08/15 (4.07.4) - Fix conversion and sign conversion warnings +- 2021/08/08 (4.07.3) - Fix crash when baking merged fonts +- 2021/08/08 (4.07.2) - Fix Multiline Edit wrong offset +- 2021/03/17 (4.07.1) - Fix warning about unused parameter +- 2021/03/17 (4.07.0) - Fix nk_property hover bug +- 2021/03/15 (4.06.4) - Change nk_propertyi back to int +- 2021/03/15 (4.06.3) - Update documentation for functions that now return nk_bool +- 2020/12/19 (4.06.2) - Fix additional C++ style comments which are not allowed in ISO C90. +- 2020/10/11 (4.06.1) - Fix C++ style comments which are not allowed in ISO C90. +- 2020/10/07 (4.06.0) - Fix nk_combo return type wrongly changed to nk_bool +- 2020/09/05 (4.05.0) - Use the nk_font_atlas allocator for stb_truetype memory management. +- 2020/09/04 (4.04.1) - Replace every boolean int by nk_bool +- 2020/09/04 (4.04.0) - Add nk_bool with NK_INCLUDE_STANDARD_BOOL +- 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes. +- 2020/06/04 (4.03.0) - Made nk_combo header symbols optional. +- 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget. +- 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug +- 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS +- 2020/04/30 (4.02.2) - Fix nk_edit border drawing bug - 2020/04/09 (4.02.1) - Removed unused nk_sqrt function to fix compiler warnings - Fixed compiler warnings if you bring your own methods for nk_cos/nk_sin/nk_strtod/nk_memset/nk_memcopy/nk_dtoa diff --git a/index.html b/index.html new file mode 100644 index 0000000..e69de29 diff --git a/nuklear.h b/nuklear.h index febee39..b06753f 100644 --- a/nuklear.h +++ b/nuklear.h @@ -48,6 +48,7 @@ /// - No global or hidden state /// - Customizable library modules (you can compile and use only what you need) /// - Optional font baker and vertex buffer output +/// - [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/) /// /// ## Features /// - Absolutely no platform dependent code @@ -3797,149 +3798,155 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune * FONT * * ===============================================================*/ -/* Font handling in this library was designed to be quite customizable and lets - you decide what you want to use and what you want to provide. There are three - different ways to use the font atlas. The first two will use your font - handling scheme and only requires essential data to run nuklear. The next - slightly more advanced features is font handling with vertex buffer output. - Finally the most complex API wise is using nuklear's font baking API. - - 1.) Using your own implementation without vertex buffer output - -------------------------------------------------------------- - So first up the easiest way to do font handling is by just providing a - `nk_user_font` struct which only requires the height in pixel of the used - font and a callback to calculate the width of a string. This way of handling - fonts is best fitted for using the normal draw shape command API where you - do all the text drawing yourself and the library does not require any kind - of deeper knowledge about which font handling mechanism you use. - IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist - over the complete life time! I know this sucks but it is currently the only - way to switch between fonts. - - float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) - { - your_font_type *type = handle.ptr; - float text_width = ...; - return text_width; - } - - struct nk_user_font font; - font.userdata.ptr = &your_font_class_or_struct; - font.height = your_font_height; - font.width = your_text_width_calculation; - - struct nk_context ctx; - nk_init_default(&ctx, &font); - - 2.) Using your own implementation with vertex buffer output - -------------------------------------------------------------- - While the first approach works fine if you don't want to use the optional - vertex buffer output it is not enough if you do. To get font handling working - for these cases you have to provide two additional parameters inside the - `nk_user_font`. First a texture atlas handle used to draw text as subimages - of a bigger font atlas texture and a callback to query a character's glyph - information (offset, size, ...). So it is still possible to provide your own - font and use the vertex buffer output. - - float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) - { - your_font_type *type = handle.ptr; - float text_width = ...; - return text_width; - } - void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) - { - your_font_type *type = handle.ptr; - glyph.width = ...; - glyph.height = ...; - glyph.xadvance = ...; - glyph.uv[0].x = ...; - glyph.uv[0].y = ...; - glyph.uv[1].x = ...; - glyph.uv[1].y = ...; - glyph.offset.x = ...; - glyph.offset.y = ...; - } - - struct nk_user_font font; - font.userdata.ptr = &your_font_class_or_struct; - font.height = your_font_height; - font.width = your_text_width_calculation; - font.query = query_your_font_glyph; - font.texture.id = your_font_texture; - - struct nk_context ctx; - nk_init_default(&ctx, &font); - - 3.) Nuklear font baker - ------------------------------------ - The final approach if you do not have a font handling functionality or don't - want to use it in this library is by using the optional font baker. - The font baker APIs can be used to create a font plus font atlas texture - and can be used with or without the vertex buffer output. - - It still uses the `nk_user_font` struct and the two different approaches - previously stated still work. The font baker is not located inside - `nk_context` like all other systems since it can be understood as more of - an extension to nuklear and does not really depend on any `nk_context` state. - - Font baker need to be initialized first by one of the nk_font_atlas_init_xxx - functions. If you don't care about memory just call the default version - `nk_font_atlas_init_default` which will allocate all memory from the standard library. - If you want to control memory allocation but you don't care if the allocated - memory is temporary and therefore can be freed directly after the baking process - is over or permanent you can call `nk_font_atlas_init`. - - After successfully initializing the font baker you can add Truetype(.ttf) fonts from - different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. - functions. Adding font will permanently store each font, font config and ttf memory block(!) - inside the font atlas and allows to reuse the font atlas. If you don't want to reuse - the font baker by for example adding additional fonts you can call - `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). - - As soon as you added all fonts you wanted you can now start the baking process - for every selected glyph to image by calling `nk_font_atlas_bake`. - The baking process returns image memory, width and height which can be used to - either create your own image object or upload it to any graphics library. - No matter which case you finally have to call `nk_font_atlas_end` which - will free all temporary memory including the font atlas image so make sure - you created our texture beforehand. `nk_font_atlas_end` requires a handle - to your font texture or object and optionally fills a `struct nk_draw_null_texture` - which can be used for the optional vertex output. If you don't want it just - set the argument to `NULL`. - - At this point you are done and if you don't want to reuse the font atlas you - can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration - memory. Finally if you don't use the font atlas and any of it's fonts anymore - you need to call `nk_font_atlas_clear` to free all memory still being used. - - struct nk_font_atlas atlas; - nk_font_atlas_init_default(&atlas); - nk_font_atlas_begin(&atlas); - nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); - nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); - const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); - nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); - - struct nk_context ctx; - nk_init_default(&ctx, &font->handle); - while (1) { - - } - nk_font_atlas_clear(&atlas); - - The font baker API is probably the most complex API inside this library and - I would suggest reading some of my examples `example/` to get a grip on how - to use the font atlas. There are a number of details I left out. For example - how to merge fonts, configure a font with `nk_font_config` to use other languages, - use another texture coordinate format and a lot more: - - struct nk_font_config cfg = nk_font_config(font_pixel_height); - cfg.merge_mode = nk_false or nk_true; - cfg.range = nk_font_korean_glyph_ranges(); - cfg.coord_type = NK_COORD_PIXEL; - nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); - +/*/// ### Font +/// Font handling in this library was designed to be quite customizable and lets +/// you decide what you want to use and what you want to provide. There are three +/// different ways to use the font atlas. The first two will use your font +/// handling scheme and only requires essential data to run nuklear. The next +/// slightly more advanced features is font handling with vertex buffer output. +/// Finally the most complex API wise is using nuklear's font baking API. +// +/// #### Using your own implementation without vertex buffer output +/// +/// So first up the easiest way to do font handling is by just providing a +/// `nk_user_font` struct which only requires the height in pixel of the used +/// font and a callback to calculate the width of a string. This way of handling +/// fonts is best fitted for using the normal draw shape command API where you +/// do all the text drawing yourself and the library does not require any kind +/// of deeper knowledge about which font handling mechanism you use. +/// IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist +/// over the complete life time! I know this sucks but it is currently the only +/// way to switch between fonts. +/// +/// ```c +/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) +/// { +/// your_font_type *type = handle.ptr; +/// float text_width = ...; +/// return text_width; +/// } +/// +/// struct nk_user_font font; +/// font.userdata.ptr = &your_font_class_or_struct; +/// font.height = your_font_height; +/// font.width = your_text_width_calculation; +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font); +/// ``` +/// #### Using your own implementation with vertex buffer output +/// +/// While the first approach works fine if you don't want to use the optional +/// vertex buffer output it is not enough if you do. To get font handling working +/// for these cases you have to provide two additional parameters inside the +/// `nk_user_font`. First a texture atlas handle used to draw text as subimages +/// of a bigger font atlas texture and a callback to query a character's glyph +/// information (offset, size, ...). So it is still possible to provide your own +/// font and use the vertex buffer output. +/// +/// ```c +/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) +/// { +/// your_font_type *type = handle.ptr; +/// float text_width = ...; +/// return text_width; +/// } +/// void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) +/// { +/// your_font_type *type = handle.ptr; +/// glyph.width = ...; +/// glyph.height = ...; +/// glyph.xadvance = ...; +/// glyph.uv[0].x = ...; +/// glyph.uv[0].y = ...; +/// glyph.uv[1].x = ...; +/// glyph.uv[1].y = ...; +/// glyph.offset.x = ...; +/// glyph.offset.y = ...; +/// } +/// +/// struct nk_user_font font; +/// font.userdata.ptr = &your_font_class_or_struct; +/// font.height = your_font_height; +/// font.width = your_text_width_calculation; +/// font.query = query_your_font_glyph; +/// font.texture.id = your_font_texture; +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font); +/// ``` +/// +/// #### Nuklear font baker +/// +/// The final approach if you do not have a font handling functionality or don't +/// want to use it in this library is by using the optional font baker. +/// The font baker APIs can be used to create a font plus font atlas texture +/// and can be used with or without the vertex buffer output. +/// +/// It still uses the `nk_user_font` struct and the two different approaches +/// previously stated still work. The font baker is not located inside +/// `nk_context` like all other systems since it can be understood as more of +/// an extension to nuklear and does not really depend on any `nk_context` state. +/// +/// Font baker need to be initialized first by one of the nk_font_atlas_init_xxx +/// functions. If you don't care about memory just call the default version +/// `nk_font_atlas_init_default` which will allocate all memory from the standard library. +/// If you want to control memory allocation but you don't care if the allocated +/// memory is temporary and therefore can be freed directly after the baking process +/// is over or permanent you can call `nk_font_atlas_init`. +/// +/// After successfully initializing the font baker you can add Truetype(.ttf) fonts from +/// different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. +/// functions. Adding font will permanently store each font, font config and ttf memory block(!) +/// inside the font atlas and allows to reuse the font atlas. If you don't want to reuse +/// the font baker by for example adding additional fonts you can call +/// `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). +/// +/// As soon as you added all fonts you wanted you can now start the baking process +/// for every selected glyph to image by calling `nk_font_atlas_bake`. +/// The baking process returns image memory, width and height which can be used to +/// either create your own image object or upload it to any graphics library. +/// No matter which case you finally have to call `nk_font_atlas_end` which +/// will free all temporary memory including the font atlas image so make sure +/// you created our texture beforehand. `nk_font_atlas_end` requires a handle +/// to your font texture or object and optionally fills a `struct nk_draw_null_texture` +/// which can be used for the optional vertex output. If you don't want it just +/// set the argument to `NULL`. +/// +/// At this point you are done and if you don't want to reuse the font atlas you +/// can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration +/// memory. Finally if you don't use the font atlas and any of it's fonts anymore +/// you need to call `nk_font_atlas_clear` to free all memory still being used. +/// +/// ```c +/// struct nk_font_atlas atlas; +/// nk_font_atlas_init_default(&atlas); +/// nk_font_atlas_begin(&atlas); +/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); +/// nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); +/// const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); +/// nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font->handle); +/// while (1) { +/// +/// } +/// nk_font_atlas_clear(&atlas); +/// ``` +/// The font baker API is probably the most complex API inside this library and +/// I would suggest reading some of my examples `example/` to get a grip on how +/// to use the font atlas. There are a number of details I left out. For example +/// how to merge fonts, configure a font with `nk_font_config` to use other languages, +/// use another texture coordinate format and a lot more: +/// +/// ```c +/// struct nk_font_config cfg = nk_font_config(font_pixel_height); +/// cfg.merge_mode = nk_false or nk_true; +/// cfg.range = nk_font_korean_glyph_ranges(); +/// cfg.coord_type = NK_COORD_PIXEL; +/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); +/// ``` */ struct nk_user_font_glyph; typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len); @@ -4110,33 +4117,34 @@ NK_API void nk_font_atlas_clear(struct nk_font_atlas*); * MEMORY BUFFER * * ===============================================================*/ -/* A basic (double)-buffer with linear allocation and resetting as only - freeing policy. The buffer's main purpose is to control all memory management - inside the GUI toolkit and still leave memory control as much as possible in - the hand of the user while also making sure the library is easy to use if - not as much control is needed. - In general all memory inside this library can be provided from the user in - three different ways. - - The first way and the one providing most control is by just passing a fixed - size memory block. In this case all control lies in the hand of the user - since he can exactly control where the memory comes from and how much memory - the library should consume. Of course using the fixed size API removes the - ability to automatically resize a buffer if not enough memory is provided so - you have to take over the resizing. While being a fixed sized buffer sounds - quite limiting, it is very effective in this library since the actual memory - consumption is quite stable and has a fixed upper bound for a lot of cases. - - If you don't want to think about how much memory the library should allocate - at all time or have a very dynamic UI with unpredictable memory consumption - habits but still want control over memory allocation you can use the dynamic - allocator based API. The allocator consists of two callbacks for allocating - and freeing memory and optional userdata so you can plugin your own allocator. - - The final and easiest way can be used by defining - NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory - allocation functions malloc and free and takes over complete control over - memory in this library. +/*/// ### Memory Buffer +/// A basic (double)-buffer with linear allocation and resetting as only +/// freeing policy. The buffer's main purpose is to control all memory management +/// inside the GUI toolkit and still leave memory control as much as possible in +/// the hand of the user while also making sure the library is easy to use if +/// not as much control is needed. +/// In general all memory inside this library can be provided from the user in +/// three different ways. +/// +/// The first way and the one providing most control is by just passing a fixed +/// size memory block. In this case all control lies in the hand of the user +/// since he can exactly control where the memory comes from and how much memory +/// the library should consume. Of course using the fixed size API removes the +/// ability to automatically resize a buffer if not enough memory is provided so +/// you have to take over the resizing. While being a fixed sized buffer sounds +/// quite limiting, it is very effective in this library since the actual memory +/// consumption is quite stable and has a fixed upper bound for a lot of cases. +/// +/// If you don't want to think about how much memory the library should allocate +/// at all time or have a very dynamic UI with unpredictable memory consumption +/// habits but still want control over memory allocation you can use the dynamic +/// allocator based API. The allocator consists of two callbacks for allocating +/// and freeing memory and optional userdata so you can plugin your own allocator. +/// +/// The final and easiest way can be used by defining +/// NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory +/// allocation functions malloc and free and takes over complete control over +/// memory in this library. */ struct nk_memory_status { void *memory; @@ -4261,28 +4269,29 @@ NK_API int nk_str_len_char(struct nk_str*); * TEXT EDITOR * * ===============================================================*/ -/* Editing text in this library is handled by either `nk_edit_string` or - * `nk_edit_buffer`. But like almost everything in this library there are multiple - * ways of doing it and a balance between control and ease of use with memory - * as well as functionality controlled by flags. - * - * This library generally allows three different levels of memory control: - * First of is the most basic way of just providing a simple char array with - * string length. This method is probably the easiest way of handling simple - * user text input. Main upside is complete control over memory while the biggest - * downside in comparison with the other two approaches is missing undo/redo. - * - * For UIs that require undo/redo the second way was created. It is based on - * a fixed size nk_text_edit struct, which has an internal undo/redo stack. - * This is mainly useful if you want something more like a text editor but don't want - * to have a dynamically growing buffer. - * - * The final way is using a dynamically growing nk_text_edit struct, which - * has both a default version if you don't care where memory comes from and an - * allocator version if you do. While the text editor is quite powerful for its - * complexity I would not recommend editing gigabytes of data with it. - * It is rather designed for uses cases which make sense for a GUI library not for - * an full blown text editor. +/*/// ### Text Editor +/// Editing text in this library is handled by either `nk_edit_string` or +/// `nk_edit_buffer`. But like almost everything in this library there are multiple +/// ways of doing it and a balance between control and ease of use with memory +/// as well as functionality controlled by flags. +/// +/// This library generally allows three different levels of memory control: +/// First of is the most basic way of just providing a simple char array with +/// string length. This method is probably the easiest way of handling simple +/// user text input. Main upside is complete control over memory while the biggest +/// downside in comparison with the other two approaches is missing undo/redo. +/// +/// For UIs that require undo/redo the second way was created. It is based on +/// a fixed size nk_text_edit struct, which has an internal undo/redo stack. +/// This is mainly useful if you want something more like a text editor but don't want +/// to have a dynamically growing buffer. +/// +/// The final way is using a dynamically growing nk_text_edit struct, which +/// has both a default version if you don't care where memory comes from and an +/// allocator version if you do. While the text editor is quite powerful for its +/// complexity I would not recommend editing gigabytes of data with it. +/// It is rather designed for uses cases which make sense for a GUI library not for +/// an full blown text editor. */ #ifndef NK_TEXTEDIT_UNDOSTATECOUNT #define NK_TEXTEDIT_UNDOSTATECOUNT 99 @@ -4376,49 +4385,52 @@ NK_API void nk_textedit_redo(struct nk_text_edit*); * DRAWING * * ===============================================================*/ -/* This library was designed to be render backend agnostic so it does - not draw anything to screen. Instead all drawn shapes, widgets - are made of, are buffered into memory and make up a command queue. - Each frame therefore fills the command buffer with draw commands - that then need to be executed by the user and his own render backend. - After that the command buffer needs to be cleared and a new frame can be - started. It is probably important to note that the command buffer is the main - drawing API and the optional vertex buffer API only takes this format and - converts it into a hardware accessible format. - - To use the command queue to draw your own widgets you can access the - command buffer of each window by calling `nk_window_get_canvas` after - previously having called `nk_begin`: - - void draw_red_rectangle_widget(struct nk_context *ctx) - { - struct nk_command_buffer *canvas; - struct nk_input *input = &ctx->input; - canvas = nk_window_get_canvas(ctx); - - struct nk_rect space; - enum nk_widget_layout_states state; - state = nk_widget(&space, ctx); - if (!state) return; - - if (state != NK_WIDGET_ROM) - update_your_widget_by_user_input(...); - nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); - } - - if (nk_begin(...)) { - nk_layout_row_dynamic(ctx, 25, 1); - draw_red_rectangle_widget(ctx); - } - nk_end(..) - - Important to know if you want to create your own widgets is the `nk_widget` - call. It allocates space on the panel reserved for this widget to be used, - but also returns the state of the widget space. If your widget is not seen and does - not have to be updated it is '0' and you can just return. If it only has - to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both - update and draw your widget. The reason for separating is to only draw and - update what is actually necessary which is crucial for performance. +/*/// ### Drawing +/// This library was designed to be render backend agnostic so it does +/// not draw anything to screen. Instead all drawn shapes, widgets +/// are made of, are buffered into memory and make up a command queue. +/// Each frame therefore fills the command buffer with draw commands +/// that then need to be executed by the user and his own render backend. +/// After that the command buffer needs to be cleared and a new frame can be +/// started. It is probably important to note that the command buffer is the main +/// drawing API and the optional vertex buffer API only takes this format and +/// converts it into a hardware accessible format. +/// +/// To use the command queue to draw your own widgets you can access the +/// command buffer of each window by calling `nk_window_get_canvas` after +/// previously having called `nk_begin`: +/// +/// ```c +/// void draw_red_rectangle_widget(struct nk_context *ctx) +/// { +/// struct nk_command_buffer *canvas; +/// struct nk_input *input = &ctx->input; +/// canvas = nk_window_get_canvas(ctx); +/// +/// struct nk_rect space; +/// enum nk_widget_layout_states state; +/// state = nk_widget(&space, ctx); +/// if (!state) return; +/// +/// if (state != NK_WIDGET_ROM) +/// update_your_widget_by_user_input(...); +/// nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); +/// } +/// +/// if (nk_begin(...)) { +/// nk_layout_row_dynamic(ctx, 25, 1); +/// draw_red_rectangle_widget(ctx); +/// } +/// nk_end(..) +/// +/// ``` +/// Important to know if you want to create your own widgets is the `nk_widget` +/// call. It allocates space on the panel reserved for this widget to be used, +/// but also returns the state of the widget space. If your widget is not seen and does +/// not have to be updated it is '0' and you can just return. If it only has +/// to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both +/// update and draw your widget. The reason for separating is to only draw and +/// update what is actually necessary which is crucial for performance. */ enum nk_command_type { NK_COMMAND_NOP, @@ -4703,18 +4715,19 @@ NK_API nk_bool nk_input_is_key_down(const struct nk_input*, enum nk_keys); * * ===============================================================*/ #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT -/* The optional vertex buffer draw list provides a 2D drawing context - with antialiasing functionality which takes basic filled or outlined shapes - or a path and outputs vertexes, elements and draw commands. - The actual draw list API is not required to be used directly while using this - library since converting the default library draw command output is done by - just calling `nk_convert` but I decided to still make this library accessible - since it can be useful. - - The draw list is based on a path buffering and polygon and polyline - rendering API which allows a lot of ways to draw 2D content to screen. - In fact it is probably more powerful than needed but allows even more crazy - things than this library provides by default. +/* ### Draw List +/// The optional vertex buffer draw list provides a 2D drawing context +/// with antialiasing functionality which takes basic filled or outlined shapes +/// or a path and outputs vertexes, elements and draw commands. +/// The actual draw list API is not required to be used directly while using this +/// library since converting the default library draw command output is done by +/// just calling `nk_convert` but I decided to still make this library accessible +/// since it can be useful. +/// +/// The draw list is based on a path buffering and polygon and polyline +/// rendering API which allows a lot of ways to draw 2D content to screen. +/// In fact it is probably more powerful than needed but allows even more crazy +/// things than this library provides by default. */ #ifdef NK_UINT_DRAW_INDEX typedef nk_uint nk_draw_index; @@ -5492,27 +5505,28 @@ struct nk_window { /*============================================================== * STACK * =============================================================*/ -/* The style modifier stack can be used to temporarily change a - * property inside `nk_style`. For example if you want a special - * red button you can temporarily push the old button color onto a stack - * draw the button with a red color and then you just pop the old color - * back from the stack: - * - * nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); - * nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); - * nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); - * nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); - * - * nk_button(...); - * - * nk_style_pop_style_item(ctx); - * nk_style_pop_style_item(ctx); - * nk_style_pop_style_item(ctx); - * nk_style_pop_vec2(ctx); - * - * Nuklear has a stack for style_items, float properties, vector properties, - * flags, colors, fonts and for button_behavior. Each has it's own fixed size stack - * which can be changed at compile time. +/*/// ### Stack +/// The style modifier stack can be used to temporarily change a +/// property inside `nk_style`. For example if you want a special +/// red button you can temporarily push the old button color onto a stack +/// draw the button with a red color and then you just pop the old color +/// back from the stack: +/// +/// nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); +/// +/// nk_button(...); +/// +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_vec2(ctx); +/// +/// Nuklear has a stack for style_items, float properties, vector properties, +/// flags, colors, fonts and for button_behavior. Each has it's own fixed size stack +/// which can be changed at compile time. */ #ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE #define NK_BUTTON_BEHAVIOR_STACK_SIZE 8 @@ -6111,32 +6125,33 @@ nk_stbtt_free(void *ptr, void *user_data) { * MATH * * ===============================================================*/ -/* Since nuklear is supposed to work on all systems providing floating point - math without any dependencies I also had to implement my own math functions - for sqrt, sin and cos. Since the actual highly accurate implementations for - the standard library functions are quite complex and I do not need high - precision for my use cases I use approximations. - - Sqrt - ---- - For square root nuklear uses the famous fast inverse square root: - https://en.wikipedia.org/wiki/Fast_inverse_square_root with - slightly tweaked magic constant. While on today's hardware it is - probably not faster it is still fast and accurate enough for - nuklear's use cases. IMPORTANT: this requires float format IEEE 754 - - Sine/Cosine - ----------- - All constants inside both function are generated Remez's minimax - approximations for value range 0...2*PI. The reason why I decided to - approximate exactly that range is that nuklear only needs sine and - cosine to generate circles which only requires that exact range. - In addition I used Remez instead of Taylor for additional precision: - www.lolengine.net/blog/2011/12/21/better-function-approximations. - - The tool I used to generate constants for both sine and cosine - (it can actually approximate a lot more functions) can be - found here: www.lolengine.net/wiki/oss/lolremez +/*/// ### Math +/// Since nuklear is supposed to work on all systems providing floating point +/// math without any dependencies I also had to implement my own math functions +/// for sqrt, sin and cos. Since the actual highly accurate implementations for +/// the standard library functions are quite complex and I do not need high +/// precision for my use cases I use approximations. +/// +/// Sqrt +/// ---- +/// For square root nuklear uses the famous fast inverse square root: +/// https://en.wikipedia.org/wiki/Fast_inverse_square_root with +/// slightly tweaked magic constant. While on today's hardware it is +/// probably not faster it is still fast and accurate enough for +/// nuklear's use cases. IMPORTANT: this requires float format IEEE 754 +/// +/// Sine/Cosine +/// ----------- +/// All constants inside both function are generated Remez's minimax +/// approximations for value range 0...2*PI. The reason why I decided to +/// approximate exactly that range is that nuklear only needs sine and +/// cosine to generate circles which only requires that exact range. +/// In addition I used Remez instead of Taylor for additional precision: +/// www.lolengine.net/blog/2011/12/21/better-function-approximations. +/// +/// The tool I used to generate constants for both sine and cosine +/// (it can actually approximate a lot more functions) can be +/// found here: www.lolengine.net/wiki/oss/lolremez */ #ifndef NK_INV_SQRT #define NK_INV_SQRT nk_inv_sqrt diff --git a/src/nuklear.h b/src/nuklear.h index 2d4af9d..36539c3 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -3576,149 +3576,155 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune * FONT * * ===============================================================*/ -/* Font handling in this library was designed to be quite customizable and lets - you decide what you want to use and what you want to provide. There are three - different ways to use the font atlas. The first two will use your font - handling scheme and only requires essential data to run nuklear. The next - slightly more advanced features is font handling with vertex buffer output. - Finally the most complex API wise is using nuklear's font baking API. - - 1.) Using your own implementation without vertex buffer output - -------------------------------------------------------------- - So first up the easiest way to do font handling is by just providing a - `nk_user_font` struct which only requires the height in pixel of the used - font and a callback to calculate the width of a string. This way of handling - fonts is best fitted for using the normal draw shape command API where you - do all the text drawing yourself and the library does not require any kind - of deeper knowledge about which font handling mechanism you use. - IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist - over the complete life time! I know this sucks but it is currently the only - way to switch between fonts. - - float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) - { - your_font_type *type = handle.ptr; - float text_width = ...; - return text_width; - } - - struct nk_user_font font; - font.userdata.ptr = &your_font_class_or_struct; - font.height = your_font_height; - font.width = your_text_width_calculation; - - struct nk_context ctx; - nk_init_default(&ctx, &font); - - 2.) Using your own implementation with vertex buffer output - -------------------------------------------------------------- - While the first approach works fine if you don't want to use the optional - vertex buffer output it is not enough if you do. To get font handling working - for these cases you have to provide two additional parameters inside the - `nk_user_font`. First a texture atlas handle used to draw text as subimages - of a bigger font atlas texture and a callback to query a character's glyph - information (offset, size, ...). So it is still possible to provide your own - font and use the vertex buffer output. - - float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) - { - your_font_type *type = handle.ptr; - float text_width = ...; - return text_width; - } - void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) - { - your_font_type *type = handle.ptr; - glyph.width = ...; - glyph.height = ...; - glyph.xadvance = ...; - glyph.uv[0].x = ...; - glyph.uv[0].y = ...; - glyph.uv[1].x = ...; - glyph.uv[1].y = ...; - glyph.offset.x = ...; - glyph.offset.y = ...; - } - - struct nk_user_font font; - font.userdata.ptr = &your_font_class_or_struct; - font.height = your_font_height; - font.width = your_text_width_calculation; - font.query = query_your_font_glyph; - font.texture.id = your_font_texture; - - struct nk_context ctx; - nk_init_default(&ctx, &font); - - 3.) Nuklear font baker - ------------------------------------ - The final approach if you do not have a font handling functionality or don't - want to use it in this library is by using the optional font baker. - The font baker APIs can be used to create a font plus font atlas texture - and can be used with or without the vertex buffer output. - - It still uses the `nk_user_font` struct and the two different approaches - previously stated still work. The font baker is not located inside - `nk_context` like all other systems since it can be understood as more of - an extension to nuklear and does not really depend on any `nk_context` state. - - Font baker need to be initialized first by one of the nk_font_atlas_init_xxx - functions. If you don't care about memory just call the default version - `nk_font_atlas_init_default` which will allocate all memory from the standard library. - If you want to control memory allocation but you don't care if the allocated - memory is temporary and therefore can be freed directly after the baking process - is over or permanent you can call `nk_font_atlas_init`. - - After successfully initializing the font baker you can add Truetype(.ttf) fonts from - different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. - functions. Adding font will permanently store each font, font config and ttf memory block(!) - inside the font atlas and allows to reuse the font atlas. If you don't want to reuse - the font baker by for example adding additional fonts you can call - `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). - - As soon as you added all fonts you wanted you can now start the baking process - for every selected glyph to image by calling `nk_font_atlas_bake`. - The baking process returns image memory, width and height which can be used to - either create your own image object or upload it to any graphics library. - No matter which case you finally have to call `nk_font_atlas_end` which - will free all temporary memory including the font atlas image so make sure - you created our texture beforehand. `nk_font_atlas_end` requires a handle - to your font texture or object and optionally fills a `struct nk_draw_null_texture` - which can be used for the optional vertex output. If you don't want it just - set the argument to `NULL`. - - At this point you are done and if you don't want to reuse the font atlas you - can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration - memory. Finally if you don't use the font atlas and any of it's fonts anymore - you need to call `nk_font_atlas_clear` to free all memory still being used. - - struct nk_font_atlas atlas; - nk_font_atlas_init_default(&atlas); - nk_font_atlas_begin(&atlas); - nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); - nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); - const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); - nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); - - struct nk_context ctx; - nk_init_default(&ctx, &font->handle); - while (1) { - - } - nk_font_atlas_clear(&atlas); - - The font baker API is probably the most complex API inside this library and - I would suggest reading some of my examples `example/` to get a grip on how - to use the font atlas. There are a number of details I left out. For example - how to merge fonts, configure a font with `nk_font_config` to use other languages, - use another texture coordinate format and a lot more: - - struct nk_font_config cfg = nk_font_config(font_pixel_height); - cfg.merge_mode = nk_false or nk_true; - cfg.range = nk_font_korean_glyph_ranges(); - cfg.coord_type = NK_COORD_PIXEL; - nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); - +/*/// ### Font +/// Font handling in this library was designed to be quite customizable and lets +/// you decide what you want to use and what you want to provide. There are three +/// different ways to use the font atlas. The first two will use your font +/// handling scheme and only requires essential data to run nuklear. The next +/// slightly more advanced features is font handling with vertex buffer output. +/// Finally the most complex API wise is using nuklear's font baking API. +// +/// #### Using your own implementation without vertex buffer output +/// +/// So first up the easiest way to do font handling is by just providing a +/// `nk_user_font` struct which only requires the height in pixel of the used +/// font and a callback to calculate the width of a string. This way of handling +/// fonts is best fitted for using the normal draw shape command API where you +/// do all the text drawing yourself and the library does not require any kind +/// of deeper knowledge about which font handling mechanism you use. +/// IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist +/// over the complete life time! I know this sucks but it is currently the only +/// way to switch between fonts. +/// +/// ```c +/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) +/// { +/// your_font_type *type = handle.ptr; +/// float text_width = ...; +/// return text_width; +/// } +/// +/// struct nk_user_font font; +/// font.userdata.ptr = &your_font_class_or_struct; +/// font.height = your_font_height; +/// font.width = your_text_width_calculation; +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font); +/// ``` +/// #### Using your own implementation with vertex buffer output +/// +/// While the first approach works fine if you don't want to use the optional +/// vertex buffer output it is not enough if you do. To get font handling working +/// for these cases you have to provide two additional parameters inside the +/// `nk_user_font`. First a texture atlas handle used to draw text as subimages +/// of a bigger font atlas texture and a callback to query a character's glyph +/// information (offset, size, ...). So it is still possible to provide your own +/// font and use the vertex buffer output. +/// +/// ```c +/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) +/// { +/// your_font_type *type = handle.ptr; +/// float text_width = ...; +/// return text_width; +/// } +/// void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) +/// { +/// your_font_type *type = handle.ptr; +/// glyph.width = ...; +/// glyph.height = ...; +/// glyph.xadvance = ...; +/// glyph.uv[0].x = ...; +/// glyph.uv[0].y = ...; +/// glyph.uv[1].x = ...; +/// glyph.uv[1].y = ...; +/// glyph.offset.x = ...; +/// glyph.offset.y = ...; +/// } +/// +/// struct nk_user_font font; +/// font.userdata.ptr = &your_font_class_or_struct; +/// font.height = your_font_height; +/// font.width = your_text_width_calculation; +/// font.query = query_your_font_glyph; +/// font.texture.id = your_font_texture; +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font); +/// ``` +/// +/// #### Nuklear font baker +/// +/// The final approach if you do not have a font handling functionality or don't +/// want to use it in this library is by using the optional font baker. +/// The font baker APIs can be used to create a font plus font atlas texture +/// and can be used with or without the vertex buffer output. +/// +/// It still uses the `nk_user_font` struct and the two different approaches +/// previously stated still work. The font baker is not located inside +/// `nk_context` like all other systems since it can be understood as more of +/// an extension to nuklear and does not really depend on any `nk_context` state. +/// +/// Font baker need to be initialized first by one of the nk_font_atlas_init_xxx +/// functions. If you don't care about memory just call the default version +/// `nk_font_atlas_init_default` which will allocate all memory from the standard library. +/// If you want to control memory allocation but you don't care if the allocated +/// memory is temporary and therefore can be freed directly after the baking process +/// is over or permanent you can call `nk_font_atlas_init`. +/// +/// After successfully initializing the font baker you can add Truetype(.ttf) fonts from +/// different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. +/// functions. Adding font will permanently store each font, font config and ttf memory block(!) +/// inside the font atlas and allows to reuse the font atlas. If you don't want to reuse +/// the font baker by for example adding additional fonts you can call +/// `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). +/// +/// As soon as you added all fonts you wanted you can now start the baking process +/// for every selected glyph to image by calling `nk_font_atlas_bake`. +/// The baking process returns image memory, width and height which can be used to +/// either create your own image object or upload it to any graphics library. +/// No matter which case you finally have to call `nk_font_atlas_end` which +/// will free all temporary memory including the font atlas image so make sure +/// you created our texture beforehand. `nk_font_atlas_end` requires a handle +/// to your font texture or object and optionally fills a `struct nk_draw_null_texture` +/// which can be used for the optional vertex output. If you don't want it just +/// set the argument to `NULL`. +/// +/// At this point you are done and if you don't want to reuse the font atlas you +/// can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration +/// memory. Finally if you don't use the font atlas and any of it's fonts anymore +/// you need to call `nk_font_atlas_clear` to free all memory still being used. +/// +/// ```c +/// struct nk_font_atlas atlas; +/// nk_font_atlas_init_default(&atlas); +/// nk_font_atlas_begin(&atlas); +/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); +/// nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); +/// const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); +/// nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font->handle); +/// while (1) { +/// +/// } +/// nk_font_atlas_clear(&atlas); +/// ``` +/// The font baker API is probably the most complex API inside this library and +/// I would suggest reading some of my examples `example/` to get a grip on how +/// to use the font atlas. There are a number of details I left out. For example +/// how to merge fonts, configure a font with `nk_font_config` to use other languages, +/// use another texture coordinate format and a lot more: +/// +/// ```c +/// struct nk_font_config cfg = nk_font_config(font_pixel_height); +/// cfg.merge_mode = nk_false or nk_true; +/// cfg.range = nk_font_korean_glyph_ranges(); +/// cfg.coord_type = NK_COORD_PIXEL; +/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); +/// ``` */ struct nk_user_font_glyph; typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len); @@ -3889,33 +3895,34 @@ NK_API void nk_font_atlas_clear(struct nk_font_atlas*); * MEMORY BUFFER * * ===============================================================*/ -/* A basic (double)-buffer with linear allocation and resetting as only - freeing policy. The buffer's main purpose is to control all memory management - inside the GUI toolkit and still leave memory control as much as possible in - the hand of the user while also making sure the library is easy to use if - not as much control is needed. - In general all memory inside this library can be provided from the user in - three different ways. - - The first way and the one providing most control is by just passing a fixed - size memory block. In this case all control lies in the hand of the user - since he can exactly control where the memory comes from and how much memory - the library should consume. Of course using the fixed size API removes the - ability to automatically resize a buffer if not enough memory is provided so - you have to take over the resizing. While being a fixed sized buffer sounds - quite limiting, it is very effective in this library since the actual memory - consumption is quite stable and has a fixed upper bound for a lot of cases. - - If you don't want to think about how much memory the library should allocate - at all time or have a very dynamic UI with unpredictable memory consumption - habits but still want control over memory allocation you can use the dynamic - allocator based API. The allocator consists of two callbacks for allocating - and freeing memory and optional userdata so you can plugin your own allocator. - - The final and easiest way can be used by defining - NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory - allocation functions malloc and free and takes over complete control over - memory in this library. +/*/// ### Memory Buffer +/// A basic (double)-buffer with linear allocation and resetting as only +/// freeing policy. The buffer's main purpose is to control all memory management +/// inside the GUI toolkit and still leave memory control as much as possible in +/// the hand of the user while also making sure the library is easy to use if +/// not as much control is needed. +/// In general all memory inside this library can be provided from the user in +/// three different ways. +/// +/// The first way and the one providing most control is by just passing a fixed +/// size memory block. In this case all control lies in the hand of the user +/// since he can exactly control where the memory comes from and how much memory +/// the library should consume. Of course using the fixed size API removes the +/// ability to automatically resize a buffer if not enough memory is provided so +/// you have to take over the resizing. While being a fixed sized buffer sounds +/// quite limiting, it is very effective in this library since the actual memory +/// consumption is quite stable and has a fixed upper bound for a lot of cases. +/// +/// If you don't want to think about how much memory the library should allocate +/// at all time or have a very dynamic UI with unpredictable memory consumption +/// habits but still want control over memory allocation you can use the dynamic +/// allocator based API. The allocator consists of two callbacks for allocating +/// and freeing memory and optional userdata so you can plugin your own allocator. +/// +/// The final and easiest way can be used by defining +/// NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory +/// allocation functions malloc and free and takes over complete control over +/// memory in this library. */ struct nk_memory_status { void *memory; @@ -4040,28 +4047,29 @@ NK_API int nk_str_len_char(struct nk_str*); * TEXT EDITOR * * ===============================================================*/ -/* Editing text in this library is handled by either `nk_edit_string` or - * `nk_edit_buffer`. But like almost everything in this library there are multiple - * ways of doing it and a balance between control and ease of use with memory - * as well as functionality controlled by flags. - * - * This library generally allows three different levels of memory control: - * First of is the most basic way of just providing a simple char array with - * string length. This method is probably the easiest way of handling simple - * user text input. Main upside is complete control over memory while the biggest - * downside in comparison with the other two approaches is missing undo/redo. - * - * For UIs that require undo/redo the second way was created. It is based on - * a fixed size nk_text_edit struct, which has an internal undo/redo stack. - * This is mainly useful if you want something more like a text editor but don't want - * to have a dynamically growing buffer. - * - * The final way is using a dynamically growing nk_text_edit struct, which - * has both a default version if you don't care where memory comes from and an - * allocator version if you do. While the text editor is quite powerful for its - * complexity I would not recommend editing gigabytes of data with it. - * It is rather designed for uses cases which make sense for a GUI library not for - * an full blown text editor. +/*/// ### Text Editor +/// Editing text in this library is handled by either `nk_edit_string` or +/// `nk_edit_buffer`. But like almost everything in this library there are multiple +/// ways of doing it and a balance between control and ease of use with memory +/// as well as functionality controlled by flags. +/// +/// This library generally allows three different levels of memory control: +/// First of is the most basic way of just providing a simple char array with +/// string length. This method is probably the easiest way of handling simple +/// user text input. Main upside is complete control over memory while the biggest +/// downside in comparison with the other two approaches is missing undo/redo. +/// +/// For UIs that require undo/redo the second way was created. It is based on +/// a fixed size nk_text_edit struct, which has an internal undo/redo stack. +/// This is mainly useful if you want something more like a text editor but don't want +/// to have a dynamically growing buffer. +/// +/// The final way is using a dynamically growing nk_text_edit struct, which +/// has both a default version if you don't care where memory comes from and an +/// allocator version if you do. While the text editor is quite powerful for its +/// complexity I would not recommend editing gigabytes of data with it. +/// It is rather designed for uses cases which make sense for a GUI library not for +/// an full blown text editor. */ #ifndef NK_TEXTEDIT_UNDOSTATECOUNT #define NK_TEXTEDIT_UNDOSTATECOUNT 99 @@ -4155,49 +4163,52 @@ NK_API void nk_textedit_redo(struct nk_text_edit*); * DRAWING * * ===============================================================*/ -/* This library was designed to be render backend agnostic so it does - not draw anything to screen. Instead all drawn shapes, widgets - are made of, are buffered into memory and make up a command queue. - Each frame therefore fills the command buffer with draw commands - that then need to be executed by the user and his own render backend. - After that the command buffer needs to be cleared and a new frame can be - started. It is probably important to note that the command buffer is the main - drawing API and the optional vertex buffer API only takes this format and - converts it into a hardware accessible format. - - To use the command queue to draw your own widgets you can access the - command buffer of each window by calling `nk_window_get_canvas` after - previously having called `nk_begin`: - - void draw_red_rectangle_widget(struct nk_context *ctx) - { - struct nk_command_buffer *canvas; - struct nk_input *input = &ctx->input; - canvas = nk_window_get_canvas(ctx); - - struct nk_rect space; - enum nk_widget_layout_states state; - state = nk_widget(&space, ctx); - if (!state) return; - - if (state != NK_WIDGET_ROM) - update_your_widget_by_user_input(...); - nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); - } - - if (nk_begin(...)) { - nk_layout_row_dynamic(ctx, 25, 1); - draw_red_rectangle_widget(ctx); - } - nk_end(..) - - Important to know if you want to create your own widgets is the `nk_widget` - call. It allocates space on the panel reserved for this widget to be used, - but also returns the state of the widget space. If your widget is not seen and does - not have to be updated it is '0' and you can just return. If it only has - to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both - update and draw your widget. The reason for separating is to only draw and - update what is actually necessary which is crucial for performance. +/*/// ### Drawing +/// This library was designed to be render backend agnostic so it does +/// not draw anything to screen. Instead all drawn shapes, widgets +/// are made of, are buffered into memory and make up a command queue. +/// Each frame therefore fills the command buffer with draw commands +/// that then need to be executed by the user and his own render backend. +/// After that the command buffer needs to be cleared and a new frame can be +/// started. It is probably important to note that the command buffer is the main +/// drawing API and the optional vertex buffer API only takes this format and +/// converts it into a hardware accessible format. +/// +/// To use the command queue to draw your own widgets you can access the +/// command buffer of each window by calling `nk_window_get_canvas` after +/// previously having called `nk_begin`: +/// +/// ```c +/// void draw_red_rectangle_widget(struct nk_context *ctx) +/// { +/// struct nk_command_buffer *canvas; +/// struct nk_input *input = &ctx->input; +/// canvas = nk_window_get_canvas(ctx); +/// +/// struct nk_rect space; +/// enum nk_widget_layout_states state; +/// state = nk_widget(&space, ctx); +/// if (!state) return; +/// +/// if (state != NK_WIDGET_ROM) +/// update_your_widget_by_user_input(...); +/// nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); +/// } +/// +/// if (nk_begin(...)) { +/// nk_layout_row_dynamic(ctx, 25, 1); +/// draw_red_rectangle_widget(ctx); +/// } +/// nk_end(..) +/// +/// ``` +/// Important to know if you want to create your own widgets is the `nk_widget` +/// call. It allocates space on the panel reserved for this widget to be used, +/// but also returns the state of the widget space. If your widget is not seen and does +/// not have to be updated it is '0' and you can just return. If it only has +/// to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both +/// update and draw your widget. The reason for separating is to only draw and +/// update what is actually necessary which is crucial for performance. */ enum nk_command_type { NK_COMMAND_NOP, @@ -4482,18 +4493,19 @@ NK_API nk_bool nk_input_is_key_down(const struct nk_input*, enum nk_keys); * * ===============================================================*/ #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT -/* The optional vertex buffer draw list provides a 2D drawing context - with antialiasing functionality which takes basic filled or outlined shapes - or a path and outputs vertexes, elements and draw commands. - The actual draw list API is not required to be used directly while using this - library since converting the default library draw command output is done by - just calling `nk_convert` but I decided to still make this library accessible - since it can be useful. - - The draw list is based on a path buffering and polygon and polyline - rendering API which allows a lot of ways to draw 2D content to screen. - In fact it is probably more powerful than needed but allows even more crazy - things than this library provides by default. +/* ### Draw List +/// The optional vertex buffer draw list provides a 2D drawing context +/// with antialiasing functionality which takes basic filled or outlined shapes +/// or a path and outputs vertexes, elements and draw commands. +/// The actual draw list API is not required to be used directly while using this +/// library since converting the default library draw command output is done by +/// just calling `nk_convert` but I decided to still make this library accessible +/// since it can be useful. +/// +/// The draw list is based on a path buffering and polygon and polyline +/// rendering API which allows a lot of ways to draw 2D content to screen. +/// In fact it is probably more powerful than needed but allows even more crazy +/// things than this library provides by default. */ #ifdef NK_UINT_DRAW_INDEX typedef nk_uint nk_draw_index; @@ -5271,27 +5283,28 @@ struct nk_window { /*============================================================== * STACK * =============================================================*/ -/* The style modifier stack can be used to temporarily change a - * property inside `nk_style`. For example if you want a special - * red button you can temporarily push the old button color onto a stack - * draw the button with a red color and then you just pop the old color - * back from the stack: - * - * nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); - * nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); - * nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); - * nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); - * - * nk_button(...); - * - * nk_style_pop_style_item(ctx); - * nk_style_pop_style_item(ctx); - * nk_style_pop_style_item(ctx); - * nk_style_pop_vec2(ctx); - * - * Nuklear has a stack for style_items, float properties, vector properties, - * flags, colors, fonts and for button_behavior. Each has it's own fixed size stack - * which can be changed at compile time. +/*/// ### Stack +/// The style modifier stack can be used to temporarily change a +/// property inside `nk_style`. For example if you want a special +/// red button you can temporarily push the old button color onto a stack +/// draw the button with a red color and then you just pop the old color +/// back from the stack: +/// +/// nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); +/// +/// nk_button(...); +/// +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_vec2(ctx); +/// +/// Nuklear has a stack for style_items, float properties, vector properties, +/// flags, colors, fonts and for button_behavior. Each has it's own fixed size stack +/// which can be changed at compile time. */ #ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE #define NK_BUTTON_BEHAVIOR_STACK_SIZE 8 diff --git a/src/nuklear_math.c b/src/nuklear_math.c index c288a0b..672fd81 100644 --- a/src/nuklear_math.c +++ b/src/nuklear_math.c @@ -6,32 +6,33 @@ * MATH * * ===============================================================*/ -/* Since nuklear is supposed to work on all systems providing floating point - math without any dependencies I also had to implement my own math functions - for sqrt, sin and cos. Since the actual highly accurate implementations for - the standard library functions are quite complex and I do not need high - precision for my use cases I use approximations. - - Sqrt - ---- - For square root nuklear uses the famous fast inverse square root: - https://en.wikipedia.org/wiki/Fast_inverse_square_root with - slightly tweaked magic constant. While on today's hardware it is - probably not faster it is still fast and accurate enough for - nuklear's use cases. IMPORTANT: this requires float format IEEE 754 - - Sine/Cosine - ----------- - All constants inside both function are generated Remez's minimax - approximations for value range 0...2*PI. The reason why I decided to - approximate exactly that range is that nuklear only needs sine and - cosine to generate circles which only requires that exact range. - In addition I used Remez instead of Taylor for additional precision: - www.lolengine.net/blog/2011/12/21/better-function-approximations. - - The tool I used to generate constants for both sine and cosine - (it can actually approximate a lot more functions) can be - found here: www.lolengine.net/wiki/oss/lolremez +/*/// ### Math +/// Since nuklear is supposed to work on all systems providing floating point +/// math without any dependencies I also had to implement my own math functions +/// for sqrt, sin and cos. Since the actual highly accurate implementations for +/// the standard library functions are quite complex and I do not need high +/// precision for my use cases I use approximations. +/// +/// Sqrt +/// ---- +/// For square root nuklear uses the famous fast inverse square root: +/// https://en.wikipedia.org/wiki/Fast_inverse_square_root with +/// slightly tweaked magic constant. While on today's hardware it is +/// probably not faster it is still fast and accurate enough for +/// nuklear's use cases. IMPORTANT: this requires float format IEEE 754 +/// +/// Sine/Cosine +/// ----------- +/// All constants inside both function are generated Remez's minimax +/// approximations for value range 0...2*PI. The reason why I decided to +/// approximate exactly that range is that nuklear only needs sine and +/// cosine to generate circles which only requires that exact range. +/// In addition I used Remez instead of Taylor for additional precision: +/// www.lolengine.net/blog/2011/12/21/better-function-approximations. +/// +/// The tool I used to generate constants for both sine and cosine +/// (it can actually approximate a lot more functions) can be +/// found here: www.lolengine.net/wiki/oss/lolremez */ #ifndef NK_INV_SQRT #define NK_INV_SQRT nk_inv_sqrt From 892a5cb7ca47bd1e337383541a91f441e26b87c4 Mon Sep 17 00:00:00 2001 From: vabenil Date: Fri, 17 Feb 2023 15:53:55 +0200 Subject: [PATCH 49/61] fix variable name in docs --- nuklear.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuklear.h b/nuklear.h index febee39..2339d57 100644 --- a/nuklear.h +++ b/nuklear.h @@ -2153,7 +2153,7 @@ NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// if (nk_begin_xxx(...) { /// // two rows with height: 30 composed of two widgets with width 60 and 40 -/// const float size[] = {60,40}; +/// const float ratio[] = {60,40}; /// nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); /// nk_widget(...); /// nk_widget(...); From f0e776031b47309f4e05815f83d2a0f9e279e4ad Mon Sep 17 00:00:00 2001 From: vabenil Date: Mon, 20 Feb 2023 18:59:43 +0200 Subject: [PATCH 50/61] Fix docs variable name in source --- src/nuklear.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nuklear.h b/src/nuklear.h index 2d4af9d..dac6ca0 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -1932,7 +1932,7 @@ NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// if (nk_begin_xxx(...) { /// // two rows with height: 30 composed of two widgets with width 60 and 40 -/// const float size[] = {60,40}; +/// const float ratio[] = {60,40}; /// nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); /// nk_widget(...); /// nk_widget(...); From c09e3b36f8c80f06386e3bad09890d6ab47fa9df Mon Sep 17 00:00:00 2001 From: Andrew Kravchuk Date: Wed, 1 Mar 2023 18:53:02 +0100 Subject: [PATCH 51/61] demo/allegro5: minor string-related tweaks --- demo/allegro5/nuklear_allegro5.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/demo/allegro5/nuklear_allegro5.h b/demo/allegro5/nuklear_allegro5.h index 8e10c9b..0e980c7 100644 --- a/demo/allegro5/nuklear_allegro5.h +++ b/demo/allegro5/nuklear_allegro5.h @@ -101,7 +101,7 @@ static float nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text, int len) { float width; - char *strcpy; + char *str; NkAllegro5Font *font = (NkAllegro5Font*)handle.ptr; NK_UNUSED(height); if (!font || !text) { @@ -111,11 +111,11 @@ nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text as nuklear uses variable size buffers and al_get_text_width doesn't accept a length, it infers length from null-termination (which is unsafe API design by allegro devs!) */ - strcpy = malloc(len + 1); - strncpy(strcpy, text, len); - strcpy[len] = '\0'; - width = al_get_text_width(font->font, strcpy); - free(strcpy); + str = calloc((size_t)len + 1, 1); + if(!str) return 0; + strncpy(str, text, len); + width = al_get_text_width(font->font, str); + free(str); return width; } @@ -473,10 +473,9 @@ nk_allegro5_clipboard_copy(nk_handle usr, const char *text, int len) char *str = 0; (void)usr; if (!len) return; - str = (char*)malloc((size_t)len+1); + str = calloc((size_t)len + 1, 1); if (!str) return; - memcpy(str, text, (size_t)len); - str[len] = '\0'; + strncpy(str, text, len); al_set_clipboard_text(allegro5.dsp, str); free(str); } From fa4ed560dded62d14547ce11eb3523babd0bdd3b Mon Sep 17 00:00:00 2001 From: Richard Gill Date: Fri, 28 Apr 2023 21:58:43 +0200 Subject: [PATCH 52/61] Delete index.html removed that one as it has no purpose (empty anyway) --- index.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index e69de29..0000000 From 77490e155cd7bba8e0b7c05fe2af07b5410c098a Mon Sep 17 00:00:00 2001 From: Richard Gill Date: Tue, 16 May 2023 09:21:51 +0200 Subject: [PATCH 53/61] fixed titlebar options in overview demo --- demo/common/overview.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index b696011..86cb9f2 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -3,30 +3,19 @@ overview(struct nk_context *ctx) { /* window flags */ static int show_menu = nk_true; - static int titlebar = nk_true; - static int border = nk_true; - static int resize = nk_true; - static int movable = nk_true; - static int no_scrollbar = nk_false; - static int scale_left = nk_false; - static nk_flags window_flags = 0; - static int minimizable = nk_true; + static nk_flags window_flags = NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE; + nk_flags actual_window_flags; /* popups */ static enum nk_style_header_align header_align = NK_HEADER_RIGHT; static int show_app_about = nk_false; - /* window flags */ - window_flags = 0; ctx->style.window.header.align = header_align; - if (border) window_flags |= NK_WINDOW_BORDER; - if (resize) window_flags |= NK_WINDOW_SCALABLE; - if (movable) window_flags |= NK_WINDOW_MOVABLE; - if (no_scrollbar) window_flags |= NK_WINDOW_NO_SCROLLBAR; - if (scale_left) window_flags |= NK_WINDOW_SCALE_LEFT; - if (minimizable) window_flags |= NK_WINDOW_MINIMIZABLE; - if (nk_begin(ctx, "Overview", nk_rect(10, 10, 400, 600), window_flags)) + actual_window_flags = window_flags; + if (!(actual_window_flags & NK_WINDOW_TITLE)) + actual_window_flags &= ~(NK_WINDOW_MINIMIZABLE|NK_WINDOW_CLOSABLE); + if (nk_begin(ctx, "Overview", nk_rect(10, 10, 400, 600), actual_window_flags)) { if (show_menu) { @@ -132,14 +121,14 @@ overview(struct nk_context *ctx) /* window flags */ if (nk_tree_push(ctx, NK_TREE_TAB, "Window", NK_MINIMIZED)) { nk_layout_row_dynamic(ctx, 30, 2); - nk_checkbox_label(ctx, "Titlebar", &titlebar); nk_checkbox_label(ctx, "Menu", &show_menu); - nk_checkbox_label(ctx, "Border", &border); - nk_checkbox_label(ctx, "Resizable", &resize); - nk_checkbox_label(ctx, "Movable", &movable); - nk_checkbox_label(ctx, "No Scrollbar", &no_scrollbar); - nk_checkbox_label(ctx, "Minimizable", &minimizable); - nk_checkbox_label(ctx, "Scale Left", &scale_left); + nk_checkbox_flags_label(ctx, "Titlebar", &window_flags, NK_WINDOW_TITLE); + nk_checkbox_flags_label(ctx, "Border", &window_flags, NK_WINDOW_BORDER); + nk_checkbox_flags_label(ctx, "Resizable", &window_flags, NK_WINDOW_SCALABLE); + nk_checkbox_flags_label(ctx, "Movable", &window_flags, NK_WINDOW_MOVABLE); + nk_checkbox_flags_label(ctx, "No Scrollbar", &window_flags, NK_WINDOW_NO_SCROLLBAR); + nk_checkbox_flags_label(ctx, "Minimizable", &window_flags, NK_WINDOW_MINIMIZABLE); + nk_checkbox_flags_label(ctx, "Scale Left", &window_flags, NK_WINDOW_SCALE_LEFT); nk_tree_pop(ctx); } From e48dd2144fdc21a5a1aca049412c14fce60634b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Mon, 26 Jun 2023 19:30:45 +0900 Subject: [PATCH 54/61] Fix Click-Drag for touch events. --- src/nuklear_input.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nuklear_input.c b/src/nuklear_input.c index e438581..49d878b 100644 --- a/src/nuklear_input.c +++ b/src/nuklear_input.c @@ -83,6 +83,10 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, nk_boo btn->clicked_pos.y = (float)y; btn->down = down; btn->clicked++; + + /* Fix Click-Drag for touch events. */ + in->mouse.delta.x = 0; + in->mouse.delta.y = 0; #ifdef NK_BUTTON_TRIGGER_ON_RELEASE if (down == 1 && id == NK_BUTTON_LEFT) { From 71bc457d39f7bea871995d9cfb32b6b69c7ca322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Mon, 26 Jun 2023 19:37:51 +0900 Subject: [PATCH 55/61] Update nuklear.h --- nuklear.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nuklear.h b/nuklear.h index b06753f..e4afef4 100644 --- a/nuklear.h +++ b/nuklear.h @@ -17898,6 +17898,10 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, nk_boo btn->clicked_pos.y = (float)y; btn->down = down; btn->clicked++; + + /* Fix Click-Drag for touch events. */ + in->mouse.delta.x = 0; + in->mouse.delta.y = 0; #ifdef NK_BUTTON_TRIGGER_ON_RELEASE if (down == 1 && id == NK_BUTTON_LEFT) { From 4848a032825cce7144b53da090c00bde61c2bba5 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 9 Jul 2023 22:17:11 -0400 Subject: [PATCH 56/61] Remove doc binary --- doc/doc | Bin 33632 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 doc/doc diff --git a/doc/doc b/doc/doc deleted file mode 100755 index 906b2cc19faa9e40ab935b2e401968269fa40f9e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 33632 zcmeI5eQZ-z6u{4GhrocXz#IcLJdCV}v=#Xjw$ZUIFcCJ#j8%+}(!Q?G^=o~vj(zBg z2IB`1j3kiw1tvsCkO&$i0kyv`%h>1~{CJ_8%i3uofGU_?+y>49*3DG~#Nlx!M z=bn4sxxd%`d2hcN=({!^KmZgA>O@pA4`4HhXaP(`U5P45^_44Xo~UW4qv%M{7mo~G z=TV)PFj0~kYdno3r}g#jkufm+Q5Yu0mUNLMP2Q-P4i35XQf0vfhzpMt}5X)YW2ID8w`Q&JHr(cy07qSN zMk@wMscjpoBsE2|Uc(LRWw?RcSdU9}xeY%v@00?=-?N8n*Q~0kuFZT$k~w{$PqLnx zL7{$3l)673AW8kvTc&-^GyPrYQ!m7(1obrfV{qKK37{Uwai}zA3+0khuQ!rw}t%ZliYzyeFR@9u@y~U`1+B1Vx?NT;q3=7CZY(H;Qo_%jlQd%=FzwyByNb}n~fU&;nO z2}*IG`X`eHpLNfC(@GCcp%k025#WOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XB zzyz286JP>NfC(^xAp!$UN4x)&gzi5cvvgmsvvv=5?YQv%H2ZG(D>KSjBdjNEl(L$YD8qZ;d0Vg2R!oXYNjrW5a{tkRjO zI5!2g7?sxEUJRa+ykx^@fFg>~+=HWGB0UF>52hO_e;>|weFiP5e0O^CTG{T#~MW~`@YQXcJ%@~&Xs zDa<=(ffkBUt@RcU_Ept>Wy;QJlye;C@vP{FwtRO#Sf-!R?Sd?OQkGq8*kxf^^NPNp zH?GQBxjmr;9E!gRn6s%DgLO>=~LBZ zR8{rGm6%qM$*PNKN;IODcW6=HT6)Y9dsy}>iLm|IrDZNN8Omlj9O7!~4+}359gYgK zj;O|cx71DMxz4Z>aXw8g4L`*=AABbml0DK{Upfnn=b&}Or!&Ok@eHs{KT!<$ zvjFo5wk;{(9G>h=8fS%VN#l66Eomg!l5_?iC8>Y%2NPfdOn?b60Vco%m;e)C0!)Aj zFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#WOn?b60Vco%m;e)C0!)Aj zFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCh)%#5V2xCY7mwF>)f~t01XuLf&ks7 z{}RuLZo4ttorxIh1iU~%C`O%wikDaj)u>clk|b60E0LIKMH3pD0XZ4~sY%v+AjJ~q zr%ELS3C8M|5m=;fP?9&wzJw-ALD}n<<1i}hRU$Cc3aK{p@fm}b6bg9L1Pbi~TS4Er z6M=lXD*;C`b)o+|&-Ul$_=|G<@*KY^$0uHNR|0XwyFm2+UZ=Yha^oUmxPD)fzOP$F zh2@82;OzJm?r1v(GJ7n-7`>HFuwWM!y`?8{-eWEr3$W?5Xwm cD(caGJlWe?d+q9$FFv`jZTDB7Tb9=T4GB_2tpET3 From 351e5d7296ed83e1b95a18138d1a3e5ee74660e0 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 9 Jul 2023 22:18:20 -0400 Subject: [PATCH 57/61] doc: Add clean up, and git ignore the binary --- .gitignore | 1 + doc/Makefile | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 65a3136..e0495a0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ example/bin/* docs/xml docs/build docs/src +doc/doc* *.tmp *.swo *.swp diff --git a/doc/Makefile b/doc/Makefile index 72a598b..967bd8f 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -13,12 +13,14 @@ LIBS = else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) - LIBS = + LIBS = else LIBS = endif endif -$(BIN): - rm -f $(BIN) $(OBJS) +$(BIN): clean $(CC) $(SRC) $(CFLAGS) -o $(BIN) + +clean: + rm -f $(BIN) $(OBJS) From 24ceaad002d2e477dad68362a8798b5afd720f73 Mon Sep 17 00:00:00 2001 From: nyaruku <38096703+nyaruku@users.noreply.github.com> Date: Wed, 6 Sep 2023 04:47:25 +0300 Subject: [PATCH 58/61] Add files via upload --- demo/gdi/nuklear_gdi.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index 8efc8da..ecab260 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -516,6 +516,7 @@ static void nk_gdi_draw_text(HDC dc, short x, short y, unsigned short w, unsigned short h, const char *text, int len, GdiFont *font, struct nk_color cbg, struct nk_color cfg) { + int wsize; WCHAR* wstr; @@ -524,8 +525,8 @@ nk_gdi_draw_text(HDC dc, short x, short y, unsigned short w, unsigned short h, wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t)); MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); - - SetBkColor(dc, convert_color(cbg)); + // Transparent Text Background + SetBkMode(dc, TRANSPARENT); SetTextColor(dc, convert_color(cfg)); SelectObject(dc, font->handle); From 1aae7b555ab400f0017fbd4da8811e9354203023 Mon Sep 17 00:00:00 2001 From: nyaruku <38096703+nyaruku@users.noreply.github.com> Date: Wed, 6 Sep 2023 05:00:45 +0300 Subject: [PATCH 59/61] Update nuklear_gdi.h --- demo/gdi/nuklear_gdi.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index ecab260..4f52cb2 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -516,7 +516,6 @@ static void nk_gdi_draw_text(HDC dc, short x, short y, unsigned short w, unsigned short h, const char *text, int len, GdiFont *font, struct nk_color cbg, struct nk_color cfg) { - int wsize; WCHAR* wstr; @@ -525,8 +524,9 @@ nk_gdi_draw_text(HDC dc, short x, short y, unsigned short w, unsigned short h, wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t)); MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); - // Transparent Text Background - SetBkMode(dc, TRANSPARENT); + + SetBkMode(dc, TRANSPARENT); // Transparent Text Background + SetBkColor(dc, convert_color(cbg)); SetTextColor(dc, convert_color(cfg)); SelectObject(dc, font->handle); From 0435477a914dc4a58e3e80dd5301314757a67749 Mon Sep 17 00:00:00 2001 From: nyaruku <38096703+nyaruku@users.noreply.github.com> Date: Fri, 8 Sep 2023 16:29:21 +0300 Subject: [PATCH 60/61] Fix Copy/Paste/Select All for Text Input --- demo/gdip/nuklear_gdip.h | 131 ++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 77 deletions(-) diff --git a/demo/gdip/nuklear_gdip.h b/demo/gdip/nuklear_gdip.h index f83964d..c0dd5dd 100644 --- a/demo/gdip/nuklear_gdip.h +++ b/demo/gdip/nuklear_gdip.h @@ -761,7 +761,7 @@ nk_gdipfont_get_text_width(nk_handle handle, float height, const char *text, int (void)height; wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); - wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t)); + wstr = (WCHAR*)_malloca(wsize * sizeof(wchar_t)); MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); GdipMeasureString(gdip.memory, wstr, wsize, font->handle, &layout, gdip.format, &bbox, NULL, NULL); @@ -777,93 +777,63 @@ nk_gdipfont_del(GdipFont *font) } static void -nk_gdip_clipboard_paste(nk_handle usr, struct nk_text_edit *edit) +nk_gdip_clipboard_paste(nk_handle usr, struct nk_text_edit* edit) { - HGLOBAL mem; - SIZE_T size; - LPCWSTR wstr; - int utf8size; - char* utf8; (void)usr; - - if (!IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) - return; - - mem = (HGLOBAL)GetClipboardData(CF_UNICODETEXT); - if (!mem) { + if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) + { + HGLOBAL mem = GetClipboardData(CF_UNICODETEXT); + if (mem) + { + SIZE_T size = GlobalSize(mem) - 1; + if (size) + { + LPCWSTR wstr = (LPCWSTR)GlobalLock(mem); + if (wstr) + { + int utf8size = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), NULL, 0, NULL, NULL); + if (utf8size) + { + char* utf8 = (char*)malloc(utf8size); + if (utf8) + { + WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), utf8, utf8size, NULL, NULL); + nk_textedit_paste(edit, utf8, utf8size); + free(utf8); + } + } + GlobalUnlock(mem); + } + } + } CloseClipboard(); - return; } - - size = GlobalSize(mem) - 1; - if (!size) { - CloseClipboard(); - return; - } - - wstr = (LPCWSTR)GlobalLock(mem); - if (!wstr) { - CloseClipboard(); - return; - } - - utf8size = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), NULL, 0, NULL, NULL); - if (!utf8size) { - GlobalUnlock(mem); - CloseClipboard(); - return; - } - - utf8 = (char*)malloc(utf8size); - if (!utf8) { - GlobalUnlock(mem); - CloseClipboard(); - return; - } - - WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), utf8, utf8size, NULL, NULL); - nk_textedit_paste(edit, utf8, utf8size); - free(utf8); - GlobalUnlock(mem); - CloseClipboard(); } static void -nk_gdip_clipboard_copy(nk_handle usr, const char *text, int len) +nk_gdip_clipboard_copy(nk_handle usr, const char* text, int len) { - HGLOBAL mem; - wchar_t* wstr; - int wsize; - (void)usr; + if (OpenClipboard(NULL)) + { + int wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); + if (wsize) + { + HGLOBAL mem = (HGLOBAL)GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t)); + if (mem) + { + wchar_t* wstr = (wchar_t*)GlobalLock(mem); + if (wstr) + { + MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); + wstr[wsize] = 0; + GlobalUnlock(mem); - if (!OpenClipboard(NULL)) - return; - - wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); - if (!wsize) { + SetClipboardData(CF_UNICODETEXT, mem); + } + } + } CloseClipboard(); - return; } - - mem = (HGLOBAL)GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t)); - if (!mem) { - CloseClipboard(); - return; - } - - wstr = (wchar_t*)GlobalLock(mem); - if (!wstr) { - GlobalFree(mem); - CloseClipboard(); - return; - } - - MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); - wstr[wsize] = 0; - GlobalUnlock(mem); - if (!SetClipboardData(CF_UNICODETEXT, mem)) - GlobalFree(mem); - CloseClipboard(); } NK_API struct nk_context* @@ -997,6 +967,13 @@ nk_gdip_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) nk_input_key(&gdip.ctx, NK_KEY_SCROLL_UP, down); return 1; + case 'A': + if (ctrl) { + nk_input_key(&gdip.ctx, NK_KEY_TEXT_SELECT_ALL, down); + return 1; + } + break; + case 'C': if (ctrl) { nk_input_key(&gdip.ctx, NK_KEY_COPY, down); From 036f8226bbbb5a4550ac1ba39b8e05e875b92b8c Mon Sep 17 00:00:00 2001 From: nyaruku <38096703+nyaruku@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:47:27 +0300 Subject: [PATCH 61/61] Fixed Transparent Text Background for GDI Co-authored-by: Rob Loach --- demo/gdi/nuklear_gdi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index 4f52cb2..6bbedb6 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -525,7 +525,7 @@ nk_gdi_draw_text(HDC dc, short x, short y, unsigned short w, unsigned short h, wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t)); MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize); - SetBkMode(dc, TRANSPARENT); // Transparent Text Background + SetBkMode(dc, TRANSPARENT); /* Transparent Text Background */ SetBkColor(dc, convert_color(cbg)); SetTextColor(dc, convert_color(cfg));