From 31e9818e4276afc1ca82e562e7ecf56d571e4048 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 28 Sep 2025 08:37:12 +0000 Subject: [PATCH] basic stuff git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@11 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 1 + include/Milsko/Core.h | 24 ++++-------------------- include/Milsko/LowLevel.h | 7 ++++--- include/Milsko/MachDep.h | 4 ++++ include/Milsko/Milsko.h | 2 ++ include/Milsko/TypeDef.h | 20 ++++++++++++++++++++ src/core.c | 23 +++++++++++++++++++++-- src/window.c | 6 ++++++ src/x11.c | 4 ++++ 9 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/window.c diff --git a/GNUmakefile b/GNUmakefile index 70fd0f4..7ce94d8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -8,6 +8,7 @@ LDFLAGS = LIBS = L_OBJS = src/ds.o src/core.o +L_OBJS += src/window.o ifeq ($(TARGET),NetBSD) CFLAGS += -I/usr/X11R7/include -I/usr/pkg/include diff --git a/include/Milsko/Core.h b/include/Milsko/Core.h index 5a45bd2..d364b86 100644 --- a/include/Milsko/Core.h +++ b/include/Milsko/Core.h @@ -3,28 +3,12 @@ #define __MILSKO_CORE_H__ #include - -typedef struct _MilskoClass* MilskoClass; - -#ifdef _MILSKO -#include - -typedef struct _Milsko* HMILSKO; - -typedef struct _Milsko { - HMILSKOLL lowlevel; - HMILSKO parent; - HMILSKO* children; - MilskoClass class; -}* HMILSKO; -#else -typedef void* HMILSKO; -#endif - -typedef struct _MilskoClass { -}* MilskoClass; +#include MILSKODECL HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsigned int width, unsigned int height); MILSKODECL void MilskoDestroyWidget(HMILSKO handle); +MILSKODECL void MilskoLoop(HMILSKO handle); +MILSKODECL void MilskoStep(HMILSKO handle); +MILSKODECL int MilskoPending(HMILSKO handle); #endif diff --git a/include/Milsko/LowLevel.h b/include/Milsko/LowLevel.h index e7d4e3e..fd4d408 100644 --- a/include/Milsko/LowLevel.h +++ b/include/Milsko/LowLevel.h @@ -2,9 +2,6 @@ #ifndef __MILSKO_LL_H__ #define __MILSKO_LL_H__ -#include -#include - #ifdef _MILSKO #ifdef USE_X11 #include @@ -17,6 +14,9 @@ typedef void* HMILSKOLL; typedef void* HMILSKOCOLOR; #endif +#include +#include + 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); @@ -24,5 +24,6 @@ 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 int MilskoLLPending(HMILSKOLL handle); MILSKODECL void MilskoLLNextEvent(HMILSKOLL handle); +MILSKODECL void MilskoLLSleep(int ms); #endif diff --git a/include/Milsko/MachDep.h b/include/Milsko/MachDep.h index 8d4419e..76917e4 100644 --- a/include/Milsko/MachDep.h +++ b/include/Milsko/MachDep.h @@ -5,6 +5,10 @@ #include #include #include +#ifdef _WIN32 +#else +#include +#endif #if defined(_MILSKO) && defined(_WIN32) #define MILSKODECL extern __declsped(dllexport) diff --git a/include/Milsko/Milsko.h b/include/Milsko/Milsko.h index b3a654f..deb16d0 100644 --- a/include/Milsko/Milsko.h +++ b/include/Milsko/Milsko.h @@ -6,4 +6,6 @@ #include #include +#include + #endif diff --git a/include/Milsko/TypeDef.h b/include/Milsko/TypeDef.h index 8c56255..6989ff6 100644 --- a/include/Milsko/TypeDef.h +++ b/include/Milsko/TypeDef.h @@ -9,4 +9,24 @@ typedef struct _MilskoPoint { int y; } MilskoPoint; +typedef struct _MilskoClass* MilskoClass; + +#ifdef _MILSKO +#include + +typedef struct _Milsko* HMILSKO; + +typedef struct _Milsko { + HMILSKOLL lowlevel; + HMILSKO parent; + HMILSKO* children; + MilskoClass class; +}* HMILSKO; +#else +typedef void* HMILSKO; +#endif + +typedef struct _MilskoClass { +}* MilskoClass, MilskoClassRec; + #endif diff --git a/src/core.c b/src/core.c index c1ee24e..69c1e08 100644 --- a/src/core.c +++ b/src/core.c @@ -8,10 +8,10 @@ HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsi h->parent = parent; h->children = NULL; - h->lowlevel = MilskoLLCreate(parent->lowlevel, x, y, width, height); + h->lowlevel = MilskoLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height); h->class = class; - arrput(parent->children, h); + if(parent != NULL) arrput(parent->children, h); return h; } @@ -40,3 +40,22 @@ void MilskoDestroyWidget(HMILSKO handle) { MilskoLLDestroy(handle->lowlevel); free(handle); } + +MILSKODECL void MilskoStep(HMILSKO handle){ + MilskoLLNextEvent(handle->lowlevel); +} + +MILSKODECL int MilskoPending(HMILSKO handle){ + int i; + for(i = 0; i < arrlen(handle->children); i++){ + if(MilskoPending(handle->children[i])) return 1; + } + return MilskoLLPending(handle->lowlevel); +} + +MILSKODECL void MilskoLoop(HMILSKO handle){ + while(1){ + MilskoStep(handle); + MilskoLLSleep(10); + } +} diff --git a/src/window.c b/src/window.c new file mode 100644 index 0000000..333c5e3 --- /dev/null +++ b/src/window.c @@ -0,0 +1,6 @@ +/* $Id$ */ +#include + +MilskoClassRec MilskoWindowClassRec = { +}; +MilskoClass MilskoWindowClass = &MilskoWindowClassRec; diff --git a/src/x11.c b/src/x11.c index 2c309fe..3f4a611 100644 --- a/src/x11.c +++ b/src/x11.c @@ -88,3 +88,7 @@ void MilskoLLNextEvent(HMILSKOLL handle) { if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) { } } + +void MilskoLLSleep(int ms){ + usleep(ms * 1000); +}