git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@166 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-04 17:52:14 +00:00
parent 88ef13212a
commit ddbf4f13e4
4 changed files with 68 additions and 14 deletions

View File

@@ -16,4 +16,12 @@ enum MwDIRECTION {
MwWEST
};
/*!
* %brief Orientation
*/
enum MwORIENTATION {
MwVERTICAL = 0,
MwHORIZONTAL
};
#endif

View File

@@ -10,6 +10,7 @@
#define MwNy "Iy"
#define MwNwidth "Iwidth"
#define MwNheight "Iheight"
#define MwNorientation "Iorientation"
#define MwNtitle "Stitle"
#define MwNtext "Stext"

View File

@@ -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);

View File

@@ -1,40 +1,85 @@
/* $Id $*/
#include <Mw/Milsko.h>
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;