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

237 lines
5.3 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_user_animation.h"
#define WIN_ANIMATION_TYPE "WIN_AnimationStruct"
WIN_AnimationStruct *WIN_CreatAnimation (WIN_WindowStruct *base,
void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
int x,int y,int x_size,int y_size)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣѭ<CFA2><D1AD>
2025-06-27 00:32:57 +08:00
if (msgLoop==0)
{
msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))ANIMATION_defaultMsgLoop;
}
WIN_AnimationStruct *ret=mymalloc (sizeof ( WIN_AnimationStruct));
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
2025-06-27 00:32:57 +08:00
if (ret)
{
mymemset (ret,0,sizeof ( WIN_AnimationStruct));
if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size))
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
2025-06-27 00:32:57 +08:00
myfree (ret);
ret=0;
}
else
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
((WIN_WindowStruct *)ret)->winType=WIN_ANIMATION_TYPE;
((WIN_WindowStruct *)ret)->deleteWindow=(void (*)(struct _WIN_WindowStruct *win))WIN_DeleteAnimation;
((WIN_WindowStruct *)ret)->intercept=1;
((WIN_WindowStruct *)ret)->bkcolor=0x808080;
((WIN_WindowStruct *)ret)->color=0xffffff;
ret->timerId= WIN_CreatTimer((WIN_WindowStruct *)ret,100);
}
}
return ret;
}
void WIN_DeleteAnimation (WIN_AnimationStruct *animation)
{
2025-07-05 19:47:28 +08:00
//<2F>ͷ<EFBFBD>ͼƬռ<C6AC>õ<EFBFBD><C3B5>ڴ<EFBFBD>
2025-06-27 00:32:57 +08:00
GIF_DecodeStructFree (animation->gif);
myfree(animation->gif);
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٺ<EFBFBD><D9BA><EFBFBD>
2025-06-27 00:32:57 +08:00
WIN_DeleteWindow ( (WIN_WindowStruct *)animation);
}
2025-07-05 19:47:28 +08:00
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD>Ļ<EFBFBD><C4BB>ƺ<EFBFBD><C6BA><EFBFBD>
2025-06-27 00:32:57 +08:00
void ANIMATION_DefaultPaint (WIN_AnimationStruct *animation)
{
WIN_WindowStruct *win=(WIN_WindowStruct *)animation;
WIN_PicStruct *pic=&win->pic;
int xsize=win->x_size;
int ysize=win->y_size;
WIN_FillRect (0,0,xsize,ysize,pic->data,0,0,pic->xsize,pic->ysize);
}
2025-07-05 19:47:28 +08:00
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void ANIMATION_defaultMsgLoop (WIN_AnimationStruct *animation,WIN_MsgStruct *msg)
{
WIN_MoveStruct *m=0;
WIN_KeyStruct *k=0;
WIN_WindowStruct *win=(WIN_WindowStruct *)animation;
switch (msg->msg)
{
case WIN_MSG_PAINT:
ANIMATION_DefaultPaint(animation);
break;
case WIN_MSG_TIMER:
if (msg->data.v==animation->timerId)
{
int delay=animation->gif->delay[animation->frameNow];
WIN_SetTimerCycle (animation->timerId,delay);
win->pic.data=animation->gif->frame[animation->frameNow];
win->pic.xsize=animation->gif->x_size;
win->pic.ysize=animation->gif->y_size;
animation->frameNow++;
if (animation->frameNow>animation->gif->frameNumber-1)
{
if(animation->once==0)
animation->frameNow=0;
else
WIN_DeleteTimer(animation->timerId);
}
WIN_SetInvalidWhenTop (win);
}
else if (msg->data.v==animation->timerIdReturn)
{
((WIN_WindowStruct *)animation)->deleteWindow((WIN_WindowStruct *)animation);
break;
}
break;
case WIN_MSG_KEY:
k=msg->data.p;
if (k->shortPress&KEY_VALUE_HOME)
((WIN_WindowStruct *)animation)->deleteWindow((WIN_WindowStruct *)animation);
break;
case WIN_MSG_MOVE:
m=msg->data.p;
switch (m->moveType)
{
case MOVE_DATA_SHORT:
((WIN_WindowStruct *)animation)->deleteWindow((WIN_WindowStruct *)animation);
break;
default:
break;
}
break;
default:
WIN_DefaultMsgLoop((WIN_WindowStruct *)animation,msg);
break;
}
}
typedef struct
{
u8 *name;
GIF_DecodeStruct *gif;
} decode_gif_struct;
2025-07-05 19:47:28 +08:00
//gif<69><66><EFBFBD><EFBFBD><EBB9A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
static int decode_gif (void *ptr)
{
decode_gif_struct *t=ptr;
return GIF_Decode (t->gif,t->name);
}
2025-07-05 19:47:28 +08:00
//<2F><>ʾһ<CABE><D2BB>ͼƬ
2025-06-27 00:32:57 +08:00
WIN_AnimationStruct *ANIMATION_ShowGif (WIN_WindowStruct *base,char *name)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>GIFͼƬ
2025-06-27 00:32:57 +08:00
//GIF_DecodeStruct *gif=GIF_Decode ((const u8 *)name);
GIF_DecodeStruct *gif=0;
decode_gif_struct dec={0};
dec.name=(u8*)name;
dec.gif=mymalloc(sizeof(GIF_DecodeStruct));
2025-07-05 19:47:28 +08:00
if(WORKING_DoWork (base,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",decode_gif,&dec)==0)
2025-06-27 00:32:57 +08:00
{
myfree(dec.gif);
return 0;
}
gif=dec.gif;
WIN_AnimationStruct *animation=0;
int x,y,xsize,ysize;
if (base)
{
x=0;y=0;xsize=base->x_size;ysize=base->y_size;
}
else
{
base=WIN_GetBaseWindow();
x=0;y=0;xsize=WIN_GetWinStruct()->lcd->getLcdSizeX();ysize=WIN_GetWinStruct()->lcd->getLcdSizeY();
}
if (gif->x_size<xsize) {x+=(xsize-gif->x_size)/2;xsize=gif->x_size;}
if (gif->y_size<ysize) {y+=(ysize-gif->y_size)/2;ysize=gif->y_size;}
animation=WIN_CreatAnimation (base,0,x,y,xsize,ysize);
animation->gif=gif;
WIN_ShowWindow((WIN_WindowStruct *)animation);
return animation;
}
2025-07-05 19:47:28 +08:00
//<2F><>ʾһ<CABE><D2BB>ͼƬָ<C6AC><D6B8>ʱ<EFBFBD><CAB1>
2025-06-27 00:32:57 +08:00
WIN_AnimationStruct *ANIMATION_ShowGifTime (WIN_WindowStruct *base,char *name,u32 ms)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>GIFͼƬ
2025-06-27 00:32:57 +08:00
//GIF_DecodeStruct *gif=GIF_Decode ((const u8 *)name);
GIF_DecodeStruct *gif=0;
decode_gif_struct dec={0};
dec.name=(u8*)name;
dec.gif=mymalloc(sizeof(GIF_DecodeStruct));
2025-07-05 19:47:28 +08:00
WORKING_DoWork (base,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",decode_gif,&dec);
2025-06-27 00:32:57 +08:00
gif=dec.gif;
if (gif==0) return 0;
WIN_AnimationStruct *animation=0;
int x,y,xsize,ysize;
if (base)
{
WIN_GetWinPosOnLcd (base,&x,&y,&xsize,&ysize);
}
else
{
base=WIN_GetBaseWindow();
x=0;y=0;xsize=WIN_GetWinStruct()->lcd->getLcdSizeX();ysize=WIN_GetWinStruct()->lcd->getLcdSizeY();
}
if (gif->x_size<xsize) {x+=(xsize-gif->x_size)/2;xsize=gif->x_size;}
if (gif->y_size<ysize) {y+=(ysize-gif->y_size)/2;ysize=gif->y_size;}
animation=WIN_CreatAnimation (base,0,x,y,xsize,ysize);
animation->gif=gif;
animation->timerIdReturn= WIN_CreatTimer ((WIN_WindowStruct *)animation,ms);
WIN_ShowWindow((WIN_WindowStruct *)animation);
return animation;
}