1 //////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // Nestopia - NES/Famicom emulator written in C++ 4 // 5 // Copyright (C) 2003-2008 Martin Freij 6 // 7 // This file is part of Nestopia. 8 // 9 // Nestopia is free software; you can redistribute it and/or modify 10 // it under the terms of the GNU General Public License as published by 11 // the Free Software Foundation; either version 2 of the License, or 12 // (at your option) any later version. 13 // 14 // Nestopia is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with Nestopia; if not, write to the Free Software 21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 // 23 //////////////////////////////////////////////////////////////////////////////////////// 24 25 #include "NstManager.hpp" 26 #include "NstDialogPreferences.hpp" 27 #include "NstManagerPreferences.hpp" 28 29 namespace Nestopia 30 { 31 namespace Managers 32 { 33 NST_COMPILE_ASSERT 34 ( 35 Preferences::START_IN_FULLSCREEN - Window::Preferences::START_IN_FULLSCREEN == 0 && 36 Preferences::SUPPRESS_WARNINGS - Window::Preferences::SUPPRESS_WARNINGS == 0 && 37 Preferences::FIRST_UNLOAD_ON_EXIT - Window::Preferences::FIRST_UNLOAD_ON_EXIT == 0 && 38 Preferences::CONFIRM_EXIT - Window::Preferences::CONFIRM_EXIT == 0 && 39 Preferences::RUN_IN_BACKGROUND - Window::Preferences::RUN_IN_BACKGROUND == 0 && 40 Preferences::AUTOSTART_EMULATION - Window::Preferences::AUTOSTART_EMULATION == 0 && 41 Preferences::SAVE_LOGFILE - Window::Preferences::SAVE_LOGFILE == 0 && 42 Preferences::ALLOW_MULTIPLE_INSTANCES - Window::Preferences::ALLOW_MULTIPLE_INSTANCES == 0 && 43 Preferences::SAVE_LAUNCHER - Window::Preferences::SAVE_LAUNCHER == 0 && 44 Preferences::CONFIRM_RESET - Window::Preferences::CONFIRM_RESET == 0 && 45 Preferences::SAVE_CHEATS - Window::Preferences::SAVE_CHEATS == 0 && 46 Preferences::SAVE_NETPLAY_GAMELIST - Window::Preferences::SAVE_NETPLAY_GAMELIST == 0 && 47 Preferences::SAVE_WINDOWPOS - Window::Preferences::SAVE_WINDOWPOS == 0 && 48 Preferences::SAVE_LAUNCHERSIZE - Window::Preferences::SAVE_LAUNCHERSIZE == 0 && 49 Preferences::SAVE_SETTINGS - Window::Preferences::SAVE_SETTINGS == 0 && 50 Preferences::NUM_SETTINGS - Window::Preferences::NUM_SETTINGS == 0 && 51 Preferences::DISABLE_STATUSMSG - Window::Preferences::DISABLE_STATUSMSG == 0 52 ); 53 54 NST_COMPILE_ASSERT 55 ( 56 Preferences::PRIORITY_NORMAL - Window::Preferences::PRIORITY_NORMAL == 0 && 57 Preferences::PRIORITY_ABOVE_NORMAL - Window::Preferences::PRIORITY_ABOVE_NORMAL == 0 && 58 Preferences::PRIORITY_HIGH - Window::Preferences::PRIORITY_HIGH == 0 59 ); 60 Preferences(Emulator & e,const Configuration & cfg,Window::Menu & m)61 Preferences::Preferences(Emulator& e,const Configuration& cfg,Window::Menu& m) 62 : 63 Manager ( e, m, this, &Preferences::OnEmuEvent, IDM_OPTIONS_PREFERENCES, &Preferences::OnCmdOptions, &Preferences::OnAppEvent ), 64 dialog ( new Window::Preferences(e,cfg) ), 65 inFullscreen ( false ) 66 { 67 UpdateSettings(); 68 } 69 ~Preferences()70 Preferences::~Preferences() 71 { 72 } 73 Save(Configuration & cfg) const74 void Preferences::Save(Configuration& cfg) const 75 { 76 dialog->Save( cfg ); 77 } 78 UpdateMenuColor() const79 void Preferences::UpdateMenuColor() const 80 { 81 const Window::Preferences::MenuLook& look = 82 ( 83 inFullscreen ? dialog->GetSettings().menuLookFullscreen : 84 dialog->GetSettings().menuLookDesktop 85 ); 86 87 if (look.enabled) 88 menu.SetColor( look.color ); 89 else 90 menu.ResetColor(); 91 } 92 UpdateSettings()93 void Preferences::UpdateSettings() 94 { 95 settings.flags = dialog->GetSettings(); 96 settings.priority = static_cast<Priority>(dialog->GetSettings().priority); 97 settings.favoredSystem = dialog->GetSettings().favoredSystem; 98 settings.alwaysAskSystem = dialog->GetSettings().alwaysAskSystem; 99 settings.disableStatusMsg = dialog->GetSettings().disableStatusMsg; 100 101 UpdateMenuColor(); 102 } 103 OnCmdOptions(uint)104 void Preferences::OnCmdOptions(uint) 105 { 106 dialog->Open(); 107 UpdateSettings(); 108 } 109 OnEmuEvent(const Emulator::Event event,const Emulator::Data data)110 void Preferences::OnEmuEvent(const Emulator::Event event,const Emulator::Data data) 111 { 112 switch (event) 113 { 114 case Emulator::EVENT_NETPLAY_MODE: 115 116 if (data) 117 { 118 settings.flags[RUN_IN_BACKGROUND] = true; 119 settings.flags[AUTOSTART_EMULATION] = true; 120 settings.flags[CONFIRM_RESET] = false; 121 settings.flags[SUPPRESS_WARNINGS] = true; 122 123 if (settings.priority == PRIORITY_NORMAL) 124 settings.priority = PRIORITY_ABOVE_NORMAL; 125 } 126 else 127 { 128 UpdateSettings(); 129 } 130 131 menu[IDM_OPTIONS_PREFERENCES].Enable( !data ); 132 break; 133 } 134 } 135 OnAppEvent(Instance::Event event,const void *)136 void Preferences::OnAppEvent(Instance::Event event,const void*) 137 { 138 switch (event) 139 { 140 case Instance::EVENT_FULLSCREEN: 141 case Instance::EVENT_DESKTOP: 142 143 inFullscreen = (event == Instance::EVENT_FULLSCREEN); 144 UpdateMenuColor(); 145 break; 146 } 147 } 148 } 149 } 150