void rut_icon_button_get_size (RutObject *self, float *width, float *height) { RutIconButton *button = self; rut_sizable_get_size (button->stack, width, height); }
static void create_sizeable_control_points(entity_state_t *entity_state) { float width, height; rut_sizable_get_size(entity_state->sizeable, &width, &height); create_box_control(entity_state, 0, 0, 0); create_box_control(entity_state, 0, height, 0); create_box_control(entity_state, width, height, 0); create_box_control(entity_state, width, 0, 0); }
static RutInputEventStatus _rut_icon_button_grab_input_cb (RutInputEvent *event, void *user_data) { IconButtonGrabState *state = user_data; RutIconButton *button = state->button; if(rut_input_event_get_type (event) == RUT_INPUT_EVENT_TYPE_MOTION) { RutShell *shell = button->ctx->shell; if (rut_motion_event_get_action (event) == RUT_MOTION_EVENT_ACTION_UP) { rut_shell_ungrab_input (shell, _rut_icon_button_grab_input_cb, user_data); rut_closure_list_invoke (&button->on_click_cb_list, RutIconButtonClickCallback, button); g_slice_free (IconButtonGrabState, state); set_state (button, ICON_BUTTON_STATE_NORMAL); return RUT_INPUT_EVENT_STATUS_HANDLED; } else if (rut_motion_event_get_action (event) == RUT_MOTION_EVENT_ACTION_MOVE) { float x = rut_motion_event_get_x (event); float y = rut_motion_event_get_y (event); float width, height; RutCamera *camera = state->camera; rut_camera_unproject_coord (camera, &state->transform, &state->inverse_transform, 0, &x, &y); rut_sizable_get_size (button, &width, &height); if (x < 0 || x > width || y < 0 || y > height) set_state (button, ICON_BUTTON_STATE_ACTIVE_CANCEL); else set_state (button, ICON_BUTTON_STATE_ACTIVE); return RUT_INPUT_EVENT_STATUS_HANDLED; } } return RUT_INPUT_EVENT_STATUS_UNHANDLED; }
RutButton * rut_button_new (RutContext *ctx, const char *label) { RutButton *button = g_slice_new0 (RutButton); GError *error = NULL; float text_width, text_height; static CoglBool initialized = FALSE; if (initialized == FALSE) { _rut_button_init_type (); initialized = TRUE; } rut_object_init (RUT_OBJECT (button), &rut_button_type); button->ref_count = 1; rut_list_init (&button->on_click_cb_list); rut_graphable_init (RUT_OBJECT (button)); rut_paintable_init (RUT_OBJECT (button)); button->ctx = ctx; button->state = BUTTON_STATE_NORMAL; button->normal_texture = rut_load_texture_from_data_file (ctx, "button.png", &error); if (button->normal_texture) { button->background_normal = rut_nine_slice_new (ctx, button->normal_texture, 11, 5, 13, 5, button->width, button->height); } else { g_warning ("Failed to load button texture: %s", error->message); g_error_free (error); } button->hover_texture = rut_load_texture_from_data_file (ctx, "button-hover.png", &error); if (button->hover_texture) { button->background_hover = rut_nine_slice_new (ctx, button->hover_texture, 11, 5, 13, 5, button->width, button->height); } else { g_warning ("Failed to load button-hover texture: %s", error->message); g_error_free (error); } button->active_texture = rut_load_texture_from_data_file (ctx, "button-active.png", &error); if (button->active_texture) { button->background_active = rut_nine_slice_new (ctx, button->active_texture, 11, 5, 13, 5, button->width, button->height); } else { g_warning ("Failed to load button-active texture: %s", error->message); g_error_free (error); } button->disabled_texture = rut_load_texture_from_data_file (ctx, "button-disabled.png", &error); if (button->disabled_texture) { button->background_disabled = rut_nine_slice_new (ctx, button->disabled_texture, 11, 5, 13, 5, button->width, button->height); } else { g_warning ("Failed to load button-disabled texture: %s", error->message); g_error_free (error); } button->text = rut_text_new_with_text (ctx, NULL, label); button->text_transform = rut_transform_new (ctx); rut_graphable_add_child (button, button->text_transform); rut_graphable_add_child (button->text_transform, button->text); rut_sizable_get_size (button->text, &text_width, &text_height); button->width = text_width + BUTTON_HPAD; button->height = text_height + BUTTON_VPAD; cogl_color_init_from_4f (&button->text_color, 0, 0, 0, 1); button->input_region = rut_input_region_new_rectangle (0, 0, button->width, button->height, _rut_button_input_cb, button); //rut_input_region_set_graphable (button->input_region, button); rut_graphable_add_child (button, button->input_region); queue_allocation (button); return button; }