void CCharWin::OnSaveFontConfiguration()
{
	CFileDialog dlg;
	dlg.AddFilter("All files (*.*)", "*.*");
	dlg.AddFilter("BMFont Font config (*.csv)", "*.csv", true);
	dlg.AddFilter("Text (*.txt)", "*.txt");

	// Open a SaveAs dialog to get a filename from the user
	if (dlg.AskForSaveFileName(this))
	{
		FILE *file = NULL;
		string path = dlg.GetFileName();
		file = fopen(path.c_str(), "w+");

		if (NULL != file)
		{
			// write the column definitions
			string definitions = "character,image_path,x_offset,y_offset,x_advance,x,y,width,height\n";
			fwrite(definitions.c_str(), 1, definitions.size(), file);
			const map<int, SIconImage *> &IconImages = fontGen->GetIconImageInfo();
			for (map<int, SIconImage *>::const_iterator itr = IconImages.begin(); IconImages.end() != itr; ++itr)
			{
				TCHAR characterT[4] = { 0 };
				characterT[0] = itr->first;
				string character;
				ConvertTCharToAnsi(characterT, character);

				char info[1024] = { 0 };
				int length = sprintf(info, "%s,%s,%d,%d,%d,%d,%d,%d,%d\n", \
					character.c_str(), \
					itr->second->fileName.c_str(), \
					itr->second->xoffset, \
					itr->second->yoffset, \
					itr->second->advance, \
					itr->second->x, \
					itr->second->y, \
					itr->second->width, \
					itr->second->height);
				fwrite(info, 1, length, file);
			}
			fclose(file);
		}
	}
}
void CCharWin::OnSaveConfiguration()
{
	CFileDialog dlg;
	dlg.AddFilter("All files (*.*)", "*.*");
	dlg.AddFilter("BMFont config (*.bmfc)", "*.bmfc", true);
	dlg.AddFilter("Text (*.txt)", "*.txt");

	string dir = fontGen->GetLastConfigFile();
	if( dir != GetDefaultConfig() )
	{
		// cut off the filename and last /
		dir = dir.substr(0, dir.find_last_of("/\\"));
		dlg.SetInitialDir(dir.c_str());
	}

	// Open a SaveAs dialog to get a filename from the user
	if( dlg.AskForSaveFileName(this) )
	{
		fontGen->SaveConfiguration(dlg.GetFileName().c_str());
	}
}
void CCharWin::OnSaveAs()
{
	if( isGenerating ) return;

	CFileDialog dlg;
	dlg.AddFilter("All files (*.*)", "*.*");
	dlg.AddFilter("Bitmap font (*.fnt)", "*.fnt", true);

	// Open a SaveAs dialog to get a filename from the user
	if( dlg.AskForSaveFileName(this) )
	{
		saveFontName = dlg.GetFileName();

		// First start the generation
		fontGen->GeneratePages();

		// Let the time know what to do when the generation is finished
		whenGenerateIsFinished = 2;
		isGenerating = true;

		SetCursor(LoadCursor(0, IDC_WAIT));
	}
}