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>
int main(){
HMILSKO window = MilskoCreateWidget(MilskoWindowClass, NULL, 0, 0, 640, 480);
MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, NULL, 0, 0, 640, 480);
MilskoApply(window,
MilskoNwidth, 480 * 2,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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