radiobox works

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@528 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-31 15:02:40 +00:00
parent 39d4030a45
commit a8bb866af2
8 changed files with 194 additions and 3 deletions

View File

@@ -195,7 +195,7 @@ void MwLLPolygon(MwLL handle, MwPoint* points, int points_count, MwLLColor color
p[i].x = points[i].x;
p[i].y = points[i].y;
}
XFillPolygon(handle->display, handle->pixmap, handle->gc, p, points_count, Convex, CoordModeOrigin);
XFillPolygon(handle->display, handle->pixmap, handle->gc, p, points_count, Nonconvex, CoordModeOrigin);
free(p);
}

View File

@@ -144,6 +144,73 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert
if(col != color) MwLLFreeColor(col);
}
void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
MwPoint p[6];
int border = MwDefaultBorderWidth(handle);
int ColorDiff = get_color_diff(handle);
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff);
MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);
MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
p[0].x = rect->x;
p[0].y = rect->y + rect->height / 2;
p[1].x = rect->x + rect->width / 2;
p[1].y = rect->y;
p[2].x = rect->x + rect->width;
p[2].y = rect->y + rect->height / 2;
p[3].x = rect->x + rect->width - border;
p[3].y = rect->y + rect->height / 2;
p[4].x = rect->x + rect->width / 2;
p[4].y = rect->y + border;
p[5].x = rect->x + border;
p[5].y = rect->y + rect->height / 2;
MwLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter);
p[0].x = rect->x;
p[0].y = rect->y + rect->height / 2;
p[1].x = rect->x + rect->width / 2;
p[1].y = rect->y + rect->height;
p[2].x = rect->x + rect->width;
p[2].y = rect->y + rect->height / 2;
p[3].x = rect->x + rect->width - border;
p[3].y = rect->y + rect->height / 2;
p[4].x = rect->x + rect->width / 2;
p[4].y = rect->y + rect->height - border;
p[5].x = rect->x + border;
p[5].y = rect->y + rect->height / 2;
MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker);
p[0].x = rect->x + rect->width / 2;
p[0].y = border;
p[1].x = rect->x + rect->width - border;
p[1].y = rect->height / 2;
p[2].x = rect->x + rect->width / 2;
p[2].y = rect->y + rect->height - border;
p[3].x = rect->x + border;
p[3].y = rect->height / 2;
MwLLPolygon(handle->lowlevel, p, 4, col);
if(col != color) MwLLFreeColor(col);
MwLLFreeColor(lighter);
MwLLFreeColor(darker);
}
void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) {
MwPoint p[6];
int ColorDiff = get_color_diff(handle);

64
src/widget/radiobox.c Normal file
View File

@@ -0,0 +1,64 @@
/* $Id: button.c 168 2025-10-04 19:30:58Z nishi $ */
#include <Mw/Milsko.h>
#include "../../external/stb_ds.h"
static int create(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNchecked, 0);
return 0;
}
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);
MwDrawRect(handle, &r, base);
MwDrawDiamond(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0);
MwLLFreeColor(base);
}
static void click(MwWidget handle) {
MwSetInteger(handle, MwNchecked, MwGetInteger(handle, MwNchecked) ? 0 : 1);
if(MwGetInteger(handle, MwNchecked) && handle->parent != NULL) {
int i;
for(i = 0; i < arrlen(handle->parent->children); i++) {
MwWidget w = handle->parent->children[i];
if(w != handle && w->widget_class == MwRadioBoxClass && MwGetInteger(w, MwNchecked)) {
MwSetInteger(w, MwNchecked, 0);
}
}
}
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNchecked) == 0) MwForceRender(handle);
}
MwClassRec MwRadioBoxClassRec = {
create, /* create */
NULL, /* destroy */
draw, /* draw */
click, /* click */
NULL, /* parent_resize */
prop_change, /* prop_change */
NULL, /* mouse_move */
MwForceRender2, /* mouse_up */
MwForceRender2, /* mouse_down */
NULL, /* key */
NULL, /* execute */
NULL,
NULL,
NULL,
NULL};
MwClass MwRadioBoxClass = &MwRadioBoxClassRec;