From ca352c94d91c19d4bd4c3754a34b08b7470f316d Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 4 Apr 2013 00:43:03 +0200 Subject: [PATCH] [DEV] start dev on MACOS interface --- sources/MacOs.mk | 21 +- sources/ewol/renderer/openGL.h | 8 +- .../ewol/renderer/os/gui.MacOs.AppDelegate.h | 10 + .../ewol/renderer/os/gui.MacOs.AppDelegate.mm | 65 +++++++ .../ewol/renderer/os/gui.MacOs.Interface.h | 9 + .../ewol/renderer/os/gui.MacOs.Interface.mm | 14 ++ .../ewol/renderer/os/gui.MacOs.OpenglView.h | 16 ++ .../ewol/renderer/os/gui.MacOs.OpenglView.mm | 67 +++++++ sources/ewol/renderer/os/gui.MacOs.cpp | 184 ++++++++++++++++++ 9 files changed, 374 insertions(+), 20 deletions(-) create mode 100644 sources/ewol/renderer/os/gui.MacOs.AppDelegate.h create mode 100644 sources/ewol/renderer/os/gui.MacOs.AppDelegate.mm create mode 100644 sources/ewol/renderer/os/gui.MacOs.Interface.h create mode 100644 sources/ewol/renderer/os/gui.MacOs.Interface.mm create mode 100644 sources/ewol/renderer/os/gui.MacOs.OpenglView.h create mode 100644 sources/ewol/renderer/os/gui.MacOs.OpenglView.mm diff --git a/sources/MacOs.mk b/sources/MacOs.mk index 149b483e..914f373d 100644 --- a/sources/MacOs.mk +++ b/sources/MacOs.mk @@ -29,16 +29,8 @@ endif LOCAL_C_INCLUDES := LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) -LOCAL_EXPORT_LDLIBS := -lGL +LOCAL_EXPORT_LDLIBS := -framework OpenGL -#`pkg-config --cflags directfb` `pkg-config --libs directfb` - -ifeq ("$(CONFIG___EWOL_LINUX_GUI_MODE_X11__)","y") -LOCAL_EXPORT_LDLIBS += -lX11 -endif -ifeq ("$(CONFIG___EWOL_LINUX_GUI_MODE_DIRECT_FB__)","y") -LOCAL_EXPORT_LDLIBS += -L/usr/local/lib -ldirectfb -lfusion -ldirect -endif #http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Introduction # needed package on linux : libgl1-mesa-dev libglew1.5-dev @@ -55,13 +47,10 @@ include $(LOCAL_PATH)/file.mk LOCAL_SRC_FILES := $(FILE_LIST) -ifeq ("$(CONFIG___EWOL_LINUX_GUI_MODE_X11__)","y") -LOCAL_SRC_FILES += ewol/renderer/os/gui.X11.cpp -endif -ifeq ("$(CONFIG___EWOL_LINUX_GUI_MODE_DIRECT_FB__)","y") -LOCAL_CFLAGS += -I/usr/local/include/directfb -LOCAL_SRC_FILES += ewol/renderer/os/gui.directFB.cpp -endif +LOCAL_SRC_FILES += ewol/renderer/os/gui.MacOs.cpp \ + ewol/renderer/os/gui.MacOs.Interface.mm \ + ewol/renderer/os/gui.MacOs.AppDelegate.mm \ + ewol/renderer/os/gui.MacOs.OpenglView.mm include $(BUILD_STATIC_LIBRARY) diff --git a/sources/ewol/renderer/openGL.h b/sources/ewol/renderer/openGL.h index 412d4b99..8c78f987 100644 --- a/sources/ewol/renderer/openGL.h +++ b/sources/ewol/renderer/openGL.h @@ -49,6 +49,10 @@ extern "C" { #error you need to specify a __TAGET_OS__ ... #endif +#ifdef __cplusplus +} +#endif + namespace ewol { namespace openGL { /** @@ -178,9 +182,5 @@ namespace ewol { }; }; -#ifdef __cplusplus -} -#endif - #endif diff --git a/sources/ewol/renderer/os/gui.MacOs.AppDelegate.h b/sources/ewol/renderer/os/gui.MacOs.AppDelegate.h new file mode 100644 index 00000000..3075a740 --- /dev/null +++ b/sources/ewol/renderer/os/gui.MacOs.AppDelegate.h @@ -0,0 +1,10 @@ + +#import + +@interface MacOsAppDelegate : NSObject { + +} + +@property (nonatomic, retain) IBOutlet UIWindow *window; + +@end diff --git a/sources/ewol/renderer/os/gui.MacOs.AppDelegate.mm b/sources/ewol/renderer/os/gui.MacOs.AppDelegate.mm new file mode 100644 index 00000000..0da177fb --- /dev/null +++ b/sources/ewol/renderer/os/gui.MacOs.AppDelegate.mm @@ -0,0 +1,65 @@ + + +#import +#import + +@implementation MacOsAppDelegate + + +@synthesize window=_window; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + OpenglView *view=[[OpenglView alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; + // Override point for customization after application launch. + [self.window addSubview:view]; + [self.window makeKeyAndVisible]; + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + /* + 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 +{ + /* + 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]; + [super dealloc]; +} + +@end diff --git a/sources/ewol/renderer/os/gui.MacOs.Interface.h b/sources/ewol/renderer/os/gui.MacOs.Interface.h new file mode 100644 index 00000000..6ac25311 --- /dev/null +++ b/sources/ewol/renderer/os/gui.MacOs.Interface.h @@ -0,0 +1,9 @@ + +#ifndef __MM_INTERFACE_H__ +#define __MM_INTERFACE_H__ + + +int mm_main(int argc, char *argv[]); + + +#endif diff --git a/sources/ewol/renderer/os/gui.MacOs.Interface.mm b/sources/ewol/renderer/os/gui.MacOs.Interface.mm new file mode 100644 index 00000000..e217aa50 --- /dev/null +++ b/sources/ewol/renderer/os/gui.MacOs.Interface.mm @@ -0,0 +1,14 @@ + + + + +#import + +int mm_main(int argc, char *argv[]) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + int retVal = UIApplicationMain(argc, argv, nil, nil); + [pool release]; + return retVal; +} + diff --git a/sources/ewol/renderer/os/gui.MacOs.OpenglView.h b/sources/ewol/renderer/os/gui.MacOs.OpenglView.h new file mode 100644 index 00000000..e2d82333 --- /dev/null +++ b/sources/ewol/renderer/os/gui.MacOs.OpenglView.h @@ -0,0 +1,16 @@ + + +#import +#import +#import + +@interface OpenglView : UIView { + + EAGLContext *mimContext; + +@private + GLuint framebuffer; + GLuint renderbuffer; +} +- (void)drawView; +@end diff --git a/sources/ewol/renderer/os/gui.MacOs.OpenglView.mm b/sources/ewol/renderer/os/gui.MacOs.OpenglView.mm new file mode 100644 index 00000000..4c556966 --- /dev/null +++ b/sources/ewol/renderer/os/gui.MacOs.OpenglView.mm @@ -0,0 +1,67 @@ + + +#import + + +@implementation OpenglView + ++ (Class) layerClass +{ + return [CAEAGLLayer class]; +} + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code + + CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer; + eaglLayer.opaque = YES; + + mimContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + BOOL setContext=[EAGLContext setCurrentContext:mimContext]; + if (!mimContext || !setContext) + { + [self release]; + return nil; + } + + //Lets init and bind render buffer with current context + glGenRenderbuffers(1, &renderbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); + [mimContext renderbufferStorage:GL_RENDERBUFFER fromDrawable: eaglLayer]; + + //Frame buffer- which is a collection of render buffers and other kind of buffers like depth etc. + glGenFramebuffers(1, &framebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); + + //Setting the dimensions of your view area. + glViewport(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame)); + + [self drawView]; + + + } + return self; +} + + +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawView +{ + // Drawing code + glClearColor(1.0f, 0.0f, 1.0f, 1); + glClear(GL_COLOR_BUFFER_BIT); + [mimContext presentRenderbuffer:GL_RENDERBUFFER]; +} + + +- (void)dealloc +{ + [super dealloc]; +} + +@end diff --git a/sources/ewol/renderer/os/gui.MacOs.cpp b/sources/ewol/renderer/os/gui.MacOs.cpp index 65799fed..640b0dc3 100644 --- a/sources/ewol/renderer/os/gui.MacOs.cpp +++ b/sources/ewol/renderer/os/gui.MacOs.cpp @@ -6,3 +6,187 @@ * @license BSD v3 (see license file) */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + + +#include +#include +#include + +int64_t guiInterface::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__ "guiInterface" + + + +static ewol::SpecialKey guiKeyBoardMode; + + + + + + +/** + * @brief Set the new title of the windows + * @param title New desired title + * @return --- + */ +void guiInterface::SetTitle(etk::UString& title) +{ + EWOL_INFO("X11: Set Title (START)"); + EWOL_INFO("X11: Set Title (END)"); +} + +void guiInterface::SetIcon(etk::UString inputFile) +{ + EWOL_TODO("plop"); +} + + +void RemoveDecoration(void) +{ + EWOL_TODO("X11:RemoveDecoration"); +} + +void AddDecoration(void) +{ + EWOL_TODO("X11:AddDecoration"); +} + + + +// ------------------------------------------------------------------------- +// ClipBoard AREA : +// ------------------------------------------------------------------------- + + +void guiInterface::ClipBoardGet(ewol::clipBoard::clipboardListe_te clipboardID) +{ + +} + + +void guiInterface::ClipBoardSet(ewol::clipBoard::clipboardListe_te clipboardID) +{ + +} + + + +#undef __class__ +#define __class__ "guiInterface" + + +void guiInterface::Stop(void) +{ + EWOL_INFO("X11-API: Stop"); +} + +void guiInterface::KeyboardShow(void) +{ + // nothing to do : No keyboard on computer ... +} + + +void guiInterface::KeyboardHide(void) +{ + // nothing to do : No keyboard on computer ... +} + + +void guiInterface::ChangeSize(ivec2 size) +{ + EWOL_INFO("X11-API: ChangeSize=" << size); +} + + +void guiInterface::ChangePos(ivec2 pos) +{ + EWOL_INFO("X11-API: ChangePos=" << pos); +} + + +void guiInterface::GetAbsPos(ivec2& pos) +{ + EWOL_INFO("X11-API: GetAbsPos"); +} + +// select the current cursor to display : +static ewol::cursorDisplay_te l_currentCursor = ewol::cursorArrow; + +void guiInterface::SetCursor(ewol::cursorDisplay_te newCursor) +{ + if (newCursor != l_currentCursor) { + EWOL_DEBUG("X11-API: Set New Cursor : " << newCursor); + // set the new one : + l_currentCursor = newCursor; + } +} + +void guiInterface::GrabPointerEvents(bool isGrabbed, vec2 forcedPosition) +{ + +} + +#include + +/** + * @brief Main of the program + * @param std IO + * @return std IO + */ +int guiInterface::main(int argc, const char *argv[]) +{ + //start the basic thread : + eSystem::Init(); + // Run ... + int ret = mm_main(argc, argv); + EWOL_INFO("Return main value=" << ret); + // close X11 : + guiInterface::Stop(); + // uninit ALL : + eSystem::UnInit(); + return 0; +} + + +void guiInterface::ForceOrientation(ewol::orientation_te orientation) +{ + // nothing to do ... +} + + + + + +