Skip to content

Commit

Permalink
xrEngine: fix SDL window prop, return back SDL_PeepEvent Loop
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg authored and Xottab-DUTY committed Jul 24, 2018
1 parent d341b9b commit 7089912
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/xrEngine/Device_Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void CRenderDevice::Initialize()

if (!m_sdlWnd)
{
Uint32 flags = SDL_WINDOW_BORDERLESS;
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALWAYS_ON_TOP;

if (strstr(Core.Params, "-gl"))
flags |= SDL_WINDOW_OPENGL;
Expand Down
16 changes: 15 additions & 1 deletion src/xrEngine/Text_Console.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "Text_Console.h"
#include "line_editor.h"
#include "SDL_syswm.h"

extern char const* const ioc_prompt;
extern char const* const ch_cursor;
Expand Down Expand Up @@ -140,7 +141,20 @@ void CTextConsole::Initialize()
{
inherited::Initialize();

//m_pMainWnd = &Device.m_hWnd;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(Device.m_sdlWnd, &info))
{
switch (info.subsystem)
{
case SDL_SYSWM_WINDOWS:
m_pMainWnd = &info.info.win.window;
break;
default: break;
}
}
else
Log("Couldn't get window information: %s", SDL_GetError());
m_dwLastUpdateTime = Device.dwTimeGlobal;
m_last_time = Device.dwTimeGlobal;

Expand Down
15 changes: 9 additions & 6 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,16 @@ void CRenderDevice::message_loop()


SDL_PumpEvents();
/*

SDL_Event event;

SDL_PeepEvents(&event, 16, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_SYSWMEVENT);
while (SDL_QUIT != event.type)
{
if (SDL_PeepEvents(&event, 16, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT))
if (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_SYSWMEVENT))
{
switch (event.type)
{
case SDL_KEYDOWN: continue;
case SDL_WINDOWEVENT:
switch (event.window.event)
{
Expand All @@ -355,7 +354,9 @@ void CRenderDevice::message_loop()
SDL_PeepEvents(&event, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
continue;
#if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_TAKE_FOCUS:
case SDL_WINDOWEVENT_SHOWN:
case SDL_WINDOWEVENT_EXPOSED:
//case SDL_WINDOWEVENT_TAKE_FOCUS:
if (editor())
{
Device.b_is_Active = TRUE;
Expand All @@ -374,9 +375,11 @@ void CRenderDevice::message_loop()

on_idle();
}
*/

/*
while (true)
on_idle();
*/

}

Expand Down
2 changes: 0 additions & 2 deletions src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class ENGINE_API CRenderDeviceData
MessageRegistry<pureScreenResolutionChanged> seqResolutionChanged;

SDL_Window* m_sdlWnd;
// HWND m_hWnd;
};

class ENGINE_API CRenderDeviceBase : public IRenderDevice, public CRenderDeviceData
Expand Down Expand Up @@ -165,7 +164,6 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase
void _SetupStates();

public:
// HWND m_hWnd;
SDL_Window* m_sdlWnd;
SDL_Renderer* m_sdlRndr;
LRESULT MsgProc(HWND, UINT, WPARAM, LPARAM);
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/x_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extern CInput* pInput;

CApplication::~CApplication()
{
//Console->Hide();
Console->Hide();

// font
xr_delete(pFontSystem);
Expand Down
43 changes: 20 additions & 23 deletions src/xrEngine/xr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,14 @@ void CInput::ClipCursor(bool clip)
{
if (clip)
{
//::ClipCursor(&Device.m_rcWindowClient);
SDL_RenderSetClipRect(Device.m_sdlRndr, &Device.m_rcWindowClient);
while (ShowCursor(FALSE) >= 0)
{
}
SDL_ShowCursor(SDL_DISABLE);
}
else
{
::ClipCursor(nullptr);
while (ShowCursor(TRUE) <= 0)
{
}
//::ClipCursor(nullptr);
SDL_ShowCursor(SDL_ENABLE);
}
}

Expand Down Expand Up @@ -317,22 +314,22 @@ void CInput::OnFrame(void)
// MouseUpdate(&event);
//MouseUpdate();
continue;
case SDL_WINDOWEVENT:
switch (event.window.event)
{
case SDL_WINDOWEVENT_CLOSE:
event.type = SDL_QUIT;
SDL_PushEvent(&event);
continue;
case SDL_WINDOWEVENT_ENTER:
#if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_TAKE_FOCUS:
RDEVICE.OnWM_Activate(event.window.data1, event.window.data2);
continue;
#endif
default: SDL_Log("Window %d got unknown event %d", event.window.windowID, event.window.event); continue;
}
continue;
// case SDL_WINDOWEVENT:
// switch (event.window.event)
// {
// case SDL_WINDOWEVENT_CLOSE:
// event.type = SDL_QUIT;
// SDL_PushEvent(&event);
// continue;
// case SDL_WINDOWEVENT_ENTER:
//#if SDL_VERSION_ATLEAST(2, 0, 5)
// case SDL_WINDOWEVENT_TAKE_FOCUS:
// RDEVICE.OnWM_Activate(event.window.data1, event.window.data2);
// continue;
//#endif
// default: SDL_Log("Window %d got unknown event %d", event.window.windowID, event.window.event); continue;
// }
// continue;
case SDL_QUIT:
Engine.Event.Defer("KERNEL:disconnect");
Engine.Event.Defer("KERNEL:quit");
Expand Down
21 changes: 19 additions & 2 deletions src/xrGame/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ui/UIBtnHint.h"
#include "xrEngine/IInputReceiver.h"
#include "xrEngine/xr_input.h"
#include "SDL_syswm.h"

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

Expand Down Expand Up @@ -126,7 +127,23 @@ void CUICursor::SetUICursorPosition(Fvector2 pos)
POINT p;
p.x = iFloor(vPos.x / (UI_BASE_WIDTH / (float)Device.m_rcWindowClient.w));
p.y = iFloor(vPos.y / (UI_BASE_HEIGHT / (float)Device.m_rcWindowClient.h));
//if (m_b_use_win_cursor)
// ClientToScreen(Device.m_hWnd, (LPPOINT)&p);
if (m_b_use_win_cursor)
{
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(Device.m_sdlWnd, &info))
{
switch (info.subsystem)
{
case SDL_SYSWM_WINDOWS :
ClientToScreen(info.info.win.window, (LPPOINT)&p);
break;
default : break;
}
}
else
Log("Couldn't get window information: %s", SDL_GetError());
}

SetCursorPos(p.x, p.y);
}

0 comments on commit 7089912

Please sign in to comment.