📄 newplayer.cpp
字号:
::SetWindowPos(g_MainWindow,HWND_NOTOPMOST,g_mainwin_rect.left,g_mainwin_rect.top,g_mainwin_rect.right - g_mainwin_rect.left,g_mainwin_rect.bottom - g_mainwin_rect.top,NULL);
}
if (Replay)
TheCKContext->Play();
} else {
TheCKContext->Pause();
int w,h,FSdriver;
if (g_Mode<0)
TheRenderContext->GoFullScreen(w=g_Width,h=g_Height,g_Bpp,FSdriver=g_Driver,g_RefreshRate);
else {
VxDriverDesc *MainDesc=TheRenderManager->GetRenderDriverDescription(g_FullScreenDriver);
if (MainDesc)
TheRenderContext->GoFullScreen(w=MainDesc->DisplayModes[g_Mode].Width,
h=MainDesc->DisplayModes[g_Mode].Height,
MainDesc->DisplayModes[g_Mode].Bpp,
FSdriver=g_FullScreenDriver,g_RefreshRate);
}
if (Replay)
TheCKContext->Play();
SetFocus(g_RenderWin);
//we have to resize the mainwin to allow correct picking (only in DX)
VxDriverDesc* Check_API_Desc=TheRenderManager->GetRenderDriverDescription(FSdriver);
if (Check_API_Desc->Caps2D.Family==CKRST_DIRECTX && TheRenderContext->IsFullScreen()) {
//store current size
GetWindowRect(g_MainWindow,&g_mainwin_rect);
//Resize the window
::SetWindowPos(g_MainWindow,HWND_TOPMOST,0,0,w,h,NULL);
//Prevent the window from beeing resized
LONG st = GetWindowLong(g_MainWindow,GWL_STYLE);
st&=(~WS_THICKFRAME);
SetWindowLong(g_MainWindow,GWL_STYLE,st);
}
//ShowWindow(g_MainWindow,SW_SHOW|SW_MAXIMIZE);
}
}
}
}
//-------------------------------------------
// CreateInterfaceSprite
//
// Creates the framerate sprite
//-------------------------------------------
void CreateInterfaceSprite()
{
TheFrameRate=(CKSpriteText *)TheCKContext->CreateObject(CKCID_SPRITETEXT,"FrameRate");
TheFrameRate->Create(60,20);
TheFrameRate->SetTransparent(TRUE);
TheFrameRate->SetFont("Arial",10);
TheFrameRate->SetBackgroundColor(0);
TheFrameRate->SetTextColor(0x00ffffff);
TheFrameRate->SetPosition(Vx2DVector(10.0f,10.0f));
if (TheRenderContext)
TheRenderContext->AddObject(TheFrameRate);
g_MadeWith=(CKSpriteText *)TheCKContext->CreateObject(CKCID_SPRITETEXT,"MadeWith?");
g_MadeWith->Create(280,50);
g_MadeWith->SetTransparent(FALSE);
g_MadeWith->SetFont("Arial",14);
g_MadeWith->SetBackgroundColor(0);
g_MadeWith->SetTextColor(0x00ffffff);
//g_MadeWith->SetAlign((CKSPRITETEXT_ALIGNMENT)(CKSPRITETEXT_CENTER|CKSPRITETEXT_HCENTER|CKSPRITETEXT_VCENTER));
g_MadeWith->SetZOrder(2000000);
g_MadeWith->Show(CKHIDE);
if (TheRenderContext)
TheRenderContext->AddObject(g_MadeWith);
}
//-------------------------------------------
// Load function
//
//-------------------------------------------
BOOL Load(char *str)
{
if (strlen(str)<=0) return FALSE;
//--- Destroy every Object... execpt CKRenderContexts (and their attached viewpoints)
TheCKContext->Pause();
TheCKContext->Reset();
TheCKContext->ClearAll();
//-- recreates the overlay bitmap for framerate
CreateInterfaceSprite();
//--- Shows a "Made With ..." sprite if not made with a full retail version
g_ShowMadeWith=FALSE;
g_MadeWith->Show(CKHIDE);
Vx2DVector MadeWithPos((float)(TheRenderContext->GetWidth()/2-140),(float)(TheRenderContext->GetHeight()/2-25));
g_MadeWith->SetPosition(MadeWithPos);
CKFileInfo fileinfo;
g_TimeToHideSprite=GetTickCount()+3000;
ZeroMemory(&fileinfo,sizeof(fileinfo));
if (TheCKContext->GetFileInfo(str,&fileinfo)==CK_OK)
{
char Text[128]="Made with Virtools ";
switch (fileinfo.ProductVersion)
{
case CK_VIRTOOLS_DEV :
case CK_VIRTOOLS_CREATION : g_TimeToHideSprite=0; break;
case CK_VIRTOOLS_DEV_NFR : strcat(Text,"Dev \n (Not For Resale)"); break;
case CK_VIRTOOLS_CREA_NFR : strcat(Text,"Creation \n (Not For Resale)"); break;
case CK_VIRTOOLS_DEV_EDU : strcat(Text,"Dev \n (Education version)"); break;
case CK_VIRTOOLS_CREA_EDU : strcat(Text,"Creation \n (Education version)"); break;
case CK_VIRTOOLS_DEV_TB :
case CK_VIRTOOLS_DEV_EVAL : strcat(Text,"Dev \n (Evaluation version)"); break;
case CK_VIRTOOLS_CREA_TB :
case CK_VIRTOOLS_CREA_EVAL : strcat(Text,"Creation \n (Evaluation version)"); break;
default: g_TimeToHideSprite=0; break;
}
if (g_TimeToHideSprite)
{
g_MadeWith->SetText(Text);
g_ShowMadeWith=TRUE;
}
}
//---------- Draws a loadind sprite
TheFrameRate->SetText("Loading...");
Vx2DVector FrameRatePos((float)(g_Width/2-35),(float)(g_Height/2-15));
TheFrameRate->SetPosition(FrameRatePos);
TheFrameRate->Show(CKSHOW);
TheRenderContext->Render();
CKObjectArray *array=CreateCKObjectArray();
//--- Adds The current load Path to the sounds and textures search paths
char path_buffer[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char dir2[_MAX_DIR];
_splitpath( str, drive, dir, NULL, NULL );
_makepath( path_buffer, drive, dir, NULL, NULL );
TheCKContext->GetPathManager()->AddPath(SOUND_PATH_IDX,XString(path_buffer));
TheCKContext->GetPathManager()->AddPath(BITMAP_PATH_IDX,XString(path_buffer));
TheCKContext->GetPathManager()->AddPath(DATA_PATH_IDX,XString(path_buffer));
strcpy(dir2,dir);
strcat(dir,"sounds");
strcat(dir2,"textures");
_makepath( path_buffer, drive, dir, NULL, NULL );
TheCKContext->GetPathManager()->AddPath(SOUND_PATH_IDX,XString(path_buffer));
_makepath( path_buffer, drive, dir2, NULL, NULL );
TheCKContext->GetPathManager()->AddPath(BITMAP_PATH_IDX,XString(path_buffer));
//-- Loads the file and fills the array with loaded objects
CKERROR res=CK_OK;
if ((res=TheCKContext->Load((char*) str,array))==CK_OK)
{
//--- Add the render context to the level
CKLevel* TheLevel=NULL;
g_Level=TheLevel=TheCKContext->GetCurrentLevel();
TheLevel->AddRenderContext(TheRenderContext,TRUE);
//--- Take the first camera we found and attach the viewpoint to it.
CK_ID* cam_ids=TheCKContext->GetObjectsListByClassID(CKCID_CAMERA);
if (!cam_ids) cam_ids=TheCKContext->GetObjectsListByClassID(CKCID_TARGETCAMERA);
if (cam_ids)
{
CKCamera *camera=(CKCamera *)TheCKContext->GetObject(cam_ids[0]);
if (camera)
TheRenderContext->AttachViewpointToCamera(camera);
}
//-- Hide curves ?
int CurveCount=TheCKContext->GetObjectsCountByClassID(CKCID_CURVE);
CK_ID* curve_ids=TheCKContext->GetObjectsListByClassID(CKCID_CURVE);
for (int i=0;i<CurveCount;++i) {
CKMesh* mesh=((CKCurve *)TheCKContext->GetObject(curve_ids[i]))->GetCurrentMesh();
if (mesh) mesh->Show(CKHIDE);
}
//--- Sets the initial conditions for the level
TheLevel->LaunchScene(NULL);
}
DeleteCKObjectArray(array);
OnReset();
//------- ReRegister OnClick Message in case it changed
g_MsgClick=TheMessageManager->AddMessageType("OnClick");
g_MsgDoubleClick=TheMessageManager->AddMessageType("OnDblClick");
TheRenderContext->Render();
g_CurrentLoadState=0;
TheFrameRate->SetText("");
TheFrameRate->Show(CKHIDE);
FrameRatePos=Vx2DVector(10.0f,10.0f);
TheFrameRate->SetPosition(FrameRatePos);
TheRenderContext->Render();
SetCursor(::LoadCursor(NULL,IDC_ARROW));
return (res==CK_OK);
}
void OnLoad()
{
static char file[256];
static char fileTitle[256];
static char filter[] = "Virtools Files (*.cmo,*.vmo)\0*.cmo;*.vmo\0"
"All Files (*.*)\0*.*\0";
OPENFILENAME ofn;
lstrcpy( file, "");
lstrcpy( fileTitle, "");
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = g_MainWindow;
ofn.hInstance = NULL;
ofn.lpstrFilter = filter;
ofn.lpstrCustomFilter = (LPSTR) NULL;
ofn.nMaxCustFilter = 0L;
ofn.nFilterIndex = 1L;
ofn.lpstrFile = file;
ofn.nMaxFile = sizeof(file);
ofn.lpstrFileTitle = fileTitle;
ofn.nMaxFileTitle = sizeof(fileTitle);
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = "Select Content To Load";
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = "*.cmo";
ofn.lCustData = 0;
ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;
// Do Load Dialog
if (GetOpenFileName(&ofn))
Load(ofn.lpstrFile);
}
//-----------------------------------------------------------
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
//
//-----------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent,btn;
switch (message)
{
case WM_KEYDOWN: // Keys
{
int Key=(int) wParam;
if (Key=='F') {
g_ShowFrameRate=!g_ShowFrameRate;
if (!g_ShowFrameRate) TheFrameRate->Show(CKHIDE); else TheFrameRate->Show();
}
else if (Key==VK_SPACE) return 1;
else if (Key==VK_RETURN) return 1;
else if (Key==VK_ESCAPE)
if (TheRenderContext)
if (TheRenderContext->IsFullScreen() && !g_DisableSwitch) {
OnFullScreen();
return 0;
}
else {
TheCKContext->Pause();
g_ExitCK=TRUE;
}
break;
} break;
case WM_RBUTTONUP: OnContextMenu(); break;
case WM_LBUTTONDBLCLK: // Sends a Message "OnClick" or "OnDblClick" if any object is under mouse cursor
case WM_LBUTTONDOWN:
{
POINT pt;
GetCursorPos(&pt);
VxIntersectionDesc desc;
int Msg=(message==WM_LBUTTONDOWN) ? g_MsgClick : g_MsgDoubleClick;
if(TheRenderContext)
{
if(!TheRenderContext->IsFullScreen())
ScreenToClient(g_RenderWin,&pt);
CKObject *obj=TheRenderContext->Pick(pt.x,pt.y,&desc);
if (obj)
if (CKIsChildClassOf(obj,CKCID_BEOBJECT))
TheMessageManager->SendMessageSingle(Msg,(CKBeObject *)obj);
if (desc.Sprite)
{
TheMessageManager->SendMessageSingle(Msg,(CKBeObject *)desc.Sprite);
}
}
}
break;
case WM_COMMAND: // Contextual menu commands
wmId = LOWORD(wParam); wmEvent = HIWORD(wParam);
switch (wmId)
{
case ID_NEMOPLAYER_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break;
case ID_NEMOPLAYER_FULLSCREEN:
SetFocus(g_MainWindow);
if (!g_DisableSwitch)
OnFullScreen();
return 0;
break;
case ID_NEMOPLAYER_PLAY: OnPlayPause(FORCE_PLAY); break;
case ID_NEMOPLAYER_PAUSE: OnPlayPause(FORCE_PAUSE); break;
case ID_NEMOPLAYER_RESET: OnReset(); break;
case ID_NEMOPLAYER_LOAD: OnLoad(); break;
case ID_NEMOPLAYER_DISPLAY: DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)Setup); break;
case ID_NEMOPLAYER_ABOUTNEMO: ShellExecute(NULL,NULL,"http://www.virtools.com",NULL,NULL, SW_SHOW); break;
case ID_GOTO_PLAYER_PAGE: ShellExecute(NULL,NULL,"http://player.virtools.com",NULL,NULL, SW_SHOW); break;
case IDM_EXIT: ExitVirtoolsPlayer(); break;
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_GETMINMAXINFO: // Minimum size of the player window
{
LPMINMAXINFO lpmmi = (LPMINMAXINFO) lParam;
if (lpmmi)
{
lpmmi->ptMinTrackSize.x=400;
lpmmi->ptMinTrackSize.y=200;
}
}
break;
case WM_SIZE: // Resize the render context
if (TheRenderContext)
if (!TheRenderContext->IsFullScreen())
{
RECT rect;
GetClientRect(g_MainWindow,&rect);
SetWindowPos(g_RenderWin,NULL,0,0,rect.right,rect.bottom-g_CaptionOffset,SWP_NOMOVE|SWP_NOZORDER);
TheRenderContext->Resize();
Vx2DVector MadeWithPos((float)(TheRenderContext->GetWidth()/2-140),(float)(TheRenderContext->GetHeight()/2-25));
g_MadeWith->SetPosition(MadeWithPos);
}
break;
case WM_SYSKEYDOWN: // If ALT-ENTER is pressed go to fullscreen
{
int Key=(int) wParam;
switch (Key)
{
case VK_RETURN: if (!g_DisableSwitch)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -