# Problem hiding cursor in Component::mouseDown

**URL:** <https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086>\
**Category:** General JUCE discussion\
**Created:** [December 23, 2010, 10:53pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086 "2010-12-23T22:53:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![juan1979](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@juan1979](https://forum.juce.com/u/juan1979)\
**Post date:** [December 23, 2010, 10:53pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/1 "2010-12-23T22:53:02Z")

</div>

I’m trying to hide the cursor when I click a component, but the problem is that the cursor doesn’t dissapear until I release the left mouse button, and I get an ugly effect because the cursor must move to another place.

[code]void BotonZoom::mouseDown(const MouseEvent &e)  
{

```
setMouseCursor(MouseCursor::NoCursor);
Desktop::setMousePosition(areaMonitorPrincipal.getCentre());

```

}  
[/code]

What could I do?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [December 23, 2010, 10:56pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/2 "2010-12-23T22:56:29Z")

</div>

try

```auto
  e.source.enableUnboundedMouseMovement (true);
```

in your mouseDown() instead of those two lines of code you have.

---

<div class="post-metadata">

**Author:** ![juan1979](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@juan1979](https://forum.juce.com/u/juan1979)\
**Post date:** [December 24, 2010, 11:17am UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/3 "2010-12-24T11:17:33Z")

</div>

Thanks! It seems to do what I wanted do in first place! 😃

btw, is there any easy method to limit the mouse movement after use this command?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [December 24, 2010, 2:40pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/4 "2010-12-24T14:40:03Z")

</div>

What do you mean limit the mouse movement? At this point the cursor is invisible. When the mouse button is released, the cursor should appear somewhere inside your component. What exactly are you trying to do?

---

<div class="post-metadata">

**Author:** ![juan1979](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@juan1979](https://forum.juce.com/u/juan1979)\
**Post date:** [December 24, 2010, 4:40pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/5 "2010-12-24T16:40:42Z")

</div>

I’m trying to create an special zoom button. If you drag it up/down you get vertical zoom (and a button animation), left/right horizontal zoom, and something between mixed vertical & horizontal zoom. The zoom goes from 0.25x to 4.00x, it’s limited with a basic if secuence.

The problem with enableUnboundedMouseMovement is that movement is totally unrestricted (= unlimited), so if you drag the button and adjust the zoom at 4.00x and you continue dragging your mouse, let’s say, one meter, you must move the mouse one meter back again if you want to reduce the zoom again.

I think I’m going to use in mouse down method:

`void BotonZoom::mouseDown(const MouseEvent &e)
{
	e.source.hideCursor(); // Thanks to you, TheVinn, I learnt about this class
	setMouseCursor(MouseCursor::NoCursor);
}
`

And then restrict the mouse movement in mouse drag. In mouse up I’ll return the cursor to the last clicked point.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [December 24, 2010, 5:06pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/6 "2010-12-24T17:06:04Z")

</div>

Yes, I understand exactly your problem. When the mouse goes beyond the limit 4x, and the user changes direction, you dont want to wait for the mouse to come back, you want to immediately begin reducing the zoom from 4x. I address this exact behavior in my custom slider (which also functions as a knob). Consider the following code:

```auto
void CustomSlider::mouseDrag (const MouseEvent& e)
{
  if (m_bEnableUnboundedMouseMovement)
  {
    e.source.enableUnboundedMouseMovement( true );
    m_bEnableUnboundedMouseMovement=false;
  }

  double value;

  switch( m_style )
  {
  case styleVertical:
    value = m_startValue
      + e.getDistanceFromDragStartX()/1500.
      - e.getDistanceFromDragStartY()/250.;
    break;

  case styleHorizontal:
    value = m_startValue
      + e.getDistanceFromDragStartX()/250.
      - e.getDistanceFromDragStartY()/1500.;
    break;

  default:
    value=0;
    break;
  };

  // MAGIC LINES ARE HERE
  if( value > 1 )
  {
    m_startValue -= value - 1;
    value = 1;
  }
  else if( value < 0 )
  {
    m_startValue -= value;
    value = 0;
  }
  // END OF MAGIC LINES

  notifySetValue( value );
}
```

m\_startValue is the initial value of the control, saved in mouseDown. If you look at the “magic lines”, I address the case where the unbounded mouse would cause the value go to outside the range (-1 and 1 in my case, and for you it would be 0.25x and 4.00x).

In my control, no matter how far you push the mouse past the control value limit of 0…1, as soon as you reverse direction the control is immediately responsive - this, I believe, is exactly what you are asking for.

---

<div class="post-metadata">

**Author:** ![juan1979](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@juan1979](https://forum.juce.com/u/juan1979)\
**Post date:** [December 24, 2010, 6:12pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/7 "2010-12-24T18:12:24Z")

</div>

That’s what I was looking for! Thanks for your support and happy chrismas! 😃

---

<div class="post-metadata">

**Author:** ![erteash](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@erteash](https://forum.juce.com/u/erteash)\
**Post date:** [December 18, 2016, 8:57pm UTC](https://forum.juce.com/t/problem-hiding-cursor-in-component-mousedown/6086/8 "2016-12-18T20:57:16Z")

</div>

This seems like a bug, have they fixed it in new versions yet?  
Everyone wants the cursor to hide when dragging, and also respond immediately when changing direction.
