diff --git a/CMakeLists.txt b/CMakeLists.txt index 127e2ec9..f8244f08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,6 +212,7 @@ SET(SRC_GTK src/gtk/windowcallbacks.cpp src/gtk/filters.cpp src/gtk/gameboyconfig.cpp + src/gtk/gameboyadvanceconfig.cpp src/gtk/joypadconfig.cpp src/gtk/directoriesconfig.cpp src/gtk/displayconfig.cpp diff --git a/src/gtk/gameboyadvanceconfig.cpp b/src/gtk/gameboyadvanceconfig.cpp new file mode 100644 index 00000000..0ea96d1d --- /dev/null +++ b/src/gtk/gameboyadvanceconfig.cpp @@ -0,0 +1,123 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2008 VBA-M development team + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or(at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "gameboyadvanceconfig.h" + +#include "intl.h" + +namespace VBA +{ + +GameBoyAdvanceConfigDialog::GameBoyAdvanceConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder) : + Gtk::Dialog(_pstDialog), + m_poConfig(0) +{ + refBuilder->get_widget("SaveTypeComboBox", m_poSaveTypeComboBox); + refBuilder->get_widget("FlashSizeComboBox", m_poFlashSizeComboBox); + refBuilder->get_widget("BiosCheckButton", m_poBiosCheckButton); + refBuilder->get_widget("BiosFileChooserButton", m_poBiosFileChooserButton); + + m_poSaveTypeComboBox->signal_changed().connect(sigc::mem_fun(*this, &GameBoyAdvanceConfigDialog::vOnSaveTypeChanged)); + m_poFlashSizeComboBox->signal_changed().connect(sigc::mem_fun(*this, &GameBoyAdvanceConfigDialog::vOnFlashSizeChanged)); + m_poBiosCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &GameBoyAdvanceConfigDialog::vOnUseBiosChanged)); + m_poBiosFileChooserButton->signal_selection_changed().connect(sigc::mem_fun(*this, &GameBoyAdvanceConfigDialog::vOnBiosSelectionChanged)); +} + +void GameBoyAdvanceConfigDialog::vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow) +{ + m_poConfig = _poConfig; + m_poWindow = _poWindow; + + VBA::Window::ESaveType eDefaultSaveType = (VBA::Window::ESaveType)m_poConfig->oGetKey("save_type"); + m_poSaveTypeComboBox->set_active(eDefaultSaveType); + + int iDefaultFlashSize = m_poConfig->oGetKey("flash_size"); + if (iDefaultFlashSize == 128) + { + m_poFlashSizeComboBox->set_active(1); + } + else + { + m_poFlashSizeComboBox->set_active(0); + } + + bool bUseBios = m_poConfig->oGetKey("use_bios_file"); + m_poBiosCheckButton->set_active(bUseBios); + m_poBiosFileChooserButton->set_sensitive(bUseBios); + + std::string sBios = m_poConfig->oGetKey("bios_file"); + m_poBiosFileChooserButton->set_filename(sBios); + + 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 < G_N_ELEMENTS(acsPattern); i++) + { + oBiosFilter.add_pattern(acsPattern[i]); + } + + m_poBiosFileChooserButton->add_filter(oAllFilter); + m_poBiosFileChooserButton->add_filter(oBiosFilter); + m_poBiosFileChooserButton->set_filter(oBiosFilter); +} + +void GameBoyAdvanceConfigDialog::vOnSaveTypeChanged() +{ + int iSaveType = m_poSaveTypeComboBox->get_active_row_number(); + m_poConfig->vSetKey("save_type", iSaveType); + m_poWindow->vApplyConfigGBASaveType(); +} + +void GameBoyAdvanceConfigDialog::vOnFlashSizeChanged() +{ + int iFlashSize = m_poFlashSizeComboBox->get_active_row_number(); + if (iFlashSize == 0) + { + m_poConfig->vSetKey("flash_size", 64); + } + else + { + m_poConfig->vSetKey("flash_size", 128); + } + + m_poWindow->vApplyConfigGBAFlashSize(); +} + +void GameBoyAdvanceConfigDialog::vOnUseBiosChanged() +{ + bool bUseBios = m_poBiosCheckButton->get_active(); + m_poConfig->vSetKey("use_bios_file", bUseBios); + m_poBiosFileChooserButton->set_sensitive(bUseBios); +} + +void GameBoyAdvanceConfigDialog::vOnBiosSelectionChanged() +{ + std::string sBios = m_poBiosFileChooserButton->get_filename(); + m_poConfig->vSetKey("bios_file", sBios); +} + +} // namespace VBA diff --git a/src/gtk/gameboyadvanceconfig.h b/src/gtk/gameboyadvanceconfig.h new file mode 100644 index 00000000..70910a66 --- /dev/null +++ b/src/gtk/gameboyadvanceconfig.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2008 VBA-M development team + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or(at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __VBA_GAMEBOYADVANCECONFIG_H__ +#define __VBA_GAMEBOYADVANCECONFIG_H__ + +#include + +#include "configfile.h" +#include "window.h" + +namespace VBA +{ + +class GameBoyAdvanceConfigDialog : public Gtk::Dialog +{ +public: + GameBoyAdvanceConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder); + + void vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow); + +private: + void vOnSaveTypeChanged(); + void vOnFlashSizeChanged(); + void vOnUseBiosChanged(); + void vOnBiosSelectionChanged(); + + VBA::Window * m_poWindow; + + Config::Section * m_poConfig; + Gtk::ComboBox * m_poSaveTypeComboBox; + Gtk::ComboBox * m_poFlashSizeComboBox; + Gtk::CheckButton * m_poBiosCheckButton; + Gtk::FileChooserButton * m_poBiosFileChooserButton; +}; + +} // namespace VBA + + +#endif // __VBA_GAMEBOYADVANCECONFIG_H__ diff --git a/src/gtk/ui/gameboyadvance.ui b/src/gtk/ui/gameboyadvance.ui new file mode 100644 index 00000000..05496327 --- /dev/null +++ b/src/gtk/ui/gameboyadvance.ui @@ -0,0 +1,229 @@ + + + + + + + + + + 64K + + + 128K + + + + + + + + + + Automatic + + + EEPROM + + + SRAM + + + Flash + + + EEPROM + Sensor + + + None + + + + + 5 + Game Boy Advance settings + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True + + + True + 0 + GTK_SHADOW_NONE + + + True + 12 + + + True + 2 + 2 + + + True + model1 + + + + 0 + + + + + 1 + 2 + 1 + 2 + + + + + True + model2 + + + + 0 + + + + + 1 + 2 + + + + + True + Flash size : + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + Save type : + + + GTK_FILL + GTK_FILL + + + + + + + + + True + <b>Cartridge</b> + True + + + + + 1 + + + + + True + 0 + GTK_SHADOW_NONE + + + True + 12 + + + True + + + True + True + Use a bios file + True + + + + + True + + + True + Bios file : + + + False + + + + + True + + + 1 + + + + + 1 + + + + + + + + + True + <b>Bios</b> + True + + + + + 2 + + + + + True + GTK_BUTTONBOX_END + + + + + + True + True + True + gtk-close + True + + + 1 + + + + + False + GTK_PACK_END + + + + + + button1 + + + diff --git a/src/gtk/ui/vbam.glade b/src/gtk/ui/vbam.glade index c13b38a1..cbfee17e 100644 --- a/src/gtk/ui/vbam.glade +++ b/src/gtk/ui/vbam.glade @@ -501,105 +501,6 @@ - - - True - Save type - True - - - - - True - _Automatic - True - True - - - - - True - EEPROM - True - SaveTypeAutomatic - - - - - True - SRAM - True - SaveTypeAutomatic - - - - - True - Flash - True - SaveTypeAutomatic - - - - - True - EEPROM+Sensor - True - SaveTypeAutomatic - - - - - True - None - True - SaveTypeAutomatic - - - - - True - - - - - True - Flash 64K - True - True - - - - - True - Flash 128K - True - SaveTypeFlash64K - - - - - - - - - True - - - - - True - _Select BIOS file... - True - - - - - True - _Use BIOS file - True - - @@ -611,6 +512,13 @@ True + + + True + Game Boy _Advance ... + True + + True @@ -628,7 +536,7 @@ True - _Directories ... + D_irectories ... True diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index fd60a2cf..a99fb3d6 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -147,6 +147,8 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : vApplyConfigGBSystem(); vApplyConfigGBBorder(); vApplyConfigGBPrinter(); + vApplyConfigGBASaveType(); + vApplyConfigGBAFlashSize(); Gtk::MenuItem * poMI; Gtk::CheckMenuItem * poCMI; @@ -296,19 +298,6 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : sigc::mem_fun(*this, &Window::vOnPauseWhenInactiveToggled), poCMI)); - m_poUseBiosItem = dynamic_cast(_poXml->get_widget("EmulatorUseBios")); - m_poUseBiosItem->set_active(m_poCoreConfig->oGetKey("use_bios_file")); - if (m_poCoreConfig->sGetKey("bios_file") == "") - { - m_poUseBiosItem->set_sensitive(false); - } - m_poUseBiosItem->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnUseBiosToggled), - m_poUseBiosItem)); - - poMI = dynamic_cast(_poXml->get_widget("EmulatorSelectBios")); - poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnSelectBios)); - // Show speed menu // struct @@ -336,66 +325,14 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : poCMI, astShowSpeed[i].m_eShowSpeed)); } - // Save type menu - // - struct - { - const char * m_csName; - const ESaveType m_eSaveType; - } - astSaveType[] = - { - { "SaveTypeAutomatic", SaveAuto }, - { "SaveTypeEeprom", SaveEEPROM }, - { "SaveTypeSram", SaveSRAM }, - { "SaveTypeFlash", SaveFlash }, - { "SaveTypeEepromSensor", SaveEEPROMSensor }, - { "SaveTypeNone", SaveNone } - }; - ESaveType eDefaultSaveType = (ESaveType)m_poCoreConfig->oGetKey("save_type"); - for (guint i = 0; i < G_N_ELEMENTS(astSaveType); i++) - { - poCMI = dynamic_cast(_poXml->get_widget(astSaveType[i].m_csName)); - if (astSaveType[i].m_eSaveType == eDefaultSaveType) - { - poCMI->set_active(); - vOnSaveTypeToggled(poCMI, eDefaultSaveType); - } - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnSaveTypeToggled), - poCMI, astSaveType[i].m_eSaveType)); - } - - // Flash size menu - // - struct - { - const char * m_csName; - const int m_iFlashSize; - } - astFlashSize[] = - { - { "SaveTypeFlash64K", 64 }, - { "SaveTypeFlash128K", 128 } - }; - int iDefaultFlashSize = m_poCoreConfig->oGetKey("flash_size"); - for (guint i = 0; i < G_N_ELEMENTS(astFlashSize); i++) - { - poCMI = dynamic_cast(_poXml->get_widget(astFlashSize[i].m_csName)); - if (astFlashSize[i].m_iFlashSize == iDefaultFlashSize) - { - poCMI->set_active(); - vOnFlashSizeToggled(poCMI, iDefaultFlashSize); - } - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnFlashSizeToggled), - poCMI, astFlashSize[i].m_iFlashSize)); - } - // Game Boy menu poMI = dynamic_cast(_poXml->get_widget("GameBoyConfigure")); poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnGameBoyConfigure)); + // Game Boy Advance menu + poMI = dynamic_cast(_poXml->get_widget("GameBoyAdvanceConfigure")); + poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnGameBoyAdvanceConfigure)); + // Display menu poMI = dynamic_cast(_poXml->get_widget("DisplayConfigure")); poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnDisplayConfigure)); @@ -934,6 +871,24 @@ void Window::vApplyConfigGBPrinter() } } +void Window::vApplyConfigGBASaveType() +{ + int iSaveType = m_poCoreConfig->oGetKey("save_type"); + cpuSaveType = iSaveType; +} + +void Window::vApplyConfigGBAFlashSize() +{ + int iFlashSize = m_poCoreConfig->oGetKey("flash_size"); + if (iFlashSize == 64) + { + flashSetSize(0x10000); + } + else + { + flashSetSize(0x20000); + } +} void Window::vHistoryAdd(const std::string & _rsFile) { diff --git a/src/gtk/window.h b/src/gtk/window.h index 7e6fd05a..528d6d9e 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -71,6 +71,16 @@ public: EmulatorSGB2 }; + enum ESaveType + { + SaveAuto, + SaveEEPROM, + SaveSRAM, + SaveFlash, + SaveEEPROMSensor, + SaveNone + }; + // GB/GBA screen sizes const int m_iGBScreenWidth; const int m_iGBScreenHeight; @@ -95,6 +105,8 @@ public: void vApplyConfigGBSystem(); void vApplyConfigGBBorder(); void vApplyConfigGBPrinter(); + void vApplyConfigGBASaveType(); + void vApplyConfigGBAFlashSize(); void vUpdateScreen(); inline ECartridge eGetCartridge() const { return m_eCartridge; } @@ -110,16 +122,6 @@ protected: ShowDetailed }; - enum ESaveType - { - SaveAuto, - SaveEEPROM, - SaveSRAM, - SaveFlash, - SaveEEPROMSensor, - SaveNone - }; - enum ESoundStatus { SoundOff, @@ -151,15 +153,12 @@ protected: virtual void vOnVideoFullscreen(); virtual void vOnDirectories(); virtual void vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI); - virtual void vOnSelectBios(); - virtual void vOnUseBiosToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnShowSpeedToggled(Gtk::CheckMenuItem * _poCMI, int _iShowSpeed); - virtual void vOnSaveTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iSaveType); - virtual void vOnFlashSizeToggled(Gtk::CheckMenuItem * _poCMI, int _iFlashSize); virtual void vOnJoypadConfigure(); virtual void vOnDisplayConfigure(); virtual void vOnSoundConfigure(); virtual void vOnGameBoyConfigure(); + virtual void vOnGameBoyAdvanceConfigure(); virtual void vOnHelpAbout(); virtual bool bOnEmuIdle(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index ee320034..4ed3fb3e 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -39,6 +39,7 @@ #include "displayconfig.h" #include "soundconfig.h" #include "gameboyconfig.h" +#include "gameboyadvanceconfig.h" namespace VBA { @@ -378,55 +379,6 @@ void Window::vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI) m_poDisplayConfig->vSetKey("pause_when_inactive", _poCMI->get_active()); } -void Window::vOnSelectBios() -{ - 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 < G_N_ELEMENTS(acsPattern); i++) - { - oBiosFilter.add_pattern(acsPattern[i]); - } - - oDialog.add_filter(oAllFilter); - oDialog.add_filter(oBiosFilter); - - oDialog.set_filter(oBiosFilter); - - 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; - } - } -} - -void Window::vOnUseBiosToggled(Gtk::CheckMenuItem * _poCMI) -{ - m_poCoreConfig->vSetKey("use_bios_file", _poCMI->get_active()); -} - void Window::vOnShowSpeedToggled(Gtk::CheckMenuItem * _poCMI, int _iShowSpeed) { if (! _poCMI->get_active()) @@ -442,35 +394,6 @@ void Window::vOnShowSpeedToggled(Gtk::CheckMenuItem * _poCMI, int _iShowSpeed) m_poDisplayConfig->vSetKey("show_speed", _iShowSpeed); } -void Window::vOnSaveTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iSaveType) -{ - if (! _poCMI->get_active()) - { - return; - } - - cpuSaveType = _iSaveType; - m_poCoreConfig->vSetKey("save_type", _iSaveType); -} - -void Window::vOnFlashSizeToggled(Gtk::CheckMenuItem * _poCMI, int _iFlashSize) -{ - if (! _poCMI->get_active()) - { - return; - } - - if (_iFlashSize == 64) - { - flashSetSize(0x10000); - } - else - { - flashSetSize(0x20000); - } - m_poCoreConfig->vSetKey("flash_size", _iFlashSize); -} - void Window::vOnJoypadConfigure() { JoypadConfigDialog oDialog(m_poInputConfig); @@ -517,6 +440,20 @@ void Window::vOnGameBoyConfigure() poDialog->hide(); } +void Window::vOnGameBoyAdvanceConfigure() +{ + std::string sUiFile = sGetUiFilePath("gameboyadvance.ui"); + Glib::RefPtr poBuilder = Gtk::Builder::create_from_file(sUiFile); + + GameBoyAdvanceConfigDialog * poDialog = 0; + poBuilder->get_widget_derived("GameBoyAdvanceConfigDialog", poDialog); + poDialog->vSetConfig(m_poCoreConfig, this); + poDialog->set_transient_for(*this); + poDialog->run(); + poDialog->hide(); +} + + void Window::vOnHelpAbout() { Gtk::AboutDialog oAboutDialog;