2021-03-09 23:51:28 -05:00
|
|
|
/*!
|
|
|
|
* @file display.cpp
|
|
|
|
* Display for graphics. This is the game window, distinct from the runtime console.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "display.h"
|
2021-08-09 19:16:39 -04:00
|
|
|
#include "gfx.h"
|
2021-03-09 23:51:28 -05:00
|
|
|
|
|
|
|
#include "common/log/log.h"
|
|
|
|
|
2021-08-14 16:00:50 -04:00
|
|
|
/*
|
|
|
|
********************************
|
|
|
|
* Internal functions
|
|
|
|
********************************
|
|
|
|
*/
|
2021-08-09 19:16:39 -04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void set_main_display(std::shared_ptr<GfxDisplay> display) {
|
|
|
|
if (Display::g_displays.size() > 0) {
|
|
|
|
Display::g_displays[0] = display;
|
|
|
|
} else {
|
|
|
|
Display::g_displays.push_back(display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2021-03-09 23:51:28 -05:00
|
|
|
|
2021-08-14 16:00:50 -04:00
|
|
|
/*
|
|
|
|
********************************
|
|
|
|
* GfxDisplay
|
|
|
|
********************************
|
|
|
|
*/
|
2021-03-09 23:51:28 -05:00
|
|
|
|
2021-08-09 19:16:39 -04:00
|
|
|
void GfxDisplay::set_title(const char* title) {
|
|
|
|
if (!is_active()) {
|
|
|
|
lg::error("No window to set title `{}`.", title);
|
2021-03-09 23:51:28 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-16 22:46:12 -04:00
|
|
|
// TODO set title?
|
2021-08-09 19:16:39 -04:00
|
|
|
m_title = title;
|
|
|
|
}
|
|
|
|
|
2021-12-30 18:48:37 -05:00
|
|
|
int GfxDisplay::width() {
|
|
|
|
int w;
|
2022-06-16 22:46:12 -04:00
|
|
|
get_size(&w, NULL);
|
2021-12-30 18:48:37 -05:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GfxDisplay::height() {
|
|
|
|
int h;
|
2022-06-16 22:46:12 -04:00
|
|
|
get_size(NULL, &h);
|
2022-03-01 20:15:15 -05:00
|
|
|
#ifdef _WIN32
|
2022-06-16 22:46:12 -04:00
|
|
|
if (last_fullscreen_mode() == GfxDisplayMode::Borderless) {
|
2022-03-01 20:15:15 -05:00
|
|
|
// windows borderless hack
|
|
|
|
h--;
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-30 18:48:37 -05:00
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxDisplay::backup_params() {
|
2022-06-16 22:46:12 -04:00
|
|
|
get_size(&m_width, &m_height);
|
|
|
|
get_position(&m_xpos, &m_ypos);
|
2021-12-30 18:48:37 -05:00
|
|
|
fmt::print("backed up window: {},{} {}x{}\n", m_xpos, m_ypos, m_width, m_height);
|
|
|
|
}
|
|
|
|
|
2021-08-14 16:00:50 -04:00
|
|
|
/*
|
|
|
|
********************************
|
|
|
|
* DISPLAY
|
|
|
|
********************************
|
|
|
|
*/
|
2021-08-09 19:16:39 -04:00
|
|
|
|
|
|
|
namespace Display {
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<GfxDisplay>> g_displays;
|
|
|
|
std::shared_ptr<GfxDisplay> GetMainDisplay() {
|
|
|
|
if (g_displays.size() == 0)
|
|
|
|
return NULL;
|
|
|
|
return g_displays.front()->is_active() ? g_displays.front() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int InitMainDisplay(int width, int height, const char* title, GfxSettings& settings) {
|
|
|
|
if (GetMainDisplay() != NULL) {
|
|
|
|
lg::warn("InitMainDisplay called when main display already exists.");
|
|
|
|
return 1;
|
|
|
|
}
|
2021-03-09 23:51:28 -05:00
|
|
|
|
2022-06-16 22:46:12 -04:00
|
|
|
auto display = Gfx::GetCurrentRenderer()->make_display(width, height, title, settings, true);
|
2021-08-09 19:16:39 -04:00
|
|
|
if (display == NULL) {
|
|
|
|
lg::error("Failed to make main display.");
|
|
|
|
return 1;
|
|
|
|
}
|
2022-06-17 19:39:33 -04:00
|
|
|
display->set_imgui_visible(true);
|
2021-08-09 19:16:39 -04:00
|
|
|
set_main_display(display);
|
2021-08-09 21:42:05 -04:00
|
|
|
return 0;
|
2021-03-09 23:51:28 -05:00
|
|
|
}
|
|
|
|
|
2021-08-13 20:06:16 -04:00
|
|
|
void KillMainDisplay() {
|
|
|
|
KillDisplay(GetMainDisplay());
|
|
|
|
}
|
|
|
|
|
2021-08-09 19:16:39 -04:00
|
|
|
void KillDisplay(std::shared_ptr<GfxDisplay> display) {
|
|
|
|
// lg::debug("kill display #x{:x}", (uintptr_t)display);
|
|
|
|
if (!display->is_active()) {
|
|
|
|
lg::warn("display #x{:x} cant be killed because it is not active");
|
2021-03-09 23:51:28 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 19:16:39 -04:00
|
|
|
if (GetMainDisplay() == display) {
|
|
|
|
// killing the main display, kill all children displays too!
|
2021-08-13 20:06:16 -04:00
|
|
|
while (g_displays.size() > 1) {
|
|
|
|
KillDisplay(g_displays.at(1));
|
2021-08-09 19:16:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// find this display in the list and remove it from there
|
|
|
|
// if everything went right the smart pointer should delete the display.
|
|
|
|
auto this_disp = std::find(g_displays.begin(), g_displays.end(), display);
|
|
|
|
g_displays.erase(this_disp);
|
2021-03-09 23:51:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Display
|