⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myimage.c

📁 手机开发环境BREW实例
💻 C
字号:
/*===========================================================================

FILE: MyImage.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEFile.h"			// File interface definitions
#include "AEEStdLib.h"        // AEE Stb Lib Services
#include "AEEMenu.h"          // AEE Menu Services
#include "AEEImageCtl.h"      // AEE ImageCtl Services
#include "AEEDisp.h"
#include "MyImage.bid"
#include "MyImage_res.h"
#include "MyImage.h"

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean MyImage_HandleEvent(IApplet * pi, AEEEvent eCode, 
                                      uint16 wParam, uint32 dwParam);

/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */

/*===========================================================================

FUNCTION: AEEClsCreateInstance

DESCRIPTION
	This function is invoked while the app is being loaded. All Modules must provide this 
	function. Ensure to retain the same name and parameters for this function.
	In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
	that has been provided in AEEAppGen.c. 

   After invoking AEEApplet_New(), this function can do app specific initialization. In this
   example, a generic structure is provided so that app developers need not change app specific
   initialization section every time except for a call to IDisplay_InitAppData(). 
   This is done as follows: InitAppData() is called to initialize AppletData 
   instance. It is app developers responsibility to fill-in app data initialization 
   code of InitAppData(). App developer is also responsible to release memory 
   allocated for data contained in AppletData -- this can be done in 
   IDisplay_FreeAppData().

PROTOTYPE:
   int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)

PARAMETERS:
	clsID: [in]: Specifies the ClassID of the applet which is being loaded

	pIShell: [in]: Contains pointer to the IShell object. 

	pIModule: pin]: Contains pointer to the IModule object to the current module to which
	this app belongs

	ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
	of memory for this structure and initializing the base data members is done by AEEApplet_New().

DEPENDENCIES
  none

RETURN VALUE
  AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
     successful
  EFAILED: If the app does not need to be loaded or if errors occurred in 
     AEEApplet_New(). If this function returns FALSE, the app will not be loaded.

SIDE EFFECTS
  none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_MYIMAGE){
      if(AEEApplet_New(sizeof(CPlayerWin), ClsId, pIShell,po,(IApplet**)ppObj,
         (AEEHANDLER)MyImage_HandleEvent,(PFNFREEAPPDATA)AutoImage_FreeAppData)
         == TRUE)
      {
		 // Add your code here .....
			if(AutoImage_InitAppData((IApplet*)*ppObj))
				return (AEE_SUCCESS);
			else
			{
				IAPPLET_Release((IApplet*)*ppObj);
				*ppObj = NULL;
				return EFAILED;
			}
      }
   }
	return (EFAILED);
}

static boolean AutoImage_InitAppData(IApplet* po)
{
	CPlayerWin * pme = (CPlayerWin *) po;
	int nAscent,nDescent;
	AEEDeviceInfo * pdi;
	AEERect  rectTitle;
	IImage * pImage;
	int cx;
	int y;
	int dy;
	char * pszFile = "media/Mouse.bci";

	//得到屏幕的相关信息
	pdi = MALLOC(sizeof(AEEDeviceInfo));
	if(!pdi)
		return FALSE;

	ISHELL_GetDeviceInfo(pme->a.m_pIShell,pdi);
	pme->m_cxWidth = pdi->cxScreen;
	pme->m_cyHeight = pdi->cyScreen;
	pme->m_nColorDepth = pdi->nColorDepth;
	FREEIF(pdi);

	IDISPLAY_GetFontMetrics(pme->a.m_pIDisplay,AEE_FONT_LARGE,&nAscent,&nDescent);
	pme->m_nLChSize = nAscent + nDescent;

	IDISPLAY_GetFontMetrics(pme->a.m_pIDisplay,AEE_FONT_NORMAL,&nAscent,&nDescent);
	pme->m_nNChSize = nAscent + nDescent;

	cx = pme->m_cxWidth;
	y = 1;
   dy = pme->m_nLChSize;
   SETAEERECT(&rectTitle, 0, y, cx, dy);

	ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_STATIC, (void **)&pme->m_pTitle);
	ISTATIC_SetRect(pme->m_pTitle, &rectTitle);
   ISTATIC_SetProperties(pme->m_pTitle, ST_CENTERTEXT | ST_NOSCROLL);

	y += rectTitle.dy + 1;
   dy = pme->m_cyHeight - y - 1;
   SETAEERECT(&pme->m_rectImage, 0, y, cx, dy);
   MEMCPY(&pme->m_rectImageCopy, &pme->m_rectImage, sizeof(AEERect));

	pme->m_pszFile = pszFile;
	pImage = ISHELL_LoadImage(pme->a.m_pIShell, pszFile);
	ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_IMAGECTL, (void **)&pme->m_pImageCtl);
 
   IIMAGECTL_SetRect(pme->m_pImageCtl, &pme->m_rectImage);
   IIMAGECTL_SetImage(pme->m_pImageCtl, pImage);
   pme->m_pImage = pImage;
   IIMAGE_Notify(pImage, CPlayerWin_ImageNotify, pme);

	CALLBACK_Init(&pme->m_cbRedraw,(PFNNOTIFY)AutoImage_RedrawNotify,pme);

	return TRUE;
}

void AutoImage_FreeAppData(IApplet* po)
{
	CPlayerWin *   pme = (CPlayerWin *)po;
	AutoImage_CancelRedraw(pme);    
}

static void AutoImage_CancelRedraw(CPlayerWin * pme)
{

	MP_RELEASEIF(pme->m_pTitle);

	FREEIF(pme->m_pszFile);

	MP_RELEASEIF(pme->m_pImage);
	MP_RELEASEIF(pme->m_pImageCtl);

}
static void CPlayerWin_ImageNotify(void * pUser, IImage * pImage, AEEImageInfo * pi, int nErr)
{
   CPlayerWin *   pme = (CPlayerWin *)pUser;

   if (pme->m_pImage == pImage && !nErr)
      AutoImage_Redraw(pme, FALSE);
}

static void AutoImage_Redraw(CPlayerWin * pme, boolean bDefer)
{
 
   if (bDefer)
      ISHELL_Resume(pme->a.m_pIShell, &pme->m_cbRedraw);//自动执行回调。
   else
      AutoImage_RedrawNotify(pme);
}

static void AutoImage_RedrawNotify(CPlayerWin * pme)
{
   CPlayerWin_Enable(pme,TRUE);
   CPlayerWin_Redraw(pme);

}

static void CPlayerWin_Enable(CPlayerWin * po, boolean bEnable)
{
   CPlayerWin *   pme = po;

   ISTATIC_SetActive(pme->m_pTitle, bEnable);

   IIMAGECTL_SetActive(pme->m_pImageCtl, bEnable);

}

static void CPlayerWin_Redraw(CPlayerWin * po)
{
   CPlayerWin *   pme = po;
   char *         pszFile = pme->m_pszFile;
   AEERect        rect;


   IDISPLAY_ClearScreen(pme->a.m_pIDisplay);


   // File name (title) text
   if (pszFile)
   {
      STRTOWSTR(MP_GetFileName(pszFile), pme->m_szText, sizeof(pme->m_szText));
      MP_FitStaticText(pme->a.m_pIDisplay, pme->m_pTitle, AEE_FONT_NORMAL, pme->m_szText);
      ISTATIC_Redraw(pme->m_pTitle);
   }

   // Draw the line below text.
   ISTATIC_GetRect(pme->m_pTitle, &rect);
   rect.y += rect.dy - 1; rect.dy = 1;
   MP_FrameRect(pme->a.m_pIDisplay, &rect);

   IIMAGECTL_Redraw(pme->m_pImageCtl);
   IDISPLAY_Update(pme->a.m_pIDisplay);

}

static void MP_FrameRect(IDisplay * pd, AEERect * pRect)
{
   RGBVAL   clr = IDISPLAY_SetColor(pd, CLR_USER_FRAME, CLR_SYS_DK_SHADOW);
   IDISPLAY_FrameRect(pd, pRect);
   IDISPLAY_SetColor(pd, CLR_USER_FRAME, clr);
}

static char * MP_GetFileName(const char * psz)
{
   char *   pszName = STRRCHR(psz, (int)DIRECTORY_CHAR);

   if (pszName)
      pszName++;
   else
      pszName = (char *)psz;

   return pszName;
}

static void MP_FitStaticText(IDisplay * pd, IStatic * ps, AEEFont font, AECHAR * pszText)
{
   int      nFits;
   AEERect  rect;
   int      nLen = WSTRLEN(pszText);
   AECHAR   chSave = (AECHAR)0;

   ISTATIC_GetRect(ps, &rect);
   IDISPLAY_MeasureTextEx(pd, font, pszText, -1, rect.dx,  &nFits);
   if (nFits < nLen)
   {
      chSave = pszText[nFits];
      pszText[nFits] = (AECHAR)0;
   }
   ISTATIC_SetText(ps, NULL, pszText, AEE_FONT_NORMAL, font);
   if (nFits < nLen)
      pszText[nFits] = chSave;
}

/*===========================================================================

FUNCTION MyImage_HandleEvent

DESCRIPTION
	This is the EventHandler for this app. All events to this app are handled in this
	function. All APPs must supply an Event Handler.

PROTOTYPE:
	boolean MyImage_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
	pi: Pointer to the AEEApplet structure. This structure contains information specific
	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 MyImage_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
	CPlayerWin * pme = (CPlayerWin *)pi;
   switch (eCode) 
	{
      case EVT_APP_START:                        
		    
		    // Add your code here .....
			AutoImage_DrawSplash(pme);

      	return(TRUE);
      case EVT_APP_STOP:
		  return (TRUE);

      default:
         break;
   }
   return FALSE;
}

static void AutoImage_DrawSplash(CPlayerWin * pme)
{
//	pme->m_bActive
   if (pme->m_bActive)
   {
		AutoImage_Redraw(pme, FALSE);
      return;
   }
   //从资源文件中装载图象并显示,同时,设置在一定时间内回调此函数。
   {
      IImage * pi = ISHELL_LoadResImage(pme->a.m_pIShell, MYIMAGE_RES_FILE, IDB_LOGO);

      if (pi)
      {
         AEERect  rect;

         IDISPLAY_ClearScreen(pme->a.m_pIDisplay);
         SETAEERECT(&rect, 0, 0, pme->m_cxWidth, pme->m_cyHeight);
         MP_DrawImage(pi, &rect, TRUE);
         IDISPLAY_Update(pme->a.m_pIDisplay);
         MP_RELEASEIF(pi);
      }

      pme->m_bActive = TRUE;
      ISHELL_SetTimer(pme->a.m_pIShell, MP_SPLASH_TIMER, (PFNNOTIFY)AutoImage_DrawSplash, pme);
   }  
}

static void MP_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter)
{
   AEEImageInfo   ii;
   int            x;
   int            y;

   IIMAGE_GetInfo(pImage, &ii);

   // 保证在装载范围内显示.
   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 + -