SFML community forums
Help => General => Topic started by: barnack on August 19, 2018, 03:14:12 am
-
Hi,
i was enjoying working more or less flawlessly in my project (not a game). Since its an utility and it doesnt have to eat resources as a game while not being used, i opted for waitEvent instead of pollEvent.
However working on workspace navigation i ended up with a "oh shit" situation.
I planned using both mouse-near-borders and arrow keys to navigate on the working zone in case it is bigger than the window.
And yeah i cant do that with waitEvent, because once the mouse gets to the border and the event triggers once, everything stops.
Indeed thinking later about that, programs like paint and paint.net, event notepad++ have keyboard navigation based on operating system simulated key repetition when the arrow is being held; which i could pretty much do as well.
The point is, is there any workaround you can suggest me to have it work with mouse-near-borders, like in rts games?
My only idea now was putting all the draw part in a function, and have my main loop looking like that (i know its ugly)
if waitEvent(event)
{
//stuff happens
switch(event)
{
case mouse on border:
while pollEvent(tmp_event)
if mouse on border
move screen
draw()
else
break out of poll event
case other events:
}
draw();
}
-
I don't fully understand the problem you're encountering (mouse near border?). Can you maybe rephrase it somehow?
User inputs such as key presses, mouse movement, etc will trigger an event, so waitEvent will return in those cases.
-
catching mouseMoved, if its coordinates are, let's say, within 2 pixels from left border, the view should constantly move left until mouse is moved out of that position. Pretty stright to do with pollEvent since the cycle will continue even if there are no events. But i dont want my program to keep doing cycles when the user is doing nothing, except for that single case, when the mouse is near the border.
-
You may have to switch to using poll event to track the mouse in real-time. However, you can do this only when you expect to need this tracking. For example, when you move "close" to the border, you can switch a state to use poll event until the mouse either moves away from this zone or leaves the window and then switch back to waiting for the event.