| 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 "editor/run/embedded_process.h" |
| 34 |
|
| 35 |
class DisplayServerMacOS; |
| 36 |
class EmbeddedProcessMacOS; |
| 37 |
|
| 38 |
class LayerHost final : public Control { |
| 39 |
GDCLASS(LayerHost, Control); |
| 40 |
|
| 41 |
ScriptEditorDebugger *script_debugger = nullptr; |
| 42 |
EmbeddedProcessMacOS *process = nullptr; |
| 43 |
bool window_focused = true; |
| 44 |
|
| 45 |
struct CustomCursor { |
| 46 |
Ref<Image> image; |
| 47 |
Vector2 hotspot; |
| 48 |
CustomCursor() {} |
| 49 |
CustomCursor(const Ref<Image> &p_image, const Vector2 &p_hotspot) { |
| 50 |
image = p_image; |
| 51 |
hotspot = p_hotspot; |
| 52 |
} |
| 53 |
}; |
| 54 |
HashMap<DisplayServer::CursorShape, CustomCursor> custom_cursors; |
| 55 |
|
| 56 |
virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 57 |
|
| 58 |
protected: |
| 59 |
void _notification(int p_what); |
| 60 |
|
| 61 |
public: |
| 62 |
void cursor_set_custom_image(const Ref<Image> &p_image, DisplayServer::CursorShape p_shape, const Vector2 &p_hotspot); |
| 63 |
void set_script_debugger(ScriptEditorDebugger *p_debugger) { |
| 64 |
script_debugger = p_debugger; |
| 65 |
} |
| 66 |
|
| 67 |
LayerHost(EmbeddedProcessMacOS *p_process); |
| 68 |
}; |
| 69 |
|
| 70 |
class EmbeddedProcessMacOS final : public EmbeddedProcessBase { |
| 71 |
GDCLASS(EmbeddedProcessMacOS, EmbeddedProcessBase); |
| 72 |
|
| 73 |
enum class EmbeddingState { |
| 74 |
IDLE, |
| 75 |
IN_PROGRESS, |
| 76 |
COMPLETED, |
| 77 |
FAILED, |
| 78 |
}; |
| 79 |
|
| 80 |
DisplayServerMacOS *ds = nullptr; |
| 81 |
EmbeddingState embedding_state = EmbeddingState::IDLE; |
| 82 |
uint32_t context_id = 0; |
| 83 |
ScriptEditorDebugger *script_debugger = nullptr; |
| 84 |
LayerHost *layer_host = nullptr; |
| 85 |
OS::ProcessID current_process_id = 0; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
DisplayServer::MouseMode mouse_mode = DisplayServer::MOUSE_MODE_VISIBLE; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
void _try_embed_process(); |
| 95 |
void update_embedded_process(); |
| 96 |
|
| 97 |
protected: |
| 98 |
void _notification(int p_what); |
| 99 |
|
| 100 |
public: |
| 101 |
|
| 102 |
|
| 103 |
void set_context_id(uint32_t p_context_id); |
| 104 |
void mouse_set_mode(DisplayServer::MouseMode p_mode); |
| 105 |
|
| 106 |
uint32_t get_context_id() const { return context_id; } |
| 107 |
void set_script_debugger(ScriptEditorDebugger *p_debugger) override; |
| 108 |
|
| 109 |
bool is_embedding_in_progress() const override { |
| 110 |
return embedding_state == EmbeddingState::IN_PROGRESS; |
| 111 |
} |
| 112 |
|
| 113 |
_FORCE_INLINE_ bool is_embedding_completed() const override { |
| 114 |
return embedding_state == EmbeddingState::COMPLETED; |
| 115 |
} |
| 116 |
|
| 117 |
bool is_process_focused() const override { return layer_host->has_focus(); } |
| 118 |
void embed_process(OS::ProcessID p_pid) override; |
| 119 |
int get_embedded_pid() const override { return current_process_id; } |
| 120 |
void reset() override; |
| 121 |
void reset_timers() override {} |
| 122 |
void request_close() override; |
| 123 |
void queue_update_embedded_process() override { update_embedded_process(); } |
| 124 |
|
| 125 |
Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const override; |
| 126 |
|
| 127 |
_FORCE_INLINE_ LayerHost *get_layer_host() const { return layer_host; } |
| 128 |
|
| 129 |
void display_state_changed(); |
| 130 |
|
| 131 |
|
| 132 |
_FORCE_INLINE_ DisplayServer::MouseMode get_mouse_mode() const { return mouse_mode; } |
| 133 |
|
| 134 |
EmbeddedProcessMacOS(); |
| 135 |
~EmbeddedProcessMacOS() override; |
| 136 |
}; |