From 3e617536af93f282afc8d0af3de7c7d19a5f5f95 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 6 Jan 2014 21:38:49 +0100 Subject: [PATCH] [DEV] better work on MacOS --- external/etk | 2 +- sources/ewol/context/Context.cpp | 6 ++-- sources/ewol/context/MacOs/Interface.mm | 9 ++++-- sources/ewol/context/MacOs/OpenglView.h | 10 +++---- sources/ewol/context/MacOs/OpenglView.mm | 37 +++++++++++++++++------- sources/ewol/context/MacOs/Windows.h | 4 ++- sources/ewol/context/MacOs/Windows.mm | 29 ++++++++++++++++++- 7 files changed, 74 insertions(+), 23 deletions(-) diff --git a/external/etk b/external/etk index 8d7bd46d..a61639ef 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit 8d7bd46da421fe42eff61cd76543992e53acba48 +Subproject commit a61639ef292b617a86a07fe30770d8533c17159b diff --git a/sources/ewol/context/Context.cpp b/sources/ewol/context/Context.cpp index e348a951..52168cf3 100644 --- a/sources/ewol/context/Context.cpp +++ b/sources/ewol/context/Context.cpp @@ -290,7 +290,7 @@ ewol::Context::Context(int32_t _argc, const char* _argv[]) : // set the curent interface : lockContext(); // parse the debug level: - for(int32_t iii=m_commandLine.size()-1 ; iii >= 0 ; --iii) { + for(int32_t iii = 0; iii < m_commandLine.size() ; ++iii) { if (m_commandLine.get(iii) == "-l0") { debug::setGeneralLevel(etk::logLevelNone); } else if (m_commandLine.get(iii) == "-l1") { @@ -316,7 +316,9 @@ ewol::Context::Context(int32_t _argc, const char* _argv[]) : continue; } m_commandLine.remove(iii); + --iii; } + //etk::cout.setOutputFile(true); EWOL_INFO("EWOL v:" << ewol::getVersion()); EWOL_INFO("Build Date: " << date::getYear() << "/" << date::getMonth() << "/" << date::getDay() << " " << date::getHour() << "h" << date::getMinute()); @@ -529,7 +531,7 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) { return false; } #endif - + //EWOL_DEBUG("DRAW"); m_previousDisplayTime = currentTime; // process the events diff --git a/sources/ewol/context/MacOs/Interface.mm b/sources/ewol/context/MacOs/Interface.mm index a2c0a6b1..9bf923a3 100644 --- a/sources/ewol/context/MacOs/Interface.mm +++ b/sources/ewol/context/MacOs/Interface.mm @@ -13,6 +13,8 @@ #import #import + + int mm_main(int argc, const char *argv[]) { [NSAutoreleasePool new]; @@ -46,13 +48,13 @@ int mm_main(int argc, const char *argv[]) { // --------------------------------------------------------------- // -- basic windows creation : - // --------------------------------------------------------------- + // ----------------------- ---------------------------------------- // create a windows of size 800/600 #if 1 id window = [ [ [EwolMainWindows alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) styleMask:(NSTitledWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask) backing:NSBackingStoreBuffered defer:NO] autorelease]; - + [window setAcceptsMouseMovedEvents:YES]; //id window = [ [MacOsAppDelegate alloc] autorelease]; // set the windows at a specific position : @@ -71,6 +73,9 @@ int mm_main(int argc, const char *argv[]) { NSRect window_frame = [window frame]; OpenGLView* view=[[OpenGLView alloc]initWithFrame:window_frame]; //NSMakeRect(0, 0, 800, 600)]; + NSTrackingArea *track = [[NSTrackingArea alloc] initWithRect:window_frame options: NSTrackingMouseMoved | NSTrackingActiveWhenFirstResponder | NSTrackingActiveInKeyWindow + owner:window userInfo:nil]; + [view addTrackingArea:track]; [window setContentView:view]; [view setAutoresizesSubviews:YES]; diff --git a/sources/ewol/context/MacOs/OpenglView.h b/sources/ewol/context/MacOs/OpenglView.h index 476f570f..b3f8c9b6 100644 --- a/sources/ewol/context/MacOs/OpenglView.h +++ b/sources/ewol/context/MacOs/OpenglView.h @@ -6,11 +6,13 @@ * @license BSD v3 (see license file) */ - - #import - +#import +#import + + @interface OpenGLView : NSOpenGLView { + NSTimer* _refreshTimer; } - (void)prepareOpenGL; - (void)drawRect:(NSRect) bounds; @@ -30,5 +32,3 @@ - (void)keyDown:(NSEvent *)theEvent; - (void)flagsChanged:(NSEvent *)theEvent; @end - - diff --git a/sources/ewol/context/MacOs/OpenglView.mm b/sources/ewol/context/MacOs/OpenglView.mm index 9b79eb56..106e84b5 100644 --- a/sources/ewol/context/MacOs/OpenglView.mm +++ b/sources/ewol/context/MacOs/OpenglView.mm @@ -13,6 +13,7 @@ #include #include + @implementation OpenGLView static ewol::key::Special guiKeyBoardMode; @@ -22,7 +23,6 @@ static ewol::key::Special guiKeyBoardMode; EWOL_ERROR("prepare"); GLint swapInt = 1; [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; // set to vbl sync - // set system dpi size : NSScreen *screen = [NSScreen mainScreen]; NSDictionary *description = [screen deviceDescription]; @@ -32,14 +32,26 @@ static ewol::key::Special guiKeyBoardMode; ewol::Dimension::setPixelRatio(vec2((float)displayPixelSize.width/(float)displayPhysicalSize.width, (float)displayPixelSize.height/(float)displayPhysicalSize.height), ewol::Dimension::Millimeter); + _refreshTimer=[ [ NSTimer scheduledTimerWithTimeInterval:0.017 target:self selector:@selector(animationTimerFired:) userInfo:nil repeats:YES ] retain ] ; + } --(void) drawRect: (NSRect) bounds -{ +-(void) drawRect: (NSRect) bounds { + if ( ! _refreshTimer ) { + _refreshTimer=[ [ NSTimer scheduledTimerWithTimeInterval:0.017 target:self selector:@selector(animationTimerFired:) userInfo:nil repeats:YES ] retain ] ; + } MacOs::draw(true); glFlush(); } +/** + * Service the animation timer. + */ +- (void) animationTimerFired: (NSTimer *) timer { + [ self setNeedsDisplay: YES ]; + //EWOL_INFO("view refresh ..." ); +} + -(void)reshape { EWOL_INFO("view reshape (" << [self frame].size.width << "," << [self frame].size.height << ")" ); @@ -68,7 +80,7 @@ static ewol::key::Special guiKeyBoardMode; } -(void)mouseMoved:(NSEvent *)event { NSPoint point = [event locationInWindow]; - //EWOL_INFO("mouseMoved : " << (float)point.x << " " << (float)point.y); + EWOL_INFO("mouseMoved : " << (float)point.x << " " << (float)point.y); MacOs::setMouseMotion(0, point.x, point.y); } -(void)mouseEntered:(NSEvent *)event { @@ -206,12 +218,15 @@ static ewol::key::Special guiKeyBoardMode; EWOL_INFO("sendEvent : " << (float)point.x << " " << (float)point.y); } */ - +/* // this generate all the event entry availlable ==> like a big keep focus ... - (BOOL)acceptsFirstResponder { return YES; } - +- (BOOL)becomeFirstResponder { + return YES; +} +*/ - (void)keyDown:(NSEvent *)theEvent { bool thisIsAReapeateKey = false; if ([theEvent isARepeat]) { @@ -242,7 +257,6 @@ static ewol::key::Special guiKeyBoardMode; } - (void)flagsChanged:(NSEvent *)theEvent { - if (([theEvent modifierFlags] & NSAlphaShiftKeyMask) != 0) { EWOL_DEBUG("NSAlphaShiftKeyMask"); if (guiKeyBoardMode.getCapsLock() == false) { @@ -339,15 +353,13 @@ static NSTimer *timer = nil; [timer invalidate]; //game_deactivate(); // freeze, pause - [self setNeedsDisplay:YES]; } - (void)windowDidBecomeMain:(NSNotification *)notification { // NSLog(@"window did become main"); //game_activate(); - [self setNeedsDisplay:YES]; - + /* timer = [NSTimer timerWithTimeInterval:FRAME_INTERVAL target:self selector:@selector(timerEvent:) @@ -355,10 +367,13 @@ static NSTimer *timer = nil; repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; + */ } - (void)timerEvent:(NSTimer *)t { //run_game(); - [self setNeedsDisplay:YES]; } + + @end + diff --git a/sources/ewol/context/MacOs/Windows.h b/sources/ewol/context/MacOs/Windows.h index e197a552..a0745e60 100644 --- a/sources/ewol/context/MacOs/Windows.h +++ b/sources/ewol/context/MacOs/Windows.h @@ -8,7 +8,9 @@ #import -@interface EwolMainWindows : NSWindow +@interface EwolMainWindows : NSWindow { + +} + (id)alloc; - (id)init; + (void)dealloc; diff --git a/sources/ewol/context/MacOs/Windows.mm b/sources/ewol/context/MacOs/Windows.mm index 83db12d4..157a9f70 100644 --- a/sources/ewol/context/MacOs/Windows.mm +++ b/sources/ewol/context/MacOs/Windows.mm @@ -9,6 +9,7 @@ #import #import +#include #include @@ -70,13 +71,39 @@ //[_window release]; [super dealloc]; } -/* +/* - (void)sendEvent:(NSEvent *)event { EWOL_WARNING(" EVENT ... "); } */ + +// this generate all the event entry availlable ==> like a big keep focus ... +- (BOOL)acceptsFirstResponder { + return YES; +} +- (BOOL)becomeFirstResponder { + return YES; +} + +-(void)mouseMoved:(NSEvent *)event { + NSPoint point = [event locationInWindow]; + EWOL_INFO("mouseMoved : " << (float)point.x << " " << (float)point.y); + MacOs::setMouseMotion(0, point.x, point.y); +} +-(void)mouseEntered:(NSEvent *)event { + NSPoint point = [event locationInWindow]; + EWOL_INFO("mouseEntered : " << (float)point.x << " " << (float)point.y); +} +-(void)mouseExited:(NSEvent *)event { + NSPoint point = [event locationInWindow]; + EWOL_INFO("mouseExited : " << (float)point.x << " " << (float)point.y); +} + + + + @end