|
8 | 8 | // [ ] Platform: Clipboard support.
|
9 | 9 | // [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
10 | 10 | // [ ] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: Check if this is even possible with Android.
|
| 11 | +// [ ] Platform: Multi-viewport support (multiple windows). Not meaningful on Android. |
11 | 12 | // Important:
|
12 | 13 | // - Consider using SDL or GLFW backend on Android, which will be more full-featured than this.
|
13 | 14 | // - FIXME: On-screen keyboard currently needs to be enabled by the application (see examples/ and issue #3446)
|
14 | 15 | // - FIXME: Unicode character inputs needs to be passed by Dear ImGui by the application (see examples/ and issue #3446)
|
15 | 16 |
|
16 | 17 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
17 | 18 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
18 |
| -// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. |
19 |
| -// Read online: https://github.com/ocornut/imgui/tree/master/docs |
| 19 | +// Learn about Dear ImGui: |
| 20 | +// - FAQ https://dearimgui.com/faq |
| 21 | +// - Getting Started https://dearimgui.com/getting-started |
| 22 | +// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). |
| 23 | +// - Introduction, links and more at the top of imgui.cpp |
20 | 24 |
|
21 | 25 | // CHANGELOG
|
22 | 26 | // (minor and older changes stripped away, please see git history for details)
|
|
27 | 31 | // 2021-03-04: Initial version.
|
28 | 32 |
|
29 | 33 | #include "imgui.h"
|
| 34 | +#ifndef IMGUI_DISABLE |
30 | 35 | #include "imgui_impl_android.h"
|
31 | 36 | #include <time.h>
|
32 | 37 | #include <android/native_window.h>
|
@@ -152,7 +157,7 @@ static ImGuiKey ImGui_ImplAndroid_KeyCodeToImGuiKey(int32_t key_code)
|
152 | 157 | }
|
153 | 158 | }
|
154 | 159 |
|
155 |
| -int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event) |
| 160 | +int32_t ImGui_ImplAndroid_HandleInputEvent(const AInputEvent* input_event) |
156 | 161 | {
|
157 | 162 | ImGuiIO& io = ImGui::GetIO();
|
158 | 163 | int32_t event_type = AInputEvent_getType(input_event);
|
@@ -217,25 +222,27 @@ int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event)
|
217 | 222 | {
|
218 | 223 | case AMOTION_EVENT_ACTION_DOWN:
|
219 | 224 | case AMOTION_EVENT_ACTION_UP:
|
| 225 | + { |
220 | 226 | // Physical mouse buttons (and probably other physical devices) also invoke the actions AMOTION_EVENT_ACTION_DOWN/_UP,
|
221 | 227 | // but we have to process them separately to identify the actual button pressed. This is done below via
|
222 | 228 | // AMOTION_EVENT_ACTION_BUTTON_PRESS/_RELEASE. Here, we only process "FINGER" input (and "UNKNOWN", as a fallback).
|
223 |
| - if((AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_FINGER) |
224 |
| - || (AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_UNKNOWN)) |
| 229 | + int tool_type = AMotionEvent_getToolType(input_event, event_pointer_index); |
| 230 | + if (tool_type == AMOTION_EVENT_TOOL_TYPE_FINGER || tool_type == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) |
225 | 231 | {
|
226 | 232 | io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
|
227 | 233 | io.AddMouseButtonEvent(0, event_action == AMOTION_EVENT_ACTION_DOWN);
|
228 | 234 | }
|
229 | 235 | break;
|
| 236 | + } |
230 | 237 | case AMOTION_EVENT_ACTION_BUTTON_PRESS:
|
231 | 238 | case AMOTION_EVENT_ACTION_BUTTON_RELEASE:
|
232 |
| - { |
233 |
| - int32_t button_state = AMotionEvent_getButtonState(input_event); |
234 |
| - io.AddMouseButtonEvent(0, (button_state & AMOTION_EVENT_BUTTON_PRIMARY) != 0); |
235 |
| - io.AddMouseButtonEvent(1, (button_state & AMOTION_EVENT_BUTTON_SECONDARY) != 0); |
236 |
| - io.AddMouseButtonEvent(2, (button_state & AMOTION_EVENT_BUTTON_TERTIARY) != 0); |
237 |
| - } |
| 239 | + { |
| 240 | + int32_t button_state = AMotionEvent_getButtonState(input_event); |
| 241 | + io.AddMouseButtonEvent(0, (button_state & AMOTION_EVENT_BUTTON_PRIMARY) != 0); |
| 242 | + io.AddMouseButtonEvent(1, (button_state & AMOTION_EVENT_BUTTON_SECONDARY) != 0); |
| 243 | + io.AddMouseButtonEvent(2, (button_state & AMOTION_EVENT_BUTTON_TERTIARY) != 0); |
238 | 244 | break;
|
| 245 | + } |
239 | 246 | case AMOTION_EVENT_ACTION_HOVER_MOVE: // Hovering: Tool moves while NOT pressed (such as a physical mouse)
|
240 | 247 | case AMOTION_EVENT_ACTION_MOVE: // Touch pointer moves while DOWN
|
241 | 248 | io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
|
@@ -294,3 +301,7 @@ void ImGui_ImplAndroid_NewFrame()
|
294 | 301 | io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f / 60.0f);
|
295 | 302 | g_Time = current_time;
|
296 | 303 | }
|
| 304 | + |
| 305 | +//----------------------------------------------------------------------------- |
| 306 | + |
| 307 | +#endif // #ifndef IMGUI_DISABLE |
0 commit comments