public void paint(GC gc) { int i = 2 * x + 1; if (values == null || i >= values.length) { return; } int value = getNextValue() * (90 + RANDOM.nextInt(20)) / 100 + RANDOM.nextInt(4) - 2; if (value > 100) { value = 100; } else if (value < -100) { value = -100; } int fx = y + value * channelHeight / 100; values[i] = fx; gc.setForeground(white); gc.setLineWidth(1); gc.drawPolyline(values); gc.setForeground(black); gc.setLineWidth(2); gc.drawRectangle(x, fx, 2, 2); if (++x >= width) { x = 0; } }
void resize() { Point size = comp.getSize(); Image oldBackgroundImage = backgroundImage; backgroundImage = new Image(comp.getDisplay(), size.x, size.y); GC gc = new GC(backgroundImage); comp.getParent().drawBackground(gc, 0, 0, size.x, size.y, 0, 0); Color background = comp.getBackground(); Color border = comp.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); RGB backgroundRGB = background.getRGB(); // TODO naive and hard coded, doesn't deal with high contrast, etc. Color gradientTop = new Color( comp.getDisplay(), backgroundRGB.red + 12, backgroundRGB.green + 10, backgroundRGB.blue + 10); int h = size.y; int curveStart = 0; int curve_width = 5; int[] curve = new int[] { 0, h, 1, h, 2, h - 1, 3, h - 2, 3, 2, 4, 1, 5, 0, }; int[] line1 = new int[curve.length + 4]; int index = 0; int x = curveStart; line1[index++] = x + 1; line1[index++] = h; for (int i = 0; i < curve.length / 2; i++) { line1[index++] = x + curve[2 * i]; line1[index++] = curve[2 * i + 1]; } line1[index++] = x + curve_width; line1[index++] = 0; int[] line2 = new int[line1.length]; index = 0; for (int i = 0; i < line1.length / 2; i++) { line2[index] = line1[index++] - 1; line2[index] = line1[index++]; } // custom gradient gc.setForeground(gradientTop); gc.setBackground(background); gc.drawLine(4, 0, size.x, 0); gc.drawLine(3, 1, size.x, 1); gc.fillGradientRectangle(2, 2, size.x - 2, size.y - 3, true); gc.setForeground(background); gc.drawLine(2, size.y - 1, size.x, size.y - 1); gradientTop.dispose(); gc.setForeground(border); gc.drawPolyline(line2); gc.dispose(); comp.setBackgroundImage(backgroundImage); if (oldBackgroundImage != null) oldBackgroundImage.dispose(); }
void paint(PaintEvent e) { GC gc = e.gc; Point size = comp.getSize(); if (curveColor == null) curveColor = e.display.getSystemColor(SWT.COLOR_BLACK); int h = size.y; int[] simpleCurve = new int[] {0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3, 0}; // draw border gc.setForeground(curveColor); gc.setAdvanced(true); if (gc.getAdvanced()) { gc.setAntialias(SWT.ON); } gc.drawPolyline(simpleCurve); Rectangle bounds = ((Control) e.widget).getBounds(); bounds.x = bounds.y = 0; Region r = new Region(); r.add(bounds); int[] simpleCurveClose = new int[simpleCurve.length + 4]; System.arraycopy(simpleCurve, 0, simpleCurveClose, 0, simpleCurve.length); int index = simpleCurve.length; simpleCurveClose[index++] = bounds.width; simpleCurveClose[index++] = 0; simpleCurveClose[index++] = bounds.width; simpleCurveClose[index++] = bounds.height; r.subtract(simpleCurveClose); Region clipping = new Region(); gc.getClipping(clipping); r.intersect(clipping); gc.setClipping(r); Image b = toolParent.getBackgroundImage(); if (b != null && !b.isDisposed()) gc.drawImage(b, 0, 0); r.dispose(); clipping.dispose(); // // gc.fillRectangle(bounds); // Rectangle mappedBounds = e.display.map(comp, comp.getParent(), // bounds); // ((Composite) toolParent).drawBackground(gc, bounds.x, bounds.y, // bounds.width, // bounds.height, mappedBounds.x, mappedBounds.y); }
@Override public void visitLine(Line line) { int length = line.xPoints.length; int[] points = new int[length * 2]; for (int i = 0, j = 0; i < length; i++, j += 2) { points[j] = scene.mapToScreenX(line.xPoints[i]); points[j + 1] = scene.mapToScreenY(line.yPoints[i]); } gc.drawPolyline(points); // SHOW BOUNDS // Bounds bounds = new Bounds(); // line.expandBounds(bounds); // gc.drawRectangle(scene.mapToScreenX(bounds.x1), // scene.mapToScreenY(bounds.y1), // scene.mapToScreenX(bounds.x2) - scene.mapToScreenX(bounds.x1), // scene.mapToScreenY(bounds.y2) - scene.mapToScreenY(bounds.y1)); }
void drawChevron(GC gc, int x, int y) { int[] polyline1, polyline2; if (expanded) { int px = x + 4 + 5; int py = y + 4 + 7; polyline1 = new int[] { px, py, px + 1, py, px + 1, py - 1, px + 2, py - 1, px + 2, py - 2, px + 3, py - 2, px + 3, py - 3, px + 3, py - 2, px + 4, py - 2, px + 4, py - 1, px + 5, py - 1, px + 5, py, px + 6, py }; py += 4; polyline2 = new int[] { px, py, px + 1, py, px + 1, py - 1, px + 2, py - 1, px + 2, py - 2, px + 3, py - 2, px + 3, py - 3, px + 3, py - 2, px + 4, py - 2, px + 4, py - 1, px + 5, py - 1, px + 5, py, px + 6, py }; } else { int px = x + 4 + 5; int py = y + 4 + 4; polyline1 = new int[] { px, py, px + 1, py, px + 1, py + 1, px + 2, py + 1, px + 2, py + 2, px + 3, py + 2, px + 3, py + 3, px + 3, py + 2, px + 4, py + 2, px + 4, py + 1, px + 5, py + 1, px + 5, py, px + 6, py }; py += 4; polyline2 = new int[] { px, py, px + 1, py, px + 1, py + 1, px + 2, py + 1, px + 2, py + 2, px + 3, py + 2, px + 3, py + 3, px + 3, py + 2, px + 4, py + 2, px + 4, py + 1, px + 5, py + 1, px + 5, py, px + 6, py }; } gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND)); gc.drawPolyline(polyline1); gc.drawPolyline(polyline2); }
protected void paintControl(PaintEvent e) { long start = System.currentTimeMillis(); for (int c = 0; c < chan.length; c++) { // if (chan[c].tailSize <= 0) { // chan[c].stack.popNegate(0); // continue; // } // Go calculate the line Object[] result = calculate(c); int[] l1 = (int[]) result[0]; int[] l2 = (int[]) result[1]; PositionPolyLine(l1); PositionPolyLine(l2); // System.out.print(System.currentTimeMillis() - start + "-"); // Draw it GC gc = e.gc; gc.setForeground(getForeground(c)); gc.setAdvanced(true); gc.setAntialias(SWT.ON); gc.setLineWidth(getLineWidth(c)); // Fade tail if (isFade(c)) { gc.setAlpha(0); double fade = 0; double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100)); for (int i = 0; i < l1.length - 4; ) { fade += (fadeOutStep / 2); setAlpha(gc, fade); gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]); i += 2; } for (int i = 0; i < l2.length - 4; ) { fade += (fadeOutStep / 2); setAlpha(gc, fade); gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]); i += 2; } } else { long time = System.nanoTime(); gc.drawPolyline(l1); gc.drawPolyline(l2); // System.out.println(System.nanoTime() - time + " nanoseconds"); } // Connects the head with the tail if (isConnect(c) && !isFade(c) && chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0 && l2.length > 0) { gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]); } } // System.out.println(System.currentTimeMillis() - start + " milliseconds for all channels"); }