Пример #1
0
static void OpenPromptWindow(txt_key_input_t *key_input)
{
    txt_window_t *window;
    txt_label_t *label;

    // Silently update when the shift button is held down.

    key_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);

    window = TXT_NewWindow(NULL);
    TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
    TXT_SetWindowAction(window, TXT_HORIZ_CENTER, 
                        TXT_NewWindowAbortAction(window));
    TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL);
    
    label = TXT_NewLabel("Press the new key...");

    TXT_AddWidget(window, label);
    TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER);

    TXT_SetKeyListener(window, KeyPressCallback, key_input);

    // Disable key mappings while we prompt for the key press

    TXT_EnableKeyMapping(0);

    // Grab input while reading the key.  On Windows Mobile
    // handheld devices, the hardware keypresses are only
    // detected when input is grabbed.

    SDL_WM_GrabInput(SDL_GRAB_ON);
    TXT_SignalConnect(window, "closed", ReleaseGrab, NULL);
}
Пример #2
0
static void OpenPromptWindow(txt_joystick_input_t *joystick_input)
{
    txt_window_t *window;
    SDL_Joystick *joystick;

    // Silently update when the shift button is held down.

    joystick_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);

    if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
    {
        return;
    }

    // Check the current joystick is valid

    joystick = SDL_JoystickOpen(joystick_index);

    if (joystick == NULL)
    {
        OpenErrorWindow();
        return;
    }

    // Open the prompt window

    window = TXT_MessageBox(NULL, "Press the new button on the controller...");

    TXT_SDL_SetEventCallback(EventCallback, joystick_input);
    TXT_SignalConnect(window, "closed", PromptWindowClosed, joystick);
    joystick_input->prompt_window = window;

    SDL_JoystickEventState(SDL_ENABLE);
}
Пример #3
0
static void OpenPromptWindow(txt_mouse_input_t *mouse_input)
{
    txt_window_t *window;

    // Silently update when the shift key is held down.
    mouse_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);

    window = TXT_MessageBox(NULL, "Press the new mouse button...");

    TXT_SetMouseListener(window, MousePressCallback, mouse_input);
}
Пример #4
0
static void TXT_FileSelectMousePress(TXT_UNCAST_ARG(fileselect),
                                     int x, int y, int b)
{
    TXT_CAST_ARG(txt_fileselect_t, fileselect);

    if (!fileselect->inputbox->editing
     && !TXT_GetModifierState(TXT_MOD_ALT)
     && b == TXT_MOUSE_LEFT)
    {
        if (DoSelectFile(fileselect))
        {
            return;
        }
    }

    return TXT_WidgetMousePress(fileselect->inputbox, x, y, b);
}
Пример #5
0
static int TXT_FileSelectKeyPress(TXT_UNCAST_ARG(fileselect), int key)
{
    TXT_CAST_ARG(txt_fileselect_t, fileselect);

    // When the enter key is pressed, pop up a file selection dialog,
    // if file selectors work. Allow holding down 'alt' to override
    // use of the native file selector, so the user can just type a path.

    if (!fileselect->inputbox->editing
     && !TXT_GetModifierState(TXT_MOD_ALT)
     && key == KEY_ENTER)
    {
        if (DoSelectFile(fileselect))
        {
            return 1;
        }
    }

    return TXT_WidgetKeyPress(fileselect->inputbox, key);
}
Пример #6
0
static void OpenPromptWindow(txt_key_input_t *key_input)
{
    txt_window_t *window;

    // Silently update when the shift button is held down.

    key_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);

    window = TXT_MessageBox(NULL, "Press the new key...");

    TXT_SetKeyListener(window, KeyPressCallback, key_input);

    // Disable key mappings while we prompt for the key press

    TXT_EnableKeyMapping(0);

    // Grab input while reading the key.  On Windows Mobile
    // handheld devices, the hardware keypresses are only
    // detected when input is grabbed.

    SDL_WM_GrabInput(SDL_GRAB_ON);
    TXT_SignalConnect(window, "closed", ReleaseGrab, NULL);
}
Пример #7
0
static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key)
{
    TXT_CAST_ARG(txt_table_t, table);
    int selected;
    int rows;

    rows = TableRows(table);

    // Send to the currently selected widget first

    selected = table->selected_y * table->columns + table->selected_x;

    if (selected >= 0 && selected < table->num_widgets)
    {
        if (IsActualWidget(table->widgets[selected])
         && TXT_SelectableWidget(table->widgets[selected])
         && TXT_WidgetKeyPress(table->widgets[selected], key))
        {
            return 1;
        }
    }

    if (key == KEY_TAB)
    {
        int dir;
        int i;

        dir = TXT_GetModifierState(TXT_MOD_SHIFT) ? -1 : 1;

        // Cycle through all widgets until we find one that can be selected.
        for (i = table->selected_y * table->columns + table->selected_x + dir;
             i >= 0 && i < table->num_widgets;
             i += dir)
        {
            if (IsActualWidget(table->widgets[i])
             && TXT_SelectableWidget(table->widgets[i]))
            {
                ChangeSelection(table, i % table->columns, i / table->columns);
                return 1;
            }
        }

        return 0;
    }

    if (key == KEY_DOWNARROW)
    {
        int new_x, new_y;

        // Move cursor down to the next selectable widget

        for (new_y = table->selected_y + 1; new_y < rows; ++new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);

            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                ChangeSelection(table, new_x, new_y);

                return 1;
            }
        }
    }

    if (key == KEY_UPARROW)
    {
        int new_x, new_y;

        // Move cursor up to the next selectable widget

        for (new_y = table->selected_y - 1; new_y >= 0; --new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);

            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                ChangeSelection(table, new_x, new_y);

                return 1;
            }
        }
    }

    if (key == KEY_LEFTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x - 1; new_x >= 0; --new_x)
        {
            if (SelectableCell(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                ChangeSelection(table, new_x, table->selected_y);

                return 1;
            }
        }
    }

    if (key == KEY_RIGHTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x + 1; new_x < table->columns; ++new_x)
        {
            if (SelectableCell(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                ChangeSelection(table, new_x, table->selected_y);

                return 1;
            }
        }
    }

    return 0;
}