Mercurial > sdl-ios-xcode
comparison src/video/uikit/SDL_uikitwindow.m @ 2765:f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Bring SDL to iPhone and iPod Touch
by Holmes Futrell, mentored by Sam Lantinga
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 04 Oct 2008 06:46:59 +0000 |
parents | |
children | 99210400e8b9 |
comparison
equal
deleted
inserted
replaced
2764:4868c0df2e83 | 2765:f55c87ae336b |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2006 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 | |
20 slouken@libsdl.org | |
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 | |
85 /* iPhone applications are single window only */ | |
86 if (nil != [SDLUIKitDelegate sharedAppDelegate].window) { | |
87 SDL_SetError("Window already exists, no multi-window support."); | |
88 return -1; | |
89 } | |
90 | |
91 /* ignore the size user requested, and make a fullscreen window */ | |
92 UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
93 | |
94 if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) { | |
95 [uiwindow release]; | |
96 return -1; | |
97 } | |
98 | |
99 [SDLUIKitDelegate sharedAppDelegate].window = uiwindow; | |
100 [uiwindow release]; /* release the window (the app delegate has retained it) */ | |
101 | |
102 return 1; | |
103 | |
104 } | |
105 | |
106 void UIKit_DestroyWindow(_THIS, SDL_Window * window) { | |
107 /* don't worry, the delegate will automatically release the window */ | |
108 | |
109 SDL_WindowData *data = (SDL_WindowData *)window->driverdata; | |
110 if (data) { | |
111 SDL_free( window->driverdata ); | |
112 } | |
113 | |
114 /* this will also destroy the window */ | |
115 [SDLUIKitDelegate sharedAppDelegate].window = nil; | |
116 | |
117 } | |
118 | |
119 /* vi: set ts=4 sw=4 expandtab: */ |