author | koda |
Sun, 24 Jan 2010 19:52:30 +0000 | |
changeset 2714 | c85ffe57d971 |
parent 2688 | 174c94b8ea72 |
child 3027 | 32890edaa483 |
permissions | -rw-r--r-- |
2688 | 1 |
/* |
2 |
SDL - Simple DirectMedia Layer |
|
3 |
Copyright (C) 1997-2009 Sam Lantinga |
|
4 |
||
5 |
This library is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU Lesser General Public |
|
7 |
License as published by the Free Software Foundation; either |
|
8 |
version 2.1 of the License, or (at your option) any later version. |
|
9 |
||
10 |
This library is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
Lesser General Public License for more details. |
|
14 |
||
15 |
You should have received a copy of the GNU Lesser General Public |
|
16 |
License along with this library; if not, write to the Free Software |
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
||
19 |
Sam Lantinga, mods for Hedgewars by Vittorio Giovara |
|
20 |
slouken@libsdl.org, vittorio.giovara@gmail.com |
|
21 |
*/ |
|
22 |
#include "SDL_config.h" |
|
23 |
||
24 |
#include "SDL_video.h" |
|
25 |
#include "SDL_mouse.h" |
|
26 |
#include "../SDL_sysvideo.h" |
|
27 |
#include "../SDL_pixels_c.h" |
|
28 |
#include "../../events/SDL_events_c.h" |
|
29 |
||
30 |
#include "SDL_uikitvideo.h" |
|
31 |
#include "SDL_uikitevents.h" |
|
32 |
#include "SDL_uikitwindow.h" |
|
33 |
#import "SDL_uikitappdelegate.h" |
|
34 |
||
35 |
#import "SDL_uikitopenglview.h" |
|
36 |
#import "SDL_renderer_sw.h" |
|
37 |
||
38 |
#include <UIKit/UIKit.h> |
|
39 |
#include <Foundation/Foundation.h> |
|
40 |
||
41 |
static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) { |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
42 |
SDL_WindowData *data; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
43 |
|
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
44 |
/* Allocate the window data */ |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
45 |
data = (SDL_WindowData *)SDL_malloc(sizeof(*data)); |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
46 |
if (!data) { |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
47 |
SDL_OutOfMemory(); |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
48 |
return -1; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
49 |
} |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
50 |
data->window = window; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
51 |
data->uiwindow = uiwindow; |
2688 | 52 |
data->view = nil; |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
53 |
|
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
54 |
/* Fill in the SDL window with the window data */ |
2688 | 55 |
{ |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
56 |
window->x = 0; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
57 |
window->y = 0; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
58 |
window->w = (int)uiwindow.frame.size.width; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
59 |
window->h = (int)uiwindow.frame.size.height; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
60 |
} |
2688 | 61 |
|
62 |
window->driverdata = data; |
|
63 |
||
64 |
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */ |
|
65 |
window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */ |
|
66 |
window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */ |
|
67 |
window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */ |
|
68 |
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */ |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
69 |
|
2688 | 70 |
/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */ |
71 |
if (window->flags & SDL_WINDOW_BORDERLESS) { |
|
72 |
[UIApplication sharedApplication].statusBarHidden = YES; |
|
73 |
} |
|
74 |
else { |
|
75 |
[UIApplication sharedApplication].statusBarHidden = NO; |
|
76 |
} |
|
77 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
78 |
return 0; |
2688 | 79 |
|
80 |
} |
|
81 |
||
82 |
int UIKit_CreateWindow(_THIS, SDL_Window *window) { |
|
83 |
/* We currently only handle single window applications on iPhone |
|
84 |
if (nil != [SDLUIKitDelegate sharedAppDelegate].window) { |
|
85 |
SDL_SetError("Window already exists, no multi-window support."); |
|
86 |
return -1; |
|
87 |
} |
|
88 |
||
89 |
// ignore the size user requested, and make a fullscreen window |
|
90 |
UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];*/ |
|
91 |
||
92 |
// since we handle the window with a NIB, we don't need the initialization above |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
93 |
if (SetupWindowData(_this, window, [SDLUIKitDelegate sharedAppDelegate].uiwindow, SDL_TRUE) < 0) { |
2688 | 94 |
SDL_SetError("SetupWindowData() failed"); |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
95 |
//[uiwindow release]; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
96 |
return -1; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
97 |
} |
2688 | 98 |
|
99 |
// This saves the main window in the app delegate so event callbacks can do stuff on the window. |
|
100 |
// This assumes a single window application design and needs to be fixed for multiple windows. |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
101 |
[SDLUIKitDelegate sharedAppDelegate].window = window; |
2688 | 102 |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
103 |
//[SDLUIKitDelegate sharedAppDelegate].uiwindow = uiwindow; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
104 |
//[uiwindow release]; /* release the window (the app delegate has retained it) */ |
2688 | 105 |
|
106 |
return 1; |
|
107 |
||
108 |
} |
|
109 |
||
110 |
void UIKit_DestroyWindow(_THIS, SDL_Window * window) { |
|
111 |
/* don't worry, the delegate will automatically release the window */ |
|
112 |
||
113 |
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; |
|
114 |
if (data) { |
|
115 |
SDL_free( window->driverdata ); |
|
116 |
} |
|
117 |
||
118 |
/* this will also destroy the window */ |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
119 |
[SDLUIKitDelegate sharedAppDelegate].window = NULL; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2688
diff
changeset
|
120 |
//[SDLUIKitDelegate sharedAppDelegate].uiwindow = nil; |
2688 | 121 |
|
122 |
} |
|
123 |
||
124 |
/* vi: set ts=4 sw=4 expandtab: */ |