diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cb806b0..4cfcf162 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,8 @@ ADD_DEFINITIONS (-DVERSION='"${VERSION}"' -DPKGDATADIR='"${PKGDATADIR}"' -DPACKA # Linking is disabled if SFML has not been found IF( NOT SFML_FOUND ) - ADD_DEFINITIONS (-DNO_LINK) - MESSAGE(STATUS "SFML was not found, link support is disabled") + ADD_DEFINITIONS (-DNO_LINK) + MESSAGE(STATUS "SFML was not found, link support is disabled") ENDIF( NOT SFML_FOUND ) # The debugger is enabled by default @@ -248,6 +248,7 @@ SET(SRC_GTK src/gtk/system.cpp src/gtk/windowcallbacks.cpp src/gtk/filters.cpp + src/gtk/generalconfig.cpp src/gtk/gameboyconfig.cpp src/gtk/gameboyadvanceconfig.cpp src/gtk/cheatlist.cpp diff --git a/src/gtk/generalconfig.cpp b/src/gtk/generalconfig.cpp new file mode 100644 index 00000000..f9b6b142 --- /dev/null +++ b/src/gtk/generalconfig.cpp @@ -0,0 +1,104 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2011 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 "generalconfig.h" + +#include +#include +#include + +#include "intl.h" + +namespace VBA +{ + +PreferencesDialog::PreferencesDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder) : + Gtk::Dialog(_pstDialog), + m_poConfig(0) +{ + refBuilder->get_widget("PauseWhenInactiveCheckButton", m_poPauseWhenInactiveCheckButton); + refBuilder->get_widget("FrameSkipAutomaticCheckButton", m_poFrameSkipAutomaticCheckButton); + refBuilder->get_widget("FrameSkipLevelSpinButton", m_poFrameSkipLevelSpinButton); + refBuilder->get_widget("SpeedIndicatorComboBox", m_poSpeedIndicatorComboBox); + + m_poPauseWhenInactiveCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &PreferencesDialog::vOnPauseWhenInactiveChanged)); + m_poFrameSkipAutomaticCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &PreferencesDialog::vOnFrameskipChanged)); + m_poFrameSkipLevelSpinButton->signal_changed().connect(sigc::mem_fun(*this, &PreferencesDialog::vOnFrameskipChanged)); + m_poSpeedIndicatorComboBox->signal_changed().connect(sigc::mem_fun(*this, &PreferencesDialog::vOnSpeedIndicatorChanged)); + +} + +void PreferencesDialog::vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow) +{ + m_poConfig = _poConfig; + m_poWindow = _poWindow; + + bool bPauseWhenInactive = m_poConfig->oGetKey("pause_when_inactive"); + m_poPauseWhenInactiveCheckButton->set_active(bPauseWhenInactive); + + std::string sFrameskip = m_poConfig->oGetKey("frameskip"); + int iFrameskip = 0; + bool bAutoFrameskip = false; + + if (sFrameskip == "auto") + bAutoFrameskip = true; + else + iFrameskip = m_poConfig->oGetKey("frameskip"); + + m_poFrameSkipAutomaticCheckButton->set_active(bAutoFrameskip); + m_poFrameSkipLevelSpinButton->set_sensitive(!bAutoFrameskip); + m_poFrameSkipLevelSpinButton->set_value(iFrameskip); + + int iShowSpeed = m_poConfig->oGetKey("show_speed"); + m_poSpeedIndicatorComboBox->set_active(iShowSpeed); +} + +void PreferencesDialog::vOnPauseWhenInactiveChanged() +{ + bool bPauseWhenInactive = m_poPauseWhenInactiveCheckButton->get_active(); + m_poConfig->vSetKey("pause_when_inactive", bPauseWhenInactive); +} + +void PreferencesDialog::vOnFrameskipChanged() +{ + bool bAutoFrameskip = m_poFrameSkipAutomaticCheckButton->get_active(); + + if (bAutoFrameskip) + { + m_poConfig->vSetKey("frameskip", "auto"); + } + else + { + int iFrameskip = m_poFrameSkipLevelSpinButton->get_value(); + m_poConfig->vSetKey("frameskip", iFrameskip); + } + + m_poFrameSkipLevelSpinButton->set_sensitive(!bAutoFrameskip); + + m_poWindow->vApplyConfigFrameskip(); +} + +void PreferencesDialog::vOnSpeedIndicatorChanged() +{ + int iShowSpeed = m_poSpeedIndicatorComboBox->get_active_row_number(); + m_poConfig->vSetKey("show_speed", iShowSpeed); + + m_poWindow->vApplyConfigShowSpeed(); +} + +} // namespace VBA diff --git a/src/gtk/generalconfig.h b/src/gtk/generalconfig.h new file mode 100644 index 00000000..d842a7f5 --- /dev/null +++ b/src/gtk/generalconfig.h @@ -0,0 +1,56 @@ +// -*- 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_GENERALCONFIG_H__ +#define __VBA_GENERALCONFIG_H__ + +#include + +#include "configfile.h" +#include "window.h" + +namespace VBA +{ + +class PreferencesDialog : public Gtk::Dialog +{ +public: + PreferencesDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder); + + void vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow); + +private: + void vOnPauseWhenInactiveChanged(); + void vOnFrameskipChanged(); + void vOnSpeedIndicatorChanged(); + + + VBA::Window * m_poWindow; + + Config::Section * m_poConfig; + Gtk::CheckButton * m_poPauseWhenInactiveCheckButton; + Gtk::CheckButton * m_poFrameSkipAutomaticCheckButton; + Gtk::SpinButton * m_poFrameSkipLevelSpinButton; + Gtk::ComboBox * m_poSpeedIndicatorComboBox; + +}; + +} // namespace VBA + + +#endif // __VBA_GENERALCONFIG_H__ diff --git a/src/gtk/ui/preferences.ui b/src/gtk/ui/preferences.ui new file mode 100644 index 00000000..cee90dab --- /dev/null +++ b/src/gtk/ui/preferences.ui @@ -0,0 +1,226 @@ + + + + + + 5 + Preferences + normal + False + + + True + 2 + + + True + 0 + none + + + True + 12 + + + Pause when inactive + True + True + False + True + + + + + + + True + <b>General</b> + True + + + + + False + 1 + + + + + True + 0 + none + + + True + 12 + + + True + 2 + + + Enable automatic frame skipping + True + True + False + True + + + 0 + + + + + True + + + True + 1 + Frameskip level : + + + False + 0 + + + + + True + False + FrameSkipAdjustment + True + + + 1 + + + + + 1 + + + + + + + + + True + <b>Frameskip</b> + True + + + + + False + 2 + + + + + True + 0 + none + + + True + 12 + + + True + + + True + Speed indicator : + + + False + 0 + + + + + True + SpeedIndicatorListStore + + + + 0 + + + + + 1 + + + + + + + + + True + <b>Appearance</b> + True + + + + + False + 3 + + + + + True + end + + + gtk-close + True + True + True + True + + + False + False + 0 + + + + + False + end + 0 + + + + + + button2 + + + + + + + + + + None + + + Percentage + + + Detailed + + + + + 9 + 1 + 1 + + diff --git a/src/gtk/ui/vbam.ui b/src/gtk/ui/vbam.ui index 0d1573c8..ca43302e 100644 --- a/src/gtk/ui/vbam.ui +++ b/src/gtk/ui/vbam.ui @@ -475,194 +475,12 @@ False - + True False False - _Frameskip + _Preferences ... True - - - False - - - True - False - False - _Automatic - True - True - - - - - True - False - False - _0 - True - FrameskipAutomatic - - - - - True - False - False - _1 - True - FrameskipAutomatic - - - - - True - False - False - _2 - True - FrameskipAutomatic - - - - - True - False - False - _3 - True - FrameskipAutomatic - - - - - True - False - False - _4 - True - FrameskipAutomatic - - - - - True - False - False - _5 - True - FrameskipAutomatic - - - - - True - False - False - _6 - True - FrameskipAutomatic - - - - - True - False - False - _7 - True - FrameskipAutomatic - - - - - True - False - False - _8 - True - FrameskipAutomatic - - - - - True - False - False - _9 - True - FrameskipAutomatic - - - - - - - - - True - False - False - _Emulator - True - - - False - - - True - False - False - Pause when inactive window - True - - - - - True - False - False - Show speed - True - - - False - - - True - False - False - None - True - True - - - - - True - False - False - Percentage - True - ShowSpeedNone - - - - - True - False - False - Detailed - True - ShowSpeedNone - - - - - - - - diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 74f3547a..a53e272c 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -68,8 +68,8 @@ const Window::SJoypadKey Window::m_astJoypad[] = { "capture", KEY_BUTTON_CAPTURE }, { "speed", KEY_BUTTON_SPEED }, { "capture", KEY_BUTTON_CAPTURE }, - { "autoA", KEY_BUTTON_AUTO_A }, - { "autoB", KEY_BUTTON_AUTO_B } + { "autoA", KEY_BUTTON_AUTO_A }, + { "autoB", KEY_BUTTON_AUTO_B } }; Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : @@ -149,6 +149,8 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml vApplyConfigGBASaveType(); vApplyConfigGBAFlashSize(); vApplyConfigGBARTC(); + vApplyConfigFrameskip(); + vApplyConfigShowSpeed(); Gtk::MenuItem * poMI; Gtk::CheckMenuItem * poCMI; @@ -253,87 +255,14 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml _poXml->get_widget("RecentMenu", m_poRecentMenu); m_poRecentMenu->set_submenu(static_cast(*m_poRecentChooserMenu)); - // Frameskip menu - // - struct - { - const char * m_csName; - const int m_iFrameskip; - } - astFrameskip[] = - { - { "FrameskipAutomatic", -1 }, - { "Frameskip0", 0 }, - { "Frameskip1", 1 }, - { "Frameskip2", 2 }, - { "Frameskip3", 3 }, - { "Frameskip4", 4 }, - { "Frameskip5", 5 }, - { "Frameskip6", 6 }, - { "Frameskip7", 7 }, - { "Frameskip8", 8 }, - { "Frameskip9", 9 } - }; - int iDefaultFrameskip; - if (m_poCoreConfig->sGetKey("frameskip") == "auto") - { - iDefaultFrameskip = -1; - } - else - { - iDefaultFrameskip = m_poCoreConfig->oGetKey("frameskip"); - } - for (guint i = 0; i < G_N_ELEMENTS(astFrameskip); i++) - { - _poXml->get_widget(astFrameskip[i].m_csName, poCMI); - if (astFrameskip[i].m_iFrameskip == iDefaultFrameskip) - { - poCMI->set_active(); - vOnFrameskipToggled(poCMI, iDefaultFrameskip); - } - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnFrameskipToggled), - poCMI, astFrameskip[i].m_iFrameskip)); - } - // Emulator menu // _poXml->get_widget("DirectoriesConfigure", poMI); poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnDirectories)); - _poXml->get_widget("EmulatorPauseWhenInactive", poCMI); - poCMI->set_active(m_poDisplayConfig->oGetKey("pause_when_inactive")); - vOnPauseWhenInactiveToggled(poCMI); - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnPauseWhenInactiveToggled), - poCMI)); - - // Show speed menu - // - struct - { - const char * m_csName; - const EShowSpeed m_eShowSpeed; - } - astShowSpeed[] = - { - { "ShowSpeedNone", ShowNone }, - { "ShowSpeedPercentage", ShowPercentage }, - { "ShowSpeedDetailed", ShowDetailed } - }; - EShowSpeed eDefaultShowSpeed = (EShowSpeed)m_poDisplayConfig->oGetKey("show_speed"); - for (guint i = 0; i < G_N_ELEMENTS(astShowSpeed); i++) - { - _poXml->get_widget(astShowSpeed[i].m_csName, poCMI); - if (astShowSpeed[i].m_eShowSpeed == eDefaultShowSpeed) - { - poCMI->set_active(); - vOnShowSpeedToggled(poCMI, eDefaultShowSpeed); - } - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnShowSpeedToggled), - poCMI, astShowSpeed[i].m_eShowSpeed)); - } + // Preferences + _poXml->get_widget("GeneralConfigure", poMI); + poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnGeneralConfigure)); // Game Boy menu _poXml->get_widget("GameBoyConfigure", poMI); @@ -592,13 +521,13 @@ void Window::vInitConfig() m_poCoreConfig->vSetKey("gb_use_bios_file", false ); m_poCoreConfig->vSetKey("gb_bios_file", "" ); m_poCoreConfig->vSetKey("emulator_type", EmulatorAuto ); - + m_poCoreConfig->vSetKey("pause_when_inactive", true ); + m_poCoreConfig->vSetKey("show_speed", ShowPercentage ); + // Display section // m_poDisplayConfig = m_oConfig.poAddSection("Display"); m_poDisplayConfig->vSetKey("scale", 1 ); - m_poDisplayConfig->vSetKey("show_speed", ShowPercentage ); - m_poDisplayConfig->vSetKey("pause_when_inactive", true ); m_poDisplayConfig->vSetKey("filter2x", FilterNone ); m_poDisplayConfig->vSetKey("filterIB", FilterIBNone ); #ifdef USE_OPENGL @@ -737,11 +666,11 @@ void Window::vCheckConfig() m_poDisplayConfig->vSetKey("scale", iAdjusted); } - iValue = m_poDisplayConfig->oGetKey("show_speed"); + iValue = m_poCoreConfig->oGetKey("show_speed"); iAdjusted = CLAMP(iValue, m_iShowSpeedMin, m_iShowSpeedMax); if (iValue != iAdjusted) { - m_poDisplayConfig->vSetKey("show_speed", iAdjusted); + m_poCoreConfig->vSetKey("show_speed", iAdjusted); } iValue = m_poDisplayConfig->oGetKey("filter2x"); @@ -943,6 +872,32 @@ void Window::vApplyConfigJoypads() } } +void Window::vApplyConfigFrameskip() +{ + std::string sFrameskip = m_poCoreConfig->oGetKey("frameskip"); + + if (sFrameskip == "auto") + { + m_bAutoFrameskip = true; + gbFrameSkip = 0; + systemFrameSkip = 0; + } + else + { + m_bAutoFrameskip = false; + int iFrameskip = m_poCoreConfig->oGetKey("frameskip"); + gbFrameSkip = iFrameskip; + systemFrameSkip = iFrameskip; + } +} + +void Window::vApplyConfigShowSpeed() +{ + m_eShowSpeed = (EShowSpeed)m_poCoreConfig->oGetKey("show_speed"); + if (m_eShowSpeed == ShowNone) + vSetDefaultTitle(); +} + void Window::vSaveJoypadsToConfig() { for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++) diff --git a/src/gtk/window.h b/src/gtk/window.h index 0befaf90..f584c29f 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -107,6 +107,8 @@ public: void vApplyConfigGBASaveType(); void vApplyConfigGBAFlashSize(); void vApplyConfigGBARTC(); + void vApplyConfigFrameskip(); + void vApplyConfigShowSpeed(); void vUpdateScreen(); inline ECartridge eGetCartridge() const { return m_eCartridge; } @@ -151,11 +153,9 @@ protected: virtual void vOnFileScreenCapture(); virtual void vOnFileClose(); virtual void vOnFileExit(); - virtual void vOnFrameskipToggled(Gtk::CheckMenuItem * _poCMI, int _iValue); virtual void vOnVideoFullscreen(); virtual void vOnDirectories(); - virtual void vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI); - virtual void vOnShowSpeedToggled(Gtk::CheckMenuItem * _poCMI, int _iShowSpeed); + virtual void vOnGeneralConfigure(); virtual void vOnJoypadConfigure(); virtual void vOnDisplayConfigure(); virtual void vOnSoundConfigure(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 3ee2dada..0ac8328c 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -40,6 +40,7 @@ #include "soundconfig.h" #include "gameboyconfig.h" #include "gameboyadvanceconfig.h" +#include "generalconfig.h" #include "cheatlist.h" namespace VBA @@ -355,29 +356,6 @@ void Window::vOnFileExit() hide(); } -void Window::vOnFrameskipToggled(Gtk::CheckMenuItem * _poCMI, int _iValue) -{ - if (! _poCMI->get_active()) - { - return; - } - - if (_iValue >= 0 && _iValue <= 9) - { - m_poCoreConfig->vSetKey("frameskip", _iValue); - gbFrameSkip = _iValue; - systemFrameSkip = _iValue; - m_bAutoFrameskip = false; - } - else - { - m_poCoreConfig->vSetKey("frameskip", "auto"); - gbFrameSkip = 0; - systemFrameSkip = 0; - m_bAutoFrameskip = true; - } -} - void Window::vOnVideoFullscreen() { vToggleFullscreen(); @@ -393,26 +371,6 @@ void Window::vOnDirectories() vUpdateGameSlots(); } -void Window::vOnPauseWhenInactiveToggled(Gtk::CheckMenuItem * _poCMI) -{ - m_poDisplayConfig->vSetKey("pause_when_inactive", _poCMI->get_active()); -} - -void Window::vOnShowSpeedToggled(Gtk::CheckMenuItem * _poCMI, int _iShowSpeed) -{ - if (! _poCMI->get_active()) - { - return; - } - - m_eShowSpeed = (EShowSpeed)_iShowSpeed; - if (m_eShowSpeed == ShowNone) - { - vSetDefaultTitle(); - } - m_poDisplayConfig->vSetKey("show_speed", _iShowSpeed); -} - void Window::vOnJoypadConfigure() { JoypadConfigDialog oDialog(m_poInputConfig); @@ -472,6 +430,19 @@ void Window::vOnGameBoyAdvanceConfigure() poDialog->hide(); } +void Window::vOnGeneralConfigure() +{ + std::string sUiFile = sGetUiFilePath("preferences.ui"); + Glib::RefPtr poBuilder = Gtk::Builder::create_from_file(sUiFile); + + PreferencesDialog * poDialog = 0; + poBuilder->get_widget_derived("PreferencesDialog", poDialog); + poDialog->vSetConfig(m_poCoreConfig, this); + poDialog->set_transient_for(*this); + poDialog->run(); + poDialog->hide(); +} + void Window::vOnCheatList() { if (m_eCartridge == CartridgeGBA) @@ -518,7 +489,7 @@ void Window::vOnHelpAbout() "along with this program. If not, see ."; const char csCopyright[] = "Copyright (C) 1999-2003 Forgotten\n" "Copyright (C) 2004-2006 VBA development team\n" - "Copyright (C) 2007-2008 VBA-M development team"; + "Copyright (C) 2007-2011 VBA-M development team"; oAboutDialog.set_transient_for(*this); @@ -563,7 +534,7 @@ bool Window::on_focus_in_event(GdkEventFocus * _pstEvent) { if (emulating && ! m_bPaused - && m_poDisplayConfig->oGetKey("pause_when_inactive")) + && m_poCoreConfig->oGetKey("pause_when_inactive")) { vStartEmu(); soundResume(); @@ -575,7 +546,7 @@ bool Window::on_focus_out_event(GdkEventFocus * _pstEvent) { if (emulating && ! m_bPaused - && m_poDisplayConfig->oGetKey("pause_when_inactive")) + && m_poCoreConfig->oGetKey("pause_when_inactive")) { vStopEmu(); soundPause();