aboutsummaryrefslogtreecommitdiff
path: root/nuklear/demo/gdi
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-10-20 10:08:35 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-10-20 10:08:35 +0200
commit279458e16cc6cb61035c029673a0e0d014de2938 (patch)
tree14124504c90506f904b5cb2411054d6f7529f022 /nuklear/demo/gdi
parent79a1bcff04006c1c93f90eb77aab6f52a9b76d9f (diff)
parent96ba797de25497f2b8e6193eecc59955877f54cf (diff)
downloadsherlock.lv2-279458e16cc6cb61035c029673a0e0d014de2938.tar.xz
Merge commit '96ba797de25497f2b8e6193eecc59955877f54cf'
Diffstat (limited to 'nuklear/demo/gdi')
-rw-r--r--nuklear/demo/gdi/main.c4
-rw-r--r--nuklear/demo/gdi/nuklear_gdi.h86
2 files changed, 85 insertions, 5 deletions
diff --git a/nuklear/demo/gdi/main.c b/nuklear/demo/gdi/main.c
index e82cd16..c91ebb4 100644
--- a/nuklear/demo/gdi/main.c
+++ b/nuklear/demo/gdi/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.17 - public domain */
+/* nuklear - 1.32.0 - public domain */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
@@ -74,6 +74,7 @@ int main(void)
/* Win32 */
memset(&wc, 0, sizeof(wc));
+ wc.style = CS_DBLCLKS;
wc.lpfnWndProc = WindowProc;
wc.hInstance = GetModuleHandleW(0);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
@@ -141,7 +142,6 @@ int main(void)
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
}
nk_end(ctx);
- if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
diff --git a/nuklear/demo/gdi/nuklear_gdi.h b/nuklear/demo/gdi/nuklear_gdi.h
index 6d3a84a..932a70a 100644
--- a/nuklear/demo/gdi/nuklear_gdi.h
+++ b/nuklear/demo/gdi/nuklear_gdi.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.17 - public domain
+ * Nuklear - 1.32.0 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -57,6 +57,78 @@ static struct {
struct nk_context ctx;
} gdi;
+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))
+ {
+ image->w = width;
+ image->h = height;
+ image->region[0] = 0;
+ image->region[1] = 0;
+ image->region[2] = width;
+ image->region[3] = height;
+
+ INT row = ((width * 3 + 3) & ~3);
+ BITMAPINFO bi = { 0 };
+ 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;
+
+ LPBYTE lpBuf, pb = NULL;
+ HBITMAP hbm = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**)&lpBuf, NULL, 0);
+
+ pb = lpBuf + row * height;
+ unsigned char * src = (unsigned char *)frame_buffer;
+ for (int v = 0; v<height; v++)
+ {
+ pb -= row;
+ for (int 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 = image->handle.ptr;
+ DeleteObject(hbm);
+ memset(image, 0, sizeof(struct nk_image));
+ }
+}
+
+static void
+nk_gdi_draw_image(short x, short y, unsigned short w, unsigned short h,
+ struct nk_image img, struct nk_color col)
+{
+ HBITMAP hbm = 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)
{
@@ -627,6 +699,7 @@ nk_gdi_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
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;
@@ -652,12 +725,16 @@ nk_gdi_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;
case WM_MOUSEWHEEL:
- nk_input_scroll(&gdi.ctx, (float)(short)HIWORD(wparam) / WHEEL_DELTA);
+ 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;
@@ -747,7 +824,10 @@ nk_gdi_render(struct nk_color clear)
q->end, q->line_thickness, q->color);
} break;
case NK_COMMAND_RECT_MULTI_COLOR:
- case NK_COMMAND_IMAGE:
+ case NK_COMMAND_IMAGE: {
+ 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:
default: break;