[DEV] Ios port

This commit is contained in:
Edouard DUPIN 2014-04-17 01:25:28 +02:00
parent 628d593326
commit 852543d957
9 changed files with 65 additions and 99 deletions

View File

@ -11,6 +11,7 @@
#import <ewol/context/IOs/OpenglView.h> #import <ewol/context/IOs/OpenglView.h>
#import <ewol/context/IOs/AppDelegate.h> #import <ewol/context/IOs/AppDelegate.h>
#include <ewol/context/IOs/Context.h>
@implementation AppDelegate @implementation AppDelegate
@ -24,7 +25,9 @@
glView = [[OpenglView alloc] initWithFrame:window.bounds]; glView = [[OpenglView alloc] initWithFrame:window.bounds];
[window addSubview:glView]; [window addSubview:glView];
[window makeKeyAndVisible]; [window makeKeyAndVisible];
// Create interface of ewol here ....
NSLog(@"CREATE EWOL interface creation\n");
IOs::createInterface();
glView.animationInterval = 1.0 / 60.0; glView.animationInterval = 1.0 / 60.0;
[glView startAnimation]; [glView startAnimation];
} }
@ -63,6 +66,9 @@
- (void)applicationWillTerminate:(UIApplication *)application - (void)applicationWillTerminate:(UIApplication *)application
{ {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Create interface of ewol here ....
NSLog(@"REMOVE EWOL interface destruction\n");
IOs::releaseInterface();
} }
/* /*
- (void)dealloc { - (void)dealloc {

View File

@ -18,8 +18,8 @@
#include <ewol/resource/Manager.h> #include <ewol/resource/Manager.h>
#include <ewol/context/Context.h> #include <ewol/context/Context.h>
#include <ewol/context/MacOs/Interface.h> #include <ewol/context/IOs/Interface.h>
#include <ewol/context/MacOs/Context.h> #include <ewol/context/IOs/Context.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -55,11 +55,11 @@ private:
public: public:
MacOSInterface(int32_t _argc, const char* _argv[]) : MacOSInterface(int32_t _argc, const char* _argv[]) :
ewol::Context(_argc, _argv) { ewol::Context(_argc, _argv) {
//mm_main(_argc, _argv); // nothing to do ...
} }
int32_t Run(void) { int32_t Run(void) {
return mm_run();
return 0; return 0;
} }
public: public:
@ -120,14 +120,14 @@ MacOSInterface* interface = NULL;
bool MacOs::draw(bool _displayEveryTime) { bool IOs::draw(bool _displayEveryTime) {
if (interface == NULL) { if (interface == NULL) {
return false; return false;
} }
return interface->MAC_Draw(_displayEveryTime); return interface->MAC_Draw(_displayEveryTime);
} }
void MacOs::resize(float _x, float _y) { void IOs::resize(float _x, float _y) {
if (interface == NULL) { if (interface == NULL) {
return; return;
} }
@ -135,55 +135,65 @@ void MacOs::resize(float _x, float _y) {
} }
void MacOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) { void IOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) {
if (interface == NULL) { if (interface == NULL) {
return; return;
} }
interface->MAC_SetMouseState(_id, _isDown, _x, _y); interface->MAC_SetMouseState(_id, _isDown, _x, _y);
} }
void MacOs::setMouseMotion(int32_t _id, float _x, float _y) { void IOs::setMouseMotion(int32_t _id, float _x, float _y) {
if (interface == NULL) { if (interface == NULL) {
return; return;
} }
interface->MAC_SetMouseMotion(_id, _x, _y); interface->MAC_SetMouseMotion(_id, _x, _y);
} }
void MacOs::setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) { void IOs::setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) {
if (interface == NULL) { if (interface == NULL) {
return; return;
} }
interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey); interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey);
} }
void MacOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown) { void IOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown) {
if (interface == NULL) { if (interface == NULL) {
return; return;
} }
interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown); interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown);
} }
static int l_argc = 0;
static const char **l_argv = NULL;
/** /**
* @brief Main of the program * @brief Main of the program
* @param std IO * @param std IO
* @return std IO * @return std IO
*/ */
int ewol::run(int _argc, const char *_argv[]) { int ewol::run(int _argc, const char *_argv[]) {
etk::setArgZero(_argv[0]); l_argc = _argc;
/* l_argv = _argv;
interface = new MacOSInterface(_argc, _argv); return mm_main(_argc, _argv);
}
// Creat and relaese ewol::Context interface:
void IOs::createInterface(void) {
etk::setArgZero(l_argv[0]);
EWOL_INFO("Create new interface");
interface = new MacOSInterface(l_argc, l_argv);
if (NULL == interface) { if (NULL == interface) {
EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error"); EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
return -2; return;
} }
}
int32_t retValue = interface->Run();
void IOs::releaseInterface(void) {
if (interface == NULL) {
return;
}
EWOL_INFO("Remove interface");
delete(interface); delete(interface);
*/
int32_t retValue = mm_main(_argc, _argv);
interface = NULL; interface = NULL;
return retValue;
} }
@ -191,4 +201,3 @@ int ewol::run(int _argc, const char *_argv[]) {

View File

@ -11,7 +11,10 @@
#include <ewol/key/key.h> #include <ewol/key/key.h>
namespace MacOs { namespace IOs {
// Create and relaese ewol::Context interface:
void createInterface(void);
void releaseInterface(void);
// return true if a flush is needed // return true if a flush is needed
bool draw(bool _displayEveryTime); bool draw(bool _displayEveryTime);
/** /**
@ -25,4 +28,5 @@ namespace MacOs {
void setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown); void setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown);
}; };
#endif #endif

View File

@ -14,7 +14,6 @@ extern "C" {
#endif #endif
int mm_main(int argc, const char *argv[]); int mm_main(int argc, const char *argv[]);
int mm_run(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -18,9 +18,3 @@ int mm_main(int argc, const char *argv[]) {
} // return no error } // return no error
return 0; return 0;
} }
int mm_run(void) {
//[NSApp run];
// return no error
return 0;
}

View File

@ -43,6 +43,5 @@
- (void)stopAnimation; - (void)stopAnimation;
- (void)drawView; - (void)drawView;
- (void)setupView;
@end @end

View File

@ -7,6 +7,7 @@
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h> #import <OpenGLES/EAGLDrawable.h>
#include <ewol/context/IOs/Context.h>
#import "OpenglView.h" #import "OpenglView.h"
@ -55,78 +56,26 @@
} }
animationInterval = 1.0 / 60.0; animationInterval = 1.0 / 60.0;
[self setupView]; //self.bounds
float width = [self frame].size.width;
float height = [self frame].size.height;
IOs::resize(width,height);
} }
return self; 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 { - (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 //setting up the draw content
[EAGLContext setCurrentContext:context]; [EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
//Draw stuff // Open GL draw : ...
IOs::draw(true);
//clear the back color back to our original color and depth buffer glFlush();
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); glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
//show the render buffer //show the render buffer
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; [context presentRenderbuffer:GL_RENDERBUFFER_OES];
} }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

View File

@ -11,8 +11,7 @@
#include <ewol/key/key.h> #include <ewol/key/key.h>
namespace MacOs { IOs // return true if a flush is needed
// return true if a flush is needed
bool draw(bool _displayEveryTime); bool draw(bool _displayEveryTime);
/** /**
* @brief The OS inform that the current windows has change his size. * @brief The OS inform that the current windows has change his size.

View File

@ -63,11 +63,10 @@ def create(target):
'ewol/context/MacOs/AppDelegate.mm']) 'ewol/context/MacOs/AppDelegate.mm'])
elif target.name=="IOs": elif target.name=="IOs":
myModule.add_src_file([ myModule.add_src_file([
'ewol/context/MacOs/Context.cpp', 'ewol/context/IOs/Context.cpp',
'ewol/context/MacOs/Interface.mm', 'ewol/context/IOs/Interface.m',
'ewol/context/MacOs/Windows.mm', 'ewol/context/IOs/OpenglView.mm',
'ewol/context/MacOs/OpenglView.mm', 'ewol/context/IOs/AppDelegate.mm'])
'ewol/context/MacOs/AppDelegate.mm'])
else: else:
debug.error("unknow mode...") debug.error("unknow mode...")
@ -223,7 +222,15 @@ def create(target):
"-framework OpenGL", "-framework OpenGL",
"-framework QuartzCore", "-framework QuartzCore",
"-framework AppKit"]) "-framework AppKit"])
elif target.name=="IOs":
myModule.add_export_flag_LD([
"-framework OpenGLES",
"-framework CoreGraphics",
"-framework UIKit",
"-framework GLKit",
"-framework Foundation",
"-framework QuartzCore"])
# add the currrent module at the # add the currrent module at the
return myModule return myModule