You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stmdspgui/source/main.cpp

124 lines
3.1 KiB
C++

3 years ago
/**
* @file main.cpp
* @brief Program entry point and main loop.
*
* Copyright (C) 2021 Clyne Sullivan
*
* Distributed under the GNU GPL v3 or later. You should have received a copy of
* the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
#include "imgui.h"
#include "backends/imgui_impl_sdl.h"
#include "backends/imgui_impl_opengl2.h"
#include "config.h"
#include "logview.h"
3 years ago
#include "stmdsp.hpp"
#include <chrono>
#include <cmath>
3 years ago
#include <string>
#include <thread>
3 years ago
extern ImFont *fontSans;
extern ImFont *fontMono;
3 years ago
extern bool guiInitialize();
extern void guiHandleEvents(bool& done);
extern void guiShutdown();
extern void guiRender(void (*func)());
extern void fileRenderMenu();
extern void fileRenderDialog();
extern void fileInit();
3 years ago
extern void codeEditorInit();
extern void codeRenderMenu();
extern void codeRenderToolbar();
extern void codeRenderWidgets();
extern void deviceRenderDraw();
3 years ago
extern void deviceRenderMenu();
extern void deviceRenderToolbar();
extern void deviceRenderWidgets();
3 years ago
// Globals that live here
bool done = false;
static LogView logView;
void log(const std::string& str)
{
logView.AddLog(str);
}
3 years ago
int main(int, char **)
{
if (!guiInitialize())
return -1;
codeEditorInit();
fileInit();
3 years ago
while (!done) {
auto endTime = std::chrono::steady_clock::now() +
std::chrono::milliseconds(static_cast<unsigned int>(std::floor(1000. / 60.)));
3 years ago
guiHandleEvents(done);
// Start the new window frame and render the menu bar.
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
if (ImGui::BeginMainMenuBar()) {
fileRenderMenu();
deviceRenderMenu();
codeRenderMenu();
ImGui::EndMainMenuBar();
}
// Begin the main view which the controls will be drawn onto.
ImGui::SetNextWindowPos({0, 22});
ImGui::SetNextWindowSize({WINDOW_WIDTH, WINDOW_HEIGHT - 22 - 200});
3 years ago
ImGui::Begin("main", nullptr,
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoBringToFrontOnFocus);
3 years ago
// Render main controls (order is important).
{
ImGui::PushFont(fontSans);
codeRenderToolbar();
deviceRenderToolbar();
fileRenderDialog();
deviceRenderWidgets();
ImGui::PopFont();
ImGui::PushFont(fontMono);
codeRenderWidgets();
ImGui::SetNextWindowPos({0, WINDOW_HEIGHT - 200});
ImGui::SetNextWindowSize({WINDOW_WIDTH, 200});
logView.Draw("log", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopFont();
}
3 years ago
ImGui::End();
deviceRenderDraw();
3 years ago
// Draw everything to the screen.
ImGui::Render();
guiRender([] {
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
});
std::this_thread::sleep_until(endTime);
3 years ago
}
guiShutdown();
return 0;
}