| 1 |
/* |
| 2 |
* Copyright (C) 2017-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "DialogGameVideoFilter.h" |
| 10 |
|
| 11 |
#include "cores/RetroPlayer/guibridge/GUIGameVideoHandle.h" |
| 12 |
#include "cores/RetroPlayer/rendering/RenderVideoSettings.h" |
| 13 |
#include "guilib/LocalizeStrings.h" |
| 14 |
#include "guilib/WindowIDs.h" |
| 15 |
#include "settings/GameSettings.h" |
| 16 |
#include "settings/MediaSettings.h" |
| 17 |
#include "utils/StringUtils.h" |
| 18 |
#include "utils/Variant.h" |
| 19 |
|
| 20 |
using namespace KODI; |
| 21 |
using namespace GAME; |
| 22 |
|
| 23 |
namespace |
| 24 |
{ |
| 25 |
struct ScalingMethodProperties |
| 26 |
{ |
| 27 |
int nameIndex; |
| 28 |
int categoryIndex; |
| 29 |
int descriptionIndex; |
| 30 |
RETRO::SCALINGMETHOD scalingMethod; |
| 31 |
}; |
| 32 |
|
| 33 |
const std::vector<ScalingMethodProperties> scalingMethods = { |
| 34 |
{16301, 16296, 16298, RETRO::SCALINGMETHOD::NEAREST}, |
| 35 |
{16302, 16297, 16299, RETRO::SCALINGMETHOD::LINEAR}, |
| 36 |
}; |
| 37 |
} // namespace |
| 38 |
|
| 39 |
CDialogGameVideoFilter::CDialogGameVideoFilter() |
| 40 |
: CDialogGameVideoSelect(WINDOW_DIALOG_GAME_VIDEO_FILTER) |
| 41 |
{ |
| 42 |
} |
| 43 |
|
| 44 |
std::string CDialogGameVideoFilter::GetHeading() |
| 45 |
{ |
| 46 |
return g_localizeStrings.Get(35225); // "Video filter" |
| 47 |
} |
| 48 |
|
| 49 |
void CDialogGameVideoFilter::PreInit() |
| 50 |
{ |
| 51 |
m_items.Clear(); |
| 52 |
|
| 53 |
InitVideoFilters(); |
| 54 |
|
| 55 |
if (m_items.Size() == 0) |
| 56 |
{ |
| 57 |
CFileItemPtr item = std::make_shared<CFileItem>(g_localizeStrings.Get(231)); // "None" |
| 58 |
m_items.Add(std::move(item)); |
| 59 |
} |
| 60 |
|
| 61 |
m_bHasDescription = false; |
| 62 |
} |
| 63 |
|
| 64 |
void CDialogGameVideoFilter::InitVideoFilters() |
| 65 |
{ |
| 66 |
if (m_gameVideoHandle) |
| 67 |
{ |
| 68 |
for (const auto& scalingMethodProps : scalingMethods) |
| 69 |
{ |
| 70 |
if (m_gameVideoHandle->SupportsScalingMethod(scalingMethodProps.scalingMethod)) |
| 71 |
{ |
| 72 |
RETRO::CRenderVideoSettings videoSettings; |
| 73 |
videoSettings.SetScalingMethod(scalingMethodProps.scalingMethod); |
| 74 |
|
| 75 |
CFileItemPtr item = |
| 76 |
std::make_shared<CFileItem>(g_localizeStrings.Get(scalingMethodProps.nameIndex)); |
| 77 |
item->SetLabel2(g_localizeStrings.Get(scalingMethodProps.categoryIndex)); |
| 78 |
item->SetProperty("game.videofilter", CVariant{videoSettings.GetVideoFilter()}); |
| 79 |
item->SetProperty("game.videofilterdescription", |
| 80 |
CVariant{g_localizeStrings.Get(scalingMethodProps.descriptionIndex)}); |
| 81 |
m_items.Add(std::move(item)); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
void CDialogGameVideoFilter::GetItems(CFileItemList& items) |
| 88 |
{ |
| 89 |
for (const auto& item : m_items) |
| 90 |
items.Add(item); |
| 91 |
} |
| 92 |
|
| 93 |
void CDialogGameVideoFilter::OnItemFocus(unsigned int index) |
| 94 |
{ |
| 95 |
if (static_cast<int>(index) < m_items.Size()) |
| 96 |
{ |
| 97 |
CFileItemPtr item = m_items[index]; |
| 98 |
|
| 99 |
std::string videoFilter; |
| 100 |
std::string description; |
| 101 |
GetProperties(*item, videoFilter, description); |
| 102 |
|
| 103 |
CGameSettings& gameSettings = CMediaSettings::GetInstance().GetCurrentGameSettings(); |
| 104 |
|
| 105 |
if (gameSettings.VideoFilter() != videoFilter) |
| 106 |
{ |
| 107 |
gameSettings.SetVideoFilter(videoFilter); |
| 108 |
gameSettings.NotifyObservers(ObservableMessageSettingsChanged); |
| 109 |
|
| 110 |
OnDescriptionChange(description); |
| 111 |
m_bHasDescription = true; |
| 112 |
} |
| 113 |
else if (!m_bHasDescription) |
| 114 |
{ |
| 115 |
OnDescriptionChange(description); |
| 116 |
m_bHasDescription = true; |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
unsigned int CDialogGameVideoFilter::GetFocusedItem() const |
| 122 |
{ |
| 123 |
CGameSettings& gameSettings = CMediaSettings::GetInstance().GetCurrentGameSettings(); |
| 124 |
|
| 125 |
for (int i = 0; i < m_items.Size(); i++) |
| 126 |
{ |
| 127 |
std::string videoFilter; |
| 128 |
std::string description; |
| 129 |
GetProperties(*m_items[i], videoFilter, description); |
| 130 |
|
| 131 |
if (videoFilter == gameSettings.VideoFilter()) |
| 132 |
{ |
| 133 |
return i; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
void CDialogGameVideoFilter::PostExit() |
| 141 |
{ |
| 142 |
m_items.Clear(); |
| 143 |
} |
| 144 |
|
| 145 |
bool CDialogGameVideoFilter::OnClickAction() |
| 146 |
{ |
| 147 |
Close(); |
| 148 |
return true; |
| 149 |
} |
| 150 |
|
| 151 |
void CDialogGameVideoFilter::GetProperties(const CFileItem& item, |
| 152 |
std::string& videoFilter, |
| 153 |
std::string& description) |
| 154 |
{ |
| 155 |
videoFilter = item.GetProperty("game.videofilter").asString(); |
| 156 |
description = item.GetProperty("game.videofilterdescription").asString(); |
| 157 |
} |