ISnowMenu.c
资源名称:brewmine3.rar [点击查看]
上传用户:yulinhuamu
上传日期:2009-12-26
资源大小:7287k
文件大小:6k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "ISnowMenu.h"
- #include "AEEAppGen.h"
- #include "Winmine.bid"
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- //
- #define MAX_POPO_NUM 3
- #define POPO_TATE 200
- #define MENUMOVE_STEP 48
- #define MINE_TANSPARENT_COLOR MAKE_RGB(255,255,255)
- #define BUTTONCOL_SEL MAKE_RGB(255,0,0)
- #define BUTTONCOL_UNSEL MAKE_RGB(0,255,0)
- static void ISNOWMENU_TimerHDL(ISnowMenu* pCtl);
- static boolean ISNOWMENU_GeneratePopo(ISnowMenu* pCtl);
- static boolean ISNOWMENU_Draw(ISnowMenu* pCtl);
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- ISnowMenu* ISNOWMENU_CreateInstance()
- {
- AEEDeviceInfo di;
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- ISnowMenu* pCtl=MALLOCREC(ISnowMenu);
- if(NULL==pCtl||NULL==pApp)
- {
- ISNOWMENU_Release(pCtl);
- return NULL;
- }
- pCtl->m_pIDisplay=pApp->m_pIDisplay;
- pCtl->m_pIShell=pApp->m_pIShell;
- pCtl->m_Popo=NULL;
- pCtl->m_PopoNum=0;
- pCtl->m_ActiveItem=CMD_MENUSTART;
- ISHELL_GetDeviceInfo(pApp->m_pIShell,&di);
- pCtl->m_rt.x=pCtl->m_rt.y=0;
- pCtl->m_rt.dx=di.cxScreen;
- pCtl->m_rt.dy=di.cyScreen;
- pCtl->m_pOldScreen=ISHELL_LoadBitmap(pApp->m_pIShell,"menuimg/menu.bmp");
- pCtl->m_pCursor=ISHELL_LoadBitmap(pApp->m_pIShell,"menuimg/cur.bmp");
- if(pCtl->m_pCursor)
- {
- AEEBitmapInfo info;
- IBITMAP_SetTransparencyColor(pCtl->m_pCursor,IBITMAP_RGBToNative(pCtl->m_pCursor,MINE_TANSPARENT_COLOR));
- IBITMAP_GetInfo(pCtl->m_pCursor,&info,sizeof(AEEBitmapInfo));
- pCtl->m_CursorRect.dx=(int)info.cx;
- pCtl->m_CursorRect.dy=(int)info.cy;
- pCtl->m_CursorRect.x=pCtl->m_rt.x+pCtl->m_rt.dx-2*pCtl->m_CursorRect.dx;
- pCtl->m_CursorRect.y=pCtl->m_rt.y+pCtl->m_rt.dy/4;
- }
- pCtl->m_pMusic=IMINEMUSIC_CreateInstance(pApp->m_pIShell);
- return pCtl;
- }
- boolean ISNOWMENU_Release(ISnowMenu* pCtl)
- {
- if(!pCtl) return FALSE;
- ISNOWMENU_Stop(pCtl);
- if(pCtl->m_pOldScreen)
- {
- IBITMAP_Release(pCtl->m_pOldScreen);
- pCtl->m_pOldScreen=NULL;
- }
- if(pCtl->m_pMusic)
- {
- IMINEMUSIC_Release(pCtl->m_pMusic);
- pCtl->m_pMusic=NULL;
- }
- return TRUE;
- }
- boolean ISNOWMENU_Start(ISnowMenu* pCtl)
- {
- if(!ISNOWMENU_Stop(pCtl)) return FALSE;
- IMINEMUSIC_Start(pCtl->m_pMusic,MMT_FLASH);
- ISNOWMENU_TimerHDL(pCtl);
- return TRUE;
- }
- boolean ISNOWMENU_Stop(ISnowMenu* pCtl)
- {
- TPopo* popo;
- if(!pCtl) return FALSE;
- ISHELL_CancelTimer(pCtl->m_pIShell,(PFNNOTIFY)ISNOWMENU_TimerHDL, pCtl);
- //release all popo
- popo=pCtl->m_Popo;
- while(popo)
- {
- pCtl->m_Popo=popo->pNext;
- if(popo->bitmap)
- IBITMAP_Release(popo->bitmap);
- FREE(popo);
- popo=pCtl->m_Popo;
- }
- pCtl->m_PopoNum=0;
- IMINEMUSIC_Stop(pCtl->m_pMusic);
- return TRUE;
- }
- boolean ISNOWMENU_HandleKeyEvent(ISnowMenu* pCtl,uint16 wParam)
- {
- if(!pCtl) return FALSE;
- switch(wParam)
- {
- case AVK_SELECT:
- case AVK_RIGHT:
- ISNOWMENU_Stop(pCtl);
- ISHELL_PostEvent(pCtl->m_pIShell, AEECLSID_WINMINE, EVT_USER, pCtl->m_ActiveItem, (uint32) 0);
- break;
- case AVK_UP:
- pCtl->m_ActiveItem--;
- if(CMD_MENUMIN==pCtl->m_ActiveItem)
- pCtl->m_ActiveItem=CMD_MENUMAX-1;
- ISNOWMENU_Draw(pCtl);
- break;
- case AVK_DOWN:
- pCtl->m_ActiveItem++;
- if(CMD_MENUMAX==pCtl->m_ActiveItem)
- pCtl->m_ActiveItem=CMD_MENUMIN+1;
- ISNOWMENU_Draw(pCtl);
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- static void ISNOWMENU_TimerHDL(ISnowMenu* pCtl)
- {
- TPopo* popo;
- ISHELL_CancelTimer(pCtl->m_pIShell,(PFNNOTIFY)ISNOWMENU_TimerHDL, pCtl);
- //refresh popo local
- ISNOWMENU_GeneratePopo(pCtl);
- popo=pCtl->m_Popo;
- while(popo)
- {
- popo->rt.y-=10;
- if(popo->rt.y<(0-popo->rt.dy))
- {
- TPopo* p;
- if(popo==pCtl->m_Popo)//first
- {
- pCtl->m_Popo=NULL;
- }
- else
- {
- p=pCtl->m_Popo;
- while(p->pNext!=popo) p=p->pNext;
- p->pNext=NULL;
- }
- while(popo)
- {
- p=popo;
- popo=p->pNext;
- if(p->bitmap)
- IBITMAP_Release(p->bitmap);
- FREE(p);
- pCtl->m_PopoNum--;
- }
- }
- else
- popo=popo->pNext;
- }
- //draw
- ISNOWMENU_Draw(pCtl);
- ISHELL_SetTimer(pCtl->m_pIShell,100,(PFNNOTIFY)ISNOWMENU_TimerHDL, pCtl);
- }
- static boolean ISNOWMENU_GeneratePopo(ISnowMenu* pCtl)
- {
- byte data;
- char* filename;
- TPopo* popo;
- AEEBitmapInfo info;
- if(pCtl->m_PopoNum>=MAX_POPO_NUM) return FALSE;
- GETRAND(&data,1);
- if(data<POPO_TATE) return FALSE;
- data-=POPO_TATE;
- popo=MALLOCREC(TPopo);
- if(!popo) return FALSE;
- switch(data&3)
- {
- case 0:
- filename="menuimg/pop1.bmp";
- break;
- case 1:
- filename="menuimg/pop2.bmp";
- break;
- default:
- filename="menuimg/pop3.bmp";
- }
- popo->bitmap= ISHELL_LoadBitmap(pCtl->m_pIShell,filename);
- if(!popo->bitmap)
- {
- FREEIF(popo);
- return FALSE;
- }
- IBITMAP_SetTransparencyColor(popo->bitmap,IBITMAP_RGBToNative(popo->bitmap,MINE_TANSPARENT_COLOR));
- IBITMAP_GetInfo(popo->bitmap,&info,sizeof(AEEBitmapInfo));
- popo->rt.dx=(int)info.cx;
- popo->rt.dy=(int)info.cy;
- popo->rt.x=pCtl->m_rt.dx*data/(256-POPO_TATE)-(int)info.cx/2;
- popo->rt.y=pCtl->m_rt.dy;
- pCtl->m_PopoNum++;
- popo->pNext=pCtl->m_Popo;
- pCtl->m_Popo=popo;
- return TRUE;
- }
- static boolean ISNOWMENU_Draw(ISnowMenu* pCtl)
- {
- TPopo* popo=pCtl->m_Popo;
- AEERect rect=pCtl->m_rt;
- //background
- if(pCtl->m_pOldScreen)
- {
- IDISPLAY_BitBlt(pCtl->m_pIDisplay,
- 0,0,
- pCtl->m_rt.dx,
- pCtl->m_rt.dy,
- pCtl->m_pOldScreen,
- 0,0,
- AEE_RO_COPY);
- }
- else
- IDISPLAY_ClearScreen(pCtl->m_pIDisplay);
- IDISPLAY_FrameRect(pCtl->m_pIDisplay,&rect);
- //menu
- if(pCtl->m_pCursor)
- {
- int y=(CMD_MENUSTART==pCtl->m_ActiveItem)?0:((CMD_MENUSCORE==pCtl->m_ActiveItem)?1:2);
- IDISPLAY_BitBlt(pCtl->m_pIDisplay,
- pCtl->m_CursorRect.x,(pCtl->m_CursorRect.y+y*MENUMOVE_STEP),
- pCtl->m_CursorRect.dx,pCtl->m_CursorRect.dy,
- pCtl->m_pCursor,
- 0,0,
- AEE_RO_TRANSPARENT );
- }
- //popo
- while(popo)
- {
- if(popo->bitmap)
- IDISPLAY_BitBlt(pCtl->m_pIDisplay,
- popo->rt.x,popo->rt.y,
- popo->rt.dx,popo->rt.dy,
- popo->bitmap,
- 0,0,
- AEE_RO_TRANSPARENT );
- popo=popo->pNext;
- }
- IDISPLAY_Update(pCtl->m_pIDisplay);
- return TRUE;
- }