main.mm (imgui-1.86) | : | main.mm (imgui-1.87) | ||
---|---|---|---|---|
skipping to change at line 110 | skipping to change at line 110 | |||
self.mtkView.delegate = self; | self.mtkView.delegate = self; | |||
#if TARGET_OS_OSX | #if TARGET_OS_OSX | |||
// Add a tracking area in order to receive mouse events whenever the mouse i s within the bounds of our view | // Add a tracking area in order to receive mouse events whenever the mouse i s within the bounds of our view | |||
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRe ct | NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRe ct | |||
options:NSTracki ngMouseMoved | NSTrackingInVisibleRect | NSTrackingActiveAlways | options:NSTracki ngMouseMoved | NSTrackingInVisibleRect | NSTrackingActiveAlways | |||
owner:self | owner:self | |||
userInfo:nil]; | userInfo:nil]; | |||
[self.view addTrackingArea:trackingArea]; | [self.view addTrackingArea:trackingArea]; | |||
// If we want to receive key events, we either need to be in the responder c | ||||
hain of the key view, | ||||
// or else we can install a local monitor. The consequence of this heavy-han | ||||
ded approach is that | ||||
// we receive events for all controls, not just Dear ImGui widgets. If we ha | ||||
d native controls in our | ||||
// window, we'd want to be much more careful than just ingesting the complet | ||||
e event stream. | ||||
// To match the behavior of other backends, we pass every event down to the | ||||
OS. | ||||
NSEventMask eventMask = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskF | ||||
lagsChanged; | ||||
[NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^NSEvent * _ | ||||
Nullable(NSEvent *event) | ||||
{ | ||||
ImGui_ImplOSX_HandleEvent(event, self.view); | ||||
return event; | ||||
}]; | ||||
ImGui_ImplOSX_Init(self.view); | ImGui_ImplOSX_Init(self.view); | |||
#endif | #endif | |||
} | } | |||
-(void)drawInMTKView:(MTKView*)view | -(void)drawInMTKView:(MTKView*)view | |||
{ | { | |||
ImGuiIO& io = ImGui::GetIO(); | ImGuiIO& io = ImGui::GetIO(); | |||
io.DisplaySize.x = view.bounds.size.width; | io.DisplaySize.x = view.bounds.size.width; | |||
io.DisplaySize.y = view.bounds.size.height; | io.DisplaySize.y = view.bounds.size.height; | |||
skipping to change at line 226 | skipping to change at line 214 | |||
-(void)mtkView:(MTKView*)view drawableSizeWillChange:(CGSize)size | -(void)mtkView:(MTKView*)view drawableSizeWillChange:(CGSize)size | |||
{ | { | |||
} | } | |||
//------------------------------------------------------------------------------ ----- | //------------------------------------------------------------------------------ ----- | |||
// Input processing | // Input processing | |||
//------------------------------------------------------------------------------ ----- | //------------------------------------------------------------------------------ ----- | |||
#if TARGET_OS_OSX | #if TARGET_OS_OSX | |||
// Forward Mouse/Keyboard events to Dear ImGui OSX backend. | // Forward Mouse events to Dear ImGui OSX backend. | |||
// Other events are registered via addLocalMonitorForEventsMatchingMask() | ||||
-(void)mouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)mouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)rightMouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)rightMouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)otherMouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)otherMouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)mouseUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)mouseUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)rightMouseUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)rightMouseUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)otherMouseUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)otherMouseUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)mouseMoved:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)mouseMoved:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)mouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)mouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)rightMouseMoved:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)rightMouseMoved:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
-(void)rightMouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | -(void)rightMouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s elf.view); } | |||
skipping to change at line 254 | skipping to change at line 241 | |||
// This touch mapping is super cheesy/hacky. We treat any touch on the screen | // This touch mapping is super cheesy/hacky. We treat any touch on the screen | |||
// as if it were a depressed left mouse button, and we don't bother handling | // as if it were a depressed left mouse button, and we don't bother handling | |||
// multitouch correctly at all. This causes the "cursor" to behave very erratica lly | // multitouch correctly at all. This causes the "cursor" to behave very erratica lly | |||
// when there are multiple active touches. But for demo purposes, single-touch | // when there are multiple active touches. But for demo purposes, single-touch | |||
// interaction actually works surprisingly well. | // interaction actually works surprisingly well. | |||
-(void)updateIOWithTouchEvent:(UIEvent *)event | -(void)updateIOWithTouchEvent:(UIEvent *)event | |||
{ | { | |||
UITouch *anyTouch = event.allTouches.anyObject; | UITouch *anyTouch = event.allTouches.anyObject; | |||
CGPoint touchLocation = [anyTouch locationInView:self.view]; | CGPoint touchLocation = [anyTouch locationInView:self.view]; | |||
ImGuiIO &io = ImGui::GetIO(); | ImGuiIO &io = ImGui::GetIO(); | |||
io.MousePos = ImVec2(touchLocation.x, touchLocation.y); | io.AddMousePosEvent(touchLocation.x, touchLocation.y); | |||
BOOL hasActiveTouch = NO; | BOOL hasActiveTouch = NO; | |||
for (UITouch *touch in event.allTouches) | for (UITouch *touch in event.allTouches) | |||
{ | { | |||
if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCance lled) | if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCance lled) | |||
{ | { | |||
hasActiveTouch = YES; | hasActiveTouch = YES; | |||
break; | break; | |||
} | } | |||
} | } | |||
io.MouseDown[0] = hasActiveTouch; | io.AddMouseButtonEvent(0, hasActiveTouch); | |||
} | } | |||
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | |||
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | |||
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | -(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | |||
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self updateIOWithTouchEvent:event]; } | |||
#endif | #endif | |||
@end | @end | |||
End of changes. 4 change blocks. | ||||
23 lines changed or deleted | 3 lines changed or added |