I have tried every google result that seems relevant and cannot find a solution to something I'm sure is simpler than I'm making it. There's a possibility all of the results are outdated, as the official documents don't seem to offer what I'm seeing in search result suggestions.
When the mouse enters an Area2D, I want the mouse cursor to change to the hand pointing cursor. When I exit the Area2D, I want it to change back to the pointer. I am not looking to use custom cursors, just the basic ones already implemented in GODOT.
I know how to use mouse_entered/mouse_exited signals. I just can't determine the correct code and location to make the change happen.
When the mouse enters an Area2D, I want the mouse cursor to change to the hand pointing cursor. When I exit the Area2D, I want it to change back to the pointer. I am not looking to use custom cursors, just the basic ones already implemented in GODOT.
For that, the functions you want are Input.set_default_cursor_shape and Input.get_current_cursor_shape.
I know how to use mouse_entered/mouse_exited signals. I just can't determine the correct code and location to make the change happen.
You place the code in whatever signal handlers you connected. I remind you that you can connect the signals from the IDE in the "Node" panel, "Signals" tab. And in the code, you should see a green icon next to the func is connected to a signal. See also Signals.
For example, I connected them to a script in the same Area2D, and added this code:
func _on_Area2D_mouse_entered() -> void:
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
func _on_Area2D_mouse_exited() -> void:
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
Or if you want to store the previous CursorShape, you can do this:
var old_cursor_shape:int = Input.CURSOR_ARROW
func _on_Area2D_mouse_entered() -> void:
old_cursor_shape = Input.get_current_cursor_shape()
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
func _on_Area2D_mouse_exited() -> void:
Input.set_default_cursor_shape(old_cursor_shape)
See CursorShape for the values. Note: There seems to be a bug in the current beta that cause these to not autocomplete.
Reason why mouse_entered/mouse_exited might not work.
Assuming they are correctly connected.
If there is any Control (for example a Container or a background) overlapping a Node2D - such as an Area2D - regardless if it is in front or behind visually. It will prevent it from taking the input. Thus, you must set its mouse_filter of the Control to Ignore.
And make sure the collision_layer and collision_mask of the Area2D are not empty (0), input_pickable is true, and of course the Area2D has a valid CollisionShape2D or CollisionPolygon2D. Otherwise mouse_entered/mouse_exited won't work.
Also, I remind you to pay attention to any errors reported by the IDE.
One thing I recommend you can do would be to make an Area2D as a child of the root node (most likely a Node2D) rename the new Area2D to whatever you want (as long as it isn't named Area2D. For the sake of teaching you, I'm gonna rename it to CursorBox) and attach a script to that new Area2D. Add a CollisionShape2D node as a child of the Area2D, set the shape as a circle, and set the radius to 0.5. Next, go to the top right and press the node button. Connect "Area Entered' and "Area Exited" to the CursorBox. Inside of your script, make sure your functions look like what I have written below.
extends Area2D
var mouseCheck = false
func _on_CursorBox_area_entered(area):
if area.name == ("Area2D"): #This `Area2D` its looking for would be the buttons Area2D
mouseCheck = true
func _on_CursorBox_area_exited(area):
if area.name == ("Area2D"):
mouseCheck = false
The mouse check is just there to see if it works, obviously put your code in there, whatever you need to put in. I would imagine you have some animation you want to play or something. If you have any more questions, just reply and we'll see what else we can do to fix it.
Related
I am using FLTK 1.3, displaying a single Flex column with a number of Flex rows inside a Fl_Scroll. I want to do something to rows that were outside of the visible area when they scroll into view. But I cannot figure out how to do that. There is no event emitted when the scroll position changes (as far as I can see) nor does a callback on the scroll seem to do anything.
The only solution I can think of is something like using the column's, scroll's, or window's callback to get informed of all UI events (such as move, key up, leave, ..) and use them to check whether the scoll's yposition has changed from the last time and run the code I need if it is....
But there surely must be a better way?
Thank you!!!
I am programming a GUI in plain C using X11 library, on Cygwin. When trying to read cursor movements over an open window using XMaskEvent() it works like a charm. It returns an XEvent structure whose coordinates point to the current mouse location and the event_type is a small positive integer number that corresponds to what happened (mouse move, button press, button release etc). So far so good. The problem is that this command blocks (it is supposed to) after each mouse move or button event so my program cannot do anything continuous.
So I tried to replace XMaskEvent() with XCheckMaskEvent() which should read an event, remove it from the queue and continue, so that my program can continue doing something. However, XCheckMaskEvent returns an event with zero coordinates, and constant crazy event_type of minus million-something. Whatever i do with the mouse or keyboard, I am always getting an empty event of a crazy type.
I am using the same event mask for both commands.
What am I doing wrong?
I'a currently working on a small utility, it's my first ever X project. The utility is used to draw a small circle around your mouse pointer. I use an app called Pinpoint to do the same on my Mac, it helps me find my mouse as I'm visually impaired.
The utility creates an transparent X window and draw a circle inside, it then moves that window with the mouse pointer so that the circle follows the mouse.
It currently works, except for one detail. Mouse events are not propagated up to the underlying windows. Basically, the utility makes the mouse useless.
As far as I can tell from the Xlib docs, if not otherwise specified, new windows should propagate all events. How can I fix this?
The code can be found on GitHub: https://github.com/blubber/circle-cursor it's a bit messy currently, becaue it is just a proof of concept.
I would suggest doing via cursor image as well, there are many ways when you won't be able to receive mouse events and only possible source would be polling with XQueryPointer.
With xfixes extension you can subscribe to all cursor image changed events and get most recent shape of the cursor, and whit XRender you can set your own ( possibly animated cursor )
I want to make a simple paint program on visual c++ which allows the user to draw a path of a series of straight lines which follow on from each other. Once the user is done this, they should double click to stop drawing. It is important that I record the co-ordinates of the beginning and end points of each line of the path because I want to use this information to find the magnitude and direction of each line using simple math. Please can someone give me somewhere to start and any other guidance.
You should start with a tutorial in: MFC.
Learn the basics: Document/View architecture and
how painting is done (GDI and device contexts).
Basically, you should:
1. create an MFC application (SDI - single document interface),
2. Handle the OnLButtonDown (WM_LBUTTONDOWN), OnMouseMove (WM_MOVE), OnLButtonUp (WM_LBUTTONUP).
3. Maintain an dynamic array/List (TypedPtrList) of the points
4. handle the double-click event for detecting completion.
You should use the Invalidate() function on (after) each click, in order to see the changes
on the screen.
That's just a little bit of information to get you started
You'll want:
a class or struct to represent a point (if you make it a class, it could have computation methods that would, for example, calculate the distance and direction to another point)
a member variable: an instance of a container class (list, array, etc) to hold your points
a member variable: a boolean flag to represent whether you are drawing or not (starting with not)
and you'll need to handle:
the mouse click event to instantiate a point and add it to your container
the mouse move event to draw a line from the last point to the current mouse position if the drawing flag is true
the mouse double-click event to add the double-click location to your container of points and turn off the drawing flag
Yaron's strategy doesn't draw lines until 2 points are clicked. Mine uses "rubberbanding" to anchor the first end of the line then let the second end follow your cursor until you click to anchor it down. Use whichever one you like better.
if i were you i would use Qt.
Qt widgets are great for user interface. you should check qt examples...
if you want to make an image processing behind, you can use imagemagick library.
this library is great for any image manipulation.
I'd like to write a Linux screen magnifier that's customized to my liking. Ideally, the magnified window would be a square about 150 pixels wide that follows the mouse cursor wherever it goes.
Is it possible to do this in X11? Would it be easier to have an application window that follows the mouse around, or would it be better (or possible) to forget about the window altogether and just make the mouse pointer a 150x150 square that magnifies whatever's underneath?
Look at the source to xeyes?
This actually already exists, it's called Xmag (do a Google search for additional info). You might want to check out the source code for it if you want to know how it works.
EDIT: looks like I misread your question a little bit... if you want a magnified square to follow the mouse pointer around, I suppose it should be possible, but I don't know the technical details of how you'd do it. Regardless, the place to start is probably by looking at Xmag as a starting point.
I am unsure if this can run as its own app or would have to be integrated into your window manager. Either way, you would need libx11 (might have a different name from distro to distro). Also, I would suggest taking a look at swarp. I know this is not even close to what you are talking about, but the source code is only 35 lines and it shows what can be done with libx11.
I would personally make that a frameless window that always stays atop with a 1px hole in the middle. The events that the user makes (Mouse clicks, keypresses, whatever) is passed to the window below.
And when the user moves it's cursor it is ought to be visible to your window and you just move it over a bit. For the magnifying part, well - that is left as an exercise to the reader (Because I do not know how to do that as of yet ;-).
Texworks comes with such a feature to inspect the pdf resulting from typesetting a latex source. You can also choose between a square or a circular magnifier. See https://www.tug.org/texworks/ for access to the code which can serve a launchpad.