[DEV] integration IOS first step

This commit is contained in:
Edouard DUPIN 2014-04-13 13:47:50 +02:00
parent 8589d9b747
commit 628d593326
12 changed files with 648 additions and 5 deletions

View File

@ -7,6 +7,14 @@
*/
#include <date/date.h>
#ifdef __TARGET_OS__IOs
#define BUILD_YEAR 1070
#define BUILD_MONTH 1
#define BUILD_DAY 1
#define BUILD_HOUR 0
#define BUILD_MINUTE 0
#define BUILD_SECOND 0
#endif
int32_t date::getYear(void) {
return BUILD_YEAR;

View File

@ -0,0 +1,20 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#import <UIKit/UIKit.h>
@class OpenglView;
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
OpenglView *glView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet OpenglView *glView;
@end

View File

@ -0,0 +1,75 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#import <UIKit/UIKit.h>
#include "ewol/context/IOs/Interface.h"
#import <ewol/context/IOs/OpenglView.h>
#import <ewol/context/IOs/AppDelegate.h>
@implementation AppDelegate
@synthesize window;
@synthesize glView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//No need for nib
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
glView = [[OpenglView alloc] initWithFrame:window.bounds];
[window addSubview:glView];
[window makeKeyAndVisible];
glView.animationInterval = 1.0 / 60.0;
[glView startAnimation];
}
/*
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
*/
- (void)applicationWillResignActive:(UIApplication *)application
{
glView.animationInterval = 1.0 / 5.0;
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
glView.animationInterval = 1.0 / 60.0;
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
/*
- (void)dealloc {
[window release];
[glView release];
[super dealloc];
}
*/
@end

View File

@ -1,8 +1,194 @@
/**
* @author Edouard DUPIN
*
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
*
* @license BSD v3 (see license file)
*/
#include <ewol/debug.h>
#include <ewol/ewol.h>
#include <ewol/key/key.h>
#include <ewol/context/commandLine.h>
#include <etk/types.h>
#include <etk/os/FSNode.h>
#include <ewol/widget/Manager.h>
#include <ewol/resource/Manager.h>
#include <ewol/context/Context.h>
#include <ewol/context/MacOs/Interface.h>
#include <ewol/context/MacOs/Context.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/times.h>
#include <mach/clock.h>
#include <mach/mach.h>
int64_t ewol::getTime(void) {
struct timespec now;
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
now.tv_sec = mts.tv_sec;
now.tv_nsec = mts.tv_nsec;
//EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us");
return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_nsec/(int64_t)1000);
}
#undef __class__
#define __class__ "MacOSInterface"
class MacOSInterface : public ewol::Context {
private:
ewol::key::Special m_guiKeyBoardMode;
public:
MacOSInterface(int32_t _argc, const char* _argv[]) :
ewol::Context(_argc, _argv) {
//mm_main(_argc, _argv);
}
int32_t Run(void) {
return mm_run();
return 0;
}
public:
//interface MacOS :
bool MAC_Draw(bool _displayEveryTime) {
return OS_Draw(_displayEveryTime);
}
void MAC_Resize(float _x, float _y) {
OS_Resize(vec2(_x,_y));
}
void MAC_SetMouseState(int32_t _id, bool _isDown, float _x, float _y) {
OS_SetMouseState(_id, _isDown, vec2(_x, _y));
}
void MAC_SetMouseMotion(int32_t _id, float _x, float _y) {
OS_SetMouseMotion(_id, vec2(_x, _y));
}
void MAC_SetKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) {
if (_unichar == u32char::Delete) {
_unichar = u32char::Suppress;
} else if (_unichar == u32char::Suppress) {
_unichar = u32char::Delete;
}
if (_unichar == u32char::CarrierReturn) {
_unichar = u32char::Return;
}
//EWOL_DEBUG("key: " << _unichar << " up=" << !_isDown);
if (_unichar <= 4) {
enum ewol::key::keyboard move;
switch(_unichar) {
case 0:
move = ewol::key::keyboardUp;
break;
case 1:
move = ewol::key::keyboardDown;
break;
case 2:
move = ewol::key::keyboardLeft;
break;
case 3:
move = ewol::key::keyboardRight;
break;
}
OS_SetKeyboardMove(_keyboardMode, move, !_isDown, _isAReapeateKey);
} else {
OS_SetKeyboard(_keyboardMode, _unichar, !_isDown, _isAReapeateKey);
}
}
void MAC_SetKeyboardMove(ewol::key::Special& _special,
enum ewol::key::keyboard _move,
bool _isDown) {
OS_SetKeyboardMove(_special, _move, _isDown);
}
};
MacOSInterface* interface = NULL;
bool MacOs::draw(bool _displayEveryTime) {
if (interface == NULL) {
return false;
}
return interface->MAC_Draw(_displayEveryTime);
}
void MacOs::resize(float _x, float _y) {
if (interface == NULL) {
return;
}
interface->MAC_Resize(_x, _y);
}
void MacOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) {
if (interface == NULL) {
return;
}
interface->MAC_SetMouseState(_id, _isDown, _x, _y);
}
void MacOs::setMouseMotion(int32_t _id, float _x, float _y) {
if (interface == NULL) {
return;
}
interface->MAC_SetMouseMotion(_id, _x, _y);
}
void MacOs::setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) {
if (interface == NULL) {
return;
}
interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey);
}
void MacOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown) {
if (interface == NULL) {
return;
}
interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown);
}
/**
* @brief Main of the program
* @param std IO
* @return std IO
*/
int ewol::run(int _argc, const char *_argv[]) {
etk::setArgZero(_argv[0]);
/*
interface = new MacOSInterface(_argc, _argv);
if (NULL == interface) {
EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
return -2;
}
int32_t retValue = interface->Run();
delete(interface);
*/
int32_t retValue = mm_main(_argc, _argv);
interface = NULL;
return retValue;
}

View File

@ -0,0 +1,28 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __MAC_OS_CONTEXT_H__
#define __MAC_OS_CONTEXT_H__
#include <ewol/key/key.h>
namespace MacOs {
// return true if a flush is needed
bool draw(bool _displayEveryTime);
/**
* @brief The OS inform that the current windows has change his size.
* @param[in] _size new size of the windows.
*/
void resize(float _x, float _y);
void setMouseState(int32_t _id, bool _isDown, float _x, float _y);
void setMouseMotion(int32_t _id, float _x, float _y);
void setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey);
void setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown);
};
#endif

View File

@ -0,0 +1,23 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_MM_INTERFACE_H__
#define __EWOL_MM_INTERFACE_H__
#ifdef __cplusplus
extern "C" {
#endif
int mm_main(int argc, const char *argv[]);
int mm_run(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,26 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#import <UIKit/UIKit.h>
#import <ewol/context/IOs/AppDelegate.h>
//#import "AppDelegate.h"
int mm_main(int argc, const char *argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, (char**)argv, nil, NSStringFromClass([AppDelegate class]));
} // return no error
return 0;
}
int mm_run(void) {
//[NSApp run];
// return no error
return 0;
}

View File

@ -0,0 +1,48 @@
//
// EAGLView.h
// OpenGLBasics
//
// Created by Charlie Key on 6/24/09.
//
#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
/*
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
The view content is basically an EAGL surface you render your OpenGL scene into.
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/
@interface OpenglView : UIView {
@private
/* The pixel dimensions of the backbuffer */
GLint backingWidth;
GLint backingHeight;
EAGLContext *context;
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
GLuint viewRenderbuffer, viewFramebuffer;
/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
GLuint depthRenderbuffer;
//NSTimer *animationTimer;
NSTimeInterval animationInterval;
CGPoint touchLocation;
}
@property NSTimeInterval animationInterval;
- (void)startAnimation;
- (void)stopAnimation;
- (void)drawView;
- (void)setupView;
@end

View File

@ -0,0 +1,227 @@
//
// EAGLView.m
// OpenGLBasics
//
// Created by Charlie Key on 6/24/09.
//
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import "OpenglView.h"
#define USE_DEPTH_BUFFER 1
#define DEGREES_TO_RADIANS(__ANGLE) ((__ANGLE) / 180.0 * M_PI)
// A class extension to declare private methods
@interface OpenglView ()
@property (nonatomic, retain) EAGLContext *context;
@property (nonatomic, assign) NSTimer *animationTimer;
- (BOOL) createFramebuffer;
- (void) destroyFramebuffer;
@end
@implementation OpenglView
@synthesize context;
@synthesize animationTimer;
@synthesize animationInterval;
// You must implement this method
+ (Class)layerClass {
return [CAEAGLLayer class];
}
//Created GlView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context]) {
//[self release];
return nil;
}
animationInterval = 1.0 / 60.0;
[self setupView];
}
return self;
}
- (void)setupView {
const GLfloat zNear = 0.1, zFar = 1000.0, fieldOfView = 60.0;
GLfloat size;
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
//Grab the size of the screen
CGRect rect = self.bounds;
glFrustumf(-size, size,
-size / (rect.size.width / rect.size.height),
size / (rect.size.width / rect.size.height),
zNear, zFar);
glViewport(0, 0, rect.size.width, rect.size.height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//Initialize touchLocation to 0, 0
touchLocation = CGPointMake(160, 240);
}
- (void)drawView {
const GLfloat triangleVertices[] = {
0.0, 1.0, -6.0, // top center
-1.0, -1.0, -6.0, // bottom left
1.0, -1.0, -6.0 // bottom right
};
const GLfloat triangleColors[] = {
1.0, 0.0, 0.0, 1.0, // red
0.0, 1.0, 0.0, 1.0, // green
0.0, 0.0, 1.0, 1.0, // blue
};
//setting up the draw content
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
//Draw stuff
//clear the back color back to our original color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//reset matrix to identity
glLoadIdentity();
//rough approximation of screen to current 3D space
GLfloat x = (touchLocation.x - 160.0) / 38.0;
GLfloat y = (240.0 - touchLocation.y) / 38.0;
//translate the triangle
glTranslatef(x, y, -1.0);
//set the format and location for verticies
glVertexPointer(3, GL_FLOAT, 0, triangleVertices);
//set the opengl state
glEnableClientState(GL_VERTEX_ARRAY);
//set the format and location for colors
glColorPointer(4, GL_FLOAT, 0, triangleColors);
//set the opengl state
glEnableClientState(GL_COLOR_ARRAY);
//draw the triangles
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
//show the render buffer
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
touchLocation = [touch locationInView:self];
}
- (void)layoutSubviews {
[EAGLContext setCurrentContext:context];
[self destroyFramebuffer];
[self createFramebuffer];
[self drawView];
}
- (BOOL)createFramebuffer {
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
if (USE_DEPTH_BUFFER) {
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
}
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
return YES;
}
- (void)destroyFramebuffer {
glDeleteFramebuffersOES(1, &viewFramebuffer);
viewFramebuffer = 0;
glDeleteRenderbuffersOES(1, &viewRenderbuffer);
viewRenderbuffer = 0;
if(depthRenderbuffer) {
glDeleteRenderbuffersOES(1, &depthRenderbuffer);
depthRenderbuffer = 0;
}
}
- (void)startAnimation {
self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
}
- (void)stopAnimation {
self.animationTimer = nil;
}
- (void)setAnimationTimer:(NSTimer *)newTimer {
[animationTimer invalidate];
animationTimer = newTimer;
}
- (void)setAnimationInterval:(NSTimeInterval)interval {
animationInterval = interval;
if (animationTimer) {
[self stopAnimation];
[self startAnimation];
}
}
- (void)dealloc {
[self stopAnimation];
if ([EAGLContext currentContext] == context) {
[EAGLContext setCurrentContext:nil];
}
//[context release];
//[super dealloc];
}
@end

View File

@ -17,7 +17,9 @@
#undef __class__
#define __class__ "ewol"
#ifndef EWOL_VERSION
#define EWOL_VERSION "0.0.0"
#endif
std::string ewol::getCompilationMode(void) {
#ifdef MODE_RELEASE

View File

@ -44,7 +44,7 @@ extern "C" {
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#elif defined(__TARGET_OS__IOs)
#include <OpenGLES/ES2/gl.h>
#else
#error you need to specify a __TAGET_OS__ ...
#endif

View File

@ -96,7 +96,7 @@ void ewol::widget::Windows::sysDraw(void) {
ewol::openGL::disable(ewol::openGL::FLAG_STENCIL_TEST);
ewol::openGL::disable(ewol::openGL::FLAG_ALPHA_TEST);
ewol::openGL::disable(ewol::openGL::FLAG_FOG);
#ifndef __TARGET_OS__Android
#if (!defined(__TARGET_OS__Android) && !defined(__TARGET_OS__IOs))
glPixelZoom(1.0,1.0);
#endif
ewol::openGL::disable(ewol::openGL::FLAG_TEXTURE_2D);