imgui

FORK: Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
git clone https://git.neptards.moe/neptards/imgui.git
Log | Files | Refs

main.cpp (5575B)


      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 
      5 // Copyright (C) 2015 by Giovanni Zito
      6 // This file is part of Dear ImGui
      7 
      8 #include "imgui.h"
      9 #include "imgui_impl_marmalade.h"
     10 #include <stdio.h>
     11 
     12 #include <s3eKeyboard.h>
     13 #include <s3ePointer.h>
     14 #include <IwGx.h>
     15 
     16 int main(int, char**)
     17 {
     18     IwGxInit();
     19 
     20     // Setup Dear ImGui context
     21     IMGUI_CHECKVERSION();
     22     ImGui::CreateContext();
     23     ImGuiIO& io = ImGui::GetIO(); (void)io;
     24     //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls
     25 
     26     // Setup Dear ImGui style
     27     ImGui::StyleColorsDark();
     28     //ImGui::StyleColorsClassic();
     29 
     30     // Setup Platform/Renderer backends
     31     ImGui_Marmalade_Init(true);
     32 
     33     // Load Fonts
     34     // - 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.
     35     // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
     36     // - 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).
     37     // - 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.
     38     // - Read 'docs/FONTS.md' for more instructions and details.
     39     // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
     40     //io.Fonts->AddFontDefault();
     41     //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
     42     //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
     43     //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
     44     //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
     45     //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
     46     //IM_ASSERT(font != NULL);
     47 
     48     // Our state
     49     bool show_demo_window = true;
     50     bool show_another_window = false;
     51     ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
     52 
     53     // Main loop
     54     while (true)
     55     {
     56         if (s3eDeviceCheckQuitRequest())
     57             break;
     58 
     59         // Poll and handle inputs
     60         // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
     61         // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
     62         // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
     63         // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
     64         s3eKeyboardUpdate();
     65         s3ePointerUpdate();
     66 
     67         // Start the Dear ImGui frame
     68         ImGui_Marmalade_NewFrame();
     69         ImGui::NewFrame();
     70 
     71         // 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!).
     72         if (show_demo_window)
     73             ImGui::ShowDemoWindow(&show_demo_window);
     74 
     75         // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
     76         {
     77             static float f = 0.0f;
     78             static int counter = 0;
     79 
     80             ImGui::Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.
     81 
     82             ImGui::Text("This is some useful text.");               // Display some text (you can use a format strings too)
     83             ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our window open/close state
     84             ImGui::Checkbox("Another Window", &show_another_window);
     85 
     86             ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f
     87             ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
     88 
     89             if (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)
     90                 counter++;
     91             ImGui::SameLine();
     92             ImGui::Text("counter = %d", counter);
     93 
     94             ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
     95             ImGui::End();
     96         }
     97 
     98         // 3. Show another simple window.
     99         if (show_another_window)
    100         {
    101             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)
    102             ImGui::Text("Hello from another window!");
    103             if (ImGui::Button("Close Me"))
    104                 show_another_window = false;
    105             ImGui::End();
    106         }
    107 
    108         // Rendering
    109         ImGui::Render();
    110         IwGxSetColClear(clear_color.x * 255, clear_color.y * 255, clear_color.z * 255, clear_color.w * 255);
    111         IwGxClear();
    112         ImGui_Marmalade_RenderDrawData(ImGui::GetDrawData());
    113         IwGxSwapBuffers();
    114 
    115         s3eDeviceYield(0);
    116     }
    117 
    118     // Cleanup
    119     ImGui_Marmalade_Shutdown();
    120     ImGui::DestroyContext();
    121     IwGxTerminate();
    122 
    123     return 0;
    124 }