Ejemplo n.º 1
0
static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox))
{
    TXT_CAST_ARG(txt_inputbox_t, inputbox);
    int focused;
    int i;
    int chars;
    int w;

    focused = inputbox->widget.focused;
    w = inputbox->widget.w;

    // Select the background color based on whether we are currently
    // editing, and if not, whether the widget is focused.

    if (inputbox->editing && focused)
    {
        TXT_BGColor(TXT_COLOR_BLACK, 0);
    }
    else
    {
        TXT_SetWidgetBG(inputbox);
    }

    if (!inputbox->editing)
    {
        // If not editing, use the current value from inputbox->value.

        SetBufferFromValue(inputbox);
    }

    // If string size exceeds the widget's width, show only the end.

    if (TXT_UTF8_Strlen(inputbox->buffer) > w - 1)
    {
        TXT_DrawString("\xae");
        TXT_DrawUTF8String(
            TXT_UTF8_SkipChars(inputbox->buffer,
                               TXT_UTF8_Strlen(inputbox->buffer) - w + 2));
        chars = w - 1;
    }
    else
    {
        TXT_DrawUTF8String(inputbox->buffer);
        chars = TXT_UTF8_Strlen(inputbox->buffer);
    }

    if (chars < w && inputbox->editing && focused)
    {
        TXT_BGColor(TXT_COLOR_BLACK, 1);
        TXT_DrawString("_");
        ++chars;
    }

    for (i=chars; i < w; ++i)
    {
        TXT_DrawString(" ");
    }
}
static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox), int selected)
{
    TXT_CAST_ARG(txt_inputbox_t, inputbox);
    int i;
    int chars;
    int w;

    w = inputbox->widget.w;

    // Select the background color based on whether we are currently
    // editing, and if not, whether the widget is selected.

    if (inputbox->editing && selected)
    {
        TXT_BGColor(TXT_COLOR_BLACK, 0);
    }
    else if (selected)
    {
        TXT_BGColor(TXT_COLOR_GREY, 0);
    }
    else
    {
        // Not even selected

        TXT_BGColor(TXT_COLOR_BLUE, 0);
    }

    TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);

    if (!inputbox->editing)
    {
        // If not editing, use the current value from inputbox->value.
 
        SetBufferFromValue(inputbox);
    }
    
    TXT_DrawString(inputbox->buffer);

    chars = strlen(inputbox->buffer);

    if (chars < w && inputbox->editing && selected)
    {
        TXT_BGColor(TXT_COLOR_BLACK, 1);
        TXT_DrawString("_");
        ++chars;
    }
    
    for (i=chars; i < w; ++i)
    {
        TXT_DrawString(" ");
    }
}
Ejemplo n.º 3
0
static void StartEditing(txt_inputbox_t *inputbox)
{
    // Integer input boxes start from an empty buffer:

    if (inputbox->widget.widget_class == &txt_int_inputbox_class)
    {
        TXT_StringCopy(inputbox->buffer, "", inputbox->buffer_len);
    }
    else
    {
        SetBufferFromValue(inputbox);
    }

    inputbox->editing = 1;
}
Ejemplo n.º 4
0
static void StartEditing(txt_inputbox_t *inputbox)
{
    // Integer input boxes start from an empty buffer:

    if (inputbox->widget.widget_class == &txt_int_inputbox_class)
    {
        TXT_StringCopy(inputbox->buffer, "", inputbox->buffer_len);
    }
    else
    {
        SetBufferFromValue(inputbox);
    }

    // Switch to text input mode so we get shifted input.
    TXT_SetInputMode(TXT_INPUT_TEXT);
    inputbox->editing = 1;
}
static int TXT_InputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key)
{
    TXT_CAST_ARG(txt_inputbox_t, inputbox);

    if (!inputbox->editing)
    {
        if (key == KEY_ENTER)
        {
            SetBufferFromValue(inputbox);
            inputbox->editing = 1;
            return 1;
        }

        return 0;
    }

    if (key == KEY_ENTER)
    {
        free(*((char **)inputbox->value));
        *((char **) inputbox->value) = strdup(inputbox->buffer);

        TXT_EmitSignal(&inputbox->widget, "changed");

        inputbox->editing = 0;
    }

    if (key == KEY_ESCAPE)
    {
        inputbox->editing = 0;
    }

    if (isprint(key))
    {
        // Add character to the buffer

        AddCharacter(inputbox, key);
    }

    if (key == KEY_BACKSPACE)
    {
        Backspace(inputbox);
    }
    
    return 1;
}
Ejemplo n.º 6
0
static void StartEditing(txt_inputbox_t *inputbox)
{
    #ifdef USE_VIRTUALKEYBOARD
    VKBCreateWindow(inputbox, 0);
    #endif // USE_VIRTUALKEYBOARD
    // Integer input boxes start from an empty buffer:

    if (inputbox->widget.widget_class == &txt_int_inputbox_class)
    {
        TXT_StringCopy(inputbox->buffer, "", inputbox->buffer_len);
    }
    else
    {
        SetBufferFromValue(inputbox);
    }

    inputbox->editing = 1;
}