cocoaTouch/SDLOverrides/SDL_uikitwindow.m
author smxx
Wed, 31 Mar 2010 17:52:55 +0000
changeset 3213 e48678c8cd28
parent 3027 32890edaa483
permissions -rw-r--r--
General: * Updated changelog for 0.9.13 (might require some sorting)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     1
/*
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     2
 SDL - Simple DirectMedia Layer
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     3
 Copyright (C) 1997-2009 Sam Lantinga
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     4
 
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     5
 This library is free software; you can redistribute it and/or
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     6
 modify it under the terms of the GNU Lesser General Public
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     7
 License as published by the Free Software Foundation; either
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     8
 version 2.1 of the License, or (at your option) any later version.
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
     9
 
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    10
 This library is distributed in the hope that it will be useful,
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    13
 Lesser General Public License for more details.
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    14
 
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    15
 You should have received a copy of the GNU Lesser General Public
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    16
 License along with this library; if not, write to the Free Software
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    17
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    18
 
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    19
 Sam Lantinga, mods for Hedgewars by Vittorio Giovara
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    20
 slouken@libsdl.org, vittorio.giovara@gmail.com
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    21
 */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    22
#include "SDL_config.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    23
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    24
#include "SDL_video.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    25
#include "SDL_mouse.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    26
#include "../SDL_sysvideo.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    27
#include "../SDL_pixels_c.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    28
#include "../../events/SDL_events_c.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    29
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    30
#include "SDL_uikitvideo.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    31
#include "SDL_uikitevents.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    32
#include "SDL_uikitwindow.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    33
#import "SDL_uikitappdelegate.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    34
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    35
#import "SDL_uikitopenglview.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    36
#import "SDL_renderer_sw.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    37
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    38
#include <UIKit/UIKit.h>
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    39
#include <Foundation/Foundation.h>
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    40
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    61
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    62
	window->driverdata = data;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    63
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    64
	window->flags &= ~SDL_WINDOW_RESIZABLE;		/* window is NEVER resizeable */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    65
	window->flags |= SDL_WINDOW_OPENGL;			/* window is always OpenGL */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    66
	window->flags |= SDL_WINDOW_FULLSCREEN;		/* window is always fullscreen */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    67
	window->flags |= SDL_WINDOW_SHOWN;			/* only one window on iPod touch, always shown */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    70
	/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    71
	if (window->flags & SDL_WINDOW_BORDERLESS) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    72
		[UIApplication sharedApplication].statusBarHidden = YES;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    73
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    74
	else {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    75
		[UIApplication sharedApplication].statusBarHidden = NO;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    76
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    79
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    80
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    81
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    82
int UIKit_CreateWindow(_THIS, SDL_Window *window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    83
	/* We currently only handle single window applications on iPhone 
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    84
	if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    85
		SDL_SetError("Window already exists, no multi-window support.");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    86
		return -1;
3027
32890edaa483 lotsa optimizations and redraws for the iFrontend
koda
parents: 2714
diff changeset
    87
	}*/
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    88
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    89
	// ignore the size user requested, and make a fullscreen window 
3027
32890edaa483 lotsa optimizations and redraws for the iFrontend
koda
parents: 2714
diff changeset
    90
	//UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    91
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    98
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    99
	// This saves the main window in the app delegate so event callbacks can do stuff on the window.
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   105
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   106
	return 1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   107
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   108
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   109
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   110
void UIKit_DestroyWindow(_THIS, SDL_Window * window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   111
	/* don't worry, the delegate will automatically release the window */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   112
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   113
	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   114
	if (data) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   115
		SDL_free( window->driverdata );
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   116
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   117
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   121
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   122
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   123
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   124
/* vi: set ts=4 sw=4 expandtab: */