Browse Source

shift+left click working (without modifying engine)

pull/25/head
Xadhoom 7 years ago
parent
commit
f661e6dffa
  1. 1
      Stub/miniwin.h
  2. 184
      Stub/miniwin_msg_sdl.cpp
  3. 2
      Stub/stubs.h

1
Stub/miniwin.h

@ -571,6 +571,7 @@ HFILE WINAPI OpenFile(LPCSTR lpFileName, LPOFSTRUCT lpReOpenBuff, UINT uStyle);
#define MK_SHIFT 0x0004 #define MK_SHIFT 0x0004
#define MK_LBUTTON 0x0001 #define MK_LBUTTON 0x0001
#define MK_RBUTTON 0x0002
// //
// Total fakes // Total fakes

184
Stub/miniwin_msg_sdl.cpp

@ -4,21 +4,10 @@
*/ */
#include "../types.h" #include "../types.h"
PlayerStruct *PlayerS;
static std::deque<MSG> message_queue; static std::deque<MSG> message_queue;
static int translate_sdl_key(SDL_Keysym key) static int translate_sdl_key(SDL_Keysym key)
{ {
int sym = key.sym; int sym = key.sym;
switch (sym) { switch (sym) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
@ -69,18 +58,12 @@ static int translate_sdl_key(SDL_Keysym key)
return VK_OEM_PERIOD; return VK_OEM_PERIOD;
case SDLK_COMMA: case SDLK_COMMA:
return VK_OEM_COMMA; return VK_OEM_COMMA;
case SDLK_LSHIFT:
// case SDLK_LSHIFT: return VK_SHIFT;
// printf("Fooooooo\n");
//PlayerS._pmode = 5;
//
// return VK_SHIFT;
case SDLK_RSHIFT: case SDLK_RSHIFT:
// Not handled yet return VK_SHIFT; // why not?
return -1;
default: default:
if (sym >= SDLK_a && sym <= SDLK_z) { if (sym >= SDLK_a && sym <= SDLK_z) {
return 'A' + (sym - SDLK_a); return 'A' + (sym - SDLK_a);
} else if (sym >= SDLK_0 && sym <= SDLK_9) { } else if (sym >= SDLK_0 && sym <= SDLK_9) {
@ -88,100 +71,125 @@ static int translate_sdl_key(SDL_Keysym key)
} else if (sym >= SDLK_F1 && sym <= SDLK_F12) { } else if (sym >= SDLK_F1 && sym <= SDLK_F12) {
return VK_F1 + (sym - SDLK_F1); return VK_F1 + (sym - SDLK_F1);
} }
DUMMY_PRINT("unknown key: name=%s sym=0x%X scan=%d mod=0x%X", SDL_GetKeyName(sym), sym, key.scancode, key.mod); DUMMY_PRINT("unknown key: name=%s sym=0x%X scan=%d mod=0x%X", SDL_GetKeyName(sym), sym, key.scancode, key.mod);
return -1; return -1;
} }
} }
WPARAM keystate_for_mouse(WPARAM ret)
{
const Uint8 *keystate = SDL_GetKeyboardState(NULL);
ret |= keystate[SDL_SCANCODE_LSHIFT] ? MK_SHIFT : 0;
// XXX: other MK_* codes not implemented
return ret;
}
static WINBOOL false_avail()
{
DUMMY_PRINT("return FALSE although event avaliable");
return FALSE;
}
WINBOOL WINAPI PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) WINBOOL WINAPI PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg)
{ {
// DUMMY_PRINT("hwnd: %d", hWnd); if(wMsgFilterMin != 0)
assert(wMsgFilterMin == 0 && wMsgFilterMax == 0); UNIMPLEMENTED();
if (wRemoveMsg == PM_NOREMOVE) { if(wMsgFilterMax != 0)
// XXX: This does not actually fill out lpMsg properly UNIMPLEMENTED();
lpMsg->hwnd = (HWND)-1; if(hWnd != NULL)
lpMsg->message = 0; UNIMPLEMENTED();
if (wRemoveMsg == PM_NOREMOVE) {
// This does not actually fill out lpMsg, but this is ok
// since the engine never uses it in this case
return !message_queue.empty() || SDL_PollEvent(NULL); return !message_queue.empty() || SDL_PollEvent(NULL);
} else if (wRemoveMsg == PM_REMOVE) { }
if (!message_queue.empty()) { if (wRemoveMsg != PM_REMOVE) {
*lpMsg = message_queue.front(); UNIMPLEMENTED();
message_queue.pop_front(); }
return TRUE;
}
SDL_Event e;
int pending = SDL_PollEvent(&e);
if (!pending) {
return FALSE;
}
lpMsg->hwnd = hWnd; if (!message_queue.empty()) {
lpMsg->lParam = 0; *lpMsg = message_queue.front();
lpMsg->wParam = 0; message_queue.pop_front();
return TRUE;
}
switch (e.type) { SDL_Event e;
case SDL_QUIT: { int pending = SDL_PollEvent(&e);
lpMsg->message = WM_QUIT; if (!pending) {
break; return FALSE;
} }
case SDL_KEYDOWN: lpMsg->hwnd = hWnd;
case SDL_KEYUP: { lpMsg->lParam = 0;
lpMsg->wParam = 0;
switch (e.type) {
case SDL_QUIT:
lpMsg->message = WM_QUIT;
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
{
int key = translate_sdl_key(e.key.keysym); int key = translate_sdl_key(e.key.keysym);
if (key == -1) { if (key == -1)
return FALSE; return false_avail();
} lpMsg->message = e.type == SDL_KEYDOWN ? WM_KEYDOWN : WM_KEYUP;
lpMsg->message = e.type == SDL_KEYDOWN ? WM_KEYFIRST : WM_KEYUP;
lpMsg->wParam = (DWORD)key; lpMsg->wParam = (DWORD)key;
// Hack: Encode modifier in lParam for TranslateMessage later // HACK: Encode modifier in lParam for TranslateMessage later
lpMsg->lParam = e.key.keysym.mod << 16; lpMsg->lParam = e.key.keysym.mod << 16;
break;
} }
break;
case SDL_MOUSEMOTION: { case SDL_MOUSEMOTION:
lpMsg->message = WM_MOUSEMOVE; lpMsg->message = WM_MOUSEMOVE;
lpMsg->lParam = (e.motion.y << 16) | (e.motion.x & 0xFFFF); lpMsg->lParam = (e.motion.y << 16) | (e.motion.x & 0xFFFF);
break; lpMsg->wParam = keystate_for_mouse(0);
} break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONDOWN: {
case SDL_MOUSEBUTTONUP: {
int button = e.button.button; int button = e.button.button;
if (button != SDL_BUTTON_LEFT && button != SDL_BUTTON_RIGHT) { if(button == SDL_BUTTON_LEFT) {
return FALSE; lpMsg->message = WM_LBUTTONDOWN;
lpMsg->lParam = (e.button.y << 16) | (e.button.x & 0xFFFF);
lpMsg->wParam = keystate_for_mouse(MK_LBUTTON);
} else if(button == SDL_BUTTON_RIGHT) {
lpMsg->message = WM_RBUTTONDOWN;
lpMsg->lParam = (e.button.y << 16) | (e.button.x & 0xFFFF);
lpMsg->wParam = keystate_for_mouse(MK_RBUTTON);
} else {
return false_avail();
} }
bool left = button == SDL_BUTTON_LEFT;
lpMsg->message = e.type == SDL_MOUSEBUTTONDOWN ? (left ? WM_LBUTTONDOWN : WM_RBUTTONDOWN)
: (left ? WM_LBUTTONUP : WM_RBUTTONUP);
lpMsg->lParam = (e.button.y << 16) | (e.button.x & 0xFFFF);
break;
}
case SDL_TEXTINPUT:
case SDL_WINDOWEVENT: {
return FALSE;
}
default: {
DUMMY_PRINT("unknown SDL message 0x%X", e.type);
return FALSE;
} }
break;
case SDL_MOUSEBUTTONUP:
{
int button = e.button.button;
if(button == SDL_BUTTON_LEFT) {
lpMsg->message = WM_LBUTTONUP;
lpMsg->lParam = (e.button.y << 16) | (e.button.x & 0xFFFF);
lpMsg->wParam = keystate_for_mouse(0);
} else if(button == SDL_BUTTON_RIGHT) {
lpMsg->message = WM_RBUTTONUP;
lpMsg->lParam = (e.button.y << 16) | (e.button.x & 0xFFFF);
lpMsg->wParam = keystate_for_mouse(0);
} else {
return false_avail();
}
} }
break;
return TRUE; case SDL_TEXTINPUT:
case SDL_WINDOWEVENT:
return false_avail();
default:
DUMMY_PRINT("unknown SDL message 0x%X", e.type);
return false_avail();
} }
UNIMPLEMENTED(); return TRUE;
} }
WINBOOL WINAPI TranslateMessage(CONST MSG *lpMsg) WINBOOL WINAPI TranslateMessage(CONST MSG *lpMsg)
{ {
DUMMY_ONCE();
assert(lpMsg->hwnd == 0); assert(lpMsg->hwnd == 0);
if (lpMsg->message == WM_KEYDOWN) { if (lpMsg->message == WM_KEYDOWN) {
int key = lpMsg->wParam; int key = lpMsg->wParam;
unsigned mod = (DWORD)lpMsg->lParam >> 16; unsigned mod = (DWORD)lpMsg->lParam >> 16;

2
Stub/stubs.h

@ -23,7 +23,7 @@
} \ } \
} while(0) } while(0)
#define DUMMY_PRINT(fmt, ...) eprintf("DUMMY: %s : " fmt "\n", __FUNCTION__, __VA_ARGS__) #define DUMMY_PRINT(fmt, ...) eprintf("DUMMY: %s : " fmt "\n", __FUNCTION__, ## __VA_ARGS__)
static inline const char *nullstr(const char *a) static inline const char *nullstr(const char *a)
{ {

Loading…
Cancel
Save