private void drawOutline(GC gc, CanvasViewInfo info) { Rectangle r = info.getAbsRect(); int x = mHScale.translate(r.x); int y = mVScale.translate(r.y); int w = mHScale.scale(r.width); int h = mVScale.scale(r.height); // Add +1 to the width and +1 to the height such that when you have a // series of boxes (in say a LinearLayout), instead of the bottom of one // box and the top of the next box being -adjacent-, they -overlap-. // This makes the outline nicer visually since you don't get // "double thickness" lines for all adjacent boxes. gc.drawRectangle(x, y, w + 1, h + 1); for (CanvasViewInfo vi : info.getChildren()) { drawOutline(gc, vi); } }
@Override public void paint(GC gc) { if (mHoverRect != null) { // Translate the hover rectangle (in canvas coordinates) to control // coordinates int x = mHScale.translate(mHoverRect.x); int y = mVScale.translate(mHoverRect.y); int w = mHScale.scale(mHoverRect.width); int h = mVScale.scale(mHoverRect.height); boolean hoverIsSelected = false; List<SelectionItem> selections = mCanvas.getSelectionManager().getSelections(); for (SelectionItem item : selections) { if (mHoverRect.equals(item.getViewInfo().getSelectionRect())) { hoverIsSelected = true; break; } } Color stroke = hoverIsSelected ? mHoverSelectStrokeColor : mHoverStrokeColor; Color fill = hoverIsSelected ? mHoverSelectFillColor : mHoverFillColor; if (stroke != null) { int oldAlpha = gc.getAlpha(); gc.setForeground(stroke); gc.setLineStyle(hoverIsSelected ? HOVER_SELECTION.getLineStyle() : HOVER.getLineStyle()); gc.setAlpha(hoverIsSelected ? HOVER_SELECTION.getStrokeAlpha() : HOVER.getStrokeAlpha()); gc.drawRectangle(x, y, w, h); gc.setAlpha(oldAlpha); } if (fill != null) { int oldAlpha = gc.getAlpha(); gc.setAlpha(hoverIsSelected ? HOVER_SELECTION.getFillAlpha() : HOVER.getFillAlpha()); gc.setBackground(fill); gc.fillRectangle(x, y, w, h); gc.setAlpha(oldAlpha); } } }