OpenBarnyard
 
Loading...
Searching...
No Matches
TMSWindow.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TMSWindow.h"
4#include "Toshi/TSystem.h"
5
9
10//-----------------------------------------------------------------------------
11// Enables memory debugging.
12// Note: Should be the last include!
13//-----------------------------------------------------------------------------
14#include "Core/TMemoryDebugOn.h"
15
17
19
21{
22 m_HWND = NULL;
23 m_pRenderer = TNULL;
24 m_bWindowed = TTRUE;
25 m_bDestroyed = TFALSE;
26 m_bIsFocused = TFALSE;
27
28 TString8 rendererName = TGetClass( TRenderD3DInterface ).GetName();
30
31 ms_StickyKeys.cbSize = sizeof( STICKYKEYS );
32 SystemParametersInfoA( SPI_GETSTICKYKEYS, sizeof( STICKYKEYS ), &ms_StickyKeys, 0 );
33
34 STICKYKEYS newStickyKeys = { sizeof( STICKYKEYS ) };
35 newStickyKeys.dwFlags = 0;
36 SystemParametersInfoA( SPI_SETSTICKYKEYS, sizeof( STICKYKEYS ), &newStickyKeys, 0 );
37}
38
39void TMSWindow::Update( TFLOAT a_fDeltaTime )
40{
41 MSG msg;
42
43 if ( m_bDestroyed ) return;
44
45 if ( !m_bIsFocused )
46 {
47 if ( !g_oSystemManager.IsPaused() )
48 {
49 if ( FALSE != PeekMessageA( &msg, NULL, 0, 0, 0 ) )
50 {
51 while ( FALSE != GetMessageA( &msg, NULL, 0, 0 ) )
52 {
53 TranslateMessage( &msg );
54 DispatchMessageA( &msg );
55
56 if ( FALSE == PeekMessageA( &msg, NULL, 0, 0, 0 ) )
57 {
58 return;
59 }
60 }
61
62 m_bDestroyed = TTRUE;
63 }
64
65 return;
66 }
67 else
68 {
69 m_bIsFocused = TTRUE;
70 LONG uStyle = GetWindowLongA( m_HWND, GWL_STYLE );
71 SetWindowLongA( m_HWND, GWL_STYLE, uStyle | WS_SYSMENU );
72 return;
73 }
74 }
75
76 while ( g_oSystemManager.IsPaused() )
77 {
78 if ( FALSE == GetMessageA( &msg, NULL, 0, 0 ) )
79 {
80 m_bDestroyed = TTRUE;
81 m_bIsFocused = TFALSE;
82 return;
83 }
84
85 TranslateMessage( &msg );
86 DispatchMessageA( &msg );
87 }
88
89 m_bIsFocused = TFALSE;
90
91 LONG uStyle = GetWindowLongA( m_HWND, GWL_STYLE );
92 SetWindowLongA( m_HWND, GWL_STYLE, uStyle & ( ~WS_SYSMENU ) );
93
94 if ( FALSE != PeekMessageA( &msg, NULL, 0, 0, 0 ) )
95 {
96 while ( FALSE != GetMessageA( &msg, NULL, 0, 0 ) )
97 {
98 TranslateMessage( &msg );
99 DispatchMessageA( &msg );
100
101 if ( FALSE == PeekMessageA( &msg, NULL, 0, 0, 0 ) )
102 {
103 return;
104 }
105 }
106 }
107}
108
110{
111 if ( m_HWND != NULL )
112 {
113 if ( ms_bIsFocused )
114 {
116 SystemParametersInfoA( SPI_SETSTICKYKEYS, sizeof( STICKYKEYS ), &ms_StickyKeys, 0 );
117 }
118
119 DestroyWindow( m_HWND );
120 m_bDestroyed = TTRUE;
121 m_HWND = NULL;
122 }
123
124 if ( m_pRenderer != TNULL )
125 {
126 UnregisterClassA( TGetClass( TRenderD3DInterface ).GetName(), m_ModuleHandle );
127 m_pRenderer = TNULL;
128 }
129}
130
131void TMSWindow::SetFocused( TBOOL a_bFocused )
132{
133 if ( ms_bIsFocused != a_bFocused )
134 {
135 ms_bIsFocused = a_bFocused;
136
137 if ( ms_bIsFocused )
138 {
139 SystemParametersInfoA( SPI_GETSTICKYKEYS, sizeof( STICKYKEYS ), &ms_StickyKeys, 0 );
140
141 STICKYKEYS newStickyKeys = { sizeof( STICKYKEYS ) };
142 newStickyKeys.dwFlags = 0;
143 SystemParametersInfoA( SPI_SETSTICKYKEYS, sizeof( STICKYKEYS ), &newStickyKeys, 0 );
144 }
145 else
146 {
147 SystemParametersInfoA( SPI_SETSTICKYKEYS, sizeof( STICKYKEYS ), &ms_StickyKeys, 0 );
148 }
149 }
150}
151
152void TMSWindow::SetPosition( UINT x, UINT y, UINT width, UINT height )
153{
154 SetWindowPos( m_HWND, HWND_TOP, x, y, width, height, 0 );
155}
156
157TBOOL TMSWindow::Create( TRenderInterface* renderer, LPCSTR title )
158{
159 m_ModuleHandle = GetModuleHandleA( NULL );
161
162 m_pRenderer = renderer;
163
164 WNDCLASSA wndClass = {
165 .style = 3,
166 .lpfnWndProc = WndProc,
167 .cbClsExtra = 0,
168 .cbWndExtra = 0,
169 .hInstance = m_ModuleHandle,
170 .hIcon = NULL,
171 .hCursor = LoadCursorA( NULL, IDC_ARROW ),
172 .hbrBackground = (HBRUSH)GetStockObject( 1 ),
173 .lpszMenuName = NULL,
174 .lpszClassName = TGetClass( TRenderD3DInterface ).GetName()
175 };
176
177 RegisterClassA( &wndClass );
178 m_HWND = CreateWindowExA(
179 0,
180 TGetClass( TRenderD3DInterface ).GetName(),
181 title,
182 0x86c00000,
183 100,
184 100,
185 0,
186 0,
187 NULL,
188 NULL,
189 m_ModuleHandle,
190 this
191 );
192
193 if ( !m_HWND ) return TFALSE;
194
195 EnableWindow( m_HWND, TRUE );
196 ShowWindow( m_HWND, SW_SHOW );
197
198 return TTRUE;
199}
200
201LRESULT CALLBACK TMSWindow::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
202{
203 static TBOOL s_bIsPaused;
204
205 if ( uMsg <= WM_ACTIVATEAPP )
206 {
207 if ( uMsg == WM_ACTIVATEAPP )
208 {
209 TMSWindow* pWindow = TREINTERPRETCAST( TMSWindow*, GetWindowLongA( hWnd, GWL_USERDATA ) );
210 TRenderD3DInterface* pRenderer = TREINTERPRETCAST( TRenderD3DInterface*, pWindow->m_pRenderer );
211
212 if ( !pWindow->m_bDestroyed )
213 {
214 const TBOOL bPaused = !wParam;
215
216 g_oSystemManager.Pause( bPaused );
217 s_bIsPaused = bPaused;
218
219 if ( wParam && !pWindow->m_bWindowed && pRenderer->GetDirect3DDevice() )
220 pRenderer->OnD3DDeviceFound();
221 else if ( !wParam && !pWindow->m_bWindowed && pRenderer->GetDirect3DDevice() )
222 pRenderer->OnD3DDeviceLost();
223
224 return 0;
225 }
226 }
227
228 if ( uMsg == WM_CREATE )
229 {
230 SetWindowLongA( hWnd, GWL_USERDATA, *(LONG*)lParam );
231 return 0;
232 }
233
234 if ( uMsg == WM_ACTIVATE )
235 {
236 SetFocused( ( wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE ) );
237
238 return DefWindowProcA( hWnd, WM_ACTIVATE, wParam, lParam );
239 }
240
241 if ( uMsg == WM_QUIT )
242 {
243 DestroyWindow( hWnd );
244
245 return DefWindowProcA( hWnd, WM_QUIT, wParam, lParam );
246 }
247 }
248 else if ( uMsg == WM_SETCURSOR )
249 {
250 TRenderD3DInterface* pRenderer = TREINTERPRETCAST( TRenderD3DInterface*, TRenderInterface::GetSingleton() );
251
252 pRenderer->GetDirect3DDevice()->ShowCursor( TRUE );
253 TFIXME( "Use data from TMouse_D3D8_Win to set cursor properties" );
254 }
255 else if ( uMsg == WM_SYSCOMMAND )
256 {
257 if ( wParam == SC_CLOSE )
258 {
259 TRenderD3DInterface* pRenderer = TREINTERPRETCAST( TRenderD3DInterface*, TRenderInterface::GetSingleton() );
260 pRenderer->Exit();
261 TTODO( "FUN_006bbb80" );
262
263 return 0;
264 }
265 else if ( wParam == SC_SCREENSAVE )
266 {
267 return 0;
268 }
269 else if ( wParam == SC_MONITORPOWER )
270 {
271 return 0;
272 }
273 }
274 else if ( uMsg == WM_MOUSEFIRST )
275 {
276 auto pMouse = TInputInterface::GetSingletonSafe()->GetDeviceByIndex<TInputDXDeviceMouse>( 0 );
277 pMouse->SetCurrentPosition( GET_X_LPARAM( lParam ), GET_Y_LPARAM( lParam ) );
278
279 return 1;
280 }
281
282 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
283}
284
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68
#define TFIXME(DESC)
Definition Defines.h:135
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TTODO(DESC)
Definition Defines.h:134
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TGetClass(CLASS)
Definition TObject.h:13
#define TDEFINE_CLASS(...)
Definition TObject.h:120
TSystemManager g_oSystemManager
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TInputDevice * GetDeviceByIndex(TClass *a_pClass, TUINT a_uiIndex)
static void SetFocused(TBOOL a_bFocused)
TBOOL Create(TRenderInterface *renderer, LPCSTR title)
static TBOOL ms_bIsFocused
Definition TMSWindow.h:65
void UnregisterWindowClass()
void Update(TFLOAT a_fDeltaTime)
Definition TMSWindow.cpp:39
void SetPosition(UINT x, UINT y, UINT width, UINT height)
static STICKYKEYS ms_StickyKeys
Definition TMSWindow.h:67
DirectX 8 implementation of the render interface Handles DirectX 8 specific rendering functionality a...
TFORCEINLINE IDirect3DDevice8 * GetDirect3DDevice() const
Gets the Direct3D device.
void Exit()
Signals the render interface to exit.
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49
static TFORCEINLINE TInputInterface * GetSingletonSafe()
Definition TSingleton.h:37