Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main #1183

Merged
merged 10 commits into from
Sep 12, 2023
6 changes: 6 additions & 0 deletions Source/CanvasViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class CanvasViewport : public Viewport {
e.originalComponent->setMouseCursor(MouseCursor::DraggingHandCursor);
downPosition = viewport->getViewPosition();
downCanvasOrigin = viewport->cnv->canvasOrigin;

for (auto* object : viewport->cnv->objects)
object->setBufferedToImage(true);
}

void mouseDrag(MouseEvent const& e) override
Expand All @@ -59,6 +62,9 @@ class CanvasViewport : public Viewport {
void mouseUp(MouseEvent const& e) override
{
e.originalComponent->setMouseCursor(MouseCursor::NormalCursor);
for (auto* object : viewport->cnv->objects){
object->setBufferedToImage(false);
}
}

private:
Expand Down
2 changes: 1 addition & 1 deletion Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void PluginEditor::resized()

palettes->setBounds(0, toolbarHeight, palettes->getWidth(), getHeight() - toolbarHeight - (statusbar->getHeight()));

splitView.setBounds(paletteWidth, toolbarHeight, (getWidth() - sidebar->getWidth() - paletteWidth) + 1, getHeight() - toolbarHeight - Statusbar::statusbarHeight);
splitView.setBounds(paletteWidth, toolbarHeight, (getWidth() - sidebar->getWidth() - paletteWidth), getHeight() - toolbarHeight - Statusbar::statusbarHeight);
sidebar->setBounds(getWidth() - sidebar->getWidth(), toolbarHeight, sidebar->getWidth(), getHeight() - toolbarHeight - Statusbar::statusbarHeight);
statusbar->setBounds(0, getHeight() - Statusbar::statusbarHeight, getWidth(), statusbar->getHeight());

Expand Down
38 changes: 16 additions & 22 deletions Source/ResizableTabbedComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "Utility/ObjectDragAndDrop.h"


#define ENABLE_SPLITS_DROPZONE_DEBUGGING 0

ResizableTabbedComponent::ResizableTabbedComponent(PluginEditor* editor, TabComponent* mainTabComponent)
Expand Down Expand Up @@ -266,19 +265,11 @@ int ResizableTabbedComponent::findZoneFromSource(SourceDetails const& dragSource
return -1;
}

void ResizableTabbedComponent::mouseDrag(MouseEvent const& e)
{
}

void ResizableTabbedComponent::mouseDown(MouseEvent const& e)
{
editor->splitView.setFocus(this);
}

void ResizableTabbedComponent::mouseMove(MouseEvent const& e)
{
}

void ResizableTabbedComponent::setBoundsWithFactors(Rectangle<int> bounds)
{
if (resizerLeft)
Expand Down Expand Up @@ -373,6 +364,7 @@ void ResizableTabbedComponent::paintOverChildren(Graphics& g)

void ResizableTabbedComponent::itemDragEnter(SourceDetails const& dragSourceDetails)
{
editor->splitView.setFocus(this);
// if we are dragging a tabbar, update the highlight split
if(dynamic_cast<TabBarButtonComponent*>(dragSourceDetails.sourceComponent.get())) {
isDragAndDropOver = true;
Expand All @@ -383,36 +375,38 @@ void ResizableTabbedComponent::itemDragEnter(SourceDetails const& dragSourceDeta

void ResizableTabbedComponent::itemDragExit(SourceDetails const& dragSourceDetails)
{
isDragAndDropOver = false;
repaint();
if(dynamic_cast<TabBarButtonComponent*>(dragSourceDetails.sourceComponent.get())) {
isDragAndDropOver = false;
repaint();
}
}

void ResizableTabbedComponent::itemDragMove(SourceDetails const& dragSourceDetails)
{
activeZone = DropZones::None;
// if we are dragging from a palette or automation item, highlight the dragged over split
if (dynamic_cast<ObjectDragAndDrop*>(dragSourceDetails.sourceComponent.get())) {
isDragAndDropOver = false;
editor->splitView.setFocus(this);
}
// if we are dragging a tabbed window or from the document browser
else if (auto sourceTabButton = static_cast<TabBarButtonComponent*>(dragSourceDetails.sourceComponent.get())) {
if (auto sourceTabButton = dynamic_cast<TabBarButtonComponent*>(dragSourceDetails.sourceComponent.get())) {
auto sourceTabContent = sourceTabButton->getTabComponent();
int sourceNumTabs = sourceTabContent->getNumTabs();

auto zone = findZoneFromSource(dragSourceDetails);

editor->splitView.setFocus(this);

if (editor->splitView.canSplit() && sourceNumTabs > 1) {
if (activeZone != zone) {
activeZone = zone;
repaint();
// std::cout << "dragging over: " << getZoneName(zone) << std::endl;
}
} else if (sourceTabButton->getTabComponent() != tabComponent.get()) {
activeZone = zone == DropZones::TabBar ? DropZones::None : DropZones::Centre;
repaint();
auto foundZone = zone == DropZones::TabBar ? DropZones::None : DropZones::Centre;
if (activeZone != foundZone){
activeZone = foundZone;
repaint();
}
} else if (sourceTabButton->getTabComponent() == tabComponent.get()) {
if (activeZone != DropZones::None) {
activeZone = DropZones::None;
repaint();
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Source/ResizableTabbedComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class ResizableTabbedComponent : public Component

~ResizableTabbedComponent();

void mouseDrag(MouseEvent const& e) override;
void mouseDown(MouseEvent const& e) override;
void mouseMove(MouseEvent const& e) override;

void resized() override;
void paintOverChildren(Graphics& g) override;
Expand Down
79 changes: 30 additions & 49 deletions Source/SplitView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,47 @@
#include "PluginProcessor.h"
#include "Sidebar/Sidebar.h"

class FadeAnimation : private Timer {
class SplitViewFocusOutline : public Component
, public ComponentListener {
public:
explicit FadeAnimation(SplitView* splitView)
: splitView(splitView)
SplitViewFocusOutline()
{
setInterceptsMouseClicks(false, false);
}

float fadeIn()
void setActive(ResizableTabbedComponent* tabComponent)
{
targetAlpha = 0.3f;
if (!isTimerRunning() && currentAlpha < targetAlpha)
startTimerHz(60);
setVisible(true);

return currentAlpha;
if (tabbedComponent != tabComponent) {
if (tabbedComponent)
tabbedComponent->removeComponentListener(this);

tabComponent->addComponentListener(this);
setBounds(tabComponent->getBounds());
tabbedComponent = tabComponent;
}
}

float fadeOut()
void componentMovedOrResized(Component& component, bool moved, bool resized) override
{
targetAlpha = 0.0f;
if (!isTimerRunning() && currentAlpha > targetAlpha)
startTimerHz(60);

return currentAlpha;
if (&component == tabbedComponent) {
setBounds(component.getBounds());
}
}

private:
void timerCallback() override
void paint(Graphics& g)
{
float const stepSize = 0.025f;
if (targetAlpha > currentAlpha) {
currentAlpha += stepSize;
if (currentAlpha >= targetAlpha) {
currentAlpha = targetAlpha;
stopTimer();
}
} else if (targetAlpha < currentAlpha) {
currentAlpha -= stepSize;
if (currentAlpha <= targetAlpha) {
currentAlpha = targetAlpha;
stopTimer();
}
}
if (splitView != nullptr)
splitView->repaint();
g.setColour(findColour(PlugDataColour::objectSelectedOutlineColourId).withAlpha(0.3f));
g.drawRect(getLocalBounds(), 2.5f);
}

private:
SplitView* splitView;
float currentAlpha = 0.0f;
float targetAlpha = 0.0f;
SafePointer<ResizableTabbedComponent> tabbedComponent;
};

SplitView::SplitView(PluginEditor* parent)
: editor(parent)
, fadeAnimation(new FadeAnimation(this))
, fadeAnimationLeft(new FadeAnimation(this))
, fadeAnimationRight(new FadeAnimation(this))
{
rootComponent = new ResizableTabbedComponent(editor);
splits.add(rootComponent);
Expand All @@ -80,6 +64,10 @@ SplitView::SplitView(PluginEditor* parent)
// either we check if the tabcomponent is welcome mode, or we check if it's nullptr down the line
activeTabComponent = rootComponent;

focusOutline = std::make_unique<SplitViewFocusOutline>();
addChildComponent(focusOutline.get());
focusOutline->setAlwaysOnTop(true);

addMouseListener(this, true);
}

Expand Down Expand Up @@ -117,6 +105,9 @@ void SplitView::removeSplit(TabComponent* toRemove)
}
}
delete toBeRemoved;

if (splits.size() == 1)
focusOutline->setVisible(false);
}

void SplitView::addSplit(ResizableTabbedComponent* split)
Expand Down Expand Up @@ -166,7 +157,7 @@ void SplitView::setFocus(ResizableTabbedComponent* selectedTabComponent)
{
if (activeTabComponent != selectedTabComponent) {
activeTabComponent = selectedTabComponent;
repaint();
focusOutline->setActive(activeTabComponent);
}
}

Expand Down Expand Up @@ -197,16 +188,6 @@ void SplitView::closeEmptySplits()
}
}

void SplitView::paintOverChildren(Graphics& g)
{
if (splits.size() > 1) {
g.setColour(findColour(PlugDataColour::objectSelectedOutlineColourId).withAlpha(0.3f));
auto screenBounds = activeTabComponent->getScreenBounds();
auto b = getLocalArea(nullptr, screenBounds);
g.drawRect(b, 2.5f);
}
}

ResizableTabbedComponent* SplitView::getSplitAtScreenPosition(Point<int> position)
{
for (auto* split : splits) {
Expand Down
12 changes: 5 additions & 7 deletions Source/SplitView.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

#pragma once

#include <JuceHeader.h>

#include "SplitViewResizer.h"
#include "ResizableTabbedComponent.h"

class PluginEditor;
class Canvas;
class FadeAnimation;
class SplitViewFocusOutline;
class SplitView : public Component {
public:
explicit SplitView(PluginEditor* parent);
Expand All @@ -31,8 +33,6 @@ class SplitView : public Component {

void closeEmptySplits();

void paintOverChildren(Graphics& g) override;

int getTabComponentSplitIndex(TabComponent* tabComponent);

ResizableTabbedComponent* getSplitAtScreenPosition(Point<int> position);
Expand All @@ -52,12 +52,10 @@ class SplitView : public Component {
SafePointer<ResizableTabbedComponent> activeTabComponent = nullptr;
ResizableTabbedComponent* rootComponent;

std::unique_ptr<FadeAnimation> fadeAnimation;
std::unique_ptr<FadeAnimation> fadeAnimationLeft;
std::unique_ptr<FadeAnimation> fadeAnimationRight;

bool splitviewIndicator = false;

std::unique_ptr<SplitViewFocusOutline> focusOutline;

PluginEditor* editor;

std::unique_ptr<Component> splitViewResizer;
Expand Down
25 changes: 22 additions & 3 deletions Source/Tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ class ButtonBar::GhostTab : public Component {
void setTabButtonToGhost(TabBarButton* tabButton)
{
tab = tabButton;
setBounds(tab->getBounds());
repaint();
// this should never happen, if it does then the index for the tab is wrong ( getTab(idx) will return nullptr )
// which can happen if the tabbar goes into overflow, because we don't know exactly when that will happen
if (tab){
setBounds(tab->getBounds());
repaint();
}
}

int getIndex()
Expand Down Expand Up @@ -165,6 +169,7 @@ void ButtonBar::itemDragEnter(SourceDetails const& dragSourceDetails)
{
if (auto* tab = dynamic_cast<TabBarButtonComponent*>(dragSourceDetails.sourceComponent.get())) {
ghostTabAnimator.cancelAllAnimations(false);
owner.setFocused();
// if this tabbar is DnD on itself, we don't need to add a new tab
// we move the existing tab
if (tab->getTabComponent() == &owner) {
Expand All @@ -180,10 +185,16 @@ void ButtonBar::itemDragEnter(SourceDetails const& dragSourceDetails)
// WARNING: because we are using the overflow (show extra items menu)
// we need to find out how many tabs are visible, not how many there are all together
auto targetTabPos = getWidth() / (getNumVisibleTabs() + 1);
auto tabPos = dragSourceDetails.localPosition.getX() / targetTabPos;
// FIXME: This is a hack. When tab is added to tabbar right edge, and it goes into overflow
// we don't know when that will happen.
// So we force the right most tab to think it's always two less when it gets added
auto tabPos = jmin(dragSourceDetails.localPosition.getX() / targetTabPos, getNumVisibleTabs() - 2);
tabPos = jmax(0, tabPos);

inOtherSplit = true;
auto unusedComponent = std::make_unique<Component>();
owner.addTab(tab->getButtonText(), unusedComponent.get(), tabPos);

auto* fakeTab = getTabButton(tabPos);
tab->getProperties().set("dragged", var(true));
ghostTab->setTabButtonToGhost(fakeTab);
Expand Down Expand Up @@ -293,6 +304,14 @@ TabComponent::~TabComponent()
tabs.reset();
}

void TabComponent::setFocused()
{
for (auto * split : editor->splitView.splits){
if (split->getTabComponent() == this)
editor->splitView.setFocus(split);
}
}

int TabComponent::getCurrentTabIndex()
{
return tabs->getCurrentTabIndex();
Expand Down
2 changes: 2 additions & 0 deletions Source/Tabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ class TabComponent : public Component

Canvas* getCurrentCanvas();

void setFocused();

PluginEditor* getEditor();

Image tabSnapshot;
Expand Down
Loading