Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Darby Johnston <darbyjohnston@yahoo.com>
  • Loading branch information
darbyjohnston committed Dec 17, 2024
1 parent 1a1a052 commit 929d66b
Show file tree
Hide file tree
Showing 26 changed files with 537 additions and 134 deletions.
2 changes: 1 addition & 1 deletion cmake/SuperBuild/Builddtk-deps.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(ExternalProject)

set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git")
set(dtk_GIT_TAG "8e1dca75fbce980fb5227d6b534bed2ba4f9e3b9")
set(dtk_GIT_TAG "60fe172aebdffbeda24adc2f0a5237140a90529b")

set(dtk-deps_ARGS
${toucan_EXTERNAL_PROJECT_ARGS}
Expand Down
2 changes: 1 addition & 1 deletion cmake/SuperBuild/Builddtk.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(ExternalProject)

set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git")
set(dtk_GIT_TAG "8e1dca75fbce980fb5227d6b534bed2ba4f9e3b9")
set(dtk_GIT_TAG "60fe172aebdffbeda24adc2f0a5237140a90529b")

set(dtk_DEPS dtk-deps)
set(dtk_ARGS
Expand Down
108 changes: 78 additions & 30 deletions data/Markers.otio
Original file line number Diff line number Diff line change
@@ -1,12 +1,78 @@
{
"OTIO_SCHEMA": "Timeline.1",
"metadata": {},
"name": "Gap",
"name": "Markers",
"global_start_time": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 100.0
},
"tracks": {
"OTIO_SCHEMA": "Stack.1",
"OTIO_SCHEMA": "Stack.1",
"markers": [
{
"OTIO_SCHEMA": "Marker.2",
"metadata": {},
"name": "Stack Marker",
"color": "GREEN",
"marked_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 9.0
},
"start_time": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 0.0
}
}
}
],
"children": [
{
"OTIO_SCHEMA": "Track.1",
"OTIO_SCHEMA": "Track.1",
"markers": [
{
"OTIO_SCHEMA": "Marker.2",
"metadata": {},
"name": "Track Marker 0",
"color": "ORANGE",
"marked_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 4.0
},
"start_time": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 0.0
}
}
},
{
"OTIO_SCHEMA": "Marker.2",
"metadata": {},
"name": "Track Marker 1",
"color": "YELLOW",
"marked_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 5.0
},
"start_time": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 4.0
}
}
}
],
"children": [
{
"OTIO_SCHEMA": "Clip.1",
Expand Down Expand Up @@ -45,7 +111,7 @@
{
"OTIO_SCHEMA": "Marker.2",
"metadata": {},
"name": "Marker A",
"name": "Letter_A Marker",
"color": "RED",
"marked_range": {
"OTIO_SCHEMA": "TimeRange.1",
Expand All @@ -62,26 +128,9 @@
}
}
]
},
{
"OTIO_SCHEMA": "Clip.1",
"media_reference": {
"OTIO_SCHEMA": "ExternalReference.1",
"available_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24,
"value": 3
},
"start_time": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24,
"value": 0
}
},
"target_url": "Letter_B.png"
},
}, {
"OTIO_SCHEMA": "Gap.1",
"name": "Gap",
"source_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
Expand All @@ -95,13 +144,12 @@
"value": 0
}
},
"name": "Letter_B",
"markers": [
{
"OTIO_SCHEMA": "Marker.2",
"metadata": {},
"name": "Marker B",
"color": "Green",
"name": "Gap Marker",
"color": "GREEN",
"marked_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
Expand Down Expand Up @@ -155,7 +203,7 @@
{
"OTIO_SCHEMA": "Marker.2",
"metadata": {},
"name": "Marker C0",
"name": "Letter_C Marker 0",
"color": "BLUE",
"marked_range": {
"OTIO_SCHEMA": "TimeRange.1",
Expand All @@ -174,14 +222,14 @@
{
"OTIO_SCHEMA": "Marker.2",
"metadata": {},
"name": "Marker C1",
"name": "Letter_C Marker 1",
"color": "PURPLE",
"marked_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 21.0
"value": 2.0
},
"start_time": {
"OTIO_SCHEMA": "RationalTime.1",
Expand Down
1 change: 0 additions & 1 deletion lib/toucanView/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <dtk/ui/DialogSystem.h>
#include <dtk/ui/FileBrowser.h>
#include <dtk/ui/MessageDialog.h>
#include <dtk/ui/RecentFilesModel.h>
#include <dtk/ui/Settings.h>

#include <dtk/core/CmdLine.h>
Expand Down
59 changes: 45 additions & 14 deletions lib/toucanView/ClipItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ namespace toucan
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Clip>& clip,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline>& timeline,
const dtk::Color4F& color,
const std::shared_ptr<IWidget>& parent)
{
auto opt = clip->trimmed_range_in_parent();
const OTIO_NS::TimeRange timeRange = opt.has_value() ? opt.value() : OTIO_NS::TimeRange();
OTIO_NS::TimeRange timeRange = clip->transformed_time_range(
clip->trimmed_range(),
timeline->tracks());
if (timeline->global_start_time().has_value())
{
timeRange = OTIO_NS::TimeRange(
timeline->global_start_time().value() + timeRange.start_time(),
timeRange.duration());
}
IItem::_init(
context,
app,
Expand All @@ -24,25 +32,41 @@ namespace toucan
"toucan::ClipItem",
parent);

_setMousePressEnabled(0, 0);

_clip = clip;
_text = !clip->name().empty() ? clip->name() : "Clip";
_color = color;

setTooltip(clip->schema_name() + ": " + _text);

_layout = dtk::VerticalLayout::create(context, shared_from_this());
_layout->setSpacingRole(dtk::SizeRole::None);
_layout->setSpacingRole(dtk::SizeRole::SpacingTool);

_label = ItemLabel::create(context, _layout);
_label->setName(_text);

const auto& markers = clip->markers();
for (const auto& marker : markers)
if (!markers.empty())
{
auto markerItem = MarkerItem::create(context, app, marker, timeRange, _layout);
_markerItems.push_back(markerItem);
_markerLayout = TimeLayout::create(context, timeRange, _layout);
for (const auto& marker : markers)
{
OTIO_NS::TimeRange markerTimeRange = clip->transformed_time_range(
marker->marked_range(),
timeline->tracks());
if (timeline->global_start_time().has_value())
{
markerTimeRange = OTIO_NS::TimeRange(
timeline->global_start_time().value() + markerTimeRange.start_time(),
markerTimeRange.duration());
}
auto markerItem = MarkerItem::create(
context,
app,
marker,
markerTimeRange,
_markerLayout);
_markerItems.push_back(markerItem);
}
}

_textUpdate();
Expand All @@ -55,27 +79,36 @@ namespace toucan
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Clip>& clip,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline>& timeline,
const dtk::Color4F& color,
const std::shared_ptr<IWidget>& parent)
{
auto out = std::make_shared<ClipItem>();
out->_init(context, app, clip, color, parent);
out->_init(context, app, clip, timeline, color, parent);
return out;
}

void ClipItem::setScale(double value)
{
IItem::setScale(value);
for (const auto& markerItem : _markerItems)
if (_markerLayout)
{
markerItem->setScale(value);
_markerLayout->setScale(value);
}
}

void ClipItem::setGeometry(const dtk::Box2I& value)
{
IItem::setGeometry(value);
_layout->setGeometry(value);
_geom.g2 = dtk::margin(value, -_size.border, 0, -_size.border, 0);
_geom.g3 = dtk::margin(_label->getGeometry(), -_size.border, 0, -_size.border, 0);
_selectionRect = _geom.g3;
}

dtk::Box2I ClipItem::getChildrenClipRect() const
{
return _geom.g2;
}

void ClipItem::sizeHintEvent(const dtk::SizeHintEvent& event)
Expand All @@ -96,10 +129,8 @@ namespace toucan
const dtk::DrawEvent& event)
{
IItem::drawEvent(drawRect, event);
const dtk::Box2I& g = _label->getGeometry();
const dtk::Box2I g2 = dtk::margin(g, -_size.border, 0, -_size.border, 0);
event.render->drawRect(
g2,
_geom.g3,
_selected ? event.style->getColorRole(dtk::ColorRole::Yellow) : _color);
}

Expand Down
11 changes: 11 additions & 0 deletions lib/toucanView/ClipItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace toucan
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<App>&,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Clip>&,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline>&,
const dtk::Color4F&,
const std::shared_ptr<IWidget>& parent);

Expand All @@ -32,12 +33,14 @@ namespace toucan
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<App>&,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Clip>&,
const OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline>&,
const dtk::Color4F&,
const std::shared_ptr<IWidget>& parent = nullptr);

void setScale(double) override;

void setGeometry(const dtk::Box2I&) override;
dtk::Box2I getChildrenClipRect() const override;
void sizeHintEvent(const dtk::SizeHintEvent&) override;
void drawEvent(const dtk::Box2I&, const dtk::DrawEvent&) override;

Expand All @@ -53,6 +56,7 @@ namespace toucan

std::shared_ptr<dtk::VerticalLayout> _layout;
std::shared_ptr<ItemLabel> _label;
std::shared_ptr<TimeLayout> _markerLayout;
std::vector<std::shared_ptr<MarkerItem> > _markerItems;

struct SizeData
Expand All @@ -62,5 +66,12 @@ namespace toucan
int border = 0;
};
SizeData _size;

struct GeomData
{
dtk::Box2I g2;
dtk::Box2I g3;
};
GeomData _geom;
};
}
Loading

0 comments on commit 929d66b

Please sign in to comment.