Files
player/Project/Src/MyWinApp/mywin_user_menu.c

171 lines
4.6 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_user_menu.h"
#define WIN_MENU_TYPE "WIN_MenuStruct"
WIN_MenuStruct *WIN_CreatMenu(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))MENU_DefaultMsgLoop;
}
WIN_MenuStruct *ret = mymalloc(sizeof(WIN_MenuStruct));
// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
if (ret) {
mymemset(ret, 0, sizeof(WIN_MenuStruct));
if (0 == WIN_CreatTouchEx((WIN_TouchWinStruct *)ret, base, msgLoop, x, y,
x_size, y_size)) {
// <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
myfree(ret);
ret = 0;
} else {
((WIN_WindowStruct *)ret)->winType = WIN_MENU_TYPE;
((WIN_WindowStruct *)ret)->color = 0xaabbcc;
ret->bar = WIN_CreatScrollbar((WIN_WindowStruct *)ret, 0, 20, 45,
x_size - 40, y_size - 90);
}
}
return ret;
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
void MENU_SetTitle(WIN_MenuStruct *menu, char *img, char *txt) {
menu->title.img = img;
mymemcpy(menu->title.txt, txt, strlen(txt) + 1);
2025-06-27 00:32:57 +08:00
}
void MENU_SetMaxItem(WIN_MenuStruct *menu, int itemNum) {
SCROLLBAR_SetItemNum(menu->bar, itemNum);
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ
void MENU_AddItem(WIN_MenuStruct *menu, char *img, char *txt) {
SCROLLBAR_AddItem(menu->bar, txt, img);
2025-06-27 00:32:57 +08:00
}
int MENU_GetAllItemNum(WIN_MenuStruct *menu) { return menu->bar->itemNum; }
2025-06-27 00:32:57 +08:00
char *MENU_GetItem(WIN_MenuStruct *menu, int index) {
if (index >= 0 && index < menu->bar->itemNum)
return menu->bar->items[index].txt;
else
return 0;
2025-06-27 00:32:57 +08:00
}
char *MENU_GetSelectItem(WIN_MenuStruct *menu) {
return MENU_GetItem(menu, menu->bar->index);
2025-06-27 00:32:57 +08:00
}
int MENU_GetIndex(WIN_MenuStruct *menu) { return menu->bar->index; }
2025-06-27 00:32:57 +08:00
// <20><>ʾһ<CABE><D2BB>item<65><EFBFBD><E1B9B9>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
void MENU_PaintItem(MENU_ItemStruct *item, int x, int y, int x_size,
int y_size) {
2025-06-27 00:32:57 +08:00
int txt_xsize = WIN_GetFontWidth() * strlen(item->txt) / 2;
2025-06-27 00:32:57 +08:00
int img_xsize = 0; // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD>
int img_ysize = 0; // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD>
int img_x = 0; // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int img_y = 0; // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
if (item->img) {
WIN_PicStruct *pic = WIN_GetPic(item->img);
WIN_DrawPic(pic, x, y + (y_size - pic->ysize) / 2, pic->xsize, pic->ysize);
img_xsize += pic->xsize + WIN_GetFontWidth() / 2;
}
int txt_x = x + img_xsize;
if (item->txt[0]) {
WIN_DrawTxtAt(item->txt, txt_x, y + y_size / 2 - WIN_GetFontHight() / 2);
}
2025-06-27 00:32:57 +08:00
}
// Ĭ<>ϻ<EFBFBD><CFBB>ƺ<EFBFBD><C6BA><EFBFBD>
void MENU_DefaultPaint(WIN_MenuStruct *menu) {
2025-06-27 00:32:57 +08:00
int x = 0;
int y = 0;
int x_size = ((WIN_WindowStruct *)menu)->x_size;
int y_size = ((WIN_WindowStruct *)menu)->y_size;
2025-06-27 00:32:57 +08:00
WIN_PaintBackGround((WIN_WindowStruct *)menu);
// <20><><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>
WIN_SetLcdColor(((WIN_WindowStruct *)menu)->color);
MENU_PaintItem(&menu->title, x + 25, y, x_size / 2, 40);
}
// Ĭ<><C4AC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void MENU_DefaultMsgLoop(WIN_MenuStruct *menu, WIN_MsgStruct *msg) {
WIN_MoveStruct *m = 0;
WIN_KeyStruct *k = 0;
switch (msg->msg) {
case WIN_MSG_PAINT:
MENU_DefaultPaint(menu);
break;
case WIN_MSG_INIT: {
int x_size = ((WIN_WindowStruct *)menu)->x_size;
int y_size = ((WIN_WindowStruct *)menu)->y_size;
menu->key_back = WIN_CreatButton(((WIN_WindowStruct *)menu), 0, x_size - 65,
y_size - 30, 65, 30);
BUTTON_SetKeyString(menu->key_back, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
} break;
case WIN_MSG_KEY:
k = msg->data.p;
if (k->shortPress & KEY_VALUE_UP) // <20>̰<EFBFBD>
{
// MENU_IndexSub (menu);
} else if (k->shortPress & KEY_VALUE_DOWN) {
// MENU_IndexAdd (menu);
}
if (k->shortPress & KEY_VALUE_HOME) {
// <20><><EFBFBD><EFBFBD>
((WIN_WindowStruct *)menu)->deleteWindow((WIN_WindowStruct *)menu);
break;
}
if (k->shortPress) {
WIN_SetInvalid((WIN_WindowStruct *)menu);
}
break; // case WIN_MSG_KEY:
case WIN_MSG_MOVE:
m = msg->data.p;
switch (m->moveType) {
case MOVE_DATA_MOVED: {
} break;
case MOVE_DATA_TOUCHIN:
break;
case MOVE_DATA_TOUCHOUT:
break;
default:
break;
}
break;
case WIN_MSG_CHID:
switch (msg->data.v) {
case CHID_DELETE:
break;
case CHID_USER: {
if (msg->srcWin == menu->key_back) {
if (msg->data2.v == BUTTON_PRESSED) {
// <20><><EFBFBD><EFBFBD>
((WIN_WindowStruct *)menu)->deleteWindow((WIN_WindowStruct *)menu);
}
} else {
}
} break;
default:
break;
}
break;
default:
WIN_DefaultMsgLoop((WIN_WindowStruct *)menu, msg);
break;
}
}