Tinkering.
[dcpomatic.git] / src / wx / film_viewer.cc
1 #include <iostream>
2 #include "lib/film.h"
3 #include "film_viewer.h"
4
5 using namespace std;
6
7 class ThumbPanel : public wxPanel
8 {
9 public:
10         ThumbPanel (wxFrame* parent)
11                 : wxPanel (parent)
12                 , _bitmap (0)
13         {
14         }
15
16         void paint_event (wxPaintEvent& ev)
17         {
18                 if (!_bitmap) {
19                         return;
20                 }
21
22                 cout << "RENDER\n";
23                 
24                 wxPaintDC dc (this);
25                 dc.DrawBitmap (*_bitmap, 0, 0, false);
26         }
27
28         void set_bitmap (wxBitmap* bitmap)
29         {
30                 _bitmap = bitmap;
31         }
32
33         DECLARE_EVENT_TABLE ();
34
35 private:
36         wxBitmap* _bitmap;
37 };
38
39 BEGIN_EVENT_TABLE (ThumbPanel, wxPanel)
40 EVT_PAINT (ThumbPanel::paint_event)
41 END_EVENT_TABLE ()
42
43 FilmViewer::FilmViewer (Film* f, wxFrame* p)
44         : _film (f)
45         , _image (0)
46         , _scaled_image (0)
47         , _bitmap (0)
48 {
49         _thumb_panel = new ThumbPanel (p);
50         _thumb_panel->Show (true);
51         int x, y;
52         _thumb_panel->GetSize (&x, &y);
53         cout << x << " " << y << "\n";
54 }
55
56 void
57 FilmViewer::load_thumbnail (int n)
58 {
59         if (_film == 0 && _film->num_thumbs() <= n) {
60                 return;
61         }
62
63         _image = new wxImage (wxString (_film->thumb_file(n).c_str (), wxConvUTF8));
64         _scaled_image = new wxImage (_image->Scale (512, 512));
65         _bitmap = new wxBitmap (*_scaled_image);
66         _thumb_panel->set_bitmap (_bitmap);
67 }
68
69 wxPanel *
70 FilmViewer::get_widget ()
71 {
72         return _thumb_panel;
73 }