237 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			237 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#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)
 | 
						|
{
 | 
						|
	//重设消息循环
 | 
						|
	if (msgLoop==0)
 | 
						|
	{
 | 
						|
		msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))ANIMATION_defaultMsgLoop;  
 | 
						|
	}
 | 
						|
	
 | 
						|
	WIN_AnimationStruct *ret=mymalloc (sizeof ( WIN_AnimationStruct));
 | 
						|
	//调用父类的构造函数
 | 
						|
	if (ret)
 | 
						|
	{
 | 
						|
		mymemset (ret,0,sizeof ( WIN_AnimationStruct));
 | 
						|
		if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size))
 | 
						|
		{
 | 
						|
			//创建失败
 | 
						|
			myfree (ret);
 | 
						|
			ret=0;
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			//构造
 | 
						|
			((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)
 | 
						|
{
 | 
						|
	//释放图片占用的内存
 | 
						|
	GIF_DecodeStructFree (animation->gif);
 | 
						|
	
 | 
						|
	myfree(animation->gif);
 | 
						|
	
 | 
						|
	//调用父类的销毁函数
 | 
						|
	WIN_DeleteWindow ( (WIN_WindowStruct *)animation);
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
//消息框的绘制函数
 | 
						|
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);
 | 
						|
}
 | 
						|
 | 
						|
//消息框的消息处理函数
 | 
						|
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;
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
//gif解码工作函数
 | 
						|
static int decode_gif (void *ptr)
 | 
						|
{
 | 
						|
	decode_gif_struct *t=ptr;
 | 
						|
	return GIF_Decode (t->gif,t->name);
 | 
						|
}
 | 
						|
 | 
						|
 
 | 
						|
 | 
						|
 | 
						|
 | 
						|
//显示一个图片
 | 
						|
WIN_AnimationStruct *ANIMATION_ShowGif (WIN_WindowStruct *base,char *name)
 | 
						|
{
 | 
						|
	//解码GIF图片
 | 
						|
	//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));
 | 
						|
	if(WORKING_DoWork (base,"动画解码中。。。",decode_gif,&dec)==0)
 | 
						|
	{
 | 
						|
		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;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
//显示一个图片指定时间
 | 
						|
WIN_AnimationStruct *ANIMATION_ShowGifTime (WIN_WindowStruct *base,char *name,u32 ms)
 | 
						|
{
 | 
						|
	//解码GIF图片
 | 
						|
	//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));
 | 
						|
	WORKING_DoWork (base,"动画解码中。。。",decode_gif,&dec);
 | 
						|
	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;
 | 
						|
	
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 |