Tweaks to not-yet-built SimpleVideoView.
[dcpomatic.git] / src / wx / simple_video_view.cc
1 /*
2     Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 SimpleVideoView::SimpleVideoView (wxWindow* parent)
22 {
23         _panel = new wxPanel (parent);
24
25 #ifndef __WXOSX__
26         _panel->SetDoubleBuffered (true);
27 #endif
28
29         _panel->SetBackgroundStyle (wxBG_STYLE_PAINT);
30         _panel->SetBackgroundColour (*wxBLACK);
31
32         _panel->Bind (wxEVT_PAINT, boost::bind (&SimpleVideoView::paint, this));
33 }
34
35 void
36 SimpleVideoView::paint ()
37 {
38         wxPaintDC dc (_panel);
39
40 #ifdef DCPOMATIC_VARIANT_SWAROOP
41         if (_background_image) {
42                 dc.Clear ();
43                 maybe_draw_background_image (dc);
44                 _state_timer.unset ();
45                 return;
46         }
47 #endif
48
49         if (!_out_size.width || !_out_size.height || !_film || !_frame || _out_size != _frame->size()) {
50                 dc.Clear ();
51         } else {
52
53                 wxImage frame (_out_size.width, _out_size.height, _frame->data()[0], true);
54                 wxBitmap frame_bitmap (frame);
55                 dc.DrawBitmap (frame_bitmap, 0, max(0, (_panel_size.height - _out_size.height) / 2));
56
57 #ifdef DCPOMATIC_VARIANT_SWAROOP
58                 DCPTime const period = DCPTime::from_seconds(Config::instance()->player_watermark_period() * 60);
59                 int64_t n = _video_position.get() / period.get();
60                 DCPTime from(n * period.get());
61                 DCPTime to = from + DCPTime::from_seconds(Config::instance()->player_watermark_duration() / 1000.0);
62                 if (from <= _video_position && _video_position <= to) {
63                         if (!_in_watermark) {
64                                 _in_watermark = true;
65                                 _watermark_x = rand() % _panel_size.width;
66                                 _watermark_y = rand() % _panel_size.height;
67                         }
68                         dc.SetTextForeground(*wxWHITE);
69                         string wm = Config::instance()->player_watermark_theatre();
70                         boost::posix_time::ptime t = boost::posix_time::second_clock::local_time();
71                         wm += "\n" + boost::posix_time::to_iso_extended_string(t);
72                         dc.DrawText(std_to_wx(wm), _watermark_x, _watermark_y);
73                 } else {
74                         _in_watermark = false;
75                 }
76 #endif
77         }
78
79         if (_out_size.width < _panel_size.width) {
80                 /* XXX: these colours are right for GNOME; may need adjusting for other OS */
81                 wxPen   p (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
82                 wxBrush b (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
83                 dc.SetPen (p);
84                 dc.SetBrush (b);
85                 dc.DrawRectangle (_out_size.width, 0, _panel_size.width - _out_size.width, _panel_size.height);
86         }
87
88         if (_out_size.height < _panel_size.height) {
89                 wxPen   p (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
90                 wxBrush b (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
91                 dc.SetPen (p);
92                 dc.SetBrush (b);
93                 int const gap = (_panel_size.height - _out_size.height) / 2;
94                 dc.DrawRectangle (0, 0, _panel_size.width, gap);
95                 dc.DrawRectangle (0, gap + _out_size.height + 1, _panel_size.width, gap + 1);
96         }
97
98         if (_outline_content) {
99                 wxPen p (wxColour (255, 0, 0), 2);
100                 dc.SetPen (p);
101                 dc.SetBrush (*wxTRANSPARENT_BRUSH);
102                 dc.DrawRectangle (_inter_position.x, _inter_position.y + (_panel_size.height - _out_size.height) / 2, _inter_size.width, _inter_size.height);
103         }
104 }