We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 258 - Window repositioning problem when menu loaded
Summary: Window repositioning problem when menu loaded
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 1.2.10
Hardware: x86 Windows (XP)
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-21 12:29 UTC by Charles MacDonald
Modified: 2006-06-24 00:31 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Charles MacDonald 2006-06-21 12:29:23 UTC
Using SDL 1.2.10 and mingw, successive calls to SetVideoMode() when a Windows menu is loaded cause the window to be displaced vertically by the number of pixels that comprise the menu height. This makes the window scroll downwards each time, until it is off-screen.

Here's a test case. Press SPACE to call SetVideoMode() with the same window dimensions. If you comment out SetMenu(), no menu is loaded and the window remains at the same position on the desktop.

#include <stdio.h>
#include <windows.h>
#include <SDL.h>
#include <SDL_syswm.h>
SDL_Surface *screen;

void resize_display(void) {
    screen = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE | SDL_ANYFORMAT);
    if(SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, rand(), rand(), rand()));
    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
    SDL_UpdateRect(screen, 0, 0, 0, 0);
}

int main (int argc, char *argv[]) {
    SDL_SysWMinfo wminfo;
    HMENU mnuMain, mnuSub;
    char *keystate;
    int running = 1;
    SDL_Event event;

    SDL_Init(SDL_INIT_VIDEO);
    SDL_VERSION(&wminfo.version);
    SDL_GetWMInfo(&wminfo);

    mnuMain = CreateMenu();
    mnuSub = CreateMenu();
    AppendMenu(mnuSub, MF_STRING, 40001, "&Hello World");
    AppendMenu(mnuMain, MF_POPUP, (UINT_PTR)mnuSub, "File");
    SetMenu(wminfo.window, mnuMain);    
    resize_display();

    while(running) {
        keystate = SDL_GetKeyState(NULL);

        if(keystate[SDLK_SPACE]) {
            resize_display();
        }

        if(keystate[SDLK_ESCAPE])
            running = 0;

        while(SDL_PollEvent(&event)) {
            if(event.type == SDL_QUIT)
                running = 0;
        }
    }

    return 0;
}
Comment 1 Sam Lantinga 2006-06-24 00:31:27 UTC
This is fixed in subversion, thanks!