Skip to content

Commit 86244fb

Browse files
committed
Refactoring
1 parent af26941 commit 86244fb

17 files changed

+195
-46
lines changed

bin/toucan-render/main.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main(int argc, char** argv)
2323
std::cout << "Options:" << std::endl;
2424
std::cout << std::endl;
2525
std::cout << "* -filmstrip - Render the timeline as thumbnails to a single image." << std::endl;
26-
std::cout << "* -graph - Print a Graphviz graph for each frame." << std::endl;
26+
std::cout << "* -graph - Write a Graphviz graph for each frame." << std::endl;
2727
std::cout << "* -v - Print verbose output." << std::endl;
2828
std::cout << std::endl;
2929
return 1;
@@ -35,7 +35,7 @@ int main(int argc, char** argv)
3535
const int outputStartFrame = atoi(outputSplit.second.c_str());
3636
const size_t outputNumberPadding = getNumberPadding(outputSplit.second);
3737
bool filmstrip = false;
38-
bool printGraph = false;
38+
bool writeGraph = false;
3939
bool verbose = false;
4040
for (int i = 3; i < argc; ++i)
4141
{
@@ -46,7 +46,7 @@ int main(int argc, char** argv)
4646
}
4747
else if ("-graph" == arg)
4848
{
49-
printGraph = true;
49+
writeGraph = true;
5050
}
5151
else if ("-v" == arg)
5252
{
@@ -129,15 +129,6 @@ int main(int argc, char** argv)
129129

130130
if (auto node = graph->exec(host, time))
131131
{
132-
// Print the graph.
133-
if (printGraph)
134-
{
135-
for (const auto& line : node->graph(time, inputPath.stem().string()))
136-
{
137-
std::cout << line << std::endl;
138-
}
139-
}
140-
141132
// Execute the graph.
142133
const auto buf = node->exec(time - startTime);
143134

@@ -168,6 +159,27 @@ int main(int argc, char** argv)
168159
thumbnailBuf);
169160
filmstripX += thumbnailSize.x + thumbnailSpacing;
170161
}
162+
163+
// Write the graph.
164+
if (writeGraph)
165+
{
166+
const std::filesystem::path path = getSequenceFrame(
167+
outputPath.parent_path(),
168+
outputSplit.first,
169+
outputStartFrame + time.to_frames(),
170+
outputNumberPadding,
171+
".dot");
172+
const std::vector<std::string> lines = node->graph(time, inputPath.stem().string());
173+
if (FILE* f = fopen(path.string().c_str(), "w"))
174+
{
175+
for (const auto& line : lines)
176+
{
177+
fprintf(f, line.c_str());
178+
fprintf(f, "\n");
179+
}
180+
fclose(f);
181+
}
182+
}
171183
}
172184
}
173185
if (filmstrip)

bin/toucan-view/ClipItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace toucan
9191
{
9292
event.render->drawMesh(
9393
dtk::border(g, _size.borderFocus),
94-
event.style->getColorRole(dtk::ColorRole::KeyFocus));
94+
event.style->getColorRole(dtk::ColorRole::Yellow));
9595
}
9696

9797
const dtk::Box2I g2 = dtk::margin(g, -_size.borderFocus);

bin/toucan-view/DocumentsModel.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@ namespace toucan
4242
}
4343

4444
void DocumentsModel::close()
45+
{
46+
close(_currentIndex->get());
47+
}
48+
49+
void DocumentsModel::close(int index)
4550
{
4651
auto documents = _documents->get();
47-
int current = _currentIndex->get();
48-
if (current >= 0 && current < documents.size())
52+
if (index >= 0 && index < documents.size())
4953
{
50-
auto document = *(documents.begin() + current);
51-
documents.erase(documents.begin() + current);
54+
auto document = *(documents.begin() + index);
55+
documents.erase(documents.begin() + index);
5256
_documents->setIfChanged(documents);
5357
_remove->setAlways(document);
54-
current = std::min(current, static_cast<int>(documents.size()) - 1);
58+
int current = std::min(index, static_cast<int>(documents.size()) - 1);
5559
_current->setAlways(
5660
(current >= 0 && current < documents.size()) ?
5761
documents[current] :

bin/toucan-view/DocumentsModel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace toucan
2727

2828
void open(const std::filesystem::path&);
2929
void close();
30+
void close(int);
3031
void closeAll();
3132

3233
std::shared_ptr<dtk::IObservableList<std::shared_ptr<Document> > > observeDocuments() const;

bin/toucan-view/GapItem.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ namespace toucan
3030
setTooltip(gap->name());
3131

3232
_gap = gap;
33-
_text = gap->name();
33+
_text = !gap->name().empty() ? gap->name() : "Gap";
34+
_color = dtk::Color4F(.3F, .3F, .3F);
35+
36+
setTooltip(_text);
3437
}
3538

3639
GapItem::~GapItem()
@@ -65,7 +68,7 @@ namespace toucan
6568
}
6669
dtk::Size2I sizeHint(
6770
_timeRange.duration().rescaled_to(1.0).value() * _scale,
68-
_size.textSize.h + _size.margin + _size.borderFocus);
71+
_size.textSize.h + _size.margin * 2 + _size.borderFocus * 2);
6972
_setSizeHint(sizeHint);
7073
}
7174

@@ -89,7 +92,7 @@ namespace toucan
8992
{
9093
event.render->drawMesh(
9194
dtk::border(g, _size.borderFocus),
92-
event.style->getColorRole(dtk::ColorRole::KeyFocus));
95+
event.style->getColorRole(dtk::ColorRole::Yellow));
9396
}
9497

9598
const dtk::Box2I g2 = dtk::margin(g, -_size.borderFocus);
@@ -103,7 +106,7 @@ namespace toucan
103106
dtk::ClipRectEnabledState clipRectEnabledState(event.render);
104107
dtk::ClipRectState clipRectState(event.render);
105108
event.render->setClipRectEnabled(true);
106-
event.render->setClipRect(g3);
109+
event.render->setClipRect(intersect(g3, drawRect));
107110
event.render->drawText(
108111
_draw.glyphs,
109112
_size.fontMetrics,

bin/toucan-view/GapItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace toucan
3535
private:
3636
OTIO_NS::SerializableObject::Retainer<OTIO_NS::Gap> _gap;
3737
std::string _text;
38-
dtk::Color4F _color = dtk::Color4F(.3F, .3F, .3F);
38+
dtk::Color4F _color;
3939

4040
struct SizeData
4141
{

bin/toucan-view/InspectorTool.cpp

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "App.h"
88

99
#include <dtk/ui/Label.h>
10+
#include <dtk/ui/Spacer.h>
11+
#include <dtk/ui/ToolButton.h>
1012

1113
namespace toucan
1214
{
@@ -41,6 +43,11 @@ namespace toucan
4143
return out;
4244
}
4345

46+
void InspectorWidget::setOpen(bool value)
47+
{
48+
_bellows->setOpen(value);
49+
}
50+
4451
void InspectorWidget::setGeometry(const dtk::Box2I& value)
4552
{
4653
IWidget::setGeometry(value);
@@ -61,11 +68,47 @@ namespace toucan
6168
{
6269
IToolWidget::_init(context, app, "toucan::InspectorTool", "Inspector", parent);
6370

64-
_scrollWidget = dtk::ScrollWidget::create(context, dtk::ScrollType::Both, shared_from_this());
65-
66-
_layout = dtk::VerticalLayout::create(context);
71+
_layout = dtk::VerticalLayout::create(context, shared_from_this());
6772
_layout->setSpacingRole(dtk::SizeRole::None);
68-
_scrollWidget->setWidget(_layout);
73+
74+
auto hLayout = dtk::HorizontalLayout::create(context, _layout);
75+
hLayout->setSpacingRole(dtk::SizeRole::SpacingTool);
76+
auto spacer = dtk::Spacer::create(context, dtk::Orientation::Horizontal, hLayout);
77+
spacer->setSpacingRole(dtk::SizeRole::None);
78+
spacer->setStretch(dtk::Stretch::Expanding);
79+
auto openButton = dtk::ToolButton::create(context, hLayout);
80+
openButton->setMarginRole(dtk::SizeRole::MarginSmall);
81+
openButton->setIcon("BellowsOpen");
82+
openButton->setTooltip("Open all");
83+
auto closeButton = dtk::ToolButton::create(context, hLayout);
84+
closeButton->setMarginRole(dtk::SizeRole::MarginSmall);
85+
closeButton->setIcon("BellowsClosed");
86+
closeButton->setTooltip("Close all");
87+
88+
_scrollWidget = dtk::ScrollWidget::create(context, dtk::ScrollType::Both, _layout);
89+
_scrollWidget->setVStretch(dtk::Stretch::Expanding);
90+
91+
_scrollLayout = dtk::VerticalLayout::create(context);
92+
_scrollLayout->setSpacingRole(dtk::SizeRole::None);
93+
_scrollWidget->setWidget(_scrollLayout);
94+
95+
openButton->setClickedCallback(
96+
[this]
97+
{
98+
for (const auto& widget : _widgets)
99+
{
100+
widget->setOpen(true);
101+
}
102+
});
103+
104+
closeButton->setClickedCallback(
105+
[this]
106+
{
107+
for (const auto& widget : _widgets)
108+
{
109+
widget->setOpen(false);
110+
}
111+
});
69112

70113
_selectionObserver = dtk::ListObserver<OTIO_NS::SerializableObject::Retainer<OTIO_NS::Item> >::create(
71114
document->getSelectionModel()->observeSelection(),
@@ -79,7 +122,7 @@ namespace toucan
79122
auto context = _getContext().lock();
80123
for (const auto& item : selection)
81124
{
82-
auto widget = InspectorWidget::create(context, item, _layout);
125+
auto widget = InspectorWidget::create(context, item, _scrollLayout);
83126
_widgets.push_back(widget);
84127
}
85128
});
@@ -102,12 +145,12 @@ namespace toucan
102145
void InspectorTool::setGeometry(const dtk::Box2I& value)
103146
{
104147
IToolWidget::setGeometry(value);
105-
_scrollWidget->setGeometry(value);
148+
_layout->setGeometry(value);
106149
}
107150

108151
void InspectorTool::sizeHintEvent(const dtk::SizeHintEvent& event)
109152
{
110153
IToolWidget::sizeHintEvent(event);
111-
_setSizeHint(_scrollWidget->getSizeHint());
154+
_setSizeHint(_layout->getSizeHint());
112155
}
113156
}

bin/toucan-view/InspectorTool.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace toucan
3131
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Item>&,
3232
const std::shared_ptr<IWidget>& parent = nullptr);
3333

34+
void setOpen(bool);
35+
3436
void setGeometry(const dtk::Box2I&) override;
3537
void sizeHintEvent(const dtk::SizeHintEvent&) override;
3638

@@ -61,8 +63,9 @@ namespace toucan
6163
void sizeHintEvent(const dtk::SizeHintEvent&) override;
6264

6365
private:
64-
std::shared_ptr<dtk::ScrollWidget> _scrollWidget;
6566
std::shared_ptr<dtk::VerticalLayout> _layout;
67+
std::shared_ptr<dtk::ScrollWidget> _scrollWidget;
68+
std::shared_ptr<dtk::VerticalLayout> _scrollLayout;
6669
std::vector<std::shared_ptr<InspectorWidget> > _widgets;
6770

6871
std::shared_ptr<dtk::ListObserver<OTIO_NS::SerializableObject::Retainer<OTIO_NS::Item> > > _selectionObserver;

bin/toucan-view/MenuBar.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,41 @@ namespace toucan
541541

542542
_menus["Window"]->addDivider();
543543

544+
_menus["Window/Resize"] = _menus["Window"]->addSubMenu("Resize");
545+
546+
_actions["Window/Resize/1280x720"] = std::make_shared<dtk::Action>(
547+
"1280x720",
548+
[windowWeak]
549+
{
550+
if (auto window = windowWeak.lock())
551+
{
552+
window->setSize(dtk::Size2I(1280, 720));
553+
}
554+
});
555+
_menus["Window/Resize"]->addItem(_actions["Window/Resize/1280x720"]);
556+
557+
_actions["Window/Resize/1920x1080"] = std::make_shared<dtk::Action>(
558+
"1920x1080",
559+
[windowWeak]
560+
{
561+
if (auto window = windowWeak.lock())
562+
{
563+
window->setSize(dtk::Size2I(1920, 1080));
564+
}
565+
});
566+
_menus["Window/Resize"]->addItem(_actions["Window/Resize/1920x1080"]);
567+
568+
_actions["Window/Resize/3840x2160"] = std::make_shared<dtk::Action>(
569+
"3840x2160",
570+
[windowWeak]
571+
{
572+
if (auto window = windowWeak.lock())
573+
{
574+
window->setSize(dtk::Size2I(3840, 2160));
575+
}
576+
});
577+
_menus["Window/Resize"]->addItem(_actions["Window/Resize/3840x2160"]);
578+
544579
_menus["Window/DisplayScale"] = _menus["Window"]->addSubMenu("Display Scale");
545580

546581
_actions["Window/DisplayScale/Auto"] = std::make_shared<dtk::Action>(
@@ -587,11 +622,21 @@ namespace toucan
587622
});
588623
_menus["Window/DisplayScale"]->addItem(_actions["Window/DisplayScale/3.0"]);
589624

625+
_actions["Window/Tooltips"] = std::make_shared<dtk::Action>(
626+
"Tooltips",
627+
[appWeak](bool value)
628+
{
629+
if (auto app = appWeak.lock())
630+
{
631+
app->getWindowModel()->setTooltips(value);
632+
}
633+
});
634+
_menus["Window"]->addItem(_actions["Window/Tooltips"]);
635+
590636
_fullScreenObserver = dtk::ValueObserver<bool>::create(
591637
window->observeFullScreen(),
592638
[this](bool value)
593639
{
594-
_actions["Window/FullScreen"]->checked = value;
595640
_menus["Window"]->setItemChecked(_actions["Window/FullScreen"], value);
596641
});
597642

@@ -618,6 +663,13 @@ namespace toucan
618663
_menus["Window/DisplayScale"]->setItemChecked(_actions["Window/DisplayScale/2.0"], 2.F == value);
619664
_menus["Window/DisplayScale"]->setItemChecked(_actions["Window/DisplayScale/3.0"], 3.F == value);
620665
});
666+
667+
_tooltipsObserver = dtk::ValueObserver<bool>::create(
668+
app->getWindowModel()->observeTooltips(),
669+
[this](bool value)
670+
{
671+
_menus["Window"]->setItemChecked(_actions["Window/Tooltips"], value);
672+
});
621673
}
622674

623675
void MenuBar::_fileMenuUpdate()
@@ -676,7 +728,6 @@ namespace toucan
676728
_document->getViewModel()->observeFrame(),
677729
[this](bool value)
678730
{
679-
_actions["View/FrameView"]->checked = value;
680731
_menus["View"]->setItemChecked(_actions["View/FrameView"], value);
681732
});
682733
}

bin/toucan-view/MenuBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace toucan
8282
std::shared_ptr<dtk::ValueObserver<bool> > _fullScreenObserver;
8383
std::shared_ptr<dtk::MapObserver<WindowControl, bool> > _controlsObserver;
8484
std::shared_ptr<dtk::ValueObserver<float> > _displayScaleObserver;
85+
std::shared_ptr<dtk::ValueObserver<bool> > _tooltipsObserver;
8586
std::shared_ptr<dtk::ValueObserver<TimeUnits> > _timeUnitsObserver;
8687
};
8788
}

0 commit comments

Comments
 (0)