| 1 |
/* |
| 2 |
* Copyright (C) 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 "DialogGameVideoRotation.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "guilib/LocalizeStrings.h" |
| 13 |
#include "guilib/WindowIDs.h" |
| 14 |
#include "settings/GameSettings.h" |
| 15 |
#include "settings/MediaSettings.h" |
| 16 |
#include "utils/Variant.h" |
| 17 |
|
| 18 |
using namespace KODI; |
| 19 |
using namespace GAME; |
| 20 |
|
| 21 |
CDialogGameVideoRotation::CDialogGameVideoRotation() |
| 22 |
: CDialogGameVideoSelect(WINDOW_DIALOG_GAME_VIDEO_ROTATION) |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
std::string CDialogGameVideoRotation::GetHeading() |
| 27 |
{ |
| 28 |
return g_localizeStrings.Get(35227); // "Rotation" |
| 29 |
} |
| 30 |
|
| 31 |
void CDialogGameVideoRotation::PreInit() |
| 32 |
{ |
| 33 |
m_rotations.clear(); |
| 34 |
|
| 35 |
// Present the user with clockwise rotation |
| 36 |
m_rotations.push_back(0); |
| 37 |
m_rotations.push_back(270); |
| 38 |
m_rotations.push_back(180); |
| 39 |
m_rotations.push_back(90); |
| 40 |
} |
| 41 |
|
| 42 |
void CDialogGameVideoRotation::GetItems(CFileItemList& items) |
| 43 |
{ |
| 44 |
for (unsigned int rotation : m_rotations) |
| 45 |
{ |
| 46 |
CFileItemPtr item = std::make_shared<CFileItem>(GetRotationLabel(rotation)); |
| 47 |
item->SetProperty("game.videorotation", CVariant{rotation}); |
| 48 |
items.Add(std::move(item)); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
void CDialogGameVideoRotation::OnItemFocus(unsigned int index) |
| 53 |
{ |
| 54 |
if (index < m_rotations.size()) |
| 55 |
{ |
| 56 |
const unsigned int rotationDegCCW = m_rotations[index]; |
| 57 |
|
| 58 |
CGameSettings& gameSettings = CMediaSettings::GetInstance().GetCurrentGameSettings(); |
| 59 |
if (gameSettings.RotationDegCCW() != rotationDegCCW) |
| 60 |
{ |
| 61 |
gameSettings.SetRotationDegCCW(rotationDegCCW); |
| 62 |
gameSettings.NotifyObservers(ObservableMessageSettingsChanged); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
unsigned int CDialogGameVideoRotation::GetFocusedItem() const |
| 68 |
{ |
| 69 |
CGameSettings& gameSettings = CMediaSettings::GetInstance().GetCurrentGameSettings(); |
| 70 |
|
| 71 |
for (unsigned int i = 0; i < m_rotations.size(); i++) |
| 72 |
{ |
| 73 |
const unsigned int rotationDegCCW = m_rotations[i]; |
| 74 |
if (rotationDegCCW == gameSettings.RotationDegCCW()) |
| 75 |
return i; |
| 76 |
} |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
void CDialogGameVideoRotation::PostExit() |
| 82 |
{ |
| 83 |
m_rotations.clear(); |
| 84 |
} |
| 85 |
|
| 86 |
bool CDialogGameVideoRotation::OnClickAction() |
| 87 |
{ |
| 88 |
Close(); |
| 89 |
return true; |
| 90 |
} |
| 91 |
|
| 92 |
std::string CDialogGameVideoRotation::GetRotationLabel(unsigned int rotationDegCCW) |
| 93 |
{ |
| 94 |
switch (rotationDegCCW) |
| 95 |
{ |
| 96 |
case 0: |
| 97 |
return g_localizeStrings.Get(35228); // 0 |
| 98 |
case 90: |
| 99 |
return g_localizeStrings.Get(35231); // 270 |
| 100 |
case 180: |
| 101 |
return g_localizeStrings.Get(35230); // 180 |
| 102 |
case 270: |
| 103 |
return g_localizeStrings.Get(35229); // 90 |
| 104 |
default: |
| 105 |
break; |
| 106 |
} |
| 107 |
|
| 108 |
return ""; |
| 109 |
} |