Search in sources :

Example 21 with Region

use of org.eclipse.swt.graphics.Region in project nebula.widgets.nattable by eclipse.

the class PercentageBarDecorator method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    Pattern originalBackgroundPattern = gc.getBackgroundPattern();
    double factor = Math.min(1.0, ((Number) cell.getDataValue()).doubleValue());
    factor = Math.max(0.0, factor);
    Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int) (rectangle.width * factor), rectangle.height);
    Color color1 = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR);
    Color color2 = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(PERCENTAGE_BAR_COMPLETE_REGION_END_COLOR);
    if (color1 == null) {
        color1 = DEFAULT_COMPLETE_REGION_START_COLOR;
    }
    if (color2 == null) {
        color2 = DEFAULT_COMPLETE_REGION_END_COLOR;
    }
    Pattern pattern = new Pattern(Display.getCurrent(), rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height, color1, color2);
    gc.setBackgroundPattern(pattern);
    gc.fillRectangle(bar);
    gc.setBackgroundPattern(originalBackgroundPattern);
    pattern.dispose();
    Color incompleteRegionColor = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(PERCENTAGE_BAR_INCOMPLETE_REGION_COLOR);
    if (incompleteRegionColor != null) {
        Region incompleteRegion = new Region();
        incompleteRegion.add(rectangle);
        incompleteRegion.subtract(bar);
        Color originalBackgroundColor = gc.getBackground();
        gc.setBackground(incompleteRegionColor);
        gc.fillRectangle(incompleteRegion.getBounds());
        gc.setBackground(originalBackgroundColor);
        incompleteRegion.dispose();
    }
    super.paintCell(cell, gc, rectangle, configRegistry);
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region)

Example 22 with Region

use of org.eclipse.swt.graphics.Region in project BiglyBT by BiglySoftware.

the class PieUtils method drawPie.

public static void drawPie(GC gc, Image image, int x, int y, int width, int height, int percent, boolean draw_border) {
    Rectangle image_size = image.getBounds();
    int width_pad = (width - image_size.width) / 2;
    int height_pad = (height - image_size.height) / 2;
    int angle = (percent * 360) / 100;
    if (angle < 4) {
        // workaround fillArc rendering bug
        angle = 0;
    }
    Region old_clipping = new Region();
    gc.getClipping(old_clipping);
    Path path_done = new Path(gc.getDevice());
    path_done.addArc(x, y, width, height, 90, -angle);
    path_done.lineTo(x + width / 2, y + height / 2);
    path_done.close();
    gc.setClipping(path_done);
    gc.drawImage(image, x + width_pad, y + height_pad + 1);
    Path path_undone = new Path(gc.getDevice());
    path_undone.addArc(x, y, width, height, 90 - angle, angle - 360);
    path_undone.lineTo(x + width / 2, y + height / 2);
    path_undone.close();
    gc.setClipping(path_undone);
    gc.setAlpha(75);
    gc.drawImage(image, x + width_pad, y + height_pad + 1);
    gc.setAlpha(255);
    gc.setClipping(old_clipping);
    if (draw_border) {
        gc.setForeground(Colors.blue);
        if (percent == 100) {
            gc.drawOval(x, y, width - 1, height - 1);
        } else {
            if (angle > 0) {
                gc.drawPath(path_done);
            }
        }
    }
    path_done.dispose();
    path_undone.dispose();
    old_clipping.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region)

Example 23 with Region

use of org.eclipse.swt.graphics.Region in project netxms by netxms.

the class Sleak method paintCanvas.

void paintCanvas(final Event event) {
    canvas.setCursor(null);
    final int index = list.getSelectionIndex();
    if (index == -1) {
        return;
    }
    final GC gc = event.gc;
    final Object object = objects[index];
    if (object instanceof Color) {
        if (((Color) object).isDisposed()) {
            return;
        }
        gc.setBackground((Color) object);
        gc.fillRectangle(canvas.getClientArea());
        return;
    }
    if (object instanceof Cursor) {
        if (((Cursor) object).isDisposed()) {
            return;
        }
        canvas.setCursor((Cursor) object);
        return;
    }
    if (object instanceof Font) {
        if (((Font) object).isDisposed()) {
            return;
        }
        gc.setFont((Font) object);
        final FontData[] array = gc.getFont().getFontData();
        // $NON-NLS-1$
        String string = "";
        final String lf = text.getLineDelimiter();
        for (final FontData data : array) {
            // $NON-NLS-1$
            String style = "NORMAL";
            final int bits = data.getStyle();
            if (bits != 0) {
                if ((bits & SWT.BOLD) != 0) {
                    // $NON-NLS-1$
                    style = "BOLD ";
                }
                if ((bits & SWT.ITALIC) != 0) {
                    // $NON-NLS-1$
                    style += "ITALIC";
                }
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            string += data.getName() + " " + data.getHeight() + " " + style + lf;
        }
        gc.drawString(string, 0, 0);
        return;
    }
    // }
    if (object instanceof Image) {
        if (((Image) object).isDisposed()) {
            return;
        }
        gc.drawImage((Image) object, 0, 0);
        return;
    }
    if (object instanceof Region) {
        if (((Region) object).isDisposed()) {
            return;
        }
        final String string = ((Region) object).getBounds().toString();
        gc.drawString(string, 0, 0);
        return;
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) Region(org.eclipse.swt.graphics.Region) GC(org.eclipse.swt.graphics.GC) Cursor(org.eclipse.swt.graphics.Cursor) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 24 with Region

use of org.eclipse.swt.graphics.Region in project pentaho-kettle by pentaho.

the class Sleak method refreshLabel.

void refreshLabel() {
    int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
    int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
    for (int i = 0; i < objects.length; i++) {
        Object object = objects[i];
        if (object instanceof Color) {
            colors++;
        }
        if (object instanceof Cursor) {
            cursors++;
        }
        if (object instanceof Font) {
            fonts++;
        }
        if (object instanceof GC) {
            gcs++;
        }
        if (object instanceof Image) {
            images++;
        }
        if (object instanceof Path) {
            paths++;
        }
        if (object instanceof Pattern) {
            patterns++;
        }
        if (object instanceof Region) {
            regions++;
        }
        if (object instanceof TextLayout) {
            textLayouts++;
        }
        if (object instanceof Transform) {
            transforms++;
        }
    }
    String string = "";
    if (colors != 0) {
        string += colors + " Color(s)\n";
    }
    if (cursors != 0) {
        string += cursors + " Cursor(s)\n";
    }
    if (fonts != 0) {
        string += fonts + " Font(s)\n";
    }
    if (gcs != 0) {
        string += gcs + " GC(s)\n";
    }
    if (images != 0) {
        string += images + " Image(s)\n";
    }
    if (paths != 0) {
        string += paths + " Paths(s)\n";
    }
    if (patterns != 0) {
        string += patterns + " Pattern(s)\n";
    }
    if (regions != 0) {
        string += regions + " Region(s)\n";
    }
    if (textLayouts != 0) {
        string += textLayouts + " TextLayout(s)\n";
    }
    if (transforms != 0) {
        string += transforms + " Transform(s)\n";
    }
    if (string.length() != 0) {
        string = string.substring(0, string.length() - 1);
    }
    label.setText(string);
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) Cursor(org.eclipse.swt.graphics.Cursor) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) TextLayout(org.eclipse.swt.graphics.TextLayout) Region(org.eclipse.swt.graphics.Region) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform)

Example 25 with Region

use of org.eclipse.swt.graphics.Region in project archi by archimatetool.

the class SWTGraphics method clipPath.

/**
 * Simple implementation of clipping a Path within the context of current
 * clipping rectangle for now (not region) <li>Note that this method wipes
 * out the clipping rectangle area, hence if clients need to reset it call
 * {@link #restoreState()}
 *
 * @see org.eclipse.draw2d.Graphics#clipPath(org.eclipse.swt.graphics.Path)
 */
@Override
public void clipPath(Path path) {
    initTransform(false);
    if (((appliedState.graphicHints ^ currentState.graphicHints) & FILL_RULE_MASK) != 0) {
        // If there is a pending change to the fill rule, apply it first.
        gc.setFillRule(((currentState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER);
        // As long as the FILL_RULE is stored in a single bit, just toggling
        // it works.
        appliedState.graphicHints ^= FILL_RULE_MASK;
    }
    Rectangle clipping = currentState.relativeClip != null ? getClip(new Rectangle()) : new Rectangle();
    if (!clipping.isEmpty()) {
        Path flatPath = new Path(path.getDevice(), path, 0.01f);
        PathData pathData = flatPath.getPathData();
        flatPath.dispose();
        Region region = new Region(path.getDevice());
        loadPath(region, pathData.points, pathData.types);
        region.intersect(new org.eclipse.swt.graphics.Rectangle(clipping.x, clipping.y, clipping.width, clipping.height));
        gc.setClipping(region);
        appliedState.relativeClip = currentState.relativeClip = null;
        region.dispose();
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Rectangle(org.eclipse.draw2d.geometry.Rectangle) PathData(org.eclipse.swt.graphics.PathData) Region(org.eclipse.swt.graphics.Region)

Aggregations

Region (org.eclipse.swt.graphics.Region)42 Rectangle (org.eclipse.swt.graphics.Rectangle)29 Test (org.junit.Test)21 SWTException (org.eclipse.swt.SWTException)13 Point (org.eclipse.swt.graphics.Point)12 Color (org.eclipse.swt.graphics.Color)8 GC (org.eclipse.swt.graphics.GC)6 Font (org.eclipse.swt.graphics.Font)5 Image (org.eclipse.swt.graphics.Image)5 Cursor (org.eclipse.swt.graphics.Cursor)4 Path (org.eclipse.swt.graphics.Path)4 Display (org.eclipse.swt.widgets.Display)4 Shell (org.eclipse.swt.widgets.Shell)4 FontData (org.eclipse.swt.graphics.FontData)3 Pattern (org.eclipse.swt.graphics.Pattern)3 TextLayout (org.eclipse.swt.graphics.TextLayout)2 Transform (org.eclipse.swt.graphics.Transform)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Tree (org.eclipse.swt.widgets.Tree)2