View Single Post
Old 12-31-2012, 08:30 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Excuse me, but you are working *WAY* too hard.

You don't *REALLY* care if the mouse has move 2 pixels, right? And that's very likely to happen with a human hand controlling the mouse.

So, instead, just check to see if the mouse is in the SAME TILE!

Like this:
Code:
      // set up all the cells:
      for ( var r = 0; r < theMap.length; ++r )
      {
          var row = theMap[r];
          var tr = tbl.insertRow(-1);
          for ( var c = 0; c < row.length; ++c )
          {
              var cell = tr.insertCell(-1);
              cell.id = (theMap.length - r - 2) + ":" + (c+1-5);
              cell.className = classes[row.charAt(c)];
              cell.onmouedown = cellClickStart;
              cell.onmouseup  = cellClickEnd;
          }
      }

      ...

  var whereButtonDown = null;

  function cellCickStart( )
  {
      whereButtonDown = this;
  }
  function cellClickEnd( )
  {
      var bDown = whereBUttonDown;
      whereBUttonDown = null; // RESET IT!

      if ( bDown != this ) /* have we moved to a different tile? */
      {
          /* yes...so treat it as a drag: */
          mouseDragged( bDown, this );
          return;
      }

      // still in same cell, so just treat as a click & show menu:
      clk.innerHTML = this.id;
      typ.innerHTML = this.className;
      pop.style.display = "block";
  }

  function mouseDragged( fromCell, toCell )
  {
      .. you can write this ..
  }
New/changed stuff in red.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote