コード例 #1
0
static void
create_box_control(entity_state_t *entity_state, float x, float y, float z)
{
    rig_selection_tool_t *tool = entity_state->tool;
    cg_texture_t *tex =
        rut_load_texture_from_data_file(tool->shell, "dot.png", NULL);
    control_point_t *point;

    point = c_slice_new0(control_point_t);
    point->entity_state = entity_state;
    point->x = x;
    point->y = y;
    point->z = z;

    point->transform = rut_transform_new(tool->shell);
    rut_graphable_add_child(tool->tool_overlay, point->transform);
    rut_object_unref(point->transform);

    point->marker = rut_nine_slice_new(tool->shell, tex, 0, 0, 0, 0, 10, 10);
    rut_graphable_add_child(point->transform, point->marker);
    rut_object_unref(point->marker);

    point->input_region =
        rut_input_region_new_circle(0, 0, 5, control_point_input_cb, point);
    rut_graphable_add_child(tool->tool_overlay, point->input_region);
    rut_object_unref(point->input_region);
    entity_state->control_points =
        c_llist_prepend(entity_state->control_points, point);

    cg_object_unref(tex);
}
コード例 #2
0
static void
_rut_fold_free(void *object)
{
    rut_fold_t *fold = object;

    rut_fold_set_child(fold, NULL);

    rut_object_unref(fold->fold_up_icon);
    rut_object_unref(fold->fold_down_icon);

    rut_graphable_destroy(fold);
    rig_introspectable_destroy(fold);

    rut_object_free(rut_fold_t, fold);
}
コード例 #3
0
static void
on_connect(uv_connect_t *connection_request, int status)
{
    rig_pb_stream_t *stream = connection_request->data;

    c_return_if_fail(stream->connecting);

    stream->connecting = false;

    if (status < 0) {
        c_warning("Failed to connect to %s:%s - %s",
                  stream->hostname,
                  stream->port,
                  uv_strerror(status));

        rut_closure_list_invoke(&stream->on_error_closures,
                                rig_pb_stream_callback_t,
                                stream);
        goto exit;
    }

    stream->type = STREAM_TYPE_TCP;
    set_connected(stream);

exit:
    /* NB: we were at least keeping the stream alive while
     * waiting for the connection request to finish... */
    stream->connecting = false;
    rut_object_unref(stream);
}
コード例 #4
0
static void
rut_headless_shell_cleanup(rut_shell_t *shell)
{
    if (shell->headless_onscreen) {
        rut_object_unref(shell->headless_onscreen);
        shell->headless_onscreen = NULL;
    }
}
コード例 #5
0
static void
_rut_attribute_free(rut_object_t *object)
{
    rut_attribute_t *attribute = object;
    if (attribute->is_buffered)
        rut_object_unref(attribute->buffered.buffer);
    rut_object_free(rut_attribute_t, attribute);
}
コード例 #6
0
static void
_rut_mesh_free(rut_object_t *object)
{
    rut_mesh_t *mesh = object;
    int i;

    for (i = 0; i < mesh->n_attributes; i++)
        rut_object_unref(mesh->attributes[i]);

    c_slice_free1(mesh->n_attributes * sizeof(void *), mesh->attributes);
    rut_object_free(rut_mesh_t, mesh);
}
コード例 #7
0
static void
on_address_resolved(uv_getaddrinfo_t *resolver,
                    int status,
                    struct addrinfo *result)
{
    rig_pb_stream_t *stream = rut_container_of(resolver, stream, resolver);
    uv_loop_t *loop = rut_uv_shell_get_loop(stream->shell);
    char ip_address[17] = {'\0'};

    c_return_if_fail(stream->resolving);

    if (status < 0) {
        c_warning("Failed to resolve slave address \"%s\": %s",
                  stream->hostname, uv_strerror(status));

        rut_closure_list_invoke(&stream->on_error_closures,
                                rig_pb_stream_callback_t,
                                stream);

        /* NB: we were at least keeping the stream alive while
         * waiting for the resolve request to finish... */
        stream->resolving = false;
        rut_object_unref(stream);

        return;
    }

    uv_ip4_name((struct sockaddr_in*)result->ai_addr, ip_address, 16);
    c_message("stream: Resolved address of \"%s\" = %s",
              stream->hostname, ip_address);

    uv_tcp_init(loop, &stream->tcp.socket);
    stream->tcp.socket.data = stream;

    /* NB: we took a reference to keep the stream alive while
     * resolving the address, so conceptually we are now handing
     * the reference over to keep the stream alive while waiting
     * for it to connect... */
    stream->resolving = false;
    stream->connecting = true;

    stream->connection_request.data = stream;
    uv_tcp_connect(&stream->connection_request,
                   &stream->tcp.socket,
                   result->ai_addr,
                   on_connect);

    uv_freeaddrinfo(result);
}
コード例 #8
0
static void
entity_state_destroy(entity_state_t *entity_state)
{
    c_llist_t *l;

    for (l = entity_state->control_points; l; l = l->next) {
        control_point_t *point = l->data;
        rut_graphable_remove_child(point->input_region);
        rut_graphable_remove_child(point->transform);
    }

    rut_object_unref(entity_state->entity);

    c_slice_free(entity_state_t, entity_state);
}
コード例 #9
0
static void
_rig_downsampler_reset(rig_downsampler_t *downsampler)
{
    if (downsampler->dest) {
        cg_object_unref(downsampler->dest);
        downsampler->dest = NULL;
    }

    if (downsampler->fb) {
        cg_object_unref(downsampler->fb);
        downsampler->fb = NULL;
    }

    if (downsampler->camera) {
        rut_object_unref(downsampler->camera);
        downsampler->camera = NULL;
    }
}
コード例 #10
0
void
rut_mesh_set_attributes(rut_mesh_t *mesh,
                        rut_attribute_t **attributes,
                        int n_attributes)
{
    rut_attribute_t **attributes_real = attributes ?
        c_slice_copy(sizeof(void *) * n_attributes, attributes) : NULL;
    int i;

    /* NB: some of the given attributes may be the same as
     * some of the current attributes so we ref before
     * unrefing to avoid destroying any of them. */
    for (i = 0; i < n_attributes; i++)
        rut_object_ref(attributes[i]);

    for (i = 0; i < mesh->n_attributes; i++)
        rut_object_unref(mesh->attributes[i]);

    mesh->attributes = attributes_real;
    mesh->n_attributes = n_attributes;
}
コード例 #11
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;
}
コード例 #12
0
rut_mesh_t *
rut_mesh_copy(rut_mesh_t *mesh)
{
    rut_buffer_t **buffers;
    int n_buffers = 0;
    rut_buffer_t **attribute_buffers;
    rut_buffer_t **attribute_buffers_map;
    rut_attribute_t **attributes;
    rut_mesh_t *copy;
    int i;

    buffers = c_alloca(sizeof(void *) * mesh->n_attributes);
    attribute_buffers = c_alloca(sizeof(void *) * mesh->n_attributes);
    attribute_buffers_map = c_alloca(sizeof(void *) * mesh->n_attributes);

    /* NB:
     * attributes may refer to shared buffers so we need to first
     * figure out how many unique buffers the mesh refers too...
     */

    for (i = 0; i < mesh->n_attributes; i++) {
        int j;

        for (j = 0; i < n_buffers; j++)
            if (buffers[j] == mesh->attributes[i]->buffered.buffer)
                break;

        if (j < n_buffers)
            attribute_buffers_map[i] = attribute_buffers[j];
        else {
            attribute_buffers[n_buffers] =
                rut_buffer_new(mesh->attributes[i]->buffered.buffer->size);
            memcpy(attribute_buffers[n_buffers]->data,
                   mesh->attributes[i]->buffered.buffer->data,
                   mesh->attributes[i]->buffered.buffer->size);

            attribute_buffers_map[i] = attribute_buffers[n_buffers];
            buffers[n_buffers++] = mesh->attributes[i]->buffered.buffer;
        }
    }

    attributes = c_alloca(sizeof(void *) * mesh->n_attributes);
    for (i = 0; i < mesh->n_attributes; i++) {
        if (mesh->attributes[i]->is_buffered) {
            attributes[i] = rut_attribute_new(attribute_buffers_map[i],
                                              mesh->attributes[i]->name,
                                              mesh->attributes[i]->buffered.stride,
                                              mesh->attributes[i]->buffered.offset,
                                              mesh->attributes[i]->buffered.n_components,
                                              mesh->attributes[i]->buffered.type);
        } else {
            attributes[i] = rut_attribute_new_const(mesh->attributes[i]->name,
                                                    mesh->attributes[i]->constant.n_components,
                                                    mesh->attributes[i]->constant.n_columns,
                                                    mesh->attributes[i]->constant.transpose,
                                                    mesh->attributes[i]->constant.value);
        }
        attributes[i]->normalized = mesh->attributes[i]->normalized;
        attributes[i]->instance_stride = mesh->attributes[i]->instance_stride;
    }

    copy = rut_mesh_new(mesh->mode, mesh->n_vertices,
                        attributes, mesh->n_attributes);

    for (i = 0; i < mesh->n_attributes; i++)
        rut_object_unref(attributes[i]);

    if (mesh->indices_buffer) {
        rut_buffer_t *indices_buffer =
            rut_buffer_new(mesh->indices_buffer->size);
        memcpy(indices_buffer->data,
               mesh->indices_buffer->data,
               mesh->indices_buffer->size);
        rut_mesh_set_indices(
            copy, mesh->indices_type, indices_buffer, mesh->n_indices);
        rut_object_unref(indices_buffer);
    }

    return copy;
}