use of org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTinyState 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);
}
Aggregations