picture works

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@83 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-30 21:58:05 +00:00
parent 8ea2d4a50a
commit 13164f0ed5
11 changed files with 71 additions and 13 deletions

View File

@@ -43,7 +43,7 @@ SO = .so
EXEC = EXEC =
else ifeq ($(WINDOWS),1) else ifeq ($(WINDOWS),1)
L_CFLAGS += -DUSE_GDI 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_OBJS += src/gdi.o
L_LIBS += -lgdi32 -lopengl32 L_LIBS += -lgdi32 -lopengl32

View File

@@ -6,11 +6,13 @@ int main() {
MwNtitle, "image button", MwNtitle, "image button",
NULL); NULL);
MwWidget button = MwCreateWidget(MwButtonClass, "button", window, 50, 50, 400, 400); 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, MwVaApply(button,
MwNpixmap, px, MwNpixmap, px,
NULL); NULL);
MwWindowSetIcon(window, px);
MwLoop(window); MwLoop(window);
} }

View File

@@ -75,7 +75,7 @@ int main() {
window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 450, window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 450,
MwNtitle, "hello world", MwNtitle, "hello world",
NULL); 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, button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 350, 300, 50,
MwNtext, "Reverse", MwNtext, "Reverse",
NULL); NULL);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -71,6 +71,7 @@ MWDECL void MwLLSleep(int ms);
MWDECL MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int height); MWDECL MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int height);
MWDECL void MwLLDestroyPixmap(MwLLPixmap pixmap); MWDECL void MwLLDestroyPixmap(MwLLPixmap pixmap);
MWDECL void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap); MWDECL void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap);
MWDECL void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -18,6 +18,13 @@ extern "C" {
*/ */
MWDECL MwClass MwWindowClass; MWDECL MwClass MwWindowClass;
/*!
* %brief Sets a window icon
* %param handle Widget
* %param pixmap Pixmap
*/
MWDECL void MwWindowSetIcon(MwWidget handle, MwLLPixmap pixmap);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -1,7 +1,7 @@
/* $Id$ */ /* $Id$ */
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
#include <stb_image.h> #include "stb_image.h"
static int hex(const char* txt, int len) { static int hex(const char* txt, int len) {
int i; int i;
@@ -150,7 +150,7 @@ void MwDrawText(MwWidget handle, MwPoint* point, const char* text, MwLLColor col
MwLLPixmap MwLoadImage(MwWidget handle, const char* path) { MwLLPixmap MwLoadImage(MwWidget handle, const char* path) {
int width, height, ch; 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; MwLLPixmap px;
if(rgb == NULL) return NULL; if(rgb == NULL) return NULL;

View File

@@ -76,7 +76,7 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetSysColorBrush(COLOR_MENU); wc.hbrBackground = GetSysColorBrush(COLOR_MENU);
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO); wc.hIconSm = NULL;
MwLLCreateCommon(r); MwLLCreateCommon(r);
@@ -94,8 +94,6 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
if(parent == NULL) { if(parent == NULL) {
RECT rc; RECT rc;
ShowWindow(r->hWnd, SW_NORMAL);
UpdateWindow(r->hWnd);
rc.left = 0; rc.left = 0;
rc.top = 0; rc.top = 0;
@@ -103,6 +101,11 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
rc.bottom = height; rc.bottom = height;
AdjustWindowRect(&rc, GetWindowLongPtr(r->hWnd, GWL_STYLE), FALSE); 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); 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; return r;
@@ -239,7 +242,7 @@ MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int hei
for(y = 0; y < height; y++) { for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) { for(x = 0; x < width; x++) {
RGBQUAD* q = &quad[y * 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->rgbRed = px[0];
q->rgbGreen = px[1]; q->rgbGreen = px[1];
q->rgbBlue = px[2]; q->rgbBlue = px[2];
@@ -267,3 +270,26 @@ void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
DeleteDC(hmdc); 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);
}

View File

@@ -2,9 +2,8 @@
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> /* nothing */
#else #else
#include <X11/X.h>
#include <GL/glx.h> #include <GL/glx.h>
#endif #endif
#include <GL/gl.h> #include <GL/gl.h>

View File

@@ -26,3 +26,7 @@ MwClassRec MwWindowClassRec = {
NULL /* click */ NULL /* click */
}; };
MwClass MwWindowClass = &MwWindowClassRec; MwClass MwWindowClass = &MwWindowClassRec;
void MwWindowSetIcon(MwWidget handle, MwLLPixmap pixmap) {
MwLLSetIcon(handle->lowlevel, pixmap);
}

View File

@@ -178,7 +178,7 @@ void MwLLSleep(int ms) {
} }
void MwLLSetTitle(MwLL handle, const char* title) { 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) { 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(y = 0; y < height; y++) {
for(x = 0; x < width; x++) { 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; unsigned long p = 0;
p <<= 8; p <<= 8;
p |= px[3];
p <<= 8;
p |= px[0]; p |= px[0];
p <<= 8; p <<= 8;
p |= px[1]; p |= px[1];
@@ -284,3 +286,20 @@ void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
XFreePixmap(handle->display, px); 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);
}