Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/macos/editor/embedded_process_macos.h
10278 views
1
/**************************************************************************/
2
/* embedded_process_macos.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 "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
// Embedded process state.
88
89
// The last mouse mode sent by the embedded process.
90
DisplayServer::MouseMode mouse_mode = DisplayServer::MOUSE_MODE_VISIBLE;
91
92
// Helper functions.
93
94
void _try_embed_process();
95
void update_embedded_process();
96
97
protected:
98
void _notification(int p_what);
99
100
public:
101
// MARK: - Message Handlers
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 request_close() override;
122
void queue_update_embedded_process() override { update_embedded_process(); }
123
124
Rect2i get_adjusted_embedded_window_rect(const Rect2i &p_rect) const override;
125
126
_FORCE_INLINE_ LayerHost *get_layer_host() const { return layer_host; }
127
128
void display_state_changed();
129
130
// MARK: - Embedded process state
131
_FORCE_INLINE_ DisplayServer::MouseMode get_mouse_mode() const { return mouse_mode; }
132
133
EmbeddedProcessMacOS();
134
~EmbeddedProcessMacOS() override;
135
};
136
137