bad solution

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@30 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-28 21:55:50 +00:00
parent c2b08729ef
commit 61b442d259
7 changed files with 92 additions and 63 deletions

View File

@@ -1,25 +1,27 @@
/* $Id$ */
#ifndef __MILSKO_X11_H__
#define __MILSKO_X11_H__
typedef struct _MilskoLowLevel* MilskoLL;
typedef struct _MilskoColor* MilskoLLColor;
#ifndef __MILSKO_GDI_H__
#define __MILSKO_GDI_H__
#include <Milsko/MachDep.h>
typedef struct _MilskoLL * MilskoLL, MilskoLLRec;
typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec;
#include <Milsko/TypeDefs.h>
#include <Milsko/LowLevel.h>
#include <windows.h>
typedef struct _MilskoLowLevel {
struct _MilskoLL {
void* user;
void (*draw)(MilskoLL handle);
}* MilskoLL;
};
typedef struct _MilskoColor {
int red;
int green;
int blue;
}* MilskoLLColor;
struct _MilskoColor {
int red;
int green;
int blue;
};
#endif

View File

@@ -1,6 +1,17 @@
/* $Id$ */
#ifndef __MILSKO_LL_H__
#define __MILSKO_LL_H__
#ifndef __MILSKO_LOWLEVEL_H__
#define __MILSKO_LOWLEVEL_H__
#include <Milsko/MachDep.h>
typedef struct _MilskoLLCallback *MilskoLLCallback, MilskoLLCallbackRec;
#ifdef _MILSKO
typedef struct _MilskoLL * MilskoLL, MilskoLLRec;
typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec;
#else
typedef void* MilskoLL;
typedef void* MilskoLLColor;
#endif
#ifdef _MILSKO
#ifdef USE_X11
@@ -9,14 +20,18 @@
#ifdef USE_GDI
#include <Milsko/GDI.h>
#endif
#else
typedef void* MilskoLL;
typedef void* MilskoLLColor;
#endif
#include <Milsko/MachDep.h>
#include <Milsko/TypeDefs.h>
#define MilskoLLDispatch(x, y) \
if(x->callback != NULL && x->callback->y != NULL) x->callback->y(x)
struct _MilskoLLCallback {
void (*draw)(MilskoLL handle);
void (*down)(MilskoLL handle);
void (*up)(MilskoLL handle);
};
MILSKODECL MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height);
MILSKODECL void MilskoLLDestroy(MilskoLL handle);

View File

@@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdarg.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

View File

@@ -4,36 +4,49 @@
#include <Milsko/MachDep.h>
typedef struct _MilskoPoint {
typedef struct _MilskoClass * MilskoClass, MilskoClassRec;
typedef struct _MilskoPoint MilskoPoint;
typedef struct _MilskoRect MilskoRect;
typedef struct _MilskoTextKeyValue MilskoTextKeyValue;
typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue;
#ifdef _MILSKO
typedef struct _Milsko *MilskoWidget, MilskoWidgetRec;
#else
typedef void* MilskoWidget;
#endif
typedef void (*MilskoHandler)(MilskoWidget handle);
#ifdef _MILSKO
#include <Milsko/LowLevel.h>
#endif
#define MilskoDispatch(x, y) \
if(x->class != NULL && x->class->y != NULL) x->class->y(x)
struct _MilskoPoint {
int x;
int y;
} MilskoPoint;
};
typedef struct _MilskoRect {
struct _MilskoRect {
int x;
int y;
unsigned int width;
unsigned int height;
} MilskoRect;
};
typedef struct _MilskoTextKeyValue {
struct _MilskoTextKeyValue {
char* key;
char* value;
} MilskoTextKeyValue;
};
typedef struct _MilskoIntegerKeyValue {
struct _MilskoIntegerKeyValue {
char* key;
int value;
} MilskoIntegerKeyValue;
typedef struct _MilskoClass* MilskoClass;
};
#ifdef _MILSKO
#include <Milsko/LowLevel.h>
typedef struct _Milsko* MilskoWidget;
typedef struct _Milsko {
struct _Milsko {
char* name;
MilskoLL lowlevel;
@@ -43,19 +56,15 @@ typedef struct _Milsko {
MilskoTextKeyValue* text;
MilskoIntegerKeyValue* integer;
}* MilskoWidget;
#else
typedef void* MilskoWidget;
};
#endif
typedef void (*MilskoHandler)(MilskoWidget handle);
typedef struct _MilskoClass {
struct _MilskoClass {
void* opaque;
MilskoHandler create;
MilskoHandler destroy;
MilskoHandler draw;
MilskoHandler click;
} *MilskoClass, MilskoClassRec;
};
#endif

View File

@@ -2,16 +2,18 @@
#ifndef __MILSKO_X11_H__
#define __MILSKO_X11_H__
typedef struct _MilskoLowLevel* MilskoLL;
typedef struct _MilskoColor* MilskoLLColor;
#include <Milsko/MachDep.h>
typedef struct _MilskoLL * MilskoLL, MilskoLLRec;
typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec;
#include <Milsko/TypeDefs.h>
#include <Milsko/LowLevel.h>
#include <X11/X.h>
#include <X11/Xutil.h>
typedef struct _MilskoLowLevel {
struct _MilskoLL {
Display* display;
Window window;
GC gc;
@@ -22,14 +24,14 @@ typedef struct _MilskoLowLevel {
unsigned int height;
void* user;
void (*draw)(MilskoLL handle);
}* MilskoLL;
MilskoLLCallback callback;
};
typedef struct _MilskoColor {
struct _MilskoLLColor {
unsigned long pixel;
int red;
int green;
int blue;
}* MilskoLLColor;
};
#endif

View File

@@ -3,12 +3,9 @@
#include "stb_ds.h"
#define Dispatch(x, y) \
if(x->class != NULL && x->class->y != NULL) x->class->y(x)
static void llhandler(MilskoLL handle) {
MilskoWidget h = (MilskoWidget)handle->user;
Dispatch(h, draw);
MilskoDispatch(h, draw);
}
MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height) {
@@ -22,8 +19,8 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge
h->lowlevel = MilskoLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height);
h->class = class;
h->lowlevel->user = h;
h->lowlevel->draw = llhandler;
h->lowlevel->user = h;
h->lowlevel->callback->draw = llhandler;
if(parent != NULL) arrput(parent->children, h);
@@ -33,7 +30,7 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge
shdefault(h->text, NULL);
shdefault(h->integer, -1);
Dispatch(h, create);
MilskoDispatch(h, create);
return h;
}
@@ -41,7 +38,7 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge
void MilskoDestroyWidget(MilskoWidget handle) {
int i;
Dispatch(handle, destroy);
MilskoDispatch(handle, destroy);
free(handle->name);

View File

@@ -9,11 +9,14 @@ MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height) {
Window root;
unsigned int border, depth;
r = malloc(sizeof(*r));
r->x = x;
r->y = y;
r->width = width;
r->height = height;
r = malloc(sizeof(*r));
r->x = x;
r->y = y;
r->width = width;
r->height = height;
r->callback = malloc(sizeof(*r->callback));
memset(r->callback, 0, sizeof(*r->callback));
if(parent == NULL) {
r->display = XOpenDisplay(NULL);
@@ -114,7 +117,7 @@ void MilskoLLNextEvent(MilskoLL handle) {
XEvent ev;
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
if(ev.type == Expose) {
if(handle->draw != NULL) handle->draw(handle);
MilskoLLDispatch(handle, draw);
}
}
}