2 Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "simple_video_view.h"
22 #include "film_viewer.h"
24 #include "lib/image.h"
27 #include <boost/bind.hpp>
31 using boost::optional;
32 using namespace dcpomatic;
34 SimpleVideoView::SimpleVideoView (FilmViewer* viewer, wxWindow* parent)
37 _panel = new wxPanel (parent);
40 _panel->SetDoubleBuffered (true);
43 _panel->SetBackgroundStyle (wxBG_STYLE_PAINT);
44 _panel->SetBackgroundColour (*wxBLACK);
46 _panel->Bind (wxEVT_PAINT, boost::bind (&SimpleVideoView::paint, this));
47 _panel->Bind (wxEVT_SIZE, boost::bind(boost::ref(Sized)));
51 SimpleVideoView::paint ()
53 _viewer->state_timer().set("paint-panel");
54 wxPaintDC dc (_panel);
56 dcp::Size const out_size = _viewer->out_size ();
57 wxSize const panel_size = _panel->GetSize ();
59 #ifdef DCPOMATIC_VARIANT_SWAROOP
60 if (_viewer->background_image()) {
62 optional<boost::filesystem::path> bg = Config::instance()->player_background_image();
64 wxImage image (std_to_wx(bg->string()));
65 wxBitmap bitmap (image);
66 dc.DrawBitmap (bitmap, max(0, (panel_size.GetWidth() - image.GetSize().GetWidth()) / 2), max(0, (panel_size.GetHeight() - image.GetSize().GetHeight()) / 2));
72 if (!out_size.width || !out_size.height || !_image || out_size != _image->size()) {
76 wxImage frame (out_size.width, out_size.height, _image->data()[0], true);
77 wxBitmap frame_bitmap (frame);
78 dc.DrawBitmap (frame_bitmap, 0, max(0, (panel_size.GetHeight() - out_size.height) / 2));
80 #ifdef DCPOMATIC_VARIANT_SWAROOP
81 DCPTime const period = DCPTime::from_seconds(Config::instance()->player_watermark_period() * 60);
82 int64_t n = _viewer->video_position().get() / period.get();
83 DCPTime from(n * period.get());
84 DCPTime to = from + DCPTime::from_seconds(Config::instance()->player_watermark_duration() / 1000.0);
85 if (from <= _viewer->video_position() && _viewer->video_position() <= to) {
88 _watermark_x = rand() % panel_size.GetWidth();
89 _watermark_y = rand() % panel_size.GetHeight();
91 dc.SetTextForeground(*wxWHITE);
92 string wm = Config::instance()->player_watermark_theatre();
93 boost::posix_time::ptime t = boost::posix_time::second_clock::local_time();
94 wm += "\n" + boost::posix_time::to_iso_extended_string(t);
95 dc.DrawText(std_to_wx(wm), _watermark_x, _watermark_y);
97 _in_watermark = false;
102 if (out_size.width < panel_size.GetWidth()) {
103 /* XXX: these colours are right for GNOME; may need adjusting for other OS */
104 wxPen p (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
105 wxBrush b (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
108 dc.DrawRectangle (out_size.width, 0, panel_size.GetWidth() - out_size.width, panel_size.GetHeight());
111 if (out_size.height < panel_size.GetHeight()) {
112 wxPen p (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
113 wxBrush b (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
116 int const gap = (panel_size.GetHeight() - out_size.height) / 2;
117 dc.DrawRectangle (0, 0, panel_size.GetWidth(), gap);
118 dc.DrawRectangle (0, gap + out_size.height + 1, panel_size.GetWidth(), gap + 1);
121 if (_viewer->outline_content()) {
122 Position<int> inter_position = _viewer->inter_position ();
123 dcp::Size inter_size = _viewer->inter_size ();
124 wxPen p (wxColour (255, 0, 0), 2);
126 dc.SetBrush (*wxTRANSPARENT_BRUSH);
127 dc.DrawRectangle (inter_position.x, inter_position.y + (panel_size.GetHeight() - out_size.height) / 2, inter_size.width, inter_size.height);
129 _viewer->state_timer().unset();
133 SimpleVideoView::update ()