File: draw-dock.hpp

package info (click to toggle)
obs-draw-dock 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 744 kB
  • sloc: cpp: 2,680; ansic: 887; sh: 259; makefile: 25
file content (125 lines) | stat: -rw-r--r-- 4,170 bytes parent folder | download
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
118
119
120
121
122
123
124
125
#pragma once
#include "qt-display.hpp"
#include <obs-frontend-api.h>
#include <QCheckBox>
#include <QComboBox>
#include <QDockWidget>
#include <QDoubleSpinBox>
#include <QMouseEvent>
#include <QToolBar>

typedef std::function<bool(QObject *, QEvent *)> EventFilterFunc;

class OBSEventFilter : public QObject {
	Q_OBJECT
public:
	OBSEventFilter(EventFilterFunc filter_) : filter(filter_) {}

protected:
	bool eventFilter(QObject *obj, QEvent *event) { return filter(obj, event); }

public:
	EventFilterFunc filter;
};

class DrawDock : public QWidget {
	Q_OBJECT
private:
	OBSEventFilter *eventFilter;
	OBSQTDisplay *preview;
	obs_source_t *draw_source = nullptr;
	gs_vertbuffer_t *box = nullptr;

	obs_source_t *mouse_down_target = nullptr;

	QToolBar *toolbar;
	QComboBox *drawCombo;
	QComboBox *toolCombo;
	QAction *colorAction;
	QAction *imageAction;
	QDoubleSpinBox *toolSizeSpin;
	QDoubleSpinBox *alphaSpin;
	QCheckBox *eraseCheckbox;

	obs_data_t *config;
	std::map<obs_hotkey_id, std::pair<QAction *, obs_data_t *>> favoriteToolHotkeys;
	obs_hotkey_id clearHotkey = OBS_INVALID_HOTKEY_ID;
	obs_hotkey_pair_id showHideHotkey = OBS_INVALID_HOTKEY_PAIR_ID;

	float zoom = 1.0f;
	float scrollX = 0.5f;
	float scrollY = 0.5f;
	int scrollingFromX = 0;
	int scrollingFromY = 0;

	bool tabletActive = false;

	QRect prevGeometry;
	bool prevFloating;
	Qt::DockWidgetArea prevArea;

	void *vendor;

	bool GetSourceRelativeXY(int mouseX, int mouseY, int &x, int &y);

	bool HandleMouseClickEvent(QMouseEvent *event);
	bool HandleMouseMoveEvent(QMouseEvent *event);
	bool HandleMouseWheelEvent(QWheelEvent *event);
	bool HandleFocusEvent(QFocusEvent *event);
	bool HandleKeyEvent(QKeyEvent *event);
	bool HandleTabletEvent(QTabletEvent *event);
	OBSEventFilter *BuildEventFilter();

	void DrawBackdrop(float cx, float cy);

	void CreateDrawSource(obs_source_t *source = nullptr);
	void DestroyDrawSource();

	void SaveConfig();

	void ClearDraw();

	QAction *AddFavoriteTool(obs_data_t *settings = nullptr);
	void ApplyFavoriteTool(obs_data_t *settings = nullptr);
	QIcon CreateToolIcon(obs_data_t *settings);
	QIcon CreateToolIcon(QColor toolColor, uint32_t tool, double alpha = 100.0, double toolSize = 20.0,
			     const char *image = nullptr);

	static void DrawPreview(void *data, uint32_t cx, uint32_t cy);
	static void frontend_event(enum obs_frontend_event event, void *data);
	static void draw_source_update(void *data, calldata_t *cd);
	static void draw_source_destroy(void *data, calldata_t *cd);
	static void source_create(void *data, calldata_t *cd);
	static void clear_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed);
	static bool show_hotkey(void *data, obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed);
	static bool hide_hotkey(void *data, obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed);
	static void favorite_tool_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed);
	static void vendor_request_version(obs_data_t *request_data, obs_data_t *response_data, void *);
	static void vendor_request_clear(obs_data_t *request_data, obs_data_t *response_data, void *);
	static void vendor_request_draw(obs_data_t *request_data, obs_data_t *response_data, void *);

	static bool scene_undo(obs_scene_t *, obs_sceneitem_t *item, void *);
	static bool scene_redo(obs_scene_t *, obs_sceneitem_t *item, void *);
	static bool scene_tool(obs_scene_t *, obs_sceneitem_t *item, void *);
	static bool scene_tool_color(obs_scene_t *, obs_sceneitem_t *item, void *);
	static bool scene_tool_image(obs_scene_t *, obs_sceneitem_t *item, void *);
	static bool scene_tool_size(obs_scene_t *, obs_sceneitem_t *item, void *);
	static bool scene_tool_alpha(obs_scene_t *, obs_sceneitem_t *item, void *);
	static bool scene_apply_tool(obs_scene_t *, obs_sceneitem_t *item, void *);

protected:
	virtual void showEvent(QShowEvent *) override;
	virtual void hideEvent(QHideEvent *) override;

private slots:
	void DrawSourceUpdate();
	void SceneChanged();
	void OpenFullScreenProjector();
	void EscapeTriggered();

public:
	void PostLoad();
	void FinishedLoad();
	DrawDock(QWidget *parent = nullptr);
	~DrawDock();
};