summaryrefslogtreecommitdiffstats
path: root/libmpv/wxwidgets_opengl/main.h
blob: 14628ed3f0c72e40b3d89c9be2f35357bfdf23bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once

#include <functional>

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include <wx/glcanvas.h>

#include <mpv/client.h>
#include <mpv/opengl_cb.h>

class MpvApp : public wxApp
{
public:
    bool OnInit() override;
};

class MpvGLCanvas : public wxGLCanvas
{
public:
    MpvGLCanvas(wxWindow *parent);
    ~MpvGLCanvas();

    void Render();
    bool SetCurrent() const;
    bool SwapBuffers() override;
    void *GetProcAddress(const char *name);

    std::function<void (wxGLCanvas *, int w, int h)> OnRender = nullptr;
    std::function<void (wxGLCanvas *)> OnSwapBuffers = nullptr;

private:
    void OnSize(wxSizeEvent &event);
    void OnPaint(wxPaintEvent &event);
    void OnErase(wxEraseEvent &event);

    void DoRender();

    wxGLContext *glContext = nullptr;

    wxDECLARE_EVENT_TABLE();
};

class MpvFrame : public wxFrame
{
public:
    MpvFrame();

    bool Destroy() override;
    bool Autofit(int percent, bool larger = true, bool smaller = true);

private:
    void MpvCreate();
    void MpvDestroy();

    void OnSize(wxSizeEvent &event);
    void OnKeyDown(wxKeyEvent &event);
    void OnDropFiles(wxDropFilesEvent &event);

    void OnMpvEvent(mpv_event &event);
    void OnMpvWakeupEvent(wxThreadEvent &event);
    void OnMpvRedrawEvent(wxThreadEvent &event);

    void DoMpvDraw(int w, int h);
    void DoMpvFlip();

    mpv_handle *mpv = nullptr;
    mpv_opengl_cb_context *mpv_gl = nullptr;
    MpvGLCanvas *glCanvas = nullptr;

    wxDECLARE_EVENT_TABLE();
};