Search in sources :

Example 16 with Device

use of org.eclipse.swt.graphics.Device in project translationstudio8 by heartsome.

the class CellRendererBase method getFont.

/**
     * Retrieve the font accrding to the cell style.
     * 
     * @param style cell style
     * @param printing true for printing
     * @param defaultFont a default font used if no font can be retrieved
     * @return font according to style or default font
     */
protected Font getFont(ICellStyle style, boolean printing, Font defaultFont) {
    Device device = printing ? _printer : Display.getCurrent();
    FontManager fm = FontManager.getFontManager(device);
    Font f = style.getFont() != null ? fm.getFont(style.getFont()) : defaultFont;
    return f;
}
Also used : Device(org.eclipse.swt.graphics.Device) FontManager(de.jaret.util.swt.FontManager) Font(org.eclipse.swt.graphics.Font)

Example 17 with Device

use of org.eclipse.swt.graphics.Device in project translationstudio8 by heartsome.

the class CellRendererBase method getForegroundColor.

/**
     * Get the foreground color according to the cell style.
     * 
     * @param style cell style
     * @param printing true for printing
     * @return the foreground color
     */
protected Color getForegroundColor(ICellStyle style, boolean printing) {
    Device device = printing ? _printer : Display.getCurrent();
    ColorManager cm = ColorManager.getColorManager(device);
    Color bg = cm.getColor(style.getForegroundColor() != null ? style.getForegroundColor() : BLACKRGB);
    return bg;
}
Also used : Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) ColorManager(de.jaret.util.swt.ColorManager)

Example 18 with Device

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

the class BallTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    if (bc[0] == null) {
        bc[0] = new BallCollection(0, 0, 5, 5, 20, 20, new Color[] { device.getSystemColor(SWT.COLOR_GREEN) });
        bc[1] = new BallCollection(50, 300, 10, -5, 50, 10, new Color[] { device.getSystemColor(SWT.COLOR_BLUE) });
        bc[2] = new BallCollection(250, 100, -5, 8, 25, 12, new Color[] { device.getSystemColor(SWT.COLOR_RED) });
        bc[3] = new BallCollection(150, 400, 5, 8, 35, 14, new Color[] { device.getSystemColor(SWT.COLOR_BLACK) });
        bc[4] = new BallCollection(100, 250, -5, -18, 100, 5, new Color[] { device.getSystemColor(SWT.COLOR_MAGENTA) });
    }
    for (BallCollection ballCollection : bc) {
        for (int i = 0; i < ballCollection.prevx.size(); i++) {
            Transform transform = new Transform(device);
            transform.translate(ballCollection.prevx.get(ballCollection.prevx.size() - (i + 1)).floatValue(), ballCollection.prevy.get(ballCollection.prevy.size() - (i + 1)).floatValue());
            gc.setTransform(transform);
            transform.dispose();
            Path path = new Path(device);
            path.addArc(0, 0, ballCollection.ball_size, ballCollection.ball_size, 0, 360);
            gc.setAlpha(255 - i * (255 / ballCollection.capacity));
            gc.setBackground(ballCollection.colors[0]);
            gc.fillPath(path);
            gc.drawPath(path);
            path.dispose();
        }
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) Transform(org.eclipse.swt.graphics.Transform)

Example 19 with Device

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

the class CountDownTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // diameter of the circle in pixels
    int diameter = ((width < height) ? width - 25 : height - 25);
    if (!getAnimation() && nextNumber == 0) {
        Font font = new Font(device, getPlatformFontFace(1), diameter / 2, SWT.NONE);
        gc.setFont(font);
        // display "SWT"
        gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
        gc.setTextAntialias(SWT.ON);
        // determine the dimensions of the word
        String text = GraphicsExample.getResourceString("SWT");
        Point point = gc.stringExtent(text);
        int textWidth = point.x;
        int textHeight = point.y;
        gc.drawString(text, (width - textWidth) / 2, (height - textHeight) / 2, true);
        font.dispose();
    } else {
        Font font = new Font(device, getPlatformFontFace(0), 6 * diameter / 10, SWT.NONE);
        gc.setFont(font);
        // set attributes from controls
        gc.setLineWidth(lineWidthSpinner.getSelection());
        // round line ends
        gc.setLineCap(lineCap);
        // smooth jagged edges
        gc.setAntialias(antialias);
        // smooth jagged edges
        gc.setTextAntialias(antialias);
        // draw the circles
        Path path = new Path(device);
        path.addArc((width - diameter) / 2, (height - diameter) / 2, diameter, diameter, 0, 360);
        path.addArc((width - diameter + 50) / 2, (height - diameter + 50) / 2, diameter - 50, diameter - 50, 0, 360);
        gc.drawPath(path);
        gc.setBackground(device.getSystemColor(SWT.COLOR_RED));
        gc.fillPath(path);
        path.dispose();
        Point point = gc.stringExtent(Integer.valueOf(nextNumber).toString());
        int textWidth = point.x;
        int textHeight = point.y;
        // draw the number
        gc.drawString(Integer.valueOf(nextNumber).toString(), (width - textWidth) / 2, (height - textHeight) / 2, true);
        // draw the rotating arm
        Transform transform = new Transform(device);
        transform.translate(width / 2, height / 2);
        transform.rotate(angle);
        gc.setTransform(transform);
        gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
        gc.drawLine(0, 0, diameter / 2, 0);
        transform.dispose();
        font.dispose();
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Point(org.eclipse.swt.graphics.Point) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 20 with Device

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

the class CurvesTab 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(5);
    Transform transform;
    // ----- cubic curve -----
    cubXPos = width / 5;
    cubYPos = height / 3;
    transform = new Transform(device);
    transform.translate(cubXPos, cubYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -70, true);
    Path path = new Path(device);
    path.cubicTo(133 + cubDiffX1, -60 + cubDiffY1, 266 + cubDiffX2, 60 + cubDiffY2, 400 + cubEndDiffX, 0 + cubEndDiffY);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
    gc.drawRectangle(cubHndl1.x + (int) cubXPos, cubHndl1.y + (int) cubYPos, cubHndl1.width, cubHndl1.height);
    gc.drawRectangle(cubHndl2.x + (int) cubXPos, cubHndl2.y + (int) cubYPos, cubHndl2.width, cubHndl2.height);
    gc.drawRectangle(cubEndHndl.x + (int) cubXPos, cubEndHndl.y + (int) cubYPos, cubEndHndl.width, cubEndHndl.height);
    // ----- quadratic curve -----
    quadXPos = width / 5;
    quadYPos = 2 * height / 3;
    transform = new Transform(device);
    transform.translate(quadXPos, quadYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_GREEN));
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);
    path = new Path(device);
    path.quadTo(200 + quadDiffX, 150 + quadDiffY, 400 + quadEndDiffX, 0 + quadEndDiffY);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.drawRectangle(quadHndl.x + (int) quadXPos, quadHndl.y + (int) quadYPos, quadHndl.width, quadHndl.height);
    gc.drawRectangle(quadEndHndl.x + (int) quadXPos, quadEndHndl.y + (int) quadYPos, quadEndHndl.width, quadEndHndl.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)

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