]> sigrok.org Git - pulseview.git/blame - pv/views/trace/tracetreeitemowner.cpp
Disable antialiasing on high-DPI displays
[pulseview.git] / pv / views / trace / tracetreeitemowner.cpp
CommitLineData
18f7104f
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18f7104f
JH
18 */
19
68b21a71
JH
20#include <cassert>
21
af503b10 22#include "tracetreeitem.hpp"
6046c19d 23#include "trace.hpp"
aca9aa83 24#include "tracetreeitemowner.hpp"
68b21a71 25
6f925ba9 26using std::find;
a5d93c27 27using std::make_pair;
6f925ba9 28using std::max;
a5d93c27
JH
29using std::min;
30using std::pair;
68b21a71 31using std::shared_ptr;
c373f828 32using std::static_pointer_cast;
68b21a71
JH
33using std::vector;
34
35namespace pv {
f4e57597 36namespace views {
1573bf16 37namespace trace {
68b21a71 38
a8743cd9 39const ViewItemOwner::item_list& TraceTreeItemOwner::child_items() const
68b21a71 40{
8dbbc7f0 41 return items_;
68b21a71
JH
42}
43
6f925ba9 44vector< shared_ptr<TraceTreeItem> >
c373f828 45TraceTreeItemOwner::trace_tree_child_items() const
68b21a71 46{
c373f828 47 vector< shared_ptr<TraceTreeItem> > items;
8dbbc7f0 48 for (auto &i : items_) {
c373f828
JH
49 assert(dynamic_pointer_cast<TraceTreeItem>(i));
50 const shared_ptr<TraceTreeItem> t(
51 static_pointer_cast<TraceTreeItem>(i));
52 items.push_back(t);
53 }
54
55 return items;
56}
57
58void TraceTreeItemOwner::clear_child_items()
59{
60 for (auto &t : trace_tree_child_items()) {
61 assert(t->owner() == this);
62 t->set_owner(nullptr);
68b21a71 63 }
8dbbc7f0 64 items_.clear();
68b21a71
JH
65}
66
6f925ba9 67void TraceTreeItemOwner::add_child_item(shared_ptr<TraceTreeItem> item)
68b21a71
JH
68{
69 assert(!item->owner());
70 item->set_owner(this);
8dbbc7f0 71 items_.push_back(item);
32218d3e
JH
72
73 extents_changed(true, true);
68b21a71
JH
74}
75
6f925ba9 76void TraceTreeItemOwner::remove_child_item(shared_ptr<TraceTreeItem> item)
68b21a71
JH
77{
78 assert(item->owner() == this);
79 item->set_owner(nullptr);
6f925ba9 80 auto iter = find(items_.begin(), items_.end(), item);
8dbbc7f0
JH
81 assert(iter != items_.end());
82 items_.erase(iter);
32218d3e
JH
83
84 extents_changed(true, true);
68b21a71
JH
85}
86
af503b10 87pair<int, int> TraceTreeItemOwner::v_extents() const
a5d93c27 88{
d9177e6c 89 bool has_children = false;
82ba380c 90
d9177e6c 91 pair<int, int> extents(INT_MAX, INT_MIN);
f4ab4b5c 92 for (const shared_ptr<TraceTreeItem>& t : trace_tree_child_items()) {
c373f828
JH
93 assert(t);
94 if (!t->enabled())
a5d93c27
JH
95 continue;
96
d9177e6c
SA
97 has_children = true;
98
c373f828
JH
99 const int child_offset = t->layout_v_offset();
100 const pair<int, int> child_extents = t->v_extents();
a5d93c27
JH
101 extents.first = min(child_extents.first + child_offset,
102 extents.first);
103 extents.second = max(child_extents.second + child_offset,
104 extents.second);
105 }
106
d9177e6c
SA
107 if (!has_children)
108 extents = make_pair(0, 0);
109
a5d93c27
JH
110 return extents;
111}
112
af503b10 113void TraceTreeItemOwner::restack_items()
7ff0145f 114{
92fdf331
SA
115 vector<shared_ptr<TraceTreeItem>> items(trace_tree_child_items());
116
117 // Sort by the centre line of the extents
118 stable_sort(items.begin(), items.end(),
119 [](const shared_ptr<TraceTreeItem> &a, const shared_ptr<TraceTreeItem> &b) {
120 const auto aext = a->v_extents();
121 const auto bext = b->v_extents();
122 return a->layout_v_offset() +
123 (aext.first + aext.second) / 2 <
124 b->layout_v_offset() +
125 (bext.first + bext.second) / 2;
126 });
127
128 int total_offset = 0;
129 for (shared_ptr<TraceTreeItem> r : items) {
130 const pair<int, int> extents = r->v_extents();
131 if (extents.first == 0 && extents.second == 0)
132 continue;
133
134 // We position disabled traces, so that they are close to the
135 // animation target positon should they be re-enabled
136 if (r->enabled())
137 total_offset += -extents.first;
138
139 if (!r->dragging())
140 r->set_layout_v_offset(total_offset);
141
142 if (r->enabled())
143 total_offset += extents.second;
144 }
7ff0145f
JH
145}
146
1573bf16 147} // namespace trace
f4e57597
SA
148} // namespace views
149} // namespace pv