Files
player/Project/Src/MyWin/Window/mywin_inputbox.c

126 lines
3.4 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_inc.h"
#define WIN_INPUTBOX_TYPE "WIN_InputboxStruct"
2025-07-06 18:46:13 +08:00
WIN_InputboxStruct *WIN_CreatInputbox(
WIN_WindowStruct *base,
void (*msgLoop)(struct _WIN_WindowStruct *win, WIN_MsgStruct *msg), int x,
int y, int x_size, int y_size) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣѭ<CFA2><D1AD>
if (msgLoop == 0) {
msgLoop = (void (*)(struct _WIN_WindowStruct *win,
WIN_MsgStruct *msg))INPUTBOX_DefaultMsgLoop;
}
WIN_InputboxStruct *ret = mymalloc(sizeof(WIN_InputboxStruct));
// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
if (ret) {
mymemset(ret, 0, sizeof(WIN_InputboxStruct));
if (0 == WIN_CreatWindowExt((WIN_WindowStruct *)ret, base, msgLoop, x, y,
x_size, y_size)) {
// <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
myfree(ret);
ret = 0;
} else {
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
((WIN_WindowStruct *)ret)->winType = WIN_INPUTBOX_TYPE;
((WIN_WindowStruct *)ret)->bkcolor = 0x342f2a;
((WIN_WindowStruct *)ret)->color = 0xc2ae9b;
((WIN_WindowStruct *)ret)->keyChid = 1; // <20><>Ϊ<EFBFBD>Ӵ<EFBFBD><D3B4>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD>
ret->color_light = 0xffffff;
ret->color_dark = 0x808080;
}
}
return ret;
2025-06-27 00:32:57 +08:00
}
2025-07-06 18:46:13 +08:00
int INPUTBOX_Clear(WIN_InputboxStruct *box) {
mymemset(box->inputs, 0, INPUTBOX_MAX_CHAR_NUM);
WIN_SetInvalid((WIN_WindowStruct *)box);
return 0;
2025-06-27 00:32:57 +08:00
}
2025-07-06 18:46:13 +08:00
int INPUTBOX_SetChars(WIN_InputboxStruct *box, char *str) {
int len = strlen(str) + 1;
if (len > INPUTBOX_MAX_CHAR_NUM)
return -1;
mymemcpy(box->inputs, str, len);
WIN_SetInvalid((WIN_WindowStruct *)box);
return 0;
2025-06-27 00:32:57 +08:00
}
2025-07-06 18:46:13 +08:00
void INPUTBOX_DefaultPaint(WIN_InputboxStruct *box) {
int x = 0;
int y = 0;
int x_size = ((WIN_WindowStruct *)box)->x_size;
int y_size = ((WIN_WindowStruct *)box)->y_size;
2025-06-27 00:32:57 +08:00
2025-07-06 18:46:13 +08:00
WIN_PaintBackGround((WIN_WindowStruct *)box);
2025-06-27 00:32:57 +08:00
2025-07-06 18:46:13 +08:00
WIN_SetLcdColor(((WIN_WindowStruct *)box)->color);
WIN_DrawTxtAtRect(box->inputs, x + 1, y + 1, x_size - 2, y_size - 2);
2025-06-27 00:32:57 +08:00
2025-07-06 18:46:13 +08:00
// <20><><EFBFBD>Ʊ߿<C6B1>
if (box->press)
WIN_SetLcdColor(box->color_light);
else
WIN_SetLcdColor(box->color_dark);
2025-06-27 00:32:57 +08:00
2025-07-06 18:46:13 +08:00
WIN_DrawRect(0, 0, ((WIN_WindowStruct *)box)->x_size,
((WIN_WindowStruct *)box)->y_size);
2025-06-27 00:32:57 +08:00
}
2025-07-06 18:46:13 +08:00
void INPUTBOX_DefaultMsgLoop(WIN_InputboxStruct *box, WIN_MsgStruct *msg) {
WIN_MoveStruct *m = 0;
WIN_KeyStruct *k = 0;
switch (msg->msg) {
case WIN_MSG_PAINT:
INPUTBOX_DefaultPaint(box);
break;
case WIN_MSG_KEY:
k = msg->data.p;
if (k->shortPress & KEY_VALUE_DOWN) {
} else if (k->shortPress & KEY_VALUE_UP) {
}
break;
case WIN_MSG_MOVE:
m = msg->data.p;
switch (m->moveType) {
case MOVE_DATA_TOUCHIN:
box->press = 1;
WIN_SetInvalid((WIN_WindowStruct *)box);
break;
case MOVE_DATA_TOUCHOUT:
if (box->press) {
box->press = 0;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
INPUT_KeyBoard(((WIN_WindowStruct *)box)->baseWin, box->inputs,
INPUTBOX_MAX_CHAR_NUM);
WIN_SetInvalid((WIN_WindowStruct *)box);
}
break;
case MOVE_DATA_MOVEOUT:
box->press = 0;
WIN_SetInvalid((WIN_WindowStruct *)box);
default:
break;
}
break;
default:
WIN_DefaultMsgLoop((WIN_WindowStruct *)box, msg);
break;
}
2025-06-27 00:32:57 +08:00
}
2025-07-06 18:46:13 +08:00
WIN_InputboxStruct *INPUTBOX_InputChars(WIN_WindowStruct *base, int x, int y,
int x_size, int y_size) {
WIN_InputboxStruct *box = WIN_CreatInputbox(base, 0, x, y, x_size, y_size);
2025-06-27 00:32:57 +08:00
2025-07-06 18:46:13 +08:00
// <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
WIN_SetBackPic((WIN_WindowStruct *)box);
2025-06-27 00:32:57 +08:00
2025-07-06 18:46:13 +08:00
WIN_ShowWindow((WIN_WindowStruct *)box);
return box;
2025-06-27 00:32:57 +08:00
}