Example #1
0
 public static Color fadeColors(Color startColor, Color endColor, double fadePosition) {
   return Color.getArgbColor(
       mixComponent(startColor.getAlpha(), endColor.getAlpha(), fadePosition),
       mixComponent(startColor.getRed(), endColor.getRed(), fadePosition),
       mixComponent(startColor.getGreen(), endColor.getGreen(), fadePosition),
       mixComponent(startColor.getBlue(), endColor.getBlue(), fadePosition));
 }
 public static void drawGradientRect(
     int x, int y, float z, int toX, int toY, Color color, Color colorFade) {
   GL11.glDisable(GL11.GL_TEXTURE_2D);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glDisable(GL11.GL_ALPHA_TEST);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   GL11.glShadeModel(GL11.GL_SMOOTH);
   Tessellator tes = Tessellator.getInstance();
   VertexBuffer vb = tes.getBuffer();
   vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
   vb.pos(toX, y, z)
       .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())
       .endVertex();
   vb.pos(x, y, z)
       .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())
       .endVertex();
   vb.pos(x, toY, z)
       .color(colorFade.getRed(), colorFade.getGreen(), colorFade.getBlue(), colorFade.getAlpha())
       .endVertex();
   vb.pos(toX, toY, z)
       .color(colorFade.getRed(), colorFade.getGreen(), colorFade.getBlue(), colorFade.getAlpha())
       .endVertex();
   tes.draw();
   GL11.glShadeModel(GL11.GL_FLAT);
   GL11.glDisable(GL11.GL_BLEND);
   GL11.glEnable(GL11.GL_ALPHA_TEST);
   GL11.glEnable(GL11.GL_TEXTURE_2D);
 }
Example #3
0
  private BufferedImage figureOutDrawImage(Sprite[] imgs) {

    Sprite img;
    if (dead) {
      return imgs[5].getBuffer();
    }

    if (Math.abs((int) (vel.y * 100)) > 0 && !piped) {
      img = imgs[1];
    } else if (!(movingRight || movingLeft) && vel.x == 0) img = imgs[0];
    else {
      if (movingRight && vel.x < 0 || movingLeft && vel.x > 0) img = imgs[4];
      else {
        if (rightFoot) img = imgs[3];
        else img = imgs[2];
      }
    }

    if (star && (starTime < 8000 / 15 || System.currentTimeMillis() % 60 > 30)) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            limg.setPixel(
                x,
                y,
                new Color(
                    255 - pixel.getRed(),
                    255 - pixel.getGreen(),
                    255 - pixel.getBlue(),
                    pixel.getAlpha()));
          }
        }
      }
      img = limg;
    } else if (metal) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            int gray = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
            limg.setPixel(x, y, new Color(gray, gray, gray, pixel.getAlpha()));
          }
        }
      }
      img = limg;
    }

    if (facingRight) {
      return img.flipX();
    } else {
      return img.getBuffer();
    }
  }
Example #4
0
  /**
   * Paints 3 different strokes around a shape to indicate focus. The widest stroke is the most
   * transparent, so this achieves a nice "glow" effect.
   *
   * <p>The catch is that you have to render this underneath the shape, and the shape should be
   * filled completely.
   *
   * @param g the graphics to paint to
   * @param shape the shape to outline
   * @param pixelSize the number of pixels the outline should cover.
   * @param focusColor the color of the focus ring to paint
   * @param changeRenderingHints if true then the rendering hints will be modified, if false they
   *     will be left in tact
   */
  public static void paintFocus(
      Graphics2D g, Shape shape, int pixelSize, Color focusColor, boolean changeRenderingHints) {
    g = (Graphics2D) g.create();
    try {
      Color[] focusArray =
          new Color[] {
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                235 * focusColor.getAlpha() / 255),
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                130 * focusColor.getAlpha() / 255),
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                80 * focusColor.getAlpha() / 255)
          };
      if (changeRenderingHints) {
        if (JVM.usingQuartz) {
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        } else {
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setRenderingHint(
              RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
        }
      }

      g.setStroke(
          new BasicStroke(2 * pixelSize + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
      g.setColor(focusArray[2]);
      g.draw(shape);
      if (2 * pixelSize + 1 > 0) {
        g.setStroke(
            new BasicStroke(2 * pixelSize - 2 + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g.setColor(focusArray[1]);
        g.draw(shape);
      }
      if (2 * pixelSize - 4 + 1 > 0) {
        g.setStroke(
            new BasicStroke(2 * pixelSize - 4 + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g.setColor(focusArray[0]);
        g.draw(shape);
      }
    } finally {
      g.dispose();
    }
  }
  public void update(final GameContainer c, final int delta) {
    if (!active) {
      return;
    }

    final int centerX = c.getWidth() >> 1;
    final int centerY = c.getHeight() >> 1;

    final int offX = (centerX - origin.getDcX()) + dX;
    final int offY = (centerY - origin.getDcY()) + dY;

    final Avatar av = World.getAvatar();
    if (av != null) {
      glueAvatarToOrigin(av);
      corridor.setCorridor(av);
    }

    Camera.getInstance().setViewport(-offX, -offY, c.getWidth(), c.getHeight());
    Camera.getInstance().clearDirtyAreas();

    if (legacyRendering) {
      Camera.getInstance().markEverythingDirty();
    }

    synchronized (display) {
      for (final Rectangle rect : removedAreaList) {
        Camera.getInstance().markAreaDirty(rect);
      }
      synchronized (GameMap.LIGHT_LOCK) {
        while (true) {
          final MapInteractionEvent event = eventQueue.poll();
          if (event == null) {
            break;
          }

          for (int i = display.size() - 1; i >= 0; i--) {
            if (display.get(i).processEvent(c, delta, event)) {
              break;
            }
          }
        }

        // update the items
        for (int i = 0, displaySize = display.size(); i < displaySize; i++) {
          display.get(i).update(c, delta);
        }
      }
    }

    if (fadeOutColor.getAlpha() > 0) {
      fadeOutColor.a = AnimationUtility.approach(fadeOutColor.getAlpha(), 0, 0, 255, delta) / 255.f;
    }
  }
Example #6
0
  /**
   * Find the color band that this value falls in and assign that color.
   *
   * @param v
   * @param color
   */
  private final void absoluteValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
      case Absolute:
        search = v;
        break;
      case MinMax:
        search = (v - min) / (max - min);
        break;
      case Modulo:
        search = v % (max - min);
        break;
      default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);

    Color c;
    if (lower == null) {
      c = entrySet().iterator().next().getValue();
    } else {
      c = lower.getValue();
    }

    color[R] = c.getRed();
    color[G] = c.getGreen();
    color[B] = c.getBlue();
    color[A] = c.getAlpha();
  }
Example #7
0
  /**
   * Interpolate the color value for the given scalar value. The result is placed in color.
   *
   * @param v
   * @param color
   * @return
   */
  private final void interpolateValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
      case Absolute:
        search = v;
        break;
      case MinMax:
        search = (v - min) / (max - min);
        break;
      case Modulo:
        search = (v - min) % (max - min);
        break;
      default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);
    final Map.Entry<Double, Color> upper = higherEntry(search);

    assert (upper != null || lower != null);

    if (upper == null) {
      final Color c = lower.getValue();
      color[R] = c.getRed();
      color[G] = c.getGreen();
      color[B] = c.getBlue();
      color[A] = c.getAlpha();
    } else if (lower == null) {
      final Color c = upper.getValue();
      color[R] = c.getRed();
      color[G] = c.getGreen();
      color[B] = c.getBlue();
      color[A] = c.getAlpha();
    } else {
      final double diff = upper.getKey().doubleValue() - lower.getKey().doubleValue();
      final double lw = 1.0 - ((search - lower.getKey().doubleValue()) / diff);
      final double uw = 1.0 - lw;

      final Color lc = lower.getValue();
      final Color uc = upper.getValue();
      color[R] = (int) Math.round(lc.getRed() * lw + uc.getRed() * uw);
      color[G] = (int) Math.round(lc.getGreen() * lw + uc.getGreen() * uw);
      color[B] = (int) Math.round(lc.getBlue() * lw + uc.getBlue() * uw);
      color[A] = (int) Math.round(lc.getAlpha() * lw + uc.getAlpha() * uw);
    }
  }
Example #8
0
  /** Tweens between the two arguments. */
  public static Color tween(Color c1, Color c2, float p) {
    int r1 = c1.getRed();
    int g1 = c1.getGreen();
    int b1 = c1.getBlue();
    int a1 = c1.getAlpha();

    int r2 = c2.getRed();
    int g2 = c2.getGreen();
    int b2 = c2.getBlue();
    int a2 = c2.getAlpha();

    return new Color(
        (int) (r1 * (1 - p) + r2 * p),
        (int) (g1 * (1 - p) + g2 * p),
        (int) (b1 * (1 - p) + b2 * p),
        (int) (a1 * (1 - p) + a2 * p));
  }
Example #9
0
 @Override
 public void write(final OutputStream out) throws IOException {
   out.write(TYPE_COLOR);
   super.write(out);
   out.write(color.getRed());
   out.write(color.getGreen());
   out.write(color.getBlue());
   out.write(color.getAlpha());
 }
Example #10
0
 public Text renderwrap(String text, Color c, int width) {
   if (wfnd == null) wfnd = new RichText.Foundry(font, defcol);
   wfnd.aa = aa;
   text = RichText.Parser.quote(text);
   if (c != null)
     text =
         String.format(
             "$col[%d,%d,%d,%d]{%s}", c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha(), text);
   return (wfnd.render(text, width));
 }
Example #11
0
 public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) {
   BufferedImage coloredTile = tiles[tileNum];
   for (int i = 0; i < this.tW; i++) {
     for (int j = 0; j < this.tH; j++) {
       Color originalColor = new Color(coloredTile.getRGB(i, j), true);
       Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha());
       coloredTile.setRGB(i, j, nc.getRGB());
     }
   }
   g.drawImage(tiles[tileNum], x, y, null);
 }
 /**
  * Set a fixed blurring color. If the blurColor has no alpha transparency factor (see {@link
  * JBusyPanel#DEFAULT_ALPHA_NO_TRANSPARENCY_FACTOR DEFAULT_ALPHA_NO_TRANSPARENCY_FACTOR} ) the
  * {@link JBusyPanel#DEFAULT_ALPHA_TRANSPARENCY_FACTOR DEFAULT_ALPHA_TRANSPARENCY_FACTOR} is
  * applied.
  *
  * <p>If the blurColor is NULL the {@link JBusyPanel#DEFAULT_ALPHA_TRANSPARENCY_FACTOR
  * DEFAULT_ALPHA_TRANSPARENCY_FACTOR} is applied to the window's background color in {@link
  * JBusyPanel#BLUR_STYLE_ALPHA_CHANNEL BLUR_STYLE_ALPHA_CHANNEL} mode.
  *
  * @param blurColor Color New blurring color.
  */
 public static synchronized void setBlurColor(Color blurColor) {
   if ((blurColor == null)
       || (blurColor.getAlpha() != JBusyPanel.DEFAULT_ALPHA_NO_TRANSPARENCY_FACTOR)) {
     getInstance().blurColor = blurColor;
   } else {
     getInstance().blurColor =
         new Color(
             blurColor.getRed(),
             blurColor.getGreen(),
             blurColor.getBlue(),
             JBusyPanel.DEFAULT_ALPHA_TRANSPARENCY_FACTOR);
   }
 }
    private void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
      myColor = color;
      myHue = hsb[0];
      mySaturation = hsb[1];
      myBrightness = hsb[2];
      myOpacity = color.getAlpha();

      fireColorChanged(source);

      repaint();
    }
    @Override
    public String getToolTipText(MouseEvent event) {
      Color color = getColor(event);
      if (color != null) {
        return String.format(
            "R: %d G: %d B: %d A: %s",
            color.getRed(),
            color.getGreen(),
            color.getBlue(),
            String.format("%.2f", (float) (color.getAlpha() / 255.0)));
      }

      return super.getToolTipText(event);
    }
    public void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);

      myBrightnessComponent.setValue(255 - (int) (hsb[2] * 255));
      myBrightnessComponent.repaint();

      myColorWheel.dropImage();
      if (myOpacityComponent != null && source instanceof ColorPicker) {
        myOpacityComponent.setValue(color.getAlpha());
        myOpacityComponent.repaint();
      }

      myColorWheel.setColor(color, source);
    }
 public final void setModulationColor(final Color modulationColor) {
   if (modulationColor == this.m_modulationColor) {
     return;
   }
   if (modulationColor != null) {
     this.m_entity3D.setColor(
         modulationColor.getRed(),
         modulationColor.getGreen(),
         modulationColor.getBlue(),
         modulationColor.getAlpha());
   } else {
     this.m_entity3D.setColor(1.0f, 1.0f, 1.0f, 1.0f);
   }
   this.m_modulationColor = modulationColor;
 }
Example #17
0
  /**
   * Returns whether the texture uses its alpha channel
   *
   * @return <code>true</code> if at least one pixel has an alpha value below 0xFF.
   */
  public boolean hasAlphaChannel() {

    // already computed?
    if (0xffffffff == needAlpha && null != data) {

      Color[] clr = getColorArray();
      for (Color c : clr) {
        if (c.getAlpha() < 255) {
          needAlpha = 1;
          return true;
        }
      }
      needAlpha = 0;
      return false;
    }
    return 0x1 == needAlpha;
  }
    public void saveColors() {
      final List<String> values = new ArrayList<>();
      for (Color recentColor : myRecentColors) {
        if (recentColor == null) break;
        values.add(
            String.format(
                "%d-%d-%d-%d",
                recentColor.getRed(),
                recentColor.getGreen(),
                recentColor.getBlue(),
                recentColor.getAlpha()));
      }

      PropertiesComponent.getInstance()
          .setValue(
              COLOR_CHOOSER_COLORS_KEY,
              values.isEmpty() ? null : StringUtil.join(values, ",,,"),
              null);
    }
Example #19
0
  // Rendering
  public void draw(DrawContext dc) {
    GL gl = dc.getGL();

    boolean attribsPushed = false;
    boolean modelviewPushed = false;
    boolean projectionPushed = false;

    try {
      gl.glPushAttrib(
          GL.GL_DEPTH_BUFFER_BIT
              | GL.GL_COLOR_BUFFER_BIT
              | GL.GL_ENABLE_BIT
              | GL.GL_TEXTURE_BIT
              | GL.GL_TRANSFORM_BIT
              | GL.GL_VIEWPORT_BIT
              | GL.GL_CURRENT_BIT);
      attribsPushed = true;

      gl.glDisable(GL.GL_TEXTURE_2D); // no textures

      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      gl.glDisable(GL.GL_DEPTH_TEST);

      double width = this.size.width;
      double height = this.size.height;

      // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
      // into the GL projection matrix.
      java.awt.Rectangle viewport = dc.getView().getViewport();
      gl.glMatrixMode(javax.media.opengl.GL.GL_PROJECTION);
      gl.glPushMatrix();
      projectionPushed = true;
      gl.glLoadIdentity();
      double maxwh = width > height ? width : height;
      gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glPushMatrix();
      modelviewPushed = true;
      gl.glLoadIdentity();

      // Scale to a width x height space
      // located at the proper position on screen
      double scale = this.computeScale(viewport);
      Vec4 locationSW = this.computeLocation(viewport, scale);
      gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
      gl.glScaled(scale, scale, 1);

      // Compute scale size in real world
      Position referencePosition = dc.getViewportCenterPosition();
      if (referencePosition != null) {
        Vec4 groundTarget = dc.getGlobe().computePointFromPosition(referencePosition);
        Double distance = dc.getView().getEyePoint().distanceTo3(groundTarget);
        this.pixelSize = dc.getView().computePixelSizeAtDistance(distance);
        Double scaleSize = this.pixelSize * width * scale; // meter
        String unitLabel = "m";
        if (this.unit.equals(UNIT_METRIC)) {
          if (scaleSize > 10000) {
            scaleSize /= 1000;
            unitLabel = "Km";
          }
        } else if (this.unit.equals(UNIT_IMPERIAL)) {
          scaleSize *= 3.280839895; // feet
          unitLabel = "ft";
          if (scaleSize > 5280) {
            scaleSize /= 5280;
            unitLabel = "mile(s)";
          }
        }

        // Rounded division size
        int pot = (int) Math.floor(Math.log10(scaleSize));
        if (!Double.isNaN(pot)) {
          int digit = Integer.parseInt(String.format("%.0f", scaleSize).substring(0, 1));
          double divSize = digit * Math.pow(10, pot);
          if (digit >= 5) divSize = 5 * Math.pow(10, pot);
          else if (digit >= 2) divSize = 2 * Math.pow(10, pot);
          double divWidth = width * divSize / scaleSize;

          // Draw scale
          if (!dc.isPickingMode()) {
            // Set color using current layer opacity
            Color backColor = this.getBackgroundColor(this.color);
            float[] colorRGB = backColor.getRGBColorComponents(null);
            gl.glColor4d(
                colorRGB[0],
                colorRGB[1],
                colorRGB[2],
                (double) backColor.getAlpha() / 255d * this.getOpacity());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawScale(dc, divWidth, height);

            colorRGB = this.color.getRGBColorComponents(null);
            gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity());
            gl.glTranslated(-1d / scale, 1d / scale, 0d);
            this.drawScale(dc, divWidth, height);

            // Draw label
            String label = String.format("%.0f ", divSize) + unitLabel;
            gl.glLoadIdentity();
            gl.glDisable(GL.GL_CULL_FACE);
            drawLabel(
                dc,
                label,
                locationSW.add3(
                    new Vec4(divWidth * scale / 2 + (width - divWidth) / 2, height * scale, 0)));
          } else {
            // Picking
            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);
            // Draw unique color across the map
            Color color = dc.getUniquePickColor();
            int colorCode = color.getRGB();
            // Add our object(s) to the pickable list
            this.pickSupport.addPickableObject(colorCode, this, referencePosition, false);
            gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawRectangle(dc, divWidth, height);
            // Done picking
            this.pickSupport.endPicking(dc);
            this.pickSupport.resolvePick(dc, dc.getPickPoint(), this);
          }
        }
      }
    } finally {
      if (projectionPushed) {
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glPopMatrix();
      }
      if (modelviewPushed) {
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glPopMatrix();
      }
      if (attribsPushed) gl.glPopAttrib();
    }
  }
Example #20
0
 public static Color relativelyTransparent(Color original, float alpha) {
   ColorSpace srbg = ICC_ColorSpace.getInstance(ColorSpace.CS_sRGB);
   double originalAlpha = 1.0 * original.getAlpha() / 255;
   alpha *= originalAlpha;
   return new Color(srbg, original.getColorComponents(null), alpha);
 }
 /**
  * Returns the transparency mode for this <code>GradientPaint</code>.
  *
  * @return an integer value representing this <code>GradientPaint</code> object's transparency
  *     mode.
  * @see Transparency
  */
 public int getTransparency() {
   int a1 = color1.getAlpha();
   int a2 = color2.getAlpha();
   return (((a1 & a2) == 0xff) ? OPAQUE : TRANSLUCENT);
 }
  protected void hitOrDraw(Graphics2D graphics, DrawInfo2D info, Bag putInHere) {
    final Grid2D field = (Grid2D) (this.field);
    if (field == null) return;

    // first question: determine the range in which we need to draw.
    final int maxX = field.getWidth();
    final int maxY = field.getHeight();
    if (maxX == 0 || maxY == 0) return;

    final double divideByX =
        ((maxX % 2 == 0) ? (3.0 * maxX / 2.0 + 0.5) : (3.0 * maxX / 2.0 + 2.0));
    final double divideByY = (1.0 + 2.0 * maxY);

    final double xScale = info.draw.width / divideByX;
    final double yScale = info.draw.height / divideByY;
    int startx = (int) (((info.clip.x - info.draw.x) / xScale - 0.5) / 1.5) - 2;
    int starty = (int) ((info.clip.y - info.draw.y) / (yScale * 2.0)) - 2;
    int endx = /*startx +*/
        (int) (((info.clip.x - info.draw.x + info.clip.width) / xScale - 0.5) / 1.5)
            + 4; // with rounding, width be as much as 1 off
    int endy = /*starty +*/
        (int) ((info.clip.y - info.draw.y + info.clip.height) / (yScale * 2.0))
            + 4; // with rounding, height be as much as 1 off

    //
    //
    // CAUTION!
    //
    // At some point we should triple check the math for rounding such
    // that the margins are drawn properly
    //
    //

    // next we determine if this is a DoubleGrid2D or an IntGrid2D

    //        final Rectangle clip = (graphics==null ? null : graphics.getClipBounds());

    final boolean isDoubleGrid2D = (field instanceof DoubleGrid2D);
    final double[][] doubleField = (isDoubleGrid2D ? ((DoubleGrid2D) field).field : null);
    final int[][] intField = (isDoubleGrid2D ? null : ((IntGrid2D) field).field);

    double xyC_x, xyC_y, xyC_ulx, xyC_uly, xyC_upx, xyC_upy, xyC_urx, xyC_ury, x0, y0, tx, ty;

    if (startx < 0) startx = 0;
    if (starty < 0) starty = 0;
    if (endx > maxX) endx = maxX;
    if (endy > maxY) endy = maxY;

    for (int y = starty; y < endy; y++)
      for (int x = startx; x < endx; x++) {
        // getxyC( x, y, xScale, yScale, info.draw.x, info.draw.y, xyC );
        // getxyC( field.ulx(x,y), field.uly(x,y), xScale, yScale, info.draw.x, info.draw.y, xyC_ul
        // );
        // getxyC( field.upx(x,y), field.upy(x,y), xScale, yScale, info.draw.x, info.draw.y, xyC_up
        // );
        // getxyC( field.urx(x,y), field.ury(x,y), xScale, yScale, info.draw.x, info.draw.y, xyC_ur
        // );

        x0 = x;
        y0 = y;
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_x = tx + xScale * (1.5 * x0 + 1);
        xyC_y = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        x0 = field.ulx(x, y);
        y0 = field.uly(x, y);
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_ulx = tx + xScale * (1.5 * x0 + 1);
        xyC_uly = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        x0 = field.upx(x, y);
        y0 = field.upy(x, y);
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_upx = tx + xScale * (1.5 * x0 + 1);
        xyC_upy = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        x0 = field.urx(x, y);
        y0 = field.ury(x, y);
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_urx = tx + xScale * (1.5 * x0 + 1);
        xyC_ury = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        xPoints[0] = (int) (xyC_urx - 0.5 * xScale);
        yPoints[0] = (int) (xyC_ury + yScale);
        xPoints[1] = (int) (xyC_upx + 0.5 * xScale);
        yPoints[1] = (int) (xyC_upy + yScale);
        xPoints[2] = (int) (xyC_upx - 0.5 * xScale);
        yPoints[2] = (int) (xyC_upy + yScale);
        xPoints[3] = (int) (xyC_ulx + 0.5 * xScale);
        yPoints[3] = (int) (xyC_uly + yScale);
        xPoints[4] = (int) (xyC_x - 0.5 * xScale);
        yPoints[4] = (int) (xyC_y + yScale);
        xPoints[5] = (int) (xyC_x + 0.5 * xScale);
        yPoints[5] = (int) (xyC_y + yScale);

        if (graphics == null) {
          generalPath.reset();
          generalPath.moveTo(xPoints[0], yPoints[0]);
          for (int i = 1; i < 6; i++) generalPath.lineTo(xPoints[i], yPoints[i]);
          generalPath.closePath();
          Area area = new Area(generalPath);
          if (area.intersects(info.clip.x, info.clip.y, info.clip.width, info.clip.height)) {
            valueToPass.val = isDoubleGrid2D ? doubleField[x][y] : intField[x][y];
            putInHere.add(getWrapper(valueToPass.val, x, y));
          }
        } else {
          Color c = map.getColor(isDoubleGrid2D ? doubleField[x][y] : intField[x][y]);
          if (c.getAlpha() == 0) continue;
          graphics.setColor(c);

          // MacOS X 10.3 Panther has a bug which resets the clip, YUCK
          //                    graphics.setClip(clip);
          graphics.fillPolygon(xPoints, yPoints, 6);
        }
      }
  }
Example #23
0
 @Override
 public void draw(PGraphics g, Context context, float time) {
   Color c = pColor.get();
   g.background(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
 }
Example #24
0
 public void setColor(int index, Color c) {
   setRGB(index, c.getRed(), c.getGreen(), c.getBlue());
   setAlpha(index, c.getAlpha());
 }
Example #25
0
  /**
   * Render all visible map items
   *
   * @param g the graphics component that is used to render the screen
   * @param c the game container the map is rendered in
   */
  public void render(final Graphics g, final GameContainer c) {
    if (!active) {
      return;
    }

    if (legacyRendering) {
      renderImpl(g);
    } else {
      Graphics usedGraphics = g;
      if (gameScreenImage == null) {
        try {
          gameScreenImage = new Image(c.getWidth(), c.getHeight(), SGL.GL_LINEAR);
        } catch (SlickException e) {
          legacyRendering = true;
          LOGGER.warn("Rendering to texture fails. Using legacy direct rendering.");
          render(g, c);
          return;
        }
      }

      try {
        usedGraphics = gameScreenImage.getGraphics();
      } catch (SlickException e) {
        legacyRendering = true;
        LOGGER.warn("Fetching render to texture context failed. Switching to legacy rendering.");
        render(g, c);
        return;
      }

      renderImpl(usedGraphics);

      if (gameScreenImage != null) {
        if (fogShader == null) {
          try {
            fogShader =
                ShaderProgram.loadProgram(
                    "illarion/client/graphics/shader/fog.vert",
                    "illarion/client/graphics/shader/fog.frag");
          } catch (SlickException e) {
            LOGGER.error("Error loading shader!", e);
          }
        }

        if (fogShader != null) {
          fogShader.bind();
          fogShader.setUniform1i("tex0", 0);

          final float x = 0.5f * gameScreenImage.getTextureWidth();
          final float y = 0.5f * gameScreenImage.getTextureHeight();
          fogShader.setUniform2f("center", x, y);
          fogShader.setUniform1f(
              "density",
              World.getWeather().getFog() * ((float) gameScreenImage.getHeight() / 200.f));

          g.drawImage(gameScreenImage, 0, 0);

          fogShader.unbind();
        } else {
          g.drawImage(gameScreenImage, 0, 0);
        }
        Camera.getInstance().renderDebug(g);
      }
    }

    if (fadeOutColor.getAlpha() > 0) {
      g.setColor(fadeOutColor);
      g.setLineWidth(3.f);
      g.fillRect(0, 0, c.getWidth(), c.getHeight());
    }
  }