summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/GBAWidget.h
blob: 6eea08970e4484f51c5031e66ea98b97d9f63229 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#ifdef HAS_LIBMGBA

#include <memory>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>

#include <QImage>
#include <QPoint>
#include <QWidget>

#include "Common/CommonTypes.h"
#include "Core/HW/GBACore.h"

class QCloseEvent;
class QContextMenuEvent;
class QDragEnterEvent;
class QDropEvent;
class QMouseEvent;
class QPaintEvent;

namespace NetPlay
{
struct PadDetails;
}  // namespace NetPlay

class GBAWidget : public QWidget
{
  Q_OBJECT
public:
  explicit GBAWidget(std::weak_ptr<HW::GBA::Core> core, const HW::GBA::CoreInfo& info,
                     const std::optional<NetPlay::PadDetails>& netplay_pad);
  ~GBAWidget() override;

  void GameChanged(const HW::GBA::CoreInfo& info);
  void SetVideoBuffer(std::span<const u32> video_buffer);

  void SetVolume(int volume);
  void VolumeDown();
  void VolumeUp();
  bool IsMuted();
  void ToggleMute();
  void ToggleDisconnect();

  void LoadROM();
  void UnloadROM();
  void PromptForEReaderCards();
  void ResetCore();
  void DoState(bool export_state);
  void ImportExportSave(bool export_save);
  void Resize(int scale);

  bool IsBorderless() const;
  void SetBorderless(bool enable);

  bool IsAlwaysOnTop() const;
  void SetAlwaysOnTop(bool enable);

private:
  void UpdateTitle();
  void UpdateVolume();

  static Qt::WindowFlags LoadWindowFlags(int device_number);
  void LoadSettings();
  void SaveSettings();

  bool CanControlCore();
  bool CanResetCore();

  void closeEvent(QCloseEvent* event) override;
  void contextMenuEvent(QContextMenuEvent* event) override;
  void mouseDoubleClickEvent(QMouseEvent* event) override;
  void mousePressEvent(QMouseEvent* event) override;
  void mouseReleaseEvent(QMouseEvent* event) override;
  void mouseMoveEvent(QMouseEvent* event) override;
  void paintEvent(QPaintEvent* event) override;

  void dragEnterEvent(QDragEnterEvent* event) override;
  void dropEvent(QDropEvent* event) override;

  std::weak_ptr<HW::GBA::Core> m_core;
  HW::GBA::CoreInfo m_core_info;
  QImage m_last_frame;
  QImage m_previous_frame;
  int m_local_pad;
  bool m_is_local_pad;
  std::string m_netplayer_name;
  int m_volume;
  bool m_muted;
  bool m_force_disconnect;
  bool m_moving;
  QPoint m_move_pos;
  bool m_interframe_blending;
};

class GBAWidgetController : public QObject
{
  Q_OBJECT
public:
  explicit GBAWidgetController() = default;
  ~GBAWidgetController() override;

  void Create(std::weak_ptr<HW::GBA::Core> core, const HW::GBA::CoreInfo& info);
  void GameChanged(const HW::GBA::CoreInfo& info);
  void FrameEnded(std::span<const u32> video_buffer);

private:
  GBAWidget* m_widget{};
};
#endif  // HAS_LIBMGBA