示例#1
0
void
rut_property_box (RutProperty *property,
                  RutBoxed *boxed)
{
    boxed->type = property->spec->type;

    switch ((RutPropertyType) property->spec->type)
    {
#define SCALAR_TYPE(SUFFIX, CTYPE, TYPE) \
    case RUT_PROPERTY_TYPE_ ## TYPE: \
      { \
        boxed->d. SUFFIX ## _val = rut_property_get_ ## SUFFIX (property); \
        break; \
      }
        /* Special case the _POINTER types so we can take a reference on
         * objects... */
#define POINTER_TYPE(SUFFIX, CTYPE, TYPE)
    case RUT_PROPERTY_TYPE_OBJECT:
    {
        RutObject *obj = rut_property_get_object (property);
        if (obj)
            boxed->d.object_val = rut_refable_ref (obj);
        else
            boxed->d.object_val = NULL;
        break;
    }
    case RUT_PROPERTY_TYPE_POINTER:
    {
        boxed->d.pointer_val = rut_property_get_pointer (property);
        break;
    }
#define COMPOSITE_TYPE(SUFFIX, CTYPE, TYPE) \
case RUT_PROPERTY_TYPE_ ## TYPE: \
  { \
    memcpy (&boxed->d. SUFFIX ## _val, \
            rut_property_get_ ## SUFFIX (property), \
            sizeof (boxed->d. SUFFIX ## _val)); \
    break; \
  }
#define ARRAY_TYPE(SUFFIX, CTYPE, TYPE, LEN) \
case RUT_PROPERTY_TYPE_ ## TYPE: \
  { \
    memcpy (&boxed->d. SUFFIX ## _val, \
            rut_property_get_ ## SUFFIX (property), \
            sizeof (CTYPE) * LEN); \
    break; \
  }
    case RUT_PROPERTY_TYPE_TEXT:
        boxed->d.text_val = g_strdup (rut_property_get_text (property));
        break;

#include "rut-property-types.h"
    }

#undef POINTER_TYPE
#undef ARRAY_TYPE
#undef COMPOSITE_TYPE
#undef SCALAR_TYPE
}
示例#2
0
文件: rut-camera.c 项目: cee1/rig
void
rut_camera_add_input_region (RutCamera *camera,
                             RutInputRegion *region)
{
  if (g_list_find (camera->input_regions, region))
    return;

  rut_refable_ref (region);
  camera->input_regions = g_list_prepend (camera->input_regions, region);
}
示例#3
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;
}
示例#4
0
static void
objects_selection_event_cb (RigObjectsSelection *selection,
                            RigObjectsSelectionEvent event,
                            RutObject *object,
                            void *user_data)
{
  RigSelectionTool *tool = user_data;
  EntityState *entity_state;
  GList *l;

  if (!tool->active && event == RIG_OBJECTS_SELECTION_ADD_EVENT)
    return;

  if (rut_object_get_type (object) != &rut_entity_type)
    return;

  for (l = tool->selected_entities; l; l = l->next)
    {
      entity_state = l->data;
      if (entity_state->entity == object)
        break;
    }
  if (l == NULL)
    entity_state = NULL;

  switch (event)
    {
    case RIG_OBJECTS_SELECTION_ADD_EVENT:
      {
        g_return_if_fail (entity_state == NULL);

        entity_state = g_slice_new0 (EntityState);
        entity_state->tool = tool;
        entity_state->entity = rut_refable_ref (object);
        entity_state->control_points = NULL;

        tool->selected_entities = g_list_prepend (tool->selected_entities,
                                                  entity_state);

#warning "TODO: create meaningful control points!"
        create_dummy_control_points (entity_state);

        break;
      }

    case RIG_OBJECTS_SELECTION_REMOVE_EVENT:
      g_return_if_fail (entity_state != NULL);

      tool->selected_entities = g_list_remove (tool->selected_entities, entity_state);
      entity_state_destroy (entity_state);
      break;
    }
}
示例#5
0
RutDiamond *
rut_diamond_new (RutContext *ctx,
                 float size,
                 int tex_width,
                 int tex_height)
{
  RutDiamond *diamond = g_slice_new0 (RutDiamond);
  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;

  rut_object_init (&diamond->_parent, &rut_diamond_type);

  diamond->ref_count = 1;

  diamond->component.type = RUT_COMPONENT_TYPE_GEOMETRY;

  diamond->ctx = rut_refable_ref (ctx);

  diamond->size = size;

  /* XXX: It could be worth maintaining a cache of diamond slices
   * indexed by the <size, tex_width, tex_height> tuple... */
  diamond->slice = diamond_slice_new (ctx, size, tex_width, tex_height);

  pick_vertices[0].x = 0;
  pick_vertices[0].y = 0;
  pick_vertices[1].x = 0;
  pick_vertices[1].y = size;
  pick_vertices[2].x = size;
  pick_vertices[2].y = size;
  pick_vertices[3] = pick_vertices[0];
  pick_vertices[4] = pick_vertices[2];
  pick_vertices[5].x = size;
  pick_vertices[5].y = 0;

  cogl_matrix_transform_points (&diamond->slice->rotate_matrix,
                                2,
                                sizeof (CoglVertexP3),
                                pick_vertices,
                                sizeof (CoglVertexP3),
                                pick_vertices,
                                6);

  diamond->pick_mesh = pick_mesh;

  return diamond;
}
示例#6
0
void
rut_boxed_copy (RutBoxed *dst,
                const RutBoxed *src)
{
    dst->type = src->type;

    switch (src->type)
    {
#define SCALAR_TYPE(SUFFIX, CTYPE, TYPE)                      \
    case RUT_PROPERTY_TYPE_ ## TYPE:                          \
      dst->d. SUFFIX ## _val = src->d. SUFFIX ## _val;        \
      return;
#define COMPOSITE_TYPE(SUFFIX, CTYPE, TYPE) \
    SCALAR_TYPE (SUFFIX, CTYPE, TYPE)
        /* Special case the _POINTER types so we can take a reference on
         * objects... */
#define POINTER_TYPE(SUFFIX, CTYPE, TYPE)
    case RUT_PROPERTY_TYPE_OBJECT:
    {
        if (src->d.object_val)
            dst->d.object_val = rut_refable_ref (src->d.object_val);
        else
            dst->d.object_val = NULL;
        return;
    }
    case RUT_PROPERTY_TYPE_POINTER:
        dst->d.pointer_val = src->d.pointer_val;
        return;
#define ARRAY_TYPE(SUFFIX, CTYPE, TYPE, LEN)                    \
    case RUT_PROPERTY_TYPE_ ## TYPE:                          \
      {                                                       \
        memcpy (&dst->d. SUFFIX ## _val,                      \
                &src->d. SUFFIX ## _val,                      \
                sizeof (CTYPE) * LEN);                        \
        return;                                               \
      }
    case RUT_PROPERTY_TYPE_TEXT:
        dst->d.text_val = g_strdup (src->d.text_val);
        return;

#include "rut-property-types.h"
    }

#undef POINTER_TYPE
#undef ARRAY_TYPE
#undef COMPOSITE_TYPE
#undef SCALAR_TYPE

    g_assert_not_reached ();
}
示例#7
0
static void
rig_journal_log (GArray *journal,
                 RigPaintContext *paint_ctx,
                 RutEntity *entity,
                 const CoglMatrix *matrix)
{

  RigJournalEntry *entry;

  g_array_set_size (journal, journal->len + 1);
  entry = &g_array_index (journal, RigJournalEntry, journal->len - 1);

  entry->entity = rut_refable_ref (entity);
  entry->matrix = *matrix;
}
示例#8
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;
}
示例#9
0
RutLight *
rut_light_new (RutContext *context)
{
  RutLight *light;

  light = g_slice_new0 (RutLight);
  rut_object_init (&light->_parent, &rut_light_type);

  light->ref_count = 1;
  light->component.type = RUT_COMPONENT_TYPE_LIGHT;
  light->context = rut_refable_ref (context);

  rut_simple_introspectable_init (light,
                                  _rut_light_prop_specs,
                                  light->properties);

  cogl_color_init_from_4f (&light->ambient, 1.0, 1.0, 1.0, 1.0);
  cogl_color_init_from_4f (&light->diffuse, 1.0, 1.0, 1.0, 1.0);
  cogl_color_init_from_4f (&light->specular, 1.0, 1.0, 1.0, 1.0);

  return light;
}