Search in sources :

Example 11 with Device

use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.

the class CurvesSWTTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Font font = new Font(device, getPlatformFont(), 16, SWT.ITALIC);
    gc.setFont(font);
    gc.setLineWidth(2);
    Transform transform;
    // ----- letter s -----
    sXPos = 4 * width / 16;
    sYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(sXPos, sYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);
    Path path = new Path(device);
    path.cubicTo(-200 + sDiffX1, 50 + sDiffY1, 200 + sDiffX2, 100 + sDiffY2, 0, 150);
    gc.drawPath(path);
    path.dispose();
    // draw the spline points
    gc.setTransform(null);
    gc.drawRectangle(sRect1.x + (int) sXPos, sRect1.y + (int) sYPos, sRect1.width, sRect1.height);
    gc.drawRectangle(sRect2.x + (int) sXPos, sRect2.y + (int) sYPos, sRect2.width, sRect2.height);
    // ----- letter w -----
    wXPos = 6 * width / 16;
    wYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(wXPos, wYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 110, -50, true);
    path = new Path(device);
    path.quadTo(100 + wDiffX1, 300 + wDiffY1, 100, 0);
    path.quadTo(100 + wDiffX2, 300 + wDiffY2, 200, 0);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.drawRectangle(wRect1.x + (int) wXPos, wRect1.y + (int) wYPos, wRect1.width, wRect1.height);
    gc.drawRectangle(wRect2.x + (int) wXPos, wRect2.y + (int) wYPos, wRect2.width, wRect2.height);
    // ----- top of letter t -----
    topTXPos = 11 * width / 16;
    topTYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(topTXPos, topTYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_YELLOW));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -50, true);
    path = new Path(device);
    path.cubicTo(33 + tTopDiffX1, -20 + tTopDiffY1, 66 + tTopDiffX2, 20 + tTopDiffY2, 100, 0);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.drawRectangle(tTopRect1.x + (int) topTXPos, tTopRect1.y + (int) topTYPos, tTopRect1.width, tTopRect1.height);
    gc.drawRectangle(tTopRect2.x + (int) topTXPos, tTopRect2.y + (int) topTYPos, tTopRect2.width, tTopRect2.height);
    // ----- vertical bar of letter t -----
    botTXPos = 12 * width / 16;
    botTYPos = (height - 150) / 2;
    transform = new Transform(device);
    transform.translate(botTXPos, botTYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);
    path = new Path(device);
    path.cubicTo(-33 + tBotDiffX1, 50 + tBotDiffY1, 33 + tBotDiffX2, 100 + tBotDiffY2, 0, 150);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.drawRectangle(tBottomRect1.x + (int) botTXPos, tBottomRect1.y + (int) botTYPos, tBottomRect1.width, tBottomRect1.height);
    gc.drawRectangle(tBottomRect2.x + (int) botTXPos, tBottomRect2.y + (int) botTYPos, tBottomRect2.width, tBottomRect2.height);
    font.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform) Font(org.eclipse.swt.graphics.Font)

Example 12 with Device

use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.

the class CustomAlphaTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Pattern pattern = null;
    if (background.getBgColor1() != null) {
        gc.setBackground(background.getBgColor1());
    } else if (background.getBgImage() != null) {
        pattern = new Pattern(device, background.getBgImage());
        gc.setBackgroundPattern(pattern);
    }
    gc.setAntialias(SWT.ON);
    gc.setAlpha(alphaSpinner.getSelection());
    // rotate on center
    Transform transform = new Transform(device);
    transform.translate(width / 2, height / 2);
    transform.rotate(-angle);
    transform.translate(-width / 2, -height / 2);
    gc.setTransform(transform);
    transform.dispose();
    // choose the smallest between height and width
    int diameter = (height < width) ? height : width;
    Path path = new Path(device);
    path.addArc((width - diameter / 5) / 2, (height - diameter / 5) / 2, diameter / 5, diameter / 5, 0, 360);
    path.addArc(5 * (width - diameter / 8) / 12, 4 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0, 360);
    path.addArc(7 * (width - diameter / 8) / 12, 8 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0, 360);
    path.addArc(6 * (width - diameter / 12) / 12, 3 * (height - diameter / 12) / 12, diameter / 12, diameter / 12, 0, 360);
    path.addArc(6 * (width - diameter / 12) / 12, 9 * (height - diameter / 12) / 12, diameter / 12, diameter / 12, 0, 360);
    path.addArc(11.5f * (width - diameter / 18) / 20, 5 * (height - diameter / 18) / 18, diameter / 18, diameter / 18, 0, 360);
    path.addArc(8.5f * (width - diameter / 18) / 20, 13 * (height - diameter / 18) / 18, diameter / 18, diameter / 18, 0, 360);
    path.addArc(62f * (width - diameter / 25) / 100, 32 * (height - diameter / 25) / 100, diameter / 25, diameter / 25, 0, 360);
    path.addArc(39f * (width - diameter / 25) / 100, 67 * (height - diameter / 25) / 100, diameter / 25, diameter / 25, 0, 360);
    gc.fillPath(path);
    path.dispose();
    if (pattern != null)
        pattern.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point)

Example 13 with Device

use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.

the class FontBounceTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Font font = new Font(device, getPlatformFontFace(fontFace), fontSize, fontStyle);
    gc.setFont(font);
    Point size = gc.stringExtent(text);
    textWidth = size.x;
    textHeight = size.y;
    Path path = new Path(device);
    path.addString(text, x, y, font);
    gc.setForeground(device.getSystemColor(foreGrdColor));
    gc.setBackground(device.getSystemColor(fillColor));
    gc.fillPath(path);
    gc.drawPath(path);
    font.dispose();
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 14 with Device

use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.

the class GraphicsExample method createCanvas.

void createCanvas(Composite parent) {
    int style = SWT.NO_BACKGROUND;
    if (dbItem.getSelection())
        style |= SWT.DOUBLE_BUFFERED;
    canvas = new Canvas(parent, style);
    canvas.addListener(SWT.Paint, event -> {
        GC gc = event.gc;
        Rectangle rect = canvas.getClientArea();
        Device device = gc.getDevice();
        Pattern pattern = null;
        if (background.getBgColor1() != null) {
            if (background.getBgColor2() != null) {
                // gradient
                pattern = new Pattern(device, 0, 0, rect.width, rect.height, background.getBgColor1(), background.getBgColor2());
                gc.setBackgroundPattern(pattern);
            } else {
                // solid color
                gc.setBackground(background.getBgColor1());
            }
        } else if (background.getBgImage() != null) {
            // image
            pattern = new Pattern(device, background.getBgImage());
            gc.setBackgroundPattern(pattern);
        }
        gc.fillRectangle(rect);
        GraphicsTab tab = getTab();
        if (tab != null)
            tab.paint(gc, rect.width, rect.height);
        if (pattern != null)
            pattern.dispose();
    });
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Canvas(org.eclipse.swt.widgets.Canvas) Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 15 with Device

use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.

the class Bug421127_Clipping_is_wrong method paintCanvas.

private static void paintCanvas(PaintEvent event, Canvas canvas) {
    GC gc = gc(event);
    Rectangle bounds = canvas.getBounds();
    Rectangle clipping = gc.getClipping();
    Device device = gc.getDevice();
    int color = SWT.COLOR_GREEN;
    String text = "CLIPPING AND BOUNDS INTERSECT";
    if (!clipping.intersects(bounds)) {
        color = SWT.COLOR_RED;
        text = "CLIPPING AND BOUNDS DON'T INTERSECT";
    }
    gc.drawText(text, 0, 0);
    gc.setAlpha(25);
    gc.setBackground(device.getSystemColor(color));
    gc.fillRectangle(bounds);
    gc.setAlpha(255);
}
Also used : Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC)

Aggregations

Device (org.eclipse.swt.graphics.Device)33 Path (org.eclipse.swt.graphics.Path)13 Point (org.eclipse.swt.graphics.Point)13 Font (org.eclipse.swt.graphics.Font)12 Pattern (org.eclipse.swt.graphics.Pattern)12 Transform (org.eclipse.swt.graphics.Transform)11 Rectangle (org.eclipse.swt.graphics.Rectangle)8 Color (org.eclipse.swt.graphics.Color)6 Image (org.eclipse.swt.graphics.Image)4 ColorManager (de.jaret.util.swt.ColorManager)3 RGB (org.eclipse.swt.graphics.RGB)3 GC (org.eclipse.swt.graphics.GC)2 FontManager (de.jaret.util.swt.FontManager)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 IMatchViewPart (net.heartsome.cat.ts.ui.view.IMatchViewPart)1 StyledText (org.eclipse.swt.custom.StyledText)1 Region (org.eclipse.swt.graphics.Region)1 Canvas (org.eclipse.swt.widgets.Canvas)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1