Merge branch 'sdl-mouse'

liquid_container
Günther Brammer 2016-02-12 21:11:21 +01:00
commit c332fe940b
7 changed files with 36 additions and 39 deletions

View File

@ -695,12 +695,16 @@ void C4Application::GameTick()
}
if(Config.Graphics.Windowed == 2 && FullScreenMode())
Application.SetVideoMode(GetConfigWidth(), GetConfigHeight(), Config.Graphics.RefreshRate, Config.Graphics.Monitor, true);
if (!isEditor)
pWindow->GrabMouse(true);
break;
case C4AS_AfterGame:
// stop game
Game.Clear();
if(Config.Graphics.Windowed == 2 && !NextMission && !isEditor)
Application.SetVideoMode(GetConfigWidth(), GetConfigHeight(), Config.Graphics.RefreshRate, Config.Graphics.Monitor, false);
if (!isEditor)
pWindow->GrabMouse(false);
AppState = C4AS_PreInit;
// if a next mission is desired, set to start it
if (NextMission)

View File

@ -31,45 +31,20 @@
static void sdlToC4MCBtn(const SDL_MouseButtonEvent &e, int32_t& button, DWORD& flags)
{
C4TimeMilliseconds lastLeftClick = C4TimeMilliseconds::Now();
C4TimeMilliseconds lastRightClick = C4TimeMilliseconds::Now();
static int lastX = 0, lastY = 0;
static const int clickDist = 2;
static const int clickDelay = 400;
button = C4MC_Button_None;
flags = 0;
flags = SDL_GetModState();
switch (e.button)
{
case SDL_BUTTON_LEFT:
if (e.state == SDL_PRESSED)
if (C4TimeMilliseconds::Now() - lastLeftClick < clickDelay && abs(lastX-e.x) <= clickDist && abs(lastY-e.y) <= clickDist)
{
lastLeftClick = 0;
button = C4MC_Button_LeftDouble;
}
else
{
lastLeftClick = C4TimeMilliseconds::Now();
button = C4MC_Button_LeftDown;
}
button = e.clicks == 2 ? C4MC_Button_LeftDouble : C4MC_Button_LeftDown;
else
button = C4MC_Button_LeftUp;
break;
case SDL_BUTTON_RIGHT:
if (e.state == SDL_PRESSED)
if (C4TimeMilliseconds::Now() - lastRightClick < clickDelay)
{
lastRightClick = 0;
button = C4MC_Button_RightDouble;
}
else
{
lastRightClick = C4TimeMilliseconds::Now();
button = C4MC_Button_RightDown;
}
button = e.clicks == 2 ? C4MC_Button_RightDouble : C4MC_Button_RightDown;
else
button = C4MC_Button_RightUp;
break;
@ -79,17 +54,7 @@ static void sdlToC4MCBtn(const SDL_MouseButtonEvent &e, int32_t& button, DWORD&
else
button = C4MC_Button_MiddleUp;
break;
/*case SDL_BUTTON_WHEELUP:
button = C4MC_Button_Wheel;
flags = (+32) << 16;
break;
case SDL_BUTTON_WHEELDOWN:
button = C4MC_Button_Wheel;
flags = (-32) << 16;
break;*/
}
lastX = e.x;
lastY = e.y;
}
/* C4AbstractApp */
@ -156,6 +121,7 @@ bool C4AbstractApp::FlushMessages()
void C4AbstractApp::HandleSDLEvent(SDL_Event& e)
{
DWORD flags;
// Directly handle QUIT messages.
switch (e.type)
{
@ -186,10 +152,16 @@ void C4AbstractApp::HandleSDLEvent(SDL_Event& e)
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
int32_t button;
DWORD flags;
sdlToC4MCBtn(e.button, button, flags);
C4GUI::MouseMove(button, e.button.x, e.button.y, flags, NULL);
break;
case SDL_MOUSEWHEEL:
flags = e.wheel.y > 0 ? (+32) << 16 : (DWORD) (-32) << 16;
flags += SDL_GetModState();
int x, y;
SDL_GetMouseState(&x, &y);
C4GUI::MouseMove(C4MC_Button_Wheel, x, y, flags, NULL);
break;
case SDL_JOYAXISMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBALLMOTION:

View File

@ -381,6 +381,7 @@ public:
void SetSize(unsigned int cx, unsigned int cy); // resize
void SetTitle(const char * Title);
void FlashWindow();
void GrabMouse(bool grab);
// request that this window be redrawn in the near future (including immediately)
virtual void RequestUpdate();
// Invokes actual drawing code - should not be called directly

View File

@ -605,6 +605,11 @@ void C4Window::FlashWindow()
//FIXME - how is this reset? gtk_window_set_urgency_hint(window, true);
}
void C4Window::GrabMouse(bool grab)
{
// TODO
}
C4Window* C4Window::Init(WindowKind windowKind, C4AbstractApp * pApp, const char * Title, const C4Rect * size)
{
Active = true;

View File

@ -136,6 +136,11 @@ void C4Window::SetSize(unsigned int cx, unsigned int cy)
[controller setContentSize:NSMakeSize(cx, cy)];
}
void C4Window::GrabMouse(bool grab)
{
// TODO
}
void C4Window::RequestUpdate()
{
[ctrler.openGLView display];

View File

@ -119,3 +119,8 @@ void C4Window::RequestUpdate()
void C4Window::FlashWindow()
{
}
void C4Window::GrabMouse(bool grab)
{
SDL_SetWindowGrab(window, grab ? SDL_TRUE : SDL_FALSE);
}

View File

@ -761,6 +761,11 @@ void C4Window::FlashWindow()
::FlashWindow(hWindow, FLASHW_ALL | FLASHW_TIMERNOFG);
}
void C4Window::GrabMouse(bool grab)
{
// TODO
}
void C4Window::EnumerateMultiSamples(std::vector<int>& samples) const
{
#ifndef USE_CONSOLE