📄 newplayer.cpp
字号:
OnFullScreen(); break;
case 'F' :{
g_ShowFrameRate=!g_ShowFrameRate;
if (!g_ShowFrameRate) TheFrameRate->Show(CKHIDE); else TheFrameRate->Show();
} break;
case VK_ESCAPE:
if (TheRenderContext)
if (TheRenderContext->IsFullScreen() && !g_DisableSwitch)
{
OnFullScreen();
return 1;
}
else ExitVirtoolsPlayer();
break;
}
return 0;
}
break;
case WM_SETCURSOR:
{
// if (!TheCKContext->IsPlaying())
// {
SetCursor(::LoadCursor(NULL,IDC_ARROW));
// }
} break;
case WM_DROPFILES: // Load any dropped file
{
char FileName[_MAX_PATH];
HDROP hdrop=(HDROP)wParam;
DragQueryFile(hdrop,0,FileName,_MAX_PATH);
Load(FileName);
DragFinish(hdrop);
} break;
case WM_NCLBUTTONDOWN: // Handle clicks on caption bar
if (TheRenderContext)
if (TheRenderContext->IsFullScreen()) return 1;
if (btn=GetTitleBtn())
{
switch (btn)
{
case BTN_PLAY: g_CurrentPlayState|=1; OnPlayPause(0); break;
case BTN_RESET: g_CurrentResetState=2; OnReset(); break;
case BTN_LOAD: g_CurrentLoadState=2; OnLoad(); break;
case BTN_CLOSE: g_CurrentCloseState=1; ExitVirtoolsPlayer(); return 0; break;
}
RepaintTitleBar();
}
// return 1;
break;
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE: // Handle Highlights on buttons
if (btn=GetTitleBtn())
{
switch (btn)
{
case BTN_PLAY: g_CurrentPlayState|=1; break;
case BTN_RESET: g_CurrentResetState=1; break;
case BTN_CLOSE: g_CurrentCloseState=1; break;
case BTN_LOAD: g_CurrentLoadState=1; break;
}
RepaintTitleBar();
}
else
if (g_CurrentResetState || g_CurrentCloseState || (g_CurrentPlayState & 1) || g_CurrentLoadState)
{
g_CurrentResetState=0;
g_CurrentCloseState=0;
g_CurrentPlayState&=2;
g_CurrentLoadState=0;
RepaintTitleBar();
}
break;
case WM_ACTIVATEAPP: { // Repaint title bar
//-----------------------------------------------------------------
// When application lose focus we pause the rendering
// (This behavior can be overriden but it solves some problems
// which could cause the computer to reboot on Nvidia cards
// if the user pressed CTRL+ALT+DEL
static int WasPlaying = 0;
static int WasFullscreen = 0;
static int FirstDeActivate = TRUE;
if (!wParam) {
// Deactivation of the application
// we pause and stop fullscreen mode
if (TheCKContext) {
if (FirstDeActivate)
WasPlaying = TheCKContext->IsPlaying();
//----- If the application should continue
// even non-active mode , comment the next line
OnPlayPause(FORCE_PAUSE);
if (TheRenderContext && TheRenderContext->IsFullScreen()) {
if (FirstDeActivate)
WasFullscreen = TRUE;
OnFullScreen(FALSE);
} else
if (FirstDeActivate)
WasFullscreen = FALSE;
}
FirstDeActivate = FALSE;
} else {
// Reactivation : If app was playing
if (WasPlaying) {
OnPlayPause(FORCE_PLAY);
}
if (WasFullscreen && !FirstDeActivate) {
OnFullScreen(WasPlaying);
}
FirstDeActivate = TRUE;
}
} break;
case WM_NCACTIVATE: // Repaint title bar
case WM_NCPAINT: RepaintTitleBar(); return 1; break;
case WM_PAINT: // Repaint main frame
if (TheRenderContext)
if (!TheRenderContext->IsFullScreen()) TheRenderContext->Render();
break;
case WM_DESTROY: // Clean up things
ExitVirtoolsPlayer();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
//-----------------------------------------
// Custom Draw For caption
//
//-------------------------------------------------------------------------
void RepaintTitleBar()
{
if (TheRenderContext)
if (TheRenderContext->IsFullScreen()) return;
RECT WR,NcRect,WinRect,ClientRect;
GetWindowRect(g_MainWindow,&WinRect);
GetClientRect(g_MainWindow,&ClientRect);
ClientToScreen(g_MainWindow, (POINT *)&ClientRect );
ClientToScreen(g_MainWindow, (POINT *)&ClientRect.right );
NcRect=WinRect;
ClientRect.left-=WinRect.left; ClientRect.top-=WinRect.top;
ClientRect.right-=WinRect.left; ClientRect.bottom-=WinRect.top;
WinRect.right-=WinRect.left; WinRect.left=0;
WinRect.bottom-=WinRect.top; WinRect.top=0;
//----- Calc Title Bar Rect
NcRect.top=GetSystemMetrics(SM_CYBORDER);
//SM_CYCAPTION
NcRect.bottom=2*GetSystemMetrics(SM_CYBORDER)+CAPTIONHEIGHT;
NcRect.right-=NcRect.left+GetSystemMetrics(SM_CXBORDER);
NcRect.left=GetSystemMetrics(SM_CXBORDER);
//---- Start Drawing
HDC dc =GetWindowDC(g_MainWindow);
HDC dc2 =CreateCompatibleDC(NULL);
HBITMAP bm =CreateCompatibleBitmap(dc,WinRect.right,WinRect.bottom);
HBITMAP oldbm=(HBITMAP)SelectObject(dc2,bm);
HBRUSH br=CreateSolidBrush(0x0);
HBRUSH brGrey=CreateSolidBrush(0x00808080);
SetTextColor(dc,0x00FFFFFF); SetBkColor(dc,0);
SetTextColor(dc2,0x00FFFFFF); SetBkColor(dc2,0);
ExcludeClipRect(dc,ClientRect.left,NcRect.bottom,ClientRect.right,ClientRect.bottom);
WR=WinRect; WR.top=NcRect.bottom;
FillRect(dc,&WR,br); // Clear Border
FrameRect(dc,&WinRect,brGrey); // Clear Border
FillRect(dc2,&NcRect,br); // Clear Caption
//---- Draw Title -----//
WR=NcRect; WR.left+=48;
DrawText(dc2,szTitle,strlen(szTitle),&WR,DT_VCENTER|DT_LEFT|DT_SINGLELINE);
//---- Draw Buttons ----//
int Center=WinRect.right/2;
int CenterY=CAPTIONHEIGHT/2;
DrawState(dc2,NULL,NULL,(DWORD)g_Virtools ,0,3,CenterY-10,0,0,DST_BITMAP|DSS_NORMAL);
DrawState(dc2,NULL,NULL,(DWORD)g_Reset[g_CurrentResetState] ,0,Center-64,CenterY-9,0,0,DST_BITMAP|DSS_NORMAL);
DrawState(dc2,NULL,NULL,(DWORD)g_Plays[g_CurrentPlayState] ,0,Center+26,CenterY-9,0,0,DST_BITMAP|DSS_NORMAL);
DrawState(dc2,NULL,NULL,(DWORD)g_Load [g_CurrentLoadState] ,0,Center-19,CenterY-9,0,0,DST_BITMAP|DSS_NORMAL);
DrawState(dc2,NULL,NULL,(DWORD)g_Close[g_CurrentCloseState] ,0,WinRect.right-25,CenterY-6,0,0,DST_BITMAP|DSS_NORMAL);
//--- Copy -----//
BitBlt(dc,NcRect.left,NcRect.top,NcRect.right-NcRect.left,NcRect.bottom-NcRect.top,dc2,NcRect.left,NcRect.top,SRCCOPY);
//---- Clean GDI Objects ----//
SelectObject(dc2,oldbm);
DeleteDC(dc2);
DeleteObject(bm);
DeleteObject(brGrey);
DeleteObject(br);
ReleaseDC(g_MainWindow,dc);
}
//-----------------------------------------
// Returns Button under mouse cursor
//
//-----------------------------------------
int GetTitleBtn()
{
POINT pt;
RECT WinRect,ClientRect;
RECT Close,Play,Reset,Load;
GetCursorPos(&pt);
GetWindowRect(g_MainWindow,&WinRect); GetClientRect(g_MainWindow,&ClientRect); ClientToScreen(g_MainWindow, (POINT *)&ClientRect );
pt.x-=WinRect.left; pt.y-=WinRect.top;
WinRect.right-=WinRect.left; ClientRect.top-=WinRect.top;
int Center=WinRect.right/2,CenterY=ClientRect.top/2;
SetRect(&Reset,Center-64,CenterY-9,Center-64+38,CenterY+10);
SetRect(&Play,Center+26,CenterY-9,Center+26+38,CenterY+10);
SetRect(&Close,WinRect.right-25,CenterY-6,WinRect.right-25+16,CenterY-6+13);
SetRect(&Load,Center-19,CenterY-9,Center+19,CenterY+10);
if (PtInRect(&Close,pt)) return BTN_CLOSE;
else
if (PtInRect(&Play,pt)) return BTN_PLAY;
else
if (PtInRect(&Reset,pt)) return BTN_RESET;
else
if (PtInRect(&Load,pt)) return BTN_LOAD;
return 0;
}
//------------------------------------------------------------------------
// Mesage handler for fullscreen Setup box.
//
//
//-------------------------------------------------------------------------
LRESULT CALLBACK Setup(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
WORD wNotifyCode = HIWORD(wParam);
int wID = LOWORD(wParam);
switch (message)
{
case WM_INITDIALOG:
{
int count=TheRenderManager->GetRenderDriverCount();
int i,index;
char Chaine[256];
// Fill List with existing drivers
for (i=0;i<count;i++)
{
VxDriverDesc *desc=TheRenderManager->GetRenderDriverDescription(i);
index=SendDlgItemMessage(hDlg,IDC_LISTDRIVER,LB_ADDSTRING,0,(LPARAM)desc->DriverName.CStr());
SendDlgItemMessage(hDlg,IDC_LISTDRIVER,LB_SETITEMDATA,index,i);
if (i==g_FullScreenDriver)
SendDlgItemMessage(hDlg,IDC_LISTDRIVER,LB_SETCURSEL,index,0);
}
// Fill List with availables Modes for this driver
VxDriverDesc *MainDesc=TheRenderManager->GetRenderDriverDescription(g_FullScreenDriver);
int prevWidth=0,prevHeight=0,prevBpp=0;
for (i=0;i<MainDesc->DisplayModes.Size();i++)
{
if (MainDesc->DisplayModes[i].Bpp>8) {
if (!((MainDesc->DisplayModes[i].Width==prevWidth) && (MainDesc->DisplayModes[i].Height==prevHeight) && (MainDesc->DisplayModes[i].Bpp==prevBpp))) {
sprintf(Chaine,"%d x %d x %d",MainDesc->DisplayModes[i].Width,MainDesc->DisplayModes[i].Height,MainDesc->DisplayModes[i].Bpp);
index=SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_ADDSTRING,0,(LPARAM)Chaine);
SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_SETITEMDATA,index,i);
prevWidth =MainDesc->DisplayModes[i].Width;
prevHeight =MainDesc->DisplayModes[i].Height;
prevBpp =MainDesc->DisplayModes[i].Bpp;
if (i==g_Mode){
SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_SETCURSEL,index,0);
SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_SETTOPINDEX,index,0);
}
}
}
}
}
return TRUE;
case WM_COMMAND:
if (wNotifyCode==LBN_SELCHANGE)
if (wID==IDC_LISTDRIVER)
{
char Chaine[256];
int index=SendDlgItemMessage(hDlg,IDC_LISTDRIVER,LB_GETCURSEL,0,0);
g_FullScreenDriver=SendDlgItemMessage(hDlg,IDC_LISTDRIVER,LB_GETITEMDATA,index,0);
VxDriverDesc *MainDesc=TheRenderManager->GetRenderDriverDescription(g_FullScreenDriver);
SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_RESETCONTENT,0,0);
int prevWidth=0,prevHeight=0,prevBpp=0;
for (int i=0;i<MainDesc->DisplayModes.Size();i++)
{
if (MainDesc->DisplayModes[i].Bpp>8) {
if (!((MainDesc->DisplayModes[i].Width==prevWidth) && (MainDesc->DisplayModes[i].Height==prevHeight) && (MainDesc->DisplayModes[i].Bpp==prevBpp))) {
sprintf(Chaine,"%d x %d x %d",MainDesc->DisplayModes[i].Width,MainDesc->DisplayModes[i].Height,MainDesc->DisplayModes[i].Bpp);
index=SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_ADDSTRING,0,(LPARAM)Chaine);
SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_SETITEMDATA,index,i);
prevWidth =MainDesc->DisplayModes[i].Width;
prevHeight =MainDesc->DisplayModes[i].Height;
prevBpp =MainDesc->DisplayModes[i].Bpp;
if (i==g_Mode){
SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_SETCURSEL,index,0);
SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_SETTOPINDEX,index,0);
}
}
}
}
}
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
int index=SendDlgItemMessage(hDlg,IDC_LISTDRIVER,LB_GETCURSEL,0,0);
if (index>=0)
g_FullScreenDriver=SendDlgItemMessage(hDlg,IDC_LISTDRIVER,LB_GETITEMDATA,index,0);
index=SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_GETCURSEL,0,0);
if (index>=0)
g_Mode=SendDlgItemMessage(hDlg,IDC_LISTMODE,LB_GETITEMDATA,index,0);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
//-------------------------------------------------------------------------
// Mesage handler for about box.
//
//-------------------------------------------------------------------------
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -