diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-09-17 17:55:54 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-09-17 17:55:54 +0200 |
| commit | 41ddcc70f6ac27688c0a7dccc975c4b72de718e2 (patch) | |
| tree | faa8cb49befe057068769a4a08bc0b4ab2a4a882 /src/main.cpp | |
| parent | 3a3fac243c013f3d211bb5141e18c82e62deacf9 (diff) | |
add license
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index ba7a2e5..2e3d215 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,19 @@ +/* +* Copyright (c) 2025 Aldrik Ramaekers <aldrik.ramaekers@gmail.com> +* +* Permission to use, copy, modify, and/or distribute this software for any +* purpose with or without fee is hereby granted, provided that the above +* copyright notice and this permission notice appear in all copies. +* +* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + #include "imgui.h" #include "imgui_impl_win32.h" #include "imgui_impl_dx11.h" @@ -9,6 +25,7 @@ #include "administration_writer.hpp" // Data +static HWND hwnd; static ID3D11Device* g_pd3dDevice = nullptr; static ID3D11DeviceContext* g_pd3dDeviceContext = nullptr; static IDXGISwapChain* g_pSwapChain = nullptr; @@ -23,10 +40,29 @@ void CreateRenderTarget(); void CleanupRenderTarget(); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +void platorm_maximize_window() +{ + LONG style = GetWindowLong(hwnd, GWL_STYLE); + + // allow resizing + maximize + style |= (WS_THICKFRAME | WS_MAXIMIZEBOX); + + SetWindowLong(hwnd, GWL_STYLE, style); + + // Apply style changes + SetWindowPos(hwnd, NULL, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + + ShowWindow(hwnd, SW_MAXIMIZE); +} + // Main code //int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) int main() { + int start_width = 1280; + int start_height = 800; + // Make process DPI aware and obtain main monitor scale ImGui_ImplWin32_EnableDpiAwareness(); float main_scale = ImGui_ImplWin32_GetDpiScaleForMonitor(::MonitorFromPoint(POINT{ 0, 0 }, MONITOR_DEFAULTTOPRIMARY)); @@ -34,7 +70,17 @@ int main() // Create application window WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr }; ::RegisterClassExW(&wc); - HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"OpenBooks", WS_OVERLAPPEDWINDOW, 100, 100, (int)(1280 * main_scale), (int)(800 * main_scale), nullptr, nullptr, wc.hInstance, nullptr); + + // Get screen size + int screenW = GetSystemMetrics(SM_CXSCREEN); + int screenH = GetSystemMetrics(SM_CYSCREEN); + + // Calculate top-left so window is centered + int x = (screenW - start_width) / 2; + int y = (screenH - start_height) / 2; + + hwnd = ::CreateWindowW(wc.lpszClassName, L"OpenBooks", WS_OVERLAPPEDWINDOW, + x, y, (int)(start_width * main_scale), (int)(start_height * main_scale), nullptr, nullptr, wc.hInstance, nullptr); // Initialize Direct3D if (!CreateDeviceD3D(hwnd)) @@ -80,7 +126,9 @@ int main() style.FontSizeBase = 18.0f; //io.Fonts->AddFontDefault(); io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf"); + //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\seguisym.ttf"); fontBold = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeuib.ttf"); + fontBig = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeuib.ttf", 36); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf"); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf"); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf"); @@ -91,6 +139,7 @@ int main() timer_lib_initialize(); administration_writer_create(); + administration_create_default(""); // Main loop bool done = false; |
