From ddbf4f13e4bb6af4bf38bd772899943bfb1157bf Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 4 Oct 2025 17:52:14 +0000 Subject: [PATCH] kinda git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@166 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/Constants.h | 8 +++++ include/Mw/StringDefs.h | 1 + src/draw.c | 2 +- src/widget/scrollbar.c | 71 +++++++++++++++++++++++++++++++++-------- 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/include/Mw/Constants.h b/include/Mw/Constants.h index 4e056f5..f3a205e 100644 --- a/include/Mw/Constants.h +++ b/include/Mw/Constants.h @@ -16,4 +16,12 @@ enum MwDIRECTION { MwWEST }; +/*! + * %brief Orientation + */ +enum MwORIENTATION { + MwVERTICAL = 0, + MwHORIZONTAL +}; + #endif diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index 3ec853d..a39e3da 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -10,6 +10,7 @@ #define MwNy "Iy" #define MwNwidth "Iwidth" #define MwNheight "Iheight" +#define MwNorientation "Iorientation" #define MwNtitle "Stitle" #define MwNtext "Stext" diff --git a/src/draw.c b/src/draw.c index c243c06..676a157 100644 --- a/src/draw.c +++ b/src/draw.c @@ -143,7 +143,7 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i 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; + const int border = BorderWidth; MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff); diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index cf5f91e..124bd73 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -1,40 +1,85 @@ /* $Id $*/ #include +typedef struct scrollbar { + MwPoint point; + int point_set; +} scrollbar_t; + static int create(MwWidget handle) { + scrollbar_t* scr = malloc(sizeof(*scr)); + + scr->point_set = 0; + + handle->internal = scr; + MwSetDefault(handle); return 0; } +static void destroy(MwWidget handle) { + free(handle->internal); +} + static void draw(MwWidget handle) { - MwRect r, rt; - MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); - MwLLColor dark = MwLightenColor(handle, base, -64, -64, -64); + MwRect r, rt; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwLLColor dark = MwLightenColor(handle, base, -64, -64, -64); + scrollbar_t* scr = handle->internal; + int or ; + int uy, dy, ux, dx; r.x = 0; r.y = 0; r.width = MwGetInteger(handle, MwNwidth); r.height = MwGetInteger(handle, MwNheight); + uy = r.width; + dy = r.height - r.width; + + ux = r.height; + dx = r.width - r.height; + MwDrawFrame(handle, &r, dark, 1); MwDrawRect(handle, &r, dark); - rt = r; - rt.height = rt.width; - MwDrawTriangle(handle, &rt, base, 0, MwNORTH); - rt.y = r.y + r.height - rt.height; - MwDrawTriangle(handle, &rt, base, 0, MwSOUTH); + if(handle->pressed && !scr->point_set) { + scr->point = handle->mouse_point; + scr->point_set = 1; + } else if(!handle->pressed && scr->point_set) { + scr->point_set = 0; + } + + rt = r; + + if((or = MwGetInteger(handle, MwNorientation)) == -1 || or == MwVERTICAL) { + rt.height = rt.width; + + rt.y = r.y; + MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y <= uy) ? 1 : 0, MwNORTH); + + rt.y = r.y + r.height - rt.height; + MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y >= dy) ? 1 : 0, MwSOUTH); + } else if((or = MwGetInteger(handle, MwNorientation)) == -1 || or == MwHORIZONTAL) { + rt.width = rt.height; + + rt.x = r.x; + MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x <= ux) ? 1 : 0, MwWEST); + + rt.x = r.x + r.width - rt.width; + MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x >= dx) ? 1 : 0, MwEAST); + } MwLLFreeColor(dark); MwLLFreeColor(base); } MwClassRec MwScrollBarClassRec = { - create, /* create */ - NULL, /* destroy */ - draw, /* draw */ - NULL, /* click */ - NULL /* parent_resize */ + create, /* create */ + destroy, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL /* parent_resize */ }; MwClass MwScrollBarClass = &MwScrollBarClassRec;