|
| 1 | +/* |
| 2 | + Simple DirectMedia Layer |
| 3 | + Copyright (C) 1997-2023 Sam Lantinga <[email protected]> |
| 4 | +
|
| 5 | + This software is provided 'as-is', without any express or implied |
| 6 | + warranty. In no event will the authors be held liable for any damages |
| 7 | + arising from the use of this software. |
| 8 | +
|
| 9 | + Permission is granted to anyone to use this software for any purpose, |
| 10 | + including commercial applications, and to alter it and redistribute it |
| 11 | + freely, subject to the following restrictions: |
| 12 | +
|
| 13 | + 1. The origin of this software must not be misrepresented; you must not |
| 14 | + claim that you wrote the original software. If you use this software |
| 15 | + in a product, an acknowledgment in the product documentation would be |
| 16 | + appreciated but is not required. |
| 17 | + 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | + misrepresented as being the original software. |
| 19 | + 3. This notice may not be removed or altered from any source distribution. |
| 20 | +*/ |
| 21 | +#include "../../SDL_internal.h" |
| 22 | + |
| 23 | +#ifdef SDL_VIDEO_DRIVER_OGC |
| 24 | + |
| 25 | +#include "SDL.h" |
| 26 | +#include "../../events/SDL_keyboard_c.h" |
| 27 | + |
| 28 | +#include "SDL_ogcosk.h" |
| 29 | +#include "SDL_ogcgxcommon.h" |
| 30 | +#include "SDL_ogcvideo.h" |
| 31 | + |
| 32 | +/* The active Virtual Keyboard plugin (if any) */ |
| 33 | +const SDL_OGC_VkPlugin *ogc_vk_plugin = NULL; |
| 34 | + |
| 35 | +static SDL_OGC_VkContext *ogc_vk_context = NULL; |
| 36 | + |
| 37 | +static void init_context() |
| 38 | +{ |
| 39 | + if (ogc_vk_context) return; |
| 40 | + |
| 41 | + ogc_vk_context = SDL_calloc(1, sizeof(SDL_OGC_VkContext)); |
| 42 | + if (!ogc_vk_context) { |
| 43 | + SDL_OutOfMemory(); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + ogc_vk_context->struct_size = sizeof(SDL_OGC_VkContext); |
| 48 | + if (ogc_vk_plugin) { |
| 49 | + ogc_vk_plugin->Init(ogc_vk_context); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +void OGC_StartTextInput(_THIS) |
| 54 | +{ |
| 55 | + if (!ogc_vk_plugin) return; |
| 56 | + ogc_vk_plugin->StartTextInput(ogc_vk_context); |
| 57 | +} |
| 58 | + |
| 59 | +void OGC_StopTextInput(_THIS) |
| 60 | +{ |
| 61 | + if (!ogc_vk_plugin) return; |
| 62 | + ogc_vk_plugin->StopTextInput(ogc_vk_context); |
| 63 | +} |
| 64 | + |
| 65 | +void OGC_SetTextInputRect(_THIS, const SDL_Rect *rect) |
| 66 | +{ |
| 67 | + if (!ogc_vk_plugin || !ogc_vk_context) { |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + ogc_vk_plugin->SetTextInputRect(ogc_vk_context, rect); |
| 72 | +} |
| 73 | + |
| 74 | +void OGC_ClearComposition(_THIS) |
| 75 | +{ |
| 76 | +} |
| 77 | + |
| 78 | +SDL_bool OGC_IsTextInputShown(_THIS) |
| 79 | +{ |
| 80 | + return ogc_vk_context && ogc_vk_context->is_open; |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | +SDL_bool OGC_HasScreenKeyboardSupport(_THIS) |
| 85 | +{ |
| 86 | + return ogc_vk_plugin != NULL; |
| 87 | +} |
| 88 | + |
| 89 | +void OGC_ShowScreenKeyboard(_THIS, SDL_Window *window) |
| 90 | +{ |
| 91 | + if (!ogc_vk_plugin) return; |
| 92 | + |
| 93 | + ogc_vk_context->window = window; |
| 94 | + ogc_vk_plugin->ShowScreenKeyboard(ogc_vk_context); |
| 95 | +} |
| 96 | + |
| 97 | +void OGC_HideScreenKeyboard(_THIS, SDL_Window *window) |
| 98 | +{ |
| 99 | + if (!ogc_vk_plugin) return; |
| 100 | + ogc_vk_plugin->HideScreenKeyboard(ogc_vk_context); |
| 101 | +} |
| 102 | + |
| 103 | +SDL_bool OGC_IsScreenKeyboardShown(_THIS, SDL_Window *window) |
| 104 | +{ |
| 105 | + return OGC_IsTextInputShown(_this); |
| 106 | +} |
| 107 | + |
| 108 | +const SDL_OGC_VkPlugin * |
| 109 | +SDL_OGC_RegisterVkPlugin(const SDL_OGC_VkPlugin *plugin) |
| 110 | +{ |
| 111 | + const SDL_OGC_VkPlugin *old_plugin = ogc_vk_plugin; |
| 112 | + ogc_vk_plugin = plugin; |
| 113 | + init_context(); |
| 114 | + return old_plugin; |
| 115 | +} |
| 116 | + |
| 117 | +SDL_bool SDL_OGC_ProcessEvent(SDL_Event *event) |
| 118 | +{ |
| 119 | + if (!ogc_vk_plugin || !ogc_vk_context || !ogc_vk_context->is_open) { |
| 120 | + return SDL_FALSE; |
| 121 | + } |
| 122 | + |
| 123 | + return ogc_vk_plugin->ProcessEvent(ogc_vk_context, event); |
| 124 | +} |
| 125 | + |
| 126 | +SDL_bool OGC_keyboard_render(_THIS) |
| 127 | +{ |
| 128 | + if (!ogc_vk_plugin || !ogc_vk_context || !ogc_vk_context->is_open) { |
| 129 | + return SDL_FALSE; |
| 130 | + } |
| 131 | + |
| 132 | + ogc_vk_plugin->RenderKeyboard(ogc_vk_context); |
| 133 | + return SDL_TRUE; |
| 134 | +} |
| 135 | + |
| 136 | +int OGC_keyboard_get_pan_y(_THIS) |
| 137 | +{ |
| 138 | + if (!ogc_vk_plugin || !ogc_vk_context) { |
| 139 | + return 0; |
| 140 | + } |
| 141 | + |
| 142 | + return ogc_vk_context->screen_pan_y; |
| 143 | +} |
| 144 | + |
| 145 | +int SDL_OGC_SendKeyboardText(const char *text) |
| 146 | +{ |
| 147 | + return SDL_SendKeyboardText(text); |
| 148 | +} |
| 149 | + |
| 150 | +int SDL_OGC_SendVirtualKeyboardKey(Uint8 state, SDL_Scancode scancode) |
| 151 | +{ |
| 152 | + return SDL_SendVirtualKeyboardKey(state, scancode); |
| 153 | +} |
| 154 | + |
| 155 | +#endif /* SDL_VIDEO_DRIVER_OGC */ |
| 156 | + |
| 157 | +/* vi: set ts=4 sw=4 expandtab: */ |
0 commit comments