Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/run/embedded_process.h
20806 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
class Timer;
37
38
class EmbeddedProcessBase : public Control {
39
GDCLASS(EmbeddedProcessBase, Control);
40
41
void _draw();
42
43
protected:
44
Ref<StyleBox> focus_style_box;
45
Size2i window_size;
46
bool keep_aspect = false;
47
Point2i margin_top_left;
48
Point2i margin_bottom_right;
49
Window *window = nullptr;
50
51
bool transp_enabled = false;
52
Color clear_color;
53
Ref<Texture2D> checkerboard;
54
55
void _project_settings_changed();
56
57
static void _bind_methods();
58
void _notification(int p_what);
59
60
public:
61
virtual void set_script_debugger(ScriptEditorDebugger *p_debugger) {}
62
63
virtual bool is_embedding_completed() const = 0;
64
virtual bool is_embedding_in_progress() const = 0;
65
virtual bool is_process_focused() const = 0;
66
virtual void embed_process(OS::ProcessID p_pid) = 0;
67
virtual int get_embedded_pid() const = 0;
68
virtual void reset() = 0;
69
virtual void reset_timers() = 0;
70
virtual void request_close() = 0;
71
virtual void queue_update_embedded_process() = 0;
72
73
void set_window_size(const Size2i &p_window_size);
74
void set_keep_aspect(bool p_keep_aspect);
75
virtual Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const = 0;
76
Rect2i get_screen_embedded_window_rect() const;
77
int get_margin_size(Side p_side) const;
78
Size2 get_margins_size() const;
79
80
EmbeddedProcessBase();
81
virtual ~EmbeddedProcessBase();
82
};
83
84
class EmbeddedProcess : public EmbeddedProcessBase {
85
GDCLASS(EmbeddedProcess, EmbeddedProcessBase);
86
87
bool application_has_focus = true;
88
uint64_t last_application_focus_time = 0;
89
OS::ProcessID focused_process_id = 0;
90
OS::ProcessID current_process_id = 0;
91
bool embedding_grab_focus = false;
92
bool embedding_completed = false;
93
uint64_t start_embedding_time = 0;
94
bool updated_embedded_process_queued = false;
95
bool last_updated_embedded_process_focused = false;
96
97
Timer *timer_embedding = nullptr;
98
Timer *timer_update_embedded_process = nullptr;
99
100
const int embedding_timeout = 45000;
101
102
Rect2i last_global_rect;
103
104
void _try_embed_process();
105
void _update_embedded_process();
106
void _timer_embedding_timeout();
107
void _timer_update_embedded_process_timeout();
108
void _check_mouse_over();
109
void _check_focused_process_id();
110
bool _is_embedded_process_updatable();
111
Window *_get_current_modal_window();
112
113
protected:
114
void _notification(int p_what);
115
116
public:
117
bool is_embedding_in_progress() const override;
118
bool is_embedding_completed() const override;
119
bool is_process_focused() const override;
120
void embed_process(OS::ProcessID p_pid) override;
121
int get_embedded_pid() const override;
122
void reset() override;
123
void reset_timers() override;
124
void request_close() override;
125
void queue_update_embedded_process() override;
126
127
Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const override;
128
129
EmbeddedProcess();
130
~EmbeddedProcess() override;
131
};
132
133