Class Joyau::Shape
In: Drawable.cpp
Parent: Joyau::Drawable

Class including functions used when setting a drawable’s colors. Notice they don’t have all the same numbers of colors. That number is usually specific to the class, yet it might be specifc to an object. You can get it with Shape#colorsNumber

Methods

Public Instance methods

color()

Alias for getColor

color=(...)

Alias for setColor

colors()

Alias for getColors

colorsNumber()

Alias for getColorsNumber

Return the shape’s first color.

[Source]

/*
  Return the shape's first color.
*/
VALUE Shape_getColor(VALUE self)
{
   Shape &ref = getRef<Shape>(self);
   return col2hash(ref.getColor());
}

Returns an array containing all the shape’s colors.

[Source]

/*
  Returns an array containing all the shape's colors.
*/
VALUE Shape_getColors(VALUE self)
{
   Shape &ref = getRef<Shape>(self);
   int size = ref.getColorsNumber();

   VALUE ret = rb_ary_new();
   OSL_COLOR *col = ref.getColors();

   for (int i = 0; i < size; ++i)
      rb_ary_push(ret, col2hash(col[i]));
   return ret;
}

Returns how many colors there are in that shape.

[Source]

/*
  Returns how many colors there are in that shape.
*/
VALUE Shape_getColorsNumber(VALUE self)
{
   Shape &ref = getRef<Shape>(self);
   return INT2FIX(ref.getColorsNumber());
}
gradient=(p1)

Alias for setGradient

Sets the sahpe’s color. If it has more than one color, all are set to the same value.

[Source]

/*
  call-seq: setColor(r, g, b, a = 255)
            setColor(col)

  Sets the sahpe's color. If it has more than one color, all are set to the
  same value.
*/
VALUE Shape_setColor(int argc, VALUE *argv, VALUE self)
{
   Shape &ref = getRef<Shape>(self);
   OSL_COLOR _col = 0;
   if (argc >= 3)
   {
      int alpha = 255;
      if (argc > 3)
         alpha = FIX2INT(argv[3]);
      _col = RGBA(FIX2INT(argv[0]), FIX2INT(argv[1]), FIX2INT(argv[2]), alpha);
   }
   else if (argc == 1)
      _col = hash2col(argv[0]);

   ref.setColor(_col);
   return Qnil;
}

Take an array as argument.

[Source]

/*
  call-seq: setGraident(colors)

  Take an array as argument.
*/
VALUE Shape_setGradient(VALUE self, VALUE col)
{
   Shape &ref = getRef<Shape>(self);
   int size = ref.getColorsNumber();

   OSL_COLOR *args = new OSL_COLOR[size];
   for(int i = 0; i < size; ++i)
      args[i] = hash2col(rb_ary_entry(col, i));

   ref.setGradient(args);
   return col;
}

[Validate]