diff options
| author | Andre Weissflog <floooh@gmail.com> | 2025-11-19 13:29:12 +0100 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2025-11-19 13:29:12 +0100 |
| commit | bf8ebc538e6b6edf2d30892f657c4d3a34c040c6 (patch) | |
| tree | 73fbe160da6fe6a48c1474ef244f1dee5f92c0cb /sokol_app.h | |
| parent | 09a31200a381974c0ecd2b1e94be9f66f62a35a5 (diff) | |
| parent | b517f27e7d6bdefc7883110e42dab27cba800b50 (diff) | |
Merge branch 'master' into experimental-vulkan
Diffstat (limited to 'sokol_app.h')
| -rw-r--r-- | sokol_app.h | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/sokol_app.h b/sokol_app.h index 2edc2891..b6638088 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -1206,6 +1206,11 @@ doesn't matter if the application is started from the command line or via double-click. + NOTE: setting both win32_console_attach and win32_console_create + to true also makes sense and has the effect that output + will appear in the existing terminal when started from the cmdline, and + otherwise (when started via double-click) will open a console window. + MEMORY ALLOCATION OVERRIDE ========================== You can override the memory allocation functions at initialization time @@ -2278,6 +2283,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 @@ -6098,7 +6106,9 @@ _SOKOL_PRIVATE void _sapp_ios_mtl_init(void) { */ _sapp.ios.view.autoResizeDrawable = false; _sapp.ios.view.userInteractionEnabled = YES; +#if !defined(_SAPP_TVOS) _sapp.ios.view.multipleTouchEnabled = YES; +#endif _sapp.ios.view_ctrl = [[UIViewController alloc] init]; _sapp.ios.view_ctrl.modalPresentationStyle = UIModalPresentationFullScreen; _sapp.ios.view_ctrl.view = _sapp.ios.view; @@ -6201,6 +6211,31 @@ _SOKOL_PRIVATE void _sapp_ios_app_event(sapp_event_type type) { } } +_SOKOL_PRIVATE void _sapp_tvos_press_event(sapp_event_type type, NSSet<UIPress *>* presses) { + if (_sapp_events_enabled()) { + for (UIPress *press in presses) { + sapp_keycode key = SAPP_KEYCODE_INVALID; + switch (press.type) { + 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_PAUSE; break; + default: 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_ios_touch_event(sapp_event_type type, NSSet<UITouch *>* touches, UIEvent* event) { if (_sapp_events_enabled()) { _sapp_init_event(type); @@ -6256,6 +6291,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 !defined(_SAPP_TVOS) [[NSNotificationCenter defaultCenter] addObserver:_sapp.ios.textfield_dlg selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; @@ -6265,6 +6301,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { [[NSNotificationCenter defaultCenter] addObserver:_sapp.ios.textfield_dlg selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil]; +#endif } if (shown) { // setting the text field as first responder brings up the onscreen keyboard @@ -6327,6 +6364,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 !defined(_SAPP_TVOS) if (_sapp.desc.ios.keyboard_resizes_canvas) { NSDictionary* info = notif.userInfo; CGFloat kbd_h = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; @@ -6334,6 +6372,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { view_frame.size.height -= kbd_h; _sapp.ios.view.frame = view_frame; } +#endif } - (void)keyboardWillBeHidden:(NSNotification*)notif { _sapp.onscreen_keyboard_shown = false; @@ -6343,6 +6382,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 !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; @@ -6350,6 +6390,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { view_frame.size.height -= kbd_h; _sapp.ios.view.frame = view_frame; } +#endif } - (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string { if (_sapp_events_enabled()) { @@ -6410,6 +6451,17 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { - (BOOL)isOpaque { return YES; } +- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_DOWN, presses); +} +- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { +} +- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_UP, presses); +} +- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { + _sapp_tvos_press_event(SAPP_EVENTTYPE_KEY_UP, presses); +} - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent*)event { _sapp_ios_touch_event(SAPP_EVENTTYPE_TOUCHES_BEGAN, touches, event); } @@ -9372,11 +9424,12 @@ _SOKOL_PRIVATE void _sapp_win32_destroy_icons(void) { _SOKOL_PRIVATE void _sapp_win32_init_console(void) { if (_sapp.desc.win32.console_create || _sapp.desc.win32.console_attach) { BOOL con_valid = FALSE; - if (_sapp.desc.win32.console_create) { - con_valid = AllocConsole(); - } else if (_sapp.desc.win32.console_attach) { + if (_sapp.desc.win32.console_attach) { con_valid = AttachConsole(ATTACH_PARENT_PROCESS); } + if (!con_valid && _sapp.desc.win32.console_create) { + con_valid = AllocConsole(); + } if (con_valid) { FILE* res_fp = 0; errno_t err; |