Skip to content

Implement MMB-drag scroll #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions material_maker/globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extends Node
# warning-ignore:unused_class_variable
var main_window

static var _is_mmb_scroll_warping : int = 0

var config : ConfigFile = ConfigFile.new()
const DEFAULT_CONFIG : Dictionary = {
locale = "",
Expand All @@ -32,6 +34,7 @@ const DEFAULT_CONFIG : Dictionary = {
auto_size_comment = true,
graph_line_curvature = 0.5,
graph_line_style = 1,
ui_use_warped_scrolling = true,
}


Expand Down Expand Up @@ -148,6 +151,32 @@ func parse_paste_data(data : String):

# Misc. UI functions

static func do_warp_mouse(position : Vector2, node : Node) -> void:
if mm_globals.get_config("ui_use_warped_scrolling"):
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
node.warp_mouse(position)
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE

static func handle_warped_mmb_scroll(event : InputEvent, node : Control, vscroll : VScrollBar,
from_rect_y : float, to_rect_y : float, mouse_pos : Vector2,
dragging_cursor : Control.CursorShape = Control.CURSOR_DRAG,
relative_offset_multiplier : float = 1.0, ignore_after_warp : int = 2) -> void:
if event is InputEventMouseMotion and (event.button_mask & MOUSE_BUTTON_MASK_MIDDLE) != 0:
node.mouse_default_cursor_shape = dragging_cursor

_is_mmb_scroll_warping -= 1 if _is_mmb_scroll_warping else 0
if not _is_mmb_scroll_warping or not mm_globals.get_config("ui_use_warped_scrolling"):
vscroll.value -= event.relative.y * relative_offset_multiplier

if mouse_pos.y > to_rect_y:
_is_mmb_scroll_warping = ignore_after_warp
do_warp_mouse(Vector2(mouse_pos.x, from_rect_y), node)
elif mouse_pos.y < from_rect_y:
_is_mmb_scroll_warping = ignore_after_warp
do_warp_mouse(Vector2(mouse_pos.x, to_rect_y), node)
else:
node.mouse_default_cursor_shape = Control.CURSOR_ARROW

static func popup_menu(menu : PopupMenu, parent : Control):
var zoom_fac = 1.0
if parent is GraphNode:
Expand Down
1 change: 1 addition & 0 deletions material_maker/panels/library/library.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ item_4/id = 4
[connection signal="about_to_popup" from="Library/Filter/Libraries" to="." method="_on_Libraries_about_to_show"]
[connection signal="item_collapsed" from="Library/Tree" to="." method="_on_Tree_item_collapsed"]
[connection signal="item_mouse_selected" from="Library/Tree" to="." method="_on_tree_item_mouse_selected"]
[connection signal="ready" from="Library/Tree" to="Library/Tree" method="_on_ready"]
[connection signal="pressed" from="Library/GetFromWebsite" to="." method="_on_GetFromWebsite_pressed"]
[connection signal="about_to_popup" from="ItemMenu" to="Library" method="_on_PopupMenu_about_to_show"]
[connection signal="index_pressed" from="ItemMenu" to="." method="_on_PopupMenu_index_pressed"]
15 changes: 15 additions & 0 deletions material_maker/panels/library/library_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ extends Tree

var scroll_position = 0.0

var tree_scrollbar : VScrollBar

func _on_ready() -> void:
for node in get_children(true):
if node is VScrollBar:
tree_scrollbar = node

func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
auto_tooltip = false
mm_globals.handle_warped_mmb_scroll(event, self, tree_scrollbar,
0, get_rect().size.y, get_local_mouse_position(), Control.CURSOR_DRAG)
else:
auto_tooltip = true

func get_last_item(parent : TreeItem):
while true:
if parent.collapsed:
Expand Down
5 changes: 5 additions & 0 deletions material_maker/widgets/code_editor/code_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func _on_gui_input(event):
%ReplaceString.grab_focus()
else:
%FindString.grab_focus()
elif event is InputEventMouseMotion:
mm_globals.handle_warped_mmb_scroll(event, self, get_v_scroll_bar(), 0,
get_rect().size.y, get_local_mouse_position(), Control.CURSOR_ARROW,
1.0 / get_line_height())


func _on_close_pressed():
%Find.visible = false
Expand Down
15 changes: 15 additions & 0 deletions material_maker/windows/about/about.gd
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,18 @@ func _notification(what: int) -> void:
NOTIFICATION_THEME_CHANGED:
%EpicLogo.material.set_shader_parameter("invert",
"light" in mm_globals.main_window.theme.resource_path)

func _on_patrons_gui_input(event: InputEvent) -> void:
mm_globals.handle_warped_mmb_scroll(event, %Patrons, %Patrons.get_v_scroll_bar(), 0,
%Patrons.get_rect().size.y, %Patrons.get_local_mouse_position())


func _on_authors_gui_input(event: InputEvent) -> void:
mm_globals.handle_warped_mmb_scroll(event, %Authors, %Authors.get_v_scroll_bar(), 0,
%Authors.get_rect().size.y, %Authors.get_local_mouse_position())


func _on_license_gui_input(event: InputEvent) -> void:
mm_globals.handle_warped_mmb_scroll(event, %License, %License.get_v_scroll_bar(), 0,
%License.get_rect().size.y, %License.get_local_mouse_position(), Control.CURSOR_DRAG,
1.0 / %License.get_line_height())
7 changes: 7 additions & 0 deletions material_maker/windows/about/about.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ tab_alignment = 1
current_tab = 0

[node name="Authors" type="ScrollContainer" parent="HBoxContainer/VBoxContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
metadata/_tab_index = 0

Expand Down Expand Up @@ -147,6 +148,7 @@ size_flags_horizontal = 4
text = "Sponsors"

[node name="Patrons" type="ItemList" parent="HBoxContainer/VBoxContainer/VBoxContainer/Donors/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
Expand All @@ -155,6 +157,7 @@ same_column_width = true
fixed_column_width = 190

[node name="License" type="TextEdit" parent="HBoxContainer/VBoxContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
size_flags_horizontal = 3
Expand Down Expand Up @@ -272,6 +275,10 @@ texture_normal = ExtResource("9")
stretch_mode = 4

[connection signal="close_requested" from="." to="." method="queue_free"]
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/VBoxContainer/Authors" to="." method="_on_authors_gui_input"]
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/VBoxContainer/Donors" to="." method="_on_donors_gui_input"]
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/VBoxContainer/Donors/VBoxContainer/Patrons" to="." method="_on_patrons_gui_input"]
[connection signal="gui_input" from="HBoxContainer/VBoxContainer/VBoxContainer/License" to="." method="_on_license_gui_input"]
[connection signal="pressed" from="HBoxContainer/MarginContainer/SocialNetworks/Patreon" to="." method="open_url" binds= ["https://www.patreon.com/rodzlabs"]]
[connection signal="pressed" from="HBoxContainer/MarginContainer/SocialNetworks/ItchIo" to="." method="open_url" binds= ["https://rodzilla.itch.io/material-maker"]]
[connection signal="pressed" from="HBoxContainer/MarginContainer/SocialNetworks/Github" to="." method="open_url" binds= ["https://github.com/RodZill4/godot-procedural-textures"]]
Expand Down
7 changes: 5 additions & 2 deletions material_maker/windows/add_node_popup/add_node_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var qc_is_output : bool

@onready var library_manager = get_node("/root/MainWindow/NodeLibraryManager")


func get_current_graph():
return get_parent().get_current_graph_edit()

Expand Down Expand Up @@ -211,7 +210,11 @@ func _on_list_gui_input(event: InputEvent) -> void:
var idx: int = %List.get_item_at_position(%List.get_local_mouse_position(), true)
if idx != -1:
_on_list_item_activated(idx)

elif event is InputEventMouseMotion:
var list_rect = %List.get_rect()
var list_viewport_rect = %List.get_viewport_rect()
mm_globals.handle_warped_mmb_scroll(event, %List, %List.get_v_scroll_bar(),
0, list_rect.size.y, %List.get_local_mouse_position(), Control.CURSOR_DRAG)

func get_list_drag_data(m_position):
var data = %List.get_item_metadata(%List.get_item_at_position(m_position))
Expand Down
10 changes: 9 additions & 1 deletion material_maker/windows/environment_editor/environment_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,22 @@ func _on_Environments_item_selected(index):
environment_list.select(index)
set_current_environment(index)


func _on_Environments_gui_input(event):
if ! (event is InputEventMouseButton) or event.button_index != MOUSE_BUTTON_RIGHT:
if event is InputEventMouseMotion:
var rect : Rect2 = environment_list.get_rect()
mm_globals.handle_warped_mmb_scroll(event, environment_list,
environment_list.get_v_scroll_bar(), rect.position.y, rect.size.y,
environment_list.get_local_mouse_position())

elif ! (event is InputEventMouseButton) or event.button_index != MOUSE_BUTTON_RIGHT:
return
var context_menu : PopupMenu = $Main/HSplitContainer/Environments/ContextMenu
var index = environment_list.get_item_at_position(event.position)
if environment_list.is_selected(index) and ! environment_manager.is_read_only(index):
mm_globals.popup_menu(context_menu, $Main/HSplitContainer/Environments)


func _on_ContextMenu_id_pressed(id):
var index = environment_list.get_selected_items()[0]
environment_manager.delete_environment(index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var only_return_index : bool = false

signal return_asset(json : Dictionary)


func _ready() -> void:
DirAccess.open("user://").make_dir_recursive("user://website_cache")

Expand Down Expand Up @@ -135,3 +134,7 @@ func _on_VBoxContainer_minimum_size_changed():

func _on_Filter_changed(new_text):
fill_list(new_text)

func _on_item_list_gui_input(event: InputEvent) -> void:
mm_globals.handle_warped_mmb_scroll(event, item_list, item_list.get_v_scroll_bar(), 0,
item_list.get_rect().size.y, item_list.get_local_mouse_position(), Control.CURSOR_ARROW)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[node name="LoadFromWebsite" type="Window"]
title = "Load from website"
position = Vector2i(0, 36)
size = Vector2i(600, 610)
exclusive = true
script = ExtResource("1")

Expand Down Expand Up @@ -59,6 +61,7 @@ text = "Cancel"
[connection signal="close_requested" from="." to="." method="_on_Cancel_pressed"]
[connection signal="minimum_size_changed" from="VBoxContainer" to="." method="_on_VBoxContainer_minimum_size_changed"]
[connection signal="text_changed" from="VBoxContainer/Filter/LineEdit" to="." method="_on_Filter_changed"]
[connection signal="gui_input" from="VBoxContainer/ItemList" to="." method="_on_item_list_gui_input"]
[connection signal="item_activated" from="VBoxContainer/ItemList" to="." method="_on_ItemList_item_activated"]
[connection signal="item_selected" from="VBoxContainer/ItemList" to="." method="_on_ItemList_item_selected"]
[connection signal="pressed" from="VBoxContainer/Buttons/OK" to="." method="_on_OK_pressed"]
Expand Down
7 changes: 7 additions & 0 deletions material_maker/windows/preferences/preferences.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ layout_mode = 2
text = "Confirm when closing a project"
config_variable = "confirm_close_project"

[node name="GuiUseWarpedScrolling" parent="VBoxContainer/TabContainer/General" instance=ExtResource("1")]
layout_mode = 2
tooltip_text = "Warp mouse position when using middle mouse drag to scroll (on supported ui panels)
Turning this off might alleviate problems associated with graphics tablets"
text = "Use warped scrolling"
config_variable = "ui_use_warped_scrolling"

[node name="Space3" type="Control" parent="VBoxContainer/TabContainer/General"]
custom_minimum_size = Vector2(0, 10)
layout_mode = 2
Expand Down