Merge branch 'master' of ssh://forgejo.nishi.boats:2222/pyrite-dev/milsko

This commit is contained in:
IoI_xD 2026-04-23 10:45:39 -07:00
commit efc6002bdb
10 changed files with 202 additions and 201 deletions

View file

@ -147,6 +147,7 @@ static void MWAPI menu_handler(MwWidget handle, void* user, void* call) {
int main() { int main() {
int i, j; int i, j;
MwWidget f, w, b; MwWidget f, w, b;
MwLLPixmap px;
int index; int index;
MwMenu m, m2; MwMenu m, m2;
void* v; void* v;
@ -157,6 +158,8 @@ int main() {
MwNtitle, "Milsko Periodic Table", MwNtitle, "Milsko Periodic Table",
NULL); NULL);
px = MwLoadIcon(window, MwIconError);
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0); menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
m = MwMenuAdd(menu, NULL, "File"); m = MwMenuAdd(menu, NULL, "File");
@ -256,6 +259,12 @@ int main() {
f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL); f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL);
add(f); add(f);
f = frame("Image", -PaddingContent, -PaddingContent, MwImageClass,
MwNpixmap, px,
NULL);
w = child(f);
add(f);
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass, f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
MwNtext, "Epic text", MwNtext, "Epic text",
NULL); NULL);
@ -292,6 +301,14 @@ int main() {
v = MwTreeViewAdd(w, v, NULL, "ghi"); v = MwTreeViewAdd(w, v, NULL, "ghi");
add(f); add(f);
f = frame("Viewport", -PaddingContent, -PaddingContent, MwViewportClass, NULL);
w = child(f);
MwViewportSetSize(w, 256, 256);
MwVaCreateWidget(MwButtonClass, "btn", MwViewportGetViewport(w), 64, 64, 128, 128,
MwNtext, "Thing",
NULL);
add(f);
if(n != 0) newrow(); if(n != 0) newrow();
if(n == 0) MwDestroyWidget(boxes[row]); if(n == 0) MwDestroyWidget(boxes[row]);
@ -300,4 +317,6 @@ int main() {
resize(window, NULL, NULL); resize(window, NULL, NULL);
MwLoop(window); MwLoop(window);
MwLLDestroyPixmap(px);
} }

View file

@ -31,9 +31,9 @@ int main() {
if(px == NULL) px = MwLoadImage(vp, "picture.png"); if(px == NULL) px = MwLoadImage(vp, "picture.png");
// MwVaCreateWidget(MwImageClass, "image", MwViewportGetViewport(vp), 0, 0, 1024, 1024, // MwVaCreateWidget(MwImageClass, "image", MwViewportGetViewport(vp), 0, 0, 1024, 1024,
// MwNpixmap, px, // MwNpixmap, px,
// NULL); // NULL);
MwViewportSetSize(vp, 1024, 1024); MwViewportSetSize(vp, 1024, 1024);
MwWidget f = MwCreateWidget(MwFrameClass, "fr", MwViewportGetViewport(vp), 256, 256, 128, 128); MwWidget f = MwCreateWidget(MwFrameClass, "fr", MwViewportGetViewport(vp), 256, 256, 128, 128);
f = MwCreateWidget(MwFrameClass, "fr", f, 0, 0, 128, 128); f = MwCreateWidget(MwFrameClass, "fr", f, 0, 0, 128, 128);

View file

@ -4,7 +4,7 @@
#define CP_UTF8 65001 #define CP_UTF8 65001
#endif #endif
char* MwACPToUTF8(const char* input){ char* MwACPToUTF8(const char* input) {
#if defined(_WIN32) && defined(MW_HAS_WCHAR) #if defined(_WIN32) && defined(MW_HAS_WCHAR)
int mbbytes = (strlen(input) + 1) * 4; int mbbytes = (strlen(input) + 1) * 4;
int wbytes = 0; int wbytes = 0;
@ -14,7 +14,7 @@ char* MwACPToUTF8(const char* input){
char* mbout = malloc(mbbytes); char* mbout = malloc(mbbytes);
wbytes = MultiByteToWideChar(CP_ACP, 0, input, strlen(input), NULL, 0) * sizeof(wchar_t); wbytes = MultiByteToWideChar(CP_ACP, 0, input, strlen(input), NULL, 0) * sizeof(wchar_t);
if(wbytes == 0){ if(wbytes == 0) {
free(mbout); free(mbout);
return MwStringDuplicate(input); return MwStringDuplicate(input);
} }
@ -26,14 +26,14 @@ char* MwACPToUTF8(const char* input){
memset(mbout, 0, mbbytes); memset(mbout, 0, mbbytes);
len = MultiByteToWideChar(CP_ACP, 0, input, strlen(input), wout, len); len = MultiByteToWideChar(CP_ACP, 0, input, strlen(input), wout, len);
if(len == 0){ if(len == 0) {
free(mbout); free(mbout);
free(wout); free(wout);
return MwStringDuplicate(input); return MwStringDuplicate(input);
} }
len = WideCharToMultiByte(CP_UTF8, 0, wout, len, mbout, mbbytes, 0, 0); len = WideCharToMultiByte(CP_UTF8, 0, wout, len, mbout, mbbytes, 0, 0);
if(len == 0){ if(len == 0) {
free(mbout); free(mbout);
free(wout); free(wout);
return MwStringDuplicate(input); return MwStringDuplicate(input);
@ -49,7 +49,7 @@ char* MwACPToUTF8(const char* input){
#endif #endif
} }
char* MwUTF8ToACP(const char* input){ char* MwUTF8ToACP(const char* input) {
#if defined(_WIN32) && defined(MW_HAS_WCHAR) #if defined(_WIN32) && defined(MW_HAS_WCHAR)
int mbbytes = (strlen(input) + 1) * 4; int mbbytes = (strlen(input) + 1) * 4;
int wbytes = 0; int wbytes = 0;
@ -59,7 +59,7 @@ char* MwUTF8ToACP(const char* input){
char* mbout = malloc(mbbytes); char* mbout = malloc(mbbytes);
wbytes = MultiByteToWideChar(CP_UTF8, 0, input, strlen(input), NULL, 0) * sizeof(wchar_t); wbytes = MultiByteToWideChar(CP_UTF8, 0, input, strlen(input), NULL, 0) * sizeof(wchar_t);
if(wbytes == 0){ if(wbytes == 0) {
free(mbout); free(mbout);
return MwStringDuplicate(input); return MwStringDuplicate(input);
} }
@ -71,14 +71,14 @@ char* MwUTF8ToACP(const char* input){
memset(mbout, 0, mbbytes); memset(mbout, 0, mbbytes);
len = MultiByteToWideChar(CP_UTF8, 0, input, strlen(input), wout, len); len = MultiByteToWideChar(CP_UTF8, 0, input, strlen(input), wout, len);
if(len == 0){ if(len == 0) {
free(mbout); free(mbout);
free(wout); free(wout);
return MwStringDuplicate(input); return MwStringDuplicate(input);
} }
len = WideCharToMultiByte(CP_ACP, 0, wout, len, mbout, mbbytes, 0, 0); len = WideCharToMultiByte(CP_ACP, 0, wout, len, mbout, mbbytes, 0, 0);
if(len == 0){ if(len == 0) {
free(mbout); free(mbout);
free(wout); free(wout);
return MwStringDuplicate(input); return MwStringDuplicate(input);

View file

@ -1763,6 +1763,7 @@ static void clip(MwLL handle) {
if(toplevel) { if(toplevel) {
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
/* i seriously have no fucking idea how this works, do not ask me how this really works (nishi) */
x = 0; x = 0;
y = 0; y = 0;
cx = 0; cx = 0;
@ -1772,11 +1773,22 @@ static void clip(MwLL handle) {
// ws is traversed result // ws is traversed result
// ws[ws.length - 1] is ignored bc it's toplevel // ws[ws.length - 1] is ignored bc it's toplevel
for(i = arrlen(ws) - 2; i >= 0; i--) { for(i = arrlen(ws) - 2; i >= 0; i--) {
int j;
int l = 0;
x += ws[i]->wayland.x; x += ws[i]->wayland.x;
y += ws[i]->wayland.y; y += ws[i]->wayland.y;
for(j = i - 1; j >= 0; j--) {
if(ws[j]->wayland.x > cx) l = 1;
if(ws[j]->wayland.y > cy) l = 1;
if(l) break;
}
if(!l) {
cx = MAX(cx, ws[i]->wayland.x); cx = MAX(cx, ws[i]->wayland.x);
cy = MAX(cy, ws[i]->wayland.y); cy = MAX(cy, ws[i]->wayland.y);
}
mx = MIN(mx, x + ws[i]->wayland.ww); mx = MIN(mx, x + ws[i]->wayland.ww);
my = MIN(my, y + ws[i]->wayland.wh); my = MIN(my, y + ws[i]->wayland.wh);

View file

@ -962,38 +962,43 @@ static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
free(pixmap); free(pixmap);
} }
#define DO_XRENDER(dest_px, src, format, bpp) \
{ \
Picture src_pic, dest_pic; \
XRenderPictFormat* fmt = XRenderFindStandardFormat(handle->x11.display, format); \
Pixmap src_px = XCreatePixmap(handle->x11.display, handle->x11.window, pixmap->common.width, pixmap->common.height, bpp); \
GC gc = XCreateGC(handle->x11.display, src_px, 0, NULL); \
\
dest_px = XCreatePixmap(handle->x11.display, handle->x11.window, rect->width, rect->height, bpp); \
\
XPutImage(handle->x11.display, src_px, gc, src, 0, 0, 0, 0, pixmap->common.width, pixmap->common.height); \
\
src_pic = XRenderCreatePicture(handle->x11.display, src_px, fmt, 0, &attr); \
dest_pic = XRenderCreatePicture(handle->x11.display, dest_px, fmt, 0, &attr); \
\
XRenderSetPictureTransform(handle->x11.display, src_pic, &m); \
XRenderComposite(handle->x11.display, PictOpSrc, src_pic, 0, dest_pic, 0, 0, 0, 0, 0, 0, rect->width, rect->height); \
\
XRenderFreePicture(handle->x11.display, src_pic); \
XRenderFreePicture(handle->x11.display, dest_pic); \
XFreePixmap(handle->x11.display, src_px); \
}
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
if(rect->width <= 0 || rect->height <= 0 || pixmap->common.width <= 0 || pixmap->common.height <= 0) return; if(rect->width <= 0 || rect->height <= 0 || pixmap->common.width <= 0 || pixmap->common.height <= 0) return;
#ifdef USE_XRENDER #ifdef USE_XRENDER
if(pixmap->x11.image != NULL && pixmap->x11.use_xrender) { if(pixmap->x11.image != NULL && pixmap->x11.use_xrender) {
Pixmap px = XCreatePixmap(handle->x11.display, handle->x11.window, pixmap->common.width, pixmap->common.height, pixmap->x11.depth); Pixmap px;
Pixmap mask = XCreatePixmap(handle->x11.display, handle->x11.window, rect->width, rect->height, 1); Pixmap mask;
Pixmap pxsrc = XCreatePixmap(handle->x11.display, handle->x11.window, rect->width, rect->height, pixmap->x11.depth);
GC maskgc = XCreateGC(handle->x11.display, mask, 0, NULL);
XRenderPictFormat* format = XRenderFindStandardFormat(handle->x11.display, PictStandardRGB24);
XRenderPictureAttributes attr; XRenderPictureAttributes attr;
Picture src, dest;
XTransform m; XTransform m;
double xsc = (double)pixmap->common.width / rect->width; double xsc;
double ysc = (double)pixmap->common.height / rect->height; double ysc;
char* dm = malloc(rect->width * rect->height * 4);
XImage* destmask;
int y, x;
destmask = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, dm, rect->width, rect->height, 32, rect->width * 4); memset(&attr, 0, sizeof(attr));
for(y = 0; y < (int)rect->height; y++) { xsc = (double)pixmap->common.width / rect->width;
for(x = 0; x < (int)rect->width; x++) { ysc = (double)pixmap->common.height / rect->height;
int sy = y * pixmap->common.height / rect->height;
int sx = x * pixmap->common.width / rect->width;
sy = (int)sy;
sx = (int)sx;
XPutPixel(destmask, x, y, XGetPixel(pixmap->x11.mask, sx, sy));
}
}
XPutImage(handle->x11.display, mask, maskgc, destmask, 0, 0, 0, 0, rect->width, rect->height);
m.matrix[0][0] = XDoubleToFixed(xsc); m.matrix[0][0] = XDoubleToFixed(xsc);
m.matrix[0][1] = XDoubleToFixed(0); m.matrix[0][1] = XDoubleToFixed(0);
@ -1007,30 +1012,16 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
m.matrix[2][1] = XDoubleToFixed(0); m.matrix[2][1] = XDoubleToFixed(0);
m.matrix[2][2] = XDoubleToFixed(1.0); m.matrix[2][2] = XDoubleToFixed(1.0);
memset(&attr, 0, sizeof(attr)); DO_XRENDER(px, pixmap->x11.image, PictStandardRGB24, pixmap->x11.depth);
DO_XRENDER(mask, pixmap->x11.mask, PictStandardA1, 1);
XPutImage(handle->x11.display, px, handle->x11.gc, pixmap->x11.image, 0, 0, 0, 0, pixmap->common.width, pixmap->common.height);
src = XRenderCreatePicture(handle->x11.display, px, format, 0, &attr);
dest = XRenderCreatePicture(handle->x11.display, pxsrc, format, 0, &attr);
XRenderSetPictureTransform(handle->x11.display, src, &m);
XRenderComposite(handle->x11.display, PictOpSrc, src, 0, dest, 0, 0, 0, 0, 0, 0, rect->width, rect->height);
XRenderFreePicture(handle->x11.display, src);
XRenderFreePicture(handle->x11.display, dest);
XSetClipMask(handle->x11.display, handle->x11.gc, mask); XSetClipMask(handle->x11.display, handle->x11.gc, mask);
XSetClipOrigin(handle->x11.display, handle->x11.gc, rect->x, rect->y); XSetClipOrigin(handle->x11.display, handle->x11.gc, rect->x, rect->y);
XCopyArea(handle->x11.display, pxsrc, handle->x11.pixmap, handle->x11.gc, 0, 0, rect->width, rect->height, rect->x, rect->y); XCopyArea(handle->x11.display, px, handle->x11.pixmap, handle->x11.gc, 0, 0, rect->width, rect->height, rect->x, rect->y);
XSetClipMask(handle->x11.display, handle->x11.gc, None); XSetClipMask(handle->x11.display, handle->x11.gc, None);
XDestroyImage(destmask);
XFreeGC(handle->x11.display, maskgc);
XFreePixmap(handle->x11.display, mask); XFreePixmap(handle->x11.display, mask);
XFreePixmap(handle->x11.display, px); XFreePixmap(handle->x11.display, px);
XFreePixmap(handle->x11.display, pxsrc);
} else } else
#endif #endif
if(pixmap->x11.image != NULL) { if(pixmap->x11.image != NULL) {

View file

@ -7,9 +7,7 @@
* These ""glyphs"" are unencumbered * These ""glyphs"" are unencumbered
*/ */
MwCursor MwCursorArrow = { MwCursor MwCursorArrow = {
14, 14, -13, -14, 14, 14, -13, -14, {3, /* ............## */
{
3, /* ............## */
15, /* ..........#### */ 15, /* ..........#### */
62, /* ........#####. */ 62, /* ........#####. */
254, /* ......#######. */ 254, /* ......#######. */
@ -23,13 +21,9 @@ MwCursor MwCursorArrow = {
7200, /* .###....#..... */ 7200, /* .###....#..... */
14336, /* ###........... */ 14336, /* ###........... */
4096, /* .#............ */ 4096, /* .#............ */
0, 0, 0}};
0
}
};
MwCursor MwCursorArrowMask = { MwCursor MwCursorArrowMask = {
16, 16, -14, -15, 16, 16, -14, -15, {
{
7, /* .............### */ 7, /* .............### */
31, /* ...........##### */ 31, /* ...........##### */
127, /* .........####### */ 127, /* .........####### */
@ -46,5 +40,4 @@ MwCursor MwCursorArrowMask = {
63552, /* #####....#...... */ 63552, /* #####....#...... */
28672, /* .###............ */ 28672, /* .###............ */
8192 /* ..#............. */ 8192 /* ..#............. */
} }};
};

View file

@ -7,9 +7,7 @@
* These ""glyphs"" are unencumbered * These ""glyphs"" are unencumbered
*/ */
MwCursor MwCursorDefault = { MwCursor MwCursorDefault = {
8, 14, 0, -14, 8, 14, 0, -14, {128, /* #....... */
{
128, /* #....... */
192, /* ##...... */ 192, /* ##...... */
224, /* ###..... */ 224, /* ###..... */
240, /* ####.... */ 240, /* ####.... */
@ -23,13 +21,9 @@ MwCursor MwCursorDefault = {
12, /* ....##.. */ 12, /* ....##.. */
6, /* .....##. */ 6, /* .....##. */
6, /* .....##. */ 6, /* .....##. */
0, 0, 0}};
0
}
};
MwCursor MwCursorDefaultMask = { MwCursor MwCursorDefaultMask = {
10, 16, -1, -15, 10, 16, -1, -15, {
{
768, /* ##........ */ 768, /* ##........ */
896, /* ###....... */ 896, /* ###....... */
960, /* ####...... */ 960, /* ####...... */
@ -46,5 +40,4 @@ MwCursor MwCursorDefaultMask = {
30, /* .....####. */ 30, /* .....####. */
30, /* .....####. */ 30, /* .....####. */
12 /* ......##.. */ 12 /* ......##.. */
} }};
};

View file

@ -7,9 +7,7 @@
* These ""glyphs"" are unencumbered * These ""glyphs"" are unencumbered
*/ */
MwCursor MwCursorText = { MwCursor MwCursorText = {
7, 14, -3, -7, 7, 14, -3, -7, {119, /* ###.### */
{
119, /* ###.### */
28, /* ..###.. */ 28, /* ..###.. */
8, /* ...#... */ 8, /* ...#... */
8, /* ...#... */ 8, /* ...#... */
@ -23,13 +21,9 @@ MwCursor MwCursorText = {
8, /* ...#... */ 8, /* ...#... */
28, /* ..###.. */ 28, /* ..###.. */
119, /* ###.### */ 119, /* ###.### */
0, 0, 0}};
0
}
};
MwCursor MwCursorTextMask = { MwCursor MwCursorTextMask = {
9, 16, -4, -8, 9, 16, -4, -8, {
{
495, /* ####.#### */ 495, /* ####.#### */
511, /* ######### */ 511, /* ######### */
511, /* ######### */ 511, /* ######### */
@ -46,5 +40,4 @@ MwCursor MwCursorTextMask = {
511, /* ######### */ 511, /* ######### */
511, /* ######### */ 511, /* ######### */
495 /* ####.#### */ 495 /* ####.#### */
} }};
};

View file

@ -204,7 +204,7 @@ static void frame_draw(MwWidget handle) {
int seek = 0; int seek = 0;
int l = 0; int l = 0;
while(str[seek] != 0){ while(str[seek] != 0) {
int cp; int cp;
seek += MwUTF8ToUTF32(str + seek, &cp); seek += MwUTF8ToUTF32(str + seek, &cp);