0.2.0-dev Download ZIP
931 lines ·31.5 KB Raw
| 1 | /**************************************************************************/ |
| 2 | /* godot_content_view.mm */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #import "godot_content_view.h" |
| 32 | |
| 33 | #import "display_server_macos.h" |
| 34 | #import "godot_window.h" |
| 35 | #import "key_mapping_macos.h" |
| 36 | |
| 37 | #include "core/input/input.h" |
| 38 | #include "core/input/input_event.h" |
| 39 | #include "core/os/keyboard.h" |
| 40 | #include "core/os/os.h" |
| 41 | #include "core/profiling/profiling.h" |
| 42 | #include "main/main.h" |
| 43 | |
| 44 | @implementation GodotContentLayerDelegate |
| 45 | |
| 46 | - (id)init { |
| 47 | self = [super init]; |
| 48 | window_id = DisplayServerEnums::INVALID_WINDOW_ID; |
| 49 | need_redraw = false; |
| 50 | return self; |
| 51 | } |
| 52 | |
| 53 | - (void)setWindowID:(DisplayServerEnums::WindowID)wid { |
| 54 | window_id = wid; |
| 55 | } |
| 56 | |
| 57 | - (void)setNeedRedraw:(bool)redraw { |
| 58 | need_redraw = redraw; |
| 59 | } |
| 60 | |
| 61 | - (void)displayLayer:(CALayer *)layer { |
| 62 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 63 | if (OS::get_singleton()->get_main_loop() && ds->get_is_resizing() && need_redraw) { |
| 64 | GodotProfileFrameMark; |
| 65 | GodotProfileZone("[GodotContentLayerDelegate displayLayer]"); |
| 66 | |
| 67 | Main::force_redraw(); |
| 68 | if (!Main::is_iterating()) { // Avoid cyclic loop. |
| 69 | Main::iteration(); |
| 70 | } |
| 71 | need_redraw = false; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | @end |
| 76 | |
| 77 | @implementation GodotContentView |
| 78 | |
| 79 | - (BOOL)acceptsFirstMouse:(NSEvent *)event { |
| 80 | return YES; |
| 81 | } |
| 82 | |
| 83 | - (void)setFrameSize:(NSSize)newSize { |
| 84 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 85 | if (ds && ds->has_window(window_id)) { |
| 86 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 87 | NSRect frameRect = [wd.window_object frame]; |
| 88 | if (wd.fs_transition || wd.initial_size) { |
| 89 | self.layerContentsPlacement = NSViewLayerContentsPlacementScaleAxesIndependently; |
| 90 | wd.initial_size = false; |
| 91 | } else { |
| 92 | bool left = (wd.last_frame_rect.origin.x != frameRect.origin.x); |
| 93 | bool bottom = (wd.last_frame_rect.origin.y != frameRect.origin.y); |
| 94 | bool right = (wd.last_frame_rect.origin.x + wd.last_frame_rect.size.width != frameRect.origin.x + frameRect.size.width); |
| 95 | bool top = (wd.last_frame_rect.origin.y + wd.last_frame_rect.size.height != frameRect.origin.y + frameRect.size.height); |
| 96 | |
| 97 | if (left && top) { |
| 98 | self.layerContentsPlacement = NSViewLayerContentsPlacementBottomRight; |
| 99 | } else if (left && bottom) { |
| 100 | self.layerContentsPlacement = NSViewLayerContentsPlacementTopRight; |
| 101 | } else if (left) { |
| 102 | self.layerContentsPlacement = NSViewLayerContentsPlacementRight; |
| 103 | } else if (right && top) { |
| 104 | self.layerContentsPlacement = NSViewLayerContentsPlacementBottomLeft; |
| 105 | } else if (right && bottom) { |
| 106 | self.layerContentsPlacement = NSViewLayerContentsPlacementTopLeft; |
| 107 | } else if (right) { |
| 108 | self.layerContentsPlacement = NSViewLayerContentsPlacementLeft; |
| 109 | } |
| 110 | } |
| 111 | wd.last_frame_rect = frameRect; |
| 112 | } |
| 113 | |
| 114 | [super setFrameSize:newSize]; |
| 115 | [layer_delegate setNeedRedraw:true]; |
| 116 | [self.layer setNeedsDisplay]; // Force "drawRect" call. |
| 117 | } |
| 118 | |
| 119 | - (void)updateLayerDelegate { |
| 120 | self.layer.delegate = layer_delegate; |
| 121 | self.layer.autoresizingMask = kCALayerHeightSizable | kCALayerWidthSizable; |
| 122 | self.layer.needsDisplayOnBoundsChange = YES; |
| 123 | } |
| 124 | |
| 125 | - (void)addObserver:(NSObject *)targetObserver forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context { |
| 126 | [registered_observers addObject:[[targetObserver description] stringByAppendingString:keyPath]]; |
| 127 | [super addObserver:targetObserver forKeyPath:keyPath options:options context:context]; |
| 128 | } |
| 129 | |
| 130 | - (void)removeObserver:(NSObject *)targetObserver forKeyPath:(NSString *)keyPath { |
| 131 | if ([registered_observers containsObject:[[targetObserver description] stringByAppendingString:keyPath]]) { |
| 132 | @try { |
| 133 | [super removeObserver:targetObserver forKeyPath:keyPath]; |
| 134 | [registered_observers removeObject:[[targetObserver description] stringByAppendingString:keyPath]]; |
| 135 | } @catch (NSException *exception) { |
| 136 | ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String)); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | - (id)init { |
| 142 | self = [super init]; |
| 143 | layer_delegate = [[GodotContentLayerDelegate alloc] init]; |
| 144 | window_id = DisplayServerEnums::INVALID_WINDOW_ID; |
| 145 | tracking_area = nil; |
| 146 | ime_input_event_in_progress = false; |
| 147 | mouse_down_control = false; |
| 148 | ignore_momentum_scroll = false; |
| 149 | last_pen_inverted = false; |
| 150 | registered_observers = [[NSMutableSet alloc] init]; |
| 151 | [self updateTrackingAreas]; |
| 152 | |
| 153 | self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize; |
| 154 | self.layerContentsPlacement = NSViewLayerContentsPlacementTopLeft; |
| 155 | |
| 156 | [self registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypeFileURL]]; |
| 157 | marked_text = [[NSMutableAttributedString alloc] init]; |
| 158 | return self; |
| 159 | } |
| 160 | |
| 161 | - (void)setWindowID:(DisplayServerEnums::WindowID)wid { |
| 162 | window_id = wid; |
| 163 | [layer_delegate setWindowID:window_id]; |
| 164 | } |
| 165 | |
| 166 | // MARK: Backing Layer |
| 167 | |
| 168 | - (CALayer *)makeBackingLayer { |
| 169 | CAMetalLayer *layer = [CAMetalLayer new]; |
| 170 | layer.edgeAntialiasingMask = 0; |
| 171 | layer.masksToBounds = NO; |
| 172 | layer.presentsWithTransaction = NO; |
| 173 | [layer removeAllAnimations]; |
| 174 | return layer; |
| 175 | } |
| 176 | |
| 177 | - (BOOL)wantsUpdateLayer { |
| 178 | return YES; |
| 179 | } |
| 180 | |
| 181 | - (BOOL)isOpaque { |
| 182 | return YES; |
| 183 | } |
| 184 | |
| 185 | // MARK: IME |
| 186 | |
| 187 | - (BOOL)hasMarkedText { |
| 188 | return (marked_text.length > 0); |
| 189 | } |
| 190 | |
| 191 | - (NSRange)markedRange { |
| 192 | return NSMakeRange(0, marked_text.length); |
| 193 | } |
| 194 | |
| 195 | - (NSRange)selectedRange { |
| 196 | static const NSRange kEmptyRange = { NSNotFound, 0 }; |
| 197 | return kEmptyRange; |
| 198 | } |
| 199 | |
| 200 | - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange { |
| 201 | if ([aString isKindOfClass:[NSAttributedString class]]) { |
| 202 | marked_text = [[NSMutableAttributedString alloc] initWithAttributedString:aString]; |
| 203 | } else { |
| 204 | marked_text = [[NSMutableAttributedString alloc] initWithString:aString]; |
| 205 | } |
| 206 | if (marked_text.length == 0) { |
| 207 | [self unmarkText]; |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 212 | if (!ds || !ds->has_window(window_id)) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 217 | if (wd.im_active) { |
| 218 | ime_input_event_in_progress = true; |
| 219 | ds->pop_last_key_event(); |
| 220 | ds->update_im_text(Point2i(selectedRange.location, selectedRange.length), String::utf8([[marked_text mutableString] UTF8String])); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | - (void)doCommandBySelector:(SEL)aSelector { |
| 225 | [self tryToPerform:aSelector with:self]; |
| 226 | } |
| 227 | |
| 228 | - (void)unmarkText { |
| 229 | if (ime_input_event_in_progress) { |
| 230 | ime_suppress_next_keyup = true; |
| 231 | } |
| 232 | ime_input_event_in_progress = false; |
| 233 | [[marked_text mutableString] setString:@""]; |
| 234 | |
| 235 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 236 | if (!ds || !ds->has_window(window_id)) { |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 241 | if (wd.im_active) { |
| 242 | ds->update_im_text(Point2i(), String()); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | - (NSArray *)validAttributesForMarkedText { |
| 247 | return [NSArray array]; |
| 248 | } |
| 249 | |
| 250 | - (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange { |
| 251 | return nil; |
| 252 | } |
| 253 | |
| 254 | - (NSUInteger)characterIndexForPoint:(NSPoint)aPoint { |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | - (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange { |
| 259 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 260 | if (!ds || !ds->has_window(window_id)) { |
| 261 | return NSMakeRect(0, 0, 0, 0); |
| 262 | } |
| 263 | |
| 264 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 265 | if (!wd.im_active) { |
| 266 | return NSMakeRect(0, 0, 0, 0); |
| 267 | } |
| 268 | |
| 269 | const NSRect content_rect = [wd.window_view frame]; |
| 270 | const float scale = ds->screen_get_max_scale(); |
| 271 | NSRect point_in_window_rect = NSMakeRect(wd.im_position.x / scale, content_rect.size.height - (wd.im_position.y / scale) - 1, 0, 0); |
| 272 | NSPoint point_on_screen = [wd.window_object convertRectToScreen:point_in_window_rect].origin; |
| 273 | |
| 274 | return NSMakeRect(point_on_screen.x, point_on_screen.y, 0, 0); |
| 275 | } |
| 276 | |
| 277 | - (void)cancelComposition { |
| 278 | [self unmarkText]; |
| 279 | [[NSTextInputContext currentInputContext] discardMarkedText]; |
| 280 | } |
| 281 | |
| 282 | - (void)insertText:(id)aString { |
| 283 | [self insertText:aString replacementRange:NSMakeRange(0, 0)]; |
| 284 | } |
| 285 | |
| 286 | - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange { |
| 287 | NSString *characters; |
| 288 | if ([aString isKindOfClass:[NSAttributedString class]]) { |
| 289 | characters = [aString string]; |
| 290 | } else { |
| 291 | characters = (NSString *)aString; |
| 292 | } |
| 293 | |
| 294 | NSCharacterSet *ctrl_chars = [NSCharacterSet controlCharacterSet]; |
| 295 | NSCharacterSet *wsnl_chars = [NSCharacterSet whitespaceAndNewlineCharacterSet]; |
| 296 | if ([characters rangeOfCharacterFromSet:ctrl_chars].length && [characters rangeOfCharacterFromSet:wsnl_chars].length == 0) { |
| 297 | [[NSTextInputContext currentInputContext] discardMarkedText]; |
| 298 | [self cancelComposition]; |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 303 | if (!ds || !ds->has_window(window_id)) { |
| 304 | [self cancelComposition]; |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | Char16String text; |
| 309 | text.resize_uninitialized([characters length] + 1); |
| 310 | [characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])]; |
| 311 | |
| 312 | String u32text = String::utf16(text.ptr(), text.length()); |
| 313 | |
| 314 | for (int i = 0; i < u32text.length(); i++) { |
| 315 | const char32_t codepoint = u32text[i]; |
| 316 | if ((codepoint & 0xFF00) == 0xF700) { |
| 317 | continue; |
| 318 | } |
| 319 | |
| 320 | DisplayServerMacOS::KeyEvent ke; |
| 321 | |
| 322 | ke.window_id = window_id; |
| 323 | ke.macos_state = 0; |
| 324 | ke.pressed = true; |
| 325 | ke.echo = false; |
| 326 | ke.raw = false; // Can have composite characters. |
| 327 | ke.ime = true; // IME event, do not remove. |
| 328 | ke.keycode = Key::NONE; |
| 329 | ke.physical_keycode = Key::NONE; |
| 330 | ke.key_label = Key::NONE; |
| 331 | ke.unicode = fix_unicode(codepoint); |
| 332 | |
| 333 | ds->push_to_key_event_buffer(ke); |
| 334 | } |
| 335 | [self cancelComposition]; |
| 336 | } |
| 337 | |
| 338 | // MARK: Drag and drop |
| 339 | |
| 340 | - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { |
| 341 | return NSDragOperationCopy; |
| 342 | } |
| 343 | |
| 344 | - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { |
| 345 | return NSDragOperationCopy; |
| 346 | } |
| 347 | |
| 348 | - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 349 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 350 | if (!ds || !ds->has_window(window_id)) { |
| 351 | return NO; |
| 352 | } |
| 353 | |
| 354 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 355 | if (wd.drop_files_callback.is_valid()) { |
| 356 | Vector<String> files; |
| 357 | NSPasteboard *pboard = [sender draggingPasteboard]; |
| 358 | |
| 359 | NSArray *items = pboard.pasteboardItems; |
| 360 | for (NSPasteboardItem *item in items) { |
| 361 | NSString *url = [item stringForType:NSPasteboardTypeFileURL]; |
| 362 | NSString *file = [NSURL URLWithString:url].path; |
| 363 | files.push_back(String::utf8([file UTF8String])); |
| 364 | } |
| 365 | Variant v_files = files; |
| 366 | const Variant *v_args[1] = { &v_files }; |
| 367 | Variant ret; |
| 368 | Callable::CallError ce; |
| 369 | wd.drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce); |
| 370 | if (ce.error != Callable::CallError::CALL_OK) { |
| 371 | ERR_FAIL_V_MSG(NO, vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(wd.drop_files_callback, v_args, 1, ce))); |
| 372 | } |
| 373 | return YES; |
| 374 | } |
| 375 | |
| 376 | return NO; |
| 377 | } |
| 378 | |
| 379 | // MARK: Focus |
| 380 | |
| 381 | - (BOOL)canBecomeKeyView { |
| 382 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 383 | if (!ds || !ds->has_window(window_id)) { |
| 384 | return YES; |
| 385 | } |
| 386 | |
| 387 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 388 | return !wd.no_focus; |
| 389 | } |
| 390 | |
| 391 | - (BOOL)acceptsFirstResponder { |
| 392 | return YES; |
| 393 | } |
| 394 | |
| 395 | // MARK: Mouse |
| 396 | |
| 397 | - (void)cursorUpdate:(NSEvent *)event { |
| 398 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 399 | if (!ds) { |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | ds->cursor_update_shape(); |
| 404 | } |
| 405 | |
| 406 | - (void)processMouseEvent:(NSEvent *)event index:(MouseButton)index pressed:(bool)pressed outofstream:(bool)outofstream { |
| 407 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 408 | if (!ds || !ds->has_window(window_id)) { |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 413 | |
| 414 | Ref<InputEventMouseButton> mb; |
| 415 | mb.instantiate(); |
| 416 | mb->set_window_id(window_id); |
| 417 | if (outofstream) { |
| 418 | ds->update_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]); |
| 419 | } else { |
| 420 | ds->update_mouse_pos(wd, [event locationInWindow]); |
| 421 | } |
| 422 | ds->get_key_modifier_state([event modifierFlags], mb); |
| 423 | mb->set_button_index(index); |
| 424 | mb->set_pressed(pressed); |
| 425 | mb->set_position(wd.mouse_pos); |
| 426 | mb->set_global_position(wd.mouse_pos); |
| 427 | mb->set_button_mask(ds->mouse_get_button_state()); |
| 428 | if (!outofstream && index == MouseButton::LEFT && pressed) { |
| 429 | mb->set_double_click([event clickCount] == 2); |
| 430 | } |
| 431 | |
| 432 | Input::get_singleton()->parse_input_event(mb); |
| 433 | } |
| 434 | |
| 435 | - (void)mouseDown:(NSEvent *)event { |
| 436 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 437 | if (ds && ds->has_window(window_id)) { |
| 438 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 439 | wd.edge = DisplayServerEnums::WINDOW_EDGE_MAX; |
| 440 | } |
| 441 | if (([event modifierFlags] & NSEventModifierFlagControl)) { |
| 442 | mouse_down_control = true; |
| 443 | [self processMouseEvent:event index:MouseButton::RIGHT pressed:true outofstream:false]; |
| 444 | } else { |
| 445 | mouse_down_control = false; |
| 446 | [self processMouseEvent:event index:MouseButton::LEFT pressed:true outofstream:false]; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | - (void)mouseDragged:(NSEvent *)event { |
| 451 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 452 | if (ds && ds->has_window(window_id)) { |
| 453 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 454 | if (wd.edge != DisplayServerEnums::WINDOW_EDGE_MAX) { |
| 455 | Size2i max_size = wd.max_size / ds->screen_get_max_scale(); |
| 456 | Size2i min_size = wd.min_size / ds->screen_get_max_scale(); |
| 457 | NSRect frame = [wd.window_object frame]; |
| 458 | switch (wd.edge) { |
| 459 | case DisplayServerEnums::WINDOW_EDGE_TOP_LEFT: { |
| 460 | int clamped_dx = CLAMP(frame.size.width - event.deltaX, min_size.x, max_size.x) - frame.size.width; |
| 461 | int clamped_dy = CLAMP(frame.size.height - event.deltaY, min_size.y, max_size.y) - frame.size.height; |
| 462 | [wd.window_object setFrame:NSMakeRect(frame.origin.x - clamped_dx, frame.origin.y, frame.size.width + clamped_dx, frame.size.height + clamped_dy) display:YES]; |
| 463 | } break; |
| 464 | case DisplayServerEnums::WINDOW_EDGE_TOP: { |
| 465 | int clamped_dy = CLAMP(frame.size.height - event.deltaY, min_size.y, max_size.y) - frame.size.height; |
| 466 | [wd.window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height + clamped_dy) display:YES]; |
| 467 | } break; |
| 468 | case DisplayServerEnums::WINDOW_EDGE_TOP_RIGHT: { |
| 469 | int clamped_dx = CLAMP(frame.size.width + event.deltaX, min_size.x, max_size.x) - frame.size.width; |
| 470 | int clamped_dy = CLAMP(frame.size.height - event.deltaY, min_size.y, max_size.y) - frame.size.height; |
| 471 | [wd.window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width + clamped_dx, frame.size.height + clamped_dy) display:YES]; |
| 472 | } break; |
| 473 | case DisplayServerEnums::WINDOW_EDGE_LEFT: { |
| 474 | int clamped_dx = CLAMP(frame.size.width - event.deltaX, min_size.x, max_size.x) - frame.size.width; |
| 475 | [wd.window_object setFrame:NSMakeRect(frame.origin.x - clamped_dx, frame.origin.y, frame.size.width + clamped_dx, frame.size.height) display:YES]; |
| 476 | } break; |
| 477 | case DisplayServerEnums::WINDOW_EDGE_RIGHT: { |
| 478 | int clamped_dx = CLAMP(frame.size.width + event.deltaX, min_size.x, max_size.x) - frame.size.width; |
| 479 | [wd.window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width + clamped_dx, frame.size.height) display:YES]; |
| 480 | } break; |
| 481 | case DisplayServerEnums::WINDOW_EDGE_BOTTOM_LEFT: { |
| 482 | int clamped_dx = CLAMP(frame.size.width - event.deltaX, min_size.x, max_size.x) - frame.size.width; |
| 483 | int clamped_dy = CLAMP(frame.size.height + event.deltaY, min_size.y, max_size.y) - frame.size.height; |
| 484 | [wd.window_object setFrame:NSMakeRect(frame.origin.x - clamped_dx, frame.origin.y - clamped_dy, frame.size.width + clamped_dx, frame.size.height + clamped_dy) display:YES]; |
| 485 | } break; |
| 486 | case DisplayServerEnums::WINDOW_EDGE_BOTTOM: { |
| 487 | int clamped_dy = CLAMP(frame.size.height + event.deltaY, min_size.y, max_size.y) - frame.size.height; |
| 488 | [wd.window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y - clamped_dy, frame.size.width, frame.size.height + clamped_dy) display:YES]; |
| 489 | } break; |
| 490 | case DisplayServerEnums::WINDOW_EDGE_BOTTOM_RIGHT: { |
| 491 | int clamped_dx = CLAMP(frame.size.width + event.deltaX, min_size.x, max_size.x) - frame.size.width; |
| 492 | int clamped_dy = CLAMP(frame.size.height + event.deltaY, min_size.y, max_size.y) - frame.size.height; |
| 493 | [wd.window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y - clamped_dy, frame.size.width + clamped_dx, frame.size.height + clamped_dy) display:YES]; |
| 494 | } break; |
| 495 | default: |
| 496 | break; |
| 497 | } |
| 498 | return; |
| 499 | } |
| 500 | } |
| 501 | [self mouseMoved:event]; |
| 502 | } |
| 503 | |
| 504 | - (void)mouseUp:(NSEvent *)event { |
| 505 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 506 | if (ds && ds->has_window(window_id)) { |
| 507 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 508 | wd.edge = DisplayServerEnums::WINDOW_EDGE_MAX; |
| 509 | } |
| 510 | if (mouse_down_control) { |
| 511 | [self processMouseEvent:event index:MouseButton::RIGHT pressed:false outofstream:false]; |
| 512 | } else { |
| 513 | [self processMouseEvent:event index:MouseButton::LEFT pressed:false outofstream:false]; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | - (void)mouseMoved:(NSEvent *)event { |
| 518 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 519 | if (!ds || !ds->has_window(window_id)) { |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 524 | |
| 525 | NSPoint delta = NSMakePoint([event deltaX], [event deltaY]); |
| 526 | NSPoint mpos = [event locationInWindow]; |
| 527 | |
| 528 | if (ds->update_mouse_wrap(wd, delta, mpos, [event timestamp])) { |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | Ref<InputEventMouseMotion> mm; |
| 533 | mm.instantiate(); |
| 534 | |
| 535 | mm->set_window_id(window_id); |
| 536 | mm->set_button_mask(ds->mouse_get_button_state()); |
| 537 | ds->update_mouse_pos(wd, mpos); |
| 538 | mm->set_position(wd.mouse_pos); |
| 539 | mm->set_pressure([event pressure]); |
| 540 | NSEventSubtype subtype = [event subtype]; |
| 541 | if (subtype == NSEventSubtypeTabletPoint) { |
| 542 | const NSPoint p = [event tilt]; |
| 543 | mm->set_tilt(Vector2(p.x, -p.y)); |
| 544 | mm->set_pen_inverted(last_pen_inverted); |
| 545 | } else if (subtype == NSEventSubtypeTabletProximity) { |
| 546 | // Check if using the eraser end of pen only on proximity event. |
| 547 | last_pen_inverted = [event pointingDeviceType] == NSPointingDeviceTypeEraser; |
| 548 | mm->set_pen_inverted(last_pen_inverted); |
| 549 | } |
| 550 | mm->set_global_position(wd.mouse_pos); |
| 551 | mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); |
| 552 | mm->set_screen_velocity(mm->get_velocity()); |
| 553 | const Vector2i relativeMotion = Vector2i(delta.x, delta.y) * ds->screen_get_max_scale(); |
| 554 | mm->set_relative(relativeMotion); |
| 555 | mm->set_relative_screen_position(relativeMotion); |
| 556 | ds->get_key_modifier_state([event modifierFlags], mm); |
| 557 | |
| 558 | const NSRect contentRect = [wd.window_view frame]; |
| 559 | if (NSPointInRect([event locationInWindow], contentRect) && [NSWindow windowNumberAtPoint:[NSEvent mouseLocation] belowWindowWithWindowNumber:0 /*topmost*/] == [wd.window_object windowNumber]) { |
| 560 | ds->mouse_enter_window(window_id); |
| 561 | } |
| 562 | |
| 563 | Input::get_singleton()->parse_input_event(mm); |
| 564 | } |
| 565 | |
| 566 | - (void)rightMouseDown:(NSEvent *)event { |
| 567 | [self processMouseEvent:event index:MouseButton::RIGHT pressed:true outofstream:false]; |
| 568 | } |
| 569 | |
| 570 | - (void)rightMouseDragged:(NSEvent *)event { |
| 571 | [self mouseMoved:event]; |
| 572 | } |
| 573 | |
| 574 | - (void)rightMouseUp:(NSEvent *)event { |
| 575 | [self processMouseEvent:event index:MouseButton::RIGHT pressed:false outofstream:false]; |
| 576 | } |
| 577 | |
| 578 | - (void)otherMouseDown:(NSEvent *)event { |
| 579 | if ((int)[event buttonNumber] == 2) { |
| 580 | [self processMouseEvent:event index:MouseButton::MIDDLE pressed:true outofstream:false]; |
| 581 | } else if ((int)[event buttonNumber] == 3) { |
| 582 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 pressed:true outofstream:false]; |
| 583 | } else if ((int)[event buttonNumber] == 4) { |
| 584 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 pressed:true outofstream:false]; |
| 585 | } else { |
| 586 | return; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | - (void)otherMouseDragged:(NSEvent *)event { |
| 591 | [self mouseMoved:event]; |
| 592 | } |
| 593 | |
| 594 | - (void)otherMouseUp:(NSEvent *)event { |
| 595 | if ((int)[event buttonNumber] == 2) { |
| 596 | [self processMouseEvent:event index:MouseButton::MIDDLE pressed:false outofstream:false]; |
| 597 | } else if ((int)[event buttonNumber] == 3) { |
| 598 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 pressed:false outofstream:false]; |
| 599 | } else if ((int)[event buttonNumber] == 4) { |
| 600 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 pressed:false outofstream:false]; |
| 601 | } else { |
| 602 | return; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | - (void)swipeWithEvent:(NSEvent *)event { |
| 607 | // Swipe gesture on Trackpad/Magic Mouse, or physical back/forward mouse buttons. |
| 608 | if ([event phase] == NSEventPhaseEnded || [event phase] == NSEventPhaseChanged) { |
| 609 | if (Math::is_equal_approx([event deltaX], 1.0)) { |
| 610 | // Swipe left (back). |
| 611 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 pressed:true outofstream:true]; |
| 612 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON1 pressed:false outofstream:true]; |
| 613 | } else if (Math::is_equal_approx([event deltaX], -1.0)) { |
| 614 | // Swipe right (forward). |
| 615 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 pressed:true outofstream:true]; |
| 616 | [self processMouseEvent:event index:MouseButton::MB_XBUTTON2 pressed:false outofstream:true]; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | - (void)mouseExited:(NSEvent *)event { |
| 622 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 623 | if (!ds || !ds->has_window(window_id)) { |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | if (ds->mouse_get_mode() != DisplayServerEnums::MOUSE_MODE_CAPTURED) { |
| 628 | ds->mouse_exit_window(window_id); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | - (void)mouseEntered:(NSEvent *)event { |
| 633 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 634 | if (!ds || !ds->has_window(window_id)) { |
| 635 | return; |
| 636 | } |
| 637 | |
| 638 | if (ds->mouse_get_mode() != DisplayServerEnums::MOUSE_MODE_CAPTURED) { |
| 639 | ds->mouse_enter_window(window_id); |
| 640 | } |
| 641 | |
| 642 | ds->cursor_update_shape(); |
| 643 | } |
| 644 | |
| 645 | - (void)magnifyWithEvent:(NSEvent *)event { |
| 646 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 647 | if (!ds || !ds->has_window(window_id)) { |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 652 | |
| 653 | Ref<InputEventMagnifyGesture> ev; |
| 654 | ev.instantiate(); |
| 655 | ev->set_window_id(window_id); |
| 656 | ds->get_key_modifier_state([event modifierFlags], ev); |
| 657 | ds->update_mouse_pos(wd, [event locationInWindow]); |
| 658 | ev->set_position(wd.mouse_pos); |
| 659 | ev->set_factor([event magnification] + 1.0); |
| 660 | |
| 661 | Input::get_singleton()->parse_input_event(ev); |
| 662 | } |
| 663 | |
| 664 | - (void)updateTrackingAreas { |
| 665 | if (tracking_area != nil) { |
| 666 | [self removeTrackingArea:tracking_area]; |
| 667 | } |
| 668 | |
| 669 | NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | NSTrackingActiveWhenFirstResponder | NSTrackingCursorUpdate | NSTrackingInVisibleRect; |
| 670 | tracking_area = [[NSTrackingArea alloc] initWithRect:[self bounds] options:options owner:self userInfo:nil]; |
| 671 | |
| 672 | [self addTrackingArea:tracking_area]; |
| 673 | [super updateTrackingAreas]; |
| 674 | } |
| 675 | |
| 676 | // MARK: Keyboard |
| 677 | |
| 678 | - (void)keyDown:(NSEvent *)event { |
| 679 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 680 | if (!ds || !ds->has_window(window_id)) { |
| 681 | return; |
| 682 | } |
| 683 | |
| 684 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 685 | |
| 686 | ignore_momentum_scroll = true; |
| 687 | |
| 688 | // Ignore all input if IME input is in progress. |
| 689 | if (!ime_input_event_in_progress) { |
| 690 | NSString *characters = [event characters]; |
| 691 | NSUInteger length = [characters length]; |
| 692 | |
| 693 | if (!wd.im_active && length > 0 && keycode_has_unicode(KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true))) { |
| 694 | // Fallback unicode character handler used if IME is not active. |
| 695 | Char16String text; |
| 696 | text.resize_uninitialized([characters length] + 1); |
| 697 | [characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])]; |
| 698 | |
| 699 | String u32text = String::utf16(text.ptr(), text.length()); |
| 700 | |
| 701 | DisplayServerMacOS::KeyEvent ke; |
| 702 | ke.window_id = window_id; |
| 703 | ke.macos_state = [event modifierFlags]; |
| 704 | ke.pressed = true; |
| 705 | ke.echo = [event isARepeat]; |
| 706 | ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false); |
| 707 | ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); |
| 708 | ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true); |
| 709 | ke.raw = true; |
| 710 | |
| 711 | if (u32text.is_empty()) { |
| 712 | ke.unicode = 0; |
| 713 | ds->push_to_key_event_buffer(ke); |
| 714 | } |
| 715 | for (int i = 0; i < u32text.length(); i++) { |
| 716 | const char32_t codepoint = u32text[i]; |
| 717 | ke.unicode = fix_unicode(codepoint); |
| 718 | ds->push_to_key_event_buffer(ke); |
| 719 | } |
| 720 | } else { |
| 721 | DisplayServerMacOS::KeyEvent ke; |
| 722 | |
| 723 | ke.window_id = window_id; |
| 724 | ke.macos_state = [event modifierFlags]; |
| 725 | ke.pressed = true; |
| 726 | ke.echo = [event isARepeat]; |
| 727 | ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false); |
| 728 | ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); |
| 729 | ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true); |
| 730 | ke.unicode = 0; |
| 731 | ke.location = KeyMappingMacOS::translate_location([event keyCode]); |
| 732 | ke.raw = false; // Can have composite characters. |
| 733 | |
| 734 | ds->push_to_key_event_buffer(ke); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | // Pass events to IME handler |
| 739 | if (wd.im_active) { |
| 740 | [self interpretKeyEvents:[NSArray arrayWithObject:event]]; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | - (void)flagsChanged:(NSEvent *)event { |
| 745 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 746 | if (!ds || !ds->has_window(window_id)) { |
| 747 | return; |
| 748 | } |
| 749 | ignore_momentum_scroll = true; |
| 750 | |
| 751 | DisplayServerMacOS::KeyEvent ke; |
| 752 | |
| 753 | ke.window_id = window_id; |
| 754 | ke.echo = false; |
| 755 | ke.raw = true; |
| 756 | |
| 757 | int key = [event keyCode]; |
| 758 | int mod = [event modifierFlags]; |
| 759 | |
| 760 | if (key == 0x36 || key == 0x37) { |
| 761 | if (mod & NSEventModifierFlagCommand) { |
| 762 | mod &= ~NSEventModifierFlagCommand; |
| 763 | ke.pressed = true; |
| 764 | } else { |
| 765 | ke.pressed = false; |
| 766 | } |
| 767 | } else if (key == 0x38 || key == 0x3c) { |
| 768 | if (mod & NSEventModifierFlagShift) { |
| 769 | mod &= ~NSEventModifierFlagShift; |
| 770 | ke.pressed = true; |
| 771 | } else { |
| 772 | ke.pressed = false; |
| 773 | } |
| 774 | } else if (key == 0x3a || key == 0x3d) { |
| 775 | if (mod & NSEventModifierFlagOption) { |
| 776 | mod &= ~NSEventModifierFlagOption; |
| 777 | ke.pressed = true; |
| 778 | } else { |
| 779 | ke.pressed = false; |
| 780 | } |
| 781 | } else if (key == 0x3b || key == 0x3e) { |
| 782 | if (mod & NSEventModifierFlagControl) { |
| 783 | mod &= ~NSEventModifierFlagControl; |
| 784 | ke.pressed = true; |
| 785 | } else { |
| 786 | ke.pressed = false; |
| 787 | } |
| 788 | } else { |
| 789 | return; |
| 790 | } |
| 791 | |
| 792 | ke.macos_state = mod; |
| 793 | ke.keycode = KeyMappingMacOS::remap_key(key, mod, false); |
| 794 | ke.physical_keycode = KeyMappingMacOS::translate_key(key); |
| 795 | ke.key_label = KeyMappingMacOS::remap_key(key, mod, true); |
| 796 | ke.unicode = 0; |
| 797 | ke.location = KeyMappingMacOS::translate_location(key); |
| 798 | |
| 799 | ds->push_to_key_event_buffer(ke); |
| 800 | } |
| 801 | |
| 802 | - (void)keyUp:(NSEvent *)event { |
| 803 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 804 | if (!ds || !ds->has_window(window_id)) { |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | // Ignore all input if IME input is in progress. |
| 809 | if (ime_suppress_next_keyup) { |
| 810 | ime_suppress_next_keyup = false; |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | if (!ime_input_event_in_progress) { |
| 815 | DisplayServerMacOS::KeyEvent ke; |
| 816 | |
| 817 | ke.window_id = window_id; |
| 818 | ke.macos_state = [event modifierFlags]; |
| 819 | ke.pressed = false; |
| 820 | ke.echo = [event isARepeat]; |
| 821 | ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false); |
| 822 | ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]); |
| 823 | ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true); |
| 824 | ke.unicode = 0; |
| 825 | ke.location = KeyMappingMacOS::translate_location([event keyCode]); |
| 826 | ke.raw = true; |
| 827 | |
| 828 | ds->push_to_key_event_buffer(ke); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | // MARK: Scroll and pan |
| 833 | |
| 834 | - (void)processScrollEvent:(NSEvent *)event button:(MouseButton)button factor:(double)factor { |
| 835 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 836 | if (!ds || !ds->has_window(window_id)) { |
| 837 | return; |
| 838 | } |
| 839 | |
| 840 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 841 | MouseButtonMask mask = mouse_button_to_mask(button); |
| 842 | |
| 843 | Ref<InputEventMouseButton> sc; |
| 844 | sc.instantiate(); |
| 845 | |
| 846 | sc->set_window_id(window_id); |
| 847 | ds->get_key_modifier_state([event modifierFlags], sc); |
| 848 | sc->set_button_index(button); |
| 849 | sc->set_factor(factor); |
| 850 | sc->set_pressed(true); |
| 851 | sc->set_position(wd.mouse_pos); |
| 852 | sc->set_global_position(wd.mouse_pos); |
| 853 | BitField<MouseButtonMask> scroll_mask = ds->mouse_get_button_state(); |
| 854 | scroll_mask.set_flag(mask); |
| 855 | sc->set_button_mask(scroll_mask); |
| 856 | |
| 857 | Input::get_singleton()->parse_input_event(sc); |
| 858 | |
| 859 | sc.instantiate(); |
| 860 | sc->set_window_id(window_id); |
| 861 | sc->set_button_index(button); |
| 862 | sc->set_factor(factor); |
| 863 | sc->set_pressed(false); |
| 864 | sc->set_position(wd.mouse_pos); |
| 865 | sc->set_global_position(wd.mouse_pos); |
| 866 | scroll_mask.clear_flag(mask); |
| 867 | sc->set_button_mask(scroll_mask); |
| 868 | |
| 869 | Input::get_singleton()->parse_input_event(sc); |
| 870 | } |
| 871 | |
| 872 | - (void)processPanEvent:(NSEvent *)event dx:(double)dx dy:(double)dy { |
| 873 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 874 | if (!ds || !ds->has_window(window_id)) { |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 879 | |
| 880 | Ref<InputEventPanGesture> pg; |
| 881 | pg.instantiate(); |
| 882 | |
| 883 | pg->set_window_id(window_id); |
| 884 | ds->get_key_modifier_state([event modifierFlags], pg); |
| 885 | pg->set_position(wd.mouse_pos); |
| 886 | pg->set_delta(Vector2(-dx, -dy)); |
| 887 | |
| 888 | Input::get_singleton()->parse_input_event(pg); |
| 889 | } |
| 890 | |
| 891 | - (void)scrollWheel:(NSEvent *)event { |
| 892 | DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton(); |
| 893 | if (!ds || !ds->has_window(window_id)) { |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | DisplayServerMacOS::WindowData &wd = ds->get_window(window_id); |
| 898 | ds->update_mouse_pos(wd, [event locationInWindow]); |
| 899 | |
| 900 | double delta_x = [event deltaX]; |
| 901 | double delta_y = [event deltaY]; |
| 902 | |
| 903 | if ([event hasPreciseScrollingDeltas]) { |
| 904 | delta_x = [event scrollingDeltaX]; |
| 905 | delta_y = [event scrollingDeltaY]; |
| 906 | } |
| 907 | |
| 908 | if ([event momentumPhase] != NSEventPhaseNone) { |
| 909 | if (ignore_momentum_scroll) { |
| 910 | return; |
| 911 | } |
| 912 | } else { |
| 913 | ignore_momentum_scroll = false; |
| 914 | } |
| 915 | |
| 916 | if ([event phase] != NSEventPhaseNone || [event momentumPhase] != NSEventPhaseNone) { |
| 917 | [self processPanEvent:event dx:delta_x dy:delta_y]; |
| 918 | } else { |
| 919 | double delta_x_abs = Math::abs(delta_x); |
| 920 | double delta_y_abs = Math::abs(delta_y); |
| 921 | |
| 922 | if (!Math::is_zero_approx(delta_x_abs)) { |
| 923 | [self processScrollEvent:event button:(0 > delta_x ? MouseButton::WHEEL_RIGHT : MouseButton::WHEEL_LEFT) factor:delta_x_abs]; |
| 924 | } |
| 925 | if (!Math::is_zero_approx(delta_y_abs)) { |
| 926 | [self processScrollEvent:event button:(0 < delta_y ? MouseButton::WHEEL_UP : MouseButton::WHEEL_DOWN) factor:delta_y_abs]; |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | @end |