main.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // ImGui - standalone example application for Allegro 5
  2. #include <stdint.h>
  3. #include <allegro5/allegro.h>
  4. #include <allegro5/allegro_primitives.h>
  5. #include <imgui.h>
  6. #include "imgui_impl_a5.h"
  7. int main(int, char**)
  8. {
  9. // Setup Allegro
  10. al_init();
  11. al_install_keyboard();
  12. al_install_mouse();
  13. al_init_primitives_addon();
  14. al_set_new_display_flags(ALLEGRO_RESIZABLE);
  15. ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
  16. al_set_window_title(display, "ImGui Allegro 5 example");
  17. ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
  18. al_register_event_source(queue, al_get_display_event_source(display));
  19. al_register_event_source(queue, al_get_keyboard_event_source());
  20. al_register_event_source(queue, al_get_mouse_event_source());
  21. // Setup ImGui binding
  22. ImGui_ImplA5_Init(display);
  23. //ImGuiIO& io = ImGui::GetIO();
  24. //ImFont* my_font0 = io.Fonts->AddFontDefault();
  25. //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
  26. //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
  27. //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
  28. //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
  29. //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
  30. bool show_test_window = true;
  31. bool show_another_window = false;
  32. ImVec4 clear_color = ImColor(114, 144, 154);
  33. // Main loop
  34. bool running = true;
  35. while (running)
  36. {
  37. ALLEGRO_EVENT ev;
  38. while (al_get_next_event(queue, &ev))
  39. {
  40. ImGui_ImplA5_ProcessEvent(&ev);
  41. if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false;
  42. if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
  43. {
  44. ImGui_ImplA5_InvalidateDeviceObjects();
  45. al_acknowledge_resize(display);
  46. Imgui_ImplA5_CreateDeviceObjects();
  47. }
  48. }
  49. ImGui_ImplA5_NewFrame();
  50. // 1. Show a simple window
  51. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
  52. {
  53. static float f;
  54. ImGui::Text("Hello, world!");
  55. ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
  56. ImGui::ColorEdit3("clear color", (float*)&clear_color);
  57. if (ImGui::Button("Test Window")) show_test_window ^= 1;
  58. if (ImGui::Button("Another Window")) show_another_window ^= 1;
  59. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  60. }
  61. // 2. Show another simple window, this time using an explicit Begin/End pair
  62. if (show_another_window)
  63. {
  64. ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver);
  65. ImGui::Begin("Another Window", &show_another_window);
  66. ImGui::Text("Hello");
  67. ImGui::End();
  68. }
  69. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  70. if (show_test_window)
  71. {
  72. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  73. ImGui::ShowTestWindow(&show_test_window);
  74. }
  75. // Rendering
  76. al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w));
  77. ImGui::Render();
  78. al_flip_display();
  79. }
  80. // Cleanup
  81. ImGui_ImplA5_Shutdown();
  82. al_destroy_event_queue(queue);
  83. al_destroy_display(display);
  84. return 0;
  85. }