📄 fep_game_window.c
字号:
//////////////////////////////////////////////////////////////////////////////////
//! \addtogroup ex_flash
//! @{
//
// Copyright (c) 2004-2005 SigmaTel, Inc.
//
//! \file fep_jpeg_window.c
//! \brief example player JPEG user interface
//! \version 1.0
//! \date 08-Aug 2005
//!
//! <Details here...>
//!
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Includes and external references
////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include "error.h"
#include "components\uim.h" // see uim_DoModal()
#include "btn_translation.h"
#include "components\handlealloc.h"
#include "components\gfx.h"
#include "src\widgets\fep_widgets.h" // Flash Example Player defines/prototypes
#include "src\fep_data.h" // Flash Example Player global data
#include "player_resources.h"
#include <os\tx_api.h>
#include "components\asi_messages.h"
#include "components\ui_messages.h"
#include "components\pqi.h"
#include "components\cmi\cmi_dai.h"
#include "components\asi_api.h"
extern gfx_Font_t g_13pxFont;
extern TX_QUEUE *g_ptx_queue_ui;
// resource playback used for background music
#include "components\mixer_api.h"
extern asi_StreamModeSetting_t g_eAsmMode;
extern asi_AudioState_t g_eAsmState;
//extern asi_StreamModule_t * g_pstDecStreamModule;
typedef enum _Resource_Playback_Mode {
RSPB_NORMAL,
RSPB_REPEAT,
}Resource_Playback_Mode_t;
typedef enum _Resource_Playback_State {
RSPB_PLAYBACK,
RSPB_END,
RSPB_INIT
}Resource_Playback_State_t;
typedef struct _Resource_Playback {
int32_t i32ResourceID;
int32_t i32ResourceHandle;
uint32_t u32ResourceSize;
uint32_t u32ResourceCurrentPos;
Resource_Playback_State_t state;
uint8_t channel;
uint32_t SamplingRate;
uint8_t format;
uint8_t *pRSData;
mixer_StreamHndl_t MixerHandle;
Resource_Playback_Mode_t mode;
}Resourc_Playback_t;
#ifndef WIN32
extern Resourc_Playback_t rs_playback;
extern RtStatus_t resource_playback(int32_t i32ResourceID, uint32_t u32Gain, Resource_Playback_Mode_t eMode);
#endif
const int8_t fourbricks[4][7][4][2] =
{
{
{ {-1,0},{0,0},{1,0},{2,0} }, //....note: -1,0,1,2 present the coordinate
{ {-1,0},{0,0},{1,0},{-1,1} }, //:''
{ {-1,0},{0,0},{1,0},{0,1} }, //':'
{ {-1,0},{0,0},{1,0},{1,1} }, //'':
{ {-1,0},{0,0},{-1,1},{0,1} }, //::
{ {-1,0},{0,0},{0,1},{1,1} }, //':.
{ {0,0},{1,0},{-1,1},{0,1} }, //.:'
},
{
{ {0,-1},{0,0},{0,1},{0,2} },
{ {-1,-1},{0,-1},{0,0},{0,1} },
{ {0,-1},{-1,0},{0,0},{0,1} },
{ {0,-1},{0,0},{0,1},{-1,1} },
{ {-1,0},{0,0},{-1,1},{0,1} },
{ {0,-1},{0,0},{-1,0},{-1,1} },
{ {-1,-1},{-1,0},{0,0},{0,1} },
},
{
{ {-1,0},{0,0},{1,0},{2,0} },
{ {1,-1},{-1,0},{0,0},{1,0} },
{ {0,-1},{-1,0},{0,0},{1,0} },
{ {-1,-1},{-1,0},{0,0},{1,0} },
{ {-1,0},{0,0},{-1,1},{0,1} },
{ {-1,0},{0,0},{0,1},{1,1} },
{ {0,0},{1,0},{-1,1},{0,1} },
},
{
{ {0,-1},{0,0},{0,1},{0,2} },
{ {0,-1},{0,0},{0,1},{1,1} },
{ {0,-1},{0,0},{1,0},{0,1} },
{ {0,-1},{1,-1},{0,0},{0,1} },
{ {-1,0},{0,0},{-1,1},{0,1} },
{ {0,-1},{0,0},{-1,0},{-1,1} },
{ {-1,-1},{-1,0},{0,0},{0,1} },
}
};
uint8_t u8LevelToHeartBeat[11] =
{
0, // no use
40, // 1 level
20,
15,
10,
8,
6,
4,
3,
2,
1
};
//make a new 4brick
void fep_window_Game_New4Bricks(GameBrickWidget_t *pGameBrickWidget)
{
uint8_t i,j;
pGameBrickWidget->Active = 1;
pGameBrickWidget->FourBrick_X=5;
pGameBrickWidget->FourBrick_Y=1;
pGameBrickWidget->Direct = 0;
pGameBrickWidget->Type = pGameBrickWidget->NextType;
pGameBrickWidget->NextType = rand()%7;
// clear the next brick grid
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
pGameBrickWidget->NextBrickGrid[i][j] = 0;
}
}
// data to grid of next brick
for(i=0;i<4;i++)
{
pGameBrickWidget->NextBrickGrid[1+fourbricks[0][pGameBrickWidget->NextType][i][1]][1+fourbricks[0][pGameBrickWidget->NextType][i][0]] = 1;
}
}
//clear the old 4brick
void fep_window_Game_Clear4Bricks(GameBrickWidget_t *pGameBrickWidget)
{
uint8_t i;
for(i=0; i<4; i++)
{
pGameBrickWidget->BrickGrid[pGameBrickWidget->FourBrick_Y + fourbricks[pGameBrickWidget->Direct][pGameBrickWidget->Type][i][1]][pGameBrickWidget->FourBrick_X + fourbricks[pGameBrickWidget->Direct][pGameBrickWidget->Type][i][0]] = 0;
}
}
//draw the new 4brick
uint8_t fep_window_Game_Set4Bricks(GameBrickWidget_t *pGameBrickWidget)
{
uint8_t i;
uint8_t ret=0;
// if the original bit is set to 1, that means there are already a brick,
// then break,return 1
for(i=0; i<4; i++)
{
if(pGameBrickWidget->BrickGrid[pGameBrickWidget->FourBrick_Y + fourbricks[pGameBrickWidget->Direct][pGameBrickWidget->Type][i][1]][pGameBrickWidget->FourBrick_X + fourbricks[pGameBrickWidget->Direct][pGameBrickWidget->Type][i][0]] == 1 )
{
ret = 1;
break;
}
}
if(ret == 1)
{
return ret;
}
else
{
for(i=0; i<4; i++)
{
pGameBrickWidget->BrickGrid[pGameBrickWidget->FourBrick_Y + fourbricks[pGameBrickWidget->Direct][pGameBrickWidget->Type][i][1]][pGameBrickWidget->FourBrick_X + fourbricks[pGameBrickWidget->Direct][pGameBrickWidget->Type][i][0]] = 1;
}
return ret;
}
}
//make a new 4brick
void fep_window_Game_Init(Widget_t *pWidget)
{
GameBrickWidget_t *pGameBrickWidget = (GameBrickWidget_t *)pWidget;
uint8_t i,j;
for(i=1; i<16; i++)
{
for(j=1;j<11; j++)
{
pGameBrickWidget->BrickGrid[i][j] = 0;
}
}
for(i=0; i<16; i++)
{
pGameBrickWidget->BrickGrid[i][0]=1;
pGameBrickWidget->BrickGrid[i][11]=1;
}
for(i=0; i<12; i++)
{
pGameBrickWidget->BrickGrid[0][i]=1;
pGameBrickWidget->BrickGrid[16][i]=1;
}
pGameBrickWidget->NextType = rand()%7;
fep_window_Game_New4Bricks(pGameBrickWidget);
fep_window_Game_Set4Bricks(pGameBrickWidget);
pGameBrickWidget->Level = 1;
pGameBrickWidget->Score = 0;
pGameBrickWidget->Pause = 0;
pGameBrickWidget->Dead = 0;
uim_widget_SetProperty(pWidget,WIDGET_PROPERTY_HEARTBEAT, u8LevelToHeartBeat[pGameBrickWidget->Level]); // set its heartbeat timeout field
}
///////////////////////////////////////////////////////////////////////////////
//! \brief This function is main message processing routine.
//! for JPEG photo
//!
//! \param[in] pWidget The parent widget.
//! \param[in] pMsg Message pointer.
//! \param[in] piResult ???.
///////////////////////////////////////////////////////////////////////////////
int fep_window_Game_ProcessMessage(Widget_t *pWidget, os_msg_struct_t *pMsg, int *piResult)
{
Widget_t *pNewWidget,*pNewWidget2; // ptr to child widgets attached to this window
RtStatus_t rtnStat;
GameBrickWidget_t *pGameBrickWidget = (GameBrickWidget_t *)pWidget;
// uint32_t ItemHeight=BITMAPSTINGLIST_ITEM_HEIGHT;
// asi_StreamParameters_t *pDecShellInStreamParams = g_pstDecStreamModule->InputStream.pStreams;
int iRtn = WIDGET_PROCESS_MSG_NOT_HANDLED;
switch(pMsg->MsgNum)
{
case MSG_UI_BTN_EVENT:
switch (pMsg->u32DataWord)
{
case BTN_EVENT_IS(BTN_FF, EVENT_DOWN):
case BTN_EVENT_IS(BTN_FF, EVENT_CLICK):
case BTN_EVENT_IS(BTN_FF, EVENT_HOLD):
if( pGameBrickWidget->Active && !pGameBrickWidget->Pause && !pGameBrickWidget->Dead )
{
fep_window_Game_Clear4Bricks(pGameBrickWidget);
pGameBrickWidget->FourBrick_X++;
if( fep_window_Game_Set4Bricks(pGameBrickWidget) )
{
pGameBrickWidget->FourBrick_X--;
fep_window_Game_Set4Bricks(pGameBrickWidget);
}
uim_widget_MarkRectForUpdate((Widget_t *)pGameBrickWidget,NULL); // update the entire container area
}
rand();
iRtn = WIDGET_PROCESS_MSG_HANDLED;
break;
case BTN_EVENT_IS(BTN_RW, EVENT_DOWN):
case BTN_EVENT_IS(BTN_RW, EVENT_CLICK):
case BTN_EVENT_IS(BTN_RW, EVENT_HOLD):
if( pGameBrickWidget->Active && !pGameBrickWidget->Pause && !pGameBrickWidget->Dead)
{
fep_window_Game_Clear4Bricks(pGameBrickWidget);
pGameBrickWidget->FourBrick_X--;
if( fep_window_Game_Set4Bricks(pGameBrickWidget) )
{
pGameBrickWidget->FourBrick_X++;
fep_window_Game_Set4Bricks(pGameBrickWidget);
}
uim_widget_MarkRectForUpdate((Widget_t *)pGameBrickWidget,NULL); // update the entire container area
}
rand();
iRtn = WIDGET_PROCESS_MSG_HANDLED;
break;
case BTN_EVENT_IS(BTN_MENU, EVENT_DOWN):
case BTN_EVENT_IS(BTN_MENU, EVENT_CLICK):
if( pGameBrickWidget->Active && !pGameBrickWidget->Pause && !pGameBrickWidget->Dead)
{
fep_window_Game_Clear4Bricks(pGameBrickWidget);
pGameBrickWidget->Direct++;
pGameBrickWidget->Direct%= 4;
if( fep_window_Game_Set4Bricks(pGameBrickWidget) )
{
pGameBrickWidget->Direct--;
pGameBrickWidget->Direct%= 4;
fep_window_Game_Set4Bricks(pGameBrickWidget);
}
uim_widget_MarkRectForUpdate((Widget_t *)pGameBrickWidget,NULL); // update the entire container area
}
rand();
iRtn = WIDGET_PROCESS_MSG_HANDLED;
break;
case BTN_EVENT_IS(BTN_VOLDN, EVENT_DOWN):
case BTN_EVENT_IS(BTN_VOLDN, EVENT_CLICK):
case BTN_EVENT_IS(BTN_VOLDN, EVENT_HOLD):
case BTN_EVENT_IS(BTN_VOLDN, EVENT_UP):
if( pGameBrickWidget->Active && !pGameBrickWidget->Pause && !pGameBrickWidget->Dead)
{
fep_window_Game_Clear4Bricks(pGameBrickWidget);
pGameBrickWidget->FourBrick_Y++;
if( fep_window_Game_Set4Bricks(pGameBrickWidget) )
{
pGameBrickWidget->FourBrick_Y--;
fep_window_Game_Set4Bricks(pGameBrickWidget);
pGameBrickWidget->Active = 0;
}
uim_widget_MarkRectForUpdate((Widget_t *)pGameBrickWidget,NULL); // update the entire container area
}
rand();
iRtn = WIDGET_PROCESS_MSG_HANDLED;
break;
case BTN_EVENT_IS(BTN_PLAY, EVENT_CLICK):
if(!pGameBrickWidget->Dead)
{
pGameBrickWidget->Pause = !pGameBrickWidget->Pause;
if( pGameBrickWidget->Pause )
{
uim_widget_SetProperty((Widget_t *)pGameBrickWidget,WIDGET_PROPERTY_HEARTBEAT, 0); // set its heartbeat timeout field
}
else
{
uim_widget_SetProperty((Widget_t *)pGameBrickWidget,WIDGET_PROPERTY_HEARTBEAT, u8LevelToHeartBeat[pGameBrickWidget->Level]); // set its heartbeat timeout field
}
uim_widget_MarkRectForUpdate((Widget_t *)pGameBrickWidget,NULL); // update the entire container area
}
else
{
fep_window_Game_Init(pWidget);
}
iRtn = WIDGET_PROCESS_MSG_HANDLED;
break;
case BTN_EVENT_IS(BTN_MENU, EVENT_HOLD):
iRtn= WIDGET_PROCESS_MSG_HANDLED;
if(!pGameBrickWidget->bInSubWindow)
{
os_msg_struct_t msg;
//Pop up Game option menu
int32_t i32PopUp;
int32_t i32PopUpLevel = 0;
uint32_t PopUpList[]=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -