📄 nfgshow.cc
字号:
viewMenu->Check(NFG_VIEW_PROFILES, false); viewMenu->AppendSeparator(); viewMenu->Append(NFG_VIEW_NAVIGATION, "&Navigation", "Display navigation window", true); viewMenu->Check(NFG_VIEW_NAVIGATION, true); viewMenu->Append(NFG_VIEW_OUTCOMES, "&Outcomes", "Display and edit outcomes", true); viewMenu->Check(NFG_VIEW_OUTCOMES, false); viewMenu->Append(NFG_VIEW_SUPPORTS, "&Supports", "Display and edit supports", true); viewMenu->Check(NFG_VIEW_SUPPORTS, false); viewMenu->AppendSeparator(); viewMenu->Append(NFG_VIEW_DOMINANCE, "&Dominance", "Display dominance information", TRUE); viewMenu->Append(NFG_VIEW_PROBABILITIES, "&Probabilities", "Display solution probabilities", TRUE); viewMenu->Append(NFG_VIEW_VALUES, "&Values", "Display strategy values", TRUE); viewMenu->AppendSeparator(); // This probably belongs in formatting instead viewMenu->Append(NFG_VIEW_OUTCOME_LABELS, "Outcome &Labels", "Display outcome labels", TRUE); wxMenu *formatMenu = new wxMenu; wxMenu *formatDisplayMenu = new wxMenu; formatDisplayMenu->Append(NFG_FORMAT_DISPLAY_DECIMALS, "&Decimal Places", "Set number of decimal places to display"); formatMenu->Append(NFG_FORMAT_DISPLAY, "&Display", formatDisplayMenu, "Configure display options"); wxMenu *formatFontMenu = new wxMenu; formatFontMenu->Append(NFG_FORMAT_FONT_DATA, "&Data", "Set data font"); formatFontMenu->Append(NFG_FORMAT_FONT_LABELS, "&Labels", "Set label font"); formatMenu->Append(NFG_FORMAT_FONT, "&Font", formatFontMenu, "Set fonts"); wxMenu *toolsMenu = new wxMenu; toolsMenu->Append(NFG_TOOLS_DOMINANCE, "&Dominance", "Find undominated strategies"); toolsMenu->Append(NFG_TOOLS_EQUILIBRIUM, "&Equilibrium", "Compute Nash equilibria (and refinements)"); toolsMenu->Append(NFG_TOOLS_QRE, "&Qre", "Compute quantal response equilibria"); wxMenu *helpMenu = new wxMenu; helpMenu->Append(wxID_ABOUT, "&About", "About Gambit"); wxMenuBar *menuBar = new wxMenuBar(wxMB_DOCKABLE); menuBar->Append(fileMenu, "&File"); menuBar->Append(editMenu, "&Edit"); menuBar->Append(viewMenu, "&View"); menuBar->Append(formatMenu, "&Format"); menuBar->Append(toolsMenu, "&Tools"); menuBar->Append(helpMenu, "&Help"); SetMenuBar(menuBar);}#include "bitmaps/new.xpm"#include "bitmaps/open.xpm"#include "bitmaps/save.xpm"#include "bitmaps/preview.xpm"#include "bitmaps/print.xpm"#include "bitmaps/help.xpm"void NfgShow::MakeToolbar(void){ wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_DOCKABLE | wxTB_HORIZONTAL); toolBar->SetMargins(4, 4); toolBar->AddTool(wxID_NEW, wxBITMAP(new), wxNullBitmap, false, -1, -1, 0, "New game", "Create a new game"); toolBar->AddTool(wxID_OPEN, wxBITMAP(open), wxNullBitmap, false, -1, -1, 0, "Open file", "Open a saved game"); toolBar->AddTool(wxID_SAVE, wxBITMAP(save), wxNullBitmap, false, -1, -1, 0, "Save game", "Save this game"); toolBar->AddSeparator(); toolBar->AddTool(wxID_PREVIEW, wxBITMAP(preview), wxNullBitmap, false, -1, -1, 0, "Print Preview", "View a preview of the game printout"); toolBar->AddTool(wxID_PRINT, wxBITMAP(print), wxNullBitmap, false, -1, -1, 0, "Print", "Print this game"); toolBar->AddSeparator(); toolBar->AddTool(wxID_ABOUT, wxBITMAP(help), wxNullBitmap, false, -1, -1, 0, "Help", "Table of contents"); toolBar->Realize(); toolBar->SetRows(1);}void NfgShow::UpdateMenus(void){ wxMenuBar *menu = GetMenuBar(); gArray<int> profile(GetContingency()); menu->Enable(NFG_VIEW_PROBABILITIES, m_profiles.Length() > 0); menu->Enable(NFG_VIEW_VALUES, m_profiles.Length() > 0); menu->Check(NFG_VIEW_OUTCOME_LABELS, !m_table->GetSettings().OutcomeValues());}//----------------------------------------------------------------------// NfgShow: Menu handlers - File menu//----------------------------------------------------------------------void NfgShow::OnFileNew(wxCommandEvent &){ wxGetApp().OnFileNew(this);}void NfgShow::OnFileOpen(wxCommandEvent &){ wxGetApp().OnFileOpen(this);}void NfgShow::OnFileSave(wxCommandEvent &p_event){ if (p_event.GetId() == wxID_SAVEAS || m_filename == "") { wxFileDialog dialog(this, "Choose file", wxPathOnly(m_filename), wxFileNameFromPath(m_filename), "*.nfg", wxSAVE | wxOVERWRITE_PROMPT); switch (dialog.ShowModal()) { case wxID_OK: SetFilename(dialog.GetPath()); break; case wxID_CANCEL: default: return; } } Nfg *nfg = 0; try { gFileOutput file(m_filename.c_str()); nfg = CompressNfg(m_nfg, *m_currentSupport); nfg->WriteNfgFile(file, 6); m_nfg.SetIsDirty(false); delete nfg; } catch (gFileOutput::OpenFailed &) { wxMessageBox(wxString::Format("Could not open %s for writing.", m_filename.c_str()), "Error", wxOK, this); if (nfg) delete nfg; } catch (gFileOutput::WriteFailed &) { wxMessageBox(wxString::Format("Write error occurred in saving %s.\n", m_filename.c_str()), "Error", wxOK, this); if (nfg) delete nfg; } catch (gException &) { wxMessageBox("Internal exception in Gambit", "Error", wxOK, this); if (nfg) delete nfg; }}void NfgShow::OnFilePageSetup(wxCommandEvent &){ wxPageSetupDialog dialog(this, &m_pageSetupData); if (dialog.ShowModal() == wxID_OK) { m_printData = dialog.GetPageSetupData().GetPrintData(); m_pageSetupData = dialog.GetPageSetupData(); }}void NfgShow::OnFilePrintPreview(wxCommandEvent &){ wxPrintDialogData data(m_printData); wxPrintPreview *preview = new wxPrintPreview(new NfgPrintout(m_nfg, m_table->GetRowPlayer(), m_table->GetColPlayer(), (char *) m_nfg.GetTitle()), new NfgPrintout(m_nfg, m_table->GetRowPlayer(), m_table->GetColPlayer(), (char *) m_nfg.GetTitle()), &data); if (!preview->Ok()) { delete preview; return; } wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Print Preview", wxPoint(100, 100), wxSize(600, 650)); frame->Initialize(); frame->Show(true);}void NfgShow::OnFilePrint(wxCommandEvent &){ wxPrintDialogData data(m_printData); wxPrinter printer(&data); NfgPrintout printout(m_nfg, m_table->GetRowPlayer(), m_table->GetColPlayer(), (char *) m_nfg.GetTitle()); if (!printer.Print(this, &printout, true)) { if (wxPrinter::GetLastError() == wxPRINTER_ERROR) { wxMessageBox("There was an error in printing", "Error", wxOK); } // Otherwise, user hit "cancel"; just be quiet and return. return; } else { m_printData = printer.GetPrintDialogData().GetPrintData(); }}void NfgShow::OnFileExit(wxCommandEvent &){ while (wxGetApp().GetTopWindow()) { delete wxGetApp().GetTopWindow(); }}void NfgShow::OnFileMRUFile(wxCommandEvent &p_event){ wxGetApp().OnFileMRUFile(p_event);}//----------------------------------------------------------------------// NfgShow: Menu handlers - Edit menu//----------------------------------------------------------------------void NfgShow::OnEditStrategies(wxCommandEvent &){ dialogStrategies dialog(this, m_nfg); if (dialog.ShowModal() == wxID_OK) { for (int pl = 1; pl <= m_nfg.NumPlayers(); pl++) { NFPlayer *player = m_nfg.Players()[pl]; for (int st = 1; st <= player->NumStrats(); st++) { player->Strategies()[st]->SetName(dialog.GetStrategyName(pl, st)); } } m_table->RefreshTable(); }}void NfgShow::OnEditContingency(wxCommandEvent &){ dialogEditContingency dialog(this, m_nfg, GetContingency()); if (dialog.ShowModal() == wxID_OK) { if (dialog.GetOutcome() == 0) { m_nfg.SetOutcome(GetContingency(), 0); } else { m_nfg.SetOutcome(GetContingency(), m_nfg.Outcomes()[dialog.GetOutcome()]); } m_table->RefreshTable(); }}void NfgShow::OnEditGame(wxCommandEvent &){ dialogNfgProperties dialog(this, m_nfg, m_filename); if (dialog.ShowModal() == wxID_OK) { m_nfg.SetTitle(dialog.GetGameTitle().c_str()); SetFilename(Filename()); m_nfg.SetComment(dialog.GetComment().c_str()); for (int pl = 1; pl <= dialog.NumPlayers(); pl++) { m_nfg.Players()[pl]->SetName(dialog.GetPlayerName(pl).c_str()); } m_navigateWindow->UpdateLabels(); m_outcomeWindow->UpdateValues(); m_supportWindow->UpdateValues(); }}//----------------------------------------------------------------------// NfgShow: Menu handlers - View menu//----------------------------------------------------------------------void NfgShow::OnViewProfiles(wxCommandEvent &){ if (m_solutionSashWindow->IsShown()) { m_profileTable->Show(false); m_solutionSashWindow->Show(false); GetMenuBar()->Check(NFG_VIEW_PROFILES, false); } else { m_profileTable->Show(true); m_solutionSashWindow->Show(true); GetMenuBar()->Check(NFG_VIEW_PROFILES, true); } AdjustSizes();}void NfgShow::OnViewNavigation(wxCommandEvent &){ if (m_infoSashWindow->IsShown() && m_infoNotebook->GetSelection() != 0) { m_infoNotebook->SetSelection(0); m_navigateWindow->Show(true); GetMenuBar()->Check(NFG_VIEW_NAVIGATION, true); GetMenuBar()->Check(NFG_VIEW_OUTCOMES, false); GetMenuBar()->Check(NFG_VIEW_SUPPORTS, false); } else if (m_infoSashWindow->IsShown()) { m_infoSashWindow->Show(false); GetMenuBar()->Check(NFG_VIEW_NAVIGATION, false); } else { m_infoSashWindow->Show(true); m_infoNotebook->SetSelection(0); GetMenuBar()->Check(NFG_VIEW_NAVIGATION, true); } AdjustSizes();}void NfgShow::OnViewOutcomes(wxCommandEvent &){ if (m_infoSashWindow->IsShown() && m_infoNotebook->GetSelection() != 1) { m_infoNotebook->SetSelection(1); m_navigateWindow->Show(true); GetMenuBar()->Check(NFG_VIEW_OUTCOMES, true); GetMenuBar()->Check(NFG_VIEW_NAVIGATION, false); GetMenuBar()->Check(NFG_VIEW_SUPPORTS, false); } else if (m_infoSashWindow->IsShown()) { m_infoSashWindow->Show(false); GetMenuBar()->Check(NFG_VIEW_OUTCOMES, false); } else { m_infoSashWindow->Show(true); m_infoNotebook->SetSelection(1); GetMenuBar()->Check(NFG_VIEW_OUTCOMES, true); } AdjustSizes();}void NfgShow::OnViewSupports(wxCommandEvent &){ if (m_infoSashWindow->IsShown() && m_infoNotebook->GetSelection() != 2) { m_infoNotebook->SetSelection(2); m_navigateWindow->Show(true); GetMenuBar()->Check(NFG_VIEW_OUTCOMES, false); GetMenuBar()->Check(NFG_VIEW_NAVIGATION, false); GetMenuBar()->Check(NFG_VIEW_SUPPORTS, true); } else if (m_infoSashWindow->IsShown()) { m_infoSashWindow->Show(false); GetMenuBar()->Check(NFG_VIEW_SUPPORTS, false); } else { m_infoSashWindow->Show(true); m_infoNotebook->SetSelection(2); GetMenuBar()->Check(NFG_VIEW_SUPPORTS, true); } AdjustSizes();}void NfgShow::OnViewDominance(wxCommandEvent &){ m_table->ToggleDominance();}void NfgShow::OnViewProbabilities(wxCommandEvent &){ m_table->ToggleProbs();}void NfgShow::OnViewValues(wxCommandEvent &){ m_table->ToggleValues();}void NfgShow::OnViewOutcomeLabels(wxCommandEvent &){ m_table->SetOutcomeValues(1 - m_table->OutcomeValues()); m_table->RefreshTable();}//----------------------------------------------------------------------// NfgShow: Menu handlers - Format menu//----------------------------------------------------------------------void NfgShow::OnFormatDisplayDecimals(wxCommandEvent &){ dialogSpinCtrl dialog(this, "Decimal places", 0, 25, m_table->GetSettings().GetDecimals()); if (dialog.ShowModal() == wxID_OK) { m_table->GetSettings().SetDecimals(dialog.GetValue()); m_table->GetSettings().SaveSettings(); m_table->RefreshTable(); }}void NfgShow::OnFormatFontData(wxCommandEvent &){ wxFontData data; wxFontDialog dialog(this, &data);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -