Ejemplo n.º 1
0
RutClosure *
rut_sizable_add_preferred_size_callback (RutObject *object,
                                         RutSizablePreferredSizeCallback cb,
                                         void *user_data,
                                         RutClosureDestroyCallback destroy_cb)
{
  RutSizableVTable *sizable =
    rut_object_get_vtable (object, RUT_INTERFACE_ID_SIZABLE);

  /* If the object has no implementation for the needs layout callback
   * then we'll assume its preferred size never changes. We'll return
   * a dummy closure object that will never be invoked so that the
   * rest of the code doesn't need to handle this specially */
  if (sizable->add_preferred_size_callback == NULL)
    {
      RutList dummy_list;
      RutClosure *closure;

      rut_list_init (&dummy_list);

      closure = rut_closure_list_add (&dummy_list,
                                      cb,
                                      user_data,
                                      destroy_cb);

      rut_list_init (&closure->list_node);

      return closure;
    }
  else
    return sizable->add_preferred_size_callback (object,
                                                 cb,
                                                 user_data,
                                                 destroy_cb);
}
Ejemplo n.º 2
0
RutShape *
rut_shape_new (RutContext *ctx,
               CoglBool shaped,
               int tex_width,
               int tex_height)
{
  RutShape *shape = g_slice_new0 (RutShape);

  rut_object_init (&shape->_parent, &rut_shape_type);

  shape->ref_count = 1;

  shape->component.type = RUT_COMPONENT_TYPE_GEOMETRY;

  shape->ctx = rut_refable_ref (ctx);

  shape->tex_width = tex_width;
  shape->tex_height = tex_height;
  shape->shaped = shaped;

  rut_list_init (&shape->reshaped_cb_list);

  rut_simple_introspectable_init (shape,
                                  _rut_shape_prop_specs,
                                  shape->properties);

  return shape;
}
Ejemplo n.º 3
0
RutBin *
rut_bin_new (RutContext *ctx)
{
    RutBin *bin = g_slice_new0 (RutBin);
    static CoglBool initialized = FALSE;

    if (initialized == FALSE)
    {
        _rut_bin_init_type ();

        initialized = TRUE;
    }

    bin->ref_count = 1;
    bin->context = rut_refable_ref (ctx);

    bin->x_position = RUT_BIN_POSITION_EXPAND;
    bin->y_position = RUT_BIN_POSITION_EXPAND;

    rut_list_init (&bin->preferred_size_cb_list);

    rut_object_init (&bin->_parent, &rut_bin_type);

    rut_graphable_init (RUT_OBJECT (bin));

    bin->child_transform = rut_transform_new (ctx);
    rut_graphable_add_child (bin, bin->child_transform);

    return bin;
}
Ejemplo n.º 4
0
Archivo: rut-fixed.c Proyecto: cee1/rig
RutFixed *
rut_fixed_new (RutContext *ctx,
               float width,
               float height)
{
  RutFixed *fixed = g_slice_new0 (RutFixed);
  static CoglBool initialized = FALSE;

  if (initialized == FALSE)
    {
      _rut_fixed_init_type ();
      initialized = TRUE;
    }

  rut_object_init (&fixed->_parent, &rut_fixed_type);

  fixed->ref_count = 1;

  fixed->context = ctx;

  rut_list_init (&fixed->preferred_size_cb_list);

  rut_graphable_init (fixed);

  fixed->width = width;
  fixed->height = height;

  return fixed;
}
Ejemplo n.º 5
0
Archivo: rut-shim.c Proyecto: cee1/rig
RutShim *
rut_shim_new (RutContext *ctx,
              float width,
              float height)
{
  RutShim *shim = g_slice_new0 (RutShim);
  static CoglBool initialized = FALSE;

  if (initialized == FALSE)
    {
      _rut_shim_init_type ();
      initialized = TRUE;
    }

  rut_object_init (&shim->_parent, &rut_shim_type);

  shim->ref_count = 1;

  shim->context = ctx;

  rut_list_init (&shim->preferred_size_cb_list);

  rut_graphable_init (shim);

  shim->width = width;
  shim->height = height;

  return shim;
}
Ejemplo n.º 6
0
RigSelectionTool *
rig_selection_tool_new (RigCameraView *view,
                        RutObject *overlay)
{
  RigSelectionTool *tool = g_slice_new0 (RigSelectionTool);
  RutContext *ctx = view->context;

  tool->view = view;
  tool->ctx = ctx;

  /* Note: we don't take a reference on this overlay to avoid creating
   * a circular reference. */
  tool->tool_overlay = overlay;

  tool->camera = view->view_camera;
  tool->camera_component =
    rut_entity_get_component (tool->camera, RUT_COMPONENT_TYPE_CAMERA);

  rut_list_init (&tool->selection_event_cb_list);

  /* pipeline to draw the tool */
  tool->default_pipeline = cogl_pipeline_new (rut_cogl_context);

  return tool;
}
Ejemplo n.º 7
0
RutPointalismGrid *
rut_pointalism_grid_new (RutContext *ctx,
                         float size,
                         int tex_width,
                         int tex_height)
{
  RutPointalismGrid *grid = g_slice_new0 (RutPointalismGrid);
  RutBuffer *buffer = rut_buffer_new (sizeof (CoglVertexP3) * 6);
  RutMesh *pick_mesh = rut_mesh_new_from_buffer_p3 (COGL_VERTICES_MODE_TRIANGLES,
                                                    6,
                                                    buffer);
  CoglVertexP3 *pick_vertices = (CoglVertexP3 *)buffer->data;
  float half_tex_width;
  float half_tex_height;

  rut_object_init (&grid->_parent, &rut_pointalism_grid_type);

  grid->ref_count = 1;

  grid->component.type = RUT_COMPONENT_TYPE_GEOMETRY;

  grid->ctx = rut_refable_ref (ctx);

  rut_list_init (&grid->updated_cb_list);

  grid->slice = pointalism_grid_slice_new (tex_width, tex_height,
                                           size);

  half_tex_width = tex_width / 2.0f;
  half_tex_height = tex_height / 2.0f;

  pick_vertices[0].x = -half_tex_width;
  pick_vertices[0].y = -half_tex_height;
  pick_vertices[1].x = -half_tex_width;
  pick_vertices[1].y = half_tex_height;
  pick_vertices[2].x = half_tex_width;
  pick_vertices[2].y = half_tex_height;
  pick_vertices[3] = pick_vertices[0];
  pick_vertices[4] = pick_vertices[2];
  pick_vertices[5].x = half_tex_width;
  pick_vertices[5].y = -half_tex_height;

  grid->pick_mesh = pick_mesh;
  grid->pointalism_scale = 1;
  grid->pointalism_z = 1;
  grid->pointalism_lighter = TRUE;
  grid->cell_size = size;
  grid->tex_width = tex_width;
  grid->tex_height = tex_height;

  rut_simple_introspectable_init (grid, _rut_pointalism_grid_prop_specs,
                                  grid->properties);

  return grid;
}
Ejemplo n.º 8
0
RutMemoryStack *
rut_memory_stack_new (size_t initial_size_bytes)
{
  RutMemoryStack *stack = g_slice_new0 (RutMemoryStack);

  rut_list_init (&stack->sub_stacks);

  rut_memory_stack_add_sub_stack (stack, initial_size_bytes);

  return stack;
}
Ejemplo n.º 9
0
RigTransition *
rig_transition_new (RutContext *context,
                    uint32_t id)
{
  //CoglError *error = NULL;
  RigTransition *transition;
  static CoglBool initialized = FALSE;

  if (initialized == FALSE)
    {
      _rig_transition_type_init ();

      initialized = TRUE;
    }

  transition = g_slice_new0 (RigTransition);

  transition->id = id;
  transition->context = rut_refable_ref (context);

  rut_object_init (&transition->_parent, &rig_transition_type);

  rut_list_init (&transition->operation_cb_list);

  rut_simple_introspectable_init (transition, _rig_transition_prop_specs, transition->props);

  transition->progress = 0;

  transition->properties = g_hash_table_new_full (g_direct_hash,
                                                  g_direct_equal,
                                                  NULL, /* key_destroy */
                                                  free_prop_data_cb);

#if 0
  rut_property_set_binding (&transition->props[RUT_TRANSITION_PROP_PROGRESS],
                            update_transition_progress_cb,
                            engine,
                            engine->timeline_elapsed,
                            NULL);
#endif

  return transition;
}
Ejemplo n.º 10
0
Archivo: rut-bin.c Proyecto: cee1/rig
RutBin *
rut_bin_new (RutContext *ctx)
{
  RutBin *bin = rut_object_alloc0 (RutBin,
                                   &rut_bin_type,
                                   _rut_bin_init_type);

  bin->ref_count = 1;
  bin->context = ctx;

  bin->x_position = RUT_BIN_POSITION_EXPAND;
  bin->y_position = RUT_BIN_POSITION_EXPAND;

  rut_list_init (&bin->preferred_size_cb_list);

  rut_graphable_init (RUT_OBJECT (bin));

  bin->child_transform = rut_transform_new (ctx);
  rut_graphable_add_child (bin, bin->child_transform);
  rut_refable_unref (bin->child_transform);

  return bin;
}
Ejemplo n.º 11
0
RutIconButton *
rut_icon_button_new (RutContext *ctx,
                     const char *label,
                     RutIconButtonPosition label_position,
                     const char *normal_icon,
                     const char *hover_icon,
                     const char *active_icon,
                     const char *disabled_icon)
{
  RutIconButton *button = g_slice_new0 (RutIconButton);
  float natural_width, natural_height;
  static CoglBool initialized = FALSE;

  if (initialized == FALSE)
    {
      _rut_icon_button_init_type ();
      initialized = TRUE;
    }

  rut_object_init (RUT_OBJECT (button), &rut_icon_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 = ICON_BUTTON_STATE_NORMAL;

  button->stack = rut_stack_new (ctx, 100, 100);

  button->layout = rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_TOP_TO_BOTTOM);
  rut_stack_add (button->stack, button->layout);
  rut_refable_unref (button->layout);

  button->bin = rut_bin_new (ctx);
  rut_box_layout_add (button->layout, TRUE, button->bin);
  rut_refable_unref (button->bin);

  button->label_position = label_position;

  if (label)
    {
      RutBin *bin = rut_bin_new (ctx);

      rut_bin_set_x_position (bin, RUT_BIN_POSITION_CENTER);

      button->label = rut_text_new_with_text (ctx, NULL, label);
      rut_bin_set_child (bin, button->label);

      rut_box_layout_add (button->layout, FALSE, bin);
      rut_refable_unref (bin);

      update_layout (button);
    }

  rut_icon_button_set_normal (button, normal_icon);
  rut_icon_button_set_hover (button, hover_icon);
  rut_icon_button_set_active (button, active_icon);
  rut_icon_button_set_disabled (button, disabled_icon);

  button->input_region =
    rut_input_region_new_rectangle (0, 0, 100, 100,
                                    _rut_icon_button_input_cb,
                                    button);
  rut_stack_add (button->stack, button->input_region);
  rut_refable_unref (button->input_region);

  rut_sizable_get_preferred_width (button->stack, -1, NULL,
                                   &natural_width);
  rut_sizable_get_preferred_height (button->stack, natural_width, NULL,
                                    &natural_height);
  rut_sizable_set_size (button->stack, natural_width, natural_height);

  rut_graphable_add_child (button, button->stack);

  return button;
}
Ejemplo n.º 12
0
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;
}