main.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // ImGui - standalone example application for Allegro 5
  2. // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
  3. #include <stdint.h>
  4. #include <allegro5/allegro.h>
  5. #include <allegro5/allegro_primitives.h>
  6. #include "imgui.h"
  7. #include "imgui_impl_a5.h"
  8. int main(int, char**)
  9. {
  10. // Setup Allegro
  11. al_init();
  12. al_install_keyboard();
  13. al_install_mouse();
  14. al_init_primitives_addon();
  15. al_set_new_display_flags(ALLEGRO_RESIZABLE);
  16. ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
  17. al_set_window_title(display, "ImGui Allegro 5 example");
  18. ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
  19. al_register_event_source(queue, al_get_display_event_source(display));
  20. al_register_event_source(queue, al_get_keyboard_event_source());
  21. al_register_event_source(queue, al_get_mouse_event_source());
  22. // Setup ImGui binding
  23. ImGui_ImplA5_Init(display);
  24. // Setup style
  25. ImGui::StyleColorsDark();
  26. //ImGui::StyleColorsClassic();
  27. // Load Fonts
  28. // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
  29. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
  30. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
  31. // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
  32. // - Read 'misc/fonts/README.txt' for more instructions and details.
  33. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
  34. //ImGuiIO& io = ImGui::GetIO();
  35. //io.Fonts->AddFontDefault();
  36. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
  37. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
  38. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
  39. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
  40. //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
  41. //IM_ASSERT(font != NULL);
  42. bool show_demo_window = true;
  43. bool show_another_window = false;
  44. ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
  45. // Main loop
  46. bool running = true;
  47. while (running)
  48. {
  49. // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
  50. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
  51. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
  52. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
  53. ALLEGRO_EVENT ev;
  54. while (al_get_next_event(queue, &ev))
  55. {
  56. ImGui_ImplA5_ProcessEvent(&ev);
  57. if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
  58. running = false;
  59. if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
  60. {
  61. ImGui_ImplA5_InvalidateDeviceObjects();
  62. al_acknowledge_resize(display);
  63. Imgui_ImplA5_CreateDeviceObjects();
  64. }
  65. }
  66. ImGui_ImplA5_NewFrame();
  67. // 1. Show a simple window.
  68. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
  69. {
  70. static float f = 0.0f;
  71. static int counter = 0;
  72. ImGui::Text("Hello, world!"); // Display some text (you can use a format string too)
  73. ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
  74. ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
  75. ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our windows open/close state
  76. ImGui::Checkbox("Another Window", &show_another_window);
  77. if (ImGui::Button("Button")) // Buttons return true when clicked (NB: most widgets return true when edited/activated)
  78. counter++;
  79. ImGui::SameLine();
  80. ImGui::Text("counter = %d", counter);
  81. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  82. }
  83. // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
  84. if (show_another_window)
  85. {
  86. ImGui::Begin("Another Window", &show_another_window);
  87. ImGui::Text("Hello from another window!");
  88. if (ImGui::Button("Close Me"))
  89. show_another_window = false;
  90. ImGui::End();
  91. }
  92. // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui!
  93. if (show_demo_window)
  94. {
  95. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
  96. ImGui::ShowDemoWindow(&show_demo_window);
  97. }
  98. // Rendering
  99. al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w));
  100. ImGui::Render();
  101. al_flip_display();
  102. }
  103. // Cleanup
  104. ImGui_ImplA5_Shutdown();
  105. al_destroy_event_queue(queue);
  106. al_destroy_display(display);
  107. return 0;
  108. }