diff --git a/demo/gdip/build.bat b/demo/gdip/build.bat index 28f51a3..81eef6e 100644 --- a/demo/gdip/build.bat +++ b/demo/gdip/build.bat @@ -2,4 +2,4 @@ call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 -cl /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib gdiplus.lib /link /incremental:no +cl /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib gdiplus.lib ole32.lib /link /incremental:no diff --git a/demo/gdip/nuklear_gdip.h b/demo/gdip/nuklear_gdip.h index edefaa4..fcb6358 100644 --- a/demo/gdip/nuklear_gdip.h +++ b/demo/gdip/nuklear_gdip.h @@ -1,7 +1,7 @@ /* - * Nuklear - v1.17 - public domain + * Nuklear - v1.20 - public domain * no warrenty implied; use at your own risk. - * authored from 2015-2016 by Micha Mettke + * authored from 2015-2017 by Micha Mettke */ /* * ============================================================== @@ -27,6 +27,10 @@ NK_API int nk_gdip_handle_event(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara NK_API void nk_gdip_render(enum nk_anti_aliasing AA, struct nk_color clear); NK_API void nk_gdip_shutdown(void); +/* image */ +NK_API struct nk_image nk_gdip_load_image_from_file(const WCHAR* filename); +NK_API struct nk_image nk_gdip_load_image_from_memory(const void* membuf, int membufSize); + #endif /* * ============================================================== @@ -191,6 +195,18 @@ GdipDisposeImage(GpImage *image); GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image, GpGraphics **graphics); +GpStatus WINGDIPAPI +GdipGetImageWidth(GpImage *image, UINT *width); + +GpStatus WINGDIPAPI +GdipGetImageHeight(GpImage *image, UINT *height); + +GpStatus WINGDIPAPI +GdipLoadImageFromFile(GDIPCONST WCHAR* filename, GpImage **image); + +GpStatus WINGDIPAPI +GdipLoadImageFromStream(IStream* stream, GpImage **image); + /* pen */ GpStatus WINGDIPAPI @@ -283,7 +299,7 @@ GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x, INT y, GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x, INT y, - INT width, INT height); + INT width, INT height); GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush, INT x, INT y, @@ -326,6 +342,10 @@ GdipGraphicsClear(GpGraphics *graphics, ARGB color); GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x, INT y); +GpStatus WINGDIPAPI +GdipDrawImageRectI(GpGraphics *graphics, GpImage *image, INT x, INT y, + INT width, INT height); + GpStatus WINGDIPAPI GdipMeasureString( GpGraphics *graphics, @@ -538,6 +558,14 @@ nk_gdip_draw_text(short x, short y, unsigned short w, unsigned short h, GdipDrawString(gdip.memory, wstr, wsize, font->handle, &layout, gdip.format, gdip.brush); } +static void +nk_gdip_draw_image(short x, short y, unsigned short w, unsigned short h, + struct nk_image img, struct nk_color col) +{ + GpImage *image = img.handle.ptr; + GdipDrawImageRectI(gdip.memory, image, x, y, w, h); +} + static void nk_gdip_clear(struct nk_color col) { @@ -550,6 +578,43 @@ nk_gdip_blit(GpGraphics *graphics) GdipDrawImageI(graphics, gdip.bitmap, 0, 0); } +struct nk_image +nk_gdip_image_to_nk(GpImage *image){ + struct nk_image img; + UINT uwidth, uheight; + img = nk_image_ptr( (void*)image ); + GdipGetImageHeight(image, &uheight); + GdipGetImageWidth(image, &uwidth); + img.h = uheight; + img.w = uwidth; + return img; +} + +struct nk_image +nk_gdip_load_image_from_file(GDIPCONST WCHAR *filename) +{ + GpImage *image; + GdipLoadImageFromFile(filename, &image); + return nk_gdip_image_to_nk(image); +} + +struct nk_image +nk_gdip_load_image_from_memory(const void *membuf, int membufSize) +{ + GpImage *image = NULL; + IStream *pStream = NULL; + HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, membufSize); + LPVOID pImage = GlobalLock(hMem); + nk_memcopy(pImage, membuf, membufSize); + GlobalUnlock(hMem); + + /* CreateStreamOnHGlobal needs OLE32 in linked libraries list */ + CreateStreamOnHGlobal(hMem, FALSE, &pStream); + GdipLoadImageFromStream(pStream, &image); + GlobalFree(hMem); + return nk_gdip_image_to_nk(image); +} + GdipFont* nk_gdipfont_create(const char *name, int size) { @@ -991,8 +1056,11 @@ nk_gdip_render(enum nk_anti_aliasing AA, struct nk_color clear) nk_gdip_stroke_curve(q->begin, q->ctrl[0], q->ctrl[1], q->end, q->line_thickness, q->color); } break; + case NK_COMMAND_IMAGE: { + const struct nk_command_image *i = (const struct nk_command_image *)cmd; + nk_gdip_draw_image(i->x, i->y, i->w, i->h, i->img, i->col); + } break; case NK_COMMAND_RECT_MULTI_COLOR: - case NK_COMMAND_IMAGE: case NK_COMMAND_ARC: case NK_COMMAND_ARC_FILLED: default: break; @@ -1003,4 +1071,3 @@ nk_gdip_render(enum nk_anti_aliasing AA, struct nk_color clear) } #endif -