Skip to content

Commit 7089912

Browse files
eagleivgXottab-DUTY
authored andcommitted
xrEngine: fix SDL window prop, return back SDL_PeepEvent Loop
1 parent d341b9b commit 7089912

File tree

7 files changed

+65
-36
lines changed

7 files changed

+65
-36
lines changed

src/xrEngine/Device_Initialize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void CRenderDevice::Initialize()
4848

4949
if (!m_sdlWnd)
5050
{
51-
Uint32 flags = SDL_WINDOW_BORDERLESS;
51+
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALWAYS_ON_TOP;
5252

5353
if (strstr(Core.Params, "-gl"))
5454
flags |= SDL_WINDOW_OPENGL;

src/xrEngine/Text_Console.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "stdafx.h"
22
#include "Text_Console.h"
33
#include "line_editor.h"
4+
#include "SDL_syswm.h"
45

56
extern char const* const ioc_prompt;
67
extern char const* const ch_cursor;
@@ -140,7 +141,20 @@ void CTextConsole::Initialize()
140141
{
141142
inherited::Initialize();
142143

143-
//m_pMainWnd = &Device.m_hWnd;
144+
SDL_SysWMinfo info;
145+
SDL_VERSION(&info.version);
146+
if (SDL_GetWindowWMInfo(Device.m_sdlWnd, &info))
147+
{
148+
switch (info.subsystem)
149+
{
150+
case SDL_SYSWM_WINDOWS:
151+
m_pMainWnd = &info.info.win.window;
152+
break;
153+
default: break;
154+
}
155+
}
156+
else
157+
Log("Couldn't get window information: %s", SDL_GetError());
144158
m_dwLastUpdateTime = Device.dwTimeGlobal;
145159
m_last_time = Device.dwTimeGlobal;
146160

src/xrEngine/device.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,16 @@ void CRenderDevice::message_loop()
331331

332332

333333
SDL_PumpEvents();
334-
/*
334+
335335
SDL_Event event;
336336

337-
SDL_PeepEvents(&event, 16, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
337+
SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_SYSWMEVENT);
338338
while (SDL_QUIT != event.type)
339339
{
340-
if (SDL_PeepEvents(&event, 16, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT))
340+
if (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_SYSWMEVENT))
341341
{
342342
switch (event.type)
343343
{
344-
case SDL_KEYDOWN: continue;
345344
case SDL_WINDOWEVENT:
346345
switch (event.window.event)
347346
{
@@ -355,7 +354,9 @@ void CRenderDevice::message_loop()
355354
SDL_PeepEvents(&event, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
356355
continue;
357356
#if SDL_VERSION_ATLEAST(2, 0, 5)
358-
case SDL_WINDOWEVENT_TAKE_FOCUS:
357+
case SDL_WINDOWEVENT_SHOWN:
358+
case SDL_WINDOWEVENT_EXPOSED:
359+
//case SDL_WINDOWEVENT_TAKE_FOCUS:
359360
if (editor())
360361
{
361362
Device.b_is_Active = TRUE;
@@ -374,9 +375,11 @@ void CRenderDevice::message_loop()
374375

375376
on_idle();
376377
}
377-
*/
378+
379+
/*
378380
while (true)
379381
on_idle();
382+
*/
380383

381384
}
382385

src/xrEngine/device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class ENGINE_API CRenderDeviceData
119119
MessageRegistry<pureScreenResolutionChanged> seqResolutionChanged;
120120

121121
SDL_Window* m_sdlWnd;
122-
// HWND m_hWnd;
123122
};
124123

125124
class ENGINE_API CRenderDeviceBase : public IRenderDevice, public CRenderDeviceData
@@ -165,7 +164,6 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase
165164
void _SetupStates();
166165

167166
public:
168-
// HWND m_hWnd;
169167
SDL_Window* m_sdlWnd;
170168
SDL_Renderer* m_sdlRndr;
171169
LRESULT MsgProc(HWND, UINT, WPARAM, LPARAM);

src/xrEngine/x_ray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extern CInput* pInput;
137137

138138
CApplication::~CApplication()
139139
{
140-
//Console->Hide();
140+
Console->Hide();
141141

142142
// font
143143
xr_delete(pFontSystem);

src/xrEngine/xr_input.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,14 @@ void CInput::ClipCursor(bool clip)
193193
{
194194
if (clip)
195195
{
196+
//::ClipCursor(&Device.m_rcWindowClient);
196197
SDL_RenderSetClipRect(Device.m_sdlRndr, &Device.m_rcWindowClient);
197-
while (ShowCursor(FALSE) >= 0)
198-
{
199-
}
198+
SDL_ShowCursor(SDL_DISABLE);
200199
}
201200
else
202201
{
203-
::ClipCursor(nullptr);
204-
while (ShowCursor(TRUE) <= 0)
205-
{
206-
}
202+
//::ClipCursor(nullptr);
203+
SDL_ShowCursor(SDL_ENABLE);
207204
}
208205
}
209206

@@ -317,22 +314,22 @@ void CInput::OnFrame(void)
317314
// MouseUpdate(&event);
318315
//MouseUpdate();
319316
continue;
320-
case SDL_WINDOWEVENT:
321-
switch (event.window.event)
322-
{
323-
case SDL_WINDOWEVENT_CLOSE:
324-
event.type = SDL_QUIT;
325-
SDL_PushEvent(&event);
326-
continue;
327-
case SDL_WINDOWEVENT_ENTER:
328-
#if SDL_VERSION_ATLEAST(2, 0, 5)
329-
case SDL_WINDOWEVENT_TAKE_FOCUS:
330-
RDEVICE.OnWM_Activate(event.window.data1, event.window.data2);
331-
continue;
332-
#endif
333-
default: SDL_Log("Window %d got unknown event %d", event.window.windowID, event.window.event); continue;
334-
}
335-
continue;
317+
// case SDL_WINDOWEVENT:
318+
// switch (event.window.event)
319+
// {
320+
// case SDL_WINDOWEVENT_CLOSE:
321+
// event.type = SDL_QUIT;
322+
// SDL_PushEvent(&event);
323+
// continue;
324+
// case SDL_WINDOWEVENT_ENTER:
325+
//#if SDL_VERSION_ATLEAST(2, 0, 5)
326+
// case SDL_WINDOWEVENT_TAKE_FOCUS:
327+
// RDEVICE.OnWM_Activate(event.window.data1, event.window.data2);
328+
// continue;
329+
//#endif
330+
// default: SDL_Log("Window %d got unknown event %d", event.window.windowID, event.window.event); continue;
331+
// }
332+
// continue;
336333
case SDL_QUIT:
337334
Engine.Event.Defer("KERNEL:disconnect");
338335
Engine.Event.Defer("KERNEL:quit");

src/xrGame/UICursor.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ui/UIBtnHint.h"
66
#include "xrEngine/IInputReceiver.h"
77
#include "xrEngine/xr_input.h"
8+
#include "SDL_syswm.h"
89

910
#define C_DEFAULT color_xrgb(0xff, 0xff, 0xff)
1011

@@ -126,7 +127,23 @@ void CUICursor::SetUICursorPosition(Fvector2 pos)
126127
POINT p;
127128
p.x = iFloor(vPos.x / (UI_BASE_WIDTH / (float)Device.m_rcWindowClient.w));
128129
p.y = iFloor(vPos.y / (UI_BASE_HEIGHT / (float)Device.m_rcWindowClient.h));
129-
//if (m_b_use_win_cursor)
130-
// ClientToScreen(Device.m_hWnd, (LPPOINT)&p);
130+
if (m_b_use_win_cursor)
131+
{
132+
SDL_SysWMinfo info;
133+
SDL_VERSION(&info.version);
134+
if (SDL_GetWindowWMInfo(Device.m_sdlWnd, &info))
135+
{
136+
switch (info.subsystem)
137+
{
138+
case SDL_SYSWM_WINDOWS :
139+
ClientToScreen(info.info.win.window, (LPPOINT)&p);
140+
break;
141+
default : break;
142+
}
143+
}
144+
else
145+
Log("Couldn't get window information: %s", SDL_GetError());
146+
}
147+
131148
SetCursorPos(p.x, p.y);
132149
}

0 commit comments

Comments
 (0)