diff options
| author | Tomas Andrle <tomovo@gmail.com> | 2025-10-22 19:39:02 +0200 |
|---|---|---|
| committer | Tomas Andrle <tomovo@gmail.com> | 2025-10-22 20:00:51 +0200 |
| commit | c1e712c80621664ee7ce5f82dd69d79c85e917d4 (patch) | |
| tree | a96052132b3c1cfb702adb8277abb76d9ba58b17 /sokol_app.h | |
| parent | 8147fcafc1c4637357ad1696611d1700247144ab (diff) | |
tvos defines redefined, press handling code in C function like the rest.
Diffstat (limited to 'sokol_app.h')
| -rw-r--r-- | sokol_app.h | 79 |
1 files changed, 44 insertions, 35 deletions
diff --git a/sokol_app.h b/sokol_app.h index dfd4620d..3be01092 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -2148,6 +2148,9 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); } #if !defined(SOKOL_METAL) && !defined(SOKOL_GLES3) #error("sokol_app.h: unknown 3D API selected for iOS, must be SOKOL_METAL or SOKOL_GLES3") #endif + #if TARGET_OS_TV + #define _SAPP_TVOS (1) + #endif #endif #elif defined(__EMSCRIPTEN__) /* emscripten (asm.js or wasm) */ @@ -5236,7 +5239,7 @@ _SOKOL_PRIVATE void _sapp_ios_mtl_init(void) { */ _sapp.ios.view.autoResizeDrawable = false; _sapp.ios.view.userInteractionEnabled = YES; -#if TARGET_OS_IPHONE && !TARGET_OS_TV +#if !defined(_SAPP_TVOS) _sapp.ios.view.multipleTouchEnabled = YES; #endif _sapp.ios.view_ctrl = [[UIViewController alloc] init]; @@ -5341,6 +5344,37 @@ _SOKOL_PRIVATE void _sapp_ios_app_event(sapp_event_type type) { } } +#if defined(_SAPP_TVOS) +_SOKOL_PRIVATE void _sapp_tvos_press_event(UIPressType press, sapp_event_type type) { + sapp_keycode key; + switch (press) { + case UIPressTypeUpArrow: key = SAPP_KEYCODE_UP; break; + case UIPressTypeDownArrow: key = SAPP_KEYCODE_DOWN; break; + case UIPressTypeLeftArrow: key = SAPP_KEYCODE_LEFT; break; + case UIPressTypeRightArrow: key = SAPP_KEYCODE_RIGHT; break; + case UIPressTypeSelect: key = SAPP_KEYCODE_ENTER; break; + case UIPressTypeMenu: key = SAPP_KEYCODE_MENU; break; + case UIPressTypePlayPause: key = SAPP_KEYCODE_MENU; break; + default: key = SAPP_KEYCODE_INVALID; break; + } + if (key != SAPP_KEYCODE_INVALID) { + _sapp_init_event(type); + _sapp.event.key_code = key; + _sapp.event.key_repeat = false; + _sapp.event.modifiers = 0; + _sapp_call_event(&_sapp.event); + } +} + +_SOKOL_PRIVATE void _sapp_tvos_press_event(sapp_event_type type, NSSet<UIPress *>* presses) { + if (_sapp_events_enabled()) { + for ( UIPress *press in presses ) { + _sapp_tvos_press_event(press.type, type); + } + } +} +#endif + _SOKOL_PRIVATE void _sapp_ios_touch_event(sapp_event_type type, NSSet<UITouch *>* touches, UIEvent* event) { if (_sapp_events_enabled()) { _sapp_init_event(type); @@ -5396,7 +5430,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { _sapp.ios.textfield.delegate = _sapp.ios.textfield_dlg; [_sapp.ios.view_ctrl.view addSubview:_sapp.ios.textfield]; -#if TARGET_OS_IPHONE && !TARGET_OS_TV +#if !defined(_SAPP_TVOS) [[NSNotificationCenter defaultCenter] addObserver:_sapp.ios.textfield_dlg selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; @@ -5469,7 +5503,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { - (void)keyboardWasShown:(NSNotification*)notif { _sapp.onscreen_keyboard_shown = true; /* query the keyboard's size, and modify the content view's size */ -#if TARGET_OS_IPHONE && !TARGET_OS_TV +#if !defined(_SAPP_TVOS) if (_sapp.desc.ios_keyboard_resizes_canvas) { NSDictionary* info = notif.userInfo; CGFloat kbd_h = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; @@ -5487,7 +5521,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { } - (void)keyboardDidChangeFrame:(NSNotification*)notif { /* this is for the case when the screen rotation changes while the keyboard is open */ -#if TARGET_OS_IPHONE && !TARGET_OS_TV +#if !defined(_SAPP_TVOS) if (_sapp.onscreen_keyboard_shown && _sapp.desc.ios_keyboard_resizes_canvas) { NSDictionary* info = notif.userInfo; CGFloat kbd_h = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; @@ -5556,45 +5590,20 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { - (BOOL)isOpaque { return YES; } -- (void)pressEvent:(UIPressType)press type:(sapp_event_type)type { - if (_sapp_events_enabled()) { - sapp_keycode key; - switch (press) { - case UIPressTypeUpArrow: key = SAPP_KEYCODE_UP; break; - case UIPressTypeDownArrow: key = SAPP_KEYCODE_DOWN; break; - case UIPressTypeLeftArrow: key = SAPP_KEYCODE_LEFT; break; - case UIPressTypeRightArrow: key = SAPP_KEYCODE_RIGHT; break; - case UIPressTypeSelect: key = SAPP_KEYCODE_ENTER; break; - case UIPressTypeMenu: key = SAPP_KEYCODE_MENU; break; - case UIPressTypePlayPause: key = SAPP_KEYCODE_MENU; break; - default: key = SAPP_KEYCODE_INVALID; break; - } - if (key != SAPP_KEYCODE_INVALID) { - _sapp_init_event(type); - _sapp.event.key_code = key; - _sapp.event.key_repeat = false; - _sapp.event.modifiers = 0; - _sapp_call_event(&_sapp.event); - } - } -} +#if defined(_SAPP_TVOS) - (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { - for ( UIPress *press in presses ) { - [self pressEvent: press.type type: SAPP_EVENTTYPE_KEY_DOWN]; - } + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_DOWN, presses); } - (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { + // Not sure if we need this, keeping it in case I find a use-case while testing. } - (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { - for ( UIPress *press in presses ) { - [self pressEvent: press.type type: SAPP_EVENTTYPE_KEY_UP]; - } + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_UP, presses); } - (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { - for ( UIPress *press in presses ) { - [self pressEvent: press.type type: SAPP_EVENTTYPE_KEY_UP]; - } + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_UP, presses); } +#endif - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent*)event { _sapp_ios_touch_event(SAPP_EVENTTYPE_TOUCHES_BEGAN, touches, event); } |