GTK : Introducing the new Game Boy config dialog

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@847 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2009-01-06 21:20:18 +00:00
parent a6e74b1e7b
commit f7b55782fd
8 changed files with 339 additions and 160 deletions

View File

@ -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

92
src/gtk/gameboyconfig.cpp Normal file
View File

@ -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 <gtkmm/stock.h>
#include <gtkmm/frame.h>
#include <gtkmm/liststore.h>
#include "intl.h"
namespace VBA
{
GameBoyConfigDialog::GameBoyConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& 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<int>("emulator_type");
m_poSystemComboBox->set_active(aEmulatorType[eDefaultEmulatorType]);
bool bBorder = m_poConfig->oGetKey<bool>("gb_border");
m_poBorderCheckButton->set_active(bBorder);
bool bPrinter = m_poConfig->oGetKey<bool>("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

55
src/gtk/gameboyconfig.h Normal file
View File

@ -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 <gtkmm/dialog.h>
#include <gtkmm/builder.h>
#include <gtkmm/combobox.h>
#include "configfile.h"
#include "window.h"
namespace VBA
{
class GameBoyConfigDialog : public Gtk::Dialog
{
public:
GameBoyConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& 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__

125
src/gtk/ui/gameboy.ui Normal file
View File

@ -0,0 +1,125 @@
<?xml version="1.0"?>
<!--Generated with glade3 3.4.5 on Tue Jan 6 21:21:29 2009 -->
<interface>
<object class="GtkListStore" id="model1">
<columns>
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0">Automatic</col>
</row>
<row>
<col id="0">Game Boy Advance</col>
</row>
<row>
<col id="0">Game Boy Color</col>
</row>
<row>
<col id="0">Super Game Boy</col>
</row>
<row>
<col id="0">Super Game Boy 2</col>
</row>
<row>
<col id="0">Game Boy</col>
</row>
</data>
</object>
<object class="GtkDialog" id="GameBoyConfigDialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Game Boy games settings</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">Emulated system : </property>
</object>
</child>
<child>
<object class="GtkComboBox" id="SystemComboBox">
<property name="visible">True</property>
<property name="model">model1</property>
<child>
<object class="GtkCellRendererText" id="renderer1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkCheckButton" id="BorderCheckButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Display Super Game Boy borders</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="PrinterCheckButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Emulate a Game Boy Printer</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-close</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button1</action-widget>
</action-widgets>
</object>
</interface>

View File

@ -605,81 +605,10 @@
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="GameboyMenu">
<widget class="GtkMenuItem" id="GameBoyConfigure">
<property name="visible">True</property>
<property name="label" translatable="yes">_Gameboy</property>
<property name="label" translatable="yes">_Game Boy ...</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="GameboyMenu_menu">
<child>
<widget class="GtkCheckMenuItem" id="GameboyBorder">
<property name="visible">True</property>
<property name="label" translatable="yes">_Border</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="GameboyPrinter">
<property name="visible">True</property>
<property name="label" translatable="yes">_Printer</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator16">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="GameboyAutomatic">
<property name="visible">True</property>
<property name="label" translatable="yes">_Automatic</property>
<property name="use_underline">True</property>
<property name="active">True</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="GameboyGba">
<property name="visible">True</property>
<property name="label" translatable="yes">_GBA</property>
<property name="use_underline">True</property>
<property name="group">GameboyAutomatic</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="GameboyCgb">
<property name="visible">True</property>
<property name="label" translatable="yes">_CGB/GBC</property>
<property name="use_underline">True</property>
<property name="group">GameboyAutomatic</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="GameboySgb">
<property name="visible">True</property>
<property name="label" translatable="yes">_SGB</property>
<property name="use_underline">True</property>
<property name="group">GameboyAutomatic</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="GameboySgb2">
<property name="visible">True</property>
<property name="label" translatable="yes">SGB_2</property>
<property name="use_underline">True</property>
<property name="group">GameboyAutomatic</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="GameboyGb">
<property name="visible">True</property>
<property name="label" translatable="yes">G_B</property>
<property name="use_underline">True</property>
<property name="group">GameboyAutomatic</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>

View File

@ -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<Xml> & _poXml) :
vApplyConfigFilterIB();
vApplyConfigMute();
vApplyConfigVolume();
vApplyConfigGBSystem();
vApplyConfigGBBorder();
vApplyConfigGBPrinter();
Gtk::MenuItem * poMI;
Gtk::CheckMenuItem * poCMI;
@ -390,49 +394,9 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
poCMI, astFlashSize[i].m_iFlashSize));
}
// Gameboy menu
//
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("GameboyBorder"));
poCMI->set_active(m_poCoreConfig->oGetKey<bool>("gb_border"));
vOnGBBorderToggled(poCMI);
poCMI->signal_toggled().connect(sigc::bind(
sigc::mem_fun(*this, &Window::vOnGBBorderToggled),
poCMI));
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("GameboyPrinter"));
poCMI->set_active(m_poCoreConfig->oGetKey<bool>("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<int>("emulator_type");
for (guint i = 0; i < G_N_ELEMENTS(astEmulatorType); i++)
{
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_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<Gtk::MenuItem *>(_poXml->get_widget("GameBoyConfigure"));
poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnGameBoyConfigure));
// Display menu
poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("DisplayConfigure"));
@ -933,6 +897,35 @@ void Window::vApplyConfigSoundSampleRate()
}
}
void Window::vApplyConfigGBSystem()
{
gbEmulatorType = m_poCoreConfig->oGetKey<int>("emulator_type");
}
void Window::vApplyConfigGBBorder()
{
gbBorderOn = m_poCoreConfig->oGetKey<bool>("gb_border");
if (emulating && m_eCartridge == CartridgeGB && gbBorderOn)
{
gbSgbRenderBorder();
}
vUpdateScreen();
}
void Window::vApplyConfigGBPrinter()
{
bool bPrinter = m_poCoreConfig->oGetKey<bool>("gb_printer");
if (bPrinter)
{
gbSerialFunction = gbPrinterSend;
}
else
{
gbSerialFunction = NULL;
}
}
void Window::vHistoryAdd(const std::string & _rsFile)
{
std::string sURL = "file://" + _rsFile;

View File

@ -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();

View File

@ -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<Gtk::Builder> 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;