From c684c75526f708c0ee5e284e91f6ca69286b8394 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 28 Sep 2025 13:46:18 +0000 Subject: [PATCH] h git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@26 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 4 +-- example.c | 4 +-- include/Milsko/Button.h | 9 ++++++ include/Milsko/Core.h | 3 -- include/Milsko/Draw.h | 13 +++++++++ include/Milsko/Milsko.h | 2 ++ src/button.c | 17 ++++++++++++ src/core.c | 41 --------------------------- src/draw.c | 61 +++++++++++++++++++++++++++++++++++++++++ src/window.c | 19 ++++--------- 10 files changed, 112 insertions(+), 61 deletions(-) create mode 100644 include/Milsko/Button.h create mode 100644 include/Milsko/Draw.h create mode 100644 src/button.c create mode 100644 src/draw.c diff --git a/GNUmakefile b/GNUmakefile index 45a4533..e0f41a6 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -7,8 +7,8 @@ CFLAGS = -fPIC -Iinclude -D_MILSKO LDFLAGS = LIBS = -L_OBJS = src/ds.o src/core.o src/default.o -L_OBJS += src/window.o +L_OBJS = src/ds.o src/core.o src/default.o src/draw.o +L_OBJS += src/window.o src/button.o ifeq ($(TARGET),NetBSD) CFLAGS += -I/usr/X11R7/include -I/usr/pkg/include diff --git a/example.c b/example.c index 93c747e..f0f1a62 100644 --- a/example.c +++ b/example.c @@ -3,10 +3,10 @@ #include int main(){ - MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 640, 480); + MilskoWidget window = MilskoCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 400, 400); + MilskoWidget button = MilskoCreateWidget(MilskoButtonClass, "button", window, 50, 50, 300, 300); MilskoApply(window, - MilskoNwidth, 480 * 2, MilskoNtitle, "hello world", NULL); diff --git a/include/Milsko/Button.h b/include/Milsko/Button.h new file mode 100644 index 0000000..ca6445e --- /dev/null +++ b/include/Milsko/Button.h @@ -0,0 +1,9 @@ +/* $Id$ */ +#ifndef __MILSKO_BUTTON_H__ +#define __MILSKO_BUTTON_H__ + +#include + +MILSKODECL MilskoClass MilskoButtonClass; + +#endif diff --git a/include/Milsko/Core.h b/include/Milsko/Core.h index a82f5dc..3d009ed 100644 --- a/include/Milsko/Core.h +++ b/include/Milsko/Core.h @@ -4,7 +4,6 @@ #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); @@ -13,8 +12,6 @@ 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/Draw.h b/include/Milsko/Draw.h new file mode 100644 index 0000000..5319496 --- /dev/null +++ b/include/Milsko/Draw.h @@ -0,0 +1,13 @@ +/* $Id$ */ +#ifndef __MILSKO_DRAW_H__ +#define __MILSKO_DRAW_H__ + +#include +#include +#include + +MILSKODECL MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text); + +MILSKODECL void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color); + +#endif diff --git a/include/Milsko/Milsko.h b/include/Milsko/Milsko.h index d31f7d1..082bf62 100644 --- a/include/Milsko/Milsko.h +++ b/include/Milsko/Milsko.h @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #endif diff --git a/src/button.c b/src/button.c new file mode 100644 index 0000000..204c9cc --- /dev/null +++ b/src/button.c @@ -0,0 +1,17 @@ +/* $Id$ */ +#include + +static void create(MilskoWidget handle) { +} + +static void draw(MilskoWidget handle) { +} + +MilskoClassRec MilskoButtonClassRec = { + NULL, /* opaque */ + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL /* click */ +}; +MilskoClass MilskoButtonClass = &MilskoButtonClassRec; diff --git a/src/core.c b/src/core.c index 869b6cf..b2d2635 100644 --- a/src/core.c +++ b/src/core.c @@ -162,44 +162,3 @@ 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/draw.c b/src/draw.c new file mode 100644 index 0000000..1275499 --- /dev/null +++ b/src/draw.c @@ -0,0 +1,61 @@ +/* $Id$ */ +#include + +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); +} + +void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color) { + MilskoPoint p[4]; + + 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; + p[2].y = rect->y + rect->height; + + p[3].x = rect->x; + p[3].y = rect->y + rect->height; + + MilskoLLPolygon(handle->lowlevel, p, 4, color); +} diff --git a/src/window.c b/src/window.c index fb46d23..68600ce 100644 --- a/src/window.c +++ b/src/window.c @@ -7,21 +7,14 @@ static void create(MilskoWidget handle) { static void draw(MilskoWidget handle) { MilskoLLColor c = MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)); - MilskoPoint p[4]; + MilskoRect r; - p[0].x = 0; - p[0].y = 0; + r.x = 0; + r.y = 0; + r.width = MilskoGetInteger(handle, MilskoNwidth); + r.height = MilskoGetInteger(handle, MilskoNheight); - p[1].x = MilskoGetInteger(handle, MilskoNwidth); - p[1].y = 0; - - p[2].x = MilskoGetInteger(handle, MilskoNwidth); - p[2].y = MilskoGetInteger(handle, MilskoNheight); - - p[3].x = 0; - p[3].y = MilskoGetInteger(handle, MilskoNheight); - - MilskoLLPolygon(handle->lowlevel, p, 4, c); + MilskoDrawRect(handle, &r, c); MilskoLLFreeColor(c); }