neoGFX
C++ GPU-oriented GUI library and app/game creation framework.
i_units_context.hpp
Go to the documentation of this file.
1 // i_units_context.hpp
2 /*
3  neogfx C++ GUI Library
4  Copyright (c) 2015 Leigh Johnston. All Rights Reserved.
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 3 of the License, or
9  (at your option) 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 this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <neogfx/neogfx.hpp>
25 
26 namespace neogfx
27 {
28  enum class units
29  {
30  Pixels,
31  Points,
32  Picas,
33  Ems,
38  Inches,
40  };
41 
43  {
44  public:
45  struct no_device_metrics : std::logic_error { no_device_metrics() : std::logic_error("neogfx::i_units_context::no_device_metrics") {} };
46  public:
47  virtual bool high_dpi() const = 0;
48  virtual dimension dpi_scale_factor() const = 0;
49  public:
50  virtual bool device_metrics_available() const = 0;
51  virtual const i_device_metrics& device_metrics() const = 0;
52  virtual neogfx::units units() const = 0;
53  virtual neogfx::units set_units(neogfx::units aUnits) const = 0;
54  // helpers
55  public:
57  {
58  return aValue * dpi_scale_factor();
59  }
60  size dpi_scale(const size& aSize) const
61  {
62  auto result = aSize;
63  if (result.cx != size::max_dimension())
64  result.cx *= dpi_scale_factor();
65  if (result.cy != size::max_dimension())
66  result.cy *= dpi_scale_factor();
67  return result;
68  }
69  point dpi_scale(const point& aPoint) const
70  {
71  return aPoint * dpi_scale_factor();
72  }
73  margins dpi_scale(const margins& aMargins) const
74  {
75  return aMargins * dpi_scale_factor();
76  }
77  template <typename T>
78  T&& dpi_select(T&& aLowDpiValue, T&& aHighDpiValue) const
79  {
80  return std::forward<T>(high_dpi() ? aHighDpiValue : aLowDpiValue);
81  }
82  };
83 
84  enum class alignment : uint32_t
85  {
86  None = 0x0000,
87  Left = 0x0001,
88  Right = 0x0002,
89  Centre = 0x0004,
91  Justify = 0x0008,
92  Top = 0x0010,
93  VCentre = 0x0020,
95  Bottom = 0x0040,
97  Vertical = Top | VCentre | Bottom
98  };
99 
100  inline constexpr alignment operator|(alignment aLhs, alignment aRhs)
101  {
102  return static_cast<alignment>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
103  }
104 
105  inline constexpr alignment operator&(alignment aLhs, alignment aRhs)
106  {
107  return static_cast<alignment>(static_cast<uint32_t>(aLhs) & static_cast<uint32_t>(aRhs));
108  }
109 }
T && dpi_select(T &&aLowDpiValue, T &&aHighDpiValue) const
margins dpi_scale(const margins &aMargins) const
static constexpr dimension_type max_dimension()
dimension_type cx
point dpi_scale(const point &aPoint) const
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition: i_style.hpp:40
size dpi_scale(const size &aSize) const
constexpr style_aspect operator &(style_aspect aLhs, style_aspect aRhs)
Definition: i_style.hpp:45
default_geometry_value_type dimension
Definition: geometrical.hpp:33
dimension dpi_scale(dimension aValue) const