Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/run/embedded_process.h
9896 views
1
/**************************************************************************/
2
/* embedded_process.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "scene/gui/control.h"
34
35
class ScriptEditorDebugger;
36
37
class EmbeddedProcessBase : public Control {
38
GDCLASS(EmbeddedProcessBase, Control);
39
40
void _draw();
41
42
protected:
43
Ref<StyleBox> focus_style_box;
44
Size2i window_size;
45
bool keep_aspect = false;
46
Point2i margin_top_left;
47
Point2i margin_bottom_right;
48
Window *window = nullptr;
49
50
bool transp_enabled = false;
51
Color clear_color;
52
Ref<Texture2D> checkerboard;
53
54
void _project_settings_changed();
55
56
static void _bind_methods();
57
void _notification(int p_what);
58
59
public:
60
virtual void set_script_debugger(ScriptEditorDebugger *p_debugger) {}
61
62
virtual bool is_embedding_completed() const = 0;
63
virtual bool is_embedding_in_progress() const = 0;
64
virtual bool is_process_focused() const = 0;
65
virtual void embed_process(OS::ProcessID p_pid) = 0;
66
virtual int get_embedded_pid() const = 0;
67
virtual void reset() = 0;
68
virtual void request_close() = 0;
69
virtual void queue_update_embedded_process() = 0;
70
71
void set_window_size(const Size2i &p_window_size);
72
void set_keep_aspect(bool p_keep_aspect);
73
virtual Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const = 0;
74
Rect2i get_screen_embedded_window_rect() const;
75
int get_margin_size(Side p_side) const;
76
Size2 get_margins_size() const;
77
78
EmbeddedProcessBase();
79
virtual ~EmbeddedProcessBase();
80
};
81
82
class EmbeddedProcess : public EmbeddedProcessBase {
83
GDCLASS(EmbeddedProcess, EmbeddedProcessBase);
84
85
bool application_has_focus = true;
86
uint64_t last_application_focus_time = 0;
87
OS::ProcessID focused_process_id = 0;
88
OS::ProcessID current_process_id = 0;
89
bool embedding_grab_focus = false;
90
bool embedding_completed = false;
91
uint64_t start_embedding_time = 0;
92
bool updated_embedded_process_queued = false;
93
bool last_updated_embedded_process_focused = false;
94
95
Timer *timer_embedding = nullptr;
96
Timer *timer_update_embedded_process = nullptr;
97
98
const int embedding_timeout = 45000;
99
100
Rect2i last_global_rect;
101
102
void _try_embed_process();
103
void _update_embedded_process();
104
void _timer_embedding_timeout();
105
void _timer_update_embedded_process_timeout();
106
void _check_mouse_over();
107
void _check_focused_process_id();
108
bool _is_embedded_process_updatable();
109
Window *_get_current_modal_window();
110
111
protected:
112
void _notification(int p_what);
113
114
public:
115
bool is_embedding_in_progress() const override;
116
bool is_embedding_completed() const override;
117
bool is_process_focused() const override;
118
void embed_process(OS::ProcessID p_pid) override;
119
int get_embedded_pid() const override;
120
void reset() override;
121
void request_close() override;
122
void queue_update_embedded_process() override;
123
124
Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const override;
125
126
EmbeddedProcess();
127
~EmbeddedProcess() override;
128
};
129
130