mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-03 03:30:06 +00:00
More MouseInputSource tweaks.
This commit is contained in:
parent
6758ce0bc9
commit
4233f603db
4 changed files with 56 additions and 31 deletions
|
|
@ -28,11 +28,28 @@
|
|||
|
||||
|
||||
//==============================================================================
|
||||
SourceCodeEditor::SourceCodeEditor (OpenDocumentManager::Document* document_,
|
||||
CodeDocument& codeDocument)
|
||||
SourceCodeEditor::SourceCodeEditor (OpenDocumentManager::Document* document_, CodeDocument& codeDocument)
|
||||
: DocumentEditorComponent (document_)
|
||||
{
|
||||
addAndMakeVisible (editor = createEditor (codeDocument));
|
||||
createEditor (codeDocument);
|
||||
}
|
||||
|
||||
SourceCodeEditor::SourceCodeEditor (OpenDocumentManager::Document* document_)
|
||||
: DocumentEditorComponent (document_)
|
||||
{
|
||||
}
|
||||
|
||||
void SourceCodeEditor::createEditor (CodeDocument& codeDocument)
|
||||
{
|
||||
if (document->getFile().hasFileExtension (sourceOrHeaderFileExtensions))
|
||||
setEditor (new CppCodeEditorComponent (codeDocument));
|
||||
else
|
||||
setEditor (new CodeEditorComponent (codeDocument, nullptr));
|
||||
}
|
||||
|
||||
void SourceCodeEditor::setEditor (CodeEditorComponent* newEditor)
|
||||
{
|
||||
addAndMakeVisible (editor = newEditor);
|
||||
|
||||
#if JUCE_MAC
|
||||
Font font (13.0f);
|
||||
|
|
@ -54,14 +71,6 @@ SourceCodeEditor::~SourceCodeEditor()
|
|||
getAppSettings().appearance.settings.removeListener (this);
|
||||
}
|
||||
|
||||
CodeEditorComponent* SourceCodeEditor::createEditor (CodeDocument& codeDocument)
|
||||
{
|
||||
if (document->getFile().hasFileExtension (sourceOrHeaderFileExtensions))
|
||||
return new CppCodeEditorComponent (codeDocument);
|
||||
|
||||
return new CodeEditorComponent (codeDocument, nullptr);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void SourceCodeEditor::resized()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,14 +34,16 @@ class SourceCodeEditor : public DocumentEditorComponent,
|
|||
private ValueTree::Listener
|
||||
{
|
||||
public:
|
||||
SourceCodeEditor (OpenDocumentManager::Document* document,
|
||||
CodeDocument& codeDocument);
|
||||
SourceCodeEditor (OpenDocumentManager::Document* document, CodeDocument& codeDocument);
|
||||
SourceCodeEditor (OpenDocumentManager::Document* document);
|
||||
~SourceCodeEditor();
|
||||
|
||||
void createEditor (CodeDocument& codeDocument);
|
||||
void setEditor (CodeEditorComponent*);
|
||||
|
||||
private:
|
||||
ScopedPointer<CodeEditorComponent> editor;
|
||||
|
||||
CodeEditorComponent* createEditor (CodeDocument&);
|
||||
void resized();
|
||||
|
||||
void valueTreePropertyChanged (ValueTree&, const Identifier&);
|
||||
|
|
@ -125,6 +127,8 @@ private:
|
|||
|
||||
static String getIndentForCurrentBlock (CodeDocument::Position pos)
|
||||
{
|
||||
int braceCount = 0;
|
||||
|
||||
while (pos.getLineNumber() > 0)
|
||||
{
|
||||
pos = pos.movedByLines (-1);
|
||||
|
|
@ -132,8 +136,18 @@ private:
|
|||
const String line (pos.getLineText());
|
||||
const String trimmedLine (line.trimStart());
|
||||
|
||||
if (trimmedLine.startsWithChar ('{'))
|
||||
return getLeadingWhitespace (line);
|
||||
StringArray tokens;
|
||||
tokens.addTokens (trimmedLine, true);
|
||||
|
||||
for (int i = tokens.size(); --i >= 0;)
|
||||
{
|
||||
if (tokens[i] == "}")
|
||||
++braceCount;
|
||||
|
||||
if (tokens[i] == "{")
|
||||
if (--braceCount < 0)
|
||||
return getLeadingWhitespace (line);
|
||||
}
|
||||
}
|
||||
|
||||
return String::empty;
|
||||
|
|
|
|||
|
|
@ -28,13 +28,18 @@ class MouseInputSourceInternal : public AsyncUpdater
|
|||
public:
|
||||
//==============================================================================
|
||||
MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
|
||||
: index (index_), isMouseDevice (isMouseDevice_), isDragging (false), source (source_),
|
||||
lastPeer (nullptr), isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false),
|
||||
currentCursorHandle (nullptr), mouseEventCounter (0)
|
||||
: index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (nullptr),
|
||||
isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (nullptr),
|
||||
mouseEventCounter (0), mouseMovedSignificantlySincePressed (false)
|
||||
{
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool isDragging() const noexcept
|
||||
{
|
||||
return buttonState.isAnyMouseButtonDown();
|
||||
}
|
||||
|
||||
Component* getComponentUnderMouse() const
|
||||
{
|
||||
return static_cast <Component*> (componentUnderMouse);
|
||||
|
|
@ -129,7 +134,7 @@ public:
|
|||
return false;
|
||||
|
||||
// (avoid sending a spurious mouse-drag when we receive a mouse-up)
|
||||
if (! (buttonState.isAnyMouseButtonDown() && ! newButtonState.isAnyMouseButtonDown()))
|
||||
if (! (isDragging() && ! newButtonState.isAnyMouseButtonDown()))
|
||||
setScreenPos (screenPos, time, false);
|
||||
|
||||
// (ignore secondary clicks when there's already a button down)
|
||||
|
|
@ -149,7 +154,6 @@ public:
|
|||
{
|
||||
const ModifierKeys oldMods (getCurrentModifiers());
|
||||
buttonState = newButtonState; // must change this before calling sendMouseUp, in case it runs a modal loop
|
||||
isDragging = false;
|
||||
|
||||
sendMouseUp (current, screenPos + unboundedMouseOffset, time, oldMods);
|
||||
}
|
||||
|
|
@ -167,7 +171,6 @@ public:
|
|||
|
||||
if (current != nullptr)
|
||||
{
|
||||
isDragging = true;
|
||||
registerMouseDown (screenPos, time, current, buttonState);
|
||||
sendMouseDown (current, screenPos, time);
|
||||
}
|
||||
|
|
@ -223,7 +226,7 @@ public:
|
|||
|
||||
void setScreenPos (const Point<int>& newScreenPos, const Time& time, const bool forceUpdate)
|
||||
{
|
||||
if (! isDragging)
|
||||
if (! isDragging())
|
||||
setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
|
||||
|
||||
if (newScreenPos != lastScreenPos || forceUpdate)
|
||||
|
|
@ -235,7 +238,7 @@ public:
|
|||
|
||||
if (current != nullptr)
|
||||
{
|
||||
if (isDragging)
|
||||
if (isDragging())
|
||||
{
|
||||
registerMouseDrag (newScreenPos);
|
||||
sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
|
||||
|
|
@ -261,7 +264,7 @@ public:
|
|||
++mouseEventCounter;
|
||||
const Point<int> screenPos (newPeer->localToGlobal (positionWithinPeer));
|
||||
|
||||
if (isDragging && newMods.isAnyMouseButtonDown())
|
||||
if (isDragging() && newMods.isAnyMouseButtonDown())
|
||||
{
|
||||
setScreenPos (screenPos, time, false);
|
||||
}
|
||||
|
|
@ -294,7 +297,7 @@ public:
|
|||
setScreenPos (screenPos, time, false);
|
||||
triggerFakeMove();
|
||||
|
||||
if (! isDragging)
|
||||
if (! isDragging())
|
||||
{
|
||||
Component* current = getComponentUnderMouse();
|
||||
if (current != nullptr)
|
||||
|
|
@ -347,7 +350,7 @@ public:
|
|||
//==============================================================================
|
||||
void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
|
||||
{
|
||||
enable = enable && isDragging;
|
||||
enable = enable && isDragging();
|
||||
isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
|
||||
|
||||
if (enable != isUnboundedMouseModeOn)
|
||||
|
|
@ -422,7 +425,6 @@ public:
|
|||
//==============================================================================
|
||||
const int index;
|
||||
const bool isMouseDevice;
|
||||
bool isDragging;
|
||||
Point<int> lastScreenPos;
|
||||
ModifierKeys buttonState;
|
||||
|
||||
|
|
@ -495,7 +497,7 @@ bool MouseInputSource::isTouch() const { return
|
|||
bool MouseInputSource::canHover() const { return isMouse(); }
|
||||
bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
|
||||
int MouseInputSource::getIndex() const { return pimpl->index; }
|
||||
bool MouseInputSource::isDragging() const { return pimpl->isDragging; }
|
||||
bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
|
||||
Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
|
||||
ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
|
||||
Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
|
||||
|
|
|
|||
|
|
@ -779,7 +779,7 @@ void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, cons
|
|||
if (isCancel)
|
||||
{
|
||||
currentTouches.clear();
|
||||
currentModifiers = currentModifiers.withoutMouseButtons();
|
||||
modsToSend = currentModifiers = currentModifiers.withoutMouseButtons();
|
||||
}
|
||||
|
||||
handleMouseEvent (touchIndex, pos, modsToSend, time);
|
||||
|
|
@ -788,7 +788,7 @@ void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, cons
|
|||
|
||||
if (isUp || isCancel)
|
||||
{
|
||||
handleMouseEvent (touchIndex, Point<int> (-1, -1), currentModifiers, time);
|
||||
handleMouseEvent (touchIndex, Point<int> (-1, -1), modsToSend, time);
|
||||
if (! isValidPeer (this))
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue