From 8d0cefd133b717d2fa2620febe8779cac7173622 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 16 Nov 2025 00:33:44 +0000 Subject: [PATCH] add separator git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@733 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/Milsko.h | 1 + include/Mw/Widget/Separator.h | 25 ++++++++++++++++ pl/rules.pl | 1 + src/widget/separator.c | 54 +++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 include/Mw/Widget/Separator.h create mode 100644 src/widget/separator.c diff --git a/include/Mw/Milsko.h b/include/Mw/Milsko.h index 60f25bb..0f97777 100644 --- a/include/Mw/Milsko.h +++ b/include/Mw/Milsko.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #endif diff --git a/include/Mw/Widget/Separator.h b/include/Mw/Widget/Separator.h new file mode 100644 index 0000000..1a7d8af --- /dev/null +++ b/include/Mw/Widget/Separator.h @@ -0,0 +1,25 @@ +/* $Id$ */ +/*! + * @file Mw/Widget/Separator.h + * @brief Separator widget + */ +#ifndef __MW_WIDGET_SEPARATOR_H__ +#define __MW_WIDGET_SEPARATOR_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * @brief Separator widget class + */ +MWDECL MwClass MwSeparatorClass; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/pl/rules.pl b/pl/rules.pl index d4809d2..6bdfdca 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -61,6 +61,7 @@ new_object("src/widget/numberentry.c"); new_object("src/widget/progressbar.c"); new_object("src/widget/radiobox.c"); new_object("src/widget/scrollbar.c"); +new_object("src/widget/separator.c"); new_object("src/widget/submenu.c"); new_object("src/widget/viewport.c"); new_object("src/widget/window.c"); diff --git a/src/widget/separator.c b/src/widget/separator.c new file mode 100644 index 0000000..2a64f2c --- /dev/null +++ b/src/widget/separator.c @@ -0,0 +1,54 @@ +/* $Id$ */ +#include + +static int create(MwWidget handle) { + MwSetDefault(handle); + + MwSetInteger(handle, MwNorientation, MwVERTICAL); + + 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); + + if(MwGetInteger(handle, MwNorientation) == MwVERTICAL) { + r.x = (r.width - MwDefaultBorderWidth(handle) * 2) / 2; + r.width = MwDefaultBorderWidth(handle) * 2; + } else if(MwGetInteger(handle, MwNorientation) == MwHORIZONTAL) { + r.y = (r.height - MwDefaultBorderWidth(handle) * 2) / 2; + r.height = MwDefaultBorderWidth(handle) * 2; + } + MwDrawWidgetBack(handle, &r, base, 0, 1); + + MwLLFreeColor(base); +} + +static void prop_change(MwWidget handle, const char* key) { + if(strcmp(key, MwNorientation) == 0) MwForceRender(handle); +} + +MwClassRec MwSeparatorClassRec = { + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + prop_change, /* prop_change */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL, /* mouse_down */ + NULL, /* key */ + NULL, /* execute */ + NULL, /* tick */ + NULL, + NULL, + NULL}; +MwClass MwSeparatorClass = &MwSeparatorClassRec;