diff --git a/GNUmakefile b/GNUmakefile index fdc9003..5041b2b 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -16,7 +16,7 @@ E_LDFLAGS = $(LDFLAGS) -Lsrc E_LIBS = $(LIBS) -lMw L_OBJS = src/ds.o src/core.o src/default.o src/draw.o src/lowlevel.o src/font.o -L_OBJS += src/window.o src/button.o src/opengl.o +L_OBJS += src/window.o src/button.o src/opengl.o src/frame.o ifeq ($(TARGET),NetBSD) CFLAGS += -I/usr/X11R7/include -I/usr/pkg/include diff --git a/examples/example.c b/examples/example.c index 8f4c25f..f17ebfa 100644 --- a/examples/example.c +++ b/examples/example.c @@ -1,5 +1,4 @@ /* $Id$ */ - #include MwWidget window, button, button2, button3, button4; diff --git a/examples/opengl.c b/examples/opengl.c index e15fb57..fa7a283 100644 --- a/examples/opengl.c +++ b/examples/opengl.c @@ -1,5 +1,4 @@ /* $Id$ */ - #include #include diff --git a/examples/rotate.c b/examples/rotate.c index 6bbd06c..49097c1 100644 --- a/examples/rotate.c +++ b/examples/rotate.c @@ -1,6 +1,5 @@ /* $Id$ */ /* this demo does not work well on windows */ - #include #include diff --git a/include/Mw/Draw.h b/include/Mw/Draw.h index 79c7f88..ff018b2 100644 --- a/include/Mw/Draw.h +++ b/include/Mw/Draw.h @@ -14,6 +14,7 @@ MWDECL MwLLColor MwParseColor(MwWidget handle, const char* text); MWDECL void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color); MWDECL void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert); +MWDECL void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border); MWDECL void MwDrawText(MwWidget handle, MwPoint* point, const char* text, MwLLColor color); #ifdef __cplusplus diff --git a/include/Mw/Frame.h b/include/Mw/Frame.h new file mode 100644 index 0000000..3e635b2 --- /dev/null +++ b/include/Mw/Frame.h @@ -0,0 +1,18 @@ +/* $Id$ */ +#ifndef __MW_FRAME_H__ +#define __MW_FRAME_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +MWDECL MwClass MwFrameClass; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/Mw/Milsko.h b/include/Mw/Milsko.h index be88652..6be505e 100644 --- a/include/Mw/Milsko.h +++ b/include/Mw/Milsko.h @@ -13,6 +13,7 @@ #include #include +#include #include #endif diff --git a/src/draw.c b/src/draw.c index 8269149..1598cb1 100644 --- a/src/draw.c +++ b/src/draw.c @@ -61,49 +61,54 @@ void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) { } void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) { + const int border = 2; + + MwDrawFrameEx(handle, rect, color, invert, border); +} + +void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) { MwPoint p[6]; const int diff = 128; - const int border = 2; MwLLColor darker = MwLLAllocColor(handle->lowlevel, color->red - diff, color->green - diff, color->blue - diff); MwLLColor lighter = MwLLAllocColor(handle->lowlevel, color->red + diff, color->green + diff, color->blue + diff); - p[0].x = 0; - p[0].y = 0; + p[0].x = rect->x; + p[0].y = rect->y; - p[1].x = 0 + rect->width; - p[1].y = 0; + p[1].x = rect->x + rect->width; + p[1].y = rect->y; - p[2].x = 0 + rect->width - border; - p[2].y = 0 + border; + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + border; - p[3].x = 0 + border; - p[3].y = 0 + border; + p[3].x = rect->x + border; + p[3].y = rect->y + border; - p[4].x = 0 + border; - p[4].y = 0 + rect->height - border; + p[4].x = rect->x + border; + p[4].y = rect->y + rect->height - border; - p[5].x = 0; - p[5].y = 0 + rect->height; + p[5].x = rect->x; + p[5].y = rect->y + rect->height; MwLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter); - p[0].x = 0 + rect->width; - p[0].y = 0; + p[0].x = rect->x + rect->width; + p[0].y = rect->y; - p[1].x = 0 + rect->width - border; - p[1].y = 0 + border; + p[1].x = rect->x + rect->width - border; + p[1].y = rect->y + border; - p[2].x = 0 + rect->width - border; - p[2].y = 0 + rect->height - border; + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + rect->height - border; - p[3].x = 0 + border; - p[3].y = 0 + rect->height - border; + p[3].x = rect->x + border; + p[3].y = rect->y + rect->height - border; - p[4].x = 0; - p[4].y = 0 + rect->height; + p[4].x = rect->x; + p[4].y = rect->y + rect->height; - p[5].x = 0 + rect->width; - p[5].y = 0 + rect->height; + p[5].x = rect->x + rect->width; + p[5].y = rect->y + rect->height; MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); @@ -137,6 +142,6 @@ void MwDrawText(MwWidget handle, MwPoint* point, const char* text, MwLLColor col } } } - sx += 8 * sc; + sx += fw * sc; } } diff --git a/src/frame.c b/src/frame.c new file mode 100644 index 0000000..0fc1889 --- /dev/null +++ b/src/frame.c @@ -0,0 +1,30 @@ +/* $Id$ */ +#include + +static void create(MwWidget handle) { + MwSetDefault(handle); +} + +static void draw(MwWidget handle) { + MwRect r; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + + r.x = 0; + r.y = 0; + r.width = MwGetInteger(handle, MwNwidth); + r.height = MwGetInteger(handle, MwNheight); + + MwDrawFrameEx(handle, &r, base, 1, 1); + MwDrawFrameEx(handle, &r, base, 0, 1); + MwDrawRect(handle, &r, base); + + MwLLFreeColor(base); +} + +MwClassRec MwFrameClassRec = { + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL /* click */ +}; +MwClass MwFrameClass = &MwFrameClassRec;