Merge pull request #2900 from mus65/os-release
[vuplus_xbmc] / xbmc / settings / DisplaySettings.h
1 #pragma once
2 /*
3  *      Copyright (C) 2013 Team XBMC
4  *      http://www.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/ISettingCallback.h"
28 #include "settings/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
97 protected:
98   CDisplaySettings();
99   CDisplaySettings(const CDisplaySettings&);
100   CDisplaySettings& operator=(CDisplaySettings const&);
101   virtual ~CDisplaySettings();
102
103   DisplayMode GetCurrentDisplayMode() const;
104
105   static RESOLUTION GetResolutionFromString(const std::string &strResolution);
106   static std::string GetStringFromResolution(RESOLUTION resolution, float refreshrate = 0.0f);
107   static RESOLUTION GetResolutionForScreen();
108
109   static RESOLUTION FindBestMatchingResolution(const std::map<RESOLUTION, RESOLUTION_INFO> &resolutionInfos, int screen, int width, int height, float refreshrate, bool interlaced);
110
111 private:
112   // holds the real gui resolution
113   RESOLUTION m_currentResolution;
114
115   typedef std::vector<RESOLUTION_INFO> ResolutionInfos;
116   ResolutionInfos m_resolutions;
117   ResolutionInfos m_calibrations;
118
119   float m_zoomAmount;         // current zoom amount
120   float m_pixelRatio;         // current pixel ratio
121   float m_verticalShift;      // current vertical shift
122   bool  m_nonLinearStretched;   // current non-linear stretch
123
124   bool m_resolutionChangeAborted;
125   CCriticalSection m_critical;
126 };