AronaCore/core/application/window_manager.cpp
Nanako 0acf109ef2 新增mixer_track ui_buffer用于绘制混音台轨道音量
新增默认插件窗口位置
新增portaudio启用默认asio输出设备
修复circular_audio_buffer编译错误
2024-03-04 01:15:28 +08:00

96 lines
2.8 KiB
C++

#include "window_manager.h"
#include <ranges>
#include "audio/plugin_host/plugin_host.h"
window_manager::window_manager() {
main_window_ = nullptr;
}
void window_manager::init(singleton_initliazer& initliazer) {
singleton_t<window_manager>::init(initliazer);
// start_idle_thread();
}
void window_manager::release(singleton_release_guard& release_guard) {
singleton_t<window_manager>::release(release_guard);
if (main_window_)
glfwDestroyWindow(main_window_);
}
void window_manager::tick() {
glfwPollEvents();
if (should_close()) {
destroy_all_plugin_host_window();
return;
}
update_host_window();
}
void window_manager::destroy_all_plugin_host_window() {
for (const auto& window: host_window_map_ | std::views::values) {
glfwDestroyWindow(window);
}
host_window_map_.clear();
}
GLFWwindow* window_manager::create_main_window(const char* title, int width, int height) {
if (!main_window_)
main_window_ = glfwCreateWindow(width, height, title, nullptr, nullptr);
return main_window_;
}
GLFWwindow* window_manager::create_plugin_host_window(plugin_host* host) {
if (!host->has_editor())
return nullptr;
if (host_window_map_.contains(host))
return host_window_map_[host];
auto editor_size = host->get_editor_size();
auto new_window = glfwCreateWindow(editor_size.x, editor_size.y, host->name.c_str(), nullptr, nullptr);
if (host_window_pos_map_.contains(host)) {
auto pos = host_window_pos_map_[host];
glfwSetWindowPos(new_window, pos.x, pos.y);
}else {
glfwSetWindowPos(new_window, 100, 100);
}
host_window_map_[host] = new_window;
glfwShowWindow(new_window);
return new_window;
}
void window_manager::destroy_plugin_host_window(plugin_host* host) {
if (!host_window_map_.contains(host))
return;
int x, y;
glfwGetWindowPos(host_window_map_[host], &x, &y);
glfwDestroyWindow(host_window_map_[host]);
host_window_map_.erase(host);
host_window_pos_map_[host] = ImVec2(x, y);
}
void window_manager::resize_plugin_host_window(plugin_host* host, int width, int height) {
if (!host_window_map_.contains(host))
return;
glfwSetWindowSize(host_window_map_[host], width, height);
}
void window_manager::idle_plugin_host_window() const {
for (const auto& window_map: host_window_map_) {
window_map.first->idle_editor();
}
}
void window_manager::update_host_window() {
std::vector<plugin_host*> host_editor_to_close;
for (const auto& [host, window]: host_window_map_) {
if (glfwWindowShouldClose(window)) {
host_editor_to_close.push_back(host);
}
}
for (auto host: host_editor_to_close) {
host->try_close_editor();
}
idle_plugin_host_window();
}