?? pic.c
字號:
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean PicApp_HandleEvent(CPicApp * pApp, AEEEvent evt, uint16 w, uint32 dw)
{
switch (evt)
{
case EVT_APP_START:
return PicApp_Start(pApp);
case EVT_KEY:
return PicApp_HandleKey(pApp,w,dw);
default:
break;
}
return FALSE;
}
static boolean PicApp_InitAppData(CPicApp * pApp)
{
/*get the device information*/
AEEDeviceInfo deviceInfo;
ISHELL_GetDeviceInfo(pApp->a.m_pIShell, &deviceInfo);
/*get the height of font*/
pApp->m_nLineHeight = IDISPLAY_GetFontMetrics(pApp->a.m_pIDisplay,
AEE_FONT_NORMAL,
NULL,
NULL);
pApp->m_nLargeLineHeight = IDISPLAY_GetFontMetrics(pApp->a.m_pIDisplay,
AEE_FONT_LARGE,
NULL,
NULL);
SETAEERECT(&pApp->m_nClntAreaRect,
0,
0,
deviceInfo.cxScreen,
deviceInfo.cyScreen-pApp->m_nLargeLineHeight);
SETAEERECT(&pApp->m_nSoftkeyAreaRect,
pApp->m_nClntAreaRect.x,
pApp->m_nClntAreaRect.y+pApp->m_nClntAreaRect.dy,
pApp->m_nClntAreaRect.dx,
pApp->m_nLargeLineHeight);
pApp->m_nScrHeight = deviceInfo.cyScreen;
pApp->m_nScrWidth = deviceInfo.cxScreen;
pApp->m_x = (pApp->m_nScrWidth - GLASS_WIDTH)/2;
pApp->m_y = (pApp->m_nScrHeight - GLASS_HEIGHT)/2;
return TRUE;
}
static void PicApp_FreeAppData(CPicApp * pApp)
{
}
static void PicApp_ReleaseObj(void ** ppObj)
{
if ( ppObj && *ppObj )
{
(void) IBASE_Release( ( (IBase *) *ppObj ) );
*ppObj = NULL;
}
}
static boolean PicApp_Start(CPicApp * pApp)
{
IFile *pIFile = NULL;
unsigned long fileLen = 0;
const char *filename = "wallpaper.bmp";
AEERect nRect;
fileLen = UpStoGetFileSize(filename);
if(NULL != (pIFile = UpStoOpenFile(filename,_OFM_READ)))
{
UpStoReadFile(pIFile, 0, bmpimage,fileLen);
UpStoCloseFile(pIFile);
pIFile = NULL;
PicApp_DrawBMP(pApp->a.m_pIDisplay, (U8 *)bmpimage,0,0);
if(pApp->m_x > pApp->m_nScrWidth || pApp->m_x<1) pApp->m_x = 1;
if(pApp->m_y > pApp->m_nScrHeight || pApp->m_y<1) pApp->m_y = 1;
if(pApp->m_x + GLASS_WIDTH > pApp->m_nScrWidth) pApp->m_x = pApp->m_nScrWidth - GLASS_WIDTH;
if(pApp->m_y + GLASS_HEIGHT > pApp->m_nScrHeight) pApp->m_y = pApp->m_nScrHeight - GLASS_HEIGHT;
SETAEERECT(&nRect,
pApp->m_x,
pApp->m_y,
GLASS_WIDTH,
GLASS_HEIGHT);
PicApp_DrawRect(pApp->a.m_pIDisplay, (const AEERect *)&nRect,GLASS_COLOR);
IDISPLAY_Update(pApp->a.m_pIDisplay);
PicApp_SaveScreen(pApp->a.m_pIDisplay, "test.bmp");
return TRUE;
}
return FALSE;
}
static boolean PicApp_Stop(CPicApp * pApp)
{
return TRUE;
}
/*all Bitmap Data has been placed into imagedata */
static boolean PicApp_DrawBMP(IDisplay *pIdisp, U8 *imagedata,int x, int y)
{
BitmapFileHeader_Type *pbmpfileheader = NULL;
BitmapInfoHeader_Type *pbmpinfoheader = NULL;
U8 *pbitmapinfo;
int bytesPerRow;
IDIB *pdib=NULL;
U8 *pbmpinfo=imagedata;
if(NULL == imagedata) return FALSE;
if(!('B'==*imagedata && 'M'==*(imagedata+1)) ) return FALSE;
pbmpfileheader = (BitmapFileHeader_Type *)(pbmpinfo+2);
pbmpinfoheader=(BitmapInfoHeader_Type *)(pbmpinfo+2+sizeof(BitmapFileHeader_Type));
pbitmapinfo = pbmpinfo+pbmpfileheader->bfOffBits;
bytesPerRow = ((pbmpinfoheader->biWidth*pbmpinfoheader->biBitCount+31)/32)*4;
if(SUCCESS!=IDISPLAY_CreateDIBitmap(pIdisp,
(IDIB **)&pdib,
(uint8)pbmpinfoheader->biBitCount,
0,
0
))
return FALSE;
pdib->pBmp = pbitmapinfo+bytesPerRow*(pbmpinfoheader->biHeight-1);
pdib->pRGB = (U32 *)(pbmpinfo+14+pbmpinfoheader->biSize);
pdib->ncTransparent = 0; // 32-bit native color value
pdib->cx = (uint16)pbmpinfoheader->biWidth; // number of pixels in width
pdib->cy = (uint16)pbmpinfoheader->biHeight; // number of pixels in height
pdib->nPitch = -bytesPerRow; // offset from one row to the next
pdib->cntRGB = (uint16)(pbmpfileheader->bfOffBits-pbmpinfoheader->biSize-14)>>2; // number of palette entries
pdib->nDepth = (uint8)pbmpinfoheader->biBitCount; // size of pixel in bits
pdib->nColorScheme = IDIB_COLORSCHEME_888; // IDIB_COLORSCHEME_...
/* Do work for starting app */
IDISPLAY_BitBlt( pIdisp,
x,
y,
pdib->cx,
pdib->cy,
IDIB_TO_IBITMAP(pdib),
0,
0,
AEE_RO_COPY );
IDIB_Release(pdib);
return TRUE;
}
static int PicApp_SaveScreen(IDisplay *pIdisp, const char *filename)
{
IBitmap *pDevBmp = NULL;
IDIB *pDib = NULL;
const char *BMPFLAG = "BM";
int index = 0;
int byteswriten = 0;
BitmapFileHeader_Type FileHeader;
BitmapInfoHeader_Type InfoHeader;
MEMSET(&FileHeader,0, sizeof(BitmapFileHeader_Type));
MEMSET(&InfoHeader,0, sizeof(BitmapInfoHeader_Type));
if(SUCCESS == IDISPLAY_GetDeviceBitmap(pIdisp, &pDevBmp))
{
IFile *pIFile = NULL;
pDib = (IDIB *)pDevBmp;
FileHeader.bfOffBits = 2 + sizeof(BitmapFileHeader_Type) + sizeof(BitmapInfoHeader_Type) + pDib->cntRGB *sizeof(U32);
FileHeader.bfSize = FileHeader.bfOffBits + pDib->cy*pDib->nPitch;
InfoHeader.biSize = sizeof(BitmapInfoHeader_Type);
InfoHeader.biWidth = pDib->cx;
InfoHeader.biHeight = pDib->cy;
InfoHeader.biBitCount = pDib->nDepth;
InfoHeader.biXPelsPerMeter = 0;
InfoHeader.biYPelsPerMeter = 0;
InfoHeader.biClrUsed = pDib->cntRGB;
InfoHeader.biPlanes = 1;
InfoHeader.biSizeImage = pDib->cy*pDib->nPitch;
if(NULL != (pIFile = UpStoOpenFile(filename,_OFM_CREATE)))
{
byteswriten = UpStoWriteFile(pIFile, index, BMPFLAG,STRLEN(BMPFLAG));
index += byteswriten;
byteswriten = UpStoWriteFile(pIFile, index, &FileHeader,sizeof(BitmapFileHeader_Type));
index += byteswriten;
byteswriten = UpStoWriteFile(pIFile, index, &InfoHeader,sizeof(BitmapInfoHeader_Type));
index += byteswriten;
if(pDib->cntRGB > 0)
{
byteswriten = UpStoWriteFile(pIFile, index, pDib->pRGB,pDib->cntRGB *sizeof(U32));
index += byteswriten;
}
{
U8 *pSrc = pDib->pBmp + pDib->nPitch*(pDib->cy-1);
U32 row = pDib->cy;
U8 *tmp = NULL;
U8 *pDest = NULL;
tmp = MALLOC(pDib->nPitch*pDib->cy);
if(tmp)
{
pDest = tmp;
while(row--)
{
MEMCPY(pDest,pSrc,pDib->nPitch);
if(16 == pDib->nDepth)
{
U32 col = pDib->cx;
U16 *p = (U16 *)pDest;
while(col--)
{
*p = RGB565TORGB555(*p);
p++;
}
}
pDest += pDib->nPitch;
pSrc -= pDib->nPitch;
}
byteswriten = UpStoWriteFile(pIFile, index, tmp,pDib->nPitch*pDib->cy);
index += byteswriten;
}
else
{
while(row--)
{
byteswriten = UpStoWriteFile(pIFile, index, pSrc,pDib->nPitch);
pSrc -= pDib->nPitch;
index += byteswriten;
}
}
}
UpStoCloseFile(pIFile);
}
IBITMAP_Release(pDevBmp);
}
return -1;
}
static boolean PicApp_DrawRect(IDisplay *pIdisp, const AEERect *pRect, U16 transpCLR)
{
IBitmap *pDevBmp = NULL;
IDIB *pDib = NULL;
if(SUCCESS == IDISPLAY_GetDeviceBitmap(pIdisp, &pDevBmp))
{
pDib = (IDIB *)pDevBmp;
if(16 == pDib->nDepth)
{
U8 *pDest = (U8 *)pDib->pBmp;
int x = 0, y = 0;
pDest += pDib->nPitch * (pRect->y-1) + ((pRect->x)<<1);
for(y=0; y< pRect->dy;y++)
{
U16 *pBmp = (U16 *)pDest;
for(x=0; x<pRect->dx;x++)
{
*pBmp = *pBmp & transpCLR;
pBmp++;
}
pDest += pDib->nPitch;
}
}
IBITMAP_Release(pDevBmp);
}
return TRUE;
}
static boolean PicApp_HandleKey(CPicApp * pApp, uint16 w, uint32 dw)
{
AEERect nRect;
switch(w)
{
case AVK_UP:
pApp->m_y--;
break;
case AVK_DOWN:
pApp->m_y++;
break;
case AVK_LEFT:
pApp->m_x--;
break;
case AVK_RIGHT:
pApp->m_x++;
break;
default:
return FALSE;
}
PicApp_DrawBMP(pApp->a.m_pIDisplay, (U8 *)bmpimage,0,0);
if(pApp->m_x > pApp->m_nScrWidth || pApp->m_x<1) pApp->m_x = 1;
if(pApp->m_y > pApp->m_nScrHeight || pApp->m_y<1) pApp->m_y = 1;
if(pApp->m_x + GLASS_WIDTH > pApp->m_nScrWidth) pApp->m_x = pApp->m_nScrWidth - GLASS_WIDTH;
if(pApp->m_y + GLASS_HEIGHT > pApp->m_nScrHeight) pApp->m_y = pApp->m_nScrHeight - GLASS_HEIGHT;
SETAEERECT(&nRect,
pApp->m_x,
pApp->m_y,
GLASS_WIDTH,
GLASS_HEIGHT);
PicApp_DrawRect(pApp->a.m_pIDisplay, (const AEERect *)&nRect,GLASS_COLOR);
IDISPLAY_Update(pApp->a.m_pIDisplay);
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -