From f57a402e6ef2eeb08ff3112a8b38dab3a7da9634 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 4 Oct 2025 17:28:33 +0000 Subject: [PATCH] better git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@164 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/Constants.h | 19 ++++ include/Mw/Draw.h | 1 - include/Mw/MachDep.h | 1 + src/draw.c | 227 +++++++++++++++++++++++++++++++++++++++-- src/widget/scrollbar.c | 4 +- src/widget/submenu.c | 17 +-- 6 files changed, 246 insertions(+), 23 deletions(-) create mode 100644 include/Mw/Constants.h diff --git a/include/Mw/Constants.h b/include/Mw/Constants.h new file mode 100644 index 0000000..4e056f5 --- /dev/null +++ b/include/Mw/Constants.h @@ -0,0 +1,19 @@ +/* $Id$ */ +/*! + * %file Mw/Constants.h + * %brief Constants + */ +#ifndef __MW_CONSTANTS_H__ +#define __MW_CONSTANTS_H__ + +/*! + * %brief Direction enumeration + */ +enum MwDIRECTION { + MwNORTH = 0, + MwSOUTH, + MwEAST, + MwWEST +}; + +#endif diff --git a/include/Mw/Draw.h b/include/Mw/Draw.h index d75b277..ccb4856 100644 --- a/include/Mw/Draw.h +++ b/include/Mw/Draw.h @@ -57,7 +57,6 @@ MWDECL void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int inve * %param rect Rectangle area * %param color Color * %param invert Invert the 3D border color or not - * %warning `rect` gets changed to the area of rectangle inside */ MWDECL void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction); diff --git a/include/Mw/MachDep.h b/include/Mw/MachDep.h index a9552ab..cb98e70 100644 --- a/include/Mw/MachDep.h +++ b/include/Mw/MachDep.h @@ -13,6 +13,7 @@ #include #include #include +#include #ifndef _WIN32 #include #include diff --git a/src/draw.c b/src/draw.c index 2e56e4a..c243c06 100644 --- a/src/draw.c +++ b/src/draw.c @@ -6,6 +6,8 @@ #define FontWidth 7 #define FontHeight 14 #define FontScale 1 +#define ColorDiff 128 +#define BorderWidth 2 static int hex(const char* txt, int len) { int i; @@ -82,16 +84,13 @@ 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); + MwDrawFrameEx(handle, rect, color, invert, BorderWidth); } void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) { MwPoint p[6]; - const int diff = 128; - 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); + MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); + MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff); p[0].x = rect->x; p[0].y = rect->y; @@ -142,6 +141,219 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i rect->height -= border * 2; } +void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) { + MwPoint p1[4], p2[4], p3[4], p4[3]; + const int border = BorderWidth * 2; + MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); + MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff); + + double deg = 30 + ((direction == MwEAST || direction == MwWEST) ? 30 : 0); + double c = cos(deg / 180 * M_PI); + double s = sin(deg / 180 * M_PI); + + if(direction == MwNORTH) { + p1[0].x = rect->x + rect->width / 2; + p1[0].y = rect->y; + + p1[1].x = rect->x; + p1[1].y = rect->y + rect->height; + + p1[2].x = rect->x + c * border; + p1[2].y = rect->y + rect->height - s * border; + + p1[3].x = rect->x + rect->width / 2; + p1[3].y = rect->y + border; + + p2[0].x = rect->x + rect->width / 2; + p2[0].y = rect->y; + + p2[1].x = rect->x + rect->width; + p2[1].y = rect->y + rect->height; + + p2[2].x = rect->x + rect->width - c * border; + p2[2].y = rect->y + rect->height - s * border; + + p2[3].x = rect->x + rect->width / 2; + p2[3].y = rect->y + border; + + p3[0].x = rect->x + c * border; + p3[0].y = rect->y + rect->height - s * border; + + p3[1].x = rect->x; + p3[1].y = rect->y + rect->height; + + p3[2].x = rect->x + rect->width; + p3[2].y = rect->y + rect->height; + + p3[3].x = rect->x + rect->width - c * border; + p3[3].y = rect->y + rect->height - s * border; + + MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter); + MwLLPolygon(handle->lowlevel, p2, 4, invert ? lighter : darker); + MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker); + + p4[0].x = rect->x + c * border; + p4[0].y = rect->y + rect->height - s * border; + + p4[1].x = rect->x + rect->width - c * border; + p4[1].y = rect->y + rect->height - s * border; + + p4[2].x = rect->x + rect->width / 2; + p4[2].y = rect->y + border; + } else if(direction == MwSOUTH) { + p1[0].x = rect->x; + p1[0].y = rect->y; + + p1[1].x = rect->x + c * border; + p1[1].y = rect->y + s * border; + + p1[2].x = rect->x + rect->width - c * border; + p1[2].y = rect->y + s * border; + + p1[3].x = rect->x + rect->width; + p1[3].y = rect->y; + + p2[0].x = rect->x; + p2[0].y = rect->y; + + p2[1].x = rect->x + c * border; + p2[1].y = rect->y + s * border; + + p2[2].x = rect->x + rect->width / 2; + p2[2].y = rect->y + rect->height - border; + + p2[3].x = rect->x + rect->width / 2; + p2[3].y = rect->y + rect->height; + + p3[0].x = rect->x + rect->width; + p3[0].y = rect->y; + + p3[1].x = rect->x + rect->width / 2; + p3[1].y = rect->y + rect->height; + + p3[2].x = rect->x + rect->width / 2; + p3[2].y = rect->y + rect->height - border; + + p3[3].x = rect->x + rect->width - c * border; + p3[3].y = rect->y + s * border; + + MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter); + MwLLPolygon(handle->lowlevel, p2, 4, invert ? darker : lighter); + MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker); + + p4[0].x = rect->x + c * border; + p4[0].y = rect->y + s * border; + + p4[1].x = rect->x + rect->width - c * border; + p4[1].y = rect->y + s * border; + + p4[2].x = rect->x + rect->width / 2; + p4[2].y = rect->y + rect->height - border; + } else if(direction == MwEAST) { + p1[0].x = rect->x; + p1[0].y = rect->y; + + p1[1].x = rect->x + c * border; + p1[1].y = rect->y + s * border; + + p1[2].x = rect->x + c * border; + p1[2].y = rect->y + rect->height - s * border; + + p1[3].x = rect->x; + p1[3].y = rect->y + rect->height; + + p2[0].x = rect->x; + p2[0].y = rect->y; + + p2[1].x = rect->x + rect->width; + p2[1].y = rect->y + rect->height / 2; + + p2[2].x = rect->x + rect->width - border; + p2[2].y = rect->y + rect->height / 2; + + p2[3].x = rect->x + c * border; + p2[3].y = rect->y + s * border; + + p3[0].x = rect->x + c * border; + p3[0].y = rect->y + rect->height - s * border; + + p3[1].x = rect->x; + p3[1].y = rect->y + rect->height; + + p3[2].x = rect->x + rect->width; + p3[2].y = rect->y + rect->height / 2; + + p3[3].x = rect->x + rect->width - border; + p3[3].y = rect->y + rect->height / 2; + + MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter); + MwLLPolygon(handle->lowlevel, p2, 4, invert ? darker : lighter); + MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker); + + p4[0].x = rect->x + rect->width - border; + p4[0].y = rect->y + rect->height / 2; + + p4[1].x = rect->x + c * border; + p4[1].y = rect->y + rect->height - s * border; + + p4[2].x = rect->x + c * border; + p4[2].y = rect->y + s * border; + } else if(direction == MwWEST) { + p1[0].x = rect->x; + p1[0].y = rect->y + rect->height / 2; + + p1[1].x = rect->x + border; + p1[1].y = rect->y + rect->height / 2; + + p1[2].x = rect->x + rect->width - c * border; + p1[2].y = rect->y + s * border; + + p1[3].x = rect->x + rect->width; + p1[3].y = rect->y; + + p2[0].x = rect->x; + p2[0].y = rect->y + rect->height / 2; + + p2[1].x = rect->x + border; + p2[1].y = rect->y + rect->height / 2; + + p2[2].x = rect->x + rect->width - c * border; + p2[2].y = rect->y + rect->height - s * border; + + p2[3].x = rect->x + rect->width; + p2[3].y = rect->y + rect->height; + + p3[0].x = rect->x + rect->width; + p3[0].y = rect->y; + + p3[1].x = rect->x + rect->width - c * border; + p3[1].y = rect->y + s * border; + + p3[2].x = rect->x + rect->width - c * border; + p3[2].y = rect->y + rect->height - s * border; + + p3[3].x = rect->x + rect->width; + p3[3].y = rect->y + rect->height; + + MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter); + MwLLPolygon(handle->lowlevel, p2, 4, invert ? lighter : darker); + MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker); + + p4[0].x = rect->x + border; + p4[0].y = rect->y + rect->height / 2; + + p4[1].x = rect->x + rect->width - c * border; + p4[1].y = rect->y + rect->height - s * border; + + p4[2].x = rect->x + rect->width - c * border; + p4[2].y = rect->y + s * border; + } + MwLLPolygon(handle->lowlevel, p4, 3, color); + + MwLLFreeColor(lighter); + MwLLFreeColor(darker); +} + void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color) { int i, x, y, sx, sy; MwRect r; @@ -192,6 +404,3 @@ MwLLPixmap MwLoadImage(MwWidget handle, const char* path) { return px; } - -void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) { -} diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index 1b2db71..cf5f91e 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -22,7 +22,9 @@ static void draw(MwWidget handle) { rt = r; rt.height = rt.width; - MwDrawTriangle(handle, &r, base, 0, MwNORTH); + MwDrawTriangle(handle, &rt, base, 0, MwNORTH); + rt.y = r.y + r.height - rt.height; + MwDrawTriangle(handle, &rt, base, 0, MwSOUTH); MwLLFreeColor(dark); MwLLFreeColor(base); diff --git a/src/widget/submenu.c b/src/widget/submenu.c index c8459b0..193a965 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -67,20 +67,13 @@ static void draw(MwWidget handle) { MwDrawText(handle, &p, menu->sub[i]->name, 1, text); if(arrlen(menu->sub[i]->sub) > 0) { - MwPoint pl[3]; + MwRect tr; - p.x = 5 + tw + 10; + tr.x = p.x + tw / 2 + 5; + tr.y = p.y - th / 2 + 2; + tr.width = tr.height = 11; - pl[0].x = p.x - 5; - pl[0].y = p.y - th / 2; - - pl[1].x = p.x - 5; - pl[1].y = p.y + th / 2; - - pl[2].x = p.x + 5; - pl[2].y = p.y; - - MwLLPolygon(handle->lowlevel, pl, 3, text); + MwDrawTriangle(handle, &tr, base, menu->sub[i]->wsub != NULL ? 1 : 0, MwEAST); } p.y += th / 2 + 3;