mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-10 19:33:28 +00:00
things
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@18 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -7,12 +7,15 @@
|
|||||||
|
|
||||||
MILSKODECL HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsigned int width, unsigned int height);
|
MILSKODECL HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsigned int width, unsigned int height);
|
||||||
MILSKODECL void MilskoDestroyWidget(HMILSKO handle);
|
MILSKODECL void MilskoDestroyWidget(HMILSKO handle);
|
||||||
MILSKODECL void MilskoLoop(HMILSKO handle);
|
|
||||||
MILSKODECL void MilskoStep(HMILSKO handle);
|
|
||||||
MILSKODECL int MilskoPending(HMILSKO handle);
|
|
||||||
|
|
||||||
MILSKODECL void MilskoSetInteger(HMILSKO handle, const char* key, int n);
|
MILSKODECL void MilskoLoop(HMILSKO handle);
|
||||||
MILSKODECL void MilskoSetText(HMILSKO handle, const char* key, const char* value);
|
MILSKODECL void MilskoStep(HMILSKO handle);
|
||||||
MILSKODECL void MilskoApply(HMILSKO handle, ...);
|
MILSKODECL int MilskoPending(HMILSKO 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, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ typedef struct _MilskoPoint {
|
|||||||
int y;
|
int y;
|
||||||
} MilskoPoint;
|
} MilskoPoint;
|
||||||
|
|
||||||
|
typedef struct _MilskoRect {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int height;
|
||||||
|
} MilskoRect;
|
||||||
|
|
||||||
typedef struct _MilskoTextKeyValue {
|
typedef struct _MilskoTextKeyValue {
|
||||||
char* key;
|
char* key;
|
||||||
char* value;
|
char* value;
|
||||||
@@ -40,6 +47,11 @@ typedef void* HMILSKO;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct _MilskoClass {
|
typedef struct _MilskoClass {
|
||||||
|
void* opaque;
|
||||||
|
void (*create)(HMILSKO handle);
|
||||||
|
void (*destroy)(HMILSKO handle);
|
||||||
|
void (*draw)(HMILSKO handle);
|
||||||
|
void (*click)(HMILSKO handle);
|
||||||
} *MilskoClass, MilskoClassRec;
|
} *MilskoClass, MilskoClassRec;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
28
src/core.c
28
src/core.c
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include "stb_ds.h"
|
#include "stb_ds.h"
|
||||||
|
|
||||||
|
#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 MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsigned int width, unsigned int height) {
|
||||||
HMILSKO h = malloc(sizeof(*h));
|
HMILSKO h = malloc(sizeof(*h));
|
||||||
|
|
||||||
@@ -19,12 +22,16 @@ HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsi
|
|||||||
shdefault(h->text, NULL);
|
shdefault(h->text, NULL);
|
||||||
shdefault(h->integer, -1);
|
shdefault(h->integer, -1);
|
||||||
|
|
||||||
|
Dispatch(h, create);
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilskoDestroyWidget(HMILSKO handle) {
|
void MilskoDestroyWidget(HMILSKO handle) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
Dispatch(handle, destroy);
|
||||||
|
|
||||||
if(handle->children != NULL) {
|
if(handle->children != NULL) {
|
||||||
for(i = 0; i < arrlen(handle->children); i++) {
|
for(i = 0; i < arrlen(handle->children); i++) {
|
||||||
if(handle->children[i] == handle) {
|
if(handle->children[i] == handle) {
|
||||||
@@ -105,6 +112,27 @@ void MilskoSetText(HMILSKO handle, const char* key, const char* value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MilskoGetInteger(HMILSKO 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;
|
||||||
|
|
||||||
|
MilskoLLGetXYWH(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;
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return shget(handle->integer, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* MilskoGetText(HMILSKO handle, const char* key) {
|
||||||
|
return shget(handle->text, key);
|
||||||
|
}
|
||||||
|
|
||||||
void MilskoApply(HMILSKO handle, ...) {
|
void MilskoApply(HMILSKO handle, ...) {
|
||||||
va_list va;
|
va_list va;
|
||||||
char* key;
|
char* key;
|
||||||
|
|||||||
10
src/window.c
10
src/window.c
@@ -1,5 +1,11 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#include <Milsko/Milsko.h>
|
#include <Milsko/Milsko.h>
|
||||||
|
|
||||||
MilskoClassRec MilskoWindowClassRec = {};
|
MilskoClassRec MilskoWindowClassRec = {
|
||||||
MilskoClass MilskoWindowClass = &MilskoWindowClassRec;
|
NULL, /* opaque */
|
||||||
|
NULL, /* create */
|
||||||
|
NULL, /* destroy */
|
||||||
|
NULL, /* draw */
|
||||||
|
NULL /* click */
|
||||||
|
};
|
||||||
|
MilskoClass MilskoWindowClass = &MilskoWindowClassRec;
|
||||||
|
|||||||
Reference in New Issue
Block a user