/* Copyright (C) 2019 Carl Hetherington This file is part of DCP-o-matic. DCP-o-matic 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. DCP-o-matic 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 DCP-o-matic. If not, see . */ #include "simple_video_view.h" #include "film_viewer.h" #include "wx_util.h" #include "lib/image.h" #include #include #include using std::max; using std::string; using boost::optional; using namespace dcpomatic; SimpleVideoView::SimpleVideoView (FilmViewer* viewer, wxWindow* parent) : VideoView (viewer) { _panel = new wxPanel (parent); #ifndef __WXOSX__ _panel->SetDoubleBuffered (true); #endif _panel->SetBackgroundStyle (wxBG_STYLE_PAINT); _panel->SetBackgroundColour (*wxBLACK); _panel->Bind (wxEVT_PAINT, boost::bind (&SimpleVideoView::paint, this)); _panel->Bind (wxEVT_SIZE, boost::bind(boost::ref(Sized))); } 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()) { dc.Clear (); optional 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 if (!out_size.width || !out_size.height || !_image || out_size != _image->size()) { dc.Clear (); } else { wxImage frame (out_size.width, out_size.height, _image->data()[0], true); wxBitmap frame_bitmap (frame); dc.DrawBitmap (frame_bitmap, 0, max(0, (panel_size.GetHeight() - out_size.height) / 2)); #ifdef DCPOMATIC_VARIANT_SWAROOP DCPTime const period = DCPTime::from_seconds(Config::instance()->player_watermark_period() * 60); 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 <= _viewer->video_position() && _viewer->video_position() <= to) { if (!_in_watermark) { _in_watermark = true; _watermark_x = rand() % panel_size.GetWidth(); _watermark_y = rand() % panel_size.GetHeight(); } dc.SetTextForeground(*wxWHITE); string wm = Config::instance()->player_watermark_theatre(); boost::posix_time::ptime t = boost::posix_time::second_clock::local_time(); wm += "\n" + boost::posix_time::to_iso_extended_string(t); dc.DrawText(std_to_wx(wm), _watermark_x, _watermark_y); } else { _in_watermark = false; } #endif } if (out_size.width < panel_size.GetWidth()) { /* XXX: these colours are right for GNOME; may need adjusting for other OS */ wxPen p (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240)); wxBrush b (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240)); dc.SetPen (p); dc.SetBrush (b); dc.DrawRectangle (out_size.width, 0, panel_size.GetWidth() - out_size.width, panel_size.GetHeight()); } if (out_size.height < panel_size.GetHeight()) { wxPen p (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240)); wxBrush b (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240)); dc.SetPen (p); dc.SetBrush (b); int const gap = (panel_size.GetHeight() - out_size.height) / 2; dc.DrawRectangle (0, 0, panel_size.GetWidth(), gap); dc.DrawRectangle (0, gap + out_size.height + 1, panel_size.GetWidth(), gap + 1); } if (_viewer->outline_content()) { Position inter_position = _viewer->inter_position (); dcp::Size inter_size = _viewer->inter_size (); wxPen p (wxColour (255, 0, 0), 2); dc.SetPen (p); 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 (); }