2015-03-18 18:00:27 -04:00
// Copyright 2015 Dolphin Emulator Project
2015-05-18 01:08:10 +02:00
// Licensed under GPLv2+
2015-03-18 18:00:27 -04:00
// Refer to the license.txt file included.
#include <string>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/choice.h>
2015-12-08 02:13:32 +01:00
#include <wx/gbsizer.h>
2015-03-18 18:00:27 -04:00
#include <wx/language.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include "Common/CommonPaths.h"
#include "Common/FileSearch.h"
#include "Common/FileUtil.h"
#include "Core/ConfigManager.h"
#include "Core/HotkeyManager.h"
#include "DolphinWX/Frame.h"
#include "DolphinWX/InputConfigDiag.h"
#include "DolphinWX/Main.h"
#include "DolphinWX/WxUtils.h"
#include "DolphinWX/Config/InterfaceConfigPane.h"
#if defined(HAVE_XRANDR) && HAVE_XRANDR
#include "DolphinWX/X11Utils.h"
#endif
static const wxLanguage language_ids [] =
{
wxLANGUAGE_DEFAULT ,
2016-05-23 08:58:30 +02:00
wxLANGUAGE_MALAY ,
2015-03-18 18:00:27 -04:00
wxLANGUAGE_CATALAN ,
wxLANGUAGE_CZECH ,
2016-05-23 08:58:30 +02:00
wxLANGUAGE_DANISH ,
2015-03-18 18:00:27 -04:00
wxLANGUAGE_GERMAN ,
wxLANGUAGE_ENGLISH ,
wxLANGUAGE_SPANISH ,
wxLANGUAGE_FRENCH ,
2016-05-23 08:58:30 +02:00
wxLANGUAGE_CROATIAN ,
2015-03-18 18:00:27 -04:00
wxLANGUAGE_ITALIAN ,
wxLANGUAGE_HUNGARIAN ,
wxLANGUAGE_DUTCH ,
wxLANGUAGE_NORWEGIAN_BOKMAL ,
wxLANGUAGE_POLISH ,
wxLANGUAGE_PORTUGUESE ,
wxLANGUAGE_PORTUGUESE_BRAZILIAN ,
2016-05-23 08:58:30 +02:00
wxLANGUAGE_ROMANIAN ,
2015-03-18 18:00:27 -04:00
wxLANGUAGE_SERBIAN ,
wxLANGUAGE_SWEDISH ,
wxLANGUAGE_TURKISH ,
wxLANGUAGE_GREEK ,
wxLANGUAGE_RUSSIAN ,
wxLANGUAGE_ARABIC ,
wxLANGUAGE_FARSI ,
wxLANGUAGE_KOREAN ,
wxLANGUAGE_JAPANESE ,
wxLANGUAGE_CHINESE_SIMPLIFIED ,
wxLANGUAGE_CHINESE_TRADITIONAL ,
};
InterfaceConfigPane :: InterfaceConfigPane ( wxWindow * parent , wxWindowID id )
: wxPanel ( parent , id )
{
InitializeGUI ();
LoadGUIValues ();
}
void InterfaceConfigPane :: InitializeGUI ()
{
// GUI language arrayStrings
2016-05-23 08:58:30 +02:00
// keep these in sync with the language_ids array at the beginning of this file
2015-03-18 18:00:27 -04:00
m_interface_lang_strings . Add ( _ ( "<System Language>" ));
2016-05-23 08:58:30 +02:00
m_interface_lang_strings . Add ( L "Bahasa Melayu" ); // Malay
2015-03-18 18:00:27 -04:00
m_interface_lang_strings . Add ( L "Catal \u00E0 " ); // Catalan
m_interface_lang_strings . Add ( L " \u010C e \u0161 tina" ); // Czech
2016-05-23 08:58:30 +02:00
m_interface_lang_strings . Add ( L "Dansk" ); // Danish
2015-03-18 18:00:27 -04:00
m_interface_lang_strings . Add ( L "Deutsch" ); // German
m_interface_lang_strings . Add ( L "English" ); // English
m_interface_lang_strings . Add ( L "Espa \u00F1 ol" ); // Spanish
m_interface_lang_strings . Add ( L "Fran \u00E7 ais" ); // French
2016-05-23 08:58:30 +02:00
m_interface_lang_strings . Add ( L "Hrvatski" ); // Croatian
2015-03-18 18:00:27 -04:00
m_interface_lang_strings . Add ( L "Italiano" ); // Italian
m_interface_lang_strings . Add ( L "Magyar" ); // Hungarian
m_interface_lang_strings . Add ( L "Nederlands" ); // Dutch
m_interface_lang_strings . Add ( L "Norsk bokm \u00E5 l" ); // Norwegian
m_interface_lang_strings . Add ( L "Polski" ); // Polish
m_interface_lang_strings . Add ( L "Portugu \u00EA s" ); // Portuguese
m_interface_lang_strings . Add ( L "Portugu \u00EA s (Brasil)" ); // Portuguese (Brazil)
2016-05-23 08:58:30 +02:00
m_interface_lang_strings . Add ( L "Rom \u00E2 n \u0103 " ); // Romanian
2015-03-18 18:00:27 -04:00
m_interface_lang_strings . Add ( L "Srpski" ); // Serbian
m_interface_lang_strings . Add ( L "Svenska" ); // Swedish
m_interface_lang_strings . Add ( L "T \u00FC rk \u00E7 e" ); // Turkish
2016-05-23 08:58:30 +02:00
2015-03-18 18:00:27 -04:00
m_interface_lang_strings . Add ( L " \u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC " ); // Greek
m_interface_lang_strings . Add ( L " \u0420\u0443\u0441\u0441\u043A\u0438\u0439 " ); // Russian
m_interface_lang_strings . Add ( L " \u0627\u0644\u0639\u0631\u0628\u064A\u0629 " ); // Arabic
m_interface_lang_strings . Add ( L " \u0641\u0627\u0631\u0633\u06CC " ); // Farsi
m_interface_lang_strings . Add ( L " \uD55C\uAD6D\uC5B4 " ); // Korean
m_interface_lang_strings . Add ( L " \u65E5\u672C\u8A9E " ); // Japanese
m_interface_lang_strings . Add ( L " \u7B80\u4F53\u4E2D\u6587 " ); // Simplified Chinese
m_interface_lang_strings . Add ( L " \u7E41\u9AD4\u4E2D\u6587 " ); // Traditional Chinese
m_confirm_stop_checkbox = new wxCheckBox ( this , wxID_ANY , _ ( "Confirm on Stop" ));
m_panic_handlers_checkbox = new wxCheckBox ( this , wxID_ANY , _ ( "Use Panic Handlers" ));
m_osd_messages_checkbox = new wxCheckBox ( this , wxID_ANY , _ ( "On-Screen Display Messages" ));
m_pause_focus_lost_checkbox = new wxCheckBox ( this , wxID_ANY , _ ( "Pause on Focus Lost" ));
m_interface_lang_choice = new wxChoice ( this , wxID_ANY , wxDefaultPosition , wxDefaultSize , m_interface_lang_strings );
m_theme_choice = new wxChoice ( this , wxID_ANY );
m_confirm_stop_checkbox -> Bind ( wxEVT_CHECKBOX , & InterfaceConfigPane :: OnConfirmStopCheckBoxChanged , this );
m_panic_handlers_checkbox -> Bind ( wxEVT_CHECKBOX , & InterfaceConfigPane :: OnPanicHandlersCheckBoxChanged , this );
m_osd_messages_checkbox -> Bind ( wxEVT_CHECKBOX , & InterfaceConfigPane :: OnOSDMessagesCheckBoxChanged , this );
m_pause_focus_lost_checkbox -> Bind ( wxEVT_CHECKBOX , & InterfaceConfigPane :: OnPauseOnFocusLostCheckBoxChanged , this );
m_interface_lang_choice -> Bind ( wxEVT_CHOICE , & InterfaceConfigPane :: OnInterfaceLanguageChoiceChanged , this );
m_theme_choice -> Bind ( wxEVT_CHOICE , & InterfaceConfigPane :: OnThemeSelected , this );
m_confirm_stop_checkbox -> SetToolTip ( _ ( "Show a confirmation box before stopping a game." ));
m_panic_handlers_checkbox -> SetToolTip ( _ ( "Show a message box when a potentially serious error has occurred. \n Disabling this may avoid annoying and non-fatal messages, but it may result in major crashes having no explanation at all." ));
m_osd_messages_checkbox -> SetToolTip ( _ ( "Display messages over the emulation screen area. \n These messages include memory card writes, video backend and CPU information, and JIT cache clearing." ));
m_pause_focus_lost_checkbox -> SetToolTip ( _ ( "Pauses the emulator when focus is taken away from the emulation window." ));
m_interface_lang_choice -> SetToolTip ( _ ( "Change the language of the user interface. \n Requires restart." ));
2015-12-08 02:13:32 +01:00
wxGridBagSizer * const language_and_theme_grid_sizer = new wxGridBagSizer ();
language_and_theme_grid_sizer -> Add ( new wxStaticText ( this , wxID_ANY , _ ( "Language:" )), wxGBPosition ( 0 , 0 ), wxDefaultSpan , wxALIGN_CENTER_VERTICAL | wxALL , 5 );
language_and_theme_grid_sizer -> Add ( m_interface_lang_choice , wxGBPosition ( 0 , 1 ), wxDefaultSpan , wxALL , 5 );
language_and_theme_grid_sizer -> Add ( new wxStaticText ( this , wxID_ANY , _ ( "Theme:" )), wxGBPosition ( 1 , 0 ), wxDefaultSpan , wxALIGN_CENTER_VERTICAL | wxALL , 5 );
language_and_theme_grid_sizer -> Add ( m_theme_choice , wxGBPosition ( 1 , 1 ), wxDefaultSpan , wxALL , 5 );
2015-03-18 18:00:27 -04:00
wxStaticBoxSizer * const main_static_box_sizer = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( "Interface Settings" ));
main_static_box_sizer -> Add ( m_confirm_stop_checkbox , 0 , wxALL , 5 );
main_static_box_sizer -> Add ( m_panic_handlers_checkbox , 0 , wxALL , 5 );
main_static_box_sizer -> Add ( m_osd_messages_checkbox , 0 , wxALL , 5 );
main_static_box_sizer -> Add ( m_pause_focus_lost_checkbox , 0 , wxALL , 5 );
2015-12-08 02:13:32 +01:00
main_static_box_sizer -> Add ( language_and_theme_grid_sizer , 0 , wxEXPAND | wxALL , 0 );
2015-03-18 18:00:27 -04:00
wxBoxSizer * const main_box_sizer = new wxBoxSizer ( wxVERTICAL );
main_box_sizer -> Add ( main_static_box_sizer , 0 , wxEXPAND | wxALL , 5 );
SetSizer ( main_box_sizer );
}
void InterfaceConfigPane :: LoadGUIValues ()
{
2015-06-12 13:56:53 +02:00
const SConfig & startup_params = SConfig :: GetInstance ();
2015-03-18 18:00:27 -04:00
m_confirm_stop_checkbox -> SetValue ( startup_params . bConfirmStop );
m_panic_handlers_checkbox -> SetValue ( startup_params . bUsePanicHandlers );
m_osd_messages_checkbox -> SetValue ( startup_params . bOnScreenDisplayMessages );
m_pause_focus_lost_checkbox -> SetValue ( SConfig :: GetInstance (). m_PauseOnFocusLost );
for ( size_t i = 0 ; i < sizeof ( language_ids ) / sizeof ( wxLanguage ); i ++ )
{
if ( language_ids [ i ] == SConfig :: GetInstance (). m_InterfaceLanguage )
{
m_interface_lang_choice -> SetSelection ( i );
break ;
}
}
LoadThemes ();
}
void InterfaceConfigPane :: LoadThemes ()
{
2015-09-21 20:01:08 -04:00
auto sv = DoFileSearch ({ "" }, {
2014-11-15 15:46:40 -05:00
File :: GetUserPath ( D_THEMES_IDX ),
File :: GetSysDirectory () + THEMES_DIR
}, /*recursive*/ false );
2015-03-18 18:00:27 -04:00
for ( const std :: string & filename : sv )
{
std :: string name , ext ;
SplitPath ( filename , nullptr , & name , & ext );
name += ext ;
const wxString wxname = StrToWxStr ( name );
if ( - 1 == m_theme_choice -> FindString ( wxname ))
m_theme_choice -> Append ( wxname );
}
2015-06-12 13:56:53 +02:00
m_theme_choice -> SetStringSelection ( StrToWxStr ( SConfig :: GetInstance (). theme_name ));
2015-03-18 18:00:27 -04:00
}
void InterfaceConfigPane :: OnConfirmStopCheckBoxChanged ( wxCommandEvent & event )
{
2015-06-12 13:56:53 +02:00
SConfig :: GetInstance (). bConfirmStop = m_confirm_stop_checkbox -> IsChecked ();
2015-03-18 18:00:27 -04:00
}
void InterfaceConfigPane :: OnPanicHandlersCheckBoxChanged ( wxCommandEvent & event )
{
2015-06-12 13:56:53 +02:00
SConfig :: GetInstance (). bUsePanicHandlers = m_panic_handlers_checkbox -> IsChecked ();
2015-03-18 18:00:27 -04:00
SetEnableAlert ( m_panic_handlers_checkbox -> IsChecked ());
}
void InterfaceConfigPane :: OnOSDMessagesCheckBoxChanged ( wxCommandEvent & event )
{
2015-06-12 13:56:53 +02:00
SConfig :: GetInstance (). bOnScreenDisplayMessages = m_osd_messages_checkbox -> IsChecked ();
2015-03-18 18:00:27 -04:00
}
void InterfaceConfigPane :: OnInterfaceLanguageChoiceChanged ( wxCommandEvent & event )
{
if ( SConfig :: GetInstance (). m_InterfaceLanguage != language_ids [ m_interface_lang_choice -> GetSelection ()])
SuccessAlertT ( "You must restart Dolphin in order for the change to take effect." );
SConfig :: GetInstance (). m_InterfaceLanguage = language_ids [ m_interface_lang_choice -> GetSelection ()];
}
void InterfaceConfigPane :: OnPauseOnFocusLostCheckBoxChanged ( wxCommandEvent & event )
{
SConfig :: GetInstance (). m_PauseOnFocusLost = m_pause_focus_lost_checkbox -> IsChecked ();
}
void InterfaceConfigPane :: OnThemeSelected ( wxCommandEvent & event )
{
2015-06-12 13:56:53 +02:00
SConfig :: GetInstance (). theme_name = WxStrToStr ( m_theme_choice -> GetStringSelection ());
2015-03-18 18:00:27 -04:00
main_frame -> InitBitmaps ();
main_frame -> UpdateGameList ();
}