mirror of https://github.com/axmolengine/axmol.git
126 lines
2.7 KiB
C++
126 lines
2.7 KiB
C++
// Application main form file.
|
|
|
|
// Original file name: App_HelloWorldMainForm.cpp
|
|
// Generated by TOPS Builder:Project wizard,Date:2010-4-23
|
|
|
|
#include "test_spriteMainForm.h"
|
|
#include "test_sprite_res_def.h"
|
|
|
|
#include "GLESRef.h"
|
|
|
|
static void TimerCallback(Int32 nTimerId, UInt32 uUserData);
|
|
|
|
TMainForm::TMainForm(TApplication * pApp):TWindow(pApp)
|
|
{
|
|
Create(TEST_S_ID_Form1002);
|
|
m_bGLESInit = FALSE;
|
|
m_gbitmap = NULL;
|
|
m_nTimerID = 0;
|
|
}
|
|
|
|
TMainForm::~TMainForm()
|
|
{
|
|
if (m_gbitmap)
|
|
{
|
|
m_gbitmap->Destroy();
|
|
m_gbitmap = NULL;
|
|
}
|
|
}
|
|
|
|
Boolean TMainForm::EventHandler(TApplication * pApp, EventType * pEvent)
|
|
{
|
|
Boolean bHandled = FALSE;
|
|
|
|
switch(pEvent->eType)
|
|
{
|
|
case EVENT_WinInit:
|
|
{
|
|
m_bGLESInit = GLES_Init();
|
|
|
|
m_nTimerID = TIMER_Create(20,TIMER_MODE_PERIOD,TimerCallback,this->GetWindowHwndId(),0);
|
|
TIMER_Start(m_nTimerID,(UInt32)this);
|
|
|
|
bHandled = TRUE;
|
|
break;
|
|
}
|
|
case EVENT_WinPaint:
|
|
{
|
|
if (m_bGLESInit)
|
|
{
|
|
GLES_Draw();
|
|
|
|
SetBackGround();
|
|
}
|
|
DrawWindow();
|
|
|
|
bHandled = TRUE;
|
|
break;
|
|
}
|
|
case EVENT_CtrlSelect:
|
|
{
|
|
//switch(pEvent->sParam1)
|
|
//{
|
|
//case RES_SYSTEM_WINDOW_TITLE_BUTTON_ID:
|
|
// bHandled = TRUE;
|
|
// break;
|
|
//}
|
|
break;
|
|
}
|
|
case EVENT_WinClose:
|
|
{
|
|
if (m_bGLESInit)
|
|
{
|
|
GLES_UnInit();
|
|
}
|
|
|
|
TIMER_Stop(m_nTimerID);
|
|
TIMER_Release(m_nTimerID);
|
|
|
|
// Stop the application since the main form has been closed
|
|
pApp->SendStopEvent();
|
|
}
|
|
break;
|
|
}
|
|
if (bHandled == FALSE)
|
|
{
|
|
return TWindow::EventHandler(pApp,pEvent);
|
|
}
|
|
return bHandled;
|
|
}
|
|
|
|
Boolean TMainForm::SetBackGround()
|
|
{
|
|
Boolean bbHandled = FALSE;
|
|
int nWidth = gles_GetScreenWidth();
|
|
int nHeight = gles_GetScreenHeight();
|
|
unsigned char *pGLData = (unsigned char*)gles_GetScreenData();
|
|
TBitmap *bitmap = TBitmap::Create(nWidth, nHeight, 32);
|
|
UInt8 *pDataPtr = bitmap->GetDataPtr();
|
|
ColorRefType color;
|
|
for (int i = 0; i < nHeight; i++)
|
|
for (int j = 0; j < nWidth; j++)
|
|
{
|
|
int nIndex = (i * nWidth + j) * 4;
|
|
color = (DWORD)(pGLData[nIndex+3] << 24) + (DWORD)(pGLData[nIndex] << 16) + (DWORD)(pGLData[nIndex+1] << 8) + (DWORD)(pGLData[nIndex+2]);
|
|
bitmap->Fill32(color, j, nHeight - i, 1, 1);
|
|
}
|
|
|
|
if (m_gbitmap != NULL)
|
|
{
|
|
m_gbitmap->Destroy();
|
|
m_gbitmap = NULL;
|
|
}
|
|
m_gbitmap = bitmap->DupBitmapTo32();
|
|
bbHandled = this->SetBackGroundBitmap(m_gbitmap,0);
|
|
//TDC dc(this);
|
|
//dc.DrawBitmap(m_gbitmap,0,50);
|
|
bitmap->Destroy();
|
|
|
|
return bbHandled;
|
|
}
|
|
|
|
static void TimerCallback(Int32 nTimerId, UInt32 uUserData)
|
|
{
|
|
TMainForm* pobForm = static_cast<TMainForm*>((LPVOID)uUserData);
|
|
pobForm ->UpdateWindow(0);
|
|
} |