⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdlviewer.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	g_pChoreoView->SetUseForMainWindowTitle( true );

	Con_Printf( "IFacePoserToolWindow::Init\n" );

	IFacePoserToolWindow::Init();

	Con_Printf( "windowtab->Init\n" );
	
	windowtab->Init();

	Con_Printf( "loadRecentFiles\n" );

	loadRecentFiles ();
	initRecentFiles ();

	Con_Printf( "LoadWindowPositions\n" );

	LoadWindowPositions();

	Con_Printf( "RestoreThumbnailSize\n" );

	g_pExpressionTrayTool->RestoreThumbnailSize();

	Con_Printf( "Add Tool Windows\n" );

	int c = IFacePoserToolWindow::GetToolCount();
	for ( i = 0; i < c ; i++ )
	{
		IFacePoserToolWindow *tool = IFacePoserToolWindow::GetTool( i );
		menuWindow->add( tool->GetToolName(), IDC_WINDOW_FIRSTTOOL + i );
	}

	menuWindow->addSeparator();
	menuWindow->add( "Cascade", IDC_WINDOW_CASCADE );
	menuWindow->addSeparator();
	menuWindow->add( "Tile", IDC_WINDOW_TILE );
	menuWindow->add( "Tile Horizontally", IDC_WINDOW_TILE_HORIZ );
	menuWindow->add( "Tile Vertically", IDC_WINDOW_TILE_VERT );
	menuWindow->addSeparator();
	menuWindow->add( "Hide All", IDC_WINDOW_HIDEALL );
	menuWindow->add( "Show All", IDC_WINDOW_SHOWALL );

	Con_Printf( "UpdateWindowMenu\n" );

	UpdateWindowMenu();

	m_nCurrentFrame = 0;

	Con_Printf( "gridsettings->Init()\n" );

	gridsettings->Init();

	Con_Printf( "Model viewer created\n" );
}

void MDLViewer::UpdateWindowMenu( void )
{
	int c = IFacePoserToolWindow::GetToolCount();
	for ( int i = 0; i < c ; i++ )
	{
		IFacePoserToolWindow *tool = IFacePoserToolWindow::GetTool( i );
		menuWindow->setChecked( IDC_WINDOW_FIRSTTOOL + i, tool->GetMxWindow()->isVisible() );
	}
}

bool MDLViewer::CanClose()
{
	return true;
}

void MDLViewer::OnDelete()
{
	saveRecentFiles ();
	SaveViewerSettings( g_viewerSettings.modelFile );

#ifdef WIN32
	DeleteFile ("hlmv.cfg");
	DeleteFile ("midump.txt");
#endif

	g_MDLViewer = NULL;
}

MDLViewer::~MDLViewer ()
{
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void MDLViewer::InitModelTab( void )
{
	modeltab->Init();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void MDLViewer::InitGridSettings( void )
{
	gridsettings->Init();
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : int
//-----------------------------------------------------------------------------
int MDLViewer::GetActiveModelTab( void )
{
	return modeltab->getSelectedIndex();
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : modelindex - 
//-----------------------------------------------------------------------------
void MDLViewer::SetActiveModelTab( int modelindex )
{
	modeltab->select( modelindex );
	modeltab->HandleModelSelect();
}

//-----------------------------------------------------------------------------
// Purpose: Reloads the currently loaded model file.
//-----------------------------------------------------------------------------
void MDLViewer::Refresh( void )
{
	g_pMaterialSystem->ReloadTextures( );

	if ( recentFiles[0][0] != '\0' )
	{
		char szFile[MAX_PATH];
		strcpy( szFile, recentFiles[0] ); 
		LoadModelFile( szFile );
	}
}


//-----------------------------------------------------------------------------
// Purpose: Loads the file and updates the MRU list.
// Input  : pszFile - File to load.
//-----------------------------------------------------------------------------
void MDLViewer::LoadModelFile( const char *pszFile )
{
	int i;
	
	models->LoadModel( pszFile );

	for (i = 0; i < 4; i++)
	{
		if (!mx_strcasecmp( recentFiles[i], pszFile ))
			break;
	}

	// swap existing recent file
	if (i < 4)
	{
		char tmp[256];
		strcpy (tmp, recentFiles[0]);
		strcpy (recentFiles[0], recentFiles[i]);
		strcpy (recentFiles[i], tmp);
	}

	// insert recent file
	else
	{
		for (i = 3; i > 0; i--)
			strcpy (recentFiles[i], recentFiles[i - 1]);

		strcpy( recentFiles[0], pszFile );
	}

	initRecentFiles ();
}

/*
void MDLViewer::SwitchToChoreoMode( bool choreo )
{
	g_pFlexPanel->setEnabled( !choreo );
	g_pChoreoView->setEnabled( choreo );

	g_pFlexPanel->setVisible( !choreo );
	g_pChoreoView->setVisible( choreo );

	// So we'll be in the same mode when we restart
	g_viewerSettings.application_mode = choreo ? 1 : 0;

	if (choreo)
	{
		g_viewerSettings.solveHeadTurn = 1;
		g_viewerSettings.flHeadTurn = 0.0;
		g_viewerSettings.vecHeadTarget = Vector(0,0,0);
		g_viewerSettings.vecEyeTarget = Vector(0,0,0);
	}
	else
	{
		g_viewerSettings.solveHeadTurn = 2;
		g_viewerSettings.flHeadTurn = 1.0;
		g_viewerSettings.vecHeadTarget = Vector(0,0,0);
		g_viewerSettings.vecEyeTarget = Vector(0,0,0);
	}
}
*/

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *wnd - 
//			x - 
//			y - 
// Output : static bool
//-----------------------------------------------------------------------------
static bool WindowContainsPoint( mxWindow *wnd, int x, int y )
{
	POINT pt;
	pt.x = (short)x;
	pt.y = (short)y;

	HWND window = (HWND)wnd->getHandle();
	if ( !window )
		return false;

	ScreenToClient( window, &pt );

	if ( pt.x < 0 )
		return false;
	if ( pt.y < 0 )
		return false;
	if ( pt.x > wnd->w() )
		return false;
	if ( pt.y > wnd->h() )
		return false;

	return true;
}

int MDLViewer::handleEvent (mxEvent *event)
{
	int iret = 0;

	switch (event->event)
	{
	case mxEvent::Size:
		{
			int width = w2();
			int height = h2();

			workspace->setBounds( 0, 0, width, height - WINDOW_TAB_OFFSET );
			int gridsettingswide = 100;
			int gridstart = width - gridsettingswide - 5;
			int windowwide = gridstart * 0.6f;
			int modelwide = gridstart * 0.4f;

			gridsettings->setBounds( gridstart, height - WINDOW_TAB_OFFSET + 1, gridsettingswide, WINDOW_TAB_OFFSET - 2 );

			windowtab->setBounds( 0, height - WINDOW_TAB_OFFSET, windowwide, WINDOW_TAB_OFFSET );
			modeltab->setBounds( windowwide, height - WINDOW_TAB_OFFSET, modelwide, WINDOW_TAB_OFFSET );

			iret = 1;
		}
		break;
	case mxEvent::Action:
		{
			iret = 1;
			switch (event->action)
			{
			case IDC_WINDOW_TAB:
				{
					windowtab->HandleWindowSelect();
				}
				break;
			case IDC_MODEL_TAB:
				{
					modeltab->HandleModelSelect();
				}
				break;
			case IDC_EDIT_COPY:
				{
					Copy();
				}
				break;
				
			case IDC_EDIT_PASTE:
				{
					Paste();
				}
				break;
				
			case IDC_EDIT_UNDO:
				{
					Undo();
				}
				break;
				
			case IDC_EDIT_REDO:
				{
					Redo();
				}
				break;
				
			case IDC_FILE_LOADMODEL:
				{
					const char *ptr = mxGetOpenFileName(
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/models/", GetGameDirectory() ) ),
						"*.mdl");
					if (ptr)
					{
						LoadModelFile( ptr );
					}
				}
				break;
				
			case IDC_FILE_REFRESH:
				{
					Refresh();
					break;
				}
				
			case IDC_FILE_LOADBACKGROUNDTEX:
			case IDC_FILE_LOADGROUNDTEX:
				{
					const char *ptr = mxGetOpenFileName (this, 0, "*.*");
					if (ptr)
					{
						if (0 /* g_pMatSysWindow->loadTexture (ptr, event->action - IDC_FILE_LOADBACKGROUNDTEX) */)
						{
							if (event->action == IDC_FILE_LOADBACKGROUNDTEX)
								g_pControlPanel->setShowBackground (true);
							else
								g_pControlPanel->setShowGround (true);
							
						}
						else
							mxMessageBox (this, "Error loading texture.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
					}
				}
				break;
				
			case IDC_FILE_UNLOADGROUNDTEX:
				{
					// g_pMatSysWindow->loadTexture (0, 1);
					g_pControlPanel->setShowGround (false);
				}
				break;
				
			case IDC_FILE_RECENTMODELS1:
			case IDC_FILE_RECENTMODELS2:
			case IDC_FILE_RECENTMODELS3:
			case IDC_FILE_RECENTMODELS4:
				{
					int i = event->action - IDC_FILE_RECENTMODELS1;
					
					LoadModelFile( recentFiles[ i ] );
					
					char tmp[256];			
					strcpy (tmp, recentFiles[0]);
					strcpy (recentFiles[0], recentFiles[i]);
					strcpy (recentFiles[i], tmp);
					
					initRecentFiles ();
					
					redraw ();
				}
				break;
				
			case IDC_FILE_EXIT:
				{
					redraw ();
					mx::quit ();
				}
				break;
				
			case IDC_OPTIONS_COLORBACKGROUND:
			case IDC_OPTIONS_COLORGROUND:
			case IDC_OPTIONS_COLORLIGHT:
				{
					float *cols[3] = { g_viewerSettings.bgColor, g_viewerSettings.gColor, g_viewerSettings.lColor };
					float *col = cols[event->action - IDC_OPTIONS_COLORBACKGROUND];
					int r = (int) (col[0] * 255.0f);
					int g = (int) (col[1] * 255.0f);
					int b = (int) (col[2] * 255.0f);
					if (mxChooseColor (this, &r, &g, &b))
					{
						col[0] = (float) r / 255.0f;
						col[1] = (float) g / 255.0f;
						col[2] = (float) b / 255.0f;
					}
				}
				break;
				
			case IDC_OPTIONS_CENTERVIEW:
				g_pControlPanel->centerView ();
				break;
				
			case IDC_OPTIONS_CENTERONFACE:
				g_pControlPanel->CenterOnFace();
				break;
				
			case IDC_OPTIONS_MAKESCREENSHOT:
				{
					char *ptr = (char *) mxGetSaveFileName (this, "", "*.tga");
					if (ptr)
					{
						if (!strstr (ptr, ".tga"))
							strcat (ptr, ".tga");
						// g_pMatSysWindow->dumpViewport (ptr);
					}
				}
				break;
				
			case IDC_OPTIONS_DUMP:
				g_pControlPanel->dumpModelInfo ();
				break;
				
#ifdef WIN32
			case IDC_HELP_GOTOHOMEPAGE:
				ShellExecute (0, "open", "http://www.swissquake.ch/chumbalum-soft/index.html", 0, 0, SW_SHOW);
				break;
#endif
				
			case IDC_HELP_ABOUT:
				mxMessageBox (this,
					"v0.1 (c) 2001, Valve, LLC.  All rights reserved.\r\nBuild Date: "__DATE__"",
					"Valve Face Poser", 
					MX_MB_OK | MX_MB_INFORMATION);
				break;
				
			case IDC_EXPRESSIONS_REDOBITMAPS:
				{
					bool saveOverrides = g_pExpressionTrayTool->GetOverridesShowing();
					g_pExpressionTrayTool->SetOverridesShowing( false );
					CExpClass *active = expressions->GetActiveClass();
					if ( active )
					{
						for ( int i = 0; i < active->GetNumExpressions() ; i++ )
						{
							CExpression *exp = active->GetExpression( i );
							if ( !exp )
								continue;
							
							active->SelectExpression( i );
							exp->CreateNewBitmap( models->GetActiveModelIndex() );
							
							if ( ! ( i % 5 ) )
							{
								g_pExpressionTrayTool->redraw();
							}
						}
						
						if ( active->HasOverrideClass() )
						{
							
							g_pExpressionTrayTool->SetOverridesShowing( true );
							
							CExpClass *oc = active->GetOverrideClass();
							for ( int i = 0; i < oc->GetNumExpressions() ; i++ )
							{
								CExpression *exp = oc->GetExpression( i );
								if ( !exp )
									continue;
								
								oc->SelectExpression( i );
								exp->CreateNewBitmap( models->GetActiveModelIndex() );
								
								if ( ! ( i % 5 ) )
								{
									g_pExpressionTrayTool->redraw();
								}
							}
						}
						active->SelectExpression( 0 );
					}
					
					g_pExpressionTrayTool->SetOverridesShowing( saveOverrides );
				}
				break;
			case IDC_EXPRESSIONS_NEW:
				{
					const char *filename = mxGetSaveFileName( 
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/expressions/", GetGameDirectory() ) ), 
						"*.txt" );
					if ( filename && filename[ 0 ] )
					{
						char classfile[ 512 ];
						strcpy( classfile, filename );
						StripExtension( classfile );
						DefaultExtension( classfile, ".txt" );
						
						expressions->CreateNewClass( classfile );
					}
				}
				break;
			case IDC_EXPRESSIONS_LOAD:
				{
					const char *filename = NULL;
					

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -