#include "simple_video_view.h"
#include "film_viewer.h"
+#include "wx_util.h"
#include "lib/image.h"
+#include "lib/dcpomatic_log.h"
+#include "lib/butler.h"
#include <dcp/util.h>
#include <wx/wx.h>
#include <boost/bind.hpp>
using std::max;
+using std::string;
+using boost::optional;
+using namespace dcpomatic;
SimpleVideoView::SimpleVideoView (FilmViewer* viewer, wxWindow* parent)
- : _viewer (viewer)
+ : VideoView (viewer)
{
_panel = new wxPanel (parent);
_panel->Bind (wxEVT_PAINT, boost::bind (&SimpleVideoView::paint, this));
_panel->Bind (wxEVT_SIZE, boost::bind(boost::ref(Sized)));
+
+ _timer.Bind (wxEVT_TIMER, boost::bind(&SimpleVideoView::timer, this));
}
void
SimpleVideoView::paint ()
{
+ _viewer->state_timer().set("paint-panel");
wxPaintDC dc (_panel);
+ dcp::Size const out_size = _viewer->out_size ();
+ wxSize const panel_size = _panel->GetSize ();
+
#ifdef DCPOMATIC_VARIANT_SWAROOP
- if (viewer->background_image()) {
+ if (_viewer->background_image()) {
dc.Clear ();
- maybe_draw_background_image (dc);
+ optional<boost::filesystem::path> bg = Config::instance()->player_background_image();
+ if (bg) {
+ wxImage image (std_to_wx(bg->string()));
+ wxBitmap bitmap (image);
+ dc.DrawBitmap (bitmap, max(0, (panel_size.GetWidth() - image.GetSize().GetWidth()) / 2), max(0, (panel_size.GetHeight() - image.GetSize().GetHeight()) / 2));
+ }
return;
}
#endif
- dcp::Size const out_size = _viewer->out_size ();
- wxSize const panel_size = _panel->GetSize ();
-
if (!out_size.width || !out_size.height || !_image || out_size != _image->size()) {
dc.Clear ();
} else {
dc.DrawBitmap (frame_bitmap, 0, max(0, (panel_size.GetHeight() - out_size.height) / 2));
#ifdef DCPOMATIC_VARIANT_SWAROOP
- XXX
DCPTime const period = DCPTime::from_seconds(Config::instance()->player_watermark_period() * 60);
- int64_t n = _video_position.get() / period.get();
+ int64_t n = _viewer->video_position().get() / period.get();
DCPTime from(n * period.get());
DCPTime to = from + DCPTime::from_seconds(Config::instance()->player_watermark_duration() / 1000.0);
- if (from <= _video_position && _video_position <= to) {
+ if (from <= _viewer->video_position() && _viewer->video_position() <= to) {
if (!_in_watermark) {
_in_watermark = true;
- _watermark_x = rand() % _panel_size.width;
- _watermark_y = rand() % _panel_size.height;
+ _watermark_x = rand() % panel_size.GetWidth();
+ _watermark_y = rand() % panel_size.GetHeight();
}
dc.SetTextForeground(*wxWHITE);
string wm = Config::instance()->player_watermark_theatre();
dc.SetBrush (*wxTRANSPARENT_BRUSH);
dc.DrawRectangle (inter_position.x, inter_position.y + (panel_size.GetHeight() - out_size.height) / 2, inter_size.width, inter_size.height);
}
+ _viewer->state_timer().unset();
+}
+
+void
+SimpleVideoView::update ()
+{
+ _panel->Refresh ();
+ _panel->Update ();
+}
+
+void
+SimpleVideoView::timer ()
+{
+ if (!_viewer->_film || !_viewer->_playing) {
+ return;
+ }
+
+ _viewer->get (false);
+ DCPTime const next = _viewer->_video_position + _viewer->one_video_frame();
+
+ if (next >= _viewer->_film->length()) {
+ _viewer->stop ();
+ _viewer->Finished ();
+ return;
+ }
+
+ LOG_DEBUG_PLAYER("%1 -> %2; delay %3", next.seconds(), _viewer->time().seconds(), max((next.seconds() - _viewer->time().seconds()) * 1000, 1.0));
+ _timer.Start (max ((next.seconds() - _viewer->time().seconds()) * 1000, 1.0), wxTIMER_ONE_SHOT);
+
+ if (_viewer->_butler) {
+ _viewer->_butler->rethrow ();
+ }
}