#define DCPOMATIC_RECT_H
#include "position.h"
+#include <boost/optional.hpp>
#include <algorithm>
/* Put this inside a namespace as Apple put a Rect in the global namespace */
return Position<T> (x, y);
}
- Rect<T> intersection (Rect<T> const & other) const
+ boost::optional<Rect<T> > intersection (Rect<T> const & other) const
{
- T const tx = max (x, other.x);
- T const ty = max (y, other.y);
+ /* This isn't exactly the paragon of mathematical precision */
- return Rect (
+ T const tx = std::max (x, other.x);
+ T const ty = std::max (y, other.y);
+
+ Rect r (
tx, ty,
- min (x + width, other.x + other.width) - tx,
- min (y + height, other.y + other.height) - ty
+ std::min (x + width, other.x + other.width) - tx,
+ std::min (y + height, other.y + other.height) - ty
);
+
+ if (r.width < 0 || r.height < 0) {
+ return boost::optional<Rect<T> > ();
+ }
+
+ return r;
}
void extend (Rect<T> const & other)
return;
}
- for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
- (*i)->paint (gc);
+
+ BOOST_FOREACH (shared_ptr<TimelineView> i, _views) {
+
+ shared_ptr<TimelineContentView> ic = dynamic_pointer_cast<TimelineContentView> (i);
+
+ /* Find areas of overlap */
+ list<dcpomatic::Rect<int> > overlaps;
+ BOOST_FOREACH (shared_ptr<TimelineView> j, _views) {
+ shared_ptr<TimelineContentView> jc = dynamic_pointer_cast<TimelineContentView> (j);
+ if (!ic || !jc || i == j || ic->track() != jc->track() || !ic->active() || !jc->active()) {
+ continue;
+ }
+
+ optional<dcpomatic::Rect<int> > r = j->bbox().intersection (i->bbox());
+ if (r) {
+ overlaps.push_back (r.get ());
+ }
+ }
+
+ i->paint (gc, overlaps);
}
delete gc;
continue;
}
- shared_ptr<Content> content = cv->content();
-
- if (dynamic_pointer_cast<VideoContent> (content)) {
+ if (dynamic_pointer_cast<TimelineVideoContentView> (*i)) {
/* Video on track 0 */
cv->set_track (0);
_tracks = max (_tracks, 1);
continue;
- } else if (dynamic_pointer_cast<SubtitleContent> (content)) {
+ } else if (dynamic_pointer_cast<TimelineSubtitleContentView> (*i)) {
/* Subtitles on track 1 */
cv->set_track (1);
_tracks = max (_tracks, 2);
/* Audio on tracks 2 and up */
int t = 2;
+ shared_ptr<Content> content = cv->content();
DCPTimePeriod content_period (content->position(), content->end());
while (true) {
TimelineAudioContentView (Timeline& tl, boost::shared_ptr<Content> c);
private:
+ bool active () const {
+ return true;
+ }
wxColour background_colour () const;
wxColour foreground_colour () const;
};
#include <wx/graphics.h>
#include <boost/foreach.hpp>
+using std::list;
using boost::shared_ptr;
TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
}
void
-TimelineContentView::do_paint (wxGraphicsContext* gc)
+TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> > overlaps)
{
DCPOMATIC_ASSERT (_track);
gc->StrokePath (path);
}
+ /* Overlaps */
+ gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
+ for (list<dcpomatic::Rect<int> >::const_iterator i = overlaps.begin(); i != overlaps.end(); ++i) {
+ gc->DrawRectangle (i->x, i->y + 4, i->width, i->height - 8);
+ }
+
/* Label text */
wxString name = std_to_wx (cont->summary());
wxDouble name_width;
/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
void unset_track ();
boost::optional<int> track () const;
+ virtual bool active () const = 0;
virtual wxColour background_colour () const = 0;
virtual wxColour foreground_colour () const = 0;
private:
- void do_paint (wxGraphicsContext* gc);
+ void do_paint (wxGraphicsContext* gc, std::list<dcpomatic::Rect<int> > overlaps);
int y_pos (int t) const;
void content_changed (int p);
/*
- Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <boost/foreach.hpp>
using std::min;
+using std::list;
TimelineReelsView::TimelineReelsView (Timeline& tl, int y)
: TimelineView (tl)
}
void
-TimelineReelsView::do_paint (wxGraphicsContext* gc)
+TimelineReelsView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> >)
{
if (!_timeline.pixels_per_second()) {
return;
/*
- Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
void set_y (int y);
private:
- void do_paint (wxGraphicsContext* gc);
+ void do_paint (wxGraphicsContext* gc, std::list<dcpomatic::Rect<int> > overlaps);
private:
int _y;
TimelineSubtitleContentView::background_colour () const
{
shared_ptr<SubtitleContent> sc = _subtitle_content.lock ();
- if (!sc || !sc->use_subtitles ()) {
+ if (!active ()) {
return wxColour (210, 210, 210, 128);
}
TimelineSubtitleContentView::foreground_colour () const
{
shared_ptr<SubtitleContent> sc = _subtitle_content.lock ();
- if (!sc || !sc->use_subtitles ()) {
+ if (!active ()) {
return wxColour (180, 180, 180, 128);
}
return wxColour (0, 0, 0, 255);
}
+
+bool
+TimelineSubtitleContentView::active () const
+{
+ shared_ptr<SubtitleContent> sc = _subtitle_content.lock ();
+ return sc && sc->use_subtitles();
+}
TimelineSubtitleContentView (Timeline& tl, boost::shared_ptr<SubtitleContent> c);
private:
+ bool active () const;
wxColour background_colour () const;
wxColour foreground_colour () const;
/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <wx/wx.h>
#include <wx/graphics.h>
+using std::list;
+
TimelineTimeAxisView::TimelineTimeAxisView (Timeline& tl, int y)
: TimelineView (tl)
, _y (y)
}
void
-TimelineTimeAxisView::do_paint (wxGraphicsContext* gc)
+TimelineTimeAxisView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> >)
{
if (!_timeline.pixels_per_second()) {
return;
/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
void set_y (int y);
private:
- void do_paint (wxGraphicsContext* gc);
+ void do_paint (wxGraphicsContext* gc, std::list<dcpomatic::Rect<int> > overlaps);
private:
int _y;
TimelineVideoContentView (Timeline& tl, boost::shared_ptr<Content> c);
private:
+ bool active () const {
+ return true;
+ }
wxColour background_colour () const;
wxColour foreground_colour () const;
};
#include "timeline_view.h"
#include "timeline.h"
+using std::list;
+
/** @class TimelineView
* @brief Parent class for components of the timeline (e.g. a piece of content or an axis).
*/
}
void
-TimelineView::paint (wxGraphicsContext* g)
+TimelineView::paint (wxGraphicsContext* g, list<dcpomatic::Rect<int> > overlaps)
{
_last_paint_bbox = bbox ();
- do_paint (g);
+ do_paint (g, overlaps);
}
void
TimelineView (Timeline& t);
virtual ~TimelineView () {}
- void paint (wxGraphicsContext* g);
+ void paint (wxGraphicsContext* g, std::list<dcpomatic::Rect<int> > overlaps);
void force_redraw ();
virtual dcpomatic::Rect<int> bbox () const = 0;
protected:
- virtual void do_paint (wxGraphicsContext *) = 0;
+ virtual void do_paint (wxGraphicsContext *, std::list<dcpomatic::Rect<int> > overlaps) = 0;
int time_x (DCPTime t) const;
--- /dev/null
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "lib/rect.h"
+#include <boost/test/unit_test.hpp>
+#include <iostream>
+
+using boost::optional;
+
+BOOST_AUTO_TEST_CASE (rect_test)
+{
+ dcpomatic::Rect<int> a (0, 0, 100, 100);
+ dcpomatic::Rect<int> b (200, 200, 100, 100);
+ optional<dcpomatic::Rect<int> > c = a.intersection (b);
+ BOOST_CHECK (!c);
+}
ratio_test.cc
repeat_frame_test.cc
recover_test.cc
+ rect_test.cc
reels_test.cc
required_disk_space_test.cc
resampler_test.cc