Krotos Modules 3
Loading...
Searching...
No Matches
ZoomableComponent.cpp
Go to the documentation of this file.
1namespace krotos
2{
4 {
5 float halfZoom = m_hZoom * 0.5f;
6 return {m_hCenter - halfZoom, m_hCenter + halfZoom};
7 }
8
10 {
11 return {m_vCenter - m_vCenter * m_vZoom, m_vCenter + (1.0f - m_vCenter) * m_vZoom};
12 }
13
14 void ZoomableComponent::drawNormalisedZoomedRect(Graphics& g, const Rectangle<float>& rect) const
15 {
16 g.fillRect(rect.transformedBy(m_transform));
17 }
18
19 void ZoomableComponent::drawNormalisedZoomedRectLine(Graphics& g, const Rectangle<float>& rect) const
20 {
21 g.drawRect(rect.transformedBy(m_transform));
22 }
23
24 void ZoomableComponent::drawZoomedRect(Graphics& g, const Rectangle<float>& rect) const
25 {
26 auto width = float(getWidth());
27 auto height = float(getHeight());
28
29 auto normalised = Rectangle<float>(rect.getX() / width, rect.getY() / height, rect.getWidth() / width,
30 rect.getHeight() / height);
31
32 drawNormalisedZoomedRect(g, normalised);
33 }
34
35 void ZoomableComponent::drawNormalisedZoomedLine(Graphics& g, Line<float> line, float thickness) const
36 {
37 line.applyTransform(m_transform);
38 g.drawLine(line, thickness);
39 }
40
41 void ZoomableComponent::drawNormalisedZoomedText(Graphics& g, String text, Rectangle<float> boundary) const
42 {
43 g.drawFittedText(text, boundary.transformedBy(m_transform).toNearestInt(), Justification::centredLeft, 1);
44 }
45
46 void ZoomableComponent::drawZoomedLine(Graphics& g, const Line<float>& line, float thickness) const
47 {
48 auto width = float(getWidth());
49 auto height = float(getHeight());
50
51 auto normalised = Line<float>(line.getStartX() / width, line.getStartY() / height, line.getEndX() / width,
52 line.getEndY() / height);
53
54 drawNormalisedZoomedLine(g, normalised, thickness);
55 }
56
57 void ZoomableComponent::drawNormalisedZoomedPath(Graphics& g, const Path& path, float thickness)
58 {
59 g.strokePath(path, PathStrokeType(thickness), m_transform);
60 }
61
62 void ZoomableComponent::drawZoomedPath(Graphics& g, Path path, float thickness)
63 {
64 auto width = float(getWidth());
65 auto height = float(getHeight());
66
67 auto t = AffineTransform::scale(1.0f / width, 1.0f / height);
68 path.applyTransform(t);
69
70 drawNormalisedZoomedPath(g, path, thickness);
71 }
72
73 void ZoomableComponent::drawNormalisedZoomedImage(Graphics& g, Image& image, const Rectangle<float>& bounds,
74 bool fillAlphaChannelWithCurrentBrush)
75 {
76 g.drawImage(image, bounds.transformedBy(m_transform), RectanglePlacement::stretchToFit,
77 fillAlphaChannelWithCurrentBrush);
78 }
79
80 void ZoomableComponent::fillNormalisedZoomedEllipse(Graphics& g, const Rectangle<float>& bounds)
81 {
82 g.fillEllipse(bounds.transformedBy(m_transform));
83 }
84
85 void ZoomableComponent::drawNormalisedZoomedEllipse(Graphics& g, const Rectangle<float>& bounds)
86 {
87 g.drawEllipse(bounds.transformedBy(m_transform), 1.f);
88 }
89
90 void ZoomableComponent::drawZoomedEllipse(Graphics& g, const Rectangle<float>& bounds)
91 {
92 auto width = float(getWidth());
93 auto height = float(getHeight());
94
95 auto normalised = Rectangle<float>(bounds.getX() / width, bounds.getY() / height, bounds.getWidth() / width,
96 bounds.getHeight() / height);
97
98 drawNormalisedZoomedEllipse(g, normalised);
99 }
100
102 {
103 auto xr = getHorizontalRange();
104 auto yr = getVerticalRange();
105 auto height = float(getHeight());
106 auto width = float(getWidth());
107
109 AffineTransform::fromTargetPoints(xr.getStart(), yr.getStart(), 0.0f, 0.0f, xr.getEnd(), yr.getStart(),
110 width, 0.0f, xr.getStart(), yr.getEnd(), 0.0f, height);
111
112 repaint();
113 }
114
115 // Range should contain start and end of the section we want to fill the view with, normalised 0->1
117 {
118 m_hCenter = (xr.getStart() + xr.getEnd()) * 0.5f;
119 m_hZoom = -2.f * xr.getStart() + 2.f * m_hCenter;
121 }
122
123 void ZoomableComponent::SetTransformToFit(int width, int height)
124 {
125 m_hCenter = 0.5f;
126 m_hZoom = 1.0f;
127 auto xr = getHorizontalRange();
128 auto yr = getVerticalRange();
130 AffineTransform::fromTargetPoints(xr.getStart(), yr.getStart(), 0.0f, 0.0f, xr.getEnd(), yr.getStart(),
131 width, 0.0f, xr.getStart(), yr.getEnd(), 0.0f, height);
132 }
133
134} // namespace krotos
void drawZoomedEllipse(Graphics &g, const Rectangle< float > &bounds)
Definition ZoomableComponent.cpp:90
AffineTransform m_transform
Definition ZoomableComponent.h:73
void drawZoomedLine(Graphics &g, const Line< float > &line, float thickness) const
Definition ZoomableComponent.cpp:46
void drawZoomedRect(Graphics &g, const Rectangle< float > &rect) const
Definition ZoomableComponent.cpp:24
void SetTransformToFit(int width, int height)
Definition ZoomableComponent.cpp:123
void drawNormalisedZoomedRect(Graphics &g, const Rectangle< float > &rect) const
Definition ZoomableComponent.cpp:14
void drawNormalisedZoomedRectLine(Graphics &g, const Rectangle< float > &rect) const
Definition ZoomableComponent.cpp:19
float m_hCenter
Definition ZoomableComponent.h:68
void drawNormalisedZoomedImage(Graphics &g, Image &image, const Rectangle< float > &bounds, bool fillAlphaChannelWithCurrentBrush=false)
Definition ZoomableComponent.cpp:73
float m_hZoom
Definition ZoomableComponent.h:67
void drawNormalisedZoomedPath(Graphics &g, const Path &path, float thickness)
Definition ZoomableComponent.cpp:57
void drawNormalisedZoomedText(Graphics &g, String text, Rectangle< float > bounds) const
Definition ZoomableComponent.cpp:41
void drawNormalisedZoomedLine(Graphics &g, Line< float > line, float thickness) const
Definition ZoomableComponent.cpp:35
void setHorizontalZoomFromRange(const Range< float > xr)
Definition ZoomableComponent.cpp:116
void drawZoomedPath(Graphics &g, Path path, float thickness)
Definition ZoomableComponent.cpp:62
Range< float > getVerticalRange() const
Definition ZoomableComponent.cpp:9
void updateTransform()
Definition ZoomableComponent.cpp:101
Range< float > getHorizontalRange() const
Definition ZoomableComponent.cpp:3
void fillNormalisedZoomedEllipse(Graphics &g, const Rectangle< float > &bounds)
Definition ZoomableComponent.cpp:80
void drawNormalisedZoomedEllipse(Graphics &g, const Rectangle< float > &bounds)
Definition ZoomableComponent.cpp:85
float m_vCenter
Definition ZoomableComponent.h:71
float m_vZoom
Definition ZoomableComponent.h:70
Definition AirAbsorptionFilter.cpp:2