From 5ca92a90cb6009b5955d3780a1581a6aeb02684a Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 25 Sep 2013 15:25:47 +0200 Subject: [PATCH] [DEV] mac work again but not ended anymore --- external/etk | 2 +- sources/ewol/renderer/MacOs/AppDelegate.mm | 4 +- sources/ewol/renderer/MacOs/Context.cpp | 225 ++++++++++----------- sources/ewol/renderer/MacOs/Context.h | 31 +++ sources/ewol/renderer/MacOs/Interface.h | 1 + sources/ewol/renderer/MacOs/Interface.mm | 77 +------ sources/ewol/renderer/MacOs/OpenglView.mm | 45 +++-- sources/ewol/renderer/X11/Context.cpp | 2 + 8 files changed, 172 insertions(+), 215 deletions(-) create mode 100644 sources/ewol/renderer/MacOs/Context.h diff --git a/external/etk b/external/etk index bb085be5..1826eb6f 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit bb085be53d88d727686a5e23aa7c3e2cb2caf7f5 +Subproject commit 1826eb6fd917c330ecabbfb7333a509044673964 diff --git a/sources/ewol/renderer/MacOs/AppDelegate.mm b/sources/ewol/renderer/MacOs/AppDelegate.mm index 247cf5ee..bab7282e 100644 --- a/sources/ewol/renderer/MacOs/AppDelegate.mm +++ b/sources/ewol/renderer/MacOs/AppDelegate.mm @@ -7,8 +7,8 @@ */ -#import -#import +#import +#import @implementation MacOsAppDelegate diff --git a/sources/ewol/renderer/MacOs/Context.cpp b/sources/ewol/renderer/MacOs/Context.cpp index fedd091f..96d4dce1 100644 --- a/sources/ewol/renderer/MacOs/Context.cpp +++ b/sources/ewol/renderer/MacOs/Context.cpp @@ -10,15 +10,17 @@ #include #include #include -#include #include #include #include +#include #include -#include -#include +#include +#include +#include +#include #include #include #include @@ -30,7 +32,7 @@ #include -int64_t guiInterface::GetTime(void) +int64_t ewol::GetTime(void) { struct timespec now; clock_serv_t cclock; @@ -45,144 +47,120 @@ int64_t guiInterface::GetTime(void) } #undef __class__ -#define __class__ "guiInterface" +#define __class__ "MacOSInterface" -static ewol::SpecialKey guiKeyBoardMode; - - - - - - -/** - * @brief Set the new title of the windows - * @param title New desired title - * @return --- - */ -void guiInterface::SetTitle(etk::UString& title) +class MacOSInterface : public ewol::eContext { - EWOL_INFO("X11: Set Title (START)"); - EWOL_INFO("X11: Set Title (END)"); -} + private: + ewol::SpecialKey m_guiKeyBoardMode; + public: + MacOSInterface(int32_t _argc, const char* _argv[]) : + ewol::eContext(_argc, _argv) + { + mm_main(_argc, _argv); + } + + int32_t Run(void) + { + return mm_run(); + } + 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::SpecialKey _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) + { + if (_unichar == '\r') { + _unichar = '\n'; + } + EWOL_DEBUG("key: " << _unichar << " up=" << !_isDown); + OS_SetKeyboard(_keyboardMode, _unichar, !_isDown, _isAReapeateKey); + } +}; -void guiInterface::SetIcon(etk::UString inputFile) + +MacOSInterface* interface = NULL; + + + +bool MacOs::Draw(bool _displayEveryTime) { - 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; + if (interface == NULL) { + return false; } + return interface->MAC_Draw(_displayEveryTime); } -void guiInterface::GrabPointerEvents(bool isGrabbed, vec2 forcedPosition) +void MacOs::Resize(float _x, float _y) { - + if (interface == NULL) { + return; + } + interface->MAC_Resize(_x, _y); } -#include + +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::SpecialKey _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) +{ + if (interface == NULL) { + return; + } + interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey); +} + + /** * @brief Main of the program * @param std IO * @return std IO */ -int guiInterface::main(int argc, const char *argv[]) +int ewol::Run(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 ... + 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); + interface = NULL; + return retValue; } @@ -190,3 +168,4 @@ void guiInterface::ForceOrientation(ewol::orientation_te orientation) + diff --git a/sources/ewol/renderer/MacOs/Context.h b/sources/ewol/renderer/MacOs/Context.h new file mode 100644 index 00000000..6491f0ef --- /dev/null +++ b/sources/ewol/renderer/MacOs/Context.h @@ -0,0 +1,31 @@ +/** + * @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 + +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::SpecialKey _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey); + +}; + +#endif \ No newline at end of file diff --git a/sources/ewol/renderer/MacOs/Interface.h b/sources/ewol/renderer/MacOs/Interface.h index c1a33d03..ae3bcfa0 100644 --- a/sources/ewol/renderer/MacOs/Interface.h +++ b/sources/ewol/renderer/MacOs/Interface.h @@ -14,6 +14,7 @@ extern "C" { #endif int mm_main(int argc, const char *argv[]); +int mm_run(void); #ifdef __cplusplus } diff --git a/sources/ewol/renderer/MacOs/Interface.mm b/sources/ewol/renderer/MacOs/Interface.mm index 1312062a..82f11942 100644 --- a/sources/ewol/renderer/MacOs/Interface.mm +++ b/sources/ewol/renderer/MacOs/Interface.mm @@ -6,26 +6,11 @@ * @license BSD v3 (see license file) */ - -/* - #import -#import -#include +#include "ewol/renderer/MacOs/Interface.h" -int mm_main(int argc, const char *argv[]) -{ - return NSApplicationMain(argc, (const char **)argv); -} -*/ - - - -#import -#include "ewol/renderer/os/gui.MacOs.Interface.h" - -#import -#import +#import +#import int mm_main(int argc, const char *argv[]) { @@ -92,58 +77,14 @@ int mm_main(int argc, const char *argv[]) //[window makeKeyAndVisible]; [window setDelegate:view]; - // start application : - [NSApp run]; // return no error return 0; } - - - /* - -NSView* view0 = ...; // a view made with IB -NSView* view1 = ... ;// another view made with IB -NSWindow* window = [self window]; - -NSRect window_frame = [window frame]; - -NSView* cv = [[[NSView alloc] initWithFrame:window_frame] autorelease]; -[window setContentView:cv]; -[cv setAutoresizesSubviews:YES]; - -// add subview so it fits within the contentview frame -{ - NSView* v = view0; - NSRect vframe = [v frame]; - [v setHidden:YES]; - [v setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - - NSView* tmp_superview = [[[NSView alloc] initWithFrame:vframe] autorelease]; - [tmp_superview addSubview:v]; - [tmp_superview setAutoresizesSubviews:YES]; - [tmp_superview setFrame:window_frame]; - - [v removeFromSuperview]; - [cv addSubview:v]; + int mm_run(void) + { + [NSApp run]; + // return no error + return 0; } - -// add subview so it fits within the contentview frame -{ - NSView* v = view1; - NSRect vframe = [v frame]; - [v setHidden:YES]; - [v setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - - NSView* tmp_superview = [[[NSView alloc] initWithFrame:vframe] autorelease]; - [tmp_superview addSubview:v]; - [tmp_superview setAutoresizesSubviews:YES]; - [tmp_superview setFrame:window_frame]; - - [v removeFromSuperview]; - [cv addSubview:v]; -} - -[view0 setHidden:NO]; - -*/ + \ No newline at end of file diff --git a/sources/ewol/renderer/MacOs/OpenglView.mm b/sources/ewol/renderer/MacOs/OpenglView.mm index 3cca3f8c..a3763257 100644 --- a/sources/ewol/renderer/MacOs/OpenglView.mm +++ b/sources/ewol/renderer/MacOs/OpenglView.mm @@ -7,9 +7,9 @@ */ -#import +#import #include -#include +#include #include #include @@ -39,7 +39,7 @@ static ewol::SpecialKey guiKeyBoardMode; -(void) drawRect: (NSRect) bounds { - eSystem::Draw(true); + MacOs::Draw(true); glFlush(); } @@ -50,7 +50,7 @@ static ewol::SpecialKey guiKeyBoardMode; // but they are floats float width = [self frame].size.width; float height = [self frame].size.height; - eSystem::Resize(width,height); + MacOs::Resize(width,height); } @@ -58,22 +58,22 @@ static ewol::SpecialKey guiKeyBoardMode; NSPoint point = [event locationInWindow]; //float x = [event locationInWindow].x; //point.x; //EWOL_INFO("mouseDown : " << (float)point.x << " " << (float)point.y); - eSystem::SetMouseState(1, true, point.x, point.y); + MacOs::SetMouseState(1, true, point.x, point.y); } -(void)mouseDragged:(NSEvent *)event { NSPoint point = [event locationInWindow]; //EWOL_INFO("mouseDragged : " << (float)point.x << " " << (float)point.y); - eSystem::SetMouseMotion(1, point.x, point.y); + MacOs::SetMouseMotion(1, point.x, point.y); } -(void)mouseUp:(NSEvent *)event { NSPoint point = [event locationInWindow]; //EWOL_INFO("mouseUp : " << (float)point.x << " " << (float)point.y); - eSystem::SetMouseState(1, false, point.x, point.y); + MacOs::SetMouseState(1, false, point.x, point.y); } -(void)mouseMoved:(NSEvent *)event { NSPoint point = [event locationInWindow]; //EWOL_INFO("mouseMoved : " << (float)point.x << " " << (float)point.y); - eSystem::SetMouseMotion(0, point.x, point.y); + MacOs::SetMouseMotion(0, point.x, point.y); } -(void)mouseEntered:(NSEvent *)event { NSPoint point = [event locationInWindow]; @@ -86,17 +86,17 @@ static ewol::SpecialKey guiKeyBoardMode; -(void)rightMouseDown:(NSEvent *)event { NSPoint point = [event locationInWindow]; //EWOL_INFO("rightMouseDown : " << (float)point.x << " " << (float)point.y); - eSystem::SetMouseState(3, true, point.x, point.y); + MacOs::SetMouseState(3, true, point.x, point.y); } -(void)rightMouseDragged:(NSEvent *)event { NSPoint point = [event locationInWindow]; //EWOL_INFO("rightMouseDragged : " << (float)point.x << " " << (float)point.y); - eSystem::SetMouseMotion(3, point.x, point.y); + MacOs::SetMouseMotion(3, point.x, point.y); } -(void)rightMouseUp:(NSEvent *)event { NSPoint point = [event locationInWindow]; //EWOL_INFO("rightMouseUp : " << (float)point.x << " " << (float)point.y); - eSystem::SetMouseState(3, false, point.x, point.y); + MacOs::SetMouseState(3, false, point.x, point.y); } -(void)otherMouseDown:(NSEvent *)event { NSPoint point = [event locationInWindow]; @@ -123,8 +123,8 @@ static ewol::SpecialKey guiKeyBoardMode; return; } for (float iii=abs(deltaY) ; iii>=0.0f ; iii-=1.0f) { - eSystem::SetMouseState(idEvent, true , point.x, point.y); - eSystem::SetMouseState(idEvent, false, point.x, point.y); + MacOs::SetMouseState(idEvent, true , point.x, point.y); + MacOs::SetMouseState(idEvent, false, point.x, point.y); } } /* @@ -146,16 +146,18 @@ static ewol::SpecialKey guiKeyBoardMode; thisIsAReapeateKey = true; } NSString *str = [theEvent charactersIgnoringModifiers]; + // TODO : set if for every char in the string !!! unichar c = [str characterAtIndex:0]; - + /* if (c < ' ' || c > '~') { // only ASCII please c = 0; return; } - EWOL_DEBUG("KeyDown " << (char)c); - eSystem::SetKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey); + */ + //EWOL_DEBUG("KeyDown " << (char)c); + MacOs::SetKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey); if (true==thisIsAReapeateKey) { - eSystem::SetKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey); + MacOs::SetKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey); } } @@ -164,17 +166,18 @@ static ewol::SpecialKey guiKeyBoardMode; if ([theEvent isARepeat]) { thisIsAReapeateKey = true; } - EWOL_DEBUG("KeyUp "); + //EWOL_DEBUG("KeyUp "); NSString *str = [theEvent charactersIgnoringModifiers]; unichar c = [str characterAtIndex:0]; - + /* if (c < ' ' || c > '~') { // only ASCII please c = 0; return; } - eSystem::SetKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey); + */ + MacOs::SetKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey); if (true==thisIsAReapeateKey) { - eSystem::SetKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey); + MacOs::SetKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey); } } diff --git a/sources/ewol/renderer/X11/Context.cpp b/sources/ewol/renderer/X11/Context.cpp index f14bcdde..c40c04ed 100644 --- a/sources/ewol/renderer/X11/Context.cpp +++ b/sources/ewol/renderer/X11/Context.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -1285,6 +1286,7 @@ class X11Interface : public ewol::eContext */ int ewol::Run(int _argc, const char *_argv[]) { + etk::SetArgZero(_argv[0]); X11Interface* interface = new X11Interface(_argc, _argv); if (NULL == interface) { EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");