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

📄 myfirstapp.c

📁 application on brew
💻 C
字号:
/*===========================================================================
FILE: myfirstapp.c
===========================================================================*/


/*==============================================================================
INCLUDES AND VARIABLE DEFINITIONS
===============================================================================*/
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "myfirstapp.brh"       // Resource ID definitions
#include "myfirstapp.bid"

/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _myfirstapp {
	AEEApplet      a ;	       // First element of this structure must be AEEApplet
    AEEDeviceInfo  DeviceInfo; // Always have access to the hardware device information
    IDisplay      *pIDisplay;  // Give a standard way to access the Display interface
    IShell        *pIShell;    // Give a standard way to access the Shell interface

    int m_cxWidth;    // Stores the device screen width
	int m_cyHeight;   // Stores the device screen height
	int m_nCursorX;   // Stores the cursor bitmap x coordinate
	int m_nCursorY;   // Stores the cursor bitmap y coordinate
	IImage * pIImage; // IImage interface pointer

} myfirstapp;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static  boolean myfirstapp_HandleEvent(myfirstapp* pMe, 
                                                   AEEEvent eCode, uint16 wParam, 
                                                   uint32 dwParam);
boolean myfirstapp_InitAppData(myfirstapp* pMe);
void    myfirstapp_FreeAppData(myfirstapp* pMe);
static void myfirstapp_DrawScreen(myfirstapp * pMe);
static void myfirstapp_Move(myfirstapp * pMe, int xc, int yc);

/*===============================================================================
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: [in]: 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

*ppObj = NULL;
		
   if(AEEApplet_New( sizeof(AEEApplet),                  // Size of our private class
                     ClsId,                              // Our class ID
                     pIShell,                            // Shell interface
                     pMod,                               // Module instance
                     (IApplet**)ppObj,                   // Return object
                     (AEEHANDLER)myfirstapp_HandleEvent, // Our event handler
                     NULL))                              // No special "cleanup" function
      return(AEE_SUCCESS);

	return (EFAILED);
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
	*ppObj = NULL;

	if( ClsId == AEECLSID_MYFIRSTAPP )
	{
		// Create the applet and make room for the applet structure
		if( AEEApplet_New(sizeof(myfirstapp),
                          ClsId,
                          pIShell,
                          po,
                          (IApplet**)ppObj,
                          (AEEHANDLER)myfirstapp_HandleEvent,
                          (PFNFREEAPPDATA)myfirstapp_FreeAppData) ) // The FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
                          
		{
			// Initialize applet data, this is called before sending EVT_APP_START
            // To the HandleEvent function
			if(myfirstapp_InitAppData((myfirstapp*)*ppObj))
			{
				return(AEE_SUCCESS);
			}
			else
			{
				// Release the applet. This will free the memory allocated for the applet when
				// AEEApplet_New was called.
				IAPPLET_Release((IApplet*)*ppObj);
				return EFAILED;
			}

        } // End AEEApplet_New

    }

	return(EFAILED);
}


/*===========================================================================
FUNCTION SampleAppWizard_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 SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
	pMe: 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 myfirstapp_HandleEvent(myfirstapp* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{ 
    switch (eCode) 
	{
        // App is told it is starting up        
 	    case EVT_APP_START:                        
	    	myfirstapp_DrawScreen(pMe);
        	return(TRUE);

	    case EVT_APP_STOP:      
        	return(TRUE);
    
        case EVT_APP_SUSPEND:		    
        	return(TRUE);
    
        case EVT_APP_RESUME:
		    myfirstapp_DrawScreen(pMe);
        	return(TRUE);

        case EVT_APP_MESSAGE:
        	return(TRUE);

        // A key was pressed. Look at the wParam above to see which key was pressed. The key
        // codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
        case EVT_KEY:
		    switch (wParam)
		    {		
		        case AVK_LEFT:
		        case AVK_RIGHT:
			        myfirstapp_Move(pMe,(wParam == AVK_RIGHT ? 1 : -1),0); 
			        break;
		        case AVK_UP:
		        case AVK_DOWN:
		    	    myfirstapp_Move(pMe,0,(wParam == AVK_UP ? -1 : 1));
		    	    break;
		        default:
			        return(FALSE);
		}
      	return(TRUE);
    
        default:
            break;
   }
   return(FALSE);
}

/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent

DESCRIPTION
	Function is called when your application is starting up                 
    Initializes applet-specific data  

PROTOTYPE:
    boolean myfirstapp_InitAppData(myfirstapp* pMe)

PARAMETERS:
	pMe: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AEEClsCreateInstance() function.

DEPENDENCIES
    none

RETURN VALUE
    TRUE: If the app has processed the event
    FALSE: If the app did not process the event

SIDE EFFECTS
    none
===========================================================================*/

boolean myfirstapp_InitAppData(myfirstapp* pMe)
{	
	pMe -> pIImage = NULL;
	
	pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);	
	ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
	pMe->pIDisplay = pMe->a.m_pIDisplay;
	pMe->pIShell   = pMe->a.m_pIShell;   

	pMe->m_cxWidth =  pMe->DeviceInfo.cxScreen;	// Cache the width of the device screen
	pMe->m_cyHeight = pMe->DeviceInfo.cyScreen;	// Cache the height of the device screen
	
	pMe->m_nCursorX = pMe->m_cxWidth/2; 		// Initialize the coordinates of the 
	pMe->m_nCursorY = pMe->m_cyHeight*2/3;	    // Initial cursor position on the screen

	// If there have been no failures up to this point then return success
	return TRUE;
}

/*===========================================================================
FUNCTION myfirstapp_FreeAppData

DESCRIPTION
	Function is called when your application is exiting                       
    frees application data stored in the applet data structure.   

PROTOTYPE:
    void myfirstapp_FreeAppData(myfirstapp* pMe)

PARAMETERS:
	pMe: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AEEClsCreateInstance() function.

DEPENDENCIES
    none

RETURN VALUE
    TRUE: If the app has processed the event
    FALSE: If the app did not process the event

SIDE EFFECTS
    none
===========================================================================*/

void myfirstapp_FreeAppData(myfirstapp* pMe)
{
	if (pMe->pIImage != NULL)
	{
		IIMAGE_Release (pMe->pIImage);
		pMe->pIImage = NULL;
	}

}

/*===========================================================================
FUNCTION myfirstapp_Move

DESCRIPTION
	Function  that allows the user to move the cursor on the device screen.         
    The function uses an applet data structure pointer and two integer variables    
    corresponding to incremental movements of the cursor in the x and y directions.

PROTOTYPE:
    static void myfirstapp_Move(myfirstapp * pMe, int xc, int yc)

PARAMETERS:
	pMe: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AEEClsCreateInstance() function.

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 void myfirstapp_Move(myfirstapp * pMe, int xc, int yc)
{  
	AEEImageInfo iInfo;  
	int min, max;
	int x = pMe->m_nCursorX;                // x & y are intialized w/coordinates of the current
	int y = pMe->m_nCursorY;                // Cursor position
	IIMAGE_GetInfo (pMe->pIImage, &iInfo);  // IIMAGE_GetInfo gets the image information
	IDISPLAY_EraseRgn (pMe->pIDisplay, x, y, iInfo.cx,  iInfo.cy);  //erases the region where 
	x += xc;								// The cursor was previously displayed
	y += yc;  
	// Delimit the x & y coordinated to lower half of the screen
	min = 0;  
	max = pMe->m_cxWidth - iInfo.cx;  
	x = ((x < min) ? (min) : (x > max) ? max : (x));   
	min = pMe->m_cyHeight/2;  
	max = pMe->m_cyHeight - iInfo.cy;  
	y = ((y < min) ? (min) : (y > max) ? max : (y));   
	                                    // Draw cursor at new position.  
	IIMAGE_Draw (pMe->pIImage, x, y);   // Displays cursor at new coordinates
	pMe->m_nCursorX = x;                // Store new x coordinate  
	pMe->m_nCursorY = y;                // Store new y coordinate  
 	IDISPLAY_Update(pMe->pIDisplay);    // Update display.
}

/*===========================================================================
FUNCTION myfirstapp_DrawScreen

DESCRIPTION
	Function is called when the app starts and resumes.  Draws text and images      
    to the screen. 

PROTOTYPE:
    static void myfirstapp_DrawScreen(myfirstapp * pMe)

PARAMETERS:
	pMe: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AEEClsCreateInstance() function.

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 void myfirstapp_DrawScreen(myfirstapp * pMe)
{
	AEERect rc;
	AECHAR szBuf[30] = {0};
	AECHAR *szText = L"Hello BREW";
	
   
	IDISPLAY_DrawText(pMe->pIDisplay,      // Display instance
				AEE_FONT_BOLD,             // Use BOLD font
				szText,                    // Text - Normally comes from resource
				-1,                        // -1 = Use full string length
				0,                         // Ignored - IDF_ALIGN_CENTER
				0,                         // Ignored - IDF_ALIGN_MIDDLE
				NULL,                      // No clipping
				IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
   
	IDISPLAY_ClearScreen (pMe->pIDisplay); // Erases whole screen

	// Load string from resource file
	ISHELL_LoadResString(pMe->pIShell, MYFIRSTAPP_RES_FILE,IDS_STRING_1001, szBuf, sizeof (szBuf));  
	IDISPLAY_DrawText(pMe->pIDisplay, AEE_FONT_NORMAL, szBuf, -1, pMe->m_cxWidth/5, pMe->m_cyHeight/8, 0, IDF_ALIGN_CENTER);

	// Load string from resource file
	ISHELL_LoadResString(pMe->pIShell, MYFIRSTAPP_RES_FILE, IDS_STRING_1002, szBuf, sizeof (szBuf));  
	IDISPLAY_DrawText(pMe->pIDisplay, AEE_FONT_NORMAL, szBuf, -1, pMe->m_cxWidth/5, pMe->m_cyHeight/5, 0,IDF_ALIGN_CENTER ); 
	
	// Initialize rectangle
	SETAEERECT (&rc, 0, pMe->m_cyHeight/2-2, pMe->m_cxWidth, 2);
	IDISPLAY_DrawRect (pMe->pIDisplay, &rc, 0, 1, IDF_RECT_FILL);  
	pMe->pIImage = ISHELL_LoadResImage(pMe->pIShell,MYFIRSTAPP_RES_FILE,IDI_IMG_CURSOR);
	IIMAGE_Draw (pMe->pIImage, pMe->m_nCursorX, pMe->m_nCursorY); // Draws the image on the screen at the specified position  
	IDISPLAY_Update(pMe->pIDisplay);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -