Skip to content

Commit

Permalink
modify cursor set state, add window control flipping
Browse files Browse the repository at this point in the history
  • Loading branch information
torcado194 committed Mar 30, 2024
1 parent f99ac03 commit 05d3995
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 33 deletions.
68 changes: 42 additions & 26 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2484,38 +2484,54 @@ void DisplayServerWindows::multi_cursor_event(CursorID p_cursor, int flags) {

POINT resetPos;
GetCursorPos(&resetPos);
// POINT p;
// p.x = cd.pos.x;
// p.y = cd.pos.y;
// ClientToScreen(windows[_get_focused_window_or_popup()].hWnd, &p);

INPUT Input_[1];
ZeroMemory(Input_, sizeof(INPUT) * 1);
Input_[0].type = INPUT_MOUSE;
Input_[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, Input_, sizeof(INPUT));
// if(get_mouse_state(0)){
// }
SetCursorPos(cd.pos.x + screenRect.left, cd.pos.y + screenRect.top);

if(flags == 1){
// POINT p;
// p.x = cd.pos.x;
// p.y = cd.pos.y;
// ClientToScreen(windows[_get_focused_window_or_popup()].hWnd, &p);

INPUT Input_[1];
ZeroMemory(Input_, sizeof(INPUT) * 1);
Input_[0].type = INPUT_MOUSE;
Input_[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, Input_, sizeof(INPUT));
// if(get_mouse_state(0)){
// }
SetCursorPos(cd.pos.x + screenRect.left, cd.pos.y + screenRect.top);

INPUT Input[3];
ZeroMemory(Input, sizeof(INPUT) * 3);

Input[0].type = INPUT_MOUSE;
Input[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;

Input[1].type = INPUT_MOUSE;
Input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
INPUT Input[3];
ZeroMemory(Input, sizeof(INPUT) * 3);

Input[0].type = INPUT_MOUSE;
Input[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;

Input[2].type = INPUT_MOUSE;
Input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, Input, sizeof(INPUT));
Input[1].type = INPUT_MOUSE;
Input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;

// Input[0].mi.dwFlags = flags;
// SendInput(1, Input, sizeof(INPUT));
Input[2].type = INPUT_MOUSE;
Input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, Input, sizeof(INPUT));

SetCursorPos(resetPos.x, resetPos.y);
// Input[0].mi.dwFlags = flags;
// SendInput(1, Input, sizeof(INPUT));

SetCursorPos(resetPos.x, resetPos.y);
} else {
SetCursorPos(cd.pos.x + screenRect.left, cd.pos.y + screenRect.top);

INPUT Input[2];
ZeroMemory(Input, sizeof(INPUT) * 2);

Input[0].type = INPUT_MOUSE;
Input[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;

Input[1].type = INPUT_MOUSE;
Input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;

SendInput(2, Input, sizeof(INPUT));
}
}

bool DisplayServerWindows::multi_cursor_get_state(CursorID p_cursor, int button) {
Expand Down
34 changes: 27 additions & 7 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,32 +333,48 @@ void Viewport::_sub_window_update(Window *p_window) {
int close_v_ofs = p_window->theme_cache.close_v_offset;
int icon_h_ofs = p_window->theme_cache.icon_h_offset;
int icon_v_ofs = p_window->theme_cache.icon_v_offset;
int title_v_ofs = p_window->theme_cache.icon_v_offset;
int controls_left = p_window->theme_cache.controls_left;
Ref<Texture2D> controls_icon = p_window->theme_cache.controls_icon;

TextLine title_text = TextLine(p_window->atr(p_window->get_title()), title_font, font_size);
title_text.set_width(r.size.width - panel->get_minimum_size().x - close_h_ofs);
title_text.set_direction(p_window->is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
// int x = (r.size.width - title_text.get_size().x) / 2;
int x = p_window->theme_cache.center_title ? (r.size.width - title_text.get_size().x) / 2 : 32.0;
int x = p_window->theme_cache.center_title ? (r.size.width - title_text.get_size().x) / 2 : 32.0 + title_v_ofs;
int y = (-title_height - title_text.get_size().y) / 2;

if(controls_left && !p_window->theme_cache.center_title){
x = controls_icon->get_size().x + 12 + title_v_ofs;
}

Color font_outline_color = p_window->theme_cache.title_outline_modulate;
int outline_size = p_window->theme_cache.title_outline_size;
if (outline_size > 0 && font_outline_color.a > 0) {
title_text.draw_outline(sw.canvas_item, r.position + Point2(x, y), outline_size, font_outline_color);
}
title_text.draw(sw.canvas_item, r.position + Point2(x, y), title_color);

Ref<Texture2D> controls_icon = p_window->theme_cache.controls_icon;
// controls_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - close_h_ofs - controls_icon->get_size().x, -close_v_ofs));
controls_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - controls_icon->get_size().x + close_h_ofs, -controls_icon->get_size().y + close_v_ofs));

bool pressed = gui.subwindow_focused == sw.window && gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE && gui.subwindow_drag_close_inside;
Ref<Texture2D> close_icon = pressed ? p_window->theme_cache.close_pressed : p_window->theme_cache.close;
// close_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - close_h_ofs - close_icon->get_size().x, -close_v_ofs));
close_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - close_icon->get_size().x + close_h_ofs, -close_icon->get_size().y + close_v_ofs));

if(controls_left){
controls_icon->draw(sw.canvas_item, r.position + Vector2(close_h_ofs, -controls_icon->get_size().y + close_v_ofs));
close_icon->draw(sw.canvas_item, r.position + Vector2(close_h_ofs, -close_icon->get_size().y + close_v_ofs));
} else {
controls_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - controls_icon->get_size().x + close_h_ofs, -controls_icon->get_size().y + close_v_ofs));
close_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - close_icon->get_size().x + close_h_ofs, -close_icon->get_size().y + close_v_ofs));
}

Ref<Texture2D> icon = p_window->theme_cache.icon;
icon->draw(sw.canvas_item, r.position + Vector2(icon_h_ofs, -icon->get_size().y + icon_v_ofs));
if(controls_left){
icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - icon->get_size().x + icon_h_ofs, -icon->get_size().y + icon_v_ofs));
} else {
icon->draw(sw.canvas_item, r.position + Vector2(icon_h_ofs, -icon->get_size().y + icon_v_ofs));
}
}

RS::get_singleton()->canvas_item_add_texture_rect(sw.canvas_item, r, sw.window->get_texture()->get_rid());
Expand Down Expand Up @@ -1546,7 +1562,7 @@ void Viewport::_gui_show_tooltip() {
panel->set_transient(true);
panel->set_flag(Window::FLAG_NO_FOCUS, true);
panel->set_flag(Window::FLAG_POPUP, false);
panel->set_flag(Window::FLAG_MOUSE_PASSTHROUGH, true);
// panel->set_flag(Window::FLAG_MOUSE_PASSTHROUGH, true);
panel->set_wrap_controls(true);
panel->add_child(base_tooltip);
panel->gui_parent = this;
Expand Down Expand Up @@ -3020,7 +3036,11 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {

Rect2 close_rect;
// close_rect.position = Vector2(r.position.x + r.size.x - close_h_ofs - close_icon->get_size().x, r.position.y - close_v_ofs);
close_rect.position = Vector2(r.position.x + r.size.x - close_icon->get_size().x + close_h_ofs, r.position.y - close_icon->get_size().y + close_v_ofs);
if(sw.window->theme_cache.controls_left){
close_rect.position = Vector2(r.position.x + close_h_ofs, r.position.y - close_icon->get_size().y + close_v_ofs);
} else {
close_rect.position = Vector2(r.position.x + r.size.x - close_icon->get_size().x + close_h_ofs, r.position.y - close_icon->get_size().y + close_v_ofs);
}
close_rect.size = close_icon->get_size();

if (gui.subwindow_focused != sw.window) {
Expand Down
2 changes: 2 additions & 0 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,8 @@ void Window::_bind_methods() {
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Window, title_outline_modulate);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, title_outline_size);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, center_title);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, controls_left);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, title_v_ofs);

BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Window, close);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Window, close_pressed);
Expand Down
2 changes: 2 additions & 0 deletions scene/main/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class Window : public Viewport {
int title_font_size = 0;
Color title_color;
int title_height = 0;
int title_v_ofs = 0;
Color title_outline_modulate;
int title_outline_size = 0;
int center_title = 0;
Expand All @@ -222,6 +223,7 @@ class Window : public Viewport {
int close_expand = 0;
int icon_h_offset = 0;
int icon_v_offset = 0;
int controls_left = 0;

int resize_margin = 0;
} theme_cache;
Expand Down

0 comments on commit 05d3995

Please sign in to comment.