예제 #1
0
/*< private >
 * _clutter_paint_node_init_types:
 *
 * Initializes the required types for ClutterPaintNode subclasses
 */
void
_clutter_paint_node_init_types (void)
{
  CoglContext *ctx;
  CoglColor cogl_color;
  GType node_type G_GNUC_UNUSED;

  if (G_LIKELY (default_color_pipeline != NULL))
    return;

  ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());

  node_type = clutter_paint_node_get_type ();

  cogl_color_init_from_4f (&cogl_color, 1.0, 1.0, 1.0, 1.0);

  default_color_pipeline = cogl_pipeline_new (ctx);
  cogl_pipeline_set_color (default_color_pipeline, &cogl_color);

  default_texture_pipeline = cogl_pipeline_new (ctx);
  cogl_pipeline_set_layer_null_texture (default_texture_pipeline, 0,
                                        COGL_TEXTURE_TYPE_2D);
  cogl_pipeline_set_color (default_texture_pipeline, &cogl_color);
  cogl_pipeline_set_layer_wrap_mode (default_texture_pipeline, 0,
                                     COGL_PIPELINE_WRAP_MODE_AUTOMATIC);
}
예제 #2
0
파일: cogl-color.c 프로젝트: nobled/clutter
/* XXX: deprecated, use cogl_color_init_from_4f */
void
cogl_color_set_from_4f (CoglColor *color,
                        float      red,
                        float      green,
                        float      blue,
                        float      alpha)
{
  cogl_color_init_from_4f (color, red, green, blue, alpha);
}
예제 #3
0
파일: cogl.c 프로젝트: collinss/muffin
void
cogl_set_source_color4f (float red,
                         float green,
                         float blue,
                         float alpha)
{
  CoglColor c = { 0, };

  cogl_color_init_from_4f (&c, red, green, blue, alpha);
  cogl_set_source_color (&c);
}
예제 #4
0
void
cogl_pipeline_set_color4f (CoglPipeline *pipeline,
			   float red,
                           float green,
                           float blue,
                           float alpha)
{
  CoglColor color;
  cogl_color_init_from_4f (&color, red, green, blue, alpha);
  cogl_pipeline_set_color (pipeline, &color);
}
예제 #5
0
파일: cogl-color.c 프로젝트: 3v1n0/cogl
void
cogl_color_init_from_hsl (CoglColor *color,
                          float      hue,
                          float      saturation,
                          float      luminance)
{
  float tmp1, tmp2;
  float tmp3[3];
  float clr[3];
  int   i;

  hue /= 360.0;

  if (saturation == 0)
    {
      cogl_color_init_from_4f (color, luminance, luminance, luminance, 1.0f);
      return;
    }

  if (luminance <= 0.5)
    tmp2 = luminance * (1.0 + saturation);
  else
    tmp2 = luminance + saturation - (luminance * saturation);

  tmp1 = 2.0 * luminance - tmp2;

  tmp3[0] = hue + 1.0 / 3.0;
  tmp3[1] = hue;
  tmp3[2] = hue - 1.0 / 3.0;

  for (i = 0; i < 3; i++)
    {
      if (tmp3[i] < 0)
        tmp3[i] += 1.0;

      if (tmp3[i] > 1)
        tmp3[i] -= 1.0;

      if (6.0 * tmp3[i] < 1.0)
        clr[i] = tmp1 + (tmp2 - tmp1) * tmp3[i] * 6.0;
      else if (2.0 * tmp3[i] < 1.0)
        clr[i] = tmp2;
      else if (3.0 * tmp3[i] < 2.0)
        clr[i] = (tmp1 + (tmp2 - tmp1) * ((2.0 / 3.0) - tmp3[i]) * 6.0);
      else
        clr[i] = tmp1;
    }

  color->red   = clr[0];
  color->green = clr[1];
  color->blue  = clr[2];
  color->alpha = 1.0f;
}
예제 #6
0
파일: rut-camera.c 프로젝트: cee1/rig
void
rut_camera_set_background_color4f (RutCamera *camera,
                                   float red,
                                   float green,
                                   float blue,
                                   float alpha)
{
  cogl_color_init_from_4f (&camera->bg_color,
                           red, green, blue, alpha);
  rut_property_dirty (&camera->ctx->property_ctx,
                      &camera->properties[RUT_CAMERA_PROP_BG_COLOR]);
}
예제 #7
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;
}
예제 #8
0
파일: rut-button.c 프로젝트: cee1/rig
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;
}
예제 #9
0
파일: rut-fold.c 프로젝트: cee1/rig
RutFold *
rut_fold_new (RutContext *ctx,
              const char *label)
{
  RutFold *fold = g_slice_new0 (RutFold);
  static CoglBool initialized = FALSE;
  RutBoxLayout *header_hbox;
  RutStack *left_header_stack;
  RutBoxLayout *left_header_hbox;
  RutBin *label_bin;
  RutBin *fold_icon_align;
  CoglTexture *texture;
  CoglColor black;

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

      initialized = TRUE;
    }

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

  rut_object_init (&fold->_parent, &rut_fold_type);

  rut_graphable_init (fold);

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

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

  header_hbox =
    rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
  rut_box_layout_add (fold->vbox, FALSE, header_hbox);
  rut_refable_unref (header_hbox);

  left_header_stack = rut_stack_new (ctx, 0, 0);
  rut_box_layout_add (header_hbox, TRUE, left_header_stack);
  rut_refable_unref (left_header_stack);

  left_header_hbox =
    rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_LEFT_TO_RIGHT);
  rut_stack_add (left_header_stack, left_header_hbox);
  rut_refable_unref (left_header_hbox);

  fold_icon_align = rut_bin_new (ctx);
  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_refable_unref (fold_icon_align);

  texture = rut_load_texture_from_data_file (ctx, "tri-fold-up.png", NULL);
  fold->fold_up_icon = rut_nine_slice_new (ctx, texture,
                                           0, 0, 0, 0,
                                           cogl_texture_get_width (texture),
                                           cogl_texture_get_height (texture));
  cogl_object_unref (texture);

  texture = rut_load_texture_from_data_file (ctx, "tri-fold-down.png", NULL);
  fold->fold_down_icon = rut_nine_slice_new (ctx, texture,
                                             0, 0, 0, 0,
                                             cogl_texture_get_width (texture),
                                             cogl_texture_get_height (texture));
  cogl_object_unref (texture);

  fold->fold_icon_shim = rut_fixed_new (ctx,
                                        cogl_texture_get_width (texture),
                                        cogl_texture_get_height (texture));
  rut_bin_set_child (fold_icon_align, fold->fold_icon_shim);
  rut_refable_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 (ctx);
  rut_bin_set_y_position (label_bin, RUT_BIN_POSITION_CENTER);
  rut_box_layout_add (left_header_hbox, FALSE, label_bin);
  rut_refable_unref (label_bin);

  fold->label = rut_text_new_with_text (ctx, NULL, label);
  rut_bin_set_child (label_bin, fold->label);
  rut_refable_unref (fold->label);

  fold->header_hbox_right =
    rut_box_layout_new (ctx, RUT_BOX_LAYOUT_PACKING_RIGHT_TO_LEFT);
  rut_box_layout_add (header_hbox, TRUE, fold->header_hbox_right);
  rut_refable_unref (fold->header_hbox_right);

  cogl_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_refable_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_refable_unref (fold->input_region);

  fold->folded = FALSE;

  return fold;
}
예제 #10
0
static void _clone_paint_cb (ClutterActor *actor) {
    ClutterActor *source;
    ClutterActorBox box;
    CoglHandle material;
    gfloat width, height;
    guint8 opacity;
    CoglColor color_1, color_2;
    CoglTextureVertex vertices[4];

    /* if we don't have a source actor, don't paint */
    source = clutter_clone_get_source (CLUTTER_CLONE (actor));
    if (source == NULL)
        goto out;

    /* if the source texture does not have any content, don't paint */
    material = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (source));
    if (material == NULL)
        goto out;

    /* get the size of the reflection */
    clutter_actor_get_allocation_box (actor, &box);
    clutter_actor_box_get_size (&box, &width, &height);

    /* get the composite opacity of the actor */
    opacity = clutter_actor_get_paint_opacity (actor);

    /* figure out the two colors for the reflection: the first is
     * full color and the second is the same, but at 0 opacity
     */
    cogl_color_init_from_4f (&color_1, 1.0, 1.0, 1.0, opacity / 255.0);
    cogl_color_premultiply (&color_1);
    cogl_color_init_from_4f (&color_2, 1.0, 1.0, 1.0, 0.0);
    cogl_color_premultiply (&color_2);

    /* now describe the four vertices of the quad; since it has
     * to be a reflection, we need to invert it as well
     */
    vertices[0].x = 0; vertices[0].y = 0; vertices[0].z = 0;
    vertices[0].tx = 0.0; vertices[0].ty = 1.0;
    vertices[0].color = color_1;

    vertices[1].x = width; vertices[1].y = 0; vertices[1].z = 0;
    vertices[1].tx = 1.0; vertices[1].ty = 1.0;
    vertices[1].color = color_1;

    vertices[2].x = width; vertices[2].y = height; vertices[2].z = 0;
    vertices[2].tx = 1.0; vertices[2].ty = 0.0;
    vertices[2].color = color_2;

    vertices[3].x = 0; vertices[3].y = height; vertices[3].z = 0;
    vertices[3].tx = 0.0; vertices[3].ty = 0.0;
    vertices[3].color = color_2;

    /* paint the same texture but with a different geometry */
    cogl_set_source (material);
    cogl_polygon (vertices, 4, TRUE);

    out:
      /* prevent the default clone handler from running */
      g_signal_stop_emission_by_name (actor, "paint");
}