cocoaTouch/SDLOverrides/SDL_uikitwindow.m
author nemo
Sun, 24 Jan 2010 16:35:47 +0000
changeset 2710 94e2aed1fd48
parent 2688 174c94b8ea72
child 2714 c85ffe57d971
permissions -rw-r--r--
Some value for opacity. Did not adjust water colour.
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) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    42
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    43
    SDL_WindowData *data;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    44
		
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    45
    /* Allocate the window data */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    46
    data = (SDL_WindowData *)SDL_malloc(sizeof(*data));
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    47
    if (!data) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    48
        SDL_OutOfMemory();
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    49
        return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    50
    }
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    51
    data->windowID = window->id;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    52
    data->uiwindow = uiwindow;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    53
	data->view = nil;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    54
		
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    55
    /* Fill in the SDL window with the window data */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    56
	{
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    57
        window->x = 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    58
        window->y = 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    59
        window->w = (int)uiwindow.frame.size.width;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    60
        window->h = (int)uiwindow.frame.size.height;
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
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    63
	window->driverdata = data;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    64
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    65
	window->flags &= ~SDL_WINDOW_RESIZABLE;		/* window is NEVER resizeable */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    66
	window->flags |= SDL_WINDOW_OPENGL;			/* window is always OpenGL */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    67
	window->flags |= SDL_WINDOW_FULLSCREEN;		/* window is always fullscreen */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    68
	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
    69
	window->flags |= SDL_WINDOW_INPUT_FOCUS;	/* always has input focus */	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    70
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    71
	/* SDL_WINDOW_BORDERLESS controls whether status bar is hidden */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    72
	if (window->flags & SDL_WINDOW_BORDERLESS) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    73
		[UIApplication sharedApplication].statusBarHidden = YES;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    74
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    75
	else {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    76
		[UIApplication sharedApplication].statusBarHidden = NO;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    77
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    78
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    79
    return 0;
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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    83
int UIKit_CreateWindow(_THIS, SDL_Window *window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    84
	/* We currently only handle single window applications on iPhone 
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    85
	if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    86
		SDL_SetError("Window already exists, no multi-window support.");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    87
		return -1;
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
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    90
	// ignore the size user requested, and make a fullscreen window 
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    91
	UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];*/
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    92
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    93
	// since we handle the window with a NIB, we don't need the initialization above
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    94
	if (SetupWindowData(_this, window, [SDLUIKitDelegate sharedAppDelegate].window, SDL_TRUE) < 0) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    95
		SDL_SetError("SetupWindowData() failed");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    96
        return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    97
    }	
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.
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   101
	[SDLUIKitDelegate sharedAppDelegate].windowID = window->id;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   102
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   103
/*	[SDLUIKitDelegate sharedAppDelegate].window = uiwindow;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   104
	[uiwindow release]; /* release the window (the app delegate has retained it) */
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 */
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   119
	//[SDLUIKitDelegate sharedAppDelegate].window = nil;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   120
	[SDLUIKitDelegate sharedAppDelegate].windowID = 0;
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: */