From adb04f7316f9b2f7871b91b62d3bd920194bf97d Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 12 Mar 2022 01:28:23 +0100 Subject: Moved Inits for Application and Instance into GameWinDX9 --- Stars45/Game.cpp | 124 ------------------------------------------------- Stars45/Game.h | 4 +- Stars45/GameWinDX9.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++++++ Stars45/GameWinDX9.h | 2 + 4 files changed, 123 insertions(+), 127 deletions(-) (limited to 'Stars45') diff --git a/Stars45/Game.cpp b/Stars45/Game.cpp index ed2ee92..f149a00 100644 --- a/Stars45/Game.cpp +++ b/Stars45/Game.cpp @@ -207,130 +207,6 @@ Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) // +--------------------------------------------------------------------+ bool -Game::InitApplication(HINSTANCE hInstance) -{ - WNDCLASS wc; - LOGBRUSH brush = { BS_SOLID, RGB(0,0,0), 0 }; - - if (server) - brush.lbColor = RGB(255,255,255); - - // Fill in window class structure with parameters that - // describe the main window. - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = (WNDPROC) WndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(100)); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - - wc.hbrBackground = CreateBrushIndirect(&brush); - wc.lpszMenuName = app_name; - wc.lpszClassName = app_name; - - // Register the window class and return success/failure code. - if (RegisterClass(&wc) == 0) { - DWORD err = GetLastError(); - - if (err == 1410) // class already exists, this is OK - return true; - - else - Print("WARNING: Register Window Class: %08x\n", err); - } - - return true; -} - -// +--------------------------------------------------------------------+ - -bool -Game::InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - hInst = hInstance; - - // center window on display: - int screenx = GetSystemMetrics(SM_CXSCREEN); - int screeny = GetSystemMetrics(SM_CYSCREEN); - int x_offset = 0; - int y_offset = 0; - int s_width = 800; - int s_height = 600; - - if (server) { - s_width = 320; - s_height = 200; - } - - else if (video_settings) { - s_width = video_settings->window_width; - s_height = video_settings->window_height; - } - - if (s_width < screenx) - x_offset = (screenx - s_width) / 2; - - if (s_height < screeny) - y_offset = (screeny - s_height) / 2; - - // Create a main window for this application instance - RECT rctmp; - rctmp.left = x_offset; - rctmp.top = y_offset; - rctmp.right = x_offset + s_width; - rctmp.bottom = y_offset + s_height; - - window_style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | - WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE; - - AdjustWindowRect(&rctmp, window_style, 1); - - hwnd = CreateWindow( - app_name, // Class name - app_name, // Caption - - window_style, - - x_offset, // Position - y_offset, - - rctmp.right - rctmp.left, // Size - rctmp.bottom - rctmp.top, - - 0, // Parent window (no parent) - 0, // use class menu - hInst, // handle to window instance - 0); // no params to pass on - - // If window could not be created, return "failure" - if (!hwnd) { - Panic::Panic("Could not create window\n"); - return false; - } - - Print(" Window created.\n"); - - // Make the window visible and draw it - ShowWindow(hwnd, nCmdShow); // Show the window - UpdateWindow(hwnd); // Sends WM_PAINT message - - // Save window properties - window_style = GetWindowLong(hwnd, GWL_STYLE); - GetWindowRect(hwnd, &bounds_rect); - GetClientRect(hwnd, &client_rect); - - // Use client area to set video window size - video_settings->window_width = client_rect.right - client_rect.left; - video_settings->window_height = client_rect.bottom - client_rect.top; - - Print(" Instance initialized.\n"); - return true; -} - -// +--------------------------------------------------------------------+ - -bool Game::InitVideo() { if (server) return true; diff --git a/Stars45/Game.h b/Stars45/Game.h index 033968c..afd8f27 100644 --- a/Stars45/Game.h +++ b/Stars45/Game.h @@ -14,6 +14,7 @@ #include "Types.h" #include "Screen.h" #include "Video.h" +#include "VideoSettings.h" // +--------------------------------------------------------------------+ @@ -32,7 +33,6 @@ class Sound; class SoundCard; class Video; class VideoFactory; -class VideoSettings; class Text; // +--------------------------------------------------------------------+ @@ -103,8 +103,6 @@ public: virtual void UpdateScreen(); virtual void CollectStats(); - virtual bool InitApplication(HINSTANCE); - virtual bool InitInstance(HINSTANCE, int); virtual bool InitGame(); virtual bool InitVideo(); virtual bool ResizeVideo(); diff --git a/Stars45/GameWinDX9.cpp b/Stars45/GameWinDX9.cpp index 2cd4fbe..f40be9b 100644 --- a/Stars45/GameWinDX9.cpp +++ b/Stars45/GameWinDX9.cpp @@ -10,6 +10,7 @@ #include "MachineInfo.h" #include "Panic.h" #include "Types.h" +#include "Utils.h" GameWinDX9::GameWinDX9() @@ -72,3 +73,122 @@ GameWinDX9::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) return false; return Game::Init(hi, hpi, cmdline, nCmdShow); } + + +bool +GameWinDX9::InitApplication(HINSTANCE hInstance) +{ + WNDCLASS wc; + LOGBRUSH brush = { BS_SOLID, RGB(0,0,0), 0 }; + + if (server) + brush.lbColor = RGB(255,255,255); + + // Fill in window class structure with parameters that + // describe the main window. + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = (WNDPROC) WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(100)); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + + wc.hbrBackground = CreateBrushIndirect(&brush); + wc.lpszMenuName = app_name; + wc.lpszClassName = app_name; + + // Register the window class and return success/failure code. + if (RegisterClass(&wc) == 0) { + DWORD err = GetLastError(); + + if (err == 1410) // class already exists, this is OK + return true; + + else + Print("WARNING: Register Window Class: %08x\n", err); + } + + return true; +} + + +bool +GameWinDX9::InitInstance(HINSTANCE hInstance, int nCmdShow) +{ + hInst = hInstance; + + // center window on display: + int screenx = GetSystemMetrics(SM_CXSCREEN); + int screeny = GetSystemMetrics(SM_CYSCREEN); + int x_offset = 0; + int y_offset = 0; + int s_width = 800; + int s_height = 600; + + if (server) { + s_width = 320; + s_height = 200; + } + + else if (video_settings) { + s_width = video_settings->window_width; + s_height = video_settings->window_height; + } + + if (s_width < screenx) + x_offset = (screenx - s_width) / 2; + + if (s_height < screeny) + y_offset = (screeny - s_height) / 2; + + // Create a main window for this application instance + RECT rctmp; + rctmp.left = x_offset; + rctmp.top = y_offset; + rctmp.right = x_offset + s_width; + rctmp.bottom = y_offset + s_height; + + window_style = + WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | + WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE; + + AdjustWindowRect(&rctmp, window_style, 1); + + hwnd = CreateWindow( + app_name, // Class name + app_name, // Caption + window_style, + x_offset, // Position + y_offset, + rctmp.right - rctmp.left, // Size + rctmp.bottom - rctmp.top, + 0, // Parent window (no parent) + 0, // use class menu + hInst, // handle to window instance + 0); // no params to pass on + + // If window could not be created, return "failure" + if (!hwnd) { + Panic::Panic("Could not create window\n"); + return false; + } + + Print(" Window created.\n"); + + // Make the window visible and draw it + ShowWindow(hwnd, nCmdShow); // Show the window + UpdateWindow(hwnd); // Sends WM_PAINT message + + // Save window properties + window_style = GetWindowLong(hwnd, GWL_STYLE); + GetWindowRect(hwnd, &bounds_rect); + GetClientRect(hwnd, &client_rect); + + // Use client area to set video window size + video_settings->window_width = client_rect.right - client_rect.left; + video_settings->window_height = client_rect.bottom - client_rect.top; + + Print(" Instance initialized.\n"); + return true; +} diff --git a/Stars45/GameWinDX9.h b/Stars45/GameWinDX9.h index 3ad8a7c..719bc04 100644 --- a/Stars45/GameWinDX9.h +++ b/Stars45/GameWinDX9.h @@ -18,6 +18,8 @@ public: virtual ~GameWinDX9(); virtual bool Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow); + virtual bool InitApplication(HINSTANCE hInstance); + virtual bool InitInstance(HINSTANCE hInstance, int nCmdShow); }; -- cgit v1.1