[DEV] MAC : mouse event availlable and periodic display (limited at 30 fps???)
This commit is contained in:
parent
b4940a4bc3
commit
6ff6693871
2
external/etk
vendored
2
external/etk
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 1c21a6f3d5df76f313040a87a837b201c70a5edf
|
Subproject commit c90b9d1b3986f21cbd2a3f0a3ad8f12ab1df3bd1
|
@ -31,7 +31,8 @@ static const float millimeterToKilometer = 1.0f/1000000.0f;
|
|||||||
|
|
||||||
void ewol::dimension::Init(void)
|
void ewol::dimension::Init(void)
|
||||||
{
|
{
|
||||||
ratio = vec2(96,96)*inchToMillimeter;
|
ewol::Dimension conversion(vec2(72,72), ewol::Dimension::Inch);
|
||||||
|
ratio = conversion.GetMillimeter();
|
||||||
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
|
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
|
||||||
windowsSize.Set(vec2(200,200), ewol::Dimension::Pixel);
|
windowsSize.Set(vec2(200,200), ewol::Dimension::Pixel);
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,9 @@ int mm_main(int argc, const char *argv[])
|
|||||||
autorelease];
|
autorelease];
|
||||||
// set the windows at a specific position :
|
// set the windows at a specific position :
|
||||||
[window cascadeTopLeftFromPoint:NSMakePoint(50,50)];
|
[window cascadeTopLeftFromPoint:NSMakePoint(50,50)];
|
||||||
|
// set the windows resizable
|
||||||
|
[window setStyleMask:[window styleMask] | NSResizableWindowMask];
|
||||||
|
// oposite : [window setStyleMask:[window styleMask] & ~NSResizableWindowMask];
|
||||||
// set the title
|
// set the title
|
||||||
[window setTitle:appName];
|
[window setTitle:appName];
|
||||||
|
|
||||||
@ -88,7 +91,7 @@ int mm_main(int argc, const char *argv[])
|
|||||||
//[window addChildWindow:view];
|
//[window addChildWindow:view];
|
||||||
//[window makeKeyAndVisible];
|
//[window makeKeyAndVisible];
|
||||||
|
|
||||||
|
[window setDelegate:view];
|
||||||
// start application :
|
// start application :
|
||||||
[NSApp run];
|
[NSApp run];
|
||||||
// return no error
|
// return no error
|
||||||
|
@ -10,9 +10,10 @@
|
|||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface OpenGLView : NSOpenGLView
|
@interface OpenGLView : NSOpenGLView<NSWindowDelegate>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
- (void)prepareOpenGL;
|
||||||
- (void)drawRect:(NSRect) bounds;
|
- (void)drawRect:(NSRect) bounds;
|
||||||
- (void)mouseDown:(NSEvent *) event;
|
- (void)mouseDown:(NSEvent *) event;
|
||||||
- (void)mouseDragged:(NSEvent *) event;
|
- (void)mouseDragged:(NSEvent *) event;
|
||||||
@ -27,6 +28,7 @@
|
|||||||
- (void)otherMouseDragged:(NSEvent *)event;
|
- (void)otherMouseDragged:(NSEvent *)event;
|
||||||
- (void)otherMouseUp:(NSEvent *)event;
|
- (void)otherMouseUp:(NSEvent *)event;
|
||||||
//- (void)sendEvent:(NSEvent *)event
|
//- (void)sendEvent:(NSEvent *)event
|
||||||
|
- (void)keyDown:(NSEvent *)theEvent;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,43 +11,69 @@
|
|||||||
#include <OpenGL/gl.h>
|
#include <OpenGL/gl.h>
|
||||||
#include <ewol/renderer/os/eSystem.h>
|
#include <ewol/renderer/os/eSystem.h>
|
||||||
#include <ewol/debug.h>
|
#include <ewol/debug.h>
|
||||||
|
#include <ewol/Dimension.h>
|
||||||
|
|
||||||
static int32_t width=0, height=0;
|
|
||||||
|
|
||||||
@implementation OpenGLView
|
@implementation OpenGLView
|
||||||
|
|
||||||
|
|
||||||
|
static ewol::SpecialKey guiKeyBoardMode;
|
||||||
|
|
||||||
|
- (void) prepareOpenGL
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
|
||||||
|
CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
|
||||||
|
|
||||||
|
ewol::dimension::SetPixelRatio(vec2((float)displayPixelSize.width/(float)displayPhysicalSize.width,
|
||||||
|
(float)displayPixelSize.height/(float)displayPhysicalSize.height),
|
||||||
|
ewol::Dimension::Millimeter);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
-(void) drawRect: (NSRect) bounds
|
-(void) drawRect: (NSRect) bounds
|
||||||
{
|
{
|
||||||
if( width!= bounds.size.width
|
|
||||||
|| height!= bounds.size.height) {
|
|
||||||
width= bounds.size.width;
|
|
||||||
height= bounds.size.height;
|
|
||||||
eSystem::Resize(width,height);
|
|
||||||
}
|
|
||||||
eSystem::Draw(true);
|
eSystem::Draw(true);
|
||||||
glFlush();
|
glFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)reshape {
|
||||||
|
EWOL_INFO("view reshape (" << [self frame].size.width << "," << [self frame].size.height << ")" );
|
||||||
|
|
||||||
|
// window resize; width and height are in pixel coordinates
|
||||||
|
// but they are floats
|
||||||
|
float width = [self frame].size.width;
|
||||||
|
float height = [self frame].size.height;
|
||||||
|
eSystem::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;
|
||||||
EWOL_INFO("mouseDown : " << (float)point.x << " " << (float)point.y);
|
//EWOL_INFO("mouseDown : " << (float)point.x << " " << (float)point.y);
|
||||||
eSystem::SetMouseState(1, true, point.x, point.y);
|
eSystem::SetMouseState(1, true, point.x, point.y);
|
||||||
}
|
}
|
||||||
-(void)mouseDragged:(NSEvent *)event {
|
-(void)mouseDragged:(NSEvent *)event {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
EWOL_INFO("mouseDragged : " << (float)point.x << " " << (float)point.y);
|
//EWOL_INFO("mouseDragged : " << (float)point.x << " " << (float)point.y);
|
||||||
eSystem::SetMouseMotion(1, point.x, point.y);
|
eSystem::SetMouseMotion(1, point.x, point.y);
|
||||||
}
|
}
|
||||||
-(void)mouseUp:(NSEvent *)event {
|
-(void)mouseUp:(NSEvent *)event {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
EWOL_INFO("mouseUp : " << (float)point.x << " " << (float)point.y);
|
//EWOL_INFO("mouseUp : " << (float)point.x << " " << (float)point.y);
|
||||||
eSystem::SetMouseState(1, false, point.x, point.y);
|
eSystem::SetMouseState(1, false, point.x, point.y);
|
||||||
}
|
}
|
||||||
-(void)mouseMoved:(NSEvent *)event {
|
-(void)mouseMoved:(NSEvent *)event {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
EWOL_INFO("mouseMoved : " << (float)point.x << " " << (float)point.y);
|
//EWOL_INFO("mouseMoved : " << (float)point.x << " " << (float)point.y);
|
||||||
|
eSystem::SetMouseMotion(0, point.x, point.y);
|
||||||
}
|
}
|
||||||
-(void)mouseEntered:(NSEvent *)event {
|
-(void)mouseEntered:(NSEvent *)event {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
@ -59,17 +85,17 @@ static int32_t width=0, height=0;
|
|||||||
}
|
}
|
||||||
-(void)rightMouseDown:(NSEvent *)event {
|
-(void)rightMouseDown:(NSEvent *)event {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
EWOL_INFO("rightMouseDown : " << (float)point.x << " " << (float)point.y);
|
//EWOL_INFO("rightMouseDown : " << (float)point.x << " " << (float)point.y);
|
||||||
eSystem::SetMouseState(3, true, point.x, point.y);
|
eSystem::SetMouseState(3, true, point.x, point.y);
|
||||||
}
|
}
|
||||||
-(void)rightMouseDragged:(NSEvent *)event {
|
-(void)rightMouseDragged:(NSEvent *)event {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
EWOL_INFO("rightMouseDragged : " << (float)point.x << " " << (float)point.y);
|
//EWOL_INFO("rightMouseDragged : " << (float)point.x << " " << (float)point.y);
|
||||||
eSystem::SetMouseMotion(3, point.x, point.y);
|
eSystem::SetMouseMotion(3, point.x, point.y);
|
||||||
}
|
}
|
||||||
-(void)rightMouseUp:(NSEvent *)event {
|
-(void)rightMouseUp:(NSEvent *)event {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
EWOL_INFO("rightMouseUp : " << (float)point.x << " " << (float)point.y);
|
//EWOL_INFO("rightMouseUp : " << (float)point.x << " " << (float)point.y);
|
||||||
eSystem::SetMouseState(3, false, point.x, point.y);
|
eSystem::SetMouseState(3, false, point.x, point.y);
|
||||||
}
|
}
|
||||||
-(void)otherMouseDown:(NSEvent *)event {
|
-(void)otherMouseDown:(NSEvent *)event {
|
||||||
@ -84,6 +110,23 @@ static int32_t width=0, height=0;
|
|||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
EWOL_INFO("otherMouseUp : " << (float)point.x << " " << (float)point.y);
|
EWOL_INFO("otherMouseUp : " << (float)point.x << " " << (float)point.y);
|
||||||
}
|
}
|
||||||
|
- (void)scrollWheel:(NSEvent *)event {
|
||||||
|
NSPoint point = [event locationInWindow];
|
||||||
|
//EWOL_INFO("scrollWheel : " << (float)point.x << " " << (float)point.y << "button : " << (int32_t)([event buttonNumber]));
|
||||||
|
EWOL_INFO("scrollWheel : " << (float)point.x << " " << (float)point.y << " delta(" << (float)([event deltaX]) << "," << (float)([event deltaY]) << ")");
|
||||||
|
float deltaY = [event deltaY];
|
||||||
|
int32_t idEvent = 4;
|
||||||
|
if (deltaY < 0) {
|
||||||
|
idEvent = 5;
|
||||||
|
}
|
||||||
|
if (abs(deltaY) < 0.1f) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
// http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html
|
// http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html
|
||||||
-(void)sendEvent:(NSEvent *)event {
|
-(void)sendEvent:(NSEvent *)event {
|
||||||
@ -91,4 +134,79 @@ static int32_t width=0, height=0;
|
|||||||
EWOL_INFO("sendEvent : " << (float)point.x << " " << (float)point.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)keyDown:(NSEvent *)theEvent {
|
||||||
|
bool thisIsAReapeateKey = false;
|
||||||
|
if ([theEvent isARepeat]) {
|
||||||
|
thisIsAReapeateKey = true;
|
||||||
|
}
|
||||||
|
NSString *str = [theEvent charactersIgnoringModifiers];
|
||||||
|
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);
|
||||||
|
if (true==thisIsAReapeateKey) {
|
||||||
|
eSystem::SetKeyboard(guiKeyBoardMode, (char)c, false, thisIsAReapeateKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)keyUp:(NSEvent *)theEvent {
|
||||||
|
bool thisIsAReapeateKey = false;
|
||||||
|
if ([theEvent isARepeat]) {
|
||||||
|
thisIsAReapeateKey = true;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
if (true==thisIsAReapeateKey) {
|
||||||
|
eSystem::SetKeyboard(guiKeyBoardMode, (char)c, true, thisIsAReapeateKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define FRAME_INTERVAL (0.01)
|
||||||
|
|
||||||
|
static NSTimer *timer = nil;
|
||||||
|
|
||||||
|
- (void)windowDidResignMain:(NSNotification *)notification {
|
||||||
|
// NSLog(@"window did resign main");
|
||||||
|
[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:)
|
||||||
|
userInfo:nil
|
||||||
|
repeats:YES];
|
||||||
|
|
||||||
|
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)timerEvent:(NSTimer *)t {
|
||||||
|
//run_game();
|
||||||
|
[self setNeedsDisplay:YES];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user