summaryrefslogtreecommitdiff
path: root/Userland/Applications/VideoPlayer/VideoFrameWidget.h
blob: a1280fb306ac3fb04b0557be172d3e53fa09860c (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
/*
 * Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/StringView.h>
#include <LibGUI/Event.h>
#include <LibGUI/Frame.h>

namespace VideoPlayer {

enum class VideoSizingMode : u8 {
    Fit,
    Fill,
    Stretch,
    FullSize,
    Sentinel
};

class VideoFrameWidget final : public GUI::Frame {
    C_OBJECT(VideoFrameWidget)
public:
    virtual ~VideoFrameWidget() override = default;

    void set_bitmap(Gfx::Bitmap const*);
    Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); }

    void set_sizing_mode(VideoSizingMode value);
    VideoSizingMode sizing_mode() const { return m_sizing_mode; }

    void set_auto_resize(bool value);
    bool auto_resize() const { return m_auto_resize; }

    Function<void()> on_click;
    Function<void()> on_doubleclick;

protected:
    explicit VideoFrameWidget();

    virtual void mousedown_event(GUI::MouseEvent&) override;
    virtual void doubleclick_event(GUI::MouseEvent&) override;
    virtual void paint_event(GUI::PaintEvent&) override;

private:
    RefPtr<Gfx::Bitmap const> m_bitmap;
    VideoSizingMode m_sizing_mode { VideoSizingMode::Fit };
    bool m_auto_resize { false };
};

constexpr StringView video_sizing_mode_name(VideoSizingMode mode)
{
    switch (mode) {
    case VideoSizingMode::Fit:
        return "Fit"sv;
        break;
    case VideoSizingMode::Fill:
        return "Fill"sv;
        break;
    case VideoSizingMode::Stretch:
        return "Stretch"sv;
        break;
    case VideoSizingMode::FullSize:
        return "Full size"sv;
        break;
    default:
        VERIFY_NOT_REACHED();
    }
}

}