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) {
|
|
42 |
|
|
43 |
SDL_WindowData *data;
|
|
44 |
|
|
45 |
/* Allocate the window data */
|
|
46 |
data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
|
|
47 |
if (!data) {
|
|
48 |
SDL_OutOfMemory();
|
|
49 |
return -1;
|
|
50 |
}
|
|
51 |
data->windowID = window->id;
|
|
52 |
data->uiwindow = uiwindow;
|
|
53 |
data->view = nil;
|
|
54 |
|
|
55 |
/* Fill in the SDL window with the window data */
|
|
56 |
{
|
|
57 |
window->x = 0;
|
|
58 |
window->y = 0;
|
|
59 |
window->w = (int)uiwindow.frame.size.width;
|
|
60 |
window->h = (int)uiwindow.frame.size.height;
|
|
61 |
}
|
|
62 |
|
|
63 |
window->driverdata = data;
|
|
64 |
|
|
65 |
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
|
|
66 |
window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */
|
|
67 |
window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
|
|
68 |
window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */
|
|
69 |
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
|
|
70 |
|
|
71 |
/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
|
|
72 |
if (window->flags & SDL_WINDOW_BORDERLESS) {
|
|
73 |
[UIApplication sharedApplication].statusBarHidden = YES;
|
|
74 |
}
|
|
75 |
else {
|
|
76 |
[UIApplication sharedApplication].statusBarHidden = NO;
|
|
77 |
}
|
|
78 |
|
|
79 |
return 0;
|
|
80 |
|
|
81 |
}
|
|
82 |
|
|
83 |
int UIKit_CreateWindow(_THIS, SDL_Window *window) {
|
|
84 |
/* We currently only handle single window applications on iPhone
|
|
85 |
if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
|
|
86 |
SDL_SetError("Window already exists, no multi-window support.");
|
|
87 |
return -1;
|
|
88 |
}
|
|
89 |
|
|
90 |
// ignore the size user requested, and make a fullscreen window
|
|
91 |
UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];*/
|
|
92 |
|
|
93 |
// since we handle the window with a NIB, we don't need the initialization above
|
|
94 |
if (SetupWindowData(_this, window, [SDLUIKitDelegate sharedAppDelegate].window, SDL_TRUE) < 0) {
|
|
95 |
SDL_SetError("SetupWindowData() failed");
|
|
96 |
return -1;
|
|
97 |
}
|
|
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.
|
|
101 |
[SDLUIKitDelegate sharedAppDelegate].windowID = window->id;
|
|
102 |
|
|
103 |
/* [SDLUIKitDelegate sharedAppDelegate].window = uiwindow;
|
|
104 |
[uiwindow release]; /* release the window (the app delegate has retained it) */
|
|
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 */
|
|
119 |
//[SDLUIKitDelegate sharedAppDelegate].window = nil;
|
|
120 |
[SDLUIKitDelegate sharedAppDelegate].windowID = 0;
|
|
121 |
|
|
122 |
}
|
|
123 |
|
|
124 |
/* vi: set ts=4 sw=4 expandtab: */
|