示例#1
0
void Main_OnKeyJoyEvent(SDL_Event evt)
{
    int pressed = (evt.type == SDL_KEYDOWN || evt.type == SDL_JOYBUTTONDOWN);
    //int sourcetype = (evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP) ? EVKEY : EVJOY;

    //DEBUG
    if (pressed) printf("KeyDown %d\n", evt.key.keysym.sym);

    BYTE ukncscan = FindKeyMapping(evt.key.keysym.sym);
    if (ukncscan != 0)  // UKNC event mapping found
    {
        Emulator_KeyboardEvent(ukncscan, pressed);
    }
    else if (pressed)  // Commands works only on key/button press, not release
    {
        int command = FindCommandMapping(evt.key.keysym.sym);
        if (command != 0)  // Command mapping found
        {
            Main_ExecuteCommand(command);
        }
    }
}
示例#2
0
// Handles SDL keyboard press/release and joystick button press/release events.
void Main_OnKeyJoyEvent(SDL_Event evt)
{
    KeyMappingStruct* mapping;
    int pressed = (evt.type == SDL_KEYDOWN || evt.type == SDL_JOYBUTTONDOWN);
    int sourcetype = (evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP) ? EVKEY : EVJOY;

    if (g_okKeyboard)  // Onscreen keyboard mode
    {
        mapping = FindKeyMapping(sourcetype, evt.key.keysym.sym, TRUE);
        if (mapping == NULL)
            return;
        int command = mapping->resultcd;
        if (pressed)
        {
            switch (command)
            {
            case ID_MENU_ESCAPE:
            case ID_MENU:
            case ID_KEYBOARD:
                Main_ExecuteCommand(ID_KEYBOARD);
                return;
            case ID_MENU_UP:
            case ID_MENU_DOWN:
            case ID_MENU_LEFT:
            case ID_MENU_RIGHT:
                g_KeyboardCurrent = Main_KeyboardFindNearestKey(command);
                return;
            case ID_MENU_SELECT:
                Emulator_KeyboardEvent(m_arrKeyboardKeys[g_KeyboardCurrent].code, TRUE);
                break;
            default:
                break;
            }
        }
        else
        {
            if (command == ID_MENU_SELECT)
            {
                Emulator_KeyboardEvent(m_arrKeyboardKeys[g_KeyboardCurrent].code, FALSE);
            }
        }
        return;
    }

    mapping = FindKeyMapping(sourcetype, evt.key.keysym.sym, FALSE);
    if (mapping != NULL)  // BK event mapping found
    {
        BYTE result = mapping->resultcd;
        if (mapping->resulttype == EVJOY)
            Emulator_JoystickEvent(result, pressed);
        else
            Emulator_KeyboardEvent(result, pressed);
    }
    else if (pressed)  // Commands works only on key/button press, not release
    {
        mapping = FindKeyMapping(sourcetype, evt.key.keysym.sym, TRUE);
        if (mapping != NULL)  // Command mapping found
        {
            Main_ExecuteCommand(mapping->resultcd);
        }
    }
}
示例#3
0
// Show directory browser for *.BIN mask
void Main_BrowseAndLoadBin()
{
    // Get file list by mask
    char ** pfilenames = Common_FindFiles(g_AppDirectory, "*.bin");

    int exitBrowser = FALSE;
    int currentItem = 0;
    int redrawScreen = TRUE;
    int menuItemCount = 0;
    const int menuLeft = 12;
    const int menuWidth = 8 * 32;
    const int menuHeight = 11 * 20;

    while (!exitBrowser)
    {
        if (redrawScreen)
        {
            Main_DrawScreen();

            // Draw menu background
            SDL_Rect rc;
            rc.x = menuLeft - 8;
            rc.y = 8 - 4;
            rc.w = 12 + menuWidth;
            rc.h = 8 + menuHeight;
            SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 32, 32, 192));
            // Draw selected item background
            rc.x = menuLeft - 4;
            rc.y = 8 - 1 + currentItem * 11;
            rc.w = 4 + menuWidth;
            rc.h = 11 + 2;
            SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 192, 32, 32));

            // Draw menu items
            char ** pitem = pfilenames;
            int y = 8;
            menuItemCount = 0;
            while (*pitem != NULL)
            {
                Font_DrawText(menuLeft, y, *pitem);
                pitem++;
                y += 11;
                menuItemCount++;
            }

            SDL_Flip(g_Screen);

            redrawScreen = FALSE;
        }

        SDL_Event evt;
        while (SDL_PollEvent(&evt))
        {
            redrawScreen = TRUE;
            if (evt.type == SDL_QUIT)
            {
                g_okQuit = exitBrowser = TRUE;
                break;
            }
            if (evt.type == SDL_KEYDOWN)
            {
                switch (evt.key.keysym.sym)
                {
                case SDLK_PAUSE:  // POWER UP button on Dingoo
                    g_okQuit = exitBrowser = TRUE;
                    break;
                case SDLK_TAB:  // Left shoulder on Dingoo
                case SDLK_ESCAPE:  // SELECT button on Dingoo
                    exitBrowser = TRUE;
                    break;
                case SDLK_UP:
                    if (currentItem > 0) currentItem--;
                    else currentItem = menuItemCount - 1;
                    break;
                case SDLK_DOWN:
                    if (currentItem < menuItemCount - 1) currentItem++;
                    else currentItem = 0;
                    break;
                case SDLK_LCTRL:  // A button on Dingoo
                case SDLK_SPACE:  // X button on Dingoo
                case SDLK_RETURN:  // START button on Dingoo
                {
                    char * filename = pfilenames[currentItem];
                    Main_LoadBin(filename);
                    // Print "S1000"
                    Emulator_KeyboardEvent(0123, TRUE);
                    Emulator_KeyboardEvent(0123, FALSE);
                    Emulator_KeyboardEvent(061, TRUE);
                    Emulator_KeyboardEvent(061, FALSE);
                    Emulator_KeyboardEvent(060, TRUE);
                    Emulator_KeyboardEvent(060, FALSE);
                    Emulator_KeyboardEvent(060, TRUE);
                    Emulator_KeyboardEvent(060, FALSE);
                    Emulator_KeyboardEvent(060, TRUE);
                    Emulator_KeyboardEvent(060, FALSE);
                    exitBrowser = TRUE;
                }
                break;
                default:
                    break;
                }
            }
        }

        SDL_Delay(50);
    }

    Common_FindFiles_Cleanup(pfilenames);
}