void setWindowRect(WindowsDesc* winDesc, const RectDesc& rect) { HWND hwnd = (HWND)winDesc->handle; RectDesc& currentRect = winDesc->fullScreen ? winDesc->fullscreenRect : winDesc->windowedRect; currentRect = rect; MoveWindow(hwnd, rect.left, rect.top, getRectWidth(rect), getRectHeight(rect), TRUE); }
static void onResize(const WindowResizeEventData* pData) { pApp->mSettings.mWidth = getRectWidth(pData->rect); pApp->mSettings.mHeight = getRectHeight(pData->rect); pApp->mSettings.mFullScreen = pData->pWindow->fullScreen; pApp->Unload(); pApp->Load(); }
void drawNumberOnTimeLabel(HDC hdc, RECT rect, LPCWSTR pWStr, COLORREF fontColor) { HFONT font = createFont(getRectHeight(rect) * 0.66 / 2); SetTextColor(hdc, fontColor); // Font color SetBkMode(hdc, TRANSPARENT); // Background color transparentk SelectObject(hdc, font); // Set font DrawText(hdc, pWStr, -1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER); DeleteObject(font); }
void drawNumberOnRect(HDC hdc, RECT rect, const int &number, COLORREF fontColor) { HFONT font = createFont(getRectHeight(rect) * 0.66); SetTextColor(hdc, fontColor); // Font color SetBkMode(hdc, TRANSPARENT); // Background color transparentk SelectObject(hdc, font); // Set font wchar_t buffer[256]; wsprintfW(buffer, L"%d", number); DrawText(hdc, buffer, -1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER); DeleteObject(font); }
// 画数字 void drawNumberOnCell(HDC hdc, RECT cellRect, const int &number, COLORREF fontColor) { int fontSize = log2(number); double factor = fontSize < 7 ? 1 : (fontSize < 10 ? 1.5 : 2); HFONT font = createFont(getRectHeight(cellRect) * 0.66 / factor); SetTextColor(hdc, fontColor); // Font color SetBkMode(hdc, TRANSPARENT); // Background color transparentk SelectObject(hdc, font); // Set font wchar_t buffer[256]; wsprintfW(buffer, L"%d", number); DrawText(hdc, buffer, -1, &cellRect, DT_CENTER | DT_SINGLELINE | DT_VCENTER); DeleteObject(font); }
int WindowsMain(int argc, char** argv, IApp* app) { pApp = app; //Used for automated testing, if enabled app will exit after 120 frames bool testing = false; uint32_t testingFrameCount = 0; const uint32_t testingDesiredFrameCount = 120; //search for --test in command line arguments if (argc > 1) { for(int i = 0 ; i < argc ; i++) { if (strcmp(argv[i], "--testing")) testing = true; } } FileSystem::SetCurrentDir(FileSystem::GetProgramDir()); IApp::Settings* pSettings = &pApp->mSettings; WindowsDesc window = {}; Timer deltaTimer; if (pSettings->mWidth == -1 || pSettings->mHeight == -1) { RectDesc rect = {}; getRecommendedResolution(&rect); pSettings->mWidth = getRectWidth(rect); pSettings->mHeight = getRectHeight(rect); } window.windowedRect = { 0, 0, (int)pSettings->mWidth, (int)pSettings->mHeight }; window.fullScreen = pSettings->mFullScreen; window.maximized = false; openWindow(pApp->GetName(), &window); pSettings->mWidth = window.fullScreen ? getRectWidth(window.fullscreenRect) : getRectWidth(window.windowedRect); pSettings->mHeight = window.fullScreen ? getRectHeight(window.fullscreenRect) : getRectHeight(window.windowedRect); pApp->pWindow = &window; pApp->mCommandLine = GetCommandLineA(); if (!pApp->Init()) return EXIT_FAILURE; registerWindowResizeEvent(onResize); while (isRunning()) { float deltaTime = deltaTimer.GetMSec(true) / 1000.0f; // if framerate appears to drop below about 6, assume we're at a breakpoint and simulate 20fps. if (deltaTime > 0.15f) deltaTime = 0.05f; handleMessages(); pApp->Update(deltaTime); pApp->Draw(); //used in automated tests only. if (testing) { testingFrameCount++; if (testingFrameCount >= testingDesiredFrameCount) break; } } pApp->Exit(); return 0; }
void openWindow(const char* app_name, WindowsDesc* winDesc) { winDesc->fullscreenRect = { 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) }; // If user provided invalid or zero rect, get the rect from renderer if (getRectWidth(winDesc->windowedRect) <= 0 || getRectHeight(winDesc->windowedRect) <= 0) { getRecommendedResolution(&winDesc->windowedRect); } RECT clientRect = { (LONG)winDesc->windowedRect.left, (LONG)winDesc->windowedRect.top, (LONG)winDesc->windowedRect.right, (LONG)winDesc->windowedRect.bottom }; AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, FALSE); winDesc->windowedRect = { (int)clientRect.left, (int)clientRect.top, (int)clientRect.right, (int)clientRect.bottom }; RectDesc& rect = winDesc->fullScreen ? winDesc->fullscreenRect : winDesc->windowedRect; WCHAR app[MAX_PATH]; size_t charConverted = 0; mbstowcs_s(&charConverted, app, app_name, MAX_PATH); HWND hwnd = CreateWindowW(CONFETTI_WINDOW_CLASS, app, WS_OVERLAPPEDWINDOW | ((winDesc->visible) ? WS_VISIBLE : 0), CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, (HINSTANCE)GetModuleHandle(NULL), 0 ); if (hwnd) { GetClientRect(hwnd, &clientRect); winDesc->windowedRect = { (int)clientRect.left, (int)clientRect.top, (int)clientRect.right, (int)clientRect.bottom }; winDesc->handle = hwnd; gHWNDMap.insert({ hwnd, winDesc }); if (winDesc->visible) { if (winDesc->maximized) { ShowWindow(hwnd, SW_MAXIMIZE); } else if (winDesc->minimized) { ShowWindow(hwnd, SW_MINIMIZE); } else if (winDesc->fullScreen) { adjustWindow(winDesc); } } LOGINFOF("Created window app %s", app_name); } else { LOGERRORF("Failed to create window app %s", app_name); } }