src/video/win32/SDL_win32window.c
changeset 1956 ba0d62354872
parent 1952 420716272158
child 2580 64fa227c01ce
child 2710 44e49d3fa6cf
child 3767 abc8acb8e3d7
equal deleted inserted replaced
1955:8c6106e45fc1 1956:ba0d62354872
   131 
   131 
   132 int
   132 int
   133 WIN_CreateWindow(_THIS, SDL_Window * window)
   133 WIN_CreateWindow(_THIS, SDL_Window * window)
   134 {
   134 {
   135     HWND hwnd;
   135     HWND hwnd;
   136     LPTSTR title = NULL;
       
   137     HWND top;
   136     HWND top;
   138     RECT rect;
   137     RECT rect;
   139     DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
   138     DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
   140     int x, y;
   139     int x, y;
   141     int w, h;
   140     int w, h;
   142 
   141 
   143     if (window->title) {
   142     if (window->flags & SDL_WINDOW_BORDERLESS) {
   144         title = WIN_UTF8ToString(window->title);
       
   145     } else {
       
   146         title = NULL;
       
   147     }
       
   148 
       
   149     if (window->flags & SDL_WINDOW_SHOWN) {
       
   150         style |= WS_VISIBLE;
       
   151     }
       
   152     if ((window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS))) {
       
   153         style |= WS_POPUP;
   143         style |= WS_POPUP;
   154     } else {
   144     } else {
   155         style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
   145         style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
   156     }
   146     }
   157     if (window->flags & SDL_WINDOW_RESIZABLE) {
   147     if (window->flags & SDL_WINDOW_RESIZABLE) {
   158         style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
   148         style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
   159     }
       
   160     if (window->flags & SDL_WINDOW_MAXIMIZED) {
       
   161         style |= WS_MAXIMIZE;
       
   162     }
       
   163     if (window->flags & SDL_WINDOW_MINIMIZED) {
       
   164         style |= WS_MINIMIZE;
       
   165     }
   149     }
   166 
   150 
   167     /* Figure out what the window area will be */
   151     /* Figure out what the window area will be */
   168     if (window->flags & SDL_WINDOW_FULLSCREEN) {
   152     if (window->flags & SDL_WINDOW_FULLSCREEN) {
   169         top = HWND_TOPMOST;
   153         top = HWND_TOPMOST;
   176     rect.bottom = window->h;
   160     rect.bottom = window->h;
   177     AdjustWindowRectEx(&rect, style, FALSE, 0);
   161     AdjustWindowRectEx(&rect, style, FALSE, 0);
   178     w = (rect.right - rect.left);
   162     w = (rect.right - rect.left);
   179     h = (rect.bottom - rect.top);
   163     h = (rect.bottom - rect.top);
   180 
   164 
   181     if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
   165     if (window->x == SDL_WINDOWPOS_CENTERED) {
   182         window->x == SDL_WINDOWPOS_CENTERED) {
       
   183         x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
   166         x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
   184     } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   167     } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   185         x = CW_USEDEFAULT;
   168         x = CW_USEDEFAULT;
   186     } else {
   169     } else {
   187         x = window->x + rect.left;
   170         x = window->x + rect.left;
   188     }
   171     }
   189     if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
   172     if (window->y == SDL_WINDOWPOS_CENTERED) {
   190         window->y == SDL_WINDOWPOS_CENTERED) {
       
   191         y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
   173         y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
   192     } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   174     } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   193         y = CW_USEDEFAULT;
   175         y = CW_USEDEFAULT;
   194     } else {
   176     } else {
   195         y = window->y + rect.top;
   177         y = window->y + rect.top;
   196     }
   178     }
   197 
   179 
   198     hwnd = CreateWindow(SDL_Appname,
   180     hwnd =
   199                         title ? title : TEXT(""),
   181         CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
   200                         style, x, y, w, h, NULL, NULL, SDL_Instance, NULL);
   182                      SDL_Instance, NULL);
   201     WIN_PumpEvents(_this);
   183     WIN_PumpEvents(_this);
   202 
       
   203     if (title) {
       
   204         SDL_free(title);
       
   205     }
       
   206 
   184 
   207     if (!hwnd) {
   185     if (!hwnd) {
   208         WIN_SetError("Couldn't create window");
   186         WIN_SetError("Couldn't create window");
   209         return -1;
   187         return -1;
   210     }
   188     }
   275     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   253     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   276     RECT rect;
   254     RECT rect;
   277     DWORD style;
   255     DWORD style;
   278     HWND top;
   256     HWND top;
   279     int x, y;
   257     int x, y;
       
   258 
       
   259     /* Figure out what the window area will be */
       
   260     if (window->flags & SDL_WINDOW_FULLSCREEN) {
       
   261         top = HWND_TOPMOST;
       
   262     } else {
       
   263         top = HWND_NOTOPMOST;
       
   264     }
       
   265     style = GetWindowLong(hwnd, GWL_STYLE);
       
   266     rect.left = 0;
       
   267     rect.top = 0;
       
   268     rect.right = window->w;
       
   269     rect.bottom = window->h;
       
   270     AdjustWindowRectEx(&rect, style,
       
   271                        (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
       
   272                                                            NULL), 0);
       
   273     x = window->x + rect.left;
       
   274     y = window->y + rect.top;
       
   275 
       
   276     SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
       
   277 }
       
   278 
       
   279 void
       
   280 WIN_SetWindowSize(_THIS, SDL_Window * window)
       
   281 {
       
   282     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
       
   283     RECT rect;
       
   284     DWORD style;
       
   285     HWND top;
   280     int w, h;
   286     int w, h;
   281 
   287 
   282     /* Figure out what the window area will be */
   288     /* Figure out what the window area will be */
   283     if (window->flags & SDL_WINDOW_FULLSCREEN) {
   289     if (window->flags & SDL_WINDOW_FULLSCREEN) {
   284         top = HWND_TOPMOST;
   290         top = HWND_TOPMOST;
   294                        (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   300                        (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
   295                                                            NULL), 0);
   301                                                            NULL), 0);
   296     w = (rect.right - rect.left);
   302     w = (rect.right - rect.left);
   297     h = (rect.bottom - rect.top);
   303     h = (rect.bottom - rect.top);
   298 
   304 
   299     if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
       
   300         window->x == SDL_WINDOWPOS_CENTERED) {
       
   301         x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
       
   302         window->x = x - rect.left;
       
   303     } else {
       
   304         x = window->x + rect.left;
       
   305     }
       
   306     if ((window->flags & SDL_WINDOW_FULLSCREEN) ||
       
   307         window->y == SDL_WINDOWPOS_CENTERED) {
       
   308         y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
       
   309         window->y = y - rect.top;
       
   310     } else {
       
   311         y = window->y + rect.top;
       
   312     }
       
   313     SetWindowPos(hwnd, top, x, y, h, w, (SWP_NOCOPYBITS | SWP_NOSIZE));
       
   314 }
       
   315 
       
   316 void
       
   317 WIN_SetWindowSize(_THIS, SDL_Window * window)
       
   318 {
       
   319     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
       
   320     RECT rect;
       
   321     DWORD style;
       
   322     HWND top;
       
   323     int w, h;
       
   324 
       
   325     /* Figure out what the window area will be */
       
   326     if (window->flags & SDL_WINDOW_FULLSCREEN) {
       
   327         top = HWND_TOPMOST;
       
   328     } else {
       
   329         top = HWND_NOTOPMOST;
       
   330     }
       
   331     style = GetWindowLong(hwnd, GWL_STYLE);
       
   332     rect.left = 0;
       
   333     rect.top = 0;
       
   334     rect.right = window->w;
       
   335     rect.bottom = window->h;
       
   336     AdjustWindowRectEx(&rect, style,
       
   337                        (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) !=
       
   338                                                            NULL), 0);
       
   339     w = (rect.right - rect.left);
       
   340     h = (rect.bottom - rect.top);
       
   341 
       
   342     SetWindowPos(hwnd, top, 0, 0, h, w, (SWP_NOCOPYBITS | SWP_NOMOVE));
   305     SetWindowPos(hwnd, top, 0, 0, h, w, (SWP_NOCOPYBITS | SWP_NOMOVE));
   343 }
   306 }
   344 
   307 
   345 void
   308 void
   346 WIN_ShowWindow(_THIS, SDL_Window * window)
   309 WIN_ShowWindow(_THIS, SDL_Window * window)
   436 WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   399 WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   437 {
   400 {
   438     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   401     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
   439     if (info->version.major <= SDL_MAJOR_VERSION) {
   402     if (info->version.major <= SDL_MAJOR_VERSION) {
   440         info->window = hwnd;
   403         info->window = hwnd;
   441         /* FIXME! */
       
   442         info->hglrc = NULL;
       
   443         return SDL_TRUE;
   404         return SDL_TRUE;
   444     } else {
   405     } else {
   445         SDL_SetError("Application not compiled with SDL %d.%d\n",
   406         SDL_SetError("Application not compiled with SDL %d.%d\n",
   446                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   407                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   447         return SDL_FALSE;
   408         return SDL_FALSE;