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

111 lines
3.0 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_user_stat.h"
#include "mywin_inc.h"
2025-06-27 00:32:57 +08:00
#define WIN_STAT_TYPE "WIN_StatStruct"
WIN_StatStruct *WIN_CreatStat(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))STAT_DefaultMsgLoop;
}
2025-06-27 00:32:57 +08:00
WIN_StatStruct *ret = mymalloc(sizeof(WIN_StatStruct));
// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
if (ret) {
mymemset(ret, 0, sizeof(WIN_StatStruct));
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 {
((WIN_WindowStruct *)ret)->winType = WIN_STAT_TYPE;
((WIN_WindowStruct *)ret)->keyShield = 1; // <20><><EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD>Ϣ
((WIN_WindowStruct *)ret)->bkcolor = 0x000000;
((WIN_WindowStruct *)ret)->color = 0xffffff;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
WIN_SetAsTopWin((WIN_WindowStruct *)ret); // <20><><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>
}
}
2025-06-27 00:32:57 +08:00
return ret;
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>֣<EFBFBD><D6A3>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>1
int STAT_SetTxt(WIN_StatStruct *stat, char *txt) {
int ret = 0;
int len = strlen(txt);
if (len >= STAT_TXT_MAXLEN) {
ret = 0;
len = STAT_TXT_MAXLEN - 1;
mymemcpy(stat->txt, txt, len);
stat->txt[len] = 0;
} else {
ret = 1;
mymemcpy(stat->txt, txt, len + 1);
}
return ret;
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
int STAT_SetImg(WIN_StatStruct *stat, uint8_t *img) {
stat->img = img;
return 1;
2025-06-27 00:32:57 +08:00
}
// Ĭ<>ϻ<EFBFBD><CFBB>ƺ<EFBFBD><C6BA><EFBFBD>
void STAT_DefaultPaint(WIN_StatStruct *stat) {
2025-06-27 00:32:57 +08:00
int x = 0;
int y = 0;
int x_size = ((WIN_WindowStruct *)stat)->x_size;
int y_size = ((WIN_WindowStruct *)stat)->y_size;
WIN_PaintBackGround((WIN_WindowStruct *)stat);
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 = x_size - 1; // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int img_y = 0; // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
int font_size = WIN_SetFontSize(12);
WIN_SetLcdColor(((WIN_WindowStruct *)stat)->color);
if (stat->img) {
WIN_GetImageSize(stat->img, &img_xsize, &img_ysize);
if (img_xsize > x_size)
img_xsize = x_size;
if (img_ysize > y_size)
img_ysize = y_size;
img_x = x_size / 2 - img_xsize / 2;
img_y = y_size / 2 - img_ysize / 2;
// <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ɫ
if (1) {
WIN_DrawImag(img_x, img_y, img_xsize, img_ysize, stat->img);
}
} else if (stat->txt[0]) {
WIN_DrawTxtHCenterAt(stat->txt, x_size / 2,
y_size / 2 - WIN_GetFontHight() / 2);
}
WIN_SetFontSize(font_size);
}
2025-06-27 00:32:57 +08:00
// Ĭ<><C4AC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void STAT_DefaultMsgLoop(WIN_StatStruct *stat, WIN_MsgStruct *msg) {
WIN_MoveStruct *m = 0;
WIN_TouchStruct *t = 0;
switch (msg->msg) {
case WIN_MSG_PAINT:
STAT_DefaultPaint(stat);
break;
case WIN_MSG_TIMER:
if (stat->TimerCallBack)
stat->TimerCallBack(stat);
break;
default:
WIN_DefaultMsgLoop((WIN_WindowStruct *)stat, msg);
break;
}
}