Skip to content

Commit c286e9b

Browse files
authored
Fix text selection + Minor fixes/improvements. (#25)
* Fix text selection. * Check for exact mask match. * Remove unused function in C++ AppExample. * Add platforms section to README. * Update project structure focus. * Update file structure. * Adjust file_path when inspector requested. * Update godot_file_system.hpp * Change render call order based on UL docs. * Properly check bitmask. * Add a proper signal example.
1 parent 87a7114 commit c286e9b

File tree

10 files changed

+73
-38
lines changed

10 files changed

+73
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ demo/ultralight.log
77
demo/default
88
demo/inspector/
99
demo/addons/gdhtml/resources/
10+
demo/addons/gdhtml/inspector/
1011
demo/addons/gdhtml/bin/*.*.*.*.dll
1112
demo/addons/gdhtml/bin/*.*.*.*.exp
1213
demo/addons/gdhtml/bin/*.*.*.*.lib

README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ A GDExtension, using Ultralight, to render HTML.
1111
- Godot 4.3+
1212
- Ultralight 1.4.0 Beta
1313

14+
## Platforms
15+
| Platform | x64 | arm64 | x32 |
16+
| - | :-: | :-: | :-: |
17+
| Windows | :white_check_mark: | :warning: | :x: |
18+
| Linux | :white_check_mark: | :warning: | :x: |
19+
| Mac | :white_check_mark: | :white_check_mark: | :x: |
20+
21+
> :white_check_mark: = Successfully ran the demo project.
22+
23+
> :warning: = Supported, but not tested.
24+
25+
> :x: = Not supported.
26+
1427
## Table of contents
1528
- [What can this plugin do?](#can-do)
1629
- [What's left to do?](#to-do)
@@ -49,27 +62,21 @@ Some of the notable limitations are:
4962
- Download [Ultralight](https://ultralig.ht/download/)
5063

5164
## Project Structure
52-
Your project structure should look like this before building and running.
65+
Your project structure should look like this before running with this extension.
5366
```
54-
main_folder/
55-
+--demo/ # game example/demo to test the extension
56-
| +--addons/ # addons
57-
| | +--gdhtml/ # plugin folder
58-
| | +--bin/ # plugin build folder / Other libraries
59-
| | | +--windows/
60-
| | | +--Ultralight.dll
61-
| | | +--UltralightCore.dll
62-
| | | +--WebCore.dll
63-
| | | +--AppCore.dll
64-
| | +--resources/ # Ultralight resources folder (Copied from SDK folder)
65-
| +--inspector/ # Ultralight inspector folder (Copied from SDK folder)
66-
+--godot-cpp/ # C++ bindings
67-
+--src/ # Source code of the extension we are building
68-
+--ultralight/ # Ultralight SDK
69-
+--bin # Ultralight libraries
70-
+--include # Ultralight Headers
71-
+--lib # Ultralight .lib for windows build
72-
+--license # Ultralight Licenses
67+
demo/ # Godot project (Root)
68+
addons/ # Addons
69+
gdhtml/ # Godot-HTML extension
70+
bin/ # Extension libraries
71+
| windows/ # Library platform
72+
| x86_64/ # Platform arch
73+
| gdhtml.*.dll # Extension library
74+
| Ultralight.dll # Ultralight libraries
75+
| UltralightCore.dll # ...
76+
| WebCore.dll # ...
77+
| AppCore.dll # ...
78+
inspector/ # Ultralight inspector
79+
resources/ # Ultralight resources
7380
```
7481

7582
## Building

SConstruct

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ elif env["platform"] == "macos":
111111
)
112112

113113
copy_resources = env.Install(
114-
f"{projectdir}/addons/{libname}/resources",
115-
source = [
116-
"ultralight/resources/cacert.pem",
117-
"ultralight/resources/icudt67l.dat"
118-
]
114+
f"{projectdir}/addons/{libname}/",
115+
source = ["ultralight/resources/"]
119116
)
120117

121-
default_args = [library, copy, copy_libraries, copy_resources]
118+
copy_inspector = env.Install(
119+
f"{projectdir}/addons/{libname}/",
120+
source = ["ultralight/inspector/"]
121+
)
122+
123+
default_args = [library, copy, copy_libraries, copy_resources, copy_inspector]
122124
Default(*default_args)

demo/app_example.gd

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func _on_dom_ready(_url):
2323
},
2424
"array": [1, 2, 3, 4, 5],
2525
"object": self,
26-
"signal_test": signal_test
26+
"signal": _signal_to_dictionary(test_signal)
2727
}
2828

2929
func test_callable(temp = ""):
@@ -37,5 +37,16 @@ func test_nested_callable():
3737
print("test_nested_callable")
3838
return 420
3939

40-
func signal_test():
41-
test_signal.emit()
40+
func _signal_to_dictionary(p_signal: Signal):
41+
return {
42+
"connect": p_signal.connect,
43+
# "disconnect": p_signal.disconnect, # ALERT: Disconnect does not work yet.
44+
"emit": p_signal.emit,
45+
"get_connections": p_signal.get_connections,
46+
"get_name": p_signal.get_name,
47+
"get_object": p_signal.get_object,
48+
"get_object_id": p_signal.get_object_id,
49+
"has_connections": p_signal.has_connections,
50+
# "is_connected": p_signal.is_connected, # ALERT: Is_connected probably doesn't work. Same reason as above.
51+
"is_null": p_signal.is_null
52+
}

src/app_example.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ namespace godot {
88
class AppExample : public HtmlRect {
99
GDCLASS(AppExample, HtmlRect)
1010

11-
private:
12-
static JSValueRef ExampleCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
13-
1411
protected:
1512
static void _bind_methods();
1613

src/convert/convert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ JSValueRef Convert::ToJSValue(JSContextRef context, Variant variant)
167167
Variant::Type type = static_cast<Variant::Type>((int)property_info["type"]);
168168
PropertyUsageFlags usage = static_cast<PropertyUsageFlags>((uint64_t)property_info["usage"]);
169169

170-
if(type != Variant::NIL && !(usage & PROPERTY_USAGE_INTERNAL))
170+
if(type != Variant::NIL && (usage & PROPERTY_USAGE_INTERNAL) != PROPERTY_USAGE_INTERNAL)
171171
{
172172
Variant property = object->get(name);
173173
JSValueRef js_value;

src/godot/js_callable/js_callable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using namespace godot;
66

7+
// ALERT: Find a way to fix hash & compare to allow disconnecting callables from signals.
78
uint32_t JSCallable::hash() const
89
{
910
return 420;

src/godot/ultralight_manager/ultralight_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ void UltralightManager::UpdateLogic() {
7878
}
7979

8080
void UltralightManager::RenderFrame() {
81-
renderer->Render();
8281
renderer->RefreshDisplay(0);
82+
renderer->Render();
8383
}
8484

8585
}

src/godot/view_rect/view_rect.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ void ViewRect::_draw()
125125

126126
#pragma region ViewRect Private methods.
127127

128+
MouseEvent::Button latest_mouse_button = MouseEvent::Button::kButton_None;
129+
128130
void ViewRect::HandleMouseButton(InputEventMouseButton *event)
129131
{
130132
MouseButton index = event->get_button_index();
@@ -158,6 +160,7 @@ void ViewRect::HandleMouseButton(InputEventMouseButton *event)
158160
evt.button = MouseEvent::Button::kButton_Right;
159161
break;
160162
};
163+
latest_mouse_button = evt.button;
161164
mouse_events.push(evt);
162165
events.push(Event::mouse);
163166
}
@@ -170,7 +173,7 @@ void ViewRect::HandleMouseMotion(InputEventMouseMotion *event)
170173
evt.type = MouseEvent::kType_MouseMoved;
171174
evt.x = (int)pos.x;
172175
evt.y = (int)pos.y;
173-
evt.button = MouseEvent::kButton_None;
176+
evt.button = latest_mouse_button;
174177
mouse_events.push(evt);
175178
events.push(Event::mouse);
176179
}
@@ -206,7 +209,7 @@ void ViewRect::HandleKey(InputEventKey *event)
206209
auto modifiers = event->get_modifiers_mask();
207210
uint8_t ultralightModifier = 0;
208211
for (const auto& [godotMask, ultralightMask] : ModifierMap) {
209-
if (modifiers & godotMask) {
212+
if ((modifiers & godotMask) == godotMask) {
210213
ultralightModifier |= ultralightMask;
211214
}
212215
}

src/ultralight/godot_file_system.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ namespace ultralight
1313
GodotFileSystem() {}
1414
~GodotFileSystem() override {}
1515

16+
godot::String AdjustPath(godot::String file_path)
17+
{
18+
if(file_path.begins_with("inspector/"))
19+
{
20+
file_path = "addons/gdhtml/" + file_path;
21+
}
22+
return file_path;
23+
}
24+
1625
String SetupPath(const String& file_path)
1726
{
18-
return ("res://"+file_path);
27+
auto adjusted_file_path = String(
28+
AdjustPath(
29+
godot::String(file_path.utf8().data())
30+
).utf8().get_data()
31+
);
32+
return "res://" + adjusted_file_path;
1933
}
2034

2135
bool FileExists(const String& file_path) override
@@ -38,7 +52,6 @@ namespace ultralight
3852
godot::PackedByteArray data = godot::FileAccess::get_file_as_bytes(SetupPath(file_path).utf8().data());
3953
return Buffer::CreateFromCopy(data.ptr(), data.size());
4054
}
41-
4255
};
4356
};
4457

0 commit comments

Comments
 (0)