git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@36 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-29 00:04:04 +00:00
parent 4910b4d1d8
commit b490488422
19 changed files with 253 additions and 253 deletions

View File

@@ -1,32 +1,32 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>
static void create(MilskoWidget handle) {
MilskoSetDefault(handle);
static void create(MwWidget handle) {
MwSetDefault(handle);
}
static void draw(MilskoWidget handle) {
MilskoRect r;
static void draw(MwWidget handle) {
MwRect r;
r.x = 0;
r.y = 0;
r.width = MilskoGetInteger(handle, MilskoNwidth);
r.height = MilskoGetInteger(handle, MilskoNheight);
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
MilskoDrawFrame(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)), handle->pressed);
MwDrawFrame(handle, &r, MwParseColor(handle, MwGetText(handle, MwNbackground)), handle->pressed);
MilskoDrawRect(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)));
MwDrawRect(handle, &r, MwParseColor(handle, MwGetText(handle, MwNbackground)));
}
static void click(MilskoWidget handle) {
MilskoDispatchUserHandler(handle, MilskoNactivateHandler, NULL);
static void click(MwWidget handle) {
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
}
MilskoClassRec MilskoButtonClassRec = {
MwClassRec MwButtonClassRec = {
NULL, /* opaque */
create, /* create */
NULL, /* destroy */
draw, /* draw */
click /* click */
};
MilskoClass MilskoButtonClass = &MilskoButtonClassRec;
MwClass MwButtonClass = &MwButtonClassRec;

View File

@@ -1,34 +1,34 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>
#include "stb_ds.h"
static void lldrawhandler(MilskoLL handle) {
MilskoWidget h = (MilskoWidget)handle->user;
MilskoDispatch(h, draw);
static void lldrawhandler(MwLL handle) {
MwWidget h = (MwWidget)handle->user;
MwDispatch(h, draw);
}
static void lluphandler(MilskoLL handle) {
MilskoWidget h = (MilskoWidget)handle->user;
static void lluphandler(MwLL handle) {
MwWidget h = (MwWidget)handle->user;
h->pressed = 0;
MilskoDispatch(h, click);
MwDispatch(h, click);
}
static void lldownhandler(MilskoLL handle) {
MilskoWidget h = (MilskoWidget)handle->user;
static void lldownhandler(MwLL handle) {
MwWidget h = (MwWidget)handle->user;
h->pressed = 1;
}
MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height) {
MilskoWidget h = malloc(sizeof(*h));
MwWidget MwCreateWidget(MwClass class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
MwWidget h = malloc(sizeof(*h));
h->name = malloc(strlen(name) + 1);
strcpy(h->name, name);
h->parent = parent;
h->children = NULL;
h->lowlevel = MilskoLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height);
h->lowlevel = MwLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height);
h->class = class;
h->pressed = 0;
@@ -46,42 +46,42 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge
shdefault(h->text, NULL);
shdefault(h->handler, NULL);
MilskoDispatch(h, create);
MwDispatch(h, create);
return h;
}
MilskoWidget MilskoVaCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height, ...) {
MilskoWidget h;
MwWidget MwVaCreateWidget(MwClass class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, ...) {
MwWidget h;
va_list va;
va_start(va, height);
h = MilskoVaListCreateWidget(class, name, parent, x, y, width, height, va);
h = MwVaListCreateWidget(class, name, parent, x, y, width, height, va);
va_end(va);
return h;
}
MilskoWidget MilskoVaListCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height, va_list va) {
MilskoWidget h;
MwWidget MwVaListCreateWidget(MwClass class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, va_list va) {
MwWidget h;
h = MilskoCreateWidget(class, name, parent, x, y, width, height);
MilskoVaListApply(h, va);
h = MwCreateWidget(class, name, parent, x, y, width, height);
MwVaListApply(h, va);
return h;
}
void MilskoDestroyWidget(MilskoWidget handle) {
void MwDestroyWidget(MwWidget handle) {
int i;
MilskoDispatch(handle, destroy);
MwDispatch(handle, destroy);
free(handle->name);
if(handle->children != NULL) {
for(i = 0; i < arrlen(handle->children); i++) {
if(handle->children[i] == handle) {
MilskoDestroyWidget(handle->children[i]);
MwDestroyWidget(handle->children[i]);
break;
}
}
@@ -96,7 +96,7 @@ void MilskoDestroyWidget(MilskoWidget handle) {
}
}
}
MilskoLLDestroy(handle->lowlevel);
MwLLDestroy(handle->lowlevel);
shfree(handle->integer);
@@ -110,49 +110,49 @@ void MilskoDestroyWidget(MilskoWidget handle) {
free(handle);
}
void MilskoStep(MilskoWidget handle) {
void MwStep(MwWidget handle) {
int i;
for(i = 0; i < arrlen(handle->children); i++) MilskoStep(handle->children[i]);
MilskoLLNextEvent(handle->lowlevel);
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
MwLLNextEvent(handle->lowlevel);
}
int MilskoPending(MilskoWidget handle) {
int MwPending(MwWidget handle) {
int i;
for(i = 0; i < arrlen(handle->children); i++) {
if(MilskoPending(handle->children[i])) return 1;
if(MwPending(handle->children[i])) return 1;
}
return MilskoLLPending(handle->lowlevel);
return MwLLPending(handle->lowlevel);
}
void MilskoLoop(MilskoWidget handle) {
void MwLoop(MwWidget handle) {
while(1) {
MilskoStep(handle);
MilskoLLSleep(5);
MwStep(handle);
MwLLSleep(5);
}
}
void MilskoSetInteger(MilskoWidget handle, const char* key, int n) {
void MwSetInteger(MwWidget handle, const char* key, int n) {
int xy = 0;
int wh = 0;
if((xy = (strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0)) || (wh = (strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0))) {
if((xy = (strcmp(key, MwNx) == 0 || strcmp(key, MwNy) == 0)) || (wh = (strcmp(key, MwNwidth) == 0 || strcmp(key, MwNheight) == 0))) {
int x, y;
unsigned int w, h;
MilskoLLGetXYWH(handle->lowlevel, &x, &y, &w, &h);
if(strcmp(key, MilskoNx) == 0) x = n;
if(strcmp(key, MilskoNy) == 0) y = n;
if(strcmp(key, MilskoNwidth) == 0) w = n;
if(strcmp(key, MilskoNheight) == 0) h = n;
if(xy) MilskoLLSetXY(handle->lowlevel, x, y);
if(wh) MilskoLLSetWH(handle->lowlevel, w, h);
MwLLGetXYWH(handle->lowlevel, &x, &y, &w, &h);
if(strcmp(key, MwNx) == 0) x = n;
if(strcmp(key, MwNy) == 0) y = n;
if(strcmp(key, MwNwidth) == 0) w = n;
if(strcmp(key, MwNheight) == 0) h = n;
if(xy) MwLLSetXY(handle->lowlevel, x, y);
if(wh) MwLLSetWH(handle->lowlevel, w, h);
} else {
shput(handle->integer, key, n);
}
}
void MilskoSetText(MilskoWidget handle, const char* key, const char* value) {
if(strcmp(key, MilskoNtitle) == 0) {
MilskoLLSetTitle(handle->lowlevel, value);
void MwSetText(MwWidget handle, const char* key, const char* value) {
if(strcmp(key, MwNtitle) == 0) {
MwLLSetTitle(handle->lowlevel, value);
} else {
char* v = malloc(strlen(value) + 1);
strcpy(v, value);
@@ -163,47 +163,47 @@ void MilskoSetText(MilskoWidget handle, const char* key, const char* value) {
}
}
int MilskoGetInteger(MilskoWidget handle, const char* key) {
if(strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0 || strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0) {
int MwGetInteger(MwWidget handle, const char* key) {
if(strcmp(key, MwNx) == 0 || strcmp(key, MwNy) == 0 || strcmp(key, MwNwidth) == 0 || strcmp(key, MwNheight) == 0) {
int x, y;
unsigned int w, h;
MilskoLLGetXYWH(handle->lowlevel, &x, &y, &w, &h);
MwLLGetXYWH(handle->lowlevel, &x, &y, &w, &h);
if(strcmp(key, MilskoNx) == 0) return x;
if(strcmp(key, MilskoNy) == 0) return y;
if(strcmp(key, MilskoNwidth) == 0) return w;
if(strcmp(key, MilskoNheight) == 0) return h;
if(strcmp(key, MwNx) == 0) return x;
if(strcmp(key, MwNy) == 0) return y;
if(strcmp(key, MwNwidth) == 0) return w;
if(strcmp(key, MwNheight) == 0) return h;
return -1;
} else {
return shget(handle->integer, key);
}
}
const char* MilskoGetText(MilskoWidget handle, const char* key) {
const char* MwGetText(MwWidget handle, const char* key) {
return shget(handle->text, key);
}
void MilskoVaApply(MilskoWidget handle, ...) {
void MwVaApply(MwWidget handle, ...) {
va_list va;
va_start(va, handle);
MilskoVaListApply(handle, va);
MwVaListApply(handle, va);
va_end(va);
}
void MilskoVaListApply(MilskoWidget handle, va_list va) {
void MwVaListApply(MwWidget handle, va_list va) {
char* key;
while((key = va_arg(va, char*)) != NULL) {
if(key[0] == 'I') {
int n = va_arg(va, int);
MilskoSetInteger(handle, key, n);
MwSetInteger(handle, key, n);
} else if(key[0] == 'S') {
char* t = va_arg(va, char*);
MilskoSetText(handle, key, t);
MwSetText(handle, key, t);
} else if(key[0] == 'C') {
MilskoUserHandler h = va_arg(va, MilskoUserHandler);
MwUserHandler h = va_arg(va, MwUserHandler);
int ind;
shput(handle->handler, key, h);
@@ -213,18 +213,18 @@ void MilskoVaListApply(MilskoWidget handle, va_list va) {
}
}
void MilskoSetDefault(MilskoWidget handle) {
MilskoSetText(handle, MilskoNbackground, MilskoDefaultBackground);
void MwSetDefault(MwWidget handle) {
MwSetText(handle, MwNbackground, MwDefaultBackground);
}
void MilskoDispatchUserHandler(MilskoWidget handle, const char* key, void* handler_data) {
void MwDispatchUserHandler(MwWidget handle, const char* key, void* handler_data) {
int ind = shgeti(handle->handler, key);
if(ind == -1) return;
handle->handler[ind].value(handle, handle->handler[ind].user_data, handler_data);
}
void MilskoAddUserHandler(MilskoWidget handle, const char* key, MilskoUserHandler handler, void* user_data) {
void MwAddUserHandler(MwWidget handle, const char* key, MwUserHandler handler, void* user_data) {
int ind;
shput(handle->handler, key, handler);

View File

@@ -1,4 +1,4 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>
const char* MilskoDefaultBackground = "#ddd";
const char* MwDefaultBackground = "#ddd";

View File

@@ -1,5 +1,5 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>
static int hex(const char* txt, int len) {
int i;
@@ -20,7 +20,7 @@ static int hex(const char* txt, int len) {
return r;
}
MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text) {
MwLLColor MwParseColor(MwWidget handle, const char* text) {
int r = 0;
int g = 0;
int b = 0;
@@ -39,11 +39,11 @@ MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text) {
b = hex(text + 5, 2);
}
return MilskoLLAllocColor(handle->lowlevel, r, g, b);
return MwLLAllocColor(handle->lowlevel, r, g, b);
}
void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color) {
MilskoPoint p[4];
void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) {
MwPoint p[4];
p[0].x = rect->x;
p[0].y = rect->y;
@@ -57,15 +57,15 @@ void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color)
p[3].x = rect->x;
p[3].y = rect->y + rect->height;
MilskoLLPolygon(handle->lowlevel, p, 4, color);
MwLLPolygon(handle->lowlevel, p, 4, color);
}
void MilskoDrawFrame(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color, int invert) {
MilskoPoint p[6];
void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
MwPoint p[6];
const int diff = 128;
const int border = 2;
MilskoLLColor darker = MilskoLLAllocColor(handle->lowlevel, color->red - diff, color->green - diff, color->blue - diff);
MilskoLLColor lighter = MilskoLLAllocColor(handle->lowlevel, color->red + diff, color->green + diff, color->blue + diff);
MwLLColor darker = MwLLAllocColor(handle->lowlevel, color->red - diff, color->green - diff, color->blue - diff);
MwLLColor lighter = MwLLAllocColor(handle->lowlevel, color->red + diff, color->green + diff, color->blue + diff);
p[0].x = rect->x;
p[0].y = rect->y;
@@ -85,7 +85,7 @@ void MilskoDrawFrame(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color,
p[5].x = rect->x;
p[5].y = rect->y + rect->height;
MilskoLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter);
MwLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter);
p[0].x = rect->x + rect->width;
p[0].y = rect->y;
@@ -105,10 +105,10 @@ void MilskoDrawFrame(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color,
p[5].x = rect->x + rect->height;
p[5].y = rect->y + rect->height;
MilskoLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker);
MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker);
MilskoLLFreeColor(lighter);
MilskoLLFreeColor(darker);
MwLLFreeColor(lighter);
MwLLFreeColor(darker);
rect->x += border;
rect->y += border;

View File

@@ -1,2 +1,2 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>

View File

@@ -1,11 +1,11 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>
void MilskoLLCreateCommon(MilskoLL handle) {
void MwLLCreateCommon(MwLL handle) {
handle->handler = malloc(sizeof(*handle->handler));
memset(handle->handler, 0, sizeof(*handle->handler));
}
void MilskoLLDestroyCommon(MilskoLL handle) {
void MwLLDestroyCommon(MwLL handle) {
free(handle->handler);
}

View File

@@ -1,29 +1,29 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>
static void create(MilskoWidget handle) {
MilskoSetDefault(handle);
static void create(MwWidget handle) {
MwSetDefault(handle);
}
static void draw(MilskoWidget handle) {
MilskoLLColor c = MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground));
MilskoRect r;
static void draw(MwWidget handle) {
MwLLColor c = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwRect r;
r.x = 0;
r.y = 0;
r.width = MilskoGetInteger(handle, MilskoNwidth);
r.height = MilskoGetInteger(handle, MilskoNheight);
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
MilskoDrawRect(handle, &r, c);
MwDrawRect(handle, &r, c);
MilskoLLFreeColor(c);
MwLLFreeColor(c);
}
MilskoClassRec MilskoWindowClassRec = {
MwClassRec MwWindowClassRec = {
NULL, /* opaque */
create, /* create */
NULL, /* destroy */
draw, /* draw */
NULL /* click */
};
MilskoClass MilskoWindowClass = &MilskoWindowClassRec;
MwClass MwWindowClass = &MwWindowClassRec;

View File

@@ -1,17 +1,17 @@
/* $Id$ */
#include <Milsko/Milsko.h>
#include <Mw/Mw.h>
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask;
MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height) {
MilskoLL r;
MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
MwLL r;
Window p;
Window root;
unsigned int border, depth;
r = malloc(sizeof(*r));
MilskoLLCreateCommon(r);
MwLLCreateCommon(r);
if(parent == NULL) {
r->display = XOpenDisplay(NULL);
@@ -31,15 +31,15 @@ MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height) {
return r;
}
void MilskoLLDestroy(MilskoLL handle) {
MilskoLLDestroyCommon(handle);
void MwLLDestroy(MwLL handle) {
MwLLDestroyCommon(handle);
XFreeGC(handle->display, handle->gc);
XDestroyWindow(handle->display, handle->window);
free(handle);
}
void MilskoLLPolygon(MilskoLL handle, MilskoPoint* points, int points_count, MilskoLLColor color) {
void MwLLPolygon(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
int i;
XPoint* p = malloc(sizeof(*p) * points_count);
@@ -54,8 +54,8 @@ void MilskoLLPolygon(MilskoLL handle, MilskoPoint* points, int points_count, Mil
free(p);
}
MilskoLLColor MilskoLLAllocColor(MilskoLL handle, int r, int g, int b) {
MilskoLLColor c = malloc(sizeof(*c));
MwLLColor MwLLAllocColor(MwLL handle, int r, int g, int b) {
MwLLColor c = malloc(sizeof(*c));
XColor xc;
if(r > 255) r = 255;
@@ -77,26 +77,26 @@ MilskoLLColor MilskoLLAllocColor(MilskoLL handle, int r, int g, int b) {
return c;
}
void MilskoLLGetXYWH(MilskoLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
void MwLLGetXYWH(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
Window root;
unsigned int border, depth;
XGetGeometry(handle->display, handle->window, &root, x, y, w, h, &border, &depth);
}
void MilskoLLSetXY(MilskoLL handle, int x, int y) {
void MwLLSetXY(MwLL handle, int x, int y) {
XMoveWindow(handle->display, handle->window, x, y);
}
void MilskoLLSetWH(MilskoLL handle, int w, int h) {
void MwLLSetWH(MwLL handle, int w, int h) {
XResizeWindow(handle->display, handle->window, w, h);
}
void MilskoLLFreeColor(MilskoLLColor color) {
void MwLLFreeColor(MwLLColor color) {
free(color);
}
int MilskoLLPending(MilskoLL handle) {
int MwLLPending(MwLL handle) {
XEvent ev;
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
XPutBackEvent(handle->display, &ev);
@@ -105,29 +105,29 @@ int MilskoLLPending(MilskoLL handle) {
return 0;
}
void MilskoLLNextEvent(MilskoLL handle) {
void MwLLNextEvent(MwLL handle) {
XEvent ev;
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
if(ev.type == Expose) {
MilskoLLDispatch(handle, draw);
MwLLDispatch(handle, draw);
} else if(ev.type == ButtonPress) {
if(ev.xbutton.button == Button1) {
MilskoLLDispatch(handle, down);
MilskoLLDispatch(handle, draw);
MwLLDispatch(handle, down);
MwLLDispatch(handle, draw);
}
} else if(ev.type == ButtonRelease) {
if(ev.xbutton.button == Button1) {
MilskoLLDispatch(handle, up);
MilskoLLDispatch(handle, draw);
MwLLDispatch(handle, up);
MwLLDispatch(handle, draw);
}
}
}
}
void MilskoLLSleep(int ms) {
void MwLLSleep(int ms) {
usleep(ms * 1000);
}
void MilskoLLSetTitle(MilskoLL handle, const char* title) {
XSetStandardProperties(handle->display, handle->window, title, "Milsko Widget Toolkit", None, (char**)NULL, 0, NULL);
void MwLLSetTitle(MwLL handle, const char* title) {
XSetStandardProperties(handle->display, handle->window, title, "Mw Widget Toolkit", None, (char**)NULL, 0, NULL);
}