/** * Constructs a new Pattern that represents a linear, two color gradient. Drawing with the pattern * will cause the resulting area to be tiled with the gradient specified by the arguments. * * <p>This operation requires the operating system's advanced graphics subsystem which may not be * available on some platforms. * * @param device the device on which to allocate the pattern * @param x1 the x coordinate of the starting corner of the gradient * @param y1 the y coordinate of the starting corner of the gradient * @param x2 the x coordinate of the ending corner of the gradient * @param y2 the y coordinate of the ending corner of the gradient * @param color1 the starting color of the gradient * @param alpha1 the starting alpha value of the gradient * @param color2 the ending color of the gradient * @param alpha2 the ending alpha value of the gradient * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or if * either color1 or color2 is null * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available * </ul> * * @exception SWTError * <ul> * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained * </ul> * * @see #dispose() * @since 3.2 */ public Pattern( Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) { super(device); if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); this.device.checkCairo(); handle = Cairo.cairo_pattern_create_linear(x1, y1, x2, y2); if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); GC.setCairoPatternColor(handle, 0, color1, alpha1); GC.setCairoPatternColor(handle, 1, color2, alpha2); Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT); init(); }
/** * Add a stop to the collection of stops defining the color and alpha blending of this SVG style * linear or radial gradient. * * <p>For linear gradients, the stops represent locations along the gradient vector. For radial * gradients, they represent locations from the focal point (fx,fy) to the edge of the * outermost/largest circle. * * @param color the color to use at that gradient stop * @param offset a number between 0.0 and 1.0 which indicates the location of the gradient stop. * For linear gradients, the �offset� attribute represents a location along the gradient * vector. For radial gradients, it represents a percentage distance from (fx,fy) to the edge * of the outermost/largest circle * @param alpha the alpha value of the gradient at this stop location (from 0 to 255) * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if color is null * <li>ERROR_INVALID_ARGUMENT - if color has been disposed * </ul> */ public void addStop(Color color, float /*double*/ offset, int alpha) { GC.setCairoPatternColor(handle, offset, color, alpha); }