Implemented mouse tracking on OS X.
This commit is contained in:
parent
35f2cc55da
commit
c095d80098
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
@interface areaView : NSView {
|
@interface areaView : NSView {
|
||||||
uiArea *libui_a;
|
uiArea *libui_a;
|
||||||
|
NSTrackingArea *libui_ta;
|
||||||
}
|
}
|
||||||
- (id)initWithFrame:(NSRect)r area:(uiArea *)a;
|
- (id)initWithFrame:(NSRect)r area:(uiArea *)a;
|
||||||
- (uiModifiers)parseModifiers:(NSEvent *)e;
|
- (uiModifiers)parseModifiers:(NSEvent *)e;
|
||||||
|
@ -12,6 +13,7 @@
|
||||||
- (int)doKeyDown:(NSEvent *)e;
|
- (int)doKeyDown:(NSEvent *)e;
|
||||||
- (int)doKeyUp:(NSEvent *)e;
|
- (int)doKeyUp:(NSEvent *)e;
|
||||||
- (int)doFlagsChanged:(NSEvent *)e;
|
- (int)doFlagsChanged:(NSEvent *)e;
|
||||||
|
- (void)setupNewTrackingArea;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
struct uiArea {
|
struct uiArea {
|
||||||
|
@ -34,8 +36,10 @@ uiDarwinDefineControl(
|
||||||
- (id)initWithFrame:(NSRect)r area:(uiArea *)a
|
- (id)initWithFrame:(NSRect)r area:(uiArea *)a
|
||||||
{
|
{
|
||||||
self = [super initWithFrame:r];
|
self = [super initWithFrame:r];
|
||||||
if (self)
|
if (self) {
|
||||||
self->libui_a = a;
|
self->libui_a = a;
|
||||||
|
[self setupNewTrackingArea];
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +99,28 @@ uiDarwinDefineControl(
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setupNewTrackingArea
|
||||||
|
{
|
||||||
|
// TODO NSTrackingAssumeInside?
|
||||||
|
self->libui_ta = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
||||||
|
options:(NSTrackingMouseEnteredAndExited |
|
||||||
|
NSTrackingMouseMoved |
|
||||||
|
NSTrackingActiveAlways |
|
||||||
|
NSTrackingInVisibleRect |
|
||||||
|
NSTrackingEnabledDuringMouseDrag)
|
||||||
|
owner:self
|
||||||
|
userInfo:nil];
|
||||||
|
[self addTrackingArea:self->libui_ta];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO when do we call super here?
|
||||||
|
- (void)updateTrackingAreas
|
||||||
|
{
|
||||||
|
[self removeTrackingArea:self->libui_ta];
|
||||||
|
[self->libui_ta release];
|
||||||
|
[self setupNewTrackingArea];
|
||||||
|
}
|
||||||
|
|
||||||
// capture on drag is done automatically on OS X
|
// capture on drag is done automatically on OS X
|
||||||
- (void)doMouseEvent:(NSEvent *)e
|
- (void)doMouseEvent:(NSEvent *)e
|
||||||
{
|
{
|
||||||
|
@ -182,7 +208,6 @@ uiDarwinDefineControl(
|
||||||
{ \
|
{ \
|
||||||
[self doMouseEvent:e]; \
|
[self doMouseEvent:e]; \
|
||||||
}
|
}
|
||||||
// TODO set up tracking events
|
|
||||||
mouseEvent(mouseMoved)
|
mouseEvent(mouseMoved)
|
||||||
mouseEvent(mouseDragged)
|
mouseEvent(mouseDragged)
|
||||||
mouseEvent(rightMouseDragged)
|
mouseEvent(rightMouseDragged)
|
||||||
|
@ -194,6 +219,20 @@ mouseEvent(mouseUp)
|
||||||
mouseEvent(rightMouseUp)
|
mouseEvent(rightMouseUp)
|
||||||
mouseEvent(otherMouseUp)
|
mouseEvent(otherMouseUp)
|
||||||
|
|
||||||
|
- (void)mouseEntered:(NSEvent *)e
|
||||||
|
{
|
||||||
|
uiArea *a = self->libui_a;
|
||||||
|
|
||||||
|
(*(a->ah->MouseCrossed))(a->ah, a, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)mouseExited:(NSEvent *)e
|
||||||
|
{
|
||||||
|
uiArea *a = self->libui_a;
|
||||||
|
|
||||||
|
(*(a->ah->MouseCrossed))(a->ah, a, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// note: there is no equivalent to WM_CAPTURECHANGED on Mac OS X; there literally is no way to break a grab like that
|
// note: there is no equivalent to WM_CAPTURECHANGED on Mac OS X; there literally is no way to break a grab like that
|
||||||
// even if I invoke the task switcher and switch processes, the mouse grab will still be held until I let go of all buttons
|
// even if I invoke the task switcher and switch processes, the mouse grab will still be held until I let go of all buttons
|
||||||
// therefore, no DragBroken()
|
// therefore, no DragBroken()
|
||||||
|
|
Loading…
Reference in New Issue