<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with _onmousedown() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=_onmousedown%28%29</link>
      <pubDate>Sun, 08 Aug 2021 20:05:48 +0000</pubDate>
         <description>Tagged with _onmousedown() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged_onmousedown%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Click event on rect object</title>
      <link>https://forum.processing.org/two/discussion/25722/click-event-on-rect-object</link>
      <pubDate>Tue, 26 Dec 2017 16:45:53 +0000</pubDate>
      <dc:creator>UsamaRehan</dc:creator>
      <guid isPermaLink="false">25722@/two/discussions</guid>
      <description><![CDATA[<p>I have a rect object which I draw it as a grid on the canvas and I need to trigger an event when I press on a particular object,I do something.</p>

<pre><code>function allBorders(x,y,w,h){
  this.x = x;
  this.y = y;
  this.w = w;
  this.h = h;

  this.fills = false;
  this.drawBorders = function(){
    push();
    strokeWeight(5);
    stroke(150);
    if(this.fills){
      fill(0,255,0);
    }
    rect(this.x,this.y,this.w,this.h);
    pop();
  }

  this.clickedOnRects = function(x_,y_){

    if( ((x_ &gt;= this.x) &amp;&amp; (x_ &lt;= this.w)) &amp;&amp; ((y_ &gt;= this.y) &amp;&amp; (y_ &lt;= this.h)) ){
      this.fills = true;
    }

  }
}
</code></pre>

<p>This is my mousePressed function</p>

<pre><code>function mousePressed(){
  for(let x = 0 ; x &lt; borders.length ; x++){
    borders[x].clickedOnRects(mouseX,mouseY);
  }
}
</code></pre>

<p>I do like,when the mouse is pressed then call all the object's <code>clickedOnRects</code> and check whether the mouseX,mouseY is inside the object or not.</p>

<p>These are my array objects.</p>

<pre><code>  borders.push( new allBorders(0,0,width/3,height/4));
  borders.push( new allBorders(width/3,0,width/3,height/4));
  borders.push( new allBorders(width/3*2,0,width/3,height/4));
  borders.push( new allBorders(0,height/4,width/3,height/4));
  borders.push( new allBorders(width/3,height/4,width/3,height/4));
  borders.push( new allBorders(width/3*2,height/4,width/3,height/4));
  borders.push( new allBorders(0,(height/4)*2,width/3,height/4));
  borders.push( new allBorders(width/3,(height/4)*2,width/3,height/4));
  borders.push( new allBorders(width/3*2,(height/4)*2,width/3,height/4));
</code></pre>

<p>But the problem is the click function is working only for the first's object and not on the other object. Can someone suggest what is wrong in my code.</p>

<p>Working example</p>

<p><a href="http://alpha.editor.p5js.org/zusamarehan/sketches/B1GpXWlQf" target="_blank" rel="nofollow">http://alpha.editor.p5js.org/zusamarehan/sketches/B1GpXWlQf</a></p>
]]></description>
   </item>
   </channel>
</rss>