bWidgets
Core widget toolkit designed for Blender
bwRectangle.h
Go to the documentation of this file.
1
#pragma once
2
3
namespace
bWidgets
{
4
5
template
<
typename
T>
class
bwRectangle
{
6
public
:
7
inline
bwRectangle
(
const
T
xmin
= 0,
const
T
xmax
= 0,
const
T
ymin
= 0,
const
T
ymax
= 0)
8
:
xmin
(
xmin
),
xmax
(
xmax
),
ymin
(
ymin
),
ymax
(
ymax
)
9
{
10
}
11
template
<
typename
U>
12
inline
bwRectangle
(
const
bwRectangle<U>
& rect)
13
:
xmin
(rect.
xmin
),
xmax
(rect.
xmax
),
ymin
(rect.
ymin
),
ymax
(rect.
ymax
)
14
{
15
}
16
template
<
typename
U>
17
inline
bwRectangle
(
bwRectangle<U>
&& rect)
18
:
xmin
(rect.
xmin
),
xmax
(rect.
xmax
),
ymin
(rect.
ymin
),
ymax
(rect.
ymax
)
19
{
20
}
21
22
inline
void
set
(
const
T _xmin,
const
T
width
,
const
T _ymin,
const
T
height
)
23
{
24
xmin
= _xmin;
25
xmax
=
xmin
+
width
;
26
ymin
= _ymin;
27
ymax
=
ymin
+
height
;
28
}
29
33
inline
void
resize
(
const
T pixel)
34
{
35
xmin
-= pixel;
36
xmax
+= pixel;
37
ymin
-= pixel;
38
ymax
+= pixel;
39
}
40
41
template
<
typename
U>
inline
bool
isCoordinateInside
(
const
U x,
const
U y)
const
42
{
43
return
(x >=
xmin
) && (x <=
xmax
) && (y >=
ymin
) && (y <=
ymax
);
44
}
45
46
inline
bool
isEmpty
()
const
47
{
48
return
(
xmin
==
xmax
) || (
ymin
==
ymax
);
49
}
50
51
inline
T
width
()
const
52
{
53
return
xmax
-
xmin
;
54
}
55
inline
T
height
()
const
56
{
57
return
ymax
-
ymin
;
58
}
59
60
inline
T
centerX
()
const
61
{
62
return
xmin
+ (
width
() / T(2));
63
}
64
inline
T
centerY
()
const
65
{
66
return
ymin
+ (
height
() / T(2));
67
}
68
69
inline
void
scale
(
float
scale
)
70
{
71
const
T cent_x =
centerX
();
72
const
T cent_y =
centerY
();
73
const
T size_x_half =
width
() * (
scale
* 0.5f);
74
const
T size_y_half =
height
() * (
scale
* 0.5f);
75
xmin
= cent_x - size_x_half;
76
ymin
= cent_y - size_y_half;
77
xmax
= cent_x + size_x_half;
78
ymax
= cent_y + size_y_half;
79
}
80
81
inline
void
clamp
(
const
bwRectangle<T>
boundary)
82
{
83
if
(
xmin
< boundary.
xmin
) {
84
xmin
= boundary.
xmin
;
85
}
86
if
(
xmin
> boundary.
xmax
) {
87
xmin
= boundary.
xmax
;
88
}
89
if
(
xmax
> boundary.
xmax
) {
90
xmax
= boundary.
xmax
;
91
}
92
if
(
xmax
< boundary.
xmin
) {
93
xmax
= boundary.
xmin
;
94
}
95
if
(
ymin
< boundary.
ymin
) {
96
ymin
= boundary.
ymin
;
97
}
98
if
(
ymin
> boundary.
ymax
) {
99
ymin
= boundary.
ymax
;
100
}
101
if
(
ymax
> boundary.
ymax
) {
102
ymax
= boundary.
ymax
;
103
}
104
if
(
ymax
< boundary.
ymin
) {
105
ymax
= boundary.
ymin
;
106
}
107
}
108
109
T
xmin
,
xmax
;
110
T
ymin
,
ymax
;
111
};
112
113
// useful aliases
114
using
bwRectanglePixel
=
bwRectangle<int>
;
115
116
}
// namespace bWidgets
bWidgets::bwRectangle
Definition:
bwRectangle.h:5
bWidgets::bwRectangle::isEmpty
bool isEmpty() const
Definition:
bwRectangle.h:46
bWidgets::bwRectangle::isCoordinateInside
bool isCoordinateInside(const U x, const U y) const
Definition:
bwRectangle.h:41
bWidgets::bwRectangle::ymax
T ymax
Definition:
bwRectangle.h:110
bWidgets::bwRectangle::clamp
void clamp(const bwRectangle< T > boundary)
Definition:
bwRectangle.h:81
bWidgets::bwRectangle::bwRectangle
bwRectangle(bwRectangle< U > &&rect)
Definition:
bwRectangle.h:17
bWidgets::bwRectangle::height
T height() const
Definition:
bwRectangle.h:55
bWidgets::bwRectangle::centerY
T centerY() const
Definition:
bwRectangle.h:64
bWidgets::bwRectangle::bwRectangle
bwRectangle(const bwRectangle< U > &rect)
Definition:
bwRectangle.h:12
bWidgets::bwRectangle::ymin
T ymin
Definition:
bwRectangle.h:110
bWidgets::bwRectangle::centerX
T centerX() const
Definition:
bwRectangle.h:60
bWidgets::bwRectangle::bwRectangle
bwRectangle(const T xmin=0, const T xmax=0, const T ymin=0, const T ymax=0)
Definition:
bwRectangle.h:7
bWidgets::bwRectangle::width
T width() const
Definition:
bwRectangle.h:51
bWidgets::bwRectangle::xmax
T xmax
Definition:
bwRectangle.h:109
bWidgets::bwRectangle::set
void set(const T _xmin, const T width, const T _ymin, const T height)
Definition:
bwRectangle.h:22
bWidgets::bwRectangle::scale
void scale(float scale)
Definition:
bwRectangle.h:69
bWidgets::bwRectangle::xmin
T xmin
Definition:
bwRectangle.h:109
bWidgets::bwRectangle::resize
void resize(const T pixel)
Definition:
bwRectangle.h:33
bWidgets
Definition:
bwContext.h:3
bwidgets
generics
bwRectangle.h
Generated by
1.9.3