Example #1
0
rut_fold_t *
rut_fold_new(rut_shell_t *shell, const char *label)
{
    rut_fold_t *fold =
        rut_object_alloc0(rut_fold_t, &rut_fold_type, _rut_fold_init_type);
    rut_box_layout_t *header_hbox;
    rut_stack_t *left_header_stack;
    rut_box_layout_t *left_header_hbox;
    rut_bin_t *label_bin;
    rut_bin_t *fold_icon_align;
    cg_texture_t *texture;
    cg_color_t black;

    fold->shell = shell;

    rut_graphable_init(fold);

    rig_introspectable_init(fold, _rut_fold_prop_specs, fold->properties);

    fold->vbox = rut_box_layout_new(shell,
                                    RUT_BOX_LAYOUT_PACKING_TOP_TO_BOTTOM);

    header_hbox = rut_box_layout_new(shell,
                                     RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
    rut_box_layout_add(fold->vbox, false, header_hbox);
    rut_object_unref(header_hbox);

    left_header_stack = rut_stack_new(shell, 0, 0);
    rut_box_layout_add(header_hbox, true, left_header_stack);
    rut_object_unref(left_header_stack);

    left_header_hbox =
        rut_box_layout_new(shell, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
    rut_stack_add(left_header_stack, left_header_hbox);
    rut_object_unref(left_header_hbox);

    fold_icon_align = rut_bin_new(shell);
    rut_bin_set_x_position(fold_icon_align, RUT_BIN_POSITION_BEGIN);
    rut_bin_set_y_position(fold_icon_align, RUT_BIN_POSITION_CENTER);
    rut_bin_set_right_padding(fold_icon_align, 10);
    rut_box_layout_add(left_header_hbox, false, fold_icon_align);
    rut_object_unref(fold_icon_align);

    texture = rut_load_texture_from_data_file(shell, "tri-fold-up.png", NULL);
    fold->fold_up_icon = rut_nine_slice_new(shell,
                                            texture,
                                            0,
                                            0,
                                            0,
                                            0,
                                            cg_texture_get_width(texture),
                                            cg_texture_get_height(texture));
    cg_object_unref(texture);

    texture = rut_load_texture_from_data_file(shell, "tri-fold-down.png",
                                              NULL);
    fold->fold_down_icon = rut_nine_slice_new(shell,
                                              texture,
                                              0,
                                              0,
                                              0,
                                              0,
                                              cg_texture_get_width(texture),
                                              cg_texture_get_height(texture));
    cg_object_unref(texture);

    fold->fold_icon_shim = rut_fixed_new(shell, cg_texture_get_width(texture),
                                         cg_texture_get_height(texture));
    rut_bin_set_child(fold_icon_align, fold->fold_icon_shim);
    rut_object_unref(fold->fold_icon_shim);

    rut_graphable_add_child(fold->fold_icon_shim, fold->fold_down_icon);

    /* NB: we keep references to the icons so they can be swapped
     * without getting disposed. */

    label_bin = rut_bin_new(shell);
    rut_bin_set_y_position(label_bin, RUT_BIN_POSITION_CENTER);
    rut_box_layout_add(left_header_hbox, false, label_bin);
    rut_object_unref(label_bin);

    fold->label = rut_text_new_with_text(shell, NULL, label);
    rut_bin_set_child(label_bin, fold->label);
    rut_object_unref(fold->label);

    fold->header_hbox_right =
        rut_box_layout_new(shell, RUT_BOX_LAYOUT_PACKING_RIGHT_TO_LEFT);
    rut_box_layout_add(header_hbox, true, fold->header_hbox_right);
    rut_object_unref(fold->header_hbox_right);

    cg_color_init_from_4f(&black, 0, 0, 0, 1);
    rut_fold_set_folder_color(fold, &black);
    rut_fold_set_label_color(fold, &black);

    rut_graphable_add_child(fold, fold->vbox);
    rut_object_unref(fold->vbox);

    fold->input_region =
        rut_input_region_new_rectangle(0, 0, 0, 0, input_cb, fold);
    rut_stack_add(left_header_stack, fold->input_region);
    rut_object_unref(fold->input_region);

    fold->folded = false;

    return fold;
}
Example #2
0
cg_texture_t *
rig_downsampler_downsample(rig_downsampler_t *downsampler,
                           cg_texture_t *source,
                           int scale_factor_x,
                           int scale_factor_y)
{
    cg_texture_components_t components;
    int src_w, src_h;
    int dest_width, dest_height;
    cg_pipeline_t *pipeline;

    /* validation */
    src_w = cg_texture_get_width(source);
    src_h = cg_texture_get_height(source);

    if (src_w % scale_factor_x != 0) {
        c_warning("downsample: the width of the texture (%d) is not a "
                  "multiple of the scale factor (%d)",
                  src_w,
                  scale_factor_x);
    }
    if (src_h % scale_factor_y != 0) {
        c_warning("downsample: the height of the texture (%d) is not a "
                  "multiple of the scale factor (%d)",
                  src_h,
                  scale_factor_y);
    }

    /* create the destination texture up front */
    dest_width = src_w / scale_factor_x;
    dest_height = src_h / scale_factor_y;
    components = cg_texture_get_components(source);

    if (downsampler->dest == NULL ||
        cg_texture_get_width(downsampler->dest) != dest_width ||
        cg_texture_get_height(downsampler->dest) != dest_height ||
        cg_texture_get_components(downsampler->dest) != components) {
        cg_offscreen_t *offscreen;
        cg_texture_2d_t *texture_2d = cg_texture_2d_new_with_size(
            downsampler->engine->shell->cg_device, dest_width, dest_height);

        cg_texture_set_components(texture_2d, components);

        _rig_downsampler_reset(downsampler);

        downsampler->dest = texture_2d;

        /* create the FBO to render the downsampled texture */
        offscreen = cg_offscreen_new_with_texture(downsampler->dest);
        downsampler->fb = offscreen;

        /* create the camera that will setup the scene for the render */
        downsampler->camera = rig_camera_new(downsampler->engine,
                                             dest_width, /* ortho width */
                                             dest_height, /* ortho height */
                                             downsampler->fb);
        rut_camera_set_near_plane(downsampler->camera, -1.f);
        rut_camera_set_far_plane(downsampler->camera, 1.f);
    }

    pipeline = cg_pipeline_copy(downsampler->pipeline);
    cg_pipeline_set_layer_texture(pipeline, 0, source);

    rut_camera_flush(downsampler->camera);

    cg_framebuffer_draw_rectangle(
        downsampler->fb, pipeline, 0, 0, dest_width, dest_height);

    rut_camera_end_frame(downsampler->camera);

    cg_object_unref(pipeline);

    return cg_object_ref(downsampler->dest);
}