main.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Dear ImGui: standalone example application for Marmalade
  2. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
  3. // Read online: https://github.com/ocornut/imgui/tree/master/docs
  4. // Copyright (C) 2015 by Giovanni Zito
  5. // This file is part of Dear ImGui
  6. #include "imgui.h"
  7. #include "imgui_impl_marmalade.h"
  8. #include <stdio.h>
  9. #include <s3eKeyboard.h>
  10. #include <s3ePointer.h>
  11. #include <IwGx.h>
  12. int main(int, char**)
  13. {
  14. IwGxInit();
  15. // Setup Dear ImGui context
  16. IMGUI_CHECKVERSION();
  17. ImGui::CreateContext();
  18. ImGuiIO& io = ImGui::GetIO(); (void)io;
  19. //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
  20. // Setup Dear ImGui style
  21. ImGui::StyleColorsDark();
  22. //ImGui::StyleColorsClassic();
  23. // Setup Platform/Renderer backends
  24. ImGui_Marmalade_Init(true);
  25. // Load Fonts
  26. // - 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.
  27. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
  28. // - 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).
  29. // - 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.
  30. // - Read 'docs/FONTS.md' for more instructions and details.
  31. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
  32. //io.Fonts->AddFontDefault();
  33. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
  34. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
  35. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
  36. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
  37. //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
  38. //IM_ASSERT(font != NULL);
  39. // Our state
  40. bool show_demo_window = true;
  41. bool show_another_window = false;
  42. ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
  43. // Main loop
  44. while (true)
  45. {
  46. if (s3eDeviceCheckQuitRequest())
  47. break;
  48. // Poll and handle inputs
  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. s3eKeyboardUpdate();
  54. s3ePointerUpdate();
  55. // Start the Dear ImGui frame
  56. ImGui_Marmalade_NewFrame();
  57. ImGui::NewFrame();
  58. // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
  59. if (show_demo_window)
  60. ImGui::ShowDemoWindow(&show_demo_window);
  61. // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
  62. {
  63. static float f = 0.0f;
  64. static int counter = 0;
  65. ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
  66. ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
  67. ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
  68. ImGui::Checkbox("Another Window", &show_another_window);
  69. ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
  70. ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
  71. if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
  72. counter++;
  73. ImGui::SameLine();
  74. ImGui::Text("counter = %d", counter);
  75. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  76. ImGui::End();
  77. }
  78. // 3. Show another simple window.
  79. if (show_another_window)
  80. {
  81. ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
  82. ImGui::Text("Hello from another window!");
  83. if (ImGui::Button("Close Me"))
  84. show_another_window = false;
  85. ImGui::End();
  86. }
  87. // Rendering
  88. ImGui::Render();
  89. IwGxSetColClear(clear_color.x * 255, clear_color.y * 255, clear_color.z * 255, clear_color.w * 255);
  90. IwGxClear();
  91. ImGui_Marmalade_RenderDrawData(ImGui::GetDrawData());
  92. IwGxSwapBuffers();
  93. s3eDeviceYield(0);
  94. }
  95. // Cleanup
  96. ImGui_Marmalade_Shutdown();
  97. ImGui::DestroyContext();
  98. IwGxTerminate();
  99. return 0;
  100. }