-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoUpCompareWgt.cpp
More file actions
121 lines (98 loc) · 3.35 KB
/
Copy pathTwoUpCompareWgt.cpp
File metadata and controls
121 lines (98 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "StatusWgt.h"
#include "ITextureSource.h"
#include "TwoUpCompareWgt.h"
#include <QPaintEvent>
#include <QPainter>
#include "IImageSource.h"
static constexpr QVector4D darkGrey (0.4F, 0.4F, 0.4F, 1.0F);
constexpr int boarder = 5.0F;
TwoUpCompareWgt::TwoUpCompareWgt(QWidget *parent) : BaseCompareWgt(parent)
{
setMouseTracking(true);
}
void TwoUpCompareWgt::paintGL()
{
checkError();
BaseCompareWgt::paintGL ();
auto r = Rect<>(rect());
m_leftRect = r;
m_leftRect.setSize(r.size() * 0.5F);
m_leftRect.shrink (boarder);
m_rightRect = m_leftRect;
m_rightRect.moveLeft (r.center().x() + boarder);
m_diffRect = m_rightRect;
m_diffRect.moveTop(r.center().y() + boarder);
m_diffRect.moveLeft ((r.width() - m_diffRect.width()) * 0.5F);
glClearColor (darkGrey.x(), darkGrey.y(), darkGrey.z(), darkGrey.w());
glClear (GL_COLOR_BUFFER_BIT);
checkError();
if (!m_textureSource->leftTexture().isStorageAllocated() || !m_textureSource->rightTexture().isStorageAllocated())
{
return;
}
Point<> off = offset();
//Rect<> dst (0, 0, r.width(), r.bottom());
drawImageSection (m_textureSource->leftTexture(), m_leftRect, off);
drawImageSection (m_textureSource->rightTexture(), m_rightRect, off);
drawImageSection (diffsTexture(), m_diffRect, off);
checkError();
}
void TwoUpCompareWgt::drawImageSection (QOpenGLTexture& tex, const Rect<>& dst, const Point<>& offset)
{
tex.setMagnificationFilter(QOpenGLTexture::Nearest);
tex.setMinificationFilter(QOpenGLTexture::Linear);
tex.setWrapMode(QOpenGLTexture::ClampToBorder);
tex.setBorderColor(Qt::transparent);
auto w = static_cast<float>(tex.width());
auto h = static_cast<float>(tex.height());
Point<> textureOffset = offset / Point<>(w, h) / scale();
Rect<> src1 (textureOffset.x(), textureOffset.y(), dst.width() / w / scale(), dst.height() / h / scale());
auto actualSrc = src1.intersect(Rect<>::ZeroToOne);
Rect<> actualDest (actualSrc.x() * scale() * w, actualSrc.y() * scale() * h, actualSrc.width() * w * scale(), actualSrc.height() * h * scale());
actualDest -= offset;
drawBg (dst);
drawImage (tex.textureId(), dst, src1);
}
void TwoUpCompareWgt::initializeGL()
{
BaseCompareWgt::initializeGL();
}
void TwoUpCompareWgt::showDiffs(bool show)
{
m_showDiffs = show;
update ();
}
void TwoUpCompareWgt::reportSample(const Point<>& pt)
{
if (m_leftRect.contains(pt))
{
reportSample (m_leftRect, pt);
}
else if (m_rightRect.contains(pt))
{
reportSample (m_rightRect, pt);
}
else if (m_diffRect.contains(pt))
{
reportSample (m_diffRect, pt);
}
else
{
StatusWgt::instance()->clear ();
}
}
auto TwoUpCompareWgt::displayRect() -> Rect<>
{
return m_leftRect;
}
void TwoUpCompareWgt::reportSample(const Rect<>& r, const Point<>& pt)
{
if (!m_textureSource->leftImage() || !m_textureSource->rightImage())
{
return;
}
auto off = pt - r.topLeft();
auto imageOffset = (off + currentOffset()) / scale();
StatusWgt::instance()->setLeftColour(pt, Colour::fromArgb(m_textureSource->leftImage()->image().pixel(imageOffset.x(), imageOffset.y())));
StatusWgt::instance()->setRightColour(pt, Colour::fromArgb(m_textureSource->rightImage()->image().pixel(imageOffset.x(), imageOffset.y())));
}