| 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 |
#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 |
}; |