2016-03-29 03:03:54 +02:00
|
|
|
/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <Engine/Base/Types.h>
|
2016-04-09 08:18:57 +02:00
|
|
|
#include <Engine/Base/Assert.h>
|
2016-03-29 03:03:54 +02:00
|
|
|
#include <Engine/Base/SDL/SDLEvents.h>
|
|
|
|
#include "SDL.h"
|
|
|
|
|
2016-04-09 08:18:57 +02:00
|
|
|
SDL_EventType WM_SYSKEYDOWN;
|
|
|
|
SDL_EventType WM_LBUTTONDOWN;
|
|
|
|
SDL_EventType WM_LBUTTONUP;
|
|
|
|
SDL_EventType WM_RBUTTONDOWN;
|
|
|
|
SDL_EventType WM_RBUTTONUP;
|
|
|
|
SDL_EventType WM_PAINT;
|
2016-03-29 03:03:54 +02:00
|
|
|
|
|
|
|
// This keeps the input subsystem in sync with everything else, by
|
|
|
|
// making sure all SDL events tunnel through one function.
|
|
|
|
extern int SE_SDL_InputEventPoll(SDL_Event *event);
|
|
|
|
|
|
|
|
|
2016-04-09 08:18:57 +02:00
|
|
|
// !!! FIXME: maybe not try to emulate win32 here?
|
2016-03-29 03:03:54 +02:00
|
|
|
BOOL PeekMessage(MSG *msg, void *hwnd, UINT wMsgFilterMin,
|
|
|
|
UINT wMsgFilterMax, UINT wRemoveMsg)
|
|
|
|
{
|
2016-04-09 08:18:57 +02:00
|
|
|
ASSERT(msg != NULL);
|
|
|
|
ASSERT(wRemoveMsg == PM_REMOVE);
|
|
|
|
ASSERT(wMsgFilterMin == 0);
|
|
|
|
ASSERT(wMsgFilterMax == 0);
|
2016-03-29 03:03:54 +02:00
|
|
|
|
|
|
|
SDL_Event sdlevent;
|
2016-04-09 08:18:57 +02:00
|
|
|
while (SE_SDL_InputEventPoll(&sdlevent))
|
2016-03-29 03:03:54 +02:00
|
|
|
{
|
2016-04-09 08:18:57 +02:00
|
|
|
SDL_zerop(msg);
|
|
|
|
msg->message = sdlevent.type;
|
|
|
|
|
|
|
|
switch (sdlevent.type)
|
|
|
|
{
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
msg->lParam = (
|
|
|
|
((sdlevent.motion.y << 16) & 0xFFFF0000) |
|
|
|
|
((sdlevent.motion.x ) & 0x0000FFFF)
|
|
|
|
);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
if (sdlevent.key.keysym.mod & KMOD_ALT)
|
|
|
|
msg->message = WM_SYSKEYDOWN;
|
|
|
|
// deliberate fall through...
|
|
|
|
case SDL_KEYUP:
|
|
|
|
if (sdlevent.key.keysym.sym == SDLK_BACKQUOTE)
|
|
|
|
msg->unicode = '~'; // !!! FIXME: this is all a hack.
|
2020-07-11 10:26:01 +02:00
|
|
|
#if defined(PLATFORM_PANDORA) || defined(PLATFORM_PYRA)
|
2016-04-12 22:29:39 +02:00
|
|
|
if(sdlevent.key.keysym.sym == SDLK_RCTRL) {
|
|
|
|
msg->message = (sdlevent.type==SDL_KEYDOWN)?WM_RBUTTONDOWN:WM_RBUTTONUP;
|
|
|
|
} else if(sdlevent.key.keysym.sym == SDLK_RSHIFT) {
|
|
|
|
msg->message = (sdlevent.type==SDL_KEYDOWN)?WM_LBUTTONDOWN:WM_LBUTTONUP;
|
|
|
|
} else
|
|
|
|
#endif
|
2016-04-09 08:18:57 +02:00
|
|
|
msg->wParam = sdlevent.key.keysym.sym;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case SDL_TEXTINPUT:
|
|
|
|
msg->wParam = sdlevent.text.text[0]; // !!! FIXME: dropping characters!
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case SDL_MOUSEWHEEL:
|
|
|
|
if (sdlevent.wheel.y > 0) // wheel up
|
|
|
|
msg->wParam = 120 << 16; // !!! FIXME: deal with actual y value.
|
|
|
|
else if (sdlevent.wheel.y < 0) // wheel down
|
|
|
|
msg->wParam = -(120 << 16); // !!! FIXME: deal with actual y value.
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
if (sdlevent.button.button == SDL_BUTTON_LEFT)
|
|
|
|
msg->message = (sdlevent.button.state == SDL_PRESSED) ? WM_LBUTTONDOWN : WM_LBUTTONUP;
|
|
|
|
else if (sdlevent.button.button == SDL_BUTTON_RIGHT)
|
|
|
|
msg->message = (sdlevent.button.state == SDL_PRESSED) ? WM_RBUTTONDOWN : WM_RBUTTONUP;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
if (sdlevent.window.event == SDL_WINDOWEVENT_EXPOSED)
|
|
|
|
{
|
|
|
|
msg->message = WM_PAINT;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// These all map to WM_* things without any drama.
|
|
|
|
case SDL_QUIT:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
} // switch
|
|
|
|
} // while
|
|
|
|
|
|
|
|
return FALSE;
|
2016-03-29 03:03:54 +02:00
|
|
|
} // PeekMessage
|
|
|
|
|
|
|
|
|
|
|
|
void TranslateMessage(MSG *msg)
|
|
|
|
{
|
2016-04-09 08:18:57 +02:00
|
|
|
// do nothing.
|
2016-03-29 03:03:54 +02:00
|
|
|
} // TranslateMessage
|
|
|
|
|
|
|
|
|
|
|
|
void DispatchMessage(MSG *msg)
|
|
|
|
{
|
|
|
|
// do nothing.
|
|
|
|
} // DispatchMessage
|
|
|
|
|
|
|
|
|
|
|
|
SHORT GetKeyState(int vk)
|
|
|
|
{
|
|
|
|
SHORT retval = 0;
|
2020-06-13 21:21:52 +02:00
|
|
|
#if defined(PLATFORM_PANDORA) || defined(PLATFORM_PYRA)
|
2016-04-12 22:29:39 +02:00
|
|
|
Uint8 *keystate = SDL_GetKeyboardState(NULL);
|
|
|
|
#endif
|
2016-03-29 03:03:54 +02:00
|
|
|
|
|
|
|
switch (vk)
|
|
|
|
{
|
|
|
|
case VK_LBUTTON:
|
|
|
|
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LMASK)
|
|
|
|
retval = 0x8000;
|
2020-06-13 21:21:52 +02:00
|
|
|
#if defined(PLATFORM_PANDORA) || defined(PLATFORM_PYRA)
|
2016-04-12 22:29:39 +02:00
|
|
|
if(keystate[SDL_SCANCODE_RSHIFT])
|
|
|
|
retval = 0x8000;
|
|
|
|
#endif
|
2016-03-29 03:03:54 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_RBUTTON:
|
|
|
|
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_RMASK)
|
|
|
|
retval = 0x8000;
|
2020-06-13 21:21:52 +02:00
|
|
|
#if defined(PLATFORM_PANDORA) || defined(PLATFORM_PYRA)
|
2016-04-12 22:29:39 +02:00
|
|
|
if(keystate[SDL_SCANCODE_RCTRL])
|
|
|
|
retval = 0x8000;
|
|
|
|
#endif
|
2016-03-29 03:03:54 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_MBUTTON:
|
|
|
|
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_MMASK)
|
|
|
|
retval = 0x8000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-04-09 08:18:57 +02:00
|
|
|
STUBBED("this can't possibly be right, yeah?");
|
2020-06-13 21:21:52 +02:00
|
|
|
#if defined(PLATFORM_PANDORA) || defined(PLATFORM_PYRA)
|
2016-04-12 22:29:39 +02:00
|
|
|
if (keystate[SDL_GetScancodeFromKey((SDL_Keycode)vk)])
|
|
|
|
#else
|
2016-04-09 08:18:57 +02:00
|
|
|
if (SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey((SDL_Keycode)vk)])
|
2016-04-12 22:29:39 +02:00
|
|
|
#endif
|
2016-03-29 03:03:54 +02:00
|
|
|
retval = 0x8000;
|
|
|
|
break;
|
|
|
|
} // switch
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
} // GetKeyState
|
|
|
|
|
|
|
|
|
|
|
|
SHORT GetAsyncKeyState(int vk)
|
|
|
|
{
|
|
|
|
return(GetKeyState(vk));
|
|
|
|
} // GetAsyncKeyState
|
|
|
|
|
|
|
|
|
|
|
|
BOOL GetCursorPos(LPPOINT lpPoint)
|
|
|
|
{
|
2016-04-09 08:18:57 +02:00
|
|
|
ASSERT(lpPoint != NULL);
|
2016-03-29 03:03:54 +02:00
|
|
|
|
|
|
|
int x, y;
|
|
|
|
SDL_GetMouseState(&x, &y);
|
|
|
|
lpPoint->x = x;
|
|
|
|
lpPoint->y = y;
|
|
|
|
return(TRUE);
|
|
|
|
} // GetCursorPos
|
|
|
|
|
|
|
|
|
|
|
|
BOOL ScreenToClient(void *hWnd, LPPOINT lpPoint)
|
|
|
|
{
|
|
|
|
// do nothing. SDL returns points in client coordinates already.
|
2016-04-09 08:18:57 +02:00
|
|
|
return 1; // success. :)
|
2016-03-29 03:03:54 +02:00
|
|
|
} // ScreenToClient
|
|
|
|
|
|
|
|
|
|
|
|
int ShowCursor(BOOL yes)
|
|
|
|
{
|
|
|
|
static int count = 0;
|
|
|
|
count += (yes) ? 1 : -1;
|
2016-04-09 08:18:57 +02:00
|
|
|
SDL_ShowCursor((count >= 0) ? SDL_TRUE : SDL_FALSE);
|
|
|
|
return count;
|
2016-03-29 03:03:54 +02:00
|
|
|
} // ShowCursor
|
|
|
|
|
2016-04-09 08:18:57 +02:00
|
|
|
BOOL IsIconic(void *hwnd)
|
|
|
|
{
|
|
|
|
return (hwnd != NULL) && ((SDL_GetWindowFlags((SDL_Window *) hwnd) & SDL_WINDOW_MINIMIZED) == SDL_WINDOW_MINIMIZED);
|
|
|
|
}
|
|
|
|
|
2016-03-29 03:03:54 +02:00
|
|
|
// end of SDLEvents.cpp ...
|
|
|
|
|
|
|
|
|