Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1119 lines
41 KiB

  1. //-----------------------------------------------------------------------------
  2. // Name: FontMaker.cpp
  3. //
  4. // Desc: Defines the class behaviors for the application.
  5. //
  6. // Hist: 09.06.02 - Revised Fontmaker sample
  7. //
  8. // Copyright (c) Microsoft Corporation. All rights reserved.
  9. //-----------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "FontMaker.h"
  12. #include "Glyphs.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. CTextureFont g_Font;
  19. extern BOOL g_bIsGlyphSelected;
  20. extern int g_iSelectedGlyphNum;
  21. extern GLYPH_ATTR* g_pSelectedGylph;
  22. extern WCHAR g_cSelectedGlyph;
  23. //-----------------------------------------------------------------------------
  24. // CFontMakerApp
  25. //-----------------------------------------------------------------------------
  26. BEGIN_MESSAGE_MAP(CFontMakerApp, CWinApp)
  27. //{{AFX_MSG_MAP(CFontMakerApp)
  28. ON_COMMAND(IDM_FILE_NEWFONT, OnNewFontButton)
  29. ON_BN_CLICKED(IDC_EFFECTSOUTLINED_CHECK, OnEffectsCheck)
  30. ON_BN_CLICKED(IDC_EFFECTSSHADOWED_CHECK, OnEffectsCheck)
  31. ON_BN_CLICKED(IDC_EFFECTSBLURRED_CHECK, OnEffectsCheck)
  32. ON_BN_CLICKED(IDC_EFFECTSSCANLINES_CHECK, OnEffectsCheck)
  33. ON_BN_CLICKED(IDC_EFFECTSANTIALIAS_CHECK, OnEffectsCheck)
  34. ON_BN_CLICKED(IDC_GLYPHSFROMRANGE_RADIO, OnGlyphsFromRangeRadio)
  35. ON_EN_CHANGE(IDC_GLYPHSRANGEFROM_EDIT, OnChangeGlpyhsRangeEdit)
  36. ON_BN_CLICKED(IDC_GLYPHSFROMFILE_RADIO, OnGlyphsFromFileRadio)
  37. ON_EN_KILLFOCUS(IDC_GLYPHSFILE_EDIT, OnChangeGlyphsFileEdit)
  38. ON_BN_CLICKED(IDC_GLYPHSFILESELECTOR_BUTTON, OnGlyphsFileSelectorButton)
  39. ON_BN_CLICKED(IDC_GLYPHSCUSTOM_RADIO, OnGlyphsCustom)
  40. ON_BN_CLICKED(IDC_TEXTURESIZE_BUTTON, OnTextureSizeButton)
  41. ON_BN_CLICKED(IDC_MAGNIFY_BUTTON, OnMagnifyButton)
  42. ON_BN_CLICKED(IDC_GLYPH_SPECIAL, OnGlyphSpecial)
  43. ON_UPDATE_COMMAND_UI(IDC_MAGNIFY_BUTTON, OnUpdateButton)
  44. ON_COMMAND(IDM_FILE_LOADFONTFILE, OnLoadButton)
  45. ON_COMMAND(IDM_FILE_SAVEFONTFILES, OnSaveButton)
  46. ON_COMMAND(IDM_FILE_LOADFONTLAYOUT, OnLoadCustomFontButton)
  47. ON_COMMAND(IDM_FILE_EXIT, OnExit)
  48. ON_COMMAND(ID_APP_ABOUT, OnAbout)
  49. ON_COMMAND(ID_HELP, OnHelp)
  50. ON_EN_CHANGE(IDC_GLYPHSRANGETO_EDIT, OnChangeGlpyhsRangeEdit)
  51. ON_UPDATE_COMMAND_UI(IDC_TEXTURESIZE_BUTTON, OnUpdateButton)
  52. ON_UPDATE_COMMAND_UI(IDC_GLYPHSFILESELECTOR_BUTTON, OnUpdateButton)
  53. ON_UPDATE_COMMAND_UI(IDM_FILE_NEWFONT, OnUpdateButton)
  54. ON_UPDATE_COMMAND_UI(IDM_FILE_LOADFONTFILE, OnUpdateButton)
  55. ON_UPDATE_COMMAND_UI(IDM_FILE_LOADFONTLAYOUT, OnUpdateButton)
  56. ON_UPDATE_COMMAND_UI(IDM_FILE_SAVEFONTFILES, OnUpdateButton)
  57. ON_UPDATE_COMMAND_UI(IDM_FILE_EXIT, OnUpdateButton)
  58. ON_UPDATE_COMMAND_UI(ID_APP_ABOUT, OnUpdateButton)
  59. ON_UPDATE_COMMAND_UI(ID_HELP, OnUpdateButton)
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. //-----------------------------------------------------------------------------
  63. // The one and only CFontMakerApp object
  64. //-----------------------------------------------------------------------------
  65. CFontMakerApp theApp;
  66. //-----------------------------------------------------------------------------
  67. // Name: InitInstance()
  68. // Desc: App initialization
  69. //-----------------------------------------------------------------------------
  70. BOOL CFontMakerApp::InitInstance()
  71. {
  72. // Create the main frame window for the app
  73. CFontMakerFrameWnd* pFrameWnd = new CFontMakerFrameWnd;
  74. m_pMainWnd = pFrameWnd;
  75. // Associate the view with the frame
  76. CCreateContext context;
  77. context.m_pCurrentFrame = NULL;
  78. context.m_pCurrentDoc = NULL;
  79. context.m_pNewViewClass = RUNTIME_CLASS(CFontMakerView);
  80. context.m_pNewDocTemplate = NULL;
  81. // Create the frame and load resources (menu, accelerator, etc.)
  82. pFrameWnd->LoadFrame( IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,
  83. NULL, &context );
  84. // Call OnInitialUpdate() to be called for the view
  85. pFrameWnd->InitialUpdateFrame( NULL, TRUE );
  86. // The one and only window has been initialized, so show and update it.
  87. m_pMainWnd->ShowWindow( SW_SHOW );
  88. m_pMainWnd->UpdateWindow();
  89. // Load the hourglass cursor
  90. m_hWaitCursor = LoadCursor( IDC_WAIT );
  91. // Get access the the dialog controls and the view
  92. m_pDialogBar = pFrameWnd->GetDialogBar();
  93. m_pView = (CFontMakerView*)pFrameWnd->GetActiveView();
  94. // Initially, no font is selected
  95. m_pDialogBar->GetDlgItem( IDC_FONTNAME_STATIC )->SetWindowText( _T("<Choose font>") );
  96. m_pDialogBar->GetDlgItem( IDC_FONTSTYLE_STATIC )->SetWindowText( _T("") );
  97. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_STATIC )->SetWindowText( _T("") );
  98. return TRUE;
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Name: OnUpdateButton()
  102. // Desc: This function is needed to override some internal mucking with button
  103. // states. Without it, button and menu enabling will make you crazy.
  104. //-----------------------------------------------------------------------------
  105. void CFontMakerApp::OnUpdateButton( CCmdUI* pCmdUI )
  106. {
  107. BOOL bEnable;
  108. switch( pCmdUI->m_nID )
  109. {
  110. // Controls which are active all the time
  111. case IDM_FILE_NEWFONT:
  112. case IDM_FILE_LOADFONTLAYOUT:
  113. case IDM_FILE_LOADFONTFILE:
  114. case IDM_FILE_EXIT:
  115. case ID_APP_ABOUT:
  116. case ID_HELP:
  117. bEnable = TRUE;
  118. break;
  119. case IDC_TEXTURESIZE_BUTTON:
  120. case IDM_FILE_SAVEFONTFILES:
  121. case IDC_MAGNIFY_BUTTON:
  122. bEnable = g_Font.m_hFont ? TRUE : FALSE;
  123. if ( !bEnable )
  124. bEnable = g_Font.m_pCustomFilename ? TRUE : FALSE;
  125. break;
  126. // Controls which are active only when a font is available
  127. default:
  128. bEnable = g_Font.m_hFont ? TRUE : FALSE;
  129. break;
  130. }
  131. pCmdUI->Enable( bEnable );
  132. }
  133. BOOL g_bFirstTime = TRUE;
  134. //-----------------------------------------------------------------------------
  135. // Name: OnNewFontButton()
  136. // Desc: Called when the user hits the "New Font" button, this loads the font
  137. // and enables all the other windows controls.
  138. //-----------------------------------------------------------------------------
  139. void CFontMakerApp::OnNewFontButton()
  140. {
  141. // Initialize the LOGFONT structure. It's static so it's state is remembered
  142. if ( g_Font.m_LogFont.lfHeight == 0 )
  143. {
  144. // first time init
  145. strcpy( g_Font.m_LogFont.lfFaceName, "Arial" ); // Arial font for a default
  146. g_Font.m_LogFont.lfHeight = 16; // 16 height font for a default
  147. g_Font.m_LogFont.lfWeight = 400; // 400 = normal, 700 = bold, etc.
  148. g_Font.m_LogFont.lfItalic = 0; // 0 = normal, 255 = italic
  149. g_Font.m_LogFont.lfQuality = ANTIALIASED_QUALITY;
  150. }
  151. // convert to point size for dialog purposes
  152. HDC hDC = GetDC( m_pMainWnd->m_hWnd );
  153. // Current point size unit=1/10 pts
  154. INT iPointSize = g_Font.m_LogFont.lfHeight * 10;
  155. g_Font.m_LogFont.lfHeight= -MulDiv( iPointSize, GetDeviceCaps( hDC, LOGPIXELSY ), 720 );
  156. ReleaseDC( m_pMainWnd->m_hWnd, hDC );
  157. // Create the CHOOSEFONT structure
  158. static CHOOSEFONT cf = {0};
  159. cf.lStructSize = sizeof(CHOOSEFONT);
  160. cf.lpLogFont = &g_Font.m_LogFont;
  161. cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
  162. cf.nFontType = SCREEN_FONTTYPE;
  163. if ( 0 == ChooseFont( &cf ) )
  164. return;
  165. g_Font.m_pCustomFilename = NULL;
  166. // NOT using point sizes, but cell heights
  167. g_Font.m_LogFont.lfHeight = cf.iPointSize/10;
  168. // Reset the selected glpyh
  169. UpdateSelectedGlyph( FALSE );
  170. if( FAILED( CalculateAndRenderGlyphs() ) )
  171. {
  172. // Could not create new font
  173. MessageBox( m_pMainWnd->m_hWnd, "Could not create the requested font!", "Error", MB_ICONERROR|MB_OK );
  174. return;
  175. }
  176. char tempName[256];
  177. sprintf( tempName, "%s_%d", g_Font.m_LogFont.lfFaceName, cf.iPointSize/10 );
  178. // remove any spaces in the font name
  179. for (unsigned int i=0,j=0; i<strlen( tempName )+1; i++)
  180. {
  181. if ( tempName[i] != ' ' )
  182. {
  183. g_Font.m_strFontName[j++] = tempName[i];
  184. }
  185. }
  186. if ( g_bFirstTime )
  187. {
  188. CString str;
  189. // Set font properties
  190. m_pDialogBar->GetDlgItem( IDC_FONT_GROUPBOX )->EnableWindow( TRUE );
  191. m_pDialogBar->GetDlgItem( IDC_FONTNAME_LABEL )->EnableWindow( TRUE );
  192. m_pDialogBar->GetDlgItem( IDC_FONTSTYLE_LABEL )->EnableWindow( TRUE );
  193. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_LABEL )->EnableWindow( TRUE );
  194. m_pDialogBar->GetDlgItem( IDC_FONTNAME_STATIC )->EnableWindow( TRUE );
  195. m_pDialogBar->GetDlgItem( IDC_FONTSTYLE_STATIC )->EnableWindow( TRUE );
  196. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_STATIC )->EnableWindow( TRUE );
  197. m_pDialogBar->GetDlgItem( IDC_EFFECTSOUTLINED_CHECK )->EnableWindow( TRUE );
  198. m_pDialogBar->GetDlgItem( IDC_EFFECTSSHADOWED_CHECK )->EnableWindow( TRUE );
  199. m_pDialogBar->GetDlgItem( IDC_EFFECTSBLURRED_CHECK )->EnableWindow( TRUE );
  200. m_pDialogBar->GetDlgItem( IDC_EFFECTSSCANLINES_CHECK )->EnableWindow( TRUE );
  201. m_pDialogBar->GetDlgItem( IDC_EFFECTSANTIALIAS_CHECK )->EnableWindow( TRUE );
  202. m_pDialogBar->GetDlgItem( IDC_BLUR_EDIT )->EnableWindow( TRUE );
  203. m_pDialogBar->GetDlgItem( IDC_SCANLINES_EDIT )->EnableWindow( TRUE );
  204. if ( g_Font.m_bAntialiasEffect )
  205. {
  206. ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSANTIALIAS_CHECK ))->SetCheck( TRUE );
  207. }
  208. else
  209. {
  210. ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSANTIALIAS_CHECK ))->SetCheck( FALSE );
  211. }
  212. str.Format( "%d", g_Font.m_nBlur );
  213. m_pDialogBar->GetDlgItem( IDC_BLUR_EDIT )->SetWindowText( str );
  214. str.Format( "%d", g_Font.m_nScanlines );
  215. m_pDialogBar->GetDlgItem( IDC_SCANLINES_EDIT )->SetWindowText( str );
  216. str.Format( "%s", g_Font.m_LogFont.lfFaceName );
  217. m_pDialogBar->GetDlgItem( IDC_FONTNAME_STATIC )->SetWindowText( str );
  218. if( g_Font.m_LogFont.lfItalic )
  219. str.Format( "Italic", g_Font.m_LogFont.lfWeight < 550 ? "" : "Bold " );
  220. else
  221. str.Format( "%s", g_Font.m_LogFont.lfWeight < 550 ? "Regular" : "Bold" );
  222. m_pDialogBar->GetDlgItem( IDC_FONTSTYLE_STATIC )->SetWindowText( str );
  223. str.Format( "%ld", cf.iPointSize/10 );
  224. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_STATIC )->SetWindowText( str );
  225. // Set texture properties
  226. m_pDialogBar->GetDlgItem( IDC_TEXTURE_GROUPBOX )->EnableWindow( TRUE );
  227. m_pDialogBar->GetDlgItem( IDC_TEXTUREWIDTH_LABEL )->EnableWindow( TRUE );
  228. m_pDialogBar->GetDlgItem( IDC_TEXTUREHEIGHT_LABEL )->EnableWindow( TRUE );
  229. m_pDialogBar->GetDlgItem( IDC_TEXTUREWIDTH_STATIC )->EnableWindow( TRUE );
  230. m_pDialogBar->GetDlgItem( IDC_TEXTUREHEIGHT_STATIC )->EnableWindow( TRUE );
  231. m_pDialogBar->GetDlgItem( IDC_TEXTURESIZE_BUTTON )->EnableWindow( TRUE );
  232. SetTextureSize( g_Font.m_dwTextureWidth, g_Font.m_dwTextureHeight );
  233. // Set glyph range properties
  234. m_pDialogBar->GetDlgItem( IDC_GLYPHS_GROUPBOX )->EnableWindow( TRUE );
  235. m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMRANGE_RADIO )->EnableWindow( TRUE );
  236. m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMFILE_RADIO )->EnableWindow( TRUE );
  237. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_EDIT )->EnableWindow( TRUE );
  238. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_EDIT )->EnableWindow( TRUE );
  239. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_LABEL )->EnableWindow( TRUE );
  240. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_LABEL )->EnableWindow( TRUE );
  241. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILE_EDIT )->EnableWindow( FALSE );
  242. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILESELECTOR_BUTTON )->EnableWindow( FALSE );
  243. m_pDialogBar->GetDlgItem( IDC_GLYPHSCUSTOM_RADIO )->EnableWindow( TRUE );
  244. // Set a default range of glyphs to use
  245. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMRANGE_RADIO ))->SetCheck( TRUE );
  246. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_EDIT )->SetWindowText( "32" );
  247. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_EDIT )->SetWindowText( "127" );
  248. g_Font.ExtractValidGlyphsFromRange( 32, 127 );
  249. m_pDialogBar->GetDlgItem( IDC_INSERTGLYPH_LABEL )->EnableWindow( TRUE );
  250. m_pDialogBar->GetDlgItem( IDC_INSERTGLYPH_EDIT )->EnableWindow( TRUE );
  251. }
  252. else
  253. {
  254. CString str;
  255. str.Format( "%s", g_Font.m_LogFont.lfFaceName );
  256. m_pDialogBar->GetDlgItem( IDC_FONTNAME_STATIC )->SetWindowText( str );
  257. if ( g_Font.m_LogFont.lfItalic )
  258. str.Format( "Italic", g_Font.m_LogFont.lfWeight < 550 ? "" : "Bold " );
  259. else
  260. str.Format( "%s", g_Font.m_LogFont.lfWeight < 550 ? "Regular" : "Bold" );
  261. m_pDialogBar->GetDlgItem( IDC_FONTSTYLE_STATIC )->SetWindowText( str );
  262. str.Format( "%ld", cf.iPointSize/10 );
  263. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_STATIC )->SetWindowText( str );
  264. }
  265. g_bFirstTime = FALSE;
  266. }
  267. //-----------------------------------------------------------------------------
  268. // Name: OnGlyphsFromRangeRadio()
  269. // Desc: User will be specifying a glyph range manually
  270. //-----------------------------------------------------------------------------
  271. void CFontMakerApp::OnGlyphsFromRangeRadio()
  272. {
  273. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_LABEL )->EnableWindow( TRUE );
  274. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_LABEL )->EnableWindow( TRUE );
  275. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_EDIT )->EnableWindow( TRUE );
  276. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_EDIT )->EnableWindow( TRUE );
  277. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILE_EDIT )->EnableWindow( FALSE );
  278. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILESELECTOR_BUTTON )->EnableWindow( FALSE );
  279. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMFILE_RADIO ))->SetCheck( false );
  280. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMRANGE_RADIO ))->SetCheck( true );
  281. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSCUSTOM_RADIO ))->SetCheck( false );
  282. OnChangeGlpyhsRangeEdit();
  283. }
  284. //-----------------------------------------------------------------------------
  285. // Name: OnChangeGlpyhsRangeEdit()
  286. // Desc: User changed the range of glpyhs
  287. //-----------------------------------------------------------------------------
  288. void CFontMakerApp::OnChangeGlpyhsRangeEdit()
  289. {
  290. if( NULL == g_Font.m_hFont )
  291. return;
  292. CEdit* pGlyphRangeFromEdit = (CEdit*)m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_EDIT );
  293. CEdit* pGlyphRangeToEdit = (CEdit*)m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_EDIT );
  294. CString strFrom;
  295. CString strTo;
  296. pGlyphRangeFromEdit->GetWindowText( strFrom );
  297. pGlyphRangeToEdit->GetWindowText( strTo );
  298. WORD wFrom = (WORD)max( 0, atoi( strFrom ) );
  299. WORD wTo = (WORD)min( 65535, atoi( strTo ) );
  300. g_Font.ExtractValidGlyphsFromRange( wFrom, wTo );
  301. // Draw the new font glyphs
  302. CalculateAndRenderGlyphs();
  303. }
  304. void CFontMakerApp::OnGlyphsCustom()
  305. {
  306. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMFILE_RADIO ))->SetCheck( false );
  307. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMRANGE_RADIO ))->SetCheck( false );
  308. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSCUSTOM_RADIO ))->SetCheck( true );
  309. }
  310. //-----------------------------------------------------------------------------
  311. // Name: OnGlyphsFromFileRadio()
  312. // Desc: User want to extract glyphs that are used in a text file
  313. //-----------------------------------------------------------------------------
  314. void CFontMakerApp::OnGlyphsFromFileRadio()
  315. {
  316. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_LABEL )->EnableWindow( FALSE );
  317. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_LABEL )->EnableWindow( FALSE );
  318. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_EDIT )->EnableWindow( FALSE );
  319. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_EDIT )->EnableWindow( FALSE );
  320. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILE_EDIT )->EnableWindow( TRUE );
  321. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILESELECTOR_BUTTON )->EnableWindow( TRUE );
  322. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMFILE_RADIO ))->SetCheck( true );
  323. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMRANGE_RADIO ))->SetCheck( false );
  324. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSCUSTOM_RADIO ))->SetCheck( false );
  325. OnChangeGlyphsFileEdit();
  326. }
  327. //-----------------------------------------------------------------------------
  328. // Name: OnChangeGlyphsFileEdit()
  329. // Desc: Handle change in name of file to extract glyphs from
  330. //-----------------------------------------------------------------------------
  331. void CFontMakerApp::OnChangeGlyphsFileEdit()
  332. {
  333. CEdit* pGlyphFileNameEdit = (CEdit*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFILE_EDIT );
  334. CString strFileName;
  335. pGlyphFileNameEdit->GetWindowText( strFileName );
  336. if( strFileName.IsEmpty() )
  337. return;
  338. g_Font.ExtractValidGlyphsFromFile( (const TCHAR*)strFileName );
  339. // Draw the new font glyphs
  340. CalculateAndRenderGlyphs();
  341. }
  342. //-----------------------------------------------------------------------------
  343. // Name: OnGlyphsFileSelectorButton()
  344. // Desc: Handle change in name of file to extract glyphs from
  345. //-----------------------------------------------------------------------------
  346. void CFontMakerApp::OnGlyphsFileSelectorButton()
  347. {
  348. static TCHAR strFileName[MAX_PATH] = _T("");
  349. static TCHAR strFileName2[MAX_PATH] = _T("");
  350. static TCHAR strInitialDir[MAX_PATH] = _T("c:\\");
  351. // Display the OpenFileName dialog. Then, try to load the specified file
  352. OPENFILENAME ofn = { sizeof(OPENFILENAME), NULL, NULL,
  353. _T("Text files (.txt)\0*.txt\0\0"),
  354. NULL, 0, 1, strFileName, MAX_PATH, strFileName2, MAX_PATH,
  355. strInitialDir, _T("Open Text File"),
  356. OFN_FILEMUSTEXIST, 0, 1, NULL, 0, NULL, NULL };
  357. if( TRUE == GetOpenFileName( &ofn ) )
  358. {
  359. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILE_EDIT )->SetWindowText( ofn.lpstrFile);
  360. OnChangeGlyphsFileEdit();
  361. }
  362. }
  363. //-----------------------------------------------------------------------------
  364. // Name: OnEffectsCheck()
  365. // Desc: User changed font rendering options
  366. //-----------------------------------------------------------------------------
  367. void CFontMakerApp::OnEffectsCheck()
  368. {
  369. g_Font.m_bOutlineEffect = ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSOUTLINED_CHECK ))->GetCheck();
  370. g_Font.m_bShadowEffect = ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSSHADOWED_CHECK ))->GetCheck();
  371. g_Font.m_bAntialiasEffect = ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSANTIALIAS_CHECK ))->GetCheck();
  372. bool bValveEffects = false;
  373. if ( g_Font.m_bOutlineEffect || g_Font.m_bShadowEffect )
  374. {
  375. m_pDialogBar->GetDlgItem( IDC_EFFECTSBLURRED_CHECK )->EnableWindow( false );
  376. m_pDialogBar->GetDlgItem( IDC_EFFECTSSCANLINES_CHECK )->EnableWindow( false );
  377. ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSBLURRED_CHECK ))->SetCheck( false );
  378. ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSSCANLINES_CHECK ))->SetCheck( false );
  379. }
  380. else
  381. {
  382. m_pDialogBar->GetDlgItem( IDC_EFFECTSBLURRED_CHECK )->EnableWindow( true );
  383. m_pDialogBar->GetDlgItem( IDC_EFFECTSSCANLINES_CHECK )->EnableWindow( true );
  384. bValveEffects = true;
  385. }
  386. if ( bValveEffects && ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSBLURRED_CHECK ))->GetCheck() )
  387. {
  388. CEdit* pBlurEdit = (CEdit*)m_pDialogBar->GetDlgItem( IDC_BLUR_EDIT );
  389. CString strBlur;
  390. pBlurEdit->GetWindowText( strBlur );
  391. g_Font.m_nBlur = max( 2, atoi( strBlur ) );
  392. strBlur.Format( "%d", g_Font.m_nBlur );
  393. pBlurEdit->SetWindowText( strBlur );
  394. }
  395. else
  396. {
  397. g_Font.m_nBlur = 0;
  398. }
  399. if ( bValveEffects && ((CButton*)m_pDialogBar->GetDlgItem( IDC_EFFECTSSCANLINES_CHECK ))->GetCheck() )
  400. {
  401. CEdit* pScanlineEdit = (CEdit*)m_pDialogBar->GetDlgItem( IDC_SCANLINES_EDIT );
  402. CString strScanlines;
  403. pScanlineEdit->GetWindowText( strScanlines );
  404. g_Font.m_nScanlines = max( 2, atoi( strScanlines ) );
  405. strScanlines.Format( "%d", g_Font.m_nScanlines );
  406. pScanlineEdit->SetWindowText( strScanlines );
  407. }
  408. else
  409. {
  410. g_Font.m_nScanlines = 0;
  411. }
  412. // Draw the new font glyphs
  413. CalculateAndRenderGlyphs();
  414. }
  415. //-----------------------------------------------------------------------------
  416. // Name: OnMagnifyButton()
  417. // Desc: User wants to run the Windows "magnify" tool
  418. //-----------------------------------------------------------------------------
  419. void CFontMakerApp::OnMagnifyButton()
  420. {
  421. // Run the Windows "magnify" tool
  422. WinExec( "magnify.exe", TRUE );
  423. }
  424. //-----------------------------------------------------------------------------
  425. // Name: class CTextureSizeDlg
  426. // Desc: Simple dialog to change the font texture size
  427. //-----------------------------------------------------------------------------
  428. class CTextureSizeDlg : public CDialog
  429. {
  430. public:
  431. CTextureSizeDlg();
  432. // Dialog Data
  433. //{{AFX_DATA(CTextureSizeDlg)
  434. enum { IDD = IDD_TEXTURESIZE };
  435. //}}AFX_DATA
  436. // ClassWizard generated virtual function overrides
  437. //{{AFX_VIRTUAL(CTextureSizeDlg)
  438. protected:
  439. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  440. //}}AFX_VIRTUAL
  441. // Implementation
  442. protected:
  443. //{{AFX_MSG(CTextureSizeDlg)
  444. // No message handlers
  445. //}}AFX_MSG
  446. DECLARE_MESSAGE_MAP()
  447. };
  448. CTextureSizeDlg::CTextureSizeDlg() : CDialog(CTextureSizeDlg::IDD)
  449. {
  450. //{{AFX_DATA_INIT(CTextureSizeDlg)
  451. //}}AFX_DATA_INIT
  452. }
  453. void CTextureSizeDlg::DoDataExchange(CDataExchange* pDX)
  454. {
  455. CDialog::DoDataExchange(pDX);
  456. //{{AFX_DATA_MAP(CTextureSizeDlg)
  457. DDX_Text( pDX, IDC_WIDTH, g_Font.m_dwTextureWidth );
  458. DDV_MinMaxInt( pDX, g_Font.m_dwTextureWidth, 16, 2048 );
  459. DDX_Text( pDX, IDC_HEIGHT, g_Font.m_dwTextureHeight );
  460. DDV_MinMaxInt( pDX, g_Font.m_dwTextureHeight, 16, 2048 );
  461. //}}AFX_DATA_MAP
  462. }
  463. BEGIN_MESSAGE_MAP(CTextureSizeDlg, CDialog)
  464. //{{AFX_MSG_MAP(CTextureSizeDlg)
  465. //}}AFX_MSG_MAP
  466. END_MESSAGE_MAP()
  467. void CFontMakerApp::SetTextureSize( int width, int height )
  468. {
  469. g_Font.m_dwTextureWidth = width;
  470. g_Font.m_dwTextureHeight = height;
  471. CString str;
  472. str.Format( "%ld", g_Font.m_dwTextureWidth );
  473. m_pDialogBar->GetDlgItem( IDC_TEXTUREWIDTH_STATIC )->SetWindowText( str );
  474. str.Format( "%ld", g_Font.m_dwTextureHeight );
  475. m_pDialogBar->GetDlgItem( IDC_TEXTUREHEIGHT_STATIC )->SetWindowText( str );
  476. }
  477. //-----------------------------------------------------------------------------
  478. // Name: OnTextureSizeButton()
  479. // Desc: User wants to change the font texture size
  480. //-----------------------------------------------------------------------------
  481. void CFontMakerApp::OnTextureSizeButton()
  482. {
  483. if ( !g_Font.m_hFont && !g_Font.m_pCustomFilename )
  484. return;
  485. CTextureSizeDlg dlgTextureSize;
  486. dlgTextureSize.DoModal();
  487. SetTextureSize( g_Font.m_dwTextureWidth, g_Font.m_dwTextureHeight );
  488. // Draw the new font glyphs
  489. CalculateAndRenderGlyphs();
  490. }
  491. void CFontMakerApp::InsertGlyph()
  492. {
  493. CEdit* pGlyphInsert = (CEdit*)m_pDialogBar->GetDlgItem( IDC_INSERTGLYPH_EDIT );
  494. CString strInsert;
  495. pGlyphInsert->GetWindowText( strInsert );
  496. WORD wGlyph = atoi( strInsert );
  497. if ( wGlyph < 0 )
  498. wGlyph = 0;
  499. else if ( wGlyph > 65535 )
  500. wGlyph = 65535;
  501. g_Font.InsertGlyph( wGlyph );
  502. }
  503. //-----------------------------------------------------------------------------
  504. // Name: UpdateSelectedGlyph()
  505. // Desc: User changed (via mouse or keyboard) which glyph is selected
  506. //-----------------------------------------------------------------------------
  507. void CFontMakerApp::UpdateSelectedGlyph( BOOL bGlyphSelected, int iSelectedGlyph )
  508. {
  509. // Handle case where no glyph is selected
  510. g_bIsGlyphSelected = FALSE;
  511. g_iSelectedGlyphNum = 0;
  512. g_pSelectedGylph = NULL;
  513. g_cSelectedGlyph = L'\0';
  514. if ( bGlyphSelected )
  515. {
  516. for ( DWORD i=0; i<=g_Font.m_cMaxGlyph; i++ )
  517. {
  518. if ( g_Font.m_TranslatorTable[i] == iSelectedGlyph )
  519. {
  520. g_bIsGlyphSelected = TRUE;
  521. g_iSelectedGlyphNum = iSelectedGlyph;
  522. g_pSelectedGylph = &g_Font.m_pGlyphs[iSelectedGlyph];
  523. g_cSelectedGlyph = (WCHAR)i;
  524. break;
  525. }
  526. }
  527. }
  528. // Enable/disable/set-text-of the appropriate controls
  529. if ( g_bIsGlyphSelected )
  530. {
  531. CString str;
  532. str.Format( "%d", g_cSelectedGlyph ); m_pDialogBar->GetDlgItem( IDC_GLYPH_VALUE_STATIC )->SetWindowText( str );
  533. str.Format( "%d", g_pSelectedGylph->x ); m_pDialogBar->GetDlgItem( IDC_GLYPH_X_STATIC )->SetWindowText( str );
  534. str.Format( "%d", g_pSelectedGylph->y ); m_pDialogBar->GetDlgItem( IDC_GLYPH_Y_STATIC )->SetWindowText( str );
  535. str.Format( "%d", g_pSelectedGylph->w ); m_pDialogBar->GetDlgItem( IDC_GLYPH_W_STATIC )->SetWindowText( str );
  536. str.Format( "%d", g_pSelectedGylph->h ); m_pDialogBar->GetDlgItem( IDC_GLYPH_H_STATIC )->SetWindowText( str );
  537. str.Format( "%d", g_pSelectedGylph->a ); m_pDialogBar->GetDlgItem( IDC_GLYPH_A_STATIC )->SetWindowText( str );
  538. str.Format( "%d", g_pSelectedGylph->b ); m_pDialogBar->GetDlgItem( IDC_GLYPH_B_STATIC )->SetWindowText( str );
  539. str.Format( "%d", g_pSelectedGylph->c ); m_pDialogBar->GetDlgItem( IDC_GLYPH_C_STATIC )->SetWindowText( str );
  540. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPH_SPECIAL ))->SetCheck( g_Font.m_ValidGlyphs[g_cSelectedGlyph] == 2 );
  541. }
  542. else
  543. {
  544. CString str("");
  545. m_pDialogBar->GetDlgItem( IDC_GLYPH_VALUE_STATIC )->SetWindowText( str );
  546. m_pDialogBar->GetDlgItem( IDC_GLYPH_X_STATIC )->SetWindowText( str );
  547. m_pDialogBar->GetDlgItem( IDC_GLYPH_Y_STATIC )->SetWindowText( str );
  548. m_pDialogBar->GetDlgItem( IDC_GLYPH_W_STATIC )->SetWindowText( str );
  549. m_pDialogBar->GetDlgItem( IDC_GLYPH_H_STATIC )->SetWindowText( str );
  550. m_pDialogBar->GetDlgItem( IDC_GLYPH_A_STATIC )->SetWindowText( str );
  551. m_pDialogBar->GetDlgItem( IDC_GLYPH_B_STATIC )->SetWindowText( str );
  552. m_pDialogBar->GetDlgItem( IDC_GLYPH_C_STATIC )->SetWindowText( str );
  553. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPH_SPECIAL ))->SetCheck( FALSE );
  554. }
  555. m_pDialogBar->GetDlgItem( IDC_SELECTEDGLYPH_GROUPBOX )->EnableWindow( g_bIsGlyphSelected );
  556. m_pDialogBar->GetDlgItem( IDC_GLYPH_VALUE_LABEL )->EnableWindow( g_bIsGlyphSelected );
  557. m_pDialogBar->GetDlgItem( IDC_GLYPH_X_LABEL )->EnableWindow( g_bIsGlyphSelected );
  558. m_pDialogBar->GetDlgItem( IDC_GLYPH_Y_LABEL )->EnableWindow( g_bIsGlyphSelected );
  559. m_pDialogBar->GetDlgItem( IDC_GLYPH_W_LABEL )->EnableWindow( g_bIsGlyphSelected );
  560. m_pDialogBar->GetDlgItem( IDC_GLYPH_H_LABEL )->EnableWindow( g_bIsGlyphSelected );
  561. m_pDialogBar->GetDlgItem( IDC_GLYPH_A_LABEL )->EnableWindow( g_bIsGlyphSelected );
  562. m_pDialogBar->GetDlgItem( IDC_GLYPH_B_LABEL )->EnableWindow( g_bIsGlyphSelected );
  563. m_pDialogBar->GetDlgItem( IDC_GLYPH_C_LABEL )->EnableWindow( g_bIsGlyphSelected );
  564. m_pDialogBar->GetDlgItem( IDC_GLYPH_VALUE_STATIC )->EnableWindow( g_bIsGlyphSelected );
  565. m_pDialogBar->GetDlgItem( IDC_GLYPH_X_STATIC )->EnableWindow( g_bIsGlyphSelected );
  566. m_pDialogBar->GetDlgItem( IDC_GLYPH_Y_STATIC )->EnableWindow( g_bIsGlyphSelected );
  567. m_pDialogBar->GetDlgItem( IDC_GLYPH_W_STATIC )->EnableWindow( g_bIsGlyphSelected );
  568. m_pDialogBar->GetDlgItem( IDC_GLYPH_H_STATIC )->EnableWindow( g_bIsGlyphSelected );
  569. m_pDialogBar->GetDlgItem( IDC_GLYPH_A_STATIC )->EnableWindow( g_bIsGlyphSelected );
  570. m_pDialogBar->GetDlgItem( IDC_GLYPH_B_STATIC )->EnableWindow( g_bIsGlyphSelected );
  571. m_pDialogBar->GetDlgItem( IDC_GLYPH_C_STATIC )->EnableWindow( g_bIsGlyphSelected );
  572. m_pDialogBar->GetDlgItem( IDC_GLYPH_SPECIAL )->EnableWindow( g_bIsGlyphSelected );
  573. }
  574. //-----------------------------------------------------------------------------
  575. // Name: OnGlyphSpecial()
  576. // Desc: User changed the status of the selected glyph
  577. //-----------------------------------------------------------------------------
  578. void CFontMakerApp::OnGlyphSpecial()
  579. {
  580. if( g_bIsGlyphSelected )
  581. {
  582. if( ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPH_SPECIAL ))->GetCheck() )
  583. g_Font.m_ValidGlyphs[g_cSelectedGlyph] = 2;
  584. else
  585. g_Font.m_ValidGlyphs[g_cSelectedGlyph] = 1;
  586. // Draw the font glyphs, which may have changed layout
  587. CalculateAndRenderGlyphs();
  588. }
  589. }
  590. //-----------------------------------------------------------------------------
  591. // Name: OnLoadButton()
  592. // Desc: User wants to load a font file
  593. //-----------------------------------------------------------------------------
  594. void CFontMakerApp::OnLoadButton()
  595. {
  596. CHAR strVBFFileName[MAX_PATH];
  597. sprintf( strVBFFileName, "%s.vbf", g_Font.m_strFontName );
  598. OPENFILENAME ofnVBF; // common dialog box structure
  599. ZeroMemory( &ofnVBF, sizeof(OPENFILENAME) );
  600. ofnVBF.lStructSize = sizeof(OPENFILENAME);
  601. ofnVBF.hwndOwner = m_pMainWnd->m_hWnd;
  602. ofnVBF.lpstrFilter = "Font files (*.vbf)\0*.vbf\0\0";
  603. ofnVBF.nFilterIndex = 1;
  604. ofnVBF.lpstrFile = strVBFFileName;
  605. ofnVBF.nMaxFile = sizeof(strVBFFileName);
  606. ofnVBF.lpstrFileTitle = NULL;
  607. ofnVBF.nMaxFileTitle = 0;
  608. ofnVBF.lpstrInitialDir = NULL;
  609. ofnVBF.lpstrTitle = "Load Font (VBF) File...";
  610. ofnVBF.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_READONLY;
  611. // Display the Load dialog box for the VBF file
  612. if ( FALSE == GetOpenFileName( &ofnVBF ) )
  613. return;
  614. if ( FAILED( g_Font.ReadFontInfoFile( strVBFFileName ) ) )
  615. {
  616. m_pMainWnd->MessageBox( "Could not load the Valve bitmap font info file.",
  617. "Error", MB_ICONERROR|MB_OK );
  618. return;
  619. }
  620. }
  621. //-----------------------------------------------------------------------------
  622. // OnLoadCustomFontButton
  623. //-----------------------------------------------------------------------------
  624. void CFontMakerApp::OnLoadCustomFontButton()
  625. {
  626. CHAR strVCFFileName[MAX_PATH];
  627. strVCFFileName[0] = '\0';
  628. OPENFILENAME ofnVCF; // common dialog box structure
  629. ZeroMemory( &ofnVCF, sizeof(OPENFILENAME) );
  630. ofnVCF.lStructSize = sizeof(OPENFILENAME);
  631. ofnVCF.hwndOwner = m_pMainWnd->m_hWnd;
  632. ofnVCF.lpstrFilter = "Custom Font files (*.vcf)\0*.vcf\0\0";
  633. ofnVCF.nFilterIndex = 1;
  634. ofnVCF.lpstrFile = strVCFFileName;
  635. ofnVCF.nMaxFile = sizeof(strVCFFileName);
  636. ofnVCF.lpstrFileTitle = NULL;
  637. ofnVCF.nMaxFileTitle = 0;
  638. ofnVCF.lpstrInitialDir = NULL;
  639. ofnVCF.lpstrTitle = "Load Custom Font (VCF) File...";
  640. ofnVCF.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_READONLY;
  641. // Display the Load dialog box for the VBF file
  642. if ( FALSE == GetOpenFileName( &ofnVCF ) )
  643. return;
  644. if ( FAILED( g_Font.ReadCustomFontFile( strVCFFileName ) ) )
  645. {
  646. m_pMainWnd->MessageBox( "Could not load the Valve bitmap custom font file.",
  647. "Error", MB_ICONERROR|MB_OK );
  648. return;
  649. }
  650. // Reset the selected glpyh
  651. UpdateSelectedGlyph( FALSE );
  652. if ( FAILED( CalculateAndRenderGlyphs() ) )
  653. {
  654. // Could not create new font
  655. MessageBox( m_pMainWnd->m_hWnd, "Could not create the requested font!", "Error", MB_ICONERROR|MB_OK );
  656. return;
  657. }
  658. m_pDialogBar->GetDlgItem( IDC_FONT_GROUPBOX )->EnableWindow( FALSE );
  659. m_pDialogBar->GetDlgItem( IDC_FONTNAME_LABEL )->EnableWindow( TRUE );
  660. m_pDialogBar->GetDlgItem( IDC_FONTSTYLE_LABEL )->EnableWindow( TRUE );
  661. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_LABEL )->EnableWindow( TRUE );
  662. m_pDialogBar->GetDlgItem( IDC_FONTNAME_STATIC )->EnableWindow( TRUE );
  663. m_pDialogBar->GetDlgItem( IDC_FONTSTYLE_STATIC )->EnableWindow( FALSE );
  664. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_STATIC )->EnableWindow( TRUE );
  665. m_pDialogBar->GetDlgItem( IDC_EFFECTSOUTLINED_CHECK )->EnableWindow( FALSE );
  666. m_pDialogBar->GetDlgItem( IDC_EFFECTSSHADOWED_CHECK )->EnableWindow( FALSE );
  667. m_pDialogBar->GetDlgItem( IDC_EFFECTSBLURRED_CHECK )->EnableWindow( FALSE );
  668. m_pDialogBar->GetDlgItem( IDC_EFFECTSSCANLINES_CHECK )->EnableWindow( FALSE );
  669. m_pDialogBar->GetDlgItem( IDC_EFFECTSANTIALIAS_CHECK )->EnableWindow( FALSE );
  670. m_pDialogBar->GetDlgItem( IDC_BLUR_EDIT )->EnableWindow( FALSE );
  671. m_pDialogBar->GetDlgItem( IDC_SCANLINES_EDIT )->EnableWindow( FALSE );
  672. CString str;
  673. str.Format( "%s", g_Font.m_strFontName );
  674. m_pDialogBar->GetDlgItem( IDC_FONTNAME_STATIC )->SetWindowText( str );
  675. str.Format( "%d", g_Font.m_maxCustomCharHeight );
  676. m_pDialogBar->GetDlgItem( IDC_FONTSIZE_STATIC )->SetWindowText( str );
  677. // Set texture properties
  678. m_pDialogBar->GetDlgItem( IDC_TEXTURE_GROUPBOX )->EnableWindow( TRUE );
  679. m_pDialogBar->GetDlgItem( IDC_TEXTUREWIDTH_LABEL )->EnableWindow( TRUE );
  680. m_pDialogBar->GetDlgItem( IDC_TEXTUREHEIGHT_LABEL )->EnableWindow( TRUE );
  681. m_pDialogBar->GetDlgItem( IDC_TEXTUREWIDTH_STATIC )->EnableWindow( TRUE );
  682. m_pDialogBar->GetDlgItem( IDC_TEXTUREHEIGHT_STATIC )->EnableWindow( TRUE );
  683. m_pDialogBar->GetDlgItem( IDC_TEXTURESIZE_BUTTON )->EnableWindow( TRUE );
  684. SetTextureSize( g_Font.m_dwTextureWidth, g_Font.m_dwTextureHeight );
  685. // Set glyph range properties
  686. m_pDialogBar->GetDlgItem( IDC_GLYPHS_GROUPBOX )->EnableWindow( FALSE );
  687. m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMRANGE_RADIO )->EnableWindow( FALSE );
  688. m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMFILE_RADIO )->EnableWindow( FALSE );
  689. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_EDIT )->EnableWindow( FALSE );
  690. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_EDIT )->EnableWindow( FALSE );
  691. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGEFROM_LABEL )->EnableWindow( FALSE );
  692. m_pDialogBar->GetDlgItem( IDC_GLYPHSRANGETO_LABEL )->EnableWindow( FALSE );
  693. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILE_EDIT )->EnableWindow( FALSE );
  694. m_pDialogBar->GetDlgItem( IDC_GLYPHSFILESELECTOR_BUTTON )->EnableWindow( FALSE );
  695. m_pDialogBar->GetDlgItem( IDC_GLYPHSCUSTOM_RADIO )->EnableWindow( TRUE );
  696. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMRANGE_RADIO ))->SetCheck( FALSE );
  697. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSFROMFILE_RADIO ))->SetCheck( FALSE );
  698. ((CButton*)m_pDialogBar->GetDlgItem( IDC_GLYPHSCUSTOM_RADIO ))->SetCheck( TRUE );
  699. m_pDialogBar->GetDlgItem( IDC_INSERTGLYPH_LABEL )->EnableWindow( FALSE );
  700. m_pDialogBar->GetDlgItem( IDC_INSERTGLYPH_EDIT )->EnableWindow( FALSE );
  701. }
  702. //-----------------------------------------------------------------------------
  703. // Name: OnSaveButton()
  704. // Desc: User wants to save the font files
  705. //-----------------------------------------------------------------------------
  706. void CFontMakerApp::OnSaveButton()
  707. {
  708. CHAR strTGAFileName[MAX_PATH];
  709. CHAR strVBFFileName[MAX_PATH];
  710. if ( !g_Font.m_hFont && !g_Font.m_pCustomFilename )
  711. return;
  712. sprintf( strTGAFileName, "%s.tga", g_Font.m_strFontName );
  713. OPENFILENAME ofnTGA; // common dialog box structure
  714. ZeroMemory( &ofnTGA, sizeof(OPENFILENAME) );
  715. ofnTGA.lStructSize = sizeof(OPENFILENAME);
  716. ofnTGA.hwndOwner = m_pMainWnd->m_hWnd;
  717. ofnTGA.lpstrFilter = "Targa files (*.tga)\0*.tga\0\0";
  718. ofnTGA.nFilterIndex = 1;
  719. ofnTGA.lpstrFile = strTGAFileName;
  720. ofnTGA.nMaxFile = sizeof(strTGAFileName);
  721. ofnTGA.lpstrFileTitle = NULL;
  722. ofnTGA.nMaxFileTitle = 0;
  723. ofnTGA.lpstrInitialDir = NULL;
  724. ofnTGA.lpstrTitle = "Save Font Texture Image (TGA) File...";
  725. ofnTGA.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_EXPLORER;
  726. // Display the Save As dialog box for the TGA file
  727. if ( FALSE == GetSaveFileName( &ofnTGA ) )
  728. return;
  729. // use the tga name, but replace the extension
  730. CHAR *ptr;
  731. CHAR temp[MAX_PATH];
  732. int len;
  733. strcpy( temp, strTGAFileName );
  734. len = strlen( temp );
  735. if ( len > 4 && temp[len-4] == '.' )
  736. {
  737. temp[len-3] = 'v';
  738. temp[len-2] = 'b';
  739. temp[len-1] = 'f';
  740. // strip the path
  741. ptr = strrchr( temp, '\\' );
  742. if ( ptr )
  743. {
  744. strcpy( strVBFFileName, ptr+1 );
  745. }
  746. else
  747. {
  748. strcpy( strVBFFileName, temp );
  749. }
  750. }
  751. else
  752. {
  753. sprintf( strVBFFileName, "%s.vbf", g_Font.m_strFontName );
  754. }
  755. // place the VBF files in the materials directory
  756. CHAR materialsDir[MAX_PATH];
  757. strcpy( materialsDir, strTGAFileName );
  758. strlwr( materialsDir );
  759. ptr = strstr( materialsDir, "\\content\\hl2x\\materialsrc\\" );
  760. if ( ptr )
  761. {
  762. // need the final dirs, skip past
  763. CHAR *ptr2 = ptr + strlen( "\\content\\hl2x\\materialsrc\\" );
  764. strcpy( temp, ptr2 );
  765. *ptr = '\0';
  766. strcat( materialsDir, "\\game\\hl2x\\materials\\" );
  767. strcat( materialsDir, temp );
  768. // strip terminal filename
  769. ptr = materialsDir + strlen( materialsDir ) - 1;
  770. while ( ptr > materialsDir )
  771. {
  772. if ( *ptr == '\\' )
  773. {
  774. *ptr = '\0';
  775. break;
  776. }
  777. ptr--;
  778. }
  779. }
  780. else
  781. {
  782. materialsDir[0] = '\0';
  783. }
  784. // Initialize OPENFILENAME
  785. OPENFILENAME ofnVBF; // common dialog box structure
  786. ZeroMemory( &ofnVBF, sizeof(OPENFILENAME) );
  787. ofnVBF.lStructSize = sizeof(OPENFILENAME);
  788. ofnVBF.hwndOwner = m_pMainWnd->m_hWnd;
  789. ofnVBF.lpstrFilter = "Font files (*.vbf)\0*.vbf\0\0";
  790. ofnVBF.nFilterIndex = 1;
  791. ofnVBF.lpstrFile = strVBFFileName;
  792. ofnVBF.nMaxFile = sizeof(strVBFFileName);
  793. ofnVBF.lpstrFileTitle = NULL;
  794. ofnVBF.nMaxFileTitle = 0;
  795. ofnVBF.lpstrInitialDir = materialsDir[0] ? materialsDir : NULL;
  796. ofnVBF.lpstrTitle = "Save Valve Bitmap Font (VBF) File...";
  797. ofnVBF.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_EXPLORER;
  798. // Display the Save As dialog box for the ABC file
  799. if ( FALSE == GetSaveFileName( &ofnVBF ) )
  800. return;
  801. // Make sure the names are valid
  802. if ( !lstrcmp( strVBFFileName, strTGAFileName ) )
  803. {
  804. m_pMainWnd->MessageBox( "Cannot have VBF and TGA filenames be the same!\nFiles not saved.",
  805. "Error", MB_ICONERROR|MB_OK );
  806. return;
  807. }
  808. // Add an extension, if there was not one
  809. if ( 0 == ofnVBF.nFileExtension )
  810. lstrcat( strVBFFileName, ".vbf" );
  811. if ( 0 == ofnTGA.nFileExtension )
  812. lstrcat( strTGAFileName, ".tga" );
  813. // Save the valve bitmap font info file (.vbf)
  814. if ( FAILED( g_Font.WriteFontInfoFile( strVBFFileName ) ) )
  815. {
  816. m_pMainWnd->MessageBox( "Could not write the Valve bitmap font info file.",
  817. "Error", MB_ICONERROR|MB_OK );
  818. return;
  819. }
  820. // blur or scanline effects require special processing to ensure
  821. // they can be used in additive mode
  822. bool bAdditiveMode = ( g_Font.m_nBlur || g_Font.m_nScanlines );
  823. // a custom font requires special processing
  824. bool bCustomFont = g_Font.m_pCustomFilename != NULL;
  825. // Save the font image file (.tga)
  826. if ( FAILED( g_Font.WriteFontImageFile( strTGAFileName, bAdditiveMode, bCustomFont ) ) )
  827. {
  828. m_pMainWnd->MessageBox( "Could not write the font texture image file.",
  829. "Error", MB_ICONERROR|MB_OK );
  830. }
  831. }
  832. //-----------------------------------------------------------------------------
  833. // Name: OnAbout()
  834. // Desc: Display about box
  835. //-----------------------------------------------------------------------------
  836. void CFontMakerApp::OnAbout()
  837. {
  838. CDialog dlg(IDD_ABOUT);
  839. dlg.DoModal();
  840. }
  841. //-----------------------------------------------------------------------------
  842. // Name: OnHelp()
  843. // Desc: Display app help
  844. //-----------------------------------------------------------------------------
  845. void CFontMakerApp::OnHelp()
  846. {
  847. HKEY hRegKey;
  848. if( ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  849. _T("SOFTWARE\\Microsoft\\XboxSDK"),
  850. 0, KEY_QUERY_VALUE, &hRegKey ) )
  851. {
  852. DWORD dwSize = MAX_PATH;
  853. CHAR InstallPath[MAX_PATH];
  854. if( ERROR_SUCCESS == RegQueryValueEx( hRegKey, _T("InstallPath"), NULL,
  855. NULL, (unsigned char *)InstallPath, &dwSize ) )
  856. {
  857. CString path = InstallPath;
  858. path += _T("\\doc\\xboxsdk.chm::/xbox_jbh_tool_fontmaker.htm");
  859. ::HtmlHelp( m_pMainWnd->GetSafeHwnd(), path, HH_DISPLAY_TOPIC, NULL );
  860. RegCloseKey( hRegKey );
  861. return;
  862. }
  863. RegCloseKey( hRegKey );
  864. }
  865. MessageBox( m_pMainWnd->GetSafeHwnd(),
  866. "Unable to find the Xbox SDK Help file xboxsdk.chm.",
  867. "Help file error", MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL );
  868. }
  869. //-----------------------------------------------------------------------------
  870. // Name: OnExit()
  871. // Desc: User chose to exit the app
  872. //-----------------------------------------------------------------------------
  873. void CFontMakerApp::OnExit()
  874. {
  875. // Send a close message to the main window
  876. m_pMainWnd->SendMessage( WM_CLOSE );
  877. }
  878. //-----------------------------------------------------------------------------
  879. // Name: ExitInstance()
  880. // Desc: Do some cleanup before exitting the app
  881. //-----------------------------------------------------------------------------
  882. int CFontMakerApp::ExitInstance()
  883. {
  884. DestroyCursor( m_hWaitCursor );
  885. return CWinApp::ExitInstance();
  886. }
  887. //-----------------------------------------------------------------------------
  888. // Name: CalculateAndRenderGlyphs()
  889. // Desc: User changed the status of the selected glyph
  890. //-----------------------------------------------------------------------------
  891. HRESULT CFontMakerApp::CalculateAndRenderGlyphs()
  892. {
  893. HRESULT hr;
  894. // This may take some time, so display a wait cursor
  895. HCURSOR hOldCursor = GetCursor();
  896. SetCursor( m_hWaitCursor );
  897. // Draw the font glyphs, which may have changed layout
  898. if( FAILED( hr = g_Font.CalculateAndRenderGlyphs() ) )
  899. return hr;
  900. // Re-select the current glyph since the font data may have changed
  901. theApp.UpdateSelectedGlyph( g_bIsGlyphSelected, g_iSelectedGlyphNum );
  902. // Inform the view of the new font glyphs
  903. m_pView->OnNewFontGlyphs();
  904. // Restore the cursor
  905. SetCursor( hOldCursor );
  906. return S_OK;
  907. }