diff --git a/include/Milsko/Draw.h b/include/Milsko/Draw.h index 5319496..2177a22 100644 --- a/include/Milsko/Draw.h +++ b/include/Milsko/Draw.h @@ -9,5 +9,6 @@ MILSKODECL MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text); MILSKODECL void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color); +MILSKODECL void MilskoDrawFrame(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color, int invert); #endif diff --git a/src/button.c b/src/button.c index 5e4a4c5..1289dad 100644 --- a/src/button.c +++ b/src/button.c @@ -6,7 +6,15 @@ static void create(MilskoWidget handle) { } static void draw(MilskoWidget handle) { - MilskoPoint p[6]; + MilskoRect r; + + r.x = 0; + r.y = 0; + r.width = MilskoGetInteger(handle, MilskoNwidth); + r.height = MilskoGetInteger(handle, MilskoNheight); + + MilskoDrawFrame(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)), 0); + MilskoDrawRect(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground))); } MilskoClassRec MilskoButtonClassRec = { diff --git a/src/core.c b/src/core.c index 6d4c7f7..b03d3a4 100644 --- a/src/core.c +++ b/src/core.c @@ -77,6 +77,8 @@ void MilskoDestroyWidget(MilskoWidget handle) { } void MilskoStep(MilskoWidget handle) { + int i; + for(i = 0; i < arrlen(handle->children); i++) MilskoStep(handle->children[i]); MilskoLLNextEvent(handle->lowlevel); } @@ -121,6 +123,8 @@ void MilskoSetText(MilskoWidget handle, const char* key, const char* value) { char* v = malloc(strlen(value) + 1); strcpy(v, value); + if(shgeti(handle->text, key) != -1) free(shget(handle->text, key)); + shput(handle->text, key, v); } } diff --git a/src/draw.c b/src/draw.c index 1275499..162235e 100644 --- a/src/draw.c +++ b/src/draw.c @@ -59,3 +59,59 @@ void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color) MilskoLLPolygon(handle->lowlevel, p, 4, color); } + +void MilskoDrawFrame(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color, int invert) { + MilskoPoint p[6]; + const int diff = 128; + const int border = 4; + MilskoLLColor darker = MilskoLLAllocColor(handle->lowlevel, color->red - diff, color->green - diff, color->blue - diff); + MilskoLLColor lighter = MilskoLLAllocColor(handle->lowlevel, color->red + diff, color->green + diff, color->blue + diff); + + p[0].x = rect->x; + p[0].y = rect->y; + + p[1].x = rect->x + rect->width; + p[1].y = rect->y; + + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + border; + + p[3].x = rect->x + border; + p[3].y = rect->y + border; + + p[4].x = rect->x + border; + p[4].y = rect->y + rect->height - border; + + p[5].x = rect->x; + p[5].y = rect->y + rect->height; + + MilskoLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter); + + p[0].x = rect->x + rect->width; + p[0].y = rect->y; + + p[1].x = rect->x + rect->width - border; + p[1].y = rect->y + border; + + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + rect->height - border; + + p[3].x = rect->x + border; + p[3].y = rect->y + rect->height - border; + + p[4].x = rect->x; + p[4].y = rect->y + rect->height; + + p[5].x = rect->x + rect->height; + p[5].y = rect->y + rect->height; + + MilskoLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); + + MilskoLLFreeColor(lighter); + MilskoLLFreeColor(darker); + + rect->x += border; + rect->y += border; + rect->width -= border * 2; + rect->height -= border * 2; +} diff --git a/src/x11.c b/src/x11.c index 3c55697..fc529b1 100644 --- a/src/x11.c +++ b/src/x11.c @@ -57,6 +57,14 @@ void MilskoLLPolygon(MilskoLL handle, MilskoPoint* points, int points_count, Mil MilskoLLColor MilskoLLAllocColor(MilskoLL handle, int r, int g, int b) { MilskoLLColor c = malloc(sizeof(*c)); XColor xc; + + if(r > 255) r = 255; + if(g > 255) g = 255; + if(b > 255) b = 255; + if(r < 0) r = 0; + if(g < 0) g = 0; + if(b < 0) b = 0; + xc.red = 256 * r; xc.green = 256 * g; xc.blue = 256 * b;