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

Commit

Permalink
Simplified driver window creation code.
Browse files Browse the repository at this point in the history
Implemented several Cocoa window functions
  • Loading branch information
slouken committed Jul 29, 2006
1 parent 545e4ff commit 3fce07c
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 175 deletions.
1 change: 0 additions & 1 deletion include/SDL_syswm.h
Expand Up @@ -148,7 +148,6 @@ struct SDL_SysWMinfo
{ {
SDL_version version; SDL_version version;
HWND window; /* The Win32 display window */ HWND window; /* The Win32 display window */
HGLRC hglrc; /* The OpenGL context, if any */
}; };


#elif defined(SDL_VIDEO_DRIVER_RISCOS) #elif defined(SDL_VIDEO_DRIVER_RISCOS)
Expand Down
8 changes: 3 additions & 5 deletions include/SDL_video.h
Expand Up @@ -574,17 +574,15 @@ extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green,
* *
* \brief Create a window with the specified position, dimensions, and flags. * \brief Create a window with the specified position, dimensions, and flags.
* *
* \param title The title of the window * \param title The title of the window, in UTF-8 encoding
* \param x The x position of the window * \param x The x position of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
* \param y The y position of the window * \param y The y position of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
* \param w The width of the window * \param w The width of the window
* \param h The height of the window * \param h The height of the window
* \param flags The flags for the window, a mask of any of the following: SDL_WINDOW_FULLSCREEN, SDL_WINDOW_OPENGL, SDL_WINDOW_SHOWN, SDL_WINDOW_BORDERLESS, SDL_WINDOW_RESIZABLE, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MINIMIZED, SDL_WINDOW_INPUT_GRABBED * \param flags The flags for the window, a mask of any of the following: SDL_WINDOW_FULLSCREEN, SDL_WINDOW_OPENGL, SDL_WINDOW_SHOWN, SDL_WINDOW_BORDERLESS, SDL_WINDOW_RESIZABLE, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MINIMIZED, SDL_WINDOW_INPUT_GRABBED
* *
* \return The id of the window created, or zero if window creation failed. * \return The id of the window created, or zero if window creation failed.
* *
* \note Setting the position to -1, -1, indicates any position is fine.
*
* \sa SDL_DestroyWindow() * \sa SDL_DestroyWindow()
*/ */
extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindow(const char *title, extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindow(const char *title,
Expand Down
106 changes: 73 additions & 33 deletions src/video/SDL_video.c
Expand Up @@ -614,9 +614,8 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode)
for (i = 0; i < display->num_windows; ++i) { for (i = 0; i < display->num_windows; ++i) {
SDL_Window *window = &display->windows[i]; SDL_Window *window = &display->windows[i];
if (FULLSCREEN_VISIBLE(window)) { if (FULLSCREEN_VISIBLE(window)) {
SDL_SetWindowPosition(window->id, SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED,
((display_mode.w - window->w) / 2), SDL_WINDOWPOS_CENTERED);
((display_mode.h - window->h) / 2));
} }
} }


Expand Down Expand Up @@ -718,12 +717,8 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{ {
const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
SDL_WINDOW_OPENGL | SDL_WINDOW_OPENGL |
SDL_WINDOW_SHOWN |
SDL_WINDOW_BORDERLESS | SDL_WINDOW_BORDERLESS |
SDL_WINDOW_RESIZABLE | SDL_WINDOW_RESIZABLE);
SDL_WINDOW_MAXIMIZED |
SDL_WINDOW_MINIMIZED |
SDL_WINDOW_INPUT_GRABBED);
SDL_VideoDisplay *display; SDL_VideoDisplay *display;
SDL_Window window; SDL_Window window;
int num_windows; int num_windows;
Expand All @@ -739,9 +734,14 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
return 0; return 0;
} }


/* Fullscreen windows don't have any window decorations */
if (flags & SDL_WINDOW_FULLSCREEN) {
flags |= SDL_WINDOW_BORDERLESS;
flags &= ~SDL_WINDOW_RESIZABLE;
}

SDL_zero(window); SDL_zero(window);
window.id = _this->next_object_id++; window.id = _this->next_object_id++;
window.title = title ? SDL_strdup(title) : NULL;
window.x = x; window.x = x;
window.y = y; window.y = y;
window.w = w; window.w = w;
Expand All @@ -750,9 +750,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
window.display = _this->current_display; window.display = _this->current_display;


if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
if (window.title) {
SDL_free(window.title);
}
return 0; return 0;
} }


Expand All @@ -764,27 +761,27 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (_this->DestroyWindow) { if (_this->DestroyWindow) {
_this->DestroyWindow(_this, &window); _this->DestroyWindow(_this, &window);
} }
if (window.title) {
SDL_free(window.title);
}
return 0; return 0;
} }
windows[num_windows] = window; windows[num_windows] = window;
display->windows = windows; display->windows = windows;
display->num_windows++; display->num_windows++;


if (FULLSCREEN_VISIBLE(&window)) { if (title) {
/* Hide any other fullscreen windows */ SDL_SetWindowTitle(window.id, title);
int i; }
for (i = 0; i < display->num_windows; ++i) { if (flags & SDL_WINDOW_MAXIMIZED) {
SDL_Window *other = &display->windows[i]; SDL_MaximizeWindow(window.id);
if (other->id != window.id && FULLSCREEN_VISIBLE(other)) { }
SDL_MinimizeWindow(other->id); if (flags & SDL_WINDOW_MINIMIZED) {
} SDL_MinimizeWindow(window.id);
} }
SDL_SetDisplayMode(display->fullscreen_mode); if (flags & SDL_WINDOW_SHOWN) {
SDL_ShowWindow(window.id);
}
if (flags & SDL_WINDOW_INPUT_GRABBED) {
SDL_SetWindowGrab(window.id, 1);
} }

return window.id; return window.id;
} }


Expand Down Expand Up @@ -833,15 +830,44 @@ SDL_CreateWindowFrom(const void *data)
int int
SDL_RecreateWindow(SDL_Window * window, Uint32 flags) SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
{ {
char *title = window->title;

if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
SDL_SetError("No OpenGL support in video driver"); SDL_SetError("No OpenGL support in video driver");
return -1; return -1;
} }

if (_this->DestroyWindow) { if (_this->DestroyWindow) {
_this->DestroyWindow(_this, window); _this->DestroyWindow(_this, window);
} }
window->flags = flags;
return _this->CreateWindow(_this, window); window->title = NULL;
window->flags =
(flags &
~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN |
SDL_WINDOW_INPUT_GRABBED));

if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
return -1;
}

if (title) {
SDL_SetWindowTitle(window->id, title);
SDL_free(title);
}
if (flags & SDL_WINDOW_MAXIMIZED) {
SDL_MaximizeWindow(window->id);
}
if (flags & SDL_WINDOW_MINIMIZED) {
SDL_MinimizeWindow(window->id);
}
if (flags & SDL_WINDOW_SHOWN) {
SDL_ShowWindow(window->id);
}
if (flags & SDL_WINDOW_INPUT_GRABBED) {
SDL_SetWindowGrab(window->id, 1);
}
return 0;
} }


SDL_Window * SDL_Window *
Expand Down Expand Up @@ -873,6 +899,9 @@ SDL_GetDisplayFromWindow(SDL_Window * window)
SDL_UninitializedVideo(); SDL_UninitializedVideo();
return NULL; return NULL;
} }
if (!window) {
return NULL;
}
return &_this->displays[window->display]; return &_this->displays[window->display];
} }


Expand All @@ -891,14 +920,20 @@ void
SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) SDL_SetWindowTitle(SDL_WindowID windowID, const char *title)
{ {
SDL_Window *window = SDL_GetWindowFromID(windowID); SDL_Window *window = SDL_GetWindowFromID(windowID);
const char *last_title;


if (!window) { if (!window || title == window->title) {
return; return;
} }

if (window->title) { if (window->title) {
SDL_free(window->title); SDL_free(window->title);
} }
window->title = SDL_strdup(title); if (title) {
window->title = SDL_strdup(title);
} else {
window->title = NULL;
}


if (_this->SetWindowTitle) { if (_this->SetWindowTitle) {
_this->SetWindowTitle(_this, window); _this->SetWindowTitle(_this, window);
Expand Down Expand Up @@ -942,15 +977,20 @@ void
SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
{ {
SDL_Window *window = SDL_GetWindowFromID(windowID); SDL_Window *window = SDL_GetWindowFromID(windowID);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);


if (!window) { if (!window) {
return; return;
} }


if (x != SDL_WINDOWPOS_UNDEFINED) { if (x == SDL_WINDOWPOS_CENTERED) {
window->x = (display->current_mode.w - window->w) / 2;
} else if (x != SDL_WINDOWPOS_UNDEFINED) {
window->x = x; window->x = x;
} }
if (y != SDL_WINDOWPOS_UNDEFINED) { if (y == SDL_WINDOWPOS_CENTERED) {
window->y = (display->current_mode.h - window->h) / 2;
} else if (y != SDL_WINDOWPOS_UNDEFINED) {
window->y = y; window->y = y;
} }


Expand Down Expand Up @@ -1045,7 +1085,7 @@ SDL_RaiseWindow(SDL_WindowID windowID)
{ {
SDL_Window *window = SDL_GetWindowFromID(windowID); SDL_Window *window = SDL_GetWindowFromID(windowID);


if (!window) { if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
return; return;
} }


Expand Down
2 changes: 0 additions & 2 deletions src/video/cocoa/SDL_cocoawindow.h
Expand Up @@ -55,8 +55,6 @@ typedef struct SDL_WindowData SDL_WindowData;
-(void) otherMouseUp:(NSEvent *) theEvent; -(void) otherMouseUp:(NSEvent *) theEvent;
-(void) mouseMoved:(NSEvent *) theEvent; -(void) mouseMoved:(NSEvent *) theEvent;
-(void) scrollWheel:(NSEvent *) theEvent; -(void) scrollWheel:(NSEvent *) theEvent;
-(void) mouseEntered:(NSEvent *) theEvent;
-(void) mouseExited:(NSEvent *) theEvent;
-(void) keyDown:(NSEvent *) theEvent; -(void) keyDown:(NSEvent *) theEvent;
-(void) keyUp:(NSEvent *) theEvent; -(void) keyUp:(NSEvent *) theEvent;
@end @end
Expand Down

0 comments on commit 3fce07c

Please sign in to comment.