From 1543a02585c9fe42d1ed7f3313a31fee4dbc8190 Mon Sep 17 00:00:00 2001 From: bgk Date: Tue, 6 Jan 2009 21:20:18 +0000 Subject: [PATCH] GTK : Introducing the new Game Boy config dialog --- CMakeLists.txt | 1 + src/gtk/gameboyconfig.cpp | 92 ++++++++++++++++++++++++++ src/gtk/gameboyconfig.h | 55 ++++++++++++++++ src/gtk/ui/gameboy.ui | 125 ++++++++++++++++++++++++++++++++++++ src/gtk/ui/vbam.glade | 75 +--------------------- src/gtk/window.cpp | 79 +++++++++++------------ src/gtk/window.h | 27 ++++---- src/gtk/windowcallbacks.cpp | 45 ++++--------- 8 files changed, 339 insertions(+), 160 deletions(-) create mode 100644 src/gtk/gameboyconfig.cpp create mode 100644 src/gtk/gameboyconfig.h create mode 100644 src/gtk/ui/gameboy.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index b69547a2..127e2ec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,7 @@ SET(SRC_GTK src/gtk/system.cpp src/gtk/windowcallbacks.cpp src/gtk/filters.cpp + src/gtk/gameboyconfig.cpp src/gtk/joypadconfig.cpp src/gtk/directoriesconfig.cpp src/gtk/displayconfig.cpp diff --git a/src/gtk/gameboyconfig.cpp b/src/gtk/gameboyconfig.cpp new file mode 100644 index 00000000..a864a377 --- /dev/null +++ b/src/gtk/gameboyconfig.cpp @@ -0,0 +1,92 @@ +// -*- 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 "gameboyconfig.h" + +#include +#include +#include + +#include "intl.h" + +namespace VBA +{ + +GameBoyConfigDialog::GameBoyConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder) : + Gtk::Dialog(_pstDialog), + m_poConfig(0) +{ + refBuilder->get_widget("SystemComboBox", m_poSystemComboBox); + refBuilder->get_widget("BorderCheckButton", m_poBorderCheckButton); + refBuilder->get_widget("PrinterCheckButton", m_poPrinterCheckButton); + + m_poSystemComboBox->signal_changed().connect(sigc::mem_fun(*this, &GameBoyConfigDialog::vOnSystemChanged)); + m_poBorderCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &GameBoyConfigDialog::vOnBorderChanged)); + m_poPrinterCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &GameBoyConfigDialog::vOnPrinterChanged)); +} + +void GameBoyConfigDialog::vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow) +{ + m_poConfig = _poConfig; + m_poWindow = _poWindow; + + const int aEmulatorType[] = { 0, 2, 3, 5, 1, 4 }; + + VBA::Window::EEmulatorType eDefaultEmulatorType = (VBA::Window::EEmulatorType)m_poConfig->oGetKey("emulator_type"); + m_poSystemComboBox->set_active(aEmulatorType[eDefaultEmulatorType]); + + bool bBorder = m_poConfig->oGetKey("gb_border"); + m_poBorderCheckButton->set_active(bBorder); + + bool bPrinter = m_poConfig->oGetKey("gb_printer"); + m_poPrinterCheckButton->set_active(bPrinter); +} + +void GameBoyConfigDialog::vOnSystemChanged() +{ + const VBA::Window::EEmulatorType aEmulatorType[] = + { + VBA::Window::EmulatorAuto, + VBA::Window::EmulatorCGB, + VBA::Window::EmulatorSGB, + VBA::Window::EmulatorGB, + VBA::Window::EmulatorGBA, + VBA::Window::EmulatorSGB2 + }; + + int iSystem = m_poSystemComboBox->get_active_row_number(); + m_poConfig->vSetKey("emulator_type", aEmulatorType[iSystem]); + + m_poWindow->vApplyConfigGBSystem(); +} + +void GameBoyConfigDialog::vOnBorderChanged() +{ + bool bBorder = m_poBorderCheckButton->get_active(); + m_poConfig->vSetKey("gb_border", bBorder); + m_poWindow->vApplyConfigGBBorder(); +} + +void GameBoyConfigDialog::vOnPrinterChanged() +{ + bool bPrinter = m_poPrinterCheckButton->get_active(); + m_poConfig->vSetKey("gb_printer", bPrinter); + m_poWindow->vApplyConfigGBPrinter(); +} + +} // namespace VBA diff --git a/src/gtk/gameboyconfig.h b/src/gtk/gameboyconfig.h new file mode 100644 index 00000000..ddbc8be3 --- /dev/null +++ b/src/gtk/gameboyconfig.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_GAMEBOYCONFIG_H__ +#define __VBA_GAMEBOYCONFIG_H__ + +#include +#include +#include + +#include "configfile.h" +#include "window.h" + +namespace VBA +{ + +class GameBoyConfigDialog : public Gtk::Dialog +{ +public: + GameBoyConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder); + + void vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow); + +private: + void vOnSystemChanged(); + void vOnBorderChanged(); + void vOnPrinterChanged(); + + VBA::Window * m_poWindow; + + Config::Section * m_poConfig; + Gtk::ComboBox * m_poSystemComboBox; + Gtk::CheckButton * m_poBorderCheckButton; + Gtk::CheckButton * m_poPrinterCheckButton; +}; + +} // namespace VBA + + +#endif // __VBA_GAMEBOYCONFIG_H__ diff --git a/src/gtk/ui/gameboy.ui b/src/gtk/ui/gameboy.ui new file mode 100644 index 00000000..f5b648e6 --- /dev/null +++ b/src/gtk/ui/gameboy.ui @@ -0,0 +1,125 @@ + + + + + + + + + + Automatic + + + Game Boy Advance + + + Game Boy Color + + + Super Game Boy + + + Super Game Boy 2 + + + Game Boy + + + + + 5 + Game Boy games settings + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True + + + True + + + True + + + True + Emulated system : + + + + + True + model1 + + + + 0 + + + + + 1 + + + + + + + True + True + Display Super Game Boy borders + True + + + 1 + + + + + True + True + Emulate a Game Boy Printer + True + + + 2 + + + + + 1 + + + + + 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 8ee2a2a9..c13b38a1 100644 --- a/src/gtk/ui/vbam.glade +++ b/src/gtk/ui/vbam.glade @@ -605,81 +605,10 @@ - + True - _Gameboy + _Game Boy ... True - - - - - True - _Border - True - - - - - True - _Printer - True - - - - - True - - - - - True - _Automatic - True - True - - - - - True - _GBA - True - GameboyAutomatic - - - - - True - _CGB/GBC - True - GameboyAutomatic - - - - - True - _SGB - True - GameboyAutomatic - - - - - True - SGB_2 - True - GameboyAutomatic - - - - - True - G_B - True - GameboyAutomatic - - - - diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index c8653ad8..91360ae5 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -31,6 +31,7 @@ #include "../gb/gb.h" #include "../gb/gbGlobals.h" #include "../gb/gbSound.h" +#include "../gb/gbPrinter.h" #include "../Util.h" #include "tools.h" @@ -145,6 +146,9 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : vApplyConfigFilterIB(); vApplyConfigMute(); vApplyConfigVolume(); + vApplyConfigGBSystem(); + vApplyConfigGBBorder(); + vApplyConfigGBPrinter(); Gtk::MenuItem * poMI; Gtk::CheckMenuItem * poCMI; @@ -390,49 +394,9 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : poCMI, astFlashSize[i].m_iFlashSize)); } - // Gameboy menu - // - poCMI = dynamic_cast(_poXml->get_widget("GameboyBorder")); - poCMI->set_active(m_poCoreConfig->oGetKey("gb_border")); - vOnGBBorderToggled(poCMI); - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnGBBorderToggled), - poCMI)); - - poCMI = dynamic_cast(_poXml->get_widget("GameboyPrinter")); - poCMI->set_active(m_poCoreConfig->oGetKey("gb_printer")); - vOnGBPrinterToggled(poCMI); - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnGBPrinterToggled), - poCMI)); - - struct - { - const char * m_csName; - const EEmulatorType m_eEmulatorType; - } - astEmulatorType[] = - { - { "GameboyAutomatic", EmulatorAuto }, - { "GameboyGba", EmulatorGBA }, - { "GameboyCgb", EmulatorCGB }, - { "GameboySgb", EmulatorSGB }, - { "GameboySgb2", EmulatorSGB2 }, - { "GameboyGb", EmulatorGB } - }; - EEmulatorType eDefaultEmulatorType = (EEmulatorType)m_poCoreConfig->oGetKey("emulator_type"); - for (guint i = 0; i < G_N_ELEMENTS(astEmulatorType); i++) - { - poCMI = dynamic_cast(_poXml->get_widget(astEmulatorType[i].m_csName)); - if (astEmulatorType[i].m_eEmulatorType == eDefaultEmulatorType) - { - poCMI->set_active(); - vOnEmulatorTypeToggled(poCMI, eDefaultEmulatorType); - } - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnEmulatorTypeToggled), - poCMI, astEmulatorType[i].m_eEmulatorType)); - } + // Game Boy menu + poMI = dynamic_cast(_poXml->get_widget("GameBoyConfigure")); + poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnGameBoyConfigure)); // Display menu poMI = dynamic_cast(_poXml->get_widget("DisplayConfigure")); @@ -933,6 +897,35 @@ void Window::vApplyConfigSoundSampleRate() } } +void Window::vApplyConfigGBSystem() +{ + gbEmulatorType = m_poCoreConfig->oGetKey("emulator_type"); +} + +void Window::vApplyConfigGBBorder() +{ + gbBorderOn = m_poCoreConfig->oGetKey("gb_border"); + if (emulating && m_eCartridge == CartridgeGB && gbBorderOn) + { + gbSgbRenderBorder(); + } + vUpdateScreen(); +} + +void Window::vApplyConfigGBPrinter() +{ + bool bPrinter = m_poCoreConfig->oGetKey("gb_printer"); + if (bPrinter) + { + gbSerialFunction = gbPrinterSend; + } + else + { + gbSerialFunction = NULL; + } +} + + void Window::vHistoryAdd(const std::string & _rsFile) { std::string sURL = "file://" + _rsFile; diff --git a/src/gtk/window.h b/src/gtk/window.h index 65912f6f..cf9a3f65 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -60,6 +60,16 @@ public: OutputOpenGL, OutputXvideo }; + + enum EEmulatorType + { + EmulatorAuto, + EmulatorCGB, + EmulatorSGB, + EmulatorGB, + EmulatorGBA, + EmulatorSGB2 + }; // GB/GBA screen sizes const int m_iGBScreenWidth; @@ -82,6 +92,9 @@ public: void vApplyConfigMute(); void vApplyConfigVolume(); void vApplyConfigSoundSampleRate(); + void vApplyConfigGBSystem(); + void vApplyConfigGBBorder(); + void vApplyConfigGBPrinter(); void vUpdateScreen(); inline ECartridge eGetCartridge() const { return m_eCartridge; } @@ -114,16 +127,6 @@ protected: SoundOn }; - enum EEmulatorType - { - EmulatorAuto, - EmulatorCGB, - EmulatorSGB, - EmulatorGB, - EmulatorGBA, - EmulatorSGB2 - }; - enum EColorFormat { ColorFormatRGB, @@ -153,12 +156,10 @@ protected: 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 vOnGBBorderToggled(Gtk::CheckMenuItem * _poCMI); - virtual void vOnGBPrinterToggled(Gtk::CheckMenuItem * _poCMI); - virtual void vOnEmulatorTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iEmulatorType); virtual void vOnJoypadConfigure(); virtual void vOnDisplayConfigure(); virtual void vOnSoundConfigure(); + virtual void vOnGameBoyConfigure(); virtual void vOnHelpAbout(); virtual bool bOnEmuIdle(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 971b31b4..ee320034 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -29,7 +29,6 @@ #include "../gba/Sound.h" #include "../gb/gb.h" #include "../gb/gbGlobals.h" -#include "../gb/gbPrinter.h" #include "../Util.h" #include "../sdl/inputSDL.h" @@ -39,6 +38,7 @@ #include "directoriesconfig.h" #include "displayconfig.h" #include "soundconfig.h" +#include "gameboyconfig.h" namespace VBA { @@ -471,36 +471,6 @@ void Window::vOnFlashSizeToggled(Gtk::CheckMenuItem * _poCMI, int _iFlashSize) m_poCoreConfig->vSetKey("flash_size", _iFlashSize); } -void Window::vOnGBBorderToggled(Gtk::CheckMenuItem * _poCMI) -{ - gbBorderOn = _poCMI->get_active(); - if (emulating && m_eCartridge == CartridgeGB && _poCMI->get_active()) - { - gbSgbRenderBorder(); - } - vUpdateScreen(); - m_poCoreConfig->vSetKey("gb_border", _poCMI->get_active()); -} - -void Window::vOnGBPrinterToggled(Gtk::CheckMenuItem * _poCMI) -{ - if (_poCMI->get_active()) - { - gbSerialFunction = gbPrinterSend; - } - else - { - gbSerialFunction = NULL; - } - m_poCoreConfig->vSetKey("gb_printer", _poCMI->get_active()); -} - -void Window::vOnEmulatorTypeToggled(Gtk::CheckMenuItem * _poCMI, int _iEmulatorType) -{ - gbEmulatorType = _iEmulatorType; - m_poCoreConfig->vSetKey("emulator_type", _iEmulatorType); -} - void Window::vOnJoypadConfigure() { JoypadConfigDialog oDialog(m_poInputConfig); @@ -534,6 +504,19 @@ void Window::vOnSoundConfigure() poDialog->hide(); } +void Window::vOnGameBoyConfigure() +{ + std::string sUiFile = sGetUiFilePath("gameboy.ui"); + Glib::RefPtr poBuilder = Gtk::Builder::create_from_file(sUiFile); + + GameBoyConfigDialog * poDialog = 0; + poBuilder->get_widget_derived("GameBoyConfigDialog", poDialog); + poDialog->vSetConfig(m_poCoreConfig, this); + poDialog->set_transient_for(*this); + poDialog->run(); + poDialog->hide(); +} + void Window::vOnHelpAbout() { Gtk::AboutDialog oAboutDialog;