GTK : Replaced the sound configuration menu by a dialog

This commit is contained in:
bgk 2008-12-23 13:51:48 +00:00
parent 21563e5ca4
commit 753b72123d
8 changed files with 369 additions and 208 deletions

View File

@ -209,6 +209,7 @@ SET(SRC_GTK
src/gtk/joypadconfig.cpp
src/gtk/directoriesconfig.cpp
src/gtk/displayconfig.cpp
src/gtk/soundconfig.cpp
src/gtk/screenarea.cpp
src/gtk/screenarea-cairo.cpp
src/gtk/screenarea-xvideo.cpp

125
src/gtk/soundconfig.cpp Normal file
View File

@ -0,0 +1,125 @@
// -*- 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 "soundconfig.h"
#include <gtkmm/stock.h>
#include <gtkmm/frame.h>
#include <gtkmm/liststore.h>
#include "intl.h"
namespace VBA
{
SoundConfigDialog::SoundConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder) :
Gtk::Dialog(_pstDialog),
m_poConfig(0)
{
refBuilder->get_widget("VolumeComboBox", m_poVolumeComboBox);
refBuilder->get_widget("RateComboBox", m_poRateComboBox);
m_poVolumeComboBox->signal_changed().connect(sigc::mem_fun(*this, &SoundConfigDialog::vOnVolumeChanged));
m_poRateComboBox->signal_changed().connect(sigc::mem_fun(*this, &SoundConfigDialog::vOnRateChanged));
}
void SoundConfigDialog::vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow)
{
m_poConfig = _poConfig;
m_poWindow = _poWindow;
bool bMute = m_poConfig->oGetKey<bool>("mute");
float fSoundVolume = m_poConfig->oGetKey<float>("volume");
if (bMute)
m_poVolumeComboBox->set_active(0);
else if (0.0f <= fSoundVolume && fSoundVolume <= 0.25f)
m_poVolumeComboBox->set_active(1);
else if (0.25f < fSoundVolume && fSoundVolume <= 0.50f)
m_poVolumeComboBox->set_active(2);
else if (1.0f < fSoundVolume && fSoundVolume <= 2.0f)
m_poVolumeComboBox->set_active(4);
else
m_poVolumeComboBox->set_active(3);
VBA::Window::ESoundQuality eSoundQuality = (VBA::Window::ESoundQuality)m_poConfig->oGetKey<int>("quality");
switch (eSoundQuality)
{
case VBA::Window::Sound44K:
m_poRateComboBox->set_active(2);
break;
case VBA::Window::Sound22K:
m_poRateComboBox->set_active(1);
break;
case VBA::Window::Sound11K:
m_poRateComboBox->set_active(0);
break;
}
}
void SoundConfigDialog::vOnVolumeChanged()
{
int iVolume = m_poVolumeComboBox->get_active_row_number();
switch (iVolume)
{
case 0: // Mute
m_poConfig->vSetKey("mute", true);
m_poConfig->vSetKey("volume", 1.0f);
break;
case 1: // 25 %
m_poConfig->vSetKey("mute", false);
m_poConfig->vSetKey("volume", 0.25f);
break;
case 2: // 50 %
m_poConfig->vSetKey("mute", false);
m_poConfig->vSetKey("volume", 0.50f);
break;
case 4: // 200 %
m_poConfig->vSetKey("mute", false);
m_poConfig->vSetKey("volume", 2.00f);
break;
case 3: // 100 %
default:
m_poConfig->vSetKey("mute", false);
m_poConfig->vSetKey("volume", 1.00f);
break;
}
m_poWindow->vApplyConfigMute();
m_poWindow->vApplyConfigVolume();
}
void SoundConfigDialog::vOnRateChanged()
{
int iRate = m_poRateComboBox->get_active_row_number();
switch (iRate)
{
case 0: // 11 KHz
m_poConfig->vSetKey("quality", VBA::Window::Sound11K);
break;
case 1: // 22 KHz
m_poConfig->vSetKey("quality", VBA::Window::Sound22K);
break;
case 2: // 44 KHz
default:
m_poConfig->vSetKey("quality", VBA::Window::Sound44K);
break;
}
}
} // namespace VBA

53
src/gtk/soundconfig.h Normal file
View File

@ -0,0 +1,53 @@
// -*- 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_SOUNDCONFIG_H__
#define __VBA_SOUNDCONFIG_H__
#include <gtkmm/dialog.h>
#include <gtkmm/builder.h>
#include <gtkmm/combobox.h>
#include "configfile.h"
#include "window.h"
namespace VBA
{
class SoundConfigDialog : public Gtk::Dialog
{
public:
SoundConfigDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
void vSetConfig(Config::Section * _poConfig, VBA::Window * _poWindow);
private:
void vOnVolumeChanged();
void vOnRateChanged();
VBA::Window * m_poWindow;
Config::Section * m_poConfig;
Gtk::ComboBox * m_poVolumeComboBox;
Gtk::ComboBox * m_poRateComboBox;
};
} // namespace VBA
#endif // __VBA_SOUNDCONFIG_H__

151
src/gtk/ui/sound.ui Normal file
View File

@ -0,0 +1,151 @@
<?xml version="1.0"?>
<!--Generated with glade3 3.4.5 on Tue Dec 23 13:54:59 2008 -->
<interface>
<object class="GtkListStore" id="model1">
<columns>
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0">Mute</col>
</row>
<row>
<col id="0">25 %</col>
</row>
<row>
<col id="0">50 %</col>
</row>
<row>
<col id="0">100 %</col>
</row>
<row>
<col id="0">200 %</col>
</row>
</data>
</object>
<object class="GtkListStore" id="model2">
<columns>
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0">11 KHz</col>
</row>
<row>
<col id="0">22 KHz</col>
</row>
<row>
<col id="0">44 KHz</col>
</row>
</data>
</object>
<object class="GtkDialog" id="SoundConfigDialog">
<property name="border_width">5</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>
<property name="spacing">2</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="border_width">10</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">10</property>
<property name="row_spacing">10</property>
<child>
<object class="GtkComboBox" id="VolumeComboBox">
<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="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Volume : </property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Sample rate : </property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="RateComboBox">
<property name="visible">True</property>
<property name="model">model2</property>
<child>
<object class="GtkCellRendererText" id="renderer2"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">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

@ -604,101 +604,6 @@
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="SoundMenu">
<property name="visible">True</property>
<property name="label" translatable="yes">_Sound</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="SoundMenu_menu">
<child>
<widget class="GtkCheckMenuItem" id="SoundMute">
<property name="visible">True</property>
<property name="label" translatable="yes">Mute</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator11">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="Sound11Khz">
<property name="visible">True</property>
<property name="label" translatable="yes">11 _Khz</property>
<property name="use_underline">True</property>
<property name="active">True</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="Sound22Khz">
<property name="visible">True</property>
<property name="label" translatable="yes">22 K_hz</property>
<property name="use_underline">True</property>
<property name="group">Sound11Khz</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="Sound44Khz">
<property name="visible">True</property>
<property name="label" translatable="yes">44 Kh_z</property>
<property name="use_underline">True</property>
<property name="group">Sound11Khz</property>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator15">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="VolumeMenu">
<property name="visible">True</property>
<property name="label" translatable="yes">_Volume</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="VolumeMenu_menu">
<child>
<widget class="GtkRadioMenuItem" id="Volume25">
<property name="visible">True</property>
<property name="label" translatable="yes">25%</property>
<property name="use_underline">True</property>
<property name="active">True</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="Volume50">
<property name="visible">True</property>
<property name="label" translatable="yes">50%</property>
<property name="use_underline">True</property>
<property name="group">Volume25</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="Volume100">
<property name="visible">True</property>
<property name="label" translatable="yes">100%</property>
<property name="use_underline">True</property>
<property name="group">Volume25</property>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="Volume200">
<property name="visible">True</property>
<property name="label" translatable="yes">200%</property>
<property name="use_underline">True</property>
<property name="group">Volume25</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="GameboyMenu">
<property name="visible">True</property>
@ -784,6 +689,13 @@
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="SoundConfigure">
<property name="visible">True</property>
<property name="label" translatable="yes">_Sound ...</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="DirectoriesConfigure">
<property name="visible">True</property>

View File

@ -144,6 +144,8 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
vApplyConfigScreenArea();
vApplyConfigFilter();
vApplyConfigFilterIB();
vApplyConfigMute();
vApplyConfigVolume();
Gtk::MenuItem * poMI;
Gtk::CheckMenuItem * poCMI;
@ -389,68 +391,6 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
poCMI, astFlashSize[i].m_iFlashSize));
}
// Sound menu
//
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("SoundMute"));
poCMI->set_active(m_poSoundConfig->oGetKey<bool>("mute"));
vOnSoundMuteToggled(poCMI);
poCMI->signal_toggled().connect(sigc::bind(
sigc::mem_fun(*this, &Window::vOnSoundMuteToggled),
poCMI));
struct
{
const char * m_csName;
const ESoundQuality m_eSoundQuality;
}
astSoundQuality[] =
{
{ "Sound11Khz", Sound11K },
{ "Sound22Khz", Sound22K },
{ "Sound44Khz", Sound44K }
};
ESoundQuality eDefaultSoundQuality = (ESoundQuality)m_poSoundConfig->oGetKey<int>("quality");
for (guint i = 0; i < G_N_ELEMENTS(astSoundQuality); i++)
{
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astSoundQuality[i].m_csName));
if (astSoundQuality[i].m_eSoundQuality == eDefaultSoundQuality)
{
poCMI->set_active();
vOnSoundQualityToggled(poCMI, eDefaultSoundQuality);
}
poCMI->signal_toggled().connect(sigc::bind(
sigc::mem_fun(*this, &Window::vOnSoundQualityToggled),
poCMI, astSoundQuality[i].m_eSoundQuality));
}
// Volume menu
//
struct
{
const char * m_csName;
const float m_fSoundVolume;
}
astSoundVolume[] =
{
{ "Volume25", 0.25f },
{ "Volume50", 0.50f },
{ "Volume100", 1.00f },
{ "Volume200", 2.00f }
};
float fDefaultSoundVolume = m_poSoundConfig->oGetKey<float>("volume");
for (guint i = 0; i < G_N_ELEMENTS(astSoundVolume); i++)
{
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget(astSoundVolume[i].m_csName));
if (astSoundVolume[i].m_fSoundVolume == fDefaultSoundVolume)
{
poCMI->set_active();
vOnSoundVolumeToggled(poCMI, fDefaultSoundVolume);
}
poCMI->signal_toggled().connect(sigc::bind(
sigc::mem_fun(*this, &Window::vOnSoundVolumeToggled),
poCMI, astSoundVolume[i].m_fSoundVolume));
}
// Gameboy menu
//
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("GameboyBorder"));
@ -499,6 +439,10 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("DisplayConfigure"));
poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnDisplayConfigure));
// Sound menu
poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("SoundConfigure"));
poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnSoundConfigure));
// Joypad menu
//
poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("JoypadConfigure"));
@ -979,14 +923,14 @@ void Window::vApplyConfigVolume()
void Window::vApplyConfigSoundQuality()
{
m_eSoundQuality = (ESoundQuality)m_poSoundConfig->oGetKey<int>("quality");
ESoundQuality eSoundQuality = (ESoundQuality)m_poSoundConfig->oGetKey<int>("quality");
if (m_eCartridge == CartridgeGBA)
{
soundSetQuality(m_eSoundQuality);
soundSetQuality(eSoundQuality);
}
else if (m_eCartridge == CartridgeGB)
{
gbSoundSetQuality(m_eSoundQuality);
gbSoundSetQuality(eSoundQuality);
}
}
@ -1132,14 +1076,7 @@ bool Window::bLoadROM(const std::string & _rsFile)
emulating = 1;
m_bWasEmulating = false;
if (m_eCartridge == CartridgeGBA)
{
soundSetQuality(m_eSoundQuality);
}
else
{
gbSoundSetQuality(m_eSoundQuality);
}
vApplyConfigSoundQuality();
vUpdateGameSlots();
vHistoryAdd(_rsFile);

View File

@ -61,6 +61,13 @@ public:
OutputXvideo
};
enum ESoundQuality
{
Sound44K = 1,
Sound22K = 2,
Sound11K = 4
};
// GB/GBA screen sizes
const int m_iGBScreenWidth;
const int m_iGBScreenHeight;
@ -114,13 +121,6 @@ protected:
SoundOn
};
enum ESoundQuality
{
Sound44K = 1,
Sound22K = 2,
Sound11K = 4
};
enum EEmulatorType
{
EmulatorAuto,
@ -160,14 +160,12 @@ 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 vOnSoundMuteToggled(Gtk::CheckMenuItem * _poCMI);
virtual void vOnSoundQualityToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundQuality);
virtual void vOnSoundVolumeToggled(Gtk::CheckMenuItem * _poCMI, float _fSoundVolume);
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 vOnHelpAbout();
virtual bool bOnEmuIdle();
@ -261,7 +259,6 @@ private:
bool m_bWasEmulating;
bool m_bAutoFrameskip;
EShowSpeed m_eShowSpeed;
ESoundQuality m_eSoundQuality;
void vInitSystem();
void vUnInitSystem();

View File

@ -39,6 +39,7 @@
#include "joypadconfig.h"
#include "directoriesconfig.h"
#include "displayconfig.h"
#include "soundconfig.h"
namespace VBA
{
@ -471,35 +472,6 @@ void Window::vOnFlashSizeToggled(Gtk::CheckMenuItem * _poCMI, int _iFlashSize)
m_poCoreConfig->vSetKey("flash_size", _iFlashSize);
}
void Window::vOnSoundMuteToggled(Gtk::CheckMenuItem * _poCMI)
{
bool bMute = _poCMI->get_active();
m_poSoundConfig->vSetKey("mute", bMute);
vApplyConfigMute();
}
void Window::vOnSoundQualityToggled(Gtk::CheckMenuItem * _poCMI, int _iSoundQuality)
{
if (! _poCMI->get_active())
{
return;
}
m_poSoundConfig->vSetKey("quality", _iSoundQuality);
vApplyConfigSoundQuality();
}
void Window::vOnSoundVolumeToggled(Gtk::CheckMenuItem * _poCMI, float _fSoundVolume)
{
if (! _poCMI->get_active())
{
return;
}
m_poSoundConfig->vSetKey("volume", _fSoundVolume);
vApplyConfigVolume();
}
void Window::vOnGBBorderToggled(Gtk::CheckMenuItem * _poCMI)
{
gbBorderOn = _poCMI->get_active();
@ -550,6 +522,19 @@ void Window::vOnDisplayConfigure()
poDialog->hide();
}
void Window::vOnSoundConfigure()
{
std::string sUiFile = sGetUiFilePath("sound.ui");
Glib::RefPtr<Gtk::Builder> poBuilder = Gtk::Builder::create_from_file(sUiFile);
SoundConfigDialog * poDialog = 0;
poBuilder->get_widget_derived("SoundConfigDialog", poDialog);
poDialog->vSetConfig(m_poSoundConfig, this);
poDialog->set_transient_for(*this);
poDialog->run();
poDialog->hide();
}
void Window::vOnHelpAbout()
{
Gtk::AboutDialog oAboutDialog;