mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-07 09:59:45 +00:00
name
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@33 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
#include <Milsko/Milsko.h>
|
#include <Milsko/Milsko.h>
|
||||||
|
|
||||||
|
void handler(MilskoWidget handle){
|
||||||
|
printf("hello world!\n");
|
||||||
|
}
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 400, 400);
|
MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 400, 400);
|
||||||
MilskoWidget button = MilskoCreateWidget(MilskoButtonClass, "button", window, 50, 50, 300, 300);
|
MilskoWidget button = MilskoCreateWidget(MilskoButtonClass, "button", window, 50, 50, 300, 300);
|
||||||
@@ -10,5 +14,9 @@ int main(){
|
|||||||
MilskoNtitle, "hello world",
|
MilskoNtitle, "hello world",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
MilskoApply(button,
|
||||||
|
MilskoNactivateHandler, handler,
|
||||||
|
NULL);
|
||||||
|
|
||||||
MilskoLoop(window);
|
MilskoLoop(window);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
#include <Milsko/MachDep.h>
|
#include <Milsko/MachDep.h>
|
||||||
#include <Milsko/TypeDefs.h>
|
#include <Milsko/TypeDefs.h>
|
||||||
|
|
||||||
|
#define MilskoDispatch(x, y) \
|
||||||
|
if(x->class != NULL && x->class->y != NULL) x->class->y(x)
|
||||||
|
|
||||||
MILSKODECL MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height);
|
MILSKODECL MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height);
|
||||||
MILSKODECL void MilskoDestroyWidget(MilskoWidget handle);
|
MILSKODECL void MilskoDestroyWidget(MilskoWidget handle);
|
||||||
|
|
||||||
@@ -14,8 +17,11 @@ MILSKODECL int MilskoPending(MilskoWidget handle);
|
|||||||
|
|
||||||
MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
|
MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
|
||||||
MILSKODECL void MilskoSetText(MilskoWidget handle, const char* key, const char* value);
|
MILSKODECL void MilskoSetText(MilskoWidget handle, const char* key, const char* value);
|
||||||
|
MILSKODECL void MilskoSetHandler(MilskoWidget handle, const char* key, MilskoHandler value);
|
||||||
MILSKODECL int MilskoGetInteger(MilskoWidget handle, const char* key);
|
MILSKODECL int MilskoGetInteger(MilskoWidget handle, const char* key);
|
||||||
MILSKODECL const char* MilskoGetText(MilskoWidget handle, const char* key);
|
MILSKODECL const char* MilskoGetText(MilskoWidget handle, const char* key);
|
||||||
|
MILSKODECL MilskoHandler MilskoGetHandler(MilskoWidget handle, const char* key);
|
||||||
|
MILSKODECL void MilskoDispatchHandler(MilskoWidget handle, const char* key);
|
||||||
MILSKODECL void MilskoSetDefault(MilskoWidget handle);
|
MILSKODECL void MilskoSetDefault(MilskoWidget handle);
|
||||||
MILSKODECL void MilskoApply(MilskoWidget handle, ...);
|
MILSKODECL void MilskoApply(MilskoWidget handle, ...);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec;
|
|||||||
struct _MilskoLL {
|
struct _MilskoLL {
|
||||||
void* user;
|
void* user;
|
||||||
|
|
||||||
void (*draw)(MilskoLL handle);
|
MilskoLLHandler handler;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MilskoColor {
|
struct _MilskoColor {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <Milsko/MachDep.h>
|
#include <Milsko/MachDep.h>
|
||||||
|
|
||||||
typedef struct _MilskoLLCallback *MilskoLLCallback, MilskoLLCallbackRec;
|
typedef struct _MilskoLLHandler *MilskoLLHandler, MilskoLLHandlerRec;
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
typedef struct _MilskoLL * MilskoLL, MilskoLLRec;
|
typedef struct _MilskoLL * MilskoLL, MilskoLLRec;
|
||||||
typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec;
|
typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec;
|
||||||
@@ -24,9 +24,9 @@ typedef void* MilskoLLColor;
|
|||||||
#include <Milsko/TypeDefs.h>
|
#include <Milsko/TypeDefs.h>
|
||||||
|
|
||||||
#define MilskoLLDispatch(x, y) \
|
#define MilskoLLDispatch(x, y) \
|
||||||
if(x->callback != NULL && x->callback->y != NULL) x->callback->y(x)
|
if(x->handler != NULL && x->handler->y != NULL) x->handler->y(x)
|
||||||
|
|
||||||
struct _MilskoLLCallback {
|
struct _MilskoLLHandler {
|
||||||
void (*draw)(MilskoLL handle);
|
void (*draw)(MilskoLL handle);
|
||||||
void (*up)(MilskoLL handle);
|
void (*up)(MilskoLL handle);
|
||||||
void (*down)(MilskoLL handle);
|
void (*down)(MilskoLL handle);
|
||||||
|
|||||||
@@ -10,4 +10,6 @@
|
|||||||
#define MilskoNtitle "Stitle"
|
#define MilskoNtitle "Stitle"
|
||||||
#define MilskoNbackground "Sbackground"
|
#define MilskoNbackground "Sbackground"
|
||||||
|
|
||||||
|
#define MilskoNactivateHandler "Cactivate"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
typedef struct _MilskoClass * MilskoClass, MilskoClassRec;
|
typedef struct _MilskoClass * MilskoClass, MilskoClassRec;
|
||||||
typedef struct _MilskoPoint MilskoPoint;
|
typedef struct _MilskoPoint MilskoPoint;
|
||||||
typedef struct _MilskoRect MilskoRect;
|
typedef struct _MilskoRect MilskoRect;
|
||||||
typedef struct _MilskoTextKeyValue MilskoTextKeyValue;
|
|
||||||
typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue;
|
typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue;
|
||||||
|
typedef struct _MilskoTextKeyValue MilskoTextKeyValue;
|
||||||
|
typedef struct _MilskoHandlerKeyValue MilskoHandlerKeyValue;
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
typedef struct _MilskoWidget *MilskoWidget, MilskoWidgetRec;
|
typedef struct _MilskoWidget *MilskoWidget, MilskoWidgetRec;
|
||||||
#else
|
#else
|
||||||
@@ -20,9 +21,6 @@ typedef void (*MilskoHandler)(MilskoWidget handle);
|
|||||||
#include <Milsko/LowLevel.h>
|
#include <Milsko/LowLevel.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MilskoDispatch(x, y) \
|
|
||||||
if(x->class != NULL && x->class->y != NULL) x->class->y(x)
|
|
||||||
|
|
||||||
struct _MilskoPoint {
|
struct _MilskoPoint {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
@@ -45,6 +43,11 @@ struct _MilskoIntegerKeyValue {
|
|||||||
int value;
|
int value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _MilskoHandlerKeyValue {
|
||||||
|
char* key;
|
||||||
|
MilskoHandler value;
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
struct _MilskoWidget {
|
struct _MilskoWidget {
|
||||||
char* name;
|
char* name;
|
||||||
@@ -56,8 +59,9 @@ struct _MilskoWidget {
|
|||||||
|
|
||||||
int pressed;
|
int pressed;
|
||||||
|
|
||||||
MilskoTextKeyValue* text;
|
|
||||||
MilskoIntegerKeyValue* integer;
|
MilskoIntegerKeyValue* integer;
|
||||||
|
MilskoTextKeyValue* text;
|
||||||
|
MilskoHandlerKeyValue* handler;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ struct _MilskoLL {
|
|||||||
Colormap colormap;
|
Colormap colormap;
|
||||||
void* user;
|
void* user;
|
||||||
|
|
||||||
MilskoLLCallback callback;
|
MilskoLLHandler handler;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MilskoLLColor {
|
struct _MilskoLLColor {
|
||||||
|
|||||||
@@ -18,11 +18,15 @@ static void draw(MilskoWidget handle) {
|
|||||||
MilskoDrawRect(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)));
|
MilskoDrawRect(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void click(MilskoWidget handle) {
|
||||||
|
MilskoDispatchHandler(handle, MilskoNactivateHandler);
|
||||||
|
}
|
||||||
|
|
||||||
MilskoClassRec MilskoButtonClassRec = {
|
MilskoClassRec MilskoButtonClassRec = {
|
||||||
NULL, /* opaque */
|
NULL, /* opaque */
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL /* click */
|
click /* click */
|
||||||
};
|
};
|
||||||
MilskoClass MilskoButtonClass = &MilskoButtonClassRec;
|
MilskoClass MilskoButtonClass = &MilskoButtonClassRec;
|
||||||
|
|||||||
25
src/core.c
25
src/core.c
@@ -33,17 +33,18 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge
|
|||||||
h->pressed = 0;
|
h->pressed = 0;
|
||||||
|
|
||||||
h->lowlevel->user = h;
|
h->lowlevel->user = h;
|
||||||
h->lowlevel->callback->draw = lldrawhandler;
|
h->lowlevel->handler->draw = lldrawhandler;
|
||||||
h->lowlevel->callback->up = lluphandler;
|
h->lowlevel->handler->up = lluphandler;
|
||||||
h->lowlevel->callback->down = lldownhandler;
|
h->lowlevel->handler->down = lldownhandler;
|
||||||
|
|
||||||
if(parent != NULL) arrput(parent->children, h);
|
if(parent != NULL) arrput(parent->children, h);
|
||||||
|
|
||||||
sh_new_strdup(h->text);
|
sh_new_strdup(h->text);
|
||||||
sh_new_strdup(h->integer);
|
sh_new_strdup(h->integer);
|
||||||
|
|
||||||
shdefault(h->text, NULL);
|
|
||||||
shdefault(h->integer, -1);
|
shdefault(h->integer, -1);
|
||||||
|
shdefault(h->text, NULL);
|
||||||
|
shdefault(h->handler, NULL);
|
||||||
|
|
||||||
MilskoDispatch(h, create);
|
MilskoDispatch(h, create);
|
||||||
|
|
||||||
@@ -141,6 +142,10 @@ void MilskoSetText(MilskoWidget handle, const char* key, const char* value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MilskoSetHandler(MilskoWidget handle, const char* key, MilskoHandler value) {
|
||||||
|
shput(handle->handler, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
int MilskoGetInteger(MilskoWidget 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;
|
||||||
@@ -162,6 +167,10 @@ const char* MilskoGetText(MilskoWidget handle, const char* key) {
|
|||||||
return shget(handle->text, key);
|
return shget(handle->text, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MilskoHandler MilskoGetHandler(MilskoWidget handle, const char* key) {
|
||||||
|
return shget(handle->handler, key);
|
||||||
|
}
|
||||||
|
|
||||||
void MilskoApply(MilskoWidget handle, ...) {
|
void MilskoApply(MilskoWidget handle, ...) {
|
||||||
va_list va;
|
va_list va;
|
||||||
char* key;
|
char* key;
|
||||||
@@ -174,6 +183,9 @@ void MilskoApply(MilskoWidget handle, ...) {
|
|||||||
} else if(key[0] == 'S') {
|
} else if(key[0] == 'S') {
|
||||||
char* t = va_arg(va, char*);
|
char* t = va_arg(va, char*);
|
||||||
MilskoSetText(handle, key, t);
|
MilskoSetText(handle, key, t);
|
||||||
|
} else if(key[0] == 'C') {
|
||||||
|
MilskoHandler h = va_arg(va, MilskoHandler);
|
||||||
|
MilskoSetHandler(handle, key, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@@ -182,3 +194,8 @@ void MilskoApply(MilskoWidget handle, ...) {
|
|||||||
void MilskoSetDefault(MilskoWidget handle) {
|
void MilskoSetDefault(MilskoWidget handle) {
|
||||||
MilskoSetText(handle, MilskoNbackground, MilskoDefaultBackground);
|
MilskoSetText(handle, MilskoNbackground, MilskoDefaultBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MilskoDispatchHandler(MilskoWidget handle, const char* key) {
|
||||||
|
MilskoHandler handler = MilskoGetHandler(handle, key);
|
||||||
|
if(handler != NULL) handler(handle);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
#include <Milsko/Milsko.h>
|
#include <Milsko/Milsko.h>
|
||||||
|
|
||||||
void MilskoLLCreateCommon(MilskoLL handle) {
|
void MilskoLLCreateCommon(MilskoLL handle) {
|
||||||
handle->callback = malloc(sizeof(*handle->callback));
|
handle->handler = malloc(sizeof(*handle->handler));
|
||||||
memset(handle->callback, 0, sizeof(*handle->callback));
|
memset(handle->handler, 0, sizeof(*handle->handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilskoLLDestroyCommon(MilskoLL handle) {
|
void MilskoLLDestroyCommon(MilskoLL handle) {
|
||||||
free(handle->callback);
|
free(handle->handler);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user