I'm trying to implement a way to click and drag the screen in SFML. The idea being that when the user clicks down on their mouse, an sf::View gets changed by how much the user moves their mouse until they release it.
I tried to use the sf::Event::MouseMoveEvent struct under the assumption it would give the mouse movement and not the position. When I used it in code, however, it gets the position.
I could try and keep track of the previous mouse position and subtract it out to get the change, but I would expect that there would be a struct or function that would give me the delta position. It has this functionality for the scroll wheel, so I'd hope it does for the mouse.
Related
I'm writing a C++ Win32 application that supports both mouse and touch input.
However when I put my finger on the touchscreen, then the OS moves the mouse cursor into that position.
If I move the finger across the screen, and move the mouse at the same time, then OS will cause mouse cursor flickering, one frame it's under finger, 2nd frame under old mouse position.
I want the touch input to stop changing mouse cursor position.
I want to keep the 2 inputs separate - touch not affecting the mouse.
I want to keep reading 2 inputs at the same time - touch not affecting the mouse.
Here's a solution.
Use WH_MOUSE_LL hook, and block mouse event cause by touching. Then compare MSLLHOOKSTRUCT->dwExtraInfo and 0xFF515700 to determine if it's a touch-caused mouse event.
I'm making a chess game, where I have a box shaped selector, now I want to select a sprite with that box and move it in a specific location with the selection box.
Any link or code?
You keep track of the position of everything.
Poll for events, see where the mouse is. If in the rectangle of a piece, put the selector on top of the piece (assuming you have colorkeying or alpha). You should be able to listen to keyboard input and move the selector based on that.
When mouse clicks, see where the selector is. Find the piece that's under it, and remember it.
When mouse clicks again, see where the selector is now. Check if moving there is valid. If yes, move the piece you remember to the new position.
I'm programming my first 2D game in Qt.
I have QWidged where I draw my game (isometric view). When mouse enters border of widget it moves map view (like in every strategy game...).
And here is my trouble... I'm tracking mouse position with mouseMoveEvent but it fires only when mouse moves (only when position changes). So map moves only when I move mouse at borders. If mouse stand still, map does not move (mouseMoveEvent is not triggered). And I have no idea how to solve this. It's annoying when you try to play it.
This is my first post here.. and I hope that I explained my problem clearly :)
Edit (little more clarify):
Imagine this: you want to move map. So you move mouse to the edge of screen (QWidget) but at the moment when you stop mouse, map stops moving too. But mouse is still at edge of screen. What I want to do is that map will still move after mouse stops at edge.
You can create QPropertyAnimation for coordinates and start/stop it when mouse moves to/from widget's border.
Or you can remember current state ("changing x by -1 every 100ms, changing y by 0") and call some slot that does the real moving with QTimer.
https://stackoverflow.com/questions/9466359/graphics-editor-in-c
I've developed a simple graphics editor in c++.It requires me to drag the mouse to draw a shape .After drawing the shape I want to fill it by picking a color but since dragging the mouse amounts to a large number of clicks because of which the entire screen gets filled with a default color even before i've drawn the shape. delay() doesn't work either.
the mouse click event in turbo c++ has two part. one where you press the button and two when you release the button. you need to drag so you should use the clrscr() function in the loop which goes on iterating until the mouse button is pressed down along with the code for the shape you want to draw. that way your screen keeps getting updated when you are dragging the mouse. and the loop ends when you release the button.
for filling the shape using the flood fill function should suffice
Perhaps one of the following links is what you're looking for:
http://www.codeproject.com/Articles/11313/Mouse-Programming-in-C-C
http://www.cprogrammingreference.com/Tutorials/Advance_Tutorials/mouseprogramming.php
http://www.brackeen.com/vga/mouse.html
This is my first attempt at writing a QT app, and I'm just trying to get a feel for how it works. My goal is to have a 400x400 widget which knows the exact position of the mouse when the mouse is hovering over it. For example, if the mouse was hovering in the top left corner, the position might be 10,10 (or something similar). If the mouse is in the bottom right corner, it might say 390,390.
Eventually, these coordinates will be displayed in a label on the main window, but that should be trivial. I'm stuck at the actual fetching of the coordinates. Any ideas?
For your widget, you must enable mouse tracking.
Then, you can either install an event filter, paying attention to mouse events and looking for the move event, or you can inherit from QWidget and override the mouse event, looking for mouse move events.
http://doc.qt.io/qt-4.8/qwidget.html#mouseTracking-prop
http://doc.qt.io/qt-4.8/eventsandfilters.html
http://doc.qt.io/qt-4.8/qmouseevent.html
If you are ever in a situation when you don't need actual tracking, just position at the moment, you can use QCursor::pos().