From 13164f0ed58ae4d7cd128d1a5f69e29c75645366 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 30 Sep 2025 21:58:05 +0000 Subject: [PATCH] picture works git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@83 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 2 +- examples/image.c | 4 +++- examples/opengl.c | 2 +- examples/picture.png | Bin 27213 -> 27213 bytes include/Mw/LowLevel.h | 1 + include/Mw/Window.h | 7 +++++++ src/draw.c | 4 ++-- src/gdi.c | 34 ++++++++++++++++++++++++++++++---- src/opengl.c | 3 +-- src/window.c | 4 ++++ src/x11.c | 23 +++++++++++++++++++++-- 11 files changed, 71 insertions(+), 13 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 9893a5c..416c857 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -43,7 +43,7 @@ SO = .so EXEC = else ifeq ($(WINDOWS),1) L_CFLAGS += -DUSE_GDI -L_LDFLAGS += -Wl,--out-implib,src/libMw.lib +L_LDFLAGS += -Wl,--out-implib,src/libMw.lib -static-libgcc L_OBJS += src/gdi.o L_LIBS += -lgdi32 -lopengl32 diff --git a/examples/image.c b/examples/image.c index 8f36279..8511966 100644 --- a/examples/image.c +++ b/examples/image.c @@ -6,11 +6,13 @@ int main() { MwNtitle, "image button", NULL); MwWidget button = MwCreateWidget(MwButtonClass, "button", window, 50, 50, 400, 400); - MwLLPixmap px = MwLoadImage(button, "examples/picture.png"); + MwLLPixmap px = MwLoadImage(window, "examples/picture.png"); MwVaApply(button, MwNpixmap, px, NULL); + MwWindowSetIcon(window, px); + MwLoop(window); } diff --git a/examples/opengl.c b/examples/opengl.c index fa7a283..b080a9c 100644 --- a/examples/opengl.c +++ b/examples/opengl.c @@ -75,7 +75,7 @@ int main() { window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 450, MwNtitle, "hello world", NULL); - opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, (ow = 300), (oh = 250)); + opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, (ow = 300), (oh = 300)); button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 350, 300, 50, MwNtext, "Reverse", NULL); diff --git a/examples/picture.png b/examples/picture.png index bd35fa4252b3547c0f53c8a5fd1b14d95e6460e3..01b9e4547928f95d63fecf5f24ffaeb314f4531d 100644 GIT binary patch delta 40 ucmX?mh4Jha#tr&eaz=($rsh^A#@Yr3Rt5&&LJMjbfWXt$&t;ucLK6TPy$qxP delta 40 ucmX?mh4Jha#tr&ea)#zsCT3P9M%o4jRt5%(UYQy&0D-5gpUXO@geCwMW(;5e diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index dcd3c8f..c11ba1e 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -71,6 +71,7 @@ MWDECL void MwLLSleep(int ms); MWDECL MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int height); MWDECL void MwLLDestroyPixmap(MwLLPixmap pixmap); MWDECL void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap); +MWDECL void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap); #ifdef __cplusplus } diff --git a/include/Mw/Window.h b/include/Mw/Window.h index 6e11144..e3db384 100644 --- a/include/Mw/Window.h +++ b/include/Mw/Window.h @@ -18,6 +18,13 @@ extern "C" { */ MWDECL MwClass MwWindowClass; +/*! + * %brief Sets a window icon + * %param handle Widget + * %param pixmap Pixmap + */ +MWDECL void MwWindowSetIcon(MwWidget handle, MwLLPixmap pixmap); + #ifdef __cplusplus } #endif diff --git a/src/draw.c b/src/draw.c index dd06505..1e216c6 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1,7 +1,7 @@ /* $Id$ */ #include -#include +#include "stb_image.h" static int hex(const char* txt, int len) { int i; @@ -150,7 +150,7 @@ void MwDrawText(MwWidget handle, MwPoint* point, const char* text, MwLLColor col MwLLPixmap MwLoadImage(MwWidget handle, const char* path) { int width, height, ch; - unsigned char* rgb = stbi_load(path, &width, &height, &ch, 3); + unsigned char* rgb = stbi_load(path, &width, &height, &ch, 4); MwLLPixmap px; if(rgb == NULL) return NULL; diff --git a/src/gdi.c b/src/gdi.c index 1813f28..c422f9a 100644 --- a/src/gdi.c +++ b/src/gdi.c @@ -76,7 +76,7 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) { wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = GetSysColorBrush(COLOR_MENU); wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); - wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO); + wc.hIconSm = NULL; MwLLCreateCommon(r); @@ -94,8 +94,6 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) { if(parent == NULL) { RECT rc; - ShowWindow(r->hWnd, SW_NORMAL); - UpdateWindow(r->hWnd); rc.left = 0; rc.top = 0; @@ -103,6 +101,11 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) { rc.bottom = height; AdjustWindowRect(&rc, GetWindowLongPtr(r->hWnd, GWL_STYLE), FALSE); SetWindowPos(r->hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE); + + ShowWindow(r->hWnd, SW_NORMAL); + UpdateWindow(r->hWnd); + + InvalidateRect(r->hWnd, NULL, FALSE); } return r; @@ -239,7 +242,7 @@ MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int hei for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { RGBQUAD* q = &quad[y * width + x]; - unsigned char* px = &data[(y * width + x) * 3]; + unsigned char* px = &data[(y * width + x) * 4]; q->rgbRed = px[0]; q->rgbGreen = px[1]; q->rgbBlue = px[2]; @@ -267,3 +270,26 @@ void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { DeleteDC(hmdc); } + +void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap) { + ICONINFO ii; + HICON ico; + HBITMAP mask; + + mask = CreateBitmap(pixmap->width, pixmap->height, 1, 1, NULL); + + memset(&ii, 0, sizeof(ii)); + ii.fIcon = TRUE; + ii.xHotspot = 0; + ii.yHotspot = 0; + ii.hbmMask = mask; + ii.hbmColor = pixmap->hBitmap; + + ico = CreateIconIndirect(&ii); + + DeleteObject(mask); + + SetClassLongPtr(handle->hWnd, GCLP_HICON, (LPARAM)ico); + + DestroyIcon(ico); +} diff --git a/src/opengl.c b/src/opengl.c index 98b4588..0cbfa2a 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -2,9 +2,8 @@ #include #ifdef _WIN32 -#include +/* nothing */ #else -#include #include #endif #include diff --git a/src/window.c b/src/window.c index fd63827..a26ec67 100644 --- a/src/window.c +++ b/src/window.c @@ -26,3 +26,7 @@ MwClassRec MwWindowClassRec = { NULL /* click */ }; MwClass MwWindowClass = &MwWindowClassRec; + +void MwWindowSetIcon(MwWidget handle, MwLLPixmap pixmap) { + MwLLSetIcon(handle->lowlevel, pixmap); +} diff --git a/src/x11.c b/src/x11.c index f699856..227cc4a 100644 --- a/src/x11.c +++ b/src/x11.c @@ -178,7 +178,7 @@ void MwLLSleep(int ms) { } void MwLLSetTitle(MwLL handle, const char* title) { - XSetStandardProperties(handle->display, handle->window, title, "Mw Widget Toolkit", None, (char**)NULL, 0, NULL); + XSetStandardProperties(handle->display, handle->window, title, title, None, (char**)NULL, 0, NULL); } MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int height) { @@ -212,9 +212,11 @@ MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int hei for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { - unsigned char* px = &data[(y * width + x) * 3]; + unsigned char* px = &data[(y * width + x) * 4]; unsigned long p = 0; p <<= 8; + p |= px[3]; + p <<= 8; p |= px[0]; p <<= 8; p |= px[1]; @@ -284,3 +286,20 @@ void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { XFreePixmap(handle->display, px); } } + +void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap) { + unsigned long* icon = malloc((2 + pixmap->width * pixmap->height) * sizeof(*icon)); + int i; + Atom atom = XInternAtom(lowlevel->display, "_NET_WM_ICON", False); + + icon[0] = pixmap->width; + icon[1] = pixmap->height; + + for(i = 0; i < pixmap->width * pixmap->height; i++) { + icon[2 + i] = *(unsigned long*)(&pixmap->image->data[i * 4]); + } + + XChangeProperty(lowlevel->display, lowlevel->window, atom, 6, 32, PropModeReplace, (unsigned char*)icon, 2 + pixmap->width * pixmap->height); + + free(icon); +}