diff --git a/singe/Framework.singe b/singe/Framework.singe index deb1e0f4e..4114f0281 100644 --- a/singe/Framework.singe +++ b/singe/Framework.singe @@ -346,10 +346,45 @@ GAMEPAD_3_MAX = GAMEPAD_1_MAX + 200 GAMEPAD_4_MIN = GAMEPAD_1_MAX + 300 GAMEPAD_4_MAX = GAMEPAD_1_MAX + 300 +MOUSE_1 = { + BUTTON_LEFT = { name = "BUTTON_LEFT", value = 1000 }, + BUTTON_RIGHT = { name = "BUTTON_RIGHT", value = 1001 }, + BUTTON_MIDDLE = { name = "BUTTON_MIDDLE", value = 1002 }, + BUTTON_X1 = { name = "BUTTON_X1", value = 1003 }, + BUTTON_X2 = { name = "BUTTON_X2", value = 1004 }, + WHEEL_UP = { name = "WHEEL_UP", value = 1005 }, + WHEEL_DOWN = { name = "WHEEL_DOWN", value = 1006 } +} + +MOUSE_1_MIN = 1000 +MOUSE_1_MAX = 1006 + +MOUSE_2 = deepcopy(MOUSE_1) +MOUSE_3 = deepcopy(MOUSE_1) +MOUSE_4 = deepcopy(MOUSE_1) + +for key, value in pairs(MOUSE_1) do + MOUSE_2[key].value = MOUSE_2[key].value + 100 + MOUSE_3[key].value = MOUSE_3[key].value + 200 + MOUSE_4[key].value = MOUSE_4[key].value + 300 +end + +MOUSE_2_MIN = MOUSE_1_MAX + 100 +MOUSE_2_MAX = MOUSE_1_MAX + 100 + +MOUSE_3_MIN = MOUSE_1_MAX + 200 +MOUSE_3_MAX = MOUSE_1_MAX + 200 + +MOUSE_4_MIN = MOUSE_1_MAX + 300 +MOUSE_4_MAX = MOUSE_1_MAX + 300 + SWITCH_BUTTON4 = 21 SWITCH_TILT = 22 SWITCH_GRAB = 23 +MOUSE_SINGLE = 100 +MOUSE_MANY = 200 + -- Singe 1.xx Features @@ -389,3 +424,6 @@ SOUND_ERROR_FULL = -2 OVERLAY_NOT_UPDATED = 0 OVERLAY_UPDATED = 1 + +SINGLE_MOUSE = 100 +MANY_MOUSE = 200 diff --git a/singe/controls.cfg b/singe/controls.cfg index 392f2f095..08da4ed35 100644 --- a/singe/controls.cfg +++ b/singe/controls.cfg @@ -10,10 +10,10 @@ INPUT_1P_COIN = { SCANCODE.MAIN_5, SCANCODE.C, GAMEPAD_1.BUTTON_LEFT_BUMPER INPUT_2P_COIN = { SCANCODE.MAIN_6 } INPUT_1P_START = { SCANCODE.MAIN_1, GAMEPAD_1.BUTTON_RIGHT_BUMPER } INPUT_2P_START = { SCANCODE.MAIN_2 } -INPUT_ACTION_1 = { SCANCODE.SPACE, SCANCODE.LCTRL, GAMEPAD_1.BUTTON_A } -INPUT_ACTION_2 = { SCANCODE.LALT, GAMEPAD_1.BUTTON_B } -INPUT_ACTION_3 = { SCANCODE.LSHIFT, GAMEPAD_1.BUTTON_X } -INPUT_ACTION_4 = { SCANCODE.RSHIFT, GAMEPAD_1.BUTTON_Y } +INPUT_ACTION_1 = { SCANCODE.SPACE, SCANCODE.LCTRL, GAMEPAD_1.BUTTON_A, MOUSE_1.BUTTON_LEFT } +INPUT_ACTION_2 = { SCANCODE.LALT, GAMEPAD_1.BUTTON_B, MOUSE_1.BUTTON_RIGHT } +INPUT_ACTION_3 = { SCANCODE.LSHIFT, GAMEPAD_1.BUTTON_X, MOUSE_1.BUTTON_MIDDLE } +INPUT_ACTION_4 = { SCANCODE.RSHIFT, GAMEPAD_1.BUTTON_Y, MOUSE_1.BUTTON_X1 } INPUT_SKILL_EASY = { SCANCODE.KP_DIVIDE } INPUT_SKILL_MEDIUM = { SCANCODE.KP_MULTIPLY } INPUT_SKILL_HARD = { SCANCODE.KP_MINUS } diff --git a/singe/singe.c b/singe/singe.c index b73549fe6..7f561ecb9 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -103,37 +103,6 @@ typedef struct MappingS { } MappingT; -//***TODO*** Replacing these with INPUT_* defines. -enum { - SWITCH_UP, - SWITCH_LEFT, - SWITCH_DOWN, - SWITCH_RIGHT, - SWITCH_START1, - SWITCH_START2, - SWITCH_BUTTON1, - SWITCH_BUTTON2, - SWITCH_BUTTON3, - SWITCH_COIN1, - SWITCH_COIN2, - SWITCH_SKILL1, - SWITCH_SKILL2, - SWITCH_SKILL3, - SWITCH_SERVICE, - SWITCH_TEST, - SWITCH_RESET, - SWITCH_SCREENSHOT, - SWITCH_QUIT, - SWITCH_PAUSE, - SWITCH_CONSOLE, - SWITCH_TILT, - SWITCH_GRAB, - SWITCH_MOUSE_SCROLL_UP, - SWITCH_MOUSE_SCROLL_DOWN, - SWITCH_MOUSE_DISCONNECT, - SWITCH_COUNT -}; - enum { KEYBD_NORMAL = 0, KEYBD_FULL @@ -1596,6 +1565,8 @@ int32_t apiMouseSetMode(lua_State *L) { } } + //utilSay("MouseMode now %d", _mouseMode); + if (result) { luaTrace(L, "mouseSetMode", "%d", _mouseMode); } else { @@ -2138,15 +2109,16 @@ void processKey(bool down, int32_t keysym, int32_t scancode) { int32_t move; int32_t index; - utilSay("U:%d SY:%d SC:%d", down, keysym, scancode); + //utilSay("U:%d SY:%d SC:%d", down, keysym, scancode); if (_keyboardMode == KEYBD_NORMAL) { // Mappable keys for (move=0; move 0) { for (index=0; index<_controlMappings[move].inputCount; index++) { - utilSay("Checking %s %d = %d", _controlMappings[move].name, _controlMappings[move].input[index], scancode); + //utilSay("Checking %s %d = %d", _controlMappings[move].name, _controlMappings[move].input[index], scancode); if (_controlMappings[move].input[index] == scancode) { + //utilSay("Found %s %d", _controlMappings[move].name, _controlMappings[move].input[index]); if (!down) { if ((move == INPUT_PAUSE) && (_pauseEnabled)) { //***TODO*** g_game->toggle_game_pause(); @@ -2171,9 +2143,7 @@ void processKey(bool down, int32_t keysym, int32_t scancode) { _requestScreenShot = true; } } - if (move != INPUT_PAUSE) { - callLua(down ? "onInputPressed" : "onInputReleased", "ii", move, NOMOUSE); - } + callLua(down ? "onInputPressed" : "onInputReleased", "ii", move, NOMOUSE); } } } @@ -2211,14 +2181,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { SDL_Event event; ManyMouseEvent mouseEvent; MouseT *mouse = NULL; - int32_t mouseButtonMap[] = { - SWITCH_BUTTON1, // Left - SWITCH_BUTTON3, // Middle - SWITCH_BUTTON2, // Right - SWITCH_BUTTON1, // Wheel Up - SWITCH_BUTTON2, // Wheel Down - SWITCH_MOUSE_DISCONNECT - }; // Hang on to some SDL stuff _window = window; @@ -2563,6 +2525,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { } break; + case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: // Determine which "scancode" to process - see Framework.singe // Controller codes begin at 500 and increment in 100 @@ -2570,17 +2533,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { // The button values line up with the enumeration used by SDL + 18 x += event.cbutton.button + 18; // Fire down event - processKey(false, 0, x); - break; - - case SDL_CONTROLLERBUTTONDOWN: - // Determine which "scancode" to process - see Framework.singe - // Controller codes begin at 500 and increment in 100 - x = event.cbutton.which * 100 + 500; - // The button values line up with the enumeration used by SDL + 18 - x += event.cbutton.button + 18; - // Fire down event - processKey(true, 0, x); + processKey((event.type == SDL_CONTROLLERBUTTONDOWN) ? true : false, 0, x); break; case SDL_CONTROLLERDEVICEADDED: @@ -2590,11 +2543,8 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { break; case SDL_KEYDOWN: - processKey(true, event.key.keysym.sym, event.key.keysym.scancode); - break; - case SDL_KEYUP: - processKey(false, event.key.keysym.sym, event.key.keysym.scancode); + processKey((event.type == SDL_KEYDOWN) ? true : false, event.key.keysym.sym, event.key.keysym.scancode); break; case SDL_MOUSEMOTION: @@ -2608,20 +2558,39 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { break; case SDL_MOUSEBUTTONDOWN: - for (x=0; x 0 ? 0 : 1); + // Fire events + processKey(true, 0, x); + processKey(false, 0, x); } break; @@ -2679,19 +2648,24 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { y = (int32_t)(mouse->y * _overlayScaleY); xr = (int32_t)(mouse->relx * _overlayScaleX); yr = (int32_t)(mouse->relx * _overlayScaleY); - utilSay("Mouse %d: Absolute %d, %d", mouseEvent.device, x, y); + //utilSay("Mouse %d: Absolute %d, %d", mouseEvent.device, x, y); callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device); break; case MANYMOUSE_EVENT_BUTTON: - if (mouseEvent.item < 32) { + if (mouseEvent.item < 5 /* 32 */) { // Limited to 5 buttons so it matches single-mouse mode + //utilSay("ManyMouse %d Button: %d", mouseEvent.device, mouseEvent.item); + // Mouse events start at "scancode" 1000 with 100 spacing + x = mouseEvent.device * 100 + 1000; + // ManyMouse maps buttons L,R,M,X1,X2 starting at 0 + x += mouseEvent.item; if (mouseEvent.value == 1) { // Button pressed - callLua("onInputPressed", "ii", mouseButtonMap[mouseEvent.item], mouseEvent.device); + processKey(true, 0, x); mouse->buttons |= (1 << mouseEvent.item); } else { // Button released - callLua("onInputReleased", "ii", mouseButtonMap[mouseEvent.item], mouseEvent.device); + processKey(false, 0, x); mouse->buttons &= ~(1 << mouseEvent.item); } } @@ -2699,22 +2673,18 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { case MANYMOUSE_EVENT_SCROLL: if (mouseEvent.item == 0) { - if (mouseEvent.value > 0) { - // Scroll up - callLua("onInputPressed", "ii", SWITCH_MOUSE_SCROLL_UP, mouseEvent.device); - callLua("onInputReleased", "ii", SWITCH_MOUSE_SCROLL_UP, mouseEvent.device); - } else { - // Scroll down - callLua("onInputPressed", "ii", SWITCH_MOUSE_SCROLL_DOWN, mouseEvent.device); - callLua("onInputReleased", "ii", SWITCH_MOUSE_SCROLL_DOWN, mouseEvent.device); - } + // Mouse events start at "scancode" 1000 with 100 spacing + x = mouseEvent.device * 100 + 1000; + // Scroll events start at 1005 and are mapped UP then DOWN + x += 5 + (mouseEvent.value > 0 ? 0 : 1); + // Fire events + processKey(true, 0, x); + processKey(false, 0, x); } break; case MANYMOUSE_EVENT_DISCONNECT: mouse->connected = false; - callLua("onInputPressed", "ii", SWITCH_MOUSE_DISCONNECT, mouseEvent.device); - callLua("onInputReleased", "ii", SWITCH_MOUSE_DISCONNECT, mouseEvent.device); break; case MANYMOUSE_EVENT_MAX: @@ -2912,6 +2882,7 @@ void takeScreenshot(void) { surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 32, 0, 0, 0, 0); if (!surface) utilDie("%s", SDL_GetError()); if (SDL_RenderReadPixels(_renderer, NULL, surface->format->format, surface->pixels, surface->pitch) != 0) utilDie("%s", SDL_GetError()); + //***FIX*** This crashes with a SEGFAULT sometimes. Not sure why. if (IMG_SavePNG(surface, filename) < 0) utilDie("%s", IMG_GetError()); SDL_FreeSurface(surface); free(pixels);