public void draw(GraphicsWrapper gw) { palette.draw(gw); // draw filled rectangles over the selected strokes gw.setCoordinateSystemToWorldSpaceUnits(); for (Stroke s : selectedStrokes) { AlignedRectangle2D r = s.getBoundingRectangle(); gw.setColor(1.0f, 0.5f, 0, 0.2f); // transparent orange Vector2D diagonal = r.getDiagonal(); gw.fillRect(r.getMin().x(), r.getMin().y(), diagonal.x(), diagonal.y()); } gw.setCoordinateSystemToPixels(); // draw cursors for (int i = 0; i < cursorContainer.getNumCursors(); ++i) { MyCursor cursor = cursorContainer.getCursorByIndex(i); if (cursor.type == MyCursor.TYPE_NOTHING) gw.setColor(0.5f, 0, 0, 0.65f); // red (because this cursor is being ignored) else gw.setColor(0, 0.5f, 0.5f, 0.65f); // cyan gw.fillCircle(cursor.getCurrentPosition().x() - 10, cursor.getCurrentPosition().y() - 10, 10); if (cursor.type == MyCursor.TYPE_INKING) { // draw ink trail gw.setColor(0, 0, 0); gw.drawPolyline(cursor.getPositions()); } else if (cursor.type == MyCursor.TYPE_SELECTION) { if (cursor.doesDragLookLikeLassoGesture()) { // draw filled polygon gw.setColor(0, 0, 0, 0.2f); gw.fillPolygon(cursor.getPositions()); } else { // draw polyline to indicate that a lasso could be started gw.setColor(0, 0, 0); gw.drawPolyline(cursor.getPositions()); // also draw selection rectangle gw.setColor(0, 0, 0, 0.2f); Vector2D diagonal = Point2D.diff(cursor.getCurrentPosition(), cursor.getFirstPosition()); gw.fillRect( cursor.getFirstPosition().x(), cursor.getFirstPosition().y(), diagonal.x(), diagonal.y()); } } } }
public Palette() { final int W = PaletteButton.width; final int H = PaletteButton.height; PaletteButton b = null; buttons = new ArrayList<PaletteButton>(); // Create first row of buttons b = new PaletteButton(0, 0, "Move", "Drag on this button to move the palette.", false); movePalette_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton(W, 0, "Ink", "When active, use other fingers to draw ink strokes.", true); ink_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton( 2 * W, 0, "Select", "When active, use another finger to select strokes.", true); select_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton( 3 * W, 0, "Manip.", "When active, use one or two other fingers to directly manipulate the selection.", true); manipulate_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton( 4 * W, 0, "Camera", "When active, use one or two other fingers to directly manipulate the camera.", true); camera_buttonIndex = buttons.size(); buttons.add(b); // Create second row of buttons b = new PaletteButton(0, H, "Black", "Changes ink color.", true); black_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton(W, H, "Red", "Changes ink color.", true); red_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton(2 * W, H, "Green", "Changes ink color.", true); green_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton( 3 * W, H, "Hor. Flip", "Flip the selection horizontally (around a vertical axis).", false); horizFlip_buttonIndex = buttons.size(); buttons.add(b); b = new PaletteButton(4 * W, H, "Frame all", "Frames the entire drawing.", false); frameAll_buttonIndex = buttons.size(); buttons.add(b); // Initialize remaining state buttons.get(ink_buttonIndex).isPressed = true; currentlyActiveModalButton = ink_buttonIndex; buttons.get(black_buttonIndex).isPressed = true; currentlyActiveColorButton = black_buttonIndex; current_red = current_green = current_blue = 0; // Figure out the width and height of the palette. // To do this, compute a bounding rectangle. AlignedRectangle2D boundingRectangle = new AlignedRectangle2D(); for (int j = 0; j < buttons.size(); ++j) { boundingRectangle.bound(buttons.get(j).getBoundingRectangle()); } // Note that the bounding rectangle contains coordinates in the palette's local space. // We only store the width and height of the bounding rectangle. width = Math.round(boundingRectangle.getDiagonal().x()); height = Math.round(boundingRectangle.getDiagonal().y()); }