Various stuff; mostly change to decoder scaling and adding subtitle; scaling test.
[dcpomatic.git] / src / wx / film_viewer.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/film_viewer.h
21  *  @brief A wx widget to view `thumbnails' of a Film.
22  */
23
24 #include <wx/wx.h>
25 #include "lib/film.h"
26
27 class wxToggleButton;
28 class FFmpegPlayer;
29 class Image;
30 class RGBPlusAlphaImage;
31
32 /** @class FilmViewer
33  *  @brief A wx widget to view a preview of a Film.
34  *
35  *  The film takes the following path through the viewer:
36  *
37  *  1.  get_frame() asks our _player to decode some data.  If it does, process_video()
38  *      will be called.
39  *
40  *  2.  process_video() takes the image from the decoder (_raw_frame) and calls raw_to_display().
41  * 
42  *  3.  raw_to_display() copies _raw_frame to _display_frame, processing it and scaling it.
43  *
44  *  4.  calling _panel->Refresh() and _panel->Update() results in paint_panel() being called;
45  *      this creates frame_bitmap from _display_frame and blits it to the display.
46  *
47  * update_from_decoder() asks the player to re-emit its current frame on the next pass(), and then
48  * starts from step #1.
49  *
50  * update_from_raw() starts at step #3, then calls _panel->Refresh and _panel->Update.
51  */
52 class FilmViewer : public wxPanel
53 {
54 public:
55         FilmViewer (boost::shared_ptr<Film>, wxWindow *);
56
57         void set_film (boost::shared_ptr<Film>);
58
59 private:
60         void film_changed (Film::Property);
61         void film_content_changed (boost::weak_ptr<Content>, int);
62         void paint_panel (wxPaintEvent &);
63         void panel_sized (wxSizeEvent &);
64         void slider_moved (wxScrollEvent &);
65         void play_clicked (wxCommandEvent &);
66         void timer (wxTimerEvent &);
67         void process_video (boost::shared_ptr<const Image>, bool, Time);
68         void calculate_sizes ();
69         void check_play_state ();
70         void update_from_raw ();
71         void update_from_decoder ();
72         void raw_to_display ();
73         void get_frame ();
74         void active_jobs_changed (bool);
75         void back_clicked (wxCommandEvent &);
76         void forward_clicked (wxCommandEvent &);
77
78         boost::shared_ptr<Film> _film;
79         boost::shared_ptr<Player> _player;
80
81         wxSizer* _v_sizer;
82         wxPanel* _panel;
83         wxSlider* _slider;
84         wxButton* _back_button;
85         wxButton* _forward_button;
86         wxStaticText* _frame;
87         wxStaticText* _timecode;
88         wxToggleButton* _play_button;
89         wxTimer _timer;
90
91         boost::shared_ptr<const Image> _raw_frame;
92         boost::shared_ptr<const Image> _display_frame;
93         /* The x offset at which we display the actual film content; this corresponds
94            to the film's padding converted to our coordinates.
95         */
96         int _display_frame_x;
97         bool _got_frame;
98
99         /** Size of our output (including padding if we have any) */
100         libdcp::Size _out_size;
101         /** Size that we will make our film (equal to _out_size unless we have padding) */
102         libdcp::Size _film_size;
103         /** Size of the panel that we have available */
104         libdcp::Size _panel_size;
105 };