Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
You can now create multiple windows on Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jun 28, 2006
1 parent 2bc6d2f commit 7598c3d
Show file tree
Hide file tree
Showing 8 changed files with 394 additions and 18 deletions.
29 changes: 23 additions & 6 deletions include/SDL_video.h
Expand Up @@ -116,17 +116,28 @@ typedef Uint32 SDL_WindowID;
typedef enum
{
SDL_WINDOW_FULLSCREEN = 0x00000001, /**< fullscreen window, implies borderless */
SDL_WINDOW_BORDERLESS = 0x00000002, /**< no window decoration */
SDL_WINDOW_OPENGL = 0x00000002, /**< window usable with OpenGL context */
SDL_WINDOW_SHOWN = 0x00000004, /**< window is visible */
SDL_WINDOW_OPENGL = 0x00000008, /**< window usable with OpenGL context */
SDL_WINDOW_BORDERLESS = 0x00000008, /**< no window decoration */
SDL_WINDOW_RESIZABLE = 0x00000010, /**< window can be resized */
SDL_WINDOW_MAXIMIZED = 0x00000020, /**< maximized */
SDL_WINDOW_MINIMIZED = 0x00000040, /**< minimized */
SDL_WINDOW_INPUT_GRABBED = 0x00000080, /**< window has grabbed input focus */
SDL_WINDOW_KEYBOARD_FOCUS = 0x00000100, /**< window has keyboard focus */
SDL_WINDOW_MOUSE_FOCUS = 0x00000200, /**< window has mouse focus */
SDL_WINDOW_INPUT_GRABBED = 0x00000100, /**< window has grabbed input focus */
SDL_WINDOW_KEYBOARD_FOCUS = 0x00000200, /**< window has keyboard focus */
SDL_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */
} SDL_WindowFlags;

/**
* \def SDL_WINDOWPOS_UNDEFINED
* \brief Used to indicate that you don't care what the window position is.
*/
#define SDL_WINDOWPOS_UNDEFINED 0x7FFFFFF
/**
* \def SDL_WINDOWPOS_CENTERED
* \brief Used to indicate that the window position should be centered.
*/
#define SDL_WINDOWPOS_CENTERED 0x7FFFFFE

/**
* \enum SDL_WindowEventID
*
Expand Down Expand Up @@ -584,6 +595,12 @@ extern DECLSPEC void *SDLCALL SDL_GetWindowData(SDL_WindowID windowID);
*
* \brief Set the position of the window.
*
* \param windowID The window to reposition
* \param x The x coordinate of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
* \param y The y coordinate of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
*
* \note The window coordinate origin is the upper left of the display.
*
* \sa SDL_GetWindowPosition()
*/
extern DECLSPEC void SDLCALL SDL_SetWindowPosition(SDL_WindowID windowID,
Expand Down Expand Up @@ -737,7 +754,7 @@ extern DECLSPEC int SDLCALL SDL_GetRendererInfo(int index,
*
* \brief Create and make active a 2D rendering context for a window.
*
* \param windowID The window used for rendering.
* \param windowID The window used for rendering
* \param index The index of the render manager to initialize, or -1 to initialize the first one supporting the requested flags.
* \param flags SDL_RendererFlags
*
Expand Down
12 changes: 8 additions & 4 deletions src/video/SDL_video.c
Expand Up @@ -647,9 +647,9 @@ SDL_WindowID
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{
const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
SDL_WINDOW_BORDERLESS |
SDL_WINDOW_SHOWN |
SDL_WINDOW_OPENGL |
SDL_WINDOW_SHOWN |
SDL_WINDOW_BORDERLESS |
SDL_WINDOW_RESIZABLE |
SDL_WINDOW_MAXIMIZED |
SDL_WINDOW_MINIMIZED |
Expand Down Expand Up @@ -842,8 +842,12 @@ SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
return;
}

window->x = x;
window->y = y;
if (x != SDL_WINDOWPOS_UNDEFINED) {
window->x = x;
}
if (y != SDL_WINDOWPOS_UNDEFINED) {
window->y = y;
}

if (_this->SetWindowPosition) {
_this->SetWindowPosition(_this, window);
Expand Down
36 changes: 31 additions & 5 deletions src/video/win32/SDL_win32events.c
Expand Up @@ -24,10 +24,20 @@
#include "SDL_win32video.h"


static LRESULT CALLBACK
WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
SDL_WindowData *data;
SDL_Window *window;

/* Get the window data for the window */
data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
if (!data) {
return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
}
window = data->window;

return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
}

void
Expand Down Expand Up @@ -63,7 +73,7 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst)
}

if (name) {
SDL_Appname = SDL_iconv_utf8_ucs2(name);
SDL_Appname = WIN_UTF8ToString(name);
SDL_Appstyle = style;
SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
}
Expand All @@ -77,7 +87,7 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst)
class.hbrBackground = NULL;
class.hInstance = SDL_Instance;
class.style = SDL_Appstyle;
class.lpfnWndProc = WinMessage;
class.lpfnWndProc = DefWindowProc;
class.cbWndExtra = 0;
class.cbClsExtra = 0;
if (!RegisterClass(&class)) {
Expand Down Expand Up @@ -110,4 +120,20 @@ SDL_UnregisterApp()
}
}

/* Sets an error message based on GetLastError() */
void
WIN_SetError(const char *prefix)
{
TCHAR buffer[1024];
char *message;

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(), 0, buffer, SDL_arraysize(buffer), NULL);

message = WIN_StringToUTF8(buffer);
SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ":" : "", message);
SDL_free(message);
}

/* vi: set ts=4 sw=4 expandtab: */
5 changes: 3 additions & 2 deletions src/video/win32/SDL_win32events.h
Expand Up @@ -24,13 +24,14 @@
#ifndef _SDL_win32events_h
#define _SDL_win32events_h

#include "../SDL_sysvideo.h"

extern LPTSTR SDL_Appname;
extern Uint32 SDL_Appstyle;
extern HINSTANCE SDL_Instance;

extern LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam);
extern void WIN_PumpEvents(_THIS);
extern void WIN_SetError(const char *prefix);

#endif /* _SDL_win32events_h */

Expand Down
8 changes: 8 additions & 0 deletions src/video/win32/SDL_win32video.h
Expand Up @@ -33,6 +33,14 @@
#include "SDL_win32events.h"
#include "SDL_win32window.h"

#ifdef UNICODE
#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2", (char *)S, (wcslen(S)+1)*sizeof(WCHAR))
#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1)
#else
#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)S, (strlen(S)+1))
#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1)
#endif

/* Private display data */

struct SDL_PrivateVideoData
Expand Down

0 comments on commit 7598c3d

Please sign in to comment.