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
ab0fcbfb
Commit
ab0fcbfb
authored
Mar 29, 2011
by
Ryan C. Gordon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added orientation rotation for iOS.
parent
15b112e3
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
114 additions
and
19 deletions
+114
-19
SDL_uikitopengles.m
src/video/uikit/SDL_uikitopengles.m
+12
-6
SDL_uikitopenglview.m
src/video/uikit/SDL_uikitopenglview.m
+3
-0
SDL_uikitview.h
src/video/uikit/SDL_uikitview.h
+13
-1
SDL_uikitwindow.h
src/video/uikit/SDL_uikitwindow.h
+1
-0
SDL_uikitwindow.m
src/video/uikit/SDL_uikitwindow.m
+81
-11
testgles.c
test/testgles.c
+1
-1
testsprite2.c
test/testsprite2.c
+3
-0
No files found.
src/video/uikit/SDL_uikitopengles.m
View file @
ab0fcbfb
...
...
@@ -117,13 +117,15 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
majorVersion
:
_
this
->
gl
_
config
.
major
_
version
]
;
data
->
view
=
view
;
view
->
viewcontroller
=
data
->
viewcontroller
;
if
(
view
->
viewcontroller
!=
nil
)
{
[
view
->
viewcontroller
setView
:
view
]
;
[
view
->
viewcontroller
retain
]
;
}
/*
add
the
view
to
our
window
*/
[
uiwindow
addSubview
:
view
]
;
/*
Don
'
t
worry
,
the
window
retained
the
view
*/
[
view
release
]
;
if
(
UIKit
_
GL
_
MakeCurrent
(
_
this
,
window
,
view
)
<
0
)
{
UIKit
_
GL
_
DeleteContext
(
_
this
,
view
)
;
return
NULL
;
...
...
@@ -140,8 +142,12 @@ void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
{
/*
the
delegate
has
retained
the
view
,
this
will
release
him
*/
SDL
_
uikitopenglview
*
view
=
(
SDL
_
uikitopenglview
*
)
context
;
/*
this
will
also
delete
it
*/
if
(
view
->
viewcontroller
)
{
[
view
->
viewcontroller
setView
:
nil
]
;
[
view
->
viewcontroller
release
]
;
}
[
view
removeFromSuperview
]
;
[
view
release
]
;
}
/*
vi
:
set
ts
=
4
sw
=
4
expandtab
:
*/
src/video/uikit/SDL_uikitopenglview.m
View file @
ab0fcbfb
...
...
@@ -121,9 +121,12 @@
}
/* end create buffers */
// !!! FIXME: use the screen this is on!
/* Use the main screen scale (for retina display support) */
if
([[
UIScreen
mainScreen
]
respondsToSelector
:
@selector
(
scale
)])
self
.
contentScaleFactor
=
[
UIScreen
mainScreen
].
scale
;
self
.
autoresizingMask
=
UIViewAutoresizingFlexibleWidth
|
UIViewAutoresizingFlexibleHeight
;
}
return
self
;
}
...
...
src/video/uikit/SDL_uikitview.h
View file @
ab0fcbfb
...
...
@@ -30,6 +30,16 @@
#define MAX_SIMULTANEOUS_TOUCHES 5
#endif
@interface
SDL_uikitviewcontroller
:
UIViewController
{
@private
SDL_Window
*
window
;
}
-
(
id
)
initWithSDLWindow
:
(
SDL_Window
*
)
_window
;
-
(
BOOL
)
shouldAutorotateToInterfaceOrientation
:(
UIInterfaceOrientation
)
orient
;
-
(
void
)
loadView
;
-
(
void
)
willRotateToInterfaceOrientation
:(
UIInterfaceOrientation
)
toInterfaceOrientation
duration
:(
NSTimeInterval
)
duration
;
@end
/* *INDENT-OFF* */
#if SDL_IPHONE_KEYBOARD
@interface
SDL_uikitview
:
UIView
<
UITextFieldDelegate
>
{
...
...
@@ -49,6 +59,8 @@
BOOL
keyboardVisible
;
#endif
@public
SDL_uikitviewcontroller
*
viewcontroller
;
}
-
(
void
)
touchesBegan
:
(
NSSet
*
)
touches
withEvent
:
(
UIEvent
*
)
event
;
-
(
void
)
touchesEnded
:(
NSSet
*
)
touches
withEvent
:(
UIEvent
*
)
event
;
...
...
src/video/uikit/SDL_uikitwindow.h
View file @
ab0fcbfb
...
...
@@ -40,6 +40,7 @@ struct SDL_WindowData
{
UIWindow
*
uiwindow
;
SDL_uikitopenglview
*
view
;
SDL_uikitviewcontroller
*
viewcontroller
;
};
...
...
src/video/uikit/SDL_uikitwindow.m
View file @
ab0fcbfb
...
...
@@ -38,6 +38,58 @@
#include <Foundation/Foundation.h>
@implementation
SDL_uikitviewcontroller
-
(
id
)
initWithSDLWindow
:(
SDL_Window
*
)
_window
{
[
self
init
];
self
->
window
=
_window
;
return
self
;
}
-
(
BOOL
)
shouldAutorotateToInterfaceOrientation
:(
UIInterfaceOrientation
)
orient
{
return
YES
;
}
-
(
void
)
loadView
{
// do nothing.
}
// Send a resized event when the orientation changes.
-
(
void
)
willRotateToInterfaceOrientation
:
(
UIInterfaceOrientation
)
toInterfaceOrientation
duration
:
(
NSTimeInterval
)
duration
{
SDL_WindowData
*
data
=
self
->
window
->
driverdata
;
UIWindow
*
uiwindow
=
data
->
uiwindow
;
CGRect
frame
=
[
uiwindow
frame
];
const
CGSize
size
=
frame
.
size
;
int
w
,
h
;
switch
(
toInterfaceOrientation
)
{
case
UIInterfaceOrientationPortrait
:
case
UIInterfaceOrientationPortraitUpsideDown
:
w
=
(
size
.
width
<
size
.
height
)
?
size
.
width
:
size
.
height
;
h
=
(
size
.
width
>
size
.
height
)
?
size
.
width
:
size
.
height
;
break
;
case
UIInterfaceOrientationLandscapeLeft
:
case
UIInterfaceOrientationLandscapeRight
:
w
=
(
size
.
width
>
size
.
height
)
?
size
.
width
:
size
.
height
;
h
=
(
size
.
width
<
size
.
height
)
?
size
.
width
:
size
.
height
;
break
;
default
:
SDL_assert
(
0
&&
"Unexpected interface orientation!"
);
return
;
}
self
->
window
->
w
=
w
;
self
->
window
->
h
=
h
;
frame
.
size
.
width
=
w
;
frame
.
size
.
height
=
h
;
SDL_SendWindowEvent
(
self
->
window
,
SDL_WINDOWEVENT_RESIZED
,
w
,
h
);
}
@end
static
int
SetupWindowData
(
_THIS
,
SDL_Window
*
window
,
UIWindow
*
uiwindow
,
SDL_bool
created
)
{
SDL_VideoDisplay
*
display
=
SDL_GetDisplayForWindow
(
window
);
...
...
@@ -51,6 +103,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
return
-
1
;
}
data
->
uiwindow
=
uiwindow
;
data
->
viewcontroller
=
nil
;
data
->
view
=
nil
;
/* Fill in the SDL window with the window data */
...
...
@@ -63,8 +116,10 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
window
->
driverdata
=
data
;
// !!! FIXME: should we force this? Shouldn't specifying FULLSCREEN
// !!! FIXME: imply BORDERLESS?
window
->
flags
|=
SDL_WINDOW_FULLSCREEN
;
/* window is always fullscreen */
window->flags |= SDL_WINDOW_SHOWN; /* only one window on i
Pod touch
, always shown */
window
->
flags
|=
SDL_WINDOW_SHOWN
;
/* only one window on i
OS
, always shown */
// SDL_WINDOW_BORDERLESS controls whether status bar is hidden.
// This is only set if the window is on the main screen. Other screens
...
...
@@ -72,6 +127,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
if
([
UIScreen
mainScreen
]
!=
uiscreen
)
{
window
->
flags
&=
~
SDL_WINDOW_RESIZABLE
;
// window is NEVER resizeable
window
->
flags
&=
~
SDL_WINDOW_INPUT_FOCUS
;
// never has input focus
window
->
flags
|=
SDL_WINDOW_BORDERLESS
;
// never has a status bar.
}
else
{
window
->
flags
|=
SDL_WINDOW_INPUT_FOCUS
;
// always has input focus
...
...
@@ -81,21 +137,34 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
// Rotate the view if we have to, but only on the main screen
// (presumably, an external display doesn't report orientation).
const
CGSize
uisize
=
[[
uiscreen
currentMode
]
size
];
if ( ((window->w > window->h) && (uisize.width < uisize.height)) ||
((window->w < window->h) && (uisize.width > uisize.height)) ) {
// !!! FIXME: flip orientation.
}
const
UIDeviceOrientation
o
=
[[
UIDevice
currentDevice
]
orientation
];
const
BOOL
landscape
=
(
o
==
UIDeviceOrientationLandscapeLeft
)
||
(
o
==
UIDeviceOrientationLandscapeRight
);
const
BOOL
rotate
=
(
((
window
->
w
>
window
->
h
)
&&
(
!
landscape
))
||
((
window
->
w
<
window
->
h
)
&&
(
landscape
))
);
if
(
window
->
flags
&
SDL_WINDOW_RESIZABLE
)
{
// !!! FIXME: register for orientation change alerts.
// The View Controller will handle rotating the view when the
// device orientation changes. We expose these as resize events.
SDL_uikitviewcontroller
*
controller
;
controller
=
[
SDL_uikitviewcontroller
alloc
];
data
->
viewcontroller
=
[
controller
initWithSDLWindow
:
window
];
[
data
->
viewcontroller
setTitle
:
@"SDL App"
];
// !!! FIXME: hook up SDL_SetWindowTitle()
// !!! FIXME: if (rotate), force a "resize" right at the start
}
else
{
// Rotate the view if we have to, but only on the main screen
// (presumably, an external display doesn't report orientation).
if
(
rotate
)
{
#define D2R(x) (M_PI * (x) / 180.0) // degrees to radians.
[
uiwindow
setTransform
:
CGAffineTransformIdentity
];
[
uiwindow
setTransform
:
CGAffineTransformMakeRotation
(
D2R
(
90
))];
#undef D2R
}
}
}
return
0
;
}
int
...
...
@@ -107,7 +176,7 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
// SDL currently puts this window at the start of display's linked list. We rely on this.
SDL_assert
(
_this
->
windows
==
window
);
/*
We
currently
only
handle
a
single
window
per
display
on
i
Phone
*/
/* We currently only handle a single window per display on i
OS
*/
if
(
window
->
next
!=
NULL
)
{
SDL_SetError
(
"Only one window allowed per display."
);
return
-
1
;
...
...
@@ -172,6 +241,7 @@ void
UIKit_DestroyWindow
(
_THIS
,
SDL_Window
*
window
)
{
SDL_WindowData
*
data
=
(
SDL_WindowData
*
)
window
->
driverdata
;
if
(
data
)
{
[
data
->
viewcontroller
release
];
[
data
->
uiwindow
release
];
SDL_free
(
data
);
window
->
driverdata
=
NULL
;
...
...
test/testgles.c
View file @
ab0fcbfb
...
...
@@ -140,7 +140,7 @@ main(int argc, char *argv[])
}
/* Set OpenGL parameters */
state
->
window_flags
|=
SDL_WINDOW_OPENGL
;
state
->
window_flags
|=
SDL_WINDOW_OPENGL
|
SDL_WINDOW_RESIZABLE
|
SDL_WINDOW_BORDERLESS
;
state
->
gl_red_size
=
5
;
state
->
gl_green_size
=
5
;
state
->
gl_blue_size
=
5
;
...
...
test/testsprite2.c
View file @
ab0fcbfb
...
...
@@ -219,6 +219,9 @@ main(int argc, char *argv[])
if
(
!
state
)
{
return
1
;
}
state
->
window_flags
|=
SDL_WINDOW_RESIZABLE
;
for
(
i
=
1
;
i
<
argc
;)
{
int
consumed
;
...
...
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