-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageBrowserThumbnailPane.cpp
More file actions
96 lines (81 loc) · 2.62 KB
/
Copy pathImageBrowserThumbnailPane.cpp
File metadata and controls
96 lines (81 loc) · 2.62 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
#include "ImageBrowserThumbnailPane.h"
#include "FD2D/Util.h"
#include <algorithm>
#include <cmath>
ImageBrowserThumbnailPane::ImageBrowserThumbnailPane()
: FD2D::Wnd(L"thumbnailPane")
{
}
void ImageBrowserThumbnailPane::Build(
const std::shared_ptr<FD2D::SplitPanel>& rootSplit,
const std::function<void(int)>& onWheelSteps,
const std::function<void()>& onWheelFocus)
{
if (!rootSplit)
{
return;
}
m_onWheelSteps = onWheelSteps;
m_onWheelFocus = onWheelFocus;
m_wheelRemainder = 0;
m_thumbPanel = std::make_shared<FD2D::StackPanel>(L"thumbs", FD2D::Orientation::Horizontal);
m_thumbPanel->SetSpacing(4.0f);
m_thumbPanel->SetPadding(4.0f);
m_thumbScroll = std::make_shared<FD2D::ScrollView>(L"thumbScroll");
m_thumbScroll->SetScrollStep(96.0f);
m_thumbScroll->SetSmoothTimeMs(110);
m_thumbScroll->SetVerticalScrollEnabled(false);
m_thumbScroll->SetScrollBarsVisible(true); // horizontal bar when the strip overflows
m_thumbScroll->SetContent(m_thumbPanel);
ClearChildren();
AddChild(m_thumbScroll);
rootSplit->SetSecondChild(shared_from_this());
}
bool ImageBrowserThumbnailPane::TryGetStripRect(D2D1_RECT_F& outRect) const
{
if (m_thumbScroll == nullptr)
{
return false;
}
outRect = m_thumbScroll->LayoutRect();
return outRect.right > outRect.left && outRect.bottom > outRect.top;
}
size_t ImageBrowserThumbnailPane::PagingStep(float itemExtent) const
{
D2D1_RECT_F stripRect {};
if (!TryGetStripRect(stripRect))
{
return 1;
}
const float width = stripRect.right - stripRect.left;
if (width <= 1.0f)
{
return 1;
}
const float clampedExtent = (std::max)(1.0f, itemExtent);
const int count = static_cast<int>(std::floor(width / clampedExtent));
return static_cast<size_t>((std::max)(1, count));
}
bool ImageBrowserThumbnailPane::OnInputEvent(const FD2D::InputEvent& event)
{
if (event.type == FD2D::InputEventType::MouseWheel && event.hasPoint && m_thumbScroll != nullptr)
{
const D2D1_RECT_F stripRect = m_thumbScroll->LayoutRect();
if (FD2D::Util::RectContainsPoint(stripRect, event.point))
{
if (m_onWheelFocus)
{
m_onWheelFocus();
}
m_wheelRemainder += event.wheelDelta;
const int steps = m_wheelRemainder / WHEEL_DELTA;
m_wheelRemainder = m_wheelRemainder % WHEEL_DELTA;
if (steps != 0 && m_onWheelSteps)
{
m_onWheelSteps(steps);
}
return true;
}
}
return Wnd::OnInputEvent(event);
}