diff --git a/include/Milsko/Core.h b/include/Milsko/Core.h index 3d009ed..a82f5dc 100644 --- a/include/Milsko/Core.h +++ b/include/Milsko/Core.h @@ -4,6 +4,7 @@ #include #include +#include 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); @@ -12,6 +13,8 @@ MILSKODECL void MilskoLoop(MilskoWidget handle); MILSKODECL void MilskoStep(MilskoWidget handle); MILSKODECL int MilskoPending(MilskoWidget handle); +MILSKODECL MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text); + 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); diff --git a/include/Milsko/Default.h b/include/Milsko/Default.h new file mode 100644 index 0000000..501458d --- /dev/null +++ b/include/Milsko/Default.h @@ -0,0 +1,7 @@ +/* $Id$ */ +#ifndef __MILSKO_DEFAULT_H__ +#define __MILSKO_DEFAULT_H__ + +#define MILSKO_BACKGROUND "#ddd" + +#endif diff --git a/include/Milsko/Milsko.h b/include/Milsko/Milsko.h index c123572..d31f7d1 100644 --- a/include/Milsko/Milsko.h +++ b/include/Milsko/Milsko.h @@ -7,6 +7,7 @@ #include #include #include +#include #include diff --git a/include/Milsko/StringDefs.h b/include/Milsko/StringDefs.h index b2c5ec8..2ef6562 100644 --- a/include/Milsko/StringDefs.h +++ b/include/Milsko/StringDefs.h @@ -8,5 +8,6 @@ #define MilskoNheight "Iheight" #define MilskoNtitle "Stitle" +#define MilskoNbackground "Sbackground" #endif diff --git a/include/Milsko/TypeDefs.h b/include/Milsko/TypeDefs.h index afb0ecb..04c79f8 100644 --- a/include/Milsko/TypeDefs.h +++ b/include/Milsko/TypeDefs.h @@ -56,6 +56,9 @@ typedef struct _MilskoClass { MilskoHandler destroy; MilskoHandler draw; MilskoHandler click; + + MilskoTextKeyValue* text; + MilskoIntegerKeyValue* integer; } *MilskoClass, MilskoClassRec; #endif diff --git a/src/core.c b/src/core.c index b2d2635..869b6cf 100644 --- a/src/core.c +++ b/src/core.c @@ -162,3 +162,44 @@ void MilskoApply(MilskoWidget handle, ...) { } va_end(va); } + +static int hex(const char* txt, int len) { + int i; + int r = 0; + for(i = 0; i < len; i++) { + char c = txt[i]; + int n = 0; + if('a' <= c && c <= 'f') { + n = c - 'a' + 10; + } else if('A' <= c && c <= 'F') { + n = c - 'A' + 10; + } else if('0' <= c && c <= '9') { + n = c - '0'; + } + r = r << 4; + r |= n; + } + return r; +} + +MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text) { + int r = 0; + int g = 0; + int b = 0; + + if(text[0] == '#' && strlen(text) == 4) { + r = hex(text + 1, 1); + g = hex(text + 2, 1); + b = hex(text + 3, 1); + + r |= r << 4; + g |= g << 4; + b |= b << 4; + } else if(text[0] == '#' && strlen(text) == 7) { + r = hex(text + 1, 2); + g = hex(text + 3, 2); + b = hex(text + 5, 2); + } + + return MilskoLLAllocColor(handle->lowlevel, r, g, b); +} diff --git a/src/window.c b/src/window.c index f10e3a8..10d6e24 100644 --- a/src/window.c +++ b/src/window.c @@ -1,8 +1,12 @@ /* $Id$ */ #include +static void create(MilskoWidget handle) { + MilskoSetText(handle, MilskoNbackground, MILSKO_BACKGROUND); +} + static void draw(MilskoWidget handle) { - MilskoLLColor c = MilskoLLAllocColor(handle->lowlevel, 255, 0, 0); + MilskoLLColor c = MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)); MilskoPoint p[4]; p[0].x = 0; @@ -23,10 +27,10 @@ static void draw(MilskoWidget handle) { } MilskoClassRec MilskoWindowClassRec = { - NULL, /* opaque */ - NULL, /* create */ - NULL, /* destroy */ - draw, /* draw */ - NULL /* click */ + NULL, /* opaque */ + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL /* click */ }; MilskoClass MilskoWindowClass = &MilskoWindowClassRec;