Accessing MouseInputSource from MouseEvent?

I’m trying to access the MouseInputSource from a MouseEvent can all MouseInputSource ::setScreenPisition but I keep getting errors?


2>D:\sourcecode\starvoicevst\StarVoice\Source\StarVoiceBasicGUIComponents.cpp(73,56): error C2662: 'void juce::MouseInputSource::setScreenPosition(juce::Point<float>)': cannot convert 'this' pointer from 'const juce::MouseInputSource' to 'juce::MouseInputSource &'
2>D:\sourcecode\starvoicevst\StarVoice\Source\StarVoiceBasicGUIComponents.cpp(73,6): message : Conversion loses qualifiers
2>D:\sourcecode\starvoicevst\StarVoice\JUCE\modules\juce_gui_basics\mouse/juce_MouseInputSource.h(222,10): message : see declaration of 'juce::MouseInputSource::setScreenPosition' (compiling source file D:\sourcecode\starvoicevst\StarVoice\Source\StarVoiceBasicGUIComponents.cpp)

I am a bit confused as I can’t see anything in the MouseInputSource class that should cause this error. And I’ve seen lots of examples on the list of people calling this method from within a mouse drag or move handler… :thinking: What am I missing here?

p.s. those call to canDoUnbounded… and enableUnbounded… were just tests to see if I can call other member functions of the source object without issues…

e is const, and MouseInputSource::setScreenPosition() is a non-const method. You could use Desktop::getInstance().getMainMouseSource() if you know you’ll only have one input source (on desktop for example) or use ::getNumMouseSources() and ::getMouseSource() to iterate over the sources.

Thanks Ed. Yes, this makes sense. I didn’t notice the const-ness, even though the compiler was screaming it right in my ear. I feel sorry for the compiler. Imagine having to work with me on a regular basis! :laughing: