📄 test.c
字号:
{
// The following 'If statement' is entered only after the splash timer runs out...
if (pMe->m_eActiveWin == MPW_MAIN)
{
CTest_SetWindow(pMe, MPW_MAIN, 0);
return;
}
// Draw the splash screen, set the timer.
// The timer callback calls this function and redraws the main window.
{
IImage * pi = ISHELL_LoadResImage(pMe->a.m_pIShell, TEST_RES_FILE, IDB_LOGO);
if (pi)
{
AEERect rect;
IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
//初始化矩形屏幕
SETAEERECT(&rect, 0, 0, pMe->m_cxWidth, pMe->m_cyHeight);
CT_DrawImage(pi, &rect, TRUE);
IDISPLAY_Update(pMe->a.m_pIDisplay);
T_RELEASEIF(pi);
}
// Set main window as active and start the timer.
pMe->m_eActiveWin = MPW_MAIN;
ISHELL_SetTimer(pMe->a.m_pIShell, CT_SPLASH_TIMER, (PFNNOTIFY)CTest_DrawSplash, pMe);
}
}
/*=================================================================================
TEST DRAW Functions
===================================================================================
/*===========================================================================
This function schedules an aynchronous redraw if bDefer is TRUE else
it redras immediately.
===========================================================================*/
static void CTest_Redraw(test * pme, boolean bDefer)
{
if (pme->m_bRedraw)
return;
pme->m_bRedraw = TRUE;
if (bDefer)
ISHELL_Resume(pme->a.m_pIShell, &pme->m_cbRedraw);
else
CTest_RedrawNotify(pme);
}
/*===========================================================================
This function redraws the current window.
This function is called either by IShell in response to the resume scheduled
in CMediaPlayer_Redraw() or by CMediaPlayer_Redraw() directly.
===========================================================================*/
static void CTest_RedrawNotify(test * pme)
{
if (!pme->m_bRedraw)
return;
pme->m_bRedraw = FALSE;
if (pme->m_pWin)
{
IWINDOW_Enable(pme->m_pWin);
IWINDOW_Redraw(pme->m_pWin);
}
}
/*==================================================================================
CMainWin Functions
===================================================================================*/
/*===========================================================================
This function is the base class constructor of an IWindow object.
It allocates memory for the interface and sets the vtbl.
===========================================================================*/
static IWindow * CWindow_New(int16 nSize, test * pOwner, VTBL(IWindow) * pvt)
{
CWindow * pme;
VTBL(IWindow) * pVtbl;
pme = MALLOC(nSize + sizeof(VTBL(IWindow)));
if (!pme)
return NULL;
pme->m_pOwner = pOwner;
pme->m_pIShell = pme->m_pOwner->a.m_pIShell;
pme->m_pIDisplay = pme->m_pOwner->a.m_pIDisplay;
pVtbl = (VTBL(IWindow) *)((byte *)pme + nSize);
MEMCPY(pVtbl, pvt, sizeof(VTBL(IWindow)));
INIT_VTBL(pme, IWindow, *pVtbl);
return (IWindow *)pme;
}
/*===========================================================================
This function indicates if IWINDOW_Enable()/IWINDOW_Disable() needs to be
processed and also sets the bActive flag appropriately.
It is called by derived class IWINDOW_Enable() function before processing
the command.
===========================================================================*/
static boolean CWindow_ProcessEnable(IWindow * po, boolean bEnable)
{
CWindow * pme = (CWindow *)po;
boolean bProc = TRUE;
if (!bEnable)
{
if (pme->m_bActive)
{
pme->m_bActive = FALSE;
CTest_CancelRedraw(pme->m_pOwner);
}
else
bProc = FALSE;
}
else
{
if (pme->m_bActive)
bProc = FALSE;
else
pme->m_bActive = TRUE;
}
return bProc;
}
static boolean CTest_SetWindow(test * pme, TWindow eWin, uint32 dwParam)
{
// If same window, then redraw and return.
if (pme->m_pWin && pme->m_eActiveWin == eWin && eWin != MPW_NONE)
{
CTest_Redraw(pme, TRUE);
return TRUE;
}
CT_RELEASEWIN(pme->m_pWin);
switch (eWin)
{
case MPW_MAIN:
pme->m_pWin = CMainWin_New(pme);
break;
case MPW_FILELIST:
//pme->m_pWin = CFileListWin_New(pme);
break;
case MPW_PLAYER:
//pme->m_pWin = CPlayerWin_New(pme, (MPPlayerWin)dwParam);
break;
case MPW_NONE:
return TRUE;
break;
#if defined(MEDIAPLAYER_SETTINGS)
case MPW_SETTINGS:
return FALSE;
break;
#endif // defined(MEDIAPLAYER_SETTINGS)
default:
return FALSE;
break;
}
if (!pme->m_pWin)
{
eWin = MPW_NONE;
return FALSE;
}
pme->m_eActiveWin = eWin;
CTest_Redraw(pme, TRUE);
return TRUE;
}
/*===========================================================================
This function constucts the main window.
===========================================================================*/
static IWindow * CMainWin_New(test * pOwner)
{
CMainWin * pme;
VTBL(IWindow) vtbl;
CT_IWINDOW_SETVTBL(&vtbl, CMainWin_Enable, CMainWin_Redraw, CMainWin_HandleEvent, CMainWin_Delete);
pme = (CMainWin *)CWindow_New(sizeof(CMainWin), pOwner, &vtbl);
if (!pme)
return NULL;
{
int cx = pme->m_pOwner->m_cxWidth;
int cy = pme->m_pOwner->m_cyHeight;
int y, dy;
AEERect rect;
// Initialize logo below the header
pme->m_pLogo = ISHELL_LoadResImage(pme->m_pIShell, TEST_RES_FILE, IDB_LOGO);
pOwner->m_pLogo = pme->m_pLogo;
if (!pme->m_pLogo)
CT_WINERR_RETURN(pme);
y = pme->m_pOwner->m_rectHdr.dy + 1;
dy = cy/2 - y;
SETAEERECT(&pme->m_rectLogo, 0, y, cx, dy);
IIMAGE_SetFrameCount(pme->m_pLogo, 2);
IIMAGE_SetAnimationRate(pme->m_pLogo, 500);
if (ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_MENUCTL, (void **)&pme->m_pMainMenu))
CT_WINERR_RETURN(pme);
SETAEERECT(&rect, 0, cy/2 + 1, cx, cy/2 - 1);
CTest_SetMenuAttr(pme->m_pMainMenu, AEECLSID_MENUCTL, pme->m_pOwner->m_nColorDepth, &rect, 0);
CTest_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_PLAYFILE, NULL, IDB_PLAY, IDM_MAIN_PLAYFILE, 0);
CTest_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_RECORD, NULL, IDB_RECORD, IDM_MAIN_RECORD, 0);
#if defined(MEDIAPLAYER_SETTINGS)
CTest_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_SETTINGS, NULL, IDB_SETTINGS, IDM_MAIN_SETTINGS, 0);
#endif // defined(MEDIAPLAYER_SETTINGS)
CTest_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_ABOUT, NULL, IDB_ABOUT, IDM_MAIN_ABOUT, 0);
}
return (IWindow *)pme;
}
/*===========================================================================
This function enables/disables the main window.
===========================================================================*/
static void CMainWin_Enable(IWindow * pMe, boolean bEnable)
{
CMainWin * pme = (CMainWin *)pMe;
if (!CWindow_ProcessEnable(pMe, bEnable))
return;
if (!pme->m_bActive)
{
IMENUCTL_SetActive(pme->m_pMainMenu, FALSE);
IIMAGE_Stop(pme->m_pLogo);
return;
}
IDISPLAY_ClearScreen(pme->m_pOwner->a.m_pIDisplay);
IMENUCTL_SetActive(pme->m_pMainMenu, TRUE);
IMENUCTL_SetSel(pme->m_pMainMenu, pme->m_pOwner->m_wMainWin);
CT_DrawImage(pme->m_pLogo, &pme->m_pOwner->m_rectHdr, TRUE);
}
/*===========================================================================
This function redraws the main window.
===========================================================================*/
static void CMainWin_Redraw(IWindow * po)
{
CMainWin * pme = (CMainWin *)po;
if (!pme->m_bActive)
return;
IDISPLAY_ClearScreen(pme->m_pIDisplay);
CT_DRAWHEADER(pme);
CT_DrawImage(pme->m_pLogo, &pme->m_rectLogo, TRUE);
IMENUCTL_Redraw(pme->m_pMainMenu);
IDISPLAY_Update(pme->m_pIDisplay);
}
/*===========================================================================
This function deletes the main window.
===========================================================================*/
static void CMainWin_Delete(IWindow * po)
{
CMainWin * pme = (CMainWin *)po;
T_RELEASEIF(pme->m_pLogo);
if (pme->m_pMainMenu)
pme->m_pOwner->m_wMainWin = IMENUCTL_GetSel(pme->m_pMainMenu);
T_RELEASEIF(pme->m_pMainMenu);
FREE(pme);
}
/*===========================================================================
This function processes events routed to main window.
===========================================================================*/
static boolean CMainWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
CMainWin * pme = (CMainWin *)po;
boolean bRet = TRUE;
if (eCode == EVT_COPYRIGHT_END && pme->m_bAbout)
{
pme->m_bAbout = FALSE;
CTest_Redraw(pme->m_pOwner, TRUE);
return TRUE;
}
if (CT_ISEVTKEY(eCode))
return IMENUCTL_HandleEvent(pme->m_pMainMenu, eCode, wParam, dwParam);
if (!CT_ISEVTCMD(eCode))
return FALSE;
switch (wParam)
{
case IDM_MAIN_PLAYFILE:
CTest_SetWindow(pme->m_pOwner, MPW_FILELIST, 0);
break;
case IDM_MAIN_RECORD:
// CTest_RecordQCPFile(pme->m_pOwner, CT_QCP_REC_FILE);
break;
#if defined(MEDIAPLAYER_SETTINGS)
case IDM_MAIN_SETTINGS:
break;
#endif // defined(MEDIAPLAYER_SETTINGS)
case IDM_MAIN_ABOUT:
CMainWin_About(pme);
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
/*===========================================================================
This function displays the About dialog of the app.
===========================================================================*/
static void CMainWin_About(CMainWin * pme)
{
CTest_DisableWin(pme->m_pOwner);
pme->m_bAbout = TRUE;
IDISPLAY_ClearScreen(pme->m_pIDisplay);
CT_DRAWHEADER(pme);
ISHELL_ShowCopyright(pme->m_pIShell);
}
/*===========================================================================
Menu Functions
============================================================================*/
/*===========================================================================
This function sets the menu attributes based on BREW Style Sheet for
menu control.
===========================================================================*/
static void CTest_SetMenuAttr(IMenuCtl * pMenu, AEECLSID clsMenu, uint16 nColorDepth, AEERect * pRect, uint32 dwProps)
{
AEEItemStyle sel, normal;
AEEMenuColors col;
// Menu Style
normal.ft = MENU8_FT;
normal.xOffset = 0;
normal.yOffset = 0;
normal.roImage = MENU8_RO;
sel.ft = MENU8_SELECT_FT;
sel.xOffset = 0;
sel.yOffset = 0;
sel.roImage = MENU8_SELECT_RO;
// Menu Colors
col.cSelText = MENU8_SELECT_TEXT;
col.wMask = MENU8_COLOR_MASK;
if (clsMenu == AEECLSID_MENUCTL)
{
col.cBack = MENU8_BACKGROUND;
col.cSelBack = MENU8_SELECT_BACKGROUND;
dwProps |= IMENUCTL_GetProperties(pMenu);
}
else if (clsMenu == AEECLSID_SOFTKEYCTL || clsMenu == AEECLSID_ICONVIEWCTL)
{
col.cBack = TB8_BACKGROUND;
col.cSelBack = TB8_SELECT_BACKGROUND;
dwProps |= MP_ICON_TEXT_TOP | MP_NO_ARROWS;
}
if (clsMenu == AEECLSID_MENUCTL || clsMenu == AEECLSID_SOFTKEYCTL || clsMenu == AEECLSID_ICONVIEWCTL)
{
IMENUCTL_SetStyle(pMenu, &normal, &sel);
IMENUCTL_SetColors(pMenu, &col);
IMENUCTL_SetProperties(pMenu, dwProps);
if (pRect)
IMENUCTL_SetRect(pMenu, pRect);
}
}
/*===========================================================================
This function adds one item to the specified IMenuCtl.
===========================================================================*/
static boolean CTest_AddMenuItem(IMenuCtl * pMenu, uint16 wTextID, AECHAR * pText, uint16 wImageID, uint16 wItemID, uint32 dwData)
{
CtlAddItem ai;
// Fill in the CtlAddItem structure values
ai.pText = pText;
ai.pImage = NULL;
ai.pszResImage = TEST_RES_FILE;
ai.pszResText = TEST_RES_FILE;
ai.wText = wTextID;
ai.wFont = AEE_FONT_NORMAL;
ai.wImage = wImageID;
ai.wItemID = wItemID;
ai.dwData = dwData;
// Add the item to the menu control
return IMENUCTL_AddItemEx( pMenu, &ai );
}
/*===========================================================================
Draw Image Functions
============================================================================*/
/*===========================================================================
This function draws the image and centers it within the specified
rectangle if bCenter is TRUE.
===========================================================================*/
static void CT_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter)
{
AEEImageInfo ii;
int x;
int y;
IIMAGE_GetInfo(pImage, &ii);
// Do not display if image does not fit in the allocated rectangle.
if (ii.cx > pRect->dx || ii.cy > pRect->dy)
return;
if (bCenter)
{
x = pRect->x + (pRect->dx / 2) - (ii.cxFrame / 2);
y = pRect->y + (pRect->dy / 2) - (ii.cy / 2);
}
else
{
x = pRect->x;
y = pRect->y;
}
IIMAGE_Start(pImage, x, y);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -