| 1 |
/* |
| 2 |
Copyright (C) 2009-2013 wxLauncher Team |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License |
| 6 |
as published by the Free Software Foundation; either version 2 |
| 7 |
of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "datastructures/ResolutionMap.h" |
| 20 |
|
| 21 |
#include <wx/hashmap.h> |
| 22 |
|
| 23 |
#include "controls/ModList.h" |
| 24 |
#include "apis/EventHandlers.h" |
| 25 |
|
| 26 |
LAUNCHER_DEFINE_EVENT_TYPE(EVT_RESOLUTION_MAP_CHANGED); |
| 27 |
|
| 28 |
EventHandlers ResolutionMap::resolutionMapChangedHandlers; |
| 29 |
|
| 30 |
PreferredResolutionMap ResolutionMap::prefResMap; |
| 31 |
|
| 32 |
const ResolutionData* ResolutionMap::ResolutionRead(const wxString& shortname) { |
| 33 |
PreferredResolutionMap::const_iterator it = prefResMap.find(shortname); |
| 34 |
|
| 35 |
return (it == prefResMap.end()) ? NULL : &it->second; |
| 36 |
} |
| 37 |
|
| 38 |
void ResolutionMap::ResolutionWrite(const wxString& shortname, const ResolutionData& resData) { |
| 39 |
wxASSERT(!shortname.IsEmpty()); |
| 40 |
wxASSERT(resData.IsValid()); |
| 41 |
|
| 42 |
prefResMap[shortname] = resData; |
| 43 |
wxLogDebug(_T("Wrote resolution %ldx%ld for mod %s"), |
| 44 |
resData.width, resData.height, shortname.c_str()); |
| 45 |
GenerateResolutionMapChanged(); |
| 46 |
} |
| 47 |
|
| 48 |
bool ResolutionMap::HasEntryForActiveMod() { |
| 49 |
const ModItem* activeMod = ModList::GetActiveMod(); |
| 50 |
wxCHECK_MSG(activeMod != NULL, false, |
| 51 |
_T("HasEntryForActiveMod: activeMod is NULL!")); |
| 52 |
|
| 53 |
return prefResMap.find(activeMod->shortname) != prefResMap.end(); |
| 54 |
} |
| 55 |
|
| 56 |
void ResolutionMap::RegisterResolutionMapChanged(wxEvtHandler *handler) { |
| 57 |
wxASSERT_MSG(resolutionMapChangedHandlers.IndexOf(handler) == wxNOT_FOUND, |
| 58 |
wxString::Format( |
| 59 |
_T("RegisterResolutionMapChanged(): Handler at %p already registered."), |
| 60 |
handler)); |
| 61 |
resolutionMapChangedHandlers.Append(handler); |
| 62 |
} |
| 63 |
void ResolutionMap::UnRegisterResolutionMapChanged(wxEvtHandler *handler) { |
| 64 |
wxASSERT_MSG(resolutionMapChangedHandlers.IndexOf(handler) != wxNOT_FOUND, |
| 65 |
wxString::Format( |
| 66 |
_T("UnRegisterResolutionMapChanged(): Handler at %p not registered."), |
| 67 |
handler)); |
| 68 |
resolutionMapChangedHandlers.DeleteObject(handler); |
| 69 |
} |
| 70 |
void ResolutionMap::GenerateResolutionMapChanged() { |
| 71 |
wxCommandEvent event(EVT_RESOLUTION_MAP_CHANGED, wxID_NONE); |
| 72 |
wxLogDebug(_T("Generating EVT_RESOLUTION_MAP_CHANGED event")); |
| 73 |
EventHandlers::iterator iter = resolutionMapChangedHandlers.begin(); |
| 74 |
while (iter != resolutionMapChangedHandlers.end()) { |
| 75 |
wxEvtHandler* current = *iter; |
| 76 |
current->AddPendingEvent(event); |
| 77 |
wxLogDebug(_T(" Sent EVT_RESOLUTION_MAP_CHANGED event to %p"), current); |
| 78 |
iter++; |
| 79 |
} |
| 80 |
} |