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 SimpleVideoView::SimpleVideoView (wxWindow* parent)
23 _panel = new wxPanel (parent);
26 _panel->SetDoubleBuffered (true);
29 _panel->SetBackgroundStyle (wxBG_STYLE_PAINT);
30 _panel->SetBackgroundColour (*wxBLACK);
32 _panel->Bind (wxEVT_PAINT, boost::bind (&SimpleVideoView::paint_panel, this));
33 _panel->Bind (wxEVT_SIZE, boost::bind (&SimpleVideoView::panel_sized, this, _1));
37 SimpleVideoView::paint_panel ()
39 wxPaintDC dc (_panel);
41 #ifdef DCPOMATIC_VARIANT_SWAROOP
42 if (_background_image) {
44 maybe_draw_background_image (dc);
45 _state_timer.unset ();
50 if (!_out_size.width || !_out_size.height || !_film || !_frame || _out_size != _frame->size()) {
54 wxImage frame (_out_size.width, _out_size.height, _frame->data()[0], true);
55 wxBitmap frame_bitmap (frame);
56 dc.DrawBitmap (frame_bitmap, 0, max(0, (_panel_size.height - _out_size.height) / 2));
58 #ifdef DCPOMATIC_VARIANT_SWAROOP
59 DCPTime const period = DCPTime::from_seconds(Config::instance()->player_watermark_period() * 60);
60 int64_t n = _video_position.get() / period.get();
61 DCPTime from(n * period.get());
62 DCPTime to = from + DCPTime::from_seconds(Config::instance()->player_watermark_duration() / 1000.0);
63 if (from <= _video_position && _video_position <= to) {
66 _watermark_x = rand() % _panel_size.width;
67 _watermark_y = rand() % _panel_size.height;
69 dc.SetTextForeground(*wxWHITE);
70 string wm = Config::instance()->player_watermark_theatre();
71 boost::posix_time::ptime t = boost::posix_time::second_clock::local_time();
72 wm += "\n" + boost::posix_time::to_iso_extended_string(t);
73 dc.DrawText(std_to_wx(wm), _watermark_x, _watermark_y);
75 _in_watermark = false;
80 if (_out_size.width < _panel_size.width) {
81 /* XXX: these colours are right for GNOME; may need adjusting for other OS */
82 wxPen p (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
83 wxBrush b (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
86 dc.DrawRectangle (_out_size.width, 0, _panel_size.width - _out_size.width, _panel_size.height);
89 if (_out_size.height < _panel_size.height) {
90 wxPen p (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
91 wxBrush b (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
94 int const gap = (_panel_size.height - _out_size.height) / 2;
95 dc.DrawRectangle (0, 0, _panel_size.width, gap);
96 dc.DrawRectangle (0, gap + _out_size.height + 1, _panel_size.width, gap + 1);
99 if (_outline_content) {
100 wxPen p (wxColour (255, 0, 0), 2);
102 dc.SetBrush (*wxTRANSPARENT_BRUSH);
103 dc.DrawRectangle (_inter_position.x, _inter_position.y + (_panel_size.height - _out_size.height) / 2, _inter_size.width, _inter_size.height);
108 SimpleVideoView::panel_sized (wxSizeEvent& ev)
110 _panel_size.width = ev.GetSize().GetWidth();
111 _panel_size.height = ev.GetSize().GetHeight();
114 if (!quick_refresh()) {