[DEV] update MacOs onput mouse to be compatible wit Linux

This commit is contained in:
Edouard DUPIN 2013-11-28 21:13:40 +01:00
parent c6928fa591
commit 971acf0036
6 changed files with 229 additions and 195 deletions

2
external/etk vendored

@ -1 +1 @@
Subproject commit 216f3a55280227155a8acded577dec14be5734a0 Subproject commit 9e93578be9d48f8cbf21de9fe56ceaf17eeb8b21

View File

@ -11,12 +11,9 @@
#import <ewol/renderer/MacOs/OpenglView.h> #import <ewol/renderer/MacOs/OpenglView.h>
@implementation MacOsAppDelegate @implementation MacOsAppDelegate
@synthesize window=_window; @synthesize window=_window;
- (BOOL)application:(MacOsAppDelegate *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(MacOsAppDelegate *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
{
OpenGLView *view=[[OpenGLView alloc]initWithFrame:[[NSScreen mainScreen] bounds]]; OpenGLView *view=[[OpenGLView alloc]initWithFrame:[[NSScreen mainScreen] bounds]];
// Override point for customization after application launch. // Override point for customization after application launch.
[self.window addSubview:view]; [self.window addSubview:view];
@ -24,38 +21,33 @@
return YES; return YES;
} }
- (void)applicationWillResignActive:(MacOsAppDelegate *)application - (void)applicationWillResignActive:(MacOsAppDelegate *)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. 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. 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:(MacOsAppDelegate *)application - (void)applicationDidEnterBackground:(MacOsAppDelegate *)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. 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. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/ */
} }
- (void)applicationWillEnterForeground:(MacOsAppDelegate *)application - (void)applicationWillEnterForeground:(MacOsAppDelegate *)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. 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:(MacOsAppDelegate *)application - (void)applicationDidBecomeActive:(MacOsAppDelegate *)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. 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:(MacOsAppDelegate *)application - (void)applicationWillTerminate:(MacOsAppDelegate *)application {
{
/* /*
Called when the application is about to terminate. Called when the application is about to terminate.
Save data if appropriate. Save data if appropriate.
@ -63,8 +55,7 @@
*/ */
} }
- (void)dealloc - (void)dealloc {
{
[_window release]; [_window release];
[super dealloc]; [super dealloc];
} }

View File

@ -11,9 +11,7 @@
#include <ewol/key.h> #include <ewol/key.h>
namespace MacOs namespace MacOs {
{
// return true if a flush is needed // return true if a flush is needed
bool draw(bool _displayEveryTime); bool draw(bool _displayEveryTime);
/** /**
@ -21,11 +19,9 @@ namespace MacOs
* @param[in] _size new size of the windows. * @param[in] _size new size of the windows.
*/ */
void resize(float _x, float _y); void resize(float _x, float _y);
void setMouseState(int32_t _id, bool _isDown, 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 setMouseMotion(int32_t _id, float _x, float _y);
void setKeyboard(ewol::SpecialKey _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey); void setKeyboard(ewol::SpecialKey _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey);
}; };
#endif #endif

View File

@ -12,9 +12,7 @@
#import <ewol/renderer/MacOs/OpenglView.h> #import <ewol/renderer/MacOs/OpenglView.h>
#import <ewol/renderer/MacOs/AppDelegate.h> #import <ewol/renderer/MacOs/AppDelegate.h>
int mm_main(int argc, const char *argv[]) int mm_main(int argc, const char *argv[]) {
{
[NSAutoreleasePool new]; [NSAutoreleasePool new];
[NSApplication sharedApplication]; [NSApplication sharedApplication];
@ -81,10 +79,8 @@ int mm_main(int argc, const char *argv[])
return 0; return 0;
} }
int mm_run(void) int mm_run(void) {
{
[NSApp run]; [NSApp run];
// return no error // return no error
return 0; return 0;
} }

View File

@ -10,8 +10,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@interface OpenGLView : NSOpenGLView<NSWindowDelegate> @interface OpenGLView : NSOpenGLView<NSWindowDelegate> {
{
} }
- (void)prepareOpenGL; - (void)prepareOpenGL;
- (void)drawRect:(NSRect) bounds; - (void)drawRect:(NSRect) bounds;

View File

@ -13,10 +13,8 @@
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ewol/Dimension.h> #include <ewol/Dimension.h>
@implementation OpenGLView @implementation OpenGLView
static ewol::SpecialKey guiKeyBoardMode; static ewol::SpecialKey guiKeyBoardMode;
- (void) prepareOpenGL - (void) prepareOpenGL
@ -34,7 +32,6 @@ static ewol::SpecialKey guiKeyBoardMode;
ewol::dimension::setPixelRatio(vec2((float)displayPixelSize.width/(float)displayPhysicalSize.width, ewol::dimension::setPixelRatio(vec2((float)displayPixelSize.width/(float)displayPhysicalSize.width,
(float)displayPixelSize.height/(float)displayPhysicalSize.height), (float)displayPixelSize.height/(float)displayPhysicalSize.height),
ewol::Dimension::Millimeter); ewol::Dimension::Millimeter);
} }
-(void) drawRect: (NSRect) bounds -(void) drawRect: (NSRect) bounds
@ -53,7 +50,6 @@ static ewol::SpecialKey guiKeyBoardMode;
MacOs::resize(width,height); MacOs::resize(width,height);
} }
-(void)mouseDown:(NSEvent *)event { -(void)mouseDown:(NSEvent *)event {
NSPoint point = [event locationInWindow]; NSPoint point = [event locationInWindow];
//float x = [event locationInWindow].x; //point.x; //float x = [event locationInWindow].x; //point.x;
@ -100,22 +96,90 @@ static ewol::SpecialKey guiKeyBoardMode;
} }
-(void)otherMouseDown:(NSEvent *)event { -(void)otherMouseDown:(NSEvent *)event {
NSPoint point = [event locationInWindow]; NSPoint point = [event locationInWindow];
EWOL_INFO("otherMouseDown : " << (float)point.x << " " << (float)point.y); int32_t btNumber = [event buttonNumber];
switch (btNumber) {
case 2: // 2 : Middle button
btNumber = 2;
break;
case 3: // 3 : border button DOWN
btNumber = 8;
break;
case 4: // 4 : border button UP
btNumber = 9;
break;
case 5: // 5 : horizontal scroll Right to left
btNumber = 11;
break;
case 6: // 6 : horizontal scroll left to Right
btNumber = 10;
break;
case 7: // 7 : Red button
btNumber = 12;
break;
default:
btNumber = 15;
break;
}
//EWOL_INFO("otherMouseDown : " << (float)point.x << " " << (float)point.y);
MacOs::setMouseState(btNumber, true, point.x, point.y);
} }
-(void)otherMouseDragged:(NSEvent *)event { -(void)otherMouseDragged:(NSEvent *)event {
NSPoint point = [event locationInWindow]; NSPoint point = [event locationInWindow];
EWOL_INFO("otherMouseDragged : " << (float)point.x << " " << (float)point.y); int32_t btNumber = [event buttonNumber];
switch (btNumber) {
case 2: // 2 : Middle button
btNumber = 2;
break;
case 3: // 3 : border button DOWN
btNumber = 8;
break;
case 4: // 4 : border button UP
btNumber = 9;
break;
case 5: // 5 : horizontal scroll Right to left
btNumber = 11;
break;
case 6: // 6 : horizontal scroll left to Right
btNumber = 10;
break;
case 7: // 7 : Red button
btNumber = 12;
break;
default:
btNumber = 15;
break;
}
//EWOL_INFO("otherMouseDragged : " << (float)point.x << " " << (float)point.y);
MacOs::setMouseMotion(btNumber, point.x, point.y);
} }
-(void)otherMouseUp:(NSEvent *)event { -(void)otherMouseUp:(NSEvent *)event {
NSPoint point = [event locationInWindow]; NSPoint point = [event locationInWindow];
int32_t btNumber = [event buttonNumber]; int32_t btNumber = [event buttonNumber];
EWOL_INFO("otherMouseUp : " << (float)point.x << " " << (float)point.y << " bt id=" << btNumber ); switch (btNumber) {
// 2 : Middle button case 2: // 2 : Middle button
// 3 : border button DOWN btNumber = 2;
// 4 : border button UP break;
// 7 : Red button case 3: // 3 : border button DOWN
// 5 : horizontal scroll Right to left btNumber = 8;
// 6 : horizontal scroll left to Right break;
case 4: // 4 : border button UP
btNumber = 9;
break;
case 5: // 5 : horizontal scroll Right to left
btNumber = 11;
break;
case 6: // 6 : horizontal scroll left to Right
btNumber = 10;
break;
case 7: // 7 : Red button
btNumber = 12;
break;
default:
btNumber = 15;
break;
}
//EWOL_INFO("otherMouseUp : " << (float)point.x << " " << (float)point.y << " bt id=" << btNumber );
MacOs::setMouseState(btNumber, false, point.x, point.y);
} }
- (void)scrollWheel:(NSEvent *)event { - (void)scrollWheel:(NSEvent *)event {
NSPoint point = [event locationInWindow]; NSPoint point = [event locationInWindow];
@ -155,12 +219,6 @@ static ewol::SpecialKey guiKeyBoardMode;
NSString *str = [theEvent charactersIgnoringModifiers]; NSString *str = [theEvent charactersIgnoringModifiers];
// TODO : set if for every char in the string !!! // TODO : set if for every char in the string !!!
unichar c = [str characterAtIndex:0]; unichar c = [str characterAtIndex:0];
/*
if (c < ' ' || c > '~') { // only ASCII please
c = 0;
return;
}
*/
//EWOL_DEBUG("KeyDown " << (char)c); //EWOL_DEBUG("KeyDown " << (char)c);
MacOs::setKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey); MacOs::setKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey);
if (true==thisIsAReapeateKey) { if (true==thisIsAReapeateKey) {
@ -176,12 +234,6 @@ static ewol::SpecialKey guiKeyBoardMode;
//EWOL_DEBUG("KeyUp "); //EWOL_DEBUG("KeyUp ");
NSString *str = [theEvent charactersIgnoringModifiers]; NSString *str = [theEvent charactersIgnoringModifiers];
unichar c = [str characterAtIndex:0]; unichar c = [str characterAtIndex:0];
/*
if (c < ' ' || c > '~') { // only ASCII please
c = 0;
return;
}
*/
MacOs::setKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey); MacOs::setKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey);
if (true==thisIsAReapeateKey) { if (true==thisIsAReapeateKey) {
MacOs::setKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey); MacOs::setKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey);