new cursor

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@674 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-12 18:28:25 +00:00
parent da33803835
commit 94e0fe41c0
6 changed files with 139 additions and 3 deletions

View File

@@ -24,6 +24,16 @@ MWDECL MwCursor MwCursorDefault;
*/ */
MWDECL MwCursor MwCursorDefaultMask; MWDECL MwCursor MwCursorDefaultMask;
/*!
* @brief Arrow cursor
*/
MWDECL MwCursor MwCursorArrow;
/*!
* @brief Arrow cursor mask
*/
MWDECL MwCursor MwCursorArrowMask;
/*! /*!
* @brief Cross cursor * @brief Cross cursor
*/ */

View File

@@ -131,7 +131,9 @@ struct _MwListBox {
}; };
struct _MwComboBox { struct _MwComboBox {
char** list;
int opened; int opened;
int selected;
}; };
struct _MwDirectoryEntry { struct _MwDirectoryEntry {

View File

@@ -18,6 +18,16 @@ extern "C" {
*/ */
MWDECL MwClass MwComboBoxClass; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@@ -585,5 +585,13 @@
<property name="checked" /> <property name="checked" />
</properties> </properties>
</widget> </widget>
<widget name="ComboBox">
<functions>
<function name="Add">
<integer name="index" />
<string name="text" />
</function>
</functions>
</widget>
</widgets> </widgets>
</milsko> </milsko>

70
src/cursor/arrow.c Normal file
View File

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

View File

@@ -1,10 +1,14 @@
/* $Id$ */ /* $Id$ */
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
#include "../../external/stb_ds.h"
static int create(MwWidget handle) { static int create(MwWidget handle) {
MwComboBox cb = malloc(sizeof(*cb)); MwComboBox cb = malloc(sizeof(*cb));
cb->list = NULL;
cb->opened = 0; cb->opened = 0;
cb->selected = 0;
handle->internal = cb; handle->internal = cb;
MwSetDefault(handle); MwSetDefault(handle);
@@ -13,12 +17,20 @@ static int create(MwWidget handle) {
} }
static void destroy(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); free(handle->internal);
} }
static void draw(MwWidget handle) { static void draw(MwWidget handle) {
MwRect r, rc; MwRect r, rc;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
MwComboBox cb = handle->internal; MwComboBox cb = handle->internal;
r.x = 0; r.x = 0;
@@ -31,20 +43,28 @@ static void draw(MwWidget handle) {
rc = r; rc = r;
/* draw text */ /* 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 = rc;
r.height /= 5; r.height /= 5;
r.width = r.height * 3; 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.y = MwDefaultBorderWidth(handle);
r.height = rc.height; r.height = rc.height;
r.width += (r.width / 3) * 2; r.width += MwDefaultBorderWidth(handle) * 2;
MwDrawWidgetBack(handle, &r, base, 0, 0); MwDrawWidgetBack(handle, &r, base, 0, 0);
r = rc; r = rc;
r.width = r.height * 3 / 5; r.width = r.height * 3 / 5;
r.height = r.width - MwDefaultBorderWidth(handle) * 2; 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; r.y = (MwGetInteger(handle, MwNheight) - (r.height + MwDefaultBorderWidth(handle) * 2)) / 2;
MwDrawTriangle(handle, &r, base, cb->opened, MwSOUTH); MwDrawTriangle(handle, &r, base, cb->opened, MwSOUTH);
@@ -52,6 +72,7 @@ static void draw(MwWidget handle) {
r.height = MwDefaultBorderWidth(handle) * 2; r.height = MwDefaultBorderWidth(handle) * 2;
MwDrawFrame(handle, &r, base, 0); MwDrawFrame(handle, &r, base, 0);
MwLLFreeColor(text);
MwLLFreeColor(base); MwLLFreeColor(base);
} }
@@ -63,8 +84,23 @@ static void click(MwWidget handle) {
MwForceRender(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) { static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
(void)out;
if(strcmp(name, "mwComboBoxAdd") == 0) { if(strcmp(name, "mwComboBoxAdd") == 0) {
int index = va_arg(va, int);
const char* text = va_arg(va, const char*);
mwComboBoxAddImpl(handle, index, text);
} }
} }