blob: 846025ce56e39c2f26ad467ec40a00ca736fad6a (
plain)
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
|
#include "drape/overlay_tree.hpp"
#include "std/bind.hpp"
namespace dp
{
void OverlayTree::StartOverlayPlacing(ScreenBase const & screen, bool canOverlap)
{
m_traits.m_modelView = screen;
m_canOverlap = canOverlap;
ASSERT(IsEmpty(), ());
}
void OverlayTree::Add(RefPointer<OverlayHandle> handle)
{
ScreenBase const & modelView = GetModelView();
handle->SetIsVisible(m_canOverlap);
handle->Update(modelView);
if (!handle->IsValid())
return;
m2::RectD const pixelRect = handle->GetPixelRect(modelView);
if (!m_traits.m_modelView.PixelRect().IsIntersect(pixelRect))
{
handle->SetIsVisible(false);
return;
}
typedef buffer_vector<RefPointer<OverlayHandle>, 8> OverlayContainerT;
OverlayContainerT elements;
/*
* Find elements that already on OverlayTree and it's pixel rect
* intersect with handle pixel rect ("Intersected elements")
*/
ForEachInRect(pixelRect, [&] (RefPointer<OverlayHandle> r)
{
if (handle->IsIntersect(modelView, *r.GetRaw()))
elements.push_back(r);
});
double const inputPriority = handle->GetPriority();
/*
* In this loop we decide which element must be visible
* If input element "handle" more priority than all "Intersected elements"
* than we remove all "Intersected elements" and insert input element "handle"
* But if some of already inserted elements more priority than we don't insert "handle"
*/
for (OverlayContainerT::const_iterator it = elements.begin(); it != elements.end(); ++it)
if (inputPriority < (*it)->GetPriority())
return;
for (OverlayContainerT::const_iterator it = elements.begin(); it != elements.end(); ++it)
Erase(*it);
BaseT::Add(handle, pixelRect);
}
void OverlayTree::EndOverlayPlacing()
{
ForEach([] (RefPointer<OverlayHandle> handle)
{
handle->SetIsVisible(true);
});
Clear();
}
} // namespace dp
|