summaryrefslogtreecommitdiff
path: root/platform/windows
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows')
-rw-r--r--platform/windows/os_windows.cpp35
-rw-r--r--platform/windows/os_windows.h1
2 files changed, 32 insertions, 4 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 0a9cfc0214..07470cec92 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1537,6 +1537,7 @@ void OS_Windows::finalize() {
memdelete(camera_server);
touch_state.clear();
+ cursors_cache.clear();
visual_server->finish();
memdelete(visual_server);
#ifdef OPENGL_ENABLED
@@ -1812,7 +1813,7 @@ Size2 OS_Windows::get_min_window_size() const {
void OS_Windows::set_min_window_size(const Size2 p_size) {
if ((p_size != Size2()) && (max_size != Size2()) && ((p_size.x > max_size.x) || (p_size.y > max_size.y))) {
- WARN_PRINT("Minimum window size can't be larger than maximum window size!");
+ ERR_PRINT("Minimum window size can't be larger than maximum window size!");
return;
}
min_size = p_size;
@@ -1821,7 +1822,7 @@ void OS_Windows::set_min_window_size(const Size2 p_size) {
void OS_Windows::set_max_window_size(const Size2 p_size) {
if ((p_size != Size2()) && ((p_size.x < min_size.x) || (p_size.y < min_size.y))) {
- WARN_PRINT("Maximum window size can't be smaller than minimum window size!");
+ ERR_PRINT("Maximum window size can't be smaller than minimum window size!");
return;
}
max_size = p_size;
@@ -2251,9 +2252,17 @@ uint64_t OS_Windows::get_unix_time() const {
FILETIME fep;
SystemTimeToFileTime(&ep, &fep);
- // FIXME: dereferencing type-punned pointer will break strict-aliasing rules (GCC warning)
+ // Type punning through unions (rather than pointer cast) as per:
// https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime#remarks
- return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000;
+ ULARGE_INTEGER ft_punning;
+ ft_punning.LowPart = ft.dwLowDateTime;
+ ft_punning.HighPart = ft.dwHighDateTime;
+
+ ULARGE_INTEGER fep_punning;
+ fep_punning.LowPart = fep.dwLowDateTime;
+ fep_punning.HighPart = fep.dwHighDateTime;
+
+ return (ft_punning.QuadPart - fep_punning.QuadPart) / 10000000;
};
uint64_t OS_Windows::get_system_time_secs() const {
@@ -2367,7 +2376,20 @@ OS::CursorShape OS_Windows::get_cursor_shape() const {
}
void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
+
if (p_cursor.is_valid()) {
+
+ Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
+
+ if (cursor_c) {
+ if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
+ set_cursor_shape(p_shape);
+ return;
+ }
+
+ cursors_cache.erase(p_shape);
+ }
+
Ref<Texture> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
@@ -2450,6 +2472,11 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
cursors[p_shape] = CreateIconIndirect(&iconinfo);
+ Vector<Variant> params;
+ params.push_back(p_cursor);
+ params.push_back(p_hotspot);
+ cursors_cache.insert(p_shape, params);
+
if (p_shape == cursor_shape) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
SetCursor(cursors[p_shape]);
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index fc8ad1b188..ce55328173 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -155,6 +155,7 @@ class OS_Windows : public OS {
HCURSOR cursors[CURSOR_MAX] = { NULL };
CursorShape cursor_shape;
+ Map<CursorShape, Vector<Variant> > cursors_cache;
InputDefault *input;
JoypadWindows *joypad;