Fix update on drag with GL canvas.
[dcpomatic.git] / src / wx / gl_video_view.cc
index 5c18d28cb895c34855775df41ee0f997ff6598d6..b3f036ded57d30a3949724c447f5e399c7ecf4f0 100644 (file)
 
 using std::cout;
 using boost::shared_ptr;
+using boost::optional;
 
 GLVideoView::GLVideoView (wxWindow *parent)
 {
        _canvas = new wxGLCanvas (parent, wxID_ANY, 0, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE);
        _context = new wxGLContext (_canvas);
-       _canvas->Bind (wxEVT_PAINT, boost::bind(&GLVideoView::paint, this, _1));
+       _canvas->Bind (wxEVT_PAINT, boost::bind(&GLVideoView::paint, this));
+       _canvas->Bind (wxEVT_SIZE, boost::bind(boost::ref(Sized)));
 
        glGenTextures (1, &_id);
        glBindTexture (GL_TEXTURE_2D, _id);
@@ -51,8 +53,6 @@ GLVideoView::~GLVideoView ()
 {
        glDeleteTextures (1, &_id);
        delete _context;
-       /* XXX: should we delete this? */
-       delete _canvas;
 }
 
 static void
@@ -65,10 +65,26 @@ check_gl_error (char const * last)
 }
 
 void
-GLVideoView::paint (wxPaintEvent &)
+GLVideoView::paint ()
 {
        _canvas->SetCurrent (*_context);
        wxPaintDC dc (_canvas);
+       draw ();
+}
+
+void
+GLVideoView::update ()
+{
+       if (!_canvas->IsShownOnScreen()) {
+               return;
+       }
+       wxClientDC dc (_canvas);
+       draw ();
+}
+
+void
+GLVideoView::draw ()
+{
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        check_gl_error ("glClear");
 
@@ -116,6 +132,11 @@ GLVideoView::paint (wxPaintEvent &)
 void
 GLVideoView::set_image (shared_ptr<const Image> image)
 {
+       if (!image) {
+               _size = optional<dcp::Size>();
+               return;
+       }
+
        DCPOMATIC_ASSERT (image->pixel_format() == AV_PIX_FMT_RGB24);
        DCPOMATIC_ASSERT (!image->aligned());
 
@@ -131,6 +152,4 @@ GLVideoView::set_image (shared_ptr<const Image> image)
        glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        check_gl_error ("glTexParameterf");
-
-       _canvas->Refresh ();
 }