Search in sources :

Example 11 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class TimeGraphControl method drawMarker.

/**
 * Draw a single marker
 *
 * @param marker
 *            The marker event
 * @param bounds
 *            The bounds of the control
 * @param timeProvider
 *            The time provider
 * @param nameSpace
 *            The width reserved for the name
 * @param gc
 *            Reference to the SWT GC object
 * @since 2.0
 */
protected void drawMarker(IMarkerEvent marker, Rectangle bounds, ITimeDataProvider timeProvider, int nameSpace, GC gc) {
    Rectangle rect = Utils.clone(bounds);
    if (marker.getEntry() != null) {
        int index = fItemData.findItemIndex(marker.getEntry());
        if (index == -1) {
            return;
        }
        rect = getStatesRect(bounds, index, nameSpace);
        if (rect.y < 0 || rect.y > bounds.height) {
            return;
        }
    }
    int x0 = getXForTime(marker.getTime());
    int x1 = getXForTime(marker.getTime() + marker.getDuration());
    if (x0 > bounds.width || x1 < nameSpace) {
        return;
    }
    rect.x = Math.max(nameSpace, Math.min(bounds.width, x0));
    rect.width = Math.max(1, Math.min(bounds.width, x1) - rect.x);
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(marker);
    if (elementStyle == null) {
        return;
    }
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    int colorInt = (rgba != null) ? rgba.toInt() : RGBAUtil.fromRGBA(marker.getColor());
    Color color = TimeGraphRender.getColor(colorInt);
    Object symbolType = styleManager.getStyle(elementStyle, StyleProperties.SYMBOL_TYPE);
    if (symbolType != null && symbolType != SymbolType.NONE) {
        gc.setAlpha(colorInt & 0xff);
        Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
        heightFactor = (heightFactor != null) ? Math.max(0.0f, Math.min(1.0f, heightFactor)) : 1.0f;
        int symbolSize = (int) Math.ceil(rect.height * heightFactor / 2);
        Object verticalAlign = styleManager.getStyle(elementStyle, StyleProperties.VERTICAL_ALIGN);
        int y = rect.y + rect.height / 2;
        if (VerticalAlign.BOTTOM.equals(verticalAlign)) {
            y += Math.max(0, rect.height / 2 - symbolSize);
        } else if (VerticalAlign.TOP.equals(verticalAlign)) {
            y -= Math.max(0, rect.height / 2 - symbolSize);
        }
        switch(String.valueOf(symbolType)) {
            case SymbolType.CROSS:
                SymbolHelper.drawCross(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.PLUS:
                SymbolHelper.drawPlus(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.SQUARE:
                SymbolHelper.drawSquare(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.TRIANGLE:
                SymbolHelper.drawTriangle(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.INVERTED_TRIANGLE:
                SymbolHelper.drawInvertedTriangle(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.CIRCLE:
                SymbolHelper.drawCircle(gc, color, symbolSize, rect.x, y);
                break;
            default:
                SymbolHelper.drawDiamond(gc, color, symbolSize, rect.x, y);
        }
        gc.setAlpha(OPAQUE);
        if (marker.getDuration() == 0) {
            return;
        }
    }
    oldDrawMarker(marker, gc, rect, colorInt);
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Rectangle(org.eclipse.swt.graphics.Rectangle) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)

Example 12 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class TimeGraphControl method drawLineGraphEntry.

private void drawLineGraphEntry(long time0, @NonNull Rectangle rect, double pixelsPerNanoSec, Iterator<ITimeEvent> iterator) {
    // clamp 0 - max positive
    long max = Long.MIN_VALUE;
    long min = 0;
    List<@NonNull List<@NonNull LongPoint>> seriesModel = new ArrayList<>();
    TimeLineEvent lastValid = null;
    while (iterator.hasNext()) {
        ITimeEvent event = iterator.next();
        if (!(event instanceof TimeLineEvent)) {
            continue;
        }
        int x = SaturatedArithmetic.add(rect.x, (int) ((event.getTime() - time0) * pixelsPerNanoSec));
        if (x >= rect.x + rect.width) {
            // event is out of bounds
            continue;
        }
        TimeLineEvent timeEvent = (TimeLineEvent) event;
        List<Long> values = timeEvent.getValues();
        for (int i = 0; i < values.size(); i++) {
            if (seriesModel.size() <= i) {
                seriesModel.add(new ArrayList<>());
            }
            Long val = values.get(i);
            if (val != null) {
                // get max and min, this is a relative scale.
                max = Math.max(Math.abs(val), max);
                min = 0;
                lastValid = timeEvent;
                seriesModel.get(i).add(new LongPoint(x, val));
            }
        }
    }
    if (lastValid == null) {
        return;
    }
    double scale = (max - min) == 0 ? 1.0 : (double) rect.height / (max - min);
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(lastValid);
    if (elementStyle == null) {
        return;
    }
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    fLines.add(new DeferredLine(rect, min, seriesModel, rgba == null ? BLACK : rgba, scale));
}
Also used : ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ArrayList(java.util.ArrayList) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) DeferredLine(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) TimeLineEvent(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.model.TimeLineEvent) NonNull(org.eclipse.jdt.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager)

Example 13 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class TimeGraphControl method drawArrow.

/**
 * Draw an arrow
 *
 * @param colors
 *            Color scheme
 * @param event
 *            Time event for which we're drawing the arrow
 * @param rect
 *            The arrow rectangle
 * @param gc
 *            Graphics context
 * @return true if the arrow was drawn
 */
protected boolean drawArrow(TimeGraphColorScheme colors, @NonNull ITimeEvent event, Rectangle rect, GC gc) {
    if (rect == null || ((rect.height == 0) && (rect.width == 0))) {
        return false;
    }
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(event);
    if (elementStyle == null) {
        return false;
    }
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    rgba = (rgba != null) ? rgba : BLACK;
    int colorInt = rgba.toInt();
    Color color = TimeGraphRender.getColor(colorInt);
    int alpha = rgba.getAlpha();
    int prevAlpha = gc.getAlpha();
    gc.setAlpha(alpha);
    gc.setForeground(color);
    gc.setBackground(color);
    int old = gc.getLineWidth();
    Float widthFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.WIDTH);
    if (widthFactor == null) {
        Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
        widthFactor = (heightFactor != null) ? heightFactor * 10.0f : 1.0f;
    }
    widthFactor = Math.max(1.0f, Math.min(10.0f, widthFactor));
    gc.setLineWidth(widthFactor.intValue());
    /* Draw the arrow */
    Point newEndpoint = drawArrowHead(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, widthFactor, gc);
    gc.drawLine(rect.x, rect.y, newEndpoint.x, newEndpoint.y);
    gc.setLineWidth(old);
    gc.setAlpha(prevAlpha);
    if (!Boolean.TRUE.equals(styleManager.getStyle(elementStyle, ITimeEventStyleStrings.annotated()))) {
        fPostDrawArrows.add(new PostDrawEvent(event, rect));
    }
    return true;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) PostDrawEvent(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.PostDrawEvent) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)

Example 14 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class TimeGraphControl method drawState.

/**
 * Draw the state (color fill)
 *
 * @param colors
 *            Color scheme
 * @param event
 *            Time event for which we're drawing the state
 * @param rect
 *            The state rectangle
 * @param gc
 *            Graphics context
 * @param selected
 *            Is this time event currently selected (so it appears
 *            highlighted)
 * @param timeSelected
 *            Is the timestamp currently selected
 * @return true if the state was drawn
 */
protected boolean drawState(TimeGraphColorScheme colors, @NonNull ITimeEvent event, Rectangle rect, GC gc, boolean selected, boolean timeSelected) {
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(event);
    if (elementStyle == null) {
        return false;
    }
    boolean transparent = elementStyle.getParentKey() == null && elementStyle.getStyleValues().isEmpty();
    boolean visible = rect.width <= 0 ? false : true;
    rect.width = Math.max(1, rect.width);
    Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
    heightFactor = (heightFactor != null) ? Math.max(0.0f, Math.min(1.0f, heightFactor)) : DEFAULT_STATE_WIDTH;
    int height = 0;
    if (heightFactor != 0.0f && rect.height != 0) {
        height = Math.max(1, (int) (rect.height * heightFactor));
    }
    Rectangle drawRect = new Rectangle(rect.x, rect.y + ((rect.height - height) / 2), rect.width, height);
    Color black = TimeGraphRender.getColor(BLACK.toInt());
    gc.setForeground(black);
    List<DeferredItem> states = fCurrentDeferredEntry.getItems();
    if (transparent) {
        if (visible) {
            // Avoid overlapping transparent states
            int x = Math.max(fLastTransparentX, drawRect.x);
            drawRect.width = drawRect.x + drawRect.width - x;
            if (drawRect.width > 0) {
                // Draw transparent background
                RGBAColor bgColor = fTransparentGrayColor;
                DeferredItem deferredItem = new DeferredTransparentState(drawRect, bgColor);
                if (states.isEmpty() || !states.get(states.size() - 1).getBounds().intersects(drawRect)) {
                    states.add(deferredItem);
                    deferredItem.add(new PostDrawEvent(event, drawRect));
                }
                fLastTransparentX = Math.max(fLastTransparentX, drawRect.x + drawRect.width);
            } else {
                // clamp it to 0, just in case
                drawRect.width = 0;
            }
            if (drawRect.width <= 2) {
                // Draw point over state
                addPoint(fPoints, rect.x, rect.y - 2);
                if (drawRect.width == 2) {
                    addPoint(fPoints, rect.x + 1, rect.y - 2);
                }
            }
        } else {
            addPoint(fPoints, rect.x, rect.y - 2);
        }
        return false;
    }
    int arc = Math.min(drawRect.height + 1, drawRect.width) / 2;
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.BACKGROUND_COLOR);
    @NonNull RGBAColor bgColor = (rgba != null) ? rgba : BLACK;
    boolean reallySelected = timeSelected && selected;
    // fill all rect area
    boolean draw = visible || fBlendSubPixelEvents;
    DeferredItem last = null;
    if (draw) {
        if (!states.isEmpty()) {
            DeferredItem state = states.get(states.size() - 1);
            while ((state instanceof DeferredTransparentState) && (state.getBounds().x == drawRect.x)) {
                states.remove(states.size() - 1);
                state = states.isEmpty() ? null : states.get(states.size() - 1);
            }
        }
        RGBAColor borderColor = BLACK;
        int lineWidth = DeferredItem.NO_BORDER;
        Object borderStyle = styleManager.getStyle(elementStyle, StyleProperties.BORDER_STYLE);
        boolean hasBorders = borderStyle != null && !BorderStyle.NONE.equals(borderStyle);
        if (hasBorders) {
            Object borderWidth = styleManager.getStyle(elementStyle, StyleProperties.BORDER_WIDTH);
            lineWidth = 1;
            if (borderWidth instanceof Integer) {
                lineWidth = (int) borderWidth;
            }
            borderColor = styleManager.getColorStyle(elementStyle, StyleProperties.BORDER_COLOR);
            if (borderColor == null) {
                borderColor = BLACK;
            }
        }
        /*
             * This has been tested in Linux and Windows, results may vary. The
             * rounded rectangle is not noticeable for adjacent states of the
             * same color until width=6 (arc=3) with antialiasing, or width=8
             * (arc=4) without antialiasing.
             *
             * In other words, only draw rounded rectangles if the arc is
             * noticeable.
             */
        if (arc >= 2) {
            last = new DeferredState(drawRect, bgColor, Objects.requireNonNull(borderColor), arc, lineWidth, fLabelsVisible ? event.getLabel() : null);
            states.add(last);
        } else {
            DeferredTinyState tinyCandidate = new DeferredTinyState(drawRect, bgColor, Objects.requireNonNull(borderColor), lineWidth);
            boolean skipState = false;
            if (!states.isEmpty()) {
                DeferredItem prev = states.get(states.size() - 1);
                if (prev instanceof DeferredTinyState) {
                    DeferredTinyState tinyState = (DeferredTinyState) prev;
                    if (fBlendSubPixelEvents) {
                        skipState = tinyState.squash(tinyCandidate);
                    } else if (tinyState.extend(tinyCandidate)) {
                        skipState = true;
                    }
                }
            }
            if (!skipState) {
                states.add(tinyCandidate);
            }
            last = tinyCandidate;
        }
    }
    if (reallySelected) {
        fSelectedRectangles.add(drawRect);
    }
    if (!visible) {
        addPoint(fPoints, rect.x, rect.y - 2);
    }
    if (visible && !Boolean.TRUE.equals(styleManager.getStyle(elementStyle, ITimeEventStyleStrings.annotated())) && last != null) {
        last.add(new PostDrawEvent(event, drawRect));
    }
    return visible && !event.isPropertyActive(IFilterProperty.DIMMED);
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) DeferredItem(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredItem) DeferredTinyState(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTinyState) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Rectangle(org.eclipse.swt.graphics.Rectangle) DeferredState(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredState) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) PostDrawEvent(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.PostDrawEvent) NonNull(org.eclipse.jdt.annotation.NonNull) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager) DeferredTransparentState(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTransparentState)

Example 15 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class CustomAnnotationProviderTest method testSimple.

/**
 * Test simple
 */
@Test
public void testSimple() {
    List<Annotation> annotationList;
    MarkerSet set = new MarkerSet("name", "id");
    fProvider.configure(set);
    assertAnnotationCategoriesModelResponse(Collections.emptyList(), fProvider.fetchAnnotationCategories(Collections.emptyMap(), new NullProgressMonitor()));
    /*
         * period: 10 ms, offset: 20 ms, range: 0..4
         *
         * requested range: 100 ms-200 ms
         *
         * expected annotations: 90 ms[2] 100 ms[3] 110 ms[4] 120 ms[0] ... 200
         * ms[3] 210 ms[4]
         */
    Marker markerA = new PeriodicMarker("A", "A %d", "a", "ref.a", COLOR_STR, 10.0, "ms", Range.closed(0L, 4L), 20L, ImmutableRangeSet.of(Range.all()));
    set.addMarker(markerA);
    fProvider.configure(set);
    assertAnnotationCategoriesModelResponse(Arrays.asList("A"), fProvider.fetchAnnotationCategories(Collections.emptyMap(), new NullProgressMonitor()));
    annotationList = getAnnotationList("A", 100000000L, 200000000L, 1000L, new NullProgressMonitor());
    assertEquals(annotationList.toString(), 13, annotationList.size());
    for (int i = 0; i < annotationList.size(); i++) {
        long t = (i + 9) * 10000000L;
        int index = (i + 9) - 2;
        int labelIndex = index % 5;
        RGBAColor color = index % 2 == 0 ? COLOR : ODD_COLOR;
        validateAnnotation(annotationList.get(i), t, 10000000L, "A", String.format("A %d", labelIndex), color);
    }
}
Also used : MarkerSet(org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) Marker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) WeightedMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker) SubMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker) SplitMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) Test(org.junit.Test)

Aggregations

RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)25 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)12 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 NonNull (org.eclipse.jdt.annotation.NonNull)5 Color (org.eclipse.swt.graphics.Color)5 Point (org.eclipse.swt.graphics.Point)5 RGB (org.eclipse.swt.graphics.RGB)5 PeriodicMarker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker)5 SubMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker)5 StateItem (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Marker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker)4 MarkerSet (org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet)4 SplitMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker)4 WeightedMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker)4 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)4 StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)4 Test (org.junit.Test)4