Fix keymap.
[vuplus_xbmc] / xbmc / settings / DisplaySettings.h
1 #pragma once
2 /*
3  *      Copyright (C) 2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <map>
23 #include <set>
24 #include <vector>
25
26 #include "guilib/Resolution.h"
27 #include "settings/lib/ISettingCallback.h"
28 #include "settings/lib/ISubSettings.h"
29 #include "threads/CriticalSection.h"
30 #include "utils/Observer.h"
31
32 class TiXmlNode;
33
34 class CDisplaySettings : public ISettingCallback, public ISubSettings,
35                          public Observable
36 {
37 public:
38   static CDisplaySettings& Get();
39
40   virtual bool Load(const TiXmlNode *settings);
41   virtual bool Save(TiXmlNode *settings) const;
42   virtual void Clear();
43
44   virtual bool OnSettingChanging(const CSetting *setting);
45   virtual bool OnSettingUpdate(CSetting* &setting, const char *oldSettingId, const TiXmlNode *oldSettingNode);
46
47   /*!
48    \brief Returns the currently active resolution
49
50    This resolution might differ from the display resolution which is based on
51    the user's settings.
52
53    \sa SetCurrentResolution
54    \sa GetResolutionInfo
55    \sa GetDisplayResolution
56    */
57   RESOLUTION GetCurrentResolution() const { return m_currentResolution; }
58   void SetCurrentResolution(RESOLUTION resolution, bool save = false);
59   /*!
60    \brief Returns the best-matching resolution of the videoscreen.screenmode setting value
61
62    This resolution might differ from the current resolution which is based on
63    the properties of the operating system and the attached displays.
64
65    \sa GetCurrentResolution
66    */
67   RESOLUTION GetDisplayResolution() const;
68
69   const RESOLUTION_INFO& GetResolutionInfo(size_t index) const;
70   const RESOLUTION_INFO& GetResolutionInfo(RESOLUTION resolution) const;
71   RESOLUTION_INFO& GetResolutionInfo(size_t index);
72   RESOLUTION_INFO& GetResolutionInfo(RESOLUTION resolution);
73   size_t ResolutionInfoSize() const { return m_resolutions.size(); }
74   void AddResolutionInfo(const RESOLUTION_INFO &resolution);
75
76   const RESOLUTION_INFO& GetCurrentResolutionInfo() const { return GetResolutionInfo(m_currentResolution); }
77   RESOLUTION_INFO& GetCurrentResolutionInfo() { return GetResolutionInfo(m_currentResolution); }
78
79   void ApplyCalibrations();
80   void UpdateCalibrations();
81
82   float GetZoomAmount() const { return m_zoomAmount; }
83   void SetZoomAmount(float zoomAmount) { m_zoomAmount = zoomAmount; }
84   float GetPixelRatio() const { return m_pixelRatio; }
85   void SetPixelRatio(float pixelRatio) { m_pixelRatio = pixelRatio; }
86   float GetVerticalShift() const { return m_verticalShift; }
87   void SetVerticalShift(float verticalShift) { m_verticalShift = verticalShift; }
88   bool IsNonLinearStretched() const { return m_nonLinearStretched; }
89   void SetNonLinearStretched(bool nonLinearStretch) { m_nonLinearStretched = nonLinearStretch; }
90
91   static void SettingOptionsRefreshChangeDelaysFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int &current);
92   static void SettingOptionsRefreshRatesFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
93   static void SettingOptionsResolutionsFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int &current);
94   static void SettingOptionsScreensFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int &current);
95   static void SettingOptionsVerticalSyncsFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int &current);
96   static void SettingOptionsStereoscopicModesFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int &current);
97   static void SettingOptionsPreferredStereoscopicViewModesFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int &current);
98
99 protected:
100   CDisplaySettings();
101   CDisplaySettings(const CDisplaySettings&);
102   CDisplaySettings& operator=(CDisplaySettings const&);
103   virtual ~CDisplaySettings();
104
105   DisplayMode GetCurrentDisplayMode() const;
106
107   static RESOLUTION GetResolutionFromString(const std::string &strResolution);
108   static std::string GetStringFromResolution(RESOLUTION resolution, float refreshrate = 0.0f);
109   static RESOLUTION GetResolutionForScreen();
110
111   static RESOLUTION FindBestMatchingResolution(const std::map<RESOLUTION, RESOLUTION_INFO> &resolutionInfos, int screen, int width, int height, float refreshrate, unsigned int flags);
112
113 private:
114   // holds the real gui resolution
115   RESOLUTION m_currentResolution;
116
117   typedef std::vector<RESOLUTION_INFO> ResolutionInfos;
118   ResolutionInfos m_resolutions;
119   ResolutionInfos m_calibrations;
120
121   float m_zoomAmount;         // current zoom amount
122   float m_pixelRatio;         // current pixel ratio
123   float m_verticalShift;      // current vertical shift
124   bool  m_nonLinearStretched;   // current non-linear stretch
125
126   bool m_resolutionChangeAborted;
127   CCriticalSection m_critical;
128 };