2019-01-28 19:46:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-07-01 15:12:19 +00:00
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkUtils.h"
|
|
|
|
#include "tools/sk_app/mac/WindowContextFactory_mac.h"
|
|
|
|
#include "tools/sk_app/mac/Window_mac.h"
|
2019-08-29 14:39:22 +00:00
|
|
|
#include "tools/skui/ModifierKey.h"
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-02-13 17:26:35 +00:00
|
|
|
@interface WindowDelegate : NSObject<NSWindowDelegate>
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-02-13 17:26:35 +00:00
|
|
|
- (WindowDelegate*)initWithWindow:(sk_app::Window_mac*)initWindow;
|
2019-01-28 19:46:04 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2019-02-13 17:26:35 +00:00
|
|
|
@interface MainView : NSView
|
2019-05-16 14:31:56 +00:00
|
|
|
|
|
|
|
- (MainView*)initWithWindow:(sk_app::Window_mac*)initWindow;
|
|
|
|
|
2019-01-28 19:46:04 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
using sk_app::Window;
|
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
2019-02-13 17:26:35 +00:00
|
|
|
SkTDynamicHash<Window_mac, NSInteger> Window_mac::gWindowMap;
|
2019-01-28 19:46:04 +00:00
|
|
|
|
|
|
|
Window* Window::CreateNativeWindow(void*) {
|
|
|
|
Window_mac* window = new Window_mac();
|
|
|
|
if (!window->initWindow()) {
|
|
|
|
delete window;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window_mac::initWindow() {
|
|
|
|
// we already have a window
|
|
|
|
if (fWindow) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
// Create a delegate to track certain events
|
|
|
|
WindowDelegate* delegate = [[WindowDelegate alloc] initWithWindow:this];
|
|
|
|
if (nil == delegate) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Cocoa window
|
2019-01-28 19:46:04 +00:00
|
|
|
constexpr int initialWidth = 1280;
|
|
|
|
constexpr int initialHeight = 960;
|
2019-05-16 14:31:56 +00:00
|
|
|
NSRect windowRect = NSMakeRect(100, 100, initialWidth, initialHeight);
|
2019-01-28 19:46:04 +00:00
|
|
|
|
|
|
|
NSUInteger windowStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask |
|
|
|
|
NSMiniaturizableWindowMask);
|
|
|
|
|
|
|
|
fWindow = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle
|
|
|
|
backing:NSBackingStoreBuffered defer:NO];
|
|
|
|
if (nil == fWindow) {
|
2019-05-16 14:31:56 +00:00
|
|
|
[delegate release];
|
2019-01-28 19:46:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create view
|
2020-07-01 15:12:19 +00:00
|
|
|
MainView* view = [[MainView alloc] initWithWindow:this];
|
2019-01-28 19:46:04 +00:00
|
|
|
if (nil == view) {
|
|
|
|
[fWindow release];
|
2019-05-16 14:31:56 +00:00
|
|
|
[delegate release];
|
2019-01-28 19:46:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fWindow setContentView:view];
|
2019-05-16 14:31:56 +00:00
|
|
|
[fWindow makeFirstResponder:view];
|
|
|
|
[fWindow setDelegate:delegate];
|
|
|
|
[fWindow setAcceptsMouseMovedEvents:YES];
|
|
|
|
[fWindow setRestorable:NO];
|
|
|
|
|
|
|
|
// Should be retained by window now
|
|
|
|
[view release];
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-02-13 17:26:35 +00:00
|
|
|
fWindowNumber = fWindow.windowNumber;
|
|
|
|
gWindowMap.add(this);
|
|
|
|
|
2019-01-28 19:46:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window_mac::closeWindow() {
|
2019-02-13 17:26:35 +00:00
|
|
|
if (nil != fWindow) {
|
|
|
|
gWindowMap.remove(fWindowNumber);
|
|
|
|
if (sk_app::Window_mac::gWindowMap.count() < 1) {
|
|
|
|
[NSApp terminate:fWindow];
|
|
|
|
}
|
2019-05-16 14:31:56 +00:00
|
|
|
[fWindow close];
|
2019-02-13 17:26:35 +00:00
|
|
|
fWindow = nil;
|
|
|
|
}
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window_mac::setTitle(const char* title) {
|
2020-07-01 15:12:19 +00:00
|
|
|
if (NSString* titleStr = [NSString stringWithUTF8String:title]) {
|
|
|
|
[fWindow setTitle:titleStr];
|
|
|
|
}
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window_mac::show() {
|
2019-05-16 14:31:56 +00:00
|
|
|
[fWindow orderFront:nil];
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2019-01-28 19:46:04 +00:00
|
|
|
[fWindow makeKeyAndOrderFront:NSApp];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window_mac::attach(BackendType attachType) {
|
|
|
|
this->initWindow();
|
|
|
|
|
|
|
|
window_context_factory::MacWindowInfo info;
|
2019-02-13 17:26:35 +00:00
|
|
|
info.fMainView = [fWindow contentView];
|
2019-01-28 19:46:04 +00:00
|
|
|
switch (attachType) {
|
2019-08-02 19:04:52 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
case kDawn_BackendType:
|
|
|
|
fWindowContext = MakeDawnMTLForMac(info, fRequestedDisplayParams);
|
|
|
|
break;
|
|
|
|
#endif
|
2019-02-14 19:07:46 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
case kVulkan_BackendType:
|
2019-08-01 20:21:49 +00:00
|
|
|
fWindowContext = MakeVulkanForMac(info, fRequestedDisplayParams);
|
2019-02-14 19:07:46 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2019-02-08 20:36:14 +00:00
|
|
|
#ifdef SK_METAL
|
|
|
|
case kMetal_BackendType:
|
2019-08-01 20:21:49 +00:00
|
|
|
fWindowContext = MakeMetalForMac(info, fRequestedDisplayParams);
|
2019-02-08 20:36:14 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2019-01-28 19:46:04 +00:00
|
|
|
case kNativeGL_BackendType:
|
|
|
|
default:
|
2019-08-01 20:21:49 +00:00
|
|
|
fWindowContext = MakeGLForMac(info, fRequestedDisplayParams);
|
2019-01-28 19:46:04 +00:00
|
|
|
break;
|
2020-03-19 19:54:28 +00:00
|
|
|
#else
|
|
|
|
default:
|
|
|
|
#endif
|
|
|
|
case kRaster_BackendType:
|
|
|
|
fWindowContext = MakeRasterForMac(info, fRequestedDisplayParams);
|
|
|
|
break;
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
this->onBackendCreated();
|
|
|
|
|
2020-07-01 15:12:19 +00:00
|
|
|
return SkToBool(fWindowContext);
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
void Window_mac::PaintWindows() {
|
2020-03-14 21:22:45 +00:00
|
|
|
gWindowMap.foreach([&](Window_mac* window) {
|
|
|
|
if (window->fIsContentInvalidated) {
|
|
|
|
window->onPaint();
|
2019-05-16 14:31:56 +00:00
|
|
|
}
|
2020-03-14 21:22:45 +00:00
|
|
|
});
|
2019-05-16 14:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sk_app
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
@implementation WindowDelegate {
|
|
|
|
sk_app::Window_mac* fWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WindowDelegate*)initWithWindow:(sk_app::Window_mac *)initWindow {
|
|
|
|
fWindow = initWindow;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResize:(NSNotification *)notification {
|
|
|
|
const NSRect mainRect = [fWindow->window().contentView bounds];
|
|
|
|
|
|
|
|
fWindow->onResize(mainRect.size.width, mainRect.size.height);
|
2019-05-20 14:49:41 +00:00
|
|
|
fWindow->inval();
|
2019-05-16 14:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(NSWindow*)sender {
|
|
|
|
fWindow->closeWindow();
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
static skui::Key get_key(unsigned short vk) {
|
2019-01-28 19:46:04 +00:00
|
|
|
// This will work with an ANSI QWERTY keyboard.
|
|
|
|
// Something more robust would be needed to support alternate keyboards.
|
|
|
|
static const struct {
|
|
|
|
unsigned short fVK;
|
2020-07-01 15:12:19 +00:00
|
|
|
skui::Key fKey;
|
2019-01-28 19:46:04 +00:00
|
|
|
} gPair[] = {
|
2020-07-01 15:12:19 +00:00
|
|
|
{ kVK_Delete, skui::Key::kBack },
|
|
|
|
{ kVK_Return, skui::Key::kOK },
|
|
|
|
{ kVK_UpArrow, skui::Key::kUp },
|
|
|
|
{ kVK_DownArrow, skui::Key::kDown },
|
|
|
|
{ kVK_LeftArrow, skui::Key::kLeft },
|
|
|
|
{ kVK_RightArrow, skui::Key::kRight },
|
|
|
|
{ kVK_Tab, skui::Key::kTab },
|
|
|
|
{ kVK_PageUp, skui::Key::kPageUp },
|
|
|
|
{ kVK_PageDown, skui::Key::kPageDown },
|
|
|
|
{ kVK_Home, skui::Key::kHome },
|
|
|
|
{ kVK_End, skui::Key::kEnd },
|
|
|
|
{ kVK_ForwardDelete, skui::Key::kDelete },
|
|
|
|
{ kVK_Escape, skui::Key::kEscape },
|
|
|
|
{ kVK_Shift, skui::Key::kShift },
|
|
|
|
{ kVK_RightShift, skui::Key::kShift },
|
|
|
|
{ kVK_Control, skui::Key::kCtrl },
|
|
|
|
{ kVK_RightControl, skui::Key::kCtrl },
|
|
|
|
{ kVK_Option, skui::Key::kOption },
|
|
|
|
{ kVK_RightOption, skui::Key::kOption },
|
|
|
|
{ kVK_Command, skui::Key::kSuper },
|
|
|
|
{ kVK_RightCommand, skui::Key::kSuper },
|
|
|
|
{ kVK_ANSI_A, skui::Key::kA },
|
|
|
|
{ kVK_ANSI_C, skui::Key::kC },
|
|
|
|
{ kVK_ANSI_V, skui::Key::kV },
|
|
|
|
{ kVK_ANSI_X, skui::Key::kX },
|
|
|
|
{ kVK_ANSI_Y, skui::Key::kY },
|
|
|
|
{ kVK_ANSI_Z, skui::Key::kZ },
|
2019-01-28 19:46:04 +00:00
|
|
|
};
|
2020-07-01 15:12:19 +00:00
|
|
|
|
2019-01-28 19:46:04 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
|
|
|
|
if (gPair[i].fVK == vk) {
|
|
|
|
return gPair[i].fKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
return skui::Key::kNONE;
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
static skui::ModifierKey get_modifiers(const NSEvent* event) {
|
2019-01-28 19:46:04 +00:00
|
|
|
NSUInteger modifierFlags = [event modifierFlags];
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::ModifierKey modifiers = skui::ModifierKey::kNone;
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-07-31 16:10:08 +00:00
|
|
|
if (modifierFlags & NSEventModifierFlagCommand) {
|
2019-08-29 14:39:22 +00:00
|
|
|
modifiers |= skui::ModifierKey::kCommand;
|
2019-07-31 16:10:08 +00:00
|
|
|
}
|
2019-01-28 19:46:04 +00:00
|
|
|
if (modifierFlags & NSEventModifierFlagShift) {
|
2019-08-29 14:39:22 +00:00
|
|
|
modifiers |= skui::ModifierKey::kShift;
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
if (modifierFlags & NSEventModifierFlagControl) {
|
2019-08-29 14:39:22 +00:00
|
|
|
modifiers |= skui::ModifierKey::kControl;
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
if (modifierFlags & NSEventModifierFlagOption) {
|
2019-08-29 14:39:22 +00:00
|
|
|
modifiers |= skui::ModifierKey::kOption;
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 15:12:19 +00:00
|
|
|
if ((NSKeyDown == [event type] || NSKeyUp == [event type]) && ![event isARepeat]) {
|
2019-08-29 14:39:22 +00:00
|
|
|
modifiers |= skui::ModifierKey::kFirstPress;
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
@implementation MainView {
|
|
|
|
sk_app::Window_mac* fWindow;
|
|
|
|
// A TrackingArea prevents us from capturing events outside the view
|
|
|
|
NSTrackingArea* fTrackingArea;
|
2020-07-01 15:12:19 +00:00
|
|
|
// We keep track of the state of the modifier keys on each event in order to synthesize
|
|
|
|
// key-up/down events for each modifier.
|
|
|
|
skui::ModifierKey fLastModifiers;
|
2019-02-13 17:26:35 +00:00
|
|
|
}
|
2019-01-30 15:33:36 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (MainView*)initWithWindow:(sk_app::Window_mac *)initWindow {
|
|
|
|
self = [super init];
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
fWindow = initWindow;
|
|
|
|
fTrackingArea = nil;
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
[self updateTrackingAreas];
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
return self;
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[fTrackingArea release];
|
|
|
|
[super dealloc];
|
2019-02-28 18:49:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (BOOL)isOpaque {
|
|
|
|
return YES;
|
|
|
|
}
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (BOOL)canBecomeKeyView {
|
|
|
|
return YES;
|
|
|
|
}
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (BOOL)acceptsFirstResponder {
|
|
|
|
return YES;
|
2019-02-13 17:26:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)updateTrackingAreas {
|
|
|
|
if (fTrackingArea != nil) {
|
|
|
|
[self removeTrackingArea:fTrackingArea];
|
|
|
|
[fTrackingArea release];
|
|
|
|
}
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
const NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
|
|
|
|
NSTrackingActiveInKeyWindow |
|
|
|
|
NSTrackingEnabledDuringMouseDrag |
|
|
|
|
NSTrackingCursorUpdate |
|
|
|
|
NSTrackingInVisibleRect |
|
|
|
|
NSTrackingAssumeInside;
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
fTrackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
2020-07-01 15:12:19 +00:00
|
|
|
options:options
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
[self addTrackingArea:fTrackingArea];
|
|
|
|
[super updateTrackingAreas];
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 17:14:21 +00:00
|
|
|
- (skui::ModifierKey) updateModifierKeys:(NSEvent*) event {
|
2020-07-01 15:12:19 +00:00
|
|
|
using sknonstd::Any;
|
|
|
|
|
2020-07-06 17:14:21 +00:00
|
|
|
skui::ModifierKey modifiers = get_modifiers(event);
|
2020-07-01 15:12:19 +00:00
|
|
|
skui::ModifierKey changed = modifiers ^ fLastModifiers;
|
|
|
|
fLastModifiers = modifiers;
|
|
|
|
|
|
|
|
struct ModMap {
|
|
|
|
skui::ModifierKey modifier;
|
|
|
|
skui::Key key;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Map each modifier bit to the equivalent skui Key and send key-up/down events.
|
|
|
|
for (const ModMap& cur : {ModMap{skui::ModifierKey::kCommand, skui::Key::kSuper},
|
|
|
|
ModMap{skui::ModifierKey::kShift, skui::Key::kShift},
|
|
|
|
ModMap{skui::ModifierKey::kControl, skui::Key::kCtrl},
|
|
|
|
ModMap{skui::ModifierKey::kOption, skui::Key::kOption}}) {
|
|
|
|
if (Any(changed & cur.modifier)) {
|
|
|
|
const skui::InputState state = Any(modifiers & cur.modifier) ? skui::InputState::kDown
|
|
|
|
: skui::InputState::kUp;
|
|
|
|
(void) fWindow->onKey(cur.key, state, modifiers);
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 17:14:21 +00:00
|
|
|
|
|
|
|
return modifiers;
|
2020-07-01 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)performKeyEquivalent:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
[self updateModifierKeys:event];
|
|
|
|
|
|
|
|
// By default, unhandled key equivalents send -keyDown events; unfortunately, they do not send
|
|
|
|
// a matching -keyUp. In other words, we can claim that we didn't handle the event and OS X will
|
|
|
|
// turn this event into a -keyDown automatically, but we need to synthesize a matching -keyUp on
|
|
|
|
// a later frame. Since we only read the modifiers and key code from the event, we can reuse
|
|
|
|
// this "key-equivalent" event as a "key up".
|
2020-07-01 15:12:19 +00:00
|
|
|
[self performSelector:@selector(keyUp:) withObject:event afterDelay:0.1];
|
2020-07-06 17:14:21 +00:00
|
|
|
return NO;
|
2020-07-01 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)keyDown:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
skui::ModifierKey modifiers = [self updateModifierKeys:event];
|
2020-07-01 15:12:19 +00:00
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::Key key = get_key([event keyCode]);
|
|
|
|
if (key != skui::Key::kNONE) {
|
2020-07-01 15:12:19 +00:00
|
|
|
if (!fWindow->onKey(key, skui::InputState::kDown, modifiers)) {
|
2019-08-29 14:39:22 +00:00
|
|
|
if (skui::Key::kEscape == key) {
|
2019-05-16 14:31:56 +00:00
|
|
|
[NSApp terminate:fWindow->window()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
NSString* characters = [event charactersIgnoringModifiers];
|
|
|
|
NSUInteger len = [characters length];
|
|
|
|
if (len > 0) {
|
|
|
|
unichar* charBuffer = new unichar[len+1];
|
|
|
|
[characters getCharacters:charBuffer range:NSMakeRange(0, len)];
|
|
|
|
for (NSUInteger i = 0; i < len; ++i) {
|
2020-07-01 15:12:19 +00:00
|
|
|
(void) fWindow->onChar((SkUnichar) charBuffer[i], modifiers);
|
2019-05-16 14:31:56 +00:00
|
|
|
}
|
|
|
|
delete [] charBuffer;
|
|
|
|
}
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)keyUp:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
skui::ModifierKey modifiers = [self updateModifierKeys:event];
|
2020-07-01 15:12:19 +00:00
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::Key key = get_key([event keyCode]);
|
|
|
|
if (key != skui::Key::kNONE) {
|
2020-07-01 15:12:19 +00:00
|
|
|
(void) fWindow->onKey(key, skui::InputState::kUp, modifiers);
|
2019-05-16 14:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2020-07-01 15:12:19 +00:00
|
|
|
-(void)flagsChanged:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
[self updateModifierKeys:event];
|
2020-07-01 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)mouseDown:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
skui::ModifierKey modifiers = [self updateModifierKeys:event];
|
2020-07-01 15:12:19 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
const NSPoint pos = [event locationInWindow];
|
|
|
|
const NSRect rect = [fWindow->window().contentView frame];
|
2020-07-01 15:12:19 +00:00
|
|
|
fWindow->onMouse(pos.x, rect.size.height - pos.y, skui::InputState::kDown, modifiers);
|
2019-05-16 14:31:56 +00:00
|
|
|
}
|
2019-02-13 17:26:35 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)mouseUp:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
skui::ModifierKey modifiers = [self updateModifierKeys:event];
|
2020-07-01 15:12:19 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
const NSPoint pos = [event locationInWindow];
|
|
|
|
const NSRect rect = [fWindow->window().contentView frame];
|
2020-07-01 15:12:19 +00:00
|
|
|
fWindow->onMouse(pos.x, rect.size.height - pos.y, skui::InputState::kUp, modifiers);
|
2019-02-13 17:26:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)mouseDragged:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
[self updateModifierKeys:event];
|
2019-05-16 14:31:56 +00:00
|
|
|
[self mouseMoved:event];
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)mouseMoved:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
skui::ModifierKey modifiers = [self updateModifierKeys:event];
|
2020-07-01 15:12:19 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
const NSPoint pos = [event locationInWindow];
|
|
|
|
const NSRect rect = [fWindow->window().contentView frame];
|
2020-07-01 15:12:19 +00:00
|
|
|
fWindow->onMouse(pos.x, rect.size.height - pos.y, skui::InputState::kMove, modifiers);
|
2019-01-28 19:46:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)scrollWheel:(NSEvent *)event {
|
2020-07-06 17:14:21 +00:00
|
|
|
skui::ModifierKey modifiers = [self updateModifierKeys:event];
|
2020-07-01 15:12:19 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
// TODO: support hasPreciseScrollingDeltas?
|
2020-07-01 15:12:19 +00:00
|
|
|
fWindow->onMouseWheel([event scrollingDeltaY], modifiers);
|
2019-02-13 17:26:35 +00:00
|
|
|
}
|
2019-01-28 19:46:04 +00:00
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
- (void)drawRect:(NSRect)rect {
|
2019-05-20 14:49:41 +00:00
|
|
|
fWindow->onPaint();
|
2019-02-13 17:26:35 +00:00
|
|
|
}
|
2019-05-16 14:31:56 +00:00
|
|
|
|
2019-01-28 19:46:04 +00:00
|
|
|
@end
|