Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge X11+D3D FreeLook feature into DolphinWX
This removes the redundant code and also implements this feature for OSX and Wayland.
But so it's dropped for non-wx builds...

imo DolphinWX still isn't the best place for this, but now it's in the same file as all other hotkeys. Maybe they'll be moved to InputCommon sometimes at once ...
  • Loading branch information
degasus committed Nov 29, 2013
1 parent 95aeede commit 69137cf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 110 deletions.
53 changes: 53 additions & 0 deletions Source/Core/DolphinWX/Src/Frame.cpp
Expand Up @@ -1028,6 +1028,59 @@ void CFrame::OnMouse(wxMouseEvent& event)
event.GetPosition().x, event.GetPosition().y, event.ButtonDown());
}
#endif

// next handlers are all for FreeLook, so we don't need to check them if disabled
if(!g_Config.bFreeLook)
{
event.Skip();
return;
}

// Free look variables
static bool mouseLookEnabled = false;
static bool mouseMoveEnabled = false;
static float lastMouse[2];

if(event.MiddleDown())
{
lastMouse[0] = event.GetX();
lastMouse[1] = event.GetY();
mouseMoveEnabled = true;
}
else if(event.RightDown())
{
lastMouse[0] = event.GetX();
lastMouse[1] = event.GetY();
mouseLookEnabled = true;
}
else if(event.MiddleUp())
{
mouseMoveEnabled = false;
}
else if(event.RightUp())
{
mouseLookEnabled = false;
}
// no button, so it's a move event
else if(event.GetButton() == wxMOUSE_BTN_NONE)
{
if (mouseLookEnabled)
{
VertexShaderManager::RotateView((event.GetX() - lastMouse[0]) / 200.0f,
(event.GetY() - lastMouse[1]) / 200.0f);
lastMouse[0] = event.GetX();
lastMouse[1] = event.GetY();
}

if (mouseMoveEnabled)
{
VertexShaderManager::TranslateView((event.GetX() - lastMouse[0]) / 50.0f,
(event.GetY() - lastMouse[1]) / 50.0f);
lastMouse[0] = event.GetX();
lastMouse[1] = event.GetY();
}
}

event.Skip();
}

Expand Down
57 changes: 0 additions & 57 deletions Source/Core/DolphinWX/Src/GLInterface/X11_Util.cpp
Expand Up @@ -18,7 +18,6 @@
#include "Host.h"
#include "VideoConfig.h"
#include "../GLInterface.h"
#include "VertexShaderManager.h"

#if USE_EGL
bool cXInterface::ServerConnect(void)
Expand Down Expand Up @@ -166,69 +165,13 @@ void cX11Window::DestroyXWindow(void)
void cX11Window::XEventThread()
#endif
{
// Free look variables
static bool mouseLookEnabled = false;
static bool mouseMoveEnabled = false;
static float lastMouse[2];
while (GLWin.win)
{
XEvent event;
for (int num_events = XPending(GLWin.evdpy); num_events > 0; num_events--)
{
XNextEvent(GLWin.evdpy, &event);
switch(event.type) {
case ButtonPress:
if (g_Config.bFreeLook)
{
switch (event.xbutton.button)
{
case 2: // Middle button
lastMouse[0] = event.xbutton.x;
lastMouse[1] = event.xbutton.y;
mouseMoveEnabled = true;
break;
case 3: // Right button
lastMouse[0] = event.xbutton.x;
lastMouse[1] = event.xbutton.y;
mouseLookEnabled = true;
break;
}
}
break;
case ButtonRelease:
if (g_Config.bFreeLook)
{
switch (event.xbutton.button)
{
case 2: // Middle button
mouseMoveEnabled = false;
break;
case 3: // Right button
mouseLookEnabled = false;
break;
}
}
break;
case MotionNotify:
if (g_Config.bFreeLook)
{
if (mouseLookEnabled)
{
VertexShaderManager::RotateView((event.xmotion.x - lastMouse[0]) / 200.0f,
(event.xmotion.y - lastMouse[1]) / 200.0f);
lastMouse[0] = event.xmotion.x;
lastMouse[1] = event.xmotion.y;
}

if (mouseMoveEnabled)
{
VertexShaderManager::TranslateView((event.xmotion.x - lastMouse[0]) / 50.0f,
(event.xmotion.y - lastMouse[1]) / 50.0f);
lastMouse[0] = event.xmotion.x;
lastMouse[1] = event.xmotion.y;
}
}
break;
case ConfigureNotify:
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
break;
Expand Down
53 changes: 0 additions & 53 deletions Source/Core/VideoCommon/Src/EmuWindow.cpp
Expand Up @@ -7,7 +7,6 @@
#include "VideoConfig.h"
#include "EmuWindow.h"
#include "Fifo.h"
#include "VertexShaderManager.h"
#include "VideoBackendBase.h"
#include "Core.h"
#include "Host.h"
Expand Down Expand Up @@ -41,60 +40,8 @@ HWND GetParentWnd()
return m_hParent;
}

void FreeLookInput( UINT iMsg, WPARAM wParam )
{
static bool mouseLookEnabled = false;
static bool mouseMoveEnabled = false;
static float lastMouse[2];
POINT point;

switch(iMsg)
{
case WM_MOUSEMOVE:
if (mouseLookEnabled)
{
GetCursorPos(&point);
VertexShaderManager::RotateView((point.x - lastMouse[0]) / 200.0f, (point.y - lastMouse[1]) / 200.0f);
lastMouse[0] = (float)point.x;
lastMouse[1] = (float)point.y;
}

if (mouseMoveEnabled)
{
GetCursorPos(&point);
VertexShaderManager::TranslateView((point.x - lastMouse[0]) / 50.0f, (point.y - lastMouse[1]) / 50.0f);
lastMouse[0] = (float)point.x;
lastMouse[1] = (float)point.y;
}
break;

case WM_RBUTTONDOWN:
GetCursorPos(&point);
lastMouse[0] = (float)point.x;
lastMouse[1] = (float)point.y;
mouseLookEnabled= true;
break;
case WM_MBUTTONDOWN:
GetCursorPos(&point);
lastMouse[0] = (float)point.x;
lastMouse[1] = (float)point.y;
mouseMoveEnabled= true;
break;
case WM_RBUTTONUP:
mouseLookEnabled = false;
break;
case WM_MBUTTONUP:
mouseMoveEnabled = false;
break;
}
}


LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
{
if (g_ActiveConfig.bFreeLook)
FreeLookInput( iMsg, wParam );

switch( iMsg )
{
case WM_PAINT:
Expand Down

0 comments on commit 69137cf

Please sign in to comment.