📄 newplayer.cpp
字号:
//---- If there is no file to load and we go fullscreen
//---- stops now
if (g_GoFullScreen && strlen(FileName)<=0)
{
MessageBox(NULL,"No file specified...","Virtools Player Error",MB_ICONEXCLAMATION|MB_OK);
return FALSE;
}
DestroyWindow(splash);
ShowWindow(g_MainWindow, m_nCmdShow);
UpdateWindow(g_MainWindow);
ShowWindow(g_RenderWin, m_nCmdShow);
UpdateWindow(g_RenderWin);
//---- Create Render Context
if (g_GoFullScreen)
{
dev.right=g_Width;
dev.left=0;
dev.top=0;
dev.bottom=g_Height;
g_DisableSwitch=TRUE;
TheRenderContext = TheRenderManager->CreateRenderContext(g_RenderWin,g_Driver,(CKRECT*)&dev,TRUE,g_Bpp,-1,-1,g_RefreshRate);
VxDriverDesc* Check_API_Desc=TheRenderManager->GetRenderDriverDescription(g_Driver);
/*
if (Check_API_Desc->Caps2D.Family!=CKRST_OPENGL) {
if (!(Check_API_Desc->Caps3D.CKRasterizerSpecificCaps & CKRST_SPECIFICCAPS_DX8))
SetWindowPos(g_MainWindow,HWND_TOPMOST,0,0,dev.right,dev.bottom,0);
SetWindowPos(g_RenderWin,HWND_TOPMOST,0,0,dev.right,dev.bottom,0);
}*/
}
else
TheRenderContext=TheRenderManager->CreateRenderContext(g_RenderWin,g_Driver,(CKRECT*)&dev,FALSE);
//-------Check Render Context Validity
if (!TheRenderContext)
{
MessageBox(NULL,"Cannot Initialize Render Context (Try 16 or 32 bits display)","Virtools Player Error",MB_ICONEXCLAMATION|MB_OK);
return FALSE;
}
//------- Register OnClick Message
g_MsgClick=TheMessageManager->AddMessageType("OnClick");
g_MsgDoubleClick=TheMessageManager->AddMessageType("OnDblClick");
//------- Creates a Sprite for Text Output
CreateInterfaceSprite();
//-------- Load Resources
g_ContextMenu= LoadMenu(m_hInstance, MAKEINTRESOURCE(IDR_MENU1) );
g_Reset[0]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_STATUS_RESTORE_IC1));
g_Reset[1]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_STATUS_RESTORE_IC2));
g_Reset[2]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_STATUS_RESTORE_IC3));
g_Plays[0]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_STATUS_PLAY1));
g_Plays[1]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_STATUS_PLAY2));
g_Plays[2]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_STATUS_PLAY3));
g_Plays[3]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_STATUS_PLAY4));
g_Close[0]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_CLOSE_N));
g_Close[1]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_CLOSE_P));
g_Load[0]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_LOAD1));
g_Load[1]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_LOAD2));
g_Load[2]=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_LOAD3));
g_Virtools=LoadBitmap(m_hInstance,MAKEINTRESOURCE(IDB_VIRTOOLS));
RepaintTitleBar();
TheRenderContext->Clear();
TheRenderContext->BackToFront();
TheRenderContext->Clear();
SetCursor(::LoadCursor(NULL,IDC_ARROW));
if (Load(FileName))
{
OnPlayPause(FORCE_PLAY);
}
return TRUE;
}
//--------------------------------------------
int CNewPlayerApp::Run()
{
MSG msg;
while (1)
{
if (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
{
if (msg.message==WM_QUIT) {
return msg.wParam;
}
else
if (!TranslateAccelerator(msg.hwnd, g_hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
if (!IsIconic(g_MainWindow))
DoVirtoolsProcess(); // Do Process On Idle
}
return msg.wParam;
}
//---------------------------------------------------------------------------------------
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
//---------------------------------------------------------------------------------------
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_NEWPLAYER);
wcex.hCursor = NULL;
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
WNDCLASS MyRenderClass;
ZeroMemory(&MyRenderClass,sizeof(MyRenderClass));
MyRenderClass.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
MyRenderClass.lpfnWndProc=(WNDPROC)WndProc;
MyRenderClass.hInstance=hInstance;
MyRenderClass.lpszClassName=szRenderWindowClass;
RegisterClass(&MyRenderClass);
return RegisterClassEx(&wcex);
}
//---------------------------------------------------------------------------------------
// FUNCTION: DeleteObjects
//
// PURPOSE: Cleans up allocated objects
//
//---------------------------------------------------------------------------------------
void ExitVirtoolsPlayer()
{
if(!g_GoFullScreen) {
DestroyMenu(g_ContextMenu);
for (int i=0;i<4;i++) DeleteObject(g_Plays[i]);
for (i=0;i<3;i++) DeleteObject(g_Load[i]);
for (i=0;i<3;i++) DeleteObject(g_Reset[i]);
for (i=0;i<2;i++) DeleteObject(g_Close[i]);
DeleteObject(g_Virtools);
}
TheCKContext->Reset();
TheCKContext->ClearAll();
TheRenderManager->DestroyRenderContext(TheRenderContext);
TheRenderContext = NULL;
CKCloseContext(TheCKContext);
CKShutdown();
TheCKContext = NULL;
PostQuitMessage(0);
}
//---------------------------------------------------------------------------------------
// FUNCTION: OnPlayPause
//
// PURPOSE: Play or Pause the content
//
//---------------------------------------------------------------------------------------
void OnPlayPause(int force)
{
if (force==FORCE_PLAY)
{
if (g_ShowMadeWith && TheCKContext->IsReseted())
{
g_TimeToHideSprite=GetTickCount()+3000;
g_MadeWith->Show(CKSHOW);
} //Stay 3 seconds
TheCKContext->Play();
g_CurrentPlayState=2; RepaintTitleBar();
}
else
if (force==FORCE_PAUSE)
{
TheCKContext->Pause();
g_CurrentPlayState=0; RepaintTitleBar();
}
else
if (!TheCKContext->IsPlaying())
{
if (g_ShowMadeWith && TheCKContext->IsReseted())
{
g_TimeToHideSprite=GetTickCount()+3000;
g_MadeWith->Show(CKSHOW);
} //Stay 3 seconds
TheCKContext->Play();
g_CurrentPlayState=2; RepaintTitleBar();
}
else
{
TheCKContext->Pause();
g_CurrentPlayState=0; RepaintTitleBar();
}
}
//---------------------------------------------------------------------------------------
// FUNCTION: OnContextMenu
//
// PURPOSE: Launch the context menu
//
//---------------------------------------------------------------------------------------
void OnContextMenu()
{
if (!g_NoContextMenu)
if(TheRenderContext)
if(!TheRenderContext->IsFullScreen())
{
POINT point;
RECT rect;
GetCursorPos(&point);
GetClientRect( g_MainWindow,&rect );
ClientToScreen(g_MainWindow, (POINT *)&rect ); ClientToScreen(g_MainWindow, (POINT *)&rect.right );
if( PtInRect(&rect, point ) )
{
HMENU smenu=GetSubMenu(g_ContextMenu,0);
if (g_DisableSwitch)
{
EnableMenuItem(smenu,ID_NEMOPLAYER_FULLSCREEN,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(smenu,ID_NEMOPLAYER_DISPLAY,MF_BYCOMMAND|MF_GRAYED);
}
TrackPopupMenu( smenu, TPM_LEFTALIGN | TPM_LEFTBUTTON |
TPM_RIGHTBUTTON, point.x,
point.y, 0,g_MainWindow,NULL);
}
}
}
//---------------------------------------------------------------------------------------
// FUNCTION: DoVirtoolsProcess
//
//---------------------------------------------------------------------------------------
void DoVirtoolsProcess()
{
static int i=0;
static LARGE_INTEGER frate;
LARGE_INTEGER freq;
LARGE_INTEGER current;
if (TheCKContext)
if (TheCKContext->IsPlaying())
{
if (g_ShowMadeWith)
if (g_TimeToHideSprite)
{
if (GetTickCount()>g_TimeToHideSprite)
{
g_MadeWith->Show(CKHIDE);
g_TimeToHideSprite=0;
}
}
float BeforeRender=0,BeforeProcess=0;
TheTimeManager->GetTimeToWaitForLimits(BeforeRender,BeforeProcess);
if (BeforeProcess<=0) //
{
TheTimeManager->ResetChronos(FALSE,TRUE);
TheCKContext->Process();
}
if (BeforeRender<=0)
{
TheTimeManager->ResetChronos(TRUE,FALSE);
TheRenderContext->Render();
//--- Calculate FrameRate every 30 frames
if(i == 30) {
i = 0;
QueryPerformanceCounter(¤t);
QueryPerformanceFrequency(&freq);
float rate = 30.0f * (float) freq.LowPart / (float) (current.LowPart - frate.LowPart);
if (g_ShowFrameRate)
{
char str[50];
sprintf(str,"%.1f fps",rate);
TheFrameRate->SetPosition(Vx2DVector(10.0f,10.0f));
TheFrameRate->SetText(str);
}
frate = current;
}
i++;
//---------------------------------------
}
if (!g_ExitCK) {
CKAttributeManager* am = NULL;
am = TheCKContext->GetAttributeManager();
if (am && g_Level) {
//Check attribute to determine if we must exit the player
g_attr = am->GetAttributeTypeByName("quit");
g_po = g_Level->GetAttributeParameter(g_attr);
if (g_po) {
g_po->GetValue(&g_ExitCK);
}
}
}
}
if (g_ExitCK) {
TheCKContext->Pause();
ExitVirtoolsPlayer();
}
}
void OnReset()
{
TheCKContext->Reset(TRUE);
g_CurrentResetState=2;
g_CurrentPlayState=0;
RepaintTitleBar();
TheRenderContext->Render();
}
void OnFullScreen(BOOL Replay)
{
if (!Replay || TheCKContext->IsPlaying()) {
if(TheRenderContext) {
if(TheRenderContext->IsFullScreen()) {
TheCKContext->Pause();
TheRenderContext->StopFullScreen();
ShowWindow(g_MainWindow,SW_RESTORE);
//restore the main window size (only in DirectX rasterizer->g_mainwin_rect.bottom not modified)
if (g_mainwin_rect.bottom!=0 && !TheRenderContext->IsFullScreen()) {
//allow the window to be resized
LONG st = GetWindowLong(g_MainWindow,GWL_STYLE);
st|=WS_THICKFRAME;
SetWindowLong(g_MainWindow,GWL_STYLE,st);
//reposition the window
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -