|
9 | 9 | #include <OvRendering/Entities/Light.h> |
10 | 10 | #include <OvCore/Global/ServiceLocator.h> |
11 | 11 | #include <OvTools/Utils/SystemCalls.h> |
| 12 | +#include <OvDebug/Assertion.h> |
12 | 13 |
|
13 | 14 | #include "OvEditor/Core/Context.h" |
14 | 15 |
|
15 | 16 | using namespace OvCore::Global; |
16 | 17 | using namespace OvCore::ResourceManagement; |
17 | 18 |
|
| 19 | +constexpr std::array<std::pair<int, int>, 13> kResolutions |
| 20 | +{ |
| 21 | + std::make_pair(640, 360), // nHD |
| 22 | + std::make_pair(854, 480), // FWVGA |
| 23 | + std::make_pair(960, 540), // qHD |
| 24 | + std::make_pair(1024, 576), // WSVGA |
| 25 | + std::make_pair(1280, 720), // HD |
| 26 | + std::make_pair(1366, 768), // FWXGA |
| 27 | + std::make_pair(1600, 900), // HD+ |
| 28 | + std::make_pair(1920, 1080), // Full HD |
| 29 | + std::make_pair(2560, 1440), // QHD |
| 30 | + std::make_pair(3200, 1800), // QHD+ |
| 31 | + std::make_pair(3840, 2160), // 4K UHD |
| 32 | + std::make_pair(5120, 2880), // 5K |
| 33 | + std::make_pair(7680, 4320), // 8K UHD |
| 34 | +}; |
| 35 | + |
| 36 | +std::array<int, 4> FindBestFitWindowSizeAndPosition(std::array<int, 4> p_workAreaSize) |
| 37 | +{ |
| 38 | + // Extract work area dimensions |
| 39 | + int workAreaX = p_workAreaSize[0]; |
| 40 | + int workAreaY = p_workAreaSize[1]; |
| 41 | + int workAreaWidth = p_workAreaSize[2]; |
| 42 | + int workAreaHeight = p_workAreaSize[3]; |
| 43 | + |
| 44 | + // Iterate over available resolutions |
| 45 | + for (auto it = kResolutions.rbegin(); it != kResolutions.rend(); ++it) |
| 46 | + { |
| 47 | + int width = it->first; |
| 48 | + int height = it->second; |
| 49 | + |
| 50 | + // Check if resolution fits within work area |
| 51 | + if (width <= workAreaWidth && height <= workAreaHeight) |
| 52 | + { |
| 53 | + // Center the resolution within the work area |
| 54 | + int posX = workAreaX + workAreaWidth / 2 - width / 2; |
| 55 | + int posY = workAreaY + workAreaHeight / 2 - height / 2; |
| 56 | + |
| 57 | + return { posX, posY, width, height }; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + OVASSERT(false, "No resolution found to fit the work area"); |
| 62 | +} |
| 63 | + |
18 | 64 | OvEditor::Core::Context::Context(const std::string& p_projectPath, const std::string& p_projectName) : |
19 | 65 | projectPath(p_projectPath), |
20 | 66 | projectName(p_projectName), |
@@ -42,23 +88,21 @@ OvEditor::Core::Context::Context(const std::string& p_projectPath, const std::st |
42 | 88 | OvWindowing::Settings::DeviceSettings deviceSettings; |
43 | 89 | deviceSettings.contextMajorVersion = 4; |
44 | 90 | deviceSettings.contextMinorVersion = 3; |
45 | | - windowSettings.title = "Overload"; |
46 | | - windowSettings.width = 1600; |
47 | | - windowSettings.height = 900; |
48 | 91 |
|
49 | 92 | /* Window creation */ |
50 | 93 | device = std::make_unique<OvWindowing::Context::Device>(deviceSettings); |
| 94 | + const auto workAreaSize = device->GetWorkAreaSize(); |
| 95 | + const auto bestFitWindowSizeAndPosition = FindBestFitWindowSizeAndPosition(workAreaSize); |
| 96 | + windowSettings.title = "Overload"; |
| 97 | + windowSettings.x = bestFitWindowSizeAndPosition[0]; |
| 98 | + windowSettings.y = bestFitWindowSizeAndPosition[1]; |
| 99 | + windowSettings.width = bestFitWindowSizeAndPosition[2]; |
| 100 | + windowSettings.height = bestFitWindowSizeAndPosition[3]; |
51 | 101 | window = std::make_unique<OvWindowing::Window>(*device, windowSettings); |
52 | 102 | std::vector<uint64_t> iconRaw = { 0,0,144115188614240000,7500771567664627712,7860776967494637312,0,0,0,0,7212820467466371072,11247766461832697600,14274185407633888512,12905091124788992000,5626708973701824512,514575842263176960,0,0,6564302121125019648,18381468271671515136,18381468271654737920,18237353083595659264,18165295488836311040,6708138037527189504,0,4186681893338480640,7932834557741046016,17876782538917681152,11319824055216379904,15210934132358518784,18381468271520454400,1085667680982603520,0,18093237891929479168,18309410677600032768,11391881649237530624,7932834561381570304,17300321784231761408,15210934132375296000,8293405106311272448,2961143145139082752,16507969723533236736,17516777143216379904,10671305705855129600,7356091234422036224,16580027318695106560,2240567205413984000,18381468271470188544,10959253511276599296,4330520004484136960,10815138323200743424,11607771853338181632,8364614976649238272,17444719546862998784,2669156352,18381468269893064448,6419342512197474304,11103650170688640000,6492244531366860800,14346241902646925312,13841557270159628032,7428148827772098304,3464698581331941120,18381468268953606144,1645680384,18381468271554008832,7140201027266418688,5987558797656659712,17588834734687262208,7284033640602212096,14273902834169157632,18381468269087692288,6852253225049397248,17732667349600245504,16291515470083266560,10022503688432981760,11968059825861367552,9733991836700645376,14850363587428816640,18381468271168132864,16147400282007410688,656430432014827520,18381468270950094848,15715054717226194944,72057596690306560,11823944635485519872,15859169905251653376,17084149004500473856,8581352906816952064,2527949855582584832,18381468271419856896,8581352907253225472,252776704,1376441223417430016,14994761349590357760,10527190521537370112,0,9806614576878321664,18381468271671515136,17156206598538401792,6059619689256392448,10166619973990488064,18381468271403079424,17444719549178451968,420746240,870625192710242304,4906133035823863552,18381468269289150464,18381468271671515136,18381468271671515136,9950729769032620032,14778305994951169792,269422336,0,0,18381468268785833984,8941923452686178304,18381468270950094848,3440842496,1233456333565402880,0,0,0,11823944636091210240,2383877888,16724143605745719296,2316834816,0,0 }; |
53 | 103 | window->SetIconFromMemory(reinterpret_cast<uint8_t*>(iconRaw.data()), 16, 16); |
54 | 104 | inputManager = std::make_unique<OvWindowing::Inputs::InputManager>(*window); |
55 | 105 | window->MakeCurrentContext(); |
56 | | - |
57 | | - /* Center Window */ |
58 | | - auto [monWidth, monHeight] = device->GetMonitorSize(); |
59 | | - auto [winWidth, winHeight] = window->GetSize(); |
60 | | - window->SetPosition(monWidth / 2 - winWidth / 2, monHeight / 2 - winHeight / 2); |
61 | | - |
62 | 106 | device->SetVsync(true); |
63 | 107 |
|
64 | 108 | /* Graphics context creation */ |
|
0 commit comments