コード例 #1
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
 /** Returns the bounding box of this Drawable in screen coordinates. */
 @Override
 public final org.geogebra.common.awt.GRectangle getBounds() {
   if (!geo.isDefined() || !geo.isEuclidianVisible()) {
     return null;
   }
   return gp.getBounds();
 }
コード例 #2
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
  @Override
  public final void update() {
    isVisible = geo.isEuclidianVisible();
    if (isVisible) {
      if (!geo.getDrawAlgorithm().equals(geo.getParentAlgorithm())) init();
      int slopeTriangleSize = slope.getSlopeTriangleSize();
      double rwHeight = slope.getValue() * slopeTriangleSize;
      double height = view.getYscale() * rwHeight;
      if (Math.abs(height) > Float.MAX_VALUE) {
        isVisible = false;
        return;
      }

      // get point on line g
      g.getInhomPointOnLine(coords);
      if (g.getStartPoint() == null) {
        // get point on y-axis and line g
        coords[0] = 0.0d;
        coords[1] = -g.z / g.y;
      }
      view.toScreenCoords(coords);

      // draw slope triangle
      double x = coords[0];
      double y = coords[1];
      double xright = x + view.getXscale() * slopeTriangleSize;
      if (gp == null) gp = new GeneralPathClipped(view);
      gp.reset();
      gp.moveTo(x, y);
      gp.lineTo(xright, y);
      gp.lineTo(xright, y - height);
      // closePath important for clipping: #4048
      gp.closePath();
      // gp on screen?
      if (!gp.intersects(0, 0, view.getWidth(), view.getHeight())) {
        isVisible = false;
        // don't return here to make sure that getBounds() works for
        // offscreen points too
      }

      // label position
      labelVisible = geo.isLabelVisible();
      StringTemplate tpl = StringTemplate.defaultTemplate;
      if (labelVisible) {
        if (slopeTriangleSize > 1) {
          StringBuilder sb = new StringBuilder();
          switch (slope.getLabelMode()) {
            case GeoElement.LABEL_NAME_VALUE:
              sb.append(slopeTriangleSize);
              sb.append(' ');
              sb.append(geo.getLabel(tpl));
              sb.append(" = ");
              sb.append(kernel.format(rwHeight, tpl));
              break;

            case GeoElement.LABEL_VALUE:
              sb.append(kernel.format(rwHeight, tpl));
              break;

            default: // case GeoElement.LABEL_NAME:
              sb.append(slopeTriangleSize);
              sb.append(' ');
              sb.append(geo.getLabel(tpl));
              break;
          }
          labelDesc = sb.toString();
        } else {
          labelDesc = geo.getLabelDescription();
        }
        yLabel = (int) (y - height / 2.0f + 6);
        xLabel = (int) (xright) + 5;
        addLabelOffset();

        // position off horizontal label (i.e. slopeTriangleSize)
        xLabelHor = (int) ((x + xright) / 2.0);
        yLabelHor = (int) (y + view.getFontSize() + 2);
        StringBuilder sb = new StringBuilder();
        sb.append(slopeTriangleSize);
        horLabel = sb.toString();
      }
      updateStrokes(slope);
    }
  }
コード例 #3
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
 @Override
 public boolean intersectsRectangle(GRectangle rect) {
   return gp != null && (gp.intersects(rect));
 }
コード例 #4
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
 @Override
 public final boolean hit(int x, int y, int hitThreshold) {
   return gp != null && (gp.contains(x, y) || gp.intersects(x, y, hitThreshold));
 }