/**
   * 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();
    }
  }
Example #2
0
  protected void applyBackground(
      DrawContext dc,
      WWIcon icon,
      Vec4 screenPoint,
      double width,
      double height,
      double pedestalSpacing,
      double pedestalScale) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    double backgroundScale;
    backgroundScale = icon.getBackgroundScale();

    if (icon.getBackgroundTexture() != null) {
      if (icon.getBackgroundTexture().bind(dc)) {
        TextureCoords texCoords = icon.getBackgroundTexture().getTexCoords();
        gl.glPushMatrix();
        gl.glLoadIdentity();
        double bgwidth = backgroundScale * width;
        double bgheight = backgroundScale * height;
        // Offset the background for the highlighted scale.
        // if (icon.isHighlighted())
        // {
        //    gl.glTranslated(0d, height * (icon.getHighlightScale() - 1) / 2, 0d);
        // }
        // Offset the background for the pedestal height.
        gl.glTranslated(0d, (pedestalScale * height) + pedestalSpacing, 0d);
        // Place the background centered behind the icon.
        gl.glTranslated(screenPoint.x - bgwidth / 2, screenPoint.y - (bgheight - height) / 2, 0d);
        // Scale to the background image dimension.
        gl.glScaled(bgwidth, bgheight, 1d);
        dc.drawUnitQuad(texCoords);
        gl.glPopMatrix();
      }
    }
  }
Example #3
0
  protected void drawIcon(DrawContext dc, SurfaceTileDrawContext sdc) {
    if (this.locations == null) return;

    GL gl = dc.getGL();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    double drawScale = 1;
    TextureCoords textureCoords = new TextureCoords(0, 0, 1, 1);

    // Compute draw scale only once if not maintaining strict appearance
    if (!this.isMaintainAppearance()) drawScale = this.computeDrawScale(dc, sdc, null);
    // Determine which locations are to be drawn
    Iterable<? extends LatLon> drawLocations = this.computeDrawLocations(dc, sdc);
    // Draw icons
    for (LatLon location : drawLocations) {
      gl.glPushMatrix();

      if (this.isMaintainAppearance()) drawScale = this.computeDrawScale(dc, sdc, location);
      this.applyDrawTransform(dc, sdc, location, drawScale);
      gl.glScaled(this.imageWidth, this.imageHeight, 1d);
      dc.drawUnitQuad(textureCoords);

      gl.glPopMatrix();
    }
  }
Example #4
0
  protected void drawIcon(DrawContext dc) {
    if (this.getIconFilePath() == null) return;

    GL gl = dc.getGL();
    OGLStackHandler ogsh = new OGLStackHandler();

    try {
      // Initialize texture if necessary
      Texture iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath());
      if (iconTexture == null) {
        this.initializeTexture(dc);
        iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath());
        if (iconTexture == null) {
          String msg = Logging.getMessage("generic.ImageReadFailed");
          Logging.logger().finer(msg);
          return;
        }
      }
      gl.glDisable(GL.GL_DEPTH_TEST);

      double width = this.getScaledIconWidth();
      double height = this.getScaledIconHeight();

      // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
      // into the GL projection matrix.
      java.awt.Rectangle viewport = dc.getView().getViewport();
      ogsh.pushProjectionIdentity(gl);
      double maxwh = width > height ? width : height;
      gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

      // Translate and scale
      ogsh.pushModelviewIdentity(gl);
      double scale = this.computeScale(viewport);
      Vec4 locationSW = this.computeLocation(viewport, scale);
      gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
      // Scale to 0..1 space
      gl.glScaled(scale, scale, 1);
      gl.glScaled(width, height, 1d);

      if (!dc.isPickingMode()) {
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

        // Draw background color behind the map
        gl.glColor4ub(
            (byte) this.backColor.getRed(),
            (byte) this.backColor.getGreen(),
            (byte) this.backColor.getBlue(),
            (byte) (this.backColor.getAlpha() * this.getOpacity()));
        dc.drawUnitQuad();

        // Draw world map icon
        gl.glColor4d(1d, 1d, 1d, this.getOpacity());
        gl.glEnable(GL.GL_TEXTURE_2D);
        iconTexture.bind();

        TextureCoords texCoords = iconTexture.getImageTexCoords();
        dc.drawUnitQuad(texCoords);
        gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
        gl.glDisable(GL.GL_TEXTURE_2D);

        // Draw crosshair for current location
        gl.glLoadIdentity();
        gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
        // Scale to width x height space
        gl.glScaled(scale, scale, 1);
        // Set color
        float[] colorRGB = this.color.getRGBColorComponents(null);
        gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity());

        // Draw crosshair
        Position groundPos = this.computeGroundPosition(dc, dc.getView());
        if (groundPos != null) {
          int x = (int) (width * (groundPos.getLongitude().degrees + 180) / 360);
          int y = (int) (height * (groundPos.getLatitude().degrees + 90) / 180);
          int w = 10; // cross branch length
          // Draw
          gl.glBegin(GL.GL_LINE_STRIP);
          gl.glVertex3d(x - w, y, 0);
          gl.glVertex3d(x + w + 1, y, 0);
          gl.glEnd();
          gl.glBegin(GL.GL_LINE_STRIP);
          gl.glVertex3d(x, y - w, 0);
          gl.glVertex3d(x, y + w + 1, 0);
          gl.glEnd();
        }

        // Draw view footprint in map icon space
        if (this.showFootprint) {
          this.footPrintPositions = this.computeViewFootPrint(dc, 32);
          if (this.footPrintPositions != null) {
            gl.glBegin(GL.GL_LINE_STRIP);
            LatLon p1 = this.footPrintPositions.get(0);
            for (LatLon p2 : this.footPrintPositions) {
              int x = (int) (width * (p2.getLongitude().degrees + 180) / 360);
              int y = (int) (height * (p2.getLatitude().degrees + 90) / 180);
              // Draw
              if (LatLon.locationsCrossDateline(p1, p2)) {
                int y1 = (int) (height * (p1.getLatitude().degrees + 90) / 180);
                gl.glVertex3d(x < width / 2 ? width : 0, (y1 + y) / 2, 0);
                gl.glEnd();
                gl.glBegin(GL.GL_LINE_STRIP);
                gl.glVertex3d(x < width / 2 ? 0 : width, (y1 + y) / 2, 0);
              }
              gl.glVertex3d(x, y, 0);
              p1 = p2;
            }
            gl.glEnd();
          }
        }
        // Draw 1px border around and inside the map
        gl.glBegin(GL.GL_LINE_STRIP);
        gl.glVertex3d(0, 0, 0);
        gl.glVertex3d(width, 0, 0);
        gl.glVertex3d(width, height - 1, 0);
        gl.glVertex3d(0, height - 1, 0);
        gl.glVertex3d(0, 0, 0);
        gl.glEnd();
      } else {
        // Picking
        this.pickSupport.clearPickList();
        this.pickSupport.beginPicking(dc);
        // Where in the world are we picking ?
        Position pickPosition =
            computePickPosition(
                dc, locationSW, new Dimension((int) (width * scale), (int) (height * scale)));
        Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        this.pickSupport.addPickableObject(colorCode, this, pickPosition, false);
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
        dc.drawUnitQuad();
        this.pickSupport.endPicking(dc);
        this.pickSupport.resolvePick(dc, dc.getPickPoint(), this);
      }
    } finally {
      dc.restoreDefaultDepthTesting();
      dc.restoreDefaultCurrentColor();
      if (dc.isPickingMode()) dc.restoreDefaultBlending();
      ogsh.pop(gl);
    }
  }
Example #5
0
  protected Vec4 drawIcon(DrawContext dc, OrderedIcon uIcon) {
    if (uIcon.point == null) {
      String msg = Logging.getMessage("nullValue.PointIsNull");
      Logging.logger().severe(msg);

      // Record feedback data for this WWIcon if feedback is enabled.
      if (uIcon.icon != null) this.recordFeedback(dc, uIcon.icon, null, null);

      return null;
    }

    WWIcon icon = uIcon.icon;
    if (dc.getView().getFrustumInModelCoordinates().getNear().distanceTo(uIcon.point) < 0) {
      // Record feedback data for this WWIcon if feedback is enabled.
      this.recordFeedback(dc, icon, uIcon.point, null);

      return null;
    }

    final Vec4 screenPoint = dc.getView().project(uIcon.point);
    if (screenPoint == null) {
      // Record feedback data for this WWIcon if feedback is enabled.
      this.recordFeedback(dc, icon, uIcon.point, null);

      return null;
    }

    double pedestalScale;
    double pedestalSpacing;
    if (this.pedestal != null) {
      pedestalScale = this.pedestal.getScale();
      pedestalSpacing = pedestal.getSpacingPixels();
    } else {
      pedestalScale = 0d;
      pedestalSpacing = 0d;
    }

    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    this.setDepthFunc(dc, uIcon, screenPoint);

    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    Dimension size = icon.getSize();
    double width = size != null ? size.getWidth() : icon.getImageTexture().getWidth(dc);
    double height = size != null ? size.getHeight() : icon.getImageTexture().getHeight(dc);
    gl.glTranslated(
        screenPoint.x - width / 2, screenPoint.y + (pedestalScale * height) + pedestalSpacing, 0d);

    if (icon.isHighlighted()) {
      double heightDelta = this.pedestal != null ? 0 : height / 2; // expand only above the pedestal
      gl.glTranslated(width / 2, heightDelta, 0);
      gl.glScaled(icon.getHighlightScale(), icon.getHighlightScale(), icon.getHighlightScale());
      gl.glTranslated(-width / 2, -heightDelta, 0);
    }

    Rectangle rect =
        new Rectangle(
            (int) (screenPoint.x - width / 2),
            (int) (screenPoint.y),
            (int) width,
            (int) (height + (pedestalScale * height) + pedestalSpacing));

    if (dc.isPickingMode()) {
      // If in picking mode and pick clipping is enabled, check to see if the icon is within the
      // pick volume.
      if (this.isPickFrustumClippingEnabled() && !dc.getPickFrustums().intersectsAny(rect)) {
        // Record feedback data for this WWIcon if feedback is enabled.
        this.recordFeedback(dc, icon, uIcon.point, rect);

        return screenPoint;
      } else {
        java.awt.Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        this.pickSupport.addPickableObject(colorCode, icon, uIcon.getPosition(), false);
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
      }
    }

    if (icon.getBackgroundTexture() != null)
      this.applyBackground(dc, icon, screenPoint, width, height, pedestalSpacing, pedestalScale);

    if (icon.getImageTexture().bind(dc)) {
      TextureCoords texCoords = icon.getImageTexture().getTexCoords();
      gl.glScaled(width, height, 1d);
      dc.drawUnitQuad(texCoords);
    }

    if (this.pedestal != null && this.pedestal.getImageTexture() != null) {
      gl.glLoadIdentity();
      gl.glTranslated(screenPoint.x - (pedestalScale * (width / 2)), screenPoint.y, 0d);
      gl.glScaled(width * pedestalScale, height * pedestalScale, 1d);

      if (this.pedestal.getImageTexture().bind(dc)) {
        TextureCoords texCoords = this.pedestal.getImageTexture().getTexCoords();
        dc.drawUnitQuad(texCoords);
      }
    }

    // Record feedback data for this WWIcon if feedback is enabled.
    this.recordFeedback(dc, icon, uIcon.point, rect);

    return screenPoint;
  }