Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
f8481050
Commit
f8481050
authored
Feb 22, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified and unified the window creation process a little.
parent
165076c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
59 deletions
+69
-59
SDL_video.h
include/SDL_video.h
+6
-5
SDL_video.c
src/video/SDL_video.c
+57
-33
SDL_cocoawindow.m
src/video/cocoa/SDL_cocoawindow.m
+6
-21
No files found.
include/SDL_video.h
View file @
f8481050
...
@@ -97,13 +97,14 @@ typedef struct SDL_Window SDL_Window;
...
@@ -97,13 +97,14 @@ typedef struct SDL_Window SDL_Window;
*/
*/
typedef
enum
typedef
enum
{
{
SDL_WINDOW_FULLSCREEN
=
0x00000001
,
/**< fullscreen window
, implies borderless
*/
SDL_WINDOW_FULLSCREEN
=
0x00000001
,
/**< fullscreen window */
SDL_WINDOW_OPENGL
=
0x00000002
,
/**< window usable with OpenGL context */
SDL_WINDOW_OPENGL
=
0x00000002
,
/**< window usable with OpenGL context */
SDL_WINDOW_SHOWN
=
0x00000004
,
/**< window is visible */
SDL_WINDOW_SHOWN
=
0x00000004
,
/**< window is visible */
SDL_WINDOW_BORDERLESS
=
0x00000008
,
/**< no window decoration */
SDL_WINDOW_HIDDEN
=
0x00000008
,
/**< window is not visible */
SDL_WINDOW_RESIZABLE
=
0x00000010
,
/**< window can be resized */
SDL_WINDOW_BORDERLESS
=
0x00000010
,
/**< no window decoration */
SDL_WINDOW_MINIMIZED
=
0x00000020
,
/**< window is minimized */
SDL_WINDOW_RESIZABLE
=
0x00000020
,
/**< window can be resized */
SDL_WINDOW_MAXIMIZED
=
0x00000040
,
/**< window is maximized */
SDL_WINDOW_MINIMIZED
=
0x00000040
,
/**< window is minimized */
SDL_WINDOW_MAXIMIZED
=
0x00000080
,
/**< window is maximized */
SDL_WINDOW_INPUT_GRABBED
=
0x00000100
,
/**< window has grabbed input focus */
SDL_WINDOW_INPUT_GRABBED
=
0x00000100
,
/**< window has grabbed input focus */
SDL_WINDOW_INPUT_FOCUS
=
0x00000200
,
/**< window has input focus */
SDL_WINDOW_INPUT_FOCUS
=
0x00000200
,
/**< window has input focus */
SDL_WINDOW_MOUSE_FOCUS
=
0x00000400
,
/**< window has mouse focus */
SDL_WINDOW_MOUSE_FOCUS
=
0x00000400
,
/**< window has mouse focus */
...
...
src/video/SDL_video.c
View file @
f8481050
...
@@ -580,6 +580,21 @@ SDL_GetNumVideoDisplays(void)
...
@@ -580,6 +580,21 @@ SDL_GetNumVideoDisplays(void)
return
_this
->
num_displays
;
return
_this
->
num_displays
;
}
}
int
SDL_GetIndexOfDisplay
(
SDL_VideoDisplay
*
display
)
{
int
displayIndex
;
for
(
displayIndex
=
0
;
displayIndex
<
_this
->
num_displays
;
++
displayIndex
)
{
if
(
display
==
&
_this
->
displays
[
displayIndex
])
{
return
displayIndex
;
}
}
/* Couldn't find the display, just use index 0 */
return
0
;
}
int
int
SDL_GetDisplayBounds
(
int
displayIndex
,
SDL_Rect
*
rect
)
SDL_GetDisplayBounds
(
int
displayIndex
,
SDL_Rect
*
rect
)
{
{
...
@@ -1066,14 +1081,32 @@ SDL_UpdateFullscreenMode(SDL_Window * window)
...
@@ -1066,14 +1081,32 @@ SDL_UpdateFullscreenMode(SDL_Window * window)
SDL_OnWindowResized
(
window
);
SDL_OnWindowResized
(
window
);
}
}
#define CREATE_FLAGS \
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE)
static
void
SDL_FinishWindowCreation
(
SDL_Window
*
window
,
Uint32
flags
)
{
if
(
flags
&
SDL_WINDOW_MAXIMIZED
)
{
SDL_MaximizeWindow
(
window
);
}
if
(
flags
&
SDL_WINDOW_MINIMIZED
)
{
SDL_MinimizeWindow
(
window
);
}
if
(
flags
&
SDL_WINDOW_FULLSCREEN
)
{
SDL_SetWindowFullscreen
(
window
,
SDL_TRUE
);
}
if
(
flags
&
SDL_WINDOW_INPUT_GRABBED
)
{
SDL_SetWindowGrab
(
window
,
SDL_TRUE
);
}
if
(
!
(
flags
&
SDL_WINDOW_HIDDEN
))
{
SDL_ShowWindow
(
window
);
}
}
SDL_Window
*
SDL_Window
*
SDL_CreateWindow
(
const
char
*
title
,
int
x
,
int
y
,
int
w
,
int
h
,
Uint32
flags
)
SDL_CreateWindow
(
const
char
*
title
,
int
x
,
int
y
,
int
w
,
int
h
,
Uint32
flags
)
{
{
const
Uint32
allowed_flags
=
(
SDL_WINDOW_FULLSCREEN
|
SDL_WINDOW_OPENGL
|
SDL_WINDOW_BORDERLESS
|
SDL_WINDOW_RESIZABLE
|
SDL_WINDOW_INPUT_GRABBED
);
SDL_Window
*
window
;
SDL_Window
*
window
;
if
(
!
_this
)
{
if
(
!
_this
)
{
...
@@ -1101,7 +1134,22 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
...
@@ -1101,7 +1134,22 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
window
->
y
=
y
;
window
->
y
=
y
;
window
->
w
=
w
;
window
->
w
=
w
;
window
->
h
=
h
;
window
->
h
=
h
;
window
->
flags
=
(
flags
&
allowed_flags
);
if
(
SDL_WINDOWPOS_ISUNDEFINED
(
x
)
||
SDL_WINDOWPOS_ISUNDEFINED
(
y
)
||
SDL_WINDOWPOS_ISCENTERED
(
x
)
||
SDL_WINDOWPOS_ISCENTERED
(
y
))
{
SDL_VideoDisplay
*
display
=
SDL_GetDisplayForWindow
(
window
);
int
displayIndex
;
SDL_Rect
bounds
;
displayIndex
=
SDL_GetIndexOfDisplay
(
display
);
SDL_GetDisplayBounds
(
displayIndex
,
&
bounds
);
if
(
SDL_WINDOWPOS_ISUNDEFINED
(
x
)
||
SDL_WINDOWPOS_ISCENTERED
(
y
))
{
window
->
x
=
bounds
.
x
+
(
bounds
.
w
-
w
)
/
2
;
}
if
(
SDL_WINDOWPOS_ISUNDEFINED
(
y
)
||
SDL_WINDOWPOS_ISCENTERED
(
y
))
{
window
->
y
=
bounds
.
y
+
(
bounds
.
h
-
h
)
/
2
;
}
}
window
->
flags
=
((
flags
&
CREATE_FLAGS
)
|
SDL_WINDOW_HIDDEN
);
window
->
next
=
_this
->
windows
;
window
->
next
=
_this
->
windows
;
if
(
_this
->
windows
)
{
if
(
_this
->
windows
)
{
_this
->
windows
->
prev
=
window
;
_this
->
windows
->
prev
=
window
;
...
@@ -1116,16 +1164,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
...
@@ -1116,16 +1164,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if
(
title
)
{
if
(
title
)
{
SDL_SetWindowTitle
(
window
,
title
);
SDL_SetWindowTitle
(
window
,
title
);
}
}
if
(
flags
&
SDL_WINDOW_MAXIMIZED
)
{
SDL_FinishWindowCreation
(
window
,
flags
);
SDL_MaximizeWindow
(
window
);
}
if
(
flags
&
SDL_WINDOW_MINIMIZED
)
{
SDL_MinimizeWindow
(
window
);
}
if
(
flags
&
SDL_WINDOW_SHOWN
)
{
SDL_ShowWindow
(
window
);
}
SDL_UpdateWindowGrab
(
window
);
return
window
;
return
window
;
}
}
...
@@ -1160,12 +1199,6 @@ SDL_CreateWindowFrom(const void *data)
...
@@ -1160,12 +1199,6 @@ SDL_CreateWindowFrom(const void *data)
int
int
SDL_RecreateWindow
(
SDL_Window
*
window
,
Uint32
flags
)
SDL_RecreateWindow
(
SDL_Window
*
window
,
Uint32
flags
)
{
{
const
Uint32
allowed_flags
=
(
SDL_WINDOW_FULLSCREEN
|
SDL_WINDOW_OPENGL
|
SDL_WINDOW_BORDERLESS
|
SDL_WINDOW_RESIZABLE
|
SDL_WINDOW_INPUT_GRABBED
|
SDL_WINDOW_FOREIGN
);
char
*
title
=
window
->
title
;
char
*
title
=
window
->
title
;
if
((
flags
&
SDL_WINDOW_OPENGL
)
&&
!
_this
->
GL_CreateContext
)
{
if
((
flags
&
SDL_WINDOW_OPENGL
)
&&
!
_this
->
GL_CreateContext
)
{
...
@@ -1204,7 +1237,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
...
@@ -1204,7 +1237,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
}
}
window
->
title
=
NULL
;
window
->
title
=
NULL
;
window
->
flags
=
(
flags
&
allowed_flags
);
window
->
flags
=
(
(
flags
&
CREATE_FLAGS
)
|
SDL_WINDOW_HIDDEN
);
if
(
_this
->
CreateWindow
&&
!
(
flags
&
SDL_WINDOW_FOREIGN
))
{
if
(
_this
->
CreateWindow
&&
!
(
flags
&
SDL_WINDOW_FOREIGN
))
{
if
(
_this
->
CreateWindow
(
_this
,
window
)
<
0
)
{
if
(
_this
->
CreateWindow
(
_this
,
window
)
<
0
)
{
...
@@ -1219,16 +1252,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
...
@@ -1219,16 +1252,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
SDL_SetWindowTitle
(
window
,
title
);
SDL_SetWindowTitle
(
window
,
title
);
SDL_free
(
title
);
SDL_free
(
title
);
}
}
if
(
flags
&
SDL_WINDOW_MAXIMIZED
)
{
SDL_FinishWindowCreation
(
window
,
flags
);
SDL_MaximizeWindow
(
window
);
}
if
(
flags
&
SDL_WINDOW_MINIMIZED
)
{
SDL_MinimizeWindow
(
window
);
}
if
(
flags
&
SDL_WINDOW_SHOWN
)
{
SDL_ShowWindow
(
window
);
}
SDL_UpdateWindowGrab
(
window
);
return
0
;
return
0
;
}
}
...
...
src/video/cocoa/SDL_cocoawindow.m
View file @
f8481050
...
@@ -516,7 +516,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
...
@@ -516,7 +516,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
{
{
unsigned
int
style
=
[
nswindow
styleMask
];
unsigned
int
style
=
[
nswindow
styleMask
];
if
(
(
style
&
~
NSResizableWindowMask
)
==
NSBorderlessWindowMask
)
{
if
(
style
==
NSBorderlessWindowMask
)
{
window
->
flags
|=
SDL_WINDOW_BORDERLESS
;
window
->
flags
|=
SDL_WINDOW_BORDERLESS
;
}
else
{
}
else
{
window
->
flags
&=
~
SDL_WINDOW_BORDERLESS
;
window
->
flags
&=
~
SDL_WINDOW_BORDERLESS
;
...
@@ -527,7 +527,8 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
...
@@ -527,7 +527,8 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
window
->
flags
&=
~
SDL_WINDOW_RESIZABLE
;
window
->
flags
&=
~
SDL_WINDOW_RESIZABLE
;
}
}
}
}
if
([
nswindow
isZoomed
])
{
/* isZoomed always returns true if the window is not resizable */
if
((
window
->
flags
&
SDL_WINDOW_RESIZABLE
)
&&
[
nswindow
isZoomed
])
{
window
->
flags
|=
SDL_WINDOW_MAXIMIZED
;
window
->
flags
|=
SDL_WINDOW_MAXIMIZED
;
}
else
{
}
else
{
window
->
flags
&=
~
SDL_WINDOW_MAXIMIZED
;
window
->
flags
&=
~
SDL_WINDOW_MAXIMIZED
;
...
@@ -540,10 +541,6 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
...
@@ -540,10 +541,6 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
if
([
nswindow
isKeyWindow
])
{
if
([
nswindow
isKeyWindow
])
{
window
->
flags
|=
SDL_WINDOW_INPUT_FOCUS
;
window
->
flags
|=
SDL_WINDOW_INPUT_FOCUS
;
SDL_SetKeyboardFocus
(
data
->
window
);
SDL_SetKeyboardFocus
(
data
->
window
);
if
(
window
->
flags
&
SDL_WINDOW_INPUT_GRABBED
)
{
/* FIXME */
}
}
}
/* All done! */
/* All done! */
...
@@ -563,20 +560,8 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
...
@@ -563,20 +560,8 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
unsigned
int
style
;
unsigned
int
style
;
Cocoa_GetDisplayBounds
(
_this
,
display
,
&
bounds
);
Cocoa_GetDisplayBounds
(
_this
,
display
,
&
bounds
);
if
(
SDL_WINDOWPOS_ISCENTERED
(
window
->
x
))
{
rect
.
origin
.
x
=
window
->
x
;
rect
.
origin
.
x
=
bounds
.
x
+
(
bounds
.
w
-
window
->
w
)
/
2
;
rect
.
origin
.
y
=
window
->
y
;
}
else
if
(
SDL_WINDOWPOS_ISUNDEFINED
(
window
->
x
))
{
rect
.
origin
.
x
=
bounds
.
x
;
}
else
{
rect
.
origin
.
x
=
window
->
x
;
}
if
(
SDL_WINDOWPOS_ISCENTERED
(
window
->
y
))
{
rect
.
origin
.
y
=
bounds
.
y
+
(
bounds
.
h
-
window
->
h
)
/
2
;
}
else
if
(
SDL_WINDOWPOS_ISUNDEFINED
(
window
->
y
))
{
rect
.
origin
.
y
=
bounds
.
y
;
}
else
{
rect
.
origin
.
y
=
window
->
y
;
}
rect
.
size
.
width
=
window
->
w
;
rect
.
size
.
width
=
window
->
w
;
rect
.
size
.
height
=
window
->
h
;
rect
.
size
.
height
=
window
->
h
;
ConvertNSRect
(
&
rect
);
ConvertNSRect
(
&
rect
);
...
@@ -763,7 +748,7 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window)
...
@@ -763,7 +748,7 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window)
if
([
nswindow
isMiniaturized
])
{
if
([
nswindow
isMiniaturized
])
{
[
nswindow
deminiaturize
:
nil
];
[
nswindow
deminiaturize
:
nil
];
}
else
if
([
nswindow
isZoomed
])
{
}
else
if
(
(
window
->
flags
&
SDL_WINDOW_RESIZABLE
)
&&
[
nswindow
isZoomed
])
{
[
nswindow
zoom
:
nil
];
[
nswindow
zoom
:
nil
];
}
}
[
pool
release
];
[
pool
release
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment