Examples: Allegro5: Add touchscreen support
diff --git a/examples/example_allegro5/README.md b/examples/example_allegro5/README.md
index 5fdcc50..1a83fe8 100644
--- a/examples/example_allegro5/README.md
+++ b/examples/example_allegro5/README.md
@@ -12,7 +12,7 @@
 - On Ubuntu 14.04+
 
 ```bash
-g++ -DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" -I .. -I ../.. main.cpp ..\imgui_impl_allegro5.cpp ../../imgui*.cpp -lallegro -lallegro_primitives -o allegro5_example
+g++ -DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" -I .. -I ../.. main.cpp ../imgui_impl_allegro5.cpp ../../imgui*.cpp -lallegro -lallegro_primitives -o allegro5_example
 ```
 
 - On Windows with Visual Studio's CLI
diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp
index 9a9c580..a85ed91 100644
--- a/examples/imgui_impl_allegro5.cpp
+++ b/examples/imgui_impl_allegro5.cpp
@@ -15,6 +15,7 @@
 
 // CHANGELOG
 // (minor and older changes stripped away, please see git history for details)
+//  2018-11-30: Platform: Added touchscreen support.
 //  2018-06-13: Platform: Added clipboard support (from Allegro 5.1.12).
 //  2018-06-13: Renderer: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
 //  2018-06-13: Renderer: Backup/restore transform and clipping rectangle.
@@ -266,6 +267,8 @@
     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
     io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
     io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText;
@@ -297,8 +300,31 @@
     switch (ev->type)
     {
     case ALLEGRO_EVENT_MOUSE_AXES:
-        io.MouseWheel += ev->mouse.dz;
-        io.MouseWheelH += ev->mouse.dw;
+        if (ev->mouse.display == g_Display)
+        {
+            io.MouseWheel += ev->mouse.dz;
+            io.MouseWheelH += ev->mouse.dw;
+            io.MousePos = ImVec2(ev->mouse.x, ev->mouse.y);
+        }
+        return true;
+    case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
+    case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
+        if (ev->mouse.display == g_Display && ev->mouse.button <= 5)
+            io.MouseDown[ev->mouse.button - 1] = (ev->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN);
+        return true;
+    case ALLEGRO_EVENT_TOUCH_MOVE:
+        if (ev->touch.display == g_Display)
+            io.MousePos = ImVec2(ev->touch.x, ev->touch.y);
+        return true;
+    case ALLEGRO_EVENT_TOUCH_BEGIN:
+    case ALLEGRO_EVENT_TOUCH_END:
+    case ALLEGRO_EVENT_TOUCH_CANCEL:
+        if (ev->touch.display == g_Display && ev->touch.primary)
+            io.MouseDown[0] = (ev->type == ALLEGRO_EVENT_TOUCH_BEGIN);
+        return true;
+    case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY:
+        if (ev->mouse.display == g_Display)
+            io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
         return true;
     case ALLEGRO_EVENT_KEY_CHAR:
         if (ev->keyboard.display == g_Display)
@@ -368,21 +394,5 @@
     io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR);
     io.KeySuper = al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN);
 
-    ALLEGRO_MOUSE_STATE mouse;
-    if (keys.display == g_Display)
-    {
-        al_get_mouse_state(&mouse);
-        io.MousePos = ImVec2((float)mouse.x, (float)mouse.y);
-    }
-    else
-    {
-        io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
-    }
-
-    al_get_mouse_state(&mouse);
-    io.MouseDown[0] = mouse.buttons & (1 << 0);
-    io.MouseDown[1] = mouse.buttons & (1 << 1);
-    io.MouseDown[2] = mouse.buttons & (1 << 2);
-
     ImGui_ImplAllegro5_UpdateMouseCursor();
 }