Пример #1
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());
        }
      }
    }
  }
Пример #2
0
  /**
   * Draws segment on screen via graphics attribute gc Helper method for traverse_ssector
   *
   * @param seg whose seen attribute may be set to true
   * @param ox1
   * @param y1
   * @param ox2
   * @param y2
   */
  private void drawrect(Seg seg, int ox1, int y1, int ox2, int y2) {
    // int y11, y12, y21, y22;
    // Log.v("inside drawrect", "hooray");
    int z1 = 0;
    int z2 = 100;

    drawrect_ct++; // debug, counter
    ox1 -= viewx;
    y1 -= viewy;
    z1 -= viewz;
    ox2 -= viewx;
    y2 -= viewy;
    z2 -= viewz;

    int y11, y12, y21, y22;
    y11 = y21 = -z1;
    y12 = y22 = -z2;

    int x1;
    int x2;
    x1 = -viewd_unscale(view_dy * ox1 - view_dx * y1);
    z1 = -viewd_unscale(view_dx * ox1 + view_dy * y1);
    x2 = -viewd_unscale(view_dy * ox2 - view_dx * y2);
    z2 = -viewd_unscale(view_dx * ox2 + view_dy * y2);

    RangePair rp = new RangePair(x1, z1, x2, z2);
    if (!clip3d(rp)) {
      return;
    }

    y11 = y11 * zscale / rp.z1 + (view_height / 2); // constant from here
    y12 = y12 * zscale / rp.z1 + (view_height / 2); // constant from here
    y21 = y21 * zscale / rp.z2 + (view_height / 2); // constant from here
    y22 = y22 * zscale / rp.z2 + (view_height / 2); // constant from here
    x1 = rp.x1 * zscale / rp.z1 + (view_width / 2); // constant from here
    x2 = rp.x2 * zscale / rp.z2 + (view_width / 2); // constant from here
    if (x1 >= x2) {
        /* reject backfaces */
      // Log.v("hatefulthings", "grrr");
      return;
    }
    int x1i = x1;
    int xd = x2 - x1;
    gw.setColor(seg.col);

    boolean drawn = false;
    drawrect_late_ct++; // debug, counter
    // loop variable is x1i, upper limit x2 is fixed
    // Log.v("more things", ""+x1i);
    // Log.v("more more things", ""+x2);
    while (x1i <= x2) {
      // check if there is an intersection,
      // if there is none proceed exit the loop,
      // if there is one, get it as (x1i,x2i)
      int[] p = {x1i, x2};
      if (!rset.intersect(p)) break;
      x1i = p[0];
      int x2i = p[1];
      // let's work on the intersection (x1i,x2i)
      int xps[] = {x1i, x1i, x2i + 1, x2i + 1};
      int yps[] = {
        y11 + (x1i - x1) * (y21 - y11) / xd,
        y12 + (x1i - x1) * (y22 - y12) / xd + 1,
        y22 + (x2i - x2) * (y22 - y12) / xd + 1,
        y21 + (x2i - x2) * (y21 - y11) / xd
      };
      System.out.println("I get to here");
      gw.fillPolygon(xps, yps, 4);
      drawn = true;
      rset.remove(x1i, x2i);
      x1i = x2i + 1;
      drawrect_segment_ct++; // debug, counter
    }
    if (drawn && !seg.seen) {
      udpateSeenCellsForSegment(seg);
    }
  }