stroke() influencing the textstyle()?

There is an interessting bug, when my function calls stroke in an object it changes the textstyle afterwards and gives a strokeWeight() to it... my TextClass:

    function textClass(_x, _y) {
      colorMode(HSB,100);
      textAlign(CENTER);
      this.x = _x;
      this.y = _y;
      this.writeText = function(_content, _font, _size, _color) {
        this.content = _content;
        this.font = _font;
        this.size = _size;
        this.col = color(_color);
        textSize(this.size);
        fill (this.col);
        text (this.content, this.x, this.y);
      }
      this.writeTextBox = function(_content, _font, _size, _color, _x2, _y2) {
        this.content = _content;
        this.font = _font;
        this.size = _size;
        this.col = color(_color);
        this.x2 = _x2;
        this.y2 = _y2;
        textSize(this.size);
        fill (this.col);
        text (this.content, this.x, this.y, this.x2, this.y2);
      }
    }

And my objectClass with the stroke(255)-Problem.

function buttons(_bPosX, _bPosY, _bWidth2, _bHeight2, _bColor) {
  colorMode(HSB, 100);
  this.bPosX = _bPosX;
  this.bPosY = _bPosY;
  this.bWidth2 = _bWidth2;
  this.bHeight2 = _bHeight2;
  this.bColor = color(_bColor);
  //function to draw Rect Buttons
  this.drawButtonRect = function() {
    //bPosX = _bPosX;
    stroke(1);//HERE IS NO PROBLEM
    strokeWeight(1);
    fill(this.bColor);
    rect(this.bPosX, this.bPosY, this.bWidth2, this.bHeight2);
    noStroke();
  }

  //function to draw Ellipse Buttons
  this.drawButtonEllipse = function() {
    stroke(1);//HERE IS THE PROBLEM, JUST FOR ELLIPSE BUTTONS, if away no StrokeWeight to text, but also no stockeWeight to my ellipse...hmmm
    strokeWeight(1);
    fill(this.bColor);
    ellipseMode(CENTER);
    ellipse(this.bPosX, this.bPosY, this.bWidth2, this.bHeight2);
  }

  //function to update the Buttons
  this.updateButtonRect = function() {
    stroke(255); //DOES NOT MAKE ANY PROBLEM AT ALL
    strokeWeight(1);
    //colorMode(HSB, 100);
    this.bSelectColor = color('#9b8c8c');
    fill(this.bSelectColor);
    rect(this.bPosX, this.bPosY, this.bWidth2, this.bHeight2);
  }

  this.updateButtonEllipse = function() {
      stroke(255); //HERE IS THE PROBLEM, JUST FOR ELLIPSE BUTTONS
      strokeWeight(1);
      //colorMode(HSB, 100);
      this.bSelectColor = color('#939393');
      fill(this.bSelectColor);
      ellipseMode(CENTER);
      ellipse(this.bPosX, this.bPosY, this.bWidth2, this.bHeight2);
    }
    //
    //Checks if Mouse is Over Rectangular Button
  this.mouseOverRect = function() {
      if (touchX > this.bPosX && touchX < this.bPosX + this.bWidth2 && touchY > this.bPosY && touchY < this.bPosY + this.bHeight2) {
        return true;
      } else {
        return false;
      }
    }
    //Checks if Mouse is Over Rectangular Button
  this.mouseOverEllipse = function() {
    this.disX = this.bPosX - touchX;
    this.disY = this.bPosY - touchY;
    if (sqrt(sq(this.disX) + sq(this.disY)) < this.bWidth2 / 2) {
      return true;
    } else {
      return false;
    }
  }
}

Any Ideas where the Problem could lie?

Answers

  • Answer ✓

    Can't you just call noStroke() before text()? :-??

  • It works in the textclass but not when I'm calling it after the objectcreation in my maincode...strange. But anyway it would interest me how stroke() affects some of my text and some other not.

    Thanks for the quick replay!

  • Answer ✓

    Both stroke() & strokeWeight() affect p5.Font's text().
    It was unintentional. But once found out, it became a p5.js' feature. ;))
    The other Processing modes/spin-offs don't have that though. :(|)

Sign In or Register to comment.