Starting at line 1190 of GraphEditorPanel.cpp (https://github.com/juce-framework/JUCE/blob/master/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp#L1190), there is the code shown below:
if (isOnTouchDevice())
{
if (isOnTouchDevice())
{
titleBarComponent.reset (new TitleBarComponent (*this));
addAndMakeVisible (titleBarComponent.get());
}
pluginListBoxModel.reset (new PluginListBoxModel (pluginListBox, pluginList));
pluginListBox.setModel (pluginListBoxModel.get());
pluginListBox.setRowHeight (40);
pluginListSidePanel.setContent (&pluginListBox, false);
mobileSettingsSidePanel.setContent (new AudioDeviceSelectorComponent (deviceManager,
0, 2, 0, 2,
true, true, true, false));
if (isOnTouchDevice())
{
addAndMakeVisible (pluginListSidePanel);
addAndMakeVisible (mobileSettingsSidePanel);
}
}
My question is, is the second and third “inOnTouchDevice” judgment in this code necessary?
Continue to analyze in depth, the implementation of “isOnTouchDevice” is in line 152 of HostStartup.cpp (https://github.com/juce-framework/JUCE/blob/master/extras/AudioPluginHost/Source/HostStartup.cpp#L152):
bool isOnTouchDevice() { return Desktop::getInstance().getMainMouseSource().isTouch(); }
The list of mouse sources is constructed by the code “mouseSources (new MouseInputSource::SourceList())
” when creating an instance of Desktop.
Then the constructor of MouseInputSource::SourceList is just as follows:
SourceList()
{
#if JUCE_ANDROID || JUCE_IOS
auto mainMouseInputType = MouseInputSource::InputSourceType::touch;
#else
auto mainMouseInputType = MouseInputSource::InputSourceType::mouse;
#endif
addSource (0, mainMouseInputType);
}
So it seems that the main mouse source is always a mouse on the desktop platform and always a touch on the mobile platform.
So back to the original question, is the second and third judgment of “isOnTouchDevice” necessary? Or are there other conditions that may cause the main mouse source to be changed at runtime?