Esempio n. 1
0
static void
_rut_button_allocate_cb (RutObject *graphable,
                         void *user_data)
{
  RutButton *button = graphable;
  float text_min_width, text_natural_width;
  float text_min_height, text_natural_height;
  int text_width, text_height;
  int text_x, text_y;

  rut_sizable_get_preferred_width (button->text,
                                   -1,
                                   &text_min_width,
                                   &text_natural_width);

  rut_sizable_get_preferred_height (button->text,
                                    -1,
                                    &text_min_height,
                                    &text_natural_height);

  if (button->width > (BUTTON_HPAD + text_natural_width))
    text_width = text_natural_width;
  else
    text_width = MAX (0, button->width - BUTTON_HPAD);

  if (button->height > (BUTTON_VPAD + text_natural_height))
    text_height = text_natural_height;
  else
    text_height = MAX (0, button->height - BUTTON_VPAD);

  rut_sizable_set_size (button->text, text_width, text_height);

  rut_transform_init_identity (button->text_transform);

  text_x = (button->width / 2) - (text_width / 2.0);
  text_y = (button->height / 2) - (text_height / 2.0);
  rut_transform_translate (button->text_transform, text_x, text_y, 0);
}
Esempio n. 2
0
void
update_control_point_positions(rig_selection_tool_t *tool,
                               rut_object_t *paint_camera) /* 2d ui camera */
{
    rut_object_t *camera = tool->camera_component;
    c_llist_t *l;

    for (l = tool->selected_entities; l; l = l->next) {
        entity_state_t *entity_state = l->data;
        c_matrix_t transform;
        const c_matrix_t *projection;
        float screen_space[4], x, y;
        const float *viewport;
        c_llist_t *l2;

        get_modelview_matrix(tool->camera, entity_state->entity, &transform);

        projection = rut_camera_get_projection(camera);

        viewport = rut_camera_get_viewport(camera);

        for (l2 = entity_state->control_points; l2; l2 = l2->next) {
            control_point_t *point = l2->data;

            point->position[0] = point->x;
            point->position[1] = point->y;
            point->position[2] = point->z;

            c_matrix_transform_points(&transform,
                                       3, /* num components for input */
                                       sizeof(float) * 3, /* input stride */
                                       point->position,
                                       sizeof(float) * 3, /* output stride */
                                       point->position,
                                       1 /* n_points */);

            /* update the input region, need project the transformed point and
             * do
             * the viewport transform */
            screen_space[0] = point->position[0];
            screen_space[1] = point->position[1];
            screen_space[2] = point->position[2];
            c_matrix_project_points(projection,
                                     3, /* num components for input */
                                     sizeof(float) * 3, /* input stride */
                                     screen_space,
                                     sizeof(float) * 4, /* output stride */
                                     screen_space,
                                     1 /* n_points */);

            /* perspective divide */
            screen_space[0] /= screen_space[3];
            screen_space[1] /= screen_space[3];

            /* apply viewport transform */
            x = VIEWPORT_TRANSFORM_X(screen_space[0], viewport[0], viewport[2]);
            y = VIEWPORT_TRANSFORM_Y(screen_space[1], viewport[1], viewport[3]);

            point->screen_pos[0] = x;
            point->screen_pos[1] = y;

            map_window_coords_to_overlay_coord(
                paint_camera, tool->tool_overlay, &x, &y);

            rut_transform_init_identity(point->transform);
            rut_transform_translate(point->transform, x, y, 0);
            rut_input_region_set_circle(point->input_region, x, y, 10);
        }
    }
}
Esempio n. 3
0
static void
allocate_cb (RutObject *graphable,
             void *user_data)
{
    RutBin *bin = RUT_BIN (graphable);

    if (bin->child)
    {
        float child_width, child_height;
        float child_x = bin->left_padding;
        float child_y = bin->top_padding;
        float available_width =
            bin->width - bin->left_padding - bin->right_padding;
        float available_height =
            bin->height - bin->top_padding - bin->bottom_padding;

        rut_sizable_get_preferred_width (bin->child,
                                         -1, /* for_height */
                                         NULL, /* min_width_p */
                                         &child_width);

        if (child_width > available_width)
            child_width = available_width;

        switch (bin->x_position)
        {
        case RUT_BIN_POSITION_BEGIN:
            break;

        case RUT_BIN_POSITION_CENTER:
            if (child_width < available_width)
                child_x = nearbyintf (bin->width / 2.0f - child_width / 2.0f);
            break;

        case RUT_BIN_POSITION_END:
            if (child_width < available_width)
                child_x = bin->width - bin->right_padding - child_width;
            break;

        case RUT_BIN_POSITION_EXPAND:
            child_width = available_width;
            break;
        }

        rut_sizable_get_preferred_height (bin->child,
                                          child_width, /* for_width */
                                          NULL, /* min_height_p */
                                          &child_height);

        if (child_height > available_height)
            child_height = available_height;

        switch (bin->y_position)
        {
        case RUT_BIN_POSITION_BEGIN:
            break;

        case RUT_BIN_POSITION_CENTER:
            if (child_height < available_height)
                child_y = nearbyintf (bin->height / 2.0f - child_height / 2.0f);
            break;

        case RUT_BIN_POSITION_END:
            if (child_height < available_height)
                child_y = bin->height - bin->bottom_padding - child_height;
            break;

        case RUT_BIN_POSITION_EXPAND:
            child_height = available_height;
            break;
        }

        rut_transform_init_identity (bin->child_transform);
        rut_transform_translate (bin->child_transform, child_x, child_y, 0.0f);
        rut_sizable_set_size (bin->child, child_width, child_height);
    }
}