git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@69 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-30 00:52:43 +00:00
parent 99c28db60d
commit e230b5441c
9 changed files with 172 additions and 12 deletions

View File

@@ -1,8 +1,25 @@
/* $Id$ */
#include <Mw/Milsko.h>
MwLLPixmap pixmap;
static void create(MwWidget handle) {
MwSetDefault(handle);
int y, x;
unsigned char* dat = malloc(640 * 480 * 3);
for(y = 0; y < 480; y++) {
for(x = 0; x < 640; x++) {
unsigned char* px = &dat[(y * 640 + x) * 3];
double c = (double)x / 640 * 255 / 2 + (double)y / 480 * 255 / 2;
px[0] = c;
px[1] = 0;
px[2] = 0;
}
}
pixmap = MwLLCreatePixmap(handle->lowlevel, dat, 640, 480);
free(dat);
}
static void draw(MwWidget handle) {
@@ -16,7 +33,8 @@ static void draw(MwWidget handle) {
MwDrawFrameEx(handle, &r, base, 1, 1);
MwDrawFrameEx(handle, &r, base, 0, 1);
MwDrawRect(handle, &r, base);
MwLLDrawPixmap(handle->lowlevel, &r, pixmap);
// MwDrawRect(handle, &r, base);
MwLLFreeColor(base);
}

View File

@@ -45,6 +45,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else if(msg == WM_SIZE) {
MwLLDispatch(u->ll, resize);
} else if(msg == WM_ERASEBKGND) {
return 1;
} else if(msg == WM_NCHITTEST) {
return HTCLIENT;
} else if(msg == WM_DESTROY) {
@@ -210,3 +211,59 @@ void MwLLNextEvent(MwLL handle) {
void MwLLSleep(int ms) {
Sleep(ms);
}
MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
HDC dc = GetDC(handle->hWnd);
BITMAPINFOHEADER bmih;
RGBQUAD* quad = NULL;
int y, x;
r->width = width;
r->height = height;
bmih.biSize = sizeof(bmih);
bmih.biWidth = width;
bmih.biHeight = -(LONG)height;
bmih.biPlanes = 1;
bmih.biBitCount = 32;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = 0;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
r->hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&quad, NULL, (DWORD)0);
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];
q->rgbRed = px[0];
q->rgbGreen = px[1];
q->rgbBlue = px[2];
}
}
ReleaseDC(handle->hWnd, dc);
return r;
}
void MwLLDestroyPixmap(MwLLPixmap pixmap) {
DeleteObject(pixmap->hBitmap);
free(pixmap);
}
void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
HDC hmdc = CreateCompatibleDC(handle->hDC);
SelectObject(hmdc, pixmap->hBitmap);
SetStretchBltMode(handle->hDC, HALFTONE);
StretchBlt(handle->hDC, rect->x, rect->y, rect->width, rect->height, hmdc, 0, 0, pixmap->width, pixmap->height, SRCCOPY);
DeleteDC(hmdc);
}

View File

@@ -25,6 +25,8 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
r->gc = XCreateGC(r->display, r->window, 0, 0);
XSetGraphicsExposures(r->display, r->gc, False);
XSelectInput(r->display, r->window, mask);
XMapWindow(r->display, r->window);
@@ -137,3 +139,65 @@ 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);
}
MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
char* d = malloc(4 * width * height);
int y, x;
r->width = width;
r->height = height;
r->display = handle->display;
r->use_shm = XShmQueryExtension(handle->display) ? 1 : 0;
if(r->use_shm) {
r->image = XShmCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 24, ZPixmap, NULL, &r->shm, width, height);
free(d);
r->shm.shmid = shmget(IPC_PRIVATE, r->image->bytes_per_line * height, IPC_CREAT | 0777);
r->shm.shmaddr = d = r->image->data = shmat(r->shm.shmid, 0, 0);
r->shm.readOnly = False;
XShmAttach(handle->display, &r->shm);
} else {
r->image = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 24, ZPixmap, 0, d, width, height, 32, width * 4);
}
for(y = 0; y < height; y++) {
for(x = 0; x < height; x++) {
unsigned char* px = &data[(y * width + x) * 3];
unsigned long p = 0;
p <<= 8;
p |= px[0];
p <<= 8;
p |= px[1];
p <<= 8;
p |= px[2];
XPutPixel(r->image, x, y, p);
}
}
return r;
}
void MwLLDestroyPixmap(MwLLPixmap pixmap) {
if(pixmap->use_shm) {
XShmDetach(pixmap->display, &pixmap->shm);
}
XDestroyImage(pixmap->image);
if(pixmap->use_shm) {
shmdt(pixmap->shm.shmaddr);
shmctl(pixmap->shm.shmid, IPC_RMID, 0);
}
free(pixmap);
}
void MwLLDrawPixmap(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
if(pixmap->image != NULL) {
if(pixmap->use_shm) {
XShmPutImage(handle->display, handle->window, handle->gc, pixmap->image, 0, 0, rect->x, rect->y, rect->width, rect->height, False);
} else {
XPutImage(handle->display, handle->window, handle->gc, pixmap->image, 0, 0, rect->x, rect->y, rect->width, rect->height);
}
}
}