Exemple #1
0
component* textinput_create(const text_settings *tconf, const char *text, const char *initialvalue) {
    component *c = widget_create();

    textinput *tb = malloc(sizeof(textinput));
    memset(tb, 0, sizeof(textinput));
    tb->text = strdup(text);
    memcpy(&tb->tconf, tconf, sizeof(text_settings));
    tb->pos = &tb->pos_;

    // Background for field
    int tsize = text_char_width(&tb->tconf);
    image img;
    image_create(&img, 15*tsize+2, tsize+3);
    image_clear(&img, COLOR_MENU_BG);
    image_rect(&img, 0, 0, 15*tsize+1, tsize+2, COLOR_MENU_BORDER);
    surface_create_from_image(&tb->sur, &img);
    image_free(&img);

    // Copy over the initial value
    memcpy(tb->buf, initialvalue, strlen(initialvalue)+1);

    // Widget stuff
    widget_set_obj(c, tb);
    widget_set_render_cb(c, textinput_render);
    widget_set_event_cb(c, textinput_event);
    widget_set_tick_cb(c, textinput_tick);
    widget_set_free_cb(c, textinput_free);
    return c;
}
Exemple #2
0
component* textbutton_create(const text_settings *tconf, const char *text, int disabled, textbutton_click_cb cb, void *userdata) {
    component *c = widget_create();
    component_disable(c, disabled);

    textbutton *tb = malloc(sizeof(textbutton));
    memset(tb, 0, sizeof(textbutton));
    tb->text = strdup(text);
    memcpy(&tb->tconf, tconf, sizeof(text_settings));
    tb->click_cb = cb;
    tb->userdata = userdata;
    widget_set_obj(c, tb);

    widget_set_render_cb(c, textbutton_render);
    widget_set_action_cb(c, textbutton_action);
    widget_set_tick_cb(c, textbutton_tick);
    widget_set_free_cb(c, textbutton_free);

    return c;
}
Exemple #3
0
component* spritebutton_create(const text_settings *tconf, const char *text, surface *img, int disabled, spritebutton_click_cb cb, void *userdata) {
    component *c = widget_create();
    component_disable(c, disabled);

    spritebutton *sb = malloc(sizeof(spritebutton));
    memset(sb, 0, sizeof(spritebutton));
    if(text != NULL)
        sb->text = strdup(text);
    memcpy(&sb->tconf, tconf, sizeof(text_settings));
    sb->click_cb = cb;
    sb->img = img;
    sb->userdata = userdata;
    widget_set_obj(c, sb);

    widget_set_render_cb(c, spritebutton_render);
    widget_set_action_cb(c, spritebutton_action);
    widget_set_tick_cb(c, spritebutton_tick);
    widget_set_free_cb(c, spritebutton_free);

    return c;
}