Ejemplo n.º 1
0
  @Override
  public Surface drawLine(float x0, float y0, float x1, float y1, float width) {
    bindFramebuffer();

    // swap the line end points if x1 is less than x0
    if (x1 < x0) {
      float temp = x0;
      x0 = x1;
      x1 = temp;
      temp = y0;
      y0 = y1;
      y1 = temp;
    }

    float dx = x1 - x0, dy = y1 - y0;
    float length = FloatMath.sqrt(dx * dx + dy * dy);
    float wx = dx * (width / 2) / length;
    float wy = dy * (width / 2) / length;

    InternalTransform l = ctx.createTransform();
    l.setRotation(FloatMath.atan2(dy, dx));
    l.setTranslation(x0 + wy, y0 - wx);
    l.preConcatenate(topTransform());

    GLShader shader = ctx.quadShader(this.shader);
    if (fillPattern != null) {
      int tex = fillPattern.ensureTexture();
      if (tex > 0) {
        shader.prepareTexture(tex, tint);
        shader.addQuad(
            l,
            0,
            0,
            length,
            width,
            0,
            0,
            length / fillPattern.width(),
            width / fillPattern.height());
      }
    } else {
      int tex = ctx.fillImage().ensureTexture();
      shader.prepareTexture(tex, Tint.combine(fillColor, tint));
      shader.addQuad(l, 0, 0, length, width, 0, 0, 1, 1);
    }
    return this;
  }
Ejemplo n.º 2
0
  @Override
  public Surface fillRect(float x, float y, float width, float height) {
    bindFramebuffer();

    GLShader shader = ctx.quadShader(this.shader);
    if (fillPattern != null) {
      int tex = fillPattern.ensureTexture(true, true);
      if (tex > 0) {
        shader.prepareTexture(tex, tint);
        float tw = fillPattern.width(), th = fillPattern.height(), r = x + width, b = y + height;
        shader.addQuad(topTransform(), x, y, x + width, y + height, x / tw, y / th, r / tw, b / th);
      }
    } else {
      shader.prepareColor(Tint.combine(fillColor, tint));
      shader.addQuad(topTransform(), x, y, x + width, y + height, 0, 0, 1, 1);
    }
    return this;
  }