Beispiel #1
0
  public synchronized void draw() {
    gw.clear(1, 1, 1);
    gw.setColor(0, 0, 0);
    gw.setupForDrawing();

    gw.setCoordinateSystemToWorldSpaceUnits();
    gw.enableAlphaBlending();

    drawing.draw(gw);

    gw.setCoordinateSystemToPixels();

    for (int j = 0; j < Constant.NUM_USERS; ++j) {
      userContexts[j].draw(gw);
    }

    // Draw some text to indicate the number of fingers touching the user interface.
    // This is useful for debugging.
    int totalNumCursors = 0;
    String s = "[";
    for (int j = 0; j < Constant.NUM_USERS; ++j) {
      totalNumCursors += userContexts[j].getNumCursors();
      s += (j == 0 ? "" : "+") + userContexts[j].getNumCursors();
    }
    s += " contacts]";
    if (totalNumCursors > 0) {
      gw.setColor(0, 0, 0);
      gw.setFontHeight(Constant.TEXT_HEIGHT);
      gw.drawString(Constant.TEXT_HEIGHT, 2 * Constant.TEXT_HEIGHT, s);
    }
  }
Beispiel #2
0
  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());
        }
      }
    }
  }