Esempio n. 1
0
  /**
   * Render the label interior as a filled rectangle.
   *
   * @param dc Current draw context.
   */
  protected void drawInterior(DrawContext dc) {
    GL gl = dc.getGL();

    double width = this.bounds.getWidth();
    double height = this.bounds.getHeight();

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    // Adjust x to account for text alignment
    int xAligned = x;
    if (AVKey.CENTER.equals(textAlign)) xAligned = x - (int) (width / 2);
    else if (AVKey.RIGHT.equals(textAlign)) xAligned = x - (int) width;

    // We draw text top-down, so adjust y to compensate.
    int yAligned = (int) (y - height);

    // Apply insets
    Insets insets = this.getInsets();
    xAligned -= insets.left;
    width = width + insets.left + insets.right;
    yAligned -= insets.bottom;
    height = height + insets.bottom + insets.top;

    if (!dc.isPickingMode()) {
      // Apply the frame background color and opacity if we're in normal rendering mode.
      Color color = this.computeBackgroundColor(this.getMaterial().getDiffuse());
      gl.glColor4ub(
          (byte) color.getRed(),
          (byte) color.getGreen(),
          (byte) color.getBlue(),
          (byte) (this.interiorOpacity < 1 ? (int) (this.interiorOpacity * 255 + 0.5) : 255));
    }

    try {
      // Draw a quad
      gl.glPushMatrix();
      gl.glTranslated(xAligned, yAligned, 0);
      gl.glScaled(width, height, 1.0);
      dc.drawUnitQuad();
    } finally {
      gl.glPopMatrix();
    }
  }
Esempio n. 2
0
  /**
   * Determine the screen rectangle covered by a label. The input coordinate identifies either the
   * top left, top center, or top right corner of the label, depending on the text alignment. If the
   * label is rotated to align with features on the surface then the extent will be the smallest
   * screen rectangle that completely encloses the rotated label.
   *
   * @param x X coordinate at which to draw the label.
   * @param y Y coordinate at which to draw the label.
   * @param rotation Label rotation.
   * @return The rectangle, in OGL screen coordinates (origin at bottom left corner), that is
   *     covered by the label.
   */
  protected Rectangle computeTextExtent(int x, int y, Angle rotation) {
    double width = this.bounds.getWidth();
    double height = this.bounds.getHeight();

    String textAlign = this.getTextAlign();

    int xAligned = x;
    if (AVKey.CENTER.equals(textAlign)) xAligned = x - (int) (width / 2);
    else if (AVKey.RIGHT.equals(textAlign)) xAligned = x - (int) width;

    int yAligned = (int) (y - height);

    Rectangle screenRect = new Rectangle(xAligned, yAligned, (int) width, (int) height);

    // Compute bounds of the rotated rectangle, if there is a rotation angle.
    if (rotation != null && rotation.degrees != 0) {
      screenRect = this.computeRotatedScreenExtent(screenRect, x, y, rotation);
    }

    return screenRect;
  }