From: S?bastien G. <kx...@us...> - 2004-05-04 20:33:56
|
Update of /cvsroot/vba/VisualBoyAdvance/src/gtk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14729 Modified Files: tools.cpp tools.h window.cpp window.h windowcallbacks.cpp Log Message: Added load/save dialogs. Index: tools.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/tools.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tools.h 29 Mar 2004 22:08:40 -0000 1.1 --- tools.h 4 May 2004 20:33:16 -0000 1.2 *************** *** 22,31 **** #include <string> namespace VBA { ! std::string sCutSuffix(const std::string & _sString, ! const std::string & _sSep = std::string(".")); } --- 22,39 ---- #include <string> + #include <glibmm/ustring.h> namespace VBA { ! std::string sCutSuffix(const std::string & _rsString, ! const std::string & _rsSep = "."); ! ! Glib::ustring sCutSuffix(const Glib::ustring & _rsString, ! const Glib::ustring & _rsSep = "."); ! ! bool bHasSuffix(const Glib::ustring & _rsString, ! const Glib::ustring & _rsSuffix, ! bool _bCaseSensitive = true); } Index: tools.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/tools.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tools.cpp 29 Mar 2004 22:08:40 -0000 1.1 --- tools.cpp 4 May 2004 20:33:16 -0000 1.2 *************** *** 23,30 **** { ! std::string sCutSuffix(const std::string & _sString, ! const std::string & _sSep) { ! return _sString.substr(0, _sString.find_last_of(_sSep)); } --- 23,65 ---- { ! std::string sCutSuffix(const std::string & _rsString, ! const std::string & _rsSep) { ! return _rsString.substr(0, _rsString.find_last_of(_rsSep)); ! } ! ! Glib::ustring sCutSuffix(const Glib::ustring & _rsString, ! const Glib::ustring & _rsSep) ! { ! return _rsString.substr(0, _rsString.find_last_of(_rsSep)); ! } ! ! bool bHasSuffix(const Glib::ustring & _rsString, ! const Glib::ustring & _rsSuffix, ! bool _bCaseSensitive) ! { ! if (_rsSuffix.size() > _rsString.size()) ! { ! return false; ! } ! ! Glib::ustring sEnd = _rsString.substr(_rsString.size() - _rsSuffix.size()); ! ! if (_bCaseSensitive) ! { ! if (_rsSuffix == sEnd) ! { ! return true; ! } ! } ! else ! { ! if (_rsSuffix.lowercase() == sEnd.lowercase()) ! { ! return true; ! } ! } ! ! return false; } Index: window.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/window.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** window.h 3 May 2004 17:00:27 -0000 1.13 --- window.h 4 May 2004 20:33:16 -0000 1.14 *************** *** 128,136 **** virtual void vOnFileOpen(); virtual void vOnLoadGameMostRecent(); virtual void vOnLoadGameAutoToggled(Gtk::CheckMenuItem * _poCMI); ! virtual void vOnLoadGame(int _iSlot); virtual void vOnSaveGameOldest(); ! virtual void vOnSaveGame(int _iSlot); virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnFileReset(); --- 128,138 ---- virtual void vOnFileOpen(); + virtual void vOnLoadGame(); + virtual void vOnSaveGame(); virtual void vOnLoadGameMostRecent(); virtual void vOnLoadGameAutoToggled(Gtk::CheckMenuItem * _poCMI); ! virtual void vOnLoadGameSlot(int _iSlot); virtual void vOnSaveGameOldest(); ! virtual void vOnSaveGameSlot(int _iSlot); virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnFileReset(); *************** *** 216,222 **** --- 218,229 ---- Config::Section * m_poSoundConfig; + #ifdef GTKMM20 Gtk::FileSelection * m_poFileOpenDialog; + #else // ! GTKMM20 + Gtk::FileChooserDialog * m_poFileOpenDialog; + #endif // ! GTKMM20 ScreenArea * m_poScreenArea; Gtk::Menu * m_poRecentMenu; + Gtk::MenuItem * m_poRecentResetItem; Gtk::CheckMenuItem * m_poFilePauseItem; Gtk::CheckMenuItem * m_poUseBiosItem; Index: window.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/window.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** window.cpp 3 May 2004 17:00:27 -0000 1.13 --- window.cpp 4 May 2004 20:33:16 -0000 1.14 *************** *** 131,134 **** --- 131,142 ---- poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileOpen)); + poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileLoad")); + poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnLoadGame)); + m_listSensitiveWhenPlaying.push_back(poMI); + + poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("FileSave")); + poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnSaveGame)); + m_listSensitiveWhenPlaying.push_back(poMI); + for (int i = 0; i < 10; i++) { *************** *** 140,147 **** m_apoLoadGameItem[i]->signal_activate().connect(SigC::bind<int>( ! SigC::slot(*this, &Window::vOnLoadGame), i + 1)); m_apoSaveGameItem[i]->signal_activate().connect(SigC::bind<int>( ! SigC::slot(*this, &Window::vOnSaveGame), i + 1)); } --- 148,155 ---- m_apoLoadGameItem[i]->signal_activate().connect(SigC::bind<int>( ! SigC::slot(*this, &Window::vOnLoadGameSlot), i + 1)); m_apoSaveGameItem[i]->signal_activate().connect(SigC::bind<int>( ! SigC::slot(*this, &Window::vOnSaveGameSlot), i + 1)); } *************** *** 187,192 **** vUpdateHistoryMenu(); ! poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("RecentReset")); ! poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnRecentReset)); poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("RecentFreeze")); --- 195,200 ---- vUpdateHistoryMenu(); ! m_poRecentResetItem = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("RecentReset")); ! m_poRecentResetItem->signal_activate().connect(SigC::slot(*this, &Window::vOnRecentReset)); poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("RecentFreeze")); Index: windowcallbacks.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/windowcallbacks.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** windowcallbacks.cpp 3 May 2004 17:00:27 -0000 1.2 --- windowcallbacks.cpp 4 May 2004 20:33:16 -0000 1.3 *************** *** 54,65 **** if (m_poFileOpenDialog == NULL) { ! m_poFileOpenDialog = new Gtk::FileSelection(_("Open")); ! m_poFileOpenDialog->set_transient_for(*this); ! std::string sDir = m_poDirConfig->sGetKey("gba_roms"); ! if (sDir != "") { ! m_poFileOpenDialog->set_filename(sDir + "/"); } } --- 54,130 ---- if (m_poFileOpenDialog == NULL) { ! std::string sGBDir = m_poDirConfig->sGetKey("gb_roms"); ! std::string sGBADir = m_poDirConfig->sGetKey("gba_roms"); ! #ifdef GTKMM20 ! ! Gtk::FileSelection * poDialog = new Gtk::FileSelection(_("Open")); ! poDialog->set_transient_for(*this); ! ! if (sGBADir != "") { ! poDialog->set_filename(sGBADir + "/"); ! } ! else if (sGBDir != "") ! { ! poDialog->set_filename(sGBDir + "/"); } + + #else // ! GTKMM20 + + Gtk::FileChooserDialog * poDialog = new Gtk::FileChooserDialog(*this, _("Open")); + poDialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + poDialog->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + + if (sGBDir != "") + { + poDialog->add_shortcut_folder(sGBDir); + poDialog->set_current_folder(sGBDir); + } + + if (sGBADir != "" && sGBADir != sGBDir) + { + poDialog->add_shortcut_folder(sGBADir); + poDialog->set_current_folder(sGBADir); + } + + const char * acsPattern[] = + { + // GBA + "*.[bB][iI][nN]", "*.[aA][gG][bB]", "*.[gG][bB][aA]", + // GB + "*.[gG][bB]", "*.[sS][gG][bB]", "*.[cC][gG][bB]", "*.[gG][bB][cC]", + // Both + "*.[mM][bB]", "*.[eE][lL][fF]", "*.[zZ][iI][pP]", "*.[zZ]", "*.[gG][zZ]" + }; + + Gtk::FileFilter oAllGBAFilter; + oAllGBAFilter.set_name(_("All Gameboy Advance files")); + for (guint i = 0; i < sizeof(acsPattern) / sizeof(acsPattern[0]); i++) + { + oAllGBAFilter.add_pattern(acsPattern[i]); + } + + Gtk::FileFilter oGBAFilter; + oGBAFilter.set_name(_("Gameboy Advance files")); + for (int i = 0; i < 3; i++) + { + oGBAFilter.add_pattern(acsPattern[i]); + } + + Gtk::FileFilter oGBFilter; + oGBFilter.set_name(_("Gameboy files")); + for (int i = 3; i < 7; i++) + { + oGBFilter.add_pattern(acsPattern[i]); + } + + poDialog->add_filter(oAllGBAFilter); + poDialog->add_filter(oGBAFilter); + poDialog->add_filter(oGBFilter); + + #endif // ! GTKMM20 + + m_poFileOpenDialog = poDialog; } *************** *** 74,77 **** --- 139,271 ---- } + void Window::vOnLoadGame() + { + std::string sSaveDir = m_poDirConfig->sGetKey("saves"); + + #ifdef GTKMM20 + + Gtk::FileSelection oDialog(_("Load game")); + oDialog.set_transient_for(*this); + + if (sSaveDir == "") + { + oDialog.set_filename(Glib::path_get_dirname(m_sRomFile) + "/"); + } + else + { + oDialog.set_filename(sSaveDir + "/"); + } + + #else // ! GTKMM20 + + Gtk::FileChooserDialog oDialog(*this, _("Load game")); + oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + oDialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + + if (sSaveDir == "") + { + oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile)); + } + else + { + oDialog.set_current_folder(sSaveDir); + oDialog.add_shortcut_folder(sSaveDir); + } + + Gtk::FileFilter oSaveFilter; + oSaveFilter.set_name(_("VisualBoyAdvance save game")); + oSaveFilter.add_pattern("*.[sS][gG][mM]"); + + oDialog.add_filter(oSaveFilter); + + #endif // ! GTKMM20 + + while (oDialog.run() == Gtk::RESPONSE_OK) + { + if (m_stEmulator.emuReadState(oDialog.get_filename().c_str())) + { + break; + } + } + } + + void Window::vOnSaveGame() + { + Glib::ustring sSaveDir = m_poDirConfig->sGetKey("saves"); + + #ifdef GTKMM20 + + Gtk::FileSelection oDialog(_("Save game")); + oDialog.set_transient_for(*this); + + Glib::ustring sDefaultFile; + if (sSaveDir == "") + { + sDefaultFile = sCutSuffix(m_sRomFile) + ".sgm"; + } + else + { + sDefaultFile = sSaveDir + "/" + + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sgm"; + } + oDialog.set_filename(sDefaultFile); + + #else // ! GTKMM20 + + Gtk::FileChooserDialog oDialog(*this, _("Save game"), + Gtk::FILE_CHOOSER_ACTION_SAVE); + oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + oDialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + + if (sSaveDir == "") + { + oDialog.set_current_folder(Glib::path_get_dirname(m_sRomFile)); + } + else + { + oDialog.set_current_folder(sSaveDir); + oDialog.add_shortcut_folder(sSaveDir); + } + oDialog.set_current_name(sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".sgm"); + + Gtk::FileFilter oSaveFilter; + oSaveFilter.set_name(_("VisualBoyAdvance save game")); + oSaveFilter.add_pattern("*.[sS][gG][mM]"); + + oDialog.add_filter(oSaveFilter); + + #endif // ! GTKMM20 + + while (oDialog.run() == Gtk::RESPONSE_OK) + { + Glib::ustring sFile = oDialog.get_filename(); + if (! bHasSuffix(sFile, ".sgm", false)) + { + sFile += ".sgm"; + } + + if (Glib::file_test(oDialog.get_filename(), Glib::FILE_TEST_EXISTS)) + { + Gtk::MessageDialog oConfirm(*this, + _("File already exists. Overwrite it?"), + #ifndef GTKMM20 + false, + #endif // ! GTKMM20 + Gtk::MESSAGE_QUESTION, + Gtk::BUTTONS_YES_NO, + true); + if (oConfirm.run() != Gtk::RESPONSE_YES) + { + continue; + } + } + + if (m_stEmulator.emuWriteState(sFile.c_str())) + { + break; + } + } + } + void Window::vOnLoadGameMostRecent() { *************** *** 91,95 **** if (iMostRecent >= 0) { ! vOnLoadGame(iMostRecent + 1); } } --- 285,289 ---- if (iMostRecent >= 0) { ! vOnLoadGameSlot(iMostRecent + 1); } } *************** *** 100,104 **** } ! void Window::vOnLoadGame(int _iSlot) { int i = _iSlot - 1; --- 294,298 ---- } ! void Window::vOnLoadGameSlot(int _iSlot) { int i = _iSlot - 1; *************** *** 127,139 **** if (iOldest >= 0) { ! vOnSaveGame(iOldest + 1); } else { ! vOnSaveGame(1); } } ! void Window::vOnSaveGame(int _iSlot) { int i = _iSlot - 1; --- 321,333 ---- if (iOldest >= 0) { ! vOnSaveGameSlot(iOldest + 1); } else { ! vOnSaveGameSlot(1); } } ! void Window::vOnSaveGameSlot(int _iSlot) { int i = _iSlot - 1; *************** *** 177,180 **** --- 371,375 ---- void Window::vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI) { + m_poRecentResetItem->set_sensitive(! _poCMI->get_active()); m_poHistoryConfig->vSetKey("freeze", _poCMI->get_active()); } *************** *** 393,407 **** void Window::vOnDirectorySelect(Gtk::Entry * _poEntry) { ! Gtk::FileSelection * poDialog = new Gtk::FileSelection(_("Select directory")); ! poDialog->set_transient_for(*this); if (_poEntry->get_text() != "") { ! poDialog->set_filename(_poEntry->get_text() + "/"); } ! if (poDialog->run() == Gtk::RESPONSE_OK) { ! std::string sFile = poDialog->get_filename(); if (! Glib::file_test(sFile, Glib::FILE_TEST_IS_DIR)) { --- 588,604 ---- void Window::vOnDirectorySelect(Gtk::Entry * _poEntry) { ! #ifdef GTKMM20 ! ! Gtk::FileSelection oDialog(_("Select directory")); ! oDialog.set_transient_for(*this); if (_poEntry->get_text() != "") { ! oDialog.set_filename(_poEntry->get_text() + "/"); } ! if (oDialog.run() == Gtk::RESPONSE_OK) { ! std::string sFile = oDialog.get_filename(); if (! Glib::file_test(sFile, Glib::FILE_TEST_IS_DIR)) { *************** *** 411,415 **** } ! delete poDialog; } --- 608,630 ---- } ! #else // ! GTKMM20 ! ! Gtk::FileChooserDialog oDialog(*this, _("Select directory"), ! Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); ! oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ! oDialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); ! ! if (_poEntry->get_text() != "") ! { ! oDialog.add_shortcut_folder(_poEntry->get_text()); ! oDialog.set_current_folder(_poEntry->get_text()); ! } ! ! if (oDialog.run() == Gtk::RESPONSE_OK) ! { ! _poEntry->set_text(oDialog.get_filename()); ! } ! ! #endif // ! GTKMM20 } *************** *** 421,443 **** void Window::vOnSelectBios() { ! Gtk::FileSelection * poDialog = new Gtk::FileSelection(_("Select BIOS file")); ! poDialog->set_transient_for(*this); if (m_poCoreConfig->sGetKey("bios_file") != "") { ! poDialog->set_filename(m_poCoreConfig->sGetKey("bios_file")); } ! while (poDialog->run() == Gtk::RESPONSE_OK) { ! if (Glib::file_test(poDialog->get_filename(), Glib::FILE_TEST_IS_REGULAR)) { ! m_poCoreConfig->vSetKey("bios_file", poDialog->get_filename()); m_poUseBiosItem->set_sensitive(); break; } } - - delete poDialog; } --- 636,693 ---- void Window::vOnSelectBios() { ! #ifdef GTKMM20 ! ! Gtk::FileSelection oDialog(_("Select BIOS file")); ! oDialog.set_transient_for(*this); if (m_poCoreConfig->sGetKey("bios_file") != "") { ! oDialog.set_filename(m_poCoreConfig->sGetKey("bios_file")); } ! #else // ! GTKMM20 ! ! Gtk::FileChooserDialog oDialog(*this, _("Select BIOS file")); ! oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ! oDialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); ! ! if (m_poCoreConfig->sGetKey("bios_file") != "") { ! oDialog.set_filename(m_poCoreConfig->sGetKey("bios_file")); ! } ! ! const char * acsPattern[] = ! { ! "*.[bB][iI][nN]", "*.[aA][gG][bB]", "*.[gG][bB][aA]", ! "*.[bB][iI][oO][sS]", "*.[zZ][iI][pP]", "*.[zZ]", "*.[gG][zZ]" ! }; ! ! Gtk::FileFilter oAllFilter; ! oAllFilter.set_name(_("All files")); ! oAllFilter.add_pattern("*"); ! ! Gtk::FileFilter oBiosFilter; ! oBiosFilter.set_name(_("Gameboy Advance BIOS")); ! for (guint i = 0; i < sizeof(acsPattern) / sizeof(acsPattern[0]); i++) ! { ! oBiosFilter.add_pattern(acsPattern[i]); ! } ! ! oDialog.add_filter(oAllFilter); ! oDialog.add_filter(oBiosFilter); ! ! oDialog.set_filter(oBiosFilter); ! ! #endif // ! GTKMM20 ! ! while (oDialog.run() == Gtk::RESPONSE_OK) ! { ! if (Glib::file_test(oDialog.get_filename(), Glib::FILE_TEST_IS_REGULAR)) { ! m_poCoreConfig->vSetKey("bios_file", oDialog.get_filename()); m_poUseBiosItem->set_sensitive(); break; } } } *************** *** 740,744 **** EKey eKey; ! if ((_pstEvent->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK)) || (eKey = m_oKeymap.eGetKey(_pstEvent->keyval)) == KeyNone) { --- 990,994 ---- EKey eKey; ! if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask()) || (eKey = m_oKeymap.eGetKey(_pstEvent->keyval)) == KeyNone) { *************** *** 746,749 **** --- 996,1002 ---- } + // TEST + printf("scan code: %hd\n", _pstEvent->hardware_keycode); + switch (eKey) { *************** *** 798,802 **** EKey eKey; ! if ((_pstEvent->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK)) || (eKey = m_oKeymap.eGetKey(_pstEvent->keyval)) == KeyNone) { --- 1051,1055 ---- EKey eKey; ! if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask()) || (eKey = m_oKeymap.eGetKey(_pstEvent->keyval)) == KeyNone) { |