The problem i have, it’s very silly.
I’m creating a scrollbar but when i pollEvent SDL_MOUSEWHEEL the structure SDL_MouseMotionEvent.y(shows a random const), SDL_MouseMotionEvent.x(shows wheel.y) don’t show the cursor position.
And when i pollEvent SDL_MOUSEMOTION the structure SDL_MouseWheelEvent.y(shows motion.y), SDL_MouseWheelEvent.x(shows 0).
Seems like the structures some how get corrupted or maybe there is something i don’t know.
The idea was use motion.y and motion.x to limit the mouse the same size of the scrollbar and wheel.y to control de value of the scrollbar.
Here is a screenshot to explain much better:
Code main.h:
...
while(true){
// Update the surface
SDL_UpdateWindowSurface( window );
SDL_Event event;
while(SDL_PollEvent(&event)){
if(myScrollV.onChange(event)){
myScrollV.Gui_draw(screenSurface);
}
else if(myScrollV.onWheelMove(event)){
myScrollV.Gui_draw(screenSurface);
}
}
}
...
Code scrollbar.h:
...
bool Gui_scrollbar_vertical::onChange(SDL_Event &event){
if(event.button.button == SDL_BUTTON_LEFT && event.motion.y >= rect.y && event.motion.y <= (rect.y + rect.h) && event.motion.x > (rect.x - grabSize) && (event.motion.x < (rect.x + rect.w + grabSize)) ){
value = event.motion.y - rect.y;
if(event.motion.y <= ((rect.y + rect.h) - indicatorRect.h)){// para que no lo renderice afuera
indicatorRect.y = event.motion.y;
}
return true;
}
else{
return false;
}
}
bool Gui_scrollbar_vertical::onWheelMove(SDL_Event &event){
if(event.type == SDL_MOUSEWHEEL || event.type == SDL_MOUSEMOTION){
printf("event.motion.y: %d event.motion.x: %d event.wheel.y: %d event.wheel.x: %d\n", event.button.y, event.button.x, event.wheel.y, event.wheel.x);
return true;
}
return false;
}
...
If anyone has any idea, I really will thank.
PS: by the way my english it’s not quite good. So it’s possible i made a lot of mistakes.