diff --git a/CMakeLists.txt b/CMakeLists.txt index a2af7adf..daf928f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,7 @@ SET(SRC_GTK src/gtk/windowcallbacks.cpp src/gtk/filters.cpp src/gtk/joypadconfig.cpp + src/gtk/directoriesconfig.cpp src/gtk/screenarea.cpp src/gtk/screenarea-cairo.cpp src/gtk/screenarea-xvideo.cpp diff --git a/src/gtk/directoriesconfig.cpp b/src/gtk/directoriesconfig.cpp new file mode 100644 index 00000000..ed000edc --- /dev/null +++ b/src/gtk/directoriesconfig.cpp @@ -0,0 +1,68 @@ +// -*- 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 "directoriesconfig.h" + +#include + +#include "intl.h" + +namespace VBA +{ + +const DirectoriesConfigDialog::SDirEntry DirectoriesConfigDialog::m_astDirs[] = +{ + { "gba_roms", "GBA roms :", "GBARomsDirEntry" }, + { "gb_roms", "GB roms :", "GBRomsDirEntry" }, + { "batteries", "Batteries :", "BatteriesDirEntry" }, + { "saves", "Saves :", "SavesDirEntry" }, + { "captures", "Captures :", "CapturesDirEntry" } +}; + +DirectoriesConfigDialog::DirectoriesConfigDialog(Config::Section * _poConfig) : + Gtk::Dialog("Directories config", true, true), + m_poConfig(_poConfig) +{ + Gtk::Table * poTable = Gtk::manage( new Gtk::Table(G_N_ELEMENTS(m_astDirs), 2, false)); + poTable->set_border_width(5); + poTable->set_spacings(5); + + for (guint i = 0; i < G_N_ELEMENTS(m_astDirs); i++) + { + Gtk::Label * poLabel = Gtk::manage( new Gtk::Label(m_astDirs[i].m_csLabel, Gtk::ALIGN_RIGHT) ); + m_poButtons[i] = Gtk::manage( new Gtk::FileChooserButton(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER) ); + m_poButtons[i]->set_current_folder(m_poConfig->sGetKey(m_astDirs[i].m_csKey)); + + poTable->attach(* poLabel, 0, 1, i, i + 1); + poTable->attach(* m_poButtons[i], 1, 2, i, i + 1); + } + + add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE); + get_vbox()->pack_start(* poTable); + show_all_children(); +} + +void DirectoriesConfigDialog::on_response(int response_id) +{ + for (guint i = 0; i < G_N_ELEMENTS(m_astDirs); i++) + { + m_poConfig->vSetKey(m_astDirs[i].m_csKey, m_poButtons[i]->get_current_folder()); + } +} + +} // namespace VBA diff --git a/src/gtk/directoriesconfig.h b/src/gtk/directoriesconfig.h new file mode 100644 index 00000000..d98ba1da --- /dev/null +++ b/src/gtk/directoriesconfig.h @@ -0,0 +1,58 @@ +// -*- 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_DIRECTORIESCONFIG_H__ +#define __VBA_DIRECTORIESCONFIG_H__ + +#include + +#include +#include +#include +#include + +#include "configfile.h" + +namespace VBA +{ + +class DirectoriesConfigDialog : public Gtk::Dialog +{ +public: + DirectoriesConfigDialog(Config::Section * _poConfig); + +protected: + void on_response(int response_id); + +private: + struct SDirEntry + { + const char * m_csKey; + const char * m_csLabel; + const char * m_csFileChooserButton; + }; + + Config::Section * m_poConfig; + static const SDirEntry m_astDirs[]; + Gtk::FileChooserButton * m_poButtons[5]; +}; + +} // namespace VBA + + +#endif // __VBA_DIRECTORIESCONFIG_H__ diff --git a/src/gtk/joypadconfig.cpp b/src/gtk/joypadconfig.cpp index ca5a65b0..53bce490 100644 --- a/src/gtk/joypadconfig.cpp +++ b/src/gtk/joypadconfig.cpp @@ -43,14 +43,15 @@ const JoypadConfigDialog::SJoypadKey JoypadConfigDialog::m_astKeys[] = { KEY_BUTTON_AUTO_B, "Autofire B :" } }; -JoypadConfigDialog::JoypadConfigDialog() : +JoypadConfigDialog::JoypadConfigDialog(Config::Section * _poConfig) : Gtk::Dialog("Joypad config", true, true), m_oTitleHBox(false, 5), m_oTitleLabel("Joypad :", Gtk::ALIGN_RIGHT), m_oDefaultJoypad("Default joypad"), m_oTable(G_N_ELEMENTS(m_astKeys), 2, false), m_bUpdating(false), - m_ePad(PAD_MAIN) + m_ePad(PAD_MAIN), + m_poConfig(_poConfig) { // Joypad selection m_oTitleCombo.append_text("1"); @@ -195,6 +196,11 @@ bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent) return true; } +void JoypadConfigDialog::on_response(int response_id) +{ + m_poConfig->vSetKey("active_joypad", inputGetDefaultJoypad()); +} + void JoypadConfigDialog::vOnInputEvent(const SDL_Event &event) { if (m_iCurrentEntry < 0) diff --git a/src/gtk/joypadconfig.h b/src/gtk/joypadconfig.h index bfd2824d..1b110b27 100644 --- a/src/gtk/joypadconfig.h +++ b/src/gtk/joypadconfig.h @@ -31,6 +31,7 @@ #include #include "../sdl/inputSDL.h" +#include "configfile.h" namespace VBA { @@ -38,7 +39,7 @@ namespace VBA class JoypadConfigDialog : public Gtk::Dialog { public: - JoypadConfigDialog(); + JoypadConfigDialog(Config::Section * _poConfig); virtual ~JoypadConfigDialog(); protected: @@ -47,6 +48,7 @@ protected: void vOnInputEvent(const SDL_Event &event); bool on_key_press_event(GdkEventKey * _pstEvent); + void on_response(int response_id); private: struct SJoypadKey @@ -69,6 +71,7 @@ private: sigc::connection m_oConfigSig; SDL_Event m_oPreviousEvent; EPad m_ePad; + Config::Section * m_poConfig; bool bOnConfigIdle(); void vOnJoypadSelect(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 9b4b4666..e26a6941 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -37,6 +36,7 @@ #include "tools.h" #include "intl.h" #include "joypadconfig.h" +#include "directoriesconfig.h" namespace VBA { @@ -386,50 +386,10 @@ void Window::vOnVideoScaleToggled(Gtk::CheckMenuItem * _poCMI, int _iScale) void Window::vOnDirectories() { - struct - { - const char * m_csKey; - const char * m_csLabel; - const char * m_csFileChooserButton; - Gtk::FileChooserButton * m_poFileChooserButton; - } - astRow[] = - { - { "gba_roms", "GBA roms :", "GBARomsDirEntry", 0 }, - { "gb_roms", "GB roms :", "GBRomsDirEntry", 0 }, - { "batteries", "Batteries :", "BatteriesDirEntry", 0 }, - { "saves", "Saves :", "SavesDirEntry", 0 }, - { "captures", "Captures :", "CapturesDirEntry", 0 } - }; - - Gtk::Table oTable(G_N_ELEMENTS(astRow), 2, false); - oTable.set_border_width(5); - oTable.set_spacings(5); - - for (guint i = 0; i < G_N_ELEMENTS(astRow); i++) - { - Gtk::Label * poLabel = Gtk::manage( new Gtk::Label(astRow[i].m_csLabel, Gtk::ALIGN_RIGHT) ); - astRow[i].m_poFileChooserButton = Gtk::manage( new Gtk::FileChooserButton(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER) ); - astRow[i].m_poFileChooserButton->set_current_folder(m_poDirConfig->sGetKey(astRow[i].m_csKey)); - - oTable.attach(* poLabel, 0, 1, i, i + 1); - oTable.attach(* astRow[i].m_poFileChooserButton, 1, 2, i, i + 1); - } - - Gtk::Dialog oDialog("Directories", true, true); - oDialog.add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE); - oDialog.get_vbox()->pack_start(oTable); + DirectoriesConfigDialog oDialog(m_poDirConfig); oDialog.set_transient_for(*this); - oDialog.show_all_children(); oDialog.run(); - for (guint i = 0; i < G_N_ELEMENTS(astRow); i++) - { - Glib::ustring sDir = astRow[i].m_poFileChooserButton->get_current_folder(); - - m_poDirConfig->vSetKey(astRow[i].m_csKey, sDir); - } - // Needed if saves dir changed vUpdateGameSlots(); } @@ -638,11 +598,9 @@ void Window::vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB) void Window::vOnJoypadConfigure() { - JoypadConfigDialog oDialog; + JoypadConfigDialog oDialog(m_poInputConfig); oDialog.set_transient_for(*this); oDialog.run(); - - m_poInputConfig->vSetKey("active_joypad", inputGetDefaultJoypad()); } void Window::vOnHelpAbout()