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"
23 #include "lib/image.h"
26 #include <boost/bind.hpp>
30 SimpleVideoView::SimpleVideoView (FilmViewer* viewer, wxWindow* parent)
33 _panel = new wxPanel (parent);
36 _panel->SetDoubleBuffered (true);
39 _panel->SetBackgroundStyle (wxBG_STYLE_PAINT);
40 _panel->SetBackgroundColour (*wxBLACK);
42 _panel->Bind (wxEVT_PAINT, boost::bind (&SimpleVideoView::paint, this));
46 SimpleVideoView::paint ()
48 wxPaintDC dc (_panel);
50 #ifdef DCPOMATIC_VARIANT_SWAROOP
51 if (viewer->background_image()) {
53 maybe_draw_background_image (dc);
58 dcp::Size const out_size = _viewer->out_size ();
59 wxSize const panel_size = _panel->GetSize ();
61 if (!out_size.width || !out_size.height || !_image || out_size != _image->size()) {
65 wxImage frame (out_size.width, out_size.height, _image->data()[0], true);
66 wxBitmap frame_bitmap (frame);
67 dc.DrawBitmap (frame_bitmap, 0, max(0, (panel_size.GetHeight() - out_size.height) / 2));
69 #ifdef DCPOMATIC_VARIANT_SWAROOP
71 DCPTime const period = DCPTime::from_seconds(Config::instance()->player_watermark_period() * 60);
72 int64_t n = _video_position.get() / period.get();
73 DCPTime from(n * period.get());
74 DCPTime to = from + DCPTime::from_seconds(Config::instance()->player_watermark_duration() / 1000.0);
75 if (from <= _video_position && _video_position <= to) {
78 _watermark_x = rand() % _panel_size.width;
79 _watermark_y = rand() % _panel_size.height;
81 dc.SetTextForeground(*wxWHITE);
82 string wm = Config::instance()->player_watermark_theatre();
83 boost::posix_time::ptime t = boost::posix_time::second_clock::local_time();
84 wm += "\n" + boost::posix_time::to_iso_extended_string(t);
85 dc.DrawText(std_to_wx(wm), _watermark_x, _watermark_y);
87 _in_watermark = false;
92 if (out_size.width < panel_size.GetWidth()) {
93 /* XXX: these colours are right for GNOME; may need adjusting for other OS */
94 wxPen p (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
95 wxBrush b (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
98 dc.DrawRectangle (out_size.width, 0, panel_size.GetWidth() - out_size.width, panel_size.GetHeight());
101 if (out_size.height < panel_size.GetHeight()) {
102 wxPen p (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
103 wxBrush b (_viewer->pad_black() ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
106 int const gap = (panel_size.GetHeight() - out_size.height) / 2;
107 dc.DrawRectangle (0, 0, panel_size.GetWidth(), gap);
108 dc.DrawRectangle (0, gap + out_size.height + 1, panel_size.GetWidth(), gap + 1);
111 if (_viewer->outline_content()) {
112 Position<int> inter_position = _viewer->inter_position ();
113 dcp::Size inter_size = _viewer->inter_size ();
114 wxPen p (wxColour (255, 0, 0), 2);
116 dc.SetBrush (*wxTRANSPARENT_BRUSH);
117 dc.DrawRectangle (inter_position.x, inter_position.y + (panel_size.GetHeight() - out_size.height) / 2, inter_size.width, inter_size.height);