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 1/4] 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 8efc8daf3..ecab26020 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 2/4] 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 ecab26020..4f52cb2a0 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 3/4] Fix Copy/Paste/Select All for Text Input --- demo/gdip/nuklear_gdip.h | 133 ++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 78 deletions(-) diff --git a/demo/gdip/nuklear_gdip.h b/demo/gdip/nuklear_gdip.h index f83964d0a..c0dd5dd41 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) { - 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); + 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; } - - 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)) - return; - - wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0); - if (!wsize) { - 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); + 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(); - 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 4/4] 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 4f52cb2a0..6bbedb632 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));