Class: Imlib2::Gradient

### Home Classes Methods

### In Files

- imlib2.c

### Parent

Object

### Methods

- ::new
- #add_color

### Files

- AUTHORS
- COPYING
- ChangeLog
- README
- TODO

### Class/Module Index

Quicksearch

- Imlib2
- Imlib2::Border
- Imlib2::Cache
- Imlib2::Color
- Imlib2::Color::CmyaColor
- Imlib2::Color::HlsaColor
- Imlib2::Color::HsvaColor
- Imlib2::Color::RgbaColor
- Imlib2::ColorModifier
- Imlib2::Context
- Imlib2::Dir
- Imlib2::Direction
- Imlib2::Encoding
- Imlib2::Error
- Imlib2::Error::DeletedError
- Imlib2::FileError
- Imlib2::Filter
- Imlib2::Font
- Imlib2::Gradient
- Imlib2::Image
- Imlib2::Op
- Imlib2::Operation
- Imlib2::Polygon

No matching classes.

# Imlib2::Gradient

### Public Class Methods

new(*args) click to toggle source

Return a new Imlib2::Gradient.

Examples:

    # create a blue to green gradient
    grad = Imlib2::Gradient.new
    grad.add_color 0, Imlib2::Color::BLUE
    grad.add_color 100, Imlib2::Color::GREEN

    # create a red to yellow to black gradient
    colors = [ [0,   Imlib2::Color::RED    ],
               [100, Imlib2::Color::YELLOW ],
               [200, Imlib2::Color::BLACK  ] ]
    grad = Imlib2::Gradient.new *colors

    VALUE gradient_new(int argc, VALUE *argv, VALUE klass) {
      Imlib_Color_Range *range;
      VALUE g_o;

      range = malloc(sizeof(Imlib_Color_Range*));
      *range = imlib_create_color_range();

      g_o = Data_Wrap_Struct(klass, 0, gradient_free, range);
      rb_obj_call_init(g_o, argc, argv);

      return g_o;
    }

### Public Instance Methods

add_color(p1, p2) click to toggle source

Add a color at the given distance

Examples:

    # add the context color with a 100 pixel offset
    grad.add_color 100

    # add white at a 100 pixel offset
    grad.add_color 100, Imlib2::Color::WHITE

    static VALUE gradient_add_color(int argc, VALUE *argv, VALUE self) {
      Imlib_Color_Range *grad;
      VALUE color = Qnil;
      int distance;

      switch (argc) {
        case 1:
          distance = NUM2INT(argv[0]);
          break;
        case 2:
          distance = NUM2INT(argv[0]);
          color = argv[1];
          break;
        default:
          rb_raise(rb_eTypeError, "Invalid argument count (not 1 or 2)");
      }

      Data_Get_Struct(self, Imlib_Color_Range, grad);
      imlib_context_set_color_range(*grad);

      if (color != Qnil)
        set_context_color(color);

      imlib_add_color_to_color_range(distance);

      return self;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.