git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@19 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-28 09:50:28 +00:00
parent 6c44baff6c
commit 9f96056a1a
8 changed files with 83 additions and 63 deletions

View File

@@ -3,7 +3,7 @@
#include <Milsko/Milsko.h> #include <Milsko/Milsko.h>
int main(){ int main(){
HMILSKO window = MilskoCreateWidget(MilskoWindowClass, NULL, 0, 0, 640, 480); MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, NULL, 0, 0, 640, 480);
MilskoApply(window, MilskoApply(window,
MilskoNwidth, 480 * 2, MilskoNwidth, 480 * 2,

View File

@@ -5,17 +5,17 @@
#include <Milsko/MachDep.h> #include <Milsko/MachDep.h>
#include <Milsko/TypeDefs.h> #include <Milsko/TypeDefs.h>
MILSKODECL HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsigned int width, unsigned int height); MILSKODECL MilskoWidget MilskoCreateWidget(MilskoClass class, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height);
MILSKODECL void MilskoDestroyWidget(HMILSKO handle); MILSKODECL void MilskoDestroyWidget(MilskoWidget handle);
MILSKODECL void MilskoLoop(HMILSKO handle); MILSKODECL void MilskoLoop(MilskoWidget handle);
MILSKODECL void MilskoStep(HMILSKO handle); MILSKODECL void MilskoStep(MilskoWidget handle);
MILSKODECL int MilskoPending(HMILSKO handle); MILSKODECL int MilskoPending(MilskoWidget handle);
MILSKODECL void MilskoSetInteger(HMILSKO handle, const char* key, int n); MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
MILSKODECL void MilskoSetText(HMILSKO handle, const char* key, const char* value); MILSKODECL void MilskoSetText(MilskoWidget handle, const char* key, const char* value);
MILSKODECL int MilskoGetInteger(HMILSKO handle, const char* key); MILSKODECL int MilskoGetInteger(MilskoWidget handle, const char* key);
MILSKODECL const char* MilskoGetText(HMILSKO handle, const char* key); MILSKODECL const char* MilskoGetText(MilskoWidget handle, const char* key);
MILSKODECL void MilskoApply(HMILSKO handle, ...); MILSKODECL void MilskoApply(MilskoWidget handle, ...);
#endif #endif

View File

@@ -10,23 +10,23 @@
#include <Milsko/GDI.h> #include <Milsko/GDI.h>
#endif #endif
#else #else
typedef void* HMILSKOLL; typedef void* MilskoLL;
typedef void* HMILSKOCOLOR; typedef void* MilskoLLColor;
#endif #endif
#include <Milsko/MachDep.h> #include <Milsko/MachDep.h>
#include <Milsko/TypeDefs.h> #include <Milsko/TypeDefs.h>
MILSKODECL HMILSKOLL MilskoLLCreate(HMILSKOLL parent, int x, int y, int width, int height); MILSKODECL MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height);
MILSKODECL void MilskoLLDestroy(HMILSKOLL handle); MILSKODECL void MilskoLLDestroy(MilskoLL handle);
MILSKODECL void MilskoLLPolygon(HMILSKOLL handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color); MILSKODECL void MilskoLLPolygon(MilskoLL handle, MilskoPoint* points, int points_count, MilskoLLColor color);
MILSKODECL HMILSKOCOLOR MilskoLLAllocColor(HMILSKOLL handle, int r, int g, int b); MILSKODECL MilskoLLColor MilskoLLAllocColor(MilskoLL handle, int r, int g, int b);
MILSKODECL void MilskoLLGetXYWH(HMILSKOLL handle, int* x, int* y, unsigned int* w, unsigned int* h); MILSKODECL void MilskoLLGetXYWH(MilskoLL handle, int* x, int* y, unsigned int* w, unsigned int* h);
MILSKODECL void MilskoLLSetXY(HMILSKOLL handle, int x, int y); MILSKODECL void MilskoLLSetXY(MilskoLL handle, int x, int y);
MILSKODECL void MilskoLLSetWH(HMILSKOLL handle, int w, int h); MILSKODECL void MilskoLLSetWH(MilskoLL handle, int w, int h);
MILSKODECL void MilskoLLSetTitle(HMILSKOLL handle, const char* title); MILSKODECL void MilskoLLSetTitle(MilskoLL handle, const char* title);
MILSKODECL int MilskoLLPending(HMILSKOLL handle); MILSKODECL int MilskoLLPending(MilskoLL handle);
MILSKODECL void MilskoLLNextEvent(HMILSKOLL handle); MILSKODECL void MilskoLLNextEvent(MilskoLL handle);
MILSKODECL void MilskoLLSleep(int ms); MILSKODECL void MilskoLLSleep(int ms);
#endif #endif

View File

@@ -31,27 +31,29 @@ typedef struct _MilskoClass* MilskoClass;
#ifdef _MILSKO #ifdef _MILSKO
#include <Milsko/LowLevel.h> #include <Milsko/LowLevel.h>
typedef struct _Milsko* HMILSKO; typedef struct _Milsko* MilskoWidget;
typedef struct _Milsko { typedef struct _Milsko {
HMILSKOLL lowlevel; MilskoLL lowlevel;
HMILSKO parent; MilskoWidget parent;
HMILSKO* children; MilskoWidget* children;
MilskoClass class; MilskoClass class;
MilskoTextKeyValue* text; MilskoTextKeyValue* text;
MilskoIntegerKeyValue* integer; MilskoIntegerKeyValue* integer;
}* HMILSKO; }* MilskoWidget;
#else #else
typedef void* HMILSKO; typedef void* MilskoWidget;
#endif #endif
typedef void (*MilskoHandler)(MilskoWidget handle);
typedef struct _MilskoClass { typedef struct _MilskoClass {
void* opaque; void* opaque;
void (*create)(HMILSKO handle); MilskoHandler create;
void (*destroy)(HMILSKO handle); MilskoHandler destroy;
void (*draw)(HMILSKO handle); MilskoHandler draw;
void (*click)(HMILSKO handle); MilskoHandler click;
} *MilskoClass, MilskoClassRec; } *MilskoClass, MilskoClassRec;
#endif #endif

View File

@@ -2,7 +2,11 @@
#ifndef __MILSKO_X11_H__ #ifndef __MILSKO_X11_H__
#define __MILSKO_X11_H__ #define __MILSKO_X11_H__
typedef struct _MilskoLowLevel* MilskoLL;
typedef struct _MilskoColor* MilskoLLColor;
#include <Milsko/MachDep.h> #include <Milsko/MachDep.h>
#include <Milsko/TypeDefs.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
@@ -16,10 +20,13 @@ typedef struct _MilskoLowLevel {
int y; int y;
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
}* HMILSKOLL; void* user;
void (*draw)(MilskoLL handle);
}* MilskoLL;
typedef struct _MilskoColor { typedef struct _MilskoColor {
unsigned long pixel; unsigned long pixel;
}* HMILSKOCOLOR; }* MilskoLLColor;
#endif #endif

View File

@@ -6,14 +6,22 @@
#define Dispatch(x, y) \ #define Dispatch(x, y) \
if(x->class != NULL && x->class->y != NULL) x->class->y(x) if(x->class != NULL && x->class->y != NULL) x->class->y(x)
HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsigned int width, unsigned int height) { static void llhandler(MilskoLL handle) {
HMILSKO h = malloc(sizeof(*h)); MilskoWidget h = (MilskoWidget)handle;
Dispatch(h, draw);
}
MilskoWidget MilskoCreateWidget(MilskoClass class, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height) {
MilskoWidget h = malloc(sizeof(*h));
h->parent = parent; h->parent = parent;
h->children = NULL; h->children = NULL;
h->lowlevel = MilskoLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height); h->lowlevel = MilskoLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height);
h->class = class; h->class = class;
h->lowlevel->user = h;
h->lowlevel->draw = llhandler;
if(parent != NULL) arrput(parent->children, h); if(parent != NULL) arrput(parent->children, h);
sh_new_strdup(h->text); sh_new_strdup(h->text);
@@ -27,7 +35,7 @@ HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsi
return h; return h;
} }
void MilskoDestroyWidget(HMILSKO handle) { void MilskoDestroyWidget(MilskoWidget handle) {
int i; int i;
Dispatch(handle, destroy); Dispatch(handle, destroy);
@@ -63,11 +71,11 @@ void MilskoDestroyWidget(HMILSKO handle) {
free(handle); free(handle);
} }
void MilskoStep(HMILSKO handle) { void MilskoStep(MilskoWidget handle) {
MilskoLLNextEvent(handle->lowlevel); MilskoLLNextEvent(handle->lowlevel);
} }
int MilskoPending(HMILSKO handle) { int MilskoPending(MilskoWidget handle) {
int i; int i;
for(i = 0; i < arrlen(handle->children); i++) { for(i = 0; i < arrlen(handle->children); i++) {
if(MilskoPending(handle->children[i])) return 1; if(MilskoPending(handle->children[i])) return 1;
@@ -75,14 +83,14 @@ int MilskoPending(HMILSKO handle) {
return MilskoLLPending(handle->lowlevel); return MilskoLLPending(handle->lowlevel);
} }
void MilskoLoop(HMILSKO handle) { void MilskoLoop(MilskoWidget handle) {
while(1) { while(1) {
MilskoStep(handle); MilskoStep(handle);
MilskoLLSleep(10); MilskoLLSleep(10);
} }
} }
void MilskoSetInteger(HMILSKO handle, const char* key, int n) { void MilskoSetInteger(MilskoWidget handle, const char* key, int n) {
int xy = 0; int xy = 0;
int wh = 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, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0)) || (wh = (strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0))) {
@@ -101,7 +109,7 @@ void MilskoSetInteger(HMILSKO handle, const char* key, int n) {
} }
} }
void MilskoSetText(HMILSKO handle, const char* key, const char* value) { void MilskoSetText(MilskoWidget handle, const char* key, const char* value) {
if(strcmp(key, MilskoNtitle) == 0) { if(strcmp(key, MilskoNtitle) == 0) {
MilskoLLSetTitle(handle->lowlevel, value); MilskoLLSetTitle(handle->lowlevel, value);
} else { } else {
@@ -112,7 +120,7 @@ void MilskoSetText(HMILSKO handle, const char* key, const char* value) {
} }
} }
int MilskoGetInteger(HMILSKO handle, const char* key) { int MilskoGetInteger(MilskoWidget handle, const char* key) {
if(strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0 || strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0) { if(strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0 || strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0) {
int x, y; int x, y;
unsigned int w, h; unsigned int w, h;
@@ -129,11 +137,11 @@ int MilskoGetInteger(HMILSKO handle, const char* key) {
} }
} }
const char* MilskoGetText(HMILSKO handle, const char* key) { const char* MilskoGetText(MilskoWidget handle, const char* key) {
return shget(handle->text, key); return shget(handle->text, key);
} }
void MilskoApply(HMILSKO handle, ...) { void MilskoApply(MilskoWidget handle, ...) {
va_list va; va_list va;
char* key; char* key;

View File

@@ -1,11 +1,14 @@
/* $Id$ */ /* $Id$ */
#include <Milsko/Milsko.h> #include <Milsko/Milsko.h>
static void draw(MilskoWidget handle) {
}
MilskoClassRec MilskoWindowClassRec = { MilskoClassRec MilskoWindowClassRec = {
NULL, /* opaque */ NULL, /* opaque */
NULL, /* create */ NULL, /* create */
NULL, /* destroy */ NULL, /* destroy */
NULL, /* draw */ draw, /* draw */
NULL /* click */ NULL /* click */
}; };
MilskoClass MilskoWindowClass = &MilskoWindowClassRec; MilskoClass MilskoWindowClass = &MilskoWindowClassRec;

View File

@@ -3,8 +3,8 @@
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask; static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask;
HMILSKOLL MilskoLLCreate(HMILSKOLL parent, int x, int y, int width, int height) { MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height) {
HMILSKOLL r; MilskoLL r;
Window p; Window p;
Window root; Window root;
unsigned int border, depth; unsigned int border, depth;
@@ -33,13 +33,13 @@ HMILSKOLL MilskoLLCreate(HMILSKOLL parent, int x, int y, int width, int height)
return r; return r;
} }
void MilskoLLDestroy(HMILSKOLL handle) { void MilskoLLDestroy(MilskoLL handle) {
XFreeGC(handle->display, handle->gc); XFreeGC(handle->display, handle->gc);
XDestroyWindow(handle->display, handle->window); XDestroyWindow(handle->display, handle->window);
free(handle); free(handle);
} }
void MilskoLLPolygon(HMILSKOLL handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color) { void MilskoLLPolygon(MilskoLL handle, MilskoPoint* points, int points_count, MilskoLLColor color) {
int i; int i;
XPoint* p = malloc(sizeof(*p) * points_count); XPoint* p = malloc(sizeof(*p) * points_count);
@@ -54,9 +54,9 @@ void MilskoLLPolygon(HMILSKOLL handle, MilskoPoint* points, int points_count, HM
free(p); free(p);
} }
HMILSKOCOLOR MilskoLLAllocColor(HMILSKOLL handle, int r, int g, int b) { MilskoLLColor MilskoLLAllocColor(MilskoLL handle, int r, int g, int b) {
HMILSKOCOLOR c = malloc(sizeof(*c)); MilskoLLColor c = malloc(sizeof(*c));
XColor xc; XColor xc;
xc.red = 256 * r; xc.red = 256 * r;
xc.green = 256 * g; xc.green = 256 * g;
xc.blue = 256 * b; xc.blue = 256 * b;
@@ -66,7 +66,7 @@ HMILSKOCOLOR MilskoLLAllocColor(HMILSKOLL handle, int r, int g, int b) {
return c; return c;
} }
void MilskoLLGetXYWH(HMILSKOLL handle, int* x, int* y, unsigned int* w, unsigned int* h) { void MilskoLLGetXYWH(MilskoLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
Window root; Window root;
unsigned int border, depth; unsigned int border, depth;
@@ -78,19 +78,19 @@ void MilskoLLGetXYWH(HMILSKOLL handle, int* x, int* y, unsigned int* w, unsigned
handle->height = *h; handle->height = *h;
} }
void MilskoLLSetXY(HMILSKOLL handle, int x, int y) { void MilskoLLSetXY(MilskoLL handle, int x, int y) {
XMoveWindow(handle->display, handle->window, x, y); XMoveWindow(handle->display, handle->window, x, y);
} }
void MilskoLLSetWH(HMILSKOLL handle, int w, int h) { void MilskoLLSetWH(MilskoLL handle, int w, int h) {
XResizeWindow(handle->display, handle->window, w, h); XResizeWindow(handle->display, handle->window, w, h);
} }
void MilskoLLFreeColor(HMILSKOCOLOR color) { void MilskoLLFreeColor(MilskoLLColor color) {
free(color); free(color);
} }
int MilskoLLPending(HMILSKOLL handle) { int MilskoLLPending(MilskoLL handle) {
XEvent ev; XEvent ev;
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) { if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
XPutBackEvent(handle->display, &ev); XPutBackEvent(handle->display, &ev);
@@ -99,7 +99,7 @@ int MilskoLLPending(HMILSKOLL handle) {
return 0; return 0;
} }
void MilskoLLNextEvent(HMILSKOLL handle) { void MilskoLLNextEvent(MilskoLL handle) {
XEvent ev; XEvent ev;
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) { if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
} }
@@ -109,6 +109,6 @@ void MilskoLLSleep(int ms) {
usleep(ms * 1000); usleep(ms * 1000);
} }
void MilskoLLSetTitle(HMILSKOLL handle, const char* title) { void MilskoLLSetTitle(MilskoLL handle, const char* title) {
XSetStandardProperties(handle->display, handle->window, title, "Milsko Widget Toolkit", None, (char**)NULL, 0, NULL); XSetStandardProperties(handle->display, handle->window, title, "Milsko Widget Toolkit", None, (char**)NULL, 0, NULL);
} }