コード例 #1
0
 /**
  * Constructs a new Pattern that can be used to draw an SVG style radial gradient. Before using
  * the pattern, at least two color stops must be added.
  *
  * <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 cx the x coordinate of the center of the largest (i.e., outermost) circle for the radial
  *     gradient. The gradient will be drawn such that the 100% gradient stop is mapped to the
  *     perimeter of this largest (i.e., outermost) circle.
  * @param cy the y coordinate of the center of the largest (i.e., outermost) circle
  * @param fx the x coordinate of the focal point for the radial gradient. The gradient will be
  *     drawn such that the 0% gradient stop is mapped to (fx, fy).
  * @param fy the y coordinate of the focal point
  * @param r the radius of the largest (i.e., outermost) circle
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
  *     </ul>
  *
  * @see #addStop(Color, float)
  * @see #addStop(Color, float, int)
  * @since ???
  */
 public Pattern(Device device, float cx, float cy, float fx, float fy, float r) {
   super(device);
   this.device.checkCairo();
   handle = Cairo.cairo_pattern_create_radial(fx, fy, 0, cx, cy, r);
   Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_PAD);
   init();
 }
コード例 #2
0
 /**
  * Constructs a new Pattern that can be used to draw an SVG style linear gradient. Before using
  * the pattern, at least two color stops must be added.
  *
  * <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
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
  *     </ul>
  *
  * @see #addStop(Color, float)
  * @see #addStop(Color, float, int)
  * @since ???
  */
 public Pattern(Device device, float x1, float y1, float x2, float y2) {
   super(device);
   this.device.checkCairo();
   handle = Cairo.cairo_pattern_create_linear(x1, y1, x2, y2);
   Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_PAD);
   init();
 }
コード例 #3
0
 /**
  * Constructs a new Pattern given an image. Drawing with the resulting pattern will cause the
  * image to be tiled over the resulting area.
  *
  * <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 image the image that the pattern will draw
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the
  *           image is null
  *       <li>ERROR_INVALID_ARGUMENT - if the image 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()
  */
 public Pattern(Device device, Image image) {
   super(device);
   if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   this.device.checkCairo();
   image.createSurface();
   handle = Cairo.cairo_pattern_create_for_surface(image.surface);
   if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT);
   surface = image.surface;
   init();
 }
コード例 #4
0
 /**
  * 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();
 }
コード例 #5
0
 /**
  * Indicates what happens if the gradient starts or ends inside the bounds of the object(s) being
  * painted by the gradient.
  *
  * <p>Possible values are: 'pad', which says to use the terminal colors of the gradient to fill
  * the remainder of the target region, 'reflect', which says to reflect the gradient pattern
  * start-to-end, end-to-start, start-to-end, etc. continuously until the target rectangle is
  * filled, and repeat, which says to repeat the gradient pattern start-to-end, start-to-end,
  * start-to-end, etc. continuously until the target region is filled. If the attribute is not
  * specified, the effect is as if a value of 'pad' were specified.
  *
  * @see #PAD
  * @see #REFLECT
  * @see #REPEAT
  */
 public void setSpreadMethod(int method) {
   if (method != PAD && method != REFLECT && method != REPEAT) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   Cairo.cairo_pattern_set_extend(handle, method);
 }
コード例 #6
0
 void destroy() {
   Cairo.cairo_pattern_destroy(handle);
   handle = surface = 0;
 }