From 94e0fe41c02dfae799a7e2896d0e62e517586042 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Wed, 12 Nov 2025 18:28:25 +0000 Subject: [PATCH] new cursor git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@674 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/Resource/Cursor.h | 10 ++++++ include/Mw/TypeDefs.h | 2 ++ include/Mw/Widget/ComboBox.h | 10 ++++++ milsko.xml | 8 +++++ src/cursor/arrow.c | 70 ++++++++++++++++++++++++++++++++++++ src/widget/combobox.c | 42 ++++++++++++++++++++-- 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 src/cursor/arrow.c diff --git a/include/Mw/Resource/Cursor.h b/include/Mw/Resource/Cursor.h index f615ae2..3ae2ce5 100644 --- a/include/Mw/Resource/Cursor.h +++ b/include/Mw/Resource/Cursor.h @@ -24,6 +24,16 @@ MWDECL MwCursor MwCursorDefault; */ MWDECL MwCursor MwCursorDefaultMask; +/*! + * @brief Arrow cursor + */ +MWDECL MwCursor MwCursorArrow; + +/*! + * @brief Arrow cursor mask + */ +MWDECL MwCursor MwCursorArrowMask; + /*! * @brief Cross cursor */ diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index c16a058..5e94b0e 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -131,7 +131,9 @@ struct _MwListBox { }; struct _MwComboBox { + char** list; int opened; + int selected; }; struct _MwDirectoryEntry { diff --git a/include/Mw/Widget/ComboBox.h b/include/Mw/Widget/ComboBox.h index 3b4d629..1918c98 100644 --- a/include/Mw/Widget/ComboBox.h +++ b/include/Mw/Widget/ComboBox.h @@ -18,6 +18,16 @@ extern "C" { */ MWDECL MwClass MwComboBoxClass; +/*! + * @brief Adds the entry to ComboBox + * @param handle Widget + * @param index Index + * @param text Text + */ +MwInline void MwComboBoxAdd(MwWidget handle, int index, const char* text) { + MwVaWidgetExecute(handle, "mwComboBoxAdd", NULL, index, text); +} + #ifdef __cplusplus } #endif diff --git a/milsko.xml b/milsko.xml index 377a0f5..af5d12b 100644 --- a/milsko.xml +++ b/milsko.xml @@ -585,5 +585,13 @@ + + + + + + + + diff --git a/src/cursor/arrow.c b/src/cursor/arrow.c new file mode 100644 index 0000000..3f50e35 --- /dev/null +++ b/src/cursor/arrow.c @@ -0,0 +1,70 @@ +/* $Id$ */ +#include + +/** + * Copyright notice: + * Copyright (c) Digital Equipment Corporation,1988. All Rights Reserved. + */ +/** + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notices appear in all copies and + * that both those copyright notices and this permission notice appear + * in supporting documentation, and that the name + * Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the software without + * specific, written prior permission. Digital + * Equipment Corporation makes no representations about the suitability + * of this software for any purpose. It is provided "as is" without + * express or implied warranty. + * DIGITAL EQUIPMENT CORPORATION DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +MwCursor MwCursorArrow = { + 16, 16, -15, -15, + { + 0, /* ................ */ + 6, /* .............##. */ + 30, /* ...........####. */ + 124, /* .........#####.. */ + 508, /* .......#######.. */ + 2040, /* .....########... */ + 8184, /* ...##########... */ + 496, /* .......#####.... */ + 1008, /* ......######.... */ + 1888, /* .....###.##..... */ + 3680, /* ....###..##..... */ + 7232, /* ...###...#...... */ + 14400, /* ..###....#...... */ + 28672, /* .###............ */ + 8192, /* ..#............. */ + 0 /* ................ */ + } +}; +MwCursor MwCursorArrowMask = { + 16, 16, -15, -15, + { + 7, /* .............### */ + 31, /* ...........##### */ + 127, /* .........####### */ + 510, /* .......########. */ + 2046, /* .....##########. */ + 8188, /* ...###########.. */ + 16380, /* ..############.. */ + 8184, /* ...##########... */ + 2040, /* .....########... */ + 4080, /* ....########.... */ + 8176, /* ...#########.... */ + 16096, /* ..#####.###..... */ + 31968, /* .#####..###..... */ + 63552, /* #####....#...... */ + 28672, /* .###............ */ + 8192 /* ..#............. */ + } +}; diff --git a/src/widget/combobox.c b/src/widget/combobox.c index 46d8b1f..c7d201f 100644 --- a/src/widget/combobox.c +++ b/src/widget/combobox.c @@ -1,10 +1,14 @@ /* $Id$ */ #include +#include "../../external/stb_ds.h" + static int create(MwWidget handle) { MwComboBox cb = malloc(sizeof(*cb)); + cb->list = NULL; cb->opened = 0; + cb->selected = 0; handle->internal = cb; MwSetDefault(handle); @@ -13,12 +17,20 @@ static int create(MwWidget handle) { } static void destroy(MwWidget handle) { + MwComboBox cb = handle->internal; + int i; + + for(i = 0; i < arrlen(cb->list); i++){ + free(cb->list[i]); + } + arrfree(cb->list); free(handle->internal); } static void draw(MwWidget handle) { MwRect r, rc; MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground)); MwComboBox cb = handle->internal; r.x = 0; @@ -31,20 +43,28 @@ static void draw(MwWidget handle) { rc = r; /* draw text */ + if(arrlen(cb->list) > cb->selected){ + MwPoint p; + + p.x = MwDefaultBorderWidth(handle) * 2; + p.y = MwGetInteger(handle, MwNheight) / 2; + + MwDrawText(handle, &p, cb->list[0], 0, MwALIGNMENT_BEGINNING, text); + } r = rc; r.height /= 5; r.width = r.height * 3; - r.x = MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) - r.width - (r.width / 3) * 2; + r.x = MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) - r.width - MwDefaultBorderWidth(handle) * 2; r.y = MwDefaultBorderWidth(handle); r.height = rc.height; - r.width += (r.width / 3) * 2; + r.width += MwDefaultBorderWidth(handle) * 2; MwDrawWidgetBack(handle, &r, base, 0, 0); r = rc; r.width = r.height * 3 / 5; r.height = r.width - MwDefaultBorderWidth(handle) * 2; - r.x = MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) - r.width - r.width / 3; + r.x = MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) - r.width - MwDefaultBorderWidth(handle) * 2; r.y = (MwGetInteger(handle, MwNheight) - (r.height + MwDefaultBorderWidth(handle) * 2)) / 2; MwDrawTriangle(handle, &r, base, cb->opened, MwSOUTH); @@ -52,6 +72,7 @@ static void draw(MwWidget handle) { r.height = MwDefaultBorderWidth(handle) * 2; MwDrawFrame(handle, &r, base, 0); + MwLLFreeColor(text); MwLLFreeColor(base); } @@ -63,8 +84,23 @@ static void click(MwWidget handle) { MwForceRender(handle); } +static void mwComboBoxAddImpl(MwWidget handle, int index, const char* text){ + MwComboBox cb = handle->internal; + char* t = MwStringDupliacte(text); + + if(index == -1) index = arrlen(cb->list); + + arrins(cb->list, index, t); + + if(index <= cb->selected) MwForceRender(handle); +} + static void func_handler(MwWidget handle, const char* name, void* out, va_list va) { + (void)out; if(strcmp(name, "mwComboBoxAdd") == 0) { + int index = va_arg(va, int); + const char* text = va_arg(va, const char*); + mwComboBoxAddImpl(handle, index, text); } }