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
>
23
#include <
neogfx/core/geometrical.hpp
>
24
#include <
neogfx/core/device_metrics.hpp
>
25
26
namespace
neogfx
27
{
28
enum class
units
29
{
30
Pixels
,
31
Points
,
32
Picas
,
33
Ems
,
34
Millimetres
,
35
Millimeters
=
units::Millimetres
,
36
Centimetres
,
37
Centimeters
=
units::Centimetres
,
38
Inches
,
39
Percentage
40
};
41
42
class
i_units_context
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
:
56
dimension
dpi_scale
(
dimension
aValue)
const
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,
90
Center
=
alignment::Centre
,
91
Justify
= 0x0008,
92
Top
= 0x0010,
93
VCentre
= 0x0020,
94
VCenter
=
alignment::VCentre
,
95
Bottom
= 0x0040,
96
Horizontal
=
Left
|
Centre
|
Right
|
Justify
,
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
}
neogfx::i_units_context::dpi_select
T && dpi_select(T &&aLowDpiValue, T &&aHighDpiValue) const
Definition:
i_units_context.hpp:78
neogfx::units::Millimeters
neogfx::i_units_context::dpi_scale
margins dpi_scale(const margins &aMargins) const
Definition:
i_units_context.hpp:73
neogfx::alignment::Centre
neogfx.hpp
neogfx::style_aspect::None
neogfx::alignment::VCentre
geometrical.hpp
neogfx::i_units_context
Definition:
i_units_context.hpp:42
neogfx::alignment::VCenter
neogfx::alignment::Right
neogfx::alignment::Bottom
neogfx::alignment::Center
neogfx::units::Inches
neogfx
Definition:
action.hpp:26
neogfx::units::Centimetres
neogfx::i_units_context::no_device_metrics::no_device_metrics
no_device_metrics()
Definition:
i_units_context.hpp:45
neogfx::units::Ems
neogfx::units::Millimetres
neogfx::basic_size< coordinate >::max_dimension
static constexpr dimension_type max_dimension()
Definition:
geometrical.hpp:207
neogfx::alignment::Horizontal
neogfx::basic_size::cx
dimension_type cx
Definition:
geometrical.hpp:211
neogfx::alignment::Vertical
neogfx::units::Percentage
device_metrics.hpp
neogfx::i_device_metrics
Definition:
device_metrics.hpp:42
neogfx::i_units_context::dpi_scale
point dpi_scale(const point &aPoint) const
Definition:
i_units_context.hpp:69
neogfx::i_units_context::no_device_metrics
Definition:
i_units_context.hpp:45
neogfx::operator|
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition:
i_style.hpp:40
neogfx::i_units_context::dpi_scale
size dpi_scale(const size &aSize) const
Definition:
i_units_context.hpp:60
neogfx::alignment::Justify
neogfx::units
units
Definition:
i_units_context.hpp:28
neogfx::operator &
constexpr style_aspect operator &(style_aspect aLhs, style_aspect aRhs)
Definition:
i_style.hpp:45
neogfx::units::Picas
neogfx::units::Pixels
neogfx::dimension
default_geometry_value_type dimension
Definition:
geometrical.hpp:33
neogfx::alignment
alignment
Definition:
i_units_context.hpp:84
neogfx::units::Centimeters
neogfx::alignment::Top
neogfx::basic_point< coordinate >
neogfx::alignment::Left
neogfx::basic_margins< dimension >
neogfx::i_units_context::dpi_scale
dimension dpi_scale(dimension aValue) const
Definition:
i_units_context.hpp:56
neogfx::units::Points
neogfx::basic_size< coordinate >
include
neogfx
core
i_units_context.hpp
Generated by
1.8.13