imgui_impl_allegro5.cpp (imgui-1.86) | : | imgui_impl_allegro5.cpp (imgui-1.87) | ||
---|---|---|---|---|
// dear imgui: Renderer + Platform Backend for Allegro 5 | // dear imgui: Renderer + Platform Backend for Allegro 5 | |||
// (Info: Allegro 5 is a cross-platform general purpose library for handling win dows, inputs, graphics, etc.) | // (Info: Allegro 5 is a cross-platform general purpose library for handling win dows, inputs, graphics, etc.) | |||
// Implemented features: | // Implemented features: | |||
// [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Re ad the FAQ about ImTextureID! | // [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Re ad the FAQ about ImTextureID! | |||
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(Im GuiKey_Space). [Legacy ALLEGRO_KEY_* values will also be supported unless IMGUI_ DISABLE_OBSOLETE_KEYIO is set] | ||||
// [X] Platform: Clipboard support (from Allegro 5.1.12) | // [X] Platform: Clipboard support (from Allegro 5.1.12) | |||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlag s |= ImGuiConfigFlags_NoMouseCursorChange'. | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlag s |= ImGuiConfigFlags_NoMouseCursorChange'. | |||
// Issues: | // Issues: | |||
// [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers a nd convert vertices manually. | // [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers a nd convert vertices manually. | |||
// [ ] Platform: Missing gamepad support. | // [ ] Platform: Missing gamepad support. | |||
// You can use unmodified imgui_impl_* files in your project. See examples/ fold er for examples of using this. | // You can use unmodified imgui_impl_* files in your project. See examples/ fold er for examples of using this. | |||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. | |||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. | |||
// Read online: https://github.com/ocornut/imgui/tree/master/docs | // Read online: https://github.com/ocornut/imgui/tree/master/docs | |||
// CHANGELOG | // CHANGELOG | |||
// (minor and older changes stripped away, please see git history for details) | // (minor and older changes stripped away, please see git history for details) | |||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two wee | ||||
ks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusio | ||||
n. | ||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEven | ||||
t(), io.AddMouseWheelEvent() API (1.87+). | ||||
// 2022-01-17: Inputs: always calling io.AddKeyModsEvent() next and before key | ||||
event (not in NewFrame) to fix input queue with very low framerates. | ||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io. | ||||
SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. | ||||
// 2021-12-08: Renderer: Fixed mishandling of the the ImDrawCmd::IdxOffset fiel d! This is an old bug but it never had an effect until some internal rendering c hanges in 1.86. | // 2021-12-08: Renderer: Fixed mishandling of the the ImDrawCmd::IdxOffset fiel d! This is an old bug but it never had an effect until some internal rendering c hanges in 1.86. | |||
// 2021-08-17: Calling io.AddFocusEvent() on ALLEGRO_EVENT_DISPLAY_SWITCH_OUT/A LLEGRO_EVENT_DISPLAY_SWITCH_IN events. | // 2021-08-17: Calling io.AddFocusEvent() on ALLEGRO_EVENT_DISPLAY_SWITCH_OUT/A LLEGRO_EVENT_DISPLAY_SWITCH_IN events. | |||
// 2021-06-29: Reorganized backend to pull data from a single structure to faci litate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). | // 2021-06-29: Reorganized backend to pull data from a single structure to faci litate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). | |||
// 2021-05-19: Renderer: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) | // 2021-05-19: Renderer: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) | |||
// 2021-02-18: Change blending equation to preserve alpha in output buffer. | // 2021-02-18: Change blending equation to preserve alpha in output buffer. | |||
// 2020-08-10: Inputs: Fixed horizontal mouse wheel direction. | // 2020-08-10: Inputs: Fixed horizontal mouse wheel direction. | |||
// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse curs or. | // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse curs or. | |||
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. | // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. | |||
// 2019-05-11: Inputs: Don't filter character value from ALLEGRO_EVENT_KEY_CHAR before calling AddInputCharacter(). | // 2019-05-11: Inputs: Don't filter character value from ALLEGRO_EVENT_KEY_CHAR before calling AddInputCharacter(). | |||
// 2019-04-30: Renderer: Added support for special ImDrawCallback_ResetRenderSt ate callback to reset render state. | // 2019-04-30: Renderer: Added support for special ImDrawCallback_ResetRenderSt ate callback to reset render state. | |||
skipping to change at line 277 | skipping to change at line 282 | |||
return bd->ClipboardTextData; | return bd->ClipboardTextData; | |||
} | } | |||
static void ImGui_ImplAllegro5_SetClipboardText(void*, const char* text) | static void ImGui_ImplAllegro5_SetClipboardText(void*, const char* text) | |||
{ | { | |||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData(); | ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData(); | |||
al_set_clipboard_text(bd->Display, text); | al_set_clipboard_text(bd->Display, text); | |||
} | } | |||
#endif | #endif | |||
static ImGuiKey ImGui_ImplAllegro5_KeyCodeToImGuiKey(int key_code) | ||||
{ | ||||
switch (key_code) | ||||
{ | ||||
case ALLEGRO_KEY_TAB: return ImGuiKey_Tab; | ||||
case ALLEGRO_KEY_LEFT: return ImGuiKey_LeftArrow; | ||||
case ALLEGRO_KEY_RIGHT: return ImGuiKey_RightArrow; | ||||
case ALLEGRO_KEY_UP: return ImGuiKey_UpArrow; | ||||
case ALLEGRO_KEY_DOWN: return ImGuiKey_DownArrow; | ||||
case ALLEGRO_KEY_PGUP: return ImGuiKey_PageUp; | ||||
case ALLEGRO_KEY_PGDN: return ImGuiKey_PageDown; | ||||
case ALLEGRO_KEY_HOME: return ImGuiKey_Home; | ||||
case ALLEGRO_KEY_END: return ImGuiKey_End; | ||||
case ALLEGRO_KEY_INSERT: return ImGuiKey_Insert; | ||||
case ALLEGRO_KEY_DELETE: return ImGuiKey_Delete; | ||||
case ALLEGRO_KEY_BACKSPACE: return ImGuiKey_Backspace; | ||||
case ALLEGRO_KEY_SPACE: return ImGuiKey_Space; | ||||
case ALLEGRO_KEY_ENTER: return ImGuiKey_Enter; | ||||
case ALLEGRO_KEY_ESCAPE: return ImGuiKey_Escape; | ||||
case ALLEGRO_KEY_QUOTE: return ImGuiKey_Apostrophe; | ||||
case ALLEGRO_KEY_COMMA: return ImGuiKey_Comma; | ||||
case ALLEGRO_KEY_MINUS: return ImGuiKey_Minus; | ||||
case ALLEGRO_KEY_FULLSTOP: return ImGuiKey_Period; | ||||
case ALLEGRO_KEY_SLASH: return ImGuiKey_Slash; | ||||
case ALLEGRO_KEY_SEMICOLON: return ImGuiKey_Semicolon; | ||||
case ALLEGRO_KEY_EQUALS: return ImGuiKey_Equal; | ||||
case ALLEGRO_KEY_OPENBRACE: return ImGuiKey_LeftBracket; | ||||
case ALLEGRO_KEY_BACKSLASH: return ImGuiKey_Backslash; | ||||
case ALLEGRO_KEY_CLOSEBRACE: return ImGuiKey_RightBracket; | ||||
case ALLEGRO_KEY_TILDE: return ImGuiKey_GraveAccent; | ||||
case ALLEGRO_KEY_CAPSLOCK: return ImGuiKey_CapsLock; | ||||
case ALLEGRO_KEY_SCROLLLOCK: return ImGuiKey_ScrollLock; | ||||
case ALLEGRO_KEY_NUMLOCK: return ImGuiKey_NumLock; | ||||
case ALLEGRO_KEY_PRINTSCREEN: return ImGuiKey_PrintScreen; | ||||
case ALLEGRO_KEY_PAUSE: return ImGuiKey_Pause; | ||||
case ALLEGRO_KEY_PAD_0: return ImGuiKey_Keypad0; | ||||
case ALLEGRO_KEY_PAD_1: return ImGuiKey_Keypad1; | ||||
case ALLEGRO_KEY_PAD_2: return ImGuiKey_Keypad2; | ||||
case ALLEGRO_KEY_PAD_3: return ImGuiKey_Keypad3; | ||||
case ALLEGRO_KEY_PAD_4: return ImGuiKey_Keypad4; | ||||
case ALLEGRO_KEY_PAD_5: return ImGuiKey_Keypad5; | ||||
case ALLEGRO_KEY_PAD_6: return ImGuiKey_Keypad6; | ||||
case ALLEGRO_KEY_PAD_7: return ImGuiKey_Keypad7; | ||||
case ALLEGRO_KEY_PAD_8: return ImGuiKey_Keypad8; | ||||
case ALLEGRO_KEY_PAD_9: return ImGuiKey_Keypad9; | ||||
case ALLEGRO_KEY_PAD_DELETE: return ImGuiKey_KeypadDecimal; | ||||
case ALLEGRO_KEY_PAD_SLASH: return ImGuiKey_KeypadDivide; | ||||
case ALLEGRO_KEY_PAD_ASTERISK: return ImGuiKey_KeypadMultiply; | ||||
case ALLEGRO_KEY_PAD_MINUS: return ImGuiKey_KeypadSubtract; | ||||
case ALLEGRO_KEY_PAD_PLUS: return ImGuiKey_KeypadAdd; | ||||
case ALLEGRO_KEY_PAD_ENTER: return ImGuiKey_KeypadEnter; | ||||
case ALLEGRO_KEY_PAD_EQUALS: return ImGuiKey_KeypadEqual; | ||||
case ALLEGRO_KEY_LCTRL: return ImGuiKey_LeftCtrl; | ||||
case ALLEGRO_KEY_LSHIFT: return ImGuiKey_LeftShift; | ||||
case ALLEGRO_KEY_ALT: return ImGuiKey_LeftAlt; | ||||
case ALLEGRO_KEY_LWIN: return ImGuiKey_LeftSuper; | ||||
case ALLEGRO_KEY_RCTRL: return ImGuiKey_RightCtrl; | ||||
case ALLEGRO_KEY_RSHIFT: return ImGuiKey_RightShift; | ||||
case ALLEGRO_KEY_ALTGR: return ImGuiKey_RightAlt; | ||||
case ALLEGRO_KEY_RWIN: return ImGuiKey_RightSuper; | ||||
case ALLEGRO_KEY_MENU: return ImGuiKey_Menu; | ||||
case ALLEGRO_KEY_0: return ImGuiKey_0; | ||||
case ALLEGRO_KEY_1: return ImGuiKey_1; | ||||
case ALLEGRO_KEY_2: return ImGuiKey_2; | ||||
case ALLEGRO_KEY_3: return ImGuiKey_3; | ||||
case ALLEGRO_KEY_4: return ImGuiKey_4; | ||||
case ALLEGRO_KEY_5: return ImGuiKey_5; | ||||
case ALLEGRO_KEY_6: return ImGuiKey_6; | ||||
case ALLEGRO_KEY_7: return ImGuiKey_7; | ||||
case ALLEGRO_KEY_8: return ImGuiKey_8; | ||||
case ALLEGRO_KEY_9: return ImGuiKey_9; | ||||
case ALLEGRO_KEY_A: return ImGuiKey_A; | ||||
case ALLEGRO_KEY_B: return ImGuiKey_B; | ||||
case ALLEGRO_KEY_C: return ImGuiKey_C; | ||||
case ALLEGRO_KEY_D: return ImGuiKey_D; | ||||
case ALLEGRO_KEY_E: return ImGuiKey_E; | ||||
case ALLEGRO_KEY_F: return ImGuiKey_F; | ||||
case ALLEGRO_KEY_G: return ImGuiKey_G; | ||||
case ALLEGRO_KEY_H: return ImGuiKey_H; | ||||
case ALLEGRO_KEY_I: return ImGuiKey_I; | ||||
case ALLEGRO_KEY_J: return ImGuiKey_J; | ||||
case ALLEGRO_KEY_K: return ImGuiKey_K; | ||||
case ALLEGRO_KEY_L: return ImGuiKey_L; | ||||
case ALLEGRO_KEY_M: return ImGuiKey_M; | ||||
case ALLEGRO_KEY_N: return ImGuiKey_N; | ||||
case ALLEGRO_KEY_O: return ImGuiKey_O; | ||||
case ALLEGRO_KEY_P: return ImGuiKey_P; | ||||
case ALLEGRO_KEY_Q: return ImGuiKey_Q; | ||||
case ALLEGRO_KEY_R: return ImGuiKey_R; | ||||
case ALLEGRO_KEY_S: return ImGuiKey_S; | ||||
case ALLEGRO_KEY_T: return ImGuiKey_T; | ||||
case ALLEGRO_KEY_U: return ImGuiKey_U; | ||||
case ALLEGRO_KEY_V: return ImGuiKey_V; | ||||
case ALLEGRO_KEY_W: return ImGuiKey_W; | ||||
case ALLEGRO_KEY_X: return ImGuiKey_X; | ||||
case ALLEGRO_KEY_Y: return ImGuiKey_Y; | ||||
case ALLEGRO_KEY_Z: return ImGuiKey_Z; | ||||
case ALLEGRO_KEY_F1: return ImGuiKey_F1; | ||||
case ALLEGRO_KEY_F2: return ImGuiKey_F2; | ||||
case ALLEGRO_KEY_F3: return ImGuiKey_F3; | ||||
case ALLEGRO_KEY_F4: return ImGuiKey_F4; | ||||
case ALLEGRO_KEY_F5: return ImGuiKey_F5; | ||||
case ALLEGRO_KEY_F6: return ImGuiKey_F6; | ||||
case ALLEGRO_KEY_F7: return ImGuiKey_F7; | ||||
case ALLEGRO_KEY_F8: return ImGuiKey_F8; | ||||
case ALLEGRO_KEY_F9: return ImGuiKey_F9; | ||||
case ALLEGRO_KEY_F10: return ImGuiKey_F10; | ||||
case ALLEGRO_KEY_F11: return ImGuiKey_F11; | ||||
case ALLEGRO_KEY_F12: return ImGuiKey_F12; | ||||
default: return ImGuiKey_None; | ||||
} | ||||
} | ||||
bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display) | bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display) | |||
{ | { | |||
ImGuiIO& io = ImGui::GetIO(); | ImGuiIO& io = ImGui::GetIO(); | |||
IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platf orm backend!"); | IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platf orm backend!"); | |||
// Setup backend capabilities flags | // Setup backend capabilities flags | |||
ImGui_ImplAllegro5_Data* bd = IM_NEW(ImGui_ImplAllegro5_Data)(); | ImGui_ImplAllegro5_Data* bd = IM_NEW(ImGui_ImplAllegro5_Data)(); | |||
io.BackendPlatformUserData = (void*)bd; | io.BackendPlatformUserData = (void*)bd; | |||
io.BackendPlatformName = io.BackendRendererName = "imgui_impl_allegro5"; | io.BackendPlatformName = io.BackendRendererName = "imgui_impl_allegro5"; | |||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) | io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) | |||
skipping to change at line 302 | skipping to change at line 420 | |||
// We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion. | // We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion. | |||
ALLEGRO_VERTEX_ELEMENT elems[] = | ALLEGRO_VERTEX_ELEMENT elems[] = | |||
{ | { | |||
{ ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAll egro, pos) }, | { ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAll egro, pos) }, | |||
{ ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAl legro, uv) }, | { ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAl legro, uv) }, | |||
{ ALLEGRO_PRIM_COLOR_ATTR, 0, IM_OFFSETOF(ImDrawVertAllegro, col) }, | { ALLEGRO_PRIM_COLOR_ATTR, 0, IM_OFFSETOF(ImDrawVertAllegro, col) }, | |||
{ 0, 0, 0 } | { 0, 0, 0 } | |||
}; | }; | |||
bd->VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro)); | bd->VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro)); | |||
io.KeyMap[ImGuiKey_Tab] = ALLEGRO_KEY_TAB; | ||||
io.KeyMap[ImGuiKey_LeftArrow] = ALLEGRO_KEY_LEFT; | ||||
io.KeyMap[ImGuiKey_RightArrow] = ALLEGRO_KEY_RIGHT; | ||||
io.KeyMap[ImGuiKey_UpArrow] = ALLEGRO_KEY_UP; | ||||
io.KeyMap[ImGuiKey_DownArrow] = ALLEGRO_KEY_DOWN; | ||||
io.KeyMap[ImGuiKey_PageUp] = ALLEGRO_KEY_PGUP; | ||||
io.KeyMap[ImGuiKey_PageDown] = ALLEGRO_KEY_PGDN; | ||||
io.KeyMap[ImGuiKey_Home] = ALLEGRO_KEY_HOME; | ||||
io.KeyMap[ImGuiKey_End] = ALLEGRO_KEY_END; | ||||
io.KeyMap[ImGuiKey_Insert] = ALLEGRO_KEY_INSERT; | ||||
io.KeyMap[ImGuiKey_Delete] = ALLEGRO_KEY_DELETE; | ||||
io.KeyMap[ImGuiKey_Backspace] = ALLEGRO_KEY_BACKSPACE; | ||||
io.KeyMap[ImGuiKey_Space] = ALLEGRO_KEY_SPACE; | ||||
io.KeyMap[ImGuiKey_Enter] = ALLEGRO_KEY_ENTER; | ||||
io.KeyMap[ImGuiKey_Escape] = ALLEGRO_KEY_ESCAPE; | ||||
io.KeyMap[ImGuiKey_KeyPadEnter] = ALLEGRO_KEY_PAD_ENTER; | ||||
io.KeyMap[ImGuiKey_A] = ALLEGRO_KEY_A; | ||||
io.KeyMap[ImGuiKey_C] = ALLEGRO_KEY_C; | ||||
io.KeyMap[ImGuiKey_V] = ALLEGRO_KEY_V; | ||||
io.KeyMap[ImGuiKey_X] = ALLEGRO_KEY_X; | ||||
io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y; | ||||
io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z; | ||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); | ||||
#if ALLEGRO_HAS_CLIPBOARD | #if ALLEGRO_HAS_CLIPBOARD | |||
io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText; | io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText; | |||
io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText; | io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText; | |||
io.ClipboardUserData = NULL; | io.ClipboardUserData = NULL; | |||
#endif | #endif | |||
return true; | return true; | |||
} | } | |||
void ImGui_ImplAllegro5_Shutdown() | void ImGui_ImplAllegro5_Shutdown() | |||
skipping to change at line 352 | skipping to change at line 446 | |||
if (bd->VertexDecl) | if (bd->VertexDecl) | |||
al_destroy_vertex_decl(bd->VertexDecl); | al_destroy_vertex_decl(bd->VertexDecl); | |||
if (bd->ClipboardTextData) | if (bd->ClipboardTextData) | |||
al_free(bd->ClipboardTextData); | al_free(bd->ClipboardTextData); | |||
io.BackendPlatformUserData = NULL; | io.BackendPlatformUserData = NULL; | |||
io.BackendPlatformName = io.BackendRendererName = NULL; | io.BackendPlatformName = io.BackendRendererName = NULL; | |||
IM_DELETE(bd); | IM_DELETE(bd); | |||
} | } | |||
// ev->keyboard.modifiers seems always zero so using that... | ||||
static void ImGui_ImplAllegro5_UpdateKeyModifiers() | ||||
{ | ||||
ImGuiIO& io = ImGui::GetIO(); | ||||
ALLEGRO_KEYBOARD_STATE keys; | ||||
al_get_keyboard_state(&keys); | ||||
io.AddKeyEvent(ImGuiKey_ModCtrl, al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al | ||||
_key_down(&keys, ALLEGRO_KEY_RCTRL)); | ||||
io.AddKeyEvent(ImGuiKey_ModShift, al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || | ||||
al_key_down(&keys, ALLEGRO_KEY_RSHIFT)); | ||||
io.AddKeyEvent(ImGuiKey_ModAlt, al_key_down(&keys, ALLEGRO_KEY_ALT) || al_ke | ||||
y_down(&keys, ALLEGRO_KEY_ALTGR)); | ||||
io.AddKeyEvent(ImGuiKey_ModSuper, al_key_down(&keys, ALLEGRO_KEY_LWIN) || al | ||||
_key_down(&keys, ALLEGRO_KEY_RWIN)); | ||||
} | ||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. | // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. | |||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. | |||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. | |||
// Generally you may always pass all inputs to dear imgui, and hide them from yo ur application based on those two flags. | // Generally you may always pass all inputs to dear imgui, and hide them from yo ur application based on those two flags. | |||
bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* ev) | bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* ev) | |||
{ | { | |||
ImGuiIO& io = ImGui::GetIO(); | ImGuiIO& io = ImGui::GetIO(); | |||
ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData(); | ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData(); | |||
switch (ev->type) | switch (ev->type) | |||
{ | { | |||
case ALLEGRO_EVENT_MOUSE_AXES: | case ALLEGRO_EVENT_MOUSE_AXES: | |||
if (ev->mouse.display == bd->Display) | if (ev->mouse.display == bd->Display) | |||
{ | { | |||
io.MouseWheel += ev->mouse.dz; | io.AddMousePosEvent(ev->mouse.x, ev->mouse.y); | |||
io.MouseWheelH -= ev->mouse.dw; | io.AddMouseWheelEvent(-ev->mouse.dw, ev->mouse.dz); | |||
io.MousePos = ImVec2(ev->mouse.x, ev->mouse.y); | ||||
} | } | |||
return true; | return true; | |||
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: | case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: | |||
case ALLEGRO_EVENT_MOUSE_BUTTON_UP: | case ALLEGRO_EVENT_MOUSE_BUTTON_UP: | |||
if (ev->mouse.display == bd->Display && ev->mouse.button <= 5) | if (ev->mouse.display == bd->Display && ev->mouse.button > 0 && ev->mous | |||
io.MouseDown[ev->mouse.button - 1] = (ev->type == ALLEGRO_EVENT_MOUS | e.button <= 5) | |||
E_BUTTON_DOWN); | io.AddMouseButtonEvent(ev->mouse.button - 1, ev->type == ALLEGRO_EVE | |||
NT_MOUSE_BUTTON_DOWN); | ||||
return true; | return true; | |||
case ALLEGRO_EVENT_TOUCH_MOVE: | case ALLEGRO_EVENT_TOUCH_MOVE: | |||
if (ev->touch.display == bd->Display) | if (ev->touch.display == bd->Display) | |||
io.MousePos = ImVec2(ev->touch.x, ev->touch.y); | io.AddMousePosEvent(ev->touch.x, ev->touch.y); | |||
return true; | return true; | |||
case ALLEGRO_EVENT_TOUCH_BEGIN: | case ALLEGRO_EVENT_TOUCH_BEGIN: | |||
case ALLEGRO_EVENT_TOUCH_END: | case ALLEGRO_EVENT_TOUCH_END: | |||
case ALLEGRO_EVENT_TOUCH_CANCEL: | case ALLEGRO_EVENT_TOUCH_CANCEL: | |||
if (ev->touch.display == bd->Display && ev->touch.primary) | if (ev->touch.display == bd->Display && ev->touch.primary) | |||
io.MouseDown[0] = (ev->type == ALLEGRO_EVENT_TOUCH_BEGIN); | io.AddMouseButtonEvent(0, ev->type == ALLEGRO_EVENT_TOUCH_BEGIN); | |||
return true; | return true; | |||
case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY: | case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY: | |||
if (ev->mouse.display == bd->Display) | if (ev->mouse.display == bd->Display) | |||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); | io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); | |||
return true; | return true; | |||
case ALLEGRO_EVENT_KEY_CHAR: | case ALLEGRO_EVENT_KEY_CHAR: | |||
if (ev->keyboard.display == bd->Display) | if (ev->keyboard.display == bd->Display) | |||
if (ev->keyboard.unichar != 0) | if (ev->keyboard.unichar != 0) | |||
io.AddInputCharacter((unsigned int)ev->keyboard.unichar); | io.AddInputCharacter((unsigned int)ev->keyboard.unichar); | |||
return true; | return true; | |||
case ALLEGRO_EVENT_KEY_DOWN: | case ALLEGRO_EVENT_KEY_DOWN: | |||
case ALLEGRO_EVENT_KEY_UP: | case ALLEGRO_EVENT_KEY_UP: | |||
if (ev->keyboard.display == bd->Display) | if (ev->keyboard.display == bd->Display) | |||
io.KeysDown[ev->keyboard.keycode] = (ev->type == ALLEGRO_EVENT_KEY_D | { | |||
OWN); | ImGui_ImplAllegro5_UpdateKeyModifiers(); | |||
ImGuiKey key = ImGui_ImplAllegro5_KeyCodeToImGuiKey(ev->keyboard.key | ||||
code); | ||||
io.AddKeyEvent(key, (ev->type == ALLEGRO_EVENT_KEY_DOWN)); | ||||
io.SetKeyEventNativeData(key, ev->keyboard.keycode, -1); // To suppo | ||||
rt legacy indexing (<1.87 user code) | ||||
} | ||||
return true; | return true; | |||
case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT: | case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT: | |||
if (ev->display.source == bd->Display) | if (ev->display.source == bd->Display) | |||
io.AddFocusEvent(false); | io.AddFocusEvent(false); | |||
return true; | return true; | |||
case ALLEGRO_EVENT_DISPLAY_SWITCH_IN: | case ALLEGRO_EVENT_DISPLAY_SWITCH_IN: | |||
if (ev->display.source == bd->Display) | if (ev->display.source == bd->Display) | |||
{ | { | |||
io.AddFocusEvent(true); | io.AddFocusEvent(true); | |||
#if defined(ALLEGRO_UNSTABLE) | #if defined(ALLEGRO_UNSTABLE) | |||
skipping to change at line 468 | skipping to change at line 578 | |||
int w, h; | int w, h; | |||
w = al_get_display_width(bd->Display); | w = al_get_display_width(bd->Display); | |||
h = al_get_display_height(bd->Display); | h = al_get_display_height(bd->Display); | |||
io.DisplaySize = ImVec2((float)w, (float)h); | io.DisplaySize = ImVec2((float)w, (float)h); | |||
// Setup time step | // Setup time step | |||
double current_time = al_get_time(); | double current_time = al_get_time(); | |||
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1 .0f / 60.0f); | io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1 .0f / 60.0f); | |||
bd->Time = current_time; | bd->Time = current_time; | |||
// Setup inputs | // Setup mouse cursor shape | |||
ALLEGRO_KEYBOARD_STATE keys; | ||||
al_get_keyboard_state(&keys); | ||||
io.KeyCtrl = al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALL | ||||
EGRO_KEY_RCTRL); | ||||
io.KeyShift = al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, A | ||||
LLEGRO_KEY_RSHIFT); | ||||
io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGR | ||||
O_KEY_ALTGR); | ||||
io.KeySuper = al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALL | ||||
EGRO_KEY_RWIN); | ||||
ImGui_ImplAllegro5_UpdateMouseCursor(); | ImGui_ImplAllegro5_UpdateMouseCursor(); | |||
} | } | |||
End of changes. 12 change blocks. | ||||
47 lines changed or deleted | 157 lines changed or added |