How to have built-in control nodes block custom drawing control nodes?
Asked Answered
G

9

0

Based on https://docs.godotengine.org/en/stable/tutorials/2d/custom_drawing_in_2d.html, I have created a few controls that have custom drawing. If I have a custom control on top of a built-in control, like a button, mouse cursor blocking works as expected, as long as the custom control's rect overlaps with the built-in control:


CustomControl script:

extends Control

func _process(delta):
	queue_redraw()

func _draw():

	if get_global_rect().has_point(get_global_mouse_position()):
		draw_rect(get_global_rect(), Color.MAGENTA)
	else:
		draw_rect(get_global_rect(), Color.AQUA)

However, I would also like reverse: when a built-in node is on top of a custom drawn node, I want it to block.
This is what happens with the script I have (obviously I need to add something to it, or do something in order to actually have it block.):

Is there some property or variable I can access in the _draw function in the CustomControl's script so that I can know when it should be being blocked, or is there something else entirely that I should be doing? My goal is to be able to create control nodes with custom drawing that behave like the rest of the control nodes. Thanks.

Graces answered 4/8, 2023 at 23:26 Comment(0)
G
0

edited, the fourth image was accidently a copy of the third one.

Graces answered 4/8, 2023 at 23:35 Comment(0)
B
0

Not sure if i understand what you wish to do.
Can be related to pause one element and keep other active?
It that case can be an idea checking this:
https://docs.godotengine.org/en/stable/tutorials/scripting/pausing_games.html
You can freeze the CustomControl to be inactive while process the button.

Broz answered 5/8, 2023 at 0:43 Comment(0)
E
1

Graces I think instead of querying the mouse-vs-control-rect during the draw, you want to use the 'mouse_entered' signal. This will only trigger when the mouse enters the part of the control's rect that is exposed, and not occluded by other controls.

https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-signal-mouse-entered

Add a bool member variable on the control, set it true on 'mouse_entered', false on 'mouse_exited'. Change the drawing style based on that.

Excavator answered 5/8, 2023 at 1:25 Comment(0)
G
0

Excavator Thanks, will have to try it out later but that sounds like what I'm looking for

Graces answered 5/8, 2023 at 3:1 Comment(0)
G
0

Graces Just tried it out, it seems to work. Thanks again. If anyone else is trying to do similar custom controls like this you might also want to modify the mouse filter mode (in the inspector, Control/Mouse/Filter) in case you have a control you don't want blocking other controls.

Graces answered 6/8, 2023 at 2:21 Comment(0)
B
0

Graces I don't know if it has been fixed but I have a bad experience with "Mouse entered".
Because if your game is borderless or windoned, and the mouse goes out of the window, the "mouse entered" update fails to update. In this case you also have to deal with focus in/out, and it fails aswell.

Broz answered 6/8, 2023 at 7:21 Comment(0)
G
0

Broz (using Godot 4.1) Just tested with both windowed and borderless, looks like it works okay. The mouse_exited signal gets emitted when mouse exits window (on whatever the last control entered was), and mouse_entered signal gets emitted when mouse enters back into the window, for whatever control node is entered first.
Is this what you meant or is "mouse entered update" something different from the mouse_entered signal?

Graces answered 6/8, 2023 at 21:13 Comment(0)
B
0

Graces (Tested time ago on 3.0)

  1. Keep the cursors inside the game window on the area you wish to trigger
  2. Move the cursors out of game window (fast 0.1-0.3seconds) and focus your windows/linux desktop
  3. The area trigger by mouse_enter (even OS. commands) inside the game is still on

It was really frustrating because i was trying to make a resize-minimize button on a custom bar, but because this it become useless, the refresh always stuck when game is inactive.
And when open again the game window, without focusing, the interested area was stuck on trigger (i was using hover on buttons) and anything change without keep the window active.
This not happen with like Firefox where i can hovering the X button (its become red) even without the window focus.
The X button of Firefox becomes light grey because window inactive but still red just pass by hovering.
I wasn't able to do this with Godot 3.0 back in days.

Broz answered 6/8, 2023 at 21:20 Comment(0)
G
0

Broz Looks like it's working now then. The events get emitted (mouse entered/exited) regardless of whether the window is focused or not. Thanks though, I wouldn't have thought to test for that right away, will have to look out for similar things going forward.

Graces answered 7/8, 2023 at 1:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.