The following is simplified code showing the problem I'm facing.
The purpose of the code is to create a 512x512 window and resize Y of its top-level surface to 512x (512 + 25) when a left click is detected. When another left-click is detected, we return sizes up to 512x512.
When a left-click event is detected or upon detection, mouseMotionEventwe display the coordinate of the mouse (s printf()).
Strange behavior is observed:
When I run the code, I clicked once, the Y size of the window changes, but when I move the mouse inside the newly created area, the displayed Y coordinates are anchored to 511.
Sometimes I donโt get this strange behavior, then the Y-coordinate can be more than 511. To get strange behavior, click several times, quickly moving the mouse.
To compile (linux):
$ gcc -o test test.c `sdl-config --cflags --libs`
Source: (test.c)
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
void event_handler(void);
SDL_Surface *screen=NULL;
int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Erreur ร l'initialisation de la SDL : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
if ((screen = SDL_SetVideoMode(512, 512, 32, SDL_SWSURFACE )) == NULL) {
fprintf(stderr, "Graphic mode could not be correctly initialized : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("my window", NULL);
event_handler();
SDL_Quit();
return EXIT_SUCCESS;
}
void event_handler(void)
{
SDL_Event event;
int quit=0;
char message_is_displayed=0;
SDL_Rect mess_coord = {0,512,512,512+25};
while(!quit)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
quit = 1;
break;
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == SDL_BUTTON_LEFT)
{
if(!message_is_displayed)
{
screen = SDL_SetVideoMode(512,512+25, 32, SDL_SWSURFACE);
SDL_FillRect(screen, &mess_coord, SDL_MapRGB(screen->format, 255, 255, 255));
}
else
{
screen = SDL_SetVideoMode(512, 512, 32, SDL_SWSURFACE);
}
message_is_displayed = !message_is_displayed;
SDL_Flip(screen);
}
printf("mouse position: (%d,%d)\n",event.button.x, event.button.y);
break;
case SDL_MOUSEMOTION:
printf("mouse position: (%d,%d)\n",event.motion.x, event.motion.y);
break;
}
}
}