QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
CheckerboardTextureData.cc
Go to the documentation of this file.
1
#include "
CheckerboardTextureData.h
"
2
3
#include <QtCore/QSize>
4
5
#include <algorithm>
6
7
CheckerboardTextureData::CheckerboardTextureData
(QQuick3DObject* parent) : QQuick3DTextureData(parent)
8
{
9
_rebuild();
10
}
11
12
void
CheckerboardTextureData::setSizePixels
(
int
sizePixels)
13
{
14
const
int
clamped = std::clamp(
sizePixels
, 2, 2048);
15
if
(clamped == _sizePixels) {
16
return
;
17
}
18
_sizePixels = clamped;
19
emit
sizePixelsChanged
();
20
_rebuild();
21
}
22
23
void
CheckerboardTextureData::setCells
(
int
cells)
24
{
25
// Fixed range (no cross-property dependence: QML property init order is unspecified);
26
// _rebuild() degrades cells > sizePixels to 1-pixel cells
27
const
int
clamped = std::clamp(
cells
, 1, 2048);
28
if
(clamped == _cells) {
29
return
;
30
}
31
_cells = clamped;
32
emit
cellsChanged
();
33
_rebuild();
34
}
35
36
void
CheckerboardTextureData::setColor1
(
const
QColor& color)
37
{
38
if
(color == _color1) {
39
return
;
40
}
41
_color1 = color;
42
emit
color1Changed
();
43
_rebuild();
44
}
45
46
void
CheckerboardTextureData::setColor2
(
const
QColor& color)
47
{
48
if
(color == _color2) {
49
return
;
50
}
51
_color2 = color;
52
emit
color2Changed
();
53
_rebuild();
54
}
55
56
void
CheckerboardTextureData::_rebuild()
57
{
58
const
int
size = _sizePixels;
59
const
int
cellPixels = std::max(1, size / _cells);
60
61
QByteArray data(qsizetype(size) * size * 4, Qt::Uninitialized);
62
uchar* p =
reinterpret_cast<
uchar*
>
(data.data());
63
for
(
int
y = 0; y < size; y++) {
64
for
(
int
x = 0; x < size; x++) {
65
const
bool
odd = (((x / cellPixels) + (y / cellPixels)) % 2) != 0;
66
const
QColor& color = odd ? _color2 : _color1;
67
*p++ =
static_cast<
uchar
>
(color.red());
68
*p++ =
static_cast<
uchar
>
(color.green());
69
*p++ =
static_cast<
uchar
>
(color.blue());
70
*p++ = 255;
71
}
72
}
73
74
setSize(QSize(size, size));
75
setFormat(QQuick3DTextureData::RGBA8);
76
setHasTransparency(
false
);
77
setTextureData(data);
78
}
CheckerboardTextureData.h
CheckerboardTextureData::setCells
void setCells(int cells)
Definition
CheckerboardTextureData.cc:23
CheckerboardTextureData::setSizePixels
void setSizePixels(int sizePixels)
Definition
CheckerboardTextureData.cc:12
CheckerboardTextureData::sizePixelsChanged
void sizePixelsChanged()
CheckerboardTextureData::color2Changed
void color2Changed()
CheckerboardTextureData::color1Changed
void color1Changed()
CheckerboardTextureData::cells
int cells() const
Definition
CheckerboardTextureData.h:34
CheckerboardTextureData::CheckerboardTextureData
CheckerboardTextureData(QQuick3DObject *parent=nullptr)
Definition
CheckerboardTextureData.cc:7
CheckerboardTextureData::cellsChanged
void cellsChanged()
CheckerboardTextureData::setColor1
void setColor1(const QColor &color)
Definition
CheckerboardTextureData.cc:36
CheckerboardTextureData::sizePixels
int sizePixels() const
Definition
CheckerboardTextureData.h:30
CheckerboardTextureData::setColor2
void setColor2(const QColor &color)
Definition
CheckerboardTextureData.cc:46
src
GeoMap
CheckerboardTextureData.cc
Generated by
1.9.8