示例#1
0
/******************************************************************************\
 Ring widget event function.
\******************************************************************************/
static int ring_event(i_widget_t *widget, i_event_t event)
{
        float radius;

        /* Calculate mouse radius for mouse events */
        if (event == I_EV_MOUSE_MOVE || event == I_EV_MOUSE_DOWN)
                radius = C_vec2_len(C_vec2_sub(i_mouse, screen_origin));

        switch (event) {
        case I_EV_CONFIGURE:
                R_sprite_cleanup(&ring_sprite);
                R_sprite_init(&ring_sprite, ring_texture);
                ring_widget.size = ring_sprite.size;
                I_widget_propagate(widget, I_EV_CONFIGURE);
                position_and_pack();
                return FALSE;
        case I_EV_MOVED:
                ring_sprite.origin = ring_widget.origin;
                break;
        case I_EV_MOUSE_OUT:
                I_close_ring();
                break;
        case I_EV_MOUSE_MOVE:
                if (radius > RING_OUTER_RADIUS)
                        I_close_ring();
                else
                        detail_hover();
                break;
        case I_EV_MOUSE_DOWN:
                if (i_mouse_button != SDL_BUTTON_LEFT)
                        I_close_ring();
                if (radius <= RING_INNER_RADIUS) {
                        I_close_ring();
                        return FALSE;
                }
                break;
        case I_EV_CLEANUP:
                R_sprite_cleanup(&ring_sprite);
                break;
        case I_EV_RENDER:
                ring_sprite.modulate.a = ring_widget.fade;
                R_sprite_render(&ring_sprite);
                detail_update();
                break;
        default:
                break;
        }
        return TRUE;
}
示例#2
0
/******************************************************************************\
 Button widget event function.
\******************************************************************************/
int I_checkbox_event(i_checkbox_t *checkbox, i_event_t event)
{
        c_vec2_t origin, size;
        float width;

        switch (event) {
        case I_EV_CONFIGURE:

                /* Setup decorations */
                R_window_cleanup(&checkbox->normal);
                R_sprite_cleanup(&checkbox->checkmark);
                R_sprite_cleanup(&checkbox->hover);
                R_sprite_cleanup(&checkbox->active);

                R_window_init(&checkbox->normal, checkbox_texture);
                R_sprite_init(&checkbox->checkmark, checkmark);
                R_sprite_init(&checkbox->hover, hover);
                R_sprite_init(&checkbox->active, active);

//                /* Setup text */
//                R_sprite_cleanup(&checkbox->text);
//                R_sprite_init_text(&checkbox->text, R_FONT_GUI, 0.f,
//                                   i_shadow.value.f, FALSE, checkbox->buffer);
//                checkbox->text.modulate = i_colors[I_COLOR];

                checkbox->widget.size.y = checkbox->normal.sprite.size.y;
                checkbox->widget.size.x = checkbox->normal.sprite.size.x;

//                /* Size requisition */
//                if (checkbox->widget.size.y < 1) {
//                        checkbox->widget.size.y = checkbox->text.size.y;
//                        if (checkbox->icon.texture &&
//                            checkbox->icon.size.y > checkbox->widget.size.y)
//                                checkbox->widget.size.y = checkbox->icon.size.y;
//                        if (checkbox->type == I_BT_DECORATED)
//                                checkbox->widget.size.y += i_border.value.n * 2;
//                }
//                if (checkbox->widget.size.x < 1) {
//                        checkbox->widget.size.x = checkbox->text.size.x +
//                                                checkbox->icon.size.x;
//                        if (checkbox->type == I_BT_DECORATED)
//                                checkbox->widget.size.x += i_border.value.n * 2;
//                        if (checkbox->icon.texture && checkbox->buffer[0])
//                                checkbox->widget.size.x += i_border.value.n;
//                }

        case I_EV_MOVED:

                /* Setup decorations (for each state) to cover full area */
                origin = checkbox->widget.origin;
                size = checkbox->widget.size;
//                if (checkbox->type == I_BT_DECORATED) {
                        checkbox->normal.sprite.origin = origin;
                        checkbox->normal.sprite.size = size;
                        checkbox->checkmark.origin = origin;
                        checkbox->checkmark.size = size;
                        checkbox->hover.origin = origin;
                        checkbox->hover.size = size;
                        checkbox->active.origin = origin;
                        checkbox->active.size = size;
//                } else {
//                        c_vec2_t origin2, size2;
//                        float border;
//
//                        border = (float)i_border.value.n;
//                        if (border > size.x / 4)
//                                border = size.x / 4;
//                        if (border > size.y / 4)
//                                border = size.y / 4;
//                        origin2 = C_vec2_subf(origin, border);
//                        size2 = C_vec2_addf(size, border * 2.f);
//                        checkbox->icon_active.origin = origin2;
//                        checkbox->icon_active.size = size2;
//                        checkbox->icon_hover.origin = origin2;
//                        checkbox->icon_hover.size = size2;
//                }

//                /* Pack the icon left, vertically centered */
//                origin.y += size.y / 2;
//                if (checkbox->type == I_BT_DECORATED) {
//                        origin.x += i_border.value.n;
//                        size = C_vec2_subf(size, i_border.value.n * 2.f);
//                }
//                if (checkbox->icon.texture) {
//                        checkbox->icon.origin = C_vec2(origin.x, origin.y -
//                                                     checkbox->icon.size.y / 2);
//                        width = checkbox->icon.size.x + i_border.value.n;
//                        origin.x += width;
//                        size.x -= width;
//                }
//
//                /* Pack text */
//                checkbox->text.origin = origin;
//                checkbox->text.origin.y -= checkbox->text.size.y / 2;
//
//                /* If there is some room left, center the icon and text */
//                width = (size.x - checkbox->text.size.x) / 2.f;
//                if (width > 0.f) {
//                        checkbox->icon.origin.x += width;
//                        checkbox->text.origin.x += width;
//                }
//
//                /* Clamp origins to prevent blurriness */
//                checkbox->text.origin = R_pixel_clamp(checkbox->text.origin);

                break;
        case I_EV_CLEANUP:
                R_window_cleanup(&checkbox->normal);
                R_sprite_cleanup(&checkbox->checkmark);
                R_sprite_cleanup(&checkbox->hover);
                R_sprite_cleanup(&checkbox->active);
                break;
        case I_EV_MOUSE_MOVE:
                if (checkbox->hover_activate)
                        checkbox->widget.state = I_WS_ACTIVE;
                break;
        case I_EV_MOUSE_DOWN:
                if (i_mouse_button == SDL_BUTTON_LEFT)
                        checkbox->widget.state = I_WS_ACTIVE;
                break;
        case I_EV_MOUSE_UP:
                if (checkbox->widget.state == I_WS_ACTIVE) {
                        if (checkbox->on_change)
                                checkbox->on_change(checkbox);
                        checkbox->checkbox_checked =
                                (checkbox->checkbox_checked) ? FALSE : TRUE;
                        if (checkbox->widget.state == I_WS_ACTIVE)
                                checkbox->widget.state = I_WS_READY;
                }
                checkbox->hover_activate = FALSE;
                break;
        case I_EV_RENDER:
//                checkbox->checkbox.modulate.a = checkbox->widget.fade;
//                checkbox->text.modulate.a = checkbox->widget.fade;
                checkbox->normal.sprite.modulate.a = checkbox->widget.fade;
                checkbox->checkmark.modulate.a = checkbox->widget.fade;
                R_window_render(&checkbox->normal);
                if (checkbox->widget.state == I_WS_HOVER) {
//                        R_window_render(&checkbox->hover);
//                        checkbox->icon_hover.modulate.a = checkbox->widget.fade;
                        R_sprite_render(&checkbox->hover);
                } else if (checkbox->widget.state == I_WS_ACTIVE) {
//                        R_window_render(&checkbox->active);
//                        checkbox->icon_active.modulate.a = checkbox->widget.fade;
                        R_sprite_render(&checkbox->active);
                }
                if(checkbox->checkbox_checked)
                        R_sprite_render(&checkbox->checkmark);
                R_push_clip();
                R_clip_rect(checkbox->widget.origin, checkbox->widget.size);
//                R_sprite_render(&checkbox->icon);
//                R_sprite_render(&checkbox->text);
                R_pop_clip();
                break;
        default:
                break;
        }
        return TRUE;
}
示例#3
0
/******************************************************************************\
 Window widget event function.
\******************************************************************************/
int I_window_event(i_window_t *window, i_event_t event)
{
        switch (event) {
        case I_EV_CONFIGURE:
                R_window_cleanup(&window->window);
                I_widget_pack(&window->widget, window->pack_children,
                              window->fit);
                if (window->decorated) {
                        r_texture_t *decor;

                        decor = decor_window;
                        if (window->popup)
                                decor = decor_popup;
                        R_window_init(&window->window, decor);
                        window->window.sprite.origin = window->widget.origin;
                        window->window.sprite.size = window->widget.size;
                        R_sprite_cleanup(&window->hanger);
                        R_sprite_init(&window->hanger, hanger);
                        window->hanger.origin.y = window->widget.origin.y +
                                                  window->widget.size.y;
                        window->hanger.size.y = (float)i_border.value.n;
                }
                return FALSE;
        case I_EV_KEY_DOWN:
                if (i_key == SDLK_ESCAPE && window->auto_hide)
                        I_widget_event(&window->widget, I_EV_HIDE);
                break;
        case I_EV_MOUSE_IN:
                if (I_widget_child_of(&window->widget, i_key_focus))
                        break;
                i_key_focus = NULL;
                I_widget_propagate(&window->widget, I_EV_GRAB_FOCUS);
                break;
        case I_EV_MOVED:
                window->window.sprite.origin = window->widget.origin;
                window->hanger.origin.y = window->widget.origin.y +
                                          window->widget.size.y;
                break;
        case I_EV_MOUSE_DOWN:
                if (i_mouse_button == SDL_BUTTON_RIGHT && window->auto_hide)
                        I_widget_event(&window->widget, I_EV_HIDE);
                break;
        case I_EV_CLEANUP:
                R_window_cleanup(&window->window);
                R_sprite_cleanup(&window->hanger);
                break;
        case I_EV_RENDER:
                if (!window->decorated)
                        break;
                window->window.sprite.modulate.a = window->widget.fade;
                R_window_render(&window->window);
                if (!window->hanger_align)
                        break;
                window->hanger.origin.x = window->hanger_align->origin.x +
                                          window->hanger_align->size.x / 2 -
                                          window->hanger.size.x / 2;
                window->hanger.modulate.a = window->widget.fade;
                R_sprite_render(&window->hanger);
                break;
        default:
                break;
        }
        return TRUE;
}